Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755393AbdIGLpa (ORCPT ); Thu, 7 Sep 2017 07:45:30 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:17251 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755223AbdIGLn7 (ORCPT ); Thu, 7 Sep 2017 07:43:59 -0400 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v87BgcP3021413 X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Marc Zyngier , Thomas Gleixner , Linus Walleij , linux-gpio@vger.kernel.org, Rob Herring Cc: Jassi Brar , devicetree@vger.kernel.org, Jason Cooper , Masami Hiramatsu , David Daney , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v4 5/6] irqdomain: add IRQ_DOMAIN_FLAG_NO_CREATE flag Date: Thu, 7 Sep 2017 20:42:01 +0900 Message-Id: <1504784522-26841-6-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504784522-26841-1-git-send-email-yamada.masahiro@socionext.com> References: <1504784522-26841-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1835 Lines: 56 When an irqchip driver uses irq_domain_push_irq(), all irqs should be statically created by the irqchip. If a device tries to allocate an irq on-the-fly, irq_domain_alloc_irqs() is called. It allocates struct irq_data and invokes .alloc() hook passing fwspec as its argument. This is probably not what the irqchip expects (unless .alloc can call it recursively). This issue could happen when a device tries to get irq after irq_domain_create_hierarchy(), but before irq_domain_push_irq(). To avoid the race, add IRQ_DOMAIN_FLAG_NO_CREATE flag. This flag prevents devices from creating irqs. Devices are only allowed to get already existing irqs. Signed-off-by: Masahiro Yamada --- Changes in v4: - Newly added include/linux/irqdomain.h | 3 +++ kernel/irq/irqdomain.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h index 7609807..525de32 100644 --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -195,6 +195,9 @@ enum { /* Irq domain name was allocated in __irq_domain_add() */ IRQ_DOMAIN_NAME_ALLOCATED = (1 << 6), + /* Do not allow irq consumers to create irq */ + IRQ_DOMAIN_FLAG_NO_CREATE = (1 << 7), + /* * Flags starting from IRQ_DOMAIN_FLAG_NONCORE are reserved * for implementation specific purposes and ignored by the diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index b317a64..ecf107ab 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -806,6 +806,9 @@ unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec) return 0; } + if (domain->flags & IRQ_DOMAIN_FLAG_NO_CREATE) + return -EPROBE_DEFER; + if (irq_domain_is_hierarchy(domain)) { virq = irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, fwspec); if (virq <= 0) -- 2.7.4