Message ID | 20200422040739.18601-4-dave@stgolabs.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | kvm: Use rcuwait for vcpu blocking | expand |
On Tue, Apr 21, 2020 at 09:07:37PM -0700, Davidlohr Bueso wrote: > +static inline void prepare_to_rcuwait(struct rcuwait *w) > +{ > + rcu_assign_pointer(w->task, current); > +} > + > +static inline void finish_rcuwait(struct rcuwait *w) > +{ > + WRITE_ONCE(w->task, NULL); I think that wants to be: rcu_assign_pointer(w->task, NULL); There is a special case in rcu_assign_pointer() that looses the barrier, but it will keep the __rcu sparse people happy. That is w->task is __rcu, and WRITE_ONCE ignores that etc.. blah. The alternative is using RCU_INIT_POINTER() I suppose. > + __set_current_state(TASK_RUNNING); > +}
diff --git a/include/linux/rcuwait.h b/include/linux/rcuwait.h index 6ebb23258a27..0c6a3d0d25ab 100644 --- a/include/linux/rcuwait.h +++ b/include/linux/rcuwait.h @@ -29,12 +29,25 @@ extern int rcuwait_wake_up(struct rcuwait *w); /* * The caller is responsible for locking around rcuwait_wait_event(), - * such that writes to @task are properly serialized. + * and prepare_to_rcuwait() such that writes to @task are properly + * serialized. */ + +static inline void prepare_to_rcuwait(struct rcuwait *w) +{ + rcu_assign_pointer(w->task, current); +} + +static inline void finish_rcuwait(struct rcuwait *w) +{ + WRITE_ONCE(w->task, NULL); + __set_current_state(TASK_RUNNING); +} + #define rcuwait_wait_event(w, condition, state) \ ({ \ int __ret = 0; \ - rcu_assign_pointer((w)->task, current); \ + prepare_to_rcuwait(w); \ for (;;) { \ /* \ * Implicit barrier (A) pairs with (B) in \ @@ -51,9 +64,7 @@ extern int rcuwait_wake_up(struct rcuwait *w); \ schedule(); \ } \ - \ - WRITE_ONCE((w)->task, NULL); \ - __set_current_state(TASK_RUNNING); \ + finish_rcuwait(w); \ __ret; \ })
This allows further flexibility for some callers to implement ad-hoc versions of the generic rcuwait_wait_event(). For example, kvm will need this to maintain tracing semantics. The naming is of course similar to what waitqueue apis offer. Signed-off-by: Davidlohr Bueso <dbueso@suse.de> --- include/linux/rcuwait.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)