linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug
@ 2014-05-06  1:33 Yinghai Lu
  2014-05-06  1:33 ` [PATCH v3 1/8] x86, irq: Remove not needed irq_reserve_irqs calling Yinghai Lu
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Yinghai Lu @ 2014-05-06  1:33 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Tony Luck
  Cc: linux-kernel, Yinghai Lu

Hi,

These patches are core changes for x86 ioapic hotplug support.

First part for kill old irq_reserve_irqs:
During reviewing ioapic hotplug patchset, Thomas pointed out that
should not extend irq_reserve_irq for that purpose as that is not
actually reserve.
Neet to clean up old irq_reserve_irq before introduce reserve/alloc_reserved
method for ioapic hotplug.
So here patchset that kill irq_reserve_irq that actually set allocated_irqs.
First remove irq_reserve_irqs for x86, and remove irq_reserve_irq
for sh.
Then in set_irq_chip use irq_alloc_desc instead of irq_reserve_irq.
Next will mark bits in allocated_irqs early for init irqs in !SPARSE_IRQ

Second parts are new reserve/alloc_reserved functions:
It will introduce reserved_irqs bit maps to track reserved irqs.
New irq_alloc_reserved_desc() will only allocate desc when that irq
is reserved, at the same time irq_alloc_desc will only allocate desc
when irq is not reserved.

Thanks

Yinghai

-v2: add new reserve/alloc_reserved sets.
-v3: make irq_alloc_descs to avoid reserved irqs.

Yinghai Lu (8):
  x86, irq: Remove not needed irq_reserve_irqs calling
  sh, irq: Remove irq_reserve_irq calling
  irq: Use irq_alloc_desc_at instead of irq_reserve_irq
  s390: Mark bits in allocated_irqs in general code
  irq: Kill irq_reserve_irq/irq_reserve_irqs
  irq: Add new reserved_irqs clear/mark functions
  irq: Add irq_alloc_reserved_desc()
  irq: Do not free unallocated irq descriptors

 arch/s390/kernel/irq.c         |   6 +-
 arch/x86/kernel/apic/io_apic.c |   3 -
 drivers/sh/intc/core.c         |   7 +-
 include/linux/irq.h            |  13 ++--
 kernel/irq/chip.c              |  14 ++--
 kernel/irq/irqdesc.c           | 144 ++++++++++++++++++++++++++++++++++-------
 6 files changed, 141 insertions(+), 46 deletions(-)

-- 
1.8.4.5


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v3 1/8] x86, irq: Remove not needed irq_reserve_irqs calling
  2014-05-06  1:33 [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Yinghai Lu
@ 2014-05-06  1:33 ` Yinghai Lu
  2014-05-06  1:33 ` [PATCH v3 2/8] sh, irq: Remove irq_reserve_irq calling Yinghai Lu
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Yinghai Lu @ 2014-05-06  1:33 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Tony Luck
  Cc: linux-kernel, Yinghai Lu

Now x86 only support sparseirq path, for that path, calling path like:
	early_irq_init
		==> arch_probe_nr_irqs : return legacy irq number
		==> alloc_desc for legacy irqs and set bits in allocated_irqs
		==> arch_early_irq_init
			==> irq_reserve_irqs : set bits again

so we can kill one irq_reserve_irqs calling.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 arch/x86/kernel/apic/io_apic.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
index 6ad4658..398f9c4 100644
--- a/arch/x86/kernel/apic/io_apic.c
+++ b/arch/x86/kernel/apic/io_apic.c
@@ -206,9 +206,6 @@ int __init arch_early_irq_init(void)
 	count = ARRAY_SIZE(irq_cfgx);
 	node = cpu_to_node(0);
 
-	/* Make sure the legacy interrupts are marked in the bitmap */
-	irq_reserve_irqs(0, legacy_pic->nr_legacy_irqs);
-
 	for (i = 0; i < count; i++) {
 		irq_set_chip_data(i, &cfg[i]);
 		zalloc_cpumask_var_node(&cfg[i].domain, GFP_KERNEL, node);
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 2/8] sh, irq: Remove irq_reserve_irq calling
  2014-05-06  1:33 [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Yinghai Lu
  2014-05-06  1:33 ` [PATCH v3 1/8] x86, irq: Remove not needed irq_reserve_irqs calling Yinghai Lu
@ 2014-05-06  1:33 ` Yinghai Lu
  2014-05-06  1:33 ` [PATCH v3 3/8] irq: Use irq_alloc_desc_at instead of irq_reserve_irq Yinghai Lu
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Yinghai Lu @ 2014-05-06  1:33 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Tony Luck
  Cc: linux-kernel, Yinghai Lu, Simon Horman, Magnus Damm, linux-sh

in sh calling path:
	register_intc_controller
		==> irq_create_identity_mapping/irq_create_strict_mappins
			==>irq_alloc_desc: it will set bits on allocate_irq
		==> intc_register_irq
			==> irq_reserve_irq: set bits again

so we can kill this irq_reserve_irq calling.

-v2: Fix comment style according to Sergei Shtylyov.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Simon Horman <horms@verge.net.au>
Cc: Magnus Damm <magnus.damm@gmail.com>
Cc: linux-sh@vger.kernel.org
Acked-by: Simon Horman <horms+renesas@verge.net.au>
---
 drivers/sh/intc/core.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/sh/intc/core.c b/drivers/sh/intc/core.c
index 8f32a13..d146ce1 100644
--- a/drivers/sh/intc/core.c
+++ b/drivers/sh/intc/core.c
@@ -80,12 +80,7 @@ static void __init intc_register_irq(struct intc_desc *desc,
 	unsigned int data[2], primary;
 	unsigned long flags;
 
-	/*
-	 * Register the IRQ position with the global IRQ map, then insert
-	 * it in to the radix tree.
-	 */
-	irq_reserve_irq(irq);
-
+	/* Insert it in to the radix tree. */
 	raw_spin_lock_irqsave(&intc_big_lock, flags);
 	radix_tree_insert(&d->tree, enum_id, intc_irq_xlate_get(irq));
 	raw_spin_unlock_irqrestore(&intc_big_lock, flags);
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 3/8] irq: Use irq_alloc_desc_at instead of irq_reserve_irq
  2014-05-06  1:33 [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Yinghai Lu
  2014-05-06  1:33 ` [PATCH v3 1/8] x86, irq: Remove not needed irq_reserve_irqs calling Yinghai Lu
  2014-05-06  1:33 ` [PATCH v3 2/8] sh, irq: Remove irq_reserve_irq calling Yinghai Lu
@ 2014-05-06  1:33 ` Yinghai Lu
  2014-05-06  1:33 ` [PATCH v3 4/8] s390: Mark bits in allocated_irqs in general code Yinghai Lu
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Yinghai Lu @ 2014-05-06  1:33 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Tony Luck
  Cc: linux-kernel, Yinghai Lu

irq_reserve_irq actually only set bit allocated_irq, and it is not really
"reserve" and cause confusion.

For !CONFIG_SPARSE_IRQ path, irq_alloc_desc_at() will only set bit
in allocated_irq.

We can use that instead, kill one irq_reserve_irq() calling.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 kernel/irq/chip.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
index 6397df2..aff7481 100644
--- a/kernel/irq/chip.c
+++ b/kernel/irq/chip.c
@@ -28,8 +28,13 @@
 int irq_set_chip(unsigned int irq, struct irq_chip *chip)
 {
 	unsigned long flags;
-	struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
+	struct irq_desc *desc;
+
+#ifndef CONFIG_SPARSE_IRQ
+	irq_alloc_desc_at(irq, 0);
+#endif
 
+	desc = irq_get_desc_lock(irq, &flags, 0);
 	if (!desc)
 		return -EINVAL;
 
@@ -38,12 +43,7 @@ int irq_set_chip(unsigned int irq, struct irq_chip *chip)
 
 	desc->irq_data.chip = chip;
 	irq_put_desc_unlock(desc, flags);
-	/*
-	 * For !CONFIG_SPARSE_IRQ make the irq show up in
-	 * allocated_irqs. For the CONFIG_SPARSE_IRQ case, it is
-	 * already marked, and this call is harmless.
-	 */
-	irq_reserve_irq(irq);
+
 	return 0;
 }
 EXPORT_SYMBOL(irq_set_chip);
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 4/8] s390: Mark bits in allocated_irqs in general code
  2014-05-06  1:33 [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Yinghai Lu
                   ` (2 preceding siblings ...)
  2014-05-06  1:33 ` [PATCH v3 3/8] irq: Use irq_alloc_desc_at instead of irq_reserve_irq Yinghai Lu
@ 2014-05-06  1:33 ` Yinghai Lu
  2014-05-06  1:33 ` [PATCH v3 5/8] irq: Kill irq_reserve_irq/irq_reserve_irqs Yinghai Lu
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Yinghai Lu @ 2014-05-06  1:33 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Tony Luck
  Cc: linux-kernel, Yinghai Lu, Martin Schwidefsky, Heiko Carstens, linux390

Second irq_reserve_irqs calling is from arch s390, and
s390 does not use SPARSE_IRQ yet.

We could set bits for legacy bits early in !SPARSE_IRQ version
early_irq_init() directly instead of calling irq_reserve_irqs later.

Adding weak version arch_proble_early_allocate_nr_irqs() for
!SPARESE_IRQ, and let s390 to have specific version to
pass correct irq number that need to be marked in allocated_irqs.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: linux390@de.ibm.com
---
 arch/s390/kernel/irq.c |  6 +++++-
 include/linux/irq.h    |  1 +
 kernel/irq/irqdesc.c   | 10 ++++++++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
index c7463aa..47e29be 100644
--- a/arch/s390/kernel/irq.c
+++ b/arch/s390/kernel/irq.c
@@ -90,9 +90,13 @@ static const struct irq_class irqclass_sub_desc[NR_ARCH_IRQS] = {
 	[CPU_RST]    = {.name = "RST", .desc = "[CPU] CPU Restart"},
 };
 
+int arch_probe_early_allocate_nr_irqs(void)
+{
+	return THIN_INTERRUPT;
+}
+
 void __init init_IRQ(void)
 {
-	irq_reserve_irqs(0, THIN_INTERRUPT);
 	init_cio_interrupts();
 	init_airq_interrupts();
 	init_ext_interrupts();
diff --git a/include/linux/irq.h b/include/linux/irq.h
index 10a0b1a..28cbd3e 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -624,6 +624,7 @@ int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
 
 void irq_free_descs(unsigned int irq, unsigned int cnt);
 int irq_reserve_irqs(unsigned int from, unsigned int cnt);
+int arch_probe_early_allocate_nr_irqs(void);
 
 static inline void irq_free_desc(unsigned int irq)
 {
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index a7174617..dfb971c 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -248,10 +248,16 @@ struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
 	}
 };
 
+int __weak arch_probe_early_allocate_nr_irqs(void)
+{
+	return 0;
+}
+
 int __init early_irq_init(void)
 {
 	int count, i, node = first_online_node;
 	struct irq_desc *desc;
+	int nr = arch_probe_early_allocate_nr_irqs();
 
 	init_irq_default_affinity();
 
@@ -267,6 +273,10 @@ int __init early_irq_init(void)
 		lockdep_set_class(&desc[i].lock, &irq_desc_lock_class);
 		desc_set_defaults(i, &desc[i], node, NULL);
 	}
+
+	for (i = 0; i < nr; i++)
+		set_bit(i, allocated_irqs);
+
 	return arch_early_irq_init();
 }
 
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 5/8] irq: Kill irq_reserve_irq/irq_reserve_irqs
  2014-05-06  1:33 [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Yinghai Lu
                   ` (3 preceding siblings ...)
  2014-05-06  1:33 ` [PATCH v3 4/8] s390: Mark bits in allocated_irqs in general code Yinghai Lu
@ 2014-05-06  1:33 ` Yinghai Lu
  2014-05-06  1:33 ` [PATCH v3 6/8] irq: Add new reserved_irqs clear/mark functions Yinghai Lu
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Yinghai Lu @ 2014-05-06  1:33 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Tony Luck
  Cc: linux-kernel, Yinghai Lu

No user any more.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 include/linux/irq.h  |  6 ------
 kernel/irq/irqdesc.c | 25 -------------------------
 2 files changed, 31 deletions(-)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index 28cbd3e..02dc0e4 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -623,7 +623,6 @@ int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
 	irq_alloc_descs(-1, from, cnt, node)
 
 void irq_free_descs(unsigned int irq, unsigned int cnt);
-int irq_reserve_irqs(unsigned int from, unsigned int cnt);
 int arch_probe_early_allocate_nr_irqs(void);
 
 static inline void irq_free_desc(unsigned int irq)
@@ -631,11 +630,6 @@ static inline void irq_free_desc(unsigned int irq)
 	irq_free_descs(irq, 1);
 }
 
-static inline int irq_reserve_irq(unsigned int irq)
-{
-	return irq_reserve_irqs(irq, 1);
-}
-
 #ifndef irq_reg_writel
 # define irq_reg_writel(val, addr)	writel(val, addr)
 #endif
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index dfb971c..49bf891 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -400,31 +400,6 @@ err:
 EXPORT_SYMBOL_GPL(__irq_alloc_descs);
 
 /**
- * irq_reserve_irqs - mark irqs allocated
- * @from:	mark from irq number
- * @cnt:	number of irqs to mark
- *
- * Returns 0 on success or an appropriate error code
- */
-int irq_reserve_irqs(unsigned int from, unsigned int cnt)
-{
-	unsigned int start;
-	int ret = 0;
-
-	if (!cnt || (from + cnt) > nr_irqs)
-		return -EINVAL;
-
-	mutex_lock(&sparse_irq_lock);
-	start = bitmap_find_next_zero_area(allocated_irqs, nr_irqs, from, cnt, 0);
-	if (start == from)
-		bitmap_set(allocated_irqs, start, cnt);
-	else
-		ret = -EEXIST;
-	mutex_unlock(&sparse_irq_lock);
-	return ret;
-}
-
-/**
  * irq_get_next_irq - get next allocated irq number
  * @offset:	where to start the search
  *
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 6/8] irq: Add new reserved_irqs clear/mark functions
  2014-05-06  1:33 [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Yinghai Lu
                   ` (4 preceding siblings ...)
  2014-05-06  1:33 ` [PATCH v3 5/8] irq: Kill irq_reserve_irq/irq_reserve_irqs Yinghai Lu
@ 2014-05-06  1:33 ` Yinghai Lu
  2014-05-06  1:33 ` [PATCH v3 7/8] irq: Add irq_alloc_reserved_desc() Yinghai Lu
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Yinghai Lu @ 2014-05-06  1:33 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Tony Luck
  Cc: linux-kernel, Yinghai Lu

Prepare for ioapic hotplug.

-v2: Add reserved_or_allocated_irqs to simplify the code.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 include/linux/irq.h  |  3 +++
 kernel/irq/irqdesc.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index 02dc0e4..2ba3245 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -603,6 +603,9 @@ static inline u32 irq_get_trigger_type(unsigned int irq)
 	return d ? irqd_get_trigger_type(d) : 0;
 }
 
+int irq_clear_reserved_irqs(unsigned int from, unsigned int cnt);
+int irq_mark_reserved_irqs(int irq, unsigned int from, unsigned int cnt);
+
 int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
 		struct module *owner);
 
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 49bf891..d55297a 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -98,6 +98,8 @@ EXPORT_SYMBOL_GPL(nr_irqs);
 
 static DEFINE_MUTEX(sparse_irq_lock);
 static DECLARE_BITMAP(allocated_irqs, IRQ_BITMAP_BITS);
+static DECLARE_BITMAP(reserved_irqs, IRQ_BITMAP_BITS);
+static DECLARE_BITMAP(reserved_or_allocated_irqs, IRQ_BITMAP_BITS);
 
 #ifdef CONFIG_SPARSE_IRQ
 
@@ -400,6 +402,69 @@ err:
 EXPORT_SYMBOL_GPL(__irq_alloc_descs);
 
 /**
+ * irq_clear_reserved_irqs - clear irqs reserved
+ * @from:	clear from irq number
+ * @cnt:	number of irqs to clear
+ *
+ * Returns 0 on success or an appropriate error code
+ */
+int irq_clear_reserved_irqs(unsigned int from, unsigned int cnt)
+{
+	if (!cnt || (from + cnt) > nr_irqs)
+		return -EINVAL;
+
+	mutex_lock(&sparse_irq_lock);
+	bitmap_clear(reserved_irqs, from, cnt);
+	mutex_unlock(&sparse_irq_lock);
+
+	return 0;
+}
+
+/**
+ * irq_mark_reserved_irqs - mark irqs reserved
+ * @irq:	Reserve for specific irq number if irq >= 0
+ * @from:	mark from irq number
+ * @cnt:	number of irqs to mark
+ *
+ * Returns the first irq number or error code
+ */
+int irq_mark_reserved_irqs(int irq, unsigned int from, unsigned int cnt)
+{
+	int start, ret;
+
+	if (!cnt)
+		return -EINVAL;
+
+	if (irq >= 0) {
+		if (from > irq)
+			return -EINVAL;
+		from = irq;
+	}
+
+	mutex_lock(&sparse_irq_lock);
+	bitmap_or(reserved_or_allocated_irqs, reserved_irqs, allocated_irqs,
+			 IRQ_BITMAP_BITS);
+	start = bitmap_find_next_zero_area(reserved_or_allocated_irqs,
+					   IRQ_BITMAP_BITS, from, cnt, 0);
+	ret = -EEXIST;
+	if (irq >= 0 && start != irq)
+		goto err;
+
+	if (start + cnt > nr_irqs) {
+		ret = irq_expand_nr_irqs(start + cnt);
+		if (ret < 0)
+			goto err;
+	}
+
+	bitmap_set(reserved_irqs, start, cnt);
+	ret = start;
+
+err:
+	mutex_unlock(&sparse_irq_lock);
+	return ret;
+}
+
+/**
  * irq_get_next_irq - get next allocated irq number
  * @offset:	where to start the search
  *
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 7/8] irq: Add irq_alloc_reserved_desc()
  2014-05-06  1:33 [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Yinghai Lu
                   ` (5 preceding siblings ...)
  2014-05-06  1:33 ` [PATCH v3 6/8] irq: Add new reserved_irqs clear/mark functions Yinghai Lu
@ 2014-05-06  1:33 ` Yinghai Lu
  2014-05-06  1:33 ` [PATCH v3 8/8] irq: Do not free unallocated irq descriptors Yinghai Lu
  2014-05-07  9:46 ` [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Ingo Molnar
  8 siblings, 0 replies; 10+ messages in thread
From: Yinghai Lu @ 2014-05-06  1:33 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Tony Luck
  Cc: linux-kernel, Yinghai Lu, Joerg Roedel, Konrad Rzeszutek Wilk,
	Sebastian Andrzej Siewior

For ioapic hot-add support, it would be easy if we have continuous
irq numbers for hot added ioapic controller.

We can reserve irq range at first, and later allocate desc for those
pre-reserved irqs when they are needed.

The reasons for not allocating them during reserving:
1. only several pins of one ioapic are used, allocate for all pins, will
   waste memory for not used pins.
2. allocate later when is needed could make sure irq_desc is allocated
   on local node ram, as dev->node is set at that point.

-v2: update changelog by adding reasons, requested by Konrad.
-v3: according to tglx:
       separate core code change with arch code change.
       change function name to irq_alloc_reserved_desc.
       kill __irq_is_reserved().
       remove not need exports.
     according to Sebastian:
       spare one comments by put two functions together.
-v4: Fix the bug that tglx pointed out.
     irq_alloc_descs() should avoid reserved irqs.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
 include/linux/irq.h  |  3 ++
 kernel/irq/irqdesc.c | 97 ++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 74 insertions(+), 26 deletions(-)

diff --git a/include/linux/irq.h b/include/linux/irq.h
index 2ba3245..97b60b9 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -608,10 +608,13 @@ int irq_mark_reserved_irqs(int irq, unsigned int from, unsigned int cnt);
 
 int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
 		struct module *owner);
+int __irq_alloc_reserved_desc(int at, int node, struct module *owner);
 
 /* use macros to avoid needing export.h for THIS_MODULE */
 #define irq_alloc_descs(irq, from, cnt, node)	\
 	__irq_alloc_descs(irq, from, cnt, node, THIS_MODULE)
+#define irq_alloc_reserved_desc_at(at, node)	\
+	__irq_alloc_reserved_desc(at, node, THIS_MODULE)
 
 #define irq_alloc_desc(node)			\
 	irq_alloc_descs(-1, 0, 1, node)
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index d55297a..7b2b83a 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -352,21 +352,11 @@ void irq_free_descs(unsigned int from, unsigned int cnt)
 }
 EXPORT_SYMBOL_GPL(irq_free_descs);
 
-/**
- * irq_alloc_descs - allocate and initialize a range of irq descriptors
- * @irq:	Allocate for specific irq number if irq >= 0
- * @from:	Start the search from this irq number
- * @cnt:	Number of consecutive irqs to allocate.
- * @node:	Preferred node on which the irq descriptor should be allocated
- * @owner:	Owning module (can be NULL)
- *
- * Returns the first irq number or error code
- */
-int __ref
-__irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
-		  struct module *owner)
+/* Should be used with sparse_irq_lock */
+static int __irq_mark_allocated_irqs(int irq, unsigned int from,
+				     unsigned int cnt, int avoid_reserved)
 {
-	int start, ret;
+	int start;
 
 	if (!cnt)
 		return -EINVAL;
@@ -377,26 +367,55 @@ __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
 		from = irq;
 	}
 
-	mutex_lock(&sparse_irq_lock);
+	if (avoid_reserved) {
+		bitmap_or(reserved_or_allocated_irqs, reserved_irqs,
+			  allocated_irqs, IRQ_BITMAP_BITS);
 
-	start = bitmap_find_next_zero_area(allocated_irqs, IRQ_BITMAP_BITS,
-					   from, cnt, 0);
-	ret = -EEXIST;
-	if (irq >=0 && start != irq)
-		goto err;
+		start = bitmap_find_next_zero_area(reserved_or_allocated_irqs,
+							IRQ_BITMAP_BITS,
+							from, cnt, 0);
+	} else
+		start = bitmap_find_next_zero_area(allocated_irqs,
+							IRQ_BITMAP_BITS,
+							from, cnt, 0);
+
+	if (irq >= 0 && start != irq)
+		return -EEXIST;
 
 	if (start + cnt > nr_irqs) {
-		ret = irq_expand_nr_irqs(start + cnt);
-		if (ret)
-			goto err;
+		int ret = irq_expand_nr_irqs(start + cnt);
+
+		if (ret < 0)
+			return ret;
 	}
 
 	bitmap_set(allocated_irqs, start, cnt);
-	mutex_unlock(&sparse_irq_lock);
-	return alloc_descs(start, cnt, node, owner);
 
-err:
+	return start;
+}
+
+/**
+ * irq_alloc_descs - allocate and initialize a range of irq descriptors
+ * @irq:	Allocate for specific irq number if irq >= 0
+ * @from:	Start the search from this irq number
+ * @cnt:	Number of consecutive irqs to allocate.
+ * @node:	Preferred node on which the irq descriptor should be allocated
+ * @owner:	Owning module (can be NULL)
+ *
+ * Returns the first irq number or error code
+ */
+int __ref
+__irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
+		  struct module *owner)
+{	int ret;
+
+	mutex_lock(&sparse_irq_lock);
+	ret = __irq_mark_allocated_irqs(irq, from, cnt, 1);
 	mutex_unlock(&sparse_irq_lock);
+
+	if (ret >= 0)
+		return alloc_descs(ret, cnt, node, owner);
+
 	return ret;
 }
 EXPORT_SYMBOL_GPL(__irq_alloc_descs);
@@ -464,6 +483,32 @@ err:
 	return ret;
 }
 
+ /**
+ * __irq_alloc_reserved_desc - allocate irq descriptor for irq that is already reserved
+ * @irq:	Allocate for specific irq number if irq >= 0
+ * @node:	Preferred node on which the irq descriptor should be allocated
+ * @owner:	Owning module (can be NULL)
+ *
+ * Returns the irq number or error code
+ */
+int __ref __irq_alloc_reserved_desc(int irq, int node, struct module *owner)
+{
+	int ret = -EINVAL;
+
+	if (irq < 0 || irq >= nr_irqs)
+		return -EINVAL;
+
+	mutex_lock(&sparse_irq_lock);
+	if (test_bit(irq, reserved_irqs))
+		ret = __irq_mark_allocated_irqs(irq, irq, 1, 0);
+	mutex_unlock(&sparse_irq_lock);
+
+	if (ret >= 0)
+		return alloc_descs(ret, 1, node, owner);
+
+	return ret;
+}
+
 /**
  * irq_get_next_irq - get next allocated irq number
  * @offset:	where to start the search
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 8/8] irq: Do not free unallocated irq descriptors
  2014-05-06  1:33 [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Yinghai Lu
                   ` (6 preceding siblings ...)
  2014-05-06  1:33 ` [PATCH v3 7/8] irq: Add irq_alloc_reserved_desc() Yinghai Lu
@ 2014-05-06  1:33 ` Yinghai Lu
  2014-05-07  9:46 ` [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Ingo Molnar
  8 siblings, 0 replies; 10+ messages in thread
From: Yinghai Lu @ 2014-05-06  1:33 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Tony Luck
  Cc: linux-kernel, Yinghai Lu

Hot-added interrupt controllers can reserve a range of interrupt
numbers, but only allocate some of them. To simplify the release on
hot-remove allow them to iterate over the reserved range, let the
free_desc() code return early when the descriptor does not exist

-v2: changelog from tglx

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 kernel/irq/irqdesc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 7b2b83a..b46ab9e 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -167,6 +167,9 @@ static void free_desc(unsigned int irq)
 {
 	struct irq_desc *desc = irq_to_desc(irq);
 
+	if (!desc)
+		return;
+
 	unregister_irq_proc(irq, desc);
 
 	mutex_lock(&sparse_irq_lock);
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug
  2014-05-06  1:33 [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Yinghai Lu
                   ` (7 preceding siblings ...)
  2014-05-06  1:33 ` [PATCH v3 8/8] irq: Do not free unallocated irq descriptors Yinghai Lu
@ 2014-05-07  9:46 ` Ingo Molnar
  8 siblings, 0 replies; 10+ messages in thread
From: Ingo Molnar @ 2014-05-07  9:46 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Tony Luck, linux-kernel


* Yinghai Lu <yinghai@kernel.org> wrote:

> Hi,
> 
> These patches are core changes for x86 ioapic hotplug support.
> 
> First part for kill old irq_reserve_irqs:
> During reviewing ioapic hotplug patchset, Thomas pointed out that
> should not extend irq_reserve_irq for that purpose as that is not
> actually reserve.
> Neet to clean up old irq_reserve_irq before introduce reserve/alloc_reserved
> method for ioapic hotplug.
> So here patchset that kill irq_reserve_irq that actually set allocated_irqs.
> First remove irq_reserve_irqs for x86, and remove irq_reserve_irq
> for sh.
> Then in set_irq_chip use irq_alloc_desc instead of irq_reserve_irq.
> Next will mark bits in allocated_irqs early for init irqs in !SPARSE_IRQ
> 
> Second parts are new reserve/alloc_reserved functions:
> It will introduce reserved_irqs bit maps to track reserved irqs.
> New irq_alloc_reserved_desc() will only allocate desc when that irq
> is reserved, at the same time irq_alloc_desc will only allocate desc
> when irq is not reserved.

That's not a proper description of the problem and the solution. The 
same problem of lack of proper explanation permeates most of your 
patches as well and that's very far from the quality threshold that 
core IRQ patches need to meet.

Crappy descriptions and passive-aggressive responses where you pretend 
you don't understand our complaints and just minimally address the 
problems are not acceptable.

So I concur with Thomas and this series earns a big fat NAK from me. 
(Please Cc: me to all (if any) future resubmissions so I can track 
progress (or the lack thereof) and see whether I can lift my NAK.)

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-05-07  9:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-06  1:33 [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Yinghai Lu
2014-05-06  1:33 ` [PATCH v3 1/8] x86, irq: Remove not needed irq_reserve_irqs calling Yinghai Lu
2014-05-06  1:33 ` [PATCH v3 2/8] sh, irq: Remove irq_reserve_irq calling Yinghai Lu
2014-05-06  1:33 ` [PATCH v3 3/8] irq: Use irq_alloc_desc_at instead of irq_reserve_irq Yinghai Lu
2014-05-06  1:33 ` [PATCH v3 4/8] s390: Mark bits in allocated_irqs in general code Yinghai Lu
2014-05-06  1:33 ` [PATCH v3 5/8] irq: Kill irq_reserve_irq/irq_reserve_irqs Yinghai Lu
2014-05-06  1:33 ` [PATCH v3 6/8] irq: Add new reserved_irqs clear/mark functions Yinghai Lu
2014-05-06  1:33 ` [PATCH v3 7/8] irq: Add irq_alloc_reserved_desc() Yinghai Lu
2014-05-06  1:33 ` [PATCH v3 8/8] irq: Do not free unallocated irq descriptors Yinghai Lu
2014-05-07  9:46 ` [PATCH v3 0/8] irq: core changes for x86 ioapic hotplug Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).