lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <A8A69C22-632D-4E89-AAAA-1891DFA11416@collabora.com>
Date: Tue, 26 Aug 2025 14:46:31 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Danilo Krummrich <dakr@...nel.org>
Cc: akpm@...ux-foundation.org,
 ojeda@...nel.org,
 alex.gaynor@...il.com,
 boqun.feng@...il.com,
 gary@...yguo.net,
 bjorn3_gh@...tonmail.com,
 lossin@...nel.org,
 a.hindborg@...nel.org,
 aliceryhl@...gle.com,
 tmgross@...ch.edu,
 abdiel.janulgue@...il.com,
 acourbot@...dia.com,
 jgg@...pe.ca,
 lyude@...hat.com,
 robin.murphy@....com,
 rust-for-linux@...r.kernel.org,
 linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 4/5] samples: rust: dma: add sample code for SGTable



> On 25 Aug 2025, at 10:24, Danilo Krummrich <dakr@...nel.org> wrote:
> 
> Add sample code for allocating and mapping a scatter-gather table
> (`SGTable`).
> 
> Co-developed-by: Abdiel Janulgue <abdiel.janulgue@...il.com>
> Signed-off-by: Abdiel Janulgue <abdiel.janulgue@...il.com>
> Signed-off-by: Danilo Krummrich <dakr@...nel.org>
> ---
> samples/rust/rust_dma.rs | 35 ++++++++++++++++++++++++++---------
> 1 file changed, 26 insertions(+), 9 deletions(-)
> 
> diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs
> index c5e7cce68654..04007e29fd85 100644
> --- a/samples/rust/rust_dma.rs
> +++ b/samples/rust/rust_dma.rs
> @@ -7,15 +7,19 @@
> use kernel::{
>     bindings,
>     device::Core,
> -    dma::{CoherentAllocation, Device, DmaMask},
> -    pci,
> +    dma::{CoherentAllocation, DataDirection, Device, DmaMask},
> +    page, pci,
>     prelude::*,
> +    scatterlist::{Owned, SGTable},
>     types::ARef,
> };
> 
> +#[pin_data(PinnedDrop)]
> struct DmaSampleDriver {
>     pdev: ARef<pci::Device>,
>     ca: CoherentAllocation<MyStruct>,
> +    #[pin]
> +    sgt: SGTable<Owned<VVec<u8>>>,
> }
> 
> const TEST_VALUES: [(u32, u32); 5] = [
> @@ -70,21 +74,30 @@ fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self
>             kernel::dma_write!(ca[i] = MyStruct::new(value.0, value.1))?;
>         }
> 
> -        let drvdata = KBox::new(
> -            Self {
> +        let size = 4 * page::PAGE_SIZE;
> +        let pages = VVec::with_capacity(size, GFP_KERNEL)?;
> +
> +        let sgt = SGTable::new(pdev.as_ref(), pages, DataDirection::ToDevice, GFP_KERNEL);
> +
> +        let drvdata = KBox::pin_init(
> +            try_pin_init!(Self {
>                 pdev: pdev.into(),
>                 ca,
> -            },
> +                sgt <- sgt,
> +            }),
>             GFP_KERNEL,
>         )?;
> 
> -        Ok(drvdata.into())
> +        Ok(drvdata)
>     }
> }
> 
> -impl Drop for DmaSampleDriver {
> -    fn drop(&mut self) {
> -        dev_info!(self.pdev.as_ref(), "Unload DMA test driver.\n");
> +#[pinned_drop]
> +impl PinnedDrop for DmaSampleDriver {
> +    fn drop(self: Pin<&mut Self>) {
> +        let dev = self.pdev.as_ref();
> +
> +        dev_info!(dev, "Unload DMA test driver.\n");
> 
>         for (i, value) in TEST_VALUES.into_iter().enumerate() {
>             let val0 = kernel::dma_read!(self.ca[i].h);
> @@ -99,6 +112,10 @@ fn drop(&mut self) {
>                 assert_eq!(val1, value.1);
>             }
>         }
> +
> +        for (i, entry) in self.sgt.iter().enumerate() {
> +            dev_info!(dev, "Entry[{}]: DMA address: {:#x}", i, entry.dma_address());
> +        }
>     }
> }
> 
> -- 
> 2.51.0
> 
> 

Reviewed-by: Daniel Almeida <daniel.almeida@...labora.com>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ