From patchwork Tue May 9 13:51:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 91619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2946084vqo; Tue, 9 May 2023 07:54:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ60tc5gvV0hBnIqIoqXvfr1Vh7mwrt0S8JoqF7X7i1teZv/9YE7s4FeQFuLD/PyLb0fjdBP X-Received: by 2002:a17:902:f68a:b0:1ac:788c:872a with SMTP id l10-20020a170902f68a00b001ac788c872amr8941327plg.1.1683644058011; Tue, 09 May 2023 07:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683644057; cv=none; d=google.com; s=arc-20160816; b=x/U9twkNra0p43uzCY2z8yGdI7xhISYg4Fk26zSRIAmKh9Teq0t0Aktgr+wP4C2Y9F 6Qsw6L+WJV1f7k5Q2TgtTn1SX0J7OOBa0E3WmDoyX89qe5QjqZc8xt7J0hz6skBLtP3p SxgLnICFIEgXIWppSlcQRbq4KygfTXCu+SW7g8c0Vv/TyoU1Z/wXfeoG+WgVa+cotsTc 6FRjfkI8YHN7uX5ZKwa0G9RR/X7uL6GkIk3fPZMDIJPuudjxTjwgKxAcCl2KKfNE0Igm G8XPpYrxMRBacfCsSR/zcOyF8ACFcuriAKYRvLlGQJNshQrhRb3yp1rITIxc7CRVNZCJ qnxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=Q9OvZTH6xIkbapW5lUmosSMRbAhSiC/vIvCYG/C7N4Y=; b=NfM4YUhGuV8Oq11864O7dw2KuzpFhFxEj0B20Gwyq6IChZRCN627lFR+0gn15aTItv Li4VdX7VHISCmvS/ROlBJ82scrLdB8mSktfCQKELXQuesJtT3SrF1uC9EowypMTqbZ3B t81NNxbf2YFvjH+HQVqSp5/dMe7pt6B8eYVRL0sdlQRHoPShn1s+GfuztJcpspExww0L rTCxBJlWNpnqSVNUTQUi14uYfizyKgJtugNUnBUGoxTupbK2SwDV3kll/Un0gzghyVOi 3vX9Ck9I7ht3oJ5o4lCs8/aG2FuE3N21L13gUUC3ophTDJaalBbuAtEmf6DTr713U46Q /ChQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DKuL0WsZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c9-20020a170902724900b001ab0216d6b3si1550865pll.652.2023.05.09.07.54.02; Tue, 09 May 2023 07:54:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DKuL0WsZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230088AbjEIOQO (ORCPT + 99 others); Tue, 9 May 2023 10:16:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235296AbjEIOQN (ORCPT ); Tue, 9 May 2023 10:16:13 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FF653580; Tue, 9 May 2023 07:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683641772; x=1715177772; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=0dNyFxF2R8H8nDmO1BfaeIPx4OHrZOLpuoFOx9cABLg=; b=DKuL0WsZAyO7UmgBUucgIO3XP3RYGkdZ4SwioPiX0AeSD7/UmGJjkKI1 Z/ufS5RdlpnLt/ddHe6ksBPkfOYeK05OshSR8V0jLIMeQMESnNfVh41jc PIiRZsVUT+X67ltuT9CZmCS3wqJXx2Lxmwiht+6l79ug9sGXAe7XIBFpK GE6IZXAaNkwNFe4tAbV6b+t4d3nhlIeqvbTNAdW5ggqHqXMFZ2dnBcGtV tS3RedgqgYUsuEDGoxBud5+2phH8U540ICoQJXoxGtsXXsYy2cOmGoBVw 5PqU79Qw+/kSevWjk8Unsutm7wuM3WypL0Zc6Zw81CiFIWGyXBqkFWlcy g==; X-IronPort-AV: E=McAfee;i="6600,9927,10705"; a="349971732" X-IronPort-AV: E=Sophos;i="5.99,262,1677571200"; d="scan'208";a="349971732" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 May 2023 07:16:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10705"; a="945298305" X-IronPort-AV: E=Sophos;i="5.99,262,1677571200"; d="scan'208";a="945298305" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 May 2023 07:16:10 -0700 From: Yan Zhao To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, Yan Zhao Subject: [PATCH v2 2/6] KVM: x86/mmu: only zap EPT when guest CR0_CD changes Date: Tue, 9 May 2023 21:51:10 +0800 Message-Id: <20230509135110.1664-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230509134825.1523-1-yan.y.zhao@intel.com> References: <20230509134825.1523-1-yan.y.zhao@intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765428751805791069?= X-GMAIL-MSGID: =?utf-8?q?1765428751805791069?= Call new helper kvm_zap_gfn_for_memtype() to skip zap mmu if EPT is not enabled. Guest CR0_CD value will affect memory type of EPT leaf entry with noncoherent DMA present. But mmu zap is not necessary if EPT is not enabled. Suggested-by: Chao Gao Signed-off-by: Yan Zhao --- arch/x86/kvm/x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e7f78fe79b32..ed1e3939bd05 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -942,7 +942,7 @@ void kvm_post_set_cr0(struct kvm_vcpu *vcpu, unsigned long old_cr0, unsigned lon if (((cr0 ^ old_cr0) & X86_CR0_CD) && kvm_arch_has_noncoherent_dma(vcpu->kvm) && !kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED)) - kvm_zap_gfn_range(vcpu->kvm, 0, ~0ULL); + kvm_zap_gfn_for_memtype(vcpu->kvm, gpa_to_gfn(0), gpa_to_gfn(~0ULL)); } EXPORT_SYMBOL_GPL(kvm_post_set_cr0);