Re: [PATCH v10 2/6] x86/sev: Initialize RMPOPT configuration MSRs
From: Borislav Petkov
Date: Wed Jul 22 2026 - 21:11:41 EST
On Tue, Jun 30, 2026 at 06:10:13PM +0000, Ashish Kalra wrote:
> +static void rmpopt_cleanup(void)
> +{
> + int cpu;
> +
> + scoped_guard(cpus_read_lock) {
> + for_each_cpu(cpu, rmpopt_cpumask)
> + wrmsrq_on_cpu(cpu, MSR_AMD64_RMPOPT_BASE, 0);
> + }
> +
> + free_cpumask_var(rmpopt_cpumask);
The counterpart function which allocates this cpumask is called
snp_setup_rmpopt(). I'm guessing then this one should be called
snp_cleanup_rmpopt(). For balance...
...
> +void snp_setup_rmpopt(void)
> +{
> + u64 rmpopt_base;
> + int cpu;
> +
> + if (!cpu_feature_enabled(X86_FEATURE_RMPOPT) || !rmpopt_capable)
> + return;
> +
> + if (!zalloc_cpumask_var(&rmpopt_cpumask, GFP_KERNEL)) {
> + pr_err("Failed to allocate RMPOPT cpumask\n");
> + return;
> + }
> +
> + /*
> + * The RMPOPT_BASE MSR is per-core, so only one thread per core needs
> + * to set up the RMPOPT_BASE MSR.
> + *
> + * Note: only online primary threads are included. If a core's
> + * primary thread is offline, that core is not covered. CPU hotplug
So what happens if not all cores are online?
This should check that and fail if that is the case instead of blindly
continuing here.
> + * is not currently supported with SNP enabled.
> + */
> + scoped_guard(cpus_read_lock) {
> + for_each_online_cpu(cpu)
> + if (topology_is_primary_thread(cpu))
> + cpumask_set_cpu(cpu, rmpopt_cpumask);
> +
> + rmpopt_pa_start = ALIGN_DOWN(PFN_PHYS(min_low_pfn), SZ_1G);
> + rmpopt_base = rmpopt_pa_start | MSR_AMD64_RMPOPT_ENABLE;
> +
> + /*
> + * 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 to enable RMP optimizations for
> + * up to 2 TB of system RAM on all CPUs.
> + */
Simplify this comment.
> + for_each_cpu(cpu, rmpopt_cpumask)
> + wrmsrq_on_cpu(cpu, MSR_AMD64_RMPOPT_BASE, rmpopt_base);
> + }
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette