From patchwork Thu May 21 06:21:35 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wright X-Patchwork-Id: 25183 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n4L6Lr9T009991 for ; Thu, 21 May 2009 06:21:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751280AbZEUGVs (ORCPT ); Thu, 21 May 2009 02:21:48 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751195AbZEUGVs (ORCPT ); Thu, 21 May 2009 02:21:48 -0400 Received: from sous-sol.org ([216.99.217.87]:44416 "EHLO sequoia.sous-sol.org" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751089AbZEUGVs (ORCPT ); Thu, 21 May 2009 02:21:48 -0400 Received: from sequoia.sous-sol.org (sequoia.sous-sol.org [127.0.0.1]) by sequoia.sous-sol.org (8.14.2/8.14.2) with ESMTP id n4L6LZeO026139; Wed, 20 May 2009 23:21:35 -0700 Received: (from chrisw@localhost) by sequoia.sous-sol.org (8.14.2/8.14.2/Submit) id n4L6LZxP026138; Wed, 20 May 2009 23:21:35 -0700 Date: Wed, 20 May 2009 23:21:35 -0700 From: Chris Wright To: Avi Kivity Cc: kvm@vger.kernel.org Subject: [PATCH] kvm-kmod: fix kvm_request_irq race Message-ID: <20090521062135.GR20823@sequoia.sous-sol.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: ClamAV version 0.93.3, clamav-milter version 0.93.3 on sequoia.sous-sol.org X-Virus-Status: Clean Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Commit "32658734: Fix request_irq() for < 2.6.19" is racy between multiple guests since ioctl is only serialized per guest. Add mutex and serialize kvm_request_irq/kvm_free_irq to avoid race. Signed-off-by: Chris Wright --- external-module-compat-comm.h | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/external-module-compat-comm.h b/external-module-compat-comm.h index 8cb5440..eaad986 100644 --- a/external-module-compat-comm.h +++ b/external-module-compat-comm.h @@ -645,6 +645,7 @@ static inline int pci_reset_function(struct pci_dev *dev) typedef irqreturn_t (*kvm_irq_handler_t)(int, void *); static kvm_irq_handler_t kvm_irq_handlers[NR_IRQS]; +static DEFINE_MUTEX(kvm_irq_handlers_mutex); static irqreturn_t kvm_irq_thunk(int irq, void *dev_id, struct pt_regs *regs) { @@ -655,21 +656,28 @@ static irqreturn_t kvm_irq_thunk(int irq, void *dev_id, struct pt_regs *regs) static inline int kvm_request_irq(unsigned int a, kvm_irq_handler_t handler, unsigned long c, const char *d, void *e) { - int rc; - kvm_irq_handler_t old = kvm_irq_handlers[a]; + int rc = -EBUSY; + kvm_irq_handler_t old; + + mutex_lock(&kvm_irq_handlers_mutex); + old = kvm_irq_handlers[a]; if (old) - return -EBUSY; + goto out; kvm_irq_handlers[a] = handler; rc = request_irq(a, kvm_irq_thunk, c, d, e); if (rc) kvm_irq_handlers[a] = NULL; +out: + mutex_unlock(&kvm_irq_handlers_mutex); return rc; } static inline void kvm_free_irq(unsigned int irq, void *dev_id) { + mutex_lock(&kvm_irq_handlers_mutex); free_irq(irq, dev_id); kvm_irq_handlers[irq] = NULL; + mutex_unlock(&kvm_irq_handlers_mutex); } #else