From nobody Sun Feb 8 05:29:50 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 0AB271A8F90; Sat, 14 Dec 2024 18:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734202074; cv=none; b=h4GSSra85xOT4wCDrjVWaPk8e9d5fzqlEDPp67KR+qQtFlM2NYSENPkXsJzptr1wXLUMMxhMH6LCB9tBfwwqUGOhBmlBwwiWAbCj2yF4CJjcJ33aTd81Mjj2I6nrcxEm+VZiW+Vkmq/9JZ2EEegGUbkbGu2yR7uDmfqjCHwhtuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734202074; c=relaxed/simple; bh=tsebOpwp1V0lb9iI5cgxobFqWyLEj8UwTelApjx/EpQ=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=pQ8JcJtVyKefozyrCY5RaNZ1IAeuwfxBXNSZv+2yTnfdLMvTulxU9T02EmREjsaIDVB/7Yf7J+dT97TU+y2vzYPRQvmOmm3zHWTfMyCRHG/RSfOHoIWEQJcut4HKc+ZoK7JE0u82CUifSwEfuboWEBlF0XtRPy+y0Dnqh5bmtnc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jJmyxHy0; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IkTKFPzf; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jJmyxHy0"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IkTKFPzf" Date: Sat, 14 Dec 2024 18:47:50 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1734202071; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K0JHIAAhCRkDuR3sr+QivcBqyBOnipyqYAn4dfhz/MM=; b=jJmyxHy0uW97j5F7I9Zcqi9AWwf3aHg9XVPej7FRd67oGdJyPiKKB2OyZ/CqW0juSDpfjK oTFudds6l2qeDyrQZvIgbOLFEa2LQNTFRNqRBI9qY6JV8Z+fjpmdB4pqesl1ek5S+TV1gE HR0TbhC/PHW+X7ZgmbovJ5xJpUNztNUxyKBoJXAAW80QM0DIbGcS5BvATxXT1kg+DiQ3Dw 3Mpldcg4q4r8i5eUElm+CZKm9Um7VshbP2N1+MFlLEQS1espeYpZrrRisEStHqAu+Gra3e SaHSwCh7OfKKbj9+dQU74YnzlTTrKoo3S7rK5Gn+fiveQQUnxXGUApKVapUELQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1734202071; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K0JHIAAhCRkDuR3sr+QivcBqyBOnipyqYAn4dfhz/MM=; b=IkTKFPzfRKD9x45QDM5pRcdcEYn75/eAClFnrGgMKrY+SR+2lt0qPVPNTQ4GPUU8Y86RhC 3q1qEKS2M9KzAFBA== From: "tip-bot2 for Tom Lendacky" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/sev] x86/sev: Map only the RMP table entries instead of the full RMP range Cc: Tom Lendacky , "Borislav Petkov (AMD)" , Nikunj A Dadhania , Neeraj Upadhyay , Ashish Kalra , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: =?utf-8?q?=3C22f179998d319834f49c13a8c01187fbf0fd308d=2E17331?= =?utf-8?q?72653=2Egit=2Ethomas=2Elendacky=40amd=2Ecom=3E?= References: =?utf-8?q?=3C22f179998d319834f49c13a8c01187fbf0fd308d=2E173317?= =?utf-8?q?2653=2Egit=2Ethomas=2Elendacky=40amd=2Ecom=3E?= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <173420207030.412.6865329333499137563.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/sev branch of tip: Commit-ID: ac517965a5a12d685f1e7a7f77e64503167f87d5 Gitweb: https://git.kernel.org/tip/ac517965a5a12d685f1e7a7f77e645031= 67f87d5 Author: Tom Lendacky AuthorDate: Mon, 02 Dec 2024 14:50:50 -06:00 Committer: Borislav Petkov (AMD) CommitterDate: Sat, 14 Dec 2024 11:39:02 +01:00 x86/sev: Map only the RMP table entries instead of the full RMP range 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 Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Nikunj A Dadhania Reviewed-by: Neeraj Upadhyay Reviewed-by: Ashish Kalra Link: https://lore.kernel.org/r/22f179998d319834f49c13a8c01187fbf0fd308d.17= 33172653.git.thomas.lendacky@amd.com --- 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 0df3789..2899c2e 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 clear_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 (!clear_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;