From: KarimAllah Ahmed <karahmed@amazon.com>
To: David Woodhouse <dwmw2@infradead.org>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Jim Mattson <jmattson@google.com>,
KarimAllah Ahmed <karahmed@amazon.de>,
kvm list <kvm@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
"the arch/x86 maintainers" <x86@kernel.org>,
Asit Mallick <asit.k.mallick@intel.com>,
Arjan Van De Ven <arjan.van.de.ven@intel.com>,
Dave Hansen <dave.hansen@intel.com>,
Andi Kleen <ak@linux.intel.com>,
"Andrea Arcangeli" <aarcange@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Tim Chen <tim.c.chen@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Dan Williams <dan.j.williams@intel.com>,
Jun Nakajima <jun.nakajima@intel.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
Greg KH <gregkh@linuxfoundation.org>,
"Andy Lutomirski" <luto@kernel.org>,
Ashok Raj <ashok.raj@intel.com>
Subject: Re: [PATCH v5 4/5] KVM: VMX: Allow direct access to MSR_IA32_SPEC_CTRL
Date: Thu, 1 Feb 2018 18:46:12 +0100 [thread overview]
Message-ID: <d2db54d3-73ab-7e24-8368-3288e9d18f14@amazon.com> (raw)
In-Reply-To: <ed251937-be2a-a922-52e9-0982c15e7764@amazon.com>
On 02/01/2018 06:37 PM, KarimAllah Ahmed wrote:
> On 02/01/2018 02:25 PM, David Woodhouse wrote:
>>
>>
>> On Wed, 2018-01-31 at 23:26 -0500, Konrad Rzeszutek Wilk wrote:
>>>
>>>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>>>> index 6a9f4ec..bfc80ff 100644
>>>> --- a/arch/x86/kvm/vmx.c
>>>> +++ b/arch/x86/kvm/vmx.c
>>>> @@ -594,6 +594,14 @@ struct vcpu_vmx {
>>>> #endif
>>>> u64 arch_capabilities;
>>>> + u64 spec_ctrl;
>>>> +
>>>> + /*
>>>> + * This indicates that:
>>>> + * 1) guest_cpuid_has(X86_FEATURE_IBRS) == true &&
>>>> + * 2) The guest has actually initiated a write against the MSR.
>>>> + */
>>>> + bool spec_ctrl_used;
>>>> /*
>>>> * This indicates that:
>>
>> Thanks for persisting with the details here, Karim. In addition to
>> Konrad's heckling at the comments, I'll add my own request to his...
>>
>> I'd like the comment for spec_ctrl_used to explain why it isn't
>> entirely redundant with the spec_ctrl_intercepted() function.
>>
>> Without nesting, I believe it *would* be redundant, but the difference
>> comes when an L2 is running for which L1 has not permitted the MSR to
>> be passed through. That's when we have spec_ctrl_used = true but the
>> MSR *isn't* actually passed through in the active msr_bitmap.
>>
>> Question: if spec_ctrl_used is always equivalent to the intercept bit
>> in the vmcs01.msr_bitmap, just not the guest bitmap... should we ditch
>> it and always use the bit from the vmcs01.msr_bitmap?
>
> If I used the vmcs01.msr_bitmap, spec_ctrl_used will always be true if
> L0 passed it to L1. Even if L1 did not actually pass it to L2 and even
> if L2 has not written to it yet (!used).
>
> This pretty much renders the short-circuit at
> nested_vmx_merge_msr_bitmap useless:
>
> if (!nested_cpu_has_virt_x2apic_mode(vmcs12) &&
> !to_vmx(vcpu)->pred_cmd_used &&
> !to_vmx(vcpu)->spec_ctrl_used)
> return false;
>
> ... and the default path will be kvm_vcpu_gpa_to_page + kmap.
>
> That being said, I have to admit the logic for spec_ctrl_used is not
> perfect either.
>
> If L1 or any of the L2s touched the MSR, spec_ctrl_used will be set to
> true. So if one L2 used the MSR, all other L2s will also skip the short-
> circuit mentioned above and end up *always* going through
> kvm_vcpu_gpa_to_page + kmap.
>
> Maybe all of this is over-thinking and in reality the short-circuit
> above is really useless and all L2 guests are happily using x2apic :)
>
hehe ..
>> if spec_ctrl_used is always equivalent to the intercept bit in the
vmcs01.msr_bitmap
actually yes, we can.
I just forgot that we update the msr bitmap lazily! :)
>>
>> Sorry :)
>>
Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
next prev parent reply other threads:[~2018-02-01 17:46 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-31 19:37 [PATCH v5 0/5] KVM: Expose speculation control feature to guests KarimAllah Ahmed
2018-01-31 19:37 ` [PATCH v5 1/5] KVM: x86: Update the reverse_cpuid list to include CPUID_7_EDX KarimAllah Ahmed
2018-01-31 20:22 ` Konrad Rzeszutek Wilk
2018-01-31 19:37 ` [PATCH v5 2/5] KVM: x86: Add IBPB support KarimAllah Ahmed
2018-01-31 19:45 ` Jim Mattson
2018-01-31 19:53 ` David Woodhouse
2018-01-31 19:55 ` Jim Mattson
2018-02-01 0:27 ` KarimAllah Ahmed
2018-01-31 20:28 ` Konrad Rzeszutek Wilk
2018-01-31 20:36 ` KarimAllah Ahmed
2018-02-01 4:54 ` Tom Lendacky
2018-02-01 17:00 ` Raj, Ashok
2018-01-31 19:37 ` [PATCH v5 3/5] KVM: VMX: Emulate MSR_IA32_ARCH_CAPABILITIES KarimAllah Ahmed
2018-01-31 19:37 ` [PATCH v5 4/5] KVM: VMX: Allow direct access to MSR_IA32_SPEC_CTRL KarimAllah Ahmed
2018-01-31 19:53 ` Jim Mattson
2018-01-31 20:00 ` David Woodhouse
2018-01-31 20:01 ` KarimAllah Ahmed
2018-01-31 20:18 ` Jim Mattson
2018-01-31 20:21 ` David Woodhouse
2018-01-31 21:18 ` Jim Mattson
2018-01-31 22:05 ` David Woodhouse
2018-01-31 20:34 ` Paolo Bonzini
2018-01-31 20:54 ` Jim Mattson
2018-01-31 21:00 ` Paolo Bonzini
2018-01-31 21:05 ` Jim Mattson
2018-01-31 21:17 ` Woodhouse, David
2018-01-31 21:42 ` Paolo Bonzini
2018-01-31 21:53 ` Jim Mattson
2018-01-31 21:59 ` Paolo Bonzini
2018-01-31 21:59 ` David Woodhouse
2018-01-31 22:06 ` Jim Mattson
2018-01-31 22:10 ` David Woodhouse
2018-01-31 22:21 ` Linus Torvalds
2018-01-31 22:53 ` Andy Lutomirski
2018-02-01 14:09 ` Paolo Bonzini
2018-01-31 22:52 ` KarimAllah Ahmed
2018-02-01 0:24 ` KarimAllah Ahmed
2018-02-01 4:26 ` Konrad Rzeszutek Wilk
2018-02-01 13:25 ` David Woodhouse
2018-02-01 17:37 ` KarimAllah Ahmed
2018-02-01 17:46 ` KarimAllah Ahmed [this message]
2018-02-01 14:19 ` Konrad Rzeszutek Wilk
2018-02-01 14:28 ` KarimAllah Ahmed
2018-01-31 22:56 ` Raj, Ashok
2018-01-31 19:37 ` [PATCH v5 5/5] KVM: SVM: " KarimAllah Ahmed
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=d2db54d3-73ab-7e24-8368-3288e9d18f14@amazon.com \
--to=karahmed@amazon.com \
--cc=aarcange@redhat.com \
--cc=ak@linux.intel.com \
--cc=arjan.van.de.ven@intel.com \
--cc=ashok.raj@intel.com \
--cc=asit.k.mallick@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.hansen@intel.com \
--cc=dwmw2@infradead.org \
--cc=gregkh@linuxfoundation.org \
--cc=jmattson@google.com \
--cc=jun.nakajima@intel.com \
--cc=karahmed@amazon.de \
--cc=konrad.wilk@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=tim.c.chen@linux.intel.com \
--cc=torvalds@linux-foundation.org \
--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
all inboxes | Powered by JetHome®