From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796416489; b=TN1MSSZURUZ18/j+9bsUapak2UenYqLdRmurfxABUz5Ai9q9BjUwOA65dOtr54Vjyf+H IpXPlVX+KXdJ9AJqBnJVTVhSVAPYBa4mJzemGbYCDPlrZx5Ut3PDeEjklEBs/H7dlCCxO nsL/m02OVvbs2aJnwjrtfcsbPAGDaZ8GVtp+QqQ+E1q8WD3bbDkJQx67WLFrF+wQYeG9t yAEUJaRLRrd8z3QZx4dvPRv/Jx0p0K2w3E04+0VTSJ4YdMDJc5ZIReNIQiKMgBfWFK53h 3KvryBypsGm3blvp0ui2tdXHNBaXlURhrPvSe9RNc3/Ebyk9bdEYRGU86jImcD0VGnw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796416489; h=Received:DKIM-Signature:Mime-Version:Content-Transfer-Encoding: Content-Type:Date:Message-Id:Cc:To:From:Subject:References: In-Reply-To; bh=WMJn1RLL8V1/kZEcKQDEQ+Xzx/9rMEnx5fwAFhS2fp8=; b=AWLum2C+mMHZ+hLqqiLEomFd/UMlq5iT14c2SqBZwNu/S4Skeg8lvdmzeXKsq5Xs5TEJ SQszAdcIPsDZ/lVqv8zXrmdtjnk9Y3qGEDpiAEPtuvjWynE0Kz8VibKagIb+Ky/u0NrE/ C8suEFMbQukV8534S670YU3d+y7c/gMXMf8LW/GFDuHekn2W2w01lOuK6SroB86k69K/j tifzdl3G3wCm6YeqLh2cQx4+k9E+C30n61LRM3PF1SmPlQqSdau9wqXG99R1Fs2aQuNVl VO4K0h1Pn/R91BvNC1+OQ4pWi4UadFr/exLuu5t9tAMHciOgH7T1hHZUvgxiy0nJ/aA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MRn5AJh0; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEF24606A322; Fri, 4 Dec 2026 20:34:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MRn5AJh0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 961D71F00936; Fri, 4 Dec 2026 20:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796416489; bh=WMJn1RLL8V1/kZEcKQDEQ+Xzx/9rMEnx5fwAFhS2fp8=; h=Date:Cc:To:From:Subject:References:In-Reply-To; b=MRn5AJh0wy85bA2YuhtW9FDxyZAymQbUGus/p2V2s46FZCgyozgUzEts4M1vU9Xbs hV1GbJ/++zLSemB7LGxq+DepHRp+0QwuX1zYiKuJlQ+l2sMCQ5B3m14LpDERL7piW8 XZFInGHYsZ7gHzYz4rYUygaQJmOWdfWLbbOiIhEpzPDJnIAwU1rMHthZ46taSe0hTM +UsuEi9qOYqxtYEfop2uAmq0lPQRz8RUVD2kDaSOgwVuXu6FBqeSwmREFu5hPl4leZ qBDaXCB8Z2iUDospmwIeVqD78kLhDeY20qYL6w9dgX9dRkI7k7Cn92iaLFXr/pbJhv OXJfdr9RA+0cQ== X-Mailing-List: nova-gpu@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 04 Dec 2026 21:34:39 +0100 Message-Id: Cc: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , To: "Alok Kumar" From: "Danilo Krummrich" Subject: Re: [PATCH v6 20/34] gpu: nova-core: vgpu: add VRAM slot pool References: <626c495fc37f20e1543cc04ce5daad049e5b7484.1796191007.git.alkumar@nvidia.com> In-Reply-To: <626c495fc37f20e1543cc04ce5daad049e5b7484.1796191007.git.alkumar@nvidia.com> On Wed Dec 2, 2026 at 9:28 AM CET, Alok Kumar wrote: > +const VRAM_SLOT_MIN_ALIGN: u64 =3D u64::SZ_4K; > +// `VRAM_SLOT_MIN_ALIGN` is used for alignment. > +static_assert!(VRAM_SLOT_MIN_ALIGN.is_power_of_two()); > + > +/// Describes the VRAM layout used by vGPU instances. > +#[derive(Clone, Copy, PartialEq)] Please avoid Clone and Copy for this, if we need to make it accessible VgpuVramSlotPool can provide it via borrow. > +pub(super) struct VgpuVramLayout { > + // Firmware ID of the vGPU type this layout was built for. > + type_id: u32, > + // Maximum number of slots with this layout. > + max_slots: u32, > + // Size of the framebuffer for a vGPU instance. > + fb_size: u64, > + // Size of heap for a vGPU instance. > + heap_size: u64, > + // Alignment of the framebuffer for vGPU instances. > + fb_align: u64, > +} > + > +#[expect(dead_code)] > +impl VgpuVramLayout { > + pub(super) fn new( > + type_id: u32, > + max_slots: u32, > + fb_size: u64, > + heap_size: u64, > + fb_align: u64, > + ) -> Result { > + if max_slots =3D=3D 0 || fb_size =3D=3D 0 || heap_size =3D=3D 0 = { > + return Err(EINVAL); > + } > + > + let fb_align =3D core::cmp::max(fb_align, VRAM_SLOT_MIN_ALIGN); > + > + if !fb_align.is_power_of_two() > + || !fb_size.is_multiple_of(fb_align) > + || !heap_size.is_multiple_of(VRAM_SLOT_MIN_ALIGN) > + { > + return Err(EINVAL); > + } > + > + Ok(Self { > + type_id, > + max_slots, > + fb_size, > + heap_size, > + fb_align, > + }) > + } > + > + pub(super) fn max_slots(&self) -> u32 { > + self.max_slots > + } > +} > + > +/// A description of a VRAM slot. > +/// > +/// All device accesses and mappings of its regions must end before drop= ping the slot. > +#[must_use] > +#[expect(dead_code)] > +pub(super) struct VgpuVramSlot<'pool> { > + /// Framebuffer VRAM region. > + pub(super) fbmem: VramRegion<'pool>, > + /// Management heap VRAM region. > + pub(super) mgmt_heap: VramRegion<'pool>, > + /// Index of this slot. > + pub(super) index: u32, > +} > + > +/// A pool of VRAM slots, split according to a [`VgpuVramLayout`]. > +#[pin_data] > +pub(super) struct VgpuVramSlotPool { > + #[pin] > + backing: VramBlock, > + layout: VgpuVramLayout, > + fb_region_size: u64, > +} > + > +#[expect(dead_code)] > +impl VgpuVramSlotPool { > + /// Reserve the VRAM for all possible slots of `layout`, and returns= a [`VgpuVramSlotPool`] that > + /// can provide these slots. > + pub(super) fn new(mm: &GpuMm<'_>, layout: VgpuVramLayout) -> Result<= impl PinInit> { Please make this return impl PinInit without the additional Re= sult. > + let max_slots =3D u64::from(layout.max_slots); > + // Keep guest VRAM slots contiguous so each starts at `fb_align`= ; > + // interleaving page-aligned heaps could misalign later slots. > + let fb_region_size =3D layout.fb_size.checked_mul(max_slots).ok_= or(EINVAL)?; > + let heap_region_size =3D layout.heap_size.checked_mul(max_slots)= .ok_or(EINVAL)?; > + let pool_size =3D fb_region_size.checked_add(heap_region_size).o= k_or(EINVAL)?; > + > + let backing =3D mm.alloc_vram_range(0..pool_size, cv!(VRAM_SLOT_= MIN_ALIGN))?; > + Ok(try_pin_init!(Self { > + backing <- backing, > + layout, > + fb_region_size, > + _: { > + if !backing.range().start.is_multiple_of(layout.fb_align= ) { > + Err::<(), Error>(EINVAL)?; > + } > + }, > + })) > + } > + > + pub(super) fn max_slots(&self) -> u32 { > + self.layout.max_slots() > + } > + > + /// Returns `true` if `layout` is identical to the layout used by th= is pool. > + pub(super) fn matches_layout(&self, layout: VgpuVramLayout) -> bool = { > + self.layout =3D=3D layout > + } > + > + /// Returns the VRAM slot corresponding to `index`, or `EINVAL` if `= index` is not a valid slot > + /// index for the pool's layout. > + pub(super) fn slot(&self, index: u32) -> Result> { > + if index >=3D self.layout.max_slots { > + return Err(EINVAL); > + } > + > + let fb_size =3D self.layout.fb_size; > + let fb_offset =3D fb_size.checked_mul(index.into()).ok_or(EINVAL= )?; > + let fb_end =3D fb_offset.checked_add(fb_size).ok_or(EINVAL)?; > + > + let heap_size =3D self.layout.heap_size; > + let heap_slot_offset =3D heap_size.checked_mul(index.into()).ok_= or(EINVAL)?; > + let heap_offset =3D self > + .fb_region_size > + .checked_add(heap_slot_offset) > + .ok_or(EINVAL)?; > + let heap_end =3D heap_offset.checked_add(heap_size).ok_or(EINVAL= )?; > + > + let fbmem =3D self.backing.region(fb_offset..fb_end)?; > + let mgmt_heap =3D self.backing.region(heap_offset..heap_end)?; > + > + Ok(VgpuVramSlot { > + fbmem, > + mgmt_heap, > + index, > + }) > + } > +}