From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4758F606A322 for ; Fri, 4 Dec 2026 18:59:56 +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=YgroquqK Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A0E3710E88E; Fri, 4 Dec 2026 18:59:50 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id AC84010E88E for ; Fri, 4 Dec 2026 18:59:44 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id C7D9B61B68; Fri, 4 Dec 2026 18:59:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AD171F00A11; Fri, 4 Dec 2026 18:59:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796410783; bh=ycgOYNB+vt11AUpgvl/5CBk965GGucgH98cxo4yoD34=; h=Date:To:From:Subject:Cc:References:In-Reply-To; b=YgroquqKMw2CWTyqs5FIWiJ/tkzFwwIbNXeGWP1a+vnSCmeEErOBbgD1hnOB8Sbwv heutAJ7OXYJj8B2SXTvHCoCv1hx2OR4RVVfswU8INyB9ExXNA16+PBoQexzsHjd0RT xbSgAb3eiaq7QSTQNGw/pylTdCbL2hDeXtSNxR5p9DnK56TsGTdO97N4a4NbSsB2hk Zt5dgpsSJY+oByLeLF0POz5Jhzj6Fdb/yiXL0ihn0a/kVRSQTIS+U9w8+ByfFj4iwQ rf5phcbFCwDq7/W0MqSJuAoVG/CGZakDMUOlkSeybgb33WDTNJZM6oxvyo+XN/aivl o6tqiMcV9uQQw== X-Archived-By: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 04 Dec 2026 19:59:33 +0100 Message-Id: To: "Alok Kumar" From: "Danilo Krummrich" Subject: Re: [PATCH v6 12/34] gpu: nova-core: mm: add VramRegion Cc: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: In-Reply-To: X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "dri-devel" X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Wed Dec 2, 2026 at 9:28 AM CET, Alok Kumar wrote: > diff --git a/drivers/gpu/nova-core/mm/vram.rs b/drivers/gpu/nova-core/mm/= vram.rs > index 63bc0ce93663..be3076d065c6 100644 > --- a/drivers/gpu/nova-core/mm/vram.rs > +++ b/drivers/gpu/nova-core/mm/vram.rs > @@ -21,6 +21,21 @@ > PAGE_SIZE, // > }; > =20 > +/// Rebases the nonempty range `rel`, relative to the start of `base`, o= nto `base`. > +/// > +/// Returns `EINVAL` if `rel` is empty or does not fit within `base`. > +fn rebase(base: &Range, rel: Range) -> Result> { > + let start =3D base.start.checked_add(rel.start).ok_or(EINVAL)?; > + let end =3D base.start.checked_add(rel.end).ok_or(EINVAL)?; > + > + // Check that the rebased range on not empty and fits within `base`. > + if start >=3D end || end > base.end { > + return Err(EINVAL); > + } > + > + Ok(start..end) > +} > + > /// A physically contiguous VRAM allocation. > /// > /// # Invariants > @@ -38,6 +53,47 @@ impl VramBlock { > pub(crate) const fn range(&self) -> &Range { > &self.range > } > + > + /// Creates a byte range relative to this allocation, borrowing its = backing storage. > + pub(crate) fn region(&self, range: Range) -> Result> { > + Ok(VramRegion { > + backing: self, > + // INVARIANT: `rebase` returns a nonempty range. > + range: rebase(&self.range, range)?, > + }) > + } > +} > + > +/// A byte range borrowing its backing VRAM allocation. > +/// > +/// # Invariants > +/// > +/// `range.start < range.end`, and `range` lies within the range of `bac= king`. > +#[derive(Clone)] > +pub(crate) struct VramRegion<'pool> { > + backing: &'pool VramBlock, 'pool seems odd here, I think 'block would be reasonable, but in this case = I'd just use 'a. > + range: Range, > +} > + > +impl VramRegion<'_> { > + /// Returns the range covered by this region. > + pub(crate) const fn range(&self) -> &Range { > + &self.range > + } > + > + /// Returns the length of this region in bytes. > + pub(crate) const fn len(&self) -> u64 { > + self.range.end.saturating_sub(self.range.start) saturating_sub() seems unnecessary given the type invariant. > + } > + > + /// Creates a nonempty subregion relative to this view's start. > + pub(crate) fn subregion(&self, range: Range) -> Result { > + Ok(Self { > + backing: self.backing, > + // INVARIANT: `rebase` returns a nonempty range. > + range: rebase(&self.range, range)?, > + }) > + } > } > =20 > impl GpuMm<'_> {