Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Sean Christopherson and committed by
Wei Liu
c5eebe07 9be7e1e3

+7 -50
+1
drivers/hv/Kconfig
··· 66 66 # no particular order, making it impossible to reassemble larger pages 67 67 depends on PAGE_SIZE_4KB 68 68 select EVENTFD 69 + select VIRT_XFER_TO_GUEST_WORK 69 70 default n 70 71 help 71 72 Select this option to enable support for booting and running as root
-2
drivers/hv/mshv.h
··· 25 25 int hv_call_get_partition_property(u64 partition_id, u64 property_code, 26 26 u64 *property_value); 27 27 28 - int mshv_do_pre_guest_mode_work(ulong th_flags); 29 - 30 28 #endif /* _MSHV_H */
-22
drivers/hv/mshv_common.c
··· 138 138 return 0; 139 139 } 140 140 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);
+6 -26
drivers/hv/mshv_root_main.c
··· 8 8 * Authors: Microsoft Linux virtualization team 9 9 */ 10 10 11 + #include <linux/entry-virt.h> 11 12 #include <linux/kernel.h> 12 13 #include <linux/module.h> 13 14 #include <linux/fs.h> ··· 482 481 return 0; 483 482 } 484 483 485 - static int mshv_pre_guest_mode_work(struct mshv_vp *vp) 486 - { 487 - const ulong work_flags = _TIF_NOTIFY_SIGNAL | _TIF_SIGPENDING | 488 - _TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY | 489 - _TIF_NOTIFY_RESUME; 490 - ulong th_flags; 491 - 492 - th_flags = read_thread_flags(); 493 - while (th_flags & work_flags) { 494 - int ret; 495 - 496 - /* nb: following will call schedule */ 497 - ret = mshv_do_pre_guest_mode_work(th_flags); 498 - 499 - if (ret) 500 - return ret; 501 - 502 - th_flags = read_thread_flags(); 503 - } 504 - 505 - return 0; 506 - } 507 - 508 484 /* Must be called with interrupts enabled */ 509 485 static long mshv_run_vp_with_root_scheduler(struct mshv_vp *vp) 510 486 { ··· 502 524 u32 flags = 0; 503 525 struct hv_output_dispatch_vp output; 504 526 505 - ret = mshv_pre_guest_mode_work(vp); 506 - if (ret) 507 - break; 527 + if (__xfer_to_guest_mode_work_pending()) { 528 + ret = xfer_to_guest_mode_handle_work(); 529 + if (ret) 530 + break; 531 + } 508 532 509 533 if (vp->run.flags.intercept_suspend) 510 534 flags |= HV_DISPATCH_VP_FLAG_CLEAR_INTERCEPT_SUSPEND;