Skip to contentSkip to conversation

x86/irq: slightly improve handle_irq

PATCH Applied Heiner Kallweit 2 participants 7 messages Aug 19, 2019 – Aug 23, 2019 x86

lore
Share & tools
lore
#0 lore raw

v2 cover x86/irq: slightly improve handle_irq

When checking something else I stumbled across this code. This patch set simplifies it a little bit.

v2:
- patch 2: add "likely" to if clause and reorder it
- patch 2: For 64bit, remove handle_irq and inline call to generic_handle_irq_desc

Heiner Kallweit (3):
x86/irq: improve definition of VECTOR_SHUTDOWN et al x86/irq: factor out IS_ERR_OR_NULL check from platform-specific
handle_irq
x86/irq: slightly improve do_IRQ

 arch/x86/include/asm/hw_irq.h |  4 ++--
 arch/x86/include/asm/irq.h    |  2 +-
 arch/x86/kernel/irq.c         | 11 ++++++++---
 arch/x86/kernel/irq_32.c      |  7 +------
 arch/x86/kernel/irq_64.c      |  9 ---------
 5 files changed, 12 insertions(+), 21 deletions(-)
Signature · 1 line
2.22.1
#1 lore raw

PATCH v2 1/3 x86/irq: improve definition of VECTOR_SHUTDOWN et al

These values are used with IS_ERR(), so it's more intuitive to define them like a standard PTR_ERR() of a negative errno.

---
 arch/x86/include/asm/hw_irq.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/hw_irq.h +2 -2
index cbd97e22d..4154bc5f6 100644
@@ -153,8 +153,8 @@ extern char irq_entries_start[];
 extern char spurious_entries_start[];
 
 #define VECTOR_UNUSED		NULL
-#define VECTOR_SHUTDOWN		((void *)~0UL)
-#define VECTOR_RETRIGGERED	((void *)~1UL)
+#define VECTOR_SHUTDOWN		((void *)-1L)
+#define VECTOR_RETRIGGERED	((void *)-2L)
 
 typedef struct irq_desc* vector_irq_t[NR_VECTORS];
 DECLARE_PER_CPU(vector_irq_t, vector_irq);
Signature · 1 line
2.22.1
#2 lore raw

[tip: x86/irq] x86/irq: Improve definition of VECTOR_SHUTDOWN et al

The following commit has been merged into the x86/irq branch of tip:

The following commit has been merged into the x86/irq branch of tip:

Commit-ID:     e30c44e2e59c98023997632815cbc5e273991c25
Gitweb:        https://git.kernel.org/tip/e30c44e2e59c98023997632815cbc5e273991c25
Author:        Heiner Kallweit <[email protected]>
AuthorDate:    Mon, 19 Aug 2019 21:34:47 +02:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Mon, 19 Aug 2019 23:19:06 +02:00

x86/irq: Improve definition of VECTOR_SHUTDOWN et al

These values are used with IS_ERR(), so it's more intuitive to define them like a standard PTR_ERR() of a negative errno.

---
 arch/x86/include/asm/hw_irq.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/hw_irq.h +2 -2
index cbd97e2..4154bc5 100644
@@ -153,8 +153,8 @@ extern char irq_entries_start[];
 extern char spurious_entries_start[];
 
 #define VECTOR_UNUSED		NULL
-#define VECTOR_SHUTDOWN		((void *)~0UL)
-#define VECTOR_RETRIGGERED	((void *)~1UL)
+#define VECTOR_SHUTDOWN		((void *)-1L)
+#define VECTOR_RETRIGGERED	((void *)-2L)
 
 typedef struct irq_desc* vector_irq_t[NR_VECTORS];
 DECLARE_PER_CPU(vector_irq_t, vector_irq);
#3 lore raw

PATCH v2 2/3 x86/irq: factor out IS_ERR_OR_NULL check from platform-specific handle_irq

In reply to Heiner Kallweit

The code can be simplified a little by factoring out the IS_ERR_OR_NULL check from the platform-specific handle_irq implementations, and by inlining the remaining call to generic_handle_irq_desc for 64bit systems.

---
v2:
- add "likely" to if clause and reorder it
- For 64bit, remove handle_irq and inline call to generic_handle_irq_desc

---
 arch/x86/include/asm/irq.h | 2 +-
 arch/x86/kernel/irq.c      | 9 +++++++--
 arch/x86/kernel/irq_32.c   | 7 +------
 arch/x86/kernel/irq_64.c   | 9 ---------
 4 files changed, 9 insertions(+), 18 deletions(-)
arch/x86/include/asm/irq.h +1 -1
index 8f95686ec..a176f6165 100644
@@ -34,7 +34,7 @@ extern __visible void smp_kvm_posted_intr_nested_ipi(struct pt_regs *regs);
 extern void (*x86_platform_ipi_callback)(void);
 extern void native_init_IRQ(void);
 
-extern bool handle_irq(struct irq_desc *desc, struct pt_regs *regs);
+extern void handle_irq(struct irq_desc *desc, struct pt_regs *regs);
 
 extern __visible unsigned int do_IRQ(struct pt_regs *regs);
 
arch/x86/kernel/irq.c +7 -2
index 4215653f8..f1c8f350d 100644
@@ -243,8 +243,13 @@ __visible unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
 	RCU_LOCKDEP_WARN(!rcu_is_watching(), "IRQ failed to wake up RCU");
 
 	desc = __this_cpu_read(vector_irq[vector]);
-
-	if (!handle_irq(desc, regs)) {
+	if (likely(!IS_ERR_OR_NULL(desc))) {
+#ifdef CONFIG_X86_32
+		handle_irq(desc, regs);
+#else
+		generic_handle_irq_desc(desc);
+#endif
+	} else {
 		ack_APIC_irq();
 
 		if (desc != VECTOR_RETRIGGERED && desc != VECTOR_SHUTDOWN) {
arch/x86/kernel/irq_32.c +1 -6
index fc34816c6..a759ca97c 100644
@@ -148,18 +148,13 @@ void do_softirq_own_stack(void)
 	call_on_stack(__do_softirq, isp);
 }
 
-bool handle_irq(struct irq_desc *desc, struct pt_regs *regs)
+void handle_irq(struct irq_desc *desc, struct pt_regs *regs)
 {
 	int overflow = check_stack_overflow();
 
-	if (IS_ERR_OR_NULL(desc))
-		return false;
-
 	if (user_mode(regs) || !execute_on_irq_stack(overflow, desc)) {
 		if (unlikely(overflow))
 			print_stack_overflow();
 		generic_handle_irq_desc(desc);
 	}
-
-	return true;
 }
arch/x86/kernel/irq_64.c +0 -9
index 6bf6517a0..12df3a4ab 100644
@@ -26,15 +26,6 @@
 DEFINE_PER_CPU_PAGE_ALIGNED(struct irq_stack, irq_stack_backing_store) __visible;
 DECLARE_INIT_PER_CPU(irq_stack_backing_store);
 
-bool handle_irq(struct irq_desc *desc, struct pt_regs *regs)
-{
-	if (IS_ERR_OR_NULL(desc))
-		return false;
-
-	generic_handle_irq_desc(desc);
-	return true;
-}
-
 #ifdef CONFIG_VMAP_STACK
 /*
  * VMAP the backing store with guard pages
Signature · 1 line
2.22.1
#4 lore raw

[tip: x86/irq] x86/irq: Move IS_ERR_OR_NULL() check into common do_IRQ() code

The following commit has been merged into the x86/irq branch of tip:

The following commit has been merged into the x86/irq branch of tip:

Commit-ID:     d6f83427ff422b3a65e4a6bd84c010f78d4a30a5
Gitweb:        https://git.kernel.org/tip/d6f83427ff422b3a65e4a6bd84c010f78d4a30a5
Author:        Heiner Kallweit <[email protected]>
AuthorDate:    Mon, 19 Aug 2019 21:36:09 +02:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Mon, 19 Aug 2019 23:19:06 +02:00

x86/irq: Move IS_ERR_OR_NULL() check into common do_IRQ() code

Both the 64bit and the 32bit handle_irq() implementation check the irq descriptor pointer with IS_ERR_OR_NULL() and return failure. That can be done simpler in the common do_IRQ() code.

This reduces the 64bit handle_irq() function to a wrapper around generic_handle_irq_desc(). Invoke it directly from do_IRQ() to spare the extra function call.

[ tglx: Got rid of the #ifdef and massaged changelog ]

---
 arch/x86/include/asm/irq.h |  2 +-
 arch/x86/kernel/irq.c      |  8 ++++++--
 arch/x86/kernel/irq_32.c   |  7 +------
 arch/x86/kernel/irq_64.c   |  9 ---------
 4 files changed, 8 insertions(+), 18 deletions(-)
arch/x86/include/asm/irq.h +1 -1
index 8f95686..a176f61 100644
@@ -34,7 +34,7 @@ extern __visible void smp_kvm_posted_intr_nested_ipi(struct pt_regs *regs);
 extern void (*x86_platform_ipi_callback)(void);
 extern void native_init_IRQ(void);
 
-extern bool handle_irq(struct irq_desc *desc, struct pt_regs *regs);
+extern void handle_irq(struct irq_desc *desc, struct pt_regs *regs);
 
 extern __visible unsigned int do_IRQ(struct pt_regs *regs);
 
arch/x86/kernel/irq.c +6 -2
index 4215653..3eae012 100644
@@ -243,8 +243,12 @@ __visible unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
 	RCU_LOCKDEP_WARN(!rcu_is_watching(), "IRQ failed to wake up RCU");
 
 	desc = __this_cpu_read(vector_irq[vector]);
-
-	if (!handle_irq(desc, regs)) {
+	if (likely(!IS_ERR_OR_NULL(desc))) {
+		if (IS_ENABLED(CONFIG_X86_32))
+			handle_irq(desc, regs);
+		else
+			generic_handle_irq_desc(desc);
+	} else {
 		ack_APIC_irq();
 
 		if (desc != VECTOR_RETRIGGERED && desc != VECTOR_SHUTDOWN) {
arch/x86/kernel/irq_32.c +1 -6
index fc34816..a759ca9 100644
@@ -148,18 +148,13 @@ void do_softirq_own_stack(void)
 	call_on_stack(__do_softirq, isp);
 }
 
-bool handle_irq(struct irq_desc *desc, struct pt_regs *regs)
+void handle_irq(struct irq_desc *desc, struct pt_regs *regs)
 {
 	int overflow = check_stack_overflow();
 
-	if (IS_ERR_OR_NULL(desc))
-		return false;
-
 	if (user_mode(regs) || !execute_on_irq_stack(overflow, desc)) {
 		if (unlikely(overflow))
 			print_stack_overflow();
 		generic_handle_irq_desc(desc);
 	}
-
-	return true;
 }
arch/x86/kernel/irq_64.c +0 -9
index 6bf6517..12df3a4 100644
@@ -26,15 +26,6 @@
 DEFINE_PER_CPU_PAGE_ALIGNED(struct irq_stack, irq_stack_backing_store) __visible;
 DECLARE_INIT_PER_CPU(irq_stack_backing_store);
 
-bool handle_irq(struct irq_desc *desc, struct pt_regs *regs)
-{
-	if (IS_ERR_OR_NULL(desc))
-		return false;
-
-	generic_handle_irq_desc(desc);
-	return true;
-}
-
 #ifdef CONFIG_VMAP_STACK
 /*
  * VMAP the backing store with guard pages
#5 lore raw

PATCH v2 3/3 x86/irq: slightly improve do_IRQ

In reply to Heiner Kallweit

It's simpler and more intuitive to directly check for VECTOR_UNUSED.

---
 arch/x86/kernel/irq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/irq.c +1 -1
index f1c8f350d..857b4d7ae 100644
@@ -252,7 +252,7 @@ __visible unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
 	} else {
 		ack_APIC_irq();
 
-		if (desc != VECTOR_RETRIGGERED && desc != VECTOR_SHUTDOWN) {
+		if (desc == VECTOR_UNUSED) {
 			pr_emerg_ratelimited("%s: %d.%d No irq handler for vector\n",
 					     __func__, smp_processor_id(),
 					     vector);
Signature · 1 line
2.22.1
#6 lore raw

[tip: x86/irq] x86/irq: Check for VECTOR_UNUSED directly

The following commit has been merged into the x86/irq branch of tip:

The following commit has been merged into the x86/irq branch of tip:

Commit-ID:     8725fcd99a3084a7a15a6e70882bfa3fe7925f52
Gitweb:        https://git.kernel.org/tip/8725fcd99a3084a7a15a6e70882bfa3fe7925f52
Author:        Heiner Kallweit <[email protected]>
AuthorDate:    Mon, 19 Aug 2019 21:36:39 +02:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Mon, 19 Aug 2019 23:19:07 +02:00

x86/irq: Check for VECTOR_UNUSED directly

It's simpler and more intuitive to directly check for VECTOR_UNUSED than checking whether the other error codes are not set.

---
 arch/x86/kernel/irq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/irq.c +1 -1
index 3eae012..21efee3 100644
@@ -251,7 +251,7 @@ __visible unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
 	} else {
 		ack_APIC_irq();
 
-		if (desc != VECTOR_RETRIGGERED && desc != VECTOR_SHUTDOWN) {
+		if (desc == VECTOR_UNUSED) {
 			pr_emerg_ratelimited("%s: %d.%d No irq handler for vector\n",
 					     __func__, smp_processor_id(),
 					     vector);