From patchwork Wed Jan 13 16:58:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 72673 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o0DH1njl020835 for ; Wed, 13 Jan 2010 17:01:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756113Ab0AMRBQ (ORCPT ); Wed, 13 Jan 2010 12:01:16 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756116Ab0AMRBP (ORCPT ); Wed, 13 Jan 2010 12:01:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41334 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756115Ab0AMRBM (ORCPT ); Wed, 13 Jan 2010 12:01:12 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0DH19hZ011046 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 13 Jan 2010 12:01:09 -0500 Received: from redhat.com (vpn2-11-140.ams2.redhat.com [10.36.11.140]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o0DH13lr009191; Wed, 13 Jan 2010 12:01:03 -0500 Date: Wed, 13 Jan 2010 18:58:09 +0200 From: "Michael S. Tsirkin" To: Avi Kivity , Marcelo Tosatti , "Michael S. Tsirkin" , Gregory Haskins , Gleb Natapov , Julia Lawall , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] kvm: only allow one gsi per fd Message-ID: <20100113165809.GA13334@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index 30f70fd..62e4cd9 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -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; @@ -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);