From: Maxim Levitsky <mlevitsk@redhat.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Ravi Bangoria <ravi.bangoria@amd.com>,
Xiaoyao Li <xiaoyao.li@intel.com>,
rangemachine@gmail.com, whanos@sergal.fun
Subject: Re: [PATCH v3 0/6] KVM: SVM: Fix DEBUGCTL bugs
Date: Tue, 08 Apr 2025 11:08:35 -0400 [thread overview]
Message-ID: <1371fec40588247a5f3d42f1b0f21cf4d0f5bc4e.camel@redhat.com> (raw)
In-Reply-To: <1b0fbad5b2be164da13034fe486c207d8a19f5e7.camel@redhat.com>
On Tue, 2025-04-01 at 23:57 -0400, Maxim Levitsky wrote:
> On Thu, 2025-02-27 at 14:24 -0800, Sean Christopherson wrote:
> > Fix a long-lurking bug in SVM where KVM runs the guest with the host's
> > DEBUGCTL if LBR virtualization is disabled. AMD CPUs rather stupidly
> > context switch DEBUGCTL if and only if LBR virtualization is enabled (not
> > just supported, but fully enabled).
> >
> > The bug has gone unnoticed because until recently, the only bits that
> > KVM would leave set were things like BTF, which are guest visible but
> > won't cause functional problems unless guest software is being especially
> > particular about #DBs.
> >
> > The bug was exposed by the addition of BusLockTrap ("Detect" in the kernel),
> > as the resulting #DBs due to split-lock accesses in guest userspace (lol
> > Steam) get reflected into the guest by KVM.
> >
> > Note, I don't love suppressing DEBUGCTL.BTF, but practically speaking that's
> > likely the behavior that SVM guests have gotten the vast, vast majority of
> > the time, and given that it's the behavior on Intel, it's (hopefully) a safe
> > option for a fix, e.g. versus trying to add proper BTF virtualization on the
> > fly.
> >
> > v3:
> > - Suppress BTF, as KVM doesn't actually support it. [Ravi]
> > - Actually load the guest's DEBUGCTL (though amusingly, with BTF squashed,
> > it's guaranteed to be '0' in this scenario). [Ravi]
> >
> > v2:
> > - Load the guest's DEBUGCTL instead of simply zeroing it on VMRUN.
> > - Drop bits 5:3 from guest DEBUGCTL so that KVM doesn't let the guest
> > unintentionally enable BusLockTrap (AMD repurposed bits). [Ravi]
> > - Collect a review. [Xiaoyao]
> > - Make bits 5:3 fully reserved, in a separate not-for-stable patch.
> >
> > v1: https://lore.kernel.org/all/20250224181315.2376869-1-seanjc@google.com
> >
>
> Hi,
>
> Amusingly there is another DEBUGCTL issue, which I just got to the bottom of.
> (if I am not mistaken of course).
>
> We currently don't let the guest set DEBUGCTL.FREEZE_WHILE_SMM and neither
> set it ourselves in GUEST_IA32_DEBUGCTL vmcs field, even when supported by the host
> (If I read the code correctly, I didn't verify this in runtime)
>
> This means that the host #SMIs will interfere with the guest PMU.
> In particular this causes the 'pmu' kvm-unit-test to fail, which is something that our CI caught.
>
> I think that kvm should just set this bit, or even better, use the host value of this bit,
> and hide it from the guest, because the guest shouldn't know about host's smm,
> and we AFAIK don't really support freezing perfmon when the guest enters its own emulated SMM.
>
> What do you think? I'll post patches if you think that this is a good idea.
> (A temp hack to set this bit always in GUEST_IA32_DEBUGCTL fixed the problem for me)
>
> I also need to check if AMD also has this feature, or if this is Intel specific.
Any update?
Best regards,
Maxim Levitsky
>
> Best regards,
> Maxim Levitsky
>
> > Sean Christopherson (6):
> > KVM: SVM: Drop DEBUGCTL[5:2] from guest's effective value
> > KVM: SVM: Suppress DEBUGCTL.BTF on AMD
> > KVM: x86: Snapshot the host's DEBUGCTL in common x86
> > KVM: SVM: Manually context switch DEBUGCTL if LBR virtualization is
> > disabled
> > KVM: x86: Snapshot the host's DEBUGCTL after disabling IRQs
> > KVM: SVM: Treat DEBUGCTL[5:2] as reserved
> >
> > arch/x86/include/asm/kvm_host.h | 1 +
> > arch/x86/kvm/svm/svm.c | 24 ++++++++++++++++++++++++
> > arch/x86/kvm/svm/svm.h | 2 +-
> > arch/x86/kvm/vmx/vmx.c | 8 ++------
> > arch/x86/kvm/vmx/vmx.h | 2 --
> > arch/x86/kvm/x86.c | 2 ++
> > 6 files changed, 30 insertions(+), 9 deletions(-)
> >
> >
> > base-commit: fed48e2967f402f561d80075a20c5c9e16866e53
next prev parent reply other threads:[~2025-04-08 15:08 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 22:24 [PATCH v3 0/6] KVM: SVM: Fix DEBUGCTL bugs Sean Christopherson
2025-02-27 22:24 ` [PATCH v3 1/6] KVM: SVM: Drop DEBUGCTL[5:2] from guest's effective value Sean Christopherson
2025-02-27 22:24 ` [PATCH v3 2/6] KVM: SVM: Suppress DEBUGCTL.BTF on AMD Sean Christopherson
2025-02-27 22:24 ` [PATCH v3 3/6] KVM: x86: Snapshot the host's DEBUGCTL in common x86 Sean Christopherson
2025-02-27 22:24 ` [PATCH v3 4/6] KVM: SVM: Manually context switch DEBUGCTL if LBR virtualization is disabled Sean Christopherson
2025-02-27 22:24 ` [PATCH v3 5/6] KVM: x86: Snapshot the host's DEBUGCTL after disabling IRQs Sean Christopherson
2025-02-27 22:24 ` [PATCH v3 6/6] KVM: SVM: Treat DEBUGCTL[5:2] as reserved Sean Christopherson
2025-02-28 9:31 ` [PATCH v3 0/6] KVM: SVM: Fix DEBUGCTL bugs Ravi Bangoria
2025-02-28 14:04 ` Sean Christopherson
2025-02-28 23:40 ` Sean Christopherson
2025-04-02 3:57 ` Maxim Levitsky
2025-04-08 15:08 ` Maxim Levitsky [this message]
2025-04-08 22:43 ` Sean Christopherson
2025-04-09 20:52 ` Maxim Levitsky
2025-04-14 6:32 ` Sandipan Das
2025-04-14 14:43 ` Maxim Levitsky
2025-05-02 21:51 ` Sean Christopherson
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=1371fec40588247a5f3d42f1b0f21cf4d0f5bc4e.camel@redhat.com \
--to=mlevitsk@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rangemachine@gmail.com \
--cc=ravi.bangoria@amd.com \
--cc=seanjc@google.com \
--cc=whanos@sergal.fun \
--cc=xiaoyao.li@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).