[PATCH 0/5] Drivers: hv: Fix NEED_RESCHED_LAZY and use common APIs

Sean Christopherson posted 5 patches 1 month, 1 week ago
There is a newer version of this series
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                          |  1 +
drivers/hv/mshv.h                           |  2 --
drivers/hv/mshv_common.c                    | 22 ---------------
drivers/hv/mshv_root_main.c                 | 31 ++++-----------------
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 +-
21 files changed, 49 insertions(+), 93 deletions(-)
rename include/linux/{entry-kvm.h => entry-virt.h} (83%)
rename kernel/entry/{kvm.c => virt.c} (66%)
[PATCH 0/5] Drivers: hv: Fix NEED_RESCHED_LAZY and use common APIs
Posted by Sean Christopherson 1 month, 1 week ago
Fix a bug where MSHV root partitions 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 (which ideally would have been done when MSHV root
support was added).

Assuming all is well, maybe this could go through the tip tree?

The Hyper-V stuff and non-x86 architectures are compile-tested only.

Sean Christopherson (5):
  Drivers: hv: Move TIF pre-guest work handling fully into mshv_common.c
  Drivers: hv: Handle NEED_RESCHED_LAZY before transferring to guest
  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 before running
    guest

 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                          |  1 +
 drivers/hv/mshv.h                           |  2 --
 drivers/hv/mshv_common.c                    | 22 ---------------
 drivers/hv/mshv_root_main.c                 | 31 ++++-----------------
 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 +-
 21 files changed, 49 insertions(+), 93 deletions(-)
 rename include/linux/{entry-kvm.h => entry-virt.h} (83%)
 rename kernel/entry/{kvm.c => virt.c} (66%)


base-commit: 1b237f190eb3d36f52dffe07a40b5eb210280e00
-- 
2.51.0.261.g7ce5a0a67e-goog
Re: [PATCH 0/5] Drivers: hv: Fix NEED_RESCHED_LAZY and use common APIs
Posted by Nuno Das Neves 1 month, 1 week ago
On 8/25/2025 1:06 PM, Sean Christopherson wrote:
> Fix a bug where MSHV root partitions 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 (which ideally would have been done when MSHV root
> support was added).
> 
> Assuming all is well, maybe this could go through the tip tree?
> 
> The Hyper-V stuff and non-x86 architectures are compile-tested only.
> 

Thanks Sean, I can test the root partition changes.

A similar change will be needed in mshv_vtl_main.c since it also calls
mshv_do_pre_guest_mode_work() (hence the "common" in mshv_common.c).

Also, is it possible to make all the mshv driver changes in a single patch?
It seems like it would be cleaner than refactoring it in patches 1 & 2 and
then deleting all the refactored code in patch 5.

Thanks
Nuno

> Sean Christopherson (5):
>   Drivers: hv: Move TIF pre-guest work handling fully into mshv_common.c
>   Drivers: hv: Handle NEED_RESCHED_LAZY before transferring to guest
>   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 before running
>     guest
> 
>  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                          |  1 +
>  drivers/hv/mshv.h                           |  2 --
>  drivers/hv/mshv_common.c                    | 22 ---------------
>  drivers/hv/mshv_root_main.c                 | 31 ++++-----------------
>  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 +-
>  21 files changed, 49 insertions(+), 93 deletions(-)
>  rename include/linux/{entry-kvm.h => entry-virt.h} (83%)
>  rename kernel/entry/{kvm.c => virt.c} (66%)
> 
> 
> base-commit: 1b237f190eb3d36f52dffe07a40b5eb210280e00
Re: [PATCH 0/5] Drivers: hv: Fix NEED_RESCHED_LAZY and use common APIs
Posted by Sean Christopherson 1 month, 1 week ago
On Mon, Aug 25, 2025, Nuno Das Neves wrote:
> On 8/25/2025 1:06 PM, Sean Christopherson wrote:
> > Fix a bug where MSHV root partitions 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 (which ideally would have been done when MSHV root
> > support was added).
> > 
> > Assuming all is well, maybe this could go through the tip tree?
> > 
> > The Hyper-V stuff and non-x86 architectures are compile-tested only.
> > 
> 
> Thanks Sean, I can test the root partition changes.
> 
> A similar change will be needed in mshv_vtl_main.c since it also calls
> mshv_do_pre_guest_mode_work() (hence the "common" in mshv_common.c).

Oof, more dependencies.  I suppose the easiest thing would be to send a series
against

  git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git queue

and then route everything through there?

Alternatively, frontload the MSHV fixes (which I'll do regardless) and take those
through hyperv and the rest through the tip tree?  That seems like an absurd
amount of juggling though, especially if we want to get the cleanups into 6.18.
And if none of these lands, it's MSHV that'll suffer the most, so betting it all
on the hyperv tree doesn't seem terrible.

> Also, is it possible to make all the mshv driver changes in a single patch?

It's certainly possible, but I'd prefer not do to that.

> It seems like it would be cleaner than refactoring it in patches 1 & 2 and
> then deleting all the refactored code in patch 5.

Only if you don't care about backporting fixes, bisection, or maintaining code.

E.g. if checking NEED_RESCHED_LAZY somehow causes issues, it would be really nice
for that to bisect to exactly that patch, not a patch that also switches to a
completely different set of APIs.

And if someone is wants the fixes in a pre-6.18 kernel, they don't need to
backport all of the KVM and entry code changes just to get the fix.

As for the maintenance headache, see above.
Re: [PATCH 0/5] Drivers: hv: Fix NEED_RESCHED_LAZY and use common APIs
Posted by Wei Liu 1 month, 1 week ago
On Mon, Aug 25, 2025 at 05:27:16PM -0700, Sean Christopherson wrote:
> On Mon, Aug 25, 2025, Nuno Das Neves wrote:
> > On 8/25/2025 1:06 PM, Sean Christopherson wrote:
> > > Fix a bug where MSHV root partitions 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 (which ideally would have been done when MSHV root
> > > support was added).
> > > 
> > > Assuming all is well, maybe this could go through the tip tree?
> > > 
> > > The Hyper-V stuff and non-x86 architectures are compile-tested only.
> > > 
> > 
> > Thanks Sean, I can test the root partition changes.
> > 
> > A similar change will be needed in mshv_vtl_main.c since it also calls
> > mshv_do_pre_guest_mode_work() (hence the "common" in mshv_common.c).
> 
> Oof, more dependencies.  I suppose the easiest thing would be to send a series
> against
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git queue
> 
> and then route everything through there?

Our fixes branch is on 6.17-rc1. You can use it as a base if you want
to.

> 
> Alternatively, frontload the MSHV fixes (which I'll do regardless) and take those
> through hyperv and the rest through the tip tree?  That seems like an absurd
> amount of juggling though, especially if we want to get the cleanups into 6.18.
> And if none of these lands, it's MSHV that'll suffer the most, so betting it all
> on the hyperv tree doesn't seem terrible.
> 

I'm happy to do it however the community sees fit.

> > Also, is it possible to make all the mshv driver changes in a single patch?
> 
> It's certainly possible, but I'd prefer not do to that.
> 
> > It seems like it would be cleaner than refactoring it in patches 1 & 2 and
> > then deleting all the refactored code in patch 5.
> 
> Only if you don't care about backporting fixes, bisection, or maintaining code.
> 
> E.g. if checking NEED_RESCHED_LAZY somehow causes issues, it would be really nice
> for that to bisect to exactly that patch, not a patch that also switches to a
> completely different set of APIs.
> 
> And if someone is wants the fixes in a pre-6.18 kernel, they don't need to
> backport all of the KVM and entry code changes just to get the fix.

+1 on this.

Thanks,
Wei

> 
> As for the maintenance headache, see above.
Re: [PATCH 0/5] Drivers: hv: Fix NEED_RESCHED_LAZY and use common APIs
Posted by Peter Zijlstra 1 month, 1 week ago
On Mon, Aug 25, 2025 at 01:06:17PM -0700, Sean Christopherson wrote:
> Fix a bug where MSHV root partitions 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 (which ideally would have been done when MSHV root
> support was added).
> 
> Assuming all is well, maybe this could go through the tip tree?
> 
> The Hyper-V stuff and non-x86 architectures are compile-tested only.

I suspect there's more of this wreckage in the new VTL driver that
they just put in:

  https://lore.kernel.org/all/20250729051436.190703-3-namjain@linux.microsoft.com/

although ideally they rip that thing out. I don't know how that code can
ever be correct.
Re: [PATCH 0/5] Drivers: hv: Fix NEED_RESCHED_LAZY and use common APIs
Posted by Wei Liu 1 month, 1 week ago
On Tue, Aug 26, 2025 at 12:23:19AM +0200, Peter Zijlstra wrote:
> On Mon, Aug 25, 2025 at 01:06:17PM -0700, Sean Christopherson wrote:
> > Fix a bug where MSHV root partitions 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 (which ideally would have been done when MSHV root
> > support was added).
> > 
> > Assuming all is well, maybe this could go through the tip tree?
> > 
> > The Hyper-V stuff and non-x86 architectures are compile-tested only.
> 
> I suspect there's more of this wreckage in the new VTL driver that
> they just put in:
> 
>   https://lore.kernel.org/all/20250729051436.190703-3-namjain@linux.microsoft.com/
> 
> although ideally they rip that thing out. I don't know how that code can
> ever be correct.

Please give us some time, Peter. I have asked the corresponding team to
respond to your comments.

Wei
Re: [PATCH 0/5] Drivers: hv: Fix NEED_RESCHED_LAZY and use common APIs
Posted by Wei Liu 1 month, 1 week ago
On Mon, Aug 25, 2025 at 01:06:17PM -0700, Sean Christopherson wrote:
> Fix a bug where MSHV root partitions 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 (which ideally would have been done when MSHV root
> support was added).
> 

It is nice to have a common infrastructure.

Cc Mukesh and Nuno for review and test.

Thanks,
Wei

> Assuming all is well, maybe this could go through the tip tree?
> 
> The Hyper-V stuff and non-x86 architectures are compile-tested only.
> 
> Sean Christopherson (5):
>   Drivers: hv: Move TIF pre-guest work handling fully into mshv_common.c
>   Drivers: hv: Handle NEED_RESCHED_LAZY before transferring to guest
>   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 before running
>     guest
> 
>  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                          |  1 +
>  drivers/hv/mshv.h                           |  2 --
>  drivers/hv/mshv_common.c                    | 22 ---------------
>  drivers/hv/mshv_root_main.c                 | 31 ++++-----------------
>  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 +-
>  21 files changed, 49 insertions(+), 93 deletions(-)
>  rename include/linux/{entry-kvm.h => entry-virt.h} (83%)
>  rename kernel/entry/{kvm.c => virt.c} (66%)
> 
> 
> base-commit: 1b237f190eb3d36f52dffe07a40b5eb210280e00
> -- 
> 2.51.0.261.g7ce5a0a67e-goog
>