From nobody Fri Sep 25 15:13:24 2026 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010020.outbound.protection.outlook.com [52.101.201.20]) (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 3A13749B5C8; Thu, 10 Sep 2026 21:59:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.20 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789077578; cv=fail; b=oKfg5Uedk9rwyb0nBRMNBL/aQb6RYyYu5EpoiHS0ldYBcZwjOqCyzHN42J1D/5LKZDRsox4nl7o8CpIX/3O2y4pb78OJeF0Ykr0CCEA9SEXB73C0MacecYT2OJNednM53ujUK0M4QfjgRWfi4vjeuIVy92tLqpwIuST2IbnoR9g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789077578; c=relaxed/simple; bh=9JkAwJ6pMSnB7ov8awr/g1JBp44NzTda1sHLW2w7RaU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Rr+xFptX0WPfYCjXk4lAC9fb0voUM5meWp9UmLd1AtCyiYXgtyk0acKcTrr7vcjE+K8fLQ5pZQhQc+7Ii1KLSdJk4Hexl3se6VtzPJ3eapsnqIgmV1RwTz9c8StIkqPtOiyfP/n+TDDc16dtqprjV48Tam/Zy9kDYEq+zYujmA4= 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=ttJUU/9k; arc=fail smtp.client-ip=52.101.201.20 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="ttJUU/9k" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ERWbEubA4Fc7wVZaNm6qFUmwfYXonz24B4R17ESvcAryNDZc/c26AQzM1yOzr5MnB1ahhZuvnD6tcopznZJlMtQ4stcex2+n+z2R9CiKTmO99gUcaSDgR+3lbEmzMbovDmcJVQEbg2asTbaq2L8kz18FUHUshmjZNJZ4aPt2Pjzzg32aBAm3lco4o7tfeonpho/d8kMpRXigMDKVArIGwg4W/w0G2DeXxFj2ZcLLeGVPjCgdt8XTqLSVjFrBGoYFFRV9u+U0mHUDphicvVho6bgocHQm+jp5fKFnPSDy09qxJDN+hSPWwKzFccDA1NBkeddQ2jYLFmX3N8TO0w5L3g== 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=NMhbL123iO1Z2WBPQXbvbmYl8SN1+d4H+AT0bA6j95Q=; b=gXkt5rHKiqBY13veRKlO8uN3PkelRPszFPCdTmqtyajhXn98hsp+4obz+6gimD622IOECVKtJvuLT7nLCgf18No7MBqaDmecMk9NHlWxzxNy7h0BebLogcNJblgJsaeQgz/EZ9ZAYHk4omUNiX8hI3amGpIiMnoxhje+LCaVL43/duPRAzw/uzq/NuoyCbd//pXzoRKlekkWThtJH8JyaE94+AD3f2B3YQxUwFCYkiM6zHmfPWHKDZw7r1XJqr20aMCl6P3AhwjO7Bxsn8HhPNyRiDv8Q5oUw0iOwJvrustkfG0N364eiYmtdxeyojiDvQ+PvQQJ2Z0597NFKj9HAw== 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=NMhbL123iO1Z2WBPQXbvbmYl8SN1+d4H+AT0bA6j95Q=; b=ttJUU/9kykb3yj3ehKky1sShFhExOWWUUF5eK74Z3b92EtyyFTfyiOgO0GbVYvLVzYTcStrsVKaSaFA2W2n6cJkdG88Lzvd3TTsQJDF7ZVP7qesYOvsbNQSOwsxElbm87V7BhT/EvTDH7n8s1w93wX5ppadCXPnVNPElLvi//tA= Received: from BN9PR03CA0936.namprd03.prod.outlook.com (2603:10b6:408:108::11) by IA1PR12MB6066.namprd12.prod.outlook.com (2603:10b6:208:3ee::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.8; Thu, 10 Sep 2026 21:59:32 +0000 Received: from BN1PEPF0000468C.namprd05.prod.outlook.com (2603:10b6:408:108:cafe::9d) by BN9PR03CA0936.outlook.office365.com (2603:10b6:408:108::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.6 via Frontend Transport; Thu, 10 Sep 2026 21:59:31 +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 BN1PEPF0000468C.mail.protection.outlook.com (10.167.243.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.5 via Frontend Transport; Thu, 10 Sep 2026 21:59:31 +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.46; Thu, 10 Sep 2026 16:59:30 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 1/5] x86/cpufeatures: Add X86_FEATURE_RMPOPT feature flag Date: Thu, 10 Sep 2026 21:59:19 +0000 Message-ID: <40510457d85846fd9138b622a01bebc360e4f72e.1788984053.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: BN1PEPF0000468C:EE_|IA1PR12MB6066:EE_ X-MS-Office365-Filtering-Correlation-Id: ff831ec5-fab3-448c-e3f1-08df0f86cb12 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|82310400026|1800799024|36860700016|7416014|376014|10067099003|6133799003|3023799007|11063799006|56012099006|22082099003|18002099003|13003099007|921020; X-Microsoft-Antispam-Message-Info: dLz3Y13oO402KsgnPAwHmETGbPxwZcc9FBWAyb65zv8O2FI+ZcYfKBF/hFfccVjctKwjW25U/q9kw3ngMZvl1rf/spNh7qOLjw+8ZF4tevz3mhiwgsGnGiK/VkKTPBkafNgTKVrkhsg4VL1qfISEMz4cFPj016VTZp3ppkR6cShQJvjY6CdOLbJNoPxadR0fcTDATto7E0MVnEBuwNqCny7RIrZ1VdqbOg5vhq5Cf7/2gtyX9qHWxuv5iq/u5VLlga1Css8VTQg5N84ckM3Fnwl6Osp13quZtUQg2XX3aXVOSyD/TfxSv29b5ZFIYDUemHRlf45juiPRDXzAUHHAfE49SaeT3xp86JM0yq6v5Mk4hNLI3yozbEuQLDNioE9+f7aFPfETeuOUfZJi9nVCEUY+VDE1hmTyFzUzlhnp/f4JKC9e1VCZld1hzLxNAeXbJruTl9LnKKaiFVw5gWg23fYBAUuhfqb4fnnwfP4gMJRWVMcCoq/uhfNkx8fSKvF7qRY/BBKlRnvDaQGnG6xFVQSPrCFSa0NYQuNGHUo57EbxZUKHpE/k5vyFVlYO6zPyMg67/YISSzgudqo5EAYVHaONW2dG2mkn6IG7oLDIIyQriSQL/9IS6dnXPX9Oxt1BgubJJc1+4pvM/HUJ8+femctiCTlnQwoCKZYUQ13oXFTSWWZWgMNBb9x2viFYgfyrKJEZknHIpeSwh1CbcEQK+w== 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)(23010399003)(82310400026)(1800799024)(36860700016)(7416014)(376014)(10067099003)(6133799003)(3023799007)(11063799006)(56012099006)(22082099003)(18002099003)(13003099007)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v40u9eHpBWOcWckWjzlcrcmwX+Px6i60NCZw+jCIkAKEhC2XFAkLnYX9h/knqrHT6zkejSO3c0f+YesBjTO4UD2WBqXqkS4lGCJrV9fLxX1ork4Sj0wksou+0rSUifEPbz5smj5nNXFLeKijHaEK7jIv6qFQms6Cq6ahU2G2JhDo5IWKvfAo2aqsVLCGecJywChbn8DemfS6wqX7htA0l5DbH6wwOHuGN0BqwoTzzU5+6pSegl3LSsJlrhLaJzHwMkyv3ChvO097AN/oPNpafUu6dzLWaRYxwsfWKpMLUYZabjkDwMgOy+bsAu+dYSIPrhPwbZk9uLK4Nn7RyAwD5biUvqT1czcjorVIZqujXcqhpv3Eko+kx3DxJ7RUlgW2YH+2ZkxgHYjL15WPooFyP4x92Iial/s5viHfYofbgHUZfJmpk/+J8UmHlWVD+c3I X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2026 21:59:31.6490 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ff831ec5-fab3-448c-e3f1-08df0f86cb12 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: BN1PEPF0000468C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6066 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Add a flag indicating whether RMPOPT instruction is supported. RMPOPT is a new instruction that reduces the performance overhead of RMP checks for the hypervisor and non-SNP guests by allowing those checks to be skipped when 1-GB memory regions are known to contain no SEV-SNP guest memo= ry. For more information on the RMPOPT instruction, see the AMD64 RMPOPT technical documentation. [ bp: Zap respective tools/ change. ] Suggested-by: Borislav Petkov (AMD) Reviewed-by: Tom Lendacky Signed-off-by: Ashish Kalra Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Dave Hansen Reviewed-by: Ackerley Tng Link: https://patch.msgid.link/39e9ee269a572c516a3f4e937bfe12d00697d5e6.178= 2841284.git.ashish.kalra@amd.com --- 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 f70ee74b5f92..3b5b32d3391b 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 */ /* free: was #define X86_FEATURE_UP ( 3*32+ 9) * "up" SMP kernel running o= n 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 8665a6474806..d1795ce219da 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 Fri Sep 25 15:13:24 2026 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010066.outbound.protection.outlook.com [40.93.198.66]) (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 80EF149B5BB; Thu, 10 Sep 2026 21:59:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.198.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789077596; cv=fail; b=Y3oFif4q2awZVXSJ7u4KJydOEw+RbKHrHESpyNnM80g0qtuh+BzCoBKZJlG3nJItC14XWCU7tJnyxyHSceKEze/BgiXpE+eGlKnK4KYi6G45fFVh/440PsBV1c4ZkgDmvfQutZX9fkgW4CxxTIKVLSYs3uvkbXGA3dpS1XICRoI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789077596; c=relaxed/simple; bh=3I0/vYIJULo4zq1i/nNzduS+ukIwREO6ln2wFgrs3Ik=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DKCIM/OVVgq6Z/3Qvdoel2sVXk0kCdmDsLxX3gi10CpY0y7a43sSUnaGf02b8+oFOUoSfsuNHtq/1iawtAXIQn/O6cDLvpM3wmh57CGh8liiaXv7ycOUqJDGyPtc4GKdoA1WSPOWQ4/9LdGk1FDqko5GN8LrhgnWBb0aZnCFhho= 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=0GtF3p9N; arc=fail smtp.client-ip=40.93.198.66 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="0GtF3p9N" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UpwGI0WS9tD5bY8MSFRwePARG7rMb867enL4L/+5eTmQepiT/vxXWlXr2uUznRRqt9HjZ5WsLgOCOctmiTzkvtOxZzIQBxJiyztAzH3LcgIM1OKkFy8mgO7YOfrEpriJFNkssLbkm6B8Caum40CqOvLpyj/pEHmoD3FfA8FIpF/D9KrLcsQyGHjBwmDd7ccGpNqZTClJ9MvedsIcHdqHi1b7IWurVkn3yxmBy2eDv3DSVkINJ6O1E0EeZCpofldmT/FhEXD1eszckyoIWf2Awk+/xoVKU2f7qFQVgQ0Z5TRv3Dz8H/3NUCKXp2MTJcS98ucPHTNIFTsv9QTjNkcR7A== 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=cLHDYBoTAlysx8a2PQHWLBnWRAAJiPAV+MsXE0qTwps=; b=sGzkxv2pVt5y6wD7/BIniBpkix4gqFC8Ubl+daXB1rFO3xL1l83jHBhtKtWrKoYycQZqFpullh6Bv9Resf/tyZBAWrNXA/zop7CXkGEnWVwSwRh/qPmX8EiWG675iYUyn8R5jrYhDyGUrvmIKCO+ytaIEuUIS01fOe6Not4gR7Ryf3l7o4Mfq/e2rNjdg1QFIWoSgbVh1HkF7un0cDFbxm0CMC41+W54I/AJx03m93Pf8AbeFXcu6IlYeDKLKuCzDAI48smU/47Wlr51tTHsy8GmgKJjdmISrq+0xp8BSoGRpkbtu1sXXPS2JXY30ck5DohlJUbA8lX6M+CKTardSQ== 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=cLHDYBoTAlysx8a2PQHWLBnWRAAJiPAV+MsXE0qTwps=; b=0GtF3p9NwMiFik5pZG0AEZ5MaRHVLC32/QxWk/i5r2E7uInp6bnGwbjxAg71JcasAgNGbZqfr42DcVfeICgGToDS60K8/kVHpU/wt2ZXCRbiJJrNuujaZrHEgcFmbcrn4M9+Rc7tVOme+rkI45+NYb+Fkh9Q2O3FadOSThayzNY= Received: from BN1PR10CA0019.namprd10.prod.outlook.com (2603:10b6:408:e0::24) by DS3PR12MB442436.namprd12.prod.outlook.com (2603:10b6:8:547::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.9; Thu, 10 Sep 2026 21:59:48 +0000 Received: from BN1PEPF00004687.namprd05.prod.outlook.com (2603:10b6:408:e0:cafe::2) by BN1PR10CA0019.outlook.office365.com (2603:10b6:408:e0::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.9 via Frontend Transport; Thu, 10 Sep 2026 21:59:48 +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 BN1PEPF00004687.mail.protection.outlook.com (10.167.243.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.5 via Frontend Transport; Thu, 10 Sep 2026 21:59:48 +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.46; Thu, 10 Sep 2026 16:59:46 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 2/5] x86/sev: Disable CPU hotplug while SNP is active Date: Thu, 10 Sep 2026 21:59:36 +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: BN1PEPF00004687:EE_|DS3PR12MB442436:EE_ X-MS-Office365-Filtering-Correlation-Id: 302cc517-40ce-417d-f824-08df0f86d507 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|7416014|376014|23010399003|36860700016|6133799003|18002099003|22082099003|3023799007|10067099003|921020|5023799004|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: KMKXq/3PjAYgxDUkbyBcboD8qLIDBNIi8zPx1HCeL6qL1qp/v6CcgNzeo6tQlC/izGkBOV5R290mxAaST5TvUkQP2u7ntEGcP07azUtvLl+VR96jbmioxQE27nPFs7uCLm6+b2h4U0hhgGhXpdkrsoiJ0MbyTMlhRf1gjD1Vl3ywRy/lZIav7cdYs/035wS2SCVszeK61hEjIF+Zy5ug8JGk9jreB4Anu1ngHzw8l9Fh4yu2fry/SEZXcCy1wo+9fAT0GSjWKJVk9BDCVwesbKhHVg5CatIZPYwcbU4wH+gaLraaSxb1jqALOInBrtFrjIG25X766+ELRWl3PjwhJuoGav6nyQSZfAQ5z7j8UacoQoRdel07t/xuojr5ty+dDwlhVXBMbbBJmyXeV1rrSUTqs+nalOa0Kv41u6E3H9RCE3hMiDcJWFGBSivjvsHwMMdmqkZZOVFLGpJXrM2Db8Af3UfQI0VwMD7FO76J2yVaLDTBn61WhrkD0d/xNoN6BeSIsNJ0UUiFrj8g2kb/zjf0xJCuLcfIiluBDh2q9SzPpsOUZx6RTiiV+lnSGO5JOlzXVyOKGZgX2VUAHM8BoeGwvzo4qnLGq6ObuW4XAYJTZtk5AtnjgkT08D+yi/KqVWSikUvu4o75JgHl2DnvL8uOQVQ5X7ipvGuAvidj0B09GAu0UgqKgkj3ipeuvxmLUgZvlfT8xgRyf28vCtRdRNtWbEqrVrVF8kW9A/a2isQEaQAmoOO7Dsk33dho/8uV 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)(7416014)(376014)(23010399003)(36860700016)(6133799003)(18002099003)(22082099003)(3023799007)(10067099003)(921020)(5023799004)(56012099006)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nHiNbGxkR07VQMU7Y9RxOF/Quilri+hHARbaxu8yGdpEat6WSHsN2UokCmaj7KH4JgXvF3dX/h93oIufubpo9/p6hNHAImJdV1g9ZiFr5a+vmyJdm1tNkeY5fxyU502cqzQ/3oVA4jQf/RROENQfYxIzM5ZE20B2y/TctVa9+EFO5dNWSBxaaqZix+voSr4bKtKL3wQ80LbX6sJ34iR4qQGC+Lx0LRo4unnoVn5z+XcOz82MLr5GJHE9AzN6g2YCygHHqwHOKXQPRGuQfWlWMDqFOcBczBZIHxkeCHQ6NQxqUWbhEfHtoS1/uRKw+omMucH91t6HeuCtLcMr3MGX1RtQXIdOXpgvl1JX1+/982RwSVN/PsYsWbGFvKeTvotPUSLlabFvR4OW4rk29R2eiW12cpJYp7jupJnl6WTr2+267IcaxMKyMdOwE8nPMVyZ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2026 21:59:48.3574 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 302cc517-40ce-417d-f824-08df0f86d507 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: BN1PEPF00004687.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS3PR12MB442436 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra While SNP is active, every memory write is checked against the RMP to protect SNP guest memory. A core performs these RMP checks only once SNP has been initialized via SNP_INIT and the SNP-enable bit in SYSCFG is set on that core; the firmware requires the SNP-enable bit to be set on every present CPU before SNP initialization. A core that is not SNP-enabled and not SNP-initialized performs no RMP checks at all, so there is no valid configuration with SNP active and any CPU exempt from RMP checks. The firmware determines which CPUs are present from the processor and the BIOS/UEFI configuration (e.g. SMT disabled in the BIOS) and enumerates them at SNP init; it is not aware of the OS bringing CPUs online or offline afterwards. SNP_INIT fails unless SnpEn is set on all CPUs, so a CPU that is offline when SNP_INIT is issued, does not have SnpEn set, SNP_INIT fails, and there can be no SNP guest memory. OS CPU hotplug can thus diverge from the firmware's expectations and break SNP. Tie CPU hotplug to the SNP-enable bit: disable it in snp_prepare() before SNP is enabled, and re-enable it in snp_shutdown() once the firmware has disabled SNP. If snp_prepare() fails before enabling SNP it re-enables hotplug itself; once SNP is enabled hotplug stays disabled, including across a failed SNP_INIT and across the legacy SNP_SHUTDOWN_EX path, both of which leave SNP enabled. A kexec target that boots with SNP already enabled, disables hotplug once in snp_rmptable_init(), since snp_prepare() bails when SNP is already enabled. With CPU hotplug now disabled while SNP is active, the online CPU mask is stable, so the cpus_read_lock() previously taken in snp_prepare() to iterate it is redundant. Drop cpus_read_lock()/cpus_read_unlock() here. Suggested-by: Thomas Lendacky Reviewed-by: Tom Lendacky Signed-off-by: Ashish Kalra --- arch/x86/virt/svm/sev.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index cff285d8ad8e..558f7924a3f8 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -513,7 +513,6 @@ static void clear_hsave_pa(void *arg) =20 int snp_prepare(void) { - int ret; u64 val; =20 /* @@ -526,14 +525,18 @@ int snp_prepare(void) =20 clear_rmp(); =20 - cpus_read_lock(); + /* + * No CPU may come online without SnpEn while SNP is active; disable + * hotplug here and re-enable it in snp_shutdown(). + */ + cpu_hotplug_disable(); =20 if (!cpumask_equal(cpu_online_mask, cpu_present_mask)) { - ret =3D -EOPNOTSUPP; + cpu_hotplug_enable(); pr_warn("SNP init failed: not all CPUs online. (%*pbl online <-> %*pbl p= resent masks).\n", cpumask_pr_args(cpu_online_mask), cpumask_pr_args(cpu_present_mask)); - goto unlock; + return -EOPNOTSUPP; } =20 wbinvd_on_all_cpus(); @@ -548,12 +551,7 @@ int snp_prepare(void) /* SNP_INIT requires MSR_VM_HSAVE_PA to be cleared on all CPUs. */ on_each_cpu(clear_hsave_pa, NULL, 1); =20 - ret =3D 0; - -unlock: - cpus_read_unlock(); - - return ret; + return 0; } EXPORT_SYMBOL_FOR_MODULES(snp_prepare, "ccp"); =20 @@ -567,6 +565,13 @@ void snp_shutdown(void) =20 clear_rmp(); on_each_cpu(mfd_reconfigure, NULL, 1); + + /* + * The firmware has disabled SNP (SnpEn is clear), so re-enable CPU + * hotplug. A legacy SNP shutdown returns above with SnpEn still set and + * leaves hotplug disabled. + */ + cpu_hotplug_enable(); } EXPORT_SYMBOL_FOR_MODULES(snp_shutdown, "ccp"); =20 @@ -577,6 +582,8 @@ EXPORT_SYMBOL_FOR_MODULES(snp_shutdown, "ccp"); */ int __init snp_rmptable_init(void) { + u64 val; + if (WARN_ON_ONCE(!cc_platform_has(CC_ATTR_HOST_SEV_SNP))) return -ENOSYS; =20 @@ -586,6 +593,15 @@ int __init snp_rmptable_init(void) if (!setup_rmptable()) return -ENOSYS; =20 + /* + * On a kexec boot SNP may already be enabled (legacy firmware leaves + * SnpEn set across shutdown), in which case snp_prepare() bails without + * disabling CPU hotplug, so disable it here. + */ + rdmsrq(MSR_AMD64_SYSCFG, val); + if (val & MSR_AMD64_SYSCFG_SNP_EN) + cpu_hotplug_disable(); + /* * Setting crash_kexec_post_notifiers to 'true' to ensure that SNP panic * notifier is invoked to do SNP IOMMU shutdown before kdump. --=20 2.43.0 From nobody Fri Sep 25 15:13:24 2026 Received: from PH8PR06CU001.outbound.protection.outlook.com (mail-westus3azon11012039.outbound.protection.outlook.com [40.107.209.39]) (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 2202C373BEC; Thu, 10 Sep 2026 22:00:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.209.39 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789077620; cv=fail; b=jkCNdt9eF6tiYd+jXd3a3o2BeuDdekxXxTTEFuOH7nwneGBF82mgC4PD7BnDKkReD3dTSQH99/krZaBd2y2seWh/gy7K7gurikczIZzlJOWxwAh3I0BH8pDiIhMo1odpObxmRDEoKvF7F+nL9koOuiLCp2B2JMZqiMJu6dbMqgo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789077620; c=relaxed/simple; bh=OK56UVHa8iyFY5IhlY6nmNpVMiM/iljvMNxv+hLK2/c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gS6hh4Lct+kKMjaAADEILVzjetbT0PhcHQfJ11FU1nVrtpNt5jCdmH9VDnDhF2cIccFxL7tjx85ntny0dInsY0oTo4J8Sdo/9er6UuniQHVkv4856CoeLZMph7lYmvXLVGOoo6+opJhgnVfWmclWwRoWPA6mHXF7DEacQUVUTJ4= 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=hN9Jbf4x; arc=fail smtp.client-ip=40.107.209.39 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="hN9Jbf4x" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qR4bFjuTAuo8FSbq+n5eUhiGauOBlgW/B366hhaJ+CHe7xV+XXcgSxsTkT/eGE55xGM5QvL9ZKR5kmlS/34KQPtheGhvC1VIB/vRmn9IOj2izyr0Ibb1Phr+3p2NAA+UcfnxYBreeYMJBbmLQDZK1DVAtf4+7B1AmwIUu8uTpAKCgmQ/pleNdqcidG6A8E4Lcat2wax/LQrNJ6iM2PXoCYBqm9Ij1la47K89FbYwp2vxHZSqqqQrEZ0VjfqufZVsqFWynkbwsrBM0gpIIrfxpM5TI1Np/Hkcxi/UXIHjQvMylXH/jGquTPkxslqsFtT8M55iOVMVm7MwFq0FVfEW9Q== 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=J0BcvZQwROABkdt2eFBZCWafYEv6bIBynj11EFVVh0o=; b=sNSDr8QTR0ljaBBM/x6wX48lb+Q6b7Yadj6X6iEkwJL+31wdS1miL92M7S+b7bL+rFo0mrjIZaGMW+U/5DKMsEu8d/6Dr4VOLUG7dYHwURjp5iepUIk7G4Z+Kan2A/9Ze0V3GXb5MB0F96uws05w+GZblA7PyzNsC93sQ1sNsmGMrMzWoNCL2u1q69vJqE/Reswu9IGCDM6ngC8mB8RyTkwOz6456iC+grbiY4HDJDDlPvyEf6ag5NzdG7CytPD6Z/nKDN0grnHfZcgt46fggDXb/g/DH+mlzUgZaOFqDsxSI6KugHSwYk6MWTRtGEpxa2Uhb6gOAPutvnpZ4Pmx7Q== 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=J0BcvZQwROABkdt2eFBZCWafYEv6bIBynj11EFVVh0o=; b=hN9Jbf4xWe5v1xsRJ9z+MVRB0YrZjg7m7AnptYcnE/RRRMSEOytKaJrAg5WaMOFlATr0foO3Mik9iQEuHw+0BYGow+l+aLdweAoBYyr8VylBM5w+gs6IbfaLd+xg0bBadNOGfiVvVYRFge3d5xRuGVbN1eDBQPDNxKZSYFm3sr8= Received: from BN0PR03CA0001.namprd03.prod.outlook.com (2603:10b6:408:e6::6) by DS0PR12MB6413.namprd12.prod.outlook.com (2603:10b6:8:ce::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.9; Thu, 10 Sep 2026 22:00:05 +0000 Received: from BN1PEPF0000468E.namprd05.prod.outlook.com (2603:10b6:408:e6:cafe::af) by BN0PR03CA0001.outlook.office365.com (2603:10b6:408:e6::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.9 via Frontend Transport; Thu, 10 Sep 2026 22:00:05 +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 BN1PEPF0000468E.mail.protection.outlook.com (10.167.243.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.5 via Frontend Transport; Thu, 10 Sep 2026 22:00:05 +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.46; Thu, 10 Sep 2026 17:00:02 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 3/5] x86/sev: Initialize RMPOPT configuration MSRs Date: Thu, 10 Sep 2026 21:59:52 +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: BN1PEPF0000468E:EE_|DS0PR12MB6413:EE_ X-MS-Office365-Filtering-Correlation-Id: a9a761b6-7b40-4a76-6a45-08df0f86df37 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|7416014|376014|23010399003|1800799024|82310400026|921020|6133799003|3023799007|10067099003|11063799006|5023799004|56012099006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: kyi1Bd0iKlCNdu+qiOKlS0I1JJd6uaU8BoIuyQkWMAXYNyT3bWgZLxVaxChIuVppR/Mj3rxvP6LU0PsfpNtAbKiGfzd1k1dql6NNbHbdSqWunAhvbnSRPWoXGKbxtnJatkI+pkNOAU5j125MkIdAlj2nKmdozH0dl9yix1ztupMVpiiF/WHRneG1npad/kz5o7FWRosh1Akh45YfKyt89OnmJ+yHkre2k5XCjM4vkv1Z6bXJCumfPMI7r2RhfPLd8VkztPQBIm4YrdVamcY1HvJh3ymy+ZEHu1L1CUXI0ucR4Qbf+Uj6iJsR6gCQVZVR82jlo7ch8lW4O87GY0P3Za5mGwJF68SWVxGY0BaY8Qvk9oU3AceTaIHIhjL5g9z8ccs2Kgv6Etqz6KaMLgAsKvDEm1647up9lfKwt1YV/hjuE4nhH3HqUOGZ+EKw02HfsSxtvRUfjO2nwkcdjXoGVjcnlbz24CUV4ba4s+xSWfXXIlTeu8vFuXvI2zEgOcF68EGp/PdVpoChcvx/ho9kLIGwKKLuiobE08LSAzs/vEP2b7D6Er2sQ+w2hee2+/UxukJjM0Rd7eVaQ3ThxnO/WX/i+jE3cz3GGs+sMkKhDgDLJuFCwJGdCwTRMCudVY+F5cGcg5WA8pxkdAc2s6UBB7I8zxdiBzyLe0/99sA6ULxbQ3PfNS0E3S/Wan8prrmTEUk/6cAQ5Adr8hC0bKsqaEWz9L3rPqyKNHdM/G3/56zsCT+CQTBPfK++subcwp1L 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)(7416014)(376014)(23010399003)(1800799024)(82310400026)(921020)(6133799003)(3023799007)(10067099003)(11063799006)(5023799004)(56012099006)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kp0NLCQ7pSCdjog3k4UqeNrPmCTTaliNyTdWbRUrSsc2IjDcmsmsQjbtSpf3UDKiu9cE4XHoA+WC1HcQy6A5X9qPEES1rm/m04PtckjM7Qg2dc+tggxj84COs1VhD+dQQn0DmXaOxAHyzKC/1b89QuGOGWYee3U6rSdN1GRF1+oedfN3gcX/wNwXyYenq/nVKAaxM16GYDAmREfbBS5/YlBNwA7aOpJRcRz164+qU1HVAU28WxwXVN8f/c4rQibYyZn97QbRO4Lh5TPIIUeNhN2Y5WX1LHSh99oQ1tT0JMZfd+1KWyBTICisaag9EWHQ1qJZO/9OI/S9f4oPgoCnymBjg2K2TQS2tDNYUkyPVnBN3R7OfxQEr2NR1fuGN0CIM8uy92Pw/ZTZVwIeJ78i8wybY57Pudz9wcBOESuv1is6GymfTfVt/5M5YtuxSXkN X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2026 22:00:05.4445 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a9a761b6-7b40-4a76-6a45-08df0f86df37 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: BN1PEPF0000468E.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6413 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 Signed-off-by: Ashish Kalra --- v14: rmpopt_disable() and the RMPOPT_BASE teardown were removed from this patch (the disable path is reworked in the next patch, and the MSRs are now left in place on shutdown). Dropped Reviewed-by: Dave Hansen and Tom Lendacky due to this rework. arch/x86/include/asm/msr-index.h | 3 +++ arch/x86/include/asm/sev.h | 2 ++ arch/x86/virt/svm/sev.c | 46 ++++++++++++++++++++++++++++---- drivers/crypto/ccp/sev-dev.c | 2 ++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index 3a8e51a0c9e8..1635e2e1c576 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 9e7a077c445d..5638d09b5132 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 558f7924a3f8..a059327dc107 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -124,6 +124,8 @@ static void *rmp_bookkeeping __ro_after_init; =20 static u64 probed_rmp_base, probed_rmp_size; =20 +static phys_addr_t rmpopt_pa_start; + static LIST_HEAD(snp_leaked_pages_list); static DEFINE_SPINLOCK(snp_leaked_pages_list_lock); =20 @@ -575,6 +577,32 @@ void snp_shutdown(void) } EXPORT_SYMBOL_FOR_MODULES(snp_shutdown, "ccp"); =20 +static bool rmpopt_capable(void) +{ + return cpu_feature_enabled(X86_FEATURE_RMPOPT) && + cc_platform_has(CC_ATTR_HOST_SEV_SNP); +} + +void snp_setup_rmpopt(void) +{ + u64 rmpopt_base; + int cpu; + + if (!rmpopt_capable()) + return; + + 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 cover at most 2 TB. Program each core's + * RMPOPT_BASE with the start of RAM to optimize up to 2 TB. + */ + for_each_cpu(cpu, cpu_primary_thread_mask) + wrmsrq_on_cpu(cpu, MSR_AMD64_RMPOPT_BASE, rmpopt_base); +} +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 @@ -699,13 +727,21 @@ static bool probe_segmented_rmptable_info(void) =20 bool snp_probe_rmptable_info(void) { - if (cpu_feature_enabled(X86_FEATURE_SEGMENTED_RMP)) + if (cpu_feature_enabled(X86_FEATURE_SEGMENTED_RMP)) { rdmsrq(MSR_AMD64_RMP_CFG, rmp_cfg); =20 - if (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) - return probe_segmented_rmptable_info(); - else - return probe_contiguous_rmptable_info(); + if (rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED) + return probe_segmented_rmptable_info(); + } + + /* + * Segmented RMP is either not supported on the platform or is + * disabled by the firmware. RMPOPT is not supported without + * segmented RMP. + */ + setup_clear_cpu_cap(X86_FEATURE_RMPOPT); + + return probe_contiguous_rmptable_info(); } =20 /* diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index f833cb7e4da3..287a8345854b 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1663,6 +1663,8 @@ static int __sev_snp_init_locked(int *error, unsigned= int max_snp_asid) =20 sev_es_tmr_size =3D SNP_TMR_SIZE; =20 + snp_setup_rmpopt(); + return 0; } =20 --=20 2.43.0 From nobody Fri Sep 25 15:13:24 2026 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011036.outbound.protection.outlook.com [40.93.194.36]) (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 9B83D3AC0E5; Thu, 10 Sep 2026 22:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.194.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789077638; cv=fail; b=Grq6YfcyOzD9N0w4+P0Du+jl8aPSF5L5fPj476+BCTVyHRZ4c5kWmoulI7ra4u2wX1XxzAh0G9zXTshAkKrdyBFMP87vEmQV7thm7H9RZjPJ9+Z+6z9D1GE2zlo3MKsD2VQCTWiH5SDe2c0eSEBndDd1syirlrcQZJKss08HXMU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789077638; c=relaxed/simple; bh=MExwv9kfhXWfLqRtrvTxmw36CwTAqewVa7y2ukD7R1I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PZ78L+pMInJ8kuSa0uzS29CJtbUUr/xBpOvOxTIfc1i8mxywYXciO3qyktLs4q1iZ+k2WhBppdEdFVXLMu+TifXW70FI9JNtH4FC6OA58/YdtfHj0u1bilCl+pOS+BhiaSeliKWLjJMYvdHT8IyOnlP8G290XKOGtDxXFsqGANk= 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=QNf0LEvD; arc=fail smtp.client-ip=40.93.194.36 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="QNf0LEvD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DTmbyGL0kvxHWdomfpmfZUTLbg7ApljKQ/JWukKIXhEZdSUkdJy7fIQ8eEp3gHCe88BUt4mofOjBChdr7bb6/KnCdLtlMWO01av9ISlpnW19b5yukJ9N1GAjmzbM6Jx3MvMHjMe7GTGAxTi9l5B8BCmdW4KP4WUQAROkTK6Vnfp/fLTkasaWY8n68bWpHclFpz6S6QeNzAzicyMVHaEt7xS1I3b1lTpDbITaj0IUdkTtJduD8wLhYbsjY5MKclK0Dj2BU9+ht9MulPaAEA+GM+LKkMMgPuyjgh3dye42BdHOY0m3/ge3Lg4D/2okZYiE/vMTNfxBMHv0aac25YiFnQ== 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=U0i8QQWmNOUbzMnnzT7Fca4utAUp4HSX8gqVNKevPTA=; b=Z2RFDBXLMBG45vq2j494fuBUr4W2XWCjWqn1CM9m1LzWGn4SXdPXHW6tSBoFCigdpOJJ917zN9VNOo2meMmHHYyxkPXtO/3QjUzNbMTYtBKFvCcxHDSQo925y13ElE/OSHz0iBs14zmiHZFtXFC/T9Eop7l8M22Znb+iXXK0OmoXWF4fbdxUMq96VX8yuUPUCOMZBIic2a6LNBV8Ch40V6ahV3HqNCc6cBxrouckVd6+XIJDfBs4pBoBp7vnPWI7hUJJzbHp1ev0GSUPh50L6eyCDFUGrfKacRp6KPkc9q8jvwKEqd+zxIaga2O/WLntFbRNHTxwuxaAt4GudNKamg== 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=U0i8QQWmNOUbzMnnzT7Fca4utAUp4HSX8gqVNKevPTA=; b=QNf0LEvDXbmkkjNu2K38vNsTU1zxd/C20WibxKAmEM5I8d1q6xPRasiO0ntO9a425F30PZPegmQpcfHCUEJO/C9k1l9RI5EcOe+628dcoVUvWsVfxSwHHt9TLCkbHkmhLPizGzGnUT3+K8gVuNCbNOEvkWrz9iI/KE26Ew87AKs= Received: from BN0PR02CA0016.namprd02.prod.outlook.com (2603:10b6:408:e4::21) by PH6PR12MB902451.namprd12.prod.outlook.com (2603:10b6:510:3df::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.9; Thu, 10 Sep 2026 22:00:25 +0000 Received: from BN1PEPF0000468B.namprd05.prod.outlook.com (2603:10b6:408:e4:cafe::79) by BN0PR02CA0016.outlook.office365.com (2603:10b6:408:e4::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.9 via Frontend Transport; Thu, 10 Sep 2026 22:00: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 BN1PEPF0000468B.mail.protection.outlook.com (10.167.243.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.5 via Frontend Transport; Thu, 10 Sep 2026 22:00: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.46; Thu, 10 Sep 2026 17:00:17 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 4/5] x86/sev: Perform RMP optimizations asynchronously Date: Thu, 10 Sep 2026 22:00:08 +0000 Message-ID: <1e3d0edb6b275e33fa6f76b0c31db9e999d9a270.1788984053.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: BN1PEPF0000468B:EE_|PH6PR12MB902451:EE_ X-MS-Office365-Filtering-Correlation-Id: c172c2b9-82b1-4b89-8803-08df0f86eaaf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|7416014|376014|36860700016|23010399003|921020|6133799003|10067099003|5023799004|56012099006|11063799006|18002099003|22082099003|3023799007; X-Microsoft-Antispam-Message-Info: N84jwhV+Knvj0WbJfrCznG76QpVWNXtFuPywbbVBwgYXRadvFAIYy6AaCCUUgkLtRWtauMIdJPRuRTpt2OYdYbqT1xFlWf29OmXvrKFjgUtZeilQrP17FjseHuHbEzjEdgX53/l0ZB7+6a6UF4WdtEICVXkQnDyUKBwQtSoue589a8ckERlOjVf+zABEWOWQI8CV6gtTNCx79XdNUWAxSVladrQRQYVuJ7b1cXLBJFYfUzra9EI2CDflq3b3Q5f+9msZoPrGocKSPWdgfF1q5Z+T5Ubtj8cv6T/g2XLgzvblJ7YwYBjx5thwy2m5eXTcxNelpGxJ06I9DCXUcS8bZ1K72F5L/KRSXFB5sQcjP3tB7mBGQjSoYfZ4xh70X/b6hDKuu/eEpVxtGlYGC/Kd3mMpx73qqqokSdI0DlTk6OjeEbKHUdsxMSr38n1G/JapdthhJAQeOBWjHE6iQHKf4wO8+B/vBCYA61QmX4QEEpZ1HnDqEJDucIf3+YCp+wRwWLFAGodKhNWg2dV/IN447XZAFngykOVB8hB1ZieOesa98n7aT0F6l6aSi1FKT/6rvGTMD7Xcrcif+098sJ3ZHFlHWxjVk42D1L43E0LTXe/XFrAjK0ZtslwJwLYCmzrBwgv/6tXqsU22o7xgyOfUuE0povFDImlq30i8FTIxkRQuI5/UVP5azQ9ZSg5oEYZlkjzuFs0i14HXBkw97NnJ7YK6O9GqZ3HAEzPJgd6Oo+MjWUrw/FDIIk9z+VlUa/TW 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)(82310400026)(7416014)(376014)(36860700016)(23010399003)(921020)(6133799003)(10067099003)(5023799004)(56012099006)(11063799006)(18002099003)(22082099003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: V9ixO+yzuNztHKiMMPo8GROnIXQNZnWpUyZU2l5+NOibLXn0hCaGK8gwzQBMsxK8ZzYWFBah3bObkh5N4IKpbgWcXAqvQBjG2RcoMHe/QTecEgSi2TlrkUeNzWbJ6yAOS1wzIrD3d1T0qCJNvHrm+CPUw9vcu/AR0npYlqDR1Pr2N2ZezzgK5vaBq19gQ4dM/au/lM0N+fGHSGXxeMa8slF4Ge6bkFOTF1jdE2sp2ez6QQ3yBJa1R9LtvbNZWoyZvzpCNzHEpNzM7ioGjHwsOWB8/LpBuVC8Z2FUZCoWEfhhyqDVk45C23IGn1oZL3aaOAC5J4x5bOLbEclnZAZsRhRV1VoqkMKbCbH4gS+YatETD6fvtj5lOfTJumjhWkqVIXKP13E9TT847+tx54k6NJ+BBVADNG757lDTlqRgFkeEelV15Ux/P19J0ItqkBCA X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2026 22:00:24.7046 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c172c2b9-82b1-4b89-8803-08df0f86eaaf 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: BN1PEPF0000468B.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH6PR12MB902451 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra When SNP is enabled, all writes to memory are checked to ensure memory integrity. 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 SNP guest memory. Add support for performing RMP optimizations asynchronously using a dedicated workqueue. At RMP initialization time, run an optimization pass over all physical memory (up to 2TB of system RAM, starting from the lowest physical memory address aligned down to a 1GB boundary), skipping RMP checks for 1GB regions that do not contain SNP guest memory (excluding preassigned pages such as the RMP table and firmware pages). As SNP guests are launched, RMPUPDATE assigns their private pages to guest-owned state; when such a page falls within an optimized 1GB region, the hardware clears that region's RMPOPT optimization and RMP checks resume there to protect the guest memory. Since launching SNP guests clears these optimizations, perform them again asynchronously using the dedicated workqueue. Suggested-by: Thomas Lendacky Suggested-by: Dave Hansen Signed-off-by: Ashish Kalra --- v14: Reworked the setup/teardown - initialize once and do not tear it down; rmpopt_disable() now only cancels the pending pass. Use a dedicated per-CPU workqueue (WQ_PERCPU) and drop the migrate_disable()/ migrate_enable() around the local scan. Added a binutils-version comment above the RMPOPT .byte and trimmed redundant comments and the 2 TB pr_info(). Subject reworded from "Add support to perform RMP optimizations asynchronously". Dropped Reviewed-by: Ackerley Tng and Tom Lendacky due to the rework (kept Suggested-by). arch/x86/virt/svm/sev.c | 92 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index a059327dc107..35678b1f535d 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 @@ -124,7 +125,16 @@ static void *rmp_bookkeeping __ro_after_init; =20 static u64 probed_rmp_base, probed_rmp_size; =20 -static phys_addr_t rmpopt_pa_start; +static u64 rmpopt_pa_start, rmpopt_pa_end; + +enum rmpopt_op_type { + RMPOPT_OP_VERIFY_AND_REPORT_STATUS, + RMPOPT_OP_REPORT_STATUS +}; + +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); @@ -557,6 +567,14 @@ int snp_prepare(void) } EXPORT_SYMBOL_FOR_MODULES(snp_prepare, "ccp"); =20 +static void rmpopt_disable(void) +{ + guard(mutex)(&rmpopt_wq_mutex); + + if (rmpopt_wq) + cancel_delayed_work_sync(&rmpopt_delayed_work); +} + void snp_shutdown(void) { u64 syscfg; @@ -565,6 +583,8 @@ void snp_shutdown(void) if (syscfg & MSR_AMD64_SYSCFG_SNP_EN) return; =20 + rmpopt_disable(); + clear_rmp(); on_each_cpu(mfd_reconfigure, NULL, 1); =20 @@ -583,6 +603,43 @@ static bool rmpopt_capable(void) cc_platform_has(CC_ATTR_HOST_SEV_SNP); } =20 +/* + * RMPOPT optimizations skip RMP checks at 1GB granularity if this range of + * memory does not contain any SNP guest memory. + * + * @pa is a system physical address; RMPOPT operates on the containing 1GB. + */ +static void rmpopt(u64 pa) +{ + enum rmpopt_op_type op =3D RMPOPT_OP_VERIFY_AND_REPORT_STATUS; + u64 pa_start =3D ALIGN_DOWN(pa, SZ_1G); + + /* Supported by binutils 2.48+ */ + asm volatile(".byte 0xf2, 0x0f, 0x01, 0xfc" + :: "a" (pa_start), "c" (op) + : "memory", "cc"); +} + +/* on_each_cpu() callback: optimize the whole RMPOPT range on this CPU. */ +static void rmpopt_scan_range(void *arg) +{ + u64 pa; + + for (pa =3D rmpopt_pa_start; pa < rmpopt_pa_end; pa +=3D SZ_1G) + rmpopt(pa); +} + +static void do_rmpopt_work(struct work_struct *work) +{ + /* + * Warm up the RMPOPT cache on this pinned per-CPU worker with interrupts + * on, so the IRQ-disabled fan-out below only issues cache-hit RMPOPTs. + */ + rmpopt_scan_range(NULL); + + on_each_cpu_mask(cpu_primary_thread_mask, rmpopt_scan_range, NULL, true); +} + void snp_setup_rmpopt(void) { u64 rmpopt_base; @@ -591,6 +648,30 @@ void snp_setup_rmpopt(void) if (!rmpopt_capable()) return; =20 + guard(mutex)(&rmpopt_wq_mutex); + + /* + * Set up once: the workqueue and RMPOPT_BASE MSRs are left in place on + * shutdown, so a later re-initialization just re-queues the optimization + * pass rather than redoing the setup. + */ + if (rmpopt_wq) { + queue_delayed_work(rmpopt_wq, &rmpopt_delayed_work, 0); + return; + } + + /* + * Use a dedicated per-CPU workqueue so the potentially lengthy warm-up + * scan does not tie up a shared workqueue worker. + */ + rmpopt_wq =3D alloc_workqueue("rmpopt_wq", WQ_PERCPU, 1); + if (!rmpopt_wq) { + pr_err("Failed to allocate RMPOPT workqueue\n"); + return; + } + + INIT_DELAYED_WORK(&rmpopt_delayed_work, do_rmpopt_work); + rmpopt_pa_start =3D ALIGN_DOWN(PFN_PHYS(min_low_pfn), SZ_1G); rmpopt_base =3D rmpopt_pa_start | MSR_AMD64_RMPOPT_ENABLE; =20 @@ -600,6 +681,15 @@ void snp_setup_rmpopt(void) */ for_each_cpu(cpu, cpu_primary_thread_mask) wrmsrq_on_cpu(cpu, MSR_AMD64_RMPOPT_BASE, rmpopt_base); + + rmpopt_pa_end =3D ALIGN(PFN_PHYS(max_pfn), SZ_1G); + + if ((rmpopt_pa_end - rmpopt_pa_start) > SZ_2T) + rmpopt_pa_end =3D rmpopt_pa_start + SZ_2T; + + queue_delayed_work(rmpopt_wq, &rmpopt_delayed_work, 0); + + pr_info("RMPOPT optimizations enabled\n"); } EXPORT_SYMBOL_FOR_MODULES(snp_setup_rmpopt, "ccp"); =20 --=20 2.43.0 From nobody Fri Sep 25 15:13:24 2026 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013022.outbound.protection.outlook.com [40.107.201.22]) (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 4BCE73B2FFF; Thu, 10 Sep 2026 22:00:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.22 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789077649; cv=fail; b=CQWY/yMFKANXfaBZnlnHiM2R0T9IAs+MW68d9EW7zFkq8QLebCOYHkAJk5bt9vHhQkHdKmhGAb9vVdh7o2qkBuHgs0OFArYK2aZK86gdlw0Va4hc220KsAfrt6PnTzaZ+sjCCRedcsGXa0HBZl0jQk6H7vBRNqkyiovPGrcFnew= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789077649; c=relaxed/simple; bh=Z+lBPRspMHWamrDyoqvIdibJlMYeLXzDumTvD+yLwPk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BwrmycC35zU5QIPYNPFfcTQmWltCuOhf62eChFyo1u/PLZ33MHLOW4pfn3azkY8l0zRgmO+yI/nBDJG+MCIne1GBCUPJw5shjNWNDyHfQCctC/9OS+D0tA99Z23xWJnGgl4H1keFTCnoAGCiKCDB7THlxywPLPYgS7Hjw6H8Cz0= 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=CVsYmmgU; arc=fail smtp.client-ip=40.107.201.22 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="CVsYmmgU" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ns3ZkoR23r1VsaerECbuZcqSbMETrnHMuwbp/oOFKiZWzTizmd03keANEfCtrgOsK5Q1AlNaTY06ct97ht8EIPyQTjKzXDb/BhtqmokboSVQ1avUpqAaLG4N5HCu4DBoU+SHVS0/qQesC5RiTmAJi2WlLwMjBEPuDTMLxZE/LlvhKRMj+CImSRmtzxmYz6gHPkHtlp1r7yseBCargMl9Td/HNjOj3YpDNA5CD8YA27+RKjKyUVP/3BIo2AEXY7pcU+hZ9yt0DFXwSdA8oUNJMJ/i0qP5tihwSGjSV4KBQNgAjPhekb8ZEVMh7TepYQHqeD2SWN6gb41jSlZNOrt/ag== 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=9aD4RYHbmka90X9bPBHoIzFcYX+7mcXV8A2e+OQfIys=; b=UEy1KuBfMMzMJHQrPuNJ26owRxSu6DXyMq36StY90ZibwNg2IsePW73vokbP81b3fc2p9CNQZ8Jpgj3aOMzQ/GstweOhcc9Gr/AQw2xEemcsIo6l/sNvKR1gzzbQvASv6SD7A1NtUhynIFOLG+aaFFyRhRREGr2uuF1ORZQMAQbbfHdC/14hO2qnTMTJ5nDWAg3sAOmNsleR32FOJ+4iqjSAw5jR3S++Y2ikrua+IU8uQfuUPb9WGWkphake+Z6QRfEAYk4aPASSotSN5j46YqErrrvk89tM92YM4qqp5DlliUj4yu5xa+aiVwZ+VDyy5U5DdMfXpeJzHwZr9ptCQw== 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=9aD4RYHbmka90X9bPBHoIzFcYX+7mcXV8A2e+OQfIys=; b=CVsYmmgUc06UVMrlmV2hAc4fu9sUbOpR2OdwJRm51BLhOoZiz4kjcpY+zILU/w5UftrALFXLY60zehqCLTunGERuCSOlPPlNZBk5djqWezv2OgwY4Fb6Gjs7qov45eijvfR7K8LWyXD9Ro8HI5JvIL4KlUIaIy2Jk7moMY4DxrA= Received: from BN9PR03CA0957.namprd03.prod.outlook.com (2603:10b6:408:108::32) by PH7PR12MB6695.namprd12.prod.outlook.com (2603:10b6:510:1b2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.7; Thu, 10 Sep 2026 22:00:36 +0000 Received: from BN1PEPF0000468C.namprd05.prod.outlook.com (2603:10b6:408:108:cafe::23) by BN9PR03CA0957.outlook.office365.com (2603:10b6:408:108::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.8 via Frontend Transport; Thu, 10 Sep 2026 22:00:35 +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 BN1PEPF0000468C.mail.protection.outlook.com (10.167.243.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.5 via Frontend Transport; Thu, 10 Sep 2026 22:00:35 +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.46; Thu, 10 Sep 2026 17:00:33 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v14 5/5] x86/sev: Re-enable RMP optimizations on SNP guest shutdown Date: Thu, 10 Sep 2026 22:00:24 +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: BN1PEPF0000468C:EE_|PH7PR12MB6695:EE_ X-MS-Office365-Filtering-Correlation-Id: 02e349d9-779c-4760-28d2-08df0f86f147 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|23010399003|1800799024|7416014|376014|82310400026|5023799004|56012099006|11063799006|10067099003|921020|6133799003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: W2t2Op1Er2tnNCe/uFQZ8rQBLZzgpg0VQDjSGxjAbx8R5NjW7xHqrJlo2J0zYyDwmjyqf69wagngGxR9OgVssLfO2fpbV0DKvuJBf/LsmEncVn2EbcAe1N4Awhrsfc+UTdFjBpSokEaeEALgiFHT2k0pZPmVjNo8usT8/q/0Xw3E0wReoNcxnGt/cXHzKKV/LMk/gN8z8Fnm4QxjZ/AgGRkitp7JI5rc55x1HmSr2+jrUpe+bkh1C3DLihOOKrcwovT1Qaz6dJ9R/eOTNiLybAzm3Ad74weIpxtx/xTy6ys4ein05jXGzatEgt7TVzUTdc4SJYV7nvUXEjXrAibTf9+VCs1PpEwkZwXbfDrkjf6xNKZ11tj0eJhjk1uT85uFWP4KNKifaeRHnbl2+43+adXRMe67QnwUH25lbqrPejRBoA1nKJOCusPZ/cbNZHgsGvmE0z/0rXxbpVU6BddA72sahYHfgDNCgLz3WwkVF8gThluSRe9mILeLyhK7d9FXn227pQQ0J821VGudLM5qAk+3Si7ECzRZz/ywOVtcKQM36kxW62DLe+a8eE3WBJ2/7WhYhJJM/SltaemX14wR0yCqtMU6l27BFddhTV0x3Nd20mY/QwQz6nONdG2gkcWsYGAxNM7Go2FfkS37BDCdC4R946fvKi/Mlr1RdZa4OLureZh6Lehq9hKdrXW162j+Y+OPLPkhFAVMLvAM6qb7cnv3rBFLNBn0eflEeCL54rwYchXmRjbUuojAt2w+zYSh 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)(23010399003)(1800799024)(7416014)(376014)(82310400026)(5023799004)(56012099006)(11063799006)(10067099003)(921020)(6133799003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: J8zfr3R+QF39K4OCPz/kUh1qjbdk8BrgPrAZRmnbO+hfbSHvofJr1vwufLGBNcJtVj/WGwP6ImilKyMdVQNbpNBig+1onh21eyARpqwj2qIOh89iaDLq25uGHPUG3/fhNbYI/S3MIhN0rVTLrPBXmmyHt5F3WJJi4lRqldHfLFYwfwtta5W456hfXCtu2ooEyhTczPGIv1LMqHo592DwqcdndGar9ZAqpOMWYML82x2vOVd7xQ1Drzfxl3vuyOQ2MqojVihxs2nV6zLUllKglrReVsLNzcRKwKAHwixkco1WsJsbork3HXrnrWgUBEPR3dxY53ZjbSC7O0sfAtiU0Eplj/l/AqRCDREPiPVsHVKxtkMEzPzMqE4dXxg6i8k+I6+qnV1gAr11PCayy6e2F+Y+O420mPk7NSeLcxbY6QPdG8nZxBgUoL5aCfvxx1wV X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2026 22:00:35.7475 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 02e349d9-779c-4760-28d2-08df0f86f147 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: BN1PEPF0000468C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6695 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra The RMPOPT table is a per-CPU table which indicates whether 1GB regions of physical memory are entirely hypervisor-owned. 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. Normal guest events disable RMP optimizations: pages are converted from shared to private as SNP guests are launched, and large pages are split and collapsed during guest operation -- both disable the RMPOPT optimizations for the affected 1GB regions. When guests are torn down, their pages are converted back to shared, so those regions may become eligible for RMPOPT optimization again. Without some intervention, all RMP optimizations would eventually be lost, so re-optimize all of physical memory on SNP guest teardown. Perform the re-optimization after a delay, using mod_delayed_work() so that the delay timer is reset on each call. This batches multiple guest terminations into a single pass: the re-optimization runs 10 seconds after the *last* termination rather than after the first. mod_delayed_work() also re-queues work that is already in-flight, so a re-scan request during an active scan is not silently dropped. Guest teardown is currently the only event that returns guest memory to hypervisor ownership: SNP guests do not support ballooning or memory hotplug, so pages freed during a guest's lifetime remain guest-owned. It is therefore the only point at which memory becomes eligible for RMP re-optimization, which is why re-optimization is driven by guest teardown rather than by a periodic scan. Reviewed-by: Ackerley Tng Reviewed-by: Tom Lendacky Reviewed-by: Dave Hansen Signed-off-by: Ashish Kalra --- arch/x86/include/asm/sev.h | 2 ++ arch/x86/kvm/svm/sev.c | 2 ++ arch/x86/virt/svm/sev.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 5638d09b5132..3235e171647d 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/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 5705723f1f41..d8e6b8a08b79 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3032,6 +3032,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); } diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 35678b1f535d..c16f82642390 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -640,6 +640,37 @@ static void do_rmpopt_work(struct work_struct *work) on_each_cpu_mask(cpu_primary_thread_mask, rmpopt_scan_range, NULL, true); } =20 +/* + * Delay, in milliseconds, before the RMP re-optimization pass runs after = an SNP + * guest is torn down, passed as the delay to mod_delayed_work(). This co= alesces + * a burst of teardowns into a single scan and gives each guest's pages ti= me to + * be converted back to the shared, hypervisor-owned state. The 10 second= value + * is a heuristic trading re-optimization latency against scanning too eag= erly. + */ +#define RMPOPT_WORK_TIMEOUT (10 * MSEC_PER_SEC) + +/* + * Perform RMP optimizations on memory freed by terminating guests. The s= can + * is deferred, so it normally runs after sev_gmem_invalidate() has conver= ted + * this guest's pages back to shared, and picks them up then. A very large + * guest whose conversion has not finished by then is picked up by a later + * teardown's scan. + */ +void snp_rmpopt_all_physmem(void) +{ + if (!rmpopt_capable()) + return; + + guard(mutex)(&rmpopt_wq_mutex); + + if (!rmpopt_wq) + return; + + mod_delayed_work(rmpopt_wq, &rmpopt_delayed_work, + msecs_to_jiffies(RMPOPT_WORK_TIMEOUT)); +} +EXPORT_SYMBOL_FOR_MODULES(snp_rmpopt_all_physmem, "kvm-amd"); + void snp_setup_rmpopt(void) { u64 rmpopt_base; --=20 2.43.0