2023-02-27 09:03:20

by Santosh Shukla

[permalink] [raw]
Subject: [PATCHv4 00/11] SVM: virtual NMI


v2:
https://lore.kernel.org/all/[email protected]/

v3:
https://lore.kernel.org/all/[email protected]/
- 09/11: Clubbed x86_ops delayed NMI with vNMI changes into one,
for better readability purpose (Sean Suggestion)
- Series includes suggestion and fixes proposed in v2 series.
Refer each patch for change history(v2-->v3).

v4:
- Missed sending 01/11 patch in v3.

Series based on [1] and tested on AMD EPYC-Genoa.


APM: ((Ch-15.21.10 - NMI Virtualization)
https://www.amd.com/en/support/tech-docs/amd64-architecture-programmers-manual-volumes-1-5

Past history and work refer v5-
https://lkml.org/lkml/2022/10/27/261

Thanks,
Santosh
[1] https://github.com/kvm-x86/linux branch kvm-x86/next(62ef199250cd46f)



Maxim Levitsky (2):
KVM: nSVM: Raise event on nested VM exit if L1 doesn't intercept IRQs
KVM: SVM: add wrappers to enable/disable IRET interception

Santosh Shukla (6):
KVM: nSVM: Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is
intercepting VINTR
KVM: nSVM: Disable intercept of VINTR if saved RFLAG.IF is 0
x86/cpu: Add CPUID feature bit for VNMI
KVM: SVM: Add VNMI bit definition
KVM: x86: add support for delayed virtual NMI injection interface
KVM: nSVM: implement support for nested VNMI

Sean Christopherson (3):
KVM: x86: Raise an event request when processing NMIs if an NMI is
pending
KVM: x86: Tweak the code and comment related to handling concurrent
NMIs
KVM: x86: Save/restore all NMIs when multiple NMIs are pending

arch/x86/include/asm/cpufeatures.h | 1 +
arch/x86/include/asm/kvm-x86-ops.h | 2 +
arch/x86/include/asm/kvm_host.h | 11 ++-
arch/x86/include/asm/svm.h | 9 ++
arch/x86/kvm/svm/nested.c | 94 +++++++++++++++---
arch/x86/kvm/svm/svm.c | 152 +++++++++++++++++++++++------
arch/x86/kvm/svm/svm.h | 28 ++++++
arch/x86/kvm/x86.c | 46 +++++++--
8 files changed, 289 insertions(+), 54 deletions(-)

--
2.25.1



2023-02-27 09:05:37

by Santosh Shukla

[permalink] [raw]
Subject: [PATCHv4 01/11] KVM: nSVM: Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is intercepting VINTR

From: Santosh Shukla <[email protected]>

Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is intercepting
virtual interrupts in order to request an interrupt window, as KVM
has usurped vmcb02's int_ctl. If an interrupt window opens before
the next VM-Exit, svm_clear_vintr() will restore vmcb12's int_ctl.
If no window opens, V_IRQ will be correctly preserved in vmcb12's
int_ctl (because it was never recognized while L2 was running).

Suggested-by: Sean Christopherson <[email protected]>
Signed-off-by: Santosh Shukla <[email protected]>
---
v4:
https://lore.kernel.org/all/[email protected]/
suggested by Sean.

arch/x86/kvm/svm/nested.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 05d38944a6c0..fbade158d368 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -416,18 +416,17 @@ void nested_sync_control_from_vmcb02(struct vcpu_svm *svm)

/* Only a few fields of int_ctl are written by the processor. */
mask = V_IRQ_MASK | V_TPR_MASK;
- if (!(svm->nested.ctl.int_ctl & V_INTR_MASKING_MASK) &&
- svm_is_intercept(svm, INTERCEPT_VINTR)) {
- /*
- * In order to request an interrupt window, L0 is usurping
- * svm->vmcb->control.int_ctl and possibly setting V_IRQ
- * even if it was clear in L1's VMCB. Restoring it would be
- * wrong. However, in this case V_IRQ will remain true until
- * interrupt_window_interception calls svm_clear_vintr and
- * restores int_ctl. We can just leave it aside.
- */
+ /*
+ * Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is intercepting
+ * virtual interrupts in order to request an interrupt window, as KVM
+ * has usurped vmcb02's int_ctl. If an interrupt window opens before
+ * the next VM-Exit, svm_clear_vintr() will restore vmcb12's int_ctl.
+ * If no window opens, V_IRQ will be correctly preserved in vmcb12's
+ * int_ctl (because it was never recognized while L2 was running).
+ */
+ if (svm_is_intercept(svm, INTERCEPT_VINTR) &&
+ !test_bit(INTERCEPT_VINTR, (unsigned long *)svm->nested.ctl.intercepts))
mask &= ~V_IRQ_MASK;
- }

if (nested_vgif_enabled(svm))
mask |= V_GIF_MASK;
--
2.25.1


2023-03-10 09:26:50

by Santosh Shukla

[permalink] [raw]
Subject: Re: [PATCHv4 00/11] SVM: virtual NMI



On 2/27/2023 2:10 PM, Santosh Shukla wrote:
>
> v2:
> https://lore.kernel.org/all/[email protected]/
>
> v3:
> https://lore.kernel.org/all/[email protected]/
> - 09/11: Clubbed x86_ops delayed NMI with vNMI changes into one,
> for better readability purpose (Sean Suggestion)
> - Series includes suggestion and fixes proposed in v2 series.
> Refer each patch for change history(v2-->v3).
>
> v4:
> - Missed sending 01/11 patch in v3.
>
> Series based on [1] and tested on AMD EPYC-Genoa.
>
>
> APM: ((Ch-15.21.10 - NMI Virtualization)
> https://www.amd.com/en/support/tech-docs/amd64-architecture-programmers-manual-volumes-1-5
>
> Past history and work refer v5-
> https://lkml.org/lkml/2022/10/27/261
>
> Thanks,
> Santosh
> [1] https://github.com/kvm-x86/linux branch kvm-x86/next(62ef199250cd46f)
>
>

Gentle Ping?

Thanks,
Santosh


>
> Maxim Levitsky (2):
> KVM: nSVM: Raise event on nested VM exit if L1 doesn't intercept IRQs
> KVM: SVM: add wrappers to enable/disable IRET interception
>
> Santosh Shukla (6):
> KVM: nSVM: Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is
> intercepting VINTR
> KVM: nSVM: Disable intercept of VINTR if saved RFLAG.IF is 0
> x86/cpu: Add CPUID feature bit for VNMI
> KVM: SVM: Add VNMI bit definition
> KVM: x86: add support for delayed virtual NMI injection interface
> KVM: nSVM: implement support for nested VNMI
>
> Sean Christopherson (3):
> KVM: x86: Raise an event request when processing NMIs if an NMI is
> pending
> KVM: x86: Tweak the code and comment related to handling concurrent
> NMIs
> KVM: x86: Save/restore all NMIs when multiple NMIs are pending
>
> arch/x86/include/asm/cpufeatures.h | 1 +
> arch/x86/include/asm/kvm-x86-ops.h | 2 +
> arch/x86/include/asm/kvm_host.h | 11 ++-
> arch/x86/include/asm/svm.h | 9 ++
> arch/x86/kvm/svm/nested.c | 94 +++++++++++++++---
> arch/x86/kvm/svm/svm.c | 152 +++++++++++++++++++++++------
> arch/x86/kvm/svm/svm.h | 28 ++++++
> arch/x86/kvm/x86.c | 46 +++++++--
> 8 files changed, 289 insertions(+), 54 deletions(-)
>


2023-03-10 17:04:42

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCHv4 00/11] SVM: virtual NMI

On Fri, Mar 10, 2023, Santosh Shukla wrote:
> Gentle Ping?

I'm slowly working my into review mode for 6.4. This is very much on my todo list.

2023-03-23 01:00:24

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCHv4 00/11] SVM: virtual NMI

On Mon, Feb 27, 2023, Santosh Shukla wrote:
> Maxim Levitsky (2):
> KVM: nSVM: Raise event on nested VM exit if L1 doesn't intercept IRQs
> KVM: SVM: add wrappers to enable/disable IRET interception
>
> Santosh Shukla (6):
> KVM: nSVM: Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is
> intercepting VINTR
> KVM: nSVM: Disable intercept of VINTR if saved RFLAG.IF is 0
> x86/cpu: Add CPUID feature bit for VNMI
> KVM: SVM: Add VNMI bit definition
> KVM: x86: add support for delayed virtual NMI injection interface
> KVM: nSVM: implement support for nested VNMI
>
> Sean Christopherson (3):
> KVM: x86: Raise an event request when processing NMIs if an NMI is
> pending
> KVM: x86: Tweak the code and comment related to handling concurrent
> NMIs
> KVM: x86: Save/restore all NMIs when multiple NMIs are pending
>
> arch/x86/include/asm/cpufeatures.h | 1 +
> arch/x86/include/asm/kvm-x86-ops.h | 2 +
> arch/x86/include/asm/kvm_host.h | 11 ++-
> arch/x86/include/asm/svm.h | 9 ++
> arch/x86/kvm/svm/nested.c | 94 +++++++++++++++---
> arch/x86/kvm/svm/svm.c | 152 +++++++++++++++++++++++------
> arch/x86/kvm/svm/svm.h | 28 ++++++
> arch/x86/kvm/x86.c | 46 +++++++--
> 8 files changed, 289 insertions(+), 54 deletions(-)

Code looks good overall, I'll fixup the changelogs and comments myself. I just
need to run it through my usual test flow, which I should get done tomorrow.

2023-03-23 01:27:24

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCHv4 00/11] SVM: virtual NMI

On Wed, Mar 22, 2023, Sean Christopherson wrote:
> On Mon, Feb 27, 2023, Santosh Shukla wrote:
> > Maxim Levitsky (2):
> > KVM: nSVM: Raise event on nested VM exit if L1 doesn't intercept IRQs
> > KVM: SVM: add wrappers to enable/disable IRET interception
> >
> > Santosh Shukla (6):
> > KVM: nSVM: Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is
> > intercepting VINTR
> > KVM: nSVM: Disable intercept of VINTR if saved RFLAG.IF is 0
> > x86/cpu: Add CPUID feature bit for VNMI
> > KVM: SVM: Add VNMI bit definition
> > KVM: x86: add support for delayed virtual NMI injection interface
> > KVM: nSVM: implement support for nested VNMI
> >
> > Sean Christopherson (3):
> > KVM: x86: Raise an event request when processing NMIs if an NMI is
> > pending
> > KVM: x86: Tweak the code and comment related to handling concurrent
> > NMIs
> > KVM: x86: Save/restore all NMIs when multiple NMIs are pending
> >
> > arch/x86/include/asm/cpufeatures.h | 1 +
> > arch/x86/include/asm/kvm-x86-ops.h | 2 +
> > arch/x86/include/asm/kvm_host.h | 11 ++-
> > arch/x86/include/asm/svm.h | 9 ++
> > arch/x86/kvm/svm/nested.c | 94 +++++++++++++++---
> > arch/x86/kvm/svm/svm.c | 152 +++++++++++++++++++++++------
> > arch/x86/kvm/svm/svm.h | 28 ++++++
> > arch/x86/kvm/x86.c | 46 +++++++--
> > 8 files changed, 289 insertions(+), 54 deletions(-)
>
> Code looks good overall, I'll fixup the changelogs and comments myself. I just
> need to run it through my usual test flow, which I should get done tomorrow.

Gah, saw something shiny and forgot to finish my thought.

My plan is to get this somewhat speculatively applied and soaking in linux-next asap,
even though the cpufeatures.h change needs more eyeballs. I'll fixup and force push
if necessary; unless I'm missing something, this is the only SVM specific series
that's destined for 6.4.

2023-03-23 23:02:33

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCHv4 00/11] SVM: virtual NMI

On Mon, 27 Feb 2023 14:10:05 +0530, Santosh Shukla wrote:
> v2:
> https://lore.kernel.org/all/[email protected]/
>
> v3:
> https://lore.kernel.org/all/[email protected]/
> - 09/11: Clubbed x86_ops delayed NMI with vNMI changes into one,
> for better readability purpose (Sean Suggestion)
> - Series includes suggestion and fixes proposed in v2 series.
> Refer each patch for change history(v2-->v3).
>
> [...]

Applied to kvm-x86 svm. As mentioned in a previous reply, this is somewhat
speculative, i.e. needs acks for the cpufeatures.h change and might get
overwritten by a force push.

[01/11] KVM: nSVM: Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is intercepting VINTR
https://github.com/kvm-x86/linux/commit/5faaffab5ba8
[02/11] KVM: nSVM: Disable intercept of VINTR if saved RFLAG.IF is 0
https://github.com/kvm-x86/linux/commit/7334ede457c6
[03/11] KVM: nSVM: Raise event on nested VM exit if L1 doesn't intercept IRQs
https://github.com/kvm-x86/linux/commit/5d1ec4565200
[04/11] KVM: SVM: add wrappers to enable/disable IRET interception
https://github.com/kvm-x86/linux/commit/772f254d4d56
[05/11] KVM: x86: Raise an event request when processing NMIs if an NMI is pending
https://github.com/kvm-x86/linux/commit/2cb9317377ca
[06/11] KVM: x86: Tweak the code and comment related to handling concurrent NMIs
https://github.com/kvm-x86/linux/commit/400fee8c9b2d
[07/11] KVM: x86: Save/restore all NMIs when multiple NMIs are pending
https://github.com/kvm-x86/linux/commit/ab2ee212a57b
[08/11] x86/cpufeatures: Redefine synthetic virtual NMI bit as AMD's "real" vNMI
https://github.com/kvm-x86/linux/commit/3763bf58029f
[09/11] KVM: SVM: Add VNMI bit definition
https://github.com/kvm-x86/linux/commit/1c4522ab13b1
[10/11] KVM: x86: add support for delayed virtual NMI injection interface
https://github.com/kvm-x86/linux/commit/fa4c027a7956
[11/11] KVM: nSVM: implement support for nested VNMI
https://github.com/kvm-x86/linux/commit/0977cfac6e76

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes

2023-03-24 08:44:29

by Santosh Shukla

[permalink] [raw]
Subject: Re: [PATCHv4 00/11] SVM: virtual NMI



On 3/24/2023 4:23 AM, Sean Christopherson wrote:
> On Mon, 27 Feb 2023 14:10:05 +0530, Santosh Shukla wrote:
>> v2:
>> https://lore.kernel.org/all/[email protected]/
>>
>> v3:
>> https://lore.kernel.org/all/[email protected]/
>> - 09/11: Clubbed x86_ops delayed NMI with vNMI changes into one,
>> for better readability purpose (Sean Suggestion)
>> - Series includes suggestion and fixes proposed in v2 series.
>> Refer each patch for change history(v2-->v3).
>>
>> [...]
>
> Applied to kvm-x86 svm. As mentioned in a previous reply, this is somewhat
> speculative, i.e. needs acks for the cpufeatures.h change and might get
> overwritten by a force push.
>

Thank-you Sean!,.

Best Regards,
Santosh

> [01/11] KVM: nSVM: Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is intercepting VINTR
> https://github.com/kvm-x86/linux/commit/5faaffab5ba8
> [02/11] KVM: nSVM: Disable intercept of VINTR if saved RFLAG.IF is 0
> https://github.com/kvm-x86/linux/commit/7334ede457c6
> [03/11] KVM: nSVM: Raise event on nested VM exit if L1 doesn't intercept IRQs
> https://github.com/kvm-x86/linux/commit/5d1ec4565200
> [04/11] KVM: SVM: add wrappers to enable/disable IRET interception
> https://github.com/kvm-x86/linux/commit/772f254d4d56
> [05/11] KVM: x86: Raise an event request when processing NMIs if an NMI is pending
> https://github.com/kvm-x86/linux/commit/2cb9317377ca
> [06/11] KVM: x86: Tweak the code and comment related to handling concurrent NMIs
> https://github.com/kvm-x86/linux/commit/400fee8c9b2d
> [07/11] KVM: x86: Save/restore all NMIs when multiple NMIs are pending
> https://github.com/kvm-x86/linux/commit/ab2ee212a57b
> [08/11] x86/cpufeatures: Redefine synthetic virtual NMI bit as AMD's "real" vNMI
> https://github.com/kvm-x86/linux/commit/3763bf58029f
> [09/11] KVM: SVM: Add VNMI bit definition
> https://github.com/kvm-x86/linux/commit/1c4522ab13b1
> [10/11] KVM: x86: add support for delayed virtual NMI injection interface
> https://github.com/kvm-x86/linux/commit/fa4c027a7956
> [11/11] KVM: nSVM: implement support for nested VNMI
> https://github.com/kvm-x86/linux/commit/0977cfac6e76
>
> --
> https://github.com/kvm-x86/linux/tree/next
> https://github.com/kvm-x86/linux/tree/fixes