From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.8 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381833; b=gfjtSN1O6WajKORoyDJrGjJE4AmQxJGpLbm5v8S/UThPhC+Jdku9y40y4WIh6V6y27Hd Mb+WDtAN4G8a8OiLqFhSajxUlBe0kOxmS9f7HlI4b0e8Vxo7+z4MjbDu5VHoT12cAChcD 7sJkksGuGQQ41of51+gukSe3DbAdUzeGshAj6vdjGENu3r3JXSbbCQZfWUWn0RWiYy52S 1b6I1OoH8+W2i0z5cXMX4Muegy2rDT0t+hs1BoGc6dmgMWhsXGtwq14dtwTOTprUcaJyF 3uiUfBNMrUVz8xKaJfltT9ZQcXjw2p7UWMbjsks/37oHwwHRpeUOlYiZYsuv5RMGM8A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381833; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=uI41WQtH1I7c/qYXicqOupbadqPd5vYEB1IcQE+SjYY=; b=BBPk8PvwqAFr9OEUVATlZvQkNP54GMeQ9NLVH5F2V0sKeeZS6IS1ARibVsnMleQMh4IB mhJ3RcCfG0+eeJwB4xEpxxv7JuPCs/MO6rZugKZSuAuNUhWe3QxtgGz9+WAd8Nd71Ww4U ZYAtCoHedzadZaFcJQilEkrCmps2JuM3eblX39PZWZLgX4y18tSbGlDWNsp60rEQ0Z6B2 Su+fz52ceTCLTcQeBdspBaSL3y2sbvkUr+LZp9ViTOc3Ldizlr6JIgJ/hH550fFYxO/xF zAfLYvVj4rUf/7z7ge36t+n5ymiHkETQSaPkc0VvFo62e6Nm/kGgoCL5Dv6P5DjyHuQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=RLaQBtew; arc=none smtp.remote-ip=192.198.163.8 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F320B606A32C for ; Fri, 4 Dec 2026 10:57:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F320B606A32C 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=RLaQBtew DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796381833; x=1827917833; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uI41WQtH1I7c/qYXicqOupbadqPd5vYEB1IcQE+SjYY=; b=RLaQBtewW2h8yKP+Zek4usR4RhThwCYx8YuzkJ/PZ4cn/xtZgAyOfarm oPdJow11Ir3Ywt6P2INQbST+/3QXs85O7V2qQqGu2uM2qB81XUxVQPkfp nCZaHd8xfD3ss3/Houk4lQeTicXek/NWj12Hunvr90lbvFzCFKKxwv0+z l3GEs5JCJNlkihP5AQ1m5cVnpNpXn3+3eXZd3gPaqddZgcckZJsctwsr+ 9c4y7TGMto+wcjzx5aC1w3v53gGQJuv+OMi6G5QntH2r1kBp6TFQD8DYE PFrxuE9sXAYup4EkSY8FkHUobsr/5et1Yg1KqWT6wZCmoENQSdTHh73AJ Q==; X-CSE-ConnectionGUID: oUO/tVKZQVmoSZPsS0Mh6A== X-CSE-MsgGUID: Cu6bVXguR1iJbi/bO9m0yA== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5244593" X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="5244593" Received: from fmviesa012.fm.intel.com ([10.60.135.152]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 02:57:12 -0800 X-CSE-ConnectionGUID: QZb//b2ARw+15UzwHj4uLQ== X-CSE-MsgGUID: 8N6jbRgUT/e3XseRMCbKUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,78,1794902400"; d="scan'208";a="15701097" Received: from 984fee019967.jf.intel.com ([10.23.153.244]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 02:57:12 -0800 From: Chao Gao To: linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org Cc: yilun.xu@intel.com, arjan.van.de.ven@intel.com, binbin.wu@linux.intel.com, Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Kiryl Shutsemau , Rick Edgecombe Subject: [PATCH v4 1/2] x86/virt/seamldr: Support large TDX module binaries Date: Fri, 4 Dec 2026 02:59:47 -0800 Message-ID: <20261204105951.1811487-2-chao.gao@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20261204105951.1811487-1-chao.gao@intel.com> References: <20261204105951.1811487-1-chao.gao@intel.com> X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The kernel hands a TDX module to P-SEAMLDR through a 4KB ABI structure, mirrored in 'struct seamldr_params'. The structure holds a list of the physical addresses of all module pages. The list has to fit in the 4KB structure, which limits modules to just under 2MB. Upcoming TDX modules will be over that limit. So the P-SEAMLDR ABI was extended to support them. The last entry of the list is now a pointer to another 4KB page, which holds more entries and ends with a pointer to the next page. Pages are added this way until every module page is listed: Old layout: New layout: +-------- 4KB ---------+ +-------- 4KB ---------+ | other fields | | other fields | | 496 module page PAs | | 495 module page PAs | +----------------------+ | pointer to next page |--+ +----------------------+ | | +-------- 4KB ---------+<-+ | 511 module page PAs | | pointer to next page |--> ... +----------------------+ P-SEAMLDR enumerates its support for the new layout with a feature bit. A P-SEAMLDR with that support always expects the new layout. Redefine 'struct seamldr_params' as a 16-page structure. Its first page mirrors the first page of the new layout. The other pages mirror the pages chained to it. Fill the structure in accordingly and raise the maximum number of module pages. To keep the implementation simple: - Always use the new layout. Do not support the old one. The new layout and the old layout are identical for modules of fewer than 496 pages, so every existing module works as before. A module of more than 496 pages was never accepted by an old P-SEAMLDR. Only a module of exactly 496 pages breaks, and only on an old P-SEAMLDR, which treats the last entry as a module page address. No such module has been released. Checking the feature bit to choose a layout for that one size is not worth the extra code. - Represent all the pages of the new layout in one structure. The pages are then allocated together rather than one by one, which simplifies the allocation and free paths. - Cap the module size at a reasonable limit. Supporting any module size that the ABI allows adds complexity. It means sizing the structure for each module after its image is validated. The size also must not exceed what kmalloc() supports, or another allocator would be needed. Fix the structure at 16 pages to avoid that. 16 pages is an arbitrary choice. It fits modules of up to about 32MB. That limit will not be reached in the foreseeable future, as upcoming modules are a little over 2MB. Small modules leave up to 15 pages unused until the structure is freed at the end of the update. Signed-off-by: Chao Gao --- v4: - Add a diagram of the old and new layouts [Dave] - Make 'struct seamldr_params' follow the ABI layout, with explicit next_pa fields [Dave/Rick] - Explain how the new layout is enumerated and enforced by P-SEAMLDR - Explain the design decisions and the reasons for them v3: - Explain the math of the max module page count [Rick/Yilun] - Call out the 496-page behavior change [Binbin] - Drop the exact numbers (496/495) from the ABI description [Yilun] - Drop the boilerplate AI usage note [Dave] - Note that sigstruct_pages_pa_list[] is never chained [Yilun] - Comment the PAGE_ALIGNED() check in populate_pa_list() [Rick] v2: - Make 'struct seamldr_params' a fixed 16 pages instead of sizing it to each module, capping modules at about 32MB. [Rick] - Drop the patch that moved the allocation after image validation. [Rick] --- arch/x86/virt/vmx/tdx/seamldr.c | 67 +++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamldr.c index b1137ca6150d..5678309624ab 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -24,7 +24,23 @@ #define P_SEAMLDR_INFO 0x8000000000000000 #define P_SEAMLDR_INSTALL 0x8000000000000001 -#define SEAMLDR_MAX_NR_MODULE_PAGES 496 +/* + * The number of pages in 'struct seamldr_params'. The value is arbitrary + * and can be increased to fit larger modules. + */ +#define SEAMLDR_PARAMS_NR_PAGES 16 + +#define SEAMLDR_NR_PA_ENTRIES_FIRST_PAGE 495 +#define SEAMLDR_NR_PA_ENTRIES_CHAINED_PAGE (PAGE_SIZE / sizeof(u64) - 1) + +/* + * The number of module page addresses that 'struct seamldr_params' can + * hold. Its first page holds fewer addresses than each of the chained + * pages. + */ +#define SEAMLDR_MAX_NR_MODULE_PAGES \ + (SEAMLDR_NR_PA_ENTRIES_FIRST_PAGE + \ + (SEAMLDR_PARAMS_NR_PAGES - 1) * SEAMLDR_NR_PA_ENTRIES_CHAINED_PAGE) #define SEAMLDR_MAX_NR_SIG_PAGES 1 /* @@ -48,10 +64,15 @@ struct seamldr_params { u64 sigstruct_pages_pa_list[SEAMLDR_MAX_NR_SIG_PAGES]; u8 reserved[104]; u64 module_nr_pages; - u64 module_pages_pa_list[SEAMLDR_MAX_NR_MODULE_PAGES]; + u64 module_pages_pa_list[SEAMLDR_NR_PA_ENTRIES_FIRST_PAGE]; + u64 next_pa; /* Points to chained_pages[0]. */ + struct { + u64 module_pages_pa_list[SEAMLDR_NR_PA_ENTRIES_CHAINED_PAGE]; + u64 next_pa; /* Points to the next chained page. */ + } chained_pages[SEAMLDR_PARAMS_NR_PAGES - 1]; } __packed; -static_assert(sizeof(struct seamldr_params) == 4096); +static_assert(sizeof(struct seamldr_params) == SEAMLDR_PARAMS_NR_PAGES * PAGE_SIZE); /* * Serialize P-SEAMLDR calls since the hardware only allows a single CPU to @@ -143,6 +164,44 @@ static void populate_pa_list(u64 *pa_list, const u8 *vmalloc_addr, u32 vmalloc_l } } +/* + * Write the physical addresses of all module pages to @params. The + * addresses are spread across the pages of @params, and the first + * page holds a different number of addresses than the chained pages. + * Link a chained page when it is first used. + */ +static void populate_module_pa_list(struct seamldr_params *params, + const u8 *mod, u32 mod_nr_pages) +{ + u64 *next_pa = ¶ms->next_pa; + u32 nr; + int i; + + /* Fill in the first page. */ + nr = min(mod_nr_pages, SEAMLDR_NR_PA_ENTRIES_FIRST_PAGE); + populate_pa_list(params->module_pages_pa_list, mod, nr); + mod += nr * PAGE_SIZE; + mod_nr_pages -= nr; + + /* Fill in the chained pages. */ + for (i = 0; i < ARRAY_SIZE(params->chained_pages); i++) { + u64 *list = params->chained_pages[i].module_pages_pa_list; + + nr = min(mod_nr_pages, SEAMLDR_NR_PA_ENTRIES_CHAINED_PAGE); + /* All module pages have been processed. */ + if (nr == 0) + break; + + /* Point the previous page to this one. */ + *next_pa = __pa(¶ms->chained_pages[i]); + next_pa = ¶ms->chained_pages[i].next_pa; + + populate_pa_list(list, mod, nr); + mod += nr * PAGE_SIZE; + mod_nr_pages -= nr; + } +} + static void populate_seamldr_params(struct seamldr_params *params, const u8 *sig, u32 sig_nr_pages, const u8 *mod, u32 mod_nr_pages) @@ -152,7 +211,7 @@ static void populate_seamldr_params(struct seamldr_params *params, params->module_nr_pages = mod_nr_pages; populate_pa_list(params->sigstruct_pages_pa_list, sig, sig_nr_pages); - populate_pa_list(params->module_pages_pa_list, mod, mod_nr_pages); + populate_module_pa_list(params, mod, mod_nr_pages); } /* -- 2.52.0