diff options
| author | Arnaldo Carvalho de Melo <[email protected]> | 2020-03-04 13:29:19 +0000 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <[email protected]> | 2020-03-04 13:29:19 +0000 |
| commit | d46eec8e975a8180e178e01ba505801c44bc9a6c (patch) | |
| tree | bff067e554fc03c576e107297085d30c8e381370 /virt/kvm/kvm_main.c | |
| parent | perf/x86: Add Intel Tiger Lake uncore support (diff) | |
| parent | perf diff: Fix undefined string comparison spotted by clang's -Wstring-compare (diff) | |
| download | kernel-d46eec8e975a8180e178e01ba505801c44bc9a6c.tar.gz kernel-d46eec8e975a8180e178e01ba505801c44bc9a6c.zip | |
Merge remote-tracking branch 'acme/perf/urgent' into perf/core
To pick up fixes.
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Diffstat (limited to 'virt/kvm/kvm_main.c')
| -rw-r--r-- | virt/kvm/kvm_main.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 67ae2d5c37b2..70f03ce0e5c1 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4409,12 +4409,22 @@ static void kvm_sched_out(struct preempt_notifier *pn, /** * kvm_get_running_vcpu - get the vcpu running on the current CPU. - * Thanks to preempt notifiers, this can also be called from - * preemptible context. + * + * We can disable preemption locally around accessing the per-CPU variable, + * and use the resolved vcpu pointer after enabling preemption again, + * because even if the current thread is migrated to another CPU, reading + * the per-CPU value later will give us the same value as we update the + * per-CPU variable in the preempt notifier handlers. */ struct kvm_vcpu *kvm_get_running_vcpu(void) { - return __this_cpu_read(kvm_running_vcpu); + struct kvm_vcpu *vcpu; + + preempt_disable(); + vcpu = __this_cpu_read(kvm_running_vcpu); + preempt_enable(); + + return vcpu; } /** |
