From: "Danilo Krummrich" <dakr@kernel.org>
To: "Alok Kumar" <alkumar@nvidia.com>
Cc: <acourbot@nvidia.com>, <kvm@vger.kernel.org>,
<rust-for-linux@vger.kernel.org>, <nova-gpu@lists.linux.dev>,
<linux-pci@vger.kernel.org>, <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>, <markus.probst@posteo.de>,
<jhubbard@nvidia.com>, <apopple@nvidia.com>,
<joelagnelf@nvidia.com>, <ecourtney@nvidia.com>,
<cjia@nvidia.com>, <smitra@nvidia.com>, <kjaju@nvidia.com>,
<ankita@nvidia.com>, <aniketa@nvidia.com>, <kwankhede@nvidia.com>,
<targupta@nvidia.com>, <linux-kernel@vger.kernel.org>,
<zhiwang@kernel.org>, <zhiw@nvidia.com>, <boqun@kernel.org>,
<daniel.almeida@collabora.com>, <tamird@kernel.org>,
<work@onurozkan.dev>, <jgg@ziepe.ca>, <bhelgaas@google.com>,
<kwilczynski@kernel.org>, <dri-devel@lists.freedesktop.org>,
<peter@colberg.org>, <xinmengs@nvidia.com>
Subject: Re: [PATCH v5 12/35] gpu: nova-core: mm: add VramBlock
Date: Thu, 26 Nov 2026 23:12:47 +0100 [thread overview]
Message-ID: <DN5HKLQK65L0.1L9NVW750P85W@kernel.org> (raw)
In-Reply-To: <20261124135937.18583-13-alkumar@nvidia.com>
On Tue Nov 24, 2026 at 2:59 PM CET, Alok Kumar wrote:
> +/// A physically contiguous VRAM allocation.
> +///
> +/// # Invariants
> +///
> +/// `range.start <= range.end`.
> +pub(crate) struct VramBlock {
> + _blocks: Pin<KBox<AllocatedBlocks>>,
> + range: Range<u64>,
> +}
This allocation seems unnecessary, VramBlock can itself be constructed as pin
initializer...
> +
> +impl VramBlock {
> + /// Returns the range covered by this VRAM block.
> + pub(crate) const fn range(&self) -> &Range<u64> {
> + &self.range
> + }
> +}
> +
> +impl GpuMm<'_> {
> + /// Allocates an exact byte range relative to the buddy allocator's base.
> + pub(crate) fn alloc_vram_range(
> + &self,
> + range: Range<u64>,
> + align: Alignment,
> + ) -> Result<Arc<VramBlock>> {
> + const PAGE_SIZE_ALIGN: Alignment = Alignment::new::<PAGE_SIZE>();
> +
> + let align = if align > PAGE_SIZE_ALIGN {
> + align
> + } else {
> + PAGE_SIZE_ALIGN
> + };
> + let size = range.end.checked_sub(range.start).ok_or(EINVAL)?;
> + let buddy = self.buddy();
> + let base = buddy.base_offset();
> + let start = base.checked_add(range.start).ok_or(EOVERFLOW)?;
> + let end = base.checked_add(range.end).ok_or(EOVERFLOW)?;
> + if !start.is_multiple_of(u64::from_safe_cast(align.as_usize())) {
> + return Err(EINVAL);
> + }
> +
> + let blocks = KBox::pin_init(
> + buddy.alloc_blocks(
> + GpuBuddyAllocMode::Range(range),
> + size,
> + align,
> + GpuBuddyAllocFlags::default(),
> + ),
> + GFP_KERNEL,
> + )?;
...so we avoid this allocation.
> + Ok(Arc::new(
> + VramBlock {
> + _blocks: blocks,
> + // INVARIANT: `range.start <= range.end` was checked above, hence
> + // `address <= end`.
> + range: start..end,
> + },
> + GFP_KERNEL,
> + )?)
To me it seems that reference counting is not needed here.
AFAICS, a VramBlock does not actually have shared ownership, it is owned by the
VgpuVramSlotPool of the VgpuInstances.
A VgpuInstance owns a VgpuVramSlot, and a VgpuVramSlot owns a VramRegion. The
VramRegion borrows (a range) from the VgpuVramSlotPool's VramBlock.
Finally, a BarMapping (also owned by a VgpuInstance) also borrows from the
VgpuVramSlotPool's VramBlock.
Do I miss anything? I tried to double check and asked my clanker to inline all
the relevant structures, and it came up with this:
struct VgpuInstances {
vram_slots: Option<VgpuVramSlotPool {
backing: VramBlock {
_blocks: Pin<KBox<AllocatedBlocks {
buddy: &'mm GpuBuddy,
// Allocated buddy blocks.
}>>,
range: Range<u64>,
},
layout: VgpuVramLayout,
fb_region_size: u64,
}>,
instances: KVec<VgpuInstance {
vram_slot: VgpuVramSlot {
index: u32,
fbmem: VramRegion {
backing: &'pool VramBlock,
range: Range<u64>,
},
mgmt_heap: VramRegion {
backing: &'pool VramBlock,
range: Range<u64>,
},
},
plugin_rpc: PluginRpc {
comm: CommBufferRegion {
map: BarMapping {
region: VramRegion {
backing: &'pool VramBlock,
range: Range<u64>,
},
access: BarUserAccess {
bar_user: &BarUser,
mapped: Option<MappedRange>,
},
mm: &SharedGpuMm,
unmap_error: Option<Error>,
},
},
// Other RPC state omitted.
},
}>,
}
(In case you wonder why it says &'a GpuBuddy for AllocatedBlocks, I have [1]
applied locally.)
[1] https://lore.kernel.org/nova-gpu/20261126221108.3768637-1-dakr@kernel.org/
next prev parent reply other threads:[~2026-11-26 22:12 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 13:58 [PATCH v5 00/35] Introduce NVIDIA vGPU manager Alok Kumar
2026-11-24 13:58 ` [PATCH v5 01/35] gpu: nova-core: populate VF information in GSP_INIT Alok Kumar
2026-11-24 13:58 ` [PATCH v5 02/35] gpu: nova-core: gsp: pass boot context through setup helpers Alok Kumar
2026-11-24 13:58 ` [PATCH v5 03/35] gpu: nova-core: gsp: decouple boot context from VgpuManager Alok Kumar
2026-11-24 13:59 ` [PATCH v5 04/35] gpu: nova-core: vgpu: detect boot state independently Alok Kumar
2026-11-24 13:59 ` [PATCH v5 05/35] gpu: nova-core: gpu: add a channel ID pool for vGPU Alok Kumar
2026-11-24 13:59 ` [PATCH v5 06/35] gpu: nova-core: gsp: decode the FIFO engine table Alok Kumar
2026-11-24 13:59 ` [PATCH v5 07/35] gpu: nova-core: vgpu: initialize runtime parameters after GSP boot Alok Kumar
2026-11-24 13:59 ` [PATCH v5 08/35] gpu: nova-core: vgpu: reserve the 48-VM WPR2 heap Alok Kumar
2026-11-24 13:59 ` [PATCH v5 09/35] gpu: nova-core: mm: replace BarUserAccess accessors with typed MMIO view Alok Kumar
2026-11-24 13:59 ` [PATCH v5 10/35] gpu: nova-core: mm: retain BAR1 reservations after unmap failure Alok Kumar
2026-11-24 13:59 ` [PATCH v5 11/35] gpu: nova-core: mm: borrow BarUser for temporary BAR1 access Alok Kumar
2026-11-24 13:59 ` [PATCH v5 12/35] gpu: nova-core: mm: add VramBlock Alok Kumar
2026-11-26 22:12 ` Danilo Krummrich [this message]
2026-11-24 13:59 ` [PATCH v5 13/35] gpu: nova-core: mm: add VramRegion Alok Kumar
2026-11-24 13:59 ` [PATCH v5 14/35] gpu: nova-core: mm: add BarMapping Alok Kumar
2026-11-24 13:59 ` [PATCH v5 15/35] gpu: nova-core: mm: add SharedGpuMm Alok Kumar
2026-11-26 21:38 ` Danilo Krummrich
2026-11-24 13:59 ` [PATCH v5 16/35] gpu: nova-core: gsp: cmdq: gmc: add types for variable-length payloads Alok Kumar
2026-11-24 13:59 ` [PATCH v5 17/35] gpu: nova-core: gsp: add the vGPU commands to GmcCommandId Alok Kumar
2026-11-24 13:59 ` [PATCH v5 18/35] gpu: nova-core: gsp: cmdq: add send_gmc_command_await_event Alok Kumar
2026-11-24 13:59 ` [PATCH v5 19/35] gpu: nova-core: vgpu: add r000 plugin bindings Alok Kumar
2026-11-24 13:59 ` [PATCH v5 20/35] gpu: nova-core: gsp: factor out NVKV payload conversion Alok Kumar
2026-11-24 13:59 ` [PATCH v5 21/35] gpu: nova-core: vgpu: add VRAM slot pool Alok Kumar
2026-11-24 13:59 ` [PATCH v5 22/35] gpu: nova-core: vgpu: query VF assignments and properties Alok Kumar
2026-11-24 13:59 ` [PATCH v5 23/35] gpu: nova-core: vgpu: add instance create/destroy Alok Kumar
2026-11-24 13:59 ` [PATCH v5 24/35] gpu: nova-core: vgpu: encode vGPU boot requests Alok Kumar
2026-11-24 13:59 ` [PATCH v5 25/35] gpu: nova-core: vgpu: add GSP plugin communication buffer Alok Kumar
2026-11-24 13:59 ` [PATCH v5 26/35] gpu: nova-core: vgpu: add instance boot Alok Kumar
2026-11-24 13:59 ` [PATCH v5 27/35] gpu: nova-core: vgpu: add instance shutdown Alok Kumar
2026-11-24 13:59 ` [PATCH v5 28/35] gpu: nova-core: vgpu: add GSP plugin RPC transactions Alok Kumar
2026-11-24 13:59 ` [PATCH v5 29/35] gpu: nova-core: vgpu: negotiate the GSP plugin RPC version Alok Kumar
2026-11-24 13:59 ` [PATCH v5 30/35] gpu: nova-core: vgpu: send GSP plugin configuration parameters Alok Kumar
2026-11-24 13:59 ` [PATCH v5 31/35] gpu: nova-core: vgpu: update the GSP plugin BME state Alok Kumar
2026-11-24 13:59 ` [PATCH v5 32/35] gpu: nova-core: vgpu: add CeUtils commands Alok Kumar
2026-11-24 13:59 ` [PATCH v5 33/35] gpu: nova-core: vgpu: scrub guest VRAM with CeUtils Alok Kumar
2026-11-24 13:59 ` [PATCH v5 34/35] gpu: nova-core: vgpu: introduce SR-IOV PF APIs Alok Kumar
2026-11-24 13:59 ` [PATCH v5 35/35] gpu: nova-core: mm: keep BAR1 self-test page tables alive Alok Kumar
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=DN5HKLQK65L0.1L9NVW750P85W@kernel.org \
--to=dakr@kernel.org \
--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=apopple@nvidia.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=boqun@kernel.org \
--cc=cjia@nvidia.com \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=jgg@nvidia.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=joelagnelf@nvidia.com \
--cc=kevin.tian@intel.com \
--cc=kjaju@nvidia.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=markus.probst@posteo.de \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=peter@colberg.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=skolothumtho@nvidia.com \
--cc=smitra@nvidia.com \
--cc=tamird@kernel.org \
--cc=targupta@nvidia.com \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
--cc=xinmengs@nvidia.com \
--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