All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Danilo Krummrich" <dakr@kernel.org>
Cc: <aliceryhl@google.com>, <airlied@gmail.com>, <simona@ffwll.ch>,
	<lossin@kernel.org>, <gary@garyguo.net>, <ecourtney@nvidia.com>,
	<jhubbard@nvidia.com>, <nova-gpu@lists.linux.dev>,
	<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/4] gpu: nova-core: mm: serialize PRAMIN access
Date: Sat, 28 Nov 2026 11:01:44 +0900	[thread overview]
Message-ID: <DN6H2GAT9F0Y.2ZZRVU8FZCYZB@nvidia.com> (raw)
In-Reply-To: <20261126213652.3716162-2-dakr@kernel.org>

On Fri Nov 27, 2026 at 6:36 AM JST, Danilo Krummrich wrote:
> PRAMIN window selection and access must be serialized so that the window
> cannot move while it is in use. Give PRAMIN its own synchronization,
> independent of its GpuMm container, so sharing the memory manager does
> not require serializing unrelated VRAM allocation and TLB operations.
>
> Keep the lock across page table walks and update batches to avoid
> acquiring it separately for every entry.
>
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> ---
>  drivers/gpu/nova-core/mm.rs                | 21 ++++++++----
>  drivers/gpu/nova-core/mm/bar_user.rs       | 39 ++++++++++++++--------
>  drivers/gpu/nova-core/mm/pagetable/map.rs  | 34 +++++++++----------
>  drivers/gpu/nova-core/mm/pagetable/walk.rs |  2 +-
>  drivers/gpu/nova-core/mm/pramin.rs         | 34 +++++++++++++++++++
>  5 files changed, 91 insertions(+), 39 deletions(-)
>
> diff --git a/drivers/gpu/nova-core/mm.rs b/drivers/gpu/nova-core/mm.rs
> index f53886f9ed91..bbe23dc6351f 100644
> --- a/drivers/gpu/nova-core/mm.rs
> +++ b/drivers/gpu/nova-core/mm.rs
> @@ -72,11 +72,11 @@ macro_rules! impl_pfn_bounded {
>  ///
>  /// Provides centralized ownership of memory management resources:
>  /// - [`GpuBuddy`] allocator for VRAM page table allocation.
> -/// - [`pramin::Pramin`] for direct VRAM access.
> +/// - [`pramin::SharedPramin`] for direct VRAM access.
>  /// - [`Tlb`] manager for translation buffer flush operations.
>  pub(crate) struct GpuMm<'gpu> {
>      buddy: GpuBuddy,
> -    pramin: pramin::Pramin<'gpu>,
> +    pramin: Pin<KBox<pramin::SharedPramin<'gpu>>>,

Nice, this is probably going to remove the `SharedGpuMm` I introduced
(and hated) in the vGPU series. :)

A couple of comments below.

<...>
> index f7774b9cc972..ba23cd3c2b25 100644
> --- a/drivers/gpu/nova-core/mm/pagetable/map.rs
> +++ b/drivers/gpu/nova-core/mm/pagetable/map.rs
> @@ -96,12 +96,13 @@ fn alloc_and_zero_page(mm: &mut GpuMm<'_>, level: PageTableLevel) -> Result<Prep
>          let page_vram = VramAddress::from_raw(blocks.iter().next().ok_or(ENOMEM)?.offset());
>  
>          // Zero via PRAMIN.
> -        let window = mm
> -            .pramin_mut()
> -            .window_at::<[u64; PAGE_SIZE / 8]>(page_vram)?;
> -        for i in 0..PAGE_SIZE / 8 {
> -            io_write!(window.view(), [build: i], 0);
> -        }
> +        mm.with_pramin_locked(|pramin| -> Result {
> +            let window = pramin.window_at::<[u64; PAGE_SIZE / 8]>(page_vram)?;
> +            for i in 0..PAGE_SIZE / 8 {
> +                io_write!(window.view(), [build: i], 0);
> +            }
> +            Ok(())
> +        })?;
>  
>          Ok(PreparedPtPage {
>              alloc: blocks,
> @@ -121,16 +122,16 @@ fn ensure_single_pte_path(
>          let max_iter = 2 * M::PDE_LEVELS.len();
>  
>          for _ in 0..max_iter {
> -            let result = self
> -                .walker
> -                .walk_pde_levels(mm.pramin_mut(), vfn, |install_addr| {
> +            let result = mm.with_pramin_locked(|pramin| {

nit: With this the method-level doccomment should be about the PRAMIN
lock being released instead of the borrow.

<...>
> diff --git a/drivers/gpu/nova-core/mm/pramin.rs b/drivers/gpu/nova-core/mm/pramin.rs
> index c83b1681d241..841289d7bccc 100644
> --- a/drivers/gpu/nova-core/mm/pramin.rs
> +++ b/drivers/gpu/nova-core/mm/pramin.rs
> @@ -13,6 +13,7 @@
>          Io,
>          Mmio, //
>      },
> +    new_mutex,
>      prelude::*,
>      ptr::{
>          Alignable,
> @@ -22,6 +23,7 @@
>          SizeConstants,
>          SZ_1M, //
>      },
> +    sync::Mutex, //
>  };
>  
>  use crate::{
> @@ -54,6 +56,38 @@
>      PRAMIN: PraminWindow @ 0x700000;
>  }
>  
> +/// A [`Pramin`] shared between users, serialized by a mutex.
> +#[pin_data]
> +pub(super) struct SharedPramin<'gpu>
> +where
> +    // Hide the mutex's invariant resource lifetime so `SharedPramin` remains covariant.
> +    exists<'res>: 'gpu,
> +{
> +    #[pin]
> +    #[uses('res: invariant)]
> +    inner: Mutex<Pramin<'res>>,
> +}
> +
> +impl<'gpu> SharedPramin<'gpu> {
> +    /// Creates the shared window manager for the given VRAM region.
> +    pub(super) fn new(
> +        bar: Bar0<'gpu>,
> +        chipset: Chipset,
> +        vram_range: Range<VramAddress>,
> +    ) -> impl PinInit<Self, Error> {
> +        try_pin_init!(Self {
> +            inner <- new_mutex!(Pramin::new(bar, chipset, vram_range)?, "pramin"),
> +        })
> +    }
> +
> +    /// Runs `f` with exclusive access to the PRAMIN window.
> +    ///
> +    /// Do not perform reclaimable allocations in `f`.

A little elaboration on why (deadlocks in the fence signaling path)
would be nice here. Something similar to what Tlb::lock has maybe, and
maybe we should also put that information into some module-level
paragraph that we can refer to instead of repeating it as it is relevant
in several places.

  reply	other threads:[~2026-11-28  2:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 21:36 [PATCH 0/4] gpu: nova-core: prepare GpuMm for shared access Danilo Krummrich
2026-11-26 21:36 ` [PATCH 1/4] gpu: nova-core: mm: serialize PRAMIN access Danilo Krummrich
2026-11-28  2:01   ` Alexandre Courbot [this message]
2026-11-26 21:36 ` [PATCH 2/4] gpu: nova-core: mm: use shared references to GpuMm Danilo Krummrich
2026-11-26 21:36 ` [PATCH 3/4] gpu: nova-core: mm: initialize GpuMm in place Danilo Krummrich
2026-11-26 21:36 ` [PATCH 4/4] gpu: nova-core: mm: remove SharedPramin Danilo Krummrich
2026-11-28  2:04 ` [PATCH 0/4] gpu: nova-core: prepare GpuMm for shared access Alexandre Courbot
2026-12-01 19:19 ` Danilo Krummrich

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=DN6H2GAT9F0Y.2ZZRVU8FZCYZB@nvidia.com \
    --to=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nova-gpu@lists.linux.dev \
    --cc=simona@ffwll.ch \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.