Re: [PATCH v6 22/34] gpu: nova-core: vgpu: add instance create/destroy
From: Danilo Krummrich
Date: Fri Dec 04 2026 - 19:17:33 EST
On Wed Dec 2, 2026 at 9:28 AM CET, Alok Kumar wrote:
> @@ -390,7 +390,9 @@ unsafe fn new(
> #[pin_data]
> pub(crate) struct Gpu<'gpu> {
> pub(crate) spec: Spec,
> - vgpu: Option<VgpuManager<'chid_pool>>,
> + /// Drops before the MM and BAR1 mappings needed for instance teardown.
> + #[uses('bar_user, 'chid_pool)]
> + vgpu: Option<Pin<KBox<VgpuManager<'mm>>>>,
Ugh, I don't like this, but there's currently no alternative.
I thought that we could probably add a new pin::Option type (internally using
MaybeUninit) to overcome this, so I asked Gary about it. Turns out that Benno
has a WIP implementation with exactly this for quite a while.
Gary mentioned that he'd be happy to provide an implementation for this, but
there's of course no reason to block this series on it.
> /// GSP event interrupt registration, and the enable of its subtree.
> ///
> /// Must be kept declared *before* `gsp_resources`, so that the handler is unregistered, and
> @@ -403,7 +405,8 @@ pub(crate) struct Gpu<'gpu> {
> ///
> /// Must be kept declared *before* `gsp_resources`, so that its components are dropped while
> /// the GSP is still operational.
> - mm: GpuMm<'gpu>,
> + #[pin]
> + mm: SharedGpuMm<'gpu>,
As mentioned previously, that shouldn't be needed.
> +/// A vGPU instance and the resources reserved for it.
> +#[expect(dead_code)]
> +struct VgpuInstance<'pool, 'gpu> {
Technically this could be unified, but I assume it's easier not to do so for
storing it in the registry.
In any case, I think the names are confusing, both could be generic lifetimes,
but 'gpu should probably be 'res and 'pool actually comes from the VramBlock,
right?
> + gfid: Gfid,
> + dbdf: Dbdf,
> + vgpu_type: VgpuType,
> + vm_pid: u32,
> + chids: ChannelIdReservation<'gpu>,
> + vram_slot: VgpuVramSlot<'pool>,
> +}
> +
> +/// Identity and firmware profile used to allocate an instance.
> +pub(super) struct InstanceInfo {
> + gfid: Gfid,
> + dbdf: Dbdf,
> + vgpu_type: VgpuType,
> + vm_pid: u32,
> +}
> +
> +#[expect(dead_code)]
> +impl InstanceInfo {
> + pub(super) fn new(gfid: Gfid, dbdf: Dbdf, properties: &VgpuProperties, vm_pid: u32) -> Self {
> + Self {
> + gfid,
> + dbdf,
> + vgpu_type: VgpuType::from(properties),
> + vm_pid,
> + }
> + }
> +}
> +
> +/// Instance registry and cached VRAM pool for one physical GPU.
> +pub(super) struct VgpuInstances<'gpu> {
> + pool: Option<Pin<KBox<VgpuInstancePool<'gpu>>>>,
> +}
I'd just use a generic lifetime for this.
> +
> +/// Instances borrow the pool, and are destroyed before its backing allocation.
> +#[pin_data]
> +struct VgpuInstancePool<'gpu> {
Same here, 'pool as an invariant lifetime is fine though.
> +/// Registry of instances borrowing one layout's pool.
> +struct InstanceRegistry<'pool, 'gpu> {
> + instances: KVec<VgpuInstance<'pool, 'gpu>>,
> + pool: &'pool VgpuVramSlotPool,
> +}
Should probably be 'res instead of 'gpu. 'pool seems fine, but could also just
be a generic lifetime.