From nobody Wed Jun 16 21:05:03 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 9B05F11D2D96 for ; Wed, 16 Jun 2021 21:05:05 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) (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 4G4yPY3Ykzz3Qvm; Wed, 16 Jun 2021 21:05:05 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mail-qk1-x72f.google.com with SMTP id c9so1008328qkm.0; Wed, 16 Jun 2021 14:05:05 -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=FzoOWdLUAYDVZsuvT6QXBPmUesvtGXHvn8FSxM99bDM=; b=mtut4HKw/y7jZpx/ZO32ewLQe83Sv3punrikPL/CUOtAcRHFhf2orcUKXJ45izwENH 4vfAubPbwvnEv+Pkj9sFJkjdDE6fvfaHeNaYHm+LaN/yGaU+fZQgTI2ZJTZHe7v9tpgz MQr2v5Q37IdmUcTde56tE68xa1hYv7rbbQ5xtOlxvZ0ta0kNoti6rMv8Gi95uvFrD5gF G4DOjyxmEn4sj8aQKPpy08PWrVHeKXpPI4BdE7SLZiHmIsbiTcfWCBz0npYGNzFiy8x/ qUKCp8kBGjQIkmLGyoD2cRCp5GgNNXfFDcEf3KToeAI1djgmWThOSbKkdIGzM4s1E0ff wpaA== 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=FzoOWdLUAYDVZsuvT6QXBPmUesvtGXHvn8FSxM99bDM=; b=Kh+OGH/Pfqj+KRHoJEB8sRwSkbM03eT+gJIgA2GotowYW2bFaBe8KDuG4SUR2kSYjj 2BK6TplWpKeCXz4yUyHFh0wLYmwGFjqnfxjorieJJMv+0GZ+lfrvRoB1GtnZyRhHd1Xr +DmMF44yoJrdVukAt9fHO0B6LM0vhW2djY9tbNjpcj/Am8vqypMxSqFgySuuF9y4LlbS r1eYYFd3SPtnOgJIvzkVHczfZSf4X+nxelAUie4r/KJrx9puewW7M4nEkWm5iNIJPK53 M8Bgw1dUXbu8LIBCyDl1fs1BJZ2eTtU0eW6E6BocwRdRdA1vHV5PllJRNmZyhTWVIXt+ G8WQ== X-Gm-Message-State: AOAM531dqFcPKyXCc0U29n7i4rPgrWw3vR1tmUhOhxryQ5zbVsjELB7z 4vxh/dqEO+LDvszhXoCa7DQD622xUSzv9A== X-Google-Smtp-Source: ABdhPJyvR6eDtZowTDTNfJeMk8ttcMrnFeaTMhsOG0LvAmZN1g3+WlkpMCyLOMS/RNd7UDopKBiS6g== X-Received: by 2002:a37:6851:: with SMTP id d78mr286776qkc.483.1623877504232; Wed, 16 Jun 2021 14:05:04 -0700 (PDT) Received: from nuc ([142.126.172.178]) by smtp.gmail.com with ESMTPSA id f11sm326159qka.55.2021.06.16.14.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 14:05:03 -0700 (PDT) Date: Wed, 16 Jun 2021 17:05:03 -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: 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: X-Rspamd-Queue-Id: 4G4yPY3Ykzz3Qvm X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N On Tue, Jun 15, 2021 at 08:36:07PM -0700, Neel Chauhan wrote: > Hi current@, > > First off, sorry if I spammed developers@ and other mailing lists with > my previous message, and to bz@/hselasky@/manu@ sent so many duplicate > emails. > > Right now, I am attempting to update the drm-kmod driver to the Linux > 5.7 code, and am having an issue with the pmap lock. I am new-ish to the > kernel, meaning not a whole lot of "experience", but do have patches in > src. > > But like it not we need kernel newbies, they're the next generation of > experts. If we don't, we'd be the next Minix with **zero** development > since Tanenbaum retired. > > Going back, the code in question is here: > https://github.com/neelchauhan/drm-kmod/blob/5.7-wip/drivers/gpu/drm/i915/gem/i915_gem_mman.c#L346 > > The lines important are 346-356, but lines of interest are also the > non-"#ifdef __linux__" sections of vm_fault_cpu(). > > The code gives this error: panic: Assertion > vm_object_busied((m->object)) failed at /usr/src/sys/vm/vm_page.c:5455 > > I have attached the core dump log. > > To those who aren't graphics driver experts, it happens when I load Xorg > when Xorg attempts to map the I/O to userspace. But I feel this is more > of me not using page locks correctly (which is needed for the pmap), or > maybe a linuxkpi issue, rather than a graphics-specific issue. > > I spent days on this (all my non-$DAYJOB hours at one point + all my > weekends) and haven't figured out the locks completely. Does anyone have > suggestions to what I'm doing wrong in my code and locks? > > If it is important, OpenBSD's version of this code is here: > https://github.com/openbsd/src/blob/2207c4325726fdc5c4bcd0011af0fdf7d3dab137/sys/dev/pci/drm/i915/gem/i915_gem_mman.c#L459 > (lines 459-523, but some calls are unsurprisingly different). > 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. 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.