Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4993211pxb; Thu, 14 Oct 2021 16:37:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwM1DWe233/HjzteXBq8z2dyYQ3qj3Lq2P8MbJQyhNJ+EJgwVXUCvN8IPTI+jErZ8/C6TW X-Received: by 2002:a63:b21a:: with SMTP id x26mr2474139pge.418.1634254665756; Thu, 14 Oct 2021 16:37:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634254665; cv=none; d=google.com; s=arc-20160816; b=zGN3QboaZB3T0y2jMmWjbZZIYRVY88AOMnO6i9QGdoqS1JIOgK3zcZwLh1Wpas1CSg HRuaDuLHF5oDrUBn3hQVWGcv8vOY//yhZ0f5UmkMyv2fM3Mh4azgF0rIeqx/0ZQZ5Vk8 ldMdNmuj5OCpCuRw5KyfBJNSK/gwQWL1ABDY32ccfzqMAEG5mCPnYAXdCFk7cEPmUoCd W6qgvRMMUUAroQnXpYSDTE+XwiqhTlsId/ZxhnLRR89LA2l78AZlsj0tEKsKnbom/W8u 33sTYvpT+5n3/mIgEfyCjsBzxvRA7EFXT53COHHZpRaT2AwyU0UIBorsYnn0caTI83CD ZHJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZjimbiTSlE1l8ItQSDOS0TpKsqXd9vrfIa7epPZdvVk=; b=d3BBH+B97UXH7ArEz7iU3Hv1sMAqIRXgY5VzCeoi2TYD6k4r3cUyGNGiRAHgRNrVtD WPsIkKo72yrURoitCIpDmY4i4U7RJhuYz028pLiNsYNsMIl3lD2MQ7cAiLBV4C7OJur2 BPX1daxVHAKv7ngGY2IhHmlofhvKzxkJ2FUK+IYLeFMkGw7jk3paFPXlqal3U3cxRHMD Cj6ZkkFE+TrXLZ4Gq+q2C4Puh7Sw7rOFXD+vZTTYm7a2YN9xVbTO85ou1HhBI5kBbBx9 ttsgwLPXXJAV1TW77n+KTbDlb6+QbeWlxiEdYx+mUhbz+Gy3ygRLPRQIc8kQq3/PNBt+ 5p+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PBwp4PoA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g35si6038044pgl.237.2021.10.14.16.37.32; Thu, 14 Oct 2021 16:37:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PBwp4PoA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233188AbhJNSuv (ORCPT + 99 others); Thu, 14 Oct 2021 14:50:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232902AbhJNSuu (ORCPT ); Thu, 14 Oct 2021 14:50:50 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75D67C061570 for ; Thu, 14 Oct 2021 11:48:45 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id oa12-20020a17090b1bcc00b0019f715462a8so5436142pjb.3 for ; Thu, 14 Oct 2021 11:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ZjimbiTSlE1l8ItQSDOS0TpKsqXd9vrfIa7epPZdvVk=; b=PBwp4PoA1EnlQv0jUTHwWnlic0D6ATh3iQtz91bHBcHPDgSModSG7bGRhyFyA0EsXv 9nTSHsJC4+B/AxTSVK6HeC5Jzsywe7PQ6pON8oaNTCJCEXkJ0mCQez5O3Rspw+E6IICK AqYWJIDJyxSw8SFvRiEG4yHlWlZGXbwuDVOvXkLrXGB3HlET5hq62aa3iHOhn4uoXNiE +H6Y5WiXRfIs1iANYgEW14fpdqhwzNab+ZWeKWh8t9Xi1kwD/BuWs7nvTkLGBP/39vO+ 0t0YHkM+YT/wmIZWt6VKnEMk4v90Kj6C4MguqirpsFwoy3GzKCjg18beIrA/u1wc3lYr QpSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ZjimbiTSlE1l8ItQSDOS0TpKsqXd9vrfIa7epPZdvVk=; b=P4AJEI7o6ndzLWU5O4FdCrU/jPH2fWsy3MfahnWZXb+dNLDRfka/h2w6EIAaDXOS4T lzNuRFIsIOSasvCgAvxTX0OntrqmZAizXH4aYceAJay8dZXKTIR7hBjTeXgfXqkHYTqB /npnVIeSJHtoW5DI/HM5vVzIsECfGfc2o6pfdD5xsYVWIVEAqZxDM543mfIIWru8jamO bDoQ0bFjLhK+dC1Exx+vc7RVdwhsi7ByGIhm/GasEowFfcJ0KQH8S3RTN9mgLR00iFXk TwzOl5fBT5HexRdHROcF0q5lK/DljlY3eRvsWqXhuf/d8zsOztb2J48Y5OJ2ph+J7vuf d0WA== X-Gm-Message-State: AOAM531nlxD4yqFgr+g9nRGjg6qX4NZXo6BStJOfdXqq1uD5vMVsJ6gV 0pHb9J5ldRx3gfZ1RrPEfFDZUQ== X-Received: by 2002:a17:902:bb81:b0:12d:a7ec:3d85 with SMTP id m1-20020a170902bb8100b0012da7ec3d85mr6655532pls.17.1634237324850; Thu, 14 Oct 2021 11:48:44 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id y142sm3133125pfc.169.2021.10.14.11.48.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Oct 2021 11:48:44 -0700 (PDT) Date: Thu, 14 Oct 2021 18:48:40 +0000 From: Sean Christopherson To: Lai Jiangshan Cc: linux-kernel@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov , kvm@vger.kernel.org, Lai Jiangshan , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Subject: Re: [PATCH 1/2] KVM: X86: Don't reset mmu context when X86_CR4_PCIDE 1->0 Message-ID: References: <20210919024246.89230-1-jiangshanlai@gmail.com> <20210919024246.89230-2-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 14, 2021, Sean Christopherson wrote: > On Sun, Sep 19, 2021, Lai Jiangshan wrote: > > From: Lai Jiangshan > > > > X86_CR4_PCIDE doesn't participate in kvm_mmu_role, so the mmu context > > doesn't need to be reset. It is only required to flush all the guest > > tlb. > > > > Signed-off-by: Lai Jiangshan > > --- > > arch/x86/kvm/x86.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 86539c1686fa..7494ea0e7922 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -116,6 +116,7 @@ static void enter_smm(struct kvm_vcpu *vcpu); > > static void __kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags); > > static void store_regs(struct kvm_vcpu *vcpu); > > static int sync_regs(struct kvm_vcpu *vcpu); > > +static void kvm_vcpu_flush_tlb_guest(struct kvm_vcpu *vcpu); > > > > static int __set_sregs2(struct kvm_vcpu *vcpu, struct kvm_sregs2 *sregs2); > > static void __get_sregs2(struct kvm_vcpu *vcpu, struct kvm_sregs2 *sregs2); > > @@ -1042,9 +1043,10 @@ EXPORT_SYMBOL_GPL(kvm_is_valid_cr4); > > > > void kvm_post_set_cr4(struct kvm_vcpu *vcpu, unsigned long old_cr4, unsigned long cr4) > > { > > - if (((cr4 ^ old_cr4) & KVM_MMU_CR4_ROLE_BITS) || > > - (!(cr4 & X86_CR4_PCIDE) && (old_cr4 & X86_CR4_PCIDE))) > > + if ((cr4 ^ old_cr4) & KVM_MMU_CR4_ROLE_BITS) > > kvm_mmu_reset_context(vcpu); > > + else if (!(cr4 & X86_CR4_PCIDE) && (old_cr4 & X86_CR4_PCIDE)) > > + kvm_vcpu_flush_tlb_guest(vcpu); > > Unless there's a corner case I'm missing, I would prefer this to use > kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu) instead of calling > kvm_vcpu_flush_tlb_guest() directly. The odds of flushes actually being batched > is low, it's more to document that kvm_post_set_cr4() _isn't_ special. Forgot to say, with the change to KVM_REQ_TLB_FLUSH_GUEST: Reviewed-by: Sean Christopherson