* [PATCH] rust: iommu: replace core::mem::zeroed with pin_init::zeroed
@ 2026-06-26 20:31 Nicolás Antinori
2026-06-27 8:34 ` Alexandre Courbot
0 siblings, 1 reply; 6+ messages in thread
From: Nicolás Antinori @ 2026-06-26 20:31 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon
Cc: Nicolás Antinori, Alexandre Courbot, Alice Ryhl,
Andreas Hindborg, Benno Lossin, Björn Roy Baron, Boqun Feng,
Daniel Almeida, Danilo Krummrich, Gary Guo, Miguel Ojeda,
Onur Özkan, Robin Murphy, Shuah Khan, Tamir Duberstein,
Trevor Gross, linux-kernel, rust-for-linux, iommu,
linux-kernel-mentees
All types in `bindings` implement `Zeroable` if they can. This enables
using `pin_init::zeroed()` for `io_pgtable_cfg` initialization instead
of relying on `..unsafe { core::mem::zeroed() }`.
This change improves readability and removes an unnecessary unsafe
block.
Link: https://github.com/Rust-for-Linux/linux/issues/1189
Suggested-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
---
rust/kernel/iommu/pgtable.rs | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/rust/kernel/iommu/pgtable.rs b/rust/kernel/iommu/pgtable.rs
index c88e38fd938a..8faa1d8d9fad 100644
--- a/rust/kernel/iommu/pgtable.rs
+++ b/rust/kernel/iommu/pgtable.rs
@@ -102,8 +102,7 @@ pub unsafe fn new_raw(dev: &Device<Bound>, config: Config) -> Result<IoPageTable
coherent_walk: config.coherent_walk,
tlb: &raw const NOOP_FLUSH_OPS,
iommu_dev: dev.as_raw(),
- // SAFETY: All zeroes is a valid value for `struct io_pgtable_cfg`.
- ..unsafe { core::mem::zeroed() }
+ ..pin_init::zeroed()
};
// SAFETY:
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] rust: iommu: replace core::mem::zeroed with pin_init::zeroed
2026-06-26 20:31 [PATCH] rust: iommu: replace core::mem::zeroed with pin_init::zeroed Nicolás Antinori
@ 2026-06-27 8:34 ` Alexandre Courbot
2026-06-28 10:31 ` Miguel Ojeda
0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Courbot @ 2026-06-27 8:34 UTC (permalink / raw)
To: Nicolás Antinori
Cc: Joerg Roedel, Will Deacon, Alice Ryhl, Andreas Hindborg,
Benno Lossin, Björn Roy Baron, Boqun Feng, Daniel Almeida,
Danilo Krummrich, Gary Guo, Miguel Ojeda, Onur Özkan,
Robin Murphy, Shuah Khan, Tamir Duberstein, Trevor Gross,
linux-kernel, rust-for-linux, iommu, linux-kernel-mentees
On Sat Jun 27, 2026 at 5:31 AM JST, Nicolás Antinori wrote:
> All types in `bindings` implement `Zeroable` if they can. This enables
> using `pin_init::zeroed()` for `io_pgtable_cfg` initialization instead
> of relying on `..unsafe { core::mem::zeroed() }`.
>
> This change improves readability and removes an unnecessary unsafe
> block.
>
> Link: https://github.com/Rust-for-Linux/linux/issues/1189
> Suggested-by: Benno Lossin <lossin@kernel.org>
> Signed-off-by: Nicolás Antinori <nico.antinori.7@gmail.com>
> ---
> rust/kernel/iommu/pgtable.rs | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/rust/kernel/iommu/pgtable.rs b/rust/kernel/iommu/pgtable.rs
> index c88e38fd938a..8faa1d8d9fad 100644
> --- a/rust/kernel/iommu/pgtable.rs
> +++ b/rust/kernel/iommu/pgtable.rs
> @@ -102,8 +102,7 @@ pub unsafe fn new_raw(dev: &Device<Bound>, config: Config) -> Result<IoPageTable
> coherent_walk: config.coherent_walk,
> tlb: &raw const NOOP_FLUSH_OPS,
> iommu_dev: dev.as_raw(),
> - // SAFETY: All zeroes is a valid value for `struct io_pgtable_cfg`.
> - ..unsafe { core::mem::zeroed() }
> + ..pin_init::zeroed()
Note that you can also use `..Zeroable::zeroed()` here since we are not
in const context. Not sure which one we prefer in this case, but I'd
personally err on the side of not referring to `pin_init` unless we are
dealing with a pinned object or need to because of a const requirement.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] rust: iommu: replace core::mem::zeroed with pin_init::zeroed
2026-06-27 8:34 ` Alexandre Courbot
@ 2026-06-28 10:31 ` Miguel Ojeda
2026-06-28 17:34 ` Gary Guo
2026-06-29 19:45 ` Nicolás Antinori
0 siblings, 2 replies; 6+ messages in thread
From: Miguel Ojeda @ 2026-06-28 10:31 UTC (permalink / raw)
To: Alexandre Courbot, Benno Lossin, Gary Guo
Cc: Nicolás Antinori, Joerg Roedel, Will Deacon, Alice Ryhl,
Andreas Hindborg, Björn Roy Baron, Boqun Feng,
Daniel Almeida, Danilo Krummrich, Gary Guo, Miguel Ojeda,
Onur Özkan, Robin Murphy, Shuah Khan, Tamir Duberstein,
Trevor Gross, linux-kernel, rust-for-linux, iommu,
linux-kernel-mentees
On Sat, Jun 27, 2026 at 10:35 AM Alexandre Courbot <acourbot@nvidia.com> wrote:
>
> Note that you can also use `..Zeroable::zeroed()` here since we are not
> in const context. Not sure which one we prefer in this case, but I'd
> personally err on the side of not referring to `pin_init` unless we are
> dealing with a pinned object or need to because of a const requirement.
That sounds reasonable -- Benno/Gary, any comments?
By the way, speaking of that: the docs of `zeroed()` (both of them)
could mention the existence of the other (and the `const fn`
difference).
I guess this will eventually go through IOMMU, but I can also take it
via `rust-next` if needed.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: iommu: replace core::mem::zeroed with pin_init::zeroed
2026-06-28 10:31 ` Miguel Ojeda
@ 2026-06-28 17:34 ` Gary Guo
2026-06-29 19:45 ` Nicolás Antinori
1 sibling, 0 replies; 6+ messages in thread
From: Gary Guo @ 2026-06-28 17:34 UTC (permalink / raw)
To: Miguel Ojeda, Alexandre Courbot, Benno Lossin, Gary Guo
Cc: Nicolás Antinori, Joerg Roedel, Will Deacon, Alice Ryhl,
Andreas Hindborg, Björn Roy Baron, Boqun Feng,
Daniel Almeida, Danilo Krummrich, Gary Guo, Miguel Ojeda,
Onur Özkan, Robin Murphy, Shuah Khan, Tamir Duberstein,
Trevor Gross, linux-kernel, rust-for-linux, iommu,
linux-kernel-mentees
On Sun Jun 28, 2026 at 11:31 AM BST, Miguel Ojeda wrote:
> On Sat, Jun 27, 2026 at 10:35 AM Alexandre Courbot <acourbot@nvidia.com> wrote:
>>
>> Note that you can also use `..Zeroable::zeroed()` here since we are not
>> in const context. Not sure which one we prefer in this case, but I'd
>> personally err on the side of not referring to `pin_init` unless we are
>> dealing with a pinned object or need to because of a const requirement.
>
> That sounds reasonable -- Benno/Gary, any comments?
`Zeroable::zeroed()` should be preferred where possible. Currently init macros
also recognize and turn them into zero-init if used inside init macros --
outside init macros they don't matter, but in a future where const trait methods
are stable we would want to prefer `Zeroable::zeroed()` anyway.
Best,
Gary
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: iommu: replace core::mem::zeroed with pin_init::zeroed
2026-06-28 10:31 ` Miguel Ojeda
2026-06-28 17:34 ` Gary Guo
@ 2026-06-29 19:45 ` Nicolás Antinori
2026-06-29 19:51 ` Miguel Ojeda
1 sibling, 1 reply; 6+ messages in thread
From: Nicolás Antinori @ 2026-06-29 19:45 UTC (permalink / raw)
To: Miguel Ojeda, Alexandre Courbot, Benno Lossin, Gary Guo
Cc: Joerg Roedel, Will Deacon, Alice Ryhl, Andreas Hindborg,
Björn Roy Baron, Boqun Feng, Daniel Almeida,
Danilo Krummrich, Gary Guo, Miguel Ojeda, Onur Özkan,
Robin Murphy, Shuah Khan, Tamir Duberstein, Trevor Gross,
linux-kernel, rust-for-linux, iommu, linux-kernel-mentees
On Sun Jun 28, 2026 at 7:31 AM -03, Miguel Ojeda wrote:
> On Sat, Jun 27, 2026 at 10:35 AM Alexandre Courbot <acourbot@nvidia.com> wrote:
>>
>> Note that you can also use `..Zeroable::zeroed()` here since we are not
>> in const context. Not sure which one we prefer in this case, but I'd
>> personally err on the side of not referring to `pin_init` unless we are
>> dealing with a pinned object or need to because of a const requirement.
>
> That sounds reasonable -- Benno/Gary, any comments?
>
> By the way, speaking of that: the docs of `zeroed()` (both of them)
> could mention the existence of the other (and the `const fn`
> difference).
If it is ok, I can send a patch modifying the doc comments to link both
functions, noting that the const version should be used in const
contexts/pinned objects and that `Zeroable::zeroed()` should be
preferred when possible (as Gary commented in [1]).
I'll send a v2 with `..Zeroable::zeroed()` shortly.
Thank you all for the comments!
[1] https://lore.kernel.org/rust-for-linux/DJKV3IQ0SXA1.30T5Y71AL6KV7@garyguo.net/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] rust: iommu: replace core::mem::zeroed with pin_init::zeroed
2026-06-29 19:45 ` Nicolás Antinori
@ 2026-06-29 19:51 ` Miguel Ojeda
0 siblings, 0 replies; 6+ messages in thread
From: Miguel Ojeda @ 2026-06-29 19:51 UTC (permalink / raw)
To: Nicolás Antinori
Cc: Alexandre Courbot, Benno Lossin, Gary Guo, Joerg Roedel,
Will Deacon, Alice Ryhl, Andreas Hindborg, Björn Roy Baron,
Boqun Feng, Daniel Almeida, Danilo Krummrich, Gary Guo,
Miguel Ojeda, Onur Özkan, Robin Murphy, Shuah Khan,
Tamir Duberstein, Trevor Gross, linux-kernel, rust-for-linux,
iommu, linux-kernel-mentees
On Mon, Jun 29, 2026 at 9:46 PM Nicolás Antinori
<nico.antinori.7@gmail.com> wrote:
>
> If it is ok, I can send a patch modifying the doc comments to link both
> functions, noting that the const version should be used in const
> contexts/pinned objects and that `Zeroable::zeroed()` should be
> preferred when possible (as Gary commented in [1]).
Of course, please always feel free to send a patch (it depends if the
maintainers end up accepting it, in this case Benno/Gary, but sending
is OK :)
You can also send it as a PR to the pin-init repository -- I think
they still accept both patches here and PRs there, but a PR there may
be easier for them.
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-06-29 19:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-26 20:31 [PATCH] rust: iommu: replace core::mem::zeroed with pin_init::zeroed Nicolás Antinori
2026-06-27 8:34 ` Alexandre Courbot
2026-06-28 10:31 ` Miguel Ojeda
2026-06-28 17:34 ` Gary Guo
2026-06-29 19:45 ` Nicolás Antinori
2026-06-29 19:51 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox