mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ashish Kalra <Ashish.Kalra@amd.com>
To: <tglx@kernel.org>, <mingo@redhat.com>, <bp@alien8.de>,
	<dave.hansen@linux.intel.com>, <x86@kernel.org>, <hpa@zytor.com>,
	<seanjc@google.com>, <peterz@infradead.org>,
	<thomas.lendacky@amd.com>, <herbert@gondor.apana.org.au>,
	<davem@davemloft.net>, <ardb@kernel.org>
Cc: <pbonzini@redhat.com>, <aik@amd.com>, <Michael.Roth@amd.com>,
	<KPrateek.Nayak@amd.com>, <Tycho.Andersen@amd.com>,
	<Nathan.Fontenot@amd.com>, <ackerleytng@google.com>,
	<jackyli@google.com>, <pgonda@google.com>, <rientjes@google.com>,
	<jacobhxu@google.com>, <nikunj@amd.com>,
	<linux-kernel@vger.kernel.org>, <kvm@vger.kernel.org>,
	<linux-coco@lists.linux.dev>
Subject: [PATCH 1/2] x86/sev: Scan each core's own RMPOPT window
Date: Mon, 9 Nov 2026 21:05:48 +0000	[thread overview]
Message-ID: <2f541fd5481938bf2604397dc7bd554eb5c884c4.1794257678.git.ashish.kalra@amd.com> (raw)
In-Reply-To: <cover.1793921823.git.ashish.kalra@amd.com>

From: Ashish Kalra <ashish.kalra@amd.com>

rmpopt_scan_range() walked a single global [rmpopt_pa_start, rmpopt_pa_end]
range, which is only correct while every core shares one window.  Read the
executing core's own RMPOPT_BASE instead and walk only that window, so each
core optimizes the window its own RMPOPT_BASE points at.

The window is described entirely by the RMPOPT_BASE MSR: RMPOPT_BASE_ADDR
(bits 51:30) is the 1 GB-aligned base and RMPOPT_TABLE_SIZE (bits 22:1) is
the window size in GB.  Walk [base, base + size), clamped to the top of
populated memory.

Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
---
 arch/x86/include/asm/msr-index.h |  2 ++
 arch/x86/virt/svm/sev.c          | 29 +++++++++++++++--------------
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index c0914829a925..6d453bb13621 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -773,6 +773,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)
+#define MSR_AMD64_RMPOPT_TABLE_SIZE	GENMASK_ULL(22, 1)
+#define MSR_AMD64_RMPOPT_BASE_ADDR	GENMASK_ULL(51, 30)
 
 #define MSR_SVSM_CAA			0xc001f000
 
diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
index 4de9681cc2f8..a2756b18d5f7 100644
--- a/arch/x86/virt/svm/sev.c
+++ b/arch/x86/virt/svm/sev.c
@@ -8,6 +8,7 @@
  *
  */
 
+#include <linux/bitfield.h>
 #include <linux/cc_platform.h>
 #include <linux/printk.h>
 #include <linux/mm_types.h>
@@ -125,8 +126,6 @@ static void *rmp_bookkeeping __ro_after_init;
 
 static u64 probed_rmp_base, probed_rmp_size;
 
-static u64 rmpopt_pa_start, rmpopt_pa_end;
-
 enum rmpopt_op_type {
 	RMPOPT_OP_VERIFY_AND_REPORT_STATUS,
 	RMPOPT_OP_REPORT_STATUS
@@ -618,11 +617,18 @@ static void rmpopt(u64 pa)
 		     : "memory", "cc");
 }
 
+/* A core can only RMPOPT within its own window, [base, base + size). */
 static void rmpopt_scan_range(void *arg)
 {
-	u64 pa;
+	u64 msr, base, end, pa;
+	unsigned int size_gb;
+
+	rdmsrq(MSR_AMD64_RMPOPT_BASE, msr);
+	base = msr & MSR_AMD64_RMPOPT_BASE_ADDR;
+	size_gb = FIELD_GET(MSR_AMD64_RMPOPT_TABLE_SIZE, msr);
+	end = min_t(u64, base + (u64)size_gb * SZ_1G, ALIGN(PFN_PHYS(max_pfn), SZ_1G));
 
-	for (pa = rmpopt_pa_start; pa < rmpopt_pa_end; pa += SZ_1G)
+	for (pa = base; pa < end; pa += SZ_1G)
 		rmpopt(pa);
 }
 
@@ -650,12 +656,6 @@ static int __init rmpopt_init(void)
 
 	INIT_DELAYED_WORK(&rmpopt_delayed_work, do_rmpopt_work);
 
-	/* The optimization range is fixed at boot; compute it once. */
-	rmpopt_pa_start = ALIGN_DOWN(PFN_PHYS(min_low_pfn), SZ_1G);
-	rmpopt_pa_end = ALIGN(PFN_PHYS(max_pfn), SZ_1G);
-	if ((rmpopt_pa_end - rmpopt_pa_start) > SZ_2T)
-		rmpopt_pa_end = rmpopt_pa_start + SZ_2T;
-
 	pr_info("RMPOPT optimizations enabled\n");
 
 	rmpopt_soft_init = true;
@@ -665,7 +665,7 @@ static int __init rmpopt_init(void)
 
 void snp_enable_rmpopt(void)
 {
-	u64 base;
+	u64 base, pa_start;
 	int cpu;
 
 	if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))
@@ -678,14 +678,15 @@ void snp_enable_rmpopt(void)
 		return;
 
 	/*
-	 * Per-CPU RMPOPT tables cover at most 2 TB.  Program each core's
-	 * RMPOPT_BASE with the start of RAM to optimize up to 2 TB.
+	 * A core's RMPOPT_BASE covers at most 2 TB.  Program every core with
+	 * the start of RAM to optimize up to 2 TB.
 	 */
+	pa_start = ALIGN_DOWN(PFN_PHYS(min_low_pfn), SZ_1G);
 	rdmsrq(MSR_AMD64_RMPOPT_BASE, base);
 	if (!(base & MSR_AMD64_RMPOPT_ENABLE))
 		for_each_cpu(cpu, cpu_primary_thread_mask)
 			wrmsrq_on_cpu(cpu, MSR_AMD64_RMPOPT_BASE,
-				      rmpopt_pa_start | MSR_AMD64_RMPOPT_ENABLE);
+				      pa_start | MSR_AMD64_RMPOPT_ENABLE);
 
 	mod_delayed_work(rmpopt_wq, &rmpopt_delayed_work,
 			 msecs_to_jiffies(RMPOPT_WORK_TIMEOUT));
-- 
2.43.0


  reply	other threads:[~2026-11-09 21:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 21:05 [PATCH 0/2] x86/sev: Per-node RMPOPT windows for >2TB systems Ashish Kalra
2026-11-09 21:05 ` Ashish Kalra [this message]
2026-11-09 21:06 ` [PATCH 2/2] x86/sev: Add per-node " Ashish Kalra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2f541fd5481938bf2604397dc7bd554eb5c884c4.1794257678.git.ashish.kalra@amd.com \
    --to=ashish.kalra@amd.com \
    --cc=KPrateek.Nayak@amd.com \
    --cc=Michael.Roth@amd.com \
    --cc=Nathan.Fontenot@amd.com \
    --cc=Tycho.Andersen@amd.com \
    --cc=ackerleytng@google.com \
    --cc=aik@amd.com \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=jackyli@google.com \
    --cc=jacobhxu@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nikunj@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=pgonda@google.com \
    --cc=rientjes@google.com \
    --cc=seanjc@google.com \
    --cc=tglx@kernel.org \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®