From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 434871DC9A3; Wed, 21 May 2025 08:00:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747814435; cv=none; b=UF+gwo7vt40di+yDXkStR3nF7RRlK3x+dvNGmMa9goNtCdPV+BzFRBZmRssbvTOq9oH2d5nhIo+GpPfEjRnBXwtkFC/waakzIrafOgQlhXAAthkHbSmX/outFg1fMuHGYRSttsliQXD7hcJloRrOdL9/otP+9yHPEUK7KGplCyI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747814435; c=relaxed/simple; bh=NXbCTTtiVf1hxjNTRc1GM2RzoMelIfvrZhBNyZ0cQJs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tezvQDPv/iRw5dtmRKYa3j4SrxQDKRq4ELMX3+qSBdxUsR5ccoY3IK2XSyrleBldZfiUZy7GxJqqk24Ve3muqpkwxz5+2w25HWZMLxbveyR13jSdENS/OV43f/w/6K0QPsa1RVrnEZIu1WrK8sMoCgvDUznU4NfWdFbNvrzSF4A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m2/9uM/U; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m2/9uM/U" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 149D9C4CEE4; Wed, 21 May 2025 08:00:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747814434; bh=NXbCTTtiVf1hxjNTRc1GM2RzoMelIfvrZhBNyZ0cQJs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=m2/9uM/UEfrYjyZRB5+ZA8Cs/2Hmzow+6pqeB30HS4fYP9dE/0yDvbAta6DX0hKcW CdgvE2HGDxvB86ylvjwlpAQ5UlZ4FF2laz60QCYmYwsos8qZEvzO3e1hi84Yw8u8BA DrrnFuSjhGIQm7wGHSLQ6OYQUUb1p1BrhVK33smEnGBJK5BS2Pn/Dm+JZ59cH5UXlB uX1S5xdpjDt0HVVsA2hkx9HZdS2hwH+jsMeNXLRPxUu9VvQYzlhAzklsccQ2PKfVHQ UFFTZj3xOBMhocKbIJO49SEeXDGfWr0b/lDVE6GUSfsfGSJI3fMRxLFuvBUr68wz7o cZRSU6h8DYctw== Date: Wed, 21 May 2025 10:00:27 +0200 From: Danilo Krummrich To: Alexandre Courbot Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , John Hubbard , Ben Skeggs , Joel Fernandes , Timur Tabi , Alistair Popple , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: Re: [PATCH v4 01/20] rust: dma: expose the count and size of CoherentAllocation Message-ID: References: <20250521-nova-frts-v4-0-05dfd4f39479@nvidia.com> <20250521-nova-frts-v4-1-05dfd4f39479@nvidia.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250521-nova-frts-v4-1-05dfd4f39479@nvidia.com> On Wed, May 21, 2025 at 03:44:56PM +0900, Alexandre Courbot wrote: > These properties are very useful to have and should be accessible. > > Signed-off-by: Alexandre Courbot > --- > rust/kernel/dma.rs | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs > index 605e01e35715667f93297fd9ec49d8e7032e0910..2a60eefa47dfc1f836c30ee342e26c6ff3e9b13a 100644 > --- a/rust/kernel/dma.rs > +++ b/rust/kernel/dma.rs > @@ -129,6 +129,10 @@ pub mod attrs { > // > // Hence, find a way to revoke the device resources of a `CoherentAllocation`, but not the > // entire `CoherentAllocation` including the allocated memory itself. > +// > +// # Invariants > +// > +// The size in bytes of the allocation is equal to `size_of:: * count()`. I think this also needs an invariant comment whenever self.count is set. > pub struct CoherentAllocation { > dev: ARef, > dma_handle: bindings::dma_addr_t, > @@ -201,6 +205,20 @@ pub fn alloc_coherent( > CoherentAllocation::alloc_attrs(dev, count, gfp_flags, Attrs(0)) > } > > + /// Returns the number of elements `T` in this allocation. > + /// > + /// Note that this is not the size of the allocation in bytes, which is provided by > + /// [`Self::size`]. > + pub fn count(&self) -> usize { > + self.count > + } > + > + /// Returns the size in bytes of this allocation. > + pub fn size(&self) -> usize { > + // As per the invariants of `CoherentAllocation`. > + self.count * core::mem::size_of::() > + } > + > /// Returns the base address to the allocated region in the CPU's virtual address space. > pub fn start_ptr(&self) -> *const T { > self.cpu_addr > > -- > 2.49.0 >