Skip to contentSkip to conversation

x86/irq: slightly improve handle_irq

PATCH Superseded Heiner Kallweit 2 participants 5 messages Aug 4, 2019 – Aug 19, 2019 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover x86/irq: slightly improve handle_irq

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

Heiner Kallweit (3):
x86/irq: improve definition of VECTOR_SHUTDOWN et al x86/irq: factor out IS_ERR_OR_NULL check from platfom-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         | 7 ++++---
 arch/x86/kernel/irq_32.c      | 7 +------
 arch/x86/kernel/irq_64.c      | 6 +-----
 5 files changed, 9 insertions(+), 17 deletions(-)
Signature · 1 line
2.22.0
#1 lore raw

PATCH 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.0
#2 lore raw

PATCH 2/3 x86/irq: factor out IS_ERR_OR_NULL check from platfom-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.

---
 arch/x86/include/asm/irq.h | 2 +-
 arch/x86/kernel/irq.c      | 5 +++--
 arch/x86/kernel/irq_32.c   | 7 +------
 arch/x86/kernel/irq_64.c   | 6 +-----
 4 files changed, 6 insertions(+), 14 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 +3 -2
index 4215653f8..042f363a8 100644
@@ -243,8 +243,7 @@ __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 (IS_ERR_OR_NULL(desc)) {
 		ack_APIC_irq();
 
 		if (desc != VECTOR_RETRIGGERED && desc != VECTOR_SHUTDOWN) {
@@ -254,6 +253,8 @@ __visible unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
 		} else {
 			__this_cpu_write(vector_irq[vector], VECTOR_UNUSED);
 		}
+	} else {
+		handle_irq(desc, regs);
 	}
 
 	exiting_irq();
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 +1 -5
index 6bf6517a0..cd4595b71 100644
@@ -26,13 +26,9 @@
 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)
+void 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
Signature · 1 line
2.22.0
#3 lore raw

Re: [PATCH 2/3] x86/irq: factor out IS_ERR_OR_NULL check from platfom-specific handle_irq

arch/x86/kernel/irq.c __visible unsigned int __irq_entry do_IRQ(struct pt_regs *regs) · line 246

Quoted 3 lines · Heiner Kallweit
arch/x86/kernel/irq.c +1 -2
-
-	if (!handle_irq(desc, regs)) {
+	if (IS_ERR_OR_NULL(desc)) {

This really want's an unlikely or preferrably be written as:

	if (likely(!IS_ERR_OR_NULL(desc))) {
		handle_irq(desc);
	} else {
Quoted 16 lines
arch/x86/kernel/irq.c +2 -0
 		ack_APIC_irq();
 
 		if (desc != VECTOR_RETRIGGERED && desc != VECTOR_SHUTDOWN) {
@@ -254,6 +253,8 @@ __visible unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
 		} else {
 			__this_cpu_write(vector_irq[vector], VECTOR_UNUSED);
 		}
+	} else {
+		handle_irq(desc, regs);
 	}
 
arch/x86/kernel/irq_64.c +0 -0
index 6bf6517a0..cd4595b71 100644

arch/x86/kernel/irq_64.c line 31

Quoted 10 lines
arch/x86/kernel/irq_64.c +1 -4
@@ -26,13 +26,9 @@
 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)
+void handle_irq(struct irq_desc *desc, struct pt_regs *regs)
 {
-	if (IS_ERR_OR_NULL(desc))
-		return false;
-
 	generic_handle_irq_desc(desc);

With that the function call does not make any sense for 64bit. So the wrapper should be an inline and only for 32bit a function call.

Thanks,

tglx

#4 lore raw

PATCH 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 042f363a8..2f1a78c4d 100644
@@ -246,7 +246,7 @@ __visible unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
 	if (IS_ERR_OR_NULL(desc)) {
 		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.0