Re: [PATCH v6 11/34] gpu: nova-core: mm: add VramBlock
From: Danilo Krummrich
Date: Fri Dec 04 2026 - 13:53:01 EST
On Wed Dec 2, 2026 at 9:28 AM CET, Alok Kumar wrote:
> +/// A physically contiguous VRAM allocation.
> +///
> +/// # Invariants
> +///
> +/// `range.start <= range.end`.
> +#[pin_data]
> +pub(crate) struct VramBlock {
> + #[pin]
> + _blocks: AllocatedBlocks,
> + range: Range<u64>,
> +}
> +
> +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(
I think this should be VramBlock::new() and then GpuMm can call VramBlock::new()
in its alloc_vram_range() in its own module.
impl VramBlock {
pub(crate) fn new(
buddy: &GpuBuddy,
range: Range<u64>,
align: Alignment,
) -> impl PinInit<Self, Error> {
}
}
> + &self,
> + range: Range<u64>,
> + align: Alignment,
> + ) -> Result<impl PinInit<VramBlock, Error>> {
Please avoid Result<impl PinInit<_, Error>>, this can just be
impl PinInit<_, Error>.
> + 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 = buddy.alloc_blocks(
> + GpuBuddyAllocMode::Range(range),
> + size,
> + align,
> + GpuBuddyAllocFlags::default(),
> + );
You should be able to move the fallible calls above into the initializer.
> + Ok(try_pin_init!(VramBlock {
> + _blocks <- blocks,
> + // INVARIANT: `range.start <= range.end` was checked above.
> + range: start..end,
> + }))
> + }
> +}