[PATCH v2 0/5] dma::Device trait and DMA mask

Danilo Krummrich posted 5 patches 2 months, 3 weeks ago
rust/helpers/dma.c       |   5 ++
rust/kernel/dma.rs       | 125 ++++++++++++++++++++++++++++++++++++---
rust/kernel/pci.rs       |   2 +
rust/kernel/platform.rs  |   2 +
samples/rust/rust_dma.rs |  14 ++++-
5 files changed, 140 insertions(+), 8 deletions(-)
[PATCH v2 0/5] dma::Device trait and DMA mask
Posted by Danilo Krummrich 2 months, 3 weeks ago
This patch series adds the dma::Device trait to be implemented by bus devices on
DMA capable busses.

The dma::Device trait implements methods to set the DMA mask for for such
devices.

The first two bus devices implementing the trait are PCI and platform.

Unfortunately, the DMA mask setters have to be unsafe for now, since, with
reasonable effort, we can't prevent drivers from data races writing and reading
the DMA mask fields concurrently (see also [1]).

Link: https://lore.kernel.org/lkml/DB6YTN5P23X3.2S0NH4YECP1CP@kernel.org/ [1]
Link: https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=rust/dma-mask

Changes in v2:
  - replace dma_bit_mask() with a new type DmaMask
  - mention that DmaMask is the Rust equivalent of the C macro DMA_BIT_MASK()
  - make DmaMask::new() fallible
  - inline DmaMask methods

Danilo Krummrich (5):
  rust: dma: implement `dma::Device` trait
  rust: dma: add DMA addressing capabilities
  rust: pci: implement the `dma::Device` trait
  rust: platform: implement the `dma::Device` trait
  rust: samples: dma: set DMA mask

 rust/helpers/dma.c       |   5 ++
 rust/kernel/dma.rs       | 125 ++++++++++++++++++++++++++++++++++++---
 rust/kernel/pci.rs       |   2 +
 rust/kernel/platform.rs  |   2 +
 samples/rust/rust_dma.rs |  14 ++++-
 5 files changed, 140 insertions(+), 8 deletions(-)


base-commit: d49ac7744f578bcc8708a845cce24d3b91f86260
-- 
2.50.0
Re: [PATCH v2 0/5] dma::Device trait and DMA mask
Posted by Danilo Krummrich 2 months, 2 weeks ago
On Wed Jul 16, 2025 at 5:02 PM CEST, Danilo Krummrich wrote:
> This patch series adds the dma::Device trait to be implemented by bus devices on
> DMA capable busses.

Applied to driver-core-testing, thanks!
Re: [PATCH v2 0/5] dma::Device trait and DMA mask
Posted by Daniel Almeida 2 months, 3 weeks ago
Hi Danilo,

I think this looks good.

Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Re: [PATCH v2 0/5] dma::Device trait and DMA mask
Posted by Greg KH 2 months, 3 weeks ago
On Wed, Jul 16, 2025 at 05:02:45PM +0200, Danilo Krummrich wrote:
> This patch series adds the dma::Device trait to be implemented by bus devices on
> DMA capable busses.
> 
> The dma::Device trait implements methods to set the DMA mask for for such
> devices.
> 
> The first two bus devices implementing the trait are PCI and platform.
> 
> Unfortunately, the DMA mask setters have to be unsafe for now, since, with
> reasonable effort, we can't prevent drivers from data races writing and reading
> the DMA mask fields concurrently (see also [1]).
> 
> Link: https://lore.kernel.org/lkml/DB6YTN5P23X3.2S0NH4YECP1CP@kernel.org/ [1]
> Link: https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=rust/dma-mask
> 
> Changes in v2:
>   - replace dma_bit_mask() with a new type DmaMask
>   - mention that DmaMask is the Rust equivalent of the C macro DMA_BIT_MASK()
>   - make DmaMask::new() fallible
>   - inline DmaMask methods

I like the DmaMask stuff, nice!

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>