From patchwork Fri Dec 8 17:17:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 175964 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5598677vqy; Fri, 8 Dec 2023 09:18:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IErFUUqJUe+tYa1pny2O1stIob7EZLmTcy5RkQFQ/jnfVZ3QeTB4aDUEzfjcvvXAiFoikBl X-Received: by 2002:a05:6a20:1610:b0:18b:4fa:a877 with SMTP id l16-20020a056a20161000b0018b04faa877mr404031pzj.14.1702055908218; Fri, 08 Dec 2023 09:18:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702055908; cv=none; d=google.com; s=arc-20160816; b=ytMpa8enAnV6utUg0hVnanP+InaHJMtPlkrkDkh4olwChCvxUNIKzs0ji/2IHZsJj/ d4/r8ZDK6hg8nqq4ymUTQDhd7dTtqAbp7YUY0q6Nz1/r/bI8EM1zsG3Dl6s4CY5jbUmQ fntmsKmiPZXxuDtDtpevz2FOdJYqx5XOgMIQhdCpoe/rgKNKErroyll/Lm2fTF8k05Fz 5FAsWv5MJSSfxW6ZFq7RD8KiGTgVJ53736+rQ8/WewfhlSk0sUqBaQBECCwO7wcjggPa 1FQHlZpJLHAPC0klSsRKzGy4peSuW5+6KFBhivZ3VOXCsb9Fo7jNTJtuAmej8t/shvjg zEBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=AYK8JDa/3/4EaXRh0d/IVt4B6qp0E6G73A/t94skRCc=; fh=6X+JyjsAoK9TUwjvxGea9vfUmnvlnnDsu3Ji0y9ItP4=; b=J+OWb2KvjSJV/iFUoK8vMAdp/aBUy16u13TTb3rgfaykon8nkepY2xABpP+qcMlTfw fbZMJntYnzgvMi2j+NkZuVfty9Cj6xb1S3QT773U6FweEmz7h5SeglF+MO3JVDPTr7W6 q0OKhxGpnwKjus150A8k6UY8J75y02FOfTb3V6ajMkfIZBH2Fw7001Wxh/4rHsMaON6x NUph1ikgyBHCl0kAKPpX6r6YJEFHKa0Q7L0qvButScBkejLyXeF6aaUkO829Rfv9KtiK o8VMTG6fw6lNuRVNFWyuXT98pxjy3gzS7qr+wc5WV6AuQxl184ajV1+DvRXrzlIqg7Ej StUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0oIYRElk; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id f7-20020a635547000000b005855f67e490si1831722pgm.690.2023.12.08.09.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 09:18:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0oIYRElk; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 2BCA281DE387; Fri, 8 Dec 2023 09:18:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574434AbjLHRR1 (ORCPT + 99 others); Fri, 8 Dec 2023 12:17:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1574187AbjLHRRR (ORCPT ); Fri, 8 Dec 2023 12:17:17 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5F3E10E6; Fri, 8 Dec 2023 09:17:23 -0800 (PST) Date: Fri, 08 Dec 2023 17:17:21 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702055842; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AYK8JDa/3/4EaXRh0d/IVt4B6qp0E6G73A/t94skRCc=; b=0oIYRElkdby5tU/1BfZocijM6/KPblQvaObN54ID+YLew5Z8fAxjcMto/FAvCi+odvNdn8 BEpGygTvunR/55PtJoviZi1A55BaAK43SusbSG0Gv6cd0FbMlyB/XCBQVMH+Cc8XE9cmFg 4IzgBBxFy4wR5guawQBw751NA68JPzoY3F7G6UHxoahKPbZ55pC12Tc1F2Mrc1seW71dhD lSaueZDgQjgbJ1McT07h206/SvO9H1D1476MaxbmnTqAE8wo4fpl64ws0XvJA9SkRRGW03 K/d5MvP6iBc7k0daMVuE6vBLNp23/Lm1LKNkfAg7+kOS3pZCNotPy8rV2JQO5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702055842; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AYK8JDa/3/4EaXRh0d/IVt4B6qp0E6G73A/t94skRCc=; b=fwTcJv0iPhpGcRsuj99s5XeaFszU9sV1+/ltd4dXnL/XKYkOAAOWpUTXGzV7mwIhlhTmT6 vk1lgTQUH0niePBg== From: "tip-bot2 for Kai Huang" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] x86/virt/tdx: Configure TDX module with the TDMRs and global KeyID Cc: Kai Huang , Dave Hansen , Isaku Yamahata , "Kirill A. Shutemov" , Yuan Yao , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <170205584189.398.2713821707672808990.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 08 Dec 2023 09:18:19 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784734975984308645 X-GMAIL-MSGID: 1784734975984308645 The following commit has been merged into the x86/tdx branch of tip: Commit-ID: 554ce1c36d1bbeaec42ba870bad75e200af204be Gitweb: https://git.kernel.org/tip/554ce1c36d1bbeaec42ba870bad75e200af204be Author: Kai Huang AuthorDate: Fri, 08 Dec 2023 09:07:33 -08:00 Committer: Dave Hansen CommitterDate: Fri, 08 Dec 2023 09:12:41 -08:00 x86/virt/tdx: Configure TDX module with the TDMRs and global KeyID The TDX module uses a private KeyID as the "global KeyID" for mapping things like the PAMT and other TDX metadata. This KeyID has already been reserved when detecting TDX during the kernel early boot. Now that the "TD Memory Regions" (TDMRs) are fully built, pass them to the TDX module together with the global KeyID. Signed-off-by: Kai Huang Signed-off-by: Dave Hansen Reviewed-by: Isaku Yamahata Reviewed-by: Kirill A. Shutemov Reviewed-by: Yuan Yao Reviewed-by: Dave Hansen Link: https://lore.kernel.org/all/20231208170740.53979-13-dave.hansen%40intel.com --- arch/x86/virt/vmx/tdx/tdx.c | 43 +++++++++++++++++++++++++++++++++++- arch/x86/virt/vmx/tdx/tdx.h | 2 ++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 98283f7..5146503 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -892,6 +894,41 @@ static int construct_tdmrs(struct list_head *tmb_list, return ret; } +static int config_tdx_module(struct tdmr_info_list *tdmr_list, u64 global_keyid) +{ + struct tdx_module_args args = {}; + u64 *tdmr_pa_array; + size_t array_sz; + int i, ret; + + /* + * TDMRs are passed to the TDX module via an array of physical + * addresses of each TDMR. The array itself also has certain + * alignment requirement. + */ + array_sz = tdmr_list->nr_consumed_tdmrs * sizeof(u64); + array_sz = roundup_pow_of_two(array_sz); + if (array_sz < TDMR_INFO_PA_ARRAY_ALIGNMENT) + array_sz = TDMR_INFO_PA_ARRAY_ALIGNMENT; + + tdmr_pa_array = kzalloc(array_sz, GFP_KERNEL); + if (!tdmr_pa_array) + return -ENOMEM; + + for (i = 0; i < tdmr_list->nr_consumed_tdmrs; i++) + tdmr_pa_array[i] = __pa(tdmr_entry(tdmr_list, i)); + + args.rcx = __pa(tdmr_pa_array); + args.rdx = tdmr_list->nr_consumed_tdmrs; + args.r8 = global_keyid; + ret = seamcall_prerr(TDH_SYS_CONFIG, &args); + + /* Free the array as it is not required anymore. */ + kfree(tdmr_pa_array); + + return ret; +} + static int init_tdx_module(void) { struct tdx_tdmr_sysinfo tdmr_sysinfo; @@ -927,10 +964,14 @@ static int init_tdx_module(void) if (ret) goto err_free_tdmrs; + /* Pass the TDMRs and the global KeyID to the TDX module */ + ret = config_tdx_module(&tdx_tdmr_list, tdx_global_keyid); + if (ret) + goto err_free_pamts; + /* * TODO: * - * - Configure the TDMRs and the global KeyID to the TDX module. * - Configure the global KeyID on all packages. * - Initialize all TDMRs. * diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index 1b04efe..fa5bcf8 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -17,6 +17,7 @@ #define TDH_SYS_INIT 33 #define TDH_SYS_RD 34 #define TDH_SYS_LP_INIT 35 +#define TDH_SYS_CONFIG 45 /* * Global scope metadata field ID. @@ -53,6 +54,7 @@ struct tdmr_reserved_area { } __packed; #define TDMR_INFO_ALIGNMENT 512 +#define TDMR_INFO_PA_ARRAY_ALIGNMENT 512 struct tdmr_info { u64 base;