Linux Confidential Computing Development
 help / color / mirror / Atom feed
From: Peter Fang <peter.fang@intel.com>
To: Dave Hansen <dave.hansen@linux.intel.com>,
	Kiryl Shutsemau <kas@kernel.org>,
	Rick Edgecombe <rick.p.edgecombe@intel.com>,
	"Sean Christopherson" <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>, <x86@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>, <linux-kernel@vger.kernel.org>,
	<linux-coco@lists.linux.dev>, <kvm@vger.kernel.org>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Jason Gunthorpe <jgg@nvidia.com>,
	Tony Lindgren <tony.lindgren@linux.intel.com>,
	Chao Gao <chao.gao@intel.com>, Xiaoyao Li <xiaoyao.li@intel.com>,
	Binbin Wu <binbin.wu@linux.intel.com>,
	Sohil Mehta <sohil.mehta@intel.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	"Kishen Maloor" <kishen.maloor@intel.com>,
	Nikolay Borisov <nik.borisov@suse.com>,
	Elena Reshetova <elena.reshetova@intel.com>,
	Peter Fang <peter.fang@intel.com>
Subject: [PATCH v3 1/8] x86/virt/tdx: Add interface to generate a Quote
Date: Fri,  4 Dec 2026 10:18:22 -0800	[thread overview]
Message-ID: <20261204182022.324230-2-peter.fang@intel.com> (raw)
In-Reply-To: <20261204182022.324230-1-peter.fang@intel.com>

During TDX attestation, the TDX guest asks the host for a signed,
verifiable report (a "Quote"). With the quoting extension, the TDX
module generates the Quote and returns it in host pages.

Provide an interface for it. The SEAMCALL (TDH.QUOTE.GET) takes the host
pages in a custom linked list format. Each node is a page-sized array
holding the physical addresses of these pages. The last entry in a node
is the 'next' pointer. See [1] for details.

Each Quote request needs its own session in the TDX module. Only a
limited number of sessions are available. Let KVM manage the sessions by
assigning a session ID and a Quote buffer to each request. This avoids
resource sharing between these requests.

[1] Intel TDX Module ABI specification, Section "Physical Memory
    Management Types"

Signed-off-by: Peter Fang <peter.fang@intel.com>
---
v3:
 - Redesign the interface. Drop the global Quote buffer and its mutex,
   and let KVM pass in the Quote buffer pages. [Sean, Dave, Rick, Tony]
 - Use kmalloc() for the linked list nodes, plus cleanups. [Nikolay]
 - Take a session ID so KVM can generate Quotes concurrently.
 - Drop DEFAULT_QUOTE_ID and use [63:32] = 0 for the default quote type.
---
 arch/x86/include/asm/tdx.h  |  4 ++
 arch/x86/virt/vmx/tdx/tdx.c | 96 +++++++++++++++++++++++++++++++++++++
 arch/x86/virt/vmx/tdx/tdx.h |  1 +
 3 files changed, 101 insertions(+)

diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
index 89e7628796b00..22946d910a6f2 100644
--- a/arch/x86/include/asm/tdx.h
+++ b/arch/x86/include/asm/tdx.h
@@ -202,6 +202,10 @@ u64 tdh_mem_page_remove(struct tdx_td *td, u64 gpa, enum pg_level level, u64 *ex
 u64 tdh_phymem_cache_wb(bool resume);
 u64 tdh_phymem_page_wbinvd_tdr(struct tdx_td *td);
 u64 tdh_phymem_page_wbinvd_hkid(u64 hkid, kvm_pfn_t pfn);
+int tdx_quote_generate(struct tdx_td *td, u16 session_id,
+		       struct page *report_page, u64 report_size,
+		       struct page **quote_pages, u64 quote_buf_size,
+		       u64 *quote_size, u64 *seamcall_err);
 #else
 static inline void tdx_init(void) { }
 static inline u32 tdx_get_nr_guest_keyids(void) { return 0; }
diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index dbe17a136dced..39f280190b73d 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -2529,6 +2529,102 @@ void tdx_free_control_page(struct page *page)
 }
 EXPORT_SYMBOL_FOR_KVM(tdx_free_control_page);
 
+static u64 tdx_quote_get(struct tdx_td *td, u16 session_id,
+			 struct page *report_page, u64 report_size,
+			 u64 *quote_hpa_list, u64 quote_buf_size,
+			 u64 *quote_size)
+{
+	struct tdx_module_args args = {
+		.rcx = tdx_tdr_pa(td),
+		/* RDX[63:32] == 0 means the TDX module picks the quote type. */
+		.rdx = session_id,
+		.r8 = page_to_phys(report_page),
+		.r9 = report_size,
+		.r10 = __pa(quote_hpa_list),
+		.r11 = quote_buf_size,
+	};
+	u64 r;
+
+	do {
+		r = seamcall_ret(TDH_QUOTE_GET, &args);
+	} while (r == TDX_INTERRUPTED_RESUMABLE);
+
+	*quote_size = args.rcx;
+
+	return r;
+}
+
+#define HPAS_PER_NODE			(PAGE_SIZE / sizeof(u64))
+
+/*
+ * Convert a local report to a remotely verifiable quote. The caller
+ * allocates a free session ID.
+ *
+ * Returns 0 on success, -ENOMEM on allocation failure, or -EIO if the
+ * SEAMCALL fails, with the TDX module's error code in seamcall_err.
+ */
+int tdx_quote_generate(struct tdx_td *td, u16 session_id,
+		       struct page *report_page, u64 report_size,
+		       struct page **quote_pages, u64 quote_buf_size,
+		       u64 *quote_size, u64 *seamcall_err)
+{
+	int num_quote_pages, num_nodes, ret = 0;
+	u64 *node_head, *node_entry;
+	u64 r;
+
+	/*
+	 * Pass the quote buffer to the TDX module as an HPA linked list. Each
+	 * node holds 4KB page HPAs and the last entry points to the next node.
+	 */
+	node_head = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!node_head)
+		return -ENOMEM;
+
+	node_entry = node_head;
+	num_quote_pages = PFN_UP(quote_buf_size);
+	num_nodes = 1;
+
+	/* Populate the linked list. Allocate new nodes as needed. */
+	for (int i = 0, pages = 0; pages < num_quote_pages;
+	     i = (i + 1) % HPAS_PER_NODE) {
+		if (i == HPAS_PER_NODE - 1) {
+			u64 *new_node = kmalloc(PAGE_SIZE, GFP_KERNEL);
+
+			if (!new_node) {
+				ret = -ENOMEM;
+				goto out_free_nodes;
+			}
+
+			/* Write the 'next' pointer. */
+			node_entry[i] = __pa(new_node);
+			node_entry = new_node;
+			num_nodes++;
+			continue;
+		}
+
+		node_entry[i] = page_to_phys(quote_pages[pages]);
+		pages++;
+	}
+
+	r = tdx_quote_get(td, session_id, report_page, report_size, node_head,
+			  quote_buf_size, quote_size);
+
+	*seamcall_err = r;
+
+	if (r != TDX_SUCCESS)
+		ret = -EIO;
+
+out_free_nodes:
+	for (int i = 0; i < num_nodes; i++) {
+		node_entry = node_head;
+		node_head = __va(node_head[HPAS_PER_NODE - 1]);
+		kfree(node_entry);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_FOR_KVM(tdx_quote_generate);
+
 void tdx_sys_disable(void)
 {
 	struct tdx_module_args args = {};
diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h
index cac0a5abbff1d..612ad84968c33 100644
--- a/arch/x86/virt/vmx/tdx/tdx.h
+++ b/arch/x86/virt/vmx/tdx/tdx.h
@@ -53,6 +53,7 @@
 #define TDH_EXT_INIT			60
 #define TDH_EXT_MEM_ADD			61
 #define TDH_SYS_DISABLE			69
+#define TDH_QUOTE_GET			98
 
 /* TDX page types */
 #define	PT_NDA		0x0
-- 
2.53.0


  reply	other threads:[~2026-12-04 18:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:18 [PATCH v3 0/8] Enable DICE-based TDX quoting Peter Fang
2026-12-04 18:18 ` Peter Fang [this message]
2026-12-04 19:15   ` [PATCH v3 1/8] x86/virt/tdx: Add interface to generate a Quote Dave Hansen
2026-12-04 22:02     ` Edgecombe, Rick P
2026-12-04 21:44   ` Adrian Hunter
2026-12-04 22:04     ` Edgecombe, Rick P
2026-12-04 18:18 ` [PATCH v3 2/8] x86/virt/tdx: Add interface to check quoting capabilities Peter Fang
2026-12-04 18:18 ` [PATCH v3 3/8] KVM: TDX: Require at least one quoting session and thread per CPU Peter Fang
2026-12-04 18:18 ` [PATCH v3 4/8] KVM: TDX: Add KVM_TDX_GET_QUOTE sub-ioctl for quoting Peter Fang
2026-12-04 18:18 ` [PATCH v3 5/8] KVM: TDX: Report maximum Quote size in TDX capabilities Peter Fang
2026-12-04 18:18 ` [PATCH v3 6/8] KVM: TDX: Document KVM_TDX_GET_QUOTE Peter Fang
2026-12-04 18:18 ` [PATCH v3 7/8] x86/virt/tdx: Enable the quoting extension Peter Fang
2026-12-04 18:18 ` [PATCH v3 8/8] x86/virt/tdx: Add documentation for DICE-based quoting Peter Fang
2026-12-04 18:40 ` [PATCH v3 0/8] Enable DICE-based TDX quoting Jason Gunthorpe
2026-12-04 18:47   ` Edgecombe, Rick P
2026-12-04 18:50     ` Jason Gunthorpe
2026-12-04 19:11       ` Edgecombe, Rick P

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204182022.324230-2-peter.fang@intel.com \
    --to=peter.fang@intel.com \
    --cc=adrian.hunter@intel.com \
    --cc=binbin.wu@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=chao.gao@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=elena.reshetova@intel.com \
    --cc=hpa@zytor.com \
    --cc=jgg@nvidia.com \
    --cc=kas@kernel.org \
    --cc=kishen.maloor@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nik.borisov@suse.com \
    --cc=pbonzini@redhat.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=seanjc@google.com \
    --cc=sohil.mehta@intel.com \
    --cc=tglx@kernel.org \
    --cc=tony.lindgren@linux.intel.com \
    --cc=x86@kernel.org \
    --cc=xiaoyao.li@intel.com \
    --cc=yilun.xu@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox