From: Alistair Popple <apopple@nvidia.com>
To: Zhi Wang <zhiw@nvidia.com>
Cc: dakr@kernel.org, acourbot@nvidia.com, alex@shazbot.org,
jgg@nvidia.com, yishaih@nvidia.com, skolothumtho@nvidia.com,
kevin.tian@intel.com, airlied@gmail.com, simona@ffwll.ch,
ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com,
gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu,
jhubbard@nvidia.com, ecourtney@nvidia.com, cjia@nvidia.com,
smitra@nvidia.com, kjaju@nvidia.com, alkumar@nvidia.com,
ankita@nvidia.com, aniketa@nvidia.com, kwankhede@nvidia.com,
targupta@nvidia.com, nova-gpu@lists.linux.dev,
linux-kernel@vger.kernel.org, zhiwang@kernel.org
Subject: Re: [PATCH 02/13] gpu: nova-core: mm: add VramBlock and Bar1Map
Date: Fri, 11 Sep 2026 15:01:29 +1000 [thread overview]
Message-ID: <aqOE4FJ6eq1qu_kQ@nvdebian.thelocal> (raw)
In-Reply-To: <20260905081116.106613-3-zhiw@nvidia.com>
On 2026-09-05 at 18:11 +1000, Zhi Wang <zhiw@nvidia.com> wrote...
> GPU page table setup and VRAM-backed control structures require the
> driver to allocate physical VRAM and map it into the BAR1 aperture for
> CPU access. These operations are common to both the base driver and
> vGPU paths.
>
> VramBlock owns a buddy allocator allocation. Shared VramRegion views
> keep that allocation alive while callers select byte ranges within a
> larger preallocated block. Bar1Map retains one such region while mapping
> the containing pages and bounds all CPU accesses to the requested view.
> The mapping must be explicitly destroyed to release GPU VA resources and
> invalidate PTEs.
>
> Keep BarUser inline in Gpu and let short-lived BarUserAccess objects
> borrow it. Bar1Map owns its mapped VA range and borrows the driver-owned
> BAR1 mapping; explicit destruction returns the VA through BarUser and
> GpuMm. Its MMIO accessors remain runtime checked because BAR1 and the
> logical mapping have runtime sizes.
This patch seems to be doing three different things that build on top of each
other, so it would be a bit easier to review if it was split up into three
patches. One patch adding the VRAM allocator, one dealing with the shared
VramRegion views and another to do the actual BAR1 mappings.
> Signed-off-by: Zhi Wang <zhiw@nvidia.com>
> ---
> drivers/gpu/nova-core/gpu.rs | 20 ++-
> drivers/gpu/nova-core/mm.rs | 6 +-
> drivers/gpu/nova-core/mm/bar_user.rs | 143 ++++++++++++++++++--
> drivers/gpu/nova-core/mm/vram.rs | 187 +++++++++++++++++++++++++++
> 4 files changed, 329 insertions(+), 27 deletions(-)
> create mode 100644 drivers/gpu/nova-core/mm/vram.rs
[...]
> +/// Allocate an exact VRAM range relative to a usable region's buddy base.
> +pub(crate) fn alloc_vram_range(
> + mm: &GpuMm<'_>,
Given this operates on GpuMm I think it might be better if this was a method
implemented on GpuMm.
> + range: Range<u64>,
> + align: u64,
> +) -> Result<Arc<VramBlock>> {
> + let page_size = u64::try_from(PAGE_SIZE).map_err(|_| EOVERFLOW)?;
> + let size = range
> + .end
> + .checked_sub(range.start)
> + .filter(|size| *size != 0)
> + .ok_or(EINVAL)?;
> + if !range.start.is_multiple_of(page_size) || !size.is_multiple_of(page_size) {
> + return Err(EINVAL);
> + }
I think these should already be checked in gpu_buddy_alloc_blocks() so no need
to repeat the same checks here.
> +
> + let align = align.max(page_size);
> + let align_usize = usize::try_from(align).map_err(|_| EOVERFLOW)?;
> + let min_block_size = Alignment::new_checked(align_usize).ok_or(EINVAL)?;
> + let buddy = mm.buddy();
> + if range.end > buddy.size() {
> + return Err(ENOSPC);
> + }
Ditto.
> + let blocks = KBox::pin_init(
> + buddy.alloc_blocks(
> + GpuBuddyAllocMode::Range(range.clone()),
> + size,
> + min_block_size,
> + GpuBuddyAllocFlags::default(),
> + ),
> + GFP_KERNEL,
> + )?;
> +
> + let mut address = None;
> + let mut allocation_end = None;
> + let mut covered = 0u64;
> + for block in blocks.as_ref().iter() {
> + let block_address = block.offset();
> + let block_size = block.size();
> + let block_end = block_address.checked_add(block_size).ok_or(EOVERFLOW)?;
> + address = Some(address.map_or(block_address, |start: u64| start.min(block_address)));
> + allocation_end = Some(allocation_end.map_or(block_end, |end: u64| end.max(block_end)));
> + covered = covered.checked_add(block_size).ok_or(EOVERFLOW)?;
> + }
> +
> + let address = address.ok_or(ENOMEM)?;
> + let allocation_end = allocation_end.ok_or(ENOMEM)?;
> + let expected_address = buddy
> + .base_offset()
> + .checked_add(range.start)
> + .ok_or(EOVERFLOW)?;
> + if address != expected_address
> + || covered != size
> + || allocation_end.checked_sub(address).ok_or(EIO)? != size
> + || !address.is_multiple_of(align)
> + {
> + return Err(EIO);
> + }
What is the purpose of these checks? Do we ever expect to hit any of these
errors?
Thanks.
> + Ok(Arc::new(
> + VramBlock {
> + _blocks: blocks,
> + address,
> + size,
> + },
> + GFP_KERNEL,
> + )?)
> +}
> --
> 2.53.0
>
next prev parent reply other threads:[~2026-09-11 5:01 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 8:11 [PATCH 00/13] Introduce NVIDIA vGPU manager and VFIO variant driver Zhi Wang
2026-09-05 8:11 ` [PATCH 01/13] gpu: nova-core: vgpu: add post-GSP-boot vGPU initialization Zhi Wang
2026-09-11 6:51 ` Alexandre Courbot
2026-09-05 8:11 ` [PATCH 02/13] gpu: nova-core: mm: add VramBlock and Bar1Map Zhi Wang
2026-09-11 5:01 ` Alistair Popple [this message]
2026-09-05 8:11 ` [PATCH 03/13] gpu: nova-core: vgpu: add VRAM slot allocator Zhi Wang
2026-09-05 8:11 ` [PATCH 04/13] gpu: nova-core: vgpu: add r000 plugin bindings Zhi Wang
2026-09-05 8:11 ` [PATCH 05/13] gpu: nova-core: vgpu: add instance create/destroy Zhi Wang
2026-09-05 8:11 ` [PATCH 06/13] gpu: nova-core: gsp: add GMC transaction helpers Zhi Wang
2026-09-05 8:11 ` [PATCH 07/13] gpu: nova-core: vgpu: add vGPU bootload Zhi Wang
2026-09-05 8:11 ` [PATCH 08/13] gpu: nova-core: vgpu: implement PluginRpc channel and config params Zhi Wang
2026-09-05 8:11 ` [PATCH 09/13] gpu: nova-core: vgpu: scrub guest framebuffer memory with CeUtils Zhi Wang
2026-09-05 8:11 ` [PATCH 10/13] gpu: nova-core: vgpu: export plugin log buffers via debugfs Zhi Wang
2026-09-05 8:11 ` [PATCH 11/13] gpu: nova-core: vgpu: export lifecycle operations to VFIO Zhi Wang
2026-09-05 8:11 ` [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver Zhi Wang
2026-09-09 3:00 ` Alex Williamson
2026-09-11 20:39 ` Danilo Krummrich
2026-09-05 8:11 ` [PATCH 13/13] gpu: nova-core: reserve the 48-VM WPR2 heap Zhi Wang
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=aqOE4FJ6eq1qu_kQ@nvdebian.thelocal \
--to=apopple@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=alex@shazbot.org \
--cc=aliceryhl@google.com \
--cc=alkumar@nvidia.com \
--cc=aniketa@nvidia.com \
--cc=ankita@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=cjia@nvidia.com \
--cc=dakr@kernel.org \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=kevin.tian@intel.com \
--cc=kjaju@nvidia.com \
--cc=kwankhede@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=simona@ffwll.ch \
--cc=skolothumtho@nvidia.com \
--cc=smitra@nvidia.com \
--cc=targupta@nvidia.com \
--cc=tmgross@umich.edu \
--cc=yishaih@nvidia.com \
--cc=zhiw@nvidia.com \
--cc=zhiwang@kernel.org \
/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®