Drivers: hv: Fix NEED_RESCHED_LAZY and use common APIs
Sean Christopherson
maintainerv2 cover Drivers: hv: Fix NEED_RESCHED_LAZY and use common APIs
Fix a bug where MSHV root partitions (and upper-level VTL code) don't honor NEED_RESCHED_LAZY, and then deduplicate the TIF related MSHV code by turning the "kvm" entry APIs into more generic "virt" APIs.
This version is based on
git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git hyperv-next
in order to pickup the VTL changes that are queued for 6.18. I also squashed the NEED_RESCHED_LAZY fixes for root and VTL modes into a single patch, as it should be easy/straightforward to drop the VTL change as needed if we want this in 6.17 or earlier.
That effectively means the full series is dependent on the VTL changes being fully merged for 6.18. But I think that's ok as it's really only the MSHV changes that have any urgency whatsoever, and I assume that Microsoft is the only user that truly cares about the MSHV root fix. I.e. if the whole thing gets delayed, I think it's only the Hyper-V folks that are impacted.
I have no preference what tree this goes through, or when, and can respin and/or split as needed.
As with v1, the Hyper-V stuff and non-x86 architectures are compile-tested only.
v2:
- Rebase on hyperv-next.
- Fix and converge the VTL code as well. [Peter, Nuno]
v1: https://lore.kernel.org/all/[email protected]
Sean Christopherson (7):
Drivers: hv: Handle NEED_RESCHED_LAZY before transferring to guest
Drivers: hv: Disentangle VTL return cancellation from SIGPENDING
Drivers: hv: Disable IRQs only after handling pending work before VTL
return
entry/kvm: KVM: Move KVM details related to signal/-EINTR into KVM
proper
entry: Rename "kvm" entry code assets to "virt" to genericize APIs
Drivers: hv: Use common "entry virt" APIs to do work in root before
running guest
Drivers: hv: Use "entry virt" APIs to do work before returning to
lower VTL
MAINTAINERS | 2 +-
arch/arm64/kvm/Kconfig | 2 +-
arch/arm64/kvm/arm.c | 3 +-
arch/loongarch/kvm/Kconfig | 2 +-
arch/loongarch/kvm/vcpu.c | 3 +-
arch/riscv/kvm/Kconfig | 2 +-
arch/riscv/kvm/vcpu.c | 3 +-
arch/x86/kvm/Kconfig | 2 +-
arch/x86/kvm/vmx/vmx.c | 1 -
arch/x86/kvm/x86.c | 3 +-
drivers/hv/Kconfig | 2 ++
drivers/hv/mshv.h | 2 --
drivers/hv/mshv_common.c | 22 ---------------
drivers/hv/mshv_root_main.c | 31 ++++-----------------
drivers/hv/mshv_vtl_main.c | 23 +++++++--------
include/linux/{entry-kvm.h => entry-virt.h} | 19 +++++--------
include/linux/kvm_host.h | 17 +++++++++--
include/linux/rcupdate.h | 2 +-
kernel/entry/Makefile | 2 +-
kernel/entry/{kvm.c => virt.c} | 15 ++++------
kernel/rcu/tree.c | 6 ++--
virt/kvm/Kconfig | 2 +-
22 files changed, 60 insertions(+), 106 deletions(-)
rename include/linux/{entry-kvm.h => entry-virt.h} (83%)
rename kernel/entry/{kvm.c => virt.c} (66%)base-commit: 03ac62a578566730ab3c320f289f7320798ee2e1
Signature · 1 line
2.51.0.268.g9569e192d0-goog
Sean Christopherson
maintainerPATCH v2 1/7 Drivers: hv: Handle NEED_RESCHED_LAZY before transferring to guest
Check for NEED_RESCHED_LAZY, not just NEED_RESCHED, prior to transferring control to a guest. Failure to check for lazy resched can unnecessarily delay rescheduling until the next tick when using a lazy preemption model.
Note, ideally both the checking and processing of TIF bits would be handled in common code, to avoid having to keep three separate paths synchronized, but defer such cleanups to the future to keep the fix as standalone as possible.
--- drivers/hv/mshv_common.c | 2 +- drivers/hv/mshv_root_main.c | 3 ++- drivers/hv/mshv_vtl_main.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-)
drivers/hv/mshv_common.c +1 -1
@@ -151,7 +151,7 @@ int mshv_do_pre_guest_mode_work(ulong th_flags)if (th_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))return -EINTR ; -if (th_flags & _TIF_NEED_RESCHED) +if (th_flags & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY))schedule ();if (th_flags & _TIF_NOTIFY_RESUME)
drivers/hv/mshv_root_main.c +2 -1
@@ -484,7 +484,8 @@ mshv_vp_wait_for_hv_kick(struct mshv_vp *vp)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; + _TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY | + _TIF_NOTIFY_RESUME;ulong th_flags; th_flags =read_thread_flags ();
drivers/hv/mshv_vtl_main.c +2 -1
@@ -728,7 +728,8 @@ static int mshv_vtl_ioctl_return_to_lower_vtl(void)preempt_disable ();for (;;) {const unsigned long VTL0_WORK = _TIF_SIGPENDING | _TIF_NEED_RESCHED | - _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL; + _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL | + _TIF_NEED_RESCHED_LAZY;unsigned long ti_work;u32 cancel;unsigned long irq_flags;
Signature · 1 line
2.51.0.268.g9569e192d0-goog
Re: [PATCH v2 1/7] Drivers: hv: Handle NEED_RESCHED_LAZY before transferring to guest
Quoted 52 lines · Sean Christopherson
Check for
NEED_RESCHED_LAZY, not justNEED_RESCHED, prior to transferring control to a guest. Failure to check for lazy resched can unnecessarily delay rescheduling until the next tick when using a lazy preemption model.Note, ideally both the checking and processing of TIF bits would be handled in common code, to avoid having to keep three separate paths synchronized, but defer such cleanups to the future to keep the fix as standalone as possible.
Cc Nuno Das Neves <[email protected]>Cc Mukesh R <[email protected]>Fixes 621191d709b1 ("Drivers: hv: Introduce mshv_root module to expose /dev/mshv to VMMs")Fixes 64503b4f4468 ("Drivers: hv: Introduce mshv_vtl driver")Signed-off-by Sean Christopherson <[email protected]>--- drivers/hv/mshv_common.c | 2 +- drivers/hv/mshv_root_main.c | 3 ++- drivers/hv/mshv_vtl_main.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-)drivers/hv/mshv_common.c +1
-1@@ -151,7 +151,7 @@ int mshv_do_pre_guest_mode_work(ulong th_flags)if (th_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))return -EINTR ; -if (th_flags & _TIF_NEED_RESCHED) +if (th_flags & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY))schedule ();if (th_flags & _TIF_NOTIFY_RESUME)drivers/hv/mshv_root_main.c +2
-1@@ -484,7 +484,8 @@ mshv_vp_wait_for_hv_kick(struct mshv_vp *vp)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; + _TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY | + _TIF_NOTIFY_RESUME;ulong th_flags; th_flags =read_thread_flags ();drivers/hv/mshv_vtl_main.c +0
-0
drivers/hv/mshv_vtl_main.c static int mshv_vtl_ioctl_return_to_lower_vtl(void) · line 735
Quoted 9 lines
drivers/hv/mshv_vtl_main.c +2
-1@@ -728,7 +728,8 @@ static int mshv_vtl_ioctl_return_to_lower_vtl(void)preempt_disable ();for (;;) {const unsigned long VTL0_WORK = _TIF_SIGPENDING | _TIF_NEED_RESCHED | - _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL; + _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL | + _TIF_NEED_RESCHED_LAZY;unsigned long ti_work;u32 cancel;unsigned long irq_flags;
Tested by compiling with CONFIG_PREEMPT_LAZY=y and booting a guest. For the test I added a check to confirm _TIF_NEED_RESCHED_LAZY was set and honored.
Looks good, thanks.
Sean Christopherson
maintainerPATCH v2 2/7 Drivers: hv: Disentangle VTL return cancellation from SIGPENDING
In reply to Sean ChristophersonCheck for return to a lower VTL being cancelled separately from handling pending TIF-based work, as there is no need to immediately process pending work; the kernel will immediately exit to userspace (ignoring preemption) and handle the pending work at that time.
Disentangling cancellation from the TIF-based work will allow switching to common virtualization APIs for detecting and processing pending work.
--- drivers/hv/mshv_vtl_main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/hv/mshv_vtl_main.c +7 -5
@@ -731,19 +731,21 @@ static int mshv_vtl_ioctl_return_to_lower_vtl(void) _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL | _TIF_NEED_RESCHED_LAZY;unsigned long ti_work; -u32 cancel;unsigned long irq_flags;struct hv_vp_assist_page *hvp;int ret;local_irq_save (irq_flags); +if (READ_ONCE (mshv_vtl_this_run ()->cancel)) { +local_irq_restore (irq_flags); +preempt_enable (); +return -EINTR ; + } + ti_work =READ_ONCE (current_thread_info ()->flags); - cancel =READ_ONCE (mshv_vtl_this_run ()->cancel); -if (unlikely ((ti_work &VTL0_WORK ) || cancel)) { +if (unlikely (ti_work &VTL0_WORK )) {local_irq_restore (irq_flags);preempt_enable (); -if (cancel) - ti_work |= _TIF_SIGPENDING; ret =mshv_do_pre_guest_mode_work (ti_work);if (ret)return ret;
Signature · 1 line
2.51.0.268.g9569e192d0-goog
Wei Liu
maintainerRe: [PATCH v2 2/7] Drivers: hv: Disentangle VTL return cancellation from SIGPENDING
Quoted 9 lines · Sean Christopherson
Check for return to a lower VTL being cancelled separately from handling pending TIF-based work, as there is no need to immediately process pending work; the kernel will immediately exit to userspace (ignoring preemption) and handle the pending work at that time.
Disentangling cancellation from the TIF-based work will allow switching to common virtualization APIs for detecting and processing pending work.
Signed-off-by Sean Christopherson <[email protected]>
Thanks for this patch, Sean.
My current plan is to drop this driver from my tree (hence it will disappear from linux-next soon) because Peter has an objection to the ABI it introduces. I just have not gotten around to it yet.
I won't apply this patch, the next one and the last one. I have CC'ed the owner of that driver to this patch here so that your suggestion can be incorporated in future submissions.
CC Saurabh and Naman.
Thanks,
Wei
Quoted 39 lines
--- drivers/hv/mshv_vtl_main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/hv/mshv_vtl_main.c +7
-5@@ -731,19 +731,21 @@ static int mshv_vtl_ioctl_return_to_lower_vtl(void) _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL | _TIF_NEED_RESCHED_LAZY;unsigned long ti_work; -u32 cancel;unsigned long irq_flags;struct hv_vp_assist_page *hvp;int ret;local_irq_save (irq_flags); +if (READ_ONCE (mshv_vtl_this_run ()->cancel)) { +local_irq_restore (irq_flags); +preempt_enable (); +return -EINTR ; + } + ti_work =READ_ONCE (current_thread_info ()->flags); - cancel =READ_ONCE (mshv_vtl_this_run ()->cancel); -if (unlikely ((ti_work &VTL0_WORK ) || cancel)) { +if (unlikely (ti_work &VTL0_WORK )) {local_irq_restore (irq_flags);preempt_enable (); -if (cancel) - ti_work |= _TIF_SIGPENDING; ret =mshv_do_pre_guest_mode_work (ti_work);if (ret)return ret;Signature · 1 line
2.51.0.268.g9569e192d0-goog
Sean Christopherson
maintainerPATCH v2 3/7 Drivers: hv: Disable IRQs only after handling pending work before VTL return
In reply to Sean ChristophersonSwap the order of checking for TIF-based work and cancellation, and disable IRQs only after checking and processing TIF-based work; checking TIF with IRQs enabled is a-ok, e.g. IRQs and preemption _must_ be enabled before handling the pending work.
--- drivers/hv/mshv_vtl_main.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/hv/mshv_vtl_main.c +7 -8
@@ -735,16 +735,8 @@ static int mshv_vtl_ioctl_return_to_lower_vtl(void)struct hv_vp_assist_page *hvp;int ret; -local_irq_save (irq_flags); -if (READ_ONCE (mshv_vtl_this_run ()->cancel)) { -local_irq_restore (irq_flags); -preempt_enable (); -return -EINTR ; - } - ti_work =READ_ONCE (current_thread_info ()->flags);if (unlikely (ti_work &VTL0_WORK )) { -local_irq_restore (irq_flags);preempt_enable (); ret =mshv_do_pre_guest_mode_work (ti_work);if (ret)
@@ -753,6 +745,13 @@ static int mshv_vtl_ioctl_return_to_lower_vtl(void)continue ; } +local_irq_save (irq_flags); +if (READ_ONCE (mshv_vtl_this_run ()->cancel)) { +local_irq_restore (irq_flags); +preempt_enable (); +return -EINTR ; + } +mshv_vtl_return (&mshv_vtl_this_run ()->cpu_context);local_irq_restore (irq_flags);
Signature · 1 line
2.51.0.268.g9569e192d0-goog
Sean Christopherson
maintainerPATCH v2 4/7 entry/kvm: KVM: Move KVM details related to signal/-EINTR into KVM proper
In reply to Sean ChristophersonMove KVM's morphing of pending signals into userspace exits into KVM proper, and drop the @vcpu param from xfer_to_guest_mode_handle_work(). How KVM responds to -EINTR is a detail that really belongs in KVM itself, and invoking kvm_handle_signal_exit() from kernel code creates an inverted module dependency. E.g. attempting to move kvm_handle_signal_exit() into kvm_main.c would generate an linker error when building kvm.ko as a module.
Dropping KVM details will also converting the KVM "entry" code into a more generic virtualization framework so that it can be used when running as a Hyper-V root partition.
Lastly, eliminating usage of "struct kvm_vcpu" outside of KVM is also nice to have for KVM x86 developers, as keeping the details of kvm_vcpu purely within KVM allows changing the layout of the structure without having to boot into a new kernel, e.g. allows rebuilding and reloading kvm.ko with a modified kvm_vcpu structure as part of debug/development.
--- arch/arm64/kvm/arm.c | 3 +-- arch/loongarch/kvm/vcpu.c | 3 +-- arch/riscv/kvm/vcpu.c | 3 +-- arch/x86/kvm/vmx/vmx.c | 1 - arch/x86/kvm/x86.c | 3 +-- include/linux/entry-kvm.h | 11 +++-------- include/linux/kvm_host.h | 13 ++++++++++++- kernel/entry/kvm.c | 13 +++++-------- 8 files changed, 24 insertions(+), 26 deletions(-)
arch/arm64/kvm/arm.c +1 -2
@@ -6,7 +6,6 @@#include <linux/bug.h> #include <linux/cpu_pm.h> -#include <linux/entry-kvm.h> #include <linux/errno.h> #include <linux/err.h> #include <linux/kvm_host.h>
@@ -1177,7 +1176,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)/* * Check conditions before entering the guest */ - ret =xfer_to_guest_mode_handle_work (vcpu); + ret =kvm_xfer_to_guest_mode_handle_work (vcpu);if (!ret) ret =1 ;
arch/loongarch/kvm/vcpu.c +1 -2
@@ -4,7 +4,6 @@*/ #include <linux/kvm_host.h> -#include <linux/entry-kvm.h> #include <asm/fpu.h> #include <asm/lbt.h> #include <asm/loongarch.h>
@@ -251,7 +250,7 @@ static int kvm_enter_guest_check(struct kvm_vcpu *vcpu)/* * Check conditions before entering the guest */ - ret =xfer_to_guest_mode_handle_work (vcpu); + ret =kvm_xfer_to_guest_mode_handle_work (vcpu);if (ret <0 )return ret;
arch/riscv/kvm/vcpu.c +1 -2
@@ -7,7 +7,6 @@*/ #include <linux/bitops.h> -#include <linux/entry-kvm.h> #include <linux/errno.h> #include <linux/err.h> #include <linux/kdebug.h>
@@ -910,7 +909,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) run->exit_reason =KVM_EXIT_UNKNOWN ;while (ret >0 ) {/* Check conditions before entering the guest */ - ret =xfer_to_guest_mode_handle_work (vcpu); + ret =kvm_xfer_to_guest_mode_handle_work (vcpu);if (ret)continue ; ret =1 ;
arch/x86/kvm/vmx/vmx.c +0 -1
@@ -28,7 +28,6 @@#include <linux/slab.h> #include <linux/tboot.h> #include <linux/trace_events.h> -#include <linux/entry-kvm.h> #include <asm/apic.h> #include <asm/asm.h>
arch/x86/kvm/x86.c +1 -2
@@ -59,7 +59,6 @@#include <linux/sched/stat.h> #include <linux/sched/isolation.h> #include <linux/mem_encrypt.h> -#include <linux/entry-kvm.h> #include <linux/suspend.h> #include <linux/smp.h>
@@ -11241,7 +11240,7 @@ static int vcpu_run(struct kvm_vcpu *vcpu)if (__xfer_to_guest_mode_work_pending ()) {kvm_vcpu_srcu_read_unlock (vcpu); - r =xfer_to_guest_mode_handle_work (vcpu); + r =kvm_xfer_to_guest_mode_handle_work (vcpu);kvm_vcpu_srcu_read_lock (vcpu);if (r)return r;
include/linux/entry-kvm.h +3 -8
@@ -21,8 +21,6 @@ _TIF_NOTIFY_SIGNAL | _TIF_NOTIFY_RESUME | \ ARCH_XFER_TO_GUEST_MODE_WORK) -struct kvm_vcpu ; -/** * arch_xfer_to_guest_mode_handle_work - Architecture specific xfer to guest * mode work handling function.
@@ -32,12 +30,10 @@ struct kvm_vcpu;* Invoked from xfer_to_guest_mode_handle_work(). Defaults to NOOP. Can be * replaced by architecture specific code. */ -static inline int arch_xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu, -unsigned long ti_work); +static inline int arch_xfer_to_guest_mode_handle_work (unsigned long ti_work);#ifndef arch_xfer_to_guest_mode_work -static inline int arch_xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu, -unsigned long ti_work) +static inline int arch_xfer_to_guest_mode_handle_work (unsigned long ti_work) {return 0 ; }
@@ -46,11 +42,10 @@ static inline int arch_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu,/** * xfer_to_guest_mode_handle_work - Check and handle pending work which needs * to be handled before going to guest mode -* @vcpu: Pointer to current's VCPU data * * Returns: 0 or an error code */ -int xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu); +int xfer_to_guest_mode_handle_work (void );/** * xfer_to_guest_mode_prepare - Perform last minute preparation work that
include/linux/kvm_host.h +12 -1
@@ -2,7 +2,7 @@#ifndef __KVM_HOST_H#define __KVM_HOST_H - +#include <linux/entry-kvm.h> #include <linux/types.h> #include <linux/hardirq.h> #include <linux/list.h>
@@ -2450,6 +2450,17 @@ static inline void kvm_handle_signal_exit(struct kvm_vcpu *vcpu) vcpu->run->exit_reason =KVM_EXIT_INTR ; vcpu->stat.signal_exits++; } + +static inline int kvm_xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu) +{ +int r =xfer_to_guest_mode_handle_work (); + +if (r) { +WARN_ON_ONCE (r != -EINTR ); +kvm_handle_signal_exit (vcpu); + } +return r; +}#endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */ /*
kernel/entry/kvm.c +5 -8
@@ -1,17 +1,14 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/entry-kvm.h> -#include <linux/kvm_host.h> -static int xfer_to_guest_mode_work (struct kvm_vcpu *vcpu,unsigned long ti_work) +static int xfer_to_guest_mode_work (unsigned long ti_work) { do { int ret; - if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) { - kvm_handle_signal_exit(vcpu); + if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) return -EINTR; - } if (ti_work & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)) schedule();
@@ -19,7 +16,7 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)if (ti_work & _TIF_NOTIFY_RESUME)resume_user_mode_work (NULL ); - ret =arch_xfer_to_guest_mode_handle_work (vcpu, ti_work); + ret =arch_xfer_to_guest_mode_handle_work (ti_work);if (ret)return ret;
@@ -28,7 +25,7 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)return 0 ; } -int xfer_to_guest_mode_handle_work (struct kvm_vcpu *vcpu) +int xfer_to_guest_mode_handle_work (void ) {unsigned long ti_work;
@@ -44,6 +41,6 @@ int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu)if (!(ti_work &XFER_TO_GUEST_MODE_WORK ))return 0 ; -return xfer_to_guest_mode_work (vcpu, ti_work); +return xfer_to_guest_mode_work (ti_work); }EXPORT_SYMBOL_GPL (xfer_to_guest_mode_handle_work);
Signature · 1 line
2.51.0.268.g9569e192d0-goog
Re: [PATCH v2 4/7] entry/kvm: KVM: Move KVM details related to signal/-EINTR into KVM proper
Quoted 11 lines · Sean Christopherson
Move KVM's morphing of pending signals into userspace exits into KVM proper, and drop the @vcpu param from
xfer_to_guest_mode_handle_work(). How KVM responds to-EINTRis a detail that really belongs in KVM itself, and invokingkvm_handle_signal_exit()from kernel code creates an inverted module dependency. E.g. attempting to movekvm_handle_signal_exit()intokvm_main.cwould generate an linker error when building kvm.ko as a module.Dropping KVM details will also converting the KVM "entry" code into a more generic virtualization framework so that it can be used when running as a Hyper-V root partition.
Quoted 7 lines
Lastly, eliminating usage of "struct
kvm_vcpu" outside of KVM is also nice to have for KVM x86 developers, as keeping the details ofkvm_vcpupurely within KVM allows changing the layout of the structure without having to boot into a new kernel, e.g. allows rebuilding and reloading kvm.ko with a modifiedkvm_vcpustructure as part of debug/development.Signed-off-by Sean Christopherson <[email protected]>
Sean Christopherson
maintainerPATCH v2 5/7 entry: Rename "kvm" entry code assets to "virt" to genericize APIs
In reply to Sean ChristophersonRename the "kvm" entry code files and Kconfigs to use generic "virt" nomenclature so that the code can be reused by other hypervisors (or rather, their root/dom0 partition drivers), without incorrectly suggesting the code somehow relies on and/or involves KVM.
No functional change intended.
---
MAINTAINERS | 2 +-
arch/arm64/kvm/Kconfig | 2 +-
arch/loongarch/kvm/Kconfig | 2 +-
arch/riscv/kvm/Kconfig | 2 +-
arch/x86/kvm/Kconfig | 2 +-
include/linux/{entry-kvm.h => entry-virt.h} | 8 ++++----
include/linux/kvm_host.h | 6 +++---
include/linux/rcupdate.h | 2 +-
kernel/entry/Makefile | 2 +-
kernel/entry/{kvm.c => virt.c} | 2 +-
kernel/rcu/tree.c | 6 +++---
virt/kvm/Kconfig | 2 +-
12 files changed, 19 insertions(+), 19 deletions(-)
rename include/linux/{entry-kvm.h => entry-virt.h} (94%)
rename kernel/entry/{kvm.c => virt.c} (97%)MAINTAINERS +1 -1
@@ -10200,7 +10200,7 @@ L: [email protected] S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core/entry F: include/linux/entry-common.h -F: include/linux/entry-kvm.h +F: include/linux/entry-virt.h F: include/linux/irq-entry-common.h F: kernel/entry/
arch/arm64/kvm/Kconfig +1 -1
@@ -25,7 +25,7 @@ menuconfig KVM select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_MMIO select KVM_GENERIC_DIRTYLOG_READ_PROTECT - select KVM_XFER_TO_GUEST_WORK + select VIRT_XFER_TO_GUEST_WORK select KVM_VFIO select HAVE_KVM_DIRTY_RING_ACQ_REL select NEED_KVM_DIRTY_RING_WITH_BITMAP
arch/loongarch/kvm/Kconfig +1 -1
@@ -31,7 +31,7 @@ config KVM select KVM_GENERIC_HARDWARE_ENABLING select KVM_GENERIC_MMU_NOTIFIER select KVM_MMIO - select KVM_XFER_TO_GUEST_WORK + select VIRT_XFER_TO_GUEST_WORK select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS help
arch/riscv/kvm/Kconfig +1 -1
@@ -30,7 +30,7 @@ config KVM select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_GENERIC_HARDWARE_ENABLING select KVM_MMIO - select KVM_XFER_TO_GUEST_WORK + select VIRT_XFER_TO_GUEST_WORK select KVM_GENERIC_MMU_NOTIFIER select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS
arch/x86/kvm/Kconfig +1 -1
@@ -40,7 +40,7 @@ config KVM_X86 select HAVE_KVM_MSI select HAVE_KVM_CPU_RELAX_INTERCEPT select HAVE_KVM_NO_POLL - select KVM_XFER_TO_GUEST_WORK + select VIRT_XFER_TO_GUEST_WORK select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_VFIO select HAVE_KVM_PM_NOTIFIER if PM
include/linux/entry-virt.h renamed from include/linux/entry-kvm.h +4 -4
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __LINUX_ENTRYKVM_H -#define __LINUX_ENTRYKVM_H +#ifndef __LINUX_ENTRYVIRT_H +#define __LINUX_ENTRYVIRT_H#include <linux/static_call_types.h> #include <linux/resume_user_mode.h>
@@ -10,7 +10,7 @@#include <linux/tick.h> /* Transfer to guest mode work */ -#ifdef CONFIG_KVM_XFER_TO_GUEST_WORK +#ifdef CONFIG_VIRT_XFER_TO_GUEST_WORK #ifndef ARCH_XFER_TO_GUEST_MODE_WORK # define ARCH_XFER_TO_GUEST_MODE_WORK (0)
@@ -90,6 +90,6 @@ static inline bool xfer_to_guest_mode_work_pending(void)lockdep_assert_irqs_disabled ();return __xfer_to_guest_mode_work_pending (); } -#endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */ +#endif /* CONFIG_VIRT_XFER_TO_GUEST_WORK */ #endif
include/linux/kvm_host.h +3 -3
@@ -2,7 +2,7 @@#ifndef __KVM_HOST_H#define __KVM_HOST_H -#include <linux/entry-kvm.h> +#include <linux/entry-virt.h> #include <linux/types.h> #include <linux/hardirq.h> #include <linux/list.h>
@@ -2444,7 +2444,7 @@ static inline int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu) }#endif /* CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE */ -#ifdef CONFIG_KVM_XFER_TO_GUEST_WORK +#ifdef CONFIG_VIRT_XFER_TO_GUEST_WORK static inline void kvm_handle_signal_exit (struct kvm_vcpu *vcpu) { vcpu->run->exit_reason =KVM_EXIT_INTR ;
@@ -2461,7 +2461,7 @@ static inline int kvm_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu) }return r; } -#endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */ +#endif /* CONFIG_VIRT_XFER_TO_GUEST_WORK */ /* * If more than one page is being (un)accounted, @virt must be the address of
include/linux/rcupdate.h +1 -1
@@ -129,7 +129,7 @@ static inline void rcu_sysrq_start(void) { }static inline void rcu_sysrq_end (void ) { }#endif /* #else #ifdef CONFIG_RCU_STALL_COMMON */ -#if defined(CONFIG_NO_HZ_FULL ) && (!defined(CONFIG_GENERIC_ENTRY ) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK )) +#if defined(CONFIG_NO_HZ_FULL ) && (!defined(CONFIG_GENERIC_ENTRY ) || !defined(CONFIG_VIRT_XFER_TO_GUEST_WORK ))void rcu_irq_work_resched (void );#else static __always_inline void rcu_irq_work_resched(void) { }
kernel/entry/Makefile +1 -1
@@ -14,4 +14,4 @@ CFLAGS_common.o += -fno-stack-protector obj-$(CONFIG_GENERIC_IRQ_ENTRY) += common.o obj-$(CONFIG_GENERIC_SYSCALL) += syscall-common.o syscall_user_dispatch.o -obj-$(CONFIG_KVM_XFER_TO_GUEST_WORK) += kvm.o +obj-$(CONFIG_VIRT_XFER_TO_GUEST_WORK) += virt.o
kernel/entry/virt.c renamed from kernel/entry/kvm.c +1 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 -#include <linux/entry-kvm.h> +#include <linux/entry-virt.h> static int xfer_to_guest_mode_work (unsigned long ti_work) {
kernel/rcu/tree.c +3 -3
@@ -573,7 +573,7 @@ void rcutorture_format_gp_seqs(unsigned long long seqs, char *cp, size_t len) }EXPORT_SYMBOL_GPL (rcutorture_format_gp_seqs); -#if defined(CONFIG_NO_HZ_FULL ) && (!defined(CONFIG_GENERIC_ENTRY ) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK )) +#if defined(CONFIG_NO_HZ_FULL ) && (!defined(CONFIG_GENERIC_ENTRY ) || !defined(CONFIG_VIRT_XFER_TO_GUEST_WORK ))/* * An empty function that will trigger a reschedule on * IRQ tail once IRQs get re-enabled on userspace/guest resume.
@@ -602,7 +602,7 @@ noinstr void rcu_irq_work_resched(void)if (IS_ENABLED (CONFIG_GENERIC_ENTRY ) && !(current->flags &PF_VCPU ))return ; -if (IS_ENABLED (CONFIG_KVM_XFER_TO_GUEST_WORK ) && (current->flags &PF_VCPU )) +if (IS_ENABLED (CONFIG_VIRT_XFER_TO_GUEST_WORK ) && (current->flags &PF_VCPU ))return ;instrumentation_begin ();
@@ -611,7 +611,7 @@ noinstr void rcu_irq_work_resched(void) }instrumentation_end (); } -#endif /* #if defined(CONFIG_NO_HZ_FULL) && (!defined(CONFIG_GENERIC_ENTRY) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK)) */ +#endif /* #if defined(CONFIG_NO_HZ_FULL) && (!defined(CONFIG_GENERIC_ENTRY) || !defined(CONFIG_VIRT_XFER_TO_GUEST_WORK)) */ #ifdef CONFIG_PROVE_RCU /**
virt/kvm/Kconfig +1 -1
@@ -87,7 +87,7 @@ config HAVE_KVM_VCPU_RUN_PID_CHANGE config HAVE_KVM_NO_POLL bool -config KVM_XFER_TO_GUEST_WORK +config VIRT_XFER_TO_GUEST_WORK bool config HAVE_KVM_PM_NOTIFIER
Signature · 1 line
2.51.0.268.g9569e192d0-goog
Re: [PATCH v2 5/7] entry: Rename "kvm" entry code assets to "virt" to genericize APIs
Quoted 8 lines · Sean Christopherson
Rename the "kvm" entry code files and Kconfigs to use generic "virt" nomenclature so that the code can be reused by other hypervisors (or rather, their root/dom0 partition drivers), without incorrectly suggesting the code somehow relies on and/or involves KVM.
No functional change intended.
Signed-off-by Sean Christopherson <[email protected]>
Re: [PATCH v2 5/7] entry: Rename "kvm" entry code assets to "virt" to genericize APIs
In reply to Sean ChristophersonQuoted 8 lines · Sean Christopherson
Rename the "kvm" entry code files and Kconfigs to use generic "virt" nomenclature so that the code can be reused by other hypervisors (or rather, their root/dom0 partition drivers), without incorrectly suggesting the code somehow relies on and/or involves KVM.
No functional change intended.
Signed-off-by Sean Christopherson <[email protected]>
Quoted 12 lines
---
MAINTAINERS | 2 +-
arch/arm64/kvm/Kconfig | 2 +-
arch/loongarch/kvm/Kconfig | 2 +-
arch/riscv/kvm/Kconfig | 2 +-
arch/x86/kvm/Kconfig | 2 +-
include/linux/{entry-kvm.h => entry-virt.h} | 8 ++++----
include/linux/kvm_host.h | 6 +++---
include/linux/rcupdate.h | 2 +-
kernel/entry/Makefile | 2 +-
kernel/entry/{kvm.c => virt.c} | 2 +-
kernel/rcu/tree.c | 6 +++---For RCU part,
thanks,
- Joel
Quoted 219 lines
virt/kvm/Kconfig | 2 +- 12 files changed, 19 insertions(+), 19 deletions(-) rename include/linux/{entry-kvm.h => entry-virt.h} (94%) rename kernel/entry/{kvm.c => virt.c} (97%)MAINTAINERS +1
-1@@ -10200,7 +10200,7 @@ L: [email protected] S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core/entry F: include/linux/entry-common.h -F: include/linux/entry-kvm.h +F: include/linux/entry-virt.h F: include/linux/irq-entry-common.h F: kernel/entry/arch/arm64/kvm/Kconfig +1
-1@@ -25,7 +25,7 @@ menuconfig KVM select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_MMIO select KVM_GENERIC_DIRTYLOG_READ_PROTECT - select KVM_XFER_TO_GUEST_WORK + select VIRT_XFER_TO_GUEST_WORK select KVM_VFIO select HAVE_KVM_DIRTY_RING_ACQ_REL select NEED_KVM_DIRTY_RING_WITH_BITMAParch/loongarch/kvm/Kconfig +1
-1@@ -31,7 +31,7 @@ config KVM select KVM_GENERIC_HARDWARE_ENABLING select KVM_GENERIC_MMU_NOTIFIER select KVM_MMIO - select KVM_XFER_TO_GUEST_WORK + select VIRT_XFER_TO_GUEST_WORK select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS helparch/riscv/kvm/Kconfig +1
-1@@ -30,7 +30,7 @@ config KVM select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_GENERIC_HARDWARE_ENABLING select KVM_MMIO - select KVM_XFER_TO_GUEST_WORK + select VIRT_XFER_TO_GUEST_WORK select KVM_GENERIC_MMU_NOTIFIER select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTSarch/x86/kvm/Kconfig +1
-1@@ -40,7 +40,7 @@ config KVM_X86 select HAVE_KVM_MSI select HAVE_KVM_CPU_RELAX_INTERCEPT select HAVE_KVM_NO_POLL - select KVM_XFER_TO_GUEST_WORK + select VIRT_XFER_TO_GUEST_WORK select KVM_GENERIC_DIRTYLOG_READ_PROTECT select KVM_VFIO select HAVE_KVM_PM_NOTIFIER if PMinclude/linux/entry-virt.h renamed from include/linux/entry-kvm.h +4
-4@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __LINUX_ENTRYKVM_H -#define __LINUX_ENTRYKVM_H +#ifndef __LINUX_ENTRYVIRT_H +#define __LINUX_ENTRYVIRT_H#include <linux/static_call_types.h> #include <linux/resume_user_mode.h> @@ -10,7 +10,7 @@#include <linux/tick.h> /* Transfer to guest mode work */ -#ifdef CONFIG_KVM_XFER_TO_GUEST_WORK +#ifdef CONFIG_VIRT_XFER_TO_GUEST_WORK #ifndef ARCH_XFER_TO_GUEST_MODE_WORK # define ARCH_XFER_TO_GUEST_MODE_WORK (0)@@ -90,6 +90,6 @@ static inline bool xfer_to_guest_mode_work_pending(void)lockdep_assert_irqs_disabled ();return __xfer_to_guest_mode_work_pending (); } -#endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */ +#endif /* CONFIG_VIRT_XFER_TO_GUEST_WORK */ #endif include/linux/kvm_host.h +3
-3@@ -2,7 +2,7 @@#ifndef __KVM_HOST_H#define __KVM_HOST_H -#include <linux/entry-kvm.h> +#include <linux/entry-virt.h> #include <linux/types.h> #include <linux/hardirq.h> #include <linux/list.h> @@ -2444,7 +2444,7 @@ static inline int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu) }#endif /* CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE */ -#ifdef CONFIG_KVM_XFER_TO_GUEST_WORK +#ifdef CONFIG_VIRT_XFER_TO_GUEST_WORK static inline void kvm_handle_signal_exit (struct kvm_vcpu *vcpu) { vcpu->run->exit_reason =KVM_EXIT_INTR ;@@ -2461,7 +2461,7 @@ static inline int kvm_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu) }return r; } -#endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */ +#endif /* CONFIG_VIRT_XFER_TO_GUEST_WORK */ /* * If more than one page is being (un)accounted, @virt must be the address of include/linux/rcupdate.h +1
-1@@ -129,7 +129,7 @@ static inline void rcu_sysrq_start(void) { }static inline void rcu_sysrq_end (void ) { }#endif /* #else #ifdef CONFIG_RCU_STALL_COMMON */ -#if defined(CONFIG_NO_HZ_FULL ) && (!defined(CONFIG_GENERIC_ENTRY ) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK )) +#if defined(CONFIG_NO_HZ_FULL ) && (!defined(CONFIG_GENERIC_ENTRY ) || !defined(CONFIG_VIRT_XFER_TO_GUEST_WORK ))void rcu_irq_work_resched (void );#else static __always_inline void rcu_irq_work_resched(void) { }kernel/entry/Makefile +1
-1@@ -14,4 +14,4 @@ CFLAGS_common.o += -fno-stack-protector obj-$(CONFIG_GENERIC_IRQ_ENTRY) += common.o obj-$(CONFIG_GENERIC_SYSCALL) += syscall-common.o syscall_user_dispatch.o -obj-$(CONFIG_KVM_XFER_TO_GUEST_WORK) += kvm.o +obj-$(CONFIG_VIRT_XFER_TO_GUEST_WORK) += virt.okernel/entry/virt.c renamed from kernel/entry/kvm.c +1
-1@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 -#include <linux/entry-kvm.h> +#include <linux/entry-virt.h> static int xfer_to_guest_mode_work (unsigned long ti_work) {kernel/rcu/tree.c +3
-3@@ -573,7 +573,7 @@ void rcutorture_format_gp_seqs(unsigned long long seqs, char *cp, size_t len) }EXPORT_SYMBOL_GPL (rcutorture_format_gp_seqs); -#if defined(CONFIG_NO_HZ_FULL ) && (!defined(CONFIG_GENERIC_ENTRY ) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK )) +#if defined(CONFIG_NO_HZ_FULL ) && (!defined(CONFIG_GENERIC_ENTRY ) || !defined(CONFIG_VIRT_XFER_TO_GUEST_WORK ))/* * An empty function that will trigger a reschedule on * IRQ tail once IRQs get re-enabled on userspace/guest resume. @@ -602,7 +602,7 @@ noinstr void rcu_irq_work_resched(void)if (IS_ENABLED (CONFIG_GENERIC_ENTRY ) && !(current->flags &PF_VCPU ))return ; -if (IS_ENABLED (CONFIG_KVM_XFER_TO_GUEST_WORK ) && (current->flags &PF_VCPU )) +if (IS_ENABLED (CONFIG_VIRT_XFER_TO_GUEST_WORK ) && (current->flags &PF_VCPU ))return ;instrumentation_begin ();@@ -611,7 +611,7 @@ noinstr void rcu_irq_work_resched(void) }instrumentation_end (); } -#endif /* #if defined(CONFIG_NO_HZ_FULL) && (!defined(CONFIG_GENERIC_ENTRY) || !defined(CONFIG_KVM_XFER_TO_GUEST_WORK)) */ +#endif /* #if defined(CONFIG_NO_HZ_FULL) && (!defined(CONFIG_GENERIC_ENTRY) || !defined(CONFIG_VIRT_XFER_TO_GUEST_WORK)) */ #ifdef CONFIG_PROVE_RCU /** virt/kvm/Kconfig +1
-1@@ -87,7 +87,7 @@ config HAVE_KVM_VCPU_RUN_PID_CHANGE config HAVE_KVM_NO_POLL bool -config KVM_XFER_TO_GUEST_WORK +config VIRT_XFER_TO_GUEST_WORK bool config HAVE_KVM_PM_NOTIFIERSignature · 1 line
2.51.0.268.g9569e192d0-goog
Sean Christopherson
maintainerPATCH v2 6/7 Drivers: hv: Use common "entry virt" APIs to do work in root before running guest
In reply to Sean ChristophersonUse 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.
--- drivers/hv/Kconfig | 1 + drivers/hv/mshv_root_main.c | 32 ++++++-------------------------- 2 files changed, 7 insertions(+), 26 deletions(-)
drivers/hv/Kconfig +1 -0
@@ -66,6 +66,7 @@ config MSHV_ROOT # no particular order, making it impossible to reassemble larger pages depends on PAGE_SIZE_4KB select EVENTFD + select VIRT_XFER_TO_GUEST_WORK default n help Select this option to enable support for booting and running as root
drivers/hv/mshv_root_main.c +6 -26
@@ -8,6 +8,7 @@* Authors: Microsoft Linux virtualization team */ +#include <linux/entry-virt.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/fs.h>
@@ -481,29 +482,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_NEED_RESCHED_LAZY | - _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) {
@@ -524,9 +502,11 @@ 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); -if (ret) -break ; +if (__xfer_to_guest_mode_work_pending ()) { + ret =xfer_to_guest_mode_handle_work (); +if (ret) +break ; + }if (vp->run.flags.intercept_suspend) flags |=HV_DISPATCH_VP_FLAG_CLEAR_INTERCEPT_SUSPEND ;
Signature · 1 line
2.51.0.268.g9569e192d0-goog
Re: [PATCH v2 6/7] Drivers: hv: Use common "entry virt" APIs to do work in root before running guest
Quoted 71 lines · Sean Christopherson
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 <[email protected]>--- drivers/hv/Kconfig | 1 + drivers/hv/mshv_root_main.c | 32 ++++++-------------------------- 2 files changed, 7 insertions(+), 26 deletions(-)drivers/hv/Kconfig +1
-0@@ -66,6 +66,7 @@ config MSHV_ROOT # no particular order, making it impossible to reassemble larger pages depends on PAGE_SIZE_4KB select EVENTFD + select VIRT_XFER_TO_GUEST_WORK default n help Select this option to enable support for booting and running as rootdrivers/hv/mshv_root_main.c +1
-24@@ -8,6 +8,7 @@* Authors: Microsoft Linux virtualization team */ +#include <linux/entry-virt.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/fs.h> @@ -481,29 +482,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_NEED_RESCHED_LAZY | - _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) {@@ -524,9 +502,11 @@ 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);
drivers/hv/mshv_root_main.c static long mshv_run_vp_with_root_scheduler(struct mshv_vp *vp) · line 512
Quoted 10 lines
drivers/hv/mshv_root_main.c +5
-2-if (ret) -break ; +if (__xfer_to_guest_mode_work_pending ()) { + ret =xfer_to_guest_mode_handle_work (); +if (ret) +break ; + }if (vp->run.flags.intercept_suspend) flags |=HV_DISPATCH_VP_FLAG_CLEAR_INTERCEPT_SUSPEND ;
Also tested mshv_root with 1-6 applied, looks good to me. Possibly Naman, Saurabh, or Roman can test the mshv_vtl patches, I can't do it unfortunately.
Sean Christopherson
maintainerPATCH v2 7/7 Drivers: hv: Use "entry virt" APIs to do work before returning to lower VTL
In reply to Sean ChristophersonUse the kernel's common "entry virt" APIs to handle pending work prior to returning to a lower VTL. Drop the now-defunct common MSHV helper for doing work as the VTL driver was the last user.
No functional change intended.
--- drivers/hv/Kconfig | 1 + drivers/hv/mshv.h | 2 -- drivers/hv/mshv_common.c | 22 ---------------------- drivers/hv/mshv_vtl_main.c | 11 +++-------- 4 files changed, 4 insertions(+), 32 deletions(-)
drivers/hv/Kconfig +1 -0
@@ -85,6 +85,7 @@ config MSHV_VTL # Therefore, do not attempt to access or modify MTRRs here. depends on !MTRR select CPUMASK_OFFSTACK + select VIRT_XFER_TO_GUEST_WORK default n help Select this option to enable Hyper-V VTL driver support.
drivers/hv/mshv.h +0 -2
@@ -25,6 +25,4 @@ 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); -#endif /* _MSHV_H */
drivers/hv/mshv_common.c +0 -22
@@ -138,25 +138,3 @@ int hv_call_get_partition_property(u64 partition_id,return 0 ; }EXPORT_SYMBOL_GPL (hv_call_get_partition_property); - -/* -* Handle any pre-processing before going into the guest mode on this cpu, most -* notably call schedule(). Must be invoked with both preemption and -* interrupts enabled. -* -* Returns: 0 on success, -errno on error. -*/ -int mshv_do_pre_guest_mode_work (ulong th_flags) -{ -if (th_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) -return -EINTR ; - -if (th_flags & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)) -schedule (); - -if (th_flags & _TIF_NOTIFY_RESUME) -resume_user_mode_work (NULL ); - -return 0 ; -} -EXPORT_SYMBOL_GPL (mshv_do_pre_guest_mode_work);
drivers/hv/mshv_vtl_main.c +3 -8
@@ -8,6 +8,7 @@* Naman Jain <[email protected]> */ +#include <linux/entry-virt.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/miscdevice.h>
@@ -727,22 +728,16 @@ static int mshv_vtl_ioctl_return_to_lower_vtl(void) {preempt_disable ();for (;;) { -const unsigned long VTL0_WORK = _TIF_SIGPENDING | _TIF_NEED_RESCHED | - _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL | - _TIF_NEED_RESCHED_LAZY; -unsigned long ti_work;unsigned long irq_flags;struct hv_vp_assist_page *hvp;int ret; - ti_work =READ_ONCE (current_thread_info ()->flags); -if (unlikely (ti_work &VTL0_WORK )) { +if (__xfer_to_guest_mode_work_pending ()) {preempt_enable (); - ret =mshv_do_pre_guest_mode_work (ti_work); + ret =xfer_to_guest_mode_handle_work ();if (ret)return ret;preempt_disable (); -continue ; }local_irq_save (irq_flags);
Signature · 1 line
2.51.0.268.g9569e192d0-goog
Wei Liu
maintainerQuoted 22 lines · Sean Christopherson
Fix a bug where MSHV root partitions (and upper-level VTL code) don't honor
NEED_RESCHED_LAZY, and then deduplicate the TIF related MSHV code by turning the "kvm" entry APIs into more generic "virt" APIs.This version is based on
git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.githyperv-nextin order to pickup the VTL changes that are queued for 6.18. I also squashed the
NEED_RESCHED_LAZYfixes for root and VTL modes into a single patch, as it should be easy/straightforward to drop the VTL change as needed if we want this in 6.17 or earlier.That effectively means the full series is dependent on the VTL changes being fully merged for 6.18. But I think that's ok as it's really only the MSHV changes that have any urgency whatsoever, and I assume that Microsoft is the only user that truly cares about the MSHV root fix. I.e. if the whole thing gets delayed, I think it's only the Hyper-V folks that are impacted.
I have no preference what tree this goes through, or when, and can respin and/or split as needed.
Quoted 9 lines
As with v1, the Hyper-V stuff and non-x86 architectures are compile-tested only.
v2:
- Rebase on hyperv-next.
- Fix and converge the VTL code as well. [Peter, Nuno]
I dropped the mshv_vtl changes in this series and applied the rest (including the KVM changes) to hyperv-next.
Thanks,
Wei
Sean Christopherson
maintainerQuoted 30 lines · Wei Liu
Quoted 29 lines · Sean Christopherson
Fix a bug where MSHV root partitions (and upper-level VTL code) don't honor
NEED_RESCHED_LAZY, and then deduplicate the TIF related MSHV code by turning the "kvm" entry APIs into more generic "virt" APIs.This version is based on
git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.githyperv-nextin order to pickup the VTL changes that are queued for 6.18. I also squashed the
NEED_RESCHED_LAZYfixes for root and VTL modes into a single patch, as it should be easy/straightforward to drop the VTL change as needed if we want this in 6.17 or earlier.That effectively means the full series is dependent on the VTL changes being fully merged for 6.18. But I think that's ok as it's really only the MSHV changes that have any urgency whatsoever, and I assume that Microsoft is the only user that truly cares about the MSHV root fix. I.e. if the whole thing gets delayed, I think it's only the Hyper-V folks that are impacted.
I have no preference what tree this goes through, or when, and can respin and/or split as needed.
As with v1, the Hyper-V stuff and non-x86 architectures are compile-tested only.
v2:
- Rebase on hyperv-next.
- Fix and converge the VTL code as well. [Peter, Nuno]
Quoted 5 lines
Quoted 2 lines
I dropped the
mshv_vtlchanges in this series and applied the rest (including the KVM changes) to hyperv-next.
mshv_do_pre_guest_mode_work() ended up getting left behind since its removal was in the last mshv_vtl patch.
$ git grep mshv_do_pre_guest_mode_work drivers/hv/mshv.h:int mshv_do_pre_guest_mode_work(ulong th_flags); drivers/hv/mshv_common.c:int mshv_do_pre_guest_mode_work(ulong th_flags) drivers/hv/mshv_common.c:EXPORT_SYMBOL_GPL(mshv_do_pre_guest_mode_work);
Want to squash this into 3786d7d6b3c0 ("mshv: Use common "entry virt" APIs to do work in root before running guest")?
--- drivers/hv/mshv.h | 2 -- drivers/hv/mshv_common.c | 22 ---------------------- 2 files changed, 24 deletions(-)
drivers/hv/mshv.h +0 -2
@@ -25,6 +25,4 @@ 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); -#endif /* _MSHV_H */
drivers/hv/mshv_common.c +0 -22
@@ -138,25 +138,3 @@ int hv_call_get_partition_property(u64 partition_id,return 0 ; }EXPORT_SYMBOL_GPL (hv_call_get_partition_property); - -/* -* Handle any pre-processing before going into the guest mode on this cpu, most -* notably call schedule(). Must be invoked with both preemption and -* interrupts enabled. -* -* Returns: 0 on success, -errno on error. -*/ -int mshv_do_pre_guest_mode_work (ulong th_flags) -{ -if (th_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) -return -EINTR ; - -if (th_flags & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)) -schedule (); - -if (th_flags & _TIF_NOTIFY_RESUME) -resume_user_mode_work (NULL ); - -return 0 ; -} -EXPORT_SYMBOL_GPL (mshv_do_pre_guest_mode_work);
base-commit: 3786d7d6b3c0a412ebe4439ba4a7d4b0e27d9a12 --
Wei Liu
maintainerQuoted 40 lines · Sean Christopherson
Quoted 30 lines · Wei Liu
Quoted 29 lines · Sean Christopherson
Fix a bug where MSHV root partitions (and upper-level VTL code) don't honor
NEED_RESCHED_LAZY, and then deduplicate the TIF related MSHV code by turning the "kvm" entry APIs into more generic "virt" APIs.This version is based on
git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.githyperv-nextin order to pickup the VTL changes that are queued for 6.18. I also squashed the
NEED_RESCHED_LAZYfixes for root and VTL modes into a single patch, as it should be easy/straightforward to drop the VTL change as needed if we want this in 6.17 or earlier.That effectively means the full series is dependent on the VTL changes being fully merged for 6.18. But I think that's ok as it's really only the MSHV changes that have any urgency whatsoever, and I assume that Microsoft is the only user that truly cares about the MSHV root fix. I.e. if the whole thing gets delayed, I think it's only the Hyper-V folks that are impacted.
I have no preference what tree this goes through, or when, and can respin and/or split as needed.
As with v1, the Hyper-V stuff and non-x86 architectures are compile-tested only.
v2:
- Rebase on hyperv-next.
- Fix and converge the VTL code as well. [Peter, Nuno]Quoted 5 lines
Quoted 2 lines
I dropped the
mshv_vtlchanges in this series and applied the rest (including the KVM changes) to hyperv-next.
mshv_do_pre_guest_mode_work()ended up getting left behind since its removal was in the lastmshv_vtlpatch.
Quoted 8 lines
$ git grep mshv_do_pre_guest_mode_work drivers/hv/mshv.h:int mshv_do_pre_guest_mode_work(ulong th_flags); drivers/hv/mshv_common.c:int mshv_do_pre_guest_mode_work(ulong th_flags) drivers/hv/mshv_common.c:EXPORT_SYMBOL_GPL(mshv_do_pre_guest_mode_work);Want to squash this into
3786d7d6b3c0("mshv: Use common "entry virt" APIs to do work in root before running guest")?
It's done. Thanks for pointing it out.
Wei