From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: x86@kernel.org, "Kenneth R . Crudup" <kenny@panix.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Fenghua Yu <fenghua.yu@intel.com>,
Xiaoyao Li <xiaoyao.li@intel.com>, Nadav Amit <namit@vmware.com>,
Thomas Hellstrom <thellstrom@vmware.com>,
Tony Luck <tony.luck@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Jessica Yu <jeyu@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] KVM: VMX: Extend VMX's #AC interceptor to handle split lock #AC in guest
Date: Thu, 2 Apr 2020 10:40:23 -0700 [thread overview]
Message-ID: <20200402174023.GI13879@linux.intel.com> (raw)
In-Reply-To: <87sghln6tr.fsf@nanos.tec.linutronix.de>
On Thu, Apr 02, 2020 at 07:19:44PM +0200, Thomas Gleixner wrote:
> Sean Christopherson <sean.j.christopherson@intel.com> writes:
> > @@ -4623,6 +4623,12 @@ static int handle_machine_check(struct kvm_vcpu *vcpu)
> > return 1;
> > }
> >
> > +static inline bool guest_cpu_alignment_check_enabled(struct kvm_vcpu *vcpu)
>
> I used a different function name intentionally so the check for 'guest
> want's split lock #AC' can go there as well once it's sorted.
Heh, IIRC, I advised Xiaoyao to do the opposite so that the injection logic
in the #AC case statement was more or less complete without having to dive
into the helper, e.g. the resulting code looks like this once split-lock is
exposed to the guest:
if (!boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT) ||
guest_cpu_alignment_check_enabled(vcpu) ||
guest_cpu_sld_on(vmx)) {
kvm_queue_exception_e(vcpu, AC_VECTOR, error_code);
return 1;
}
> > +{
> > + return vmx_get_cpl(vcpu) == 3 && kvm_read_cr0_bits(vcpu, X86_CR0_AM) &&
> > + (kvm_get_rflags(vcpu) & X86_EFLAGS_AC);
> > +}
> > +
> > static int handle_exception_nmi(struct kvm_vcpu *vcpu)
> > {
> > struct vcpu_vmx *vmx = to_vmx(vcpu);
> > @@ -4688,9 +4694,6 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
> > return handle_rmode_exception(vcpu, ex_no, error_code);
> >
> > switch (ex_no) {
> > - case AC_VECTOR:
> > - kvm_queue_exception_e(vcpu, AC_VECTOR, error_code);
> > - return 1;
> > case DB_VECTOR:
> > dr6 = vmcs_readl(EXIT_QUALIFICATION);
> > if (!(vcpu->guest_debug &
> > @@ -4719,6 +4722,27 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
> > kvm_run->debug.arch.pc = vmcs_readl(GUEST_CS_BASE) + rip;
> > kvm_run->debug.arch.exception = ex_no;
> > break;
> > + case AC_VECTOR:
> > + /*
> > + * Reflect #AC to the guest if it's expecting the #AC, i.e. has
> > + * legacy alignment check enabled. Pre-check host split lock
> > + * turned on to avoid the VMREADs needed to check legacy #AC,
> > + * i.e. reflect the #AC if the only possible source is legacy
> > + * alignment checks.
> > + */
> > + if (!boot_cpu_has(X86_FEATURE_SPLIT_LOCK_DETECT) ||
>
> I think the right thing to do here is to make this really independent of
> that feature, i.e. inject the exception if
>
> (CPL==3 && CR0.AM && EFLAGS.AC) || (FUTURE && (GUEST_TEST_CTRL & SLD))
>
> iow. when its really clear that the guest asked for it. If there is an
> actual #AC with SLD disabled and !(CPL==3 && CR0.AM && EFLAGS.AC) then
> something is badly wrong and the thing should just die. That's why I
> separated handle_guest_split_lock() and tell about that case.
That puts KVM in a weird spot if/when intercepting #AC is no longer
necessary, e.g. "if" future CPUs happen to gain a feature that traps into
the hypervisor (KVM) if a potential near-infinite ucode loop is detected.
The only reason KVM intercepts #AC (before split-lock) is to prevent a
malicious guest from executing a DoS attack on the host by putting the #AC
handler in ring 3. Current CPUs will get stuck in ucode vectoring #AC
faults more or less indefinitely, e.g. long enough to trigger watchdogs in
the host.
Injecting #AC if and only if KVM is 100% certain the guest wants the #AC
would lead to divergent behavior if KVM chose to not intercept #AC, e.g.
some theoretical unknown #AC source would conditionally result in exits to
userspace depending on whether or not KVM wanted to intercept #AC for
other reasons.
That's why we went with the approach of reflecting #AC unless KVM detected
that the #AC was host-induced.
next prev parent reply other threads:[~2020-04-02 17:40 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200402124205.334622628@linutronix.de>
2020-04-02 15:55 ` [PATCH 0/3] x86: KVM: VMX: Add basic split-lock #AC handling Sean Christopherson
2020-04-02 15:55 ` [PATCH 1/3] KVM: x86: Emulate split-lock access as a write in emulator Sean Christopherson
2020-04-02 15:55 ` [PATCH 2/3] x86/split_lock: Refactor and export handle_user_split_lock() for KVM Sean Christopherson
2020-04-02 17:01 ` Thomas Gleixner
2020-04-02 17:19 ` Sean Christopherson
2020-04-02 19:06 ` Thomas Gleixner
2020-04-10 4:39 ` Xiaoyao Li
2020-04-10 10:21 ` Paolo Bonzini
2020-04-02 15:55 ` [PATCH 3/3] KVM: VMX: Extend VMX's #AC interceptor to handle split lock #AC in guest Sean Christopherson
2020-04-02 17:19 ` Thomas Gleixner
2020-04-02 17:40 ` Sean Christopherson [this message]
2020-04-02 20:07 ` Thomas Gleixner
2020-04-02 20:36 ` Andy Lutomirski
2020-04-02 20:48 ` Peter Zijlstra
2020-04-02 20:51 ` Sean Christopherson
2020-04-02 22:27 ` Thomas Gleixner
2020-04-02 22:40 ` Nadav Amit
2020-04-02 23:03 ` Thomas Gleixner
2020-04-02 23:08 ` Steven Rostedt
2020-04-02 23:16 ` Kenneth R. Crudup
2020-04-02 23:18 ` Jim Mattson
2020-04-03 12:16 ` Thomas Gleixner
2020-04-10 10:23 ` [PATCH 0/3] x86: KVM: VMX: Add basic split-lock #AC handling Paolo Bonzini
2020-04-10 11:14 ` Thomas Gleixner
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=20200402174023.GI13879@linux.intel.com \
--to=sean.j.christopherson@intel.com \
--cc=fenghua.yu@intel.com \
--cc=jeyu@kernel.org \
--cc=jmattson@google.com \
--cc=kenny@panix.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=namit@vmware.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=thellstrom@vmware.com \
--cc=tony.luck@intel.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
--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