arm/arm64: fix a migrating irq bug when hotplug cpu
Subsystems (8)
v2 cover arm/arm64: fix a migrating irq bug when hotplug cpu
Hi All,
There is a bug:
When cpu is disabled, all irqs will be migratged to another cpu. In some cases, a new affinity is different, it needed to be coppied to irq's affinity. But if the type of irq is LPI, it's affinity will not be coppied because of irq_set_affinity's return value.
As Marc and Will suggested, I refactor the arm/arm64 migrating interrupts code and fix the migrating irq bug while cpu is offline.
I'm trying let the core code do the migrating interrupts matter. kernel/irq/migration.c depends on CONFIG_GENERIC_PENDING_IRQ, so I make it selected by CONFIG_SMP and CONFIG_HOTPLUG_CPU and rename it to CONFIG_GENERIC_IRQ_MIGRATION for more general. When CONFIG_GENERIC_IRQ_MIGRATION is enabled, an interrupt whose state_use_accessors is not set with IRQD_MOVE_PCNTXT won't be migrated immediately in irq_set_affinity_locked(). So use irq_set_status_flags() helper to set the state in gic_irq_domain_map().
With the above preparation, move the migrating interrupts code into kernel/irq/migration.c and fix the bug by using irq_do_set_affinity().
Changes in v2:
- use the exiting helper to set IRQD_MOVE_PCNTXT flag
- use for_each_active_irq() instead of for_each_irq_desc()
- add some warn messages when affinity is null or do set affinity failed
Yang Yingliang (3):
irqchip: GICv3: set non-percpu irqs status with IRQ_MOVE_PCNTXT
genirq: rename config GENERIC_PENDING_IRQ to GENERIC_IRQ_MIGRATION arm/arm64: fix a migrating irq bug when hotplug cpu
arch/arc/Kconfig | 2 +- arch/arm/Kconfig | 1 + arch/arm/include/asm/irq.h | 1 - arch/arm/kernel/irq.c | 62 --------------------------------------- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/irq.h | 1 - arch/arm64/kernel/irq.c | 62 --------------------------------------- arch/hexagon/Kconfig | 2 +- arch/ia64/Kconfig | 2 +- arch/tile/Kconfig | 2 +- arch/x86/Kconfig | 2 +- arch/x86/kernel/apic/io_apic.c | 2 +- drivers/irqchip/irq-gic-v3.c | 2 ++ include/linux/irq.h | 4 ++- include/linux/irqdesc.h | 2 +- kernel/irq/Kconfig | 4 +-- kernel/irq/Makefile | 2 +- kernel/irq/irqdesc.c | 6 ++-- kernel/irq/manage.c | 2 +- kernel/irq/migration.c | 66 ++++++++++++++++++++++++++++++++++++++++++ kernel/irq/proc.c | 2 +- 21 files changed, 88 insertions(+), 142 deletions(-)
Signature · 1 line
2.5.0
RFC PATCH v2 1/3 irqchip: GICv3: set non-percpu irqs status with IRQ_MOVE_PCNTXT
Use irq_set_status_flags() helper set irqs status with IRQ_MOVE_PCNTXT. So that it can do set affinity when calling irq_set_affinity_locked().
--- drivers/irqchip/irq-gic-v3.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/irqchip/irq-gic-v3.c +2 -0
@@ -761,6 +761,7 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int irq,irq_domain_set_info (d, irq, hw, chip, d->host_data, handle_fasteoi_irq,NULL ,NULL );set_irq_flags (irq,IRQF_VALID |IRQF_PROBE ); +irq_set_status_flags (irq,IRQ_MOVE_PCNTXT ); }/* LPIs */ if (hw >=8192 && hw <GIC_ID_NR ) {
@@ -769,6 +770,7 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int irq,irq_domain_set_info (d, irq, hw, chip, d->host_data, handle_fasteoi_irq,NULL ,NULL );set_irq_flags (irq,IRQF_VALID ); +irq_set_status_flags (irq,IRQ_MOVE_PCNTXT ); }return 0 ;
Signature · 1 line
2.5.0
Re: [RFC PATCH v2 1/3] irqchip: GICv3: set non-percpu irqs status with IRQ_MOVE_PCNTXT
Quoted 29 lines · Yang Yingliang
Use
irq_set_status_flags()helper set irqs status withIRQ_MOVE_PCNTXT. So that it can do set affinity when callingirq_set_affinity_locked().Cc Jiang Liu <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Marc Zyngier <[email protected]>Cc Mark Rutland <[email protected]>Cc Will Deacon <[email protected]>Cc Russell King - ARM Linux <[email protected]>Signed-off-by Yang Yingliang <[email protected]>--- drivers/irqchip/irq-gic-v3.c | 2 ++ 1 file changed, 2 insertions(+)drivers/irqchip/irq-gic-v3.c +1
-0@@ -761,6 +761,7 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int irq,irq_domain_set_info (d, irq, hw, chip, d->host_data, handle_fasteoi_irq,NULL ,NULL );set_irq_flags (irq,IRQF_VALID |IRQF_PROBE ); +irq_set_status_flags (irq,IRQ_MOVE_PCNTXT ); }/* LPIs */ if (hw >=8192 && hw <GIC_ID_NR ) {
drivers/irqchip/irq-gic-v3.c static int gic_irq_domain_map(struct irq_domain *d, unsigned int irq, · line 776
Quoted 7 lines
drivers/irqchip/irq-gic-v3.c +1
-0@@ -769,6 +770,7 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int irq,irq_domain_set_info (d, irq, hw, chip, d->host_data, handle_fasteoi_irq,NULL ,NULL );set_irq_flags (irq,IRQF_VALID ); +irq_set_status_flags (irq,IRQ_MOVE_PCNTXT ); }return 0 ;
I'm still not keen on this approach. As far as I can tell, the only reason you are setting this flag is to be able to use GENERIC_PENDING_IRQ. irq_set_affinity_locked would work even if you don't select this config option, because irq_can_move_pcntxt() will always return true if this is not selected.
So instead of adding flags that are not required on ARM, why don't you just make migration.c to compile even when GENERIC_PENDING_IRQ is not selected? I think this would make a lot more sense.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [RFC PATCH v2 1/3] irqchip: GICv3: set non-percpu irqs status with IRQ_MOVE_PCNTXT
Quoted 44 lines · Marc Zyngier
Quoted 29 lines · Yang Yingliang
Use
irq_set_status_flags()helper set irqs status withIRQ_MOVE_PCNTXT. So that it can do set affinity when callingirq_set_affinity_locked().Cc Jiang Liu <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Marc Zyngier <[email protected]>Cc Mark Rutland <[email protected]>Cc Will Deacon <[email protected]>Cc Russell King - ARM Linux <[email protected]>Signed-off-by Yang Yingliang <[email protected]>--- drivers/irqchip/irq-gic-v3.c | 2 ++ 1 file changed, 2 insertions(+)drivers/irqchip/irq-gic-v3.c +1
-0@@ -761,6 +761,7 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int irq,irq_domain_set_info (d, irq, hw, chip, d->host_data, handle_fasteoi_irq,NULL ,NULL );set_irq_flags (irq,IRQF_VALID |IRQF_PROBE ); +irq_set_status_flags (irq,IRQ_MOVE_PCNTXT ); }/* LPIs */ if (hw >=8192 && hw <GIC_ID_NR ) {drivers/irqchip/irq-gic-v3.c static int gic_irq_domain_map(struct irq_domain *d, unsigned int irq, · line 776
Quoted 7 lines
drivers/irqchip/irq-gic-v3.c +1
-0@@ -769,6 +770,7 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int irq,irq_domain_set_info (d, irq, hw, chip, d->host_data, handle_fasteoi_irq,NULL ,NULL );set_irq_flags (irq,IRQF_VALID ); +irq_set_status_flags (irq,IRQ_MOVE_PCNTXT ); }return 0 ;I'm still not keen on this approach. As far as I can tell, the only reason you are setting this flag is to be able to use
GENERIC_PENDING_IRQ.irq_set_affinity_lockedwould work even if you don't select this config option, becauseirq_can_move_pcntxt()will always return true if this is not selected.
Quoted 3 lines
So instead of adding flags that are not required on ARM, why don't you just make
migration.cto compile even whenGENERIC_PENDING_IRQis not selected? I think this would make a lot more sense.
OK, I will try this way.
Thanks,
Yang
Quoted 5 lines
Thanks,
M.
RFC PATCH v2 2/3 genirq: rename config GENERIC_PENDING_IRQ to GENERIC_IRQ_MIGRATION
In reply to Yang YingliangMake the config name more general for moving other migration interrupts code into kernel/irq/migration.c
--- arch/arc/Kconfig | 2 +- arch/hexagon/Kconfig | 2 +- arch/ia64/Kconfig | 2 +- arch/tile/Kconfig | 2 +- arch/x86/Kconfig | 2 +- arch/x86/kernel/apic/io_apic.c | 2 +- include/linux/irq.h | 4 +++- include/linux/irqdesc.h | 2 +- kernel/irq/Kconfig | 4 ++-- kernel/irq/Makefile | 2 +- kernel/irq/irqdesc.c | 6 +++--- kernel/irq/manage.c | 2 +- kernel/irq/proc.c | 2 +- 13 files changed, 18 insertions(+), 16 deletions(-)
arch/arc/Kconfig +1 -1
@@ -19,7 +19,7 @@ config ARC select GENERIC_FIND_FIRST_BIT # for now, we don't need GENERIC_IRQ_PROBE, CONFIG_GENERIC_IRQ_CHIP select GENERIC_IRQ_SHOW - select GENERIC_PENDING_IRQ if SMP + select GENERIC_IRQ_MIGRATION if SMP select GENERIC_SMP_IDLE_THREAD select HAVE_ARCH_KGDB select HAVE_ARCH_TRACEHOOK
arch/hexagon/Kconfig +1 -1
@@ -11,7 +11,7 @@ config HEXAGON # select ARCH_WANT_OPTIONAL_GPIOLIB # select ARCH_REQUIRE_GPIOLIB # select HAVE_CLK - # select GENERIC_PENDING_IRQ if SMP + # select GENERIC_IRQ_MIGRATION if SMP select GENERIC_ATOMIC64 select HAVE_PERF_EVENTS # GENERIC_ALLOCATOR is used by dma_alloc_coherent()
arch/ia64/Kconfig +1 -1
@@ -36,7 +36,7 @@ config IA64 select VIRT_TO_BUS select ARCH_DISCARD_MEMBLOCK select GENERIC_IRQ_PROBE - select GENERIC_PENDING_IRQ if SMP + select GENERIC_IRQ_MIGRATION if SMP select GENERIC_IRQ_SHOW select GENERIC_IRQ_LEGACY select ARCH_WANT_OPTIONAL_GPIOLIB
arch/tile/Kconfig +1 -1
@@ -13,7 +13,7 @@ config TILE select CC_OPTIMIZE_FOR_SIZE select HAVE_DEBUG_KMEMLEAK select GENERIC_IRQ_PROBE - select GENERIC_PENDING_IRQ if SMP + select GENERIC_IRQ_MIGRATION if SMP select GENERIC_IRQ_SHOW select HAVE_DEBUG_BUGVERBOSE select VIRT_TO_BUS
arch/x86/Kconfig +1 -1
@@ -67,7 +67,7 @@ config X86 select GENERIC_IOMAP select GENERIC_IRQ_PROBE select GENERIC_IRQ_SHOW - select GENERIC_PENDING_IRQ if SMP + select GENERIC_IRQ_MIGRATION if SMP select GENERIC_SMP_IDLE_THREAD select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER
arch/x86/kernel/apic/io_apic.c +1 -1
@@ -1684,7 +1684,7 @@ static unsigned int startup_ioapic_irq(struct irq_data *data)atomic_t irq_mis_count; -#ifdef CONFIG_GENERIC_PENDING_IRQ +#ifdef CONFIG_GENERIC_IRQ_MIGRATION static bool io_apic_level_ack_pending (struct mp_chip_data *data) {struct irq_pin_list *entry;
include/linux/irq.h +3 -1
@@ -438,12 +438,14 @@ extern int irq_set_affinity_locked(struct irq_data *data, const struct cpumask *cpumask, bool force);extern int irq_set_vcpu_affinity (unsigned int irq,void *vcpu_info); -#if defined(CONFIG_SMP ) && defined(CONFIG_GENERIC_PENDING_IRQ ) +#if defined(CONFIG_SMP ) && defined(CONFIG_GENERIC_IRQ_MIGRATION )void irq_move_irq (struct irq_data *data);void irq_move_masked_irq (struct irq_data *data); +void migrate_irqs (void );#else static inline void irq_move_irq (struct irq_data *data) { }static inline void irq_move_masked_irq (struct irq_data *data) { } +static inline void migrate_irqs (void ) { }#endif extern int no_irq_affinity;
include/linux/irqdesc.h +1 -1
@@ -66,7 +66,7 @@ struct irq_desc {#ifdef CONFIG_SMP const struct cpumask *affinity_hint;struct irq_affinity_notify *affinity_notify; -#ifdef CONFIG_GENERIC_PENDING_IRQ +#ifdef CONFIG_GENERIC_IRQ_MIGRATION cpumask_var_t pending_mask;#endif #endif
kernel/irq/Kconfig +2 -2
@@ -26,8 +26,8 @@ config GENERIC_IRQ_SHOW_LEVEL config GENERIC_IRQ_LEGACY_ALLOC_HWIRQ bool -# Support for delayed migration from interrupt context -config GENERIC_PENDING_IRQ +# Support for generic irq migration +config GENERIC_IRQ_MIGRATION bool # Alpha specific irq affinity mechanism
kernel/irq/Makefile +1 -1
@@ -4,6 +4,6 @@ obj-$(CONFIG_GENERIC_IRQ_CHIP) += generic-chip.o obj-$(CONFIG_GENERIC_IRQ_PROBE) += autoprobe.o obj-$(CONFIG_IRQ_DOMAIN) += irqdomain.o obj-$(CONFIG_PROC_FS) += proc.o -obj-$(CONFIG_GENERIC_PENDING_IRQ) += migration.o +obj-$(CONFIG_GENERIC_IRQ_MIGRATION) += migration.o obj-$(CONFIG_PM_SLEEP) += pm.o obj-$(CONFIG_GENERIC_MSI_IRQ) += msi.o
kernel/irq/irqdesc.c +3 -3
@@ -41,7 +41,7 @@ static int alloc_masks(struct irq_desc *desc, gfp_t gfp, int node)if (!zalloc_cpumask_var_node (&desc->irq_data.affinity, gfp, node))return -ENOMEM ; -#ifdef CONFIG_GENERIC_PENDING_IRQ +#ifdef CONFIG_GENERIC_IRQ_MIGRATION if (!zalloc_cpumask_var_node (&desc->pending_mask, gfp, node)) {free_cpumask_var (desc->irq_data.affinity);return -ENOMEM ;
@@ -54,7 +54,7 @@ static void desc_smp_init(struct irq_desc *desc, int node) { desc->irq_data.node = node;cpumask_copy (desc->irq_data.affinity, irq_default_affinity); -#ifdef CONFIG_GENERIC_PENDING_IRQ +#ifdef CONFIG_GENERIC_IRQ_MIGRATION cpumask_clear (desc->pending_mask);#endif }
@@ -118,7 +118,7 @@ static void delete_irq_desc(unsigned int irq)#ifdef CONFIG_SMP static void free_masks (struct irq_desc *desc) { -#ifdef CONFIG_GENERIC_PENDING_IRQ +#ifdef CONFIG_GENERIC_IRQ_MIGRATION free_cpumask_var (desc->pending_mask);#endif free_cpumask_var (desc->irq_data.affinity);
kernel/irq/manage.c +1 -1
@@ -153,7 +153,7 @@ void irq_set_thread_affinity(struct irq_desc *desc) } } -#ifdef CONFIG_GENERIC_PENDING_IRQ +#ifdef CONFIG_GENERIC_IRQ_MIGRATION static inline bool irq_can_move_pcntxt (struct irq_data *data) {return irqd_can_move_in_process_context (data);
kernel/irq/proc.c +1 -1
@@ -41,7 +41,7 @@ static int show_irq_affinity(int type, struct seq_file *m, void *v)struct irq_desc *desc =irq_to_desc ((long )m->private);const struct cpumask *mask = desc->irq_data.affinity; -#ifdef CONFIG_GENERIC_PENDING_IRQ +#ifdef CONFIG_GENERIC_IRQ_MIGRATION if (irqd_is_setaffinity_pending (&desc->irq_data)) mask = desc->pending_mask;#endif
Signature · 1 line
2.5.0
RFC PATCH v2 3/3 arm/arm64: fix a migrating irq bug when hotplug cpu
In reply to Yang YingliangWhen cpu is disabled, all irqs will be migratged to another cpu. In some cases, a new affinity is different, it needed to be coppied to irq's affinity. But if the type of irq is LPI, it's affinity will not be coppied because of irq_set_affinity's return value. Fix it by using irq_do_set_affinity.
And migrating interrupts is a core code matter, so move the code to kernel/irq/migration.c and select CONFIG_GENERIC_IRQ_MIGRATION when CONFIG_HOTPLUG_CPU and CONFIG_SMP is enabled.
--- arch/arm/Kconfig | 1 + arch/arm/include/asm/irq.h | 1 - arch/arm/kernel/irq.c | 62 ----------------------------------------- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/irq.h | 1 - arch/arm64/kernel/irq.c | 62 ----------------------------------------- kernel/irq/migration.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 68 insertions(+), 126 deletions(-)
arch/arm/Kconfig +1 -0
@@ -22,6 +22,7 @@ config ARM select GENERIC_CLOCKEVENTS_BROADCAST if SMP select GENERIC_IDLE_POLL_SETUP select GENERIC_IRQ_PROBE + select GENERIC_IRQ_MIGRATION if SMP && HOTPLUG_CPU select GENERIC_IRQ_SHOW select GENERIC_IRQ_SHOW_LEVEL select GENERIC_PCI_IOMAP
arch/arm/include/asm/irq.h +0 -1
@@ -24,7 +24,6 @@#ifndef __ASSEMBLY__struct irqaction ;struct pt_regs ; -extern void migrate_irqs (void );extern void asm_do_IRQ (unsigned int ,struct pt_regs *);void handle_IRQ (unsigned int ,struct pt_regs *);
arch/arm/kernel/irq.c +0 -62
71 lines not on this page · raw message
arch/arm64/Kconfig +1 -0
@@ -33,6 +33,7 @@ config ARM64 select GENERIC_CPU_AUTOPROBE select GENERIC_EARLY_IOREMAP select GENERIC_IRQ_PROBE + select GENERIC_IRQ_MIGRATION if SMP && HOTPLUG_CPU select GENERIC_IRQ_SHOW select GENERIC_IRQ_SHOW_LEVEL select GENERIC_PCI_IOMAP
arch/arm64/include/asm/irq.h +0 -1
@@ -7,7 +7,6 @@struct pt_regs ; -extern void migrate_irqs (void );extern void set_handle_irq (void (*handle_irq)(struct pt_regs *));static inline void acpi_irq_init (void )
arch/arm64/kernel/irq.c +0 -62
71 lines not on this page · raw message
kernel/irq/migration.c +66 -0
75 lines not on this page · raw message
Signature · 1 line
2.5.0