Commit a0aace5a authored by Radim Krčmář's avatar Radim Krčmář Committed by Paolo Bonzini

KVM: i8254: turn kvm_kpit_state.reinject into atomic_t

Document possible races between readers and concurrent update to the
ioctl.
Suggested-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent ab4c1476
...@@ -264,7 +264,7 @@ static void pit_do_work(struct kthread_work *work) ...@@ -264,7 +264,7 @@ static void pit_do_work(struct kthread_work *work)
int i; int i;
struct kvm_kpit_state *ps = &pit->pit_state; struct kvm_kpit_state *ps = &pit->pit_state;
if (ps->reinject && !atomic_xchg(&ps->irq_ack, 0)) if (atomic_read(&ps->reinject) && !atomic_xchg(&ps->irq_ack, 0))
return; return;
kvm_set_irq(kvm, pit->irq_source_id, 0, 1, false); kvm_set_irq(kvm, pit->irq_source_id, 0, 1, false);
...@@ -289,7 +289,7 @@ static enum hrtimer_restart pit_timer_fn(struct hrtimer *data) ...@@ -289,7 +289,7 @@ static enum hrtimer_restart pit_timer_fn(struct hrtimer *data)
struct kvm_kpit_state *ps = container_of(data, struct kvm_kpit_state, timer); struct kvm_kpit_state *ps = container_of(data, struct kvm_kpit_state, timer);
struct kvm_pit *pt = pit_state_to_pit(ps); struct kvm_pit *pt = pit_state_to_pit(ps);
if (ps->reinject) if (atomic_read(&ps->reinject))
atomic_inc(&ps->pending); atomic_inc(&ps->pending);
queue_kthread_work(&pt->worker, &pt->expired); queue_kthread_work(&pt->worker, &pt->expired);
...@@ -312,7 +312,7 @@ void kvm_pit_set_reinject(struct kvm_pit *pit, bool reinject) ...@@ -312,7 +312,7 @@ void kvm_pit_set_reinject(struct kvm_pit *pit, bool reinject)
struct kvm_kpit_state *ps = &pit->pit_state; struct kvm_kpit_state *ps = &pit->pit_state;
struct kvm *kvm = pit->kvm; struct kvm *kvm = pit->kvm;
if (ps->reinject == reinject) if (atomic_read(&ps->reinject) == reinject)
return; return;
if (reinject) { if (reinject) {
...@@ -325,7 +325,7 @@ void kvm_pit_set_reinject(struct kvm_pit *pit, bool reinject) ...@@ -325,7 +325,7 @@ void kvm_pit_set_reinject(struct kvm_pit *pit, bool reinject)
kvm_unregister_irq_mask_notifier(kvm, 0, &pit->mask_notifier); kvm_unregister_irq_mask_notifier(kvm, 0, &pit->mask_notifier);
} }
ps->reinject = reinject; atomic_set(&ps->reinject, reinject);
} }
static void create_pit_timer(struct kvm_pit *pit, u32 val, int is_period) static void create_pit_timer(struct kvm_pit *pit, u32 val, int is_period)
......
...@@ -31,7 +31,7 @@ struct kvm_kpit_state { ...@@ -31,7 +31,7 @@ struct kvm_kpit_state {
u32 speaker_data_on; u32 speaker_data_on;
struct mutex lock; struct mutex lock;
bool reinject; atomic_t reinject;
atomic_t pending; /* accumulated triggered timers */ atomic_t pending; /* accumulated triggered timers */
atomic_t irq_ack; atomic_t irq_ack;
struct kvm_irq_ack_notifier irq_ack_notifier; struct kvm_irq_ack_notifier irq_ack_notifier;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment