Skip to content

Commit c5eebe0

Browse files
sean-jcliuw
authored andcommitted
mshv: Use common "entry virt" APIs to do work in root before running guest
Use the kernel's common "entry virt" APIs to handle pending work prior to (re)entering guest mode, now that the virt APIs don't have a superfluous dependency on KVM. No functional change intended. Signed-off-by: Sean Christopherson <seanjc@google.com> Tested-by: Nuno Das Neves <nunodasneves@linux.microsoft.com> Reviewed-by: Nuno Das Neves <nunodasneves@linux.microsoft.com> Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent 9be7e1e commit c5eebe0

4 files changed

Lines changed: 7 additions & 50 deletions

File tree

drivers/hv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ config MSHV_ROOT
6666
# no particular order, making it impossible to reassemble larger pages
6767
depends on PAGE_SIZE_4KB
6868
select EVENTFD
69+
select VIRT_XFER_TO_GUEST_WORK
6970
default n
7071
help
7172
Select this option to enable support for booting and running as root

drivers/hv/mshv.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ int hv_call_set_vp_registers(u32 vp_index, u64 partition_id, u16 count,
2525
int hv_call_get_partition_property(u64 partition_id, u64 property_code,
2626
u64 *property_value);
2727

28-
int mshv_do_pre_guest_mode_work(ulong th_flags);
29-
3028
#endif /* _MSHV_H */

drivers/hv/mshv_common.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,25 +138,3 @@ int hv_call_get_partition_property(u64 partition_id,
138138
return 0;
139139
}
140140
EXPORT_SYMBOL_GPL(hv_call_get_partition_property);
141-
142-
/*
143-
* Handle any pre-processing before going into the guest mode on this cpu, most
144-
* notably call schedule(). Must be invoked with both preemption and
145-
* interrupts enabled.
146-
*
147-
* Returns: 0 on success, -errno on error.
148-
*/
149-
int mshv_do_pre_guest_mode_work(ulong th_flags)
150-
{
151-
if (th_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
152-
return -EINTR;
153-
154-
if (th_flags & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY))
155-
schedule();
156-
157-
if (th_flags & _TIF_NOTIFY_RESUME)
158-
resume_user_mode_work(NULL);
159-
160-
return 0;
161-
}
162-
EXPORT_SYMBOL_GPL(mshv_do_pre_guest_mode_work);

drivers/hv/mshv_root_main.c

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Authors: Microsoft Linux virtualization team
99
*/
1010

11+
#include <linux/entry-virt.h>
1112
#include <linux/kernel.h>
1213
#include <linux/module.h>
1314
#include <linux/fs.h>
@@ -481,29 +482,6 @@ mshv_vp_wait_for_hv_kick(struct mshv_vp *vp)
481482
return 0;
482483
}
483484

484-
static int mshv_pre_guest_mode_work(struct mshv_vp *vp)
485-
{
486-
const ulong work_flags = _TIF_NOTIFY_SIGNAL | _TIF_SIGPENDING |
487-
_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY |
488-
_TIF_NOTIFY_RESUME;
489-
ulong th_flags;
490-
491-
th_flags = read_thread_flags();
492-
while (th_flags & work_flags) {
493-
int ret;
494-
495-
/* nb: following will call schedule */
496-
ret = mshv_do_pre_guest_mode_work(th_flags);
497-
498-
if (ret)
499-
return ret;
500-
501-
th_flags = read_thread_flags();
502-
}
503-
504-
return 0;
505-
}
506-
507485
/* Must be called with interrupts enabled */
508486
static long mshv_run_vp_with_root_scheduler(struct mshv_vp *vp)
509487
{
@@ -524,9 +502,11 @@ static long mshv_run_vp_with_root_scheduler(struct mshv_vp *vp)
524502
u32 flags = 0;
525503
struct hv_output_dispatch_vp output;
526504

527-
ret = mshv_pre_guest_mode_work(vp);
528-
if (ret)
529-
break;
505+
if (__xfer_to_guest_mode_work_pending()) {
506+
ret = xfer_to_guest_mode_handle_work();
507+
if (ret)
508+
break;
509+
}
530510

531511
if (vp->run.flags.intercept_suspend)
532512
flags |= HV_DISPATCH_VP_FLAG_CLEAR_INTERCEPT_SUSPEND;

0 commit comments

Comments
 (0)