From nobody Thu Nov 28 15:45:13 2024 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2067.outbound.protection.outlook.com [40.107.93.67]) (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 459281922FA for ; Mon, 30 Sep 2024 15:27:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710081; cv=fail; b=oNqR4X7DzclJQhuHoPWj1M3yHS+4H+svSZF8uDArWzKv0nPaTjvHpeJfab7X7PXu3DeDdoxN5npsZaW2GVw3BWTe487cxQgvTPL/SDplOixuLcInFowcGayCLsysKGT2JsLcGZWl0Z/wB8R2aaTEe9D1gsCVLwh9+/187vJHIBI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710081; c=relaxed/simple; bh=verHtiZf/iVNzl7U9hmkm2hjXL7PjOqURfJYRwP7070=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DUHXzGLqzVKzkLoZolY1t02ZsLpVrp2HHas6sDqx/fEoyZu6CQpv9KmIjP4vFNjzqGriNA5p4wqTxaaGTPsSpRXQj07HfnYjaez22xdo6raYM+Ee1hUuo3aR2jcy0JaOlYq1RoRDujokNANDY3Ds1Vqkem8WcLa7JQMOx2/B64g= 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=d/4s1HZ7; arc=fail smtp.client-ip=40.107.93.67 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="d/4s1HZ7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=T4ndVFhU4JMDATD2E7YjY93xe5W8KiDU1fa8gRmY1sdy4aiH8BN3/NRlywqJx872UfoTdY3jrr5FAaK7P1eSP8hRQsCB7SyTWOY46P7QioKGo0eZF561GCSEWCUxBYvSrsXjvyEk6laMuhJVhvHFmRxmWVPlzf7Z32mRBK3bzdg9G+uyQ1kqFdOHtGO9hyIBtSM/AwZ1nUqpXyLAMa41ym8cWvpX6DDdgR+kDAfBcUzlMmAhEd/shFh+ab9k02lrgevTobZxqt964ybnB6ixojUXz+UWfjVr5eyalWh1UDVVG91C8W9v/oRZsVvNEpdYUFiORSeMe38BbdftNns+VQ== 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=uTpESBTdoperuSFMsX12OBru3MYfjl7IITR/8JLUiiQ=; b=pOEeJ87r0t7BEf6jpNRQwTbctMv8N65xzOtBpduXxWgX5Qso1RQABLpVt+H3EdkmO4NInFHyZBY9fyoEKnGHt3awCoU5AJ/+t6NL4MtGtgIrp2sEI+ubvGVFPYVS+JkOUeRDsgoNJPIYZ5GDkDiX8WTD9Mw/biPr8JpF2Gzej0SfUI2/LuFVnBTOkC4js6W7illKlJUoF5Ff2pcMCXTH+ehChL5zZld6/Sz4Ay4w1AEF2UrtsC+W+xLYztvE5ovU51rD2w7dZSoOcrq7GFnOZatXXYLTho75zq9yGgzweF26pCUfCmwt2sRhDYc/nHiiV6oNmBXm1scDdvISrhSmRw== 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=uTpESBTdoperuSFMsX12OBru3MYfjl7IITR/8JLUiiQ=; b=d/4s1HZ78mqG00fSPhBCniZBEwtYegvvvPUFccPAfoYNyNTj6sYEv7Lg37MsEz2hCB17ngK/VC9pvPn63UT900LWMXJhruT3Da6XF2epP5+unyWvnYpVG6YjRkfL6YSJQgPEQJlHr6WaDJKxRT7LWIjWe5Sj8PqLR09vyDOcevc= Received: from PH7P220CA0001.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:326::35) by SN7PR12MB6689.namprd12.prod.outlook.com (2603:10b6:806:273::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27; Mon, 30 Sep 2024 15:27:56 +0000 Received: from CY4PEPF0000FCC5.namprd03.prod.outlook.com (2603:10b6:510:326:cafe::1d) by PH7P220CA0001.outlook.office365.com (2603:10b6:510:326::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26 via Frontend Transport; Mon, 30 Sep 2024 15:27: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 CY4PEPF0000FCC5.mail.protection.outlook.com (10.167.242.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Mon, 30 Sep 2024 15:27: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, 30 Sep 2024 10:23:13 -0500 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra Subject: [PATCH v3 1/8] x86/sev: Prepare for using the RMPREAD instruction to access the RMP Date: Mon, 30 Sep 2024 10:22:09 -0500 Message-ID: <4d62cc503d1e3278c3830f24462e3956233760ac.1727709735.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC5:EE_|SN7PR12MB6689:EE_ X-MS-Office365-Filtering-Correlation-Id: 3665dbd7-ae68-42e4-ee28-08dce1647572 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?sa8KsZVG2uCj/EFn3ZxxpOOEaMjBDp0Pqyz3idgeh/R2YNYNUVASmpCb/xtk?= =?us-ascii?Q?SoupkSLAzGt1bcpajoZJfDrQvylX1LUcIkMngd0S8KXfhIpUO/HbvzYdHLVa?= =?us-ascii?Q?v0CUJ3lPNQFLkAlvszUx99l0CCHuiNTwwM8jDciJfwZvpYQjiJGR5hIpsuE7?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42zsPraaBSNyaAKNCURwuL+qMLHic?= =?us-ascii?Q?KH/hliHtnPePFiEysT2jc9KWk7xREt4ZYDup7pJcVO2+rD8HQXuMd2RqGeOp?= =?us-ascii?Q?yIi9opG/h9YEBaIwX6d4oTXNyguCdNNdxd6ZEkF4+ifyXkLwMA8S0IJrb/Uk?= =?us-ascii?Q?halsOr1MUM01LD62b8fC7dFa02HxsFjL6ym+506/7P7KJx3ZEDAM2mCyeZ5G?= =?us-ascii?Q?oRFf5jbyrvlCqQKXBlOqYwjFfcRkqNqQhVQgG/pc9xUL0/KW69YPjVTDyOb8?= =?us-ascii?Q?Uz7auVNiPgMJ3Cm4b6E1b71LFceBnRaGZ9Psrk3UiOK7zdxQsVnSQ/RpMky0?= =?us-ascii?Q?frPqa+PMpynEGEqOcUpeiWAfm3BQkxL1RIM28wX6j+2TlnubgykgCd5MY9a+?= =?us-ascii?Q?y6jltPhQbj6KCYofLTRUenxwYSE+fAZR?= 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: 30 Sep 2024 15:27:56.1338 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3665dbd7-ae68-42e4-ee28-08dce1647572 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: CY4PEPF0000FCC5.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6689 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 --- arch/x86/virt/svm/sev.c | 141 ++++++++++++++++++++++++++++------------ 1 file changed, 98 insertions(+), 43 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 0ce17766c0e5..103a2dd6e81d 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -30,11 +30,27 @@ #include #include =20 +/* + * The RMP entry format 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 RMP entry format is not architectural. The format is defined in PPR * Family 19h Model 01h, Rev B1 processor. */ -struct rmpentry { +struct rmpentry_raw { union { struct { u64 assigned : 1, @@ -62,7 +78,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); @@ -247,8 +263,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 @@ -270,48 +286,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_rmpentry(unsigned long 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 *entry) +{ + struct rmpentry_raw *e; + + e =3D __get_rmpentry(pfn); + if (IS_ERR(e)) + return PTR_ERR(e); + + /* + * Map the 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(entry, 0, sizeof(*entry)); + entry->gpa =3D e->gpa << PAGE_SHIFT; + entry->asid =3D e->asid; + entry->assigned =3D e->assigned; + entry->pagesize =3D e->pagesize; + entry->immutable =3D e->immutable; + + return 0; +} + +static int __snp_lookup_rmpentry(u64 pfn, struct rmpentry *entry, int *lev= el) +{ + struct rmpentry large_entry; + int ret; + + if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) + return -ENODEV; + + ret =3D get_rmpentry(pfn, entry); + 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, &large_entry); + if (ret) + return ret; =20 - *level =3D RMP_TO_PG_LEVEL(large_entry->pagesize); + *level =3D RMP_TO_PG_LEVEL(large_entry.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); @@ -324,20 +369,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_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 @@ -356,16 +409,18 @@ 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_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_raw->hi); + pfn_i++; } } --=20 2.43.2 From nobody Thu Nov 28 15:45:14 2024 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2058.outbound.protection.outlook.com [40.107.237.58]) (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 6DAA4198A06 for ; Mon, 30 Sep 2024 15:28:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710110; cv=fail; b=KcJl6BaUmZ5Cq0RbytTbqljoF9fqN0TlX6HcM/Hu1ThZi0Bj/ons266+kdPPJvXhW05zSfcVJF/ZAnFEbUHNDSCkCSoG1gBE54xLdLK7+px8tkoBaIpGDOkjbVLYLDF2XT7p/vjtohNGuxH/nJ9rvP1kJhD0gtaoOes5fCCm8T8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710110; c=relaxed/simple; bh=T+AuwQVlO4kVy2UTybr9Ssl+QOUDs4z7w0Yl9022B30=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rNg8SAswNHii7smDC6hRW03Ti2rdBfcqKLpbl1uJRDGeS6/vkhww5lQoT+E7usFRvmsZ5RumBr4n72B1kI4RoW+jeomSSd+y80BIvrX6HXv0zb3A7TfawRtbWMad5E102DTWZcum5eLzNXbr7P6tQBwWJajPgCp8NRB9kn9eRVM= 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=0v7+stI+; arc=fail smtp.client-ip=40.107.237.58 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="0v7+stI+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sFx3m9avdXuU0T3fvmJD9djfpOksAxSFMLzGCJL1ToNENwbvzK9h8iO+v4FWi8CZ3VLpb1+9J0/GuNTZgnbvjSafmVPeDOyruG5oJiq/ZU4i8niQ4l2X0rEe1Qlrsz/wRHr0MeolrZoEuWQd8unWPi/Y1je67BLqgqJaxIpt36vMZTaN5yGcKln4zJlbMmdkKL2EkytIKY5KbLKMac0rT5qPS25BK6T6NikxIdvbQHoB4v/Vnox1BFyY1YpWgYxsHjlfQUhyzGo6QLcM0U6BHmu5MXqXRmxeq4rALvXYYf5OBaZ3XcG59j2oHcUl80qXf8mPeN5tlFhVyJIXTD1E1A== 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=nNzdsdorqmzdI1TX0wknVPixlglwQ7l2/ZAdfw+j/XY=; b=H4keKiYWU3EUWWkWif4cwXs7eiOoLr50QFAkCRK9ExeOAxnWfUpOZElpEsxh1MrcsB3wsdV2Zp+n1MfAXL98y2J+Fu/y2fD5/uyh5s4N7XvdQMJPfHIkH4WwKA9FopgQdHqq3vSdnEo4kiW7CFWoArI0j0OUiJmjCsnybz66Z3wGBS+jjgE8RY2+6yr0Y4FlVMrETCZzYRcNk5ao8LKCLOimnWybA0fUK8NiY9vO//1BcYScEtT9LVFy035PVxTf6QQLuF+8cb2KKHcwZH15gS09CtLbC7nIdyo+FpaqJOaGTZHKtGiYZ7w53eV9ONMTpC6MRpIMJPLsJjyV6oJSkA== 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=nNzdsdorqmzdI1TX0wknVPixlglwQ7l2/ZAdfw+j/XY=; b=0v7+stI+3GtZ3+d1KIdKB14P6eUXGOZaOE69Rc6Fqj4SNEH7l8p3ScNiEX+4omqWdkSmDgpwr7RZKHezaAR1HOBAdwEaGHWJL8jCtvUIsMFq+I5zg2cIr66FQCAiliCxfdkJIukI4Y7uw4XlkgrJn1uKm5wton1DHJquZcaSdgw= Received: from DM6PR03CA0045.namprd03.prod.outlook.com (2603:10b6:5:100::22) by PH7PR12MB6812.namprd12.prod.outlook.com (2603:10b6:510:1b6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26; Mon, 30 Sep 2024 15:28:26 +0000 Received: from CY4PEPF0000FCC1.namprd03.prod.outlook.com (2603:10b6:5:100:cafe::39) by DM6PR03CA0045.outlook.office365.com (2603:10b6:5:100::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27 via Frontend Transport; Mon, 30 Sep 2024 15:28:25 +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 CY4PEPF0000FCC1.mail.protection.outlook.com (10.167.242.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Mon, 30 Sep 2024 15:28:25 +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, 30 Sep 2024 10:25:26 -0500 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra Subject: [PATCH v3 2/8] x86/sev: Add support for the RMPREAD instruction Date: Mon, 30 Sep 2024 10:22:10 -0500 Message-ID: <4f9d9eac997784cd11f4243d545dd05e670b2e4c.1727709735.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC1:EE_|PH7PR12MB6812:EE_ X-MS-Office365-Filtering-Correlation-Id: 89594ea5-dda5-4387-2e98-08dce16486c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?MalnxV2oO8f+8fgPuJa9+xwVh+ceCSkEJbjaEbfNuu0G1VVTciLlT9yH92vD?= =?us-ascii?Q?HuTGc7Mzsp2RGLFppw8SRQVrvB/DYfVBTTNGkmZqeiQdnUzc1N1rb/ZtGkpx?= =?us-ascii?Q?NiGZS32PD1++aDdd5LVYQBLwDj0qEiJzBpe1RYDaGu13LG8RQXbyOZOLNQzR?= =?us-ascii?Q?g6vdVZDBeU6oG3jHohGmL5PW6wcj4UxMyD2P39d8KtGpmT0kCuKI7emFLfLx?= =?us-ascii?Q?quwJul3FJ7q/hoKywYwaSK4+NL7FMdBzpka/OXBaKVK7KchiAG/AnUXuSxxb?= =?us-ascii?Q?hAjZX4pcICKCQoi0iSVMPMD0BOjKaxSYkES5JOgo7X0kOiBkO1BHMBIAhaMR?= =?us-ascii?Q?fsEsQTiJ64T40Ul6r5iSxMdr//wgDANl6750HVWBkg1hIwuFBFb6+i7USyZQ?= =?us-ascii?Q?+FCWJUgJbslZbA4GwwDNDKx2LEFXuc4ItG/b6sT79yYYKT8fG2xAImcasL2a?= =?us-ascii?Q?eZrgx3sogTNyuCW/YdXK6VpS95n+J9nNOuxxMfJrWRP7VzUSvJZB9+xLuAxJ?= =?us-ascii?Q?LyNgKsixlmqBt5fzq31XvylBcJoj9R6p/GyFNjJyCcIpXBtfDmTLOYdcUQn6?= =?us-ascii?Q?wmB4FceFQq3shhrUTKFQCH/39H80yDjeiyilyOrWIZuBfJZJxvZ8nupWYt/W?= =?us-ascii?Q?LkI1lRGQJlQJSaW7cTdcGAJeU1g56ZBhK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ent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 15:28:25.0051 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 89594ea5-dda5-4387-2e98-08dce16486c0 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: CY4PEPF0000FCC1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6812 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: Neeraj Upadhyay Reviewed-by: Nikunj A Dadhania --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/virt/svm/sev.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index dd4682857c12..93620a4c5b15 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -447,6 +447,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 103a2dd6e81d..73d4f422829a 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -301,6 +301,17 @@ static int get_rmpentry(u64 pfn, struct rmpentry *entr= y) { struct rmpentry_raw *e; =20 + if (cpu_feature_enabled(X86_FEATURE_RMPREAD)) { + int ret; + + asm volatile(".byte 0xf2, 0x0f, 0x01, 0xfd" + : "=3Da" (ret) + : "a" (pfn << PAGE_SHIFT), "c" (entry) + : "memory", "cc"); + + return ret; + } + e =3D __get_rmpentry(pfn); if (IS_ERR(e)) return PTR_ERR(e); --=20 2.43.2 From nobody Thu Nov 28 15:45:14 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2083.outbound.protection.outlook.com [40.107.244.83]) (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 8498D199FBE for ; Mon, 30 Sep 2024 15:29:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710160; cv=fail; b=HUMx3bQ9RsEfLoh9NMRcXZTbHElv8EawUozePzk93vMYnNn1elObw/qThUDz38xp8SRCKeJRNpK7322orHQrrnriRFb8FaAdgguwsLLVd2Aix6076YT9AK7BOMJD5jmD8OgWFTokACusp+CU3ymAEAbib1XUmdCBj3SY72TXmFs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710160; c=relaxed/simple; bh=2TU800065al9d5LdU/DhO+l5xpjuxhOeAdqh9kUMAJw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OUBsZH58r2jMUnRBs/tYk059f7+zazgkvVpSK+mARmz+4ZST6lhNEn8BeiB+g9R2UH2V492mK29BGX0HdAXu4zwrbBOdo1XLOdvDDaVpB9ypj0I5U3kmfPm6ZHXpaDONWNSa5Lw+lNZMBKt6wWAH9xjQovo2DUHuZ9/CmmU6XPc= 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=KoU0dHAO; arc=fail smtp.client-ip=40.107.244.83 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="KoU0dHAO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SrjO+ozdMfgstsNXtIrPCPFbS2bDh2rOQexDjxEmmquIdv5usdqkC0SMyaWjM+XXIFRNAu0lA+HlrJswVrtXCG+n6umwUntL8RtPhZYw5FpPOCd6Rh3ViZCvOuzzYbvZnXvkwOlPsiyakLgqbUylIn8fL+Nl5sSksoakDlGVPftoFSniwBKNG2K1i5LSp2wjerSPKyUGnHIJ/L68qj1L5sYNnakTQ5hwa0BwjYcA1GlenWC+4jVjkCj/DipFdrxhIMqqJFwNayG66pjb7egk5sh2maBPOb0YB4kjOcazsRrlIeN6b4pUfQjxWWgApK7MCNIlJwaOGBpDQ6+/0zfVGQ== 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=Yt8Yeb8z/SsOQuSadXc9xRJIX6Pyk98s9HTyjBIzmnM=; b=qzVLmICxCQHZRG4XYw8TpBNOa/wr94OJl3DiFfqWyfjbPIZKN2JOh/UCPfc8HRwmKodpJSQZoIjKCOMhJ1HEzgEoOMWYi/3M2mGwXQJwLA11z72rA+bZNQ/hNenM3yGWNRUqmFi28oo2KoRnVBd0/+K4xLdZp25ufRa70gizWXrBYQ2AcMUasPEPwAOdUgt8rp+U9xhQ0bJlUra0CG7LiOoKaIfofA2gV78A5j3pQHINsJ/kNsMXiFUUHr8Hm6MGPjjTxBviRjIID1nxc7g2+nt77991NF0rMtsSCdepSxGFtjpSN/E/OAV/UPIAV5MIwI0POkXwrJzD2UqPIVC5UA== 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=Yt8Yeb8z/SsOQuSadXc9xRJIX6Pyk98s9HTyjBIzmnM=; b=KoU0dHAOnaXg8QnfFvaRjvGYM887GXks27GABGkS63PMwyg2+XeEi6IXy43xYkAmctrkCTxPNKJG9JH1GhNyeJXpBGfjFXK/NGiRD7eMCLgVFoTleZYlT7bbrYvlg1Dyr9zTMisSqmK4Q+KrRRboF23Rf1qTr01SJbeZ+IzVrUQ= Received: from DM6PR03CA0059.namprd03.prod.outlook.com (2603:10b6:5:100::36) by BL3PR12MB6572.namprd12.prod.outlook.com (2603:10b6:208:38f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26; Mon, 30 Sep 2024 15:29:08 +0000 Received: from CY4PEPF0000FCC1.namprd03.prod.outlook.com (2603:10b6:5:100:cafe::f6) by DM6PR03CA0059.outlook.office365.com (2603:10b6:5:100::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27 via Frontend Transport; Mon, 30 Sep 2024 15:29:08 +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 CY4PEPF0000FCC1.mail.protection.outlook.com (10.167.242.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Mon, 30 Sep 2024 15:29:08 +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, 30 Sep 2024 10:26:44 -0500 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra Subject: [PATCH v3 3/8] x86/sev: Require the RMPREAD instruction after Fam19h Date: Mon, 30 Sep 2024 10:22:11 -0500 Message-ID: X-Mailer: git-send-email 2.43.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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC1:EE_|BL3PR12MB6572:EE_ X-MS-Office365-Filtering-Correlation-Id: df619ae2-f90a-43a5-d19e-08dce164a063 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?c7kNDWZVJbbT8+zko5+HeZ3C3afvW2OR1PkZaJGvGBC7DoTysx5TrJqqgqbw?= =?us-ascii?Q?qytxDlVoZ8RKPhaz9Dq9GA5GDmiJyST/j4scnzqOngNLDco4xENInTMpYwi3?= =?us-ascii?Q?pUSajAITPl5jLpFYp7Z4drvmMRCKd1PuqBhMwkrs6s31l4tHVdmHIPsNjjHw?= =?us-ascii?Q?vBDZSDrVfX2Xxd12sYSBA2odrDrfk+ZTKk21V6iQrjsQ91crQVY5HqpuGro0?= =?us-ascii?Q?ehJo8DpvG7uU4+FW57RuhNtPrLPFPyfgHXSSwsO1vJ8rjlfTq4QrScwB9SAE?= =?us-ascii?Q?ri+g1f1/LfuDP7kg+UasGKi4Itzf1ig+dp/SmT/Vd79dPjpLLRlJLGfcqoIi?= =?us-ascii?Q?mC20X35A3cdAyUC+R/p3A5YcC/iQKlnZsbQROa2BR/MGT8dC0fvsQQXvvLcW?= =?us-ascii?Q?I7QQukxzKWGKUpXC267zdgb2kV8OIUEqYn2QP2cZ1h16Q5RLEo3LmWxwLpQj?= =?us-ascii?Q?wT9YxHQUbTwVxfgNTWI/k8vttkY5cN975l38CULQo1WsMIhp30q27cpxR2J9?= =?us-ascii?Q?4zkfjxS3CAvtUul+v9uq1K+EoasruBaAtak0WHdmy9Xwl9NB9vEVkYp/QF3j?= =?us-ascii?Q?4HQJF82LEwdOvSzyIJnam7Aqg+V+l/3N5e5EWHNSYRXAA1oY9EnoBtlO/R1T?= =?us-ascii?Q?axm+KH92oqJ7tF0sGucoui/kdiwYB6MxwFsAYHeIjU2AvPMzo61vfzAlgP6d?= =?us-ascii?Q?1t3cve2m3xq9TLtS1k7AH0ye/D//qTd4DygrbtnPqje9J4x5K9hLL2sZY/ix?= =?us-ascii?Q?HHtZPLyzeHyWhPCoPxHZxVhyxO1E35B5DDZrsXzkG3kR0Av9JU/+OlwOsAzA?= =?us-ascii?Q?G2FpjaqbBEe5AIbLbolre7STBEQ1dPX1KGK5yKYXlwWqiVELt+vH62wb9lWi?= =?us-ascii?Q?9S62ayKAgL6Xxbkd4eYWE7v/wECAmtAw4ta1GD6CJIoy1G9IH7whOGxAjGTV?= =?us-ascii?Q?V2cD7AW+DagPMnuCg9zh0J+4QL1JN4XUuCeB3mvusXjTZ1pMqFf7y7d4UeWU?= =?us-ascii?Q?TcJcSXW6W2V0DcyUrET7fGKmVrJhFI1yfXDdstM8W7OSa3q8xUzFqvdzkQoe?= =?us-ascii?Q?z/h4OzGcdKJD7NAZPOmFRfeGeY99kNMc7/aM3raxIpoT7e4rlIkoqCunuSE4?= =?us-ascii?Q?vUsHWHC1R69WFQbK5TxN4ludxtlLIoandsS15EorsieUvvCiX8udTjGbQu6a?= =?us-ascii?Q?Hy1zYBg9SiTqEixkzGOKyBkSHgzHh9vLbH8ya3rTGaOFqJGP+glns1oUlHqb?= =?us-ascii?Q?zRvxLuJQb20nJv3ZBKh0dIROEctAiyn0BNcaTPxX0WwcBoUNT84pl1uUDW6q?= =?us-ascii?Q?16kn5++9Wj7cs6boM0H6anaoG4kvF86iyV5q5gGdh0CrKNr48g/TEfBu2ErI?= =?us-ascii?Q?FMimymBQw8Wc0QH2guzLt2Jdi8+o?= 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: 30 Sep 2024 15:29:08.1455 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df619ae2-f90a-43a5-d19e-08dce164a063 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: CY4PEPF0000FCC1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6572 Content-Type: text/plain; charset="utf-8" Limit usage of the non-architectural RMP format to Fam19h processors. The RMPREAD instruction, with its architecture defined output, is available, and should be used, for RMP access beyond Fam19h. Signed-off-by: Tom Lendacky --- arch/x86/kernel/cpu/amd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 015971adadfc..ddbb6dd75fb2 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -358,7 +358,8 @@ static void bsp_determine_snp(struct cpuinfo_x86 *c) * for which the RMP table entry format is currently defined for. */ if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && - c->x86 >=3D 0x19 && snp_probe_rmptable_info()) { + (c->x86 =3D=3D 0x19 || 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.43.2 From nobody Thu Nov 28 15:45:14 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2046.outbound.protection.outlook.com [40.107.220.46]) (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 317BF199EBB for ; Mon, 30 Sep 2024 15:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710156; cv=fail; b=kGh7V7WTKlfVKJyxWfi0RghhR5VAk+skgYjwxhN6hhMsZqexXRLAHqp5tp9ZravFJPkhwcz8kIY7a7AzPkQguM9IPq+7T9LuOA1CtLzqXGTANfWtt/UOi81T1ut+hGvZ4CTWAYn0xcgeKmWabKVxD7ztPtE+YYxx2Qf3WcYY+uU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710156; c=relaxed/simple; bh=kBmG3oyaXCc7Kdk1lVEAUJZNeYXEr1v6wmYTK1d50qA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pbI4+hh+GJtcoFZXh0gawi7W20pOCbf+NyGQuk3XnJKtFtvD+kwOK7ZGv+3yviSuS72cVrRqRouB3Q3ftnD8Zv/MXFh1SUQQUSJEQ/CNXuCXO6plwYEb8DH3yA+QW5HaiBGhg06o4+l3h4sQhzJjRLdDICs5tscO5qtn8wS5D98= 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=g8jvLFnL; arc=fail smtp.client-ip=40.107.220.46 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="g8jvLFnL" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=umXT5Y9URXTT2b/iK4UlQNRVhWc/tldxda3iSgV9UIHOHmBtfGWk/9G5HEXL+zKoDRqrd9EtokkUXW63DyTJ4q29kvNtUCvkWK9LnSkQ61xN6AYvwdcdLA3HBjpODMoR/UyT9YWfphCVz5VrNeY3nsd3M+y8tvhqNg4D8+C2uOkBlsITlNbds6/d+XNINWsoKm3nLkWro2socgMt31PUjiBi6NVfqiK8Wmg/Bqf0qr55KGorI4F8YJ02RUL/h9w79X9UM+hCUTBWoimaRM/qtWaCV0ohT3PUymx2NP1Xr+jDxRe/HOuxVvg5V/0HfCMAtusEHT0DYbt7x4LisRyJyA== 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=MYKyywUZaArWrHpIgzRuN7q5CmO5o9ImOE065iL1XyQ=; b=dbXfuw/FCWJAvZ+FeVFuVvfZg/877KKDEuWOx2SUgdNnAmhFJ/xylRWdibjWTRbxI0SK+q8PUitjpRbdIhH1mJl6dWrjNtIZ8tKOurMSD19uGTnyIBx+F2RIYqFpcIncs9xUT8lqBmU3aOB2UxIxwfLiyPh/8purFltn1Gf3NksdqC70r4lijaET9oTa8EbU2ZxMbkhOsqAsnP156WSqaXudwOT6eg8uJj7r/VYK7rveBAYt0ZQubUB8qU7CNAPc0rmwhncd4tPeL6+hpf0gUxUp6M0TfHHP9Fc8q738GTnDYuuMNlzL5YoRmF1tdxPj0z4XEOSLesyYlt2JksxcTw== 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=MYKyywUZaArWrHpIgzRuN7q5CmO5o9ImOE065iL1XyQ=; b=g8jvLFnLr8qI2kDOor2MhUoeUV53tJrMkrlxH02+rwEh8J0VC4Yazr2t66pevuCb1xCSTkuSYnUJAL3v6PUYTXIYssmJ1T4+54UpgDuUAa54l1LQgmOP68cG/H6jexgC4GqSrTRxlOSc5fsltSbdkE/PXwhB32ueLEvpIg0HmOo= Received: from PH7P220CA0017.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:326::9) by BL1PR12MB5706.namprd12.prod.outlook.com (2603:10b6:208:385::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26; Mon, 30 Sep 2024 15:29:11 +0000 Received: from CY4PEPF0000FCC4.namprd03.prod.outlook.com (2603:10b6:510:326:cafe::a3) by PH7P220CA0017.outlook.office365.com (2603:10b6:510:326::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27 via Frontend Transport; Mon, 30 Sep 2024 15:29:11 +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 CY4PEPF0000FCC4.mail.protection.outlook.com (10.167.242.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Mon, 30 Sep 2024 15:29:10 +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, 30 Sep 2024 10:27:56 -0500 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra Subject: [PATCH v3 4/8] x86/sev: Move the SNP probe routine out of the way Date: Mon, 30 Sep 2024 10:22:12 -0500 Message-ID: X-Mailer: git-send-email 2.43.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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC4:EE_|BL1PR12MB5706:EE_ X-MS-Office365-Filtering-Correlation-Id: 2f14259f-6ad1-4c7b-ed30-08dce164a1fa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Gf3drBF+U2r4cIaFBmrFhxGEV+eUC47/uTdDgPEqUQDFu2fdw5rbmf3HYBU2?= =?us-ascii?Q?X27eGp3LPZRQj7NfoCKyKoSKsMbTnd7ZskugoRVauPn5W65DMqgSCxJwPYAC?= =?us-ascii?Q?7Ydh0VluuRdDUa4HnrzLZKWRmeCoOR3ZA1BA3BGJem3nzsZM2SMSGPyu4iw5?= =?us-ascii?Q?xvKbGGttsYWx4i8Chp6oqPR8Krzm/2/F6Sqr9yHThA7ze+HXGIhclB9XngM4?= =?us-ascii?Q?+yG28h5Tde8WrXVnCZmueXAYc9O3+kpeqYjtrdrw7rnt7Lxdd4fZEoKnK2ut?= =?us-ascii?Q?UHWNibdqrTec/Kfb2HJb21xBX4LUU6/IbAdilRlR/43kcAZhyN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pdT7aEz4cp7mrV15VGWKCtV/VHfGI/xKibJtSRE?= =?us-ascii?Q?FDDUwLvZS/wh97jQF8JcdJTOJnFzFcGlUostIaCGWKOoobIbVfyK/w5xuIFO?= =?us-ascii?Q?WrIytF/rx9lM0ZzpdjQNAABdQpJZ9NTDWZMOgOYzZUmTM9zdeBvY5gKCq+bK?= =?us-ascii?Q?idMGVXL0M6fE81VnxRzZfQV75b3VbvzKlIIIHzR/LPZYfrJ6etZ4I4jUxU5I?= =?us-ascii?Q?RhrQh3hYkZ12uC/UkoT8tRXF1L4VMgNL?= 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)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 15:29:10.8760 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2f14259f-6ad1-4c7b-ed30-08dce164a1fa 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: CY4PEPF0000FCC4.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5706 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: Neeraj Upadhyay Reviewed-by: Nikunj A Dadhania --- 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 73d4f422829a..31d1510ae119 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -132,36 +132,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)) @@ -286,6 +256,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_rmpentry(unsigned long pfn) { if (!rmptable) --=20 2.43.2 From nobody Thu Nov 28 15:45:14 2024 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2051.outbound.protection.outlook.com [40.107.237.51]) (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 79B74199FAE for ; Mon, 30 Sep 2024 15:29:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710159; cv=fail; b=sWiGx8kbKU/FHmp6OcIyEXccXorifFIFAEPkNegQdKOmRCC5S0liyfRSS0iw3HKqchIXIbEN95xh3WQIz0aDheOUKugIlUxI/wGVAdNo4sFUnwh54xJWa3AwsDj7Gp8RMgyYzSM3TwnJ7hOalnUUJCvOHsccy8n0IT4gX3ROzh4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710159; c=relaxed/simple; bh=3jBNdQuOnPDungJ/P9wT4zRL7z3ao26B4dmZqfQJDBU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jHIPyVNJlYHrqXoRlKLbMAAZmnfT/MQAzq358hF2HSugqojBixzt49REfwEsX8ntb8qheQTtk5+mU9Y2PhYVTSSvdu6QG/9iiaZ9hLyKrxEVSWL7BTKa1TKyG2JNNeXgyI2/Dqn9FJpShwgcuhjOo37E6+SB6fWDJXu4NPZsA2I= 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=ht+9iWhg; arc=fail smtp.client-ip=40.107.237.51 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="ht+9iWhg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZYIFUGFTCD1f1j857iOpaKxCkiVnu78XL8R+CFeQgMmYNI90P13YDP35N+ozTdTn3qyjX6uR+ZX1edhcKoynWQN1lQ2P/Nl5pDrXsK18xMp5PVJ0WeAQJLAwm6AFvydHSjim/4/7Hl59DRq3Wl4qeJvBvrRhg13d3oQuXUfNP/6DsPIsCKbFDT0v9mwoAcTFrNj8fX1L2k1FHnCW5YoT9HgLypG5vPYf3UQlDe51lACNWeim1XSoPiwWZT4+1n2Jun2rCicbK5NeR+6Z4CpP3wtNxnabs8bf6FpzWYZDQ2J780ocNo3Fdd1ybO18hnz2gr4Uv91rvGeXzddrJkYTMw== 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=2T6OLVACWHgZ1LYo7hE/mdJpXwj2bJ21of8Mu2wqhdk=; b=ZXVuHCC4xB1wv6Y/9MbMUnFmz+aAh4dfqJ4HVUB04BisL77UZgz6c1lVZGjEuMIe/kO0rtA2I+bVNW7gM9lMeSWYY+JjcJNjqLF/+mi9K0Hkqf5d1ArvoeJPdcQCxddkRpwSMRjasVegUzvmydiDNip8Hy3ez7KvcgNDE6+00wwKrH8McGkt3s2LZ2ODk2RU5yUszy3srEUHlAULoFUtS9CRH9gIRXpelrIbxWD7zdd/us2C85gSfG5z6xaofjq8hhq0d2DM1gixuusdRcLO1+9O4bHhW4vZ1ThjljOtPyOzHPkNkc0Yr1GRxP01b4AKIcS9CUewjg94hkYBJZojrg== 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=2T6OLVACWHgZ1LYo7hE/mdJpXwj2bJ21of8Mu2wqhdk=; b=ht+9iWhg9ji8LZV2A+DifyxBaHyN1giyYGiWxR7qIy3iSJmK+ykl685NWwJz4OblgeCqsChNqofBEx8U47T7KChK9pL2xpquxFzgJeddnTVMyc+k/ZqL0YqF1TCiIyO3n58PFbQswxHLWo+khjjKzct43QFtEVGK1wyL9NdvK40= Received: from PH8PR02CA0022.namprd02.prod.outlook.com (2603:10b6:510:2d0::12) by DS7PR12MB8232.namprd12.prod.outlook.com (2603:10b6:8:e3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26; Mon, 30 Sep 2024 15:29:12 +0000 Received: from CY4PEPF0000FCBE.namprd03.prod.outlook.com (2603:10b6:510:2d0:cafe::c5) by PH8PR02CA0022.outlook.office365.com (2603:10b6:510:2d0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26 via Frontend Transport; Mon, 30 Sep 2024 15:29:11 +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 CY4PEPF0000FCBE.mail.protection.outlook.com (10.167.242.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Mon, 30 Sep 2024 15:29:11 +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, 30 Sep 2024 10:28:24 -0500 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra Subject: [PATCH v3 5/8] x86/sev: Map only the RMP table entries instead of the full RMP range Date: Mon, 30 Sep 2024 10:22:13 -0500 Message-ID: <89d50ef2f0a9b3eaf4e9c4cf4e0a418f963d92e7.1727709735.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCBE:EE_|DS7PR12MB8232:EE_ X-MS-Office365-Filtering-Correlation-Id: 42571b3b-06cd-4fa5-ffef-08dce164a23f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?hfH23/0JrWNgeLXTqcc+8H9x3bMy3M+6H1eqw25qpa7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ndw4RWfWestllkKP5ujp7XegJ4EcmUf77/x0VteYPcLeUNy3o+?= =?us-ascii?Q?WwMRpGuv49Qzd/Brvntw1Kv8QghfY282FCRjMHV0jduxGv4lbD+nx6E8c9Gh?= =?us-ascii?Q?L6Qp/plJE8OlpYnLlunrAEw28D7gFuAwPWIw1K1iSJx5p4XK2IEh7smBZP33?= =?us-ascii?Q?dYIE7jD2355kjtrBirs+/QTCkJDNF4R/WIA/l9SBZCrpEapaqOAFVbMkYxXf?= =?us-ascii?Q?ZrBvc8yfc6AcUSQEybnua0447UebGHpVps89lkiyRDvnHHQ7otd5fZkeqOgL?= =?us-ascii?Q?feDKlefA31QVIvoH7FpaLcP49CIrmPNiJTJzY0B1XzBMWNnsYkS10NW0h9Zd?= =?us-ascii?Q?bNedQRnsyMiJnL4AFGXP+47Mx9CO3FgSYZuDrouJuTNzXZgkbPQHUejBgHTI?= =?us-ascii?Q?T+SKUpxbtD3GooH7OWuGUgMItVcj/JL52ISkGUYy2QDVVofRNxGVLWoeNvGQ?= =?us-ascii?Q?PX6JNk4F6kh3Bb8vOmCNKzVWPXWs?= 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)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 15:29:11.3287 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 42571b3b-06cd-4fa5-ffef-08dce164a23f 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: CY4PEPF0000FCBE.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8232 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 --- 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 31d1510ae119..81e21d833cf0 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -168,6 +168,23 @@ void __init snp_fixup_e820_tables(void) __snp_fixup_e820_tables(probed_rmp_base + probed_rmp_size); } =20 +static bool __init init_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 @@ -205,12 +222,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. @@ -219,7 +241,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 (!init_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(); @@ -230,9 +259,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.43.2 From nobody Thu Nov 28 15:45:14 2024 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2067.outbound.protection.outlook.com [40.107.223.67]) (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 BB7DE19AA7A for ; Mon, 30 Sep 2024 15:29:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710166; cv=fail; b=qKCSbEqHLcIlJe8Yj97AyRENBF1kl+mjZxCB+WPrT4PKF4aCw9mdkvP4vHEKuVeVx27+3sSrIMtE5EE3FlnsliAGYoh+4HWbvi5hWc0a+TKaSbNLbBV8Wr0dFTbUBZ/reSK3SsjKDqv/Rn2XdetYSoitY68Qhe1ZBfEnOtoHy4w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710166; c=relaxed/simple; bh=9MMqmyKjc+lX2mevROtL7OvvD+/w1N4NVemVhsg3J1M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m0jPrL1edxNLxec+AmHyOqsV4Pkqb5V3rLm8pw3lpSLFP99XAvJBKIEUZkcGpgP69X5esN0+z4V/f0Gppiq3E3z0gUMA8VJfA5zYouh2/2apj5gHns7eEYVKioXgUqkzD3aSXTgvJmErVyb8dR8GqJkqzZ/HCswtLX58JsDhu4M= 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=GwBY+ugc; arc=fail smtp.client-ip=40.107.223.67 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="GwBY+ugc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pr0DQ8shD7Tkzk+RsXDTvnPey99bPBoz0uTIMClKToSQGuDnKkDg2ysJbrDjrTY1rP5q3gqm4ZZy2IRDblok4UrhkHd8hC6v3FlxQT85eY08f9XCNJbECSh+0IVUcO1GIOX8jmJBfD3LkDiwk6mgY2Yq8l+nwgbvmQsW2Airfppjp5zneEoBPFHFnT3w8iYaVip4i0ZI5GTaPItw1kz7G8BuZEwpGwiDWlRDloZ0HPXSikAR+8A7OLZbLVBohQtpSsR8U7WBvI9HBrJsTGpOa4n2IFSpvPg60E/ekXAwACuKJTf7i+gClE13lBGl7ahUhGT/V1gdWfPf2oQ0ZslhdQ== 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=8O8YmUEGHg8FRli4ASVLvNhSwFw0+bIZledzUrbGj+E=; b=D8AZL+0aT9WJpqUqsDhSPbE5jzg9pD4FumaKc/qdAsanbzVVmJzgrmWg45Fd55jVu/XWNKH18+Iz7Jj2+63U7UqgspgGEKlG3cxq9W/s1rT7gTM+22/gp4v+d0+xFWS7A4XlcMJ+PH5jx/eNQd2i+/a9IQ0xLK3vWJi8666jBhWHIf4/V556GcuuY1AxeWgcwDNaaEqmIXEou0+g2W7a6qAWRx7MDtNmouFKbOcjX+jpNKzP1f1Bn7y74Tbhjr8c0sWjVlYlUBuZ5ogSOUkgUn0mOkdvNOuhi8EDEud60k38EVpgEO17BbGgbwV2224cGM0KxzIr73sMuuohTyfrQQ== 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=8O8YmUEGHg8FRli4ASVLvNhSwFw0+bIZledzUrbGj+E=; b=GwBY+ugcV652MKm7m+nwM4wGboPjCx+atujcUQA/KbpoASw29Uut2EMcddoeCGqmN7QbIJmCeedFXDSIb7SB4W8JNSzI3cBEiup8T1gnRP5AwWmw7+mGEjKtAtiCkDCQ7BWRdCLvN6vuReQzTeiwEoartbE+dYrWbNoH7QyIjbU= Received: from PH0PR07CA0013.namprd07.prod.outlook.com (2603:10b6:510:5::18) by BL3PR12MB6619.namprd12.prod.outlook.com (2603:10b6:208:38e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27; Mon, 30 Sep 2024 15:29:14 +0000 Received: from CY4PEPF0000FCBF.namprd03.prod.outlook.com (2603:10b6:510:5:cafe::db) by PH0PR07CA0013.outlook.office365.com (2603:10b6:510:5::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27 via Frontend Transport; Mon, 30 Sep 2024 15:29:14 +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 CY4PEPF0000FCBF.mail.protection.outlook.com (10.167.242.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Mon, 30 Sep 2024 15:29:14 +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, 30 Sep 2024 10:28:58 -0500 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra Subject: [PATCH v3 6/8] x86/sev: Treat the contiguous RMP table as a single RMP segment Date: Mon, 30 Sep 2024 10:22:14 -0500 Message-ID: <3a9a4f94fefe3b4ebb23a7dd3d33d9fd7a344ce1.1727709735.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCBF:EE_|BL3PR12MB6619:EE_ X-MS-Office365-Filtering-Correlation-Id: 3517278e-5672-4465-3afd-08dce164a405 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?qolK1XHBx70vnKtkZ/p0D+VGq38hIEY9gzQ+XXkmuI6lIEAen/HPT5SJ+Va6?= =?us-ascii?Q?/Tn6Oa7dC2etcpGLN/JCLhsxFinMe3zE+lF10A2dWG1QiwN0eie0XtFx4Mm9?= =?us-ascii?Q?uVZCpMx0TT2dAe4l6Vo10vNUrYduH3JareWNSVoqZpUXYMY7GrCDh9aMcODG?= =?us-ascii?Q?lnK/tv6/0sJwIsseCZhC4e77YZDbN3Vv31bd2ZXjjHqbeyT+t7PDkpAyhiEf?= =?us-ascii?Q?dLgZX9/39d96+7LV5bxzEsldgIp+cXTvJkgacdwchv9uJe8Xq0kjONgddMqM?= =?us-ascii?Q?QIjpQBYJMg/2XZC38uw18luhjzZEg0kMt8J0qCU+uUz8XX/OM/+yBRKL/UML?= =?us-ascii?Q?gVcl79uDSMWO9mBoCA1KBNLi7EwPJbSryYi5jfyve0JHTLLwuk8FQC+bT20M?= =?us-ascii?Q?o/VkVHCRRmQpeZ7/S2bQdU6Mii9ktJSaZrkePMh3Anp7MM8IGgTrW8+ogfkd?= =?us-ascii?Q?os02yGPa7F7ef2AUlPuYCrpJSjDMfwJDKB55zakWL0pm4fpx7g+6JmS8GKxa?= =?us-ascii?Q?NaTNYeVCiADCeCy99OLGXwRnx8XsbOBlIjXPBAeQ2zOc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Wa7HA5Ykh08hS3zzWdNAOmYDl/hOW?= 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)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 15:29:14.2834 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3517278e-5672-4465-3afd-08dce164a405 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: CY4PEPF0000FCBF.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6619 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 --- arch/x86/virt/svm/sev.c | 195 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 176 insertions(+), 19 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 81e21d833cf0..ebfb924652f8 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 @@ -74,12 +75,42 @@ 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 u64 rmp_segment_size_max; +static unsigned int rmp_segment_coverage_shift; +static unsigned long rmp_segment_coverage_size; +static unsigned long rmp_segment_coverage_mask; +#define RST_ENTRY_INDEX(x) ((x) >> rmp_segment_coverage_shift) +#define RMP_ENTRY_INDEX(x) PHYS_PFN((x) & rmp_segment_coverage_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); @@ -185,6 +216,92 @@ static bool __init init_rmptable_bookkeeping(void) return true; } =20 +static bool __init alloc_rmp_segment_desc(u64 segment_pa, u64 segment_size= , u64 pa) +{ + struct rmp_segment_desc *desc; + unsigned long rst_index; + void *rmp_segment; + + /* 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 (%#lx)\n", + pa, rmp_segment_coverage_size); + return false; + } + rst_index =3D array_index_nospec(rst_index, rst_max_index); + + if (rmp_segment_table[rst_index]) { + pr_err("RMP segment descriptor already exists at index %lu\n", rst_index= ); + return false; + } + + /* Map the RMP entries */ + 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 @@ -192,8 +309,8 @@ static bool __init init_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; @@ -222,17 +339,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. @@ -243,12 +361,20 @@ static int __init snp_rmptable_init(void) =20 /* Zero out the RMP bookkeeping area */ if (!init_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(); @@ -259,9 +385,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 /* @@ -282,6 +405,17 @@ 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_coverage_shift =3D segment_shift; + rmp_segment_coverage_size =3D 1UL << rmp_segment_coverage_shift; + rmp_segment_coverage_mask =3D rmp_segment_coverage_size - 1; + + /* Calculate the maximum size an RMP can be (16 bytes/page mapped) */ + rmp_segment_size_max =3D PHYS_PFN(rmp_segment_coverage_size); + rmp_segment_size_max <<=3D 4; +} + #define RMP_ADDR_MASK GENMASK_ULL(51, 13) =20 bool snp_probe_rmptable_info(void) @@ -303,6 +437,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 @@ -314,13 +453,31 @@ bool snp_probe_rmptable_info(void) =20 static struct rmpentry_raw *__get_rmpentry(unsigned long pfn) { - if (!rmptable) + struct rmp_segment_desc *desc; + unsigned long rst_index; + unsigned long paddr; + u64 segment_index; + + 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 *entry) --=20 2.43.2 From nobody Thu Nov 28 15:45:14 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2082.outbound.protection.outlook.com [40.107.244.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 0159D189F5B for ; Mon, 30 Sep 2024 15:30:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710241; cv=fail; b=HLHtLlCNniJOlP+6gJ7dF4g/LvPwgI4v9rsMPwTryv7uLkFfGApdz3B+ay6H5PyFL2/qi645leLuLjvnhQ6FKwnHwplaiBEkvcVYJbEpbh//qv0hSd8pZxwNuLIMIfaZj2K2ED3Y86/r4dwUys54nb2iN++wGZ0XwbPwBLw094A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710241; c=relaxed/simple; bh=FqzCiC+N/f9t5k9iYCu5vA8zIZxKVA49l5XtnBLXO2k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Qbk/v4quUEc8Cf2pbNQ4vwcBvXJ9jWTL5v18Bv9QqrLNdCQ5hnaIZnWYRm738+cueltI8TG0KTWW3Jz573ayeqsFtUKDTmgDFYv1egnAOjQJKy2vJTg8EFQ9TdMzGcuApNNNDCMZ00ERFfdCIUPwmW+3WXk9L/nMIOUHNe9LQTw= 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=b0o48C3w; arc=fail smtp.client-ip=40.107.244.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="b0o48C3w" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lDKtLnD9iOHQ6BHxBWrg6I0OwWhVQ+DODfq1oVqRfkf6F31cljjPZMDxN3vJiNCW56NUO+Myc6FQdtsQSBA6VLZJnStCBJvSQPPKu/mbOQJJJK283MF+RjyznsbiDN3T7dbsnU2nUWQyKe0SUk8MdWudkLqbgeO7eNDd0OTDoeXxL8LcBYsvEOfI+XL74NHCHci3bMRMRXA37WrsydZhx9LAYowapZPvu9Ke6XSKziRtWSRbwHnih1JI2uRAE9pIpv5+zGXRM/UFJzbJJM750KOjqUesQ4+vDDG4GH/mzK9PJZ/Nb8fH+B+s6SCfDuzzcD7fR2Davk8KSTYceEIiBw== 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=afXyEcvsuoWCd8s0zOotz5dguSOVcmcu/XR5XYSSDmc=; b=n22rT3VnwY/oAE/yLmGXh4wdZTq5WAziLI8JYPC6CtIMuO/T0sg7LIdj+ZGTkKZtxCISa98JP1MZDRo4rfN49MSjdzPgxx4OQrtwlMjXy054vYmyAs47hFL36fY+HhmEmAH8ELUqki1nx1J4iKMa7QdQrVxx7sLPfVJRaugIZu0LAaGaSx1Yw92xpVA0UyrNWjs8trjCOWM+PHQHm4pb6zKNPsOkXDbQxQ+lWWsudmEeaU69E0PPgyx9yH5uDRXOSHd9YGq0U/x2zq7Hnc1p26qNMLT7OgkKnIBGhCHmmLGbs8K6UfaOsbNpQoJU4pZv8/rSvUjNTQ4eeLJMMt419g== 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=afXyEcvsuoWCd8s0zOotz5dguSOVcmcu/XR5XYSSDmc=; b=b0o48C3wWRMbmw+KZb6BfbagMRN4Vh5GF1qWHG3eLatFPCu/+JYDAi0vwi4M2XVbJ2O/ryRRkIBSrmtz/eMDilD7F/Q201yWYL5QBFqFKHkCxTwDrQA6Hnci8Hb/Xrky6FXaL5n3o6liJapX89IE6SZjwMuo7/3js1ARMFJDvZk= Received: from CY5PR22CA0017.namprd22.prod.outlook.com (2603:10b6:930:16::18) by LV3PR12MB9096.namprd12.prod.outlook.com (2603:10b6:408:198::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27; Mon, 30 Sep 2024 15:30:35 +0000 Received: from CY4PEPF0000FCC2.namprd03.prod.outlook.com (2603:10b6:930:16:cafe::d7) by CY5PR22CA0017.outlook.office365.com (2603:10b6:930:16::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27 via Frontend Transport; Mon, 30 Sep 2024 15:30: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 CY4PEPF0000FCC2.mail.protection.outlook.com (10.167.242.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Mon, 30 Sep 2024 15:30: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, 30 Sep 2024 10:29:34 -0500 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra Subject: [PATCH v3 7/8] x86/sev: Add full support for a segmented RMP table Date: Mon, 30 Sep 2024 10:22:15 -0500 Message-ID: <333a437e6412a27ee666e10c2aca568985868ed9.1727709735.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.43.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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC2:EE_|LV3PR12MB9096:EE_ X-MS-Office365-Filtering-Correlation-Id: 63bf838d-fd8a-4946-61b4-08dce164d3f9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?QYouQWz5P+L2K3C7ygi05UsTLTbl6DLnQPQvxcp0C3LV4aiWPyzbxpSz5fgj?= =?us-ascii?Q?R9u+gnILIutuHwiEC6aKhpLKx9HkpyFxT0JApH+KXJsFctQZJpkxb8BGdspu?= =?us-ascii?Q?rvUBbAZ7GFZQK/HsgZAqgxr6WgYbsDuEiYTeFqg/wOqIUIRMzA7Xgu3Zfb/A?= =?us-ascii?Q?myb4BdvDLs+nc1wqw01Qqb7sz3CMm/T+k0pGN339trGX6LqoxaD4xMu/llSX?= =?us-ascii?Q?ESibdXjII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hbo?= =?us-ascii?Q?6ARLjIDJDHxaX9dBHL5zT/ZDUnQ/MywQAYN9uGcZ4c2+yhv/gans6x7vevA9?= =?us-ascii?Q?9i/yJ6R5Bnl7ezATgJC0+lYH+5rAIIpRkFw9SDSm2ieCtH3qhkAaOhRHJryb?= =?us-ascii?Q?HR7ach2UMpkIOFaBA4IZRZJ/D0GYF/k8zoGqjCIuJD/wQJXwkOLcPTP9DlxQ?= =?us-ascii?Q?IPyYIl3v3gB7m7hiR0NAGxDt/g4Nwt1Id83DvXXS7oR99D0OfobDIsQ9yw5e?= =?us-ascii?Q?MMY3pvHHAQTBSzoxaylNpBG9UVP7RGm7mz1+pAE9zpjaFKRAQeuTTPt7yHqm?= =?us-ascii?Q?XuYJy9seSpWRze0djJO/9R1YR4/oLPhz?= 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)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 15:30:34.5645 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63bf838d-fd8a-4946-61b4-08dce164d3f9 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: CY4PEPF0000FCC2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9096 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 --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 9 +- arch/x86/virt/svm/sev.c | 231 ++++++++++++++++++++++++++--- 3 files changed, 218 insertions(+), 23 deletions(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index 93620a4c5b15..417cdc636a12 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -448,6 +448,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..8b57c4d1098f 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -682,11 +682,14 @@ #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) + +#define MSR_AMD64_VIRT_SPEC_CTRL 0xc001011f =20 #define MSR_SVSM_CAA 0xc001f000 =20 diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index ebfb924652f8..2f83772d3daa 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -97,6 +97,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 @@ -107,6 +111,9 @@ static unsigned long rmp_segment_coverage_mask; #define RST_ENTRY_INDEX(x) ((x) >> rmp_segment_coverage_shift) #define RMP_ENTRY_INDEX(x) PHYS_PFN((x) & rmp_segment_coverage_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 @@ -196,7 +203,42 @@ 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)) { + unsigned long size; + unsigned int i; + u64 pa, *rst; + + 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]); + size =3D RST_ENTRY_MAPPED_SIZE(rst[i]); + if (!size) + continue; + + __snp_fixup_e820_tables(pa); + + /* Mapped size in GB */ + size *=3D (1UL << 30); + if (size > rmp_segment_coverage_size) + size =3D rmp_segment_coverage_size; + + __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 init_rmptable_bookkeeping(void) @@ -302,24 +344,12 @@ 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 @@ -336,11 +366,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; @@ -348,9 +378,116 @@ 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 *=3D (1ULL << 30); + if (mapped_size > rmp_segment_coverage_size) + mapped_size =3D rmp_segment_coverage_size; + + rmp_segment =3D RST_ENTRY_SEGMENT_BASE(rst[i]); + + rmp_size =3D PHYS_PFN(mapped_size); + rmp_size <<=3D 4; + + pa =3D (u64)i << rmp_segment_coverage_shift; + + /* Some segments may be for MMIO mapped above system RAM */ + 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. @@ -418,7 +555,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 @@ -451,6 +588,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("RMP segment table physical address [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_rmpentry(unsigned long pfn) { struct rmp_segment_desc *desc; --=20 2.43.2 From nobody Thu Nov 28 15:45:14 2024 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2087.outbound.protection.outlook.com [40.107.244.87]) (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 EB1F6192593 for ; Mon, 30 Sep 2024 15:33:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710422; cv=fail; b=l1RZBvo/jcyn61NA8VE5BFx7lkfWO0MPL2bMjskkQQYLlM76unFT2JVsGGi36isqdoWOKWgcLfPWE9mA7O0/djDrZdMpyJIlIlB4nwvwc90xJhZ3vh/Tk9yZxJ90mPx22x1sdCVgAB83D8ycHVMPPad1zwTYeAChPOQtrMk7JpE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727710422; c=relaxed/simple; bh=exS3C9Kcox2HgBeivQVKd8bigw+5WQNnQMJVz7yznoM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E2mTgTfQFKFd/6aLLq3LMrV2Xe4xMD84Y3QJfUat1BZIB1834zkpBG1nJdsPJr6ezruhD4C8ySIRA6WFRPuMFiQj3mHvLMopgBj+BGol8zAWRShxSWguLI094Kec5s/dx5lBW0QJ34OsV5dOziwpmG/Gbw4UEBGx0IxJGiBK2pA= 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=BeLr6b6K; arc=fail smtp.client-ip=40.107.244.87 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="BeLr6b6K" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yIxgEVJTBmeM8qmq6Cl0wSn+UZJkUjuItRb9tjw4ggy+tbi90Jxr0+dezi6R4/8GdpLlY5SpSEFrBN0AA7aAnzyg26kk+OEzaSgZROs4aXkaHA3e+c6Z1L4vyqvThCHk/7kB8LDl4v9OHib4MvfGMerD2+qtHdaTwdVW2m0Yp7qahWLaOWokDwl1RMm6XmvzQUCfb8d6PXwKaDDsA83ZQwgdD9+OtsFpklRXsZqToLAsmW9zyhNJTtiXMInGnx2vw1qVWJkng+YI7TCAXNTkz7xrQB8KxSeNZmhhlcneGebZUANVlCTbQBK9KFgP90W55ef3J4JnlnF7P+H+wFZzbw== 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=NBhIpja98ZqmhMQxfkiHVZI3MuNCTeFhISy+3+R8Cog=; b=yQGkKa2WHc+MzRBsBvjEPKjsQXDh3zni6L5BJHFSW1Sp1GSvwk+DfdrW2VpSRXv9kqPQ4GX91E8z+SV1l3ZRdad4fBtAg3MmMZyJj0MGOgqkHn3eB9VNaOglbiVtJ/aKHbuPjzApOBybK4cihRuouYa2j9dzGLH+MwSbXfoLbDdHVMXPgr9R88AuYjui5H903uqe5120aKA7u+5TCo5fyPUuz8ezatZo6sh272cgZ9I6wJ4mEsdcUdHl+Db1kCG0uSqu9yrfjGiFwLMbQn1wlso08fAETAIBwgO5u6KgDA2baiUPFcaIfQ40C33vPx+1zj5Q1u+DlSaD0ix3NYbP/Q== 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=NBhIpja98ZqmhMQxfkiHVZI3MuNCTeFhISy+3+R8Cog=; b=BeLr6b6KVAN1DSsOSiS7CHpRiSPV2nO7FvHRYsDOUZ/D/jqAi/A6qvy61Ax2ZrSS1OvTYCU6HGa6TaSYhpraGbzilplr4sVTJnssAAPvQ3CtkaZExUh2MQU7mWyYvmUruzl//g5HgoRzu0jN1PfUNf2PTsO/lMJ2nPlJU7AEDv4= Received: from DM6PR06CA0093.namprd06.prod.outlook.com (2603:10b6:5:336::26) by PH7PR12MB5656.namprd12.prod.outlook.com (2603:10b6:510:13b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.22; Mon, 30 Sep 2024 15:33:36 +0000 Received: from DS1PEPF00017090.namprd03.prod.outlook.com (2603:10b6:5:336:cafe::9c) by DM6PR06CA0093.outlook.office365.com (2603:10b6:5:336::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27 via Frontend Transport; Mon, 30 Sep 2024 15:33:36 +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 DS1PEPF00017090.mail.protection.outlook.com (10.167.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Mon, 30 Sep 2024 15:33:36 +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, 30 Sep 2024 10:30:39 -0500 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra Subject: [PATCH v3 8/8] x86/sev/docs: Document the SNP Reverse Map Table (RMP) Date: Mon, 30 Sep 2024 10:22:16 -0500 Message-ID: X-Mailer: git-send-email 2.43.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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017090:EE_|PH7PR12MB5656:EE_ X-MS-Office365-Filtering-Correlation-Id: 632b9ad9-ae58-4121-7cc2-08dce1654039 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?T9+tPFnBzVDMSvxyQPd6X8Gc5gb7VvdLS38xkeUct1Xk9HPFKOMVpUEMnJ+B?= =?us-ascii?Q?mPT3ulQ+2w4NvYqPzWL7Km0XlSxhUkrEaIhx+qrIEXGUd7mrxOwNvzh5dd8j?= =?us-ascii?Q?babvtnhqo7JyMLkY/q8lQt0UjAx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Qo6WTw+JLGvGNqVJYbL8VncxTQjA5icPuUFxQZxQ3HBDspcMSI5?= =?us-ascii?Q?p9A34LpLGYFXOcBJHThQHMyw/89j4yfM56a/g6h9WVSLwxCgnKO4nhpQ6BER?= =?us-ascii?Q?PJI1XGi0B9CBZF5q+drcvKTiHRk7rFMV+QM+d+Sa5pw4YnvPbbr0B5wGYwC/?= =?us-ascii?Q?5ZhgKErdO/ltz/XHeRnvUNYZo2dFoaCSEIrHy0gvlVQwaT6eBAItb1ea/AC0?= =?us-ascii?Q?DLDjOv2R5zZsVb+KUoToh/WDQz0gHck+RHyHV5R+VHXbpyvOnYAZ6sR4fsKM?= =?us-ascii?Q?Xd4W0Fog/By/EFVsTZF0j+iDT/jicjePRPYkfK6cwLyrqY5dQ5hEiSZyf/7r?= =?us-ascii?Q?iSlTqtjzLa9R75/3/Or1O6/ax5XyQCeRyTHUc5oPZDHqI8o48i7DHltSgeI/?= =?us-ascii?Q?fFpoDG2hhUFaL3wHDkvv1v4hz1LD8/5E?= 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)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 15:33:36.4129 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 632b9ad9-ae58-4121-7cc2-08dce1654039 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: DS1PEPF00017090.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5656 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: 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.43.2