From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: 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>
Subject: Re: [PATCH 3/4] KVM/VMX: Add identical ept table pointer check
Date: Mon, 02 Jul 2018 17:09:57 +0200 [thread overview]
Message-ID: <87lgatbrne.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <20180702141653.88936-4-Tianyu.Lan@microsoft.com> (Tianyu Lan's message of "Mon, 2 Jul 2018 14:17:29 +0000")
Tianyu Lan <Tianyu.Lan@microsoft.com> writes:
> 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);
It seems we can get away with identical_ept_pointer being just 'bool':
go through the vCPU list and compare ept_pointer with ept_pointer for
the current vcpu. It would also make sense to rename it to something
like 'ept_pointers_match'.
I'm also not sure we need a dedicated ept_pointer_lock, can't we just
use the already existent mmu_lock from struct kvm?
> +}
> +
> 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);
Do we always get here when we need? E.g, do we need to enforce
CPU_BASED_CR3_STORE_EXITING?
> +
> 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;
--
Vitaly
next prev parent reply other threads:[~2018-07-02 15:10 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 [this message]
2018-07-04 6:18 ` Tianyu Lan
[not found] ` <20180702172950.GA27827@linux.intel.com>
2018-07-04 6:24 ` Tianyu Lan
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=87lgatbrne.fsf@vitty.brq.redhat.com \
--to=vkuznets@redhat.com \
--cc=Michael.H.Kelley@microsoft.com \
--cc=Tianyu.Lan@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=tglx@linutronix.de \
--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
Powered by JetHome