From nobody Tue Mar 3 03:20:26 2026 Received: from DM5PR21CU001.outbound.protection.outlook.com (mail-centralusazon11011065.outbound.protection.outlook.com [52.101.62.65]) (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 5FCA2332914; Mon, 2 Mar 2026 21:35:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.62.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487339; cv=fail; b=f91B3T48JUMDPsuST0rmK0WUXAIoF8Fc3UTP8HbeRWdTqpW9LET6/HS72TAndEXJo+KSP04Xi240dH2n08xXEdCLMMJcC/exB7Tm4UXXgDYGdiD0v/dxNKCKex1iHZWtkxaazyD82mHCjgXnYPvoJSsaOQPIp1c9yVbreTAJeLs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487339; c=relaxed/simple; bh=zKj5G2hOoAJdDqX0V21QZ7oTPKuHy7FMONC77bYASwo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RGkPONtuleMMolYabXp7kh90ed5/Ixnqst5qdxV7Hmoy/EopoFngVcvQ0Lm3mGNf3kSFNIhCWgvSd0CGShuK2D/4NgteOniVgv9MN0MYguKTPOQX6HS0DV+9pV7HNKZOXp4JC2rvIjtaMzoSO3gxf+EprMGpz3E6mtfEpgnJWQI= 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=qfuU1v5i; arc=fail smtp.client-ip=52.101.62.65 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="qfuU1v5i" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ct/fSZnDSG8UvoElijrcuL/SjEg5ZbwBBoTN6IKQhagBGFC2Bhc25VKh0M25AlDC4nL16s+Wln62MBHMu28VhngyiaYdlnSJrPcMGDW4LHyvPE/MWLj+meR30AAckBbjItJo2GfTYrGJge8KyItz7pme1/cnuBL05RDKGV5103Z/VsqSs2/SQO8lElivQ7XXtz95Z4wA86PdUJYQ1PYGlxkbmp1LbA2KpqpL1yEUR9V7z/7jZKcG5JPmJlK/4Igka0dcXXyS8AhxM2C9G2//zCsNF68h5yNKv85DU7I+7Q1xlsDSP3mWxv11p6njsC+AtTNrhJLrpF1h2VopNz+OZA== 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=XydoCYoemEl9gDBl9i2Gi7y4JpGrh7eKpNR8+W0zg1g=; b=b6ukVZnYf7Thl/3t9btjC528LotDhmVOYkjunX+jejHbJ5CeKCG9vaUzaRkNq5QMqVByHhWVw+CT+2Pl2AmjqkPk/r896u0CzBUT2aLgkJ6UjpCNpxt0jx+e2x05f6AkiEq6B05m9UZRFLujzjPhA9IC1VHIIBcBxgEOLxYiqpb6wxt9b822fdD9RFkAXZcx0vKOnz1Zi6kRNInBpWSpFvfmo3hz869fSrW5G1EU9U0WqMMlPhaKwoJP3pafRPErS074VSEWrmhOuqy/w4VVE58+i5zOQ0FrGdEgizVyMjwAJ3Z8nLy68XQC291vT/ceilO7OBnug129NkfCZRAZ3w== 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=XydoCYoemEl9gDBl9i2Gi7y4JpGrh7eKpNR8+W0zg1g=; b=qfuU1v5icoQWrcmWo3cXhKZEnrPlr8t1hr3QKq69LvuCG8t1CFpWnJtJQDpV7I+t5V+e6euePu299QGZIFhDUMoKRO9n0+myIlAaRvKOaYmfPx5GeexDq0Ocx6ITnS96eohwZDxRR5kd3SC0zK7wCq4vgpvFAHTE/082F/kWnO8= Received: from CH0PR07CA0004.namprd07.prod.outlook.com (2603:10b6:610:32::9) by SJ0PR12MB6879.namprd12.prod.outlook.com (2603:10b6:a03:484::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.14; Mon, 2 Mar 2026 21:35:31 +0000 Received: from DS2PEPF000061C5.namprd02.prod.outlook.com (2603:10b6:610:32:cafe::cf) by CH0PR07CA0004.outlook.office365.com (2603:10b6:610:32::9) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9654.21 via Frontend Transport; Mon, 2 Mar 2026 21:35:21 +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 DS2PEPF000061C5.mail.protection.outlook.com (10.167.23.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.16 via Frontend Transport; Mon, 2 Mar 2026 21:35:30 +0000 Received: from nigeria-2635-os.aus-spse (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.17; Mon, 2 Mar 2026 15:35:28 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 1/7] x86/cpufeatures: Add X86_FEATURE_AMD_RMPOPT feature flag Date: Mon, 2 Mar 2026 21:35:19 +0000 Message-ID: <219ebbd57ac1d99fc5ea055431f7a8396021c2c2.1772486459.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: DS2PEPF000061C5:EE_|SJ0PR12MB6879:EE_ X-MS-Office365-Filtering-Correlation-Id: d943c38e-343d-4cfa-fa05-08de78a3a0e2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|36860700013|1800799024|921020; X-Microsoft-Antispam-Message-Info: hJjBnSCvQjJFRaqiu7gkdST7cee4Eu7eBJ3BPUq++3qBCtcDqBVnXmoEREbA4xqYSjt24UnydWOB/fPmFsoQTYJ2t0bMjQ17nol9sYECl0B30/0EOPUUXBQyhSy/v1VHmYSSMVTJAm82TDxVNlLipZtTn2+AXv0548KARjuIjuXfRXq7rQuh7HdwCNrdje5FJ0Wme3m3XN8pBB4tr7D7vLVEniWKRT2rY+anpa1+LB5KhZEprPBfc2c5UimCGik62LCtr/J1RJnFsuoeeJlGTiNeQ35xbIsRD/jhZeXXNroNeCMt/7+aFhPYAFTpHJl5Q1y2yigp8xUxI16t/tuxTzHpsflZuy1B74wFJuPhbhoejhDm4Rmp8L6llrSElM1V7CRONMy9dVsaPQASqp5hH8ffKaLkY15MdwbrvOaN68VYQc8N7pzKDFMgqmBAhAnyu609Ru3Q/wwCyn7zdklmOAsYFMFcDojLJXqRpXCjxky1JsLSepHc4WcYbUCK04mkLyMUFybI6MXCKKxxCVAh1zTDn7zPcMafE0dpAUekOL6von2EA0zoSjl6tMVONLMv8gZRNvgNCdQiDxqQtHF5XsmvDrbv8fJQ+IYAcnOmHwXdbxx200TOJ+dBWd+1TvCE7BS8RUjuMaTL20TCsQhgvV3tV18DdmKzw6jyHAsVu9N8G8QXpy3L9zqblmHywEekJZhXPLyzia12nXWMGLZv/omXll7Y7/I0IhTjU27g0o1y3gGI1+16jD9rf+AMF4UY1T/I9XMg0rIy1BuZQp4cnqZjbJwuoxaRSRidaoE0n2WeJtGCqg5uZDga9sZVnsJgjeI52aVj/F17IvhBhB5aOW8o8CvZ1/lFzGdiXJR8QfA= 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)(7416014)(82310400026)(36860700013)(1800799024)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tXIblL0+GtGwaOFC1/dFDcM5JrDdBXuBPelVcl4naLHwnUoa5SeN6emYYw9YMIAEe6LczOCPm5fi6fpznst6yRM5rMuwiIf6jVG2T1TG/AkAuRZw+t6T8zs2/KYjjPE8qGq8Vm+6pruZmjpJEP9iu4pLV9urbN8K8SI8D1zsKqMApKvjF2njZl3UpNL5SLPh8WKSqWCGm4nwkE1CLRBhB7Zi6bRCgBXVbUPvEiOjDmRqhedersF6vdQBJbWe3QWWmDXetvURqbXUCMemtWXwEfuHRKokHQkyFmTT7cVaYcqT518wNMKX0lF5TLtPHkuQNZTp5kH9eNwAk5WFwLbRmEahBpuGxuWikJxGPgncOifUi0JjZWj0JUW6FSzquFmHlI6pmtkntZ624XDScopUMg+wQAkO3c8jFm0f9ME+Lyytg/rSFKvqBgqYrrn11vXP X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2026 21:35:30.6640 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d943c38e-343d-4cfa-fa05-08de78a3a0e2 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: DS2PEPF000061C5.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6879 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Add a flag indicating whether RMPOPT instruction is supported. RMPOPT is a new instruction designed to minimize the performance overhead of RMP checks on the hypervisor and on non-SNP guests by allowing RMP checks to be skipped when 1G regions of memory are known not to contain any SEV-SNP guest memory. For more information on the RMPOPT instruction, see the AMD64 RMPOPT technical documentation. [1] Link: https://docs.amd.com/v/u/en-US/69201_1.00_AMD64_RMPOPT_PUB [1] Signed-off-by: Ashish Kalra Reviewed-by: Dave Hansen --- 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 dbe104df339b..bce1b2e2a35c 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -76,7 +76,7 @@ #define X86_FEATURE_K8 ( 3*32+ 4) /* Opteron, Athlon64 */ #define X86_FEATURE_ZEN5 ( 3*32+ 5) /* CPU based on Zen5 microarchitectur= e */ #define X86_FEATURE_ZEN6 ( 3*32+ 6) /* CPU based on Zen6 microarchitectur= e */ -/* Free ( 3*32+ 7) */ +#define X86_FEATURE_RMPOPT ( 3*32+ 7) /* Support for AMD RMPOPT instructi= on */ #define X86_FEATURE_CONSTANT_TSC ( 3*32+ 8) /* "constant_tsc" TSC ticks at= a constant rate */ #define X86_FEATURE_UP ( 3*32+ 9) /* "up" SMP kernel running on UP */ #define X86_FEATURE_ART ( 3*32+10) /* "art" Always running timer (ART) */ diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattere= d.c index 42c7eac0c387..7ac3818c4502 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -65,6 +65,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 Tue Mar 3 03:20:26 2026 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010061.outbound.protection.outlook.com [52.101.56.61]) (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 10F28375F6A; Mon, 2 Mar 2026 21:36:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.56.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487373; cv=fail; b=QQYptagqHQhtAk31Fw/LMY9z80PWSWlCtzafdtXt4dKtGmgwHuUGffnMpoF2nTdTAuDsvoa5YcAoY3ootq0cYc30krVS6Z0gCTtxeAqeTQ4BJpSq4klTCdm00QRczDfqJ+wVStEt7Ro+T6R7uhqtsr76YoBqjU7Eq8t6MMNetys= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487373; c=relaxed/simple; bh=er4KRPhms6RqX5CqXaT2huWFVD/zdl35dFo7PtsT/H4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e1l5alOxW951Qg+oeaZazlvcNgkoWow/VE5pjLk3eO7erNG16BW5T5uJpfDVdUXryYz7I8uZFlOa8Kj3aRD8fPT/lxVH2QLIYkzzsXX8epcbjg3tRLoraPDzfeKq9uG7ZAbBG/yQ+ZVBwC9Jf5/t/jWt49qzgMKyWiFx75hd/Is= 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=vfe0Gi/g; arc=fail smtp.client-ip=52.101.56.61 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="vfe0Gi/g" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cux1T/6BdA6rLLoZtpZdWS06NL0QrmQ5M2M3XzmSIlEZoUxOItVSzUfWSMNBW22XKqIseMRTZUgQrQP3RbpwSCOAutTTZE2L8liRcpLtlWIEMf/hVIpvN1VB/+1jtu2a0+uG5agHv6gAJ2eXQTtMSBnhxGjYYqmL/xCGAs5Z9FiLsqaTbyvg76LCu/xmAEs0YDoTwhd3Lcma97SL5HbTx22lyQRRHA2CM1BdAOvREdGGKIizVnyZdNr7iWDLrMfoXApVaifBsKU+G6Y+/GormsJeHyGYQdlnIMxm44/32DXiPr6SL1vA4Wg815Qwz9PvbYLTE007DdHEf8aciev6JA== 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=avIsBUyY64HPtimPp9C3pK2itMUsZgyj9uEkaruMF3U=; b=KFa/MXYsZa6fqXm3uP9lj4oIriw1T7pCN1j0D30Q+9ixFSDCF+DDz2ZQnztWO198tvKsADJXKz3T7kNAauwWuAqEOR7+kJ0R52UZhlV/tpGgvDqH3Z4oclCgxa0yr1BjPoIo54J80JziC9ep8Jo/kPw2wD/v+IYguI0pgaLr34eP45RzPeo10bIiNK1eb6hV/7y9+q20Rx9lxPr8uvz6GUSF4fp6bm2yl2ZSrO6b2GqrFyd/yEEACQXLKqbfXZsx4RDwKAkrPbJdSomov03MJFXiCEjRsbjYvHgLCDabWJccq7hm/SRbGswhOzz3f6fCOCpOAcymCMy5OUjjCo29Dw== 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=avIsBUyY64HPtimPp9C3pK2itMUsZgyj9uEkaruMF3U=; b=vfe0Gi/g13MapBZ5geSzfxyD6RtdsqTiyvnsKgaZLOjsSsJxjJU9/i9PYA8IxdIbc7cxW57Jxqa376UVyrIPfRJ4bf1zNIYnAkGzauTTOXZVGphMWwFlDMrHJVHpyiz976t69hJ9aaoKmLTEv0NvEomqYa/Jf42Huxfw3Qu/bU0= Received: from DS7PR06CA0020.namprd06.prod.outlook.com (2603:10b6:8:2a::21) by LV8PR12MB9450.namprd12.prod.outlook.com (2603:10b6:408:202::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.21; Mon, 2 Mar 2026 21:36:07 +0000 Received: from DS2PEPF000061C8.namprd02.prod.outlook.com (2603:10b6:8:2a:cafe::d5) by DS7PR06CA0020.outlook.office365.com (2603:10b6:8:2a::21) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9654.21 via Frontend Transport; Mon, 2 Mar 2026 21:36:04 +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 DS2PEPF000061C8.mail.protection.outlook.com (10.167.23.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.16 via Frontend Transport; Mon, 2 Mar 2026 21:36:06 +0000 Received: from nigeria-2635-os.aus-spse (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.17; Mon, 2 Mar 2026 15:36:05 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 2/7] x86/sev: add support for enabling RMPOPT Date: Mon, 2 Mar 2026 21:35:55 +0000 Message-ID: <85aec55af41957678d214e9629eb6249b064fa87.1772486459.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: DS2PEPF000061C8:EE_|LV8PR12MB9450:EE_ X-MS-Office365-Filtering-Correlation-Id: d0e15add-c4c2-43dd-17ca-08de78a3b678 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|376014|1800799024|82310400026|921020; X-Microsoft-Antispam-Message-Info: YjFBQTWu+3ROJ+kZdk2qFEeOhY+7TfQJMmbdmesHs5pS+1o7I4aWJ9L41IucVC88GKpP0p9YCH3TMcd9Q1Yk8TBCfD1g8EItDxwfuMFltf8qBESsyhAEwTy4G8l7L5V5o/EupFvRQVEd3Ue17+Olspzb+TIniZpeLQKvCKFfNwdTcNNkjOijsaALKiq/fcizLmKVvuKju9TYYxUTQ94TwaswMt9vRscPONrnP9YesRAv6gp6kv5UJcM86Z8kxJH7GNg+pvB7niz0FIQrcefBKRzaYe7R9W5/qDMolBnQk/nXvLrJzND62ybaOuxQQD+euHeEeemM/UmtphnsTgzJBLz6saspuoIOaH8COwc4nHx4EUJlvTTtFoQuRHf+NdEsLDsoL5tLpjEDVnm8AlchI/NlvU/5Qslnar5Z7WZFBdStN5zuiQqW2LhERm2NYFNOwjrgLXdJnVGhGGCj1NOHWqfRsBJLogOePYFw1jzfKtM3QXTzy8++Hn8Hg1x0xVp+aiIJWf6NfiFlrLyZNrsuNqfJe0CTAmmOMVUFykeIVRy8qi0b7RaPPBG7f20qNvNiThaqTFqXZc+Qv2Xy2aloR69zA9aNF+i55cEid3Sy1cqTlDRow0/YNltpMi/KU4o16jSIh7NJJh/hNjFx83ZY59QDHKFwXWLJ1dR1U5G5gGqYbhQvuy961af3xERNxmlQOP0np1keMsfDUiaqrteMvjPM2rE+0C1aBIp0LAXpTkgbHsS27oT+/mBDe7GITsfQYjz7FBMJm8yQWPvondAp2JobTMp8aA6uDIWM1MtVtPIkgmU6BK+dnc3I+aFLb+XfXdGU6paF3bxAHtqidUE5eKBwvkTE3XIPZ7+WOpJ33sI= 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)(36860700013)(7416014)(376014)(1800799024)(82310400026)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 38iNQi8vN32J3QE8EAskZlRimRQM123aKKcG9UmaiQlah3z6PbYeA/9XnJc2pGe3KEVrkpuVn9WLd1/TXbSkdml4xGztDeeTc6deirOGXZ4ZxfwtJweVnQQuB1PdivhgQbMUmTAhv1Njvu/0zpx85FJ3jWyw0IJFbCkOTZKkY6AaY/hJiKrf43M42Deea7M48iX6BIGZ1qjrVhSmLFeeiZYPfW+MEooLsU0uLHxp9VtFhd3jxm6RLhjQvxO+7fgQZTKHgXHunqksUcmpO877eHDxcNS5MZDjMNYuKoRdp8PWmgUA12XpGZLirgDaR3HrVLGnLCOjIjiE6rpXkQfxVzMMCfnXdw3x/GM6GRjAn3aT1YXOyozMwpXZ0jYvNU+hjgxnWex6/sBMLkviEIFvLjzsM0ehtnzTtO5Xks5RMDi53JxmVbuP48Q2hailfpii X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2026 21:36:06.8841 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d0e15add-c4c2-43dd-17ca-08de78a3b678 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: DS2PEPF000061C8.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9450 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra The new RMPOPT instruction sets bits in a per-CPU RMPOPT table, which indicates whether specific 1GB physical memory regions contain SEV-SNP guest memory. 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. Suggested-by: Thomas Lendacky Signed-off-by: Ashish Kalra --- arch/x86/include/asm/msr-index.h | 3 +++ arch/x86/virt/svm/sev.c | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-in= dex.h index da5275d8eda6..8e7da03abd5b 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -753,6 +753,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/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index a4f3a364fb65..405199c2f563 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -500,6 +500,41 @@ static bool __init setup_rmptable(void) } } =20 +static void __configure_rmpopt(void *val) +{ + u64 rmpopt_base =3D ((u64)val & PUD_MASK) | MSR_AMD64_RMPOPT_ENABLE; + + wrmsrq(MSR_AMD64_RMPOPT_BASE, rmpopt_base); +} + +static __init void configure_and_enable_rmpopt(void) +{ + phys_addr_t pa_start =3D ALIGN_DOWN(PFN_PHYS(min_low_pfn), PUD_SIZE); + + if (!cpu_feature_enabled(X86_FEATURE_RMPOPT)) { + pr_debug("RMPOPT not supported on this platform\n"); + return; + } + + if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) { + pr_debug("RMPOPT optimizations not enabled as SNP support is not enabled= \n"); + return; + } + + if (!(rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED)) { + pr_info("RMPOPT optimizations not enabled, segmented RMP required\n"); + return; + } + + /* + * Per-CPU RMPOPT tables support at most 2 TB of addressable memory for R= MP optimizations. + * + * Set per-core RMPOPT base to min_low_pfn to enable RMP optimization for + * up to 2TB of system RAM on all CPUs. + */ + on_each_cpu_mask(cpu_online_mask, __configure_rmpopt, (void *)pa_start, t= rue); +} + /* * Do the necessary preparations which are verified by the firmware as * described in the SNP_INIT_EX firmware command description in the SNP @@ -555,6 +590,8 @@ int __init snp_rmptable_init(void) skip_enable: cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/rmptable_init:online", __snp_= enable, NULL); =20 + configure_and_enable_rmpopt(); + /* * 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 Tue Mar 3 03:20:26 2026 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011036.outbound.protection.outlook.com [52.101.52.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 89FCC37E684; Mon, 2 Mar 2026 21:36:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487387; cv=fail; b=I1DzknJD7b1KCtqyW+HJAEs4yoAuENym5SPxwJs4Kj0X5Dq95RXvwBimknQl0cXdx0DW67SXt0zy/w7zx5b+Q0AMsdrgRYLsYKFBX/reGxjEDw+LOd5FCnxnb2spozAg31ZsNEZQq7F5ZZL7+WLwOsmvgXSZiInudShT/xd06OU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487387; c=relaxed/simple; bh=A5nTh1Q/yeTIiuuOA9ZRPWr3xQg3fDcq++7/5lSOoFY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=X5PUym2qJt0ClbNQ7v1S2Ua6RM4eiBnbLVyGpOP55q9McL061plMTnB3SN0E54UDurJfHk08Vs+TIYwvh/wLLaEqLacn6RKAB01ipBSdfXbxLP27WDEAn5FUPLgsJUfcNt6HCGhjJpvvaAv/Nno3x9dhgrs8h8pLQgKwgGO7jkA= 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=nsvID/HS; arc=fail smtp.client-ip=52.101.52.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="nsvID/HS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aKZpokdbEj5sE6yPX+tbxExS0sh6cLmCQdJafD1RtUC2utnMWBnPlY8mbLmIkkqDNGzH1x3gQXcbY4uvnYEDDM1SGLVaU0RIN0o6q3iWKd0ub9ADrxulGZyS3q69H/JlXkgEG1OmEO7gYsHgj8E77daFPJ2Xs5xCJsuoE1BqLVk/AVHotF1Bo3km7tMzIAXmMBX/+HJTZ+JJUkfSaK2iyj9cSkC2tW4Bsf/wjyzm13GjK+cE41rlwVd34E1lvTpMVH2mkPKctoMcDPBd2Px58E6BQoEhrQ2h1cwUeq+dswkjEKWeDzlnf2Hpb0upsKTWBRLfFNO4Ls+iZsInP8OQbw== 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=kdmp5XSUVMo03xR1wll8PiZ3Uq755AHE5wtx2cyGIpc=; b=CTh4C8Vi9FnIi1oxbVvuED3Kkdvj9BUsfO3tw5UbDsUydXA6gPYOThay7zTQHwaOCJ4hiL1aSn2Ggur+Ig3kz0nZY9ywlWoiN3QqPGhDNYwFtM19rjDKj+qjcLDFrMzlkvhCG2muE2Wy7fmaOriAyCEqEIFZWJRSVvMRxTNSrHqDo/QjMI9dy2M7TTpO1kb2FIahfrt94u+r5oGbCZ/qpy3ZIb5uc8TA/JmcwanxsY0tV8XlEkXF+vViaKYQCj6mvYTtmi4aH7Wiwwwhvv49XoL4oPHeD/1LxIxfYYMbWO4f4yhW9xrOz2gLullhOm9oNOWNDuKSKscE946aJhVStg== 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=kdmp5XSUVMo03xR1wll8PiZ3Uq755AHE5wtx2cyGIpc=; b=nsvID/HSrnAINQRLUef749nySlrQcfC0ZrcQWdwdn2RTUXRBgv8vgFUVXMEWNHEp6GnUEyjXm7ZKaSqG1J/KVBZ0mVqZFHzo4E38LH5w+Bpwg47Iu681IjQLWMPaKj6EITLhZXJwZ0vRkvoj3COvchKmX4XMZsXXQfEt10lEwMs= Received: from DM6PR08CA0060.namprd08.prod.outlook.com (2603:10b6:5:1e0::34) by LV8PR12MB9182.namprd12.prod.outlook.com (2603:10b6:408:192::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.16; Mon, 2 Mar 2026 21:36:22 +0000 Received: from DS2PEPF000061C7.namprd02.prod.outlook.com (2603:10b6:5:1e0:cafe::b0) by DM6PR08CA0060.outlook.office365.com (2603:10b6:5:1e0::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9654.21 via Frontend Transport; Mon, 2 Mar 2026 21:36:19 +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 DS2PEPF000061C7.mail.protection.outlook.com (10.167.23.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.16 via Frontend Transport; Mon, 2 Mar 2026 21:36:22 +0000 Received: from nigeria-2635-os.aus-spse (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.17; Mon, 2 Mar 2026 15:36:20 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 3/7] x86/sev: add support for RMPOPT instruction Date: Mon, 2 Mar 2026 21:36:11 +0000 Message-ID: <8dc0198f1261f5ae4b16388fc1ffad5ddb3895f9.1772486459.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: DS2PEPF000061C7:EE_|LV8PR12MB9182:EE_ X-MS-Office365-Filtering-Correlation-Id: 02616f90-413f-47b6-4de0-08de78a3bfaf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|82310400026|36860700013|921020; X-Microsoft-Antispam-Message-Info: rMY50e3wsUZ9FD9TgXPduSvOetTA2oRpJ9IKsKHVnNZbUZgAEdj9fRuKzkRLrryTem4owpOqRr3cv/X/AXp9P/mG1/S0097aUbnSKZFrBZYIGJAQy1C40Xg4mN7QzF3EzVF7ItXmkYCA23WvKkkuFWemsL5fd236owLXf+vaVlqiCumTeELCojDn78hdXxkeUIRb7+gCvDU7JH9Xx1KRydrKjDzF7K6dRNDnHxRq++pKidKMgQBpVbICdkPjJuOI7jlpwp0YZlPrbIhCtYvlwT3IHAbjXGWiDzTgstUcH1rOBDFbFVNCEZcTXYFZwXW1olnWIF3mRarze6RR272ObauPLafgWHcoirGBoL4QD1E4Xhz5tBhEG3uoSfRwNU8+vNb1J9k8UtrAKWqBtdJSDmJ6UBdu3od3+zyCumFAw2/DIfW1/Nm0IouT1CaYwNnb5muuGQ+P//0EYE9XDelBvjoObzy82r/kMpGHUwVRTIpcP9hGR+dIbfl9xOsHuqNrkfa7n8BsrXdCBSntUpOufb1gcaOCrW5m843zbsQT6u5sUJrLxXaeOCuJGdisO6eOEEWJSYbs8CmUBGnolX+AwZz8uAyJhLvZST/2bVgjf0qFAppT6oTXDOKHo70zkMJPZhQaHsEiU4+WVfSs3Ae5OtlJtMB39L6ZtTvrDamCXytZ/uEB5Ud8CA+p2rhpWVAthpeGuyI0383NSTyFlQZpAovGwYJaZZzq/ZOKauB2XiD5ppvzv2gqjB6cr7pMW3C2skvISr7V2BSQDXuCBdCqsiy08LGUuwMjAWkdi9U4BuzBkhtqi14f5CvWDsSzvrea/rJUlY0sSW/sTRHqyhjoZAq+urAHzhtIduzTImuY6+o= 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)(376014)(7416014)(82310400026)(36860700013)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2X555NIb0NbjhzZc72vq03z92yMVXKqHZ0eqXGMix81D0yZlZ/rC1ZgoAck6jSZpbsRbp+tYai7KlCqiFwCfXkNlrqSud6/r/F5xwn15jBpLtZd77vKxXOHubNlvPIbF3H0huUfVVto8IcowR7mfCoqhi6RpzHiYZryf99qbWMln70eCZnY6ynGR7n4pg+c/vYhDArdeKWkavi+d8+qzn35zzLCUt/0PqdLOyI2x3j/xLMzWZ1PTTQ2v3yujKajgLPxz/I2VDHdoPACrQdVzTRcC/oDTwnAVQalgWKhaOQDId0uLD6hgBBakbfHE9bhgQAwwzHBplSrnKZlayVrfP7JHRUjtPZVt13niXdVjyy5cGtRUaephkUWYYiXMztE2gDUE2B54Qeo7Emfaa9JKq5ACED/tB7uSrFqpB2FYSR9rQv+/LxP71D1dCqWaYVA8 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2026 21:36:22.3290 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 02616f90-413f-47b6-4de0-08de78a3bfaf 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: DS2PEPF000061C7.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9182 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra As SEV-SNP is enabled by default on boot when an RMP table is allocated by BIOS, the hypervisor and non-SNP guests are subject to RMP write checks to provide integrity of SNP guest memory. RMPOPT is a new instruction that minimizes the performance overhead of RMP checks on the hypervisor and on non-SNP guests by allowing RMP checks to be skipped for 1GB regions of memory that are known not to contain any SEV-SNP guest memory. Enable RMPOPT optimizations globally for all system RAM at RMP initialization time. RMP checks can initially be skipped for 1GB memory ranges that do not contain SEV-SNP guest memory (excluding preassigned pages such as the RMP table and firmware pages). As SNP guests are launched, RMPUPDATE will disable the corresponding RMPOPT optimizations. Suggested-by: Thomas Lendacky Signed-off-by: Ashish Kalra --- arch/x86/virt/svm/sev.c | 78 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 405199c2f563..c99270dfe3b3 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 @@ -122,6 +123,13 @@ static u64 rmp_cfg; =20 static u64 probed_rmp_base, probed_rmp_size; =20 +enum rmpopt_function { + RMPOPT_FUNC_VERIFY_AND_REPORT_STATUS, + RMPOPT_FUNC_REPORT_STATUS +}; + +static struct task_struct *rmpopt_task; + static LIST_HEAD(snp_leaked_pages_list); static DEFINE_SPINLOCK(snp_leaked_pages_list_lock); =20 @@ -500,6 +508,61 @@ static bool __init setup_rmptable(void) } } =20 +/* + * 'val' is a system physical address aligned to 1GB OR'ed with + * a function selection. Currently supported functions are 0 + * (verify and report status) and 1 (report status). + */ +static void rmpopt(void *val) +{ + asm volatile(".byte 0xf2, 0x0f, 0x01, 0xfc" + : : "a" ((u64)val & PUD_MASK), "c" ((u64)val & 0x1) + : "memory", "cc"); +} + +static int rmpopt_kthread(void *__unused) +{ + phys_addr_t pa_start, pa_end; + + pa_start =3D ALIGN_DOWN(PFN_PHYS(min_low_pfn), PUD_SIZE); + pa_end =3D ALIGN(PFN_PHYS(max_pfn), PUD_SIZE); + + /* Limit memory scanning to the first 2 TB of RAM */ + pa_end =3D (pa_end - pa_start) <=3D SZ_2T ? pa_end : pa_start + SZ_2T; + + while (!kthread_should_stop()) { + phys_addr_t pa; + + pr_info("RMP optimizations enabled on physical address range @1GB alignm= ent [0x%016llx - 0x%016llx]\n", + pa_start, pa_end); + + /* + * RMPOPT optimizations skip RMP checks at 1GB granularity if this range= of + * memory does not contain any SNP guest memory. + */ + for (pa =3D pa_start; pa < pa_end; pa +=3D PUD_SIZE) { + /* Bit zero passes the function to the RMPOPT instruction. */ + on_each_cpu_mask(cpu_online_mask, rmpopt, + (void *)(pa | RMPOPT_FUNC_VERIFY_AND_REPORT_STATUS), + true); + + /* Give a chance for other threads to run */ + cond_resched(); + } + + set_current_state(TASK_INTERRUPTIBLE); + schedule(); + } + + return 0; +} + +static void rmpopt_all_physmem(void) +{ + if (rmpopt_task) + wake_up_process(rmpopt_task); +} + static void __configure_rmpopt(void *val) { u64 rmpopt_base =3D ((u64)val & PUD_MASK) | MSR_AMD64_RMPOPT_ENABLE; @@ -533,6 +596,21 @@ static __init void configure_and_enable_rmpopt(void) * up to 2TB of system RAM on all CPUs. */ on_each_cpu_mask(cpu_online_mask, __configure_rmpopt, (void *)pa_start, t= rue); + + rmpopt_task =3D kthread_create(rmpopt_kthread, NULL, "rmpopt_kthread"); + if (IS_ERR(rmpopt_task)) { + pr_warn("Unable to start RMPOPT kernel thread\n"); + rmpopt_task =3D NULL; + return; + } + + pr_info("RMPOPT worker thread created with PID %d\n", task_pid_nr(rmpopt_= task)); + + /* + * Once all per-CPU RMPOPT tables have been configured, enable RMPOPT + * optimizations on all physical memory. + */ + rmpopt_all_physmem(); } =20 /* --=20 2.43.0 From nobody Tue Mar 3 03:20:26 2026 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013056.outbound.protection.outlook.com [40.93.196.56]) (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 2B34B388394; Mon, 2 Mar 2026 21:36:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.56 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487408; cv=fail; b=CwwuD0LISu49w8ZO+Wxkiih9Y486KVrnxzDykGhzFylzmr9M8hCSFGwLz5hio7HA14jP3UthUWX7EmyaYiPyvHtc23yeKcfPovRIET7UaytlONaYJ07hegZ6CJzwKF8cQk8DhPxGx/Y5aXOqIPMHY2XeHxdo0Ex4jeYZG/wojr0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487408; c=relaxed/simple; bh=D2AM4OEfCXB067RmXXVJtOhLSF5aAfN08Ql+f38qxhY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fGyQJqr8XVFn7dNRrTbZKW9ZTEVaPxGx4xvBYaWiI9EYbUXoGH5ZJji5yiwwCl7WA5P0E1NUl8g+QXxXsODTpuYSMF66lkIk5SX6ndhkzioySRr7zHXwZKKcrrXnr7kT1ZpWUy+GSygJeE58pLYIdkJJ+oRzzMezZE/tAo9dH2A= 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=Q2g1P1c9; arc=fail smtp.client-ip=40.93.196.56 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="Q2g1P1c9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jDtA7K7Wae9Yua0VfnNvABiXEXMGWTG/RKaNEYeqr4sYEMEznhcyO9IgZpfQxr9kg+QrluI/76CPVyIOrGHONe9McV6vjyF1bL95NtGdOjERtwFOsHiXmawY8h+xLpTWJgSvZDui2frYx8qEN2QhUz2S+i+cNYiLGPC0TSU9+1rxPttDM98aB6Wh3Faojyu9VTyjic46mlew/M7fyQImLDToh4aCgzoI9PQIBipEMpf6SKgh5c9TVcLfdBy7cxkjGQOLbD5U4tS9PuaEpNyhUBxRgTaIdjAgrV/CcSplw5yiCEKI+DLYVdvfM6+CSJlgPuEk8c0o7qBfERFe/GHKow== 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=RdE4GWDxtl6omytINHhFJLNpNoILCgzvjNGbqEX2CY0=; b=Y1lIiO67bSnV6ebM64b/sTKynlphix1KmrcUSFvMI+oO+10zUiTliqotwoEc5U3SYL627M2ARweZzf0XbLCVyjPPMrY9pHxJC1sPdRlV004oxL2XsbflK5uwOcejIb/asFvBv5fh6IGil5qktc5PWvVBGh4D5CkU8q5uz+uQmdAodSMT+muw7/WhumCETo8Hv9uj0leEbxc8aGrMWrok3uppLR4Pc9WBEcQXYagf2ebbvFvwGAMK3CbT8UMxCGA8N88fgWlqawli3UKKd2KRjpqpxV2TDiGJJ0K8rIAIDc6A88e07yGuAfaHYzpv5h3tx0fnSkECK7Wq0g+boX8tdQ== 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=RdE4GWDxtl6omytINHhFJLNpNoILCgzvjNGbqEX2CY0=; b=Q2g1P1c9iqTVxqOUoGJQGHgpfBTHGnLvpCDC6CRqSrgkrvv1Ic6ImghQRPUvsn46JJRpGt/fB4zH870QIEBzRMW7EYVolYFYLpO//TvR3RAceeGq+uHeKwgHabWnwV3c+adB2jkrNCOJn8zpoWZWccuaYHZ2x5XXPur1wQPKbj0= Received: from CH0PR03CA0380.namprd03.prod.outlook.com (2603:10b6:610:119::8) by IA1PR12MB7519.namprd12.prod.outlook.com (2603:10b6:208:418::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.21; Mon, 2 Mar 2026 21:36:41 +0000 Received: from DS2PEPF000061C4.namprd02.prod.outlook.com (2603:10b6:610:119:cafe::67) by CH0PR03CA0380.outlook.office365.com (2603:10b6:610:119::8) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9654.21 via Frontend Transport; Mon, 2 Mar 2026 21:36: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 DS2PEPF000061C4.mail.protection.outlook.com (10.167.23.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.16 via Frontend Transport; Mon, 2 Mar 2026 21:36:40 +0000 Received: from nigeria-2635-os.aus-spse (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.17; Mon, 2 Mar 2026 15:36:38 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 4/7] x86/sev: Add interface to re-enable RMP optimizations. Date: Mon, 2 Mar 2026 21:36:28 +0000 Message-ID: <6ff0a36460268f8325bba4267ed779b8ceb94795.1772486459.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: DS2PEPF000061C4:EE_|IA1PR12MB7519:EE_ X-MS-Office365-Filtering-Correlation-Id: d9cc0294-e85c-4cce-622e-08de78a3ca8f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|36860700013|82310400026|1800799024|921020; X-Microsoft-Antispam-Message-Info: WgLSH60yo4nsjZUbhYABMRsfvp9VneMuV8QMx3kUM7Ztiusfzx/4AAb6f4+U+Vy1Nay5J0mE6JEJVYHK7N8T5s2zOg8s1HQkoK3cixMdv7Ugx4zKEQ0l8EP4CFuaxIA9WVVf19iTIo4KA7V/n5j9fjKf8p5hAJCDufsaWd4Wt7WGRZ+ONGJnYvS/FZ8dP+O/jNqIHwV5w/tYTrvsQO+tOrZkB5HpgcIR5RhrQQTRfM/3JLQtSRXAwUI4zmytbtX3pzOZ8k2KtaASZBQDMU1AG1CTKxmIFShhogdSPLY9D7RFZo3G0OHw3wgrfhSi/ZqGZv2f/eQWcfWQWxMYKmvU/G/r9LySgrlcXcXWmI34diG+71t3l+vnIcbrcjeiXMxN5VUvHIP/VhNbL/qS2aSovsZEEI+yP/iRwka8ZwgIdIj6ZBxHjDjiThNeSbzZ1SWV7WbR5PgcUNWq0FP+XAmSSw3K1QRrTqnNjqnTyAAMHRWmUAQb+a5PtJwDAdI34SUQJGJXjPge4iBNSVZgVAVwlFZtUaIPKjz1t1gcGBC/sJloZS0XZV0UswROff/oJS6hha4KFXqDhvaNG2lkXSYvPFH72BE4Ip3CVdW2eBLE2naUjPByjOPuASVoT2htQHmIsn4fqZ0+znccHsIQPkr8F+yY/7IIR5pkEMOpnPBfpzfXGcgLs21VQSM9/wt+5AcwYPcNCqFGoexL0L0aPUVv9veVEy4KG7emhYJy7QmA3wzaMJN0oLqGegQ7GxHZcSLy6ZSIqfJuHPK+sI3DXnv3UgG2Pa7Hio9MUWTRi24oaDCK2QAQnpuRMUfJatgP1rzn1C1mWCo+6pTgvT5e4NJlV7KgPkRNW/b0spg4vucnn/s= 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)(7416014)(36860700013)(82310400026)(1800799024)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: G2hGdK6wWZEld4xH8nw2DcDt8jF6yC7q0puVEkj+3tjC9TUJ5T+1tIUK/rR4FwCerfp5HnDFxBXLRaaqNYuY2drzimHFNd6IK9Jo16KUeuVEq70YAgRvojJ7JTFNVlUGBGkeOUC0KaijUWJBkl4hCWvNW/3ppz+lid9Sd9F0YpS07r+35PHwCNLNh2hK5F6O1k7Ekbl9dv8Nf62huqX58GfaPVhIUyQD3DiagleH9Nf+m9v/0Y3EIcY7jJChi8BR+97JOcKfd6lfeLRT+5MGw5273WkpSBL6MEcFSHifZLG0wZeoTqpEP4N4niINoG+Hwa93ZGzDg3sqpxJhN92EEvW1rOrToY/t2+4DPZNhEV60MK8uAetHEzVH99qoRf/K4luZ8JfZSOqQzBEsW3AXwtRAv5huaBMb1x5zhodSebSSoHuMgd+A9hL1KvADV8sq X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2026 21:36:40.5997 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d9cc0294-e85c-4cce-622e-08de78a3ca8f 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: DS2PEPF000061C4.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7519 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra RMPOPT table is a per-processor table which indicates if 1GB regions of physical memory are entirely hypervisor-owned or not. When performing host memory accesses in hypervisor mode as well as non-SNP guest mode, the processor may consult the RMPOPT table to potentially skip an RMP access and improve performance. Events such as RMPUPDATE or SNP_INIT can clear RMP optimizations. Add an interface to re-enable those optimizations. Signed-off-by: Ashish Kalra --- arch/x86/include/asm/sev.h | 2 ++ arch/x86/virt/svm/sev.c | 17 +++++++++++++++++ drivers/crypto/ccp/sev-dev.c | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 0e6c0940100f..451fb2b2a0f7 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -657,6 +657,7 @@ int rmp_make_shared(u64 pfn, enum pg_level level); void __snp_leak_pages(u64 pfn, unsigned int npages, bool dump_rmp); void kdump_sev_callback(void); void snp_fixup_e820_tables(void); +int snp_perform_rmp_optimization(void); static inline void snp_leak_pages(u64 pfn, unsigned int pages) { __snp_leak_pages(pfn, pages, true); @@ -677,6 +678,7 @@ static inline void __snp_leak_pages(u64 pfn, unsigned i= nt npages, bool dump_rmp) 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_perform_rmp_optimization(void) { return 0; } #endif =20 #endif diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index c99270dfe3b3..4dd5a525ad32 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -1144,6 +1144,23 @@ int rmp_make_shared(u64 pfn, enum pg_level level) } EXPORT_SYMBOL_GPL(rmp_make_shared); =20 +int snp_perform_rmp_optimization(void) +{ + if (!cpu_feature_enabled(X86_FEATURE_RMPOPT)) + return -EINVAL; + + if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP)) + return -EINVAL; + + if (!(rmp_cfg & MSR_AMD64_SEG_RMP_ENABLED)) + return -EINVAL; + + rmpopt_all_physmem(); + + return 0; +} +EXPORT_SYMBOL_GPL(snp_perform_rmp_optimization); + void __snp_leak_pages(u64 pfn, unsigned int npages, bool dump_rmp) { struct page *page =3D pfn_to_page(pfn); diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c index 096f993974d1..d84178a232e0 100644 --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -1478,6 +1478,10 @@ static int __sev_snp_init_locked(int *error, unsigne= d int max_snp_asid) } =20 snp_hv_fixed_pages_state_update(sev, HV_FIXED); + + /* SNP_INIT clears the RMPOPT table, re-enable RMP optimizations */ + snp_perform_rmp_optimization(); + sev->snp_initialized =3D true; dev_dbg(sev->dev, "SEV-SNP firmware initialized, SEV-TIO is %s\n", data.tio_en ? "enabled" : "disabled"); --=20 2.43.0 From nobody Tue Mar 3 03:20:26 2026 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010062.outbound.protection.outlook.com [52.101.85.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B676C388FE3; Mon, 2 Mar 2026 21:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.85.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487428; cv=fail; b=b/SCOHLYtKRCM6KfQnBFNgPi6UxsNjWJ3Invuiz4qjr6n+oR3JQjprdif33dB8eZ2WUxHRs/WvqTBFZzeu30nFm25cJSroiXgHBCMqArdUPK1jM4LY0s+/S3M3Pw9FZ4PqOVVBbOuvRSXjeEaecx+4fsJJd0DSAEYYiAR5aY5MA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487428; c=relaxed/simple; bh=x1VCQ5cjZ5/hQSs7n7cUALz0BaWXySyLQlkH1xDQXFU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oYwE3Cpqq0sjsu1OyX0+iy3j7W9D01xUzO2w8ZqJ1yR1tZ4yE2X/a75LZbvmyao7ouPJkuPZiqQvfOFZ7syoORBUMyyurbaWEhJ3uONvE/lezWhf2cEs75UANvNmKclUSlTIe24u+RQTRfrcFPIVJCQEnJigTK4N94fSsyFd7nY= 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=FJ8Ge3e0; arc=fail smtp.client-ip=52.101.85.62 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="FJ8Ge3e0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZJ+EI6dlmZqroJ1/sCpO3IU42yvqFizuH/TXJsrabD6uc6j8HN9OXEKJVI9t6fEUynfJ9pVvzbMXk5Tyv/xprp/djw3ZSi7eyNyrpTwnVzWcMwcZzxD6eGQyokIpzoysB8wlISAyFAcOscOLSqA7qVQHplgGMA2QEEuluxOjKcjv6W7+1wIzJWTAzNu9PQsaoIqI/8pRJm9stAYjUyZSs/65bXwahOy/Q4kfU2/VlgX0JZspR0Uaf73w/DpMSixXgbCfCd7r8DAkXOavqAeSGtMbHzeDSTVHjFxB2FCbYukJvOu36iBYbRW307EcvYL6dRtyENqMFbumKLtSkP3Djw== 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=kNK9Qf6KXoQOXkdSH2R6RYiWFeG5DzOE8es7YaLInUo=; b=BneE3ApIcWon23gsTMT/rplfNdxo1q99hXjr6No5zDjZGPWtUXAPYhQMYk4LqdAtdcl6+LabZMkiwUj56A2WGEdUm4izK7+7Ab8hXj25T5jBA3keS+sFIMbiQhZI12J4YwGb/hU2QONjkIv43rUplKcqsnALF+MBtRmTAOoOPtMvD9NmzvgGRWAK6OeENRHe6vnn7cxZTnm/urhEz7UzqZKjLCweN5ubVP6R34v5gW5LRO7TNOliIH0oTjuslOXqTD9CFDL+c+HTcw25L+uJsEko5kOXa/xDM59OOfJKUdNi+0axwdsSx72yMP3UDPDw+GFk2gVheXeXWcuZe9yI+g== 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=kNK9Qf6KXoQOXkdSH2R6RYiWFeG5DzOE8es7YaLInUo=; b=FJ8Ge3e0eZdexybV/pqnRl1MpbAkpa1kfVH0snlr+arJY3F0EnO3FZ0sT5Ah9EXK3gG+rw/5BuDL5+fP6b3MwZwTTvBNZvHKqh2l9KMcx0rbVbXNFEQTwhyt0m8nJdjpJKBIsHPv5IDJbpEFIP93/Cc9mtWsA6xJftHywUNgb2U= Received: from CH0PR07CA0021.namprd07.prod.outlook.com (2603:10b6:610:32::26) by SA1PR12MB7271.namprd12.prod.outlook.com (2603:10b6:806:2b8::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.16; Mon, 2 Mar 2026 21:37:00 +0000 Received: from DS2PEPF000061C5.namprd02.prod.outlook.com (2603:10b6:610:32:cafe::9b) by CH0PR07CA0021.outlook.office365.com (2603:10b6:610:32::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9654.21 via Frontend Transport; Mon, 2 Mar 2026 21:36:47 +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 DS2PEPF000061C5.mail.protection.outlook.com (10.167.23.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.16 via Frontend Transport; Mon, 2 Mar 2026 21:37:00 +0000 Received: from nigeria-2635-os.aus-spse (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.17; Mon, 2 Mar 2026 15:36:58 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 5/7] KVM: guest_memfd: Add cleanup interface for guest teardown Date: Mon, 2 Mar 2026 21:36:48 +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: DS2PEPF000061C5:EE_|SA1PR12MB7271:EE_ X-MS-Office365-Filtering-Correlation-Id: e3bf3140-a7b1-4f0c-5d0e-08de78a3d628 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026|921020; X-Microsoft-Antispam-Message-Info: EqduD0CwiJlCObKkDc+vZNyOS7CuQzr99iWv2v9UcqOwFaq9/660ahl+JvCMcfGD8O8Ab4rXTjLvCy5qVFocpFDOcPhfIR/qDgZx1TLeMOWvSWQipXcffDXfjl1yrtst63vHa4vekoNQCk3pjo7rVQ2uZRHYKc/Har5sHoiy/LqFETlbJeV3CMD8w6Uz/FbOWqRPlLIgmWIFK4Nh5zpNJoVW2LBglRhq+LcWGuNxaKLox9mAO77CfQe1l/xRzch/DGilGAbajt/EkxB37nYCwoKkQmnOl2Of1RCBo5kyvPuNc5WP9K+4sMVpFd4YYl/sbkDTTRf9fjAaVw8CPXGKEuPpe2q7vDg/eWDsCCXKsRlpkvBQUvqB6svDnffhctqDtmLUgGG1dG1Zu4iwvWeiMqVAKsXVtJamA2U6Q+PiyjnukVaPdNr0gOEOwy2gd33VR4aGLYnji1q23YiL0KSPgiEogIDhjUC2ItzjrMdgWO5hefANM9AGCXG+0jieMIPWHqpWHTNYBdlx947qJKnvcrgmkUuyw1iROh0Tn+TXQ0p26QdZZgOtiBvi+XwznaoMLi3gUfqqlAIqC00vDYsx+Pq75BZMHiyB1A2T9wCR9SireqPV+Zw+1C8hEez+ddWFSJ5w5SgSj4r0kPctUk/BY7ymnNJ4bINAEQg+bwfQT0JGD9f878p/Kc6/njUnXQ0mz5RBYFcS+5Pwo4orercaNFlVgjOz22UB+iGBhUaPm/Ui/cO/u35XhXuArp/JQnl6mMZ4XxhCcAZdjY0J/M37fVuqSMuEMJ6mHhRwcg/PJai7FtHBf6KInfRx/ybBshrccPpY/h5ck7lcK1rwJ6LdGxf/qiL5iiSIczrnKIGwicw= 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)(7416014)(376014)(36860700013)(82310400026)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IlK+pcyQXHL/3A3A4oyk2aaiiS6TqbDXb2Z6F3YhG1abXU391BWQksQD0jXSlGJ1AvKsEDawcHI10GCnHDfkRotEsPpb17OT6Fb94Z998SLEUJoJiZbkvACoKiZV/Nczyv0NQX8uQMKkTsYw4zpMaMg/8NGqqhkyFUg8luO52m6HNhheZSaVAW7zVasPe4n0GDwoWafj2EebVeqWnb5blLpVXDqRo53rhO9JUjd60GdyD2qLB2cSStgCvyFUsrdqvA+uwYLQPN2opeAhGRNOG8nHQQNotXUFey4CQyKXZQ8Ac5JOQawUPYaEPj9Yg+LvoPMyY9QnOSjWQ5iKXv6QF1r+515NMaTsSShBEHRb3iuQJH/Ig/HJWZDmSRTCuzd1Le0e2sF9+pqJv6IM68I0Kze8DGH1/Nm38Yp4jQ8ZbCUP5GE/VVEMdHv6WnLKYlzl X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2026 21:37:00.0381 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e3bf3140-a7b1-4f0c-5d0e-08de78a3d628 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: DS2PEPF000061C5.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7271 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Introduce kvm_arch_gmem_cleanup() to perform architecture-specific cleanups when the last file descriptor for the guest_memfd inode is closed. This typically occurs during guest shutdown and termination and allows for final resource release. Signed-off-by: Ashish Kalra --- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/x86.c | 7 +++++++ include/linux/kvm_host.h | 4 ++++ virt/kvm/Kconfig | 4 ++++ virt/kvm/guest_memfd.c | 8 ++++++++ 6 files changed, 25 insertions(+) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-= x86-ops.h index de709fb5bd76..ebbecd0c9e4f 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -148,6 +148,7 @@ KVM_X86_OP_OPTIONAL(alloc_apic_backing_page) KVM_X86_OP_OPTIONAL_RET0(gmem_prepare) KVM_X86_OP_OPTIONAL_RET0(gmem_max_mapping_level) KVM_X86_OP_OPTIONAL(gmem_invalidate) +KVM_X86_OP_OPTIONAL(gmem_cleanup) =20 #undef KVM_X86_OP #undef KVM_X86_OP_OPTIONAL diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index ff07c45e3c73..7894cf791fef 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1962,6 +1962,7 @@ struct kvm_x86_ops { int (*gmem_prepare)(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_or= der); void (*gmem_invalidate)(kvm_pfn_t start, kvm_pfn_t end); int (*gmem_max_mapping_level)(struct kvm *kvm, kvm_pfn_t pfn, bool is_pri= vate); + void (*gmem_cleanup)(void); }; =20 struct kvm_x86_nested_ops { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3fb64905d190..d992848942c3 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -14080,6 +14080,13 @@ void kvm_arch_gmem_invalidate(kvm_pfn_t start, kvm= _pfn_t end) kvm_x86_call(gmem_invalidate)(start, end); } #endif + +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_CLEANUP +void kvm_arch_gmem_cleanup(void) +{ + kvm_x86_call(gmem_cleanup)(); +} +#endif #endif =20 int kvm_spec_ctrl_test_value(u64 value) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index dde605cb894e..b14143c427eb 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2607,6 +2607,10 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t gfn, v= oid __user *src, long npages void kvm_arch_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end); #endif =20 +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_CLEANUP +void kvm_arch_gmem_cleanup(void); +#endif + #ifdef CONFIG_KVM_GENERIC_PRE_FAULT_MEMORY long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu, struct kvm_pre_fault_memory *range); diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig index 267c7369c765..9072ec12d5e7 100644 --- a/virt/kvm/Kconfig +++ b/virt/kvm/Kconfig @@ -125,3 +125,7 @@ config HAVE_KVM_ARCH_GMEM_INVALIDATE config HAVE_KVM_ARCH_GMEM_POPULATE bool depends on KVM_GUEST_MEMFD + +config HAVE_KVM_ARCH_GMEM_CLEANUP + bool + depends on KVM_GUEST_MEMFD diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 017d84a7adf3..2724dd1099f2 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -955,6 +955,14 @@ static void kvm_gmem_destroy_inode(struct inode *inode) =20 static void kvm_gmem_free_inode(struct inode *inode) { +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_CLEANUP + /* + * Finalize cleanup for the inode once the last guest_memfd + * reference is released. This usually occurs after guest + * termination. + */ + kvm_arch_gmem_cleanup(); +#endif kmem_cache_free(kvm_gmem_inode_cachep, GMEM_I(inode)); } =20 --=20 2.43.0 From nobody Tue Mar 3 03:20:26 2026 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011054.outbound.protection.outlook.com [40.107.208.54]) (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 1994438644B; Mon, 2 Mar 2026 21:37:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487449; cv=fail; b=WbYm9UCYbTAFn1EaQQW1a8hndDtNMUrNheRP6/e6DOviKQxJ2/0ENqGRHLEC+d/4QvfxcY2Yw/7HhV2bUD006909j/Bt18qCOY55/G6eT6vKKgsQjvF7FxeVjwPybe1IeptOHxv0V3bTL5xrIFjYXwA3MkalcsVr9fD5+vn3JPk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487449; c=relaxed/simple; bh=Si+twPrre6YurAg23KNmjyuiw5GZjpJGDRjXFMGUtKM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OG/BTPIHDTKXx+qhrkfJ/DqmKvaC8IzTipnQAhxqJwPx7uJHD74DD8jkT+iR4rWv2ybgchrkdSNZWt97uo6zoX4alV7NB4wI5k0NYgedWZVyRWPQ8f9n84JaXL67YZprXWvZeFw5WzpEHJPZWDEo/tqILAJ0S3f6rwE6gpOUjEQ= 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=iGkrW1w/; arc=fail smtp.client-ip=40.107.208.54 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="iGkrW1w/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=L2utOTupTHncaQ5M+blHzkNXNxCaGELbmRh1bLDqfFwiZUI7eH3BNc5keP3BC734IbURwFepfa9F8vgUx3FXbKHBur95ua9b35gRnUzTLswumDqxN0RF8x4dwwZcrYqZj98kUqHS8zENrbJekGqNUVpYeRStYSPlMosF9hE6XanysK38LN/C0jAq7ODCEIBF+IrKFRFOr7e5mK3ZlNkdKCR9Khvu67BoqYXj159gvGEqm/on4ZZGd5JT72IxThzFcITcqsTwKOoAUcsrOkbpTv1h1UjAe0NmtjPnHPj0NJv/WcpPmVXc5Y19agNRFNspWjgeiYyxWjHR7YFu1LaE/g== 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=ycGcrxcAPFYhZRmBOLuQ6TnA+d8bTt5/j6eBtCtCA8I=; b=hmp5IYfvU4/H70f64rDNqVXAwYrH4pJQcpsMOlzC+z27u6TDyCNfXq2/TOO1iwtILt/Y4MM+Ppmkkv55owmGMOtAnF74UjbFZ4bps2MFNUpH6fvl5VveOABHF5cIbFiRtEqmk9BeztB6MtWYXQ7ypWWGTaLyhA+d/N52j8UUOSZWPIn8nTtQd4kUBdVdf36gciAnTOFupEgk2Y60oxH2jfxtMnERFkvlN6PQIPzdjAZGJkJ7pzEW/CpLKXiT/OiG90+0FhOD//kYGXTjOhxiLppW+LTqtYyfmh8SXmuVyh7T8VvYEGpm0aB5EdRwE1bE4FxHCGZQqEWXU94cE1RQFg== 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=ycGcrxcAPFYhZRmBOLuQ6TnA+d8bTt5/j6eBtCtCA8I=; b=iGkrW1w/OrVmhID9tQlOqx5tyVc9FPH6I+Yz5fOaL8mTKHhLHQLhn17uAus12DyZRgLEOqUMrKUSVAiIyorCyusZxO5kVAEGcZ3fjQKiFbdhcSJd8l89x3paAmqZtk/pT9jSRTAQMOd25b7Up2PINLKPggSA6UN/VEsdCDL6bMo= Received: from CH0PR07CA0010.namprd07.prod.outlook.com (2603:10b6:610:32::15) by DS7PR12MB8370.namprd12.prod.outlook.com (2603:10b6:8:eb::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.21; Mon, 2 Mar 2026 21:37:20 +0000 Received: from DS2PEPF000061C5.namprd02.prod.outlook.com (2603:10b6:610:32:cafe::8a) by CH0PR07CA0010.outlook.office365.com (2603:10b6:610:32::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9654.21 via Frontend Transport; Mon, 2 Mar 2026 21:37: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 DS2PEPF000061C5.mail.protection.outlook.com (10.167.23.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.16 via Frontend Transport; Mon, 2 Mar 2026 21:37:19 +0000 Received: from nigeria-2635-os.aus-spse (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.17; Mon, 2 Mar 2026 15:37:18 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 6/7] KVM: SEV: Implement SEV-SNP specific guest cleanup Date: Mon, 2 Mar 2026 21:37:08 +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: DS2PEPF000061C5:EE_|DS7PR12MB8370:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ba7852f-d16b-43a8-1abc-08de78a3e1f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|82310400026|36860700013|921020; X-Microsoft-Antispam-Message-Info: hFzwyeKTuzqFFMVQocjLrPPg/UvIb1sknPRJnzVozuYXMwsNlid64yYYI9tGJdJb15Rm+QZuGqitjXpuWz4ez77hpvkXHAo9wC6uKDKwPRtPmL2SEAn8BsfERjfCT1DhsJeMl7c/2KRAC7KrCfEQFpJgEfhjIs9bKsLOSp/4WCQoczrtF1qI/6/fbwrBo5Wohk2L97YwCNbO1DlJPyH1yH17I8MctGjuRcGiQxfW9UdIBOxqjLTxylfy8NTbTSH/oP8D/NPGQyU2OUgxOYZN7yFYCT92WXDrc3h7sEHKozMVNjmIdZBNz9N9AwFcnF4Sz2F0FJSW22bNXR7TkMCkx7ZQq3bGqoFJ1/hrztcI91OBCDcnOnyTF18/ejYCI0ha7iZKojP9SydQ+CfzQkCOhgtt8Sj3VvGh2BxyGi7myv2jWBgYSUEcl5IU5zBy9ntYehRi91kbQzjxrUnQx85ZKzBvX7ZDnytcOQZR4qmrdioxyEbprEnRdqLbVHRBwxWVu1VdvmpRdmKIygmpmfw2+9L9Rez9A839aywW+zgkbDQuvsTt7O0DGDKMTFO9VJh1zvHmk582oJeJm0Yu8x/gg122gow0/zt78Ahg6cFu1Wpazdlskut9TNKiXEM/WipLwG8OONK+O4ha6XYTaz6fT7AUc+42scfw8su4ueYr7otz/xC50vEPMLX0+L4azXqLNDV+v/N/FJgt9g47MR/VBOJg6mJgP4jOTRIwwFB/ZLrwZ3Wr/vmVHam6wAGC2M4IbJoht+FTDYyy4SdtxhZPr1PSZmJxU2ZHbfVpkukoS3NwRPnQLYfobzQKLd+H6kpmcILNY0i3wxk5KUogWrIKtT0J6+lG5gjymuQOo5j/ocE= 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)(7416014)(1800799024)(82310400026)(36860700013)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1PYeOqu+baRepGTNbo2N9HxEvTjb2MZ5OnYM/AsAHgIeUweOkkgd4yL7b5Dlkj4bv9ugd9R7kpBVqQ7xmpygmSQGARjj+6HMxOGuw18TsFuAFnL/wW8LKYWribQnPyUz4PjFdZY3WjMtMHLCz9ZRbRBOtREmayqJlO3T3HB3JYsIAFoBRDEJ99k9oVOJ1gXyBDXgP/WfzoNQxAX6ZoY9WX/PBGrnRM8Nk1rD6yiUAFU4IU1fDKO3JlCAE0wrYS+IpZN32g70zc8wBv8e1tI+imlJF8f7j0o7I3bzXYZDgbon0yjoQ84LHUOhdbGdqIJX6fqJJX5bSYEbvvbaIlt8Ez4h3NC4QgkcNT3FbVTJSXAJ+EpsKxewAirhzrnseAxXwLQHZHpr1mBGRXzEn6nS7te1euhHQIar/vq+5ofo00s/AVEscy8J/k36DamMhqKZ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2026 21:37:19.8826 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3ba7852f-d16b-43a8-1abc-08de78a3e1f8 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: DS2PEPF000061C5.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8370 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Implement the arch-specific cleanup for SEV-SNP via the kvm_gmem_cleanup() hook. Use this interface to re-enable RMP optimizations during guest shutdown. Signed-off-by: Ashish Kalra --- arch/x86/kvm/Kconfig | 1 + arch/x86/kvm/svm/sev.c | 9 +++++++++ arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/svm/svm.h | 2 ++ 4 files changed, 13 insertions(+) diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig index d916bd766c94..fdfdb7ac6a45 100644 --- a/arch/x86/kvm/Kconfig +++ b/arch/x86/kvm/Kconfig @@ -164,6 +164,7 @@ config KVM_AMD_SEV select HAVE_KVM_ARCH_GMEM_PREPARE select HAVE_KVM_ARCH_GMEM_INVALIDATE select HAVE_KVM_ARCH_GMEM_POPULATE + select HAVE_KVM_ARCH_GMEM_CLEANUP help Provides support for launching encrypted VMs which use Secure Encrypted Virtualization (SEV), Secure Encrypted Virtualization with diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 3f9c1aa39a0a..4c206e9f70cd 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -5109,6 +5109,15 @@ int sev_gmem_max_mapping_level(struct kvm *kvm, kvm_= pfn_t pfn, bool is_private) return level; } =20 +void sev_gmem_cleanup(void) +{ + /* + * Re-enable RMP optimizations once all guest pages are + * converted back to shared following guest shutdown. + */ + snp_perform_rmp_optimization(); +} + struct vmcb_save_area *sev_decrypt_vmsa(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm =3D to_svm(vcpu); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 8f8bc863e214..46526ab9ab92 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -5260,6 +5260,7 @@ struct kvm_x86_ops svm_x86_ops __initdata =3D { .gmem_prepare =3D sev_gmem_prepare, .gmem_invalidate =3D sev_gmem_invalidate, .gmem_max_mapping_level =3D sev_gmem_max_mapping_level, + .gmem_cleanup =3D sev_gmem_cleanup, }; =20 /* diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index ebd7b36b1ceb..443c29c23a6a 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -896,6 +896,7 @@ void sev_handle_rmp_fault(struct kvm_vcpu *vcpu, gpa_t = gpa, u64 error_code); int sev_gmem_prepare(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_or= der); void sev_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end); int sev_gmem_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn, bool is_pri= vate); +void sev_gmem_cleanup(void); struct vmcb_save_area *sev_decrypt_vmsa(struct kvm_vcpu *vcpu); void sev_free_decrypted_vmsa(struct kvm_vcpu *vcpu, struct vmcb_save_area = *vmsa); #else @@ -928,6 +929,7 @@ static inline int sev_gmem_max_mapping_level(struct kvm= *kvm, kvm_pfn_t pfn, boo { return 0; } +static inline void sev_gmem_cleanup(void) {} =20 static inline struct vmcb_save_area *sev_decrypt_vmsa(struct kvm_vcpu *vcp= u) { --=20 2.43.0 From nobody Tue Mar 3 03:20:26 2026 Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011062.outbound.protection.outlook.com [40.93.194.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67EBB37E682; Mon, 2 Mar 2026 21:37:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.194.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487466; cv=fail; b=oZbtoR8OCN8dWrvEP6ynOhvIDhDKbAtON4XgPK3ZBxpIztj6n+2WdK6Q8dvX7m+HbGr/nem3OXFDGCI6RZqeJH+aoz1v6cXPPi9sYpwCKhyq2Fz05smP9xjrH3xqEfhBmCM9ocX4znHG+kTihNmbAbjwXCC3sjcV16pTyLhOlLE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772487466; c=relaxed/simple; bh=TKvEodTkiW5FZ8zovTcaqqRclHhYEhq9qj9slYVIaa8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pIPpmhfKwlFyQDgTZS25zKAvJDp3rNBfdRy+Hmfr3gPKfZ+ul21VnsV2WUyyP3D6PmVQZudWZOH5pDVp6WrSEAVyE0ucnUkupaaQXjEO3dflB6e4sVXcEolQZNsASx0wev1qoBvqPW7t8A4Y6EkPFvXTtQ4VCDOy1roP/dA2mqQ= 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=Zccse3Az; arc=fail smtp.client-ip=40.93.194.62 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Zccse3Az" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NRHcb7OOZWSOc7l4Je3/sTZuyUJm0fI0xkOaRAnKykFn5yb9mi5Oi9jpbSzRb5H7fcfTPCgXFf4ApAjBEhUfGjbK+AjLTAwQnECskyKJ62T9oZi9EgCOUBRRkvmzygyx68UsaJpQjL7WYuQc6I2Z5kHyiqy3CuasKdpLL5iO4VjMrlBt+utqaiSwPj8FaDmMogax7s6bI0yM6tonsLsLdO5ZMfCim8QZBOAQC5Kwg9vlGhI9oTBMVwavS0HQmdl5MYVGmMnyvJCrDkHdD6y5e/FAiK9X9gB0ImJiyIxHnKfjV6k9obe6Et4QzgQTSJGa8tX3ORYDFvJd8Vi8gI0Rxg== 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=5KabDjPLVSfBS647KfV3I/TxeBbALzYgaCL+9laF59w=; b=qrXWGOjnpCfizsJLQi88M006dZ3Kuq+mXNBgDVoWk6+obAvgavYWWWBN+3ccSkfXOmUdGGMYWI5NYAZqpmhPnfga6nlXk+rqnq4n5jp5Ak+dV/IkvqZBqaBLD7JPqSosHAdxW7MTZR7h+AXjlrxBvGrrnls9rLL1UbQA49yV/ce/DfDj9Q4gq74JB7vZE1r52Y/pxoMTLhKRRmCvn1NjttcNBOHvU1sYkkRg70fGFXneZdVrR5BBlp3dv2o17AF9O9ihlkfw/4hm2P1B7teittjn6kpuHYsR0HCSSuTod3Tb7tI50SgQxrRsxnSBn4ti51T6P3VDUYBvYwCVWZr++g== 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=5KabDjPLVSfBS647KfV3I/TxeBbALzYgaCL+9laF59w=; b=Zccse3AzVQBtNrje9umwLaYX+4BkAkcfUrbC4QqzkQCaNcxErsmXbWTEk/YzTAl60q3zg98re1JkBZGoQPGc68W/mzY2jTjL+Im2K8S1UiqNPE9+Q1dJsKeujVKHCJ/iPFYrQpoplutsjaEgflCLK8eaee2iIPHfLTh1jqfZycQ= Received: from CH5PR02CA0018.namprd02.prod.outlook.com (2603:10b6:610:1ed::20) by DS0PR12MB7852.namprd12.prod.outlook.com (2603:10b6:8:147::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.14; Mon, 2 Mar 2026 21:37:37 +0000 Received: from DS2PEPF000061C3.namprd02.prod.outlook.com (2603:10b6:610:1ed:cafe::d2) by CH5PR02CA0018.outlook.office365.com (2603:10b6:610:1ed::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9654.21 via Frontend Transport; Mon, 2 Mar 2026 21:37:32 +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 DS2PEPF000061C3.mail.protection.outlook.com (10.167.23.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9654.16 via Frontend Transport; Mon, 2 Mar 2026 21:37:36 +0000 Received: from nigeria-2635-os.aus-spse (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.17; Mon, 2 Mar 2026 15:37:34 -0600 From: Ashish Kalra To: , , , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 7/7] x86/sev: Add debugfs support for RMPOPT Date: Mon, 2 Mar 2026 21:37:25 +0000 Message-ID: <7dcbcbe5dab82fa59056fdb0bfa330cd0da8e62a.1772486459.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: DS2PEPF000061C3:EE_|DS0PR12MB7852:EE_ X-MS-Office365-Filtering-Correlation-Id: e22d2292-e6a6-4361-2336-08de78a3ec0b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|7416014|82310400026|921020; X-Microsoft-Antispam-Message-Info: HJ5GmPviqbFmeMs92ggSGzjt0DNjsENS28pqnqrMS5rkQWnVcRKgt87Oa5cuwtzFmIiKR+KVEN8bfs3JfWQzqGx9j0ksvwxROzurUWr7zwXZUvyONDqB5D6a5YThX1+w+OMUxJLKXfmIKS88tEp03AF8yeJ+BykirsW5njuN9O11pwp+d3X7wxE0oUUlniZo6CWphoCmKP3hTZh4DrjYtBR83dYu1xQGzZ8242JhGlwkR0dFrHV8TP/LGmP42OmVfxIjLTrPA5mmCZ3I7uO3ewLOBYXFj92SrpIt5TaTol+UIvcYGI2KiTg8VqzG1gjOR26vQjfAZq/TqCH8C2kTkpC5irY4dqEB6M69RuSDcJ2y/rYxgjNKI6cQ0W+53BPBW01FQLyTYIgmvsP44cl42Q6nPOlBdtkPRhcNebmO8ETU+UlA82Mw5ieU8vmCymTO5rTEkYWnBYF4hc3+IFEgpHjEatv+v2q5LR0Yc8yjocywEhdICeZVsNJXbpseMsW1jWtp3ltQuEAezX+3THlhCJ3LASA2HKzuHDIPnvhD5Orgf1JYIafkDkt/G2mOWFiklX/5F1PSTry3Cwm1QOg5cybyabOgkxEu03EI6MWOzVigNt6n+uSEJT02nx8hWpyw8hHXcKUmQSzaV15WAJlp/3X/nKaXUUVa/DR8qi6di0x8TLM0yu9S957Fgll/0GFSU5kBfxH0MYC51GlcaTCBEnNRIb3Z8FpFi2/gXJtkWnG2Tc1tM+mEK/OE8wh6Mgt4dEk3/gBTrG1fsw+NuN+CTdaBod0rdYjvEx9JxWRCUwODVopkesBsmh95LllqHUpyleX4yUAS06/RrOPJwCXHwIDwTinL2+k1NsYW4lII7BA= 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)(36860700013)(1800799024)(376014)(7416014)(82310400026)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wRtEnaRKdKBEJ5/xH4N/vcmJoqK73iHDXFtk3NpBK8eZ+tSMaEVl4cAn2undZVuAsMk9rHYguEk7EZb2c3b82vYcRq84yi6ESAqzibhG9YTnjCBUvwF+xRVk6BRCX34lAK/8awBkWYgMrRF4tGXe3iLmaVFWPZ+qkgxw7LdUoqY+eSUQvQd7cKcTHPDSROV7DH/mS1zckR4KZ1CuB7Z+OGlkOWcMCgUFe2pt8OmzPV4ILSS2aMLdj2PqLll6iVO/WF6mhuwxfGdczV5FssRVCbQXZre8NN7cdVbjPNshjSgFooEeo1cblnnYT8x7CL21erP7IapA8xBZ9a0Ey6yeqYAwx+ok9wcp5N/mFHSNFuuJbev0x8iim7r2wrnTTl+ZiLIuNImx0sabGlQG+XGpScBT6ebGIuz+H/s9svZ69gJiI63frwxdNESN9sFE9CaI X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2026 21:37:36.7596 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e22d2292-e6a6-4361-2336-08de78a3ec0b 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: DS2PEPF000061C3.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7852 Content-Type: text/plain; charset="utf-8" From: Ashish Kalra Add a debugfs interface to report per-CPU RMPOPT status across all system RAM. To dump the per-CPU RMPOPT status for all system RAM: /sys/kernel/debug/rmpopt# cat rmpopt-table Memory @ 0GB: CPU(s): none Memory @ 1GB: CPU(s): none Memory @ 2GB: CPU(s): 0-1023 Memory @ 3GB: CPU(s): 0-1023 Memory @ 4GB: CPU(s): none Memory @ 5GB: CPU(s): 0-1023 Memory @ 6GB: CPU(s): 0-1023 Memory @ 7GB: CPU(s): 0-1023 ... Memory @1025GB: CPU(s): 0-1023 Memory @1026GB: CPU(s): 0-1023 Memory @1027GB: CPU(s): 0-1023 Memory @1028GB: CPU(s): 0-1023 Memory @1029GB: CPU(s): 0-1023 Memory @1030GB: CPU(s): 0-1023 Memory @1031GB: CPU(s): 0-1023 Memory @1032GB: CPU(s): 0-1023 Memory @1033GB: CPU(s): 0-1023 Memory @1034GB: CPU(s): 0-1023 Memory @1035GB: CPU(s): 0-1023 Memory @1036GB: CPU(s): 0-1023 Memory @1037GB: CPU(s): 0-1023 Memory @1038GB: CPU(s): none Suggested-by: Thomas Lendacky Signed-off-by: Ashish Kalra --- arch/x86/virt/svm/sev.c | 101 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 4dd5a525ad32..49bd7ba76169 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include =20 #include #include @@ -135,6 +137,13 @@ static DEFINE_SPINLOCK(snp_leaked_pages_list_lock); =20 static unsigned long snp_nr_leaked_pages; =20 +static cpumask_t rmpopt_cpumask; +static struct dentry *rmpopt_debugfs; + +struct seq_paddr { + phys_addr_t next_seq_paddr; +}; + #undef pr_fmt #define pr_fmt(fmt) "SEV-SNP: " fmt =20 @@ -515,9 +524,14 @@ static bool __init setup_rmptable(void) */ static void rmpopt(void *val) { + bool optimized; + asm volatile(".byte 0xf2, 0x0f, 0x01, 0xfc" - : : "a" ((u64)val & PUD_MASK), "c" ((u64)val & 0x1) + : "=3D@ccc" (optimized) + : "a" ((u64)val & PUD_MASK), "c" ((u64)val & 0x1) : "memory", "cc"); + + assign_cpu(smp_processor_id(), &rmpopt_cpumask, optimized); } =20 static int rmpopt_kthread(void *__unused) @@ -563,6 +577,89 @@ static void rmpopt_all_physmem(void) wake_up_process(rmpopt_task); } =20 +/* + * start() can be called multiple times if allocated buffer has overflowed + * and bigger buffer is allocated. + */ +static void *rmpopt_table_seq_start(struct seq_file *seq, loff_t *pos) +{ + phys_addr_t end_paddr =3D ALIGN(PFN_PHYS(max_pfn), PUD_SIZE); + struct seq_paddr *p =3D seq->private; + + if (*pos =3D=3D 0) { + p->next_seq_paddr =3D ALIGN_DOWN(PFN_PHYS(min_low_pfn), PUD_SIZE); + return &p->next_seq_paddr; + } + + if (p->next_seq_paddr =3D=3D end_paddr) + return NULL; + + return &p->next_seq_paddr; +} + +static void *rmpopt_table_seq_next(struct seq_file *seq, void *v, loff_t *= pos) +{ + phys_addr_t end_paddr =3D ALIGN(PFN_PHYS(max_pfn), PUD_SIZE); + phys_addr_t *curr_paddr =3D v; + + (*pos)++; + if (*curr_paddr =3D=3D end_paddr) + return NULL; + *curr_paddr +=3D PUD_SIZE; + + return curr_paddr; +} + +static void rmpopt_table_seq_stop(struct seq_file *seq, void *v) +{ +} + +static int rmpopt_table_seq_show(struct seq_file *seq, void *v) +{ + phys_addr_t *curr_paddr =3D v; + + seq_printf(seq, "Memory @%3lluGB: ", *curr_paddr >> PUD_SHIFT); + + cpumask_clear(&rmpopt_cpumask); + on_each_cpu_mask(cpu_online_mask, rmpopt, + (void *)(*curr_paddr | RMPOPT_FUNC_REPORT_STATUS), + true); + + if (cpumask_empty(&rmpopt_cpumask)) + seq_puts(seq, "CPU(s): none\n"); + else + seq_printf(seq, "CPU(s): %*pbl\n", cpumask_pr_args(&rmpopt_cpumask)); + + return 0; +} + +static const struct seq_operations rmpopt_table_seq_ops =3D { + .start =3D rmpopt_table_seq_start, + .next =3D rmpopt_table_seq_next, + .stop =3D rmpopt_table_seq_stop, + .show =3D rmpopt_table_seq_show +}; + +static int rmpopt_table_open(struct inode *inode, struct file *file) +{ + return seq_open_private(file, &rmpopt_table_seq_ops, sizeof(struct seq_pa= ddr)); +} + +static const struct file_operations rmpopt_table_fops =3D { + .open =3D rmpopt_table_open, + .read =3D seq_read, + .llseek =3D seq_lseek, + .release =3D seq_release_private, +}; + +static void rmpopt_debugfs_setup(void) +{ + rmpopt_debugfs =3D debugfs_create_dir("rmpopt", arch_debugfs_dir); + + debugfs_create_file("rmpopt-table", 0444, rmpopt_debugfs, + NULL, &rmpopt_table_fops); +} + static void __configure_rmpopt(void *val) { u64 rmpopt_base =3D ((u64)val & PUD_MASK) | MSR_AMD64_RMPOPT_ENABLE; @@ -611,6 +708,8 @@ static __init void configure_and_enable_rmpopt(void) * optimizations on all physical memory. */ rmpopt_all_physmem(); + + rmpopt_debugfs_setup(); } =20 /* --=20 2.43.0