From patchwork Fri Jun 16 02:34:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 108814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1077588vqr; Thu, 15 Jun 2023 21:13:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ67waVqHCu7a8FvaSB8EjXLTe4OynpHY/L22Fa1ZkxmScmUFGmIGpgDeIbEB2UMMOvKTS8q X-Received: by 2002:a17:902:d489:b0:1b0:113e:1047 with SMTP id c9-20020a170902d48900b001b0113e1047mr752263plg.62.1686888782452; Thu, 15 Jun 2023 21:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686888782; cv=none; d=google.com; s=arc-20160816; b=zbA7EHyQoYODMu7N+U3QdZzj7eHHbrNqf4XlIIY7J1jpBOWdi1kvkQ6r3Y3nSy5hpG nAxK86RDM6GldroPtVdpIeeJ9Fl8AzvQbLipGSOqz83h9Ro66r3WyRV9vb0UkMDdXjJf lVbF/oJw37xcgktqhXjNV/UqhuMOEsJNBzYcz/8XzKD8NHak9USbLj1Wkb7ySO5FaQfr kVyaKBKoQ5+NPvMr+H0WkHIemiDgOKfbs3UBdHOP8QE6lRKFZJpyyjx5JR2L0YR/H/vC C7nb5yISOwtw3xaaFnY8SSSnainQizto4Yu7lzH1JBBZotREh8qvcbxIyYWvyycOqHF2 4v/Q== 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=U6ZrHyKCEoL2hYaOj4OX6561KOcphkx90hTStb8bNEY=; b=vVPEXd/EiImrNUCSYUnSNXyZ7hucH0TCN5EaCwU6vkXWtuP4QjPCkgdHCKdC+/kxCO S1BItvLzjvj6YIdKa4TJmt2rS3R/5me0SnX5ojzhVvPBP7OkGBDv9ghd3AHB8vyvcH2s 0pelFR25N4uDMTT0pyFUJKH7HsQUKwhiDwKkGDhDIyIWR7gZL6BSr5TzPysSVkwZp//j nfe3ucLVgyrJRAkZQt6zjgmWn/t115bTpK1w4L2B17OEqbN3xSRjG/tslhC4XjpvyNwp R2AYjlZjURnfgdYLJSNPn5hoC9H18FoglNpx/8+xhk7MRZ5bT2g8ANU/gCgv5QG2n7HU aNgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=D7u16eJR; 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 k2-20020a170902d58200b001b041114a62si10525765plh.355.2023.06.15.21.12.37; Thu, 15 Jun 2023 21:13:02 -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=D7u16eJR; 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 S241268AbjFPDAO (ORCPT + 99 others); Thu, 15 Jun 2023 23:00:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbjFPC7s (ORCPT ); Thu, 15 Jun 2023 22:59:48 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D16D2953; Thu, 15 Jun 2023 19:59:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686884388; x=1718420388; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=nOdi2KVC4OwTsVt3a1I9Bdhj8qUZvzNWXLp63uGaNfw=; b=D7u16eJR0Pi7k+mPyq5IjSsihPjvex7ZG8JibahMQZsI7pzJpXeSpko3 bGUFtVdrUYhD6TkeFQS+wcVhJN/UAXwQGC5bIyX9gzI2vCKKgUXRkEoZa F9Ftez1U2h+wXRXLnvNZgL+V0ZZlv6hO+8IhpKuJqOu/0HVhbx62ummYL Hv0/s+HMSmfZ8e2LDvN6ggz77t+0TFzocepskCq0RC3efyHBtdk2yMlea 1zepPptz0WJwnVb62AIVvuN56hxejbhR6PM7ZVg0jOdS4R2lkcytckA0b ry5VGvH0qTEHtA89HkGOb2L5wGEqs3WRPhKviy+POL/pS4A+eC4weeI/b g==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="359104326" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="359104326" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 19:59:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="690036199" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="690036199" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 19:59:45 -0700 From: Yan Zhao 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 Subject: [PATCH v3 02/11] KVM: x86/mmu: Use KVM honors guest MTRRs helper in kvm_tdp_page_fault() Date: Fri, 16 Jun 2023 10:34:35 +0800 Message-Id: <20230616023435.7142-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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768831091907581056?= X-GMAIL-MSGID: =?utf-8?q?1768831091907581056?= Let kvm_tdp_page_fault() use helper function kvm_mmu_honors_guest_mtrrs() to decide if it needs to consult guest MTRR to check GFN range consistency. No functional change intended. Suggested-by: Sean Christopherson Signed-off-by: Yan Zhao --- arch/x86/kvm/mmu/mmu.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index b4f89f015c37..7f52bbe013b3 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4536,16 +4536,9 @@ int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) /* * If the guest's MTRRs may be used to compute the "real" memtype, * restrict the mapping level to ensure KVM uses a consistent memtype - * across the entire mapping. If the host MTRRs are ignored by TDP - * (shadow_memtype_mask is non-zero), and the VM has non-coherent DMA - * (DMA doesn't snoop CPU caches), KVM's ABI is to honor the memtype - * from the guest's MTRRs so that guest accesses to memory that is - * DMA'd aren't cached against the guest's wishes. - * - * Note, KVM may still ultimately ignore guest MTRRs for certain PFNs, - * e.g. KVM will force UC memtype for host MMIO. + * across the entire mapping. */ - if (shadow_memtype_mask && kvm_arch_has_noncoherent_dma(vcpu->kvm)) { + if (kvm_mmu_honors_guest_mtrrs(vcpu->kvm)) { for ( ; fault->max_level > PG_LEVEL_4K; --fault->max_level) { int page_num = KVM_PAGES_PER_HPAGE(fault->max_level); gfn_t base = gfn_round_for_level(fault->gfn,