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=1796410783; b=pgMOCi0ZHmU7jm686Elos7o68/MtqbHyxO1xIzDl5WVZjqbWe8K0DBo6lCbu/d3ItDtI HpPZgn9R7aWL+vh2B310I/Bmt2yy4ErjIx4Gyex6AHVmHoCvcBBntHWTRBojB9XyZfuIy F0j/QTb1IEKR6YrwDgyEPGy1C9nmJUV10LdWQ+rwnuifIQk6dAcLnK/umB9+dLHCs53IZ 4VIxPQF/oJ5Rsgy662e9QIdCmGHdFWESOH/5vQUrF75mhQr+sIcPWAgiReutlZJd1j+jT YUAmB1NtfsJz/tDkcEOs+0UNseoCQbTJc3Vbx/ZensJdThNqBI5WwPTlPoOrQjCNjiQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796410783; h=Received:DKIM-Signature:Mime-Version:Content-Transfer-Encoding: Content-Type:Date:Message-Id:To:From:Subject:Cc:References: In-Reply-To; bh=ycgOYNB+vt11AUpgvl/5CBk965GGucgH98cxo4yoD34=; b=l5YuI7FWuqMj2U9EA8to6GTfnbkgq8pSmDtraaMYB5VYXPK4ZgLuKweNzHl8YBLLUHEr sZz5AyE1i0A93ykSwyi9pbH5deSDBM0rGg0wZGFDuF+LIB/5WHKG2pOyiEyB3ZBydoSFS Goz/01Qd6SGugl7gcAzf/4Pzt6MFqcBbvOmRGvqR04wLnqvP8m/c41Sf47GmfEFAGFtyR rh4Yj8v1NgxWzCLkh43qmhlZfLJyF9rX0d2e/QSp8uKdPwH6hnbgkYShitjxKR6x3psy2 jXRPHILk2H2aH4UAxdY/I9V85ZXO/pa8xJ+Nl84niQD3pvnnUn40h/xl4nWUq1i70yg== 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=YgroquqK; 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 A432D606A322; Fri, 4 Dec 2026 18:59:43 +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: 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-Mailing-List: linux-kernel@vger.kernel.org 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 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: 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<'_> {