Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1702943ybi; Wed, 17 Jul 2019 20:25:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwL5vZHKtLK9G68BrvcPR2jKHofQP7QrZLq+c1ro0vaMzursrv/a6w/fPvUgre08v7f8QRP X-Received: by 2002:a65:6709:: with SMTP id u9mr17165391pgf.58.1563420319388; Wed, 17 Jul 2019 20:25:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563420319; cv=none; d=google.com; s=arc-20160816; b=AoLXWeXSHboWdho/lT+sTX5fYzyZGlChhXZVk32vIKfCQZcjMYz0TvsXqfuewmUqts HBD1B7/4gDs+283kqQdOQrrTnsqqpQToL77UAezz2C3C4S7OhTnSraAiRUulXBruhY3H Jjs9o/jsoYt76dsdQiKkO93m+0yN0mdvj4bnWPrSb/B0ffrVighspYH6sF0opPFhoq4C H/4s3LflsAHLR0/Wg6WvKZO3l30E3tAeIl+nsSEmEZ/C9L/yTarJLfQv8gtR0xID3MoK bVt9oDPfOdiW0yfi6NUTFw30bI7azGPUV3scY+ZIlAY34D3XvhBFjuUJ8m7wN/dudqCT 3pvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jL0e4DmHoXhjtSNSRg4SDrH49ly0CV4kLWJI1fzkqqM=; b=NkIx+O55Kopb9zZJlQM5ufdETgKYdiapZOQqtdYImzfFgSQeH0aSS8ZPrOrG58Nq+g wAl54bVKFMp0FIFFxH8qywwYPkjtdJp/RNN1Q90kEAjWcQ+d8VYWxUTsWF67+pVmJ6Ec WTxnBiv/Do2+04wLNW/vyIaLBhJS2AxaoX6FBvuK4uOWMe8YlDM+GbujkykboCrwxsE9 jhk8gfhLOHUbnd0OCoZEac3JzRGEIiqLACNBS9pl6cgNB24mZA7urjwDI9EIypr2IJ/S gHnjzbav4GzBEbjzZfLVr31akvwHfQzWacSY4FVRLytLXY59Zjofsi90Pcx5a+zZnksQ 5ByA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B8s39OBW; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91si910938plb.39.2019.07.17.20.25.03; Wed, 17 Jul 2019 20:25:19 -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; dkim=pass header.i=@kernel.org header.s=default header.b=B8s39OBW; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391122AbfGRDXU (ORCPT + 99 others); Wed, 17 Jul 2019 23:23:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:40070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390656AbfGRDIM (ORCPT ); Wed, 17 Jul 2019 23:08:12 -0400 Received: from localhost (115.42.148.210.bf.2iij.net [210.148.42.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CF9FB20818; Thu, 18 Jul 2019 03:08:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563419291; bh=MBiBm6iOBbyz/8UWVhfVFS5NLihhtEUDUC2dsjaqIbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B8s39OBWkgTHK2leSOs4EEHQ2aouqH2TgTA/fNXMzXrQxPFNh+SY9LToQN1b/YPBH SaokReD8jv/kk8bop0OFIrXE/7GbqeVg8MfTFAVNcrarjMVH+ubDVgvmugiPCGGWAK Grm9BlZejrvQ2Vl+nqIL4a+gyKMbgVNIJC7HMLXg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robert Hodaszi , Thomas Gleixner , Marc Zyngier Subject: [PATCH 4.19 30/47] genirq: Delay deactivation in free_irq() Date: Thu, 18 Jul 2019 12:01:44 +0900 Message-Id: <20190718030051.289662042@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718030045.780672747@linuxfoundation.org> References: <20190718030045.780672747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner tglx@linutronix.de commit 4001d8e8762f57d418b66e4e668601791900a1dd upstream When interrupts are shutdown, they are immediately deactivated in the irqdomain hierarchy. While this looks obviously correct there is a subtle issue: There might be an interrupt in flight when free_irq() is invoking the shutdown. This is properly handled at the irq descriptor / primary handler level, but the deactivation might completely disable resources which are required to acknowledge the interrupt. Split the shutdown code and deactivate the interrupt after synchronization in free_irq(). Fixup all other usage sites where this is not an issue to invoke the combined shutdown_and_deactivate() function instead. This still might be an issue if the interrupt in flight servicing is delayed on a remote CPU beyond the invocation of synchronize_irq(), but that cannot be handled at that level and needs to be handled in the synchronize_irq() context. Fixes: f8264e34965a ("irqdomain: Introduce new interfaces to support hierarchy irqdomains") Reported-by: Robert Hodaszi Signed-off-by: Thomas Gleixner Reviewed-by: Marc Zyngier Link: https://lkml.kernel.org/r/20190628111440.098196390@linutronix.de Signed-off-by: Greg Kroah-Hartman --- kernel/irq/autoprobe.c | 6 +++--- kernel/irq/chip.c | 6 ++++++ kernel/irq/cpuhotplug.c | 2 +- kernel/irq/internals.h | 1 + kernel/irq/manage.c | 10 ++++++++++ 5 files changed, 21 insertions(+), 4 deletions(-) --- a/kernel/irq/autoprobe.c +++ b/kernel/irq/autoprobe.c @@ -90,7 +90,7 @@ unsigned long probe_irq_on(void) /* It triggered already - consider it spurious. */ if (!(desc->istate & IRQS_WAITING)) { desc->istate &= ~IRQS_AUTODETECT; - irq_shutdown(desc); + irq_shutdown_and_deactivate(desc); } else if (i < 32) mask |= 1 << i; @@ -127,7 +127,7 @@ unsigned int probe_irq_mask(unsigned lon mask |= 1 << i; desc->istate &= ~IRQS_AUTODETECT; - irq_shutdown(desc); + irq_shutdown_and_deactivate(desc); } raw_spin_unlock_irq(&desc->lock); } @@ -169,7 +169,7 @@ int probe_irq_off(unsigned long val) nr_of_irqs++; } desc->istate &= ~IRQS_AUTODETECT; - irq_shutdown(desc); + irq_shutdown_and_deactivate(desc); } raw_spin_unlock_irq(&desc->lock); } --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c @@ -314,6 +314,12 @@ void irq_shutdown(struct irq_desc *desc) } irq_state_clr_started(desc); } +} + + +void irq_shutdown_and_deactivate(struct irq_desc *desc) +{ + irq_shutdown(desc); /* * This must be called even if the interrupt was never started up, * because the activation can happen before the interrupt is --- a/kernel/irq/cpuhotplug.c +++ b/kernel/irq/cpuhotplug.c @@ -116,7 +116,7 @@ static bool migrate_one_irq(struct irq_d */ if (irqd_affinity_is_managed(d)) { irqd_set_managed_shutdown(d); - irq_shutdown(desc); + irq_shutdown_and_deactivate(desc); return false; } affinity = cpu_online_mask; --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -80,6 +80,7 @@ extern int irq_activate_and_startup(stru extern int irq_startup(struct irq_desc *desc, bool resend, bool force); extern void irq_shutdown(struct irq_desc *desc); +extern void irq_shutdown_and_deactivate(struct irq_desc *desc); extern void irq_enable(struct irq_desc *desc); extern void irq_disable(struct irq_desc *desc); extern void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu); --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1619,6 +1620,7 @@ static struct irqaction *__free_irq(stru /* If this was the last handler, shut down the IRQ line: */ if (!desc->action) { irq_settings_clr_disable_unlazy(desc); + /* Only shutdown. Deactivate after synchronize_hardirq() */ irq_shutdown(desc); } @@ -1688,6 +1690,14 @@ static struct irqaction *__free_irq(stru * require it to deallocate resources over the slow bus. */ chip_bus_lock(desc); + /* + * There is no interrupt on the fly anymore. Deactivate it + * completely. + */ + raw_spin_lock_irqsave(&desc->lock, flags); + irq_domain_deactivate_irq(&desc->irq_data); + raw_spin_unlock_irqrestore(&desc->lock, flags); + irq_release_resources(desc); chip_bus_sync_unlock(desc); irq_remove_timings(desc);