From: Tianyu Lan <Tianyu.Lan@microsoft.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>,
Tianyu Lan <Tianyu.Lan@microsoft.com>
Cc: "pbonzini@redhat.com" <pbonzini@redhat.com>,
"rkrcmar@redhat.com" <rkrcmar@redhat.com>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"mingo@redhat.com" <mingo@redhat.com>,
"hpa@zytor.com" <hpa@zytor.com>,
"x86@kernel.org" <x86@kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Michael Kelley (EOSG)" <Michael.H.Kelley@microsoft.com>,
KY Srinivasan <kys@microsoft.com>,
"vkuznets@redhat.com" <vkuznets@redhat.com>
Subject: Re: [PATCH 3/4] KVM/VMX: Add identical ept table pointer check
Date: Wed, 4 Jul 2018 06:24:57 +0000 [thread overview]
Message-ID: <0551a777-880a-5019-6e9e-6c0fb5816525@microsoft.com> (raw)
In-Reply-To: <20180702172950.GA27827@linux.intel.com>
Hi Sean:
Thank for your review.
On 7/3/2018 1:29 AM, Sean Christopherson wrote:
> On Mon, Jul 02, 2018 at 02:17:29PM +0000, Tianyu Lan wrote:
>> This patch is to check ept table pointer of each cpus when set ept
>> tables and store identical ept table pointer if all ept table pointers
>> of single VM are same. This is for support of para-virt ept flush
>> hypercall.
>>
>> Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>
>> ---
>> arch/x86/kvm/vmx.c | 31 +++++++++++++++++++++++++++++++
>> 1 file changed, 31 insertions(+)
>>
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index 1689f433f3a0..0b1e4e9fef2b 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -194,6 +194,9 @@ struct kvm_vmx {
>> unsigned int tss_addr;
>> bool ept_identity_pagetable_done;
>> gpa_t ept_identity_map_addr;
>> +
>> + u64 identical_ept_pointer;
>> + spinlock_t ept_pointer_lock;
>> };
>>
>> #define NR_AUTOLOAD_MSRS 8
>> @@ -853,6 +856,7 @@ struct vcpu_vmx {
>> */
>> u64 msr_ia32_feature_control;
>> u64 msr_ia32_feature_control_valid_bits;
>> + u64 ept_pointer;
>> };
>>
>> enum segment_cache_field {
>> @@ -4958,6 +4962,29 @@ static u64 construct_eptp(struct kvm_vcpu *vcpu, unsigned long root_hpa)
>> return eptp;
>> }
>>
>> +static void check_ept_pointer(struct kvm_vcpu *vcpu, u64 eptp)
>> +{
>> + struct kvm *kvm = vcpu->kvm;
>> + u64 tmp_eptp = INVALID_PAGE;
>> + int i;
>> +
>> + spin_lock(&to_kvm_vmx(kvm)->ept_pointer_lock);
>> + to_vmx(vcpu)->ept_pointer = eptp;
>> +
>> + kvm_for_each_vcpu(i, vcpu, kvm) {
>> + if (!VALID_PAGE(tmp_eptp)) {
>> + tmp_eptp = to_vmx(vcpu)->ept_pointer;
>> + } else if (tmp_eptp != to_vmx(vcpu)->ept_pointer) {
>> + to_kvm_vmx(kvm)->identical_ept_pointer = INVALID_PAGE;
>> + spin_unlock(&to_kvm_vmx(kvm)->ept_pointer_lock);
>> + return;
>> + }
>> + }
>> +
>> + to_kvm_vmx(kvm)->identical_ept_pointer = tmp_eptp;
>> + spin_unlock(&to_kvm_vmx(kvm)->ept_pointer_lock);
>> +}
>> +
>> static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
>> {
>> unsigned long guest_cr3;
>> @@ -4967,6 +4994,8 @@ static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
>> if (enable_ept) {
>> eptp = construct_eptp(vcpu, cr3);
>> vmcs_write64(EPT_POINTER, eptp);
>> + check_ept_pointer(vcpu, eptp);
>
> Shouldn't this call, or the function itself, be conditional on Hyper-V
> or remote flushing, e.g. by checking kvm_x86_ops->tlb_remote_flush?
>
Yes, good suggestion and will update in the next version.
>> +
>> if (enable_unrestricted_guest || is_paging(vcpu) ||
>> is_guest_mode(vcpu))
>> guest_cr3 = kvm_read_cr3(vcpu);
>> @@ -10383,6 +10412,8 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
>>
>> static int vmx_vm_init(struct kvm *kvm)
>> {
>> + spin_lock_init(&to_kvm_vmx(kvm)->ept_pointer_lock);
>> +
>> if (!ple_gap)
>> kvm->arch.pause_in_guest = true;
>> return 0;
>> --
>> 2.14.3
next prev parent reply other threads:[~2018-07-04 6:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-02 14:17 [PATCH 0/4] KVM/x86/hyper-V: Introduce PV guest address space mapping flush support Tianyu Lan
2018-07-02 14:17 ` [PATCH 1/4] X86/Hyper-V: Add flush HvFlushGuestPhysicalAddressSpace hypercall support Tianyu Lan
2018-07-02 14:17 ` [PATCH 2/4] KVM: Add tlb remote flush callback in kvm_x86_ops Tianyu Lan
2018-07-03 2:39 ` kbuild test robot
2018-07-02 14:17 ` [PATCH 3/4] KVM/VMX: Add identical ept table pointer check Tianyu Lan
2018-07-02 15:09 ` Vitaly Kuznetsov
2018-07-04 6:18 ` Tianyu Lan
[not found] ` <20180702172950.GA27827@linux.intel.com>
2018-07-04 6:24 ` Tianyu Lan [this message]
2018-07-02 14:17 ` [PATCH 4/4] KVM/x86: Add tlb_remote_flush callback support for vmcs Tianyu Lan
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=0551a777-880a-5019-6e9e-6c0fb5816525@microsoft.com \
--to=tianyu.lan@microsoft.com \
--cc=Michael.H.Kelley@microsoft.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=kys@microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=sean.j.christopherson@intel.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.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
all inboxes | Powered by JetHome®