From nobody Fri Jun 18 13:57:15 2021 X-Original-To: current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4DC7B7EBE91 for ; Fri, 18 Jun 2021 13:57:16 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4G60pz4xHfz4YjR; Fri, 18 Jun 2021 13:57:15 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mail-qt1-x82a.google.com with SMTP id r7so7538577qta.12; Fri, 18 Jun 2021 06:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=qU2b3JBK4bchdaArqVBNNZ13yroJJp4RnRORlqZR1/Q=; b=DGvrNgJa5vjETRz7hJHakcEc9y8eltK/oqJeb2D5PyevvV/XVFD9IYqRrW3jgVvc6d LqXPMjeiN4lAMNZ7HFNWSRZhBhDFfjP2+a56kRMfyKZy1s9UOYoNoblhQ7xvDLxfXnvA gG9BbBQfA6RCHOjgJIolPsAK7nkLW5iTKVRuQfTj9z/U4pUNdoMWP1aaI9FS3bUpCgoo WUkqbfgMdFKHNMV/RSU5ABGRj32uhSGbrdZlbI25JU+f9HLsXwLiFOycZOW3e5myNqE6 a1ardTRvu2HW3VPVBlzK95iPP4e3PO4bW9SqoID0P+x3alFfpNKlA9tYliYV/nADVLd/ McIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=qU2b3JBK4bchdaArqVBNNZ13yroJJp4RnRORlqZR1/Q=; b=Psv9C/XYiEzq7ISmaYuElCQQ1VEKQm54DdrfRvvoQgwzF+Q4qbbSx0gOlNHF2VNRLY DPkZ5h6pvwS4ZVRNlCyOi4qmj7ofcNeTctyf3sHYIZ3X7RxHrG2MlEK1yhn1go9A7Pcu k+2gQmtMtCHwEsDKXVBPwEUjrc8mR7Rrkf4Faj63TQwZfVnCCsmev5hRlISF56cYbtd5 AYbeNDbi322BSMPfIGLZ+Or9wVZBo+k6JTysa1rfjqqVHOOLCkdAOq9Z405n8uxnO2lt uoUzPvoy2w5M94tjcXKzcrggZiRjNOIhahRiQdl3GGmg7l9EGjsY2CU4HyH0ZAFiAcDH vD8Q== X-Gm-Message-State: AOAM5309/9dyUieY282kPiejhO8cF5+VJuxlcjqAYumFR5xbClcIdZ4m /mOeHG8efsMhznqzZ7kFNsKGm/1wylhMcg== X-Google-Smtp-Source: ABdhPJzyvGjBAavBGYf6mpzbyU+pRgADUIO9n4EwUNtDRR9iCYbtwBa/9WOknR3w1GC5xcyWycAqYw== X-Received: by 2002:a05:622a:1487:: with SMTP id t7mr10906230qtx.246.1624024634515; Fri, 18 Jun 2021 06:57:14 -0700 (PDT) Received: from nuc ([142.126.172.178]) by smtp.gmail.com with ESMTPSA id m2sm3989752qkh.38.2021.06.18.06.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 06:57:14 -0700 (PDT) Date: Fri, 18 Jun 2021 09:57:15 -0400 From: Mark Johnston To: Neel Chauhan Cc: current@freebsd.org Subject: Re: Kernel/driver hacking: panic: Assertion vm_object_busied((m->object)) failed at /usr/src/sys/vm/vm_page.c:5455 Message-ID: References: <8bd27c2a72ebfa9299bca7d930297faf@FreeBSD.org> List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8bd27c2a72ebfa9299bca7d930297faf@FreeBSD.org> X-Rspamd-Queue-Id: 4G60pz4xHfz4YjR X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=DGvrNgJa; dmarc=none; spf=pass (mx1.freebsd.org: domain of markjdb@gmail.com designates 2607:f8b0:4864:20::82a as permitted sender) smtp.mailfrom=markjdb@gmail.com X-Spamd-Result: default: False [-2.70 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FORGED_SENDER(0.30)[markj@freebsd.org,markjdb@gmail.com]; MIME_TRACE(0.00)[0:+]; RBL_DBL_DONT_QUERY_IPS(0.00)[2607:f8b0:4864:20::82a:from]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[markj@freebsd.org,markjdb@gmail.com]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[freebsd.org]; SPAMHAUS_ZRD(0.00)[2607:f8b0:4864:20::82a:from:127.0.2.255]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::82a:from]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_TLS_ALL(0.00)[]; MAILMAN_DEST(0.00)[current] X-ThisMailContainsUnwantedMimeParts: N On Wed, Jun 16, 2021 at 10:16:56PM -0700, Neel Chauhan wrote: > Hi Mark, > > Thank you so much for your response! > > On 2021-06-16 14:05, Mark Johnston wrote: > > > > The function in question appears to implement a device page fault > > handler. In FreeBSD, such handlers are responsible only for ensuring > > that the requested page(s) are present in the VM object backing the > > mapping that was faulted on. The generic fault handler in > > sys/vm/vm_fault.c is responsible for actually updating the faulting > > process' page tables by calling pmap_enter(). In other words, our > > fault > > handler interface is quite different from OpenBSD's and their example > > should not be followed exactly. Adding a vm_object_busy() call in the > > loop will silence the assertion I guess but the handler is still wrong. > > Good to hear. No wonder why I still had the "blank screen of death" with > the (now previous) code. > > > If you look further down at vm_fault_gtt() (and in earlier versions of > > the DRM drivers, i915_gem_fault()), the remap_io_mapping() > > implementation in the LinuxKPI does basically what I'm describing. > > Something similar is required for vm_fault_cpu(), though I don't quite > > understand when vm_fault_cpu() is supposed to be used. > > I have some code to implement remap_io_sg() based on remap_io_mapping(), > but it's not complete. > > I am still trying to figure out how to get the physical address. Right > now, I have: > > https://github.com/neelchauhan/drm-kmod/commit/92a3d9bb585acb55c1dab9c5ed11190f7db73ecf > > My get_pfn() function (Lines 221-231) attempts to get the physical > address, and it is called at Line 248. > > Note: This code is probably incorrect, since it gives me an "page > already inserted" panic. That seems surprising, since the vm_page_grab() call should return the page at pidx if one exists. > Any hints on where the physical address is? Should we have an > FreeBSD-specific "pa" argument for the physical address if it's needed? I'm not sure. I'll just note that the Linux code appears to be trying to map a set of pages belonging to a scatter-gather list. Taking the physical address of the first page and assuming that all subsequent pages are physically contiguous doesn't seem correct, but this is what is happening in that loop, since each iteration simply increments pa by PAGE_SIZE.