Skip to content

Commit b7f7a3c

Browse files
mstsirkinAndy Whitcroft
authored andcommitted
KVM: only allow one gsi per fd
commit f1d1c309f35e9b0fb961cffd70fbd04f450ec47c upstream. 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. Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Acked-by: Gregory Haskins <[email protected]> Signed-off-by: Avi Kivity <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Andy Whitcroft <[email protected]>
1 parent 9aba841 commit b7f7a3c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

virt/kvm/eventfd.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ irqfd_ptable_queue_proc(struct file *file, wait_queue_head_t *wqh,
168168
static int
169169
kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi)
170170
{
171-
struct _irqfd *irqfd;
171+
struct _irqfd *irqfd, *tmp;
172172
struct file *file = NULL;
173173
struct eventfd_ctx *eventfd = NULL;
174174
int ret;
@@ -205,9 +205,20 @@ kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi)
205205
init_waitqueue_func_entry(&irqfd->wait, irqfd_wakeup);
206206
init_poll_funcptr(&irqfd->pt, irqfd_ptable_queue_proc);
207207

208+
spin_lock_irq(&kvm->irqfds.lock);
209+
210+
ret = 0;
211+
list_for_each_entry(tmp, &kvm->irqfds.items, list) {
212+
if (irqfd->eventfd != tmp->eventfd)
213+
continue;
214+
/* This fd is used for another irq already. */
215+
ret = -EBUSY;
216+
spin_unlock_irq(&kvm->irqfds.lock);
217+
goto fail;
218+
}
219+
208220
events = file->f_op->poll(file, &irqfd->pt);
209221

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

0 commit comments

Comments
 (0)