From: Alexey Kardashevskiy <aik@amd.com>
To: <kvm@vger.kernel.org>
Cc: <x86@kernel.org>, <linux-kernel@vger.kernel.org>,
Tom Lendacky <thomas.lendacky@amd.com>,
Sean Christopherson <seanjc@google.com>,
"Alexey Kardashevskiy" <aik@amd.com>
Subject: [PATCH kernel 4/9] KVM: SEV-ES: explicitly disable debug
Date: Thu, 15 Jun 2023 16:37:52 +1000 [thread overview]
Message-ID: <20230615063757.3039121-5-aik@amd.com> (raw)
In-Reply-To: <20230615063757.3039121-1-aik@amd.com>
SVM/SEV enable debug registers intercepts to skip swapping DRs
on entering/exiting the guest. When the guest is in control of
debug registers (vcpu->guest_debug == 0), there is an optimisation to
reduce the number of context switches: intercepts are cleared and
the KVM_DEBUGREG_WONT_EXIT flag is set to tell KVM to do swapping
on guest enter/exit.
The same code also executes for SEV-ES, however it has no effect as
- it always takes (vcpu->guest_debug == 0) branch;
- KVM_DEBUGREG_WONT_EXIT is set but DR7 intercept is not cleared;
- vcpu_enter_guest() writes DRs but VMRUN for SEV-ES swaps them
with the values from _encrypted_ VMSA.
Be explicit about SEV-ES not supporting debug:
- return right away from dr_interception() and skip unnecessary processing;
- return an error right away from the KVM_SEV_LAUNCH_UPDATE_VMSA handler
if debugging was already enabled.
KVM_SET_GUEST_DEBUG are failing already after KVM_SEV_LAUNCH_UPDATE_VMSA
is finished due to vcpu->arch.guest_state_protected set to true.
Add WARN_ON to kvm_x86::sync_dirty_debug_regs() (saves guest DRs on
guest exit) to signify that SEV-ES won't hit that path.
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Alexey Kardashevskiy <aik@amd.com>
---
Changes:
v6:
* fail in LAUNCH_UPDATE_VMSA instead of clearing the flag
* pr_warn_ratelimited -> pr_warn_once
* due to the rework, removed Tom's "rb"
v5:
* new in the series
---
arch/x86/kvm/svm/sev.c | 5 +++++
arch/x86/kvm/svm/svm.c | 9 ++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 36fe2fcb4698..981286359b72 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -619,6 +619,11 @@ static int __sev_launch_update_vmsa(struct kvm *kvm, struct kvm_vcpu *vcpu,
struct vcpu_svm *svm = to_svm(vcpu);
int ret;
+ if (vcpu->guest_debug) {
+ pr_warn_once("KVM_SET_GUEST_DEBUG for SEV-ES guest is not supported");
+ return -EINVAL;
+ }
+
/* Perform some pre-encryption checks against the VMSA */
ret = sev_es_sync_vmsa(svm);
if (ret)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 9c1b191aed4b..bec6fb82f494 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -1996,7 +1996,7 @@ static void svm_sync_dirty_debug_regs(struct kvm_vcpu *vcpu)
{
struct vcpu_svm *svm = to_svm(vcpu);
- if (vcpu->arch.guest_state_protected)
+ if (WARN_ON_ONCE(sev_es_guest(vcpu->kvm)))
return;
get_debugreg(vcpu->arch.db[0], 0);
@@ -2727,6 +2727,13 @@ static int dr_interception(struct kvm_vcpu *vcpu)
unsigned long val;
int err = 0;
+ /*
+ * SEV-ES intercepts DR7 only to disable guest debugging and the guest issues a VMGEXIT
+ * for DR7 write only. KVM cannot change DR7 (always swapped as type 'A') so return early.
+ */
+ if (sev_es_guest(vcpu->kvm))
+ return 1;
+
if (vcpu->guest_debug == 0) {
/*
* No more DR vmexits; force a reload of the debug registers
--
2.40.1
next prev parent reply other threads:[~2023-06-15 6:43 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-15 6:37 [PATCH kernel 0/9] KVM: SEV: Enable AMD SEV-ES DebugSwap Alexey Kardashevskiy
2023-06-15 6:37 ` [PATCH kernel 1/9] KVM: SEV: move set_dr_intercepts/clr_dr_intercepts from the header Alexey Kardashevskiy
2023-06-15 6:37 ` [PATCH kernel 2/9] KVM: SEV: Move SEV's GP_VECTOR intercept setup to SEV Alexey Kardashevskiy
2023-06-15 6:37 ` [PATCH kernel 3/9] KVM: SVM: Rewrite sev_es_prepare_switch_to_guest()'s comment about swap types Alexey Kardashevskiy
2023-06-15 6:37 ` Alexey Kardashevskiy [this message]
2023-06-15 6:37 ` [PATCH kernel 5/9] KVM: SVM/SEV/SEV-ES: Rework intercepts Alexey Kardashevskiy
2023-06-30 21:49 ` Sean Christopherson
2023-07-03 2:01 ` Alexey Kardashevskiy
2023-06-15 6:37 ` [PATCH kernel 6/9] KVM: SEV: Enable data breakpoints in SEV-ES Alexey Kardashevskiy
2023-06-15 6:37 ` [PATCH kernel 7/9] KVM: SEV-ES: Eliminate #DB intercept when DebugSwap enabled Alexey Kardashevskiy
2023-06-15 6:37 ` [PATCH kernel 8/9] KVM: SVM: Don't defer NMI unblocking until next exit for SEV-ES guests Alexey Kardashevskiy
2023-06-15 6:37 ` [PATCH kernel 9/9] KVM: SVM: Don't try to pointlessly single-step SEV-ES guests for NMI window Alexey Kardashevskiy
2023-06-15 7:13 ` [PATCH kernel 0/9 v6] KVM: SEV: Enable AMD SEV-ES DebugSwap Alexey Kardashevskiy
2023-06-23 1:35 ` Alexey Kardashevskiy
2023-06-23 14:19 ` Sean Christopherson
2023-06-30 2:08 ` Alexey Kardashevskiy
2023-06-30 21:52 ` Sean Christopherson
2023-07-20 19:01 ` Alexey Kardashevskiy
2023-07-28 23:49 ` [PATCH kernel 0/9] " Sean Christopherson
2023-07-29 1:57 ` Alexey Kardashevskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230615063757.3039121-5-aik@amd.com \
--to=aik@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=seanjc@google.com \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox