irqchip/sifive-plic: add irq_mask and irq_unmask
Subsystems (4)
PATCH 1/1 irqchip/sifive-plic: add irq_mask and irq_unmask
As per the existing comment, irq_mask and irq_unmask do not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g., include/linux/irqchip/chained_irq.h).
--- drivers/irqchip/irq-sifive-plic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/irqchip/irq-sifive-plic.c +9 -4
@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d)plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); } +/* +* There is no need to mask/unmask PLIC interrupts. They are "masked" +* by reading claim and "unmasked" when writing it back. +*/ +static void plic_irq_mask (struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { } +#ifdef CONFIG_SMP static int plic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force)
@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d,static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* -* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask, #ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity, #endif
Signature · 1 line
2.20.1
Quoted 34 lines · Darius Rad
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +7
-1@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d)plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); } +/* +* There is no need to mask/unmask PLIC interrupts. They are "masked" +* by reading claim and "unmasked" when writing it back. +*/ +static void plic_irq_mask (struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { } +#ifdef CONFIG_SMP static int plic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force)@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d,static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/*
drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 154
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask,#ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity,#endif
I can't find any other drivers in irqchip with empty irq_mask/irq_unmask. I'm not well versed in irqchip stuff, so I'll leave it up to the irqchip maintainers to comment on if this is the right way to do this. Either way, I'm assuming it'll go in through some the irqchip tree so
just to make sure I don't get in the way if it is the right way to do it :).
I had issues with that plic driver. The current implementation wasn't usable with driver using level sensitive interrupt together with the IRQF_ONESHOT flag.
Those null were producing crashes in the chained_irq_enter function. Filling them with dummy function fixed the issue.
Quoted 60 lines · Palmer Dabbelt
Quoted 34 lines · Darius Rad
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +7
-1@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d)plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); } +/* +* There is no need to mask/unmask PLIC interrupts. They are "masked" +* by reading claim and "unmasked" when writing it back. +*/ +static void plic_irq_mask (struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { } +#ifdef CONFIG_SMP static int plic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force)@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d,static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 154
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask,#ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity,#endif I can't find any other drivers in irqchip with empty irq_mask/irq_unmask. I'm not well versed in irqchip stuff, so I'll leave it up to the irqchip maintainers to comment on if this is the right way to do this. Either way, I'm assuming it'll go in through some the irqchip tree so
Acked-by Palmer Dabbelt <[email protected]>just to make sure I don't get in the way if it is the right way to do it :).
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 6 lines · On Sat, 14 Sep 2019 12:42:32 PDT (-0700), [email protected] wrote:
I had issues with that plic driver. The current implementation wasn't usable with driver using level sensitive interrupt together with the
IRQF_ONESHOTflag.Those null were producing crashes in the
chained_irq_enterfunction. Filling them with dummy function fixed the issue.
I'm not arguing it fixes a crash, the code Darius pointed to obviously doesn't check for NULL before calling these functions and will therefor crash. There is a bunch of other code that does check, though, so I guess my question is really: is the bug in the PLIC driver, or in this header?
If we're not allowed to have these as NULL and there's nothing to do, then this is a reasonable patch. I'm just not capable of answering that question, as I'm not an irqchip maintainer :)
Quoted 61 lines · Palmer Dabbelt
Quoted 60 lines · Darius Rad
Quoted 34 lines
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +7
-1@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d)plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); } +/* +* There is no need to mask/unmask PLIC interrupts. They are "masked" +* by reading claim and "unmasked" when writing it back. +*/ +static void plic_irq_mask (struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { } +#ifdef CONFIG_SMP static int plic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force)@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d,static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 154
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask,#ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity,#endif I can't find any other drivers in irqchip with empty irq_mask/irq_unmask. I'm not well versed in irqchip stuff, so I'll leave it up to the irqchip maintainers to comment on if this is the right way to do this. Either way, I'm assuming it'll go in through some the irqchip tree so
Acked-by Palmer Dabbelt <[email protected]>just to make sure I don't get in the way if it is the right way to do it :).
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
On Thu, 12 Sep 2019 22:40:34 +0100,
Darius Rad <[email protected]> wrote:
Hi Darius,
Quoted 17 lines
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +0
-0
drivers/irqchip/irq-sifive-plic.c static void plic_irq_disable(struct irq_data *d) · line 119
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +6
-0@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d)plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); } +/* +* There is no need to mask/unmask PLIC interrupts. They are "masked" +* by reading claim and "unmasked" when writing it back. +*/ +static void plic_irq_mask (struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { }
This outlines a bigger issue. If your irqchip doesn't require mask/unmask, you're probably not using the right interrupt flow. Looking at the code, I see you're using handle_simple_irq, which is almost universally wrong.
As per the description above, these interrupts should be using the fasteoi flow, which is designed for this exact behaviour (the interrupt controller knows which interrupt is in flight and doesn't require SW to do anything bar signalling the EOI).
Another thing is that mask/unmask tends to be a requirement, while enable/disable tends to be optional. There is no hard line here, but the expectations are that:
(a) A disabled line can drop interrupts
(b) A masked line cannot drop interrupts
Depending what the PLIC architecture mandates, you'll need to implement one and/or the other. Having just (a) is indicative of a HW bug, and I'm not assuming that this is the case. (b) only is pretty common, and (a)+(b) has a few adepts. My bet is that it requires (b) only.
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +1
-1+#ifdef CONFIG_SMP static int plic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force)@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d,static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/*
drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 154
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask,#ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity,#endif
Can you give the following patch a go? It brings the irq flow in line with what the HW can do. It is of course fully untested (not even compile tested...).
Thanks,
M.
From c0ce33a992ec18f5d3bac7f70de62b1ba2b42090 Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Sun, 15 Sep 2019 15:17:45 +0100
Subject: [PATCH] irqchip/sifive-plic: Switch to fasteoi flow
The SiFive PLIC interrupt controller seems to have all the HW features to support the fasteoi flow, but the driver seems to be stuck in a distant past. Bring it into the 21st century.
--- drivers/irqchip/irq-sifive-plic.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/irqchip/irq-sifive-plic.c +15 -14
@@ -97,7 +97,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, } } -static void plic_irq_enable (struct irq_data *d) +static void plic_irq_mask (struct irq_data *d) {unsigned int cpu =cpumask_any_and (irq_data_get_affinity_mask (d), cpu_online_mask);
@@ -106,7 +106,7 @@ static void plic_irq_enable(struct irq_data *d)plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 ); } -static void plic_irq_disable (struct irq_data *d) +static void plic_irq_unmask (struct irq_data *d) {plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); }
@@ -125,10 +125,8 @@ static int plic_set_affinity(struct irq_data *d,if (cpu >= nr_cpu_ids)return -EINVAL ; -if (!irqd_irq_disabled (d)) { -plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); -plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 ); - } +plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); +plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 );irq_data_update_effective_affinity (d,cpumask_of (cpu));
@@ -136,14 +134,18 @@ static int plic_set_affinity(struct irq_data *d, }#endif +static void plic_irq_eoi (struct irq_data *d) +{ +struct plic_handler *handler =this_cpu_ptr (&plic_handlers); + +writel (d->hwirq, handler->hart_base +CONTEXT_CLAIM ); +} +static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* -* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ - .irq_enable = plic_irq_enable, - .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask, + .irq_eoi = plic_irq_eoi, #ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity, #endif
@@ -152,7 +154,7 @@ static struct irq_chip plic_chip = {static int plic_irqdomain_map (struct irq_domain *d,unsigned int irq,irq_hw_number_t hwirq) { -irq_set_chip_and_handler (irq, &plic_chip, handle_simple_irq); +irq_set_chip_and_handler (irq, &plic_chip, handle_fasteoi_irq);irq_set_chip_data (irq,NULL );irq_set_noprobe (irq);return 0 ;
@@ -188,7 +190,6 @@ static void plic_handle_irq(struct pt_regs *regs) hwirq); elsegeneric_handle_irq (irq ); -writel (hwirq, claim); }csr_set (sie,SIE_SEIE ); }
Signature · 5 lines
2.20.1 -- Jazz is not dead, it just smells funny.
Quoted 83 lines · On Sun, 15 Sep 2019 07:24:20 PDT (-0700), [email protected] wrote:
On Thu, 12 Sep 2019 22:40:34 +0100,
Darius Rad <[email protected]> wrote:Hi Darius,
Quoted 17 lines
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +0
-0drivers/irqchip/irq-sifive-plic.c static void plic_irq_disable(struct irq_data *d) · line 119
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +6
-0@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d)plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); } +/* +* There is no need to mask/unmask PLIC interrupts. They are "masked" +* by reading claim and "unmasked" when writing it back. +*/ +static void plic_irq_mask (struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { }This outlines a bigger issue. If your irqchip doesn't require mask/unmask, you're probably not using the right interrupt flow. Looking at the code, I see you're using
handle_simple_irq, which is almost universally wrong.As per the description above, these interrupts should be using the fasteoi flow, which is designed for this exact behaviour (the interrupt controller knows which interrupt is in flight and doesn't require SW to do anything bar signalling the EOI).
Another thing is that mask/unmask tends to be a requirement, while enable/disable tends to be optional. There is no hard line here, but the expectations are that:
(a) A disabled line can drop interrupts
(b) A masked line cannot drop interruptsDepending what the PLIC architecture mandates, you'll need to implement one and/or the other. Having just (a) is indicative of a HW bug, and I'm not assuming that this is the case. (b) only is pretty common, and (a)+(b) has a few adepts. My bet is that it requires (b) only.
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +1
-1+#ifdef CONFIG_SMP static int plic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force)@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d,static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 154
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask,#ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity,#endif Can you give the following patch a go? It brings the irq flow in line with what the HW can do. It is of course fully untested (not even compile tested...).
Thanks,
M.
Quoted 8 lines
From
c0ce33a992ec18f5d3bac7f70de62b1ba2b42090Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Sun, 15 Sep 2019 15:17:45 +0100
Subject: [PATCH] irqchip/sifive-plic: Switch to fasteoi flowThe SiFive PLIC interrupt controller seems to have all the HW features to support the fasteoi flow, but the driver seems to be stuck in a distant past. Bring it into the 21st century.
Thanks. We'd gotten these comments during the review process but nobody had gotten the time to actually fix the issues.
Quoted 89 lines
Signed-off-by Marc Zyngier <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)drivers/irqchip/irq-sifive-plic.c +15
-14@@ -97,7 +97,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, } } -static void plic_irq_enable (struct irq_data *d) +static void plic_irq_mask (struct irq_data *d) {unsigned int cpu =cpumask_any_and (irq_data_get_affinity_mask (d), cpu_online_mask);@@ -106,7 +106,7 @@ static void plic_irq_enable(struct irq_data *d)plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 ); } -static void plic_irq_disable (struct irq_data *d) +static void plic_irq_unmask (struct irq_data *d) {plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); }@@ -125,10 +125,8 @@ static int plic_set_affinity(struct irq_data *d,if (cpu >= nr_cpu_ids)return -EINVAL ; -if (!irqd_irq_disabled (d)) { -plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); -plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 ); - } +plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); +plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 );irq_data_update_effective_affinity (d,cpumask_of (cpu));@@ -136,14 +134,18 @@ static int plic_set_affinity(struct irq_data *d, }#endif +static void plic_irq_eoi (struct irq_data *d) +{ +struct plic_handler *handler =this_cpu_ptr (&plic_handlers); + +writel (d->hwirq, handler->hart_base +CONTEXT_CLAIM ); +} +static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* -* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ - .irq_enable = plic_irq_enable, - .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask, + .irq_eoi = plic_irq_eoi, #ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity, #endif@@ -152,7 +154,7 @@ static struct irq_chip plic_chip = {static int plic_irqdomain_map (struct irq_domain *d,unsigned int irq,irq_hw_number_t hwirq) { -irq_set_chip_and_handler (irq, &plic_chip, handle_simple_irq); +irq_set_chip_and_handler (irq, &plic_chip, handle_fasteoi_irq);irq_set_chip_data (irq,NULL );irq_set_noprobe (irq);return 0 ;@@ -188,7 +190,6 @@ static void plic_handle_irq(struct pt_regs *regs) hwirq); elsegeneric_handle_irq (irq ); -writel (hwirq, claim); }csr_set (sie,SIE_SEIE ); }Signature · 5 lines
2.20.1 -- Jazz is not dead, it just smells funny.
We should test them on the hardware, but I don't have any with me right now. David's probably in the best spot to do this, as he's got a setup that does all the weird interrupt sources (ie, PCIe).
David: do you mind testing this? I've put the patch here:
ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/palmer/linux.git -b plic-fasteoi
On Sun, 15 Sep 2019 18:31:33 +0100,
Palmer Dabbelt <[email protected]> wrote:
Hi Palmer,
Quoted 88 lines · On Sun, 15 Sep 2019 07:24:20 PDT (-0700), [email protected] wrote:
Quoted 86 lines
On Thu, 12 Sep 2019 22:40:34 +0100,
Darius Rad <[email protected]> wrote:Hi Darius,
Quoted 17 lines
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +0
-0drivers/irqchip/irq-sifive-plic.c static void plic_irq_disable(struct irq_data *d) · line 118
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +5
-0@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d)plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); } +/* +* There is no need to mask/unmask PLIC interrupts. They are "masked" +* by reading claim and "unmasked" when writing it back. +*/ +static void plic_irq_mask(struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { }This outlines a bigger issue. If your irqchip doesn't require mask/unmask, you're probably not using the right interrupt flow. Looking at the code, I see you're using
handle_simple_irq, which is almost universally wrong.As per the description above, these interrupts should be using the fasteoi flow, which is designed for this exact behaviour (the interrupt controller knows which interrupt is in flight and doesn't require SW to do anything bar signalling the EOI).
Another thing is that mask/unmask tends to be a requirement, while enable/disable tends to be optional. There is no hard line here, but the expectations are that:
(a) A disabled line can drop interrupts
(b) A masked line cannot drop interruptsDepending what the PLIC architecture mandates, you'll need to implement one and/or the other. Having just (a) is indicative of a HW bug, and I'm not assuming that this is the case. (b) only is pretty common, and (a)+(b) has a few adepts. My bet is that it requires (b) only.
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-1+#ifdef CONFIG_SMP static int plic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force)@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d,static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 153
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask,#ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity,#endif Can you give the following patch a go? It brings the irq flow in line with what the HW can do. It is of course fully untested (not even compile tested...).
Thanks,
M.From
c0ce33a992ec18f5d3bac7f70de62b1ba2b42090Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Sun, 15 Sep 2019 15:17:45 +0100
Subject: [PATCH] irqchip/sifive-plic: Switch to fasteoi flow
Quoted 6 lines
Quoted 3 lines
The SiFive PLIC interrupt controller seems to have all the HW features to support the fasteoi flow, but the driver seems to be stuck in a distant past. Bring it into the 21st century.
Thanks. We'd gotten these comments during the review process but nobody had gotten the time to actually fix the issues.
No worries. The IRQ subsystem is an acquired taste... ;-)
Quoted 6 lines
Quoted 6 lines
Signed-off-by Marc Zyngier <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c static inline void plic_irq_toggle(const struct cpumask *mask, · line 100
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +1
-0@@ -97,7 +97,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, } } -static void plic_irq_enable(struct irq_data *d) +static void plic_irq_mask(struct irq_data *d)
Of course, this is wrong. The perks of trying to do something at the last minute while boarding an airplane. Don't do that.
This should of course read "plic_irq_unmask"...
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c static void plic_irq_enable(struct irq_data *d) · line 109
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-0{unsigned int cpu =cpumask_any_and (irq_data_get_affinity_mask (d), cpu_online_mask);@@ -106,7 +106,7 @@ static void plic_irq_enable(struct irq_data *d)plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 ); } -static void plic_irq_disable(struct irq_data *d) +static void plic_irq_unmask(struct irq_data *d)
... and this should be "plic_irq_mask".
[...]
Quoted 2 lines
Reviewed-by Palmer Dabbelt <[email protected]>
Huhuh... It may be that QEMU doesn't implement the full-fat PLIC, as the above bug should have kept the IRQ lines masked.
Quoted 8 lines
We should test them on the hardware, but I don't have any with me right now. David's probably in the best spot to do this, as he's got a setup that does all the weird interrupt sources (ie, PCIe).
David: do you mind testing this? I've put the patch here:
ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/palmer/linux.git -b plic-fasteoi
I've pushed out a branch with the fixed patch:
git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git irq/plic-fasteoi
Thanks,
M.
Signature · 6 lines
Jazz is not dead, it just smells funny. _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 134 lines · On Sun, 15 Sep 2019 11:20:40 PDT (-0700), [email protected] wrote:
On Sun, 15 Sep 2019 18:31:33 +0100,
Palmer Dabbelt <[email protected]> wrote:Hi Palmer,
Quoted 88 lines · On Sun, 15 Sep 2019 07:24:20 PDT (-0700), [email protected] wrote:
Quoted 86 lines
On Thu, 12 Sep 2019 22:40:34 +0100,
Darius Rad <[email protected]> wrote:Hi Darius,
Quoted 17 lines
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +0
-0drivers/irqchip/irq-sifive-plic.c static void plic_irq_disable(struct irq_data *d) · line 118
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +5
-0@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d)plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); } +/* +* There is no need to mask/unmask PLIC interrupts. They are "masked" +* by reading claim and "unmasked" when writing it back. +*/ +static void plic_irq_mask(struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { }This outlines a bigger issue. If your irqchip doesn't require mask/unmask, you're probably not using the right interrupt flow. Looking at the code, I see you're using
handle_simple_irq, which is almost universally wrong.As per the description above, these interrupts should be using the fasteoi flow, which is designed for this exact behaviour (the interrupt controller knows which interrupt is in flight and doesn't require SW to do anything bar signalling the EOI).
Another thing is that mask/unmask tends to be a requirement, while enable/disable tends to be optional. There is no hard line here, but the expectations are that:
(a) A disabled line can drop interrupts
(b) A masked line cannot drop interruptsDepending what the PLIC architecture mandates, you'll need to implement one and/or the other. Having just (a) is indicative of a HW bug, and I'm not assuming that this is the case. (b) only is pretty common, and (a)+(b) has a few adepts. My bet is that it requires (b) only.
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-1+#ifdef CONFIG_SMP static int plic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force)@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d,static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 153
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask,#ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity,#endif Can you give the following patch a go? It brings the irq flow in line with what the HW can do. It is of course fully untested (not even compile tested...).
Thanks,
M.From
c0ce33a992ec18f5d3bac7f70de62b1ba2b42090Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Sun, 15 Sep 2019 15:17:45 +0100
Subject: [PATCH] irqchip/sifive-plic: Switch to fasteoi flowQuoted 6 lines
Quoted 3 lines
The SiFive PLIC interrupt controller seems to have all the HW features to support the fasteoi flow, but the driver seems to be stuck in a distant past. Bring it into the 21st century.
Thanks. We'd gotten these comments during the review process but nobody had gotten the time to actually fix the issues.
No worries. The IRQ subsystem is an acquired taste... ;-)
Quoted 6 lines
Quoted 6 lines
Signed-off-by Marc Zyngier <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c static inline void plic_irq_toggle(const struct cpumask *mask, · line 100
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +1
-0@@ -97,7 +97,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, } } -static void plic_irq_enable(struct irq_data *d) +static void plic_irq_mask(struct irq_data *d)Of course, this is wrong. The perks of trying to do something at the last minute while boarding an airplane. Don't do that.
This should of course read "
plic_irq_unmask"...Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c static void plic_irq_enable(struct irq_data *d) · line 109
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-0{unsigned int cpu =cpumask_any_and (irq_data_get_affinity_mask (d), cpu_online_mask);@@ -106,7 +106,7 @@ static void plic_irq_enable(struct irq_data *d)plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 ); } -static void plic_irq_disable(struct irq_data *d) +static void plic_irq_unmask(struct irq_data *d)... and this should be "
plic_irq_mask".
Quoted 7 lines
[...]
Quoted 2 lines
Reviewed-by Palmer Dabbelt <[email protected]>Huhuh... It may be that QEMU doesn't implement the full-fat PLIC, as the above bug should have kept the IRQ lines masked.
Yep, looks like the PLIC implementation in QEMU is nonsense. That needs to be rewritten, and this needs to be tested on hardware.
Quoted 16 lines
Quoted 8 lines
We should test them on the hardware, but I don't have any with me right now. David's probably in the best spot to do this, as he's got a setup that does all the weird interrupt sources (ie, PCIe).
David: do you mind testing this? I've put the patch here:
ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/palmer/linux.git -b plic-fasteoi
I've pushed out a branch with the fixed patch:
git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.gitirq/plic-fasteoiThanks,
M.
Darius Rad
Tested-byQuoted 146 lines · Marc Zyngier
On Sun, 15 Sep 2019 18:31:33 +0100,
Palmer Dabbelt <[email protected]> wrote:Hi Palmer,
Quoted 88 lines · On Sun, 15 Sep 2019 07:24:20 PDT (-0700), [email protected] wrote:
Quoted 86 lines
On Thu, 12 Sep 2019 22:40:34 +0100,
Darius Rad <[email protected]> wrote:Hi Darius,
Quoted 17 lines
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +0
-0drivers/irqchip/irq-sifive-plic.c static void plic_irq_disable(struct irq_data *d) · line 118
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +5
-0@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d)plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); } +/* +* There is no need to mask/unmask PLIC interrupts. They are "masked" +* by reading claim and "unmasked" when writing it back. +*/ +static void plic_irq_mask(struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { }This outlines a bigger issue. If your irqchip doesn't require mask/unmask, you're probably not using the right interrupt flow. Looking at the code, I see you're using
handle_simple_irq, which is almost universally wrong.As per the description above, these interrupts should be using the fasteoi flow, which is designed for this exact behaviour (the interrupt controller knows which interrupt is in flight and doesn't require SW to do anything bar signalling the EOI).
Another thing is that mask/unmask tends to be a requirement, while enable/disable tends to be optional. There is no hard line here, but the expectations are that:
(a) A disabled line can drop interrupts
(b) A masked line cannot drop interruptsDepending what the PLIC architecture mandates, you'll need to implement one and/or the other. Having just (a) is indicative of a HW bug, and I'm not assuming that this is the case. (b) only is pretty common, and (a)+(b) has a few adepts. My bet is that it requires (b) only.
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-1+#ifdef CONFIG_SMP static int plic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force)@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d,static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 153
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask,#ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity,#endif Can you give the following patch a go? It brings the irq flow in line with what the HW can do. It is of course fully untested (not even compile tested...).
Thanks,
M.From
c0ce33a992ec18f5d3bac7f70de62b1ba2b42090Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Sun, 15 Sep 2019 15:17:45 +0100
Subject: [PATCH] irqchip/sifive-plic: Switch to fasteoi flowQuoted 6 lines
Quoted 3 lines
The SiFive PLIC interrupt controller seems to have all the HW features to support the fasteoi flow, but the driver seems to be stuck in a distant past. Bring it into the 21st century.
Thanks. We'd gotten these comments during the review process but nobody had gotten the time to actually fix the issues.
No worries. The IRQ subsystem is an acquired taste... ;-)
Quoted 6 lines
Quoted 6 lines
Signed-off-by Marc Zyngier <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c static inline void plic_irq_toggle(const struct cpumask *mask, · line 100
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +1
-0@@ -97,7 +97,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, } } -static void plic_irq_enable(struct irq_data *d) +static void plic_irq_mask(struct irq_data *d)Of course, this is wrong. The perks of trying to do something at the last minute while boarding an airplane. Don't do that.
This should of course read "
plic_irq_unmask"...Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c static void plic_irq_enable(struct irq_data *d) · line 109
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-0{unsigned int cpu =cpumask_any_and (irq_data_get_affinity_mask (d), cpu_online_mask);@@ -106,7 +106,7 @@ static void plic_irq_enable(struct irq_data *d)plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 ); } -static void plic_irq_disable(struct irq_data *d) +static void plic_irq_unmask(struct irq_data *d)... and this should be "
plic_irq_mask".[...]
Quoted 2 lines
Reviewed-by Palmer Dabbelt <[email protected]>Huhuh... It may be that QEMU doesn't implement the full-fat PLIC, as the above bug should have kept the IRQ lines masked.
Quoted 4 lines
We should test them on the hardware, but I don't have any with me right now. David's probably in the best spot to do this, as he's got a setup that does all the weird interrupt sources (ie, PCIe).
Quoted 9 lines
Quoted 4 lines
David: do you mind testing this? I've put the patch here:
ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/palmer/linux.git -b plic-fasteoi
I've pushed out a branch with the fixed patch:
git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.gitirq/plic-fasteoi
That patch works for me on real-ish hardware. I tried on two FPGA systems that have different PLIC implementations. Both include a PCIe root port (and associated interrupt source). So for whatever it's worth:
Quoted 4 lines
Thanks,
M.
Quoted 157 lines · Darius Rad
Quoted 146 lines · Marc Zyngier
On Sun, 15 Sep 2019 18:31:33 +0100,
Palmer Dabbelt <[email protected]> wrote:Hi Palmer,
Quoted 88 lines · On Sun, 15 Sep 2019 07:24:20 PDT (-0700), [email protected] wrote:
Quoted 86 lines
On Thu, 12 Sep 2019 22:40:34 +0100,
Darius Rad <[email protected]> wrote:Hi Darius,
Quoted 17 lines
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +0
-0drivers/irqchip/irq-sifive-plic.c static void plic_irq_disable(struct irq_data *d) · line 118
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +5
-0@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d)plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); } +/* +* There is no need to mask/unmask PLIC interrupts. They are "masked" +* by reading claim and "unmasked" when writing it back. +*/ +static void plic_irq_mask(struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { }This outlines a bigger issue. If your irqchip doesn't require mask/unmask, you're probably not using the right interrupt flow. Looking at the code, I see you're using
handle_simple_irq, which is almost universally wrong.As per the description above, these interrupts should be using the fasteoi flow, which is designed for this exact behaviour (the interrupt controller knows which interrupt is in flight and doesn't require SW to do anything bar signalling the EOI).
Another thing is that mask/unmask tends to be a requirement, while enable/disable tends to be optional. There is no hard line here, but the expectations are that:
(a) A disabled line can drop interrupts
(b) A masked line cannot drop interruptsDepending what the PLIC architecture mandates, you'll need to implement one and/or the other. Having just (a) is indicative of a HW bug, and I'm not assuming that this is the case. (b) only is pretty common, and (a)+(b) has a few adepts. My bet is that it requires (b) only.
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-1+#ifdef CONFIG_SMP static int plic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force)@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d,static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 153
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask,#ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity,#endif Can you give the following patch a go? It brings the irq flow in line with what the HW can do. It is of course fully untested (not even compile tested...).
Thanks,
M.From
c0ce33a992ec18f5d3bac7f70de62b1ba2b42090Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Sun, 15 Sep 2019 15:17:45 +0100
Subject: [PATCH] irqchip/sifive-plic: Switch to fasteoi flowQuoted 6 lines
Quoted 3 lines
The SiFive PLIC interrupt controller seems to have all the HW features to support the fasteoi flow, but the driver seems to be stuck in a distant past. Bring it into the 21st century.
Thanks. We'd gotten these comments during the review process but nobody had gotten the time to actually fix the issues.
No worries. The IRQ subsystem is an acquired taste... ;-)
Quoted 6 lines
Quoted 6 lines
Signed-off-by Marc Zyngier <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c static inline void plic_irq_toggle(const struct cpumask *mask, · line 100
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +1
-0@@ -97,7 +97,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, } } -static void plic_irq_enable(struct irq_data *d) +static void plic_irq_mask(struct irq_data *d)Of course, this is wrong. The perks of trying to do something at the last minute while boarding an airplane. Don't do that.
This should of course read "
plic_irq_unmask"...Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c static void plic_irq_enable(struct irq_data *d) · line 109
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-0{unsigned int cpu =cpumask_any_and (irq_data_get_affinity_mask (d), cpu_online_mask);@@ -106,7 +106,7 @@ static void plic_irq_enable(struct irq_data *d)plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 ); } -static void plic_irq_disable(struct irq_data *d) +static void plic_irq_unmask(struct irq_data *d)... and this should be "
plic_irq_mask".[...]
Quoted 2 lines
Reviewed-by Palmer Dabbelt <[email protected]>Huhuh... It may be that QEMU doesn't implement the full-fat PLIC, as the above bug should have kept the IRQ lines masked.
Quoted 4 lines
We should test them on the hardware, but I don't have any with me right now. David's probably in the best spot to do this, as he's got a setup that does all the weird interrupt sources (ie, PCIe).
Quoted 9 lines
Quoted 4 lines
David: do you mind testing this? I've put the patch here:
ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/palmer/linux.git -b plic-fasteoi
I've pushed out a branch with the fixed patch:
git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.gitirq/plic-fasteoi
Quoted 6 lines
That patch works for me on real-ish hardware. I tried on two FPGA systems that have different PLIC implementations. Both include a PCIe root port (and associated interrupt source). So for whatever it's worth:
Tested-by Darius Rad <[email protected]>
Awesome, thanks. Would it be OK to put a "(on two hardware PLIC implementations)" after that, just so we're clear as to who tested what?
Assuming one of yours wasn't a SiFive PLIC then it'd be great if David could still give this a whack, but I don't think it strictly needs to block merging the patch. I've included the right David this time, with any luck that will be more fruitful :)
Quoted 5 lines
Quoted 5 lines
Thanks,
M.
Quoted 163 lines · On Mon, 16 Sep 2019 13:51:58 -0700 (PDT) Palmer Dabbelt <[email protected]>…
Quoted 162 lines · Darius Rad
Quoted 146 lines · Marc Zyngier
On Sun, 15 Sep 2019 18:31:33 +0100,
Palmer Dabbelt <[email protected]> wrote:Hi Palmer,
Quoted 88 lines · On Sun, 15 Sep 2019 07:24:20 PDT (-0700), [email protected] wrote:
Quoted 86 lines
On Thu, 12 Sep 2019 22:40:34 +0100,
Darius Rad <[email protected]> wrote:Hi Darius,
Quoted 17 lines
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +0
-0drivers/irqchip/irq-sifive-plic.c static void plic_irq_disable(struct irq_data *d) · line 118
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +5
-0@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d)plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); } +/* +* There is no need to mask/unmask PLIC interrupts. They are "masked" +* by reading claim and "unmasked" when writing it back. +*/ +static void plic_irq_mask(struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { }This outlines a bigger issue. If your irqchip doesn't require mask/unmask, you're probably not using the right interrupt flow. Looking at the code, I see you're using
handle_simple_irq, which is almost universally wrong.As per the description above, these interrupts should be using the fasteoi flow, which is designed for this exact behaviour (the interrupt controller knows which interrupt is in flight and doesn't require SW to do anything bar signalling the EOI).
Another thing is that mask/unmask tends to be a requirement, while enable/disable tends to be optional. There is no hard line here, but the expectations are that:
(a) A disabled line can drop interrupts
(b) A masked line cannot drop interruptsDepending what the PLIC architecture mandates, you'll need to implement one and/or the other. Having just (a) is indicative of a HW bug, and I'm not assuming that this is the case. (b) only is pretty common, and (a)+(b) has a few adepts. My bet is that it requires (b) only.
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-1+#ifdef CONFIG_SMP static int plic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force)@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d,static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 153
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask,#ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity,#endif Can you give the following patch a go? It brings the irq flow in line with what the HW can do. It is of course fully untested (not even compile tested...).
Thanks,
M.From
c0ce33a992ec18f5d3bac7f70de62b1ba2b42090Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Sun, 15 Sep 2019 15:17:45 +0100
Subject: [PATCH] irqchip/sifive-plic: Switch to fasteoi flowQuoted 6 lines
Quoted 3 lines
The SiFive PLIC interrupt controller seems to have all the HW features to support the fasteoi flow, but the driver seems to be stuck in a distant past. Bring it into the 21st century.
Thanks. We'd gotten these comments during the review process but nobody had gotten the time to actually fix the issues.
No worries. The IRQ subsystem is an acquired taste... ;-)
Quoted 6 lines
Quoted 6 lines
Signed-off-by Marc Zyngier <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c static inline void plic_irq_toggle(const struct cpumask *mask, · line 100
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +1
-0@@ -97,7 +97,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, } } -static void plic_irq_enable(struct irq_data *d) +static void plic_irq_mask(struct irq_data *d)Of course, this is wrong. The perks of trying to do something at the last minute while boarding an airplane. Don't do that.
This should of course read "
plic_irq_unmask"...Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c static void plic_irq_enable(struct irq_data *d) · line 109
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-0{unsigned int cpu =cpumask_any_and (irq_data_get_affinity_mask (d), cpu_online_mask);@@ -106,7 +106,7 @@ static void plic_irq_enable(struct irq_data *d)plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 ); } -static void plic_irq_disable(struct irq_data *d) +static void plic_irq_unmask(struct irq_data *d)... and this should be "
plic_irq_mask".[...]
Quoted 2 lines
Reviewed-by Palmer Dabbelt <[email protected]>Huhuh... It may be that QEMU doesn't implement the full-fat PLIC, as the above bug should have kept the IRQ lines masked.
Quoted 4 lines
We should test them on the hardware, but I don't have any with me right now. David's probably in the best spot to do this, as he's got a setup that does all the weird interrupt sources (ie, PCIe).
Quoted 9 lines
Quoted 4 lines
David: do you mind testing this? I've put the patch here:
ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/palmer/linux.git -b plic-fasteoi
I've pushed out a branch with the fixed patch:
git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.gitirq/plic-fasteoiThat patch works for me on real-ish hardware. I tried on two FPGA systems that have different PLIC implementations. Both include a PCIe root port (and associated interrupt source). So for whatever it's worth:
Quoted 5 lines
Quoted 1 line
Tested-by Darius Rad <[email protected]>Awesome, thanks. Would it be OK to put a "(on two hardware PLIC implementations)" after that, just so we're clear as to who tested what?
Sure, no problem.
Quoted 4 lines
Assuming one of yours wasn't a SiFive PLIC then it'd be great if David could still give this a whack, but I don't think it strictly needs to block merging the patch. I've included the right David this time, with any luck that will be more fruitful :)
Well, we still have time before -rc1. Once David gets a chance to test it, I'll apply it. Additional question: do you want this backported to -stable? If so, how far?
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 174 lines · On Mon, 16 Sep 2019 14:33:23 PDT (-0700), [email protected] wrote:
Quoted 163 lines · On Mon, 16 Sep 2019 13:51:58 -0700 (PDT) Palmer Dabbelt <[email protected]>…
Quoted 162 lines · Darius Rad
Quoted 146 lines · Marc Zyngier
On Sun, 15 Sep 2019 18:31:33 +0100,
Palmer Dabbelt <[email protected]> wrote:Hi Palmer,
Quoted 88 lines · On Sun, 15 Sep 2019 07:24:20 PDT (-0700), [email protected] wrote:
Quoted 86 lines
On Thu, 12 Sep 2019 22:40:34 +0100,
Darius Rad <[email protected]> wrote:Hi Darius,
Quoted 17 lines
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +0
-0drivers/irqchip/irq-sifive-plic.c static void plic_irq_disable(struct irq_data *d) · line 118
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +5
-0@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d)plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); } +/* +* There is no need to mask/unmask PLIC interrupts. They are "masked" +* by reading claim and "unmasked" when writing it back. +*/ +static void plic_irq_mask(struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { }This outlines a bigger issue. If your irqchip doesn't require mask/unmask, you're probably not using the right interrupt flow. Looking at the code, I see you're using
handle_simple_irq, which is almost universally wrong.As per the description above, these interrupts should be using the fasteoi flow, which is designed for this exact behaviour (the interrupt controller knows which interrupt is in flight and doesn't require SW to do anything bar signalling the EOI).
Another thing is that mask/unmask tends to be a requirement, while enable/disable tends to be optional. There is no hard line here, but the expectations are that:
(a) A disabled line can drop interrupts
(b) A masked line cannot drop interruptsDepending what the PLIC architecture mandates, you'll need to implement one and/or the other. Having just (a) is indicative of a HW bug, and I'm not assuming that this is the case. (b) only is pretty common, and (a)+(b) has a few adepts. My bet is that it requires (b) only.
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-1+#ifdef CONFIG_SMP static int plic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force)@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d,static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 153
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask,#ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity,#endif Can you give the following patch a go? It brings the irq flow in line with what the HW can do. It is of course fully untested (not even compile tested...).
Thanks,
M.From
c0ce33a992ec18f5d3bac7f70de62b1ba2b42090Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Sun, 15 Sep 2019 15:17:45 +0100
Subject: [PATCH] irqchip/sifive-plic: Switch to fasteoi flowQuoted 6 lines
Quoted 3 lines
The SiFive PLIC interrupt controller seems to have all the HW features to support the fasteoi flow, but the driver seems to be stuck in a distant past. Bring it into the 21st century.
Thanks. We'd gotten these comments during the review process but nobody had gotten the time to actually fix the issues.
No worries. The IRQ subsystem is an acquired taste... ;-)
Quoted 6 lines
Quoted 6 lines
Signed-off-by Marc Zyngier <[email protected]>--- drivers/irqchip/irq-sifive-plic.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c static inline void plic_irq_toggle(const struct cpumask *mask, · line 100
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +1
-0@@ -97,7 +97,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, } } -static void plic_irq_enable(struct irq_data *d) +static void plic_irq_mask(struct irq_data *d)Of course, this is wrong. The perks of trying to do something at the last minute while boarding an airplane. Don't do that.
This should of course read "
plic_irq_unmask"...Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c static void plic_irq_enable(struct irq_data *d) · line 109
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-0{unsigned int cpu =cpumask_any_and (irq_data_get_affinity_mask (d), cpu_online_mask);@@ -106,7 +106,7 @@ static void plic_irq_enable(struct irq_data *d)plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 ); } -static void plic_irq_disable(struct irq_data *d) +static void plic_irq_unmask(struct irq_data *d)... and this should be "
plic_irq_mask".[...]
Quoted 2 lines
Reviewed-by Palmer Dabbelt <[email protected]>Huhuh... It may be that QEMU doesn't implement the full-fat PLIC, as the above bug should have kept the IRQ lines masked.
Quoted 4 lines
We should test them on the hardware, but I don't have any with me right now. David's probably in the best spot to do this, as he's got a setup that does all the weird interrupt sources (ie, PCIe).
Quoted 9 lines
Quoted 4 lines
David: do you mind testing this? I've put the patch here:
ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/palmer/linux.git -b plic-fasteoi
I've pushed out a branch with the fixed patch:
git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.gitirq/plic-fasteoiThat patch works for me on real-ish hardware. I tried on two FPGA systems that have different PLIC implementations. Both include a PCIe root port (and associated interrupt source). So for whatever it's worth:
Quoted 5 lines
Quoted 1 line
Tested-by Darius Rad <[email protected]>Awesome, thanks. Would it be OK to put a "(on two hardware PLIC implementations)" after that, just so we're clear as to who tested what?
Sure, no problem.
Quoted 8 lines
Quoted 4 lines
Assuming one of yours wasn't a SiFive PLIC then it'd be great if David could still give this a whack, but I don't think it strictly needs to block merging the patch. I've included the right David this time, with any luck that will be more fruitful :)
Well, we still have time before -rc1. Once David gets a chance to test it, I'll apply it. Additional question: do you want this backported to -stable? If so, how far?
Generally I've just been CCing stable on bug fixes and letting the automation handle it. 4.19 was the first version with a PLIC driver, and that was pretty broken so this should be deep down in the noise for anyone who's trying to use that -- and I doubt anyone is trying to do so.
Quoted 4 lines
Thanks,
M.
Paul Walmsley
Tested-byJust tested this on the SiFive HiFive Unleashed. Seems to work OK; however I did not stress-test it.
- Paul
# !cat
cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3
1: 0 0 0 0 SiFive PLIC 5 10011000.serial 3: 0 0 0 0 SiFive PLIC 51 10040000.spi 4: 6266 0 0 0 SiFive PLIC 4 10010000.serial 5: 102 0 0 0 SiFive PLIC 6 10050000.spi 6: 37 0 0 0 SiFive PLIC 53 eth0 IPI0: 1134 21128 9024 220261 Rescheduling interrupts IPI1: 10 143 18 7 Function call interrupts IPI2: 0 0 0 0 CPU stop interrupts
#
Quoted 22 lines · Paul Walmsley
Just tested this on the SiFive HiFive Unleashed. Seems to work OK; however I did not stress-test it.
- Paul
# !cat
cat/proc/interrupts
CPU0 CPU1 CPU2 CPU31: 0 0 0 0 SiFive PLIC 5 10011000.serial 3: 0 0 0 0 SiFive PLIC 51 10040000.spi 4: 6266 0 0 0 SiFive PLIC 4 10010000.serial 5: 102 0 0 0 SiFive PLIC 6 10050000.spi 6: 37 0 0 0 SiFive PLIC 53 eth0 IPI0: 1134 21128 9024 220261 Rescheduling interrupts IPI1: 10 143 18 7 Function call interrupts IPI2: 0 0 0 0 CPU stop interrupts
Quoted 1 line
#
I have applied the patch on top of 5.2.9 kernel and tried to stress it with stress-ng interrupt stressors for 2:30+ hours.
# cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3
1: 0 0 0 0 SiFive PLIC 5
10011000.serial
3: 0 0 0 0 SiFive PLIC 51 10040000.spi
4: 34240 0 0 0 SiFive PLIC 4
10010000.serial
5: 102 0 0 0 SiFive PLIC 6 10050000.spi
6: 0 0 0 0 SiFive PLIC 53 eth0
7: 0 0 0 0 SiFive PLIC 32
microsemi-pcie
IPI0: 32013933 28068736 29345256 23346339 Rescheduling interrupts
IPI1: 78514 78586 63144 100317 Function call interrupts
IPI2: 0 0 0 0 CPU stop interruptsQuoted 158 lines · Palmer Dabbelt
Quoted 157 lines · Darius Rad
Quoted 155 lines · Marc Zyngier
On Sun, 15 Sep 2019 18:31:33 +0100,
Palmer Dabbelt <[email protected]> wrote:Hi Palmer,
Quoted 88 lines · On Sun, 15 Sep 2019 07:24:20 PDT (-0700), [email protected] wrote:
Quoted 86 lines
On Thu, 12 Sep 2019 22:40:34 +0100,
Darius Rad <[email protected]> wrote:Hi Darius,
Quoted 23 lines
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>---
drivers/irqchip/irq-sifive-plic.c | 13 +++++++++----1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +0
-0@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d) plic_irq_toggle(cpu_possible_mask, d->hwirq, 0); }+/*
+ * There is no need to mask/unmask PLIC interrupts. They are "masked"
+ * by reading claim and "unmasked" when writing it back.
+ */drivers/irqchip/irq-sifive-plic.c
Quoted 2 lines
drivers/irqchip/irq-sifive-plic.c +2
-0+static void plic_irq_mask (struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { }This outlines a bigger issue. If your irqchip doesn't require mask/unmask, you're probably not using the right interrupt flow. Looking at the code, I see you're using
handle_simple_irq, which is almost universally wrong.As per the description above, these interrupts should be using the fasteoi flow, which is designed for this exact behaviour (the interrupt controller knows which interrupt is in flight and doesn't require SW to do anything bar signalling the EOI).
Another thing is that mask/unmask tends to be a requirement, while enable/disable tends to be optional. There is no hard line here, but the expectations are that:
(a) A disabled line can drop interrupts
(b) A masked line cannot drop interruptsDepending what the PLIC architecture mandates, you'll need to implement one and/or the other. Having just (a) is indicative of a HW bug, and I'm not assuming that this is the case. (b) only is pretty common, and (a)+(b) has a few adepts. My bet is that it requires (b) only.
Quoted 8 lines
+
#ifdefCONFIG_SMP
static intplic_set_affinity(struct irq_data *d, const struct cpumask *mask_val, bool force)drivers/irqchip/irq-sifive-plic.c +0
-1@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d, static struct irq_chip plic_chip = { .name = "SiFive PLIC", - /*drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 153
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask, #ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity, #endifCan you give the following patch a go? It brings the irq flow in line with what the HW can do. It is of course fully untested (not even compile tested...).
Thanks,
M.
From
c0ce33a992ec18f5d3bac7f70de62b1ba2b42090Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Sun, 15 Sep 2019 15:17:45 +0100
Subject: [PATCH] irqchip/sifive-plic: Switch to fasteoi flowQuoted 6 lines
Quoted 3 lines
The SiFive PLIC interrupt controller seems to have all the HW features to support the fasteoi flow, but the driver seems to be stuck in a distant past. Bring it into the 21st century.
Thanks. We'd gotten these comments during the review process but nobody had gotten the time to actually fix the issues.
No worries. The IRQ subsystem is an acquired taste... ;-)
Quoted 6 lines
Quoted 6 lines
Signed-off-by Marc Zyngier <[email protected]>---
drivers/irqchip/irq-sifive-plic.c | 29 +++++++++++++++--------------1 file changed, 15 insertions(+), 14 deletions(-)Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c static inline void plic_irq_toggle(const struct cpumask *mask, · line 100
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +1
-0@@ -97,7 +97,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, } } -static void plic_irq_enable(struct irq_data *d) +static void plic_irq_mask(struct irq_data *d)Of course, this is wrong. The perks of trying to do something at the last minute while boarding an airplane. Don't do that.
This should of course read "
plic_irq_unmask"...Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c static void plic_irq_enable(struct irq_data *d) · line 109
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-0{ unsigned int cpu = cpumask_any_and(irq_data_get_affinity_mask(d), cpu_online_mask);@@ -106,7 +106,7 @@ static void plic_irq_enable(struct irq_data *d) plic_irq_toggle(cpumask_of(cpu), d->hwirq, 1); } -static void plic_irq_disable(struct irq_data *d) +static void plic_irq_unmask(struct irq_data *d)... and this should be "
plic_irq_mask".[...]
Quoted 2 lines
Reviewed-by Palmer Dabbelt <[email protected]>Huhuh... It may be that QEMU doesn't implement the full-fat PLIC, as the above bug should have kept the IRQ lines masked.
Quoted 8 lines
We should test them on the hardware, but I don't have any with me right now. David's probably in the best spot to do this, as he's got a setup that does all the weird interrupt sources (ie, PCIe).
David: do you mind testing this? I've put the patch here:
ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/palmer/linux.git -b plic-fasteoi
I've pushed out a branch with the fixed patch:
git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.gitirq/plic-fasteoi
Quoted 8 lines
Quoted 6 lines
That patch works for me on real-ish hardware. I tried on two FPGA systems that have different PLIC implementations. Both include a PCIe root port (and associated interrupt source). So for whatever it's worth:
Tested-by Darius Rad <[email protected]>Awesome, thanks. Would it be OK to put a "(on two hardware PLIC implementations)" after that, just so we're clear as to who tested what?
Fine by me.
Quoted 2 lines
Assuming one of yours wasn't a SiFive PLIC then it'd be great if David could still give this a whack, but I don't think it strictly needs to block merging the patch. I've included the right David this time, with any luck that will be more fruitful :)
One of the systems I tested was based on rocket-chip, and the associated PLIC, which I guess is the SiFive PLIC, right? Can't hurt to have more testing, though.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Thanks,
M.
Quoted 168 lines · Darius Rad
Quoted 158 lines · Palmer Dabbelt
Quoted 157 lines · Darius Rad
Quoted 155 lines · Marc Zyngier
On Sun, 15 Sep 2019 18:31:33 +0100,
Palmer Dabbelt <[email protected]> wrote:Hi Palmer,
Quoted 88 lines · On Sun, 15 Sep 2019 07:24:20 PDT (-0700), [email protected] wrote:
Quoted 86 lines
On Thu, 12 Sep 2019 22:40:34 +0100,
Darius Rad <[email protected]> wrote:Hi Darius,
Quoted 23 lines
As per the existing comment,
irq_maskandirq_unmaskdo not need to do anything for the PLIC. However, the functions must exist (the pointers cannot be NULL) as they are not optional, based on the documentation (Documentation/core-api/genericirq.rst) as well as existing usage (e.g.,include/linux/irqchip/chained_irq.h).Signed-off-by Darius Rad <[email protected]>---
drivers/irqchip/irq-sifive-plic.c | 13 +++++++++----1 file changed, 9 insertions(+), 4 deletions(-)drivers/irqchip/irq-sifive-plic.c +0
-0@@ -111,6 +111,13 @@ static void plic_irq_disable(struct irq_data *d) plic_irq_toggle(cpu_possible_mask, d->hwirq, 0); }+/*
+ * There is no need to mask/unmask PLIC interrupts. They are "masked"
+ * by reading claim and "unmasked" when writing it back.
+ */drivers/irqchip/irq-sifive-plic.c
Quoted 2 lines
drivers/irqchip/irq-sifive-plic.c +2
-0+static void plic_irq_mask (struct irq_data *d) { } +static void plic_irq_unmask (struct irq_data *d) { }This outlines a bigger issue. If your irqchip doesn't require mask/unmask, you're probably not using the right interrupt flow. Looking at the code, I see you're using
handle_simple_irq, which is almost universally wrong.As per the description above, these interrupts should be using the fasteoi flow, which is designed for this exact behaviour (the interrupt controller knows which interrupt is in flight and doesn't require SW to do anything bar signalling the EOI).
Another thing is that mask/unmask tends to be a requirement, while enable/disable tends to be optional. There is no hard line here, but the expectations are that:
(a) A disabled line can drop interrupts
(b) A masked line cannot drop interruptsDepending what the PLIC architecture mandates, you'll need to implement one and/or the other. Having just (a) is indicative of a HW bug, and I'm not assuming that this is the case. (b) only is pretty common, and (a)+(b) has a few adepts. My bet is that it requires (b) only.
Quoted 8 lines
+
#ifdefCONFIG_SMP
static intplic_set_affinity(struct irq_data *d, const struct cpumask *mask_val, bool force)drivers/irqchip/irq-sifive-plic.c +0
-1@@ -138,12 +145,10 @@ static int plic_set_affinity(struct irq_data *d, static struct irq_chip plic_chip = { .name = "SiFive PLIC", - /*drivers/irqchip/irq-sifive-plic.c static int plic_set_affinity(struct irq_data *d, · line 153
Quoted 10 lines
drivers/irqchip/irq-sifive-plic.c +2
-3-* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ .irq_enable = plic_irq_enable, .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask, #ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity, #endifCan you give the following patch a go? It brings the irq flow in line with what the HW can do. It is of course fully untested (not even compile tested...).
Thanks,
M.
From
c0ce33a992ec18f5d3bac7f70de62b1ba2b42090Mon Sep 17 00:00:00 2001
From: Marc Zyngier <[email protected]>
Date: Sun, 15 Sep 2019 15:17:45 +0100
Subject: [PATCH] irqchip/sifive-plic: Switch to fasteoi flowQuoted 6 lines
Quoted 3 lines
The SiFive PLIC interrupt controller seems to have all the HW features to support the fasteoi flow, but the driver seems to be stuck in a distant past. Bring it into the 21st century.
Thanks. We'd gotten these comments during the review process but nobody had gotten the time to actually fix the issues.
No worries. The IRQ subsystem is an acquired taste... ;-)
Quoted 6 lines
Quoted 6 lines
Signed-off-by Marc Zyngier <[email protected]>---
drivers/irqchip/irq-sifive-plic.c | 29 +++++++++++++++--------------1 file changed, 15 insertions(+), 14 deletions(-)Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c static inline void plic_irq_toggle(const struct cpumask *mask, · line 100
Quoted 9 lines
drivers/irqchip/irq-sifive-plic.c +1
-0@@ -97,7 +97,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, } } -static void plic_irq_enable(struct irq_data *d) +static void plic_irq_mask(struct irq_data *d)Of course, this is wrong. The perks of trying to do something at the last minute while boarding an airplane. Don't do that.
This should of course read "
plic_irq_unmask"...Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c static void plic_irq_enable(struct irq_data *d) · line 109
Quoted 8 lines
drivers/irqchip/irq-sifive-plic.c +1
-0{ unsigned int cpu = cpumask_any_and(irq_data_get_affinity_mask(d), cpu_online_mask);@@ -106,7 +106,7 @@ static void plic_irq_enable(struct irq_data *d) plic_irq_toggle(cpumask_of(cpu), d->hwirq, 1); } -static void plic_irq_disable(struct irq_data *d) +static void plic_irq_unmask(struct irq_data *d)... and this should be "
plic_irq_mask".[...]
Quoted 2 lines
Reviewed-by Palmer Dabbelt <[email protected]>Huhuh... It may be that QEMU doesn't implement the full-fat PLIC, as the above bug should have kept the IRQ lines masked.
Quoted 8 lines
We should test them on the hardware, but I don't have any with me right now. David's probably in the best spot to do this, as he's got a setup that does all the weird interrupt sources (ie, PCIe).
David: do you mind testing this? I've put the patch here:
ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/palmer/linux.git -b plic-fasteoi
I've pushed out a branch with the fixed patch:
git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.gitirq/plic-fasteoiQuoted 8 lines
Quoted 6 lines
That patch works for me on real-ish hardware. I tried on two FPGA systems that have different PLIC implementations. Both include a PCIe root port (and associated interrupt source). So for whatever it's worth:
Tested-by Darius Rad <[email protected]>Awesome, thanks. Would it be OK to put a "(on two hardware PLIC implementations)" after that, just so we're clear as to who tested what?
Quoted 8 lines
Fine by me.
Quoted 2 lines
Assuming one of yours wasn't a SiFive PLIC then it'd be great if David could still give this a whack, but I don't think it strictly needs to block merging the patch. I've included the right David this time, with any luck that will be more fruitful :)
One of the systems I tested was based on rocket-chip, and the associated PLIC, which I guess is the SiFive PLIC, right? Can't hurt to have more testing, though.
Ya, that's ours.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Thanks,
M.
With the fixes it seems to still work fine on the Kendryte KD210. Although currently only the serial interrupt is tested and this might not be a very exhaustive test case..
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
[tip: irq/urgent] irqchip/sifive-plic: Switch to fasteoi flow
In reply to Marc ZyngierThe following commit has been merged into the irq/urgent branch of tip:
The following commit has been merged into the irq/urgent branch of tip:
Commit-ID: bb0fed1c60cccbe4063b455a7228818395dac86e Gitweb: https://git.kernel.org/tip/bb0fed1c60cccbe4063b455a7228818395dac86e Author: Marc Zyngier <[email protected]> AuthorDate: Sun, 15 Sep 2019 15:17:45 +01:00 Committer: Marc Zyngier <[email protected]> CommitterDate: Wed, 18 Sep 2019 12:29:52 +01:00
irqchip/sifive-plic: Switch to fasteoi flow
The SiFive PLIC interrupt controller seems to have all the HW features to support the fasteoi flow, but the driver seems to be stuck in a distant past. Bring it into the 21st century.
--- drivers/irqchip/irq-sifive-plic.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/irqchip/irq-sifive-plic.c +15 -14
@@ -97,7 +97,7 @@ static inline void plic_irq_toggle(const struct cpumask *mask, } } -static void plic_irq_enable (struct irq_data *d) +static void plic_irq_unmask (struct irq_data *d) {unsigned int cpu =cpumask_any_and (irq_data_get_affinity_mask (d), cpu_online_mask);
@@ -106,7 +106,7 @@ static void plic_irq_enable(struct irq_data *d)plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 ); } -static void plic_irq_disable (struct irq_data *d) +static void plic_irq_mask (struct irq_data *d) {plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); }
@@ -125,10 +125,8 @@ static int plic_set_affinity(struct irq_data *d,if (cpu >= nr_cpu_ids)return -EINVAL ; -if (!irqd_irq_disabled (d)) { -plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); -plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 ); - } +plic_irq_toggle (cpu_possible_mask, d->hwirq,0 ); +plic_irq_toggle (cpumask_of (cpu), d->hwirq,1 );irq_data_update_effective_affinity (d,cpumask_of (cpu));
@@ -136,14 +134,18 @@ static int plic_set_affinity(struct irq_data *d, }#endif +static void plic_irq_eoi (struct irq_data *d) +{ +struct plic_handler *handler =this_cpu_ptr (&plic_handlers); + +writel (d->hwirq, handler->hart_base +CONTEXT_CLAIM ); +} +static struct irq_chip plic_chip = { .name ="SiFive PLIC" , -/* -* There is no need to mask/unmask PLIC interrupts. They are "masked" -* by reading claim and "unmasked" when writing it back. -*/ - .irq_enable = plic_irq_enable, - .irq_disable = plic_irq_disable, + .irq_mask = plic_irq_mask, + .irq_unmask = plic_irq_unmask, + .irq_eoi = plic_irq_eoi, #ifdef CONFIG_SMP .irq_set_affinity = plic_set_affinity, #endif
@@ -152,7 +154,7 @@ static struct irq_chip plic_chip = {static int plic_irqdomain_map (struct irq_domain *d,unsigned int irq,irq_hw_number_t hwirq) { -irq_set_chip_and_handler (irq, &plic_chip, handle_simple_irq); +irq_set_chip_and_handler (irq, &plic_chip, handle_fasteoi_irq);irq_set_chip_data (irq,NULL );irq_set_noprobe (irq);return 0 ;
@@ -188,7 +190,6 @@ static void plic_handle_irq(struct pt_regs *regs) hwirq); elsegeneric_handle_irq (irq ); -writel (hwirq, claim); }csr_set (sie,SIE_SEIE ); }