From nobody Mon May 25 04:33:44 2026 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011040.outbound.protection.outlook.com [40.107.208.40]) (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 7125939657D; Mon, 18 May 2026 21:42:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140536; cv=fail; b=P9/rp5bbHSuCQTue4TssRmFI2qUCHr2M8lzyIwUa+qZBVf3Bz8TynsW7b5VxXiptTbTsF+gWSUejp8EJmjeFLajO+4MU69PNb7N3OkUkhEdGYhIshpHlyeZibH43SLU1+jgCzZIMunCwzbJkEtDaoswVNBF0dYlgsmN55plaOpE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140536; c=relaxed/simple; bh=sLN5AmOajVJaGH5CIEGmacfAvxKRgFVGv7NYWOfd7AY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aDP/QZxfgben0w+EjVIiIYrWtzBMwp/NT2ah2SnnOByWIZcvtA2OgKt27f8TWjDbIxsafXvRylOwI7YrZ1anSHyAfQwZKCfQrJMbal9uJQD6BkJ59McyB2MseWZ12PI4Y1ADRO1ZQ+Sk89vnlRoD1h2QQsBFyUH3PEGMV6c5uGY= 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=J/2X9ki8; arc=fail smtp.client-ip=40.107.208.40 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="J/2X9ki8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XCpLcP+7wv0ZGjvQK2rVc9CEs9JmYtbYOS/sy5J8Tf3SS0uS5J5oSlRV9PPgdvUFjrOi4optCoA40ERq8MzMfLlnZOHxvwYtK188Tl/B+RJsF+bi3Jw6zi/nDZB1k6W/L7/71kUB/IPhrqf1yNygHv43xtjCzPMhsxuxu6BcMtdblEs5xJXmeT1iIP6HmFPrCil2Rv/nuaGrvjbNmW85mNYBG2jc/OG99mNXJjwS3tiL8RT0GoFh9nDdpz1lhqJ1f+s0f56v4NhecXBmyIOSDiAAvV8v+wcvtfiF/gTsRch3fmi7sQFsF4qMfP/J5x/nLHsvceCj9LY9zJ7IUgnl5Q== 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=TOPZ6AuKEzThiVFV+sWlKZLoRw4NSQECVUsoQ5th06A=; b=hUSg8IHh1WAK3FhtTYObA3TeBVKVJj/C0Dt597h4i/kfD+DwKEm+Jh0KzT0kAvPICyyKmN9x6G2NS7HZKgz7ynkvElCOI+8rdQjKxFV2Whn8pjobzwwo65sOnyXHoDOVQXI0HcSb65kX5NV6UQ0EFiJAu1jVO62mYnMK8+c0flphGVGm/fPTWgSJpLW4r+B4pvEHWn2KkGrMqIHWfjf9ngkdmKtBlrME2ahi1Cqrj7O8iV6p5fMh+/MvkSlzaVKyACG9J4I6EZoNZnOhfR5QDxcTcBCaLfDOd/nWWW4FVqLaO952vWCGZVbTil6l1KdvyRqccWNSXJMl0E3QpvbkyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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=TOPZ6AuKEzThiVFV+sWlKZLoRw4NSQECVUsoQ5th06A=; b=J/2X9ki8zoIeYRE5Tn5PGRKNGKKwolV46ohMrJ+/GNn/snP1v6N+07W4dQuToswAL13pIW4XqkHFPL7lyzEg6fW/aGAKJwsXXubqN+NVN0aAKdPfC0SvSgpWguX9OU5OExPTq7FsBrMbF6iu2gbbRLulTJFZmO5d0izCLVKn4xU= Received: from CH0PR03CA0046.namprd03.prod.outlook.com (2603:10b6:610:b3::21) by DS0PR12MB7828.namprd12.prod.outlook.com (2603:10b6:8:14b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.25.19; Mon, 18 May 2026 21:42:10 +0000 Received: from CH2PEPF00000099.namprd02.prod.outlook.com (2603:10b6:610:b3:cafe::36) by CH0PR03CA0046.outlook.office365.com (2603:10b6:610:b3::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.25.23 via Frontend Transport; Mon, 18 May 2026 21:42:10 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH2PEPF00000099.mail.protection.outlook.com (10.167.244.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Mon, 18 May 2026 21:42:10 +0000 Received: from nigeria-2635-os.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Mon, 18 May 2026 16:42:08 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 1/7] x86/cpufeatures: Add X86_FEATURE_AMD_RMPOPT feature flag Date: Mon, 18 May 2026 21:41:53 +0000 Message-ID: <305b625c0528f16a95542001c66e643fbd3a2622.1779133590.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.43.0 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000099:EE_|DS0PR12MB7828:EE_ X-MS-Office365-Filtering-Correlation-Id: 8151e459-2686-4150-e05f-08deb52650e4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|1800799024|36860700016|11063799003|22082099003|56012099003|18002099003|3023799003|921020; X-Microsoft-Antispam-Message-Info: X6Zo3dqiy2fjT5oEgrhxc2xhVb/Q6Zn5xFGMKQKG2zDJndzsEMGDkOtgIjysxnIb+28z3JrB6OmKFWCsu1TEVSZgzhKe8HUKG1GtLsV7TsBHFR3hBisQvT6Jln05QuS8GeHU62M7LmGaI0vabQFOh4QxFBLoKxYuOrxBJe4TJUYhiMht8Tc3KrQxudRWQjAdAF7568r+OTx4LH+MYqNOp9SBIG8ikZSnnOwR1u+ObAzA5LZ2lEPxc0nI0orLONPYA635yr21pCyGy//fB7l8YCwGbw8GWyy0fR6uVqn90v5T5LZDIYVstAZvnb5J27mkotSCZZ9E/84+KDMxr1fagHx0xk22xqXo51GJIY3VX9qHL2tIb1aM15t+HyWkE1NGX13wk/t0NL3ASCu0/RuJlg0PZ11lh8KRhJGeD8ejYpjlnzdtZsGqpjm/2loV2lt8L+hJVkFlsYGfbDbcAL2Ua84iQszXU6FUSSgfm+BPWzgKkJZA6ye1VUf3fLXp39X4EQ+gfVQxfHoATFtgUhyC61YpVSX9/k4N3CLj1QpjXlkwfdpOiwbL4HwqoqqTCpLsvO3Z0fepnIQPjJLrc4zIBn7artoifSISodrqC7EeHLg4kZcMSKWE8tWNl8INf5n157uxIyTAWFu4/JTEDGaxsSdiuiKG3acW1wOcSNFnd/Dvkx1bt+bziDJ09SxubTBOLtHsgGSt1XiYxEeRwe6ctj2DlgQkhx6ebD9vK4IMdi+hWI/dQbCMTdlXCAzoShHaycQfOgGY/puSGcGReqRYzA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(1800799024)(36860700016)(11063799003)(22082099003)(56012099003)(18002099003)(3023799003)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iQjRZgZZWBCR0kg8nrtGiP6sR2YBzI+6xYATbac1W/AuC7z2vX8ui5ab8mLrHqaprdPsdOPzokvawtkwDpyKwQwo+fJjiWUjBTxBqmYJHI63PxwuxFd5ALcr1nxUsaG5PoetDgh2Cr/xcdRCkU8Moxx9LRqhxCPSYIDJ4NDsDYJNL5RpgYq+hUPVTvp6cf1Rchty6XHZeHSYgc8Dh9AoPc+MYTne+b/Zf+03B9RJ7TkcNj58u6eRfsTumFx/kxV1GiaLFrNLwBFDsCxezUYOqJkj7xtrUBu8XI1TXd8kLax32zBlwJ1IIgE4JZ3D6uII4Hog1A3Tep259rBRTnX5poTPIdDsgQzy+WwDgrOK9gVQ+9JzfbewI4mr8OEs4CLKsmLhZ9nlUz2NxUiWpL0XBTiGE39naubIkjXQHTeNLrx3CW5ir3w4icL9JvOQCcjF X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2026 21:42:10.3217 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8151e459-2686-4150-e05f-08deb52650e4 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF00000099.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7828 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Add a flag indicating whether RMPOPT instruction is supported. RMPOPT is a new instruction designed to minimize the performance overhead of RMP checks on the hypervisor and on non-SNP guests by allowing RMP checks to be skipped when 1G regions of memory are known not to contain any SEV-SNP guest memory. For more information on the RMPOPT instruction, see the AMD64 RMPOPT technical documentation. Reviewed-by: Dave Hansen Reviewed-by: Ackerley Tng Signed-off-by: Ashish Kalra --- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/kernel/cpu/scattered.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index 1d506e5d6f46..794cc96b8493 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -76,7 +76,7 @@ #define X86_FEATURE_K8 ( 3*32+ 4) /* Opteron, Athlon64 */ #define X86_FEATURE_ZEN5 ( 3*32+ 5) /* CPU based on Zen5 microarchitectur= e */ #define X86_FEATURE_ZEN6 ( 3*32+ 6) /* CPU based on Zen6 microarchitectur= e */ -/* Free ( 3*32+ 7) */ +#define X86_FEATURE_RMPOPT ( 3*32+ 7) /* Support for AMD RMPOPT instructi= on */ #define X86_FEATURE_CONSTANT_TSC ( 3*32+ 8) /* "constant_tsc" TSC ticks at= a constant rate */ #define X86_FEATURE_UP ( 3*32+ 9) /* "up" SMP kernel running on UP */ #define X86_FEATURE_ART ( 3*32+10) /* "art" Always running timer (ART) */ diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattere= d.c index 937129ce6a96..021c0bf22de2 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -67,6 +67,7 @@ static const struct cpuid_bit cpuid_bits[] =3D { { X86_FEATURE_PERFMON_V2, CPUID_EAX, 0, 0x80000022, 0 }, { X86_FEATURE_AMD_LBR_V2, CPUID_EAX, 1, 0x80000022, 0 }, { X86_FEATURE_AMD_LBR_PMC_FREEZE, CPUID_EAX, 2, 0x80000022, 0 }, + { X86_FEATURE_RMPOPT, CPUID_EDX, 0, 0x80000025, 0 }, { X86_FEATURE_AMD_HTR_CORES, CPUID_EAX, 30, 0x80000026, 0 }, { 0, 0, 0, 0, 0 } }; --=20 2.43.0 From nobody Mon May 25 04:33:44 2026 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013046.outbound.protection.outlook.com [40.107.201.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 8328439657D; Mon, 18 May 2026 21:42:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140556; cv=fail; b=bAXB/Y71HignW53kuGXhQsXxuejIhVcmdIlfJblNWyt6hkYCY2BDy2e3zs44xsB6atWGGZWYnHkGEHbtAwjZatvTdylqdyuWGgDTXlbOP549sX7E84vy/f7OmTpy0VBBU3PYsfd222r53NUnnNoJvxYzPrdGsd+IucKrzgfBFQs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140556; c=relaxed/simple; bh=sDqcWaKII8p3b0bUtEF+0vM3OdtkxTPrI53Fti45BTk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sMGtuFt/f+r4mPaNfHU0XqznICcXSL5Q0Fox+Aw5hRjpnd3TGBzMA52ExAOJcmL0EIV2Z5QNPvTAsAOvscYtKFi2tO2UDNUvjOathb9G4aM3lYvW3w7HLqm/BO97/Q9kT7v3tfdpfBUK9IxUHnpR/s9SQ8usi9Iw0b1ulAmDFw8= 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=hnrS1//E; arc=fail smtp.client-ip=40.107.201.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="hnrS1//E" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZlCjozUVV9gcp7UwqMWNK66UNfRtaW94tDt7p0Q0Wwy3JGZBP5AU1kjwdz22cSyx46fwfZDg0FJf41mDrjZl8Co7cZkZ4GSMJo5ZKHIjsK3bdONEcgQ8goyHF4EoySbMSErQCrYzgLnMbdyaq7Ti+qsUccNNbJfn+X4EZHH+eFWhFii/tc7MJrKQqEL7BPF/IGhyI+3DOJbTjeQBZcEXt21cDG+aGvN5M2v0G12QH/tGneC0Xee6e55AN4vbKu3sEdkfAmDkuB1ph3zTbapLbBkAUiDgIXxkBDli7vo7x6fXRnGCs5H8p442pyi/dKqO7RELP+cAuAAx6LXYHIDbIA== 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=7JmmRf/nL3QrCrrIVhqHcuRXy07ShGxjuAyQuXTnCak=; b=GAVShBb9u0frUMy+/2l9RACKSOXduN4Tu1ClOqWdS/wEVjQ8OrnEUTik4uF4OrmexmCp9328t2cNlrxc8w/e6OVBZPZkkiGpK/fWOCC0fLYUIJbgRkf941g13Zi4JgZ1ccBaM8r7YyWvi6ZzMw+uU10A5byvWGxHn8zCwt4omC/I7CEvve7smTaaMO5GwJIfWFD3Kz9LMG863WMdXU/0K9eNhj5UHvgKsNq9qADHtWiuiyAlFjaEiUoG9zFFD0MLftc0LuMGT3qveCrPI5TNnaAP+a3qg/PubbcI1ncuUbcb/kmMvliVKMk29E8+3uvQzfx4O7l4aVFWfmlbQwtuog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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=7JmmRf/nL3QrCrrIVhqHcuRXy07ShGxjuAyQuXTnCak=; b=hnrS1//Ez4BEP8CSdJXkwUAPbqzxod2SczwaUOwC6khHI/ryCzWRyRtrwN8zRhCHl3hCWeQxRjGgjLZn2tM5z1vUC27KPK3RYWtjXE9oqfELbFgJLAdayBSgAcpqtY8nzwb6WdgK9oYA64THBJ3YdP1WUzVniNOwfxeAHp0bhJQ= Received: from CH3P221CA0015.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:1e7::6) by IA1PR12MB7567.namprd12.prod.outlook.com (2603:10b6:208:42d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.25.23; Mon, 18 May 2026 21:42:26 +0000 Received: from CH2PEPF0000009B.namprd02.prod.outlook.com (2603:10b6:610:1e7:cafe::3f) by CH3P221CA0015.outlook.office365.com (2603:10b6:610:1e7::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.25.23 via Frontend Transport; Mon, 18 May 2026 21:42:26 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH2PEPF0000009B.mail.protection.outlook.com (10.167.244.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Mon, 18 May 2026 21:42:26 +0000 Received: from nigeria-2635-os.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Mon, 18 May 2026 16:42:25 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 2/7] x86/msr: add wrmsrq_on_cpus helper Date: Mon, 18 May 2026 21:42:15 +0000 Message-ID: X-Mailer: git-send-email 2.43.0 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009B:EE_|IA1PR12MB7567:EE_ X-MS-Office365-Filtering-Correlation-Id: 59feeffe-8436-4c67-15d8-08deb5265a94 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|1800799024|7416014|376014|82310400026|56012099003|22082099003|18002099003|921020|11063799003; X-Microsoft-Antispam-Message-Info: zV7ATvMb6LF4ApFokEKwov9urpx1+O/CKK6l+o7K+CI1lyE/KiSZceI9NYHErEr6+swh4thkpiImnbKjDAxrBBCKvfYlRaH8JaYPUjXjJEJTgXLNvXrTZGmvJRGmDrKuq7kIaOpLujgcUBSSxjz9bw872fN+3eyOtrWknLQfXE7wmiBqCl5doTuMVzW0bUtJ+JBEMOVurVJOdNAA5cEVreMLBOMkw85ktxhFLtQUJmsW/tJFx2s1Uv62BdZ9xBohcoBffHrK5Acf2ydFb4hhcGQMMsHmmZNqcKjUjIC2K7roZKTprKMirjJZSrX+yhjjqE2UaA8dv8eHoQqMc4atlQjgkYBiUpOMDVIKx2ifRokrrcIsRArEc22/a6lf0cd2nPpJLEajmf2ig8gZlwvYzqEcdnLK8UG9hhIYW7Zc2M+zojXSab3i6N4tkYrj9w0A47UKnJ2aWTSo3YCDaR9eYG1+A5IvVQ4hyLVzuxazecuZjhoRXd/BYR6ZVhPlN+fnAuhy2M4uIEyccDXXvTGUrtneZWFw8dvwFtwuCqyZvOejnHNllIlmaAMAOGzZmo3vyhOOFH36k8LjQVtRNpC2+8RBAGqFxppLDxgVM2cQaU2Brh6uu3uCmRYmZ4ylUdwiqsF2gWdlVVRkV8CoQyHER0ifrSzdWoS5LHfDhTv6RnQTZU98kft2LKBtQfdV1VlWj2QrQVtF1Rq4deYplPHbLSkNiHovs5MVY9LWkZcyQKWZn9usGCAwk6+MYyNYgl1fMho55cHAl9ACizesOP+Fdg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(1800799024)(7416014)(376014)(82310400026)(56012099003)(22082099003)(18002099003)(921020)(11063799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aH9H58izw5XCnqNIGFpb9wLZUPPG4BuVKG681StdcWLfShyrAWS6XeP1F05SuMgWqcz6hpFE6d0zlswf3+5fxd8ZlOgrrEuZBWt3KLSjfSs1BVdbaJuS8gDQHBhOpV3d2KfLFcp2phGLDsoXA8hf491JJca+nycyWf4842OTdN9VbjEKgHyi0oVerCNJXm0cC9zmSi+o7hVRtFT5WSjJVdYi4DAT9w53lhdTx1Y09kl3wkutHGeh37Zf4NdRDVD51N7hf0T1+Uonx0aKYH8/tQHl8HTYTiGKSWS+Hs0V2ceWc4liUO6mK+6W0rz0EP88Y3myf0dKXra/kJSU/EIOuOvzU9phdj43C9AJucRHp2WfajvCvbHM/E3zjKmasqGK/FGwXqGSvugRXjCul/sN+mHvfcVR08/b8M1M+qw39dp3DWm1UasSpF9llS4bh+aJ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2026 21:42:26.5630 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 59feeffe-8436-4c67-15d8-08deb5265a94 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000009B.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7567 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra The existing wrmsr_on_cpus() takes a per-cpu struct msr array, requiring callers to allocate and populate per-cpu storage even when every CPU receives the same value. This is unnecessary overhead for the common case of writing a single uniform u64 to a per-CPU MSR across multiple CPUs. Add wrmsrq_on_cpus() which writes the same u64 value to the specified MSR on all CPUs in the given cpumask. Co-developed-by: Dave Hansen Signed-off-by: Dave Hansen Reviewed-by: Ackerley Tng Signed-off-by: Ashish Kalra --- arch/x86/include/asm/msr.h | 5 +++++ arch/x86/lib/msr-smp.c | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 9c2ea29e12a9..f5f63b4115c8 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -260,6 +260,7 @@ int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, = u32 *h); int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h); int rdmsrq_on_cpu(unsigned int cpu, u32 msr_no, u64 *q); int wrmsrq_on_cpu(unsigned int cpu, u32 msr_no, u64 q); +void wrmsrq_on_cpus(const struct cpumask *mask, u32 msr_no, u64 q); void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __pe= rcpu *msrs); void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __pe= rcpu *msrs); int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h); @@ -289,6 +290,10 @@ static inline int wrmsrq_on_cpu(unsigned int cpu, u32 = msr_no, u64 q) wrmsrq(msr_no, q); return 0; } +static inline void wrmsrq_on_cpus(const struct cpumask *mask, u32 msr_no, = u64 q) +{ + wrmsrq_on_cpu(0, msr_no, q); +} static inline void rdmsr_on_cpus(const struct cpumask *m, u32 msr_no, struct msr __percpu *msrs) { diff --git a/arch/x86/lib/msr-smp.c b/arch/x86/lib/msr-smp.c index b8f63419e6ae..d2c91c9bb47b 100644 --- a/arch/x86/lib/msr-smp.c +++ b/arch/x86/lib/msr-smp.c @@ -94,6 +94,26 @@ int wrmsrq_on_cpu(unsigned int cpu, u32 msr_no, u64 q) } EXPORT_SYMBOL(wrmsrq_on_cpu); =20 +void wrmsrq_on_cpus(const struct cpumask *mask, u32 msr_no, u64 q) +{ + struct msr_info rv; + int this_cpu; + + memset(&rv, 0, sizeof(rv)); + + rv.msr_no =3D msr_no; + rv.reg.q =3D q; + + this_cpu =3D get_cpu(); + + if (cpumask_test_cpu(this_cpu, mask)) + __wrmsr_on_cpu(&rv); + + smp_call_function_many(mask, __wrmsr_on_cpu, &rv, 1); + put_cpu(); +} +EXPORT_SYMBOL(wrmsrq_on_cpus); + static void __rwmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr __percpu *msrs, void (*msr_func) (void *info)) --=20 2.43.0 From nobody Mon May 25 04:33:44 2026 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013014.outbound.protection.outlook.com [40.93.201.14]) (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 4C8BC38AC85; Mon, 18 May 2026 21:42:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.14 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140569; cv=fail; b=Mn9Zt8C5UgfO4Yn5WpTh0KPgGiNffHn7VoFj5D4PmWdVDbD4ZgYt1ckFmLxdxbRyuUasRvsSaTWHIKZoBpoLHwLb2Aw2NmxIDWexyHOjQ0qbCrwz0TD6Gcb4KaSpDWPE6rCKofV8B3F2k1UDrqFQx3MEUGNMhJ0w80UYFdaaX0c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140569; c=relaxed/simple; bh=AgyTp09JjTJmgR0TCcTG6IRMJTAN/w1JSWTkYAwSJec=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GklcvykKxSeZZITaXrOGPEYHjAxHyDKwtii3ZqYj/m8Ac+/gaD/dx/jfGdNsJw8rZ8/0tLpBsVJYbewwn6wqyFFmiDAAHGbEkxFbnYbknIMxQvaF1nvf5+hGhmNe4PWFND18uKbr/PfXu/kPxVhOFikrAcNTUuB2g1hVOc4GdIw= 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=EsHAu/3c; arc=fail smtp.client-ip=40.93.201.14 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="EsHAu/3c" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WQNqKLDNN3Q2bOjgQKTFGt0EkQt90ItkkT5sMgZb5RcoOORNyr1PDOPz8Uy7GpYBX6JZBD5e/yFMZirINaycHCk/Ayum8Tvww7+zkCSIrrMbIBXeMQw3bep82WnyjY93/5cabQeseWp6We815p8w9kqoWmApBqtpbCU/DNereNjvwtfwZR9QneH0hSE7DOI7Y+DCpXqOUqs/1dcXjDdgBBidq6jX5Ag0wzoSPkfZJX0WaSGJ/fs+MRTEAiL5lf+MjbxImo5VLdvUIK4YK63+sGIacs9frDDi2wYumhVf/j3i73BF1OX3NMuswrkFxQQQgtl02oaAPPZRuQAYSdRsSA== 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=o/ZJLko5Zf23sb7ngFnuA+NYtTRobuc6fv+N0U8t3RY=; b=HRyrr4WibXKNDFqYr/H57q2z8aR1xII1PkSVTpBaDmeOOA5EINGV/RKpHbs/aEGsMfOqZIXghUW9pIrLQsDE9H1pvw5cmVcGPv6ZYj2b4VqoF6NCZPIbANRFtkKrYmQnmkj4ukaLZyDBG0tqrTxii6joM5gkxRhOEuoXjX1uYbYK/fxziMu56gXhEvjTQeB9pyXB4yiP8HOBJHiRa8VQS1YWRuQZBRYVjmhKIN5T+NfwRYemYnEYGi2abrd9jPjp6qS9u/MPi+4MFPLlvQhzs4Dx0sPVCrt96IisA3hXOTt/8OFbDII+6euSuWVWJ+OTlYMhx/yZRYmj20wEfOM9Tw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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=o/ZJLko5Zf23sb7ngFnuA+NYtTRobuc6fv+N0U8t3RY=; b=EsHAu/3c8qrnT56zsOi9+iix962RsqD2tECnFoEubSTyrCjCMlHxop+6D6cZPaEXsfsLhHxIAKETgCAu38cmRXUYhdjeLVu7Q+Baq5nYKGzQQy6oQbYWUFg9yFq6VSlOUOCvNc14qow1Uuk1wqQ51iLrdCncJguiaQCsCWEU91w= Received: from CH0PR03CA0419.namprd03.prod.outlook.com (2603:10b6:610:11b::8) by DM6PR12MB4355.namprd12.prod.outlook.com (2603:10b6:5:2a3::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.25.23; Mon, 18 May 2026 21:42:43 +0000 Received: from CH2PEPF0000009D.namprd02.prod.outlook.com (2603:10b6:610:11b:cafe::d2) by CH0PR03CA0419.outlook.office365.com (2603:10b6:610:11b::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.25.24 via Frontend Transport; Mon, 18 May 2026 21:42:43 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH2PEPF0000009D.mail.protection.outlook.com (10.167.244.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Mon, 18 May 2026 21:42:42 +0000 Received: from nigeria-2635-os.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Mon, 18 May 2026 16:42:40 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 3/7] x86/sev: Initialize RMPOPT configuration MSRs Date: Mon, 18 May 2026 21:42:31 +0000 Message-ID: <091ac9a1498514744be85ffaffb5e0283d99814a.1779133590.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.43.0 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009D:EE_|DM6PR12MB4355:EE_ X-MS-Office365-Filtering-Correlation-Id: ccb19124-f359-470f-09b2-08deb526645d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700016|1800799024|7416014|376014|3023799003|921020|18002099003|22082099003|56012099003|11063799003; X-Microsoft-Antispam-Message-Info: QYlkZC41fQBDMPCw99F++q+XjPy3YBhyfDeOnyDsgdfwb7C/6kb+bFFVGWjb4oQ3AKPaEJkMJjD9GZbyT+ZDjeSXr+oxN3DlcnSxCC5iwUAWf9XOZnUV5PnwK4vKzaNWVCrFexOsscfABI8Z/t3RNzDGaqCCzebw2jwBfH421XKJyBakKKKIFyVlq9fE4euT2yyD/nGf5rhE87+U1D2Xwf7KK7tRrBLLnzhxo4nvreYfqqCDY1aG68vOQSXzqsBZW2wcdCpKPUG+NzkWmKDhZ99zSISUvT0Q1siR5tLuKxtU1yR0ATrtVDb1ttUG67qfPEERVLJDkDL4s7YwX2+YYdze3vv1NGKzstrv/g39K9TsK4qbkTB9w70bBpZnKq08SXgDa52Bf/M2kKG00s8cEwvy37WH3YC9s1g0bbZVpeXC8NM8O5BDVSsQBt5tru8l5N4rq5HvPt34WGwT+AoBEp+ptGEamSUX5lU3zvfY1NBSkCxYwuQ/VQxZ7u+oyPvZ8n0i/+EzI+H2sl3CmsOvk75zzi6D61RBUDrsRDf38BunsCE0FBdkHO4MLOhOpkDTby6gfZaSO4NjI6UVei7D/qekeN3dkry4wYub//qTCkX/a1EST6hONN8qHhQM1OixzkxwL3Az9H34Ahkx/twCZKavK3pZzmN1eEmaz5cjobzsogWr/11Ty5a+tAp6f3ZcTuQeCmScfNgYlYy4zqcnCMa8AI/JtkocaQqA4+BMwYQOksvc3xpN7gsNBVmaDVWhgz3BPjssT5MlOTsD1NG+qA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700016)(1800799024)(7416014)(376014)(3023799003)(921020)(18002099003)(22082099003)(56012099003)(11063799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XoL5aTGp1Gt5H+lKoFZWDP9y9Y3J5hIpwpIBrE9DPYD/Q3yGd9TdF274Jq5UZ4epuWMgmbmdZnCkPKZOwRwn96rzaE7+oKPnu1tQ8I68vSAG8JGWCdF8kg4HmDyPZUvtUm+GuUUVvzykkaHeIWkkOnb6GUJssxfiuej2NHw/BxEeqLYQNYwGaY950OQIMR7e575QyI841W/y4Bbe5Ha/YN3+2ZNc9SijWIe0AD9cIOkJlBilG2T5D2DbncFxP1TU21B/I1bcNlC6STAzyXVQEdo9MqANrM3i+Bank4xbaBkHSnjZIEMbB3NLkzZivTwG8YlTsK7SNrElGtOZWsJjN8u9L33W3GkRd9V/EOTVXBtvfedXReYu6a/FV52LiY7llJeVu+/OpdCjLe8CwXLxH/UmZaBPzy86TJbqDAugBWpYGQM9sJtf3mXHX7aPgWyf X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2026 21:42:42.9862 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ccb19124-f359-470f-09b2-08deb526645d 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000009D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4355 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra The new RMPOPT instruction helps manage per-CPU RMP optimization structures inside the CPU. It takes a 1GB-aligned physical address and either returns the status of the optimizations or tries to enable the optimizations. Per-CPU RMPOPT tables support at most 2 TB of addressable memory for RMP optimizations. Initialize the per-CPU RMPOPT table base to the starting physical address. This enables RMP optimization for up to 2 TB of system RAM on all CPUs. Additionally, add support to setup and enable RMPOPT once SNP is enabled and initialized. Suggested-by: Thomas Lendacky Suggested-by: Dave Hansen Reviewed-by: Dave Hansen Signed-off-by: Ashish Kalra --- arch/x86/coco/core.c | 1 + arch/x86/include/asm/msr-index.h | 3 ++ arch/x86/include/asm/sev.h | 2 ++ arch/x86/virt/svm/sev.c | 59 +++++++++++++++++++++++++++++++- drivers/crypto/ccp/sev-dev.c | 3 ++ 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index 989ca9f72ba3..7fdef00ca8f2 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -172,6 +172,7 @@ static void amd_cc_platform_clear(enum cc_attr attr) switch (attr) { case CC_ATTR_HOST_SEV_SNP: cc_flags.host_sev_snp =3D 0; + setup_clear_cpu_cap(X86_FEATURE_RMPOPT); break; default: break; diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index 86554de9a3f5..28540744f1eb 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -761,6 +761,9 @@ #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_RMPOPT_BASE 0xc0010139 +#define MSR_AMD64_RMPOPT_ENABLE_BIT 0 +#define MSR_AMD64_RMPOPT_ENABLE BIT_ULL(MSR_AMD64_RMPOPT_ENABLE_BIT) =20 #define MSR_SVSM_CAA 0xc001f000 =20 diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 594cfa19cbd4..6fd72a44a51e 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -662,6 +662,7 @@ static inline void snp_leak_pages(u64 pfn, unsigned int= pages) __snp_leak_pages(pfn, pages, true); } int snp_prepare(void); +void snp_setup_rmpopt(void); void snp_shutdown(void); #else static inline bool snp_probe_rmptable_info(void) { return false; } @@ -680,6 +681,7 @@ static inline void snp_leak_pages(u64 pfn, unsigned int= npages) {} static inline void kdump_sev_callback(void) { } static inline void snp_fixup_e820_tables(void) {} static inline int snp_prepare(void) { return -ENODEV; } +static inline void snp_setup_rmpopt(void) {} static inline void snp_shutdown(void) {} #endif =20 diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 8bcdce98f6dc..82f9dc7a57c3 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -124,6 +124,9 @@ static void *rmp_bookkeeping __ro_after_init; =20 static u64 probed_rmp_base, probed_rmp_size; =20 +static cpumask_t rmpopt_cpumask; +static phys_addr_t rmpopt_pa_start; + static LIST_HEAD(snp_leaked_pages_list); static DEFINE_SPINLOCK(snp_leaked_pages_list_lock); =20 @@ -488,9 +491,13 @@ static bool __init setup_segmented_rmptable(void) static bool __init setup_rmptable(void) { if (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) { - if (!setup_segmented_rmptable()) + if (!setup_segmented_rmptable()) { + setup_clear_cpu_cap(X86_FEATURE_RMPOPT); return false; + } } else { + /* Note that Segmented RMP must be enabled to enable RMPOPT. */ + setup_clear_cpu_cap(X86_FEATURE_RMPOPT); if (!setup_contiguous_rmptable()) return false; } @@ -555,6 +562,16 @@ int snp_prepare(void) } EXPORT_SYMBOL_FOR_MODULES(snp_prepare, "ccp"); =20 +static void rmpopt_cleanup(void) +{ + cpus_read_lock(); + wrmsrq_on_cpus(&rmpopt_cpumask, MSR_AMD64_RMPOPT_BASE, 0); + cpus_read_unlock(); + + cpumask_clear(&rmpopt_cpumask); + rmpopt_pa_start =3D 0; +} + void snp_shutdown(void) { u64 syscfg; @@ -563,11 +580,51 @@ void snp_shutdown(void) if (syscfg & MSR_AMD64_SYSCFG_SNP_EN) return; =20 + rmpopt_cleanup(); + clear_rmp(); on_each_cpu(mfd_reconfigure, NULL, 1); } EXPORT_SYMBOL_FOR_MODULES(snp_shutdown, "ccp"); =20 +void snp_setup_rmpopt(void) +{ + u64 rmpopt_base; + int cpu; + + if (!cpu_feature_enabled(X86_FEATURE_RMPOPT)) + return; + + cpus_read_lock(); + + /* + * The RMPOPT_BASE MSR is per-core, so only one thread per core needs + * to set up the RMPOPT_BASE MSR. + * + * Note: only online primary threads are included. If a core's + * primary thread is offline, that core is not covered. CPU hotplug + * is not currently supported with SNP enabled. + */ + + for_each_online_cpu(cpu) + if (topology_is_primary_thread(cpu)) + cpumask_set_cpu(cpu, &rmpopt_cpumask); + + rmpopt_pa_start =3D ALIGN_DOWN(PFN_PHYS(min_low_pfn), SZ_1G); + rmpopt_base =3D rmpopt_pa_start | MSR_AMD64_RMPOPT_ENABLE; + + /* + * Per-CPU RMPOPT tables support at most 2 TB of addressable memory + * for RMP optimizations. Initialize the per-CPU RMPOPT table base + * to the starting physical address to enable RMP optimizations for + * up to 2 TB of system RAM on all CPUs. + */ + wrmsrq_on_cpus(&rmpopt_cpumask, MSR_AMD64_RMPOPT_BASE, rmpopt_base); + + cpus_read_unlock(); +} +EXPORT_SYMBOL_FOR_MODULES(snp_setup_rmpopt, "ccp"); + /* * Do the necessary preparations which are verified by the firmware as * described in the SNP_INIT_EX firmware command description in the SNP diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 78f98aee7a66..217b6b19802e 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1478,6 +1478,9 @@ static int __sev_snp_init_locked(int *error, unsigned= int max_snp_asid) } =20 snp_hv_fixed_pages_state_update(sev, HV_FIXED); + + snp_setup_rmpopt(); + sev->snp_initialized =3D true; dev_dbg(sev->dev, "SEV-SNP firmware initialized, SEV-TIO is %s\n", data.tio_en ? "enabled" : "disabled"); --=20 2.43.0 From nobody Mon May 25 04:33:44 2026 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013060.outbound.protection.outlook.com [40.107.201.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB5AF397E91; Mon, 18 May 2026 21:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140598; cv=fail; b=kAayiJdXijkDh8cOd4vHtTZYKjVSTh9BeUbEJhLGhDiR+W7peqIN6zLUNG+eChmgIr6jasB5cdQyy7hvbjD4KaJqg3JeHGT5e9Wrx3TXirF3Gba76GuIVi9qh25XVubfC4YuLSgGYM7Ov8w3WouAdmhcAtqeqfOur+TR/PXnr1A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140598; c=relaxed/simple; bh=LyYJ0JnWHxYJYMjP9huKlwXs9Xq+3UqNYthnjWFpXuM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jJbXMPQ8ycyKdxvHvR1RgtedKBGNczXJDRCMUZL7kQelKwIZ8ipuiKRyjrQNrMESA5clrSdr9HP7YM9p4OnNGrVUvhTlaJVeecAVYXabyZ54WAsy3OVoaN4w3FXxCeeZAuYFN5UovssSSQOkhmGwbmPccx9xOg7A8hcRdeLuHRQ= 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=jwC8LIxd; arc=fail smtp.client-ip=40.107.201.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="jwC8LIxd" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Gw5OTXRknCexw2EVIB0HubEvq46qY/ibvLOSeooAyEUK183IhZGfuNFm0VnIGMiYdb8ixyf59Ts8J+aZT6Bkdl+14O0UkpUJWoWVQqVQiDZM1uKsvjge0E5OUSsuHE5et+8qmUHlrkGUDX2InX1Mx2UmpirP8B/OHmyIpgx62/c7kC9uXghV5/NdPW4HntkXpsAQ82GjMR+AILEkB7qemgwaiQBwcO9n7kBVkmCyOkBKhWeEB0ho3Z4X6TVDff1omLY6c2gdiSfJAV7gj+86GNd9dn76hacX3Wt5QP7PMjHakI5uRlcyDl/RkF5sb+6FIMRF1JJvYzQdGQqadSzbQw== 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=xJxqCEMHYFEQRfe4mfGDAOSJOdTe1FyGoN1kEV0LuOo=; b=IS5tcJyvjx5qjfulsIM4H7xm/E/OIAxsrr9bEWtRWl4wbjy8RDweSWtPdjphWNlSm0app4i8aTTQd2VI4Kpbet+hwQkQyy5I0+/yfR+ymzULIzq6Nf1mgA7x44WzGt8an8K4djjZk+WowzsnF33KLD9RbEghLqN3VCdTaDPe2EYSW5tu/752MWEdYDnt+NHkNyqMZP34jt7JG0JUZM+pN99qf7JiR7bmrRdIt1evh94ROuRRtiiDfjZ7JTGoTm/uPDZCzREBy/FxviKC1lndX81u2l4K2UecYJ5xaavXtKYJbO4RvBLF2ivxWBIttLn1HEoOmWHoCv96yGtxcQvYVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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=xJxqCEMHYFEQRfe4mfGDAOSJOdTe1FyGoN1kEV0LuOo=; b=jwC8LIxdxVZ9VRE6HzYBq3G9xxNxJmwhYA+5A/n3jjzwzXii+OEx4+0NGao3b5hZQNZzpw6ZknZZdjhlvof7vUDHI27VHWJMO0z9kRfwjoZUsaOf6isEoO4+fmqrvkRnqiSwDYuxtZAMfUao17K/1X1cx+xrkTOQont4m8DchCo= Received: from CH0P220CA0010.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:ef::12) by MW4PR12MB6682.namprd12.prod.outlook.com (2603:10b6:303:1e3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.25.23; Mon, 18 May 2026 21:43:07 +0000 Received: from CH2PEPF0000009C.namprd02.prod.outlook.com (2603:10b6:610:ef:cafe::b8) by CH0P220CA0010.outlook.office365.com (2603:10b6:610:ef::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.25.23 via Frontend Transport; Mon, 18 May 2026 21:43:07 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH2PEPF0000009C.mail.protection.outlook.com (10.167.244.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Mon, 18 May 2026 21:43:07 +0000 Received: from nigeria-2635-os.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Mon, 18 May 2026 16:43:05 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 4/7] x86/sev: Add support to perform RMP optimizations asynchronously Date: Mon, 18 May 2026 21:42:55 +0000 Message-ID: <6f1ec3d8ebcf3aaceccc099c07d0deb545dd4ab9.1779133590.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.43.0 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009C:EE_|MW4PR12MB6682:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d6777c7-46e2-4486-d7f8-08deb52672c1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|1800799024|7416014|376014|82310400026|3023799003|11063799003|22082099003|18002099003|56012099003|921020; X-Microsoft-Antispam-Message-Info: 0F5PBwGtrtofngejomI0Iq+1BVBB9f096pd60sjtbdw/nUvR166iSiorU46ss4/KRbIb1eMygxcbLQedWlG/ItsD5J1tVwjlqSOEuYUCbP0J3/9jrY6M6CKFEkiKBFcNDJMfNBGDsWWXO2nZnfWAzs1R3ZOgpQo7cq/jmxKqoVG76vO73IsVCCMkboqZxULxM4LRRummqG7DgYISfBeZWplWqWvyZuUMYfw7npN/H8L1OGthWoUp7hVSUslme54EncfrYgBQ+V2ExsDJ3UGuq4NU+eHdDBhoYtjwqkTVRkvXn+++heiUY1SlJVe+2Q2r1Q2pULoRP+mwTHGB2Rd1wzFCKt9bOOgKBrXp6fxeuPGCx0MTQe6pDF33VSv69pCbx2cIWCia5AefPRbfGpSGTR7cCAwHX7y8uSU9JZU8kejNgeFFIR6+8L8+mOtj9jUz52AQHPI6h2bPgqRkTQ/iflszjX2kXqphG5NOPLeJ6vOR0EveiYVAUrqyWiHNGOTsQHCWqjyNrOoxE6IbvCLs/RrW+OpLasZndex0rAhUD8tMO/dE42G1unglK2+ZbWnFkmfqXsVD6aYPagtKWeE9fixsbo8M0jEpbVFkSHJ8LJ18UnstXXGITNHY2hXWdyrHYz4m3pqybzrXI03AZqjuYs39cyc/xg8/Ue/yip5yFCtRqSKyCxYp+60jsn09vM4/0XsuKOjPlkViz7zzrsYaqPPu1EvsDle2I/DKaAlC3sqlukEL0MYEcZiP35p9bpLXrYiEh0PdBcTQzoBFLUhVKg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(1800799024)(7416014)(376014)(82310400026)(3023799003)(11063799003)(22082099003)(18002099003)(56012099003)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rQATZqbkzdJKEh/BVEP00w7m61Lw3aHat/I6k8G/iGVu2KFI8OZilwpVBRO9KzdSx9YowIRIy5KcfQN13RGX+dMn2Ktwm6OjJgo2f7pU8PTi5LKIJj9qgFObpFlPb5Rz1IRkHof6TtsX6dQHxZ5V3MTdcD0c8YwMarbt7fl3GcnwDwMPKdGY9MjsYtpY/SUSgCaW9r+D1xsxuR1x1HG4vDP/YZPCF7+de2vpB3WH8MsDp1RSZdGTCHUINM7X1ZJ1kLjqjUPWp6sP2eOVXINaCKIFScA8b8W+3dGqhc+b8J/BFko1T89ieslhWFOqdZ1RbpfvWi9yU9X5CsSKqJfqdY8e3TPOTWHVgWQB00iQmwp9nGheilXzU5d9LZEADXlJoYm5ddT9gdq8NCStyR8WFM59iuD6A/4HcEq1GckUGcrG3cAp5vTdq7FBc6xKKP43 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2026 21:43:07.1318 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9d6777c7-46e2-4486-d7f8-08deb52672c1 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000009C.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6682 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra When SEV-SNP is enabled, all writes to memory are checked to ensure integrity of SNP guest memory. This imposes performance overhead on the whole system. RMPOPT is a new instruction that minimizes the performance overhead of RMP checks on the hypervisor and on non-SNP guests by allowing RMP checks to be skipped for 1GB regions of memory that are known not to contain any SEV-SNP guest memory. Add support for performing RMP optimizations asynchronously using a dedicated workqueue. Enable RMPOPT optimizations globally for all system RAM up to 2TB at RMP initialization time. RMP checks can initially be skipped for 1GB memory ranges that do not contain SEV-SNP guest memory (excluding preassigned pages such as the RMP table and firmware pages). As SNP guests are launched, RMPUPDATE will disable the corresponding RMPOPT optimizations. Suggested-by: Thomas Lendacky Suggested-by: Dave Hansen Reviewed-by: Ackerley Tng Signed-off-by: Ashish Kalra --- arch/x86/virt/svm/sev.c | 167 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 3 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 82f9dc7a57c3..8876cac052d5 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 #include #include @@ -125,7 +126,18 @@ static void *rmp_bookkeeping __ro_after_init; static u64 probed_rmp_base, probed_rmp_size; =20 static cpumask_t rmpopt_cpumask; -static phys_addr_t rmpopt_pa_start; +static phys_addr_t rmpopt_pa_start, rmpopt_pa_end; + +enum rmpopt_function { + RMPOPT_FUNC_VERIFY_AND_REPORT_STATUS, + RMPOPT_FUNC_REPORT_STATUS +}; + +#define RMPOPT_WORK_TIMEOUT 10000 + +static struct workqueue_struct *rmpopt_wq; +static struct delayed_work rmpopt_delayed_work; +static DEFINE_MUTEX(rmpopt_wq_mutex); =20 static LIST_HEAD(snp_leaked_pages_list); static DEFINE_SPINLOCK(snp_leaked_pages_list_lock); @@ -564,12 +576,21 @@ EXPORT_SYMBOL_FOR_MODULES(snp_prepare, "ccp"); =20 static void rmpopt_cleanup(void) { + guard(mutex)(&rmpopt_wq_mutex); + + if (!rmpopt_wq) + return; + + cancel_delayed_work_sync(&rmpopt_delayed_work); + destroy_workqueue(rmpopt_wq); + cpus_read_lock(); wrmsrq_on_cpus(&rmpopt_cpumask, MSR_AMD64_RMPOPT_BASE, 0); cpus_read_unlock(); =20 cpumask_clear(&rmpopt_cpumask); - rmpopt_pa_start =3D 0; + rmpopt_pa_start =3D rmpopt_pa_end =3D 0; + rmpopt_wq =3D NULL; } =20 void snp_shutdown(void) @@ -587,6 +608,105 @@ void snp_shutdown(void) } EXPORT_SYMBOL_FOR_MODULES(snp_shutdown, "ccp"); =20 +static inline bool __rmpopt(u64 rax, u64 rcx) +{ + bool optimized; + + asm volatile(".byte 0xf2, 0x0f, 0x01, 0xfc" + : "=3D@ccc" (optimized) + : "a" (rax), "c" (rcx) + : "memory", "cc"); + + return optimized; +} + +static void rmpopt(u64 pa) +{ + u64 rax =3D ALIGN_DOWN(pa, SZ_1G); + u64 rcx =3D RMPOPT_FUNC_VERIFY_AND_REPORT_STATUS; + + __rmpopt(rax, rcx); +} + +/* + * 'val' is a system physical address. + */ +static void rmpopt_smp(void *val) +{ + rmpopt((u64)val); +} + +/* + * RMPOPT optimizations skip RMP checks at 1GB granularity if this + * range of memory does not contain any SNP guest memory. + */ +static void rmpopt_work_handler(struct work_struct *work) +{ + bool current_cpu_cleared =3D false; + phys_addr_t pa; + int this_cpu; + + pr_info("Attempt RMP optimizations on physical address range @1GB alignme= nt [0x%016llx - 0x%016llx]\n", + rmpopt_pa_start, rmpopt_pa_end); + + /* + * RMPOPT scans the RMP table, stores the result of the scan in the + * reserved processor memory. The RMP scan is the most expensive + * part. If a second RMPOPT occurs, it can skip the expensive scan + * if they can see a cached result in the reserved processor memory. + * + * Do RMPOPT on one CPU alone. Then, follow that up with RMPOPT + * on every other primary thread. This potentially allows the + * followers to use the "cached" scan results to avoid repeating + * full scans. + */ + + /* + * Pin the worker to the current CPU for the leader loop so that + * this_cpu remains valid and the RMPOPT instruction executes on + * the CPU that was cleared from the cpumask. The workqueue is + * WQ_UNBOUND, so without pinning, the scheduler could migrate + * the worker between the cpumask manipulation and the leader + * loop, causing the leader to run on a different CPU while + * this_cpu's core is skipped entirely. + * + * Use migrate_disable() rather than get_cpu() to prevent + * migration while still allowing preemption. + * + * Note: rmpopt_cpumask is modified here without holding + * rmpopt_wq_mutex. This is safe because the delayed_work + * mechanism guarantees single-threaded execution of this + * handler, and rmpopt_cleanup() calls cancel_delayed_work_sync() + * to ensure handler completion before tearing down the cpumask. + */ + migrate_disable(); + this_cpu =3D smp_processor_id(); + if (cpumask_test_cpu(this_cpu, &rmpopt_cpumask)) { + cpumask_clear_cpu(this_cpu, &rmpopt_cpumask); + current_cpu_cleared =3D true; + } + + /* Leader: prime the RMPOPT cache on this CPU */ + for (pa =3D rmpopt_pa_start; pa < rmpopt_pa_end; pa +=3D SZ_1G) + rmpopt(pa); + + migrate_enable(); + + /* Followers: run RMPOPT on all other cores */ + cpus_read_lock(); + for (pa =3D rmpopt_pa_start; pa < rmpopt_pa_end; pa +=3D SZ_1G) { + on_each_cpu_mask(&rmpopt_cpumask, rmpopt_smp, + (void *)pa, true); + + /* Give a chance for other threads to run */ + cond_resched(); + } + cpus_read_unlock(); + + if (current_cpu_cleared) + cpumask_set_cpu(this_cpu, &rmpopt_cpumask); +} + void snp_setup_rmpopt(void) { u64 rmpopt_base; @@ -595,11 +715,35 @@ void snp_setup_rmpopt(void) if (!cpu_feature_enabled(X86_FEATURE_RMPOPT)) return; =20 + guard(mutex)(&rmpopt_wq_mutex); + + /* + * Guard against re-initialization. When SNP_SHUTDOWN_EX is issued + * with x86_snp_shutdown=3D0, snp_shutdown() is not called and + * rmpopt_cleanup() is skipped, but snp_initialized is still cleared. + * A subsequent __sev_snp_init_locked() would call snp_setup_rmpopt() + * again, leaking the existing workqueue, delayed work, debugfs + * entries, and cpumask state. + */ + if (rmpopt_wq) + return; + + /* + * Create an RMPOPT-specific workqueue to avoid scheduling + * RMPOPT workitem on the global system workqueue. + */ + rmpopt_wq =3D alloc_workqueue("rmpopt_wq", WQ_UNBOUND, 1); + if (!rmpopt_wq) { + pr_err("Failed to allocate RMPOPT workqueue\n"); + return; + } + cpus_read_lock(); =20 /* * The RMPOPT_BASE MSR is per-core, so only one thread per core needs - * to set up the RMPOPT_BASE MSR. + * to set up the RMPOPT_BASE MSR. Likewise, only one thread per core + * needs to issue the RMPOPT instruction. * * Note: only online primary threads are included. If a core's * primary thread is offline, that core is not covered. CPU hotplug @@ -622,6 +766,23 @@ void snp_setup_rmpopt(void) wrmsrq_on_cpus(&rmpopt_cpumask, MSR_AMD64_RMPOPT_BASE, rmpopt_base); =20 cpus_read_unlock(); + + INIT_DELAYED_WORK(&rmpopt_delayed_work, rmpopt_work_handler); + + rmpopt_pa_end =3D ALIGN(PFN_PHYS(max_pfn), SZ_1G); + + /* Limit memory scanning to 2TB of RAM */ + if ((rmpopt_pa_end - rmpopt_pa_start) > SZ_2T) { + pr_info("RMPOPT coverage limited to 2TB; memory above 0x%llx not optimiz= ed\n", + rmpopt_pa_start + SZ_2T); + rmpopt_pa_end =3D rmpopt_pa_start + SZ_2T; + } + + /* + * Once all per-CPU RMPOPT tables have been configured, enable RMPOPT + * optimizations on all physical memory. + */ + queue_delayed_work(rmpopt_wq, &rmpopt_delayed_work, 0); } EXPORT_SYMBOL_FOR_MODULES(snp_setup_rmpopt, "ccp"); =20 --=20 2.43.0 From nobody Mon May 25 04:33:44 2026 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013016.outbound.protection.outlook.com [40.93.196.16]) (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 66E7339A056; Mon, 18 May 2026 21:43:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.16 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140611; cv=fail; b=r+D3wg452RxbugQReSv9GREW1Lr5sDb9HIA8pfobeLpSXsPw/f/P9FsCZSOFu5+Ftnogbui7Mk8XCvTpuZX7chvQgE7+2j9Cs2MSX0axlug5pSBh+qY3EJRlVqSTGbcH0gK7hdW/MKkpcx/83BaXHla1//4snf5perMp2nAhHTA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140611; c=relaxed/simple; bh=rKYIvXC25wzTl0jXKC3FRoTzjQDXVseWkZOl1u/VIvo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MOrFO7EgmcjMeDSpy0rQWfOC+by7I9jZNvv6PKFNnHoQVFBy0fYcLWx3AUpyVU21TohtCP97R0dsQYfys5dlWG/tQv8GnjdCO/5G6Qhk3ou17CS7xgzFahqVirIqG2pJ0zhF3Gp4zYMjn2FUmi1CBb5xc/vDQRNRnw++CJybX+4= 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=M1C+aooX; arc=fail smtp.client-ip=40.93.196.16 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="M1C+aooX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hFAohUF6KptbAnKslkHzndez3e8JN0Pffrrt0IYOeB5jPsZa0KQsuC9Wv30iIhQve+W5iNeLTWR2eAlbiZDYddU1bBTUnW2nJXPGNjr83hZv7L5M864ejsYksBO7/Kaa9HIIAExS+YbIAorcdOR4vTdssVQBRJDBFE2JlrEzAMD4u84xxSb+eeJBKx97iBFVU3dmLNGVwQ5qiskpR4OdSvtfyyiw6uDCegETc3DI5O2RxjDETOtEvcI0D393yjGDzPmkuAISiuZIH88nhUDPofaxZftyalRw2en2sMwr7NWND4xKPqXz1g08ScYFtbBEri62yy7koP8zer8tIjERAw== 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=bURHpmQ+XUNZ+547l6//EHJUYIiln5h/x6j1ncjuQIA=; b=jsBSN2yf0V/jAatlCaArM80LtS/SvnY+tiqwdkQdMXJ+P67nX2N2VNsDHaYa1Z72m0iIxZghaLCdB9SvafbSoe+WqR4qOXinajzbPclWxNyXV3SGKXTssIs5syaCN4YH41q9Hkr1EHhug6ew7D8r+oOIk1JbBJvVgQPJktFwggXadN7qQXEmHtyz2La8YSIzaNcCXFq90/wU27fsiMEWA1hAaADxzBAt/gKt2uuwOh3SJbNhHPBgHn+eQNwk3mpN+7NPOHiV5ewIPN+1M1pgCkjTbouINeXR2vhe+d+rFNbbU99+o163WP2N7TnyhEFSyS6apD5fJmN5CaUkK7Kd0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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=bURHpmQ+XUNZ+547l6//EHJUYIiln5h/x6j1ncjuQIA=; b=M1C+aooXfMdS1bJTqZWgNwfJPKhTVeyGXCFCGpghRUp2oP2D/B96W4ydSHPuHCTtB8U/3Peixqn1IGXJHjxMRtjm66bZ68Hed0iWKgnHyDJBZfWoUPNWyP18tdexasw64hcy8UD1uyFF3hBaTzIVkCGysDseTDs7ZzS/TvjmPwo= Received: from CH0PR08CA0020.namprd08.prod.outlook.com (2603:10b6:610:33::25) by DS7PR12MB6095.namprd12.prod.outlook.com (2603:10b6:8:9c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.25.19; Mon, 18 May 2026 21:43:24 +0000 Received: from CH2PEPF0000009E.namprd02.prod.outlook.com (2603:10b6:610:33:cafe::a5) by CH0PR08CA0020.outlook.office365.com (2603:10b6:610:33::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.25.24 via Frontend Transport; Mon, 18 May 2026 21:43:24 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH2PEPF0000009E.mail.protection.outlook.com (10.167.244.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Mon, 18 May 2026 21:43:24 +0000 Received: from nigeria-2635-os.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Mon, 18 May 2026 16:43:22 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 5/7] x86/sev: Add interface to re-enable RMP optimizations. Date: Mon, 18 May 2026 21:43:13 +0000 Message-ID: <4621de2b8354a1076bc5fb75f2a5a47509aa5f4e.1779133590.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.43.0 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009E:EE_|DS7PR12MB6095:EE_ X-MS-Office365-Filtering-Correlation-Id: df495189-144c-4a14-7a5c-08deb5267d0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700016|376014|7416014|921020|11063799003|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: YyHodIRY5NCpgeBQuBMYQOixIVbc5gIWXhbtlrZA2xazbeCjMM3XNCKFJ7TIKFu/NbcSGDB8vKITOqX8fr7VS32eGzRZzX1hfPeMfPLzB1Y1E++uI4yduEEi+Dfa8XGYjsKKqdmWbu0wmyvFcC1oGSs0udMejQn0QurYfn7dZ0tCghBMsoS+h4vgds8eXkgYyVRs/dYYfwIgfUOCbVahqVfU1BYnSnrJa02zznQK8UfYYmqbTj6uGNl+zaYbWLgwgWcNtkKW3tIrvCLHvJZtbS7OwdZFVIUD5CfpnQEciY53ZmU8I4fORdcGmbi/6OsbNixdvPSPZ+RLhNW4vqKyhreMnt+A+N93vS7ZJQ7L+g+3+lZKGzFO5q5ufzVtQzjvkHPyaGn1AoB3XnaZ0oQ3ceCSxa6L1K3U3neTJsL8xNS3qKjplbamthl+gm3kSJQx09uvmJbCgsXEZP7+jKHJKHtgxtalVGAWSGWedEFvZjh8k3OjAd+oNaMaSZ7kLgNZlRHHEqU+c13ZSvndtPfI7B4VzhHK743UxPyWcMblMKIeaxShnKTJ5QfAJS1YzWHYk4gwqLuIztnDR2Y1Nhbmu35x22VnYCS9RMa9zWtNxWmXLjruAwz0vPBLdwxpbt5lRHoKpwMw6+CUopgaWIC9/cJ069s9zi702LJ/z3mL3Y2yGXXbzhyvcKxY9CWGmajqKvuqv01xlTUt5nBWZpriY+uaSduYBSSjmHZxWrOP3gp4qd9GkSKp1RnD9gacbWRtW/HDkQcloZoVbVIv8rReTQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700016)(376014)(7416014)(921020)(11063799003)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zGhVx/dK5/4pqNTqVQiK/I3ffzZ5f/7RM8kfEqGoCA4qCK1BVeUUNe5KRw+baVLeiBn5WAnA4W0Yu5KWhIqENeU1tpEWqC+nHVKL9qeOdzvanGefc7Thu1j8lD0EB6pg6x4k5hc4y4ny5u0ozl0Ow6hIbCW+YyKo4IAYDG8dhmRLeENB9+Mfow+eR2zYcG1i+3M3uyJzUMQWik1T5jqlpvmAW6HZ8YbE9VFfnEjtFItoNPibpB9p9zUwPSNe2cEtUwXOoBtFW9wcSNI8ktdLiT/eBClfYWfJ38hF2R08I56xl8I+ndSKBTw+lL8c0glXqpLhMxC8Bb8ymLaoKr7R9hRD474XpYYqUqLgvPXRxCxZ6sRDaM2audJOb7ngHWQqv50raxCWNRSx5ofSoJ57+rACb4LoTuZI86y2DRMhvy92e6mgoxFCA2Eb4iRhzHjy X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2026 21:43:24.4195 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df495189-144c-4a14-7a5c-08deb5267d0f 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000009E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6095 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra RMPOPT table is a per-CPU table which indicates if 1GB regions of physical memory are entirely hypervisor-owned or not. When performing host memory accesses in hypervisor mode as well as non-SNP guest mode, the processor may consult the RMPOPT table to potentially skip an RMP access and improve performance. Events such as RMPUPDATE can clear RMP optimizations. Add an interface to re-enable those optimizations. Reviewed-by: Ackerley Tng Signed-off-by: Ashish Kalra --- arch/x86/include/asm/sev.h | 2 ++ arch/x86/virt/svm/sev.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 6fd72a44a51e..09b1c5d33790 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -662,6 +662,7 @@ static inline void snp_leak_pages(u64 pfn, unsigned int= pages) __snp_leak_pages(pfn, pages, true); } int snp_prepare(void); +void snp_rmpopt_all_physmem(void); void snp_setup_rmpopt(void); void snp_shutdown(void); #else @@ -681,6 +682,7 @@ static inline void snp_leak_pages(u64 pfn, unsigned int= npages) {} static inline void kdump_sev_callback(void) { } static inline void snp_fixup_e820_tables(void) {} static inline int snp_prepare(void) { return -ENODEV; } +static inline void snp_rmpopt_all_physmem(void) {} static inline void snp_setup_rmpopt(void) {} static inline void snp_shutdown(void) {} #endif diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 8876cac052d5..7f8bb09844c1 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -707,6 +707,21 @@ static void rmpopt_work_handler(struct work_struct *wo= rk) cpumask_set_cpu(this_cpu, &rmpopt_cpumask); } =20 +void snp_rmpopt_all_physmem(void) +{ + if (!cpu_feature_enabled(X86_FEATURE_RMPOPT)) + return; + + guard(mutex)(&rmpopt_wq_mutex); + + if (!rmpopt_wq) + return; + + queue_delayed_work(rmpopt_wq, &rmpopt_delayed_work, + msecs_to_jiffies(RMPOPT_WORK_TIMEOUT)); +} +EXPORT_SYMBOL_GPL(snp_rmpopt_all_physmem); + void snp_setup_rmpopt(void) { u64 rmpopt_base; --=20 2.43.0 From nobody Mon May 25 04:33:44 2026 Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11012071.outbound.protection.outlook.com [40.107.200.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B020A39A049; Mon, 18 May 2026 21:43:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.200.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140631; cv=fail; b=qe428go/kbVuCPY9/MgdV7+cXKuFVclAivzHGO9+k/S2gx0fYN6CCB0BuAGkFU0m668LalqtejMj00AWKpY6aqfDL5Xloo8DRArOBpjIXwhASWEWL/vtdFhZGTrCz3CsPfr/rpzZfjv4/a912P6tJMlsX/t/yEPqJy6aL27oTTI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140631; c=relaxed/simple; bh=vuGdLL/e7nbmHBQa3VVs/TpNpujz2G3aM+7E5CDFFTs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ixcwKVKLOcv03xz+sMYNg7k4Lzht4oDocz1+/flBNylD3ycdMXYgsOxeaFP369y6eJuWMqri8qfanrOErWfBeGMBgKspzbU9VZ67WBDnw+iCQYgoLInudR+hFVxJRSXDi41PIMwobXWYehedIs/ocQ4YJO/LeZ2b1aOOguGSAnA= 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=3DSMVqV/; arc=fail smtp.client-ip=40.107.200.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="3DSMVqV/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=G+o+llBurxuepNlbQoP3P+zRvAIh/p5a7j+jhsbPaQpqhQyxtZJI0NzjAxeVBk/K3/6cdpwCAp0U/n8eixOfbxK6bUpa8+bUoI98lV4D2pstyHCisV3o1CPkjO4DNScOazK16Nykh3hCVZsGSgGmE5PIUnlIOZ0NPWXFBaQ028Sh4akod+PwslnlZElQOht7xh6fAsFFZbGQbv3gQofNyDJSn03REW6+6FnufY/IQZOCZjwVC5bIBxuvrbQpa7e3lwc/M3VOD4ghFxB7nSV8V0P+3CjnG/XariusUc2sRuS6I+m9DS6RwxME4mZr/6JrnsWm7CHKhrEEXzPhS7ZTxQ== 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=1i1YVQlqnyjYXlJrMfo3dyWzHlnzJV9t5+x5bWLD990=; b=lY8YZPUNPcK5X3EA6LmfUZn1sOHZknipzLbAsj1jaQHaD/PqvSE5ACL7zVK8mJPhW4UtAiCvrNN5PknBVF4vQeRm5gHrFDDJJIsPPRlh27ALr4iUH5Q9kaEK+7CJGlpSS1vy/etp4gVoNfeN7hG36aScNiASBYMqwL9T7fuwDADee34djQPocck6z/iDHiq3qEWHlRBIFZTdno7GBKi7DZbMtBAylZFKpbpWMCl5mKBe5VUm4Xj1k7a1T4AsXZ9znqkqywZ4wLh1P68lkd9nvFBoIkAV/+FYIYXeTK5IFR9E8EUxtZrKP/bukSIXveE1WsDh3RHr/YgBEAETBD7qUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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=1i1YVQlqnyjYXlJrMfo3dyWzHlnzJV9t5+x5bWLD990=; b=3DSMVqV/Sv4NmXZ+QOnXzVp3SGVz/a2hm9I7b/4OlQtXeChueYfzvcz/U/cAhuLK96bPuIzvYPlY6XGcW234LRRki3SslWJaYtX4qzv4nyMC2YWPLvvWSjcxNtUOPT4HaN3avFKIF2SbJLHvhJmRiBsCZujR8VWGLLYawPPxIBA= Received: from CH0PR08CA0011.namprd08.prod.outlook.com (2603:10b6:610:33::16) by PH7PR12MB6810.namprd12.prod.outlook.com (2603:10b6:510:1b4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.25.23; Mon, 18 May 2026 21:43:41 +0000 Received: from CH2PEPF0000009E.namprd02.prod.outlook.com (2603:10b6:610:33:cafe::d2) by CH0PR08CA0011.outlook.office365.com (2603:10b6:610:33::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.25.23 via Frontend Transport; Mon, 18 May 2026 21:43:40 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH2PEPF0000009E.mail.protection.outlook.com (10.167.244.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Mon, 18 May 2026 21:43:40 +0000 Received: from nigeria-2635-os.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Mon, 18 May 2026 16:43:39 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 6/7] KVM: SEV: Perform RMP optimizations on SNP guest shutdown Date: Mon, 18 May 2026 21:43:30 +0000 Message-ID: <090bcf4d56b3966dbcd6abd60e02b3f5e3f4fdab.1779133590.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.43.0 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009E:EE_|PH7PR12MB6810:EE_ X-MS-Office365-Filtering-Correlation-Id: c231a326-4000-48a5-63e8-08deb52686bf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700016|7416014|376014|82310400026|921020|22082099003|56012099003|18002099003|11063799003; X-Microsoft-Antispam-Message-Info: tCYBAgyNjh1cA3rj3Ehc0aRWwUhdpp49HVJm9vQXL8/3ABETlcZ4VfZumChW/AxEalAxSa/elzDVqfwb32OTqCFLUqCTz3W1cNs0sco1FE+mOoqOGVDmGflnAwant59iSGQJ1mXw2Ndmjoit7eCoZzpTj3X5RSIMrT8qUoIGu47EYx6SVWrMs0xHkIVvId0lWCG0P1nj3TNwL43tC86++gYwW07w13jgr2amEo3syxFQdDDzNk8+yBiIT7mGMRrPM3oaplPFvTcif8AUWVeAHMxjGLJR9+VPolvZtd7q+8+kroDtqQiMgYq5VvBq2iBKInirJS2a7SBMdY5HLxJsOVdk5Yvy6VfcyH1VZfYzlFC7yPVRAh0HAJONQM1bxb2S9pgbfZcGkrz3WXTiGahmXfYVzGYfqvRElPLee8ROFVzcYIgMx/XfyVGJLxPx50+YnpYIrJUv1OM3xZ+2vFzGT9twLpLUogxRdTwzwwSus15reMfv3T/fXDqsU2VToIQHaCBPbH/tRN4GDMfMugjxo/lTeadcw+bwndmMcEX36/mehDgNPTSxcsEp4uCOVzJKQEPLfB1RW056jn6FUnWL5ywyt06xM4TlQZ9q7Fm8AygYuTHIsG5v5E49ggQyKOBNWy1emII4cDGNdBkhTc4EsgVm6qqzE/9fVyEL0GzyHE+bDVSBay9RdjQOR5OSLmKgghUJ4SgI1QodNyPH/MD6DaMSX64isCBZB0c9HhpO9oCAvV88ePhF0slam75p7hCe1EhFunQ6C2y63QIpSwKEEA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700016)(7416014)(376014)(82310400026)(921020)(22082099003)(56012099003)(18002099003)(11063799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RokE8t6KnJGqa+jaOSb3yLiQQ9CfC8YYZqSetbQkSy/rh9veUIEDUL6+7h4ftZ+SF3KbVTGlMc+iqWQSSb1FKF7ns0ine9dPJf1YufBueTwZ7l3K+1cW/tq8NSJbOyJH3eG0dyii4HzsxZQhEXRCCk9c3bvEAO5kF1l7DULKeaPLtXCpo9WzRjxICOmtimm/TGRTSQtFe/Uay511swQG7UQHlCDMJpzYE5/1t7raV9aKCgHbaAceDnWBVuYN+nyTRZxm2Kv/G9cQpdq1Oz1eZb19Gh9sO8lKnuO2xe+u+cQ8SPA0+YYu0HQmB/DstbLERKkAN4vctb7L3MK9vDjRgYvl0o0cZk+ZyKVTS9UJEJtQ4ZyTFPVG94T2IOxdK44zi5mURzqWUD1DkryN+XW/Lkc/UL/EQLou0T8jV6r4EA/u+DBJOFeW9RTzlb75qBBD X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2026 21:43:40.6707 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c231a326-4000-48a5-63e8-08deb52686bf 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000009E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6810 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Pages are converted from shared to private as SNP guests are launched. This destroys exisiting RMPOPT optimizations in the regions where pages are converted. Conversely, guest pages are converted back to shared during SNP guest termination and their region may become eligible for RMPOPT optimization. To take advantage of this, perform RMPOPT after guest termination. Do it after a delay so that a single RMPOPT pass can be done if multiple guests terminate in a short period of time. Acked-by: Dave Hansen Reviewed-by: Ackerley Tng Signed-off-by: Ashish Kalra --- arch/x86/kvm/svm/sev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index e107f368ed2d..29af6f6e603c 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3005,6 +3005,8 @@ void sev_vm_destroy(struct kvm *kvm) */ if (snp_decommission_context(kvm)) return; + + snp_rmpopt_all_physmem(); } else { sev_unbind_asid(kvm, sev->handle); } --=20 2.43.0 From nobody Mon May 25 04:33:44 2026 Received: from DM5PR21CU001.outbound.protection.outlook.com (mail-centralusazon11011038.outbound.protection.outlook.com [52.101.62.38]) (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 43A5239A072; Mon, 18 May 2026 21:44:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.62.38 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140651; cv=fail; b=qj5rDa0KD5TYRa28IJUUYMpEj4DiaPni+cH+wh4+OXPErmtaObpSkOa01cf70w/GVNRnT3IfmX4exQvPzLn2yntdJLNJV+GKEqtLq2SCMt3FDRBi3UZC6uhkLtJsio5pMh/Ey/RdWOo8UBoTDTkmxEK2Ir6t5iqmYjFn/j6zYOQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779140651; c=relaxed/simple; bh=jU6ySBvc1x9pPGB9Z+9RQR+yO4oIABXOmf9NjgppGg8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ATfR5y3CGP+9HYiJ1FVvBnJ6RAwqGAFzFh0y6opcotyUMN7ycnQNWHnBNtn5E9BdEk/1Xceh80jQin9UYs9uJyvis5Ov1QfNWHbsMezyG5oniOAf/i4UJtM4Ty71zyUgp+z1J5k4rZ74su+x1ptHcl6UJX00V7VB2e70CPqinJo= 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=RPWXa+cf; arc=fail smtp.client-ip=52.101.62.38 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="RPWXa+cf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GlIX7MtOSEDpEW0DDlPga3CK/3j3dzhykMW11f1aZvX6oof/42uo2d9WllLJAnpsA8Ph3qqXFptmpkoooNtlYKnm+TtfSs/hAuEGFDqPyWnKg+EvQkFw6dSOAgpGtqBY1a9l7bkgv0v3ajbC+qXlvzpxHL8mJ8/IJLv1RtElArSj1361eNbrj3XHWPSPX1Eg0Y4iCHkXDFadTSfVxehsbdoSmcAHQSwkFrRdNMiRKln8cl799Xwc8rQNezI1qCH5ycyavXZ05ut5Ayj/1YDFTXb2/avT+FDJj5QJUbqnuzI42zg2Os8/Mtgrgs1Gyfvaw0S5Oqs56hf5pt/ebkCxqg== 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=0eGlx4ZynLHtEwmiVPtxiIiMUHD9y8GF4XwtkTV/2oU=; b=WQYbEV5xy6FHnfCJeU8jre6iGbvU83KBr+24ULRyu3b3uhFeWpwS/qu1uXtzY+JRarOndDn5PzlvCFGxB8QhNbE6FQw30SI1bGeDUM/Vpm9aRK8ZxBqubnHEPxB3TQhg9/g88WrFsyiUcLtFxSTb/okJtkeNH1GMDA9ZcDlMUxICHv7PAPezqt4/HF6yvqcpTlYLiuzuysPJncRD9UQZaSFh5DUsEjqFWWTw6bIQ84FGe/o9y60XtXJGpjwXUHOp+SVeZAYd/e2mF7P+fhY2uudjzfhhR4pAwY3IZ0Jn9qjt6vbmlMwSWtXL9zKN23mv9k04AGml1Q0VS5Vlfwbfig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=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=0eGlx4ZynLHtEwmiVPtxiIiMUHD9y8GF4XwtkTV/2oU=; b=RPWXa+cfAEX38hK+1ZBaCz/zbXAd9cMbZfzrbj0AgIDKj1YuNh7P6f5aEpCimQlXNxge+v+fwHSMCiaZUxIMl0eZDmdhb5vBDKHphNXRx4vUKiKKoz1Cdy27MaJ1C0kyV5VS61TTvOvLexaagv3xVdX2JzNU0M8B64KZn+9QoVI= Received: from CH0PR03CA0415.namprd03.prod.outlook.com (2603:10b6:610:11b::26) by PH7PR12MB7891.namprd12.prod.outlook.com (2603:10b6:510:27a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.25.23; Mon, 18 May 2026 21:44:00 +0000 Received: from CH2PEPF0000009D.namprd02.prod.outlook.com (2603:10b6:610:11b:cafe::7d) by CH0PR03CA0415.outlook.office365.com (2603:10b6:610:11b::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.25.24 via Frontend Transport; Mon, 18 May 2026 21:44:00 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH2PEPF0000009D.mail.protection.outlook.com (10.167.244.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Mon, 18 May 2026 21:44:00 +0000 Received: from nigeria-2635-os.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Mon, 18 May 2026 16:43:59 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 7/7] x86/sev: Add debugfs support for RMPOPT Date: Mon, 18 May 2026 21:43:49 +0000 Message-ID: X-Mailer: git-send-email 2.43.0 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: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009D:EE_|PH7PR12MB7891:EE_ X-MS-Office365-Filtering-Correlation-Id: c722dee3-b87e-402f-2600-08deb52692a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|1800799024|7416014|376014|82310400026|56012099003|22082099003|18002099003|921020|3023799003|11063799003; X-Microsoft-Antispam-Message-Info: tPkrIPCs4aw9ji7DAROPmT+bcwh2dhi3PZt/CPWgW0d/4sPEv5l+4j/7ktzzE3h/ODSYxE/1BA8rMTVNWg/tLui/FGruOhy/AvS8zSz7PH5UmhM7Vn0HAchaEBhUl0OSikKyvvYUNDwyYWrVVwZ4LPYd/wrclslPDhPOO5BoNLYws5WazdWamEUuvd7NHoZojcXrxVb2Y00IEZczMaZjqnKky32UHbo1gfOw7fpB/IiyMlkR5KhHMj9lFs+6t2N4IGBmHXmTBNiXJbrew+VnfJaNxSchI0QqLusncWsP0/t5V30LdroIpa0K4wlxmzlprMfx6MTA+oa61svgEW5rowAMbkn65YZhQ0O5+25AkX6m+kO68EgmHh1GrYYgba8edS8hfZmmLWF+RAeI9A8uExpU1DZJSssslL0nXrDYm/b5sKlSKN8esuSi6sk76vm5hsjgLpzEBF0oeOW4UCOWrsoPj9Y6BM4DxdmJNQ/ElEVYt9wK6ExHOXAlGAD5Jbh++EJsnLFNhl3FYIbmjpB8dHFs2xfiM2p5H1mrwWYgMTRBi1BHFsJ/QBUJkFtQJvGMuCxgMMgI5bRrEIMw1Ju9MwWOvhMCcXv7bZzs0tvCE8rO1ySWPWDFR8UlMF6lFBsVZM3ZJ09xmA3YoNnM+1bZqgyKeSJvRFn2e2aqZou95dv0nSV3IA2mzqzjix9575Y8/GM7lnNerXO33G1bEyU76wtQnYA07nbJF8iy/k9gt/H8hvysWsA2zXoWjUxRgJ9aMi/HbMlYZjVjB06VczMGug== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(1800799024)(7416014)(376014)(82310400026)(56012099003)(22082099003)(18002099003)(921020)(3023799003)(11063799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IASqwDgpkRp0xoSxE/0qvwz+jm3MGkzM5JB33W78uedNR3VVPhJQdwRcHesSS1L8VAGIlcuasIF8ZLccHo9chp4Gc4AyzslZZdOtrzmMM0kltw/fMH7cyzjVUT2iWizFquJNFiIyqT5aI6VR0Po7xtClV+9t/8U0WCHkyniLpt+vbkGMUSvxn9M9PLVzpTu7Iy093huNikqBMcJaNKTnJvNAwkw82dOyl46y9HZlewCwTfoBcCcyTFRceYDs5OVDpjaGCoIuiSsPTsM+QSxossXfj3H480l6lnjjepFOJqAzkGpyOQfuFriJqQMspV6NQfMqIMiCXLpBSac1uIdL/08ZXFVidvfUnEdW9zbFWQNef676paeRdr3sO5WATCKeIPUgApmMg5dy3jmL42MAjUcMFw1B+B86jEcNv/dh7MCoUPrG0RKGGcF1my3pZVCb X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2026 21:44:00.6159 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c722dee3-b87e-402f-2600-08deb52692a4 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000009D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7891 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Add a debugfs interface to report per-CPU RMPOPT status across all system RAM. To dump the per-CPU RMPOPT status for all system RAM: /sys/kernel/debug/rmpopt# cat rmpopt-table Memory @ 0GB: CPU(s): none Memory @ 1GB: CPU(s): none Memory @ 2GB: CPU(s): 0-1023 Memory @ 3GB: CPU(s): 0-1023 Memory @ 4GB: CPU(s): none Memory @ 5GB: CPU(s): 0-1023 Memory @ 6GB: CPU(s): 0-1023 Memory @ 7GB: CPU(s): 0-1023 ... Memory @1025GB: CPU(s): 0-1023 Memory @1026GB: CPU(s): 0-1023 Memory @1027GB: CPU(s): 0-1023 Memory @1028GB: CPU(s): 0-1023 Memory @1029GB: CPU(s): 0-1023 Memory @1030GB: CPU(s): 0-1023 Memory @1031GB: CPU(s): 0-1023 Memory @1032GB: CPU(s): 0-1023 Memory @1033GB: CPU(s): 0-1023 Memory @1034GB: CPU(s): 0-1023 Memory @1035GB: CPU(s): 0-1023 Memory @1036GB: CPU(s): 0-1023 Memory @1037GB: CPU(s): 0-1023 Memory @1038GB: CPU(s): none Suggested-by: Thomas Lendacky Signed-off-by: Ashish Kalra --- arch/x86/virt/svm/sev.c | 121 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 7f8bb09844c1..ac414143feed 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include =20 #include #include @@ -144,6 +146,15 @@ static DEFINE_SPINLOCK(snp_leaked_pages_list_lock); =20 static unsigned long snp_nr_leaked_pages; =20 +/* All users of rmpopt_report_cpumask must hold rmpopt_show_mutex. */ +static cpumask_t rmpopt_report_cpumask; +static struct dentry *rmpopt_debugfs; +static DEFINE_MUTEX(rmpopt_show_mutex); + +struct seq_paddr { + phys_addr_t next_seq_paddr; +}; + #undef pr_fmt #define pr_fmt(fmt) "SEV-SNP: " fmt =20 @@ -583,6 +594,8 @@ static void rmpopt_cleanup(void) =20 cancel_delayed_work_sync(&rmpopt_delayed_work); destroy_workqueue(rmpopt_wq); + debugfs_remove_recursive(rmpopt_debugfs); + rmpopt_debugfs =3D NULL; =20 cpus_read_lock(); wrmsrq_on_cpus(&rmpopt_cpumask, MSR_AMD64_RMPOPT_BASE, 0); @@ -617,6 +630,10 @@ static inline bool __rmpopt(u64 rax, u64 rcx) : "a" (rax), "c" (rcx) : "memory", "cc"); =20 + if (rcx =3D=3D RMPOPT_FUNC_REPORT_STATUS) + assign_cpu(smp_processor_id(), &rmpopt_report_cpumask, + optimized); + return optimized; } =20 @@ -636,6 +653,108 @@ static void rmpopt_smp(void *val) rmpopt((u64)val); } =20 +/* + * 'val' is a system physical address. + */ +static void rmpopt_report_status(void *val) +{ + u64 rax =3D ALIGN_DOWN((u64)val, SZ_1G); + u64 rcx =3D RMPOPT_FUNC_REPORT_STATUS; + + __rmpopt(rax, rcx); +} + +/* + * start() can be called multiple times if allocated buffer has overflowed + * and bigger buffer is allocated. + */ +static void *rmpopt_table_seq_start(struct seq_file *seq, loff_t *pos) +{ + phys_addr_t end_paddr =3D rmpopt_pa_end; + struct seq_paddr *p =3D seq->private; + + if (*pos =3D=3D 0) { + p->next_seq_paddr =3D rmpopt_pa_start; + return &p->next_seq_paddr; + } + + if (p->next_seq_paddr =3D=3D end_paddr) + return NULL; + + return &p->next_seq_paddr; +} + +static void *rmpopt_table_seq_next(struct seq_file *seq, void *v, loff_t *= pos) +{ + phys_addr_t end_paddr =3D rmpopt_pa_end; + phys_addr_t *curr_paddr =3D v; + + (*pos)++; + *curr_paddr +=3D SZ_1G; + if (*curr_paddr >=3D end_paddr) + return NULL; + + return curr_paddr; +} + +static void rmpopt_table_seq_stop(struct seq_file *seq, void *v) +{ +} + +static int rmpopt_table_seq_show(struct seq_file *seq, void *v) +{ + phys_addr_t *curr_paddr =3D v; + + guard(mutex)(&rmpopt_show_mutex); + + seq_printf(seq, "Memory @%3lluGB: ", + *curr_paddr >> (get_order(SZ_1G) + PAGE_SHIFT)); + + /* + * Query all online CPUs rather than just rmpopt_cpumask (primary + * threads only). The RMPOPT instruction only needs to run on one + * thread per core for the optimization to take effect, but debugfs + * reporting requires the RMPOPT status across all CPUs. + * Performance is not a concern for this diagnostic interface. + */ + cpumask_clear(&rmpopt_report_cpumask); + on_each_cpu_mask(cpu_online_mask, rmpopt_report_status, + (void *)*curr_paddr, true); + + if (cpumask_empty(&rmpopt_report_cpumask)) + seq_puts(seq, "CPU(s): none\n"); + else + seq_printf(seq, "CPU(s): %*pbl\n", cpumask_pr_args(&rmpopt_report_cpumas= k)); + + return 0; +} + +static const struct seq_operations rmpopt_table_seq_ops =3D { + .start =3D rmpopt_table_seq_start, + .next =3D rmpopt_table_seq_next, + .stop =3D rmpopt_table_seq_stop, + .show =3D rmpopt_table_seq_show +}; + +static int rmpopt_table_open(struct inode *inode, struct file *file) +{ + return seq_open_private(file, &rmpopt_table_seq_ops, sizeof(struct seq_pa= ddr)); +} + +static const struct file_operations rmpopt_table_fops =3D { + .open =3D rmpopt_table_open, + .read =3D seq_read, + .release =3D seq_release_private, +}; + +static void rmpopt_debugfs_setup(void) +{ + rmpopt_debugfs =3D debugfs_create_dir("rmpopt", arch_debugfs_dir); + + debugfs_create_file("rmpopt-table", 0444, rmpopt_debugfs, + NULL, &rmpopt_table_fops); +} + /* * RMPOPT optimizations skip RMP checks at 1GB granularity if this * range of memory does not contain any SNP guest memory. @@ -798,6 +917,8 @@ void snp_setup_rmpopt(void) * optimizations on all physical memory. */ queue_delayed_work(rmpopt_wq, &rmpopt_delayed_work, 0); + + rmpopt_debugfs_setup(); } EXPORT_SYMBOL_FOR_MODULES(snp_setup_rmpopt, "ccp"); =20 --=20 2.43.0