[PATCH] ARM: spectre-v2: fix smp_processor_id() warning

Tetsuo Handa penguin-kernel at I-love.SAKURA.ne.jp
Wed Jun 22 06:31:28 PDT 2022


On 2022/06/22 20:21, Russell King (Oracle) wrote:
>>  static inline void harden_branch_predictor(void)
>>  {
>> -	harden_branch_predictor_fn_t fn = per_cpu(harden_branch_predictor_fn,
>> -						  smp_processor_id());
>> +	harden_branch_predictor_fn_t fn;
>> +
>> +	preempt_disable_notrace();
>> +	fn = per_cpu(harden_branch_predictor_fn, raw_smp_processor_id());
>> +	preempt_enable_no_resched_notrace();
>>  	if (fn)
>>  		fn();
> 
> The idea is to get the function for the specific CPU, and then to run it
> _on_ that CPU, and in theory the CPU that took the fault. However, I
> seem to remember there are issues trying to achieve that, and I don't
> have a solution for it.

Hmm, since some ARM processors support Asymmetric Multiprocessing, whether
invalidation is needed depends on which processor was assigned, and that's
the reason smp_processor_id() is used?

I'm not familiar with hardware, but if a CPU assigned to current thread
changes, wouldn't sufficient invalidation take place? In other words, do
we need to worry about fn() call if the CPU that took the fault and the CPU
which runs the code after harden_branch_predictor() returned differs?

If some instructions for CPU-A is not supported by CPU-B, I guess that
reading instructions for CPU-A at per_cpu(harden_branch_predictor_fn) and
executing instructions on CPU-B at fn() causes problems. Is it guaranteed
that all instructions used by fn() are supported by all processors?
If it is not guaranteed, we would need to make sure that fn() runs on a CPU
which per_cpu(harden_branch_predictor_fn) was done for?




More information about the linux-arm-kernel mailing list