* [PATCH v3] rust: Add support for feeding entropy to randomness pool
@ 2025-12-26 19:15 Matthew Maurer
2025-12-28 7:50 ` Alexandre Courbot
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Matthew Maurer @ 2025-12-26 19:15 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich
Cc: linux-kernel, rust-for-linux, Matthew Maurer
Adds just enough support to allow device drivers to feed entropy to the
central pool.
Signed-off-by: Matthew Maurer <mmaurer@google.com>
---
Changes in v3:
- Fixed doclink to be srctree-based instead of relative.
- Switched to prelude import instead of fine-grained imports.
- Link to v2: https://lore.kernel.org/r/20251216-add-entropy-v2-1-4d866f251474@google.com
Changes in v2:
- Added more details in the docs about the API, specifically about it
not crediting entropy and when it ought to be used.
- Link to v1: https://lore.kernel.org/r/20251212-add-entropy-v1-1-e70ad1bc9c65@google.com
---
rust/kernel/lib.rs | 1 +
rust/kernel/rand.rs | 18 ++++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index f812cf12004286962985a068665443dc22c389a2..bf64752d276b0bdea06ac0de8a5e219190129377 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -130,6 +130,7 @@
pub mod ptr;
#[cfg(CONFIG_RUST_PWM_ABSTRACTIONS)]
pub mod pwm;
+pub mod rand;
pub mod rbtree;
pub mod regulator;
pub mod revocable;
diff --git a/rust/kernel/rand.rs b/rust/kernel/rand.rs
new file mode 100644
index 0000000000000000000000000000000000000000..3e0aef2f53af122f510b34c4743a20452aaad9ad
--- /dev/null
+++ b/rust/kernel/rand.rs
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Randomness.
+//!
+//! C header: [`include/linux/random.h`](srctree/include/linux/random.h)
+
+use crate::prelude::*;
+
+/// Adds the given buffer to the entropy pool, but does not credit any entropy.
+///
+/// This is intended for use mixing in data that is likely to differ between devices or boots, but
+/// may otherwise be predictable. Examples include MAC addresses or RTC values. This slightly
+/// improves randomness in entropy-constrained environments (especially common for embedded
+/// devices).
+pub fn add_device_randomness(buf: &[u8]) {
+ // SAFETY: We just need the pointer to be valid for the length, which a slice provides.
+ unsafe { bindings::add_device_randomness(buf.as_ptr().cast::<c_void>(), buf.len()) };
+}
---
base-commit: 008d3547aae5bc86fac3eda317489169c3fda112
change-id: 20251029-add-entropy-f57e12ebe110
Best regards,
--
Matthew Maurer <mmaurer@google.com>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3] rust: Add support for feeding entropy to randomness pool
2025-12-26 19:15 [PATCH v3] rust: Add support for feeding entropy to randomness pool Matthew Maurer
@ 2025-12-28 7:50 ` Alexandre Courbot
2025-12-28 9:13 ` Brendan Shephard
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Alexandre Courbot @ 2025-12-28 7:50 UTC (permalink / raw)
To: Matthew Maurer, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich
Cc: linux-kernel, rust-for-linux
On Sat Dec 27, 2025 at 4:15 AM JST, Matthew Maurer wrote:
> Adds just enough support to allow device drivers to feed entropy to the
> central pool.
>
> Signed-off-by: Matthew Maurer <mmaurer@google.com>
> ---
> Changes in v3:
> - Fixed doclink to be srctree-based instead of relative.
> - Switched to prelude import instead of fine-grained imports.
> - Link to v2: https://lore.kernel.org/r/20251216-add-entropy-v2-1-4d866f251474@google.com
>
> Changes in v2:
> - Added more details in the docs about the API, specifically about it
> not crediting entropy and when it ought to be used.
> - Link to v1: https://lore.kernel.org/r/20251212-add-entropy-v1-1-e70ad1bc9c65@google.com
> ---
> rust/kernel/lib.rs | 1 +
> rust/kernel/rand.rs | 18 ++++++++++++++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
> index f812cf12004286962985a068665443dc22c389a2..bf64752d276b0bdea06ac0de8a5e219190129377 100644
> --- a/rust/kernel/lib.rs
> +++ b/rust/kernel/lib.rs
> @@ -130,6 +130,7 @@
> pub mod ptr;
> #[cfg(CONFIG_RUST_PWM_ABSTRACTIONS)]
> pub mod pwm;
> +pub mod rand;
> pub mod rbtree;
> pub mod regulator;
> pub mod revocable;
> diff --git a/rust/kernel/rand.rs b/rust/kernel/rand.rs
> new file mode 100644
> index 0000000000000000000000000000000000000000..3e0aef2f53af122f510b34c4743a20452aaad9ad
> --- /dev/null
> +++ b/rust/kernel/rand.rs
> @@ -0,0 +1,18 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +//! Randomness.
Let's promote this comment to a sentence at least. :)
> +//!
> +//! C header: [`include/linux/random.h`](srctree/include/linux/random.h)
> +
> +use crate::prelude::*;
> +
> +/// Adds the given buffer to the entropy pool, but does not credit any entropy.
> +///
> +/// This is intended for use mixing in data that is likely to differ between devices or boots, but
Not a native speaker, but "use mixing" sounds a bit off?
With this, and fwiw,
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] rust: Add support for feeding entropy to randomness pool
2025-12-26 19:15 [PATCH v3] rust: Add support for feeding entropy to randomness pool Matthew Maurer
2025-12-28 7:50 ` Alexandre Courbot
@ 2025-12-28 9:13 ` Brendan Shephard
2025-12-30 17:47 ` Matthew Maurer
2025-12-28 9:40 ` Alice Ryhl
2025-12-30 13:54 ` Kari Argillander
3 siblings, 1 reply; 7+ messages in thread
From: Brendan Shephard @ 2025-12-28 9:13 UTC (permalink / raw)
To: Matthew Maurer
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, linux-kernel, rust-for-linux
On Fri, Dec 26, 2025 at 07:15:10PM +0000, Matthew Maurer wrote:
> +/// Adds the given buffer to the entropy pool, but does not credit any entropy.
> +///
> +/// This is intended for use mixing in data that is likely to differ between devices or boots, but
Yeah, I agree with Alexandre here. I think this would probably be better
written as: "This function mixes in data that is likely to differ between
devices or boots". Or, "add_device_randomness mixes in data that is
likely to differ between devices or boots." If you would prefer to avoid
saying "this function".
> +/// may otherwise be predictable. Examples include MAC addresses or RTC values. This slightly
> +/// improves randomness in entropy-constrained environments (especially common for embedded
> +/// devices).
> +pub fn add_device_randomness(buf: &[u8]) {
> + // SAFETY: We just need the pointer to be valid for the length, which a slice provides.
> + unsafe { bindings::add_device_randomness(buf.as_ptr().cast::<c_void>(), buf.len()) };
> +}
>
> ---
> base-commit: 008d3547aae5bc86fac3eda317489169c3fda112
> change-id: 20251029-add-entropy-f57e12ebe110
>
> Best regards,
> --
> Matthew Maurer <mmaurer@google.com>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] rust: Add support for feeding entropy to randomness pool
2025-12-26 19:15 [PATCH v3] rust: Add support for feeding entropy to randomness pool Matthew Maurer
2025-12-28 7:50 ` Alexandre Courbot
2025-12-28 9:13 ` Brendan Shephard
@ 2025-12-28 9:40 ` Alice Ryhl
2025-12-30 13:54 ` Kari Argillander
3 siblings, 0 replies; 7+ messages in thread
From: Alice Ryhl @ 2025-12-28 9:40 UTC (permalink / raw)
To: Matthew Maurer
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
linux-kernel, rust-for-linux
On Fri, Dec 26, 2025 at 07:15:10PM +0000, Matthew Maurer wrote:
> Adds just enough support to allow device drivers to feed entropy to the
> central pool.
>
> Signed-off-by: Matthew Maurer <mmaurer@google.com>
Modulo doc suggestions from other reviews:
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] rust: Add support for feeding entropy to randomness pool
2025-12-26 19:15 [PATCH v3] rust: Add support for feeding entropy to randomness pool Matthew Maurer
` (2 preceding siblings ...)
2025-12-28 9:40 ` Alice Ryhl
@ 2025-12-30 13:54 ` Kari Argillander
2025-12-30 17:42 ` Matthew Maurer
3 siblings, 1 reply; 7+ messages in thread
From: Kari Argillander @ 2025-12-30 13:54 UTC (permalink / raw)
To: Matthew Maurer
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, linux-kernel, rust-for-linux
On Fri, 26 Dec 2025 at 21:15, Matthew Maurer <mmaurer@google.com> wrote:
> diff --git a/rust/kernel/rand.rs b/rust/kernel/rand.rs
> new file mode 100644
> index 0000000000000000000000000000000000000000..3e0aef2f53af122f510b34c4743a20452aaad9ad
> --- /dev/null
> +++ b/rust/kernel/rand.rs
> @@ -0,0 +1,18 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +//! Randomness.
> +//!
> +//! C header: [`include/linux/random.h`](srctree/include/linux/random.h)
So why rand and not random? If there is good reason to not use random.rs then
can you add that reason to commit message.
Argillander
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] rust: Add support for feeding entropy to randomness pool
2025-12-30 13:54 ` Kari Argillander
@ 2025-12-30 17:42 ` Matthew Maurer
0 siblings, 0 replies; 7+ messages in thread
From: Matthew Maurer @ 2025-12-30 17:42 UTC (permalink / raw)
To: Kari Argillander
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, linux-kernel, rust-for-linux
On Tue, Dec 30, 2025 at 5:54 AM Kari Argillander
<kari.argillander@gmail.com> wrote:
>
> On Fri, 26 Dec 2025 at 21:15, Matthew Maurer <mmaurer@google.com> wrote:
> > diff --git a/rust/kernel/rand.rs b/rust/kernel/rand.rs
> > new file mode 100644
> > index 0000000000000000000000000000000000000000..3e0aef2f53af122f510b34c4743a20452aaad9ad
> > --- /dev/null
> > +++ b/rust/kernel/rand.rs
> > @@ -0,0 +1,18 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +//! Randomness.
> > +//!
> > +//! C header: [`include/linux/random.h`](srctree/include/linux/random.h)
>
> So why rand and not random? If there is good reason to not use random.rs then
> can you add that reason to commit message.
I have no reason for rand over random and no strong preference. I'll
switch it to `random` in the next rev unless someone else chimes in.
>
> Argillander
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] rust: Add support for feeding entropy to randomness pool
2025-12-28 9:13 ` Brendan Shephard
@ 2025-12-30 17:47 ` Matthew Maurer
0 siblings, 0 replies; 7+ messages in thread
From: Matthew Maurer @ 2025-12-30 17:47 UTC (permalink / raw)
To: Brendan Shephard
Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, linux-kernel, rust-for-linux
On Sun, Dec 28, 2025 at 1:13 AM Brendan Shephard <bshephar@bne-home.net> wrote:
>
> On Fri, Dec 26, 2025 at 07:15:10PM +0000, Matthew Maurer wrote:
> > +/// Adds the given buffer to the entropy pool, but does not credit any entropy.
> > +///
> > +/// This is intended for use mixing in data that is likely to differ between devices or boots, but
> Yeah, I agree with Alexandre here. I think this would probably be better
> written as: "This function mixes in data that is likely to differ between
> devices or boots". Or, "add_device_randomness mixes in data that is
> likely to differ between devices or boots." If you would prefer to avoid
> saying "this function".
I believe the grammar to be correct here - if it helps, the "use" in
this case is the "yoos" variant of use, not the "yooz" variant.
That said, if it's confusing, it's confusing. I'll reword it as suggested.
> > +/// may otherwise be predictable. Examples include MAC addresses or RTC values. This slightly
> > +/// improves randomness in entropy-constrained environments (especially common for embedded
> > +/// devices).
> > +pub fn add_device_randomness(buf: &[u8]) {
> > + // SAFETY: We just need the pointer to be valid for the length, which a slice provides.
> > + unsafe { bindings::add_device_randomness(buf.as_ptr().cast::<c_void>(), buf.len()) };
> > +}
> >
> > ---
> > base-commit: 008d3547aae5bc86fac3eda317489169c3fda112
> > change-id: 20251029-add-entropy-f57e12ebe110
> >
> > Best regards,
> > --
> > Matthew Maurer <mmaurer@google.com>
> >
> >
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-12-30 17:47 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-26 19:15 [PATCH v3] rust: Add support for feeding entropy to randomness pool Matthew Maurer
2025-12-28 7:50 ` Alexandre Courbot
2025-12-28 9:13 ` Brendan Shephard
2025-12-30 17:47 ` Matthew Maurer
2025-12-28 9:40 ` Alice Ryhl
2025-12-30 13:54 ` Kari Argillander
2025-12-30 17:42 ` Matthew Maurer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox