Re: [PATCH 2/6] x86/sev: add support for enabling RMPOPT

From: Dave Hansen

Date: Wed Feb 18 2026 - 09:59:45 EST


On 2/17/26 19:08, K Prateek Nayak wrote:
> Hello Dave,
>
> On 2/18/2026 3:36 AM, Dave Hansen wrote:
>>> +/*
>>> + * Build a cpumask of online primary threads, accounting for primary threads
>>> + * that have been offlined while their secondary threads are still online.
>>> + */
>>> +static void get_cpumask_of_primary_threads(cpumask_var_t cpulist)
>>> +{
>>> + cpumask_t cpus;
>>> + int cpu;
>>> +
>>> + cpumask_copy(&cpus, cpu_online_mask);
>>> + for_each_cpu(cpu, &cpus) {
>>> + cpumask_set_cpu(cpu, cpulist);
>>> + cpumask_andnot(&cpus, &cpus, cpu_smt_mask(cpu));
>>> + }
>>> +}
>>
>> Don't we have a primary thread mask already? I thought we did.
>
> If you are referring to cpu_primary_thread_mask(), the CPUs are set on it
> based on the LSB of APICID, specifically:
>
> !(apicid & (__max_threads_per_core - 1))
>
> It can so happen, the primary thread ((apicid & 1) == 0) of the core is
> offline while the secondary thread ((apicid & 1) == 1) is online but the
> traversal of (cpu_primary_thread_mask() & cpu_online_mask()) will simply
> skip these cores.
>
> Is there an equivalent mask that sets the first online CPU of each core?

No I don't think we have that sitting around.

But, stepping back, why is this even necessary? Is it just saving a few
IPIs in the super rare case that someone has offlined the primary thread
but not a secondary one?

Why bother?