The use of smp_call_function_many() in kvm_emulate_wbinvd_noskip()
KVM is none of my business these days, but I was reviewing the use of smp_call_function_many(), as I made some changes to related code. During this review, I was looking at kvm_emulate_wbinvd_noskip(), and it seems wrong to me.
As you may or might now know, smp_call_function_many() does not execute the provided function on the local core. Considering this behavior, I am not sure the behavior of kvm_emulate_wbinvd_noskip() is correct. IIUC, there is an expectation that wbinvd_ipi() would run on the local core, but it would not.
If this behavior is wrong, consider using on_each_cpu_mask() instead of smp_call_function_many().
To be fair, I guess do not understand the code too well, since it really looks all racy to me (clearing wbinvd_dirty_mask instead of clearing local CPU from wbinvd_ipi()).
static int kvm_emulate_wbinvd_noskip(struct kvm_vcpu *vcpu)
{
if (!need_emulate_wbinvd(vcpu))
return X86EMUL_CONTINUE;
if (static_call(kvm_x86_has_wbinvd_exit)()) {
int cpu = get_cpu();
cpumask_set_cpu(cpu, vcpu->arch.wbinvd_dirty_mask);
smp_call_function_many(vcpu->arch.wbinvd_dirty_mask,
wbinvd_ipi, NULL, 1);
put_cpu();
cpumask_clear(vcpu->arch.wbinvd_dirty_mask);
} else
wbinvd();
return X86EMUL_CONTINUE;
}