Skip to contentSkip to conversation

error[E0277]: `*const kernel::bindings::vm_uffd_ops` cannot be shared between threads safely

PATCH In review kernel test robot 6 participants 13 messages Mar 12 – Mar 31

Subsystems (3)
lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   f90aadf1c67c8b4969d1e5e6d4fd7227adb6e4d7
commit: 9ef1985c003ea271369c900a93f8b834119fd150 [5585/5731] Merge branch 'mm-unstable' of https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
config: x86_64-randconfig-002-20260312 (https://download.01.org/0day-ci/archive/20260312/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260312/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> error[E0277]: `*const kernel::bindings::vm_uffd_ops` cannot be shared between threads safely

--> drivers/android/binder/page_range.rs:146:23
|
146 | static BINDER_VM_OPS: bindings::vm_operations_struct = pin_init::zeroed();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *const kernel::bindings::vm_uffd_ops cannot be shared between threads safely
|
= help: within kernel::bindings::vm_operations_struct, the trait Sync is not implemented for *const kernel::bindings::vm_uffd_ops
note: required because it appears within the type kernel::bindings::vm_operations_struct
--> rust/bindings/bindings_generated.rs:72795:12
|
72795 | pub struct vm_operations_struct {
| ^^^^^^^^^^^^^^^^^^^^
= note: shared static variables must have a type that implements Sync

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#1 lore raw

+ relevant parties

Quoted 18 lines · kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   f90aadf1c67c8b4969d1e5e6d4fd7227adb6e4d7
commit: 9ef1985c003ea271369c900a93f8b834119fd150 [5585/5731] Merge branch 'mm-unstable' of https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
config: x86_64-randconfig-002-20260312 (https://download.01.org/0day-ci/archive/20260312/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260312/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

Quoted 1 line
Quoted 1 line

error[E0277]: *const kernel::bindings::vm_uffd_ops cannot be shared between threads safely

--> drivers/android/binder/page_range.rs:146:23 |

Quoted 10 lines
   146   | static BINDER_VM_OPS: bindings::vm_operations_struct = pin_init::zeroed();
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const kernel::bindings::vm_uffd_ops` cannot be shared between threads safely
   |
   = help: within `kernel::bindings::vm_operations_struct`, the trait `Sync` is not implemented for `*const kernel::bindings::vm_uffd_ops`
   note: required because it appears within the type `kernel::bindings::vm_operations_struct`
   --> rust/bindings/bindings_generated.rs:72795:12
   |
   72795 | pub struct vm_operations_struct {
   |            ^^^^^^^^^^^^^^^^^^^^
   = note: shared static variables must have a type that implements `Sync`

I see this in next-20260313 still.

  $ cat kernel/configs/repro.config
  CONFIG_RUST=y
  CONFIG_ANDROID_BINDER_IPC_RUST=y
  CONFIG_USERFAULTFD=y
  $ make -skj"$(nproc)" ARCH=x86_64 LLVM=1 mrproper defconfig repro.config drivers/android/binder/rust_binder_main.o
  error[E0277]: `*const kernel::bindings::vm_uffd_ops` cannot be shared between threads safely
       --> drivers/android/binder/page_range.rs:146:23
        |
    146 | static BINDER_VM_OPS: bindings::vm_operations_struct = pin_init::zeroed();
        |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const kernel::bindings::vm_uffd_ops` cannot be shared between threads safely
        |
        = help: within `kernel::bindings::vm_operations_struct`, the trait `Sync` is not implemented for `*const kernel::bindings::vm_uffd_ops`
  note: required because it appears within the type `kernel::bindings::vm_operations_struct`
       --> rust/bindings/bindings_generated.rs:71347:12
        |
  71347 | pub struct vm_operations_struct {
        |            ^^^^^^^^^^^^^^^^^^^^
        = note: shared static variables must have a type that implements `Sync`

error: aborting due to 1 previous error

For more information about this error, try rustc --explain E0277.
...

It looks like this is a conflict between Alice's "rust_binder: check ownership before using vma" [1] (currently in char-misc-linus [2]) and Mike's "userfaultfd: introduce vm_uffd_ops" [3] (currently in mm-unstable [4]), hence why it was bisected to the -next merge commit.

[1]: https://lore.kernel.org/[email protected]/
[2]: https://git.kernel.org/gregkh/char-misc/c/8ef2c15aeae07647f530d30f6daaf79eb801bcd1
[3]: https://lore.kernel.org/[email protected]/
[4]: https://git.kernel.org/akpm/mm/c/52b7ee1715b88c61fe0696db31ac90181999ec2e

Cheers,
Nathan

#2 lore raw
Quoted 5 lines · Nathan Chancellor

It looks like this is a conflict between Alice's "rust_binder: check ownership before using vma" [1] (currently in char-misc-linus [2]) and Mike's "userfaultfd: introduce vm_uffd_ops" [3] (currently in mm-unstable [4]), hence why it was bisected to the -next merge commit.

Thanks Nathan, yeah, adding a raw pointer (not function pointer) to the struct makes the type !Sync in Rust.

I assume this is best handled with a patch on top of char-misc-linus. Perhaps creating a wrapper to assert it is Sync, since the BINDER_VM_OPS contents are unused (so far).

Cc'ing more folks related to the commit.

Cheers,
Miguel

#3 lore raw
Quoted 7 lines · Miguel Ojeda
Quoted 5 lines · Nathan Chancellor

It looks like this is a conflict between Alice's "rust_binder: check ownership before using vma" [1] (currently in char-misc-linus [2]) and Mike's "userfaultfd: introduce vm_uffd_ops" [3] (currently in mm-unstable [4]), hence why it was bisected to the -next merge commit.

Quoted 8 lines

Thanks Nathan, yeah, adding a raw pointer (not function pointer) to the struct makes the type !Sync in Rust.

I assume this is best handled with a patch on top of char-misc-linus. Perhaps creating a wrapper to assert it is Sync, since the BINDER_VM_OPS contents are unused (so far).

Cc'ing more folks related to the commit.

char-misc-linus should get merged into Linus's tree "soon" and then we can fix up the mm-unstable change for this.

thanks,

greg k-h

maintainer
#4 lore raw
Quoted 12 lines · Greg Kroah-Hartman
Quoted 10 lines · Miguel Ojeda
Quoted 5 lines · Nathan Chancellor

It looks like this is a conflict between Alice's "rust_binder: check ownership before using vma" [1] (currently in char-misc-linus [2]) and Mike's "userfaultfd: introduce vm_uffd_ops" [3] (currently in mm-unstable [4]), hence why it was bisected to the -next merge commit.

Thanks Nathan, yeah, adding a raw pointer (not function pointer) to the struct makes the type !Sync in Rust.

Quoted 8 lines
Quoted 5 lines

I assume this is best handled with a patch on top of char-misc-linus. Perhaps creating a wrapper to assert it is Sync, since the BINDER_VM_OPS contents are unused (so far).

Cc'ing more folks related to the commit.

char-misc-linus should get merged into Linus's tree "soon" and then we can fix up the mm-unstable change for this.

I'm working on the fix as we speak. It would be ideal if it went into char-misc-linus, because the commit that is wrong is mine, not the one in mm.

Alice

maintainer
#5 lore raw

PATCH 1/1 rust_binder: use AssertSync for BINDER_VM_OPS

When declaring an immutable global variable in Rust, the compiler checks that it looks thread safe, because it is generally safe to access said global variable. When using C bindings types for these globals, we don't really want this check, because it is conservative and assumes pointers are not thread safe.

In the case of BINDER_VM_OPS, this is a challenge when combined with the patch 'userfaultfd: introduce vm_uffd_ops' [1], which introduces a pointer field to vm_operations_struct. It previously only held function pointers, which are considered thread safe.

Rust Binder should not be assuming that vm_operations_struct contains no pointer fields, so to fix this, use AssertSync (which Rust Binder has already declared for another similar global of type struct file_operations with the same problem). This ensures that even if another commit adds a pointer field to vm_operations_struct, this does not cause problems.

---
 drivers/android/binder/page_range.rs       | 8 +++++---
 drivers/android/binder/rust_binder_main.rs | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/android/binder/page_range.rs +5 -3
index 9dfc154e5dd4..b57e0c7ba3f1 100644
@@ -13,6 +13,8 @@
 //
 // The shrinker will use trylock methods because it locks them in a different order.
 
+use crate::AssertSync;
+
 use core::{
     marker::PhantomPinned,
     mem::{size_of, size_of_val, MaybeUninit},
@@ -143,14 +145,14 @@ pub(crate) struct ShrinkablePageRange {
 }
 
 // We do not define any ops. For now, used only to check identity of vmas.
-static BINDER_VM_OPS: bindings::vm_operations_struct = pin_init::zeroed();
+static BINDER_VM_OPS: AssertSync<bindings::vm_operations_struct> = AssertSync(pin_init::zeroed());
 
 // To ensure that we do not accidentally install pages into or zap pages from the wrong vma, we
 // check its vm_ops and private data before using it.
 fn check_vma(vma: &virt::VmaRef, owner: *const ShrinkablePageRange) -> Option<&virt::VmaMixedMap> {
     // SAFETY: Just reading the vm_ops pointer of any active vma is safe.
     let vm_ops = unsafe { (*vma.as_ptr()).vm_ops };
-    if !ptr::eq(vm_ops, &BINDER_VM_OPS) {
+    if !ptr::eq(vm_ops, &BINDER_VM_OPS.0) {
         return None;
     }
 
@@ -342,7 +344,7 @@ pub(crate) fn register_with_vma(&self, vma: &virt::VmaNew) -> Result<usize> {
 
         // SAFETY: We own the vma, and we don't use any methods on VmaNew that rely on
         // `vm_ops`.
-        unsafe { (*vma.as_ptr()).vm_ops = &BINDER_VM_OPS };
+        unsafe { (*vma.as_ptr()).vm_ops = &BINDER_VM_OPS.0 };
 
         Ok(num_pages)
     }
drivers/android/binder/rust_binder_main.rs +1 -1
index aa5f2a75adb4..014010662df8 100644
@@ -306,7 +306,7 @@ fn init(_module: &'static kernel::ThisModule) -> Result<Self> {
 /// Makes the inner type Sync.
 #[repr(transparent)]
 pub struct AssertSync<T>(T);
-// SAFETY: Used only to insert `file_operations` into a global, which is safe.
+// SAFETY: Used only to insert C bindings types into globals, which is safe.
 unsafe impl<T> Sync for AssertSync<T> {}
 
 /// File operations that rust_binderfs.c can use.

base-commit: a0b9b0f1433c845bda708753db32befef78e0f1f

Signature · 1 line
2.53.0.851.ga537e3e6e9-goog
reviewer Reviewed-by on v1 1/1
#6 lore raw

Re: [PATCH] rust_binder: use AssertSync for BINDER_VM_OPS

Quoted 18 lines · Alice Ryhl

When declaring an immutable global variable in Rust, the compiler checks that it looks thread safe, because it is generally safe to access said global variable. When using C bindings types for these globals, we don't really want this check, because it is conservative and assumes pointers are not thread safe.

In the case of BINDER_VM_OPS, this is a challenge when combined with the patch 'userfaultfd: introduce vm_uffd_ops' [1], which introduces a pointer field to vm_operations_struct. It previously only held function pointers, which are considered thread safe.

Rust Binder should not be assuming that vm_operations_struct contains no pointer fields, so to fix this, use AssertSync (which Rust Binder has already declared for another similar global of type struct file_operations with the same problem). This ensures that even if another commit adds a pointer field to vm_operations_struct, this does not cause problems.

Quoted 5 lines
Quoted 4 lines
---
 drivers/android/binder/page_range.rs       | 8 +++++---
 drivers/android/binder/rust_binder_main.rs | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)
maintainer
#7 lore raw
In reply to Alice Ryhl
Quoted 18 lines · Alice Ryhl
Quoted 16 lines · Greg Kroah-Hartman
Quoted 14 lines · Miguel Ojeda
Quoted 5 lines · Nathan Chancellor

It looks like this is a conflict between Alice's "rust_binder: check ownership before using vma" [1] (currently in char-misc-linus [2]) and Mike's "userfaultfd: introduce vm_uffd_ops" [3] (currently in mm-unstable [4]), hence why it was bisected to the -next merge commit.

Thanks Nathan, yeah, adding a raw pointer (not function pointer) to the struct makes the type !Sync in Rust.

I assume this is best handled with a patch on top of char-misc-linus. Perhaps creating a wrapper to assert it is Sync, since the BINDER_VM_OPS contents are unused (so far).

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Cc'ing more folks related to the commit.

char-misc-linus should get merged into Linus's tree "soon" and then we can fix up the mm-unstable change for this.

I'm working on the fix as we speak. It would be ideal if it went into char-misc-linus, because the commit that is wrong is mine, not the one in mm.

To clarify, to avoid breaking bisection, the commit needs to land somewhere that is on top of commit 8ef2c15aeae0 ("rust_binder: check ownership before using vma"), and before the mm commit. But I guess there are several options for how to do that other than landing it through char-misc-linus right now.

Alice

#8 lore raw
Quoted 28 lines · Alice Ryhl
Quoted 18 lines · Alice Ryhl
Quoted 16 lines · Greg Kroah-Hartman
Quoted 14 lines · Miguel Ojeda
Quoted 5 lines · Nathan Chancellor

It looks like this is a conflict between Alice's "rust_binder: check ownership before using vma" [1] (currently in char-misc-linus [2]) and Mike's "userfaultfd: introduce vm_uffd_ops" [3] (currently in mm-unstable [4]), hence why it was bisected to the -next merge commit.

Thanks Nathan, yeah, adding a raw pointer (not function pointer) to the struct makes the type !Sync in Rust.

I assume this is best handled with a patch on top of char-misc-linus. Perhaps creating a wrapper to assert it is Sync, since the BINDER_VM_OPS contents are unused (so far).

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Cc'ing more folks related to the commit.

char-misc-linus should get merged into Linus's tree "soon" and then we can fix up the mm-unstable change for this.

I'm working on the fix as we speak. It would be ideal if it went into char-misc-linus, because the commit that is wrong is mine, not the one in mm.

Quoted 5 lines

To clarify, to avoid breaking bisection, the commit needs to land somewhere that is on top of commit 8ef2c15aeae0 ("rust_binder: check ownership before using vma"), and before the mm commit. But I guess there are several options for how to do that other than landing it through char-misc-linus right now.

I've sent off a pull request for the char-misc-linus branch now, and after -rc4 is out I'll queue this up on top of that to get merged for -rc5 to make this all work out ok.

thanks,

greg k-h

maintainer
#9 lore raw
Quoted 36 lines · Greg Kroah-Hartman
Quoted 28 lines · Alice Ryhl
Quoted 18 lines · Alice Ryhl
Quoted 16 lines · Greg Kroah-Hartman
Quoted 14 lines · Miguel Ojeda
Quoted 5 lines · Nathan Chancellor

It looks like this is a conflict between Alice's "rust_binder: check ownership before using vma" [1] (currently in char-misc-linus [2]) and Mike's "userfaultfd: introduce vm_uffd_ops" [3] (currently in mm-unstable [4]), hence why it was bisected to the -next merge commit.

Thanks Nathan, yeah, adding a raw pointer (not function pointer) to the struct makes the type !Sync in Rust.

I assume this is best handled with a patch on top of char-misc-linus. Perhaps creating a wrapper to assert it is Sync, since the BINDER_VM_OPS contents are unused (so far).

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Cc'ing more folks related to the commit.

char-misc-linus should get merged into Linus's tree "soon" and then we can fix up the mm-unstable change for this.

I'm working on the fix as we speak. It would be ideal if it went into char-misc-linus, because the commit that is wrong is mine, not the one in mm.

Quoted 5 lines

To clarify, to avoid breaking bisection, the commit needs to land somewhere that is on top of commit 8ef2c15aeae0 ("rust_binder: check ownership before using vma"), and before the mm commit. But I guess there are several options for how to do that other than landing it through char-misc-linus right now.

Quoted 3 lines

I've sent off a pull request for the char-misc-linus branch now, and after -rc4 is out I'll queue this up on top of that to get merged for -rc5 to make this all work out ok.

That works, thanks!

Alice

maintainer
#10 lore raw
In reply to Greg Kroah-Hartman
Quoted 36 lines · Greg Kroah-Hartman
Quoted 28 lines · Alice Ryhl
Quoted 18 lines · Alice Ryhl
Quoted 16 lines · Greg Kroah-Hartman
Quoted 14 lines · Miguel Ojeda
Quoted 5 lines · Nathan Chancellor

It looks like this is a conflict between Alice's "rust_binder: check ownership before using vma" [1] (currently in char-misc-linus [2]) and Mike's "userfaultfd: introduce vm_uffd_ops" [3] (currently in mm-unstable [4]), hence why it was bisected to the -next merge commit.

Thanks Nathan, yeah, adding a raw pointer (not function pointer) to the struct makes the type !Sync in Rust.

I assume this is best handled with a patch on top of char-misc-linus. Perhaps creating a wrapper to assert it is Sync, since the BINDER_VM_OPS contents are unused (so far).

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Cc'ing more folks related to the commit.

char-misc-linus should get merged into Linus's tree "soon" and then we can fix up the mm-unstable change for this.

I'm working on the fix as we speak. It would be ideal if it went into char-misc-linus, because the commit that is wrong is mine, not the one in mm.

Quoted 5 lines

To clarify, to avoid breaking bisection, the commit needs to land somewhere that is on top of commit 8ef2c15aeae0 ("rust_binder: check ownership before using vma"), and before the mm commit. But I guess there are several options for how to do that other than landing it through char-misc-linus right now.

Quoted 3 lines

I've sent off a pull request for the char-misc-linus branch now, and after -rc4 is out I'll queue this up on top of that to get merged for -rc5 to make this all work out ok.

Friendly ping on this. I don't see this applied yet.

Alice

#11 lore raw
Quoted 38 lines · Alice Ryhl
Quoted 36 lines · Greg Kroah-Hartman
Quoted 33 lines · Alice Ryhl
Quoted 18 lines · Alice Ryhl
Quoted 16 lines · Greg Kroah-Hartman
Quoted 14 lines · Miguel Ojeda
Quoted 5 lines · Nathan Chancellor

It looks like this is a conflict between Alice's "rust_binder: check ownership before using vma" [1] (currently in char-misc-linus [2]) and Mike's "userfaultfd: introduce vm_uffd_ops" [3] (currently in mm-unstable [4]), hence why it was bisected to the -next merge commit.

Thanks Nathan, yeah, adding a raw pointer (not function pointer) to the struct makes the type !Sync in Rust.

I assume this is best handled with a patch on top of char-misc-linus. Perhaps creating a wrapper to assert it is Sync, since the BINDER_VM_OPS contents are unused (so far).

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Cc'ing more folks related to the commit.

char-misc-linus should get merged into Linus's tree "soon" and then we can fix up the mm-unstable change for this.

I'm working on the fix as we speak. It would be ideal if it went into char-misc-linus, because the commit that is wrong is mine, not the one in mm.

To clarify, to avoid breaking bisection, the commit needs to land somewhere that is on top of commit 8ef2c15aeae0 ("rust_binder: check ownership before using vma"), and before the mm commit. But I guess there are several options for how to do that other than landing it through char-misc-linus right now.

Quoted 5 lines
Quoted 3 lines

I've sent off a pull request for the char-misc-linus branch now, and after -rc4 is out I'll queue this up on top of that to get merged for -rc5 to make this all work out ok.

Friendly ping on this. I don't see this applied yet.

Sorry for the delay, now queued up.

greg k-h

maintainer
#12 lore raw
Quoted 40 lines · Greg Kroah-Hartman
Quoted 38 lines · Alice Ryhl
Quoted 36 lines · Greg Kroah-Hartman
Quoted 33 lines · Alice Ryhl
Quoted 18 lines · Alice Ryhl
Quoted 16 lines · Greg Kroah-Hartman
Quoted 14 lines · Miguel Ojeda
Quoted 5 lines · Nathan Chancellor

It looks like this is a conflict between Alice's "rust_binder: check ownership before using vma" [1] (currently in char-misc-linus [2]) and Mike's "userfaultfd: introduce vm_uffd_ops" [3] (currently in mm-unstable [4]), hence why it was bisected to the -next merge commit.

Thanks Nathan, yeah, adding a raw pointer (not function pointer) to the struct makes the type !Sync in Rust.

I assume this is best handled with a patch on top of char-misc-linus. Perhaps creating a wrapper to assert it is Sync, since the BINDER_VM_OPS contents are unused (so far).

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Cc'ing more folks related to the commit.

char-misc-linus should get merged into Linus's tree "soon" and then we can fix up the mm-unstable change for this.

I'm working on the fix as we speak. It would be ideal if it went into char-misc-linus, because the commit that is wrong is mine, not the one in mm.

To clarify, to avoid breaking bisection, the commit needs to land somewhere that is on top of commit 8ef2c15aeae0 ("rust_binder: check ownership before using vma"), and before the mm commit. But I guess there are several options for how to do that other than landing it through char-misc-linus right now.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I've sent off a pull request for the char-misc-linus branch now, and after -rc4 is out I'll queue this up on top of that to get merged for -rc5 to make this all work out ok.

Friendly ping on this. I don't see this applied yet.

Sorry for the delay, now queued up.

Thanks!

Alice