From: Danilo Krummrich <dakr@kernel.org>
To: dakr@kernel.org, acourbot@nvidia.com
Cc: nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] gpu: nova-core: mm: move TLB register access behind the mutex
Date: Thu, 3 Dec 2026 22:50:03 +0100 [thread overview]
Message-ID: <20261203215019.2870117-2-dakr@kernel.org> (raw)
In-Reply-To: <20261203215019.2870117-1-dakr@kernel.org>
Store the BAR reference in the TLB mutex and use a with_bar_locked()
helper to serialize register access. This makes the locking requirement
more explicit (e.g. when adding operations such as fault replay and
cancellation).
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
drivers/gpu/nova-core/mm/tlb.rs | 70 ++++++++++++++++++---------------
1 file changed, 39 insertions(+), 31 deletions(-)
diff --git a/drivers/gpu/nova-core/mm/tlb.rs b/drivers/gpu/nova-core/mm/tlb.rs
index fff66dc03549..eb32b95623be 100644
--- a/drivers/gpu/nova-core/mm/tlb.rs
+++ b/drivers/gpu/nova-core/mm/tlb.rs
@@ -64,57 +64,65 @@ pub(crate) enum TlbAckMode with TryFrom<Bounded<u32, 2>> {
/// TLB manager for GPU translation buffer operations.
#[pin_data]
-pub(crate) struct Tlb<'gpu> {
- bar: Bar0<'gpu>,
+pub(crate) struct Tlb<'tlb>
+where
+ // Hide the mutex's invariant resource lifetime so `Tlb` remains covariant.
+ exists<'res>: 'tlb,
+{
/// TLB flush serialization lock.
///
/// Do not hold this lock across reclaimable memory allocations; see the
/// [MM locking rules](crate::mm#locking).
#[pin]
- lock: Mutex<()>,
+ #[uses('res: invariant)]
+ bar: Mutex<Bar0<'res>>,
}
-impl<'gpu> Tlb<'gpu> {
+impl<'tlb> Tlb<'tlb> {
/// Create a new TLB manager.
- pub(super) fn new(bar: Bar0<'gpu>) -> impl PinInit<Self> {
+ pub(super) fn new(bar: Bar0<'tlb>) -> impl PinInit<Self> {
pin_init!(Self {
- bar,
- lock <- new_mutex!((), "tlb_flush"),
+ bar <- new_mutex!(bar, "tlb_flush"),
})
}
+ /// Runs `f` with the TLB locked.
+ fn with_bar_locked<R>(&self, f: impl FnOnce(Bar0<'_>) -> R) -> R {
+ self.with_bar(|bar| f(*bar.lock()))
+ }
+
/// Flush the GPU TLB for a specific page directory base.
///
/// This invalidates all TLB entries associated with the given PDB address.
/// Must be called after modifying page table entries to ensure the GPU sees
/// the updated mappings.
pub(super) fn flush(&self, pdb_addr: VramAddress) -> Result {
- let _guard = self.lock.lock();
+ self.with_bar_locked(|bar| {
+ // Write PDB address.
+ bar.write_reg(regs::NV_TLB_FLUSH_PDB_LO::from_pdb_addr(
+ pdb_addr.into_raw(),
+ ));
+ bar.write_reg(regs::NV_TLB_FLUSH_PDB_HI::from_pdb_addr(
+ pdb_addr.into_raw(),
+ ));
- // Write PDB address.
- self.bar.write_reg(regs::NV_TLB_FLUSH_PDB_LO::from_pdb_addr(
- pdb_addr.into_raw(),
- ));
- self.bar.write_reg(regs::NV_TLB_FLUSH_PDB_HI::from_pdb_addr(
- pdb_addr.into_raw(),
- ));
+ // Trigger flush.
+ bar.write_reg(
+ regs::NV_TLB_FLUSH_CTRL::zeroed()
+ .with_all_va(true)
+ .with_ack(TlbAckMode::None)
+ .with_trigger(true),
+ );
- // Trigger flush.
- self.bar.write_reg(
- regs::NV_TLB_FLUSH_CTRL::zeroed()
- .with_all_va(true)
- .with_ack(TlbAckMode::None)
- .with_trigger(true),
- );
+ // Poll for completion.
+ read_poll_timeout(
+ || Ok(bar.read(regs::NV_TLB_FLUSH_CTRL)),
+ |ctrl: ®s::NV_TLB_FLUSH_CTRL| !ctrl.trigger(),
+ Delta::ZERO,
+ Delta::from_secs(2),
+ )?;
- // Poll for completion.
- read_poll_timeout(
- || Ok(self.bar.read(regs::NV_TLB_FLUSH_CTRL)),
- |ctrl: ®s::NV_TLB_FLUSH_CTRL| !ctrl.trigger(),
- Delta::ZERO,
- Delta::from_secs(2),
- )?;
-
- Ok(())
+ Ok(())
+ })
}
}
--
2.56.1
next prev parent reply other threads:[~2026-12-03 21:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 21:50 [PATCH 1/2] gpu: nova-core: mm: document fence signalling lock dependencies Danilo Krummrich
2026-12-03 21:50 ` Danilo Krummrich [this message]
2026-12-03 22:13 ` [PATCH 2/2] gpu: nova-core: mm: move TLB register access behind the mutex Gary Guo
2026-12-03 22:13 ` [PATCH 1/2] gpu: nova-core: mm: document fence signalling lock dependencies Gary Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203215019.2870117-2-dakr@kernel.org \
--to=dakr@kernel.org \
--cc=acourbot@nvidia.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nova-gpu@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®