linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: cpumask: Mark CpumaskVar as transparent
@ 2025-08-12 14:42 Baptiste Lepers
  2025-08-13  7:40 ` Alice Ryhl
  2025-08-14  4:26 ` Viresh Kumar
  0 siblings, 2 replies; 3+ messages in thread
From: Baptiste Lepers @ 2025-08-12 14:42 UTC (permalink / raw)
  Cc: Baptiste Lepers, stable, Viresh Kumar, Yury Norov, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, rust-for-linux, linux-kernel

Unsafe code in CpumaskVar's methods assumes that the type has the same
layout as `bindings::cpumask_var_t`. This is not guaranteed by
the default struct representation in Rust, but requires specifying the
`transparent` representation.

Fixes: 8961b8cb3099a ("rust: cpumask: Add initial abstractions")
Cc: stable@vger.kernel.org
Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>
---
 rust/kernel/cpumask.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rust/kernel/cpumask.rs b/rust/kernel/cpumask.rs
index 3fcbff438670..05e1c882404e 100644
--- a/rust/kernel/cpumask.rs
+++ b/rust/kernel/cpumask.rs
@@ -212,6 +212,7 @@ pub fn copy(&self, dstp: &mut Self) {
 /// }
 /// assert_eq!(mask2.weight(), count);
 /// ```
+#[repr(transparent)]
 pub struct CpumaskVar {
     #[cfg(CONFIG_CPUMASK_OFFSTACK)]
     ptr: NonNull<Cpumask>,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: cpumask: Mark CpumaskVar as transparent
  2025-08-12 14:42 [PATCH] rust: cpumask: Mark CpumaskVar as transparent Baptiste Lepers
@ 2025-08-13  7:40 ` Alice Ryhl
  2025-08-14  4:26 ` Viresh Kumar
  1 sibling, 0 replies; 3+ messages in thread
From: Alice Ryhl @ 2025-08-13  7:40 UTC (permalink / raw)
  To: Baptiste Lepers
  Cc: stable, Viresh Kumar, Yury Norov, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich, rust-for-linux,
	linux-kernel

On Tue, Aug 12, 2025 at 4:42 PM Baptiste Lepers
<baptiste.lepers@gmail.com> wrote:
>
> Unsafe code in CpumaskVar's methods assumes that the type has the same
> layout as `bindings::cpumask_var_t`. This is not guaranteed by
> the default struct representation in Rust, but requires specifying the
> `transparent` representation.
>
> Fixes: 8961b8cb3099a ("rust: cpumask: Add initial abstractions")
> Cc: stable@vger.kernel.org
> Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>

Only during CONFIG_CPUMASK_OFFSTACK=n, but yes.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: cpumask: Mark CpumaskVar as transparent
  2025-08-12 14:42 [PATCH] rust: cpumask: Mark CpumaskVar as transparent Baptiste Lepers
  2025-08-13  7:40 ` Alice Ryhl
@ 2025-08-14  4:26 ` Viresh Kumar
  1 sibling, 0 replies; 3+ messages in thread
From: Viresh Kumar @ 2025-08-14  4:26 UTC (permalink / raw)
  To: Baptiste Lepers
  Cc: stable, Yury Norov, Miguel Ojeda, Alex Gaynor, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, rust-for-linux,
	linux-kernel

On 12-08-25, 16:42, Baptiste Lepers wrote:
> Unsafe code in CpumaskVar's methods assumes that the type has the same
> layout as `bindings::cpumask_var_t`. This is not guaranteed by
> the default struct representation in Rust, but requires specifying the
> `transparent` representation.
> 
> Fixes: 8961b8cb3099a ("rust: cpumask: Add initial abstractions")
> Cc: stable@vger.kernel.org
> Signed-off-by: Baptiste Lepers <baptiste.lepers@gmail.com>
> ---
>  rust/kernel/cpumask.rs | 1 +
>  1 file changed, 1 insertion(+)

Applied. Thanks.

-- 
viresh

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-14  4:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12 14:42 [PATCH] rust: cpumask: Mark CpumaskVar as transparent Baptiste Lepers
2025-08-13  7:40 ` Alice Ryhl
2025-08-14  4:26 ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).