linux-next: manual merge of the char-misc tree with the tip tree
Subsystems (4)
Mark Brown
maintainerHi 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
@@@ -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] 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: &'staticCStr , key:Pin <&'staticLockClassKey >) ->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 >()) }; + } + }
Boqun Feng
maintainerQuoted 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.rsbetween commit:
47c3367ff096e("rust: sync: Use safesynchronize_rcu()abstraction in poll")from the tip tree and commit:
e5e86df8b6661("rust: poll: usekfree_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@@@ -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 PollCondVarunsafe { 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: &'staticCStr , key:Pin <&'staticLockClassKey >) ->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 >()) }; + } + }