Re: [PATCHv2] x86/hyperv: Hold cpus_read_lock() on assigning reenlightenment vector

From: Thomas Gleixner
Date: Thu Jun 27 2019 - 18:39:56 EST


On Mon, 17 Jun 2019, Dmitry Safonov wrote:
> @@ -196,7 +196,16 @@ void set_hv_tscchange_cb(void (*cb)(void))
> /* Make sure callback is registered before we write to MSRs */
> wmb();
>
> + /*
> + * As reenlightenment vector is global, there is no difference which
> + * CPU will register MSR, though it should be an online CPU.
> + * hv_cpu_die() callback guarantees that on CPU teardown
> + * another CPU will re-register MSR back.
> + */
> + cpus_read_lock();
> + re_ctrl.target_vp = hv_vp_index[raw_smp_processor_id()];
> wrmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl));
> + cpus_read_unlock();

Should work

> wrmsrl(HV_X64_MSR_TSC_EMULATION_CONTROL, *((u64 *)&emu_ctrl));
> }
> EXPORT_SYMBOL_GPL(set_hv_tscchange_cb);
> @@ -239,6 +248,7 @@ static int hv_cpu_die(unsigned int cpu)
>
> rdmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl));
> if (re_ctrl.target_vp == hv_vp_index[cpu]) {
> + lockdep_assert_cpus_held();

So you're not trusting the hotplug core code to hold the lock when it
brings a CPU down and invokes that callback? Come on

> /* Reassign to some other online CPU */
> new_cpu = cpumask_any_but(cpu_online_mask, cpu);

Thanks,

tglx