Skip to content

Commit

Permalink
KVM: only allow one gsi per fd
Browse files Browse the repository at this point in the history
Looks like repeatedly binding same fd to multiple gsi's with irqfd can
use up a ton of kernel memory for irqfd structures.

A simple fix is to allow each fd to only trigger one gsi: triggering a
storm of interrupts in guest is likely useless anyway, and we can do it
by binding a single gsi to many interrupts if we really want to.

Cc: [email protected]
Signed-off-by: Michael S. Tsirkin <[email protected]>
Acked-by: Acked-by: Gregory Haskins <[email protected]>
Signed-off-by: Avi Kivity <[email protected]>
  • Loading branch information
mstsirkin authored and matosatti committed Jan 25, 2010
1 parent 82b7005 commit f1d1c30
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions virt/kvm/eventfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ irqfd_ptable_queue_proc(struct file *file, wait_queue_head_t *wqh,
static int
kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi)
{
struct _irqfd *irqfd;
struct _irqfd *irqfd, *tmp;
struct file *file = NULL;
struct eventfd_ctx *eventfd = NULL;
int ret;
Expand Down Expand Up @@ -203,9 +203,20 @@ kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi)
init_waitqueue_func_entry(&irqfd->wait, irqfd_wakeup);
init_poll_funcptr(&irqfd->pt, irqfd_ptable_queue_proc);

spin_lock_irq(&kvm->irqfds.lock);

ret = 0;
list_for_each_entry(tmp, &kvm->irqfds.items, list) {
if (irqfd->eventfd != tmp->eventfd)
continue;
/* This fd is used for another irq already. */
ret = -EBUSY;
spin_unlock_irq(&kvm->irqfds.lock);
goto fail;
}

events = file->f_op->poll(file, &irqfd->pt);

spin_lock_irq(&kvm->irqfds.lock);
list_add_tail(&irqfd->list, &kvm->irqfds.items);
spin_unlock_irq(&kvm->irqfds.lock);

Expand Down

0 comments on commit f1d1c30

Please sign in to comment.