Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp559819rwb; Thu, 12 Jan 2023 09:18:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXvEnf5V+AjN7IFKCc5FEjPEZJiu1CO/xFiqvJGwkbhO9OMfi0jum35d7O3r30EVqI8fsKiN X-Received: by 2002:a17:906:ccd2:b0:84d:45ff:d27d with SMTP id ot18-20020a170906ccd200b0084d45ffd27dmr15709507ejb.38.1673543936665; Thu, 12 Jan 2023 09:18:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673543936; cv=none; d=google.com; s=arc-20160816; b=k/cIZFAmYCaRY6zJbB6eOj2BgyhV38BW0eAARKO/sKHcvlVnDCdaDyd/higIw25XDp 6OJdNr8XBLaRSc2l6tEhqmMtFYHl0nyYEJjmS132+uJ9PkDCE5vWGPvsR2f9rRllxRPL UuBdsCKRGR0TLNQmGNHf94Z0cR2bsCHAFTu0pp2rtVjWQgpcyf+xHY7ph3zbzaPzBLZn Xc/7wOh6MyaOn+ro24az+5BQJEMIsc8wQ8G4bjOz+kjKZHa19oik+LBrfbLTVdqVg9xD okyxcwGAGzHhgzOmF6N/ywmj3pDagwe2lxK+OOPUaKQPDtQRqKzithVOn4ogL560gdIV v1WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Il6tG+grFUAFOOvg0KhGTf+EIYxJETeKAbCexl2AFd0=; b=Iow7FHaG+oxhkjhcXSnmJ/VcxPinSMyPqkFCDRKySlV45g1flk2zu5n5DeTMn/xBZB AU9mL8rBQWS/hXKu8XwD2PYmsQe59dQne3yWGrqrCJW+Us/3lpZRoFPfzogrtBTJC2yE oXrXkeBnt+GHHN+n+bG9JkkauqF1Yky1K8chJ24rN0A5nWyMYcqnV98HDqBKtt9nZkxp 2SxPWrM7f9ePaFxmGvpcoa4SIT3mSond/4GsXHScd24THFflWGEpBiQr320H4SIVcesS k5xXEp92dTqW9SMsvpUMM6DCg6op2bKhFr5bl1TP25s9aut3R6UfJIzY1zuysGupwbh3 8vjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DkIUr6kS; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xf9-20020a17090731c900b0084d0b4b4fdbsi19391899ejb.555.2023.01.12.09.18.44; Thu, 12 Jan 2023 09:18:56 -0800 (PST) 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=DkIUr6kS; 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 S240935AbjALQqj (ORCPT + 50 others); Thu, 12 Jan 2023 11:46:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240199AbjALQid (ORCPT ); Thu, 12 Jan 2023 11:38:33 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99D3D1BEA3; Thu, 12 Jan 2023 08:34:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673541243; x=1705077243; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xLEJWQLYzY+JO7Q0MkVG9KzB+lHqhL0n1uYJldM9dOU=; b=DkIUr6kSbZY63AWrPM/4nTStVBjN8rJ3pSLqZ/Y08uqydnMFO8btHWgl u+mTZvC4qxTctWU/H48IeH76xpdDFS/MYkEPZp7dbN4FFhFDpF8NHZ1tj qOHeq/05dNIbpY/G3tJ7IZE9wLqm5YkuLg3Eg5UfVV8Nj1GjcRkrfoI6y g1+dQzIRy3kHhu8yRQ3YyI3L5N+XEBQ9h5hb7Ifeo6HIsxgTawxz/2Y/j XQeSfN9UNGjD0fSKDR2S35cUnEJqx8zgbsE55WPfdZ6xl0VKnKfg7Gq3h Q8/tR0oEBXVXRvVLSUsmWJrDusJErr7b7cxZIybn4OxrZoXJuye0UmS8P g==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="323811870" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="323811870" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:27 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="721151791" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="721151791" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:27 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack Subject: [PATCH v11 045/113] KVM: x86/mmu: Make make_spte() aware of shared GPA for MTRR Date: Thu, 12 Jan 2023 08:31:53 -0800 Message-Id: <5d9a6b899ea9a25a1192efd0ef5e43ecb1a0f250.1673539699.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 From: Isaku Yamahata For TDX MTRR support of shared GPA, get_mt_mask() method needs to know if the given gfn is shared or private. Make make_spte() aware of shared GPA and rename gfn of make_spte() to gfn_including_shared to make it explicit. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/mmu/spte.c | 5 +++-- arch/x86/kvm/mmu/spte.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index a23e9205fc42..7171df3e262a 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -136,13 +136,14 @@ bool spte_has_volatile_bits(u64 spte) bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, const struct kvm_memory_slot *slot, - unsigned int pte_access, gfn_t gfn, kvm_pfn_t pfn, + unsigned int pte_access, gfn_t gfn_including_shared, kvm_pfn_t pfn, u64 old_spte, bool prefetch, bool can_unsync, bool host_writable, u64 *new_spte) { int level = sp->role.level; u64 spte = SPTE_MMU_PRESENT_MASK; bool wrprot = false; + gfn_t gfn = gfn_including_shared & ~kvm_gfn_shared_mask(vcpu->kvm); WARN_ON_ONCE(!pte_access && !shadow_present_mask); @@ -190,7 +191,7 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, spte |= PT_PAGE_SIZE_MASK; if (shadow_memtype_mask) - spte |= static_call(kvm_x86_get_mt_mask)(vcpu, gfn, + spte |= static_call(kvm_x86_get_mt_mask)(vcpu, gfn_including_shared, kvm_is_mmio_pfn(pfn)); if (host_writable) spte |= shadow_host_writable_mask; diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h index 7046671b08cb..067ea1ae3a13 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -481,7 +481,7 @@ bool spte_has_volatile_bits(u64 spte); bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, const struct kvm_memory_slot *slot, - unsigned int pte_access, gfn_t gfn, kvm_pfn_t pfn, + unsigned int pte_access, gfn_t gfn_including_shared, kvm_pfn_t pfn, u64 old_spte, bool prefetch, bool can_unsync, bool host_writable, u64 *new_spte); u64 make_huge_page_split_spte(struct kvm *kvm, u64 huge_spte, -- 2.25.1