Message ID | 20230616023524.7203-1-yan.y.zhao@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1059436vqr; Thu, 15 Jun 2023 20:15:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4H3WId8jlru+GMVgkfXdw/6YpgvXbOJL2H2S1dVoZv2IbSW0uAJzu/eD1RyApOJqdPjIuZ X-Received: by 2002:a17:902:ce92:b0:1b1:82a6:7c82 with SMTP id f18-20020a170902ce9200b001b182a67c82mr822958plg.27.1686885354751; Thu, 15 Jun 2023 20:15:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686885354; cv=none; d=google.com; s=arc-20160816; b=DDo+5NOMlDBuhkGSS0T3wq//ZdOAwQkLSaiJ9mzkgZqgYzwMoYK86kyNhL9w8oVCc4 ILZgaSjBbj7gCtsefXBntQ48ZmPXdpQ4Hgu3kH2eKhKPw9Cnz2loIQh0OzmRlRPAq9xP VoktPLvC/uXQusDTTYTmmS4OaHU1RyIZCr8KcH4HhPspDFoi/G5Lm6dMjfk8iVtkKMiv Hy1IJ0ck+r4tulZKcMD2Knh+uzaQdi832+VKvu0hDW0K+mFp/G5P1ztdXMQ/ZK8TLpCy vLhKI7aGmSswDbGWO9y1dePS9URJAJz+kS134RZ8Qon0Qhvoeyr+HLbIpq4Kt+0dU9l4 N8/A== 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=l6BLSNXxImieQZF7frj1KA4k5f6r5cDWwlyJuRMctXI=; b=vZxJDeDig+xVSzAqvimjOyhgOdedgMCAzBBMu1Pjkj59o6GOEcPdYFW1Wc+91Oz1jl ASGl4+qrZOIg+rIkfKhWsAco1tkTCGJPjnX9UC45G4gXWdAVcWzL+jaG7CfLdbyQ2PjZ kmlrXuKzo1gHY/IDC0OkMhYOMRLz//v1CD9ykr2ZOUh//yQGcetWcDcgHs2fmGcXzxM/ OFaXm5ZwvjCHiKZHVm6Le/zsXqYBAdjkMvCvIL0L1MMAHQk0+RelMJa/rw3vKFl0vdWN Udyo/tH+e+NphUwtWTot7TLCNQe12g8n1ynU3hDgxLjRYKzORXgsUmJBrhNIJV1T1sVP PHYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="M41zP/Ec"; 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 f5-20020a170902ce8500b001a6e98a5f21si9280535plg.586.2023.06.15.20.15.39; Thu, 15 Jun 2023 20:15:54 -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="M41zP/Ec"; 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 S241354AbjFPDBN (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Thu, 15 Jun 2023 23:01:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241279AbjFPDBH (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 15 Jun 2023 23:01:07 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B30B32D57; Thu, 15 Jun 2023 20:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686884457; x=1718420457; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=fDH9F5ik6wgWY9hy79+dGA7B1WWmfkgvQ9/kTzs5dJw=; b=M41zP/EcGdC1LY0p8tdEJLrlcBz8q2oN1r1awh4D0Oue60KXHJgH4yBS V9i++zVBKRasHTcMSGh72nReqELBLnVLt4nK3bahxkA0xFiik75hY/cAS Lp7JZU274sN/MfvbHm2SVLWTRzjHvz/lfIcpI05S48tIVblAeKfFB97Ew whsD/sQQcFpIt9DNq+V7FBvBZxDMsq9VdM6JKrNSvG/FvLRsCLacZzo4R ZyPTy3I83wpQtbgBf4yoFXHj8JwsqNATg6lGPHRzkzdWRk9SWxUoV5qKK TTIkaa/DVK5SZcaKpBTwGlxYtaJIrT6CYCRPqpvTKr8gFKzYrVw9LUNBL Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="425031714" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="425031714" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 20:00:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="706914642" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="706914642" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 20:00:33 -0700 From: Yan Zhao <yan.y.zhao@intel.com> To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, chao.gao@intel.com, kai.huang@intel.com, robert.hoo.linux@gmail.com, Yan Zhao <yan.y.zhao@intel.com> Subject: [PATCH v3 03/11] KVM: x86/mmu: Use KVM honors guest MTRRs helper when CR0.CD toggles Date: Fri, 16 Jun 2023 10:35:24 +0800 Message-Id: <20230616023524.7203-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230616023101.7019-1-yan.y.zhao@intel.com> References: <20230616023101.7019-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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768827497656672613?= X-GMAIL-MSGID: =?utf-8?q?1768827497656672613?= |
Series |
KVM: x86/mmu: refine memtype related mmu zap
|
|
Commit Message
Yan Zhao
June 16, 2023, 2:35 a.m. UTC
Call helper to check if guest MTRRs are honored by KVM MMU before zapping,
as values of guest CR0.CD will only affect memory types of KVM TDP when
guest MTRRs are honored.
Suggested-by: Chao Gao <chao.gao@intel.com>
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
---
arch/x86/kvm/x86.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri, Jun 16, 2023, Yan Zhao wrote: > Call helper to check if guest MTRRs are honored by KVM MMU before zapping, Nit, state the effect, not what the code literally does. The important part is that the end result is that KVM will zap if and only if guest MTRRs are being honored, e.g. Zap SPTEs when CR0.CD is toggled if and only if KVM's MMU is honoring guest MTRRs, which is the only time that KVM incorporates the guest's CR0.CD into the final memtype. > as values of guest CR0.CD will only affect memory types of KVM TDP when > guest MTRRs are honored. > > Suggested-by: Chao Gao <chao.gao@intel.com> > Signed-off-by: Yan Zhao <yan.y.zhao@intel.com> > --- > 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 9e7186864542..6693daeb5686 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 > kvm_mmu_reset_context(vcpu); > > if (((cr0 ^ old_cr0) & X86_CR0_CD) && > - kvm_arch_has_noncoherent_dma(vcpu->kvm) && > + kvm_mmu_honors_guest_mtrrs(vcpu->kvm) && > !kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED)) > kvm_zap_gfn_range(vcpu->kvm, 0, ~0ULL); > } > -- > 2.17.1 >
On Wed, Jun 28, 2023 at 02:59:00PM -0700, Sean Christopherson wrote: > On Fri, Jun 16, 2023, Yan Zhao wrote: > > Call helper to check if guest MTRRs are honored by KVM MMU before zapping, > > Nit, state the effect, not what the code literally does. The important part is > that the end result is that KVM will zap if and only if guest MTRRs are being > honored, e.g. > > Zap SPTEs when CR0.CD is toggled if and only if KVM's MMU is honoring > guest MTRRs, which is the only time that KVM incorporates the guest's > CR0.CD into the final memtype. > Thanks! Will update it.
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 9e7186864542..6693daeb5686 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 kvm_mmu_reset_context(vcpu); if (((cr0 ^ old_cr0) & X86_CR0_CD) && - kvm_arch_has_noncoherent_dma(vcpu->kvm) && + kvm_mmu_honors_guest_mtrrs(vcpu->kvm) && !kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED)) kvm_zap_gfn_range(vcpu->kvm, 0, ~0ULL); }