28 #include <linux/wait.h>
29 #include <linux/poll.h>
31 #include <linux/list.h>
33 #include <linux/kernel.h>
34 #include <linux/slab.h>
137 struct kvm *kvm = resampler->
kvm;
141 list_del_rcu(&irqfd->resampler_link);
144 if (list_empty(&resampler->
list)) {
177 irqfd_resampler_shutdown(irqfd);
191 irqfd_is_active(
struct _irqfd *irqfd)
193 return list_empty(&irqfd->
list) ?
false :
true;
202 irqfd_deactivate(
struct _irqfd *irqfd)
204 BUG_ON(!irqfd_is_active(irqfd));
206 list_del_init(&irqfd->
list);
218 unsigned long flags = (
unsigned long)key;
220 struct kvm *kvm = irqfd->
kvm;
248 if (irqfd_is_active(irqfd))
249 irqfd_deactivate(irqfd);
251 spin_unlock_irqrestore(&kvm->irqfds.
lock, flags);
266 static void irqfd_update(
struct kvm *kvm,
struct _irqfd *irqfd,
272 if (irqfd->
gsi >= irq_rt->nr_rt_entries) {
279 if (e->
type == KVM_IRQ_ROUTING_MSI)
287 kvm_irqfd_assign(
struct kvm *kvm,
struct kvm_irqfd *args)
302 INIT_LIST_HEAD(&irqfd->
list);
313 if (IS_ERR(eventfd)) {
314 ret = PTR_ERR(eventfd);
324 if (IS_ERR(resamplefd)) {
325 ret = PTR_ERR(resamplefd);
335 &kvm->irqfds.resampler_list,
list) {
343 resampler = kzalloc(
sizeof(*resampler),
GFP_KERNEL);
351 INIT_LIST_HEAD(&resampler->
list);
353 resampler->
notifier.irq_acked = irqfd_resampler_ack;
354 INIT_LIST_HEAD(&resampler->
link);
356 list_add(&resampler->
link, &kvm->irqfds.resampler_list);
372 init_waitqueue_func_entry(&irqfd->
wait, irqfd_wakeup);
373 init_poll_funcptr(&irqfd->
pt, irqfd_ptable_queue_proc);
375 spin_lock_irq(&kvm->irqfds.
lock);
383 spin_unlock_irq(&kvm->irqfds.
lock);
388 lockdep_is_held(&kvm->irqfds.
lock));
389 irqfd_update(kvm, irqfd, irq_rt);
391 events = file->
f_op->poll(file, &irqfd->
pt);
402 spin_unlock_irq(&kvm->irqfds.
lock);
414 irqfd_resampler_shutdown(irqfd);
416 if (resamplefd && !IS_ERR(resamplefd))
419 if (eventfd && !IS_ERR(eventfd))
433 INIT_LIST_HEAD(&kvm->irqfds.items);
434 INIT_LIST_HEAD(&kvm->irqfds.resampler_list);
436 INIT_LIST_HEAD(&kvm->ioeventfds);
443 kvm_irqfd_deassign(
struct kvm *kvm,
struct kvm_irqfd *args)
450 return PTR_ERR(eventfd);
452 spin_lock_irq(&kvm->irqfds.
lock);
465 irqfd_deactivate(irqfd);
469 spin_unlock_irq(&kvm->irqfds.
lock);
489 return kvm_irqfd_deassign(kvm, args);
491 return kvm_irqfd_assign(kvm, args);
503 spin_lock_irq(&kvm->irqfds.
lock);
506 irqfd_deactivate(irqfd);
508 spin_unlock_irq(&kvm->irqfds.
lock);
527 spin_lock_irq(&kvm->irqfds.
lock);
532 irqfd_update(kvm, irqfd, irq_rt);
534 spin_unlock_irq(&kvm->irqfds.
lock);
542 static int __init irqfd_module_init(
void)
545 if (!irqfd_cleanup_wq)
551 static void __exit irqfd_module_exit(
void)
626 return _val == p->
datamatch ?
true :
false;
636 if (!ioeventfd_in_range(p, addr, len, val))
652 ioeventfd_release(p);
656 .write = ioeventfd_write,
657 .destructor = ioeventfd_destructor,
662 ioeventfd_check_collision(
struct kvm *kvm,
struct _ioeventfd *p)
696 if (args->addr + args->len < args->addr)
705 return PTR_ERR(eventfd);
713 INIT_LIST_HEAD(&p->
list);
714 p->
addr = args->addr;
727 if (ioeventfd_check_collision(kvm, p)) {
732 kvm_iodevice_init(&p->
dev, &ioeventfd_ops);
756 kvm_deassign_ioeventfd(
struct kvm *kvm,
struct kvm_ioeventfd *args)
766 return PTR_ERR(eventfd);
783 ioeventfd_release(p);
799 return kvm_deassign_ioeventfd(kvm, args);
801 return kvm_assign_ioeventfd(kvm, args);