]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
rcuwait: Introduce prepare_to and finish_rcuwait
authorDavidlohr Bueso <dave@stgolabs.net>
Fri, 24 Apr 2020 05:48:35 +0000 (22:48 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 13 May 2020 16:14:53 +0000 (12:14 -0400)
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.

Also go ahead and make use of rcu_assign_pointer() for both task
writes as it will make the __rcu sparse people happy - this will
be the special nil case, thus no added serialization.

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Message-Id: <20200424054837.5138-4-dave@stgolabs.net>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/linux/rcuwait.h

index 6ebb23258a27640f7a4fb4a5f627a9d1f60cf6c5..45bc6604e9b1288471e867cb26bdc84673bff63d 100644 (file)
@@ -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/finish]_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)
+{
+        rcu_assign_pointer(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;                                                          \
 })