Move the root partition's handling of pending thread work fully into
mshv_common.c so that the "work pending" and "do work" code is co-located.
Splitting the flags-to-check logic makes the code unnnecessarily difficult
to maintain, e.g. it would be all too easy to add a check in "do work" but
not in "work pending", and vice versa.

Note, this adds an extra CALL+RET when no work is pending; that will be
remedied in the near feature by switching to common virtualization entry
APIs.

No functional change intended.

Signed-off-by: Sean Christopherson <sea...@google.com>
---
 drivers/hv/mshv.h           |  2 +-
 drivers/hv/mshv_common.c    | 24 +++++++++++++++++++++++-
 drivers/hv/mshv_root_main.c | 24 +-----------------------
 3 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/drivers/hv/mshv.h b/drivers/hv/mshv.h
index 0340a67acd0a..db3aa3831c43 100644
--- a/drivers/hv/mshv.h
+++ b/drivers/hv/mshv.h
@@ -25,6 +25,6 @@ int hv_call_set_vp_registers(u32 vp_index, u64 partition_id, 
u16 count,
 int hv_call_get_partition_property(u64 partition_id, u64 property_code,
                                   u64 *property_value);
 
-int mshv_do_pre_guest_mode_work(ulong th_flags);
+int mshv_do_pre_guest_mode_work(void);
 
 #endif /* _MSHV_H */
diff --git a/drivers/hv/mshv_common.c b/drivers/hv/mshv_common.c
index 6f227a8a5af7..1acc47c4be0d 100644
--- a/drivers/hv/mshv_common.c
+++ b/drivers/hv/mshv_common.c
@@ -146,7 +146,7 @@ EXPORT_SYMBOL_GPL(hv_call_get_partition_property);
  *
  * Returns: 0 on success, -errno on error.
  */
-int mshv_do_pre_guest_mode_work(ulong th_flags)
+static int __mshv_do_pre_guest_mode_work(ulong th_flags)
 {
        if (th_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
                return -EINTR;
@@ -159,4 +159,26 @@ int mshv_do_pre_guest_mode_work(ulong th_flags)
 
        return 0;
 }
+
+int mshv_do_pre_guest_mode_work(void)
+{
+       const ulong work_flags = _TIF_NOTIFY_SIGNAL | _TIF_SIGPENDING |
+                                _TIF_NEED_RESCHED  | _TIF_NOTIFY_RESUME;
+       ulong th_flags;
+
+       th_flags = read_thread_flags();
+       while (th_flags & work_flags) {
+               int ret;
+
+               /* nb: following will call schedule */
+               ret = __mshv_do_pre_guest_mode_work(th_flags);
+               if (ret)
+                       return ret;
+
+               th_flags = read_thread_flags();
+       }
+
+       return 0;
+
+}
 EXPORT_SYMBOL_GPL(mshv_do_pre_guest_mode_work);
diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
index 72df774e410a..6f677fb93af0 100644
--- a/drivers/hv/mshv_root_main.c
+++ b/drivers/hv/mshv_root_main.c
@@ -487,28 +487,6 @@ mshv_vp_wait_for_hv_kick(struct mshv_vp *vp)
        return 0;
 }
 
-static int mshv_pre_guest_mode_work(struct mshv_vp *vp)
-{
-       const ulong work_flags = _TIF_NOTIFY_SIGNAL | _TIF_SIGPENDING |
-                                _TIF_NEED_RESCHED  | _TIF_NOTIFY_RESUME;
-       ulong th_flags;
-
-       th_flags = read_thread_flags();
-       while (th_flags & work_flags) {
-               int ret;
-
-               /* nb: following will call schedule */
-               ret = mshv_do_pre_guest_mode_work(th_flags);
-
-               if (ret)
-                       return ret;
-
-               th_flags = read_thread_flags();
-       }
-
-       return 0;
-}
-
 /* Must be called with interrupts enabled */
 static long mshv_run_vp_with_root_scheduler(struct mshv_vp *vp)
 {
@@ -529,7 +507,7 @@ static long mshv_run_vp_with_root_scheduler(struct mshv_vp 
*vp)
                u32 flags = 0;
                struct hv_output_dispatch_vp output;
 
-               ret = mshv_pre_guest_mode_work(vp);
+               ret = mshv_do_pre_guest_mode_work();
                if (ret)
                        break;
 
-- 
2.51.0.261.g7ce5a0a67e-goog


Reply via email to