* [PATCH] KVM: nVMX: Handle split-lock #AC exceptions that happen in L2
@ 2021-06-22 17:22 Sean Christopherson
2021-06-23 2:43 ` Xiaoyao Li
2021-06-23 12:32 ` Paolo Bonzini
0 siblings, 2 replies; 4+ messages in thread
From: Sean Christopherson @ 2021-06-22 17:22 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, kvm, linux-kernel, Xiaoyao Li
Mark #ACs that won't be reinjected to the guest as wanted by L0 so that
KVM handles split-lock #AC from L2 instead of forwarding the exception to
L1. Split-lock #AC isn't yet virtualized, i.e. L1 will treat it like a
regular #AC and do the wrong thing, e.g. reinject it into L2.
Fixes: e6f8b6c12f03 ("KVM: VMX: Extend VMXs #AC interceptor to handle split lock #AC in guest")
Cc: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/vmx/nested.c | 3 +++
arch/x86/kvm/vmx/vmcs.h | 5 +++++
arch/x86/kvm/vmx/vmx.c | 4 ++--
arch/x86/kvm/vmx/vmx.h | 1 +
4 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 183fd9d62fc5..fa3f50f0a3fa 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -5833,6 +5833,9 @@ static bool nested_vmx_l0_wants_exit(struct kvm_vcpu *vcpu,
else if (is_breakpoint(intr_info) &&
vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
return true;
+ else if (is_alignment_check(intr_info) &&
+ !vmx_guest_inject_ac(vcpu))
+ return true;
return false;
case EXIT_REASON_EXTERNAL_INTERRUPT:
return true;
diff --git a/arch/x86/kvm/vmx/vmcs.h b/arch/x86/kvm/vmx/vmcs.h
index de3b04d4b587..4b9957e2bf5b 100644
--- a/arch/x86/kvm/vmx/vmcs.h
+++ b/arch/x86/kvm/vmx/vmcs.h
@@ -117,6 +117,11 @@ static inline bool is_gp_fault(u32 intr_info)
return is_exception_n(intr_info, GP_VECTOR);
}
+static inline bool is_alignment_check(u32 intr_info)
+{
+ return is_exception_n(intr_info, AC_VECTOR);
+}
+
static inline bool is_machine_check(u32 intr_info)
{
return is_exception_n(intr_info, MC_VECTOR);
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index ab6f682645d7..46d9ce39249d 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -4743,7 +4743,7 @@ static int handle_machine_check(struct kvm_vcpu *vcpu)
* - Guest has #AC detection enabled in CR0
* - Guest EFLAGS has AC bit set
*/
-static inline bool guest_inject_ac(struct kvm_vcpu *vcpu)
+bool vmx_guest_inject_ac(struct kvm_vcpu *vcpu)
{
if (!boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT))
return true;
@@ -4851,7 +4851,7 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
kvm_run->debug.arch.exception = ex_no;
break;
case AC_VECTOR:
- if (guest_inject_ac(vcpu)) {
+ if (vmx_guest_inject_ac(vcpu)) {
kvm_queue_exception_e(vcpu, AC_VECTOR, error_code);
return 1;
}
diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
index 5740f8e2aa23..3979a947933a 100644
--- a/arch/x86/kvm/vmx/vmx.h
+++ b/arch/x86/kvm/vmx/vmx.h
@@ -376,6 +376,7 @@ void vmx_get_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg);
void vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg);
u64 construct_eptp(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level);
+bool vmx_guest_inject_ac(struct kvm_vcpu *vcpu);
void vmx_update_exception_bitmap(struct kvm_vcpu *vcpu);
void vmx_update_msr_bitmap(struct kvm_vcpu *vcpu);
bool vmx_nmi_blocked(struct kvm_vcpu *vcpu);
--
2.32.0.288.g62a8d224e6-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: nVMX: Handle split-lock #AC exceptions that happen in L2
2021-06-22 17:22 [PATCH] KVM: nVMX: Handle split-lock #AC exceptions that happen in L2 Sean Christopherson
@ 2021-06-23 2:43 ` Xiaoyao Li
2021-06-23 12:30 ` Paolo Bonzini
2021-06-23 12:32 ` Paolo Bonzini
1 sibling, 1 reply; 4+ messages in thread
From: Xiaoyao Li @ 2021-06-23 2:43 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
linux-kernel
On 6/23/2021 1:22 AM, Sean Christopherson wrote:
> Mark #ACs that won't be reinjected to the guest as wanted by L0 so that
> KVM handles split-lock #AC from L2 instead of forwarding the exception to
> L1. Split-lock #AC isn't yet virtualized, i.e. L1 will treat it like a
> regular #AC and do the wrong thing, e.g. reinject it into L2.
>
> Fixes: e6f8b6c12f03 ("KVM: VMX: Extend VMXs #AC interceptor to handle split lock #AC in guest")
> Cc: Xiaoyao Li <xiaoyao.li@intel.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/kvm/vmx/nested.c | 3 +++
> arch/x86/kvm/vmx/vmcs.h | 5 +++++
> arch/x86/kvm/vmx/vmx.c | 4 ++--
> arch/x86/kvm/vmx/vmx.h | 1 +
> 4 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 183fd9d62fc5..fa3f50f0a3fa 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -5833,6 +5833,9 @@ static bool nested_vmx_l0_wants_exit(struct kvm_vcpu *vcpu,
> else if (is_breakpoint(intr_info) &&
> vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
> return true;
> + else if (is_alignment_check(intr_info) &&
> + !vmx_guest_inject_ac(vcpu))
> + return true;
Why choose to check in nested_vmx_l0_wants_exit, not in
nested_vmx_l1_wants_exit()?
> return false;
> case EXIT_REASON_EXTERNAL_INTERRUPT:
> return true;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: nVMX: Handle split-lock #AC exceptions that happen in L2
2021-06-23 2:43 ` Xiaoyao Li
@ 2021-06-23 12:30 ` Paolo Bonzini
0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2021-06-23 12:30 UTC (permalink / raw)
To: Xiaoyao Li, Sean Christopherson
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
linux-kernel
On 23/06/21 04:43, Xiaoyao Li wrote:
>>
>> + else if (is_alignment_check(intr_info) &&
>> + !vmx_guest_inject_ac(vcpu))
>> + return true;
>
> Why choose to check in nested_vmx_l0_wants_exit, not in
> nested_vmx_l1_wants_exit()?
nested_vmx_l0_wants_exit() == true means "this is a vmexit that needs
some transformation before being injected into L1". Instead,
nested_vmx_l1_wants_exit() == true means "this is an event that should
either be processed directly by L0, or cause a vmexit in L1"
Typically, nested_vmx_l1_wants_exit() checks the controls in vmcs12,
while nested_vmx_l0_wants_exit() returns true unconditionally for most
vmexits; for others it checks processor state, or other state set up by
userspace with ioctls such as vcpu->guest_debug.
In this case it's *L0* that wants that vmexit, in order to either
disable split-lock detection or inject a SIGBUS, so
nested_vmx_l0_wants_exit() is the right one to test.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] KVM: nVMX: Handle split-lock #AC exceptions that happen in L2
2021-06-22 17:22 [PATCH] KVM: nVMX: Handle split-lock #AC exceptions that happen in L2 Sean Christopherson
2021-06-23 2:43 ` Xiaoyao Li
@ 2021-06-23 12:32 ` Paolo Bonzini
1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2021-06-23 12:32 UTC (permalink / raw)
To: Sean Christopherson
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
linux-kernel, Xiaoyao Li
On 22/06/21 19:22, Sean Christopherson wrote:
> Mark #ACs that won't be reinjected to the guest as wanted by L0 so that
> KVM handles split-lock #AC from L2 instead of forwarding the exception to
> L1. Split-lock #AC isn't yet virtualized, i.e. L1 will treat it like a
> regular #AC and do the wrong thing, e.g. reinject it into L2.
>
> Fixes: e6f8b6c12f03 ("KVM: VMX: Extend VMXs #AC interceptor to handle split lock #AC in guest")
> Cc: Xiaoyao Li <xiaoyao.li@intel.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/kvm/vmx/nested.c | 3 +++
> arch/x86/kvm/vmx/vmcs.h | 5 +++++
> arch/x86/kvm/vmx/vmx.c | 4 ++--
> arch/x86/kvm/vmx/vmx.h | 1 +
> 4 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index 183fd9d62fc5..fa3f50f0a3fa 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -5833,6 +5833,9 @@ static bool nested_vmx_l0_wants_exit(struct kvm_vcpu *vcpu,
> else if (is_breakpoint(intr_info) &&
> vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
> return true;
> + else if (is_alignment_check(intr_info) &&
> + !vmx_guest_inject_ac(vcpu))
> + return true;
> return false;
> case EXIT_REASON_EXTERNAL_INTERRUPT:
> return true;
> diff --git a/arch/x86/kvm/vmx/vmcs.h b/arch/x86/kvm/vmx/vmcs.h
> index de3b04d4b587..4b9957e2bf5b 100644
> --- a/arch/x86/kvm/vmx/vmcs.h
> +++ b/arch/x86/kvm/vmx/vmcs.h
> @@ -117,6 +117,11 @@ static inline bool is_gp_fault(u32 intr_info)
> return is_exception_n(intr_info, GP_VECTOR);
> }
>
> +static inline bool is_alignment_check(u32 intr_info)
> +{
> + return is_exception_n(intr_info, AC_VECTOR);
> +}
> +
> static inline bool is_machine_check(u32 intr_info)
> {
> return is_exception_n(intr_info, MC_VECTOR);
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index ab6f682645d7..46d9ce39249d 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -4743,7 +4743,7 @@ static int handle_machine_check(struct kvm_vcpu *vcpu)
> * - Guest has #AC detection enabled in CR0
> * - Guest EFLAGS has AC bit set
> */
> -static inline bool guest_inject_ac(struct kvm_vcpu *vcpu)
> +bool vmx_guest_inject_ac(struct kvm_vcpu *vcpu)
> {
> if (!boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT))
> return true;
> @@ -4851,7 +4851,7 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
> kvm_run->debug.arch.exception = ex_no;
> break;
> case AC_VECTOR:
> - if (guest_inject_ac(vcpu)) {
> + if (vmx_guest_inject_ac(vcpu)) {
> kvm_queue_exception_e(vcpu, AC_VECTOR, error_code);
> return 1;
> }
> diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
> index 5740f8e2aa23..3979a947933a 100644
> --- a/arch/x86/kvm/vmx/vmx.h
> +++ b/arch/x86/kvm/vmx/vmx.h
> @@ -376,6 +376,7 @@ void vmx_get_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg);
> void vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg);
> u64 construct_eptp(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level);
>
> +bool vmx_guest_inject_ac(struct kvm_vcpu *vcpu);
> void vmx_update_exception_bitmap(struct kvm_vcpu *vcpu);
> void vmx_update_msr_bitmap(struct kvm_vcpu *vcpu);
> bool vmx_nmi_blocked(struct kvm_vcpu *vcpu);
>
Queued with Cc to stable, thanks.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-06-23 12:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-22 17:22 [PATCH] KVM: nVMX: Handle split-lock #AC exceptions that happen in L2 Sean Christopherson
2021-06-23 2:43 ` Xiaoyao Li
2021-06-23 12:30 ` Paolo Bonzini
2021-06-23 12:32 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).