Skip to contentSkip to conversation

FAILED: patch "[PATCH] rust: init: fix `Zeroable` implementation for" failed to apply to 6.6-stable tree

PATCH In review [email protected] 5 participants 10 messages Mar 16, 2025 – Mar 18, 2025

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x df27cef153603b18a7d094b53cc3d5264ff32797
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025031635-resent-sniff-676f@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From df27cef153603b18a7d094b53cc3d5264ff32797 Mon Sep 17 00:00:00 2001
From: Benno Lossin <[email protected]>
Date: Wed, 5 Mar 2025 13:29:01 +0000
Subject: [PATCH] rust: init: fix Zeroable implementation for
Option<NonNull<T>> and Option<KBox<T>>

According to [1], NonNull<T> and #[repr(transparent)] wrapper types such as our custom KBox<T> have the null pointer optimization only if T: Sized. Thus remove the Zeroable implementation for the unsized case.

Cc [email protected] # v6.12+ (a custom patch will be needed for 6.6.y)
Fixes 38cde0bd7b67 ("rust: init: add `Zeroable` trait and `init::zeroed` function")
[ Added Closes tag and moved up the Reported-by one. - Miguel ]
rust/kernel/init.rs +4 -7
index 7fd1ea8265a5..8bbd5e3398fc 100644
@@ -1418,17 +1418,14 @@ macro_rules! impl_zeroable {
     // SAFETY: `T: Zeroable` and `UnsafeCell` is `repr(transparent)`.
     {<T: ?Sized + Zeroable>} UnsafeCell<T>,
 
-    // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee).
+    // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee:
+    // https://doc.rust-lang.org/stable/std/option/index.html#representation).
     Option<NonZeroU8>, Option<NonZeroU16>, Option<NonZeroU32>, Option<NonZeroU64>,
     Option<NonZeroU128>, Option<NonZeroUsize>,
     Option<NonZeroI8>, Option<NonZeroI16>, Option<NonZeroI32>, Option<NonZeroI64>,
     Option<NonZeroI128>, Option<NonZeroIsize>,
-
-    // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee).
-    //
-    // In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant.
-    {<T: ?Sized>} Option<NonNull<T>>,
-    {<T: ?Sized>} Option<KBox<T>>,
+    {<T>} Option<NonNull<T>>,
+    {<T>} Option<KBox<T>>,
 
     // SAFETY: `null` pointer is valid.
     //
maintainer
#1 lore raw

PATCH 1/1 rust: init: fix `Zeroable` implementation for `Option<NonNull<T>>` and `Option<Box<T>>`

From: Benno Lossin <[email protected]>

commit df27cef153603b18a7d094b53cc3d5264ff32797 upstream.

According to [1], NonNull<T> and #[repr(transparent)] wrapper types such as Box<T> have the null pointer optimization only if T: Sized. Thus remove the Zeroable implementation for the unsized case.

Cc [email protected] # v6.12+ (a custom patch will be needed for 6.6.y)
Fixes 38cde0bd7b67 ("rust: init: add `Zeroable` trait and `init::zeroed` function")
[ Added Closes tag and moved up the Reported-by one. - Miguel ]
---
 rust/kernel/init.rs | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
rust/kernel/init.rs +4 -7
index 2d4b19b86857..6ef9f6182018 100644
@@ -1310,17 +1310,14 @@ macro_rules! impl_zeroable {
     // SAFETY: `T: Zeroable` and `UnsafeCell` is `repr(transparent)`.
     {<T: ?Sized + Zeroable>} UnsafeCell<T>,
 
-    // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee).
+    // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee:
+    // https://doc.rust-lang.org/stable/std/option/index.html#representation).
     Option<NonZeroU8>, Option<NonZeroU16>, Option<NonZeroU32>, Option<NonZeroU64>,
     Option<NonZeroU128>, Option<NonZeroUsize>,
     Option<NonZeroI8>, Option<NonZeroI16>, Option<NonZeroI32>, Option<NonZeroI64>,
     Option<NonZeroI128>, Option<NonZeroIsize>,
-
-    // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee).
-    //
-    // In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant.
-    {<T: ?Sized>} Option<NonNull<T>>,
-    {<T: ?Sized>} Option<Box<T>>,
+    {<T>} Option<NonNull<T>>,
+    {<T>} Option<Box<T>>,
 
     // SAFETY: `null` pointer is valid.
     //
Signature · 1 line
2.49.0
#2 lore raw

Re: [PATCH 6.6.y] rust: init: fix `Zeroable` implementation for `Option<NonNull<T>>` and `Option<Box<T>>`

Quoted 2 lines · Miguel Ojeda

[ Added Closes tag and moved up the Reported-by one. - Miguel ]

Note that this is the note of the original commit -- for the actual backport, I changed KBox to Box, and edited the title and the log accordingly.

I can add [ ] for the backport changes itself in the future, if that helps.

Cheers,
Miguel

#3 lore raw

Re: [PATCH 6.6.y] rust: init: fix `Zeroable` implementation for `Option<NonNull<T>>` and `Option<Box<T>>`

Quoted 9 lines · Miguel Ojeda
Quoted 2 lines · Miguel Ojeda

[ Added Closes tag and moved up the Reported-by one. - Miguel ]

Note that this is the note of the original commit -- for the actual backport, I changed KBox to Box, and edited the title and the log accordingly.

I can add [ ] for the backport changes itself in the future, if that helps.

In the future, sure, that would help. Don't worry about it this time.

greg k-h

#4 lore raw

Re: [PATCH 6.6.y] rust: init: fix `Zeroable` implementation for `Option<NonNull<T>>` and `Option<Box<T>>`

Quoted 2 lines · Greg KH

In the future, sure, that would help. Don't worry about it this time.

Sounds good, thanks!

In stable-rc I see the original title/message used, is that expected?

Cheers,
Miguel

#5 lore raw

Re: [PATCH 6.6.y] rust: init: fix `Zeroable` implementation for `Option<NonNull<T>>` and `Option<Box<T>>`

Quoted 7 lines · Miguel Ojeda
Quoted 2 lines · Greg KH

In the future, sure, that would help. Don't worry about it this time.

Sounds good, thanks!

In stable-rc I see the original title/message used, is that expected?

I didn't notice that you changed the title, so yes, it's expected as the tool takes what you send and picks out the diff portion, and leaves the changelog text alone (unless you add some more lines).

Why did the title change? That's just going to confuse things.

thanks,

greg k-h

#6 lore raw

Re: [PATCH 6.6.y] rust: init: fix `Zeroable` implementation for `Option<NonNull<T>>` and `Option<Box<T>>`

Quoted 4 lines · Greg KH

I didn't notice that you changed the title, so yes, it's expected as the tool takes what you send and picks out the diff portion, and leaves the changelog text alone (unless you add some more lines).

I mentioned it in the message above, but not just the title changed, the message too.

Quoted 1 line

Why did the title change? That's just going to confuse things.

The reason is that KBox does not exist in 6.6.y. The fix still applies, though, and is the same fix for Box.

So I reworded accordingly: I renamed KBox and Box in the title and the message (and touched a bit the message to remove "custom" since in 6.6.y it is essentially the standard library one).

I hope that clarifies.

Cheers,
Miguel

#7 lore raw

Re: [PATCH 6.6.y] rust: init: fix `Zeroable` implementation for `Option<NonNull<T>>` and `Option<Box<T>>`

Quoted 2 lines · Miguel Ojeda

So I reworded accordingly: I renamed KBox and Box in the title and

s/and/to/

Anyway, if the policy is to keep titles and original log intact even in Option 3, I assume one should avoid [ ] comments in the log, and only use the one-line-before-my-SoB style for [ ], since I assume you keep the tags.

Cheers,
Miguel

#8 lore raw

Re: [PATCH 6.6.y] rust: init: fix `Zeroable` implementation for `Option<NonNull<T>>` and `Option<Box<T>>`

Quoted 11 lines · Miguel Ojeda
Quoted 2 lines · Miguel Ojeda

So I reworded accordingly: I renamed KBox and Box in the title and

s/and/to/

Anyway, if the policy is to keep titles and original log intact even in Option 3, I assume one should avoid [ ] comments in the log, and only use the one-line-before-my-SoB style for [ ], since I assume you keep the tags.

Yeah, that is good, but really it's not that big of a deal, we can parse text pretty easily and handle it when it's not "perfect" :)

greg k-h

maintainer
#9 lore raw

Re: [PATCH 6.6.y] rust: init: fix `Zeroable` implementation for `Option<NonNull<T>>` and `Option<Box<T>>`

In reply to Miguel Ojeda

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected. No action required from the submitter.

The upstream commit SHA1 provided is correct: df27cef153603b18a7d094b53cc3d5264ff32797

WARNING: Author mismatch between patch and upstream commit:
Backport author: Miguel Ojeda<[email protected]> Commit author: Benno Lossin<[email protected]>

Status in newer kernel trees:
6.13.y | Present (different SHA1: 1a1d0545f7a5)
6.12.y | Present (different SHA1: 0d876a8ae2cb)

Note: The patch differs from the upstream commit:
---
1: df27cef153603 ! 1: f87fa26b09a1f rust: init: fix Zeroable implementation for Option<NonNull<T>> and Option<KBox<T>>
@@ Metadata
Author: Benno Lossin <[email protected]>

## Commit message ##
- rust: init: fix Zeroable implementation for Option<NonNull<T>> and Option<KBox<T>>
+ rust: init: fix Zeroable implementation for Option<NonNull<T>> and Option<Box<T>>
+
+ commit df27cef153603b18a7d094b53cc3d5264ff32797 upstream.

According to [1], NonNull<T> and #[repr(transparent)] wrapper types
- such as our custom KBox<T> have the null pointer optimization only if
- T: Sized. Thus remove the Zeroable implementation for the unsized
- case.
+ such as Box<T> have the null pointer optimization only if T: Sized.
+ Thus remove the Zeroable implementation for the unsized case.

@@ rust/kernel/init.rs: macro_rules! impl_zeroable {
- //
- // In this case we are allowed to use T: ?Sized, since all zeros is the None variant.
- {<T: ?Sized>} Option<NonNull<T>>,
-- {<T: ?Sized>} Option<KBox<T>>,
+- {<T: ?Sized>} Option<Box<T>>,
+ {<T>} Option<NonNull<T>>,
-+ {<T>} Option<KBox<T>>,
++ {<T>} Option<Box<T>>,

// SAFETY: null pointer is valid.
//
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.6.y        |  Success    |  Success   |