Skip to content

Commit e875bd6

Browse files
paulburtonKAGA-KOKO
authored andcommitted
irqchip/mips-gic: Fix local interrupts
Since the device hierarchy domain was added by commit c98c182 ("irqchip/mips-gic: Add device hierarchy domain"), GIC local interrupts have been broken. Users attempting to setup a per-cpu local IRQ, for example the GIC timer clock events code in drivers/clocksource/mips-gic-timer.c, the setup_percpu_irq function would refuse with -EINVAL because the GIC irqchip driver never called irq_set_percpu_devid so the IRQ_PER_CPU_DEVID flag was never set for the IRQ. This happens because irq_set_percpu_devid was being called from the gic_irq_domain_map function which is no longer called. Doing only that runs into further problems because gic_dev_domain_alloc set the struct irq_chip for all interrupts, local or shared, to gic_level_irq_controller despite that only being suitable for shared interrupts. The typical outcome of this is that gic_level_irq_controller callback functions are called for local interrupts, and then hwirq number calculations overflow & the driver ends up attempting to access some invalid register with an address calculated from an invalid hwirq number. Best case scenario is that this then leads to a bus error. This is fixed by abstracting the setup of the hwirq & chip to a new function gic_setup_dev_chip which is used by both the root GIC IRQ domain & the device domain. Finally, decoding local interrupts failed because gic_dev_domain_alloc only called irq_domain_alloc_irqs_parent for shared interrupts. Local ones were therefore never associated with hwirqs in the root GIC IRQ domain and the virq in gic_handle_local_int would always be 0. This is fixed by calling irq_domain_alloc_irqs_parent unconditionally & having gic_irq_domain_alloc handle both local & shared interrupts, which is easy due to the aforementioned abstraction of chip setup into gic_setup_dev_chip. This fixes use of the MIPS GIC timer for clock events, which has been broken since c98c182 ("irqchip/mips-gic: Add device hierarchy domain") but hadn't been noticed due to a silent fallback to the MIPS coprocessor 0 count/compare clock events device. Fixes: c98c182 ("irqchip/mips-gic: Add device hierarchy domain") Signed-off-by: Paul Burton <paul.burton@imgtec.com> Cc: linux-mips@linux-mips.org Cc: Jason Cooper <jason@lakedaemon.net> Cc: Qais Yousef <qsyousef@gmail.com> Cc: stable@vger.kernel.org Cc: Marc Zyngier <marc.zyngier@arm.com> Link: http://lkml.kernel.org/r/20160913165335.31389-1-paul.burton@imgtec.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 727653d commit e875bd6

File tree

1 file changed

+50
-55
lines changed

1 file changed

+50
-55
lines changed

drivers/irqchip/irq-mips-gic.c

Lines changed: 50 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -638,27 +638,6 @@ static int gic_local_irq_domain_map(struct irq_domain *d, unsigned int virq,
638638
if (!gic_local_irq_is_routable(intr))
639639
return -EPERM;
640640

641-
/*
642-
* HACK: These are all really percpu interrupts, but the rest
643-
* of the MIPS kernel code does not use the percpu IRQ API for
644-
* the CP0 timer and performance counter interrupts.
645-
*/
646-
switch (intr) {
647-
case GIC_LOCAL_INT_TIMER:
648-
case GIC_LOCAL_INT_PERFCTR:
649-
case GIC_LOCAL_INT_FDC:
650-
irq_set_chip_and_handler(virq,
651-
&gic_all_vpes_local_irq_controller,
652-
handle_percpu_irq);
653-
break;
654-
default:
655-
irq_set_chip_and_handler(virq,
656-
&gic_local_irq_controller,
657-
handle_percpu_devid_irq);
658-
irq_set_percpu_devid(virq);
659-
break;
660-
}
661-
662641
spin_lock_irqsave(&gic_lock, flags);
663642
for (i = 0; i < gic_vpes; i++) {
664643
u32 val = GIC_MAP_TO_PIN_MSK | gic_cpu_pin;
@@ -724,16 +703,42 @@ static int gic_shared_irq_domain_map(struct irq_domain *d, unsigned int virq,
724703
return 0;
725704
}
726705

727-
static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq,
728-
irq_hw_number_t hw)
706+
static int gic_setup_dev_chip(struct irq_domain *d, unsigned int virq,
707+
unsigned int hwirq)
729708
{
730-
if (GIC_HWIRQ_TO_LOCAL(hw) < GIC_NUM_LOCAL_INTRS)
731-
return gic_local_irq_domain_map(d, virq, hw);
709+
struct irq_chip *chip;
710+
int err;
711+
712+
if (hwirq >= GIC_SHARED_HWIRQ_BASE) {
713+
err = irq_domain_set_hwirq_and_chip(d, virq, hwirq,
714+
&gic_level_irq_controller,
715+
NULL);
716+
} else {
717+
switch (GIC_HWIRQ_TO_LOCAL(hwirq)) {
718+
case GIC_LOCAL_INT_TIMER:
719+
case GIC_LOCAL_INT_PERFCTR:
720+
case GIC_LOCAL_INT_FDC:
721+
/*
722+
* HACK: These are all really percpu interrupts, but
723+
* the rest of the MIPS kernel code does not use the
724+
* percpu IRQ API for them.
725+
*/
726+
chip = &gic_all_vpes_local_irq_controller;
727+
irq_set_handler(virq, handle_percpu_irq);
728+
break;
729+
730+
default:
731+
chip = &gic_local_irq_controller;
732+
irq_set_handler(virq, handle_percpu_devid_irq);
733+
irq_set_percpu_devid(virq);
734+
break;
735+
}
732736

733-
irq_set_chip_and_handler(virq, &gic_level_irq_controller,
734-
handle_level_irq);
737+
err = irq_domain_set_hwirq_and_chip(d, virq, hwirq,
738+
chip, NULL);
739+
}
735740

736-
return gic_shared_irq_domain_map(d, virq, hw, 0);
741+
return err;
737742
}
738743

739744
static int gic_irq_domain_alloc(struct irq_domain *d, unsigned int virq,
@@ -744,15 +749,12 @@ static int gic_irq_domain_alloc(struct irq_domain *d, unsigned int virq,
744749
int cpu, ret, i;
745750

746751
if (spec->type == GIC_DEVICE) {
747-
/* verify that it doesn't conflict with an IPI irq */
748-
if (test_bit(spec->hwirq, ipi_resrv))
752+
/* verify that shared irqs don't conflict with an IPI irq */
753+
if ((spec->hwirq >= GIC_SHARED_HWIRQ_BASE) &&
754+
test_bit(GIC_HWIRQ_TO_SHARED(spec->hwirq), ipi_resrv))
749755
return -EBUSY;
750756

751-
hwirq = GIC_SHARED_TO_HWIRQ(spec->hwirq);
752-
753-
return irq_domain_set_hwirq_and_chip(d, virq, hwirq,
754-
&gic_level_irq_controller,
755-
NULL);
757+
return gic_setup_dev_chip(d, virq, spec->hwirq);
756758
} else {
757759
base_hwirq = find_first_bit(ipi_resrv, gic_shared_intrs);
758760
if (base_hwirq == gic_shared_intrs) {
@@ -821,7 +823,6 @@ int gic_irq_domain_match(struct irq_domain *d, struct device_node *node,
821823
}
822824

823825
static const struct irq_domain_ops gic_irq_domain_ops = {
824-
.map = gic_irq_domain_map,
825826
.alloc = gic_irq_domain_alloc,
826827
.free = gic_irq_domain_free,
827828
.match = gic_irq_domain_match,
@@ -852,29 +853,20 @@ static int gic_dev_domain_alloc(struct irq_domain *d, unsigned int virq,
852853
struct irq_fwspec *fwspec = arg;
853854
struct gic_irq_spec spec = {
854855
.type = GIC_DEVICE,
855-
.hwirq = fwspec->param[1],
856856
};
857857
int i, ret;
858-
bool is_shared = fwspec->param[0] == GIC_SHARED;
859858

860-
if (is_shared) {
861-
ret = irq_domain_alloc_irqs_parent(d, virq, nr_irqs, &spec);
862-
if (ret)
863-
return ret;
864-
}
865-
866-
for (i = 0; i < nr_irqs; i++) {
867-
irq_hw_number_t hwirq;
859+
if (fwspec->param[0] == GIC_SHARED)
860+
spec.hwirq = GIC_SHARED_TO_HWIRQ(fwspec->param[1]);
861+
else
862+
spec.hwirq = GIC_LOCAL_TO_HWIRQ(fwspec->param[1]);
868863

869-
if (is_shared)
870-
hwirq = GIC_SHARED_TO_HWIRQ(spec.hwirq + i);
871-
else
872-
hwirq = GIC_LOCAL_TO_HWIRQ(spec.hwirq + i);
864+
ret = irq_domain_alloc_irqs_parent(d, virq, nr_irqs, &spec);
865+
if (ret)
866+
return ret;
873867

874-
ret = irq_domain_set_hwirq_and_chip(d, virq + i,
875-
hwirq,
876-
&gic_level_irq_controller,
877-
NULL);
868+
for (i = 0; i < nr_irqs; i++) {
869+
ret = gic_setup_dev_chip(d, virq + i, spec.hwirq + i);
878870
if (ret)
879871
goto error;
880872
}
@@ -896,7 +888,10 @@ void gic_dev_domain_free(struct irq_domain *d, unsigned int virq,
896888
static void gic_dev_domain_activate(struct irq_domain *domain,
897889
struct irq_data *d)
898890
{
899-
gic_shared_irq_domain_map(domain, d->irq, d->hwirq, 0);
891+
if (GIC_HWIRQ_TO_LOCAL(d->hwirq) < GIC_NUM_LOCAL_INTRS)
892+
gic_local_irq_domain_map(domain, d->irq, d->hwirq);
893+
else
894+
gic_shared_irq_domain_map(domain, d->irq, d->hwirq, 0);
900895
}
901896

902897
static struct irq_domain_ops gic_dev_domain_ops = {

0 commit comments

Comments
 (0)