From nobody Fri Sep 25 04:06:50 2026 Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013003.outbound.protection.outlook.com [40.93.201.3]) (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 516D34418F2; Wed, 16 Sep 2026 19:52:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.201.3 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789588381; cv=fail; b=EiV7sHIDQ/MiCk0LIkdDDFBtNak37skkoiE89iYuJYQ8t6LHn7qBl42IkyK03WBZDXAtfTo/g7PaDCZz5cQsvcd2/HMPJuzSez4quqtWUB4MrxAOfVUvvnp2rmx9OO1mB12YJtTfo90lJYNfqA8oKnWhEMaqmDjjdTwcdMqf4GI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789588381; c=relaxed/simple; bh=9JkAwJ6pMSnB7ov8awr/g1JBp44NzTda1sHLW2w7RaU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OvWd3v/8b2878bVaUA5te5UuHAQwtczwDECl5hOFx5KutFZqfqag/CHFBK7DlNMkF/q50JLyXW5oNC1ie6qxbd0TfIjwwt0BEsR8rp5VT6a60R292pZ12Qk4KiidjO2uB1dP74Js+XFvXAqWLRi7t0CtyoPpmA8FRTpWeVk+MPg= 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=mXFwoUFH; arc=fail smtp.client-ip=40.93.201.3 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="mXFwoUFH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=m7SN9ia0+V+qbgTaYgNZWSso+IrnmZ++X3TLQdEW3iWmITMey74El377VXncxEOk6sxwmwHxK2e7z9lVNKUVBtD5J67LmfBcfY26bEAsd7d8sTnMH5BuXx9Q//5j+GAYJyEgw7tQxRVhk667xITlkOitFalK0kO2bI8YxFLAUNe6cCe6r4MXVUZW7RV8nnyTUhJ4Q26JIgiZQ52T+zXAFH3Ix1b4xIlI30zbgf48bsVtffX/jwmcepz8m/adU46R/eCvB9Sf3NG7vTHV8U5FQDa4aUY7liH2BCSGuE9vl9jX2xopon2E4c2VhUBhP0JBJRQtSYa5zAOPHS9g/9o6Vw== 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=ZLsQv7j6sKlphwBqPhpuWDAbnxXX2A4PSOvRK2iuZ8R3hXVIa47lAUn9EMbtbQLLmz2LoKtcLW6BKRLaIK7EgLinjB6/SH3+Erih7+H8CtDugSAySPPzAose4sc97KgcZpn8wOStHApiG+OXdvAtwjisjPGQ7UauBmuKsDUffCvTuUkHBVahT5nF/ngUeTyd2gFTUDXCdGwb1Dx4uE6l4tE8HNLwfOE7Sj/kofE3HJYbciDPCF2znvtZ12Sbp4MtKJvo09BoSkm8q5dDtpSw6aIHNAvw4aqopcSakfP6NKit+kp+ko9mNnO9CV+5uxUoyfuWEzoWCX3kVKBn+pDVpw== 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=mXFwoUFHTJ8WVvwTpLSlMdWz3/MFKq7YfjtpvubUFeLylwkuCZz4yNXW0A0UFZqMrbiSGo08sWItezIl3UemJ7OmDm9Y3VkTW4yHOYMUarx0Y9KRxmJhR8HerOZqxEnX6wtbDqLDj+8w7e7jwF7eZgYhIxR09r3cfDGsPwGGviM= Received: from CH0P221CA0012.NAMP221.PROD.OUTLOOK.COM (2603:10b6:610:11c::16) by CY5PR12MB6059.namprd12.prod.outlook.com (2603:10b6:930:2c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.9; Wed, 16 Sep 2026 19:52:40 +0000 Received: from CH2PEPF0000009A.namprd02.prod.outlook.com (2603:10b6:610:11c:cafe::93) by CH0P221CA0012.outlook.office365.com (2603:10b6:610:11c::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.11 via Frontend Transport; Wed, 16 Sep 2026 19:52: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 CH2PEPF0000009A.mail.protection.outlook.com (10.167.244.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Wed, 16 Sep 2026 19:52: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.49; Wed, 16 Sep 2026 14:52:38 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 1/5] x86/cpufeatures: Add X86_FEATURE_RMPOPT feature flag Date: Wed, 16 Sep 2026 19:52:28 +0000 Message-ID: <40510457d85846fd9138b622a01bebc360e4f72e.1789586444.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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009A:EE_|CY5PR12MB6059:EE_ X-MS-Office365-Filtering-Correlation-Id: 277e8553-3cdc-4f94-2580-08df142c10b0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|23010399003|82310400026|7416014|36860700016|1800799024|921020|11063799006|56012099006|6133799003|18002099003|22082099003|3023799007|10067099003; X-Microsoft-Antispam-Message-Info: WOOW7ZyuvKASUZdl/dFcQ7ZIp3n7B4kG1LumTvFwcw/bkWuhDdS3SJ4IvAUNF9/IXnDMPowXz3SNfuDiIXVoUUtjPoJUm5H/eRfMoOhzUMndsvKLCxI0VeI7725AJS9KVYl2aIZ693nb5plto9pytUcUhQuv+3AeZU4flm1MJDaZfQ7fKc4e0K11GwwH+8X5VhdjXhvk0EYQ/ysr7pqEzobd4bu9ljSu1t4NFsKrvV8oKmFlaa1i5UtsSF983rdNoU9LVJ30SbHdJBHbKIsYMIFpYQqddm6tg9PFlVVjIExmaNCPbIic5iGcykVz8C0BeI+eZHRrOJ23dJtJmwHhYp7kIJKReNfnpSYyeAJ0U0peMrzlBxZsuD6uIBraY4FXnjUjz3+bvyNJL31wGvSLG9VL0jAnrYIAMFSOAIodQ73pc8efcVE/pvblec7gtHbdm1BL0RMOvFz6hh5I9ozRwm1MWtcphRUA58fWH/+eVEqJlLWLcVf9sF9He1Ji8XoUz0amrlze9dlejJOGxSF4GTI37wYCkfgisgAR3Us2U/TFOkq9rx053YOHPCoK/u2Saqw3j+hDA0vbuVXhV0HBS7Nu1X8FTchDd/72wCuTwk2q+KHnt1g7dypcW0rW57PEt5Df6g3YAOVxmW3/X9m15tDx7+4Tp0IWDOqiv0yjekjZF+kEHyMlSfdqD6gZV33TjTgs8EtQY81e5FAUcau8rw== 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)(376014)(23010399003)(82310400026)(7416014)(36860700016)(1800799024)(921020)(11063799006)(56012099006)(6133799003)(18002099003)(22082099003)(3023799007)(10067099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GL0O4z++HH5xryTb4im7u1pgVWAmdHOeVmPPhmsGN1/gfgd5N5VVq1J25JU/DRcdbhurAKCmFRT7j7GgIqBVKdK/5QNc0tECFbAl3zAtLO3WbOIuiIZjuxuA2Mqjz1d/maVADwcoA//HALqbzGq+ls4lsnGYqRJNvv/MEl2rJpLgWGPAhk+C/pxREI1iz8bO7d4hz9+jgNTNS+bUsoTsbeZy/dQTKxJjRlLODqUCDFoyo9KAIv9kzCvqtD5IGlKbuKc1v0WG7USE2Y9oEUnJ2e0bHkuuxpb8Z02PiCXdxshjIlIHB6/f5Dgzp6tGCRKqVMzw3KaC5lXcjL3Zjv/mRAVVJY0snMxOeP3NZtfkmM44OmnwQsoaRVXBv1ttZmnHuuWNCY9Vq0lMFOkkGnUL3hVaLjrvA3JAwGXTRf5SC5D4AnKFaOcFVwroFZBEGA9C X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2026 19:52:40.0458 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 277e8553-3cdc-4f94-2580-08df142c10b0 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: CH2PEPF0000009A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6059 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 04:06:50 2026 Received: from PH8PR06CU001.outbound.protection.outlook.com (mail-westus3azon11012024.outbound.protection.outlook.com [40.107.209.24]) (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 6C0EF456E00; Wed, 16 Sep 2026 19:53:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.209.24 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789588404; cv=fail; b=MZZOcNgZYUKoB5SZg0GX7dnOPH1H3zNohHIPL1ZDzdIRKhav7GG3ia5sQV4BVzZPoNz+eKn34pJW+Gxzqjz2ZlRg2j4T3/0GpgTTULazFLr9QwXdj0TTd2ARs7sgTKQuCbNbgIbVWOw+CqwmqTprAwTAgeicw5d208mn0ihtjkI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789588404; 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=T1nVL5m9Ll2PMVIjBOfoSSBkACBZLm7Tz0fzieXsMS60zfXJcb/1VQ0G3F00pzpfhxt+tC0DdOPFbdSOCLsM0lq9zzqVq1FuHK5qtyFojWLnlN3Fh/yau7ba609K1GXCKZ5NultiDe6IeU9weiGhZWwil4uDEo3jAJAVWTTz3q8= 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=Epl6k4od; arc=fail smtp.client-ip=40.107.209.24 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="Epl6k4od" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FFrbKYaZGi8/Mx+WOEK+IKQeTxKEnEUfkMgqRDJR8NP88I5VLCMLk11kMa3C3PIos3FTnogFBUVdIpr804oMLwMBBDaa6QN12x0l5XgF3lLHRRjWDvdHzdiabLr6nMgiEqzgInvlc30QuVP6Y1hH3pQ3SxGKmnZeMZF1ZtR8UZxiXzR73CFY4IeA1KNJMXZQpHPGotKxEX/n5mb3UIs/03AYXTCVXdr4hQofGpTAC+GXNVsgAvPdV020uXThvNYj37tfWgBh3GoLXLmM8ZYUBoAWRmAPkJwwA6bWfCS9KWFmOm7Mk8X0Px8a0GDxj3M00aRf36tZUrPYvIqu5ejlxA== 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=xi/PnRzoE/Z+MAC4Z8Q4hLXR/X5k9vevDCF6Xf4pI2wevwK7n6e2uQ+TG+QncpipNN07fOifM0YKqDKz5xulZX+tO2HpYUbAFSQkRIL6076bzk0Bb0kAyFAKnVWVhk7QG7E3LuHAK7gbwCDmo5SnhsH1IhorGGzM78V2G9xgzvxX8TcUFKBxA7nuQqOObvbiH2v5JOgqpth8kghjCVcjqefb4YldYJNmgxpQXCNsxYg6KMv3Nrqe0FsKEauD21Td+rG7xt0pBbu9IyiirYiMOp/AWnhYGr4MWytUZ2x5Z260l7VVcHJevAtN3yrLY78pGabGNy+j5DKJpJiXs5enxw== 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=Epl6k4odoq4ze4rD5qw+Gxr2viuOVZSed/LbJjosQb4tF5neu8OGTRcIG3odJnDlwX/7MXZiLO41jJrR1C464qLahiYnkAgHf6+hpTZCecUCY3l4E5EdPBiUNmQueum721haO0e0ZYpBTE0h5JmMxVkkjisYCdr8CsQ0bbQAYI8= Received: from CH0PR03CA0120.namprd03.prod.outlook.com (2603:10b6:610:cd::35) by DS8PR12MB540605.namprd12.prod.outlook.com (2603:10b6:8:447::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.428.11; Wed, 16 Sep 2026 19:53:01 +0000 Received: from CH2PEPF0000009E.namprd02.prod.outlook.com (2603:10b6:610:cd:cafe::6c) by CH0PR03CA0120.outlook.office365.com (2603:10b6:610:cd::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.406.12 via Frontend Transport; Wed, 16 Sep 2026 19:53:01 +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.428.7 via Frontend Transport; Wed, 16 Sep 2026 19:53:01 +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.49; Wed, 16 Sep 2026 14:52:59 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 2/5] x86/sev: Disable CPU hotplug while SNP is active Date: Wed, 16 Sep 2026 19:52:45 +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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009E:EE_|DS8PR12MB540605:EE_ X-MS-Office365-Filtering-Correlation-Id: 1fe4e1a6-708d-44c2-6c99-08df142c1d7e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|7416014|82310400026|23010399003|36860700016|921020|6133799003|3023799007|10067099003|11063799006|56012099006|5023799004|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: eqq7ljxpv1SCieuNk6gGRZPRcqWe4Zbhs9WppdTEiCvpAODmDiags/gGqaHuJxYypH6L9UvsrDRqAyibMEnzJm4Z3KYtE6AjAyreKcC3U8sfhrz/kozjrlpmp/lij6BHrHSCTtr4H+pEbbwghSbfYXmvzLg1273CqEqzQ+DYwI5RLMq7XZbrvGP+aLFzOnaQ7kmjSOQ0QxOLVszF8qTOdzo6xG3zH7fuG43dMh9K42IVFn2f0JoGSQMcEIrXBrZz5EtBmu4UumEffwO6kfOfDaaPmb0BMubVQmGbiMt4MjIXE16vQUZqQ5cXRVQLR1EZFBrsaTrW8naqLsRZWacXY1ZTH3STHDmyWtsNNYkNp7VyEJ98PCvCdR86GmBvT8b6n0wOqO04jinw1IGVeLgwnTTpdOKZJQGWdCP3yskc7JOoICPEuISBOWI9u0MBbZUlDd4y8ZOlzHcGN6iE9LumsOUWInQk4QreT+09nObjH7yznHM3GDipHAlEb/txb/cYHwPYOxJlj//DmyIa2kU2vZcSBGTi2mzJsPUZq3cicHrmFUwvaU6dN1AomrZuiRDLHlRcICnRx1uEHKb+b9ZAgBzknfEHBynrAHFx0+/Wz2FxQ9Qn8/kHBBymrf8TPBTAdiMfKGO7L2yYWD6CsekpPMtBBQp5K66Yau3MVi4045JHHCC50Gsn1bgBfIp+hSgFJoWt/NxVYw3BJPx7HBLtvdV88gmhA26jzc1QmjpPVzotqbpMrhRFORV+Tp93NKPP 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)(376014)(1800799024)(7416014)(82310400026)(23010399003)(36860700016)(921020)(6133799003)(3023799007)(10067099003)(11063799006)(56012099006)(5023799004)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uMc91R4B+hH/UJ/tGMFnLsZyreWEx/C+5y1gZJ8HcLbPTpXAssyRnvFRqj8FfHFHSdY/mN0s9geZqbVdyZK6GkKp4CZHv1uxCHsXegxqY6ICXmMDsazx/gV3seIHmDq2i7pl/ofSHwJnqfALPL5bUQ366eM5Ubls0HzjAf3in52POhmYNoQC76n6hx91yChAsODfZ82R4RCeBTIM+E3H8ppu4jPReFk/zZ9+BEqC8DW56MDZy+Uo9VmCjU7SdB08hjtRdWDUva8TP+yPmEJn+DdlWowtB1OyzObqfJi2STeRrKQtiK6A0Ps4Wte+f+8EZiHwsYJI3HJ2gVZX2e+TfUQPhpQlOfApsr3/opVHBWsnWCkrK5obmpXir6S2AaB6SOB6u0abm3+86xd0b08OgVdpVEYvgzZcb0snKSgrB0YzXv9NmnWLdN8SqmjJomls X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2026 19:53:01.5289 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1fe4e1a6-708d-44c2-6c99-08df142c1d7e 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: DS8PR12MB540605 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 04:06:50 2026 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012039.outbound.protection.outlook.com [40.93.195.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 315CF44E643; Wed, 16 Sep 2026 19:53:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.39 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789588427; cv=fail; b=eeUmkH/ndWTNlSRS+yj3diEMJHKg3mh2yAIVGPrW5c2wBvvc9iYTOfVEuN1qn0k/5wxbvi1qXdKbtK2NM7Do0QcdbwZN+X62fNCY0ehEve4dAy2GFeI9lBymLGPhf2qF1SuUm1WWYcBQ7K2iHiruhSHsAE9XuWwY4UFWpv2tQdk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789588427; c=relaxed/simple; bh=glQ16u9TQa/gm9CQiOq7LIMZBxITzrqL0VOEqaZCjaE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rqNsKr7M+OJTrbrTpE4V8E1LETNWH8MCI9C02mtA/AnuQqJl1JazdZAMTjzN2MoMZ3sCaL2epB5I5EsVO6jtpBPLug1scOysUHoj6iZVa5nQ9HVlV7SGWUG15NJj2RddWEeGCVOE0eLREmxpkRPkVDEKsfA1M9k/GDNkklb7u50= 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=kg9RLnwj; arc=fail smtp.client-ip=40.93.195.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="kg9RLnwj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vpU+8vifJWfhojv03b5MxoL3zj8QhWdKTDRD6WoE2oAbfJ/H6kGdu5d1ogB9Z5YodsUz92ZeOaUGi6uU9KtToKFd+opH9rgtbBuj7VrAP/9WboHll93V+Af9uraYm27tzFdmHf67EzolwBCNX56PyebsaJa24dCAA8d2AMut0t0B2Qu+epY/lD3ZW+wU+Xqx+kG2NKJ9riqdfkT4Hpmdj8kEYER3WnGS7Wc0xEGqBUGf/iDnWycaCkAfMNzBJ2K0IjKuPeBWzZd7DM4aBv41VmpwZgOqmdA20mIxPlNtPM3OuHqw6zhta9aioQjnlawqXuwtbkcdeYd+SMaCT+pNEA== 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=jx9/DR6oL5c1zO/3HR+R5VGiU7auSoLdl1/baFFDETA=; b=nCu8AqdluxzPGhbUyOySqkXq3DvF8NJLGoSvQLumq4ItAAtWI8d0BxPFSylzTGW38uC9HuWHdtnsqT6jSInz9qiwDIsoa0ZJ2EueCbEr+s664NB6tkG1yyevb7eFrX+/lWDmYmPHhOMGIWdo1YmCPyZjuDLzx36azr8m5ZHEfw8/mHI0ZuCvGxjUuoWNAIroDtQEOV3gFqpznOc4dL0bKo7hhueyUZYpQ/JhlUd2iM6gX4onNhX1dfKXoEf9lJj4lNDkdxIkyC8HLJDdVhhJD/1AoV/vSNyGKIcicbCM29uzSggmWKlJx05NeDi8Bqo5BGtjso/JU9m5JZ7GsS+5Gw== 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=jx9/DR6oL5c1zO/3HR+R5VGiU7auSoLdl1/baFFDETA=; b=kg9RLnwjONT3U/Mp0urzjMEygvS3Dsejh1cPM5FRRrFiIjaOXS5kNg+FgWklzAMDYR9HWsMRBoOlIa3kR0pSnLwIHPqgPMpVJnxqUHPIoIA0MhgAxyEY1iVuncDwCbcta0HqY84mg0mE+zvZRjJBguHAG0q+NC5TYTerip1AEXc= Received: from CH0PR03CA0054.namprd03.prod.outlook.com (2603:10b6:610:b3::29) by SA5PPF8BD1FB094.namprd12.prod.outlook.com (2603:10b6:80f:fc04::8d3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Wed, 16 Sep 2026 19:53:19 +0000 Received: from CH2PEPF0000009C.namprd02.prod.outlook.com (2603:10b6:610:b3:cafe::69) by CH0PR03CA0054.outlook.office365.com (2603:10b6:610:b3::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.9 via Frontend Transport; Wed, 16 Sep 2026 19:53:18 +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.428.7 via Frontend Transport; Wed, 16 Sep 2026 19:53:18 +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.49; Wed, 16 Sep 2026 14:53:17 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 3/5] x86/sev: Initialize RMPOPT configuration MSRs Date: Wed, 16 Sep 2026 19:53:07 +0000 Message-ID: <9d57b0584549df093c5134660ee5a76f7972a1aa.1789586444.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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009C:EE_|SA5PPF8BD1FB094:EE_ X-MS-Office365-Filtering-Correlation-Id: aa627c5b-911d-4470-efd5-08df142c27c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|82310400026|1800799024|376014|36860700016|7416014|5023799004|11063799006|6133799003|56012099006|3023799007|10067099003|18002099003|22082099003|921020; X-Microsoft-Antispam-Message-Info: tW2d4jrFKNGIfER4ixP7lAKFLnqF/iyE+nP4mMbyJD31IQbNv/GYEAKZ7R0+k1IQ+YEE5IZF5Fp/gmhGtw72TwN0WWZuCeMg253H8jqBGmHeemk67EEWzXHTX6fkGwa9kabU0d7peNWfqgXhE32ca/vRdJ8HCRCLDrfZERt50fEK0ZOJ/QTk9XjBLrBbZb1WckFF4qTWuXf3e943rzSiSIjXxJysFvEkUJwM0iaviZ3ehICW5bP3MDIZSkDd3atBcp2X1dHl6AbRxc+ZunJFxX3GRrh4VKF3OJw/F+0+OYKroqJyw2KfALkHj6cBCzDP+zoHzVLKFYZBtnjwPc1X6Ut/ViPdG1DHm9j6bR/sQKKpEpxsmLEo8tDHZmPjx2CT2Bls/RBObqK3oSdsdZ0gLI6Vf70cS9c75EM3ssYROEVi/dSiLM6SBHPLV8ME8f431gU2Fcb/1ApyAFuxSjqAYl5tQTA+XbQlbzc58mPPtwD3jP4PCokAy4+MdQ5RXTSRAGSHN1qpta6up5WjJeZgRHTL8YJijqgPfi9Gsz47RvUW3hvi3R0ybQBSXijcgoREQDp1kAXWMIY93EnJBDO68mlKjbFg9+NTZWEvNiBwEJk7IJRahVcswsLAgBUv3IrDBman6Zdg8QHBf0ln4DQa/9Bwtr/RuFmXujeSeYPpC9dKMrrQreQ1de7FkMbzwRto+AB6MCSvbWdupov1B48KTFluOjt9OJxsDLkQDiWMxgGkYdfnXU2uh9HZg0fsj5Yb 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)(376014)(36860700016)(7416014)(5023799004)(11063799006)(6133799003)(56012099006)(3023799007)(10067099003)(18002099003)(22082099003)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9/9bbHHivTq0caSADZww46LS8QqkhvMxOJD8Xx/eCNSDvGuirD+h0ycuRMTnP7Nv32qamOZeFIu/6P5LcIkv7zKT9FJJ3bCOPKlADKBzVnRstHlFdFlKZafbO8/8tVGQ9SxIQ9EY/ArwFdfYZi68cExgrFLCswvUua9qLq54fYzrFHlEpwbEr9aXtD51UaoX9Djr9mvA7hQ3KKaOFlF881Bj7sKWFEp3a5QT6dHYR4eYxnUrB/A3FoXDcIRoJeg6HSp8AsDKKBu5rgDZjgGg+vUdTZ5u6UJTOv89vPDuqPQJ8uvsovG6U9XFK1ENCuzITlm0aJJm4ZxzqHelMkspFxZzNgkbrlmLQ+i/mRCWkxqwDzzaVH6YqeMmrhkUiV+1i0Hzj5CDADCIn+u0gPEPlPhxaCErDbzKqIm0q13ANUNHOvdi9yyhHxsXkBWuKQ24 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2026 19:53:18.7819 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aa627c5b-911d-4470-efd5-08df142c27c8 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: SA5PPF8BD1FB094 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. Add snp_enable_rmpopt() to program RMPOPT once SNP is enabled and initialized. Suggested-by: Thomas Lendacky Suggested-by: Dave Hansen Signed-off-by: Ashish Kalra --- Changes in v15: - Rename snp_setup_rmpopt() to snp_enable_rmpopt(). - Program each core's RMPOPT_BASE only when it is not already set. arch/x86/include/asm/msr-index.h | 3 ++ arch/x86/include/asm/sev.h | 2 ++ arch/x86/virt/svm/sev.c | 54 +++++++++++++++++++++++++++++--- drivers/crypto/ccp/sev-dev.c | 2 ++ 4 files changed, 56 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..fa81aa004e8b 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_enable_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_enable_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..f458128b9864 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,40 @@ 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); +} + +static void rmpopt_program_base(void *arg) +{ + u64 base; + + /* Only program a core whose RMPOPT_EN is not already set. */ + rdmsrq(MSR_AMD64_RMPOPT_BASE, base); + if (!(base & MSR_AMD64_RMPOPT_ENABLE)) + wrmsrq(MSR_AMD64_RMPOPT_BASE, + rmpopt_pa_start | MSR_AMD64_RMPOPT_ENABLE); +} + +void snp_enable_rmpopt(void) +{ + if (!rmpopt_capable()) + return; + + rmpopt_pa_start =3D ALIGN_DOWN(PFN_PHYS(min_low_pfn), SZ_1G); + + /* + * 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. The MSR + * can only be written after SNP is enabled, so this runs from the ccp + * SNP init path (and again on guest teardown) rather than an initcall. + */ + on_each_cpu_mask(cpu_primary_thread_mask, rmpopt_program_base, NULL, 1); +} +EXPORT_SYMBOL_FOR_MODULES(snp_enable_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 +735,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..5c996ab63895 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_enable_rmpopt(); + return 0; } =20 --=20 2.43.0 From nobody Fri Sep 25 04:06:50 2026 Received: from CY7PR03CU001.outbound.protection.outlook.com (mail-westcentralusazon11010045.outbound.protection.outlook.com [40.93.198.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D50143F4D2; Wed, 16 Sep 2026 19:53:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.198.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789588443; cv=fail; b=VErSR3fTuBZV15irkNACCHWp9U10AQdAWYPEitXER0AOM1lhb/ofN2mHwb4G/GXlzrfvYtiyUVO+aEcVe1A222/avq4Q45PGdg7wuQkMeayxuH90WBEK3U7GjuXvIuqqe/u2pNW9cWCzGXOW+ZZX35i7v5pXlJyzu4SSb3XSesw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789588443; c=relaxed/simple; bh=NDqF2mRtpmi6hJ1e88fZC4+ONzdkLLoHbg1TKS3cUN8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TeosBTeiG9M+jLFizTKuAUAoybysJ8HE3i02scWOHVcOHZdKlBp5PCsU40Uq4LjXOuQqcUY3rc4y+aR4+QUezHlNy+I9QddGSsN+RnqHq95hCCYypJzt0NmzDdxObf4c26OtaV9h3lA+/dP3jNBHqVUUv2Nied4VWn2bCv1WDXg= 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=ZxJRkWH6; arc=fail smtp.client-ip=40.93.198.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="ZxJRkWH6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=y4mWsnz6L7D8G/DqyaK/2U+LK8W8KmEBnbUZu6mayg40DJzhVeSXVk9LdiChWSf5NVSaCHfbOtTVbtMjDFmTWilEkwcSVyy2AYDJNaWIaT+KmDI9PGzUViYPtSaFc69D3FlNXVGMcumBT8050BIBpdnkk/jj5relnUTghq6sOwKmGYjDuTI++fQf0H+7bg9fJOUz5KVQyfrWwk7C0v/8zQINoxiiLxnBS4444mBVsIaNxYMCb7NITMISlYSORyPNwBJp9cYZo1tcenqUNT9MEWq6iitbSvaE0fawQOHeuA4ywFpRNAsGgxuTopeC49eXi2qSDuYKDBvr2b0VoWR2nw== 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=nP6e2ChGZEmzoc1I0PropxuzVPAcw9J692AGiObLcdg=; b=QQ6Zwr78JG6Y0QqwU2LC4zTJ+XW2L82SUk8P8FhroEQGnVSecwhGHr0VNfp2M6SLNK/PA975iuJZZlzQVKZTP0PVK6RcbrCwtAlMt0M4MYIiMGl8aiiVe7X2A2rksNCZbSPQCz7lWqqeK4DnyYJM2HrNlQD3tmS7vnixvOeGzbQYqTDKSYZJ6qyFbvPsb8mFQbb8xcPrrKpWr+Ov7FBFm5CtsbmmJQtnZBy1XmBnZYuIm83VnGrK/SO9I6CoW+3/lslPw05KcNVtDySjbQb29QwN25y2+PrYi7kvQ744ilGLtVXsPZxEtTvsGRwzsb4tJeUkFZPV9uG8WGSxqZTirQ== 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=nP6e2ChGZEmzoc1I0PropxuzVPAcw9J692AGiObLcdg=; b=ZxJRkWH6PZ6HXJsK2KaTE2wyjj9t2e9xF1k1IcnZQFk7xST1xTYDJYcN6aH3Y9v4Ew1XcW3Z9N4PF0vAqLrdE3ATgNn7gLoN72ZSF79bYKbYMH4b1AjMom4il3DDG5f3f5eevShXH8/l3s/2K7JGUQOcojWm0GK83nfRks3Pr14= Received: from CH0PR03CA0438.namprd03.prod.outlook.com (2603:10b6:610:10e::14) 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.406.12; Wed, 16 Sep 2026 19:53:40 +0000 Received: from CH2PEPF00000099.namprd02.prod.outlook.com (2603:10b6:610:10e:cafe::42) by CH0PR03CA0438.outlook.office365.com (2603:10b6:610:10e::14) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.11 via Frontend Transport; Wed, 16 Sep 2026 19:53:39 +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.428.7 via Frontend Transport; Wed, 16 Sep 2026 19:53:39 +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.49; Wed, 16 Sep 2026 14:53:37 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 4/5] x86/sev: Perform RMP optimizations asynchronously Date: Wed, 16 Sep 2026 19:53:22 +0000 Message-ID: <4d6d44f7a6483670b3f7c7362b1ea528cfbf8144.1789586444.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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000099:EE_|DM6PR12MB4355:EE_ X-MS-Office365-Filtering-Correlation-Id: 7a6ee299-97cc-4efa-aaae-08df142c33ed X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|1800799024|376014|7416014|36860700016|82310400026|10067099003|11063799006|5023799004|6133799003|3023799007|22082099003|56012099006|18002099003|921020; X-Microsoft-Antispam-Message-Info: IFDohgPvBwNcXpxYmNxWvXOTrhFiABdFjeXciAnuLlxGc17lNZkJQE/SyNOWrs2JtgbRhIB9jndkkdKO0mKSGu1SC0tdWP1z76dwC/UciHpXgss2z07mCamBkrCfPbfV4uNVvrfejUBfnr6Axo93axwIPazSV/tWadvTIL6K/Gc3u87htOubmFYLuhiQqoMnMBJHbXpARZEwb1W7xJVwu285gjsy9XjQ4YmRSNg9m+q++dT+AFP/khKHYaXao/AkC9QpSwyDnbOTERs8aymwtyPUQK3hfcAfsKq0udbm4JmhYTmws8b1/4IjV48rilglsCVql71Z9xCUtnAxJ3AENW+rxwGU2K2zCKc5k+vZeXFDidspZGSVEiOw6fqfySE/Le7WxqviaUtPUeioWyNm6CngKwx2MK5c2oDQGNOHaIOnQk/NqUA7kd9D1T0rvP3YoLUhs6EMCKO5+DwP3x52cFNgl1VPxOPdPdzGrph69MhInBJo0m9CpmZLiEdwhYSGnvB0TBT38N7E8aAoHduSE1lE/c3aecPuVpr3pG18owoayFI62VRz7vvDiBZECmk+wf2rt2y9dNhAQHriJDqpgkkGlf/2OMzEIUL5xX5qS2bj33WxrpT51eijov5Hei423ChGG2bwPOl6hzMy5P8tp8EunGqiJkadkKAVOjF6HM9bX64q9waDfRAjIQxiuzIXM9CrZz6Jq9DsK/rDh5+MDwGW7qcDUnx60RYomT6Fdtznndywbf4MgIzz3E1LHk8Q 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)(1800799024)(376014)(7416014)(36860700016)(82310400026)(10067099003)(11063799006)(5023799004)(6133799003)(3023799007)(22082099003)(56012099006)(18002099003)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YjtdWHwaT5+WQhyMPd+t+DiOxcKGhFJsnzg1xXfuh3dA9NXdnSBznKyf7z4kvS6ulrkWsUqGucm15PJXIRzgvl8zlG4M8Ujt+IUmVUAwuspWk+daDqzIoZvSWwzUX6rb5KUodwrkdy+CbNOU3SQRjMamYr6eTRSPRxLhJqUd5WlR5GcfxU+89TsfjVdkseYPUtq0lsEfpIeBNjH5+uILAtLa1QAdGH0X3XKg7fuLlNL9nRfuJq7IQnAgkP4ZPIxs0jZCVcD/gM43+Ej/14B9Nnf36cecVUCeF566HJ+KA6mt9/pi7D6csl06qV5zGk/W1OE8hXa5UmJgzpVVbhjQ9cTQJtPyGQvNYRCRo4PgsYXDpxNno2BDRJ487lDPs+GaJkz4H6BOxNbt92zZbNJtfBSPDRwxp2dV+b0AnT70PPakpWOFCvcsEYaXvgEgTOOq X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2026 19:53:39.1562 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7a6ee299-97cc-4efa-aaae-08df142c33ed 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: DM6PR12MB4355 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 per-CPU workqueue. The workqueue is allocated from an initcall, and snp_enable_rmpopt() queues the optimization pass. Shortly after SNP initialization, 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 --- Changes in v15: - Move the workqueue allocation and the (fixed) optimization range computation to an initcall; snp_enable_rmpopt() now only programs the RMPOPT_BASE MSRs and queues the optimization pass. - Gate rmpopt_capable() on a static rmpopt_enabled bool set when the workqueue is allocated, instead of an if (rmpopt_wq) check, and drop rmpopt_wq_mutex. - Queue both the initial and the teardown pass with mod_delayed_work(). arch/x86/virt/svm/sev.c | 99 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 4 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index f458128b9864..54520d4cf280 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,25 @@ 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 bool rmpopt_enabled; + +/* + * 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) =20 static LIST_HEAD(snp_leaked_pages_list); static DEFINE_SPINLOCK(snp_leaked_pages_list_lock); @@ -557,6 +576,12 @@ int snp_prepare(void) } EXPORT_SYMBOL_FOR_MODULES(snp_prepare, "ccp"); =20 +static void rmpopt_disable(void) +{ + if (rmpopt_wq) + cancel_delayed_work_sync(&rmpopt_delayed_work); +} + void snp_shutdown(void) { u64 syscfg; @@ -565,6 +590,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 @@ -580,8 +607,69 @@ EXPORT_SYMBOL_FOR_MODULES(snp_shutdown, "ccp"); static bool rmpopt_capable(void) { return cpu_feature_enabled(X86_FEATURE_RMPOPT) && - cc_platform_has(CC_ATTR_HOST_SEV_SNP); + cc_platform_has(CC_ATTR_HOST_SEV_SNP) && rmpopt_enabled; +} + +/* + * 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"); +} + +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 + * enabled, so the IRQ-disabled fan-out below only issues cache-hit RMPOP= Ts. + */ + rmpopt_scan_range(NULL); + + on_each_cpu_mask(cpu_primary_thread_mask, rmpopt_scan_range, NULL, true); +} + +static int __init rmpopt_init(void) +{ + if (!cpu_feature_enabled(X86_FEATURE_RMPOPT)) + return 0; + + rmpopt_wq =3D alloc_workqueue("rmpopt_wq", WQ_PERCPU, 1); + if (!rmpopt_wq) { + pr_err("Failed to allocate RMPOPT workqueue\n"); + return 0; + } + + INIT_DELAYED_WORK(&rmpopt_delayed_work, do_rmpopt_work); + + /* The optimization range is fixed at boot; compute it once. */ + rmpopt_pa_start =3D ALIGN_DOWN(PFN_PHYS(min_low_pfn), SZ_1G); + 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; + + rmpopt_enabled =3D true; + + return 0; } +device_initcall(rmpopt_init); =20 static void rmpopt_program_base(void *arg) { @@ -599,8 +687,6 @@ void snp_enable_rmpopt(void) if (!rmpopt_capable()) return; =20 - rmpopt_pa_start =3D ALIGN_DOWN(PFN_PHYS(min_low_pfn), SZ_1G); - /* * 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. The MSR @@ -608,6 +694,11 @@ void snp_enable_rmpopt(void) * SNP init path (and again on guest teardown) rather than an initcall. */ on_each_cpu_mask(cpu_primary_thread_mask, rmpopt_program_base, NULL, 1); + + mod_delayed_work(rmpopt_wq, &rmpopt_delayed_work, + msecs_to_jiffies(RMPOPT_WORK_TIMEOUT)); + + pr_info_once("RMPOPT optimizations enabled\n"); } EXPORT_SYMBOL_FOR_MODULES(snp_enable_rmpopt, "ccp"); =20 --=20 2.43.0 From nobody Fri Sep 25 04:06:50 2026 Received: from BN8PR05CU002.outbound.protection.outlook.com (mail-eastus2azon11011033.outbound.protection.outlook.com [52.101.57.33]) (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 8ECF2448BB5; Wed, 16 Sep 2026 19:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.57.33 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789588478; cv=fail; b=lsCqJ0zmXd135KhbpdWenayi1tmoNa4bEZL/tluHT89+iV0pJjvcDYecDfHPGZOogL4KigmsLETOOIO2tvhmrRNOsHXzzrp/S7ZkZ2jOKu7S+aWkCSKnKKnl8PndvPjqCs0EYAG7zZzkNK7WK45/p2PlaBFjs9VxTG+RbD51nAo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789588478; c=relaxed/simple; bh=6NN8vVtC81sWuzzx4naYMx8yXzF75v52ZJbCueeHTQ4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dlvC7eqqdjZAj+71sIQ/p6s3EKzteph7bgnd5gCHwFOClsi0gLdeed9qcA6UHv7b9gyC960V67b52VWZtXo2KbvfkqcyzLTb/uE7KvD0a8WwpEyVhoAq7cfu4vU6VzywNmFI0leVP/R0E+SLmGX81QCY4xXgg3n8MrB9cxHzj2s= 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=Xhp3YoXH; arc=fail smtp.client-ip=52.101.57.33 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="Xhp3YoXH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gZIc0dqEO0WbwkWo31DfQYbuL3Xh0/25Dt9hNvHdunij6orir3p3sIM59gne7IYbeCM8iVrePAdgYntviFojitdqN8BoNaqFZyaFprFShx9c8cZeG22eOlN3Hw9tyGTCp/84TqzAQimUUmkO0G422gsoBgiKSUOlZlvhq1yje18PebDeNcz/QIoBMpp5GvBjIzbuYmU5nH0nerBrMOWMv/CmdC5rX9a72FHrdgmCEDOIvF4bHAonkADaHjC3kzgqV7zkdLBsltOXDnw9BX6IqnupfHEO72ImqIS+sKI3jnEJ/7wsBg+uwf57AUFILx9+qfHxmGr3kBMkOYaagwIEdA== 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=7QiRU+QJ3rJGQlz5hLq1nFn8L9tOYZluDYEzQM9NfIw=; b=XCW3EE6RbS151ypZd7gIfrgdmHjDfe9prV3oULuG7pTXaOO0yOMvVbSniGpPkammQtyBVBZ8E1DfFCLGIOtCEpXa2+3CtdqstAXIi2BIzUOo7inJ0DKgTDz9Ta1emvNpgH4arXli0hSvumeRFRfZCtNf6o1JXY/AtoMtIauUJbFP5cqV9WQ5HALkyqwCtM0A9dIPGhtVYPLxcVqSfv6AgNXwf3JhtwRcPh3VnUEdIvYeXYP6mLLpaJPWsYU3HVxTbGNzPbgGMew+msYWG+hNqaPbR5VGPX6IruNcyjGAA7fW/vBjUA8q2sVwpEb/4tda08wMwbwdDAl7+CQaZ+pQrg== 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=7QiRU+QJ3rJGQlz5hLq1nFn8L9tOYZluDYEzQM9NfIw=; b=Xhp3YoXHiciAuJ3XjBprn2aHK0OIaimwZoNhhbWoOT3zDlJWzz+WViVf52QvTORGwdWLbQfDuD7JzaXVcifNkthjJ2f+a/12ShWGixNj+jfkeu+m/9AkHtIGbJ7GDdxpY0m2bAH/BF/vRpWuvB5IMZYje7juYmVNXnoqCEqvF40= Received: from CH2PR14CA0023.namprd14.prod.outlook.com (2603:10b6:610:60::33) by CY5PR12MB6297.namprd12.prod.outlook.com (2603:10b6:930:22::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.406.12; Wed, 16 Sep 2026 19:54:12 +0000 Received: from CH2PEPF0000009F.namprd02.prod.outlook.com (2603:10b6:610:60:cafe::57) by CH2PR14CA0023.outlook.office365.com (2603:10b6:610:60::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.428.11 via Frontend Transport; Wed, 16 Sep 2026 19:54:12 +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 CH2PEPF0000009F.mail.protection.outlook.com (10.167.244.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.428.7 via Frontend Transport; Wed, 16 Sep 2026 19:54:12 +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.49; Wed, 16 Sep 2026 14:54:10 -0500 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 5/5] x86/sev: Re-enable RMP optimizations on SNP guest shutdown Date: Wed, 16 Sep 2026 19:53:55 +0000 Message-ID: <9b4608b96d44fa256b55b6ea91603a02a7cd0a35.1789586444.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: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009F:EE_|CY5PR12MB6297:EE_ X-MS-Office365-Filtering-Correlation-Id: 3309a015-ddb9-43da-a93e-08df142c47db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|36860700016|376014|23010399003|82310400026|1800799024|921020|56012099006|11063799006|10067099003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: K/uNsTQJIB5hZWDUZYf9p/uYs/yteqLcvpAizUH01mIr2YAqKLJD6bI0aSorXNnWu9dECYJ+3RL5VqwG9wSjHIQ9THQirjLoVUrQo+y1jaqpJoTHIg/KM+ZsrQQp7vc/wVZAlVR45PpdRPlVLzVB+fyAo/+0Emjnz2vj7UB1pjWjwxWFxLMPob9yaQD8upLBh397aHPibfe796gQhRkP+NghoyOOkYWF0fjLbpW0kZvL/km3BzJcb2Oo3JXZ9cORLvfeKvuA+BgfaUhr44wktb9cTnNEvK9wCkwkpZrTO9dYCYGl/zAb7J/jrM87kH/ykumOe5ItGvAiAHMeylwtRSWeIL/HWLa3UNSaVS79pr+ivxljTODH3R9NsxNu3IZbccTVVMIzP0+JvDrOaH+PBlee53606Gz7VaxrpwaEE+0a81l6AsVo5EEcMvHlQh+trQgaAiCx2aRhFTbx4JyllMVPBW56daI7hgZev/XZAVl4ISLTYD64G8fM2ccDqb3QOSruQfwgTO4lUXO5/hNpU/cuwrEbWcO8wUFxBtP+YXINR0hh/Mt+rnqx7niPaOexXcmYc1wZcYLwUHK4pvt2Uh9+ho6Dp8HCHVfnIZoXw4FVOAUp0m63ME3pvXYaMiSuYYFQ5jbOqQHNqatu1w0JP9DoHUEfwskohuH4/auUjyxsigr70muKPR3A+nlJknvYP9L/muV0YzVz8X9jLm1oRTJjF5N5D0rfPPYyN7c1ViBFWSOyNzpER/3uq2D2NC2T 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)(7416014)(36860700016)(376014)(23010399003)(82310400026)(1800799024)(921020)(56012099006)(11063799006)(10067099003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6J1MCpofYzyH1gf23kEPUbqWLMeOAnlaAllSsYT+Rry1UfmUV+xP2iBgKSpak9INxqfZRO9zpFjlBbtU9MeNpZl5Z/AhnPPNeDh9t6eixiHJVNngkC8aM5dyWoErg5GJcI6n7ABBJU8WHOjte5JH2OYJ9u1S380TMWEmuaVYeVZFSisjlhqOcfq8nYPqmqaG6vxyaKQ1n+mwMFgWPBCJWTWjiEis0VJAJv+ytfkQ2jAZ+o7yZ0avQDutRLVHSBgBubc1qVhcVyUe1hcXQ9WXhzuYwUYFQwKdM9NIQc442Qcqjtf79uC85dW9Gmn+QoefDhzGCE0R00tIkUTx/2wj9ZD151V4uWQrTnARDq1SeT/Cn2c5pLag3tV7bBuUPlyAuJc6fsO3cUAhwQDERXf7rq8KFYthSOQIk2kTBefjHuI5x50CcJpihOesLbjKbLUz X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2026 19:54:12.6049 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3309a015-ddb9-43da-a93e-08df142c47db 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: CH2PEPF0000009F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6297 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 by calling snp_enable_rmpopt(). snp_enable_rmpopt() performs 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 --- Changes in v15: - Call snp_enable_rmpopt() on guest teardown instead of a separate snp_rmpopt_all_physmem(); the delayed re-optimization now lives in snp_enable_rmpopt(). arch/x86/kvm/svm/sev.c | 2 ++ arch/x86/virt/svm/sev.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 5705723f1f41..4d5e30af1ade 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_enable_rmpopt(); } else { sev_unbind_asid(kvm, sev->handle); } diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 54520d4cf280..0f000cc89573 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -700,7 +700,7 @@ void snp_enable_rmpopt(void) =20 pr_info_once("RMPOPT optimizations enabled\n"); } -EXPORT_SYMBOL_FOR_MODULES(snp_enable_rmpopt, "ccp"); +EXPORT_SYMBOL_FOR_MODULES(snp_enable_rmpopt, "ccp,kvm-amd"); =20 /* * Do the necessary preparations which are verified by the firmware as --=20 2.43.0