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

Mark Brown <[email protected]>
Newsgroups org.kernel.vger.linux-next,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
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.

diff --cc rust/kernel/sync/poll.rs
index 5aa0ce9ba01b7,684dfa242b1aa..0000000000000
--- a/rust/kernel/sync/poll.rs
+++ b/rust/kernel/sync/poll.rs
@@@ -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>()) };
+     }
+ }
signature.asc (application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE-----

iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmp6AyYACgkQJNaLcl1U
h9CwKwf9EaLPYyKQQV+DnDqqnJQcnmN20UZoYaftceKyV2Qng8ytAWAF/35vW0eE
Ec3TR04zKn+WTldTWCyC2VvMq+6jrvd9IjjHazQzgvsJ5sUMpoCMo0JododTI75p
woxd0eq6sUbk5P5tYxQ4V0wWWNlQZbM26HXp/MrMBteUUJelWfAhIXOOZQCosf8j
qsqXBGi15sz/7D7RWPRqDzC/JRJptiFRr32Euvro65p5AH4DmsoiBdBlg84b1cUV
d/9Fm42eGQ3MvUwhIy3DGpDS1lEAt+wfin5bdASmGfWvaOABLfOQ466sY3LLPwOJ
lJrTE9q/v858y8+D0Cgp/QlWqLDJwg==
=hsfJ
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.