Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp93285imm; Mon, 2 Jul 2018 08:12:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJN7US1FQgVuwyNui0RB0C86EomUVNGtPfi9eGJytHPWO1EogQ+RamO2ARF1dx9kUy5tT/G X-Received: by 2002:a65:4a4d:: with SMTP id a13-v6mr22083833pgu.161.1530544349999; Mon, 02 Jul 2018 08:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530544349; cv=none; d=google.com; s=arc-20160816; b=zdqnrL13JYnSO9jWy7J05dFlbdtbVUUBJLxYkLvGX8TZQKjEnfb86ffVeAo64E7+jW icaOCfREXSufN8LJT6pfJdA9Hr3FrtRsthLRA5WtMGMTuWK1Ev70AqhL+DjWHbLOhMBB CADG7/RKxsTBss0EJUs9Bruh7Hh9DazdqijFOUafDooWTN/88ZNdhkNxVoPHKuqRqnSy MTn3m/qXfCxOv948MOzGLUUfN/5NIdMFilQ3d4M6VSH1zHMji1FjB7/OcKvIbxnpCA/V /MDlOm8GjXymxIaFim4OfRymgXoo4WbeS5B/NpyBXAuGiCqN9vFph0VJWzi4idWF+giY ck4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from :arc-authentication-results; bh=hMBRezpIkjOz04X4ObSpwXHf6iXTuIZ2wzr8lSvQ0ww=; b=pHn5wGtZ9ellnXgUDpSRA9ufKqSlQV+ryHKDI5yc8gt07T+Bxr5oH90Hjx9Zvh1x6U Dr2vqxUq/nbVmHiVTeOvsOxUMPKYYin9iqUY/MWGplyQ0lYuYHR3GPNXhN/ZVQWo0vy5 hBIAkQSAe0qlewZJeA/SZxt05rkoRGlZYI3+F3ax9pD3tDf+PIvcD7CRYx8ssNeqqvjK SFUDPH1N58FzfrcvkFNipN8b6hjsgfyGDlzAwsQGXjn5pCVni0Rm9THYsQwgnGzdDrud WCEb+iP1NcjGcEy+tgNsuAf5QtPHNmgG9PgOLuoBS+1zkfzhqI0WhpZ3HTr3X1p/KW1J XWNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5-v6si10096028pgq.167.2018.07.02.08.12.09; Mon, 02 Jul 2018 08:12:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752184AbeGBPKC (ORCPT + 99 others); Mon, 2 Jul 2018 11:10:02 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57206 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751931AbeGBPKB (ORCPT ); Mon, 2 Jul 2018 11:10:01 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A6EAD4021CC2; Mon, 2 Jul 2018 15:10:00 +0000 (UTC) Received: from vitty.brq.redhat.com.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 124661C4C3; Mon, 2 Jul 2018 15:09:58 +0000 (UTC) From: Vitaly Kuznetsov To: Tianyu Lan Cc: "pbonzini\@redhat.com" , "rkrcmar\@redhat.com" , "tglx\@linutronix.de" , "mingo\@redhat.com" , "hpa\@zytor.com" , "x86\@kernel.org" , "kvm\@vger.kernel.org" , "linux-kernel\@vger.kernel.org" , "Michael Kelley \(EOSG\)" , KY Srinivasan Subject: Re: [PATCH 3/4] KVM/VMX: Add identical ept table pointer check References: <20180702141653.88936-1-Tianyu.Lan@microsoft.com> <20180702141653.88936-4-Tianyu.Lan@microsoft.com> Date: Mon, 02 Jul 2018 17:09:57 +0200 In-Reply-To: <20180702141653.88936-4-Tianyu.Lan@microsoft.com> (Tianyu Lan's message of "Mon, 2 Jul 2018 14:17:29 +0000") Message-ID: <87lgatbrne.fsf@vitty.brq.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 15:10:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 02 Jul 2018 15:10:00 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'vkuznets@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tianyu Lan 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 > --- > 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