From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BD39C2D0A3 for ; Thu, 12 Nov 2020 10:27:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A24C22203 for ; Thu, 12 Nov 2020 10:27:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="A13Y+d9K" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727875AbgKLK1W (ORCPT ); Thu, 12 Nov 2020 05:27:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46726 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726107AbgKLK1S (ORCPT ); Thu, 12 Nov 2020 05:27:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605176836; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aXviuxk2g2luW7gT8Z4OXHxjhf58cXr2ylFfxf2m04M=; b=A13Y+d9KEi8caJo+MsOkMBF8OeubVPI+5v7HLEyWbHtHZobWmVJ0ksZG4MPrd79EAMozXo MZm810pLlP3IHMfudjX9hvS1Fr4TwgooysrmwY4QhxOW+3NPx5qyENceV9M2eMOxbtJDpb yRexZ3eSHX/0veBxUisYWlGZMjUzQ7o= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-251-CId3BZ_UM-m07BnK18Kc9Q-1; Thu, 12 Nov 2020 05:27:14 -0500 X-MC-Unique: CId3BZ_UM-m07BnK18Kc9Q-1 Received: by mail-wr1-f72.google.com with SMTP id y2so1737298wrl.3 for ; Thu, 12 Nov 2020 02:27:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=aXviuxk2g2luW7gT8Z4OXHxjhf58cXr2ylFfxf2m04M=; b=XFTmOqEer42100KwPN6g9dYf25VXYr/7iAsv1qr14MN/YXdEhSL/b1TwDL+MG6BrIH hHuTrnhvT6n/o/N1ocTm1uRxLCLQaN8ifWUgZ5F0OflkEo44AKxHywuiysFhQ3QP+MwJ sAHVGoE619dKDYPr3j8KzPkfSbdRjGLKx0kKvAqJat+CSyjuzp5LgSCBDZQpBnJC+lQH smENNpJ+46nlicPuMvyn+7syi3kJaU6y4HLIc5nZS9pqOhaNmMcYFNo5QN6SBa3/xLXa pPCK/C42IrIlwHEJDfq1TrBzhk9IQFaGBNSW91XWUcaIIDeQ20UMQu5Tdt4BGasfvh6A HSUg== X-Gm-Message-State: AOAM531GBK9VR7Iu2Ij7tyLhkv6WA/yLBNCFU9NsznLdeuHs25e7oxZ7 cJ5hfkN1zAxNGRGdOuxNhIA2ct4OQVJD7oJoGvjAvV/cQpodDWb5xGoh1ajj4LDGedceZXqmx/t TDw48R6pp9vQzVX/j1OWGjuZUeOldgrunJcEwEAnhj5EcHwNBbu2y/IjcaPlD4+cHRrMn+FC2sH 3C X-Received: by 2002:adf:8366:: with SMTP id 93mr34308598wrd.321.1605176833516; Thu, 12 Nov 2020 02:27:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJynlQ3DyJ1PTaMmRIZXzM5mczKefoSq8TcT5rbFvm2qHtIqAQU+nQnA3GmegdweWwjwveJImw== X-Received: by 2002:adf:8366:: with SMTP id 93mr34308577wrd.321.1605176833321; Thu, 12 Nov 2020 02:27:13 -0800 (PST) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id c2sm6514659wrf.68.2020.11.12.02.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 02:27:12 -0800 (PST) From: Vitaly Kuznetsov To: Sean Christopherson Cc: Paolo Bonzini , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 02/11] KVM: VMX: Track common EPTP for Hyper-V's paravirt TLB flush In-Reply-To: <20201027212346.23409-3-sean.j.christopherson@intel.com> References: <20201027212346.23409-1-sean.j.christopherson@intel.com> <20201027212346.23409-3-sean.j.christopherson@intel.com> Date: Thu, 12 Nov 2020 11:27:11 +0100 Message-ID: <87eekyzx8g.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sean Christopherson writes: > Explicitly track the EPTP that is common to all vCPUs instead of > grabbing vCPU0's EPTP when invoking Hyper-V's paravirt TLB flush. > Tracking the EPTP will allow optimizing the checks when loading a new > EPTP and will also allow dropping ept_pointer_match, e.g. by marking > the common EPTP as invalid. > > This also technically fixes a bug where KVM could theoretically flush an > invalid GPA if all vCPUs have an invalid root. In practice, it's likely > impossible to trigger a remote TLB flush in such a scenario. In any > case, the superfluous flush is completely benign. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/vmx/vmx.c | 20 +++++++++----------- > arch/x86/kvm/vmx/vmx.h | 1 + > 2 files changed, 10 insertions(+), 11 deletions(-) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 273a3206cef7..ebc87df4da4d 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -483,12 +483,14 @@ static void check_ept_pointer_match(struct kvm *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)->hv_tlb_eptp = INVALID_PAGE; > to_kvm_vmx(kvm)->ept_pointers_match > = EPT_POINTERS_MISMATCH; > return; > } > } > > + to_kvm_vmx(kvm)->hv_tlb_eptp = tmp_eptp; > to_kvm_vmx(kvm)->ept_pointers_match = EPT_POINTERS_MATCH; > } > > @@ -501,21 +503,18 @@ static int kvm_fill_hv_flush_list_func(struct hv_guest_mapping_flush_list *flush > range->pages); > } > > -static inline int __hv_remote_flush_tlb_with_range(struct kvm *kvm, > - struct kvm_vcpu *vcpu, struct kvm_tlb_range *range) > +static inline int hv_remote_flush_eptp(u64 eptp, struct kvm_tlb_range *range) > { > - u64 ept_pointer = to_vmx(vcpu)->ept_pointer; > - > /* > * FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE hypercall needs address > * of the base of EPT PML4 table, strip off EPT configuration > * information. > */ > if (range) > - return hyperv_flush_guest_mapping_range(ept_pointer & PAGE_MASK, > + return hyperv_flush_guest_mapping_range(eptp & PAGE_MASK, > kvm_fill_hv_flush_list_func, (void *)range); > else > - return hyperv_flush_guest_mapping(ept_pointer & PAGE_MASK); > + return hyperv_flush_guest_mapping(eptp & PAGE_MASK); > } > > static int hv_remote_flush_tlb_with_range(struct kvm *kvm, > @@ -533,12 +532,11 @@ static int hv_remote_flush_tlb_with_range(struct kvm *kvm, > kvm_for_each_vcpu(i, vcpu, kvm) { > /* If ept_pointer is invalid pointer, bypass flush request. */ > if (VALID_PAGE(to_vmx(vcpu)->ept_pointer)) > - ret |= __hv_remote_flush_tlb_with_range( > - kvm, vcpu, range); > + ret |= hv_remote_flush_eptp(to_vmx(vcpu)->ept_pointer, > + range); > } > - } else { > - ret = __hv_remote_flush_tlb_with_range(kvm, > - kvm_get_vcpu(kvm, 0), range); > + } else if (VALID_PAGE(to_kvm_vmx(kvm)->hv_tlb_eptp)) { > + ret = hv_remote_flush_eptp(to_kvm_vmx(kvm)->hv_tlb_eptp, range); > } > > spin_unlock(&to_kvm_vmx(kvm)->ept_pointer_lock); > diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h > index a2d143276603..9a25e83f8b96 100644 > --- a/arch/x86/kvm/vmx/vmx.h > +++ b/arch/x86/kvm/vmx/vmx.h > @@ -301,6 +301,7 @@ struct kvm_vmx { > bool ept_identity_pagetable_done; > gpa_t ept_identity_map_addr; > > + hpa_t hv_tlb_eptp; > enum ept_pointers_status ept_pointers_match; > spinlock_t ept_pointer_lock; > }; Reviewed-by: Vitaly Kuznetsov -- Vitaly