Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1428578
| From | Christian Borntraeger <borntraeger@de.ibm.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] static_key: fix concurrent static_key_slow_inc |
| Date | 2016-06-22 11:00 +0200 |
| Message-ID | <rMMaR-19U-3@gated-at.bofh.it> (permalink) |
| References | <rMxlw-eK-41@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 06/21/2016 06:52 PM, Paolo Bonzini wrote:
> The following scenario is possible:
>
> CPU 1 CPU 2
> static_key_slow_inc
> atomic_inc_not_zero
> -> key.enabled == 0, no increment
> jump_label_lock
> atomic_inc_return
> -> key.enabled == 1 now
> static_key_slow_inc
> atomic_inc_not_zero
> -> key.enabled == 1, inc to 2
> return
> ** static key is wrong!
> jump_label_update
> jump_label_unlock
>
> Testing the static key at the point marked by (**) will follow the wrong
> path for jumps that have not been patched yet. This can actually happen
> when creating many KVM virtual machines with userspace LAPIC emulation;
> just run several copies of the following program:
>
> #include <fcntl.h>
> #include <unistd.h>
> #include <sys/ioctl.h>
> #include <linux/kvm.h>
>
> int main(void)
> {
> for (;;) {
> int kvmfd = open("/dev/kvm", O_RDONLY);
> int vmfd = ioctl(kvmfd, KVM_CREATE_VM, 0);
> close(ioctl(vmfd, KVM_CREATE_VCPU, 1));
> close(vmfd);
> close(kvmfd);
> }
> return 0;
> }
>
> Every KVM_CREATE_VCPU ioctl will attempt a static_key_slow_inc. The
> static key's purpose is to skip NULL pointer checks and indeed one of
> the processes eventually dereferences NULL.
Interesting. Some time ago I had a spurious bug on the preempt_notifier
when starting/stopping lots of guests, but I was never able to reliably
reproduce it. I was chasing some other bug, so I did not even considered
static_key to be broken, but this might actually be the fix for that
problem.
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] static_key: fix concurrent static_key_slow_inc Paolo Bonzini <pbonzini@redhat.com> - 2016-06-21 19:10 +0200
Re: [PATCH] static_key: fix concurrent static_key_slow_inc Peter Zijlstra <peterz@infradead.org> - 2016-06-21 21:30 +0200
Re: [PATCH] static_key: fix concurrent static_key_slow_inc Christian Borntraeger <borntraeger@de.ibm.com> - 2016-06-22 11:00 +0200
Re: [PATCH] static_key: fix concurrent static_key_slow_inc Paolo Bonzini <pbonzini@redhat.com> - 2016-06-22 12:10 +0200
csiph-web