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 EDB75C561F8 for ; Wed, 21 Oct 2020 12:39:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7DB352224E for ; Wed, 21 Oct 2020 12:39:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NwxEkHYt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408698AbgJUMja (ORCPT ); Wed, 21 Oct 2020 08:39:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51067 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407970AbgJUMj2 (ORCPT ); Wed, 21 Oct 2020 08:39:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603283967; 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=c7EH/NJ6Fg/m8L/HBnnaHt/LKhGAw4sqP6ejYqOggwk=; b=NwxEkHYt08mjksklLk9IF/PULUeLl4oqwOjD6907Cp3sEBflZTxxsD+gBRdFzwz0hDx43f 3x6wQRjzl0GqydFf/RpmbzzIPAwV7K/92DVQd3mD2BPf4SzNfJQJMVk0GYB9yGffcRMr7P 33ai9b+jHC+iOVwz5nUJbIJcMInGInc= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-9FTZFJpMPDqYCKVsgcF40A-1; Wed, 21 Oct 2020 08:39:24 -0400 X-MC-Unique: 9FTZFJpMPDqYCKVsgcF40A-1 Received: by mail-wr1-f70.google.com with SMTP id b11so2573336wrm.3 for ; Wed, 21 Oct 2020 05:39:24 -0700 (PDT) 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=c7EH/NJ6Fg/m8L/HBnnaHt/LKhGAw4sqP6ejYqOggwk=; b=WcvQpk4LboxZFmWLOYc029sRk2kUNjl5omBpZfJ/BxlKJICPlapJTIREGJyXDDDQ/7 qLDTCf+cUwLz2ynvZlO2EIItac+UGqRbJkCSK6t22tgHYhHMg7eGMDqGQ+rJmax+EL7z MT2JQovekyLwOBNCrzMiAJgsJ6VZ7t+dBhAb3pmPt/87GkgLO3rJ5WmX7fznjZVPLbqM SN6yDumQBVmieDJ5ttb7qBssvqU7skIfaa1cSmAms/CVUv/SxGLgHOWmC+Ng3gPOgjXO dHfMoma0B5wW80tbYmyPXH5UxJNdwrGFe0oFPwv+ozFXLnPNWYqOXuy5EM4LDGi47EFr FsrA== X-Gm-Message-State: AOAM533T+v284UoVsOpQwQEjNMwzsGwfVWXGCpsJI+JWC3xLqSmaMbX8 2NPnPbvN4T8ff8oDBxxTGCrm0Y9uUS3csUe0zZPyDPOXueNuchLA3ggxGsBEhjEoOkKr4MsBihw 64X0x0MgWE5qfYQ8osFTJ6sAZ X-Received: by 2002:adf:80c8:: with SMTP id 66mr4650721wrl.415.1603283962840; Wed, 21 Oct 2020 05:39:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpiPbbJK4AX5vO6QZtccwjQuHYrMpWSENlh7dEYIreZ7TRkNyQ+Z5nk41eW0foiBgy0TF1oQ== X-Received: by 2002:adf:80c8:: with SMTP id 66mr4650696wrl.415.1603283962631; Wed, 21 Oct 2020 05:39:22 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id x64sm3593660wmg.33.2020.10.21.05.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Oct 2020 05:39:21 -0700 (PDT) From: Vitaly Kuznetsov To: Sean Christopherson , Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 05/10] KVM: VMX: Invalidate hv_tlb_eptp to denote an EPTP mismatch In-Reply-To: <20201020215613.8972-6-sean.j.christopherson@intel.com> References: <20201020215613.8972-1-sean.j.christopherson@intel.com> <20201020215613.8972-6-sean.j.christopherson@intel.com> Date: Wed, 21 Oct 2020 14:39:20 +0200 Message-ID: <87wnzj4utj.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: > Drop the dedicated 'ept_pointers_match' field in favor of stuffing > 'hv_tlb_eptp' with INVALID_PAGE to mark it as invalid, i.e. to denote > that there is at least one EPTP mismatch. Use a local variable to > track whether or not a mismatch is detected so that hv_tlb_eptp can be > used to skip redundant flushes. > > No functional change intended. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/vmx/vmx.c | 16 ++++++++-------- > arch/x86/kvm/vmx/vmx.h | 7 ------- > 2 files changed, 8 insertions(+), 15 deletions(-) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 52cb9eec1db3..4dfde8b64750 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -498,13 +498,13 @@ static int hv_remote_flush_tlb_with_range(struct kvm *kvm, > struct kvm_vmx *kvm_vmx = to_kvm_vmx(kvm); > struct kvm_vcpu *vcpu; > int ret = 0, i; > + bool mismatch; > u64 tmp_eptp; > > spin_lock(&kvm_vmx->ept_pointer_lock); > > - if (kvm_vmx->ept_pointers_match != EPT_POINTERS_MATCH) { > - kvm_vmx->ept_pointers_match = EPT_POINTERS_MATCH; > - kvm_vmx->hv_tlb_eptp = INVALID_PAGE; > + if (!VALID_PAGE(kvm_vmx->hv_tlb_eptp)) { > + mismatch = false; > > kvm_for_each_vcpu(i, vcpu, kvm) { > tmp_eptp = to_vmx(vcpu)->ept_pointer; > @@ -515,12 +515,13 @@ static int hv_remote_flush_tlb_with_range(struct kvm *kvm, > if (!VALID_PAGE(kvm_vmx->hv_tlb_eptp)) > kvm_vmx->hv_tlb_eptp = tmp_eptp; > else > - kvm_vmx->ept_pointers_match > - = EPT_POINTERS_MISMATCH; > + mismatch = true; > > ret |= hv_remote_flush_eptp(tmp_eptp, range); > } > - } else if (VALID_PAGE(kvm_vmx->hv_tlb_eptp)) { > + if (mismatch) > + kvm_vmx->hv_tlb_eptp = INVALID_PAGE; > + } else { > ret = hv_remote_flush_eptp(kvm_vmx->hv_tlb_eptp, range); > } Personally, I find double negations like 'mismatch = false' hard to read :-). What if we write this all like if (!VALID_PAGE(kvm_vmx->hv_tlb_eptp)) { kvm_vmx->hv_tlb_eptp = to_vmx(vcpu0)->ept_pointer; kvm_for_each_vcpu() { tmp_eptp = to_vmx(vcpu)->ept_pointer; if (!VALID_PAGE(tmp_eptp) || tmp_eptp != kvm_vmx->hv_tlb_eptp) kvm_vmx->hv_tlb_eptp = INVALID_PAGE; if (VALID_PAGE(tmp_eptp)) ret |= hv_remote_flush_eptp(tmp_eptp, range); } } else { ret = hv_remote_flush_eptp(kvm_vmx->hv_tlb_eptp, range); } (not tested and I've probably missed something) > > @@ -3042,8 +3043,7 @@ static void vmx_load_mmu_pgd(struct kvm_vcpu *vcpu, unsigned long pgd, > if (kvm_x86_ops.tlb_remote_flush) { > spin_lock(&to_kvm_vmx(kvm)->ept_pointer_lock); > to_vmx(vcpu)->ept_pointer = eptp; > - to_kvm_vmx(kvm)->ept_pointers_match > - = EPT_POINTERS_CHECK; > + to_kvm_vmx(kvm)->hv_tlb_eptp = INVALID_PAGE; > 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 3d557a065c01..e8d7d07b2020 100644 > --- a/arch/x86/kvm/vmx/vmx.h > +++ b/arch/x86/kvm/vmx/vmx.h > @@ -288,12 +288,6 @@ struct vcpu_vmx { > } shadow_msr_intercept; > }; > > -enum ept_pointers_status { > - EPT_POINTERS_CHECK = 0, > - EPT_POINTERS_MATCH = 1, > - EPT_POINTERS_MISMATCH = 2 > -}; > - > struct kvm_vmx { > struct kvm kvm; > > @@ -302,7 +296,6 @@ struct kvm_vmx { > gpa_t ept_identity_map_addr; > > hpa_t hv_tlb_eptp; > - enum ept_pointers_status ept_pointers_match; > spinlock_t ept_pointer_lock; > }; -- Vitaly