* [PATCH 1/5] x86: KVM: SVM: fix for x2avic CVE-2023-5090
[not found] <20230928150428.199929-1-mlevitsk@redhat.com>
@ 2023-09-28 15:04 ` Maxim Levitsky
2023-09-28 15:53 ` Sean Christopherson
2023-09-28 15:04 ` [PATCH 2/5] x86: KVM: SVM: add support for Invalid IPI Vector interception Maxim Levitsky
2023-09-28 15:04 ` [PATCH 3/5] x86: KVM: SVM: refresh AVIC inhibition in svm_leave_nested() Maxim Levitsky
2 siblings, 1 reply; 6+ messages in thread
From: Maxim Levitsky @ 2023-09-28 15:04 UTC (permalink / raw)
To: kvm
Cc: Will Deacon, Borislav Petkov, Dave Hansen, Suravee Suthikulpanit,
Thomas Gleixner, Paolo Bonzini, x86, Robin Murphy, iommu,
Ingo Molnar, Joerg Roedel, Sean Christopherson, H. Peter Anvin,
linux-kernel, Maxim Levitsky, stable
The following problem exists since the x2avic was enabled in the KVM:
svm_set_x2apic_msr_interception is called to enable the interception of
the x2apic msrs.
In particular it is called at the moment the guest resets its apic.
Assuming that the guest's apic was in x2apic mode, the reset will bring
it back to the xapic mode.
The svm_set_x2apic_msr_interception however has an erroneous check for
'!apic_x2apic_mode()' which prevents it from doing anything in this case.
As a result of this, all x2apic msrs are left unintercepted, and that
exposes the bare metal x2apic (if enabled) to the guest.
Oops.
Remove the erroneous '!apic_x2apic_mode()' check to fix that.
Cc: stable@vger.kernel.org
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
arch/x86/kvm/svm/svm.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 9507df93f410a63..acdd0b89e4715a3 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -913,8 +913,7 @@ void svm_set_x2apic_msr_interception(struct vcpu_svm *svm, bool intercept)
if (intercept == svm->x2avic_msrs_intercepted)
return;
- if (!x2avic_enabled ||
- !apic_x2apic_mode(svm->vcpu.arch.apic))
+ if (!x2avic_enabled)
return;
for (i = 0; i < MAX_DIRECT_ACCESS_MSRS; i++) {
--
2.26.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/5] x86: KVM: SVM: add support for Invalid IPI Vector interception
[not found] <20230928150428.199929-1-mlevitsk@redhat.com>
2023-09-28 15:04 ` [PATCH 1/5] x86: KVM: SVM: fix for x2avic CVE-2023-5090 Maxim Levitsky
@ 2023-09-28 15:04 ` Maxim Levitsky
2023-09-28 15:46 ` Sean Christopherson
2023-09-28 15:04 ` [PATCH 3/5] x86: KVM: SVM: refresh AVIC inhibition in svm_leave_nested() Maxim Levitsky
2 siblings, 1 reply; 6+ messages in thread
From: Maxim Levitsky @ 2023-09-28 15:04 UTC (permalink / raw)
To: kvm
Cc: Will Deacon, Borislav Petkov, Dave Hansen, Suravee Suthikulpanit,
Thomas Gleixner, Paolo Bonzini, x86, Robin Murphy, iommu,
Ingo Molnar, Joerg Roedel, Sean Christopherson, H. Peter Anvin,
linux-kernel, Maxim Levitsky, stable
In later revisions of AMD's APM, there is a new 'incomplete IPI' exit code:
"Invalid IPI Vector - The vector for the specified IPI was set to an
illegal value (VEC < 16)"
Note that tests on Zen2 machine show that this VM exit doesn't happen and
instead AVIC just does nothing.
Add support for this exit code by doing nothing, instead of filling
the kernel log with errors.
Also replace an unthrottled 'pr_err()' if another unknown incomplete
IPI exit happens with WARN_ON_ONCE()
(e.g in case AMD adds yet another 'Invalid IPI' exit reason)
Cc: <stable@vger.kernel.org>
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
arch/x86/include/asm/svm.h | 1 +
arch/x86/kvm/svm/avic.c | 5 ++++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
index 19bf955b67e0da0..3ac0ffc4f3e202b 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -268,6 +268,7 @@ enum avic_ipi_failure_cause {
AVIC_IPI_FAILURE_TARGET_NOT_RUNNING,
AVIC_IPI_FAILURE_INVALID_TARGET,
AVIC_IPI_FAILURE_INVALID_BACKING_PAGE,
+ AVIC_IPI_FAILURE_INVALID_IPI_VECTOR,
};
#define AVIC_PHYSICAL_MAX_INDEX_MASK GENMASK_ULL(8, 0)
diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
index 2092db892d7d052..c44b65af494e3ff 100644
--- a/arch/x86/kvm/svm/avic.c
+++ b/arch/x86/kvm/svm/avic.c
@@ -529,8 +529,11 @@ int avic_incomplete_ipi_interception(struct kvm_vcpu *vcpu)
case AVIC_IPI_FAILURE_INVALID_BACKING_PAGE:
WARN_ONCE(1, "Invalid backing page\n");
break;
+ case AVIC_IPI_FAILURE_INVALID_IPI_VECTOR:
+ /* Invalid IPI with vector < 16 */
+ break;
default:
- pr_err("Unknown IPI interception\n");
+ WARN_ONCE(1, "Unknown avic incomplete IPI interception\n");
}
return 1;
--
2.26.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/5] x86: KVM: SVM: refresh AVIC inhibition in svm_leave_nested()
[not found] <20230928150428.199929-1-mlevitsk@redhat.com>
2023-09-28 15:04 ` [PATCH 1/5] x86: KVM: SVM: fix for x2avic CVE-2023-5090 Maxim Levitsky
2023-09-28 15:04 ` [PATCH 2/5] x86: KVM: SVM: add support for Invalid IPI Vector interception Maxim Levitsky
@ 2023-09-28 15:04 ` Maxim Levitsky
2023-09-28 16:03 ` Sean Christopherson
2 siblings, 1 reply; 6+ messages in thread
From: Maxim Levitsky @ 2023-09-28 15:04 UTC (permalink / raw)
To: kvm
Cc: Will Deacon, Borislav Petkov, Dave Hansen, Suravee Suthikulpanit,
Thomas Gleixner, Paolo Bonzini, x86, Robin Murphy, iommu,
Ingo Molnar, Joerg Roedel, Sean Christopherson, H. Peter Anvin,
linux-kernel, Maxim Levitsky, stable
svm_leave_nested() similar to a nested VM exit, get the vCPU out of nested
mode and thus should end the local inhibition of AVIC on this vCPU.
Failure to do so, can lead to hangs on guest reboot.
Raise the KVM_REQ_APICV_UPDATE request to refresh the AVIC state of the
current vCPU in this case.
Cc: stable@vger.kernel.org
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
arch/x86/kvm/svm/nested.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index dd496c9e5f91f28..3fea8c47679e689 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -1253,6 +1253,9 @@ void svm_leave_nested(struct kvm_vcpu *vcpu)
nested_svm_uninit_mmu_context(vcpu);
vmcb_mark_all_dirty(svm->vmcb);
+
+ if (kvm_apicv_activated(vcpu->kvm))
+ kvm_make_request(KVM_REQ_APICV_UPDATE, vcpu);
}
kvm_clear_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu);
--
2.26.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/5] x86: KVM: SVM: add support for Invalid IPI Vector interception
2023-09-28 15:04 ` [PATCH 2/5] x86: KVM: SVM: add support for Invalid IPI Vector interception Maxim Levitsky
@ 2023-09-28 15:46 ` Sean Christopherson
0 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2023-09-28 15:46 UTC (permalink / raw)
To: Maxim Levitsky
Cc: kvm, Will Deacon, Borislav Petkov, Dave Hansen,
Suravee Suthikulpanit, Thomas Gleixner, Paolo Bonzini, x86,
Robin Murphy, iommu, Ingo Molnar, Joerg Roedel, H. Peter Anvin,
linux-kernel, stable
On Thu, Sep 28, 2023, Maxim Levitsky wrote:
> In later revisions of AMD's APM, there is a new 'incomplete IPI' exit code:
>
> "Invalid IPI Vector - The vector for the specified IPI was set to an
> illegal value (VEC < 16)"
>
> Note that tests on Zen2 machine show that this VM exit doesn't happen and
> instead AVIC just does nothing.
>
> Add support for this exit code by doing nothing, instead of filling
> the kernel log with errors.
>
> Also replace an unthrottled 'pr_err()' if another unknown incomplete
> IPI exit happens with WARN_ON_ONCE()
>
> (e.g in case AMD adds yet another 'Invalid IPI' exit reason)
>
> Cc: <stable@vger.kernel.org>
>
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
> arch/x86/include/asm/svm.h | 1 +
> arch/x86/kvm/svm/avic.c | 5 ++++-
> 2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
> index 19bf955b67e0da0..3ac0ffc4f3e202b 100644
> --- a/arch/x86/include/asm/svm.h
> +++ b/arch/x86/include/asm/svm.h
> @@ -268,6 +268,7 @@ enum avic_ipi_failure_cause {
> AVIC_IPI_FAILURE_TARGET_NOT_RUNNING,
> AVIC_IPI_FAILURE_INVALID_TARGET,
> AVIC_IPI_FAILURE_INVALID_BACKING_PAGE,
> + AVIC_IPI_FAILURE_INVALID_IPI_VECTOR,
> };
>
> #define AVIC_PHYSICAL_MAX_INDEX_MASK GENMASK_ULL(8, 0)
> diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c
> index 2092db892d7d052..c44b65af494e3ff 100644
> --- a/arch/x86/kvm/svm/avic.c
> +++ b/arch/x86/kvm/svm/avic.c
> @@ -529,8 +529,11 @@ int avic_incomplete_ipi_interception(struct kvm_vcpu *vcpu)
> case AVIC_IPI_FAILURE_INVALID_BACKING_PAGE:
> WARN_ONCE(1, "Invalid backing page\n");
> break;
> + case AVIC_IPI_FAILURE_INVALID_IPI_VECTOR:
> + /* Invalid IPI with vector < 16 */
> + break;
> default:
> - pr_err("Unknown IPI interception\n");
> + WARN_ONCE(1, "Unknown avic incomplete IPI interception\n");
Hrm, I'm not sure KVM should WARN here. E.g. if someone runs with panic_on_warn=1,
running on new hardware might crash the host. I hope that AMD is smart enough to
make any future failure types "optional" in the sense that they're either opt-in,
or are largely informational-only (like AVIC_IPI_FAILURE_INVALID_IPI_VECTOR).
I think switching to vcpu_unimpl(), or maybe even pr_err_once(), is more appropriate.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/5] x86: KVM: SVM: fix for x2avic CVE-2023-5090
2023-09-28 15:04 ` [PATCH 1/5] x86: KVM: SVM: fix for x2avic CVE-2023-5090 Maxim Levitsky
@ 2023-09-28 15:53 ` Sean Christopherson
0 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2023-09-28 15:53 UTC (permalink / raw)
To: Maxim Levitsky
Cc: kvm, Will Deacon, Borislav Petkov, Dave Hansen,
Suravee Suthikulpanit, Thomas Gleixner, Paolo Bonzini, x86,
Robin Murphy, iommu, Ingo Molnar, Joerg Roedel, H. Peter Anvin,
linux-kernel, stable
KVM: SVM: for the shortlog scope
And my preference is to have the shortlog explain the code change and leave the
CVE reference to a line in the changelog. CVE numbers are meaningless without
context, e.g. listing the CVE isn't going to be at all helpful for future readers
that look at shortlogs.
E.g.
KVM: SVM: Always refresh x2APIC MSR intercepts when x2AVIC is enabled
or
KVM: SVM: Update MSR intercepts for x2AVIC when guest disables x2APIC
On Thu, Sep 28, 2023, Maxim Levitsky wrote:
> The following problem exists since the x2avic was enabled in the KVM:
Just "x2avic"
> svm_set_x2apic_msr_interception is called to enable the interception of
() after functions
> the x2apic msrs.
>
> In particular it is called at the moment the guest resets its apic.
>
> Assuming that the guest's apic was in x2apic mode, the reset will bring
> it back to the xapic mode.
>
> The svm_set_x2apic_msr_interception however has an erroneous check for
> '!apic_x2apic_mode()' which prevents it from doing anything in this case.
>
> As a result of this, all x2apic msrs are left unintercepted, and that
> exposes the bare metal x2apic (if enabled) to the guest.
> Oops.
>
> Remove the erroneous '!apic_x2apic_mode()' check to fix that.
>
> Cc: stable@vger.kernel.org
Fixes: 4d1d7942e36a ("KVM: SVM: Introduce logic to (de)activate x2AVIC mode")
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
> arch/x86/kvm/svm/svm.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 9507df93f410a63..acdd0b89e4715a3 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -913,8 +913,7 @@ void svm_set_x2apic_msr_interception(struct vcpu_svm *svm, bool intercept)
> if (intercept == svm->x2avic_msrs_intercepted)
> return;
>
> - if (!x2avic_enabled ||
> - !apic_x2apic_mode(svm->vcpu.arch.apic))
> + if (!x2avic_enabled)
> return;
>
> for (i = 0; i < MAX_DIRECT_ACCESS_MSRS; i++) {
> --
> 2.26.3
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/5] x86: KVM: SVM: refresh AVIC inhibition in svm_leave_nested()
2023-09-28 15:04 ` [PATCH 3/5] x86: KVM: SVM: refresh AVIC inhibition in svm_leave_nested() Maxim Levitsky
@ 2023-09-28 16:03 ` Sean Christopherson
0 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2023-09-28 16:03 UTC (permalink / raw)
To: Maxim Levitsky
Cc: kvm, Will Deacon, Borislav Petkov, Dave Hansen,
Suravee Suthikulpanit, Thomas Gleixner, Paolo Bonzini, x86,
Robin Murphy, iommu, Ingo Molnar, Joerg Roedel, H. Peter Anvin,
linux-kernel, stable
On Thu, Sep 28, 2023, Maxim Levitsky wrote:
> svm_leave_nested() similar to a nested VM exit, get the vCPU out of nested
> mode and thus should end the local inhibition of AVIC on this vCPU.
>
> Failure to do so, can lead to hangs on guest reboot.
>
> Raise the KVM_REQ_APICV_UPDATE request to refresh the AVIC state of the
> current vCPU in this case.
>
> Cc: stable@vger.kernel.org
Unnecessary newline.
Fixes: f44509f849fe ("KVM: x86: SVM: allow AVIC to co-exist with a nested guest running")
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---
> arch/x86/kvm/svm/nested.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index dd496c9e5f91f28..3fea8c47679e689 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
> @@ -1253,6 +1253,9 @@ void svm_leave_nested(struct kvm_vcpu *vcpu)
>
> nested_svm_uninit_mmu_context(vcpu);
> vmcb_mark_all_dirty(svm->vmcb);
> +
> + if (kvm_apicv_activated(vcpu->kvm))
> + kvm_make_request(KVM_REQ_APICV_UPDATE, vcpu);
> }
>
> kvm_clear_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu);
> --
> 2.26.3
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-09-28 16:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20230928150428.199929-1-mlevitsk@redhat.com>
2023-09-28 15:04 ` [PATCH 1/5] x86: KVM: SVM: fix for x2avic CVE-2023-5090 Maxim Levitsky
2023-09-28 15:53 ` Sean Christopherson
2023-09-28 15:04 ` [PATCH 2/5] x86: KVM: SVM: add support for Invalid IPI Vector interception Maxim Levitsky
2023-09-28 15:46 ` Sean Christopherson
2023-09-28 15:04 ` [PATCH 3/5] x86: KVM: SVM: refresh AVIC inhibition in svm_leave_nested() Maxim Levitsky
2023-09-28 16:03 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox