Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp61322lqh; Thu, 30 May 2024 14:08:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV1WEPd5s92FuW/tUOHecImTvYad2aqFmMF3+6Y7PEUv2iV/BJH6Wq5Zov7cSa0a+gzE1M034hb9O/ECYd7iARfLYf411h9/u83QIzuAg== X-Google-Smtp-Source: AGHT+IHwZjZyfmpTNtyGu6o80BD71JFXZHI75LIA3TJTIzRSivfLXHhbMHlj/Et5UTAAfywBjEjI X-Received: by 2002:a50:c356:0:b0:572:3b15:a40 with SMTP id 4fb4d7f45d1cf-57a3644f501mr38645a12.33.1717103317196; Thu, 30 May 2024 14:08:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717103317; cv=pass; d=google.com; s=arc-20160816; b=YZk+UH3hustd/0cL2bWFrP4x5uVThisuKfCpqdDCNFfGqVm/gcm6tsBG/OwiPdUgSi koxpYqZqtrVXOsigSWZBZ00UTTCzdnzgmqVoHzjrHpdyiBQ7YiQXzfWbxjgi/7F9hd+S vuX1GUrdH4+zYoUrDH/LojLCoJRLldSw24QeHPg+2OrZHSUcdrFr8EbAisQPWTw/NkoX DTWEsWrUJtasmD0nHBBnS1wP7JFZwOYG+wSlDjTOBkMY7nkqKTgKbYxRuKqTJwp9vkDp 5jSatk3x8KR7MdOo/IlX9v4CfPGU1LEFmzMDpXRwkGEmn+PvRPkA4/yttWxaCAQJZImT E7UQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DjtHuPSlsOJTzeFni3T9kQ6RbEx1v4R/EVdv1b+t6VY=; fh=C3/gu8bExeFKVYscWM1Y2m4wOjqguKKgJLN7mvKJHu8=; b=I/BZCxvN+8bhmq9iG0Axjcc+4wq71OSrtWwJM+abX50/4LD+eCkqcAMdeHH6FZn7HI hI+roLlqTG/nts3Gpe0DZQYkZKWMbGyzUyLVrD50zIFZrIq04/qkj4sW/xkGMypXT9J7 8OgWHfIKB+9vXHiN3Zz5H4GDuN7F3O6iyX8NkolP+BLvxnjGJk7vfwn0mofuTk8QZ1v0 kykKKGZUg2Aza0Y8CmyDEURKjmRwIBmQlubbVfqXJVAp7tHVHk0e7VBCWTn6RBSE0oco aQBkAHsejZblx/cC/+8qNBHVNK8Tu6p4DW95IvprfaolLe+C3IqzD4MQhqCyNg9rJFR8 G2BQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kfAzZenM; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-195907-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195907-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a31c92cc0si195323a12.478.2024.05.30.14.08.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 14:08:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195907-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kfAzZenM; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-195907-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195907-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AEAA61F21808 for ; Thu, 30 May 2024 21:08:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C85B186283; Thu, 30 May 2024 21:07:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kfAzZenM" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3291D17F4E0; Thu, 30 May 2024 21:07:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717103255; cv=none; b=rAxQbwyczOhI0J8sxyx3MUqYXO+SDfftbALWMDMcqQ3RVfaq/7ZJ8hWxyv1RnSS1Fdz58xHuT+pCw78CH5TuEuQfnjSme14TH2qPO1nYG1GGEw8TzALMs729LWpoqui3yPnZm3iPdXY9broXnjR4TnK2gKwgL6dFba6JTN4NC9s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717103255; c=relaxed/simple; bh=obPtbUnxNt43x6reWoyb4ohHWGS9ansaXpugJHDkDqY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ed4jS4V1w2h593NEZoTkoJfVWxubUh/30zL5Th0urg1M+yC8P2Q/60gwtifUfvE/w8RztBZslfiClpyLdGCUCueJqEnT3Fqm9MLspHPyfqUsJY8p23PJ0TH7F4yuTetwVl/0CzyNNFyzGr2Kq0rH2yJT0UJ4z3a/gWrT8PXkLrk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=kfAzZenM; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717103254; x=1748639254; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=obPtbUnxNt43x6reWoyb4ohHWGS9ansaXpugJHDkDqY=; b=kfAzZenMtpkhlQnG2rI5MyRiwRHQzjAtcHjlr3NFbfxtIiME7nc8I59Y Qh/g/1696cf4BEw0RB1/2ss35KeooOZNdvQ1MbxNk65X3ki6PzP1CwbAM dlY6SOQl6qQtNQVTLJ/ZPGI4n/b2yK5aIFFSEr+H9TRmsLYKcLX6KN0VJ jsh6wDMmU5nPOXgEo+niIxbs4Vt58HxiEROh3YBK30kdrzwCtpO+5s8H8 7nlbuo+8hvlWW9XOrA96qDuxAIf50j25rkJlsX4WMBt64boY/uRUdlhw9 wmyuWzKhsJ9CgiRzPY0ezUWOXwJxyO3UPR84vv9d1WLiRtSGs8LDDja2r Q==; X-CSE-ConnectionGUID: qzBwBnHlQuetOKnlQR+qbA== X-CSE-MsgGUID: mj5usqbaQZCFGbb56Cf2aw== X-IronPort-AV: E=McAfee;i="6600,9927,11088"; a="31117094" X-IronPort-AV: E=Sophos;i="6.08,202,1712646000"; d="scan'208";a="31117094" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2024 14:07:32 -0700 X-CSE-ConnectionGUID: DN1ieylEQouHbUW1/aHpJQ== X-CSE-MsgGUID: SyoSlZ7RRRa8+7po4Vh8KQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,202,1712646000"; d="scan'208";a="35874416" Received: from hding1-mobl.ccr.corp.intel.com (HELO rpedgeco-desk4.intel.com) ([10.209.19.65]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2024 14:07:32 -0700 From: Rick Edgecombe To: seanjc@google.com, pbonzini@redhat.com, kvm@vger.kernel.org Cc: kai.huang@intel.com, dmatlack@google.com, erdemaktas@google.com, isaku.yamahata@gmail.com, linux-kernel@vger.kernel.org, sagis@google.com, yan.y.zhao@intel.com, rick.p.edgecombe@intel.com, Isaku Yamahata Subject: [PATCH v2 04/15] KVM: x86/mmu: Add a new mirror_pt member for union kvm_mmu_page_role Date: Thu, 30 May 2024 14:07:03 -0700 Message-Id: <20240530210714.364118-5-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240530210714.364118-1-rick.p.edgecombe@intel.com> References: <20240530210714.364118-1-rick.p.edgecombe@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Isaku Yamahata Introduce a "mirror_pt" member to the kvm_mmu_page_role union to identify SPTEs associated with the mirrored EPT. The TDX module maintains the private half of the EPT mapped in the TD in its protected memory. KVM keeps a copy of the private GPAs in a mirrored EPT tree within host memory. This "mirror_pt" attribute enables vCPUs to find and get the root page of mirrored EPT from the MMU root list for a guest TD. This also allows KVM MMU code to detect changes in mirrored EPT according to the "mirror_pt" mmu page role and propagate the changes to the private EPT managed by TDX module. Signed-off-by: Isaku Yamahata Signed-off-by: Rick Edgecombe --- TDX MMU Prep v2: - Rename private -> mirrored TDX MMU Prep: - Remove warning and NULL check in is_private_sptep() (Rick) - Update commit log (Yan) v19: - Fix is_private_sptep() when NULL case. - drop CONFIG_KVM_MMU_PRIVATE --- arch/x86/include/asm/kvm_host.h | 13 ++++++++++++- arch/x86/kvm/mmu/mmu_internal.h | 5 +++++ arch/x86/kvm/mmu/spte.h | 5 +++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 250899a0239b..084f4708aff1 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -351,7 +351,8 @@ union kvm_mmu_page_role { unsigned ad_disabled:1; unsigned guest_mode:1; unsigned passthrough:1; - unsigned :5; + unsigned mirror_pt:1; + unsigned :4; /* * This is left at the top of the word so that @@ -363,6 +364,16 @@ union kvm_mmu_page_role { }; }; +static inline bool kvm_mmu_page_role_is_mirror(union kvm_mmu_page_role role) +{ + return !!role.mirror_pt; +} + +static inline void kvm_mmu_page_role_set_mirrored(union kvm_mmu_page_role *role) +{ + role->mirror_pt = 1; +} + /* * kvm_mmu_extended_role complements kvm_mmu_page_role, tracking properties * relevant to the current MMU configuration. When loading CR0, CR4, or EFER, diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index faef40a561f9..6d82e389cd65 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -157,6 +157,11 @@ static inline int kvm_mmu_page_as_id(struct kvm_mmu_page *sp) return kvm_mmu_role_as_id(sp->role); } +static inline bool is_mirror_sp(const struct kvm_mmu_page *sp) +{ + return kvm_mmu_page_role_is_mirror(sp->role); +} + static inline void *kvm_mmu_mirrored_spt(struct kvm_mmu_page *sp) { return sp->mirrored_spt; diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h index 5dd5405fa07a..b3c065280ba1 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -265,6 +265,11 @@ static inline struct kvm_mmu_page *root_to_sp(hpa_t root) return spte_to_child_sp(root); } +static inline bool is_mirror_sptep(u64 *sptep) +{ + return is_mirror_sp(sptep_to_sp(sptep)); +} + static inline bool is_mmio_spte(struct kvm *kvm, u64 spte) { return (spte & shadow_mmio_mask) == kvm->arch.shadow_mmio_value && -- 2.34.1