Skip to contentSkip to conversation

linux-next: manual merge of the char-misc tree with the tip tree

PATCH Mark Brown 2 participants 2 messages Aug 10 – Aug 11

Subsystems (4)
lore
Share & tools
lore

Mark Brown

author maintainer
#0 lore raw

Hi all,

Today's linux-next merge of the char-misc tree got a conflict in:

rust/kernel/sync/poll.rs

between commit:

47c3367ff096e ("rust: sync: Use safe synchronize_rcu() abstraction in poll")

from the tip tree and commit:

e5e86df8b6661 ("rust: poll: use kfree_rcu() for PollCondVar")

from the char-misc tree.

I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.

rust/kernel/sync/poll.rs +0 -0
diff --cc rust/kernel/sync/poll.rs
index 5aa0ce9ba01b7,684dfa242b1aa..0000000000000
@@@ -8,13 -9,14 +9,18 @@@ use crate::
      bindings,
      fs::File,
      prelude::*,
 -    sync::{CondVar, LockClassKey},
 +    sync::{
 +        rcu::synchronize_rcu,
 +        CondVar,
 +        LockClassKey, //
-     }, //
++    },
+     types::Opaque, //
+ };
+ use core::{
+     marker::PhantomData,
+     mem::ManuallyDrop,
+     ops::Deref, //
  };
- use core::{marker::PhantomData, ops::Deref};
  
  /// Creates a [`PollCondVar`] initialiser with the given name and a newly-created lock class.
  #[macro_export]
@@@ -103,6 -106,72 +110,70 @@@ impl PinnedDrop for PollCondVar 
          unsafe { bindings::__wake_up_pollfree(self.inner.wait_queue_head.get()) };
  
          // Wait for epoll items to be properly removed.
 -        //
 -        // SAFETY: Just an FFI call.
 -        unsafe { bindings::synchronize_rcu() };
 +        synchronize_rcu();
      }
  }
+ 
+ /// A [`KBox<PollCondVar>`] that uses `kfree_rcu`.
+ ///
+ /// [`KBox<PollCondVar>`]: PollCondVar
+ pub struct PollCondVarBox {
+     inner: ManuallyDrop<Pin<KBox<PollCondVarBoxInner>>>,
+ }
+ 
+ #[pin_data]
+ #[repr(C)]
+ struct PollCondVarBoxInner {
+     #[pin]
+     inner: PollCondVar,
+     rcu: Opaque<bindings::callback_head>,
+ }
+ 
+ // SAFETY: PollCondVar is Send
+ unsafe impl Send for PollCondVarBoxInner {}
+ // SAFETY: PollCondVar is Sync
+ unsafe impl Sync for PollCondVarBoxInner {}
+ 
+ impl PollCondVarBox {
+     /// Constructs a new boxed [`PollCondVar`].
+     pub fn new(name: &'static CStr, key: Pin<&'static LockClassKey>) -> Result<Self, AllocError> {
+         let b = KBox::pin_init(
+             pin_init!(PollCondVarBoxInner {
+                 inner <- PollCondVar::new(name, key),
+                 rcu: Opaque::uninit(),
+             }),
+             GFP_KERNEL,
+         )
+         .map_err(|_| AllocError)?;
+ 
+         Ok(PollCondVarBox {
+             inner: ManuallyDrop::new(b),
+         })
+     }
+ }
+ 
+ impl Deref for PollCondVarBox {
+     type Target = PollCondVar;
+     fn deref(&self) -> &PollCondVar {
+         &self.inner.inner
+     }
+ }
+ 
+ impl Drop for PollCondVarBox {
+     #[inline]
+     fn drop(&mut self) {
+         // SAFETY: ManuallyDrop::take ok because not already taken.
+         let boxed = unsafe { ManuallyDrop::take(&mut self.inner) };
+ 
+         // SAFETY: The code below frees the box without calling the actual destructor of the type,
+         // but it's okay because it re-implements the destructor using `kfree_rcu()` in place of
+         // `synchronize_rcu()`.
+         let ptr = KBox::into_raw(unsafe { Pin::into_inner_unchecked(boxed) });
+ 
+         // SAFETY: The pointer points at a valid `wait_queue_head`.
+         unsafe { bindings::__wake_up_pollfree((*ptr).inner.inner.wait_queue_head.get()) };
+ 
+         // SAFETY: This was allocated using `KBox::pin_init`, so it can be freed with `kvfree`.
+         unsafe { bindings::kvfree_call_rcu((*ptr).rcu.get(), ptr.cast::<ffi::c_void>()) };
+     }
+ }
maintainer
#1 lore raw
Quoted 2 lines · Mark Brown

Hi all,

Hi Mark,

Quoted 12 lines

Today's linux-next merge of the char-misc tree got a conflict in:

rust/kernel/sync/poll.rs

between commit:

47c3367ff096e ("rust: sync: Use safe synchronize_rcu() abstraction in poll")

from the tip tree and commit:

e5e86df8b6661 ("rust: poll: use kfree_rcu() for PollCondVar")

Quoted 9 lines

from the char-misc tree.

I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.

The fix-up looks good to me, thank you!

Regards,
Boqun

Quoted 100 lines
rust/kernel/sync/poll.rs +71 -2
diff --cc rust/kernel/sync/poll.rs
index 5aa0ce9ba01b7,684dfa242b1aa..0000000000000
@@@ -8,13 -9,14 +9,18 @@@ use crate::
      bindings,
      fs::File,
      prelude::*,
 -    sync::{CondVar, LockClassKey},
 +    sync::{
 +        rcu::synchronize_rcu,
 +        CondVar,
 +        LockClassKey, //
-     }, //
++    },
+     types::Opaque, //
+ };
+ use core::{
+     marker::PhantomData,
+     mem::ManuallyDrop,
+     ops::Deref, //
  };
- use core::{marker::PhantomData, ops::Deref};
 
  /// Creates a [`PollCondVar`] initialiser with the given name and a newly-created lock class.
  #[macro_export]
@@@ -103,6 -106,72 +110,70 @@@ impl PinnedDrop for PollCondVar 
          unsafe { bindings::__wake_up_pollfree(self.inner.wait_queue_head.get()) };
 
          // Wait for epoll items to be properly removed.
 -        //
 -        // SAFETY: Just an FFI call.
 -        unsafe { bindings::synchronize_rcu() };
 +        synchronize_rcu();
      }
  }
+ 
+ /// A [`KBox<PollCondVar>`] that uses `kfree_rcu`.
+ ///
+ /// [`KBox<PollCondVar>`]: PollCondVar
+ pub struct PollCondVarBox {
+     inner: ManuallyDrop<Pin<KBox<PollCondVarBoxInner>>>,
+ }
+ 
+ #[pin_data]
+ #[repr(C)]
+ struct PollCondVarBoxInner {
+     #[pin]
+     inner: PollCondVar,
+     rcu: Opaque<bindings::callback_head>,
+ }
+ 
+ // SAFETY: PollCondVar is Send
+ unsafe impl Send for PollCondVarBoxInner {}
+ // SAFETY: PollCondVar is Sync
+ unsafe impl Sync for PollCondVarBoxInner {}
+ 
+ impl PollCondVarBox {
+     /// Constructs a new boxed [`PollCondVar`].
+     pub fn new(name: &'static CStr, key: Pin<&'static LockClassKey>) -> Result<Self, AllocError> {
+         let b = KBox::pin_init(
+             pin_init!(PollCondVarBoxInner {
+                 inner <- PollCondVar::new(name, key),
+                 rcu: Opaque::uninit(),
+             }),
+             GFP_KERNEL,
+         )
+         .map_err(|_| AllocError)?;
+ 
+         Ok(PollCondVarBox {
+             inner: ManuallyDrop::new(b),
+         })
+     }
+ }
+ 
+ impl Deref for PollCondVarBox {
+     type Target = PollCondVar;
+     fn deref(&self) -> &PollCondVar {
+         &self.inner.inner
+     }
+ }
+ 
+ impl Drop for PollCondVarBox {
+     #[inline]
+     fn drop(&mut self) {
+         // SAFETY: ManuallyDrop::take ok because not already taken.
+         let boxed = unsafe { ManuallyDrop::take(&mut self.inner) };
+ 
+         // SAFETY: The code below frees the box without calling the actual destructor of the type,
+         // but it's okay because it re-implements the destructor using `kfree_rcu()` in place of
+         // `synchronize_rcu()`.
+         let ptr = KBox::into_raw(unsafe { Pin::into_inner_unchecked(boxed) });
+ 
+         // SAFETY: The pointer points at a valid `wait_queue_head`.
+         unsafe { bindings::__wake_up_pollfree((*ptr).inner.inner.wait_queue_head.get()) };
+ 
+         // SAFETY: This was allocated using `KBox::pin_init`, so it can be freed with `kvfree`.
+         unsafe { bindings::kvfree_call_rcu((*ptr).rcu.get(), ptr.cast::<ffi::c_void>()) };
+     }
+ }