All of lore.kernel.org
 help / color / mirror / Atom feed
From: "irqchip-bot for Johan Hovold" <tip-bot2@linutronix.de>
To: linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org, #@tip-bot2.tec.linutronix.de,
	4.8@tip-bot2.tec.linutronix.de,
	"Hsin-Yi Wang" <hsinyi@chromium.org>,
	"Mark-PK Tsai" <mark-pk.tsai@mediatek.com>,
	Johan Hovold <johan+linaro@kernel.org>,
	Marc Zyngier <maz@kernel.org>,
	tglx@linutronix.de
Subject: [irqchip: irq/irqchip-next] irqdomain: Refactor __irq_domain_alloc_irqs()
Date: Mon, 13 Feb 2023 19:40:46 -0000	[thread overview]
Message-ID: <167631724623.4906.9249607211486146477.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20230213104302.17307-6-johan+linaro@kernel.org>

The following commit has been merged into the irq/irqchip-next branch of irqchip:

Commit-ID:     d55f7f4c58c07beb5050a834bf57ae2ede599c7e
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms/d55f7f4c58c07beb5050a834bf57ae2ede599c7e
Author:        Johan Hovold <johan+linaro@kernel.org>
AuthorDate:    Mon, 13 Feb 2023 11:42:47 +01:00
Committer:     Marc Zyngier <maz@kernel.org>
CommitterDate: Mon, 13 Feb 2023 19:31:24 

irqdomain: Refactor __irq_domain_alloc_irqs()

Refactor __irq_domain_alloc_irqs() so that it can be called internally
while holding the irq_domain_mutex.

This will be used to fix a shared-interrupt mapping race, hence the
Fixes tag.

Fixes: b62b2cf5759b ("irqdomain: Fix handling of type settings for existing mappings")
Cc: stable@vger.kernel.org      # 4.8
Tested-by: Hsin-Yi Wang <hsinyi@chromium.org>
Tested-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20230213104302.17307-6-johan+linaro@kernel.org
---
 kernel/irq/irqdomain.c | 88 ++++++++++++++++++++++-------------------
 1 file changed, 48 insertions(+), 40 deletions(-)

diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c
index 9f95047..78fb480 100644
--- a/kernel/irq/irqdomain.c
+++ b/kernel/irq/irqdomain.c
@@ -1441,40 +1441,12 @@ int irq_domain_alloc_irqs_hierarchy(struct irq_domain *domain,
 	return domain->ops->alloc(domain, irq_base, nr_irqs, arg);
 }
 
-/**
- * __irq_domain_alloc_irqs - Allocate IRQs from domain
- * @domain:	domain to allocate from
- * @irq_base:	allocate specified IRQ number if irq_base >= 0
- * @nr_irqs:	number of IRQs to allocate
- * @node:	NUMA node id for memory allocation
- * @arg:	domain specific argument
- * @realloc:	IRQ descriptors have already been allocated if true
- * @affinity:	Optional irq affinity mask for multiqueue devices
- *
- * Allocate IRQ numbers and initialized all data structures to support
- * hierarchy IRQ domains.
- * Parameter @realloc is mainly to support legacy IRQs.
- * Returns error code or allocated IRQ number
- *
- * The whole process to setup an IRQ has been split into two steps.
- * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ
- * descriptor and required hardware resources. The second step,
- * irq_domain_activate_irq(), is to program the hardware with preallocated
- * resources. In this way, it's easier to rollback when failing to
- * allocate resources.
- */
-int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base,
-			    unsigned int nr_irqs, int node, void *arg,
-			    bool realloc, const struct irq_affinity_desc *affinity)
+static int irq_domain_alloc_irqs_locked(struct irq_domain *domain, int irq_base,
+					unsigned int nr_irqs, int node, void *arg,
+					bool realloc, const struct irq_affinity_desc *affinity)
 {
 	int i, ret, virq;
 
-	if (domain == NULL) {
-		domain = irq_default_domain;
-		if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n"))
-			return -EINVAL;
-	}
-
 	if (realloc && irq_base >= 0) {
 		virq = irq_base;
 	} else {
@@ -1493,24 +1465,18 @@ int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base,
 		goto out_free_desc;
 	}
 
-	mutex_lock(&irq_domain_mutex);
 	ret = irq_domain_alloc_irqs_hierarchy(domain, virq, nr_irqs, arg);
-	if (ret < 0) {
-		mutex_unlock(&irq_domain_mutex);
+	if (ret < 0)
 		goto out_free_irq_data;
-	}
 
 	for (i = 0; i < nr_irqs; i++) {
 		ret = irq_domain_trim_hierarchy(virq + i);
-		if (ret) {
-			mutex_unlock(&irq_domain_mutex);
+		if (ret)
 			goto out_free_irq_data;
-		}
 	}
-	
+
 	for (i = 0; i < nr_irqs; i++)
 		irq_domain_insert_irq(virq + i);
-	mutex_unlock(&irq_domain_mutex);
 
 	return virq;
 
@@ -1520,6 +1486,48 @@ out_free_desc:
 	irq_free_descs(virq, nr_irqs);
 	return ret;
 }
+
+/**
+ * __irq_domain_alloc_irqs - Allocate IRQs from domain
+ * @domain:	domain to allocate from
+ * @irq_base:	allocate specified IRQ number if irq_base >= 0
+ * @nr_irqs:	number of IRQs to allocate
+ * @node:	NUMA node id for memory allocation
+ * @arg:	domain specific argument
+ * @realloc:	IRQ descriptors have already been allocated if true
+ * @affinity:	Optional irq affinity mask for multiqueue devices
+ *
+ * Allocate IRQ numbers and initialized all data structures to support
+ * hierarchy IRQ domains.
+ * Parameter @realloc is mainly to support legacy IRQs.
+ * Returns error code or allocated IRQ number
+ *
+ * The whole process to setup an IRQ has been split into two steps.
+ * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ
+ * descriptor and required hardware resources. The second step,
+ * irq_domain_activate_irq(), is to program the hardware with preallocated
+ * resources. In this way, it's easier to rollback when failing to
+ * allocate resources.
+ */
+int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base,
+			    unsigned int nr_irqs, int node, void *arg,
+			    bool realloc, const struct irq_affinity_desc *affinity)
+{
+	int ret;
+
+	if (domain == NULL) {
+		domain = irq_default_domain;
+		if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n"))
+			return -EINVAL;
+	}
+
+	mutex_lock(&irq_domain_mutex);
+	ret = irq_domain_alloc_irqs_locked(domain, irq_base, nr_irqs, node, arg,
+					   realloc, affinity);
+	mutex_unlock(&irq_domain_mutex);
+
+	return ret;
+}
 EXPORT_SYMBOL_GPL(__irq_domain_alloc_irqs);
 
 /* The irq_data was moved, fix the revmap to refer to the new location */

  reply	other threads:[~2023-02-13 19:41 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-bot for Johan Hovold [this message]
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 ` [PATCH v6 07/20] irqdomain: Fix domain registration race Johan Hovold
2023-02-13 10:42   ` 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=167631724623.4906.9249607211486146477.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=#@tip-bot2.tec.linutronix.de \
    --cc=4.8@tip-bot2.tec.linutronix.de \
    --cc=hsinyi@chromium.org \
    --cc=johan+linaro@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark-pk.tsai@mediatek.com \
    --cc=maz@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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.