From nobody Wed Dec 4 18:50:58 2024 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2082.outbound.protection.outlook.com [40.107.94.82]) (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 61BBC1D9A6D for ; Mon, 2 Dec 2024 20:51:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172681; cv=fail; b=F5r9lcXo8PQibZrsWnfRojwxYGQ9L2Idor8ks64g8uQDFkWFqa9LiXjz6gGLnjpGLEaFs2TtH/vf2VWybT/rBo3vY8Tdkaa0fFs3yQ2v7PNnEgQt2lxHX1Lvl70C0k0WFlW7EDk6B7vMlcnOUaMcR2Zs0XSLptbVanZBVlmDbcY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172681; c=relaxed/simple; bh=/FufNDcq7KiOSFBU6it/sgFVuim5GISwAQWFpNuEJys=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=q9JW39nNNih8PcuLy3iC9rMw6sj+x5tnhVYmBFeLKWaGLjtYuWWKVzxWLVjskqwAIW7AGrwFj3eY+RLPgnacBr1rGb/pj6dxPnHNJZDBYTp/jJNGXZMqjMUBJ39SLSrOqEay050XF/AiumswlGegfFBMYBhQr+gNk4KZwnaDcUw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=K+7iqLJk; arc=fail smtp.client-ip=40.107.94.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="K+7iqLJk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Lzg07qnYpph5jbeOF9to6cPrWoToa9HQobXBrJO8wu8kX/RecD4cyPd4/if7fR4zhFhtQsvEITimimBtabJX445d1eDAs050I8ajrM6QL5+pINUeefJ5cGim9+upKVncjCMS51h/vg05pNjQsA2wIDqoh+srzSbMZ5Eq0BFqnI5YVsauvAVFUUxaqj9dssOOLy047rxfp/IAFW02FGM5RtMcEjQIhx9iik0v5eKZP5/6sr3N1RZNYhDKaWWBws7iTktkX+BklLz8d0M6bKwnU8tmH19Z9fI7XPadzhmHAO9FvWkNLyEqG6kXJqZtMr1g65XDekj2bV1tOsN1XND6oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TcFLDC422QBmwAMC+SB7L8vLVLVAB6fF3ocs/a4QVdg=; b=C211IoCALW50fXu9KBeVeIcc/4npdeAy1wJM1TB388NlQs2KiVk7XSKet/I9CDd11j7UZM/xNG387WwGHThZlF1oqju29Kz5upwoEKnz962wUukdFqR/Sp4iawpZ5/xIOsrjtcYzi2WBYT1rBxYPWLmpgUDvZkVVz32aQgZb7bOKrSNjbP17AMUQGkjmYX9joouchot1d5RvAs0eqR7CmLUk7SdGxfjXCv5wnpEUROQOOlXwsxSHmgXLRZwWqU+gz16fzS7VJFUJb+cy4DheBrKmhcK+Yncxay4cA1zUbdYYDngDj3hoxXMeC5MdSTr1Gs2XDeR031P/s489vIl5mg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TcFLDC422QBmwAMC+SB7L8vLVLVAB6fF3ocs/a4QVdg=; b=K+7iqLJkKggrFiVvourZH141EkzYh/pAwf55XneGXxaQWF0jjyCNBVCokaTKIFv3a1eW5e+cG1bvyA0LYBq8QMF32jvYTz70mktiySPlE3QTDmwInCxxbvMQqhHkpm13kKMrLoRgdMSJrKRRHcVRK52MhvqMaOsZ5eGPrN16/eU= Received: from SA0PR11CA0119.namprd11.prod.outlook.com (2603:10b6:806:d1::34) by DM4PR12MB7527.namprd12.prod.outlook.com (2603:10b6:8:111::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Mon, 2 Dec 2024 20:51:13 +0000 Received: from SA2PEPF00001505.namprd04.prod.outlook.com (2603:10b6:806:d1:cafe::2a) by SA0PR11CA0119.outlook.office365.com (2603:10b6:806:d1::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.17 via Frontend Transport; Mon, 2 Dec 2024 20:51:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF00001505.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Mon, 2 Dec 2024 20:51:13 +0000 Received: from tlendack-t1.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 2 Dec 2024 14:51:12 -0600 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra , Nikunj A Dadhania , Neeraj Upadhyay Subject: [PATCH v6 1/8] x86/sev: Prepare for using the RMPREAD instruction to access the RMP Date: Mon, 2 Dec 2024 14:50:46 -0600 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001505:EE_|DM4PR12MB7527:EE_ X-MS-Office365-Filtering-Correlation-Id: 3c9d0bfc-aa9d-456a-79af-08dd13130ede X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?4LWCSeI5bHduxvGeXOozACncJgcZDYHg21q0vTPOuZvSbHKSQkMZa9ws9QGt?= =?us-ascii?Q?d1Jxwj+GnPVUvAB8rc0PrOqI40Ng0na7ra9Cln3sm0ai+S/64bvf2FhcAke2?= =?us-ascii?Q?RfkRwrHgGfeEB3ok8MCYQmo3cojB+ePpmQ1ic7D97Lq75WjE+bpCswUsEG3+?= =?us-ascii?Q?dINxhVnsfARs7d5WkSxmp70nlx9Vrlsg0paPnY42DZSW+FFCUp/FtiWUd1Gj?= =?us-ascii?Q?q51ZT+lbsc+ZF5317CEANRQXyyuYmboDYDR/kfQVuVwFIX4QZvgmHhDDYYGS?= =?us-ascii?Q?Zjq8kYIDzSYNq/3qb+DwOpQTDrH8jHO44ws6XhC3ClQmZyWyzikoACTKSC7D?= =?us-ascii?Q?0QSdt++IocnWrxEZrEtCMbLJYdu0ipyDr+AoviaBHrN9T9ntlh0IJJ6CCSkH?= =?us-ascii?Q?8r9YJEExymQKOd6Dud5c3snrcAppl8G5rztKqlxSHNUdSUnb1GwajXyyxkFN?= =?us-ascii?Q?xGsDNRb2zmrmXbIT4RQaThQ4C9aZBdA3wclbyWRvMN6rBTH6UMUBD27HQoEC?= =?us-ascii?Q?iB5jK+hMA+CH5TR8BLiWNy9LlbsEFIUaIa0I3XTDIS2gI8qqMBo7JhHTTFFH?= =?us-ascii?Q?AxWV27aurlL6wil30BBGkPjWT37iY531cUI32Djo+UnhzbL8YGUhxZSMP6eQ?= =?us-ascii?Q?i043HrycRebgOrVXtTcXFnX7zgNpElll8P0ajfqD1KyDza2JUHxSxXkQ53EV?= =?us-ascii?Q?kgsC3dDun+8m8JVVvFlnvuK+ib5zWua/TwkyRMIRjUHt0c1E4o+wCigNicET?= =?us-ascii?Q?NDJd+Y0kNvQm7j6O0ybhzZyNG3UXLI19LuTkZUxTICeho9hUX5+4++jQ63Yu?= =?us-ascii?Q?DvyG3B1isWkgY/zDNsq8CoJgQgWFWxTQNV/yQLsArpsoADTNZvQBvNOp2xuN?= =?us-ascii?Q?pnjmcPEfKZJBWgwzFiie8RZlUVEWD/HQCntNgvIfLl8cbLHWOItJrtNaLwYk?= =?us-ascii?Q?0TXub2QzEN7D5STvGcHtraHrq87oO8l8zdClU+uWkgzDhjD3y3joyfNnLz17?= =?us-ascii?Q?Up1bWbV/2SEE584LtV68xtRBrdn95ir0Xc7pka+gmrBqJkw8w4E4ol3QB9nq?= =?us-ascii?Q?FkvN715qfy+ziA/VYqH1S8y8c7fuifq2585xS9atQap1f10ZVNBv2trMvoDy?= =?us-ascii?Q?tgHTkq1/yvGfssFUmGVYrZ28jyhLyOoaLt4pPOonZfqo9ZMpMEausx6czELg?= =?us-ascii?Q?7MIiAtE/J1/+hfPyrFHqlZBZMNqNk/AC3rSbOrlW0Mukzjh2hgYpJ0AGgioy?= =?us-ascii?Q?UigtkEzAlaokChHxPmOqX7ztF+ZUvLHeku5susXuh9bSBB6TKPT0APMduVUn?= =?us-ascii?Q?hU1MG81wqcSYgQMxodWkoe3ZSV6EkMr3SHOlI9LV+tSbGTJjsiNbecXQj5Qz?= =?us-ascii?Q?1DosvF2B/fdFGCtW9DP8Ar8QnrX9PsrH8p62xVQpE3L0/17771hDYyHXQmhs?= =?us-ascii?Q?5VbIHVLoqLT4erf/2aUaMgphD01Gpa35?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2024 20:51:13.0464 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3c9d0bfc-aa9d-456a-79af-08dd13130ede X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001505.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7527 Content-Type: text/plain; charset="utf-8" The RMPREAD instruction returns an architecture defined format of an RMP entry. This is the preferred method for examining RMP entries. In preparation for using the RMPREAD instruction, convert the existing code that directly accesses the RMP to map the raw RMP information into the architecture defined format. RMPREAD output returns a status bit for the 2MB region status. If the input page address is 2MB aligned and any other pages within the 2MB region are assigned, then 2MB region status will be set to 1. Otherwise, the 2MB region status will be set to 0. For systems that do not support RMPREAD, calculating this value would require looping over all of the RMP table entries within that range until one is found with the assigned bit set. Since this bit is not defined in the current format, and so not used today, do not incur the overhead associated with calculating it. Signed-off-by: Tom Lendacky Reviewed-by: Nikunj A Dadhania Reviewed-by: Neeraj Upadhyay --- arch/x86/virt/svm/sev.c | 144 ++++++++++++++++++++++++++++------------ 1 file changed, 100 insertions(+), 44 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 9a6a943d8e41..cf64e9384ea0 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -31,10 +31,29 @@ #include =20 /* - * The RMP entry format is not architectural. The format is defined in PPR - * Family 19h Model 01h, Rev B1 processor. + * The RMP entry information as returned by the RMPREAD instruction. */ struct rmpentry { + u64 gpa; + u8 assigned :1, + rsvd1 :7; + u8 pagesize :1, + hpage_region_status :1, + rsvd2 :6; + u8 immutable :1, + rsvd3 :7; + u8 rsvd4; + u32 asid; +} __packed; + +/* + * The raw RMP entry format is not architectural. The format is defined in= PPR + * Family 19h Model 01h, Rev B1 processor. This format represents the actu= al + * entry in the RMP table memory. The bitfield definitions are used for ma= chines + * without the RMPREAD instruction (Zen3 and Zen4), otherwise the "hi" and= "lo" + * fields are only used for dumping the raw data. + */ +struct rmpentry_raw { union { struct { u64 assigned : 1, @@ -62,7 +81,7 @@ struct rmpentry { #define PFN_PMD_MASK GENMASK_ULL(63, PMD_SHIFT - PAGE_SHIFT) =20 static u64 probed_rmp_base, probed_rmp_size; -static struct rmpentry *rmptable __ro_after_init; +static struct rmpentry_raw *rmptable __ro_after_init; static u64 rmptable_max_pfn __ro_after_init; =20 static LIST_HEAD(snp_leaked_pages_list); @@ -249,8 +268,8 @@ static int __init snp_rmptable_init(void) rmptable_start +=3D RMPTABLE_CPU_BOOKKEEPING_SZ; rmptable_size =3D probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ; =20 - rmptable =3D (struct rmpentry *)rmptable_start; - rmptable_max_pfn =3D rmptable_size / sizeof(struct rmpentry) - 1; + rmptable =3D (struct rmpentry_raw *)rmptable_start; + rmptable_max_pfn =3D rmptable_size / sizeof(struct rmpentry_raw) - 1; =20 cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/rmptable_init:online", __snp_= enable, NULL); =20 @@ -272,48 +291,77 @@ static int __init snp_rmptable_init(void) */ device_initcall(snp_rmptable_init); =20 -static struct rmpentry *get_rmpentry(u64 pfn) +static struct rmpentry_raw *get_raw_rmpentry(u64 pfn) { - if (WARN_ON_ONCE(pfn > rmptable_max_pfn)) - return ERR_PTR(-EFAULT); - - return &rmptable[pfn]; -} - -static struct rmpentry *__snp_lookup_rmpentry(u64 pfn, int *level) -{ - struct rmpentry *large_entry, *entry; - - if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) + if (!rmptable) return ERR_PTR(-ENODEV); =20 - entry =3D get_rmpentry(pfn); - if (IS_ERR(entry)) - return entry; + if (unlikely(pfn > rmptable_max_pfn)) + return ERR_PTR(-EFAULT); + + return rmptable + pfn; +} + +static int get_rmpentry(u64 pfn, struct rmpentry *e) +{ + struct rmpentry_raw *e_raw; + + e_raw =3D get_raw_rmpentry(pfn); + if (IS_ERR(e_raw)) + return PTR_ERR(e_raw); + + /* + * Map the raw RMP table entry onto the RMPREAD output format. + * The 2MB region status indicator (hpage_region_status field) is not + * calculated, since the overhead could be significant and the field + * is not used. + */ + memset(e, 0, sizeof(*e)); + e->gpa =3D e_raw->gpa << PAGE_SHIFT; + e->asid =3D e_raw->asid; + e->assigned =3D e_raw->assigned; + e->pagesize =3D e_raw->pagesize; + e->immutable =3D e_raw->immutable; + + return 0; +} + +static int __snp_lookup_rmpentry(u64 pfn, struct rmpentry *e, int *level) +{ + struct rmpentry e_large; + int ret; + + if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) + return -ENODEV; + + ret =3D get_rmpentry(pfn, e); + if (ret) + return ret; =20 /* * Find the authoritative RMP entry for a PFN. This can be either a 4K * RMP entry or a special large RMP entry that is authoritative for a * whole 2M area. */ - large_entry =3D get_rmpentry(pfn & PFN_PMD_MASK); - if (IS_ERR(large_entry)) - return large_entry; + ret =3D get_rmpentry(pfn & PFN_PMD_MASK, &e_large); + if (ret) + return ret; =20 - *level =3D RMP_TO_PG_LEVEL(large_entry->pagesize); + *level =3D RMP_TO_PG_LEVEL(e_large.pagesize); =20 - return entry; + return 0; } =20 int snp_lookup_rmpentry(u64 pfn, bool *assigned, int *level) { - struct rmpentry *e; + struct rmpentry e; + int ret; =20 - e =3D __snp_lookup_rmpentry(pfn, level); - if (IS_ERR(e)) - return PTR_ERR(e); + ret =3D __snp_lookup_rmpentry(pfn, &e, level); + if (ret) + return ret; =20 - *assigned =3D !!e->assigned; + *assigned =3D !!e.assigned; return 0; } EXPORT_SYMBOL_GPL(snp_lookup_rmpentry); @@ -326,20 +374,28 @@ EXPORT_SYMBOL_GPL(snp_lookup_rmpentry); */ static void dump_rmpentry(u64 pfn) { + struct rmpentry_raw *e_raw; u64 pfn_i, pfn_end; - struct rmpentry *e; - int level; + struct rmpentry e; + int level, ret; =20 - e =3D __snp_lookup_rmpentry(pfn, &level); - if (IS_ERR(e)) { - pr_err("Failed to read RMP entry for PFN 0x%llx, error %ld\n", - pfn, PTR_ERR(e)); + ret =3D __snp_lookup_rmpentry(pfn, &e, &level); + if (ret) { + pr_err("Failed to read RMP entry for PFN 0x%llx, error %d\n", + pfn, ret); return; } =20 - if (e->assigned) { + if (e.assigned) { + e_raw =3D get_raw_rmpentry(pfn); + if (IS_ERR(e_raw)) { + pr_err("Failed to read RMP contents for PFN 0x%llx, error %ld\n", + pfn, PTR_ERR(e_raw)); + return; + } + pr_info("PFN 0x%llx, RMP entry: [0x%016llx - 0x%016llx]\n", - pfn, e->lo, e->hi); + pfn, e_raw->lo, e_raw->hi); return; } =20 @@ -358,16 +414,16 @@ static void dump_rmpentry(u64 pfn) pfn, pfn_i, pfn_end); =20 while (pfn_i < pfn_end) { - e =3D __snp_lookup_rmpentry(pfn_i, &level); - if (IS_ERR(e)) { - pr_err("Error %ld reading RMP entry for PFN 0x%llx\n", - PTR_ERR(e), pfn_i); + e_raw =3D get_raw_rmpentry(pfn_i); + if (IS_ERR(e_raw)) { + pr_err("Error %ld reading RMP contents for PFN 0x%llx\n", + PTR_ERR(e_raw), pfn_i); pfn_i++; continue; } =20 - if (e->lo || e->hi) - pr_info("PFN: 0x%llx, [0x%016llx - 0x%016llx]\n", pfn_i, e->lo, e->hi); + if (e_raw->lo || e_raw->hi) + pr_info("PFN: 0x%llx, [0x%016llx - 0x%016llx]\n", pfn_i, e_raw->lo, e_r= aw->hi); pfn_i++; } } --=20 2.46.2 From nobody Wed Dec 4 18:50:58 2024 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2085.outbound.protection.outlook.com [40.107.95.85]) (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 671C11DF247 for ; Mon, 2 Dec 2024 20:51:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172685; cv=fail; b=dyzNfNJNUpP8QGayAjHan8WR1MTAojFmNabiyb6W2taokM1yQCWRAIi8P+UrC15rhaM5PI5WZ5PSL/P0jXLUHkNAK0QbIhhuF7XAMJ/5CFtAq/dNPLsI5pg/M+SfQvJIo3SgZl0167ycvN3t7Kfd/izCEo6hFbsxDN909q5Xxko= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172685; c=relaxed/simple; bh=7Oe1bonxfp00KBM5i47zkqxGEyjskCzfhC5hmngNTR0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JB+bBsqfRv6DzKHDGAqLvQ0B/HW8HSvZPDLKoSnC/gkWgMlW6OwikUr2AMDWBdrtKbU9pJNwmFX8gHhUgif/oV1AIOPzVJZOGIo8fAMP362PAyUyZIRxzDCBwmDTTTS4Iy+MM6zysBXTiupdY9vQdO2dyB6e5S+OuquwUPUDcCk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=qowuP2m1; arc=fail smtp.client-ip=40.107.95.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="qowuP2m1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ttqeVGOcEszSit0FHhWsG0TthwdL0VcFjI4QfbLLk532u5plJqUtQ1SLnL6qj4p9RgUEeovcbTmbNQL4EO669fyhrYRg0Aa8mg/w8EurbCgIsCLeh0+lnIj4dVvWx+XRvshM7raUkuIhlsVf6k9aCetXRFXgkuvd33SZ8Hg7szwBvuiYkE58si6MJnD1309eBy8uR+nGXzGjN2l/W3rB71aZFUrOb0JoG1o83LG9N6tG1BEDh44Lq89lu2HE3cbVqSORsEcbQk4q9j//odsyBFQX0E25Y8L8hggjjr1IuaXpq8gq4T9YubMeYd17wF9qDkP4/UNon4G8PWLOPdUPpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZOzXIeKM1bOge4BTH688sMoG15nyV7I2BXgFwl9dafU=; b=QIqXC8q2T/K4bhLpem/ewi4qvDHbycR/BGlLOfpm31szpN1NIz6LD7GZjr4EoCEnMs1gb5jioU6CxL9WQPTVA5ruOFMUc4ag2lq6vTi7I4StMWoGJIfIuIFzLxCCz6TCXm50J2NadWEijcBFccFjvk42KM34F/ro5czcchBeibFgZ+GkFkXABlqWHkvYbDyOp4qziZMp6cDCTUTXSJ6wYj8RCR8dqcdnxcxZHeH4PcCN3MeT9bFZu46Gl6BFPPP7Crz65HFyl8KrX8aaKYW9/zMNm4CNPZDzL+dakryyINVYQZPrQQrdj6WTniBXvNf61ddoXqX0YNjwdTaDlQf72g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZOzXIeKM1bOge4BTH688sMoG15nyV7I2BXgFwl9dafU=; b=qowuP2m13Wo8weoJdV9B/lxVA6kLpzXEmrjQF1kim+fW5+1Zm1O4ukswIXw76dZxgyeemt0by4VbtUhjKS5HtXYcKqmrUBWLHbaeut9x16AZNOBbOMKb5zKeksg0/rSOMf6tB0sqOd0ip4bt7Qc7qdQg8dYLThbsV2IJYF0jYF4= Received: from SN7PR04CA0094.namprd04.prod.outlook.com (2603:10b6:806:122::9) by DS0PR12MB8526.namprd12.prod.outlook.com (2603:10b6:8:163::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Mon, 2 Dec 2024 20:51:20 +0000 Received: from SA2PEPF00001509.namprd04.prod.outlook.com (2603:10b6:806:122:cafe::fb) by SN7PR04CA0094.outlook.office365.com (2603:10b6:806:122::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.18 via Frontend Transport; Mon, 2 Dec 2024 20:51:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF00001509.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Mon, 2 Dec 2024 20:51:20 +0000 Received: from tlendack-t1.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 2 Dec 2024 14:51:19 -0600 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra , Nikunj A Dadhania , Neeraj Upadhyay Subject: [PATCH v6 2/8] x86/sev: Add support for the RMPREAD instruction Date: Mon, 2 Dec 2024 14:50:47 -0600 Message-ID: <72c734ac8b324bbc0c839b2c093a11af4a8881fa.1733172653.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001509:EE_|DS0PR12MB8526:EE_ X-MS-Office365-Filtering-Correlation-Id: 7252f2d1-31d4-4a4f-e46f-08dd1313132a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?7p9lMJJTkPcE8cYvtCeLyAq4kZ2eMklIOIFhW1wUiPIyETG/yU3hQlBhT3a2?= =?us-ascii?Q?yKg+Ng5XxCPekEIricA7QblLKcNhoJxNz3SoJd0RUZOCr9aKEjYTWxqNEu1U?= =?us-ascii?Q?m1ZD00PMjCld8XBcDR5LiMC/IVeFpE0AwtGfGvwpWCEkMJITQXG8Dswyru5b?= =?us-ascii?Q?45i301K6zf0EYn/WrFs7qvrf7UZh2vHqtFh3opkYz62sVK3AzAf2SFRhA/TS?= =?us-ascii?Q?2/nFSIL8P1mUddlYzIAyoHu32ztdB7zlXVZ5xPWwQPWWpQCEUdnSWmWCtPWo?= =?us-ascii?Q?rCxqovWRYhEYk/Bx3ZoyLAYgdzms1ALFqHnlHXPRraQXrfsnlyAx0+dfhr8H?= =?us-ascii?Q?k2uij2tOsXSArbSAd9cLbRWUJQwvmQBGi15D+DEXOl8tXJCIpCCSQeSRY35h?= =?us-ascii?Q?USYe7+QoIaiyGkTPl+AdVa8Jz+3+C7zIrvIiUhEyRGlWujb/TiBYIJup1hBq?= =?us-ascii?Q?WagOff1yWYwV0kvgoKT+Nn/KcDuToYI/wdnMx6mjpNV823Ph9U2qFT9w8RLR?= =?us-ascii?Q?HPwky8KOlff/rwRseTDd1Hisy6q4VYhG8c4680/L9e1HzOy2rsfVK/T/qxsU?= =?us-ascii?Q?Gk2ISYK89NYjTVz1gwrPLQrPRz8ZPgy9AJkVawjbUmr9KaukSDlvOtkDC/2w?= =?us-ascii?Q?5A65eohrhNsYJ4TJuqdnR/S1oSJyVOg2fVF77crsGwS8RZJJcWiOHnFRKnOX?= =?us-ascii?Q?FslHgOI/2Woqb7XrdlstlL2ZqmGt4l/TiMdK44f4ROVcDpa3kK2JxbhqYwU4?= =?us-ascii?Q?3Jo95XnPALzHusDHfJ+GVEoZMEwUx6HkCBhyQ+e/vJ1ojuvUN1dnJOUM34iF?= =?us-ascii?Q?4sOJIAQT8DUBnGR0LxBRhqNMvUEr7/oXYGiio704e9hkeWuIMAzCIJxapW+0?= =?us-ascii?Q?skp0CaQ/5y2yU3PbImN+veReTdUalmhyM1jjAmkZTGCdKQUSzPTNtZ3rE6i4?= =?us-ascii?Q?jFp7DDL9ccUgG2uQ9c26i8hzl5oRVqFrpal8rFxZ5g6LzjmZ+g/f95ax7r1S?= =?us-ascii?Q?AY7EefI2Pb2o4vuSbtNSoJvrOHCy69oBsnzSAndaz6inSYaSMlZQCjISG4m2?= =?us-ascii?Q?Xn55VBFKj+WS8ViBBHOdPtbbbiASybXCQ5ValUeEpEi8RC156H3RqP/fW1JB?= =?us-ascii?Q?X8s9Q4qzL/A9KzRKdJV9dMLejBsZPvvJuqbUr6839FaSdwibGWtUmdAqZmk2?= =?us-ascii?Q?fp/qx030aKQotnq4QELkhjiYGIVi8W4wOvpOutdyZPg485n54LtTU4LatNf6?= =?us-ascii?Q?iNNawVu5NVeSJx5ve4uveMP/mE7n/gh3JKNgz2Kmqi0/Xuii7mzn2U5Y6THt?= =?us-ascii?Q?mRKsI6KYNd2EwKo48VZPK5WfIp913bDeCi6UfODBZx4HsOmyvfsyWQPmabQn?= =?us-ascii?Q?+JypCqrxvLepc9bV15oTWVC7lIs7YDw9qcO5i+vP4BOHHISWgzUVZMBLwGv9?= =?us-ascii?Q?DYwG0PvEn+EFlc1O/Hgnplj2JioJ24jT?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2024 20:51:20.2581 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7252f2d1-31d4-4a4f-e46f-08dd1313132a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001509.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8526 Content-Type: text/plain; charset="utf-8" The RMPREAD instruction returns an architecture defined format of an RMP table entry. This is the preferred method for examining RMP entries. The instruction is advertised in CPUID 0x8000001f_EAX[21]. Use this instruction when available. Signed-off-by: Tom Lendacky Reviewed-by: Nikunj A Dadhania Reviewed-by: Neeraj Upadhyay Reviewed-by: Ashish Kalra --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/virt/svm/sev.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index 17b6590748c0..5535edc6e8d7 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -451,6 +451,7 @@ #define X86_FEATURE_V_TSC_AUX (19*32+ 9) /* Virtual TSC_AUX */ #define X86_FEATURE_SME_COHERENT (19*32+10) /* AMD hardware-enforced cache= coherency */ #define X86_FEATURE_DEBUG_SWAP (19*32+14) /* "debug_swap" AMD SEV-ES full= debug state swap support */ +#define X86_FEATURE_RMPREAD (19*32+21) /* RMPREAD instruction */ #define X86_FEATURE_SVSM (19*32+28) /* "svsm" SVSM present */ =20 /* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word = 20 */ diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index cf64e9384ea0..18191cbd78c5 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -306,6 +306,18 @@ static int get_rmpentry(u64 pfn, struct rmpentry *e) { struct rmpentry_raw *e_raw; =20 + if (cpu_feature_enabled(X86_FEATURE_RMPREAD)) { + int ret; + + /* Binutils version 2.44 supports the RMPREAD mnemonic. */ + asm volatile(".byte 0xf2, 0x0f, 0x01, 0xfd" + : "=3Da" (ret) + : "a" (pfn << PAGE_SHIFT), "c" (e) + : "memory", "cc"); + + return ret; + } + e_raw =3D get_raw_rmpentry(pfn); if (IS_ERR(e_raw)) return PTR_ERR(e_raw); --=20 2.46.2 From nobody Wed Dec 4 18:50:58 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2068.outbound.protection.outlook.com [40.107.236.68]) (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 1F0121DF254 for ; Mon, 2 Dec 2024 20:51:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172692; cv=fail; b=B/r7zZOFQWPoqNdicB3tOhS/dxw1Zn/7VdkqXMkDOCXbckGlhPZL5AL+AOyl0ZZ9GeUMb1kYRSBWVzDL1H2x9dAVHjnv7+VBFwqbe/Zt8HXTX0QumI6Forcgl9p4TBr/P5WzNH+w1z3rjOKtugDqBBo98BMVtw/PesGc8u34pzc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172692; c=relaxed/simple; bh=yhPgIktYqNR0wimNCSTpaXDhtwRdS3LpeTchlZ1/bF8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GKYaWcU33OerYM3mZr3Yeb/gdZCbCWgh5YOE7Y+cFQBESfVYgvBIR/i0rBVeVNKratlIymwQKoIrlfUmmJBS3v0+LdzheUbiOMCOfPztrItAQM+ndZFRp1Lx4YCqJup76Kwq7+F/J87Na83+Y2k2RIdVQnidQOYihvv7RU5Q96w= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=45Z+USmy; arc=fail smtp.client-ip=40.107.236.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="45Z+USmy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OdRIKEd3GbB3nwzV3eWYkBSv5f1LLVxKPJ7BBhPVxfLK0clA+XUPfPf6IpIUUZKmHA2jK/DGFQ/SQ1Lx7jXwCYVRyFybzdw8Wcfg0pGMYDIYLUcbRW375dyK5BuxlGy439TMNcL8VpfcRgmxFWMHHmoc7nLtyhQeopdxpHsSmfPsyuGnZlWEH0UGss9zgjeoBSrHPZ5NzMC538leKT6kfeDIVyLyhsJkBJ2sXJct70YIavlDmjXSC7IV4HxphlxT2A/QJ77KTnc1OMD51Wa4FaAjea/okJcJHYnVrFDAr5Zhslk9d4xmoal9IumYjpYQfz52vTbF6e+Cg4Ta43BsWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FJOuWZ8pkj+GeQeOn7kV0DDIDj/97N3nKBoaS/gwrcQ=; b=XSqHcygSIPIT6qZqlq3jxBrYteENpbyN/Xr+1OIbSNJCl/VUrQiHJ/1XTyIETjOtyi3ECLNScu1lYnfxwozEHyXuMybzXqtUCnS17nv0293T2ZCscnOelM0yCXNfmAbCld5VhLQoxPCVu3hl7p9nrJecHeHs3TsWn3U2Kl19GsMD6flKEr4x7Ij3RNvdsyhN59hGlELaLINbDdhRhb20FqgcKGos4I+spA7BypgUQhxviGniwuQ7Ok9Z15eNqBoQe4e+vJbmf7mRM8C8TPn1fv2i0WzBqDo125waDFa2+o2NBW90qAh753AoEDvAFg/U2gd8qPHUETwx2XuolDCh4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FJOuWZ8pkj+GeQeOn7kV0DDIDj/97N3nKBoaS/gwrcQ=; b=45Z+USmyHN+isye2TOKuWAk/4ac5RxoJ1UsJkgn0dpbos78vNbriQcc8Pbu/1xPNLEZqHkw6vkRtnBATO+du9UOvzkfyL4aSVi1itVxwE0kyGCy1GSgyRN3NvirMDBNZHXz82LuQp2caatHKrEDKd5c1dxYdbJ3SgpbD87Lwuz0= Received: from SA1PR04CA0019.namprd04.prod.outlook.com (2603:10b6:806:2ce::26) by MW4PR12MB7192.namprd12.prod.outlook.com (2603:10b6:303:22a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.13; Mon, 2 Dec 2024 20:51:27 +0000 Received: from SA2PEPF00001506.namprd04.prod.outlook.com (2603:10b6:806:2ce:cafe::a2) by SA1PR04CA0019.outlook.office365.com (2603:10b6:806:2ce::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.18 via Frontend Transport; Mon, 2 Dec 2024 20:51:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF00001506.mail.protection.outlook.com (10.167.242.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Mon, 2 Dec 2024 20:51:27 +0000 Received: from tlendack-t1.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 2 Dec 2024 14:51:26 -0600 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra , Nikunj A Dadhania , Neeraj Upadhyay Subject: [PATCH v6 3/8] x86/sev: Require the RMPREAD instruction after Zen4 Date: Mon, 2 Dec 2024 14:50:48 -0600 Message-ID: <5be0093e091778a151266ea853352f62f838eb99.1733172653.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001506:EE_|MW4PR12MB7192:EE_ X-MS-Office365-Filtering-Correlation-Id: f5adfba3-d2da-44c6-5698-08dd13131774 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?CyEdB29iRTc4bMNEVSF28hADIcJxlTkDLUGpQi5+QZJQmw14ukasd81blNV6?= =?us-ascii?Q?585o0vbSIn8j6MRfSVS2Z+e3ICuPKfLzg/eHCCS9CX+LgSgy89KTfpiqVX5i?= =?us-ascii?Q?NoyUTONoFcdmgSKTjTH+efOS9T5F3cb1XW9pawer1s75OrMuVMqEY+ewNcYp?= =?us-ascii?Q?nCXspZKfyN+D4GtDQHGr3wyZsvmSLEGb2fnyz/Z5RzyfCYQT+/9QXiXYdTf6?= =?us-ascii?Q?BNX3CndacbVh9ONTV2xk8lWcld7Ymfr3d1h5rhfMcWoERmVaMXX/O9uYKiWM?= =?us-ascii?Q?N4Z5UEne1VlcPMBtKJ+sFBdOnx2FZ4/Frro4d8KRRt2JB7c+OTSaZWOZGr8T?= =?us-ascii?Q?Cmhl76n5LMLdtpuCigDnZoOPe9JDjGZRTrhf0a7Fnw5tX2ujvvo5kdysOcGo?= =?us-ascii?Q?THhpfAf78wKG14WbniSUCpj4wNaeRi0sZy6UHxys9YoQwa/5vM07TQCDRzpg?= =?us-ascii?Q?cb/NIYKgBqQIQsJUYdWEaqEqK1iyCvAWDRVAbzFnkOoTMesMHWgN54qwap0q?= =?us-ascii?Q?KRUi8Xct052+9yREtCMd6idepvxeoRvktunhOY+HFqA9CvQC1p+4Y/4rt1FR?= =?us-ascii?Q?J87ApSPo1X8ubPkcNJ+bjkRbh4j8Qj3Zx5Knum8I0STQRJyuKH8mzA1tJAH7?= =?us-ascii?Q?GxCslwdxx2cschqQ4nwzF0smr54kVupPSYhJxvso+N49gIq9MP9sgpVO6MIP?= =?us-ascii?Q?5970sxsKmAQIk4jmQKEKRMh8swew/7KtAm+lla5qi/HC8PXRPx0mhPv/qLNf?= =?us-ascii?Q?mdUN4+5WV+pxpW1LZNv92aSbvHF2hP2EZo6PpYwmVfsADieDt0rD5ryoxm0C?= =?us-ascii?Q?GadNJ1vs64Y/jxwXMSeElwNpBGV9iGtWgcYRdLrj1j2JW8WbR8O7R8qXlxJt?= =?us-ascii?Q?6j9L/spmtyjxksiq+EA5XwBLsTl2r4mZCeSpRaQ5fNEjWuO6eUdMVCmSZ0uI?= =?us-ascii?Q?yX3LUisWrw1Z/rV454NDVcloMVAPRRxnVYpQEWnLdJewqCEGEyUkUywq8lhr?= =?us-ascii?Q?k+AebMTcgXS6f26nFeXoez1sTIx5IpNCxSSLMk7RaOqqovQKLP8xZxdNiO6B?= =?us-ascii?Q?28iMeMghKn9fXiv2wovh9pO9ZViGIRSYYeERoJ9ZmzQhUB5Kvm2uSOEyJNi5?= =?us-ascii?Q?r10AX9n3G3fIyu3x03HwHrj0ZCJXdfyU3yUoLFn/8DV7QffMILnAA5bjf4S4?= =?us-ascii?Q?2qaiibcpjXyB7uZmPfnZRE3XonL1FAaw7UGRGXTMErvZ4Gw6QjVWYBg0QJrd?= =?us-ascii?Q?WvXNb2RvSxLJXHXEjSVpxocWHVTb73oF+oTBX25+rUHWXl3PlHh1BOpYXHrs?= =?us-ascii?Q?VZIZ7GHUWvQILy9+lZ+OJyFomcICJ+/lePsgjq+tgg6wNbsPz0/8jmaNGa+j?= =?us-ascii?Q?fqwTdmnxXAhlM/LG7HG04pOEf2vNCZpYBQURJoI2pmIaxxqBuzvJVY7D4jHj?= =?us-ascii?Q?L68DTzS8HVKa8ZxGD2oeBFLzCE6YR0Yi?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2024 20:51:27.4503 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f5adfba3-d2da-44c6-5698-08dd13131774 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001506.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7192 Content-Type: text/plain; charset="utf-8" Limit usage of the non-architectural RMP format to Zen3/Zen4 processors. The RMPREAD instruction, with architectural defined output, is available and should be used for RMP access beyond Zen4. Signed-off-by: Tom Lendacky Reviewed-by: Nikunj A Dadhania Reviewed-by: Neeraj Upadhyay Reviewed-by: Ashish Kalra --- arch/x86/kernel/cpu/amd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index d8408aafeed9..5f6146299165 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -355,10 +355,15 @@ static void bsp_determine_snp(struct cpuinfo_x86 *c) /* * RMP table entry format is not architectural and is defined by the * per-processor PPR. Restrict SNP support on the known CPU models - * for which the RMP table entry format is currently defined for. + * for which the RMP table entry format is currently defined or for + * processors which support the architecturally defined RMPREAD + * instruction. */ if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && - c->x86 >=3D 0x19 && snp_probe_rmptable_info()) { + (cpu_feature_enabled(X86_FEATURE_ZEN3) || + cpu_feature_enabled(X86_FEATURE_ZEN4) || + cpu_feature_enabled(X86_FEATURE_RMPREAD)) && + snp_probe_rmptable_info()) { cc_platform_set(CC_ATTR_HOST_SEV_SNP); } else { setup_clear_cpu_cap(X86_FEATURE_SEV_SNP); --=20 2.46.2 From nobody Wed Dec 4 18:50:58 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2071.outbound.protection.outlook.com [40.107.220.71]) (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 D66EC1DEFF7 for ; Mon, 2 Dec 2024 20:51:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172700; cv=fail; b=JVzSJF5arI6sYuNLzkOXbWCdmbbyxECy+fFgDcVQya007yBbzAzrThcksE7aunM/XG4SlRzx63bfo3aenCwmVUF+qQ9sRqvXmtQGLJxbY2S9mYCGWTVFqdOOk74iq9lqjD4RCVFtMZKAVng42PavHSriKnKeDK5HiwBimvz+mDE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172700; c=relaxed/simple; bh=9sW3wbF4UmkoMx0mA4ghLj1q/ZgdvZzuwFWqkgdnL+E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k8GE5KJA+BgrIE/QzG9yRveGirZKuQxO6rom+mGQ5myb+VUAKNj+4DL0fdzssbv3bNi3S40GVzer1VJOJjPRNtD+4Gn32emUPqYZwPt69fRHC0HqpfBDBwIaR3tRWRMBtplGd9cSEvIkgyrH6EGMSQIePi6vKsSzLytXzPYQOUw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Sd5dJooh; arc=fail smtp.client-ip=40.107.220.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Sd5dJooh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CLyLHPuKnYVSaI4Hq3hUMOqMVX9DR5yOLH1919eeEx+P8ijqFQ+/XcdKOvfxXXFe5g+SJlPV7bhUIg3+AsNnIoCBgpwdtepDHumpME5XibsI2ND/qjHxWaaqo+/8qTGMdsqRqaRwR8v/4m3jmOMTCHHQi/bUFsBqyfanedfnUMuziLlokZObP8s/ye+6Z57egUzDVPbs+W5W7Fg9fGhHXbEbi9JZUf067Xn+lsa43hH+5QRjXtNjoPHB63hmTBPPjAqplqWRIz0fuYxGJXYa7lMgHh0dPqUVOROS1Oj8r3ZeEZgDInxy9NB3Il6U7lmrFsqi3+2bNuv1IXge6FNmUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=A65QjPeRWZ8PmGBke4GM8IGRTLzxlZi+UAj1BMq0Z7U=; b=wIJmccldT0opUi56raLiTddBP/5cM41dkPsQh9g7EhIzGaIIQw+/Lm3XQLYAEZVX2/T4NW/r0yRCvgePmP/a+6EiFdw0SOFRnOAuwpnpkqM05drhz1wFNlFDDRnw3Ly5E1TuExYp20p8vFr+N5XyCcK1AM8Ou1qPSkMfjP4wgnaCg+9lqn+8JzsyzWfsaDRQ9aUFgH4eYmwZb/ZooqbAppdNJSjUwsTkf/6UASY7H0XicQXtu95MZ84biFe8EgfP9Yne7z/LyjcmezirebNqXGMNaVWzOUlMoa/rwjqiP/0cqM0h7pvMn6miRvNwQxcfrKXzgyhIoEUwuyYEVRe37Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=A65QjPeRWZ8PmGBke4GM8IGRTLzxlZi+UAj1BMq0Z7U=; b=Sd5dJoohihkh03eGSPj9iurk+qeUkixYNDnSP5Yt1YRnd7xZY6XH+sbiHX7AUZF9zaJspqnh5oNP6mgn60cyWKNVRXusJH9bwn9EHk6992jh/m1e5OtlPc/yJhuNPJvX6cOX8XAW6Dpn1QWHWXiktOaPx7nRpx8rsqINUPGIvgY= Received: from SA0PR11CA0108.namprd11.prod.outlook.com (2603:10b6:806:d1::23) by DM6PR12MB4339.namprd12.prod.outlook.com (2603:10b6:5:2af::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Mon, 2 Dec 2024 20:51:34 +0000 Received: from SA2PEPF00001505.namprd04.prod.outlook.com (2603:10b6:806:d1:cafe::9b) by SA0PR11CA0108.outlook.office365.com (2603:10b6:806:d1::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.18 via Frontend Transport; Mon, 2 Dec 2024 20:51:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF00001505.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Mon, 2 Dec 2024 20:51:34 +0000 Received: from tlendack-t1.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 2 Dec 2024 14:51:33 -0600 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra , Nikunj A Dadhania , Neeraj Upadhyay Subject: [PATCH v6 4/8] x86/sev: Move the SNP probe routine out of the way Date: Mon, 2 Dec 2024 14:50:49 -0600 Message-ID: <6c2975bbf132d567dd12e1435be1d18c0bf9131c.1733172653.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001505:EE_|DM6PR12MB4339:EE_ X-MS-Office365-Filtering-Correlation-Id: da3e8fe3-f89a-465c-940d-08dd13131bc4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?+xHNkoZCaotSKUaNEedmH5F0YMi8VcDul69ukd6cKjjaxOVca3GC8VR2ctwW?= =?us-ascii?Q?0xAkeZqB6zC2cjQnO31vSHnnWEKEU6UBM8FszcCh3USSi8PTuKOaMlvHFG/b?= =?us-ascii?Q?HQYtixfefmPPWX1eNQGGmB3wPak9noCqc7EBDmjYKSGXtNbJ1ptbpei77XZp?= =?us-ascii?Q?R09KXlLfo6BydibtsbGWJVe0eD8a1uAgj+pPB3zld4NsHTDaWq8j1iJ0oQI4?= =?us-ascii?Q?uuKJi6bLDoJYXoNYbTlMM5nDA1Fpg1PZEU3YLU4cwl/ht+txr40C+32A/Xhj?= =?us-ascii?Q?R2vI4E2n8erj3GPICMUWX9QogWYTsFZP79Kg+rF9wQS2ik3LT+wY3I/eiQ6B?= =?us-ascii?Q?SY7a5wUflqJ/c6Z5TqrazSQlHJQdbyMs/jXykFO004J/L7DU64foGteXtg7A?= =?us-ascii?Q?l8CTB6lnZ1nSzsJGUWOoTJf7bv5r7a/7KUI0XVtX9wuLnO6lWHHEFBfqYZ4h?= =?us-ascii?Q?Tt1G9owkohN9B9WwJ0ikLoOsa7HugaOrNL3fJ/SIbsvcPSQ+bBPQE0HVXXPT?= =?us-ascii?Q?0Tw2ZDml9OVrO893PsgAG95YgbAOzF6D+3bN6vR+SrhnsgpqH6jpqQNOk+5s?= =?us-ascii?Q?darUs9/tJ2S1i/AA3NVCRGXRmmS3lU+segm6O2thv+fSRYKs+Pp9qAYfP5hf?= =?us-ascii?Q?9hDNDDs65KdxNCkcTJZW3Mcq3KnfWgfN7wAtjph52wlSNQJtY2jsC8v7cmtC?= =?us-ascii?Q?4FF1/yxio2AvEPFMxZAJmszj1lgxWOWlI6NH0MVg761HodAk0Ub9tq5cbi1M?= =?us-ascii?Q?Zqb3joRBshFLbFHI7P+X41QQTCpOmp6/r/MIHFQ+gh1cymY4PFUIIgNowuhD?= =?us-ascii?Q?VgLUGF3e6JWwCVZdZP8+O3yNvIY01/lcGc3v3/z9llhXbxt29lDdGP8MkCGy?= =?us-ascii?Q?KafvXanQiMaWBeMmGXu6W4/gSgVspXAlg8LwPjLl6A68CsH4w6PYUh7H+tsk?= =?us-ascii?Q?w9jqJWlAlj8IJ0VvSYOL0qBziTxDk+HIWoUTRMg/lw7UcPG6YwO46W3K/B0q?= =?us-ascii?Q?w3D74rCCn2+7nQbjJ3jVOEDSAYWKVBf6GDBBa31veHNWCg3ADXhgoeDrWyqM?= =?us-ascii?Q?Kpm0DuPBMmUJPFFHxETg841TetEGVPDLUh/RLKmojAeSgN3qPKaZYwWGJTAV?= =?us-ascii?Q?r7wBN1kBBfiaaej5Fm+dhsGrs/o0eaTcMrAJh5SDiwP8r6cLaSBmbrDatXjA?= =?us-ascii?Q?LyxRcsFgHtKyWJIMv13fj6F5m2AwTEdBls5GNHXXhkg2/VeZuLOLhufWkZ//?= =?us-ascii?Q?fxepKI7mQ4jsWNjPAg1P+s5682HDqF1+iV8CPdklmZ1fJ1m87BSRrUJzkWuO?= =?us-ascii?Q?U0Vqn7ENlJTnny5kshLScKyCpnj/H2kJLn5wMm5RzESNp7D5AoJl04hPXES5?= =?us-ascii?Q?vnu/useerlywuFkCTVGy/UqPE6dXocO1L1lFExyI9zUxlSWelWKKb2XpnqUM?= =?us-ascii?Q?gG+A1gOzoYTB1XTj/sdRhYTpFj1AnYER?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2024 20:51:34.6871 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da3e8fe3-f89a-465c-940d-08dd13131bc4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001505.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4339 Content-Type: text/plain; charset="utf-8" To make patch review easier for the segmented RMP support, move the SNP probe function out from in between the initialization-related routines. No functional change. Signed-off-by: Tom Lendacky Reviewed-by: Nikunj A Dadhania Reviewed-by: Neeraj Upadhyay --- arch/x86/virt/svm/sev.c | 60 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 18191cbd78c5..0df378951ac7 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -135,36 +135,6 @@ static __init void snp_enable(void *arg) __snp_enable(smp_processor_id()); } =20 -#define RMP_ADDR_MASK GENMASK_ULL(51, 13) - -bool snp_probe_rmptable_info(void) -{ - u64 rmp_sz, rmp_base, rmp_end; - - rdmsrl(MSR_AMD64_RMP_BASE, rmp_base); - rdmsrl(MSR_AMD64_RMP_END, rmp_end); - - if (!(rmp_base & RMP_ADDR_MASK) || !(rmp_end & RMP_ADDR_MASK)) { - pr_err("Memory for the RMP table has not been reserved by BIOS\n"); - return false; - } - - if (rmp_base > rmp_end) { - pr_err("RMP configuration not valid: base=3D%#llx, end=3D%#llx\n", rmp_b= ase, rmp_end); - return false; - } - - rmp_sz =3D rmp_end - rmp_base + 1; - - probed_rmp_base =3D rmp_base; - probed_rmp_size =3D rmp_sz; - - pr_info("RMP table physical range [0x%016llx - 0x%016llx]\n", - rmp_base, rmp_end); - - return true; -} - static void __init __snp_fixup_e820_tables(u64 pa) { if (IS_ALIGNED(pa, PMD_SIZE)) @@ -291,6 +261,36 @@ static int __init snp_rmptable_init(void) */ device_initcall(snp_rmptable_init); =20 +#define RMP_ADDR_MASK GENMASK_ULL(51, 13) + +bool snp_probe_rmptable_info(void) +{ + u64 rmp_sz, rmp_base, rmp_end; + + rdmsrl(MSR_AMD64_RMP_BASE, rmp_base); + rdmsrl(MSR_AMD64_RMP_END, rmp_end); + + if (!(rmp_base & RMP_ADDR_MASK) || !(rmp_end & RMP_ADDR_MASK)) { + pr_err("Memory for the RMP table has not been reserved by BIOS\n"); + return false; + } + + if (rmp_base > rmp_end) { + pr_err("RMP configuration not valid: base=3D%#llx, end=3D%#llx\n", rmp_b= ase, rmp_end); + return false; + } + + rmp_sz =3D rmp_end - rmp_base + 1; + + probed_rmp_base =3D rmp_base; + probed_rmp_size =3D rmp_sz; + + pr_info("RMP table physical range [0x%016llx - 0x%016llx]\n", + rmp_base, rmp_end); + + return true; +} + static struct rmpentry_raw *get_raw_rmpentry(u64 pfn) { if (!rmptable) --=20 2.46.2 From nobody Wed Dec 4 18:50:58 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2060.outbound.protection.outlook.com [40.107.244.60]) (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 26D641DF266 for ; Mon, 2 Dec 2024 20:51:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172707; cv=fail; b=UTJ+GxJNDO1s+AiMsB6fIy/ee7dYzPnibE5/rTJyTEErGAbmNS0QdyBHgame1/lDitpQgqI9pWX/BUxdhjRmj/jIwm0DxBtP3VYGpf0x3c9dHQEA+mJFtg8qmq1zElUjTM2fj20Jkn+C3EwK61+UoIzifVscW1x6tnOhvst/EaY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172707; c=relaxed/simple; bh=R7FZMAxV1py2pxLIQc/aw4SUmvXARIlzGiAPk4x36VM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ru0SfFIYvH67YzDdhu5RfmGuebfMnX6z0rC8sCBqD0yYth0wQOFxKWrRfmssvSXVXucuaEkzqLWmIN4TdHJWTheVx6daucEUF8rbFb3kYYbTuBaUQjZvB/MpwW6+v813LHg2uRQRIgoUVeZ47VmCNBvPtVMAW7SqPeEluTlZB0Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=KdsuaPoC; arc=fail smtp.client-ip=40.107.244.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="KdsuaPoC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=m7/VoVxLN1QlAjwRd5xhKgHjql5SV1ZIGnMqYX7iIuV77OhuwCHOzZUoXvro2QVyQWhdqGnPWsx7rc5kavN0lHFFl/rlSciozNQB1Xcl9QZKx7WeljrTOkrSco2EGLnWXijwn1Ipddkm41fUu+udNTjcMhEgZQ1J523W6Bg6aH50yce0bSQZdSVj3QzXZ6Q6BgyHVd0/Zw8MGh/nBi+VpQpjaSil/+m1saWpFdJcMvxb/Z4sGzXQjaPNAFx6v87rDaw1Gp2JdOpPbJQwmGxIvUAPnohBzFcnB59FvsvT/ml0fUCsDuziU5Urk9JJJrudwJJRuIwG8hjPkSMAqjIl+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oK3cl4nfjFMwtSCtIczcQcTxoIT+Q+2URiAsbAwhDtI=; b=FFaAPWPz7lC4bmkKuwJun08A1FqBL8zLak/fJcXHIdIVaIOQ2wzV25usQzJh4e5li5gNbOdkOqsGPK8YnTqyNx3lr5Lhuu/dkZCARkQfM0NgH5XkDYiJodq2uuifAreSkc9aqq3odQ6aqpZfYV9cIWUQLrxditbsVtING3ZfQmeih1bAmFTA4lKwihMo/j1XdIX6+F0U73WFkXhGyGMjC/QsKAFgDh26wZ876zxDRE9QLHI7Q8cNz7v9G7UUifSNJ/i217Lh4VGdB+jzUfHb1XbqcIfZz64GkMtCPnOKPWIWefFOLMJvdOIUOrreB06tSJD8YhFnDbbxZvsqyBaGzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oK3cl4nfjFMwtSCtIczcQcTxoIT+Q+2URiAsbAwhDtI=; b=KdsuaPoCS1BF5QnLACqgHJ5INht/1B2afavJa/ZINjgMlTaa3dOHhAlT21cNVrVxZvBPl49NSl6PDKemOnIl5iGgMuY4ZNA/tVmCtg5XlNkAKL2qceGAguoq3injC4Vgf2vQGAIsfFDuolPWxzHna+0WXD3fm34ur6/UG33+W54= Received: from SN7PR18CA0014.namprd18.prod.outlook.com (2603:10b6:806:f3::26) by MN0PR12MB5809.namprd12.prod.outlook.com (2603:10b6:208:375::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Mon, 2 Dec 2024 20:51:42 +0000 Received: from SA2PEPF00001504.namprd04.prod.outlook.com (2603:10b6:806:f3:cafe::57) by SN7PR18CA0014.outlook.office365.com (2603:10b6:806:f3::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.18 via Frontend Transport; Mon, 2 Dec 2024 20:51:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF00001504.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Mon, 2 Dec 2024 20:51:41 +0000 Received: from tlendack-t1.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 2 Dec 2024 14:51:40 -0600 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra , Nikunj A Dadhania , Neeraj Upadhyay Subject: [PATCH v6 5/8] x86/sev: Map only the RMP table entries instead of the full RMP range Date: Mon, 2 Dec 2024 14:50:50 -0600 Message-ID: <22f179998d319834f49c13a8c01187fbf0fd308d.1733172653.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001504:EE_|MN0PR12MB5809:EE_ X-MS-Office365-Filtering-Correlation-Id: c7c3c524-8394-43d0-51dd-08dd13132016 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?ZwjUcjK2fpeJC8N/AbkCWkppvkqJCnVXLARme+Mef3RefZ+nqEibGfn0eIQL?= =?us-ascii?Q?EMbK89c4KvprGbu44whfBJodExBI0M788dAijzoDDVJAMFX/0AoCWjBJi9y0?= =?us-ascii?Q?ur9svP/OA6dGv+7kDJxH1rIoaMqFqSbrYm1pGbrHy9nsiMNZLI9fhs3EfEOV?= =?us-ascii?Q?ZsvpeHwrp5nCgFOzyH1FaLc+NPAQmzj30xg4wReq6MvJu4oN6lMXdNBq/sL2?= =?us-ascii?Q?+fiXM5QqPUYKbCXPCIMuggisAsK4M3CloBXpyLDkAfCZcY7S7hsqj1QIYG7Y?= =?us-ascii?Q?HcPWqWQJcCl9zeUd6u26xDkJEodsQyHIl24mHYp1NURQYraCNA/F0Di+vRru?= =?us-ascii?Q?nYSlXVgSyNzdgACYob5oDieQY5dxhrYEtIWfQNDqrOZ4xaUWugLYAirrovXj?= =?us-ascii?Q?UsLDx3L1lCPBzW1NmrXy39ayUgFUqA1p1o+53Rw1i/IQx2KwDgf7bDOr5vlr?= =?us-ascii?Q?guqcILwHIMFBXV/BdRfIdg/NBw5kerZ359ZoerJ7GelldDrktVLGLU683r5e?= =?us-ascii?Q?JDjwKmg6xKuHkbMGte33upX7g5XXXgKYx3P6Xva6wap+I1P+bOTGI+7lBbJi?= =?us-ascii?Q?ExEarfPABY8bD3VJIO9xg2YpR+/CvuQ21pjaBkb4fYQIIJOZ1OAbJAKDaBg2?= =?us-ascii?Q?rPL+00dqtjXa8QTn7EGgJ4K2x0iuz4WchVXYFL/tgBJytDzYPf/NTfNgoCmN?= =?us-ascii?Q?OyHs34slrsLm9sc8mZFg/nAktUzW1XapyYQ27ZjfpBHmk5N7y4CbMdBukZA0?= =?us-ascii?Q?GDC4eboMbHGnwG7Xp2aUZx6NdQz0bz7GUU2jExZdI8z990ghKJDkfTn6o1zH?= =?us-ascii?Q?IkNv69lyhf80o8xUj5skln7oWIXs2RGdvVEnLmXKq5p9LcN2tJtskous6pmA?= =?us-ascii?Q?6OhW5r+fP8fo6tU1Gl7H2bs292vPSrLg9aEBewKIT+m4g4a40FUf++2kkNZl?= =?us-ascii?Q?AaxUWtiTIOephpXLqMecGbhii2qAuUZP/bMCI8Gdi/Pw9s7GxG497B1X0ANR?= =?us-ascii?Q?S1hx0QrTAH0naXLEGf+CRyPUsaRE5iO+re9Ky0oQCkBukMY+ACHwdOWg5+f1?= =?us-ascii?Q?LY4yEv/VfpxD1NFNZa8Ev2H8oSsZMFG07lvLdSaG3h3utGBMfKPQE27+2L31?= =?us-ascii?Q?snAiGowXFpaPVK0+i5w+gN6dcwSe3YPvdkThjAjhCK84LEAkxnb5U5LdBpoN?= =?us-ascii?Q?bNKOJwy3d6iRWLZvPWGfYLgjsinadeR9vmQ2fnQHOtzx/XMlALGmCit0olu1?= =?us-ascii?Q?Ex+/dk//ZsmoH2CdbHWTpqv/CcZSwnt845vWmExO0jl10qT7/VEkBs3Kgv3Y?= =?us-ascii?Q?rxOJZBy0vsdned6nxyoQ9Th9LOgzkKmG9oyZTGAdPPk96W9EFmtRzc8jBLgk?= =?us-ascii?Q?rXnK96WrbzRzbE3Jh/UHe5VXhJgsu73l3iGoFky58S+zJj+MxF0VfE3UuLpX?= =?us-ascii?Q?bH0M2XtlX4V+SZW4I+Y/lNsCEDFjGVa6?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2024 20:51:41.9337 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c7c3c524-8394-43d0-51dd-08dd13132016 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001504.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5809 Content-Type: text/plain; charset="utf-8" In preparation for support of a segmented RMP table, map only the RMP table entries. The RMP bookkeeping area is only ever accessed when first enabling SNP and does not need to remain mapped. To accomplish this, split the initialization of the RMP bookkeeping area and the initialization of the RMP entry area. The RMP bookkeeping area will be mapped only while it is being initialized. Signed-off-by: Tom Lendacky Reviewed-by: Nikunj A Dadhania Reviewed-by: Neeraj Upadhyay Reviewed-by: Ashish Kalra --- arch/x86/virt/svm/sev.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 0df378951ac7..2899c2e28db9 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -173,6 +173,23 @@ void __init snp_fixup_e820_tables(void) __snp_fixup_e820_tables(probed_rmp_base + probed_rmp_size); } =20 +static bool __init clear_rmptable_bookkeeping(void) +{ + void *bk; + + bk =3D memremap(probed_rmp_base, RMPTABLE_CPU_BOOKKEEPING_SZ, MEMREMAP_WB= ); + if (!bk) { + pr_err("Failed to map RMP bookkeeping area\n"); + return false; + } + + memset(bk, 0, RMPTABLE_CPU_BOOKKEEPING_SZ); + + memunmap(bk); + + return true; +} + /* * Do the necessary preparations which are verified by the firmware as * described in the SNP_INIT_EX firmware command description in the SNP @@ -210,12 +227,17 @@ static int __init snp_rmptable_init(void) goto nosnp; } =20 - rmptable_start =3D memremap(probed_rmp_base, probed_rmp_size, MEMREMAP_WB= ); + /* Map only the RMP entries */ + rmptable_start =3D memremap(probed_rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ, + probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ, + MEMREMAP_WB); if (!rmptable_start) { pr_err("Failed to map RMP table\n"); goto nosnp; } =20 + rmptable_size =3D probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ; + /* * Check if SEV-SNP is already enabled, this can happen in case of * kexec boot. @@ -224,7 +246,14 @@ static int __init snp_rmptable_init(void) if (val & MSR_AMD64_SYSCFG_SNP_EN) goto skip_enable; =20 - memset(rmptable_start, 0, probed_rmp_size); + /* Zero out the RMP bookkeeping area */ + if (!clear_rmptable_bookkeeping()) { + memunmap(rmptable_start); + goto nosnp; + } + + /* Zero out the RMP entries */ + memset(rmptable_start, 0, rmptable_size); =20 /* Flush the caches to ensure that data is written before SNP is enabled.= */ wbinvd_on_all_cpus(); @@ -235,9 +264,6 @@ static int __init snp_rmptable_init(void) on_each_cpu(snp_enable, NULL, 1); =20 skip_enable: - rmptable_start +=3D RMPTABLE_CPU_BOOKKEEPING_SZ; - rmptable_size =3D probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ; - rmptable =3D (struct rmpentry_raw *)rmptable_start; rmptable_max_pfn =3D rmptable_size / sizeof(struct rmpentry_raw) - 1; =20 --=20 2.46.2 From nobody Wed Dec 4 18:50:58 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2045.outbound.protection.outlook.com [40.107.236.45]) (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 E41631DEFE6 for ; Mon, 2 Dec 2024 20:51:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172717; cv=fail; b=OY5OH9BYL5ODRieygbI4t5IuW5p3k+LQfu26+LV9nHQg1V+dVWUsNrs/aHpPi2PPGQpHvc3WrT6QE2ZIUQ6rkdg5gHeirTIoJqa/Rxew2nmvnIiHbMJ5sJ/d/E4283XXBdFGiwbad1NcT9FFLqp/bu2/JYxWcN1t6lEehGfuX+I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172717; c=relaxed/simple; bh=sFy40V0xq4Dc4DbXbq3WDZV8uDXzBfKvZUUAoLB2R0o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sKnNvPnXUVSCCOK0o/q9RvfHtWVqVP+sdzdrJqsYkb72sGweWeQGcKZ0O/ZeGC0eaGIi1MEG9+fV5g4GMHQq6vHqwMHSPhWI2RzpkOAAHlHIwG9/gQhF2oYHZvXDb7IQzyFoyosfY2Z8S6AjJqE6yUfo3gBRxqD1bwRI86rpUGo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=hxzb/2NJ; arc=fail smtp.client-ip=40.107.236.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="hxzb/2NJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yTEEX/zsFmzM8tlrifYrcOkrC4hVF7DjcPZ3E4qFXJ1ZT4NsBRyAlzMDeO/EsgWsFqqrkx5lGrgTAZ4jYT/6cWR+jMDOsYfcL36mtqk9harEmYQCw4fwBGerqyQtX1v5oGH/nHLe6b5ySeYsunMtW5A59K4ib2ESakPtQxkDbzIyP8H1Z0aLuqpYsuzbZye5YETA0vAJRd32fB9fHepbLWfvAhl3nFhLVQfjE8TWugLBxLZ66ojQcMGMg9rNO5mIidr2vUU6HxUcsPF1y1GdIrTe3DSAZjXO/zWluJzQy/srek20ViQm5QiUgOaFKDjL4A76I0ZueIfNaNUA04qV8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gNj+8Ot0GGzC83vES43VL0kj+x73zmUX3GPb22ieG3U=; b=wcVLGRPwIHlpWmSQDzMBuUtMa1HWwclRHZFw2G6OP2Q6tK5GKgOVH0/HecxOWOR8m1mr1gJEdJ899OUxAU/C43iwtsIFBYB/0ecTvv5krZpnS5J1+0BvzwUScmmcEqfLhq/QMi7aG7qhR43+Bxu9wUvrkkNxQc6nsmuUueEzXIcsEAZlrWhLdJgc/kdOx7VZHFk/6viufU4XvJxWrslyetGIZK/rEpeQiMfofRzPGu8sgu3tWi/UyFX7nMUQql+a9z/QHKOg8VexrkpZutfQiWtfWOElffJrwPVCa3FYswh2fRoY15tbDhuob2iOtVDDofhGFiJqtP7fnL1ilMH9wg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gNj+8Ot0GGzC83vES43VL0kj+x73zmUX3GPb22ieG3U=; b=hxzb/2NJcxCbq4YITMkWVsYv4m5FPYpmxZYg7+8urpwhW70OQjw9Ycnu+lK5MS0X+wyB9SN8f8RE2x5w1o142x+5zFJM15p2hNyFGEA8k9Scrk+KmT77VIlbbH8Qr+ITHTl7+RF/aE2cAU7ylBziLdft2e+P0jEXsuQT4WcOO/0= Received: from SA1PR04CA0006.namprd04.prod.outlook.com (2603:10b6:806:2ce::6) by MW4PR12MB7237.namprd12.prod.outlook.com (2603:10b6:303:22a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.14; Mon, 2 Dec 2024 20:51:49 +0000 Received: from SA2PEPF00001506.namprd04.prod.outlook.com (2603:10b6:806:2ce:cafe::ec) by SA1PR04CA0006.outlook.office365.com (2603:10b6:806:2ce::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.16 via Frontend Transport; Mon, 2 Dec 2024 20:51:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF00001506.mail.protection.outlook.com (10.167.242.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Mon, 2 Dec 2024 20:51:49 +0000 Received: from tlendack-t1.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 2 Dec 2024 14:51:48 -0600 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra , Nikunj A Dadhania , Neeraj Upadhyay Subject: [PATCH v6 6/8] x86/sev: Treat the contiguous RMP table as a single RMP segment Date: Mon, 2 Dec 2024 14:50:51 -0600 Message-ID: <8c40fbc9c5217f0d79b37cf861eff03ab0330bef.1733172653.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001506:EE_|MW4PR12MB7237:EE_ X-MS-Office365-Filtering-Correlation-Id: dd968c7d-eccd-415e-515c-08dd13132472 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?63U/6jD5vdjxSTNdrfX0Ky0hbG8dIvOo/QtoDzVUy0w8iDw2XMxAKn87boYf?= =?us-ascii?Q?L0p7aPAwG9IO5Wp+8O4c5JOnWZMtXg6oWfLRhqShx6SeyGCKQFAUtrv680Ha?= =?us-ascii?Q?rGGQcLQFUejD4ie55sVAmRkD2gg5WypYUeuBAn9jyRkOxDpReit4r5KCO+dy?= =?us-ascii?Q?wv0z+RfZo+3bpvNPpZQCvGGwNomST2JMHkUUl8bs60hzur4kuvxTyHmoItze?= =?us-ascii?Q?oIYFRm82meoBkTH7TT7+HwiYAtEAGvhIfZsreJ8Sot4OFPNOYjmMwCublrGK?= =?us-ascii?Q?ZVGrcRspFzWHccMBy3/iQ/K5evaU3HUowH2FL5Tkvk6oykS1fhKvBenk3Fol?= =?us-ascii?Q?X0dXqfZFWIQHXbneyXmEPPzC38rf0nWTmoYILJTu7qsN1oI+YK6Ysx9K/8sV?= =?us-ascii?Q?7uj4OHF1KbQc+xqAx3lGUZJxpH1uLZcOFcFPhnCmkHjPtKqlavd4P1Tx1VjP?= =?us-ascii?Q?N13ani+JkC8l2zOnvgr5aYS3XGKrt7CcV2MNUsw2XWrXpEFrF92l/hK1f31t?= =?us-ascii?Q?M7nsoBjh5mCdf925Trv3IHyUjlqc/KBj7O5tYSJb/AY2PVf8nPgJUnox0wo4?= =?us-ascii?Q?axiitouoaMWijShfLCyzX0geoD2xvTU9DTxKk0bPqEiav2u8p+bLW3ulpPmU?= =?us-ascii?Q?zj3fvXqHdBLU/4pBs4WR/cYmEsznHtOqM4GcYG7FqERymCEMewmmNgfzRs80?= =?us-ascii?Q?T8SAAq3ihJeT64aKZpAwcTW+YtMlI7uCoDoL0sYDadX0qt0GshgoSKtvejg7?= =?us-ascii?Q?zjD10ZcFaxdL32dmUgWjGWMXXoTemyGBxWgtjkhkVqrAQ7fdyeKj9iuE4PWC?= =?us-ascii?Q?CMTrfxV32Xsyuv3F6xqnOGuhZMCun3p6ni84YvSbyatXloKQk6t05fGlJIWC?= =?us-ascii?Q?dl7CvYILPkoMq98HlyTuqR4KCJteL//kgScmfkaA4VuWzlIWaZFubPZPveiG?= =?us-ascii?Q?GZznFJLc5EE070OyZxM5T9YjEei4aoBm7D/y9hqhG1SIoK1jB9MgV+Qxphu/?= =?us-ascii?Q?kx4Jn2gfUa3Civ+XsSFZrTEKfDNv2U7BlMux3a9YQDmTOcQBY/2AFUL0m7TX?= =?us-ascii?Q?oL3PbGyGPNcYoh7fy+c+LnFWj6W9NiC/2rIyXuAY2adSIT5i6CjCxx2HaYuP?= =?us-ascii?Q?Wm+JQboYGgkUyMf7GhTeF2zzsuY/M+SC2PnFDZgJ95zC9ZhLM/DdQqIVY3C4?= =?us-ascii?Q?Nl5zBdYiITSWmfH3kpVgLYPnMetmYzOeuc4Ma7OinW3j5EaAgYuETWmuJ5Ve?= =?us-ascii?Q?/rHKGI+/wbuTFK5WszPLThwis9klqeXhGUJwCUfe5s5XGFQg7+NTq6VZD/5C?= =?us-ascii?Q?fJy1vUMdntM+71qXQRBAtOYuFbPysIvLA3vExdhimRofzy9vlXIBlWsGOZF0?= =?us-ascii?Q?4gGnZKcaC94C8Kf1R/fJ2bGWs9rwBH9iCKSqep/ouBgWy62jQpNGUd1TBHiu?= =?us-ascii?Q?NWpnorJKEUxADmsujhTFR1oUIei0bzgq?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2024 20:51:49.1694 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd968c7d-eccd-415e-515c-08dd13132472 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001506.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7237 Content-Type: text/plain; charset="utf-8" In preparation for support of a segmented RMP table, treat the contiguous RMP table as a segmented RMP table with a single segment covering all of memory. By treating a contiguous RMP table as a single segment, much of the code that initializes and accesses the RMP can be re-used. Segmented RMP tables can have up to 512 segment entries. Each segment will have metadata associated with it to identify the segment location, the segment size, etc. The segment data and the physical address are used to determine the index of the segment within the table and then the RMP entry within the segment. For an actual segmented RMP table environment, much of the segment information will come from a configuration MSR. For the contiguous RMP, though, much of the information will be statically defined. Signed-off-by: Tom Lendacky Reviewed-by: Nikunj A Dadhania Reviewed-by: Neeraj Upadhyay --- arch/x86/virt/svm/sev.c | 190 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 171 insertions(+), 19 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 2899c2e28db9..3272a73d3594 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -18,6 +18,7 @@ #include #include #include +#include =20 #include #include @@ -77,12 +78,41 @@ struct rmpentry_raw { */ #define RMPTABLE_CPU_BOOKKEEPING_SZ 0x4000 =20 +/* + * For a non-segmented RMP table, use the maximum physical addressing as t= he + * segment size in order to always arrive at index 0 in the table. + */ +#define RMPTABLE_NON_SEGMENTED_SHIFT 52 + +struct rmp_segment_desc { + struct rmpentry_raw *rmp_entry; + u64 max_index; + u64 size; +}; + +/* + * Segmented RMP Table support. + * - The segment size is used for two purposes: + * - Identify the amount of memory covered by an RMP segment + * - Quickly locate an RMP segment table entry for a physical address + * + * - The RMP segment table contains pointers to an RMP table that covers + * a specific portion of memory. There can be up to 512 8-byte entries, + * one pages worth. + */ +static struct rmp_segment_desc **rmp_segment_table __ro_after_init; +static unsigned int rst_max_index __ro_after_init =3D 512; + +static unsigned int rmp_segment_shift; +static u64 rmp_segment_size; +static u64 rmp_segment_mask; +#define RST_ENTRY_INDEX(x) ((x) >> rmp_segment_shift) +#define RMP_ENTRY_INDEX(x) ((u64)(PHYS_PFN((x) & rmp_segment_mask))) + /* Mask to apply to a PFN to get the first PFN of a 2MB page */ #define PFN_PMD_MASK GENMASK_ULL(63, PMD_SHIFT - PAGE_SHIFT) =20 static u64 probed_rmp_base, probed_rmp_size; -static struct rmpentry_raw *rmptable __ro_after_init; -static u64 rmptable_max_pfn __ro_after_init; =20 static LIST_HEAD(snp_leaked_pages_list); static DEFINE_SPINLOCK(snp_leaked_pages_list_lock); @@ -190,6 +220,94 @@ static bool __init clear_rmptable_bookkeeping(void) return true; } =20 +static bool __init alloc_rmp_segment_desc(u64 segment_pa, u64 segment_size= , u64 pa) +{ + u64 rst_index, rmp_segment_size_max; + struct rmp_segment_desc *desc; + void *rmp_segment; + + /* Calculate the maximum size an RMP can be (16 bytes/page mapped) */ + rmp_segment_size_max =3D PHYS_PFN(rmp_segment_size); + rmp_segment_size_max <<=3D 4; + + /* Validate the RMP segment size */ + if (segment_size > rmp_segment_size_max) { + pr_err("Invalid RMP size (%#llx) for configured segment size (%#llx)\n", + segment_size, rmp_segment_size_max); + return false; + } + + /* Validate the RMP segment table index */ + rst_index =3D RST_ENTRY_INDEX(pa); + if (rst_index >=3D rst_max_index) { + pr_err("Invalid RMP segment base address (%#llx) for configured segment = size (%#llx)\n", + pa, rmp_segment_size); + return false; + } + + if (rmp_segment_table[rst_index]) { + pr_err("RMP segment descriptor already exists at index %llu\n", rst_inde= x); + return false; + } + + rmp_segment =3D memremap(segment_pa, segment_size, MEMREMAP_WB); + if (!rmp_segment) { + pr_err("Failed to map RMP segment addr 0x%llx size 0x%llx\n", + segment_pa, segment_size); + return false; + } + + desc =3D kzalloc(sizeof(*desc), GFP_KERNEL); + if (!desc) { + memunmap(rmp_segment); + return false; + } + + desc->rmp_entry =3D rmp_segment; + desc->max_index =3D segment_size / sizeof(*desc->rmp_entry); + desc->size =3D segment_size; + + /* Add the segment descriptor to the table */ + rmp_segment_table[rst_index] =3D desc; + + return true; +} + +static void __init free_rmp_segment_table(void) +{ + unsigned int i; + + for (i =3D 0; i < rst_max_index; i++) { + struct rmp_segment_desc *desc; + + desc =3D rmp_segment_table[i]; + if (!desc) + continue; + + memunmap(desc->rmp_entry); + + kfree(desc); + } + + free_page((unsigned long)rmp_segment_table); + + rmp_segment_table =3D NULL; +} + +static bool __init alloc_rmp_segment_table(void) +{ + struct page *page; + + /* Allocate the table used to index into the RMP segments */ + page =3D alloc_page(__GFP_ZERO); + if (!page) + return false; + + rmp_segment_table =3D page_address(page); + + return true; +} + /* * Do the necessary preparations which are verified by the firmware as * described in the SNP_INIT_EX firmware command description in the SNP @@ -197,8 +315,8 @@ static bool __init clear_rmptable_bookkeeping(void) */ static int __init snp_rmptable_init(void) { - u64 max_rmp_pfn, calc_rmp_sz, rmptable_size, rmp_end, val; - void *rmptable_start; + u64 max_rmp_pfn, calc_rmp_sz, rmptable_segment, rmptable_size, rmp_end, v= al; + unsigned int i; =20 if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) return 0; @@ -227,17 +345,18 @@ static int __init snp_rmptable_init(void) goto nosnp; } =20 + if (!alloc_rmp_segment_table()) + goto nosnp; + /* Map only the RMP entries */ - rmptable_start =3D memremap(probed_rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ, - probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ, - MEMREMAP_WB); - if (!rmptable_start) { - pr_err("Failed to map RMP table\n"); + rmptable_segment =3D probed_rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ; + rmptable_size =3D probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ; + + if (!alloc_rmp_segment_desc(rmptable_segment, rmptable_size, 0)) { + free_rmp_segment_table(); goto nosnp; } =20 - rmptable_size =3D probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ; - /* * Check if SEV-SNP is already enabled, this can happen in case of * kexec boot. @@ -248,12 +367,20 @@ static int __init snp_rmptable_init(void) =20 /* Zero out the RMP bookkeeping area */ if (!clear_rmptable_bookkeeping()) { - memunmap(rmptable_start); + free_rmp_segment_table(); goto nosnp; } =20 /* Zero out the RMP entries */ - memset(rmptable_start, 0, rmptable_size); + for (i =3D 0; i < rst_max_index; i++) { + struct rmp_segment_desc *desc; + + desc =3D rmp_segment_table[i]; + if (!desc) + continue; + + memset(desc->rmp_entry, 0, desc->size); + } =20 /* Flush the caches to ensure that data is written before SNP is enabled.= */ wbinvd_on_all_cpus(); @@ -264,9 +391,6 @@ static int __init snp_rmptable_init(void) on_each_cpu(snp_enable, NULL, 1); =20 skip_enable: - rmptable =3D (struct rmpentry_raw *)rmptable_start; - rmptable_max_pfn =3D rmptable_size / sizeof(struct rmpentry_raw) - 1; - cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/rmptable_init:online", __snp_= enable, NULL); =20 /* @@ -287,6 +411,13 @@ static int __init snp_rmptable_init(void) */ device_initcall(snp_rmptable_init); =20 +static void set_rmp_segment_info(unsigned int segment_shift) +{ + rmp_segment_shift =3D segment_shift; + rmp_segment_size =3D 1ULL << rmp_segment_shift; + rmp_segment_mask =3D rmp_segment_size - 1; +} + #define RMP_ADDR_MASK GENMASK_ULL(51, 13) =20 bool snp_probe_rmptable_info(void) @@ -308,6 +439,11 @@ bool snp_probe_rmptable_info(void) =20 rmp_sz =3D rmp_end - rmp_base + 1; =20 + /* Treat the contiguous RMP table as a single segment */ + rst_max_index =3D 1; + + set_rmp_segment_info(RMPTABLE_NON_SEGMENTED_SHIFT); + probed_rmp_base =3D rmp_base; probed_rmp_size =3D rmp_sz; =20 @@ -319,13 +455,29 @@ bool snp_probe_rmptable_info(void) =20 static struct rmpentry_raw *get_raw_rmpentry(u64 pfn) { - if (!rmptable) + u64 paddr, rst_index, segment_index; + struct rmp_segment_desc *desc; + + if (!rmp_segment_table) return ERR_PTR(-ENODEV); =20 - if (unlikely(pfn > rmptable_max_pfn)) + paddr =3D pfn << PAGE_SHIFT; + + rst_index =3D RST_ENTRY_INDEX(paddr); + if (unlikely(rst_index >=3D rst_max_index)) + return ERR_PTR(-EFAULT); + rst_index =3D array_index_nospec(rst_index, rst_max_index); + + desc =3D rmp_segment_table[rst_index]; + if (unlikely(!desc)) return ERR_PTR(-EFAULT); =20 - return rmptable + pfn; + segment_index =3D RMP_ENTRY_INDEX(paddr); + if (unlikely(segment_index >=3D desc->max_index)) + return ERR_PTR(-EFAULT); + segment_index =3D array_index_nospec(segment_index, desc->max_index); + + return desc->rmp_entry + segment_index; } =20 static int get_rmpentry(u64 pfn, struct rmpentry *e) --=20 2.46.2 From nobody Wed Dec 4 18:50:58 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062.outbound.protection.outlook.com [40.107.244.62]) (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 B90DC1DF247 for ; Mon, 2 Dec 2024 20:52:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172728; cv=fail; b=sAMHob9j8yDoVDTRth5uSUYaE/sigMtLFKMlqowso0zKH9CGqc/Zr3BcmRPHflWJBsJiSz16u1kIES87KV96GjkckZ9uLUT9adnYPtQ5qtjYnKZJS+l6l4lmup6repC4vuFjI1gx1pEBJc9vn8xWjj2qpcm22Hm00aObwgZ6oLM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172728; c=relaxed/simple; bh=bT+jYdSv8ptBK7RmSpaPunwKh2YhisbiKP59s+O9uow=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gdCa0uFFRlggj/LHqLk8+JhHDcV9zcxtMbEcWyerdHtx0zhshRQt/V38NnPu4C5JyEzm2SN/biN75aRdwNHPLq2OLuc4/4euhN8xDXHjqGsL7BTQdjR9q2lqpJ6JOL6KqSjETz5xVBLLXS2CzymUwoO4eKcWhPRO2fqra0VOsYA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=26mTZsI1; arc=fail smtp.client-ip=40.107.244.62 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="26mTZsI1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BUj9T42Fn0h3f2anLMoH1gemBiw7QvM60EMYd/NYNS7MRVuCbdJ6dgwoT66SMO7i5fu2NvZutFqtD8GS8n0PWOBDd1YB6X9STmZ4f/FIk7g7mh9VeB5PjnUu31RNa8yk5eRZZWukisC4D4Qv6SvCGIaF55EnhOKl3opewgf7kN7qMCR6hG8wDy4cukkInu3u/lsq9jAaxLYRBkXUDZ9/oir4fDbgvaXQUL8JwIcDRdg/YjhuOLnn6tHvC4ZaGG1CEa4Hni2d0Yx4C6AunJeOe4IsxodMEp66k5iQ4Y6LCmsb7NyBjZfpUt2LZhLmKK9VQ36YAn70P+YG/9e3Rrx/jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+G3P+kN20DMYVe8Patr1z0PqKEQE00PHXl6MS+9/a/w=; b=Ob2v2FXVMC9mKS0/Ssu8Hnvfi4qoPX3esKZYc1hacXK5eNyYPVwX9qIwh4o8Y1yun4CryaZeCtT5+OqHZUhLwhyLhcU48Hjsipx1n562pvo+01OEAUlMZ0F9IIkSzcSHID4PmUYVzNVcctuJHMXlhe845nLFWas9F+sjN1fqeiVlI2SyVcXfpnIzhPfADjm31YuHtIyKWVkSmqxlvzdmn/JbFS8J0VWg0XZHxggvXZe3AxnQtZQ78eI3TigE63jdwQpTdmr0cJW+vhBtBXPARvF+p5guYzt/0ck15JZTknNVvcu57ENgv9ThJuSOWFxphbEq9L1a9FOC8U7Ac5sb5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+G3P+kN20DMYVe8Patr1z0PqKEQE00PHXl6MS+9/a/w=; b=26mTZsI1+18qub9Si1JsQRv+hxqR7tokcvgYoZIfZOw1XxygitsHTj0RIHdw7141maXIRsV63tptlLs9KOh3FN55VIQyBVXw27QpWmpjAzydtyX8Slsif0RdrSjpYsH1gPabvhHj51zsEZ0/LWEIFw6CSR2zAqzoQSt5vNz1WRY= Received: from SN7PR04CA0114.namprd04.prod.outlook.com (2603:10b6:806:122::29) by PH7PR12MB8013.namprd12.prod.outlook.com (2603:10b6:510:27c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Mon, 2 Dec 2024 20:51:56 +0000 Received: from SA2PEPF00001509.namprd04.prod.outlook.com (2603:10b6:806:122:cafe::73) by SN7PR04CA0114.outlook.office365.com (2603:10b6:806:122::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.17 via Frontend Transport; Mon, 2 Dec 2024 20:51:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF00001509.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Mon, 2 Dec 2024 20:51:56 +0000 Received: from tlendack-t1.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 2 Dec 2024 14:51:55 -0600 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra , Nikunj A Dadhania , Neeraj Upadhyay Subject: [PATCH v6 7/8] x86/sev: Add full support for a segmented RMP table Date: Mon, 2 Dec 2024 14:50:52 -0600 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001509:EE_|PH7PR12MB8013:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ad240e4-9fa5-45f3-ec39-08dd131328b7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?O1p+KABUnzf4DDkkUp13xqF36SUDWzL9g24PmgLZmXh48aUMT7c4CdB4H/uj?= =?us-ascii?Q?7KPpHVJBINiRcKRICn+2FS3NngVQwqvMLno5exgQ/DPXkBNJSKXnwYjHm63B?= =?us-ascii?Q?t/cun4uyyg7jB2ZEl8nVkJ91sdb+1v/rooxAWZvby4xorArp8m3znxeWv3Y6?= =?us-ascii?Q?6lF1EYhPXtvXzGmI7CMzb+yLdqrryW+XbdgTJff2SwZ9n+x7vNXWgo4DdjE9?= =?us-ascii?Q?b1StEK27EJ9Sptd4Tbv2jXHYeAIy1XFrKyqvXtb6bJh7vyx/XhzNDukr2p0O?= =?us-ascii?Q?zQCBg8YccJjaZg4xYbrElyWqPh+xy25x6jR+LdhokCnjenpOoLm8McsR2qyX?= =?us-ascii?Q?Ko4LVywKiNxWgebmQazD07GFwY8MF1iOoGTSgM19K8HuDD9NArT4kI54IFYw?= =?us-ascii?Q?NfbhOl4QUrE2l+76zVB8ddKy+2Buun24JZCwQBsRia3VlT93wMJry0GNatgY?= =?us-ascii?Q?mbqxOtS2ddDV/mIhMNcyOH5G0poUdqoxCGFClqweyAtJU61TAl9/FHfMI2Uz?= =?us-ascii?Q?As4YJLiu9ZbOfbTfe4n+cF49E1fqtGvSV3kOnTRSLAzjGLRoY8MPQpEGsnj/?= =?us-ascii?Q?1ePOIfOfHeewQzmZUfX9uTgPsAymUTXLYYeHhe/qlIe/00OIXihAx4ExPk8X?= =?us-ascii?Q?tQrI7O7pEqoIGljxdHwjSnWNOLtofOuZ/Xr9Hl0JpGzLayhMYFbUi2+pUosO?= =?us-ascii?Q?aj64igpWjLQBCrQqRMVxdOT+OpJqiZF7zPBlQemFZi4hVJhtN93fUoc6rJL5?= =?us-ascii?Q?xyR1lFhba+J4OTfHiYdbTC6q7f7SwBxMLrRbQf7SSUiAfU/1UK1J5QVhEF3g?= =?us-ascii?Q?7Li2szUhbjMzaBrWk0XAsonRbB0IlZeIHaXepwOLdJlFglu2qOwsk2gWGQPm?= =?us-ascii?Q?WG9sOEJQObDF7Qk0lSohJ+BP/5L30M2V7MZm7dw50a9+tuzOuoDDxfkY/7qW?= =?us-ascii?Q?ZJP4qiW0xbxh7be5ElWr6GWIARRMwcFAWTdhvuxApFtzc5zCpNfjvW8gdFhr?= =?us-ascii?Q?vvPB9YdifZ1sdz29hlUljcWivEEPjj3soHlcPSEQQGGiMZI/5yvv0kgmwVwl?= =?us-ascii?Q?a1P78czNSAdP0ObIAORDOpB/nN4KWLD+SAPMRMtlNmtJwu9dmlGhuClmzp9C?= =?us-ascii?Q?w3qcvY4xcj9xXO6qxxLrRXK84OlqhrRrg3RjWIb5/gwEny5uCD4OqQWD/p9x?= =?us-ascii?Q?PaS9JP5V2w3/K9TChasBqxYXDzMyNqLxZMYn5Na/+0vf12OYmMOrGNLoTMl0?= =?us-ascii?Q?N1XuEygN2PTcEXAE6dOSftlHgcebk9qrgS+svXJ7GO1RJxV9WhTfecT+VlZ8?= =?us-ascii?Q?c+2RQuDzscOdfZzq0qRIl6yXh0NpX2ugYT/fqOjjjWGaojq4Re5XIce3pzmP?= =?us-ascii?Q?jh7yADMG3ZkXIzAypou6Ln8rQO2uqoY34B0BHxpPw0LP5ZeDS2ATkoiK7qEx?= =?us-ascii?Q?zcSjU46A19paSflPdL37yfLNyjnedl1F?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2024 20:51:56.4145 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3ad240e4-9fa5-45f3-ec39-08dd131328b7 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001509.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8013 Content-Type: text/plain; charset="utf-8" A segmented RMP table allows for improved locality of reference between the memory protected by the RMP and the RMP entries themselves. Add support to detect and initialize a segmented RMP table with multiple segments as configured by the system BIOS. While the RMPREAD instruction will be used to read an RMP entry in a segmented RMP, initialization and debugging capabilities will require the mapping of the segments. The RMP_CFG MSR indicates if segmented RMP support is enabled and, if enabled, the amount of memory that an RMP segment covers. When segmented RMP support is enabled, the RMP_BASE MSR points to the start of the RMP bookkeeping area, which is 16K in size. The RMP Segment Table (RST) is located immediately after the bookkeeping area and is 4K in size. The RST contains up to 512 8-byte entries that identify the location of the RMP segment and amount of memory mapped by the segment (which must be less than or equal to the configured segment size). The physical address that is covered by a segment is based on the segment size and the index of the segment in the RST. The RMP entry for a physical address is based on the offset within the segment. For example, if the segment size is 64GB (0x1000000000 or 1 << 36), then physical address 0x9000800000 is RST entry 9 (0x9000800000 >> 36) and RST entry 9 covers physical memory 0x9000000000 to 0x9FFFFFFFFF. The RMP entry index within the RMP segment is the physical address AND-ed with the segment mask, 64GB - 1 (0xFFFFFFFFF), and then right-shifted 12 bits or PHYS_PFN(0x9000800000 & 0xFFFFFFFFF), which is 0x800. CPUID 0x80000025_EBX[9:0] describes the number of RMP segments that can be cached by the hardware. Additionally, if CPUID 0x80000025_EBX[10] is set, then the number of actual RMP segments defined cannot exceed the number of RMP segments that can be cached and can be used as a maximum RST index. Signed-off-by: Tom Lendacky Reviewed-by: Nikunj A Dadhania Reviewed-by: Neeraj Upadhyay --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 8 +- arch/x86/virt/svm/sev.c | 251 ++++++++++++++++++++++++++--- 3 files changed, 236 insertions(+), 24 deletions(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index 5535edc6e8d7..6a6db7cd97cb 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -452,6 +452,7 @@ #define X86_FEATURE_SME_COHERENT (19*32+10) /* AMD hardware-enforced cache= coherency */ #define X86_FEATURE_DEBUG_SWAP (19*32+14) /* "debug_swap" AMD SEV-ES full= debug state swap support */ #define X86_FEATURE_RMPREAD (19*32+21) /* RMPREAD instruction */ +#define X86_FEATURE_SEGMENTED_RMP (19*32+23) /* Segmented RMP support */ #define X86_FEATURE_SVSM (19*32+28) /* "svsm" SVSM present */ =20 /* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word = 20 */ diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index 3ae84c3b8e6d..3f3e2bc99162 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -644,6 +644,7 @@ #define MSR_AMD64_IBS_REG_COUNT_MAX 8 /* includes MSR_AMD64_IBSBRTARGET */ #define MSR_AMD64_SVM_AVIC_DOORBELL 0xc001011b #define MSR_AMD64_VM_PAGE_FLUSH 0xc001011e +#define MSR_AMD64_VIRT_SPEC_CTRL 0xc001011f #define MSR_AMD64_SEV_ES_GHCB 0xc0010130 #define MSR_AMD64_SEV 0xc0010131 #define MSR_AMD64_SEV_ENABLED_BIT 0 @@ -682,11 +683,12 @@ #define MSR_AMD64_SNP_SMT_PROT BIT_ULL(MSR_AMD64_SNP_SMT_PROT_BIT) #define MSR_AMD64_SNP_RESV_BIT 18 #define MSR_AMD64_SNP_RESERVED_MASK GENMASK_ULL(63, MSR_AMD64_SNP_RESV_BIT) - -#define MSR_AMD64_VIRT_SPEC_CTRL 0xc001011f - #define MSR_AMD64_RMP_BASE 0xc0010132 #define MSR_AMD64_RMP_END 0xc0010133 +#define MSR_AMD64_RMP_CFG 0xc0010136 +#define MSR_AMD64_SEG_RMP_ENABLED_BIT 0 +#define MSR_AMD64_SEG_RMP_ENABLED BIT_ULL(MSR_AMD64_SEG_RMP_ENABLED_BIT) +#define MSR_AMD64_RMP_SEGMENT_SHIFT(x) (((x) & GENMASK_ULL(13, 8)) >> 8) =20 #define MSR_SVSM_CAA 0xc001f000 =20 diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 3272a73d3594..31d653db830a 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -100,6 +100,10 @@ struct rmp_segment_desc { * a specific portion of memory. There can be up to 512 8-byte entries, * one pages worth. */ +#define RST_ENTRY_MAPPED_SIZE(x) ((x) & GENMASK_ULL(19, 0)) +#define RST_ENTRY_SEGMENT_BASE(x) ((x) & GENMASK_ULL(51, 20)) + +#define RMP_SEGMENT_TABLE_SIZE SZ_4K static struct rmp_segment_desc **rmp_segment_table __ro_after_init; static unsigned int rst_max_index __ro_after_init =3D 512; =20 @@ -109,6 +113,9 @@ static u64 rmp_segment_mask; #define RST_ENTRY_INDEX(x) ((x) >> rmp_segment_shift) #define RMP_ENTRY_INDEX(x) ((u64)(PHYS_PFN((x) & rmp_segment_mask))) =20 +static u64 rmp_cfg; +#define RMP_IS_SEGMENTED(x) ((x) & MSR_AMD64_SEG_RMP_ENABLED) + /* Mask to apply to a PFN to get the first PFN of a 2MB page */ #define PFN_PMD_MASK GENMASK_ULL(63, PMD_SHIFT - PAGE_SHIFT) =20 @@ -200,7 +207,49 @@ static void __init __snp_fixup_e820_tables(u64 pa) void __init snp_fixup_e820_tables(void) { __snp_fixup_e820_tables(probed_rmp_base); - __snp_fixup_e820_tables(probed_rmp_base + probed_rmp_size); + + if (RMP_IS_SEGMENTED(rmp_cfg)) { + u64 pa, *rst, size, mapped_size; + unsigned int i; + + pa =3D probed_rmp_base; + pa +=3D RMPTABLE_CPU_BOOKKEEPING_SZ; + pa +=3D RMP_SEGMENT_TABLE_SIZE; + __snp_fixup_e820_tables(pa); + + pa -=3D RMP_SEGMENT_TABLE_SIZE; + rst =3D early_memremap(pa, RMP_SEGMENT_TABLE_SIZE); + if (!rst) + return; + + for (i =3D 0; i < rst_max_index; i++) { + pa =3D RST_ENTRY_SEGMENT_BASE(rst[i]); + mapped_size =3D RST_ENTRY_MAPPED_SIZE(rst[i]); + if (!mapped_size) + continue; + + __snp_fixup_e820_tables(pa); + + /* + * Mapped size in GB. Mapped size is allowed to exceed + * the segment coverage size, but gets reduced to the + * segment coverage size. + */ + mapped_size <<=3D 30; + if (mapped_size > rmp_segment_size) + mapped_size =3D rmp_segment_size; + + /* Calculate the RMP segment size (16 bytes/page mapped) */ + size =3D PHYS_PFN(mapped_size); + size <<=3D 4; + + __snp_fixup_e820_tables(pa + size); + } + + early_memunmap(rst, RMP_SEGMENT_TABLE_SIZE); + } else { + __snp_fixup_e820_tables(probed_rmp_base + probed_rmp_size); + } } =20 static bool __init clear_rmptable_bookkeeping(void) @@ -308,29 +357,17 @@ static bool __init alloc_rmp_segment_table(void) return true; } =20 -/* - * Do the necessary preparations which are verified by the firmware as - * described in the SNP_INIT_EX firmware command description in the SNP - * firmware ABI spec. - */ -static int __init snp_rmptable_init(void) +static bool __init contiguous_rmptable_setup(void) { - u64 max_rmp_pfn, calc_rmp_sz, rmptable_segment, rmptable_size, rmp_end, v= al; - unsigned int i; - - if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) - return 0; - - if (!amd_iommu_snp_en) - goto nosnp; + u64 max_rmp_pfn, calc_rmp_sz, rmptable_segment, rmptable_size, rmp_end; =20 if (!probed_rmp_size) - goto nosnp; + return false; =20 rmp_end =3D probed_rmp_base + probed_rmp_size - 1; =20 /* - * Calculate the amount the memory that must be reserved by the BIOS to + * Calculate the amount of memory that must be reserved by the BIOS to * address the whole RAM, including the bookkeeping area. The RMP itself * must also be covered. */ @@ -342,11 +379,11 @@ static int __init snp_rmptable_init(void) if (calc_rmp_sz > probed_rmp_size) { pr_err("Memory reserved for the RMP table does not cover full system RAM= (expected 0x%llx got 0x%llx)\n", calc_rmp_sz, probed_rmp_size); - goto nosnp; + return false; } =20 if (!alloc_rmp_segment_table()) - goto nosnp; + return false; =20 /* Map only the RMP entries */ rmptable_segment =3D probed_rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ; @@ -354,9 +391,127 @@ static int __init snp_rmptable_init(void) =20 if (!alloc_rmp_segment_desc(rmptable_segment, rmptable_size, 0)) { free_rmp_segment_table(); - goto nosnp; + return false; } =20 + return true; +} + +static bool __init segmented_rmptable_setup(void) +{ + u64 rst_pa, *rst, pa, ram_pa_end, ram_pa_max; + unsigned int i, max_index; + + if (!probed_rmp_base) + return false; + + if (!alloc_rmp_segment_table()) + return false; + + /* Map the RMP Segment Table */ + rst_pa =3D probed_rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ; + rst =3D memremap(rst_pa, RMP_SEGMENT_TABLE_SIZE, MEMREMAP_WB); + if (!rst) { + pr_err("Failed to map RMP segment table addr %#llx\n", rst_pa); + goto e_free; + } + + /* Get the address for the end of system RAM */ + ram_pa_max =3D max_pfn << PAGE_SHIFT; + + /* Process each RMP segment */ + max_index =3D 0; + ram_pa_end =3D 0; + for (i =3D 0; i < rst_max_index; i++) { + u64 rmp_segment, rmp_size, mapped_size; + + mapped_size =3D RST_ENTRY_MAPPED_SIZE(rst[i]); + if (!mapped_size) + continue; + + max_index =3D i; + + /* + * Mapped size in GB. Mapped size is allowed to exceed the + * segment coverage size, but gets reduced to the segment + * coverage size. + */ + mapped_size <<=3D 30; + if (mapped_size > rmp_segment_size) { + pr_info("RMP segment %u mapped size (0x%llx) reduced to 0x%llx\n", + i, mapped_size, rmp_segment_size); + mapped_size =3D rmp_segment_size; + } + + rmp_segment =3D RST_ENTRY_SEGMENT_BASE(rst[i]); + + /* Calculate the RMP segment size (16 bytes/page mapped) */ + rmp_size =3D PHYS_PFN(mapped_size); + rmp_size <<=3D 4; + + pa =3D (u64)i << rmp_segment_shift; + + /* + * Some segments may be for MMIO mapped above system RAM. These + * segments are used for Trusted I/O. + */ + if (pa < ram_pa_max) + ram_pa_end =3D pa + mapped_size; + + if (!alloc_rmp_segment_desc(rmp_segment, rmp_size, pa)) + goto e_unmap; + + pr_info("RMP segment %u physical address [%#llx - %#llx] covering [%#llx= - %#llx]\n", + i, rmp_segment, rmp_segment + rmp_size - 1, pa, pa + mapped_size - 1); + } + + if (ram_pa_max > ram_pa_end) { + pr_err("Segmented RMP does not cover full system RAM (expected 0x%llx go= t 0x%llx)\n", + ram_pa_max, ram_pa_end); + goto e_unmap; + } + + /* Adjust the maximum index based on the found segments */ + rst_max_index =3D max_index + 1; + + memunmap(rst); + + return true; + +e_unmap: + memunmap(rst); + +e_free: + free_rmp_segment_table(); + + return false; +} + +static bool __init rmptable_setup(void) +{ + return RMP_IS_SEGMENTED(rmp_cfg) ? segmented_rmptable_setup() + : contiguous_rmptable_setup(); +} + +/* + * Do the necessary preparations which are verified by the firmware as + * described in the SNP_INIT_EX firmware command description in the SNP + * firmware ABI spec. + */ +static int __init snp_rmptable_init(void) +{ + unsigned int i; + u64 val; + + if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) + return 0; + + if (!amd_iommu_snp_en) + goto nosnp; + + if (!rmptable_setup()) + goto nosnp; + /* * Check if SEV-SNP is already enabled, this can happen in case of * kexec boot. @@ -420,7 +575,7 @@ static void set_rmp_segment_info(unsigned int segment_s= hift) =20 #define RMP_ADDR_MASK GENMASK_ULL(51, 13) =20 -bool snp_probe_rmptable_info(void) +static bool probe_contiguous_rmptable_info(void) { u64 rmp_sz, rmp_base, rmp_end; =20 @@ -453,6 +608,60 @@ bool snp_probe_rmptable_info(void) return true; } =20 +static bool probe_segmented_rmptable_info(void) +{ + unsigned int eax, ebx, segment_shift, segment_shift_min, segment_shift_ma= x; + u64 rmp_base, rmp_end; + + rdmsrl(MSR_AMD64_RMP_BASE, rmp_base); + rdmsrl(MSR_AMD64_RMP_END, rmp_end); + + if (!(rmp_base & RMP_ADDR_MASK)) { + pr_err("Memory for the RMP table has not been reserved by BIOS\n"); + return false; + } + + WARN_ONCE(rmp_end & RMP_ADDR_MASK, + "Segmented RMP enabled but RMP_END MSR is non-zero\n"); + + /* Obtain the min and max supported RMP segment size */ + eax =3D cpuid_eax(0x80000025); + segment_shift_min =3D eax & GENMASK(5, 0); + segment_shift_max =3D (eax & GENMASK(11, 6)) >> 6; + + /* Verify the segment size is within the supported limits */ + segment_shift =3D MSR_AMD64_RMP_SEGMENT_SHIFT(rmp_cfg); + if (segment_shift > segment_shift_max || segment_shift < segment_shift_mi= n) { + pr_err("RMP segment size (%u) is not within advertised bounds (min=3D%u,= max=3D%u)\n", + segment_shift, segment_shift_min, segment_shift_max); + return false; + } + + /* Override the max supported RST index if a hardware limit exists */ + ebx =3D cpuid_ebx(0x80000025); + if (ebx & BIT(10)) + rst_max_index =3D ebx & GENMASK(9, 0); + + set_rmp_segment_info(segment_shift); + + probed_rmp_base =3D rmp_base; + probed_rmp_size =3D 0; + + pr_info("Segmented RMP base table physical range [0x%016llx - 0x%016llx]\= n", + rmp_base, rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ + RMP_SEGMENT_TABLE_SIZ= E); + + return true; +} + +bool snp_probe_rmptable_info(void) +{ + if (cpu_feature_enabled(X86_FEATURE_SEGMENTED_RMP)) + rdmsrl(MSR_AMD64_RMP_CFG, rmp_cfg); + + return RMP_IS_SEGMENTED(rmp_cfg) ? probe_segmented_rmptable_info() + : probe_contiguous_rmptable_info(); +} + static struct rmpentry_raw *get_raw_rmpentry(u64 pfn) { u64 paddr, rst_index, segment_index; --=20 2.46.2 From nobody Wed Dec 4 18:50:58 2024 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2064.outbound.protection.outlook.com [40.107.92.64]) (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 56FC51DE3B0 for ; Mon, 2 Dec 2024 20:52:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172730; cv=fail; b=K8D8JRowZkRTxxGwy3WMmcKcumKi0FkHNzS4NZA4R4ziUPGLN9jtuDGNd366Mi7BFDSx9U9dVxOD2hfX/rjYaylCyZxaWLr9qTFlj+lfx1m/8QIH4uf5eJDCrsPKkmSHN7tYQM1Q6nzLaYy3iYSIt4RndYo6EWiPPvQdldqKvZI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733172730; c=relaxed/simple; bh=Y2de6lUTpW1n177PS5GTnDQxROoZ6p4Hsl+aQ2YuLt4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MyGnqq+0b16tYGQNH0eDN7mRmuJiQ28KSH63RubGilPKsvDb3UFUJOKnzW4tST35NYKtwtthad/eHZK5Wsb8OlkPokCgNgpEnCV906dg1Tr91pBC7E+XU+HzibLbCAbZ7vlTdcrenimi+kO09vscKPQwCqwuxHiPWVVmOG2Uqug= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=hl/zWQhz; arc=fail smtp.client-ip=40.107.92.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="hl/zWQhz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nF7PLLOM/Ut9vxRd3VzH1a5Kn22axyL4rFwq6NE9Gl9OgvYuvbjbmyWwN5+hc1Yav2X2z/etVvIndYXkhFm/ZXOsZgscr1oCrZjnkkw3Dhr+TsDZT4Q/L4ihR2edYKcsQyvDY6WHryA4sYVt9G+s0Zb6FifbbbXv/S5BWB9dVMX1jpSjUMiAe931k2PGb/JZjyP0zzOKmgGAIyweyCTEzi5xEyHB48sjwcaY5zQp6tB9jA9CZBJeUbqrZUFOZLxGWSFbdgbiuMfbxlxUL2jY6zlhT4jYVxUbKgRaYPywuBa43avbaelvmU/DOMzbkXU2UrhMfbf4ru8ZqQd+t4oFMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/oKOCBMG11rkMNSBoVSobw7unon/+5oViYqKWvwSeNE=; b=Rb2ei93jZljGpC4SQaO7Yhc2fsQyL3eN1tClWPaGvAaOZ+zXZqOD8ZyBOW+I1hbGKN+otgxq/MZE77/UUkNgWqy55Cx2QojmQU2fIjHudp6cNyACo44Dls2tNc2DDYKx66M1qN9LpWrxdeq7xMWSCi4sOpKxBQbZ5WafFIy4sdH5IMAgn61XPLQeHViiVdJGR82ftMqbpz1FIUDcrFNeSIGf27YQYzfaf6JGyzV3EuRb4hjaBV50RdL4jMMER5HvrEQS4tHONHZTko0jCq9DV3zpImlJHLQ40HoL/huFjLD+fkWTQMEwg2Uk/jtwk6FMDGWVOBz8j2FbjBNfd4bKNA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/oKOCBMG11rkMNSBoVSobw7unon/+5oViYqKWvwSeNE=; b=hl/zWQhzfPkAUYlGI7ykHoz5znn111Ary5zMuOjtSyzkXt2Ipp+58UhqNBqZMINmWIZ6P1Y4Ft7xSrF88l/47dnjFqEgxXpFRBq4L2Cla6IkTDhREftbfX3ZGXUlrFqyUNkO55O1JDxnLUqbX0grO1wGjqGagzFZTH75ZtwoM/I= Received: from SN7PR18CA0006.namprd18.prod.outlook.com (2603:10b6:806:f3::8) by CY8PR12MB7705.namprd12.prod.outlook.com (2603:10b6:930:84::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.17; Mon, 2 Dec 2024 20:52:03 +0000 Received: from SA2PEPF00001504.namprd04.prod.outlook.com (2603:10b6:806:f3:cafe::3b) by SN7PR18CA0006.outlook.office365.com (2603:10b6:806:f3::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.17 via Frontend Transport; Mon, 2 Dec 2024 20:52:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF00001504.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Mon, 2 Dec 2024 20:52:03 +0000 Received: from tlendack-t1.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 2 Dec 2024 14:52:02 -0600 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra , Nikunj A Dadhania , Neeraj Upadhyay Subject: [PATCH v6 8/8] x86/sev/docs: Document the SNP Reverse Map Table (RMP) Date: Mon, 2 Dec 2024 14:50:53 -0600 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00001504:EE_|CY8PR12MB7705:EE_ X-MS-Office365-Filtering-Correlation-Id: fa4e8e72-2e8f-4ea2-2702-08dd13132d0d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Mwt556X8AxsH1bVytgERJyTEsXGMQlLP3PWMcasvbcwj+VGvSaYGEZVfc/E3?= =?us-ascii?Q?GDrE6yMBSf2qTf+PLYJa+/Z4Yqp9NWXBgXYyz1wr2l71K+rBqK4vZ0+UDLbK?= =?us-ascii?Q?Gy/LcazlMy7Bq/SEkCxRuFM+U7/gTgK6rVtYc/4o61ZiK/SDR/4e4xFwmm6C?= =?us-ascii?Q?dL6gd2Sns3DG+ZezVlLNHzlf1pU5cjen+PgYB/zjwq1oUNVs5Oymmiaagjen?= =?us-ascii?Q?mc0PVNIOoPNJDET1sVIOquGiyPGnXbW/QhlwUX0k2RNJudg5ZQ8h5WW8Qfj4?= =?us-ascii?Q?pHSq1ygISMfK36GysGQRPBEUHhT14BZ0QlpQX1DzMJWoeWcaS59k18Py9/Oe?= =?us-ascii?Q?+BRiEKgw48zz4cHaiI8CDl4ypfLtzRw5ez1ybE8QsHfI5tWFFbnEvPAsKqgz?= =?us-ascii?Q?dAuXmsHjJnDweG/OJul6pLnwzvFW5v48o9Cjw5wGza5daE6jRvko4hS/iKmp?= =?us-ascii?Q?LpNK4fa7PDSTKJf08Vrg2rsBwFBoHoC5ne3S7MxG5VLMalnw5E/AohuCbnAr?= =?us-ascii?Q?JJLR16rPXD8me5eOK8k6THfgLkShVAE6urrpO1YLavztfT225iipjWpUQV+O?= =?us-ascii?Q?CKo7fHJOw701RGVkuqzub9972LjiA90kVuLMLmDcCjvXEcODTQs5F3rwmLK5?= =?us-ascii?Q?+kzdkpcsVUeat/tdz3izMaKllntXWwttsIEGGeFJUJLMvZJCuECY98TGYlKK?= =?us-ascii?Q?wnyoS7KzW/adBYWb0a40QiMQZPyd6FUOs63nGDKUEGjdU4KaDlppSUzupzWN?= =?us-ascii?Q?lq/q59DrR1nAIaHMfVwFLaizp39j4s48fgbBXuQSglir6odERCx5sDFNzX9s?= =?us-ascii?Q?aNc5c+8XBrEB1T7LmME8etm7lFzDFuTSQc1CT1PA/82hb0DSLv1/mSfRt2XI?= =?us-ascii?Q?Aa4zE/DHLAwxTKvu0s9Q2XMjy66WtSwX02SVRgZgnXaiSHhPkHEcV3aiZ7yT?= =?us-ascii?Q?KsOtZw6EFdCwWISgccSxQtBzByK4cTGTSZxpUUmevYfkHo1/O754R+nBOuE4?= =?us-ascii?Q?QRQ+oHsoMofx1EGvEzwYDZTA9dqKoaS8J19UhBlfYs/j8Vget2Z/yicht1Na?= =?us-ascii?Q?YN+4rIbPFkA57sFdYcLnNxZgJqJe7RWFbQHfO3f4Adwgztcuv2Z1QIuKreNX?= =?us-ascii?Q?zaagfDsntk/y5TR5Y11+aKP+gCUUuh5wk2B/ZZ96+Lf2h5+2wSdwnVUPQJea?= =?us-ascii?Q?WCD13rSENMTiCan+VlvYdS/8TJOIbPEENkNrh6kyIdNWedzwluCVwEBn64fD?= =?us-ascii?Q?CKcyyLma2BEjgba7JdC0PbKMkBDABmg96IICzK3+vCERsJvMdq2APEcIFDz6?= =?us-ascii?Q?fqztsB1aopBFpiwkkVKMjUvTd3QVtHjSHdLim5OdDseeehX5qGPIi9Co+nDP?= =?us-ascii?Q?ZplynTkCYjhS1hs8u44ZbTJNpCrOqzp0FTcq+UmHgxaRYpUslIaReOqwJ4it?= =?us-ascii?Q?NmEHET/aJmCCPm6S/03UQXLIaj2Dz2tK?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2024 20:52:03.6840 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fa4e8e72-2e8f-4ea2-2702-08dd13132d0d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00001504.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7705 Content-Type: text/plain; charset="utf-8" Update the AMD memory encryption documentation to include information on the Reverse Map Table (RMP) and the two table formats. Signed-off-by: Tom Lendacky Reviewed-by: Nikunj A Dadhania Reviewed-by: Neeraj Upadhyay --- .../arch/x86/amd-memory-encryption.rst | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/Documentation/arch/x86/amd-memory-encryption.rst b/Documentati= on/arch/x86/amd-memory-encryption.rst index 6df3264f23b9..bd840df708ea 100644 --- a/Documentation/arch/x86/amd-memory-encryption.rst +++ b/Documentation/arch/x86/amd-memory-encryption.rst @@ -130,8 +130,126 @@ SNP feature support. =20 More details in AMD64 APM[1] Vol 2: 15.34.10 SEV_STATUS MSR =20 +Reverse Map Table (RMP) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The RMP is a structure in system memory that is used to ensure a one-to-one +mapping between system physical addresses and guest physical addresses. Ea= ch +page of memory that is potentially assignable to guests has one entry with= in +the RMP. + +The RMP table can be either contiguous in memory or a collection of segmen= ts +in memory. + +Contiguous RMP +-------------- + +Support for this form of the RMP is present when support for SEV-SNP is +present, which can be determined using the CPUID instruction:: + + 0x8000001f[eax]: + Bit[4] indicates support for SEV-SNP + +The location of the RMP is identified to the hardware through two MSRs:: + + 0xc0010132 (RMP_BASE): + System physical address of the first byte of the RMP + + 0xc0010133 (RMP_END): + System physical address of the last byte of the RMP + +Hardware requires that RMP_BASE and (RPM_END + 1) be 8KB aligned, but SEV +firmware increases the alignment requirement to require a 1MB alignment. + +The RMP consists of a 16KB region used for processor bookkeeping followed +by the RMP entries, which are 16 bytes in size. The size of the RMP +determines the range of physical memory that the hypervisor can assign to +SEV-SNP guests. The RMP covers the system physical address from:: + + 0 to ((RMP_END + 1 - RMP_BASE - 16KB) / 16B) x 4KB. + +The current Linux support relies on BIOS to allocate/reserve the memory for +the RMP and to set RMP_BASE and RMP_END appropriately. Linux uses the MSR +values to locate the RMP and determine the size of the RMP. The RMP must +cover all of system memory in order for Linux to enable SEV-SNP. + +Segmented RMP +------------- + +Segmented RMP support is a new way of representing the layout of an RMP. +Initial RMP support required the RMP table to be contiguous in memory. +RMP accesses from a NUMA node on which the RMP doesn't reside +can take longer than accesses from a NUMA node on which the RMP resides. +Segmented RMP support allows the RMP entries to be located on the same +node as the memory the RMP is covering, potentially reducing latency +associated with accessing an RMP entry associated with the memory. Each +RMP segment covers a specific range of system physical addresses. + +Support for this form of the RMP can be determined using the CPUID +instruction:: + + 0x8000001f[eax]: + Bit[23] indicates support for segmented RMP + +If supported, segmented RMP attributes can be found using the CPUID +instruction:: + + 0x80000025[eax]: + Bits[5:0] minimum supported RMP segment size + Bits[11:6] maximum supported RMP segment size + + 0x80000025[ebx]: + Bits[9:0] number of cacheable RMP segment definitions + Bit[10] indicates if the number of cacheable RMP segmen= ts + is a hard limit + +To enable a segmented RMP, a new MSR is available:: + + 0xc0010136 (RMP_CFG): + Bit[0] indicates if segmented RMP is enabled + Bits[13:8] contains the size of memory covered by an RMP + segment (expressed as a power of 2) + +The RMP segment size defined in the RMP_CFG MSR applies to all segments +of the RMP. Therefore each RMP segment covers a specific range of system +physical addresses. For example, if the RMP_CFG MSR value is 0x2401, then +the RMP segment coverage value is 0x24 =3D> 36, meaning the size of memory +covered by an RMP segment is 64GB (1 << 36). So the first RMP segment +covers physical addresses from 0 to 0xF_FFFF_FFFF, the second RMP segment +covers physical addresses from 0x10_0000_0000 to 0x1F_FFFF_FFFF, etc. + +When a segmented RMP is enabled, RMP_BASE points to the RMP bookkeeping +area as it does today (16K in size). However, instead of RMP entries +beginning immediately after the bookkeeping area, there is a 4K RMP +segment table (RST). Each entry in the RST is 8-bytes in size and represen= ts +an RMP segment:: + + Bits[19:0] mapped size (in GB) + The mapped size can be less than the defined segment s= ize. + A value of zero, indicates that no RMP exists for the = range + of system physical addresses associated with this segm= ent. + Bits[51:20] segment physical address + This address is left shift 20-bits (or just masked when + read) to form the physical address of the segment (1MB + alignment). + +The RST can hold 512 segment entries but can be limited in size to the num= ber +of cacheable RMP segments (CPUID 0x80000025_EBX[9:0]) if the number of cac= heable +RMP segments is a hard limit (CPUID 0x80000025_EBX[10]). + +The current Linux support relies on BIOS to allocate/reserve the memory for +the segmented RMP (the bookkeeping area, RST, and all segments), build the= RST +and to set RMP_BASE, RMP_END, and RMP_CFG appropriately. Linux uses the MSR +values to locate the RMP and determine the size and location of the RMP +segments. The RMP must cover all of system memory in order for Linux to en= able +SEV-SNP. + +More details in the AMD64 APM Vol 2, section "15.36.3 Reverse Map Table", +docID: 24593. + Secure VM Service Module (SVSM) =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D + SNP provides a feature called Virtual Machine Privilege Levels (VMPL) which defines four privilege levels at which guest software can run. The most privileged level is 0 and numerically higher numbers have lesser privilege= s. --=20 2.46.2