From: Johan Hovold <johan+linaro@kernel.org>
To: Marc Zyngier <maz@kernel.org>, Thomas Gleixner <tglx@linutronix.de>
Cc: x86@kernel.org, platform-driver-x86@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Johan Hovold <johan+linaro@kernel.org>
Subject: [PATCH v6 07/20] irqdomain: Fix domain registration race
Date: Mon, 13 Feb 2023 11:42:49 +0100 [thread overview]
Message-ID: <20230213104302.17307-8-johan+linaro@kernel.org> (raw)
In-Reply-To: <20230213104302.17307-1-johan+linaro@kernel.org>
From: Marc Zyngier <maz@kernel.org>
Hierarchical domains created using irq_domain_create_hierarchy() are
currently added to the domain list before having been fully initialised.
This specifically means that a racing allocation request might fail to
allocate irq data for the inner domains of a hierarchy in case the
parent domain pointer has not yet been set up.
Note that this is not really any issue for irqchip drivers that are
registered early (e.g. via IRQCHIP_DECLARE() or IRQCHIP_ACPI_DECLARE())
but could potentially cause trouble with drivers that are registered
later (e.g. modular drivers using IRQCHIP_PLATFORM_DRIVER_BEGIN(),
gpiochip drivers, etc.).
Fixes: afb7da83b9f4 ("irqdomain: Introduce helper function irq_domain_add_hierarchy()")
Cc: stable@vger.kernel.org # 3.19
Signed-off-by: Marc Zyngier <maz@kernel.org>
[ johan: add commit message ]
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---
kernel/irq/irqdomain.c | 62 +++++++++++++++++++++++++++++-------------
1 file changed, 43 insertions(+), 19 deletions(-)
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index bfda4adc05c0..8e14805c5508 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -126,23 +126,12 @@ void irq_domain_free_fwnode(struct fwnode_handle *fwnode)
}
EXPORT_SYMBOL_GPL(irq_domain_free_fwnode);
-/**
- * __irq_domain_add() - Allocate a new irq_domain data structure
- * @fwnode: firmware node for the interrupt controller
- * @size: Size of linear map; 0 for radix mapping only
- * @hwirq_max: Maximum number of interrupts supported by controller
- * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no
- * direct mapping
- * @ops: domain callbacks
- * @host_data: Controller private data pointer
- *
- * Allocates and initializes an irq_domain structure.
- * Returns pointer to IRQ domain, or NULL on failure.
- */
-struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, unsigned int size,
- irq_hw_number_t hwirq_max, int direct_max,
- const struct irq_domain_ops *ops,
- void *host_data)
+static struct irq_domain *__irq_domain_create(struct fwnode_handle *fwnode,
+ unsigned int size,
+ irq_hw_number_t hwirq_max,
+ int direct_max,
+ const struct irq_domain_ops *ops,
+ void *host_data)
{
struct irqchip_fwid *fwid;
struct irq_domain *domain;
@@ -230,12 +219,44 @@ struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, unsigned int s
irq_domain_check_hierarchy(domain);
+ return domain;
+}
+
+static void __irq_domain_publish(struct irq_domain *domain)
+{
mutex_lock(&irq_domain_mutex);
debugfs_add_domain_dir(domain);
list_add(&domain->link, &irq_domain_list);
mutex_unlock(&irq_domain_mutex);
pr_debug("Added domain %s\n", domain->name);
+}
+
+/**
+ * __irq_domain_add() - Allocate a new irq_domain data structure
+ * @fwnode: firmware node for the interrupt controller
+ * @size: Size of linear map; 0 for radix mapping only
+ * @hwirq_max: Maximum number of interrupts supported by controller
+ * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no
+ * direct mapping
+ * @ops: domain callbacks
+ * @host_data: Controller private data pointer
+ *
+ * Allocates and initializes an irq_domain structure.
+ * Returns pointer to IRQ domain, or NULL on failure.
+ */
+struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, unsigned int size,
+ irq_hw_number_t hwirq_max, int direct_max,
+ const struct irq_domain_ops *ops,
+ void *host_data)
+{
+ struct irq_domain *domain;
+
+ domain = __irq_domain_create(fwnode, size, hwirq_max, direct_max,
+ ops, host_data);
+ if (domain)
+ __irq_domain_publish(domain);
+
return domain;
}
EXPORT_SYMBOL_GPL(__irq_domain_add);
@@ -1138,12 +1159,15 @@ struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent,
struct irq_domain *domain;
if (size)
- domain = irq_domain_create_linear(fwnode, size, ops, host_data);
+ domain = __irq_domain_create(fwnode, size, size, 0, ops, host_data);
else
- domain = irq_domain_create_tree(fwnode, ops, host_data);
+ domain = __irq_domain_create(fwnode, 0, ~0, 0, ops, host_data);
+
if (domain) {
domain->parent = parent;
domain->flags |= flags;
+
+ __irq_domain_publish(domain);
}
return domain;
--
2.39.1
WARNING: multiple messages have this Message-ID
From: Johan Hovold <johan+linaro@kernel.org>
To: Marc Zyngier <maz@kernel.org>, Thomas Gleixner <tglx@linutronix.de>
Cc: x86@kernel.org, platform-driver-x86@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Johan Hovold <johan+linaro@kernel.org>
Subject: [PATCH v6 07/20] irqdomain: Fix domain registration race
Date: Mon, 13 Feb 2023 11:42:49 +0100 [thread overview]
Message-ID: <20230213104302.17307-8-johan+linaro@kernel.org> (raw)
In-Reply-To: <20230213104302.17307-1-johan+linaro@kernel.org>
From: Marc Zyngier <maz@kernel.org>
Hierarchical domains created using irq_domain_create_hierarchy() are
currently added to the domain list before having been fully initialised.
This specifically means that a racing allocation request might fail to
allocate irq data for the inner domains of a hierarchy in case the
parent domain pointer has not yet been set up.
Note that this is not really any issue for irqchip drivers that are
registered early (e.g. via IRQCHIP_DECLARE() or IRQCHIP_ACPI_DECLARE())
but could potentially cause trouble with drivers that are registered
later (e.g. modular drivers using IRQCHIP_PLATFORM_DRIVER_BEGIN(),
gpiochip drivers, etc.).
Fixes: afb7da83b9f4 ("irqdomain: Introduce helper function irq_domain_add_hierarchy()")
Cc: stable@vger.kernel.org # 3.19
Signed-off-by: Marc Zyngier <maz@kernel.org>
[ johan: add commit message ]
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---
kernel/irq/irqdomain.c | 62 +++++++++++++++++++++++++++++-------------
1 file changed, 43 insertions(+), 19 deletions(-)
diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index bfda4adc05c0..8e14805c5508 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -126,23 +126,12 @@ void irq_domain_free_fwnode(struct fwnode_handle *fwnode)
}
EXPORT_SYMBOL_GPL(irq_domain_free_fwnode);
-/**
- * __irq_domain_add() - Allocate a new irq_domain data structure
- * @fwnode: firmware node for the interrupt controller
- * @size: Size of linear map; 0 for radix mapping only
- * @hwirq_max: Maximum number of interrupts supported by controller
- * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no
- * direct mapping
- * @ops: domain callbacks
- * @host_data: Controller private data pointer
- *
- * Allocates and initializes an irq_domain structure.
- * Returns pointer to IRQ domain, or NULL on failure.
- */
-struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, unsigned int size,
- irq_hw_number_t hwirq_max, int direct_max,
- const struct irq_domain_ops *ops,
- void *host_data)
+static struct irq_domain *__irq_domain_create(struct fwnode_handle *fwnode,
+ unsigned int size,
+ irq_hw_number_t hwirq_max,
+ int direct_max,
+ const struct irq_domain_ops *ops,
+ void *host_data)
{
struct irqchip_fwid *fwid;
struct irq_domain *domain;
@@ -230,12 +219,44 @@ struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, unsigned int s
irq_domain_check_hierarchy(domain);
+ return domain;
+}
+
+static void __irq_domain_publish(struct irq_domain *domain)
+{
mutex_lock(&irq_domain_mutex);
debugfs_add_domain_dir(domain);
list_add(&domain->link, &irq_domain_list);
mutex_unlock(&irq_domain_mutex);
pr_debug("Added domain %s\n", domain->name);
+}
+
+/**
+ * __irq_domain_add() - Allocate a new irq_domain data structure
+ * @fwnode: firmware node for the interrupt controller
+ * @size: Size of linear map; 0 for radix mapping only
+ * @hwirq_max: Maximum number of interrupts supported by controller
+ * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no
+ * direct mapping
+ * @ops: domain callbacks
+ * @host_data: Controller private data pointer
+ *
+ * Allocates and initializes an irq_domain structure.
+ * Returns pointer to IRQ domain, or NULL on failure.
+ */
+struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, unsigned int size,
+ irq_hw_number_t hwirq_max, int direct_max,
+ const struct irq_domain_ops *ops,
+ void *host_data)
+{
+ struct irq_domain *domain;
+
+ domain = __irq_domain_create(fwnode, size, hwirq_max, direct_max,
+ ops, host_data);
+ if (domain)
+ __irq_domain_publish(domain);
+
return domain;
}
EXPORT_SYMBOL_GPL(__irq_domain_add);
@@ -1138,12 +1159,15 @@ struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent,
struct irq_domain *domain;
if (size)
- domain = irq_domain_create_linear(fwnode, size, ops, host_data);
+ domain = __irq_domain_create(fwnode, size, size, 0, ops, host_data);
else
- domain = irq_domain_create_tree(fwnode, ops, host_data);
+ domain = __irq_domain_create(fwnode, 0, ~0, 0, ops, host_data);
+
if (domain) {
domain->parent = parent;
domain->flags |= flags;
+
+ __irq_domain_publish(domain);
}
return domain;
--
2.39.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-02-13 10:43 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-13 10:42 [PATCH v6 00/20] irqdomain: fix mapping race and rework locking Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 10:42 ` [PATCH v6 01/20] irqdomain: Fix association race Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 02/20] irqdomain: Fix disassociation race Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 03/20] irqdomain: Drop bogus fwspec-mapping error handling Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 04/20] irqdomain: Look for existing mapping only once Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 05/20] irqdomain: Refactor __irq_domain_alloc_irqs() Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 06/20] irqdomain: Fix mapping-creation race Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-03-08 14:41 ` Cyril Brulebois
2023-03-08 14:41 ` Cyril Brulebois
2023-03-08 14:53 ` Marc Zyngier
2023-03-08 14:53 ` Marc Zyngier
2023-03-09 7:32 ` Johan Hovold
2023-03-09 7:32 ` Johan Hovold
2023-02-13 10:42 ` Johan Hovold [this message]
2023-02-13 10:42 ` [PATCH v6 07/20] irqdomain: Fix domain registration race Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Marc Zyngier
2023-02-13 10:42 ` [PATCH v6 08/20] irqdomain: Drop revmap mutex Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 09/20] irqdomain: Drop dead domain-name assignment Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 10/20] irqdomain: Drop leftover brackets Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 11/20] irqdomain: Clean up irq_domain_push/pop_irq() Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 12/20] x86/ioapic: Use irq_domain_create_hierarchy() Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 13/20] x86/uv: " Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 14/20] irqchip/alpine-msi: Use irq_domain_add_hierarchy() Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 15/20] irqchip/gic-v2m: Use irq_domain_create_hierarchy() Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 16/20] irqchip/gic-v3-its: " Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:42 ` [PATCH v6 17/20] irqchip/gic-v3-mbi: " Johan Hovold
2023-02-13 10:42 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:43 ` [PATCH v6 18/20] irqchip/loongson-pch-msi: " Johan Hovold
2023-02-13 10:43 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:43 ` [PATCH v6 19/20] irqchip/mvebu-odmi: " Johan Hovold
2023-02-13 10:43 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-02-13 10:43 ` [PATCH v6 20/20] irqdomain: Switch to per-domain locking Johan Hovold
2023-02-13 10:43 ` Johan Hovold
2023-02-13 19:40 ` [irqchip: irq/irqchip-next] " irqchip-bot for Johan Hovold
2023-03-07 13:51 ` [PATCH v6 20/20] " David Woodhouse
2023-03-07 13:51 ` David Woodhouse
2023-03-07 14:06 ` Juergen Gross
2023-03-07 14:06 ` Juergen Gross
2023-03-07 14:18 ` David Woodhouse
2023-03-07 14:18 ` David Woodhouse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230213104302.17307-8-johan+linaro@kernel.org \
--to=johan+linaro@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=maz@kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.