From nobody Mon Nov 25 09:41:33 2024 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2046.outbound.protection.outlook.com [40.107.236.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 090FC18FC74 for ; Mon, 28 Oct 2024 19:33:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730144025; cv=fail; b=utbImlTnyn9iLATWXfssHMYky3CgX2z6H1zyb1yBeKfI/Sc4IV6NKOUNMr46Rcb0h/+9ssyv5C3HIWiRccVWHheduNgqtxomVuxuySjLpXFwhkfavapGsRgDLrg1CL2IyPb90OYcI5IuKjBNigLX9SSOsKCO7VcEOEz+6yga6oE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730144025; c=relaxed/simple; bh=vG26Fg5VphVZ1N6SrAKhXMhv3mbFduHpoxa/W3EuSjk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=krFEwYNV5zgZkXub+LfUln0FZGJVxUNNdpPq9v3be3vZxTNW498YjMenWD24frPos6EDnQP3FoTUpaJEZY3KybJmp7AmM+8wxAzKjIOhpmgG5tmqioyct4Gew9OWY9IZ1g2prWJO1QvyFdLVJRV92DNX+H+crJ6R7IGIVGMyLCE= 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=giNTYuxn; arc=fail smtp.client-ip=40.107.236.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="giNTYuxn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=S6qKLQKeS+8ESqMZfVjInLW98nMyzkJIwkw7qztNoNgz86PVOeFR0TUTkM+hwVEyTXJS6CXfFDGMayYVUFBckYOghvPj1uSBZvVYCeOz0ellEQb0PEp0rRKEEDhxFbu5w6JN49TB/WPi9TfcgbKXzBjD68srSjMxwtJIOkLKG4+/T4KUUI53FkLlNHCqNfzftUTTlS2UJkI9EUlOnp41hiMg/XL1Z28mHaD6osP968/lYFY9KayuQRQRKcGYvzJ4wYSJjGM0HMSzUSQvcIGZumSRRDUYPG5uodehDHK0n9daThKs1WW7tZcN4gUFyZ6anJEXtg96N2iBUT3W3YElBw== 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=KFICUFsDFBij6WWSTPDM71sS2G2SAGuuRSFxJQbt66o=; b=P9kKB8Kcs1/70bDTSTqlJ8oIdff8vm99y59hFaDzkIQyXwAMPGhJpjcxIePzSypRocVTSabk3cA3BxvYrftIxplL3JpKwoj7aAKd2NVmDmnvi5dMc3xy5Iy32kyYJWiWoZa2+fLEDqx/z31JqEZIK8Ej5BT1bRCm4hrTyM9eNLxQUEqPhQr7O4/7bYDXiW9qJaD59JT1jnhHfE4uuFJgAMn0KP3UVqAW77WXCmqRIkRU7pgnsdkFyB02ZPJLemCMeQ5izvVJC9+HBpCZR1M9ca581z5opQE1ygcbUL9pIQxp1TPi+eNYepGYeMCO9ifARqEv6Gg3QYUfaP5rAUg8+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KFICUFsDFBij6WWSTPDM71sS2G2SAGuuRSFxJQbt66o=; b=giNTYuxnw1stNfynsky5e7cLxlaGJvZDVF1yrj07qvigQDtW0ni6jxGnga34Zom73/zqANIERlliYuAOhhawo4GXdmGNAxWsV0yNMjKbaVTVH/HJ59j3k4LbQg3d96jF+y/b7gfYWIJr1D8nWo0g2ukUJyMeZ/mVOpPFj37adTc= Received: from MW4PR04CA0387.namprd04.prod.outlook.com (2603:10b6:303:81::32) by DM4PR12MB7742.namprd12.prod.outlook.com (2603:10b6:8:102::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.20; Mon, 28 Oct 2024 19:33:36 +0000 Received: from BN3PEPF0000B077.namprd04.prod.outlook.com (2603:10b6:303:81:cafe::42) by MW4PR04CA0387.outlook.office365.com (2603:10b6:303:81::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.26 via Frontend Transport; Mon, 28 Oct 2024 19:33:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN3PEPF0000B077.mail.protection.outlook.com (10.167.243.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 19:33:35 +0000 Received: from tlendack-t1.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 28 Oct 2024 14:33:34 -0500 From: Tom Lendacky To: , CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Michael Roth , Ashish Kalra , Nikunj A Dadhania , Neeraj Upadhyay Subject: [PATCH v5 5/8] x86/sev: Map only the RMP table entries instead of the full RMP range Date: Mon, 28 Oct 2024 14:32:40 -0500 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B077:EE_|DM4PR12MB7742:EE_ X-MS-Office365-Filtering-Correlation-Id: 5de6db3c-3735-4b36-f25f-08dcf7876a05 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?FwBBrpp+YXK83m21C15V73ThqpC8RVBh18No1nsJwhRYnKEIAEbOzGxYMf/m?= =?us-ascii?Q?5zRdthalovzEA8HFjoBlCfct0CKI45bA1WHeKZN0Na3uUQtpeZELcg28K3/0?= =?us-ascii?Q?Wg0TsyJqyJZU//bh9qNFQCkQjXN9Qc/IQX/x9HHOvOgNRPVPE+//t7QURJRa?= =?us-ascii?Q?g47aKvBivZnrHTwcEoKsQW+5mArSc/ctHtiVY/YGO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5u0rrJoGUuD4HL8NRaO5pdJT5kNlhSkXsgBgXylqtR8YTB0W+dW?= =?us-ascii?Q?J5UsuB7/Pe9Xzb8ZN73tx8UeuVAIU+F0ZoLYuY5S9wPoS/yD/99eYS7ou8LW?= =?us-ascii?Q?mOoQw5Q2yMV8A8w1Ku57IWBGeAHg+f8aveaPP4UVIDysgs4pr0UGDW3kjHES?= =?us-ascii?Q?KkJzsdSc1iK44mQTh1Rtyzfi3kmTN1wR5nNVSQp+5p6Rz0du25+GW6bgS7p+?= =?us-ascii?Q?FLeYeLQEcnLimLIQ1GmUK/Tf4fkYbEb2SuE5CCqFo7nSDUgpQMDngkex5Pac?= =?us-ascii?Q?ICVAMKSSkZWbdz+odO5xNZEbaHVOrj7fuZTzQsNcgynRsJ5WyA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 19:33:35.0563 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5de6db3c-3735-4b36-f25f-08dcf7876a05 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B077.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7742 Content-Type: text/plain; charset="utf-8" In preparation for support of a segmented RMP table, map only the RMP table entries. The RMP bookkeeping area is only ever accessed when first enabling SNP and does not need to remain mapped. To accomplish this, split the initialization of the RMP bookkeeping area and the initialization of the RMP entry area. The RMP bookkeeping area will be mapped only while it is being initialized. Signed-off-by: Tom Lendacky Reviewed-by: Nikunj A Dadhania Reviewed-by: Neeraj Upadhyay --- arch/x86/virt/svm/sev.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c index 0b778cf7fa3d..5871c924c0b2 100644 --- a/arch/x86/virt/svm/sev.c +++ b/arch/x86/virt/svm/sev.c @@ -173,6 +173,23 @@ void __init snp_fixup_e820_tables(void) __snp_fixup_e820_tables(probed_rmp_base + probed_rmp_size); } =20 +static bool __init init_rmptable_bookkeeping(void) +{ + void *bk; + + bk =3D memremap(probed_rmp_base, RMPTABLE_CPU_BOOKKEEPING_SZ, MEMREMAP_WB= ); + if (!bk) { + pr_err("Failed to map RMP bookkeeping area\n"); + return false; + } + + memset(bk, 0, RMPTABLE_CPU_BOOKKEEPING_SZ); + + memunmap(bk); + + return true; +} + /* * Do the necessary preparations which are verified by the firmware as * described in the SNP_INIT_EX firmware command description in the SNP @@ -210,12 +227,17 @@ static int __init snp_rmptable_init(void) goto nosnp; } =20 - rmptable_start =3D memremap(probed_rmp_base, probed_rmp_size, MEMREMAP_WB= ); + /* Map only the RMP entries */ + rmptable_start =3D memremap(probed_rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ, + probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ, + MEMREMAP_WB); if (!rmptable_start) { pr_err("Failed to map RMP table\n"); goto nosnp; } =20 + rmptable_size =3D probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ; + /* * Check if SEV-SNP is already enabled, this can happen in case of * kexec boot. @@ -224,7 +246,14 @@ static int __init snp_rmptable_init(void) if (val & MSR_AMD64_SYSCFG_SNP_EN) goto skip_enable; =20 - memset(rmptable_start, 0, probed_rmp_size); + /* Zero out the RMP bookkeeping area */ + if (!init_rmptable_bookkeeping()) { + memunmap(rmptable_start); + goto nosnp; + } + + /* Zero out the RMP entries */ + memset(rmptable_start, 0, rmptable_size); =20 /* Flush the caches to ensure that data is written before SNP is enabled.= */ wbinvd_on_all_cpus(); @@ -235,9 +264,6 @@ static int __init snp_rmptable_init(void) on_each_cpu(snp_enable, NULL, 1); =20 skip_enable: - rmptable_start +=3D RMPTABLE_CPU_BOOKKEEPING_SZ; - rmptable_size =3D probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ; - rmptable =3D (struct rmpentry_raw *)rmptable_start; rmptable_max_pfn =3D rmptable_size / sizeof(struct rmpentry_raw) - 1; =20 --=20 2.46.2