Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp88049ybe; Sun, 1 Sep 2019 21:04:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqysmPAXuitxzgwZwlQZPtR4s7unpV81y1+8kWGpmUtCeNL1Gk0LmU6nuIL7apgz5XFNveuP X-Received: by 2002:a63:6f8f:: with SMTP id k137mr23363466pgc.90.1567397066305; Sun, 01 Sep 2019 21:04:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567397066; cv=none; d=google.com; s=arc-20160816; b=lSV0vP+m5KcwvkqLmwPsTQfyM8VMmjkQs6pp4X5FjRhSIdxi437NkQeXbWUNTlcbhg 9LiJ1t3PnOzA58ANOF0t6HodUIrWHJZlmHLCueawp49sjHswDHRFE6pXe10zzQjSgaly aC2V298/ydJMkcPNma7DY1uwj01ohQfc2I/ucg5035bUTJNBHDFwfDF44pv6GMYJGH2S QUARfPA/XOew1KAv6iVBCWYhVg8qtjhpJxS3YCzzt6NXQuumVxgZLCiphOrP66VQw6jD UN8zp9q5hhwsXEiRfF2p84Vu0i563+Eu+s0GOFrPATlGDBCY5jzA8QaOBvtfMxRmTJ60 oSvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from; bh=AMKcyduhXHYP16XJf91neH99fgT1gdk+irvnRhwObR8=; b=e7Gt0AdVQ/+A9TNPTntp9GmplFEwxhIfBsbWrSMxFNBWlA/EKWp9S4OHGjUAlKt+e3 w4Ze8CcAfnWzMcBEWwOzG613UGBz6Hx6BiZeNsWwyH003yqp/Y4V6Gt1kPv8uKGblr1/ GuoDTVzkKWKjrxD82fpGNO5qa4V1HQS1b0SDnnFpzmfnsyEFcadsSL2B/6bVoxe4s++U jUyufA4lFt8EGKWsogx+JyJ9rDlyVbn2CfQtzzGQMJrAy+9UPaQvtCSGLLK2XkXabKHI A60sRsgcnLBucqUJ1CwjeEq7sGJJx1LYcznMVVCe2UAz9yYQnGZK+cgHyG7OSwW7FxoI h4mw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a27si9630344pfg.105.2019.09.01.21.04.11; Sun, 01 Sep 2019 21:04:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729375AbfIBECL (ORCPT + 99 others); Mon, 2 Sep 2019 00:02:11 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:31969 "EHLO out4436.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728329AbfIBECL (ORCPT ); Mon, 2 Sep 2019 00:02:11 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R501e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04420;MF=luoben@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0Tb3eA21_1567396916; Received: from localhost(mailfrom:luoben@linux.alibaba.com fp:SMTPD_---0Tb3eA21_1567396916) by smtp.aliyun-inc.com(127.0.0.1); Mon, 02 Sep 2019 12:01:58 +0800 From: Ben Luo To: tglx@linutronix.de, alex.williamson@redhat.com Cc: linux-kernel@vger.kernel.org, tao.ma@linux.alibaba.com, gerry@linux.alibaba.com, nanhai.zou@linux.alibaba.com Subject: [PATCH v6 1/3] genirq: enhance error recovery code in free irq Date: Mon, 2 Sep 2019 12:01:50 +0800 Message-Id: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __free_irq()/__free_percpu_irq() need to return if called from IRQ context because the interrupt handler loop runs with desc->lock dropped and dev_id can be subject to load and store tearing. Also move WARNs out of lock region and print out dev_id to help debugging. Signed-off-by: Ben Luo --- kernel/irq/manage.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index e8f7f17..10ec3e9 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -1690,7 +1690,10 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id) struct irqaction *action, **action_ptr; unsigned long flags; - WARN(in_interrupt(), "Trying to free IRQ %d from IRQ context!\n", irq); + if (WARN(in_interrupt(), + "Trying to free IRQ %d (dev_id %p) from IRQ context!\n", + irq, dev_id)) + return NULL; mutex_lock(&desc->request_mutex); chip_bus_lock(desc); @@ -1705,10 +1708,11 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id) action = *action_ptr; if (!action) { - WARN(1, "Trying to free already-free IRQ %d\n", irq); raw_spin_unlock_irqrestore(&desc->lock, flags); chip_bus_sync_unlock(desc); mutex_unlock(&desc->request_mutex); + WARN(1, "Trying to free already-free IRQ %d (dev_id %p)\n", + irq, dev_id); return NULL; } @@ -2286,7 +2290,10 @@ static struct irqaction *__free_percpu_irq(unsigned int irq, void __percpu *dev_ struct irqaction *action; unsigned long flags; - WARN(in_interrupt(), "Trying to free IRQ %d from IRQ context!\n", irq); + if (WARN(in_interrupt(), + "Trying to free IRQ %d (dev_id %p) from IRQ context!\n", + irq, dev_id)) + return NULL; if (!desc) return NULL; @@ -2295,14 +2302,17 @@ static struct irqaction *__free_percpu_irq(unsigned int irq, void __percpu *dev_ action = desc->action; if (!action || action->percpu_dev_id != dev_id) { - WARN(1, "Trying to free already-free IRQ %d\n", irq); - goto bad; + raw_spin_unlock_irqrestore(&desc->lock, flags); + WARN(1, "Trying to free already-free IRQ (dev_id %p) %d\n", + dev_id, irq); + return NULL; } if (!cpumask_empty(desc->percpu_enabled)) { - WARN(1, "percpu IRQ %d still enabled on CPU%d!\n", - irq, cpumask_first(desc->percpu_enabled)); - goto bad; + raw_spin_unlock_irqrestore(&desc->lock, flags); + WARN(1, "percpu IRQ %d (dev_id %p) still enabled on CPU%d!\n", + irq, dev_id, cpumask_first(desc->percpu_enabled)); + return NULL; } /* Found it - now remove it from the list of entries: */ @@ -2317,10 +2327,6 @@ static struct irqaction *__free_percpu_irq(unsigned int irq, void __percpu *dev_ irq_chip_pm_put(&desc->irq_data); module_put(desc->owner); return action; - -bad: - raw_spin_unlock_irqrestore(&desc->lock, flags); - return NULL; } /** -- 1.8.3.1