From nobody Sat Jun 13 11:22:19 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E77A53128B2; Thu, 7 May 2026 23:33:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196799; cv=pass; b=KXR1g6t0HZ45wSfabMhiZMFmTAoZC3dBYH2+Ru2gmVIqTAXCXwCWx/Le8/B8nHyCIDb7HxrsoRjEEoOhvm8wm95DVOjC7ZGt9ng1MaY88ytV/esfCNL2LnUqwd6ggZdcFR+t90oByFE7RwXmogo7jbyFwjqQkZHCE3cLhVpVpEg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196799; c=relaxed/simple; bh=VM+IQ7Rou3qRlGMYo50nl9JASON5yKjR8Jf2rjqkHMM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oV33OzMn7Cj8u0Z+f0E0jfzS7/Wb2yEhv02x+0rCbj4CfLfUt7/hLnQ2gCRXt5t8x1YYgvTVHeb/iND4BZVrkbQ6W2IJUBBU+ZaZ7d/ZUklEvzDDi5OyAGYxsBlyu/FTIWbOvSOMYDwUUstfAx1j6a2+vmC3wN0kIMHu/xF4fos= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b=Mo9N+WCi; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b="Mo9N+WCi" ARC-Seal: i=1; a=rsa-sha256; t=1778196765; cv=none; d=zohomail.com; s=zohoarc; b=WvVL8phvZR0VPyplkOLu1nEXMtdUkgnEhpQPjC5spVZn/6nDERtv48C1rvhvyqlRd3+EzGt0KSbrWQpXxuso/SWzRAlFPpgkY/ZiNNnbbg//TJjSeBi6NLvaV7aYmMy+nqqrEqYmztEsQODGeVoxRm5MG9RydjCTh5hd5YMirAY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778196765; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=0UlbuoJOpWJO9LmwFxWlvdYkZE8HSkEeJJElxb5VGTI=; b=UV9nwN9GM94DEbqxsbxCaCZl74HAqDElQ+ehxtLRy7KEo4oqhKndGVsPQVfBL6PBSeMJZP/+VaPBSoO69mSSuMeX3b4TM7RJ8TOKkMj4IYmQY3jq1S5q2SI0jYi78FMQEmikDmAoX+rYzSYSKavlZJKjtgFkuVnMo84sQofUOsc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=deborah.brouwer@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1778196765; s=zohomail; d=collabora.com; i=deborah.brouwer@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=0UlbuoJOpWJO9LmwFxWlvdYkZE8HSkEeJJElxb5VGTI=; b=Mo9N+WCiIoOjoBPFky7Izz246sxFrA8lQrxNvNENPIUNntltUV4IgZD9mkbI+CWH nvNQE3y+KEB37MV9CARgm1O5ro/WquMFlIfpJ0xrW2AwsCbvd2DkljM/vf/tLpDxYXG HkLqN8KTmmsgYGOvZnGV441xRbgVpJfHaNgO7N+U= Received: by mx.zohomail.com with SMTPS id 1778196764054628.3617629136472; Thu, 7 May 2026 16:32:44 -0700 (PDT) From: Deborah Brouwer Date: Thu, 07 May 2026 16:32:39 -0700 Subject: [PATCH 1/7] mm: rust: add pgprot_noncached helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-tyr-mmap-v1-1-eec048a23c25@collabora.com> References: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> In-Reply-To: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> To: Alice Ryhl , Lorenzo Stoakes , "Liam R. Howlett" , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , David Airlie , Simona Vetter , Daniel Almeida Cc: linux-mm@kvack.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, boris.brezillon@collabora.com, beata.michalska@arm.com, lyude@redhat.com, acourbot@nvidia.com, work@onurozkan.dev, alvin.sun@linux.dev, Laura Nao , Deborah Brouwer X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1098; i=deborah.brouwer@collabora.com; h=from:subject:message-id; bh=+mpm0JxqkEncuLxmzYLQSpzrEq2zrX8fexEElroeW4A=; b=owGbwMvMwCVWuULzOU9c7WvG02pJDJl/FSW9vF/HnN1WZlhpk7f97HIBMxevOFbuL0JvXTe1H Dkbef94RykLgxgXg6yYIstZe6Me8ar3Rrrz/zfDzGFlAhnCwMUpABP55MLwz85R6pV83PpVbp0W T5vurtpksyJEVq6Be/EjTctmm9llQYwM6z1lFy3JOfMiPa/6VfSZLyc6pI32fr664IHvvpkOu2W r2AA= X-Developer-Key: i=deborah.brouwer@collabora.com; a=openpgp; fpr=CD3F328C177AEF322D9FFF8379A829E70C5E7DEB From: Daniel Almeida Expose pgprot_noncached() to Rust code through a small helper wrapper. Rust drivers that insert raw PFN mappings into userspace MMIO VMAs need to derive an appropriate non-cached pgprot before calling helpers such as vmf_insert_pfn_prot(). pgprot_noncached() is currently inaccessible from Rust because it is provided through C helpers/macros rather than a normal exported symbol. Add a Rust helper wrapper so Rust MMIO mmap paths can construct non-cached page protections for device mappings. Signed-off-by: Daniel Almeida Signed-off-by: Deborah Brouwer --- rust/helpers/mm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rust/helpers/mm.c b/rust/helpers/mm.c index b5540997bd20..22194d3196d2 100644 --- a/rust/helpers/mm.c +++ b/rust/helpers/mm.c @@ -48,3 +48,8 @@ __rust_helper void rust_helper_vma_end_read(struct vm_are= a_struct *vma) { vma_end_read(vma); } + +__rust_helper pgprot_t rust_helper_pgprot_noncached(pgprot_t prot) +{ + return pgprot_noncached(prot); +} --=20 2.53.0 From nobody Sat Jun 13 11:22:19 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 032AF344D95; Thu, 7 May 2026 23:33:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196812; cv=pass; b=ZhJM1NNidh6gxpwP8gyO6vNmiwXvJMhSmPGCjJvn3Dq4kk5hcxukO4COuHi36nXCJHxBE0KlYkfe/q54qMdSAMfETwFDc9+0yI6sp1YtvvnnUBthduCFs5F09hJRbgd8BI4GRm3bNp0Pl5BGPOQbnbhCZXFadrUFv5sTCgeqsJQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196812; c=relaxed/simple; bh=ryiwmubsMEvB81q0+2ze2r5daM4nZ4SezZ+kvrYnQcs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cqBcPUGDRa8FO/Z9zmlhw0maMp//sxSbGsGQb2Qc/uTNW2POaeUuDn10UceAEERcKClv3MlLXQsKMaE3om8ULBs3rcRwU1BCoTU+WnFiI8cP5L3epdxGSe9gKYniqPj0w/G0lDB/aWbkBLVNW04m8bVo3XdAOKRIyuZY4SRnQhw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b=AnYlSpPC; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b="AnYlSpPC" ARC-Seal: i=1; a=rsa-sha256; t=1778196767; cv=none; d=zohomail.com; s=zohoarc; b=Z14Bj7DC4eNrGghUKaej8B9EyEr6aJlt54767kgVsjfSY+v2GDWo9k8q6FsodFpj4l9iPm5qQSZVX85Im/soanzyiLO6kJFvp6eO+VogOyV1Texfns6ZL641RrP8cKAI+dawYBoTeUbPChH4LCSt+DQkPgyDwr38LXPMJLhvC14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778196767; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=2NLY72APnZcOWaicaOBiY0/NfOa0z6RzbN6RJkb//zI=; b=FPH9RnopzOOqgfTnfQDFSN4/2l7YcPTesrNrf1IeboROfmxihJYy2K7jvqm3l7bP7VZENSDv4qfWNB4ZZydkjMxmF5BIrnti+SJXTjSYfWppbS7AEpx6ipkoLjQ/x7Q3Uh3oygKhHGJ4u26vFnw7PJEACrNqYUFyGuwkunzWX7o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=deborah.brouwer@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1778196767; s=zohomail; d=collabora.com; i=deborah.brouwer@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=2NLY72APnZcOWaicaOBiY0/NfOa0z6RzbN6RJkb//zI=; b=AnYlSpPCYOmyvmVegZhccULOjc6A2OXwMe8xbCFeG38X/bF3Fqsg9Z+zs/a1YN1N NSFJP425GMy3csNmJRQWRhMwkpMZQ3mbCXX+CYg2LxAyoCBlD2LyL9QBbOgX22fqhhW ylHSREN/6DCqlyAqbkth3SlQD77kCVRf4yhGz+o4= Received: by mx.zohomail.com with SMTPS id 1778196765290540.1630003755475; Thu, 7 May 2026 16:32:45 -0700 (PDT) From: Deborah Brouwer Date: Thu, 07 May 2026 16:32:40 -0700 Subject: [PATCH 2/7] mm: rust: add VMA page offset helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-tyr-mmap-v1-2-eec048a23c25@collabora.com> References: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> In-Reply-To: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> To: Alice Ryhl , Lorenzo Stoakes , "Liam R. Howlett" , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , David Airlie , Simona Vetter , Daniel Almeida Cc: linux-mm@kvack.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, boris.brezillon@collabora.com, beata.michalska@arm.com, lyude@redhat.com, acourbot@nvidia.com, work@onurozkan.dev, alvin.sun@linux.dev, Laura Nao , Deborah Brouwer X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1487; i=deborah.brouwer@collabora.com; h=from:subject:message-id; bh=3UoXpSu7KF/dfK+s5Hc4A4XTkRi7kKOM3Xgjk6aPxIU=; b=owGbwMvMwCVWuULzOU9c7WvG02pJDJl/FSVdSlzlPubFRC68xhprNO/CTfev10TqDBInbAx60 H9OkiO9o5SFQYyLQVZMkeWsvVGPeNV7I935/5th5rAygQxh4OIUgImUVzD8FZp34dVrmzN7FnIl Sn4t2RFUFOJYHyPuGmgVquC370vJNYZ/moq8NZdWCZhl3TqZODlFv17+1YxLc3ZFbV9rlaV1/eI GBgA= X-Developer-Key: i=deborah.brouwer@collabora.com; a=openpgp; fpr=CD3F328C177AEF322D9FFF8379A829E70C5E7DEB From: Daniel Almeida Add VmaRef::pgoff() to expose vm_area_struct::vm_pgoff through the Rust VMA abstractions. vm_pgoff stores the mmap file offset in PAGE_SIZE units and can be used to distinguish different mmap regions and dispatch mmap or fault handling logic based on the requested offset. This matches the existing start()/end()/flags() helpers and avoids open-coded raw vm_area_struct access in Rust drivers. Signed-off-by: Daniel Almeida Signed-off-by: Deborah Brouwer --- rust/kernel/mm/virt.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rust/kernel/mm/virt.rs b/rust/kernel/mm/virt.rs index 63eb730b0b05..cb670e9d5fd9 100644 --- a/rust/kernel/mm/virt.rs +++ b/rust/kernel/mm/virt.rs @@ -92,6 +92,16 @@ pub fn end(&self) -> usize { unsafe { (*self.as_ptr()).__bindgen_anon_1.__bindgen_anon_1.vm_end= } } =20 + /// Returns the page offset of the virtual memory area. + /// + /// This is the offset in pages from the start of the file being mappe= d. + #[inline] + pub fn pgoff(&self) -> usize { + // SAFETY: By the type invariants, the caller holds at least the m= map read lock, so this + // access is not a data race. + unsafe { (*self.as_ptr()).vm_pgoff } + } + /// Zap pages in the given page range. /// /// This clears page table mappings for the range at the leaf level, l= eaving all other page --=20 2.53.0 From nobody Sat Jun 13 11:22:19 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0458831AA94; Thu, 7 May 2026 23:33:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196813; cv=pass; b=VDw7Ge4K8d8KIj9Wox3NMMIRbiFc+0fAKPlyMwH3VDWECWrvBoRLdJgBMaAnfM+woCclWyvbvGglvvI4uNPRCq+KnnbQpF6+u9BRcSMQXkV9Rfa3LxaWshtJjX3FGIV2I1ERxE5o+oImTLmeo0V8sEFV7+4tYCcxzR9qCA/UTG0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196813; c=relaxed/simple; bh=LS72whzBPfI8wJ5XGKSFg2YZwraPxlufzrfYFanpH6w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U7+ncpO5yF7KAygPwhZyq/f1D8lqUTR8e7VnbKRnnjE1Zd3I7H+mgzwL2LJmiZ9Cnc6GkL+jetz+R8HyBFehiMnIvr83Y11Pp9mOtBHAdvt7Tgbk20rClN5h8kRrzhXn5GoxqISQBoF0y3gQtSKm0i9BZuwW9Qt6adnAxFWUQ8w= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b=bLnOMmQF; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b="bLnOMmQF" ARC-Seal: i=1; a=rsa-sha256; t=1778196769; cv=none; d=zohomail.com; s=zohoarc; b=B0gKagO8Brbvh2dtH5CQYZF2oKOX1R9r00JZZXK0C/iTD1gP7WcdolnilHRz+nxsadSp3JLoGQ2mJUqSLAjTB3vgmwVNPU8Ld/3d5nBpZ/eEFCAWvZyTe64YmfahP4hF+5xh2T9wLE389CqEouzCmhabS/BLxzCsWyg2ByRc2iU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778196769; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=vTqw3jc94opHT2uoxPiQwEHdp0J+oq/GgnCRmE7vr4k=; b=Nw9RcZPiylbkyhrkkXx1dRyClrdga9qu4TyCwlawcXmmCnQRnVSK7f8bEM41UYcaVCcC7pz55Z68aHKix9vF0Z68bksprpkN2X/6f8JXXVTdusgU07FqwrphEhQvyNMTIP3NyiXev8Crl/XKkdkrCMlJaY49D4//sQSHLuoE3ng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=deborah.brouwer@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1778196769; s=zohomail; d=collabora.com; i=deborah.brouwer@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=vTqw3jc94opHT2uoxPiQwEHdp0J+oq/GgnCRmE7vr4k=; b=bLnOMmQF4ag3NVS7UO6/9eDpodF6H9woyCqEw7csrAXF8k9EjvauGMOcl61iA+5f xa79o6hQJ8k0sgn4VJl8ZQVugR1i1Wc8LjfnxQktMwz4bz9jQBb/70xOQJBbXAMLq46 QFuTH9PRyGEdrFOJAt2+gpZMLN3209lJxN0iy27w= Received: by mx.zohomail.com with SMTPS id 1778196766791583.476563743686; Thu, 7 May 2026 16:32:46 -0700 (PDT) From: Deborah Brouwer Date: Thu, 07 May 2026 16:32:41 -0700 Subject: [PATCH 3/7] drm/rust: add File::device() helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-tyr-mmap-v1-3-eec048a23c25@collabora.com> References: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> In-Reply-To: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> To: Alice Ryhl , Lorenzo Stoakes , "Liam R. Howlett" , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , David Airlie , Simona Vetter , Daniel Almeida Cc: linux-mm@kvack.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, boris.brezillon@collabora.com, beata.michalska@arm.com, lyude@redhat.com, acourbot@nvidia.com, work@onurozkan.dev, alvin.sun@linux.dev, Laura Nao , Deborah Brouwer X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1560; i=deborah.brouwer@collabora.com; h=from:subject:message-id; bh=LS72whzBPfI8wJ5XGKSFg2YZwraPxlufzrfYFanpH6w=; b=owGbwMvMwCVWuULzOU9c7WvG02pJDJl/FSXnnEoSj0v+Wfl/wVnruTPaf/gLX4m8/LJBe/f/a cYFOw6v6ShlYRDjYpAVU2Q5a2/UI1713kh3/v9mmDmsTCBDGLg4BWAitzwZGY6YKvGG9RQcXhii W3zB4vOz1xrsy18UJRiffv4+eadU+VlGhns2Zmv/hSrNiXAzEE1sdOJMLAlzOVi3hV1Gc975G0Y /+AE= X-Developer-Key: i=deborah.brouwer@collabora.com; a=openpgp; fpr=CD3F328C177AEF322D9FFF8379A829E70C5E7DEB Add a helper to retrieve the DRM device associated with an open `drm::file::File`. This wraps the common pattern of traversing `drm_file.minor->dev` and returning the corresponding `drm::Device`. This is useful for DRM file operation callbacks that need access to the owning DRM device from a `File` reference, avoiding repeated open-coded raw pointer traversal in drivers. Signed-off-by: Deborah Brouwer --- rust/kernel/drm/file.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rust/kernel/drm/file.rs b/rust/kernel/drm/file.rs index 10160601ce5a..5af28a9558e9 100644 --- a/rust/kernel/drm/file.rs +++ b/rust/kernel/drm/file.rs @@ -45,6 +45,18 @@ pub(super) fn as_raw(&self) -> *mut bindings::drm_file { self.0.get() } =20 + /// Returns the DRM device associated with this open file. + pub fn device(&self) -> &drm::Device { + // SAFETY: By the type invariant, `self.as_raw()` points to a vali= d open + // `struct drm_file`. DRM initializes `minor` for open DRM files, = and + // `minor->dev` points to the registered DRM device associated wit= h this + // file. + unsafe { + let minor =3D (*self.as_raw()).minor; + drm::Device::from_raw((*minor).dev) + } + } + fn driver_priv(&self) -> *mut T { // SAFETY: By the type invariants of `Self`, `self.as_raw()` is al= ways valid. unsafe { (*self.as_raw()).driver_priv }.cast() --=20 2.53.0 From nobody Sat Jun 13 11:22:19 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E71F36E478; Thu, 7 May 2026 23:33:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196801; cv=pass; b=DVzZP0l9SSjNC+CvnvXleEztjM8j3z/HPG163PXEsV3nSRrUmVT55OjBaNmOYOQakQe1Gb5r1lAh6P9X37LYRSGmDOpUkcIOzCqZJOqHLTISRNl7tO45ZYOSl05zkdAPkqu9m2/kwb1ExA8KBapPJGHP7IRXKyMhq5HofewOeqc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196801; c=relaxed/simple; bh=snKSqFTk/LCWniRtE2VzwTiY0L106zF+84qJmJfsNZI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TsI0ykR+XrJEglvKxyHkHAySjrOQlA6VPgstN+1nvfkQ9wZ/177aQxCe1rklHx0Lba+mrTOd0kaVwQP+qm1ncsaKB3eikhTELM81Piwkdd/F6iMqhQ8h4MWVPniP2hBFeVvSo/ENG5vE8xj/ZcR3o4k/oh5kISkNprqxR2Qqiys= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b=TXkUciE/; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b="TXkUciE/" ARC-Seal: i=1; a=rsa-sha256; t=1778196769; cv=none; d=zohomail.com; s=zohoarc; b=QBQGgnzSiXMZRek/wVE5S4DwcwZhlyUc607ZZuhr9U9a0Mr7rIYQeXY1TcBf+x+tIby3dX7O2LdnTZJmJpMIx9hvhGob9cIcNOlVESEy0ZoK74JTzsnpkUejKjeGl7XrA+uhrvVtxZLa4hopwDTVmJRtNHslI5cpAjm8w0Bc09g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778196769; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=oCMt4Wqtp340hUTxlyZxiVOiVlULGTbK7i1z5h8C21U=; b=Wbreo7nBgKEmHWiQADc9Wu+HdVBBGtfl6kBsl4W3fAYzWvNRdZZ8sfFH+qCk1S9wo696r9i6T5850UWf/J7gSf3x9yS58rcPq+4CwAmnJ6uns5XPfRY3D8t+K8ofdqWB3cCPNw/DLohouaOZGfnAkmAMSYnAKd1sPY2Q6Mo7vKc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=deborah.brouwer@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1778196769; s=zohomail; d=collabora.com; i=deborah.brouwer@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=oCMt4Wqtp340hUTxlyZxiVOiVlULGTbK7i1z5h8C21U=; b=TXkUciE/cJKYDXsmS5Oe9NPWvT9tdlEtg/c64LaikWuN8aDow1v4IXdLT9fQdiEG PZZ9qUbhMa6xj+/qu4r+/levKLwnmHM/r6VNmXcqPfNviynQWu8YS83xs0QLVs2Gkep 4bn1fri7SbgufExEbMGbbsCZW5DmeyxxFhmIA2Es= Received: by mx.zohomail.com with SMTPS id 1778196767897434.22785911951655; Thu, 7 May 2026 16:32:47 -0700 (PDT) From: Deborah Brouwer Date: Thu, 07 May 2026 16:32:42 -0700 Subject: [PATCH 4/7] drm/rust: allow drivers to override file operations Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-tyr-mmap-v1-4-eec048a23c25@collabora.com> References: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> In-Reply-To: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> To: Alice Ryhl , Lorenzo Stoakes , "Liam R. Howlett" , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , David Airlie , Simona Vetter , Daniel Almeida Cc: linux-mm@kvack.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, boris.brezillon@collabora.com, beata.michalska@arm.com, lyude@redhat.com, acourbot@nvidia.com, work@onurozkan.dev, alvin.sun@linux.dev, Laura Nao , Deborah Brouwer X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2654; i=deborah.brouwer@collabora.com; h=from:subject:message-id; bh=snKSqFTk/LCWniRtE2VzwTiY0L106zF+84qJmJfsNZI=; b=owGbwMvMwCVWuULzOU9c7WvG02pJDJl/FSUjbJZszlCUvRzy/8xh163PDNgnH5E02fXkyvXlv BKVqdN2dJSyMIhxMciKKbKctTfqEa96b6Q7/38zzBxWJpAhDFycAjCRCxsZGY5xTLm8847Lppvf eBsSLq9JuakwcQXDHp7HK0qL63Qu+p5g+B/tbXzSdzv/vxUSyu7uL7WWarULa5kyzM8vceRaOtv iFSsA X-Developer-Key: i=deborah.brouwer@collabora.com; a=openpgp; fpr=CD3F328C177AEF322D9FFF8379A829E70C5E7DEB Add a Driver::FOPS associated constant so Rust DRM drivers can override or extend the default file operations table. Use the driver's FOPS in drm::Device instead of always constructing the default GEM file operations internally. Also make drm::gem::create_fops() public so drivers can build on top of the default GEM handlers while overriding selected operations such as mmap. Signed-off-by: Deborah Brouwer --- rust/kernel/drm/device.rs | 4 ++-- rust/kernel/drm/driver.rs | 6 ++++++ rust/kernel/drm/gem/mod.rs | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs index adbafe8db54d..82760a9a426e 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -108,10 +108,10 @@ impl Device { driver_features: drm::driver::FEAT_GEM, ioctls: T::IOCTLS.as_ptr(), num_ioctls: T::IOCTLS.len() as i32, - fops: &Self::GEM_FOPS, + fops: &Self::FOPS, }; =20 - const GEM_FOPS: bindings::file_operations =3D drm::gem::create_fops(); + const FOPS: bindings::file_operations =3D T::FOPS; =20 /// Create a new `drm::Device` for a `drm::Driver`. pub fn new(dev: &device::Device, data: impl PinInit) -= > Result> { diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs index 5233bdebc9fc..79218c482fce 100644 --- a/rust/kernel/drm/driver.rs +++ b/rust/kernel/drm/driver.rs @@ -115,6 +115,12 @@ pub trait Driver { =20 /// IOCTL list. See `kernel::drm::ioctl::declare_drm_ioctls!{}`. const IOCTLS: &'static [drm::ioctl::DrmIoctlDescriptor]; + + /// File operations for this driver. + /// + /// Override to replace or extend the default GEM file operations. The= default + /// provides the standard GEM mmap handler via [`drm::gem::create_fops= `]. + const FOPS: bindings::file_operations =3D drm::gem::create_fops(); } =20 /// The registration type of a `drm::Device`. diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index 75acda7ba500..de7222ee0542 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -348,7 +348,8 @@ impl AllocImpl for Object { }; } =20 -pub(super) const fn create_fops() -> bindings::file_operations { +/// Returns the default GEM [`bindings::file_operations`] for a DRM driver. +pub const fn create_fops() -> bindings::file_operations { let mut fops: bindings::file_operations =3D pin_init::zeroed(); =20 fops.owner =3D core::ptr::null_mut(); --=20 2.53.0 From nobody Sat Jun 13 11:22:19 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78C412F8EA4; Thu, 7 May 2026 23:33:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196814; cv=pass; b=GcDpSzbtqwhFD+FNMsJIoajxFju8XqOJWBijaqozTqd4y/CVmUbxYQLZWOHxWniEXsmIIi2bYklsBwCWsTBfxLwS3wiuQD09jHm1po5BJWT2OzvUrtchZccbOQCUw90XXk5iMlOmSp0F5nmTi+fokOiwpei0xzTCxP64YadoGOY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196814; c=relaxed/simple; bh=scNdSVkRh8cTxN+OO32Yl1fQfHmpAP8i/Mt1ByfYJjw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Oh9vL5nXQGgkCdci2VSgX0b7eGxON6u0fNef9erz/PiH/H+Djg3ewu+KqnRjqWK3fkOGwZisrfMo8wgNqprypv6XCaNmG68HofZgrF+WaCIw5QKTjBmoDuRmmVOIIGyLLlSzjNOxZX4cejWz8Ifu7p02s+FgJzp1kSEcboFsvhw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b=SlTS1dl0; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b="SlTS1dl0" ARC-Seal: i=1; a=rsa-sha256; t=1778196771; cv=none; d=zohomail.com; s=zohoarc; b=HlwKowPEyLHd8XTqzn2Hra/vycEJm3d0epn4K8NOHKiAdnoMdKNvPSEF4IMj+dqpad7BeOxB3OSbfT4DEVgIoxNuw3C0e+VstWpMYiUzsEXPYuGiP1fWTxtX5FuUAVOomdNsynFuEJpjDZ+st2eBAoj6OY81SHMlV3Jkv0JuTN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778196771; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=Eikidck90nifjjcTLSu0Ily0Cr9WozMvVmtwFlS/XfE=; b=NgIiyDRryLQjjXpGsy8XWIGG4d+uW1DlhVYwmYDbJKhTKrAgsQK5S5aWvdXZvFW1H1H2CIRVB/G2NqGlm8YEJNTN6oT3KrppejwLt/TWVTPeNLQZPd5jYgTYKDs3eWlBtLFMqOKLF82N44R2XQbaxkxcfP7LcD5h9very+ljirs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=deborah.brouwer@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1778196771; s=zohomail; d=collabora.com; i=deborah.brouwer@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=Eikidck90nifjjcTLSu0Ily0Cr9WozMvVmtwFlS/XfE=; b=SlTS1dl05j3VDQXRC0dQlJ3v3q8pddW2B0URrmT4bZa72U0lsJs8szbTm/VVsEzW 0DkByIiOuO+a1Wlppa9N0KPx52vVVM1Ly0/gABMuBUcsOYjwGQUxJLyhNBCzrR3CkdA RC+RmBKx3W72DHZyHLVWG/OoS1jCYK3Zkg1IXk+s= Received: by mx.zohomail.com with SMTPS id 1778196769009768.4916995530741; Thu, 7 May 2026 16:32:49 -0700 (PDT) From: Deborah Brouwer Date: Thu, 07 May 2026 16:32:43 -0700 Subject: [PATCH 5/7] drm/tyr: add USER register page definitions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-tyr-mmap-v1-5-eec048a23c25@collabora.com> References: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> In-Reply-To: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> To: Alice Ryhl , Lorenzo Stoakes , "Liam R. Howlett" , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , David Airlie , Simona Vetter , Daniel Almeida Cc: linux-mm@kvack.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, boris.brezillon@collabora.com, beata.michalska@arm.com, lyude@redhat.com, acourbot@nvidia.com, work@onurozkan.dev, alvin.sun@linux.dev, Laura Nao , Deborah Brouwer X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1516; i=deborah.brouwer@collabora.com; h=from:subject:message-id; bh=scNdSVkRh8cTxN+OO32Yl1fQfHmpAP8i/Mt1ByfYJjw=; b=owGbwMvMwCVWuULzOU9c7WvG02pJDJl/FSXjfMxb9z/6d2NBs+UVUTklqaXL3uzsSPx0cdqc2 d3zXgat7yhlYRDjYpAVU2Q5a2/UI1713kh3/v9mmDmsTCBDGLg4BWAiE+cw/Pc/Eu/an8fzc0qY uNJVsc+TNx4SfG7Mtf8tn4y7dN1F+TJGhkYJfV1RjVkvr1lZvjkwSzUh0Hu7ueedcDEjs6gPX5l cmAE= X-Developer-Key: i=deborah.brouwer@collabora.com; a=openpgp; fpr=CD3F328C177AEF322D9FFF8379A829E70C5E7DEB Add the USER register page definition and the LATEST_FLUSH register used to track GPU cache flush completion. The USER register page is read-only and user-accessible. Tyr will use these definitions to support the Panthor userspace-MMIO mmap interface, which exposes the flush tracking register directly to userspace. Signed-off-by: Deborah Brouwer --- drivers/gpu/drm/tyr/regs.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/gpu/drm/tyr/regs.rs b/drivers/gpu/drm/tyr/regs.rs index 562023e5df2f..98d5625f5bb1 100644 --- a/drivers/gpu/drm/tyr/regs.rs +++ b/drivers/gpu/drm/tyr/regs.rs @@ -1633,6 +1633,24 @@ fn from(sh: PtwShareability) -> Self { } } =20 +/// This register corresponds to the USER register page. +/// +/// This register page is read-only and user-mode accessible. +/// It exposes cache flush tracking to userspace. +pub(crate) mod user { + use kernel::register; + + register! { + /// Latest flush ID register. Read-only. + pub(crate) LATEST_FLUSH(u32) @ 0x10000 { + /// Incremented when a full GPU cache clean-and-invalidate com= pletes. + 23:0 flush_id; + /// Indicates that a cache flush operation is currently pendin= g. + 31:31 active =3D> bool; + } + } +} + /// This module corresponds to the DOORBELL_BLOCK_n[0-63] register pages. pub(crate) mod doorbell_block { use kernel::register; --=20 2.53.0 From nobody Sat Jun 13 11:22:19 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E7A836E497; Thu, 7 May 2026 23:33:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196802; cv=pass; b=dS5U8uJltOqALFTi8JRYpfFYw7cBl693tIUHySjlelY4ZrQ5k8FeBKOX5W8rWgXt8j3ViXL96tUGMEuffKFLWP6+NrZeos0A1GBTlQcGmb2XzQu20zwj/wSByaitW8vkw8g5b6/3aEewpdwBjoy42+qEcO+iygoXIfjp0+77qV4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196802; c=relaxed/simple; bh=sq2B5J6Q8s2C6YbTn20oeUOAg0Lb4q68cApUEcd8JXg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nMubUJt9qEYDW2LsN2U4ndH1HaTGb6ppgoCHWAEDOhqLWfnCM0pVK1pwVfqRsYxsK5U0seQTzlTIo6vhrAx3xB/BzSYjI0sf3Wc4v/2wKq9CE/btIFJO+8S04ReFPk1hGPvVdRfKY2rZOyGzv2ceM2q9CBHUzXzKpawe0y+9UAk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b=GkgUSVib; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b="GkgUSVib" ARC-Seal: i=1; a=rsa-sha256; t=1778196771; cv=none; d=zohomail.com; s=zohoarc; b=FyCnaUAzfM4a/oh4N8AOggjrbsF2bUQSLb/CxAoRu1S+QAH6J1JJ9GYc5nfVcNtLNtAKGIlSnMD5iJmSG6b3WFRbSBhDsugClsggapEt54+wnwTVtoBObsMaPUmBhut4PIJcjIJyMWNkAKxHh0T7bOFvrfTRo7wPIdc9rBvMSzA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778196771; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=Yx8JvLQF2DtX5i8OpM+EnULSototWLG5JNcoDKWudLI=; b=OMOgAO7cVfPItTjB9xhEpHkzR1paHTtYyAa6QZ0pZhJJJvfqK7X1Y91TQNDs6XTU7NFMFiYfTqWOl71kc0wTN+TKMXfiKvHyI0zyyMIapkPrrVggwArPcDqFVIQXjQd+Pdp2c5RHFiglEmRGYvwbPO4pQufs4cxsbO2xLxkxwkM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=deborah.brouwer@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1778196771; s=zohomail; d=collabora.com; i=deborah.brouwer@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=Yx8JvLQF2DtX5i8OpM+EnULSototWLG5JNcoDKWudLI=; b=GkgUSVibMD711G/3qJz5u1jKCj67ghRtxDc6/G//cT4Lc1dWr+FJAvfZVpdN/xcC Y2TvMM1Gh56cEilNzDTW7jxq4twK7cFZJH1LPOmZf4Lm+CSjCS+AdTUbQylo934WhfI FHopmkuSWD/kpHo7Z/6Tn08v5ScdKYJPcnMxFLNQ= Received: by mx.zohomail.com with SMTPS id 1778196770005837.945580734471; Thu, 7 May 2026 16:32:50 -0700 (PDT) From: Deborah Brouwer Date: Thu, 07 May 2026 16:32:44 -0700 Subject: [PATCH 6/7] drm/tyr: store MMIO physical base address Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-tyr-mmap-v1-6-eec048a23c25@collabora.com> References: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> In-Reply-To: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> To: Alice Ryhl , Lorenzo Stoakes , "Liam R. Howlett" , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , David Airlie , Simona Vetter , Daniel Almeida Cc: linux-mm@kvack.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, boris.brezillon@collabora.com, beata.michalska@arm.com, lyude@redhat.com, acourbot@nvidia.com, work@onurozkan.dev, alvin.sun@linux.dev, Laura Nao , Deborah Brouwer X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1922; i=deborah.brouwer@collabora.com; h=from:subject:message-id; bh=sq2B5J6Q8s2C6YbTn20oeUOAg0Lb4q68cApUEcd8JXg=; b=owGbwMvMwCVWuULzOU9c7WvG02pJDJl/FSUvsz9WfGfwS5Jjx1Zmkz0/XLLjDbkc+TduP+ZuX m7UsulWRykLgxgXg6yYIstZe6Me8ar3Rrrz/zfDzGFlAhnCwMUpABNZ5MXIMC93xowtChndQWsN e+dY/FieVXkzatv+598ueVtq3/u4ZCrD/zAe/ySGIMPGyVksp+w6WLfffZu8LfwFz7amKXtLy3c vZQMA X-Developer-Key: i=deborah.brouwer@collabora.com; a=openpgp; fpr=CD3F328C177AEF322D9FFF8379A829E70C5E7DEB Store the physical base address of the GPU MMIO region in TyrDrmDeviceData. This will be used by the Panthor userspace-MMIO mmap path to derive the physical PFNs inserted into userspace VMAs for USER register page mappings. Co-developed-by: Daniel Almeida Signed-off-by: Daniel Almeida Signed-off-by: Deborah Brouwer --- drivers/gpu/drm/tyr/driver.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs index e20a5978eed6..2ba0a22a225b 100644 --- a/drivers/gpu/drm/tyr/driver.rs +++ b/drivers/gpu/drm/tyr/driver.rs @@ -19,7 +19,8 @@ drm::ioctl, io::{ poll, - Io, // + Io, + PhysAddr, // }, new_mutex, of, @@ -60,6 +61,9 @@ pub(crate) struct TyrPlatformDriverData { pub(crate) struct TyrDrmDeviceData { pub(crate) pdev: ARef, =20 + /// Physical base address of the MMIO region. + pub(crate) mmio_phys_addr: PhysAddr, + #[pin] clks: Mutex, =20 @@ -119,6 +123,7 @@ fn probe( let mali_regulator =3D Regulator::::get(pdev.a= s_ref(), c"mali")?; let sram_regulator =3D Regulator::::get(pdev.a= s_ref(), c"sram")?; =20 + let mmio_phys_addr =3D pdev.resource_by_index(0).ok_or(ENODEV)?.st= art(); let request =3D pdev.io_request_by_index(0).ok_or(ENODEV)?; let iomem =3D Arc::pin_init(request.iomap_sized::(), GFP_KE= RNEL)?; =20 @@ -140,6 +145,7 @@ fn probe( =20 let data =3D try_pin_init!(TyrDrmDeviceData { pdev: platform.clone(), + mmio_phys_addr, clks <- new_mutex!(Clocks { core: core_clk, stacks: stacks_clk, --=20 2.53.0 From nobody Sat Jun 13 11:22:19 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9221332907; Thu, 7 May 2026 23:33:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196804; cv=pass; b=VkrppUQLh1VonGU/jxXQmix6Umjzyz+b4wC6UiEhMtokD374wTTUKq5yc+jnjImK5qvGw9ryDrr3YIt3SWsXWfqmw79CNHVCIAxaGFPpnxrE71UL6xewL/E7roAwGO1YcxeTLvGnwU6x2HACjiH+L4lmUZXt3JC1hVCeHyrX4vE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778196804; c=relaxed/simple; bh=/jHhUub854UYefV++9aQ6NhPfxKrdfLhibAb8NJgRps=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A9YfcCtCPOto/udd+43Vnf4jZ84Q4pf+y3Z1FQciBH0Urk4sstrKo8T4K7RRjy6FbVH4xaEy7gWVS6HOQxVBerwO6vB9BALWzqDZnlpR5WZhEZuGjoQlHKbFWNvhkLtZdtJMkZldlb/6ZyyJy5N38VtoHqRQq71N+PEVRZShDr4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b=MnkldRWQ; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=deborah.brouwer@collabora.com header.b="MnkldRWQ" ARC-Seal: i=1; a=rsa-sha256; t=1778196773; cv=none; d=zohomail.com; s=zohoarc; b=bcgmC243E3hWK2Dpd6PuZBK6ZXfBsMRUenWP9KMXpxJyBf6b4yHAfxdzZJ1Q/uDRhZoWn7TYUOBxN+U7/f+qbUjR/JvLKmh+CKXnOxFLUyEuRlGdaecIq42Oov9HIz7G24gLQXb1ypX8dk4CO6qiFnOks9iPEl0u6CitelNi2Qg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1778196773; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=S/XdomGjzO6TaGgEy01tAz1U0X64Q5ShHRM2G3apMkc=; b=FMgOvvI2V3lbJtwaSZOifCFMwBtTWdSslOy0rPbyjaR3nH1gZUcFIiWCT+br53HVdKEXXJuAR+eJplaR5zcYz0i5P+1W9clZZlUnqPLjOFjihOcvi+F0nwFWey9/u9ipbteH83LiBQNF4Hwe7mNqy5SmXmphnOkAOlydpSfJ69Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=deborah.brouwer@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1778196773; s=zohomail; d=collabora.com; i=deborah.brouwer@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=S/XdomGjzO6TaGgEy01tAz1U0X64Q5ShHRM2G3apMkc=; b=MnkldRWQ2SaV5EmkYzb4hVTOhXEMmlahW5t1Rs4qNf3tYm3UHu6xsvyWhTRkbwJ3 p7Q+ddm5y71YyplBashEKAKx1MnCW2FObY2NhcDRuGpwWjOY80esMTYgKmBJT/HciiH q8AjFlC4GEj2MyTphHMbYVU0lrbHtkKrEhFsxlpQ= Received: by mx.zohomail.com with SMTPS id 1778196771052376.342991168034; Thu, 7 May 2026 16:32:51 -0700 (PDT) From: Deborah Brouwer Date: Thu, 07 May 2026 16:32:45 -0700 Subject: [PATCH 7/7] drm/tyr: add userspace MMIO mmap support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260507-tyr-mmap-v1-7-eec048a23c25@collabora.com> References: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> In-Reply-To: <20260507-tyr-mmap-v1-0-eec048a23c25@collabora.com> To: Alice Ryhl , Lorenzo Stoakes , "Liam R. Howlett" , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , David Airlie , Simona Vetter , Daniel Almeida Cc: linux-mm@kvack.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, boris.brezillon@collabora.com, beata.michalska@arm.com, lyude@redhat.com, acourbot@nvidia.com, work@onurozkan.dev, alvin.sun@linux.dev, Laura Nao , Deborah Brouwer X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=12374; i=deborah.brouwer@collabora.com; h=from:subject:message-id; bh=/jHhUub854UYefV++9aQ6NhPfxKrdfLhibAb8NJgRps=; b=owGbwMvMwCVWuULzOU9c7WvG02pJDJl/FSXnKxmL8peoZJ+xY+3RfLDz5fm6bQ372U6KBMm/P ygQbjG9o5SFQYyLQVZMkeWsvVGPeNV7I935/5th5rAygQxh4OIUgInwijD891jN7mx+wumRW+Xa ChuZLfOydPPkE2umeizTUrs342zGBYb/4QK8svdP1zJ6aFRyFPQsv1L8n68g84/fPX3lDXXxR5f zAQA= X-Developer-Key: i=deborah.brouwer@collabora.com; a=openpgp; fpr=CD3F328C177AEF322D9FFF8379A829E70C5E7DEB Add a Tyr-specific mmap handler for Panthor-style userspace MMIO mappings. Build Tyr's file operations from the default GEM fops and override only the mmap callback. The callback intercepts the reserved user MMIO mmap range and falls back to drm_gem_mmap() for normal GEM mappings. For now, support the USER_FLUSH_ID mapping. The mapping must be shared, read-only, non-executable, and exactly one page. Faults insert the page frame number (PFN) for the LATEST_FLUSH MMIO register with a non-cached page protection. Co-developed-by: Daniel Almeida Signed-off-by: Daniel Almeida Signed-off-by: Deborah Brouwer --- drivers/gpu/drm/tyr/driver.rs | 4 + drivers/gpu/drm/tyr/mmap.rs | 247 ++++++++++++++++++++++++++++++++++++++= ++++ drivers/gpu/drm/tyr/tyr.rs | 1 + 3 files changed, 252 insertions(+) diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs index 2ba0a22a225b..0d2965e3c9ad 100644 --- a/drivers/gpu/drm/tyr/driver.rs +++ b/drivers/gpu/drm/tyr/driver.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 or MIT =20 use kernel::{ + bindings, clk::{ Clk, OptionalClk, // @@ -42,6 +43,7 @@ gem::BoData, gpu, gpu::GpuInfo, + mmap::FOPS, regs::gpu_control::*, // }; =20 @@ -196,6 +198,8 @@ impl drm::Driver for TyrDrmDriver { kernel::declare_drm_ioctls! { (PANTHOR_DEV_QUERY, drm_panthor_dev_query, ioctl::RENDER_ALLOW, Ty= rDrmFileData::dev_query), } + + const FOPS: bindings::file_operations =3D FOPS; } =20 struct Clocks { diff --git a/drivers/gpu/drm/tyr/mmap.rs b/drivers/gpu/drm/tyr/mmap.rs new file mode 100644 index 000000000000..5698656faa8a --- /dev/null +++ b/drivers/gpu/drm/tyr/mmap.rs @@ -0,0 +1,247 @@ +// SPDX-License-Identifier: GPL-2.0 or MIT + +//! Memory-mapping support for the Tyr DRM driver. +//! +//! This module implements Tyr's DRM `mmap` file operation. Normal GEM buf= fer +//! mappings are handled by the standard DRM GEM mmap path +//! (`bindings::drm_gem_mmap`), while special Panthor userspace-MMIO mappi= ngs +//! are handled directly by Tyr. +//! +//! # Userspace MMIO mappings +//! +//! Panthor defines reserved DRM mmap offsets for exposing selected GPU MM= IO +//! pages directly to userspace. These are special uAPI marker offsets, not +//! hardware register offsets. +//! +//! Currently the only supported userspace-MMIO mapping is the flush-ID re= gister +//! page ([`DRM_PANTHOR_USER_FLUSH_ID_MMIO_OFFSET`]). This mapping exposes= a +//! read-only, non-cached MMIO page that userspace can poll to observe GPU= cache +//! flush completion without requiring a kernel round-trip. +//! +//! The VMA for this mapping is configured in [`mmap_user_mmio`]. Physical= MMIO +//! pages are inserted lazily through [`VM_OPS`] and [`vm_fault_handler`] = when +//! userspace first accesses the mapping. + +// TODO: When runtime PM support is added, userspace-MMIO mappings must be +// integrated with suspend/resume. Accessing this MMIO page while the regi= ster +// bank clock is disabled can hang the device. Runtime suspend will need t= o invalidate +// existing userspace-MMIO mappings, and mmap/fault handling while suspend= ed +// should expose a dummy zero page instead of the real MMIO PFN. + +use kernel::{ + bindings, + drm, + error::code::*, + io::register::Register, + mm::virt::{ + flags as vma_flags, + VmaNew, // + }, + page::{ + PAGE_SHIFT, + PAGE_SIZE, // + }, + prelude::*, // +}; + +use crate::{ + driver::TyrDrmDevice, + file::TyrDrmFileData, + regs::user::LATEST_FLUSH, // +}; + +// Reserved Panthor mmap offsets for userspace-MMIO mappings. +// +// These offsets are special uAPI marker values used to distinguish +// userspace-MMIO mappings from normal GEM object mappings in the DRM mmap +// path. They must match uapi/drm/panthor_drm.h exactly. +// +// These are not GPU register offsets or physical MMIO addresses. +// +// Tyr currently supports only the 64-bit Panthor mmap offsets. Panthor al= so +// defines 32-bit compat offsets, but that path is not implemented yet. +const DRM_PANTHOR_USER_MMIO_OFFSET_64BIT: u64 =3D 1u64 << 56; +const DRM_PANTHOR_USER_FLUSH_ID_MMIO_OFFSET: u64 =3D DRM_PANTHOR_USER_MMIO= _OFFSET_64BIT; + +// `vm_pgoff` stores mmap offsets in PAGE_SIZE units rather than byte offs= ets, +// so convert the Panthor uAPI mmap marker offsets into page offsets before +// comparing them against `vm_pgoff`. +const DRM_PANTHOR_USER_MMIO_PGOFF_64BIT: u64 =3D DRM_PANTHOR_USER_MMIO_OFF= SET_64BIT >> PAGE_SHIFT; +const DRM_PANTHOR_USER_FLUSH_ID_MMIO_PGOFF: u64 =3D + DRM_PANTHOR_USER_FLUSH_ID_MMIO_OFFSET >> PAGE_SHIFT; + +pub(crate) const FOPS: bindings::file_operations =3D { + let mut fops: bindings::file_operations =3D drm::gem::create_fops(); + fops.mmap =3D Some(mmap_callback); + fops +}; + +/// C-callable mmap file operation entry point for Tyr. +/// +/// Handles the special Panthor flush-ID mmap offset directly and falls ba= ck to +/// [`bindings::drm_gem_mmap`] for normal GEM object mappings. +/// +/// # Safety +/// +/// `filp` and `vma` must be valid pointers provided by the kernel mmap pa= th. +unsafe extern "C" fn mmap_callback( + filp: *mut bindings::file, + vma: *mut bindings::vm_area_struct, +) -> core::ffi::c_int { + // SAFETY: `filp` is a valid DRM file provided by the mmap callback. D= RM open + // initializes `filp->private_data` to point to the associated `struct= drm_file`, + // and the object remains valid until the file is released. + let drm_file_ptr =3D unsafe { (*filp).private_data.cast::() }; + if drm_file_ptr.is_null() { + return bindings::EINVAL as i32; + } + + // SAFETY: `drm_file_ptr` is a valid pointer to the DRM file associate= d with + // this open file descriptor, obtained from `filp->private_data`. + let drm_file =3D unsafe { drm::file::File::::from_raw(= drm_file_ptr) }; + + let device =3D drm_file.device(); + + // SAFETY: This is called from the DRM mmap file operation, so `vma` is + // undergoing initial setup for the duration of the callback. + let vma_new =3D unsafe { VmaNew::from_raw(vma) }; + + match mmap_user_mmio(device, vma_new) { + Some(Ok(())) =3D> 0, + Some(Err(e)) =3D> e.to_errno(), + // Fall back to the standard DRM GEM mmap path for non-userspace-M= MIO + // mappings. This matches the default GEM fops created by + // `drm::gem::create_fops()`, whose `.mmap` callback is + // `bindings::drm_gem_mmap`. + // + // SAFETY: Called from mmap context with valid `filp` and `vma`. + None =3D> unsafe { bindings::drm_gem_mmap(filp, vma) }, + } +} + +/// Handles Panthor userspace-MMIO mmap requests. +/// +/// If the VMA offset does not refer to the Panthor flush-ID mmap offset, = returns +/// [`None`] so the caller can fall back to the normal DRM GEM mmap path. +/// +/// If the offset refers to a userspace-MMIO mapping, validates the reques= ted +/// mapping parameters and configures the VMA for MMIO access. Returns +/// `Some(Err(...))` for invalid MMIO mappings and `Some(Ok(()))` on succe= ss. +fn mmap_user_mmio(device: &TyrDrmDevice, vma: &VmaNew) -> Option { + let pgoff =3D vma.pgoff() as u64; + if pgoff < DRM_PANTHOR_USER_MMIO_PGOFF_64BIT { + return None; + } + + if pgoff !=3D DRM_PANTHOR_USER_FLUSH_ID_MMIO_PGOFF { + return Some(Err(EINVAL)); + } + + if (vma.flags() & vma_flags::SHARED) =3D=3D 0 { + return Some(Err(EINVAL)); + } + + if vma.end() - vma.start() !=3D PAGE_SIZE { + return Some(Err(EINVAL)); + } + + if (vma.flags() & (vma_flags::WRITE | vma_flags::EXEC)) !=3D 0 { + return Some(Err(EINVAL)); + } + + if vma.try_clear_maywrite().is_err() { + return Some(Err(EINVAL)); + } + + vma.set_io(); + vma.set_dontcopy(); + vma.set_dontexpand(); + vma.set_dontdump(); + + let vma_ptr =3D vma.as_ptr(); + + // SAFETY: The VmaNew invariant guarantees the VMA pointer is valid an= d that the + // mapping is undergoing initial setup, so mutating VMA fields is safe. + // vm_private_data stores the DRM device pointer for the fault handler= ; the DRM + // device outlives the file and associated VMA. + unsafe { + // This VMA maps raw MMIO PFNs rather than normal memory pages. + (*vma_ptr).__bindgen_anon_2.vm_flags |=3D vma_flags::PFNMAP | vma_= flags::NORESERVE; + + // Store the device pointer so the fault handler can recover it la= ter. + (*vma_ptr).vm_private_data =3D core::ptr::from_ref(device).cast_mu= t().cast(); + + // Install the VMA operations for handling MMIO page faults. + (*vma_ptr).vm_ops =3D core::ptr::from_ref(&VM_OPS); + } + + Some(Ok(())) +} + +static VM_OPS: bindings::vm_operations_struct =3D bindings::vm_operations_= struct { + fault: Some(vm_fault_handler), + // SAFETY: Zero-initializing vm_operations_struct is valid because uns= et + // callback fields are represented as NULL function pointers. + ..unsafe { core::mem::zeroed() } +}; + +/// Page fault handler for userspace-MMIO VMAs. +/// +/// Used for lazy insertion of the MMIO page into the VMA on first access. +/// +/// Handles first access to the userspace-MMIO mapping by inserting the +/// corresponding physical MMIO page into the VMA with non-cached protecti= ons +/// via [`bindings::vmf_insert_pfn_prot`]. +/// +/// # Safety +/// +/// Must only be called by the kernel fault handling machinery with a valid +/// `vmf` pointer. +unsafe extern "C" fn vm_fault_handler(vmf: *mut bindings::vm_fault) -> bin= dings::vm_fault_t { + const VM_FAULT_SIGBUS: bindings::vm_fault_t =3D bindings::vm_fault_rea= son_VM_FAULT_SIGBUS; + + // SAFETY: `vmf` is a valid fault descriptor provided by the kernel fo= r this + // vm_ops.fault callback. Its embedded `vma` pointer and fault address= are + // initialized for the duration of the fault handling operation. + let (vma, address) =3D unsafe { ((*vmf).__bindgen_anon_1.vma, (*vmf)._= _bindgen_anon_1.address) }; + + // SAFETY: `vma` comes from a valid fault descriptor, and `vm_private_= data` + // was initialized by mmap_user_mmio() to store the associated Tyr DRM= device + // pointer for this VMA. + let ddev_ptr =3D unsafe { (*vma).vm_private_data as *const TyrDrmDevic= e }; + if ddev_ptr.is_null() { + return VM_FAULT_SIGBUS; + } + + // SAFETY: ddev_ptr is non-null, properly aligned, and was originally = a shared reference, + // so the pointee is valid for the lifetime of the device. + let ddev =3D unsafe { &*ddev_ptr }; + + // SAFETY: vma is valid (obtained from a valid vmf). + let pgoff =3D unsafe { (*vma).vm_pgoff } as u64; + + if pgoff !=3D DRM_PANTHOR_USER_FLUSH_ID_MMIO_PGOFF { + return VM_FAULT_SIGBUS; + } + + // `vm_start` and `vm_end` are behind bindgen-generated anonymous fiel= ds. + // SAFETY: vma is valid (obtained from a valid vmf). + let vm_start =3D unsafe { (*vma).__bindgen_anon_1.__bindgen_anon_1.vm_= start }; + // SAFETY: vma is valid (obtained from a valid vmf). + let vm_end =3D unsafe { (*vma).__bindgen_anon_1.__bindgen_anon_1.vm_en= d }; + + if address < vm_start || address >=3D vm_end { + return VM_FAULT_SIGBUS; + } + + let phys_addr =3D ddev.mmio_phys_addr + LATEST_FLUSH::OFFSET as u64; + let pfn =3D (phys_addr >> PAGE_SHIFT) as usize; + + // SAFETY: vma is valid (obtained from a valid vmf). + let pgprot =3D unsafe { bindings::pgprot_noncached((*vma).vm_page_prot= ) }; + + // SAFETY: vma, address, pfn, and pgprot are all valid. + let ret =3D unsafe { bindings::vmf_insert_pfn_prot(vma, address, pfn, = pgprot) }; + + ret as bindings::vm_fault_t +} diff --git a/drivers/gpu/drm/tyr/tyr.rs b/drivers/gpu/drm/tyr/tyr.rs index 9432ddd6b5b8..f1c7c46dfc3e 100644 --- a/drivers/gpu/drm/tyr/tyr.rs +++ b/drivers/gpu/drm/tyr/tyr.rs @@ -11,6 +11,7 @@ mod file; mod gem; mod gpu; +mod mmap; mod regs; =20 kernel::module_platform_driver! { --=20 2.53.0