diff options
-rw-r--r-- | Documentation/virtual/kvm/api.txt | 8 | ||||
-rw-r--r-- | arch/x86/kvm/i8254.c | 31 | ||||
-rw-r--r-- | arch/x86/kvm/i8254.h | 7 |
3 files changed, 32 insertions, 14 deletions
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index a7cb93cb215..eb62761b768 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt | |||
@@ -1810,6 +1810,14 @@ Valid flags are: | |||
1810 | 1810 | ||
1811 | #define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */ | 1811 | #define KVM_PIT_SPEAKER_DUMMY 1 /* emulate speaker port stub */ |
1812 | 1812 | ||
1813 | PIT timer interrupts may use a per-VM kernel thread for injection. If it | ||
1814 | exists, this thread will have a name of the following pattern: | ||
1815 | |||
1816 | kvm-pit/<owner-process-pid> | ||
1817 | |||
1818 | When running a guest with elevated priorities, the scheduling parameters of | ||
1819 | this thread may have to be adjusted accordingly. | ||
1820 | |||
1813 | This IOCTL replaces the obsolete KVM_CREATE_PIT. | 1821 | This IOCTL replaces the obsolete KVM_CREATE_PIT. |
1814 | 1822 | ||
1815 | 1823 | ||
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c index d68f99df690..adba28f88d1 100644 --- a/arch/x86/kvm/i8254.c +++ b/arch/x86/kvm/i8254.c | |||
@@ -34,7 +34,6 @@ | |||
34 | 34 | ||
35 | #include <linux/kvm_host.h> | 35 | #include <linux/kvm_host.h> |
36 | #include <linux/slab.h> | 36 | #include <linux/slab.h> |
37 | #include <linux/workqueue.h> | ||
38 | 37 | ||
39 | #include "irq.h" | 38 | #include "irq.h" |
40 | #include "i8254.h" | 39 | #include "i8254.h" |
@@ -249,7 +248,7 @@ static void kvm_pit_ack_irq(struct kvm_irq_ack_notifier *kian) | |||
249 | /* in this case, we had multiple outstanding pit interrupts | 248 | /* in this case, we had multiple outstanding pit interrupts |
250 | * that we needed to inject. Reinject | 249 | * that we needed to inject. Reinject |
251 | */ | 250 | */ |
252 | queue_work(ps->pit->wq, &ps->pit->expired); | 251 | queue_kthread_work(&ps->pit->worker, &ps->pit->expired); |
253 | ps->irq_ack = 1; | 252 | ps->irq_ack = 1; |
254 | spin_unlock(&ps->inject_lock); | 253 | spin_unlock(&ps->inject_lock); |
255 | } | 254 | } |
@@ -270,7 +269,7 @@ void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu) | |||
270 | static void destroy_pit_timer(struct kvm_pit *pit) | 269 | static void destroy_pit_timer(struct kvm_pit *pit) |
271 | { | 270 | { |
272 | hrtimer_cancel(&pit->pit_state.pit_timer.timer); | 271 | hrtimer_cancel(&pit->pit_state.pit_timer.timer); |
273 | cancel_work_sync(&pit->expired); | 272 | flush_kthread_work(&pit->expired); |
274 | } | 273 | } |
275 | 274 | ||
276 | static bool kpit_is_periodic(struct kvm_timer *ktimer) | 275 | static bool kpit_is_periodic(struct kvm_timer *ktimer) |
@@ -284,7 +283,7 @@ static struct kvm_timer_ops kpit_ops = { | |||
284 | .is_periodic = kpit_is_periodic, | 283 | .is_periodic = kpit_is_periodic, |
285 | }; | 284 | }; |
286 | 285 | ||
287 | static void pit_do_work(struct work_struct *work) | 286 | static void pit_do_work(struct kthread_work *work) |
288 | { | 287 | { |
289 | struct kvm_pit *pit = container_of(work, struct kvm_pit, expired); | 288 | struct kvm_pit *pit = container_of(work, struct kvm_pit, expired); |
290 | struct kvm *kvm = pit->kvm; | 289 | struct kvm *kvm = pit->kvm; |
@@ -328,7 +327,7 @@ static enum hrtimer_restart pit_timer_fn(struct hrtimer *data) | |||
328 | 327 | ||
329 | if (ktimer->reinject || !atomic_read(&ktimer->pending)) { | 328 | if (ktimer->reinject || !atomic_read(&ktimer->pending)) { |
330 | atomic_inc(&ktimer->pending); | 329 | atomic_inc(&ktimer->pending); |
331 | queue_work(pt->wq, &pt->expired); | 330 | queue_kthread_work(&pt->worker, &pt->expired); |
332 | } | 331 | } |
333 | 332 | ||
334 | if (ktimer->t_ops->is_periodic(ktimer)) { | 333 | if (ktimer->t_ops->is_periodic(ktimer)) { |
@@ -353,7 +352,7 @@ static void create_pit_timer(struct kvm *kvm, u32 val, int is_period) | |||
353 | 352 | ||
354 | /* TODO The new value only affected after the retriggered */ | 353 | /* TODO The new value only affected after the retriggered */ |
355 | hrtimer_cancel(&pt->timer); | 354 | hrtimer_cancel(&pt->timer); |
356 | cancel_work_sync(&ps->pit->expired); | 355 | flush_kthread_work(&ps->pit->expired); |
357 | pt->period = interval; | 356 | pt->period = interval; |
358 | ps->is_periodic = is_period; | 357 | ps->is_periodic = is_period; |
359 | 358 | ||
@@ -669,6 +668,8 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags) | |||
669 | { | 668 | { |
670 | struct kvm_pit *pit; | 669 | struct kvm_pit *pit; |
671 | struct kvm_kpit_state *pit_state; | 670 | struct kvm_kpit_state *pit_state; |
671 | struct pid *pid; | ||
672 | pid_t pid_nr; | ||
672 | int ret; | 673 | int ret; |
673 | 674 | ||
674 | pit = kzalloc(sizeof(struct kvm_pit), GFP_KERNEL); | 675 | pit = kzalloc(sizeof(struct kvm_pit), GFP_KERNEL); |
@@ -685,14 +686,20 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags) | |||
685 | mutex_lock(&pit->pit_state.lock); | 686 | mutex_lock(&pit->pit_state.lock); |
686 | spin_lock_init(&pit->pit_state.inject_lock); | 687 | spin_lock_init(&pit->pit_state.inject_lock); |
687 | 688 | ||
688 | pit->wq = create_singlethread_workqueue("kvm-pit-wq"); | 689 | pid = get_pid(task_tgid(current)); |
689 | if (!pit->wq) { | 690 | pid_nr = pid_vnr(pid); |
691 | put_pid(pid); | ||
692 | |||
693 | init_kthread_worker(&pit->worker); | ||
694 | pit->worker_task = kthread_run(kthread_worker_fn, &pit->worker, | ||
695 | "kvm-pit/%d", pid_nr); | ||
696 | if (IS_ERR(pit->worker_task)) { | ||
690 | mutex_unlock(&pit->pit_state.lock); | 697 | mutex_unlock(&pit->pit_state.lock); |
691 | kvm_free_irq_source_id(kvm, pit->irq_source_id); | 698 | kvm_free_irq_source_id(kvm, pit->irq_source_id); |
692 | kfree(pit); | 699 | kfree(pit); |
693 | return NULL; | 700 | return NULL; |
694 | } | 701 | } |
695 | INIT_WORK(&pit->expired, pit_do_work); | 702 | init_kthread_work(&pit->expired, pit_do_work); |
696 | 703 | ||
697 | kvm->arch.vpit = pit; | 704 | kvm->arch.vpit = pit; |
698 | pit->kvm = kvm; | 705 | pit->kvm = kvm; |
@@ -736,7 +743,7 @@ fail: | |||
736 | kvm_unregister_irq_mask_notifier(kvm, 0, &pit->mask_notifier); | 743 | kvm_unregister_irq_mask_notifier(kvm, 0, &pit->mask_notifier); |
737 | kvm_unregister_irq_ack_notifier(kvm, &pit_state->irq_ack_notifier); | 744 | kvm_unregister_irq_ack_notifier(kvm, &pit_state->irq_ack_notifier); |
738 | kvm_free_irq_source_id(kvm, pit->irq_source_id); | 745 | kvm_free_irq_source_id(kvm, pit->irq_source_id); |
739 | destroy_workqueue(pit->wq); | 746 | kthread_stop(pit->worker_task); |
740 | kfree(pit); | 747 | kfree(pit); |
741 | return NULL; | 748 | return NULL; |
742 | } | 749 | } |
@@ -756,10 +763,10 @@ void kvm_free_pit(struct kvm *kvm) | |||
756 | mutex_lock(&kvm->arch.vpit->pit_state.lock); | 763 | mutex_lock(&kvm->arch.vpit->pit_state.lock); |
757 | timer = &kvm->arch.vpit->pit_state.pit_timer.timer; | 764 | timer = &kvm->arch.vpit->pit_state.pit_timer.timer; |
758 | hrtimer_cancel(timer); | 765 | hrtimer_cancel(timer); |
759 | cancel_work_sync(&kvm->arch.vpit->expired); | 766 | flush_kthread_work(&kvm->arch.vpit->expired); |
767 | kthread_stop(kvm->arch.vpit->worker_task); | ||
760 | kvm_free_irq_source_id(kvm, kvm->arch.vpit->irq_source_id); | 768 | kvm_free_irq_source_id(kvm, kvm->arch.vpit->irq_source_id); |
761 | mutex_unlock(&kvm->arch.vpit->pit_state.lock); | 769 | mutex_unlock(&kvm->arch.vpit->pit_state.lock); |
762 | destroy_workqueue(kvm->arch.vpit->wq); | ||
763 | kfree(kvm->arch.vpit); | 770 | kfree(kvm->arch.vpit); |
764 | } | 771 | } |
765 | } | 772 | } |
diff --git a/arch/x86/kvm/i8254.h b/arch/x86/kvm/i8254.h index 51a97426e79..fdf40425ea1 100644 --- a/arch/x86/kvm/i8254.h +++ b/arch/x86/kvm/i8254.h | |||
@@ -1,6 +1,8 @@ | |||
1 | #ifndef __I8254_H | 1 | #ifndef __I8254_H |
2 | #define __I8254_H | 2 | #define __I8254_H |
3 | 3 | ||
4 | #include <linux/kthread.h> | ||
5 | |||
4 | #include "iodev.h" | 6 | #include "iodev.h" |
5 | 7 | ||
6 | struct kvm_kpit_channel_state { | 8 | struct kvm_kpit_channel_state { |
@@ -39,8 +41,9 @@ struct kvm_pit { | |||
39 | struct kvm_kpit_state pit_state; | 41 | struct kvm_kpit_state pit_state; |
40 | int irq_source_id; | 42 | int irq_source_id; |
41 | struct kvm_irq_mask_notifier mask_notifier; | 43 | struct kvm_irq_mask_notifier mask_notifier; |
42 | struct workqueue_struct *wq; | 44 | struct kthread_worker worker; |
43 | struct work_struct expired; | 45 | struct task_struct *worker_task; |
46 | struct kthread_work expired; | ||
44 | }; | 47 | }; |
45 | 48 | ||
46 | #define KVM_PIT_BASE_ADDRESS 0x40 | 49 | #define KVM_PIT_BASE_ADDRESS 0x40 |