Issue with linux threaded level triggered interrupts
Hi,
during our development on imx6 with kernel 5.4 and Xenomai 3.1 we discovered complete system stalls when using phylib with phy irqs level triggerd. This irq is connected on the imx-gpio.
Investigation showed that it seems to be an issue in the ipipe irq end function for level interrupts. Please review the patch proposal.
I am not sure if just calling unmask_irq() is ok here since this functin also does some locking. The other way would be to just call additionally the irq_state_clr_masked(desc) in the level end function itself.
The patch applies on ipipe/master in ipipe-arm.
It looks like this is an issue in all ipipe patches, but is triggered by the introduction of a check in unmask_irq().
Thanks in advance,
Gunter Grau
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
PATCH 1/1 ipipe: Fix ipipe level irq end
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in mask_irq():
bf22ff45bed6 ("genirq: Avoid unnecessary low level irq function calls")
This means if the flag is not serviced correctly
the real bit in the hardware interrupt controller may not be cleared or set.
The __ipipe_end_level_irq() function does not follow this rule. It unmasks the bit in the hardware without setting the cached flags accordingly. So after the first level interrupt is finished the mask cache has a wrong state. If now the next interrupt fires, the mask_irq() function will not really mask the interrupt in the hardware which causes a interrupt storm after reenabeling the hard irqs.
The fix now calls unmask_irq() which is handling the cached flags correctly.
--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/irq/chip.c +1 -1
@@ -987,7 +987,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { - desc->irq_data.chip->irq_unmask (&desc->irq_data); +unmask_irq (desc); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc)
--
2.25.1
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
Re: [PATCH] ipipe: Fix ipipe level irq end
Quoted 40 lines · Gunter Grau via Xenomai
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in
mask_irq():
bf22ff45bed6("genirq: Avoid unnecessary low level irq function calls")This means if the flag is not serviced correctly
the real bit in the hardware interrupt controller may not be cleared or set.
The__ipipe_end_level_irq()function does not follow this rule. It unmasks the bit in the hardware without setting the cached flags accordingly. So after the first level interrupt is finished the mask cache has a wrong state. If now the next interrupt fires, themask_irq()function will not really mask the interrupt in the hardware which causes a interrupt storm after reenabeling the hard irqs.
The fix now callsunmask_irq()which is handling the cached flags correctly.Signed-off-by Gunter Grau <[email protected]>--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/irq/chip.c +1
-2@@ -987,7 +987,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { - desc->irq_data.chip->irq_unmask (&desc->irq_data); +unmask_irq (desc); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc) --2.25.1
Quoted 9 lines
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
I’ll add this to the arm/arm64 ipipe kernels this weekend.
Thanks
Greg
Quoted 2 lines
Re: [PATCH] ipipe: Fix ipipe level irq end
In reply to Gunter GrauQuoted 37 lines · Gunter Grau via Xenomai
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in
mask_irq():
bf22ff45bed6("genirq: Avoid unnecessary low level irq function calls")This means if the flag is not serviced correctly
the real bit in the hardware interrupt controller may not be cleared or set.
The__ipipe_end_level_irq()function does not follow this rule. It unmasks the bit in the hardware without setting the cached flags accordingly. So after the first level interrupt is finished the mask cache has a wrong state. If now the next interrupt fires, themask_irq()function will not really mask the interrupt in the hardware which causes a interrupt storm after reenabeling the hard irqs.
The fix now callsunmask_irq()which is handling the cached flags correctly.Signed-off-by Gunter Grau <[email protected]>--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/irq/chip.c +1
-2@@ -987,7 +987,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { - desc->irq_data.chip->irq_unmask (&desc->irq_data); +unmask_irq (desc); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc) --
Quoted 2 lines
2.25.1
OK, so this is 4.14+, i.e. possibly our 4.19 and 5.4 ipipe trees, and that generically. Need to check why we didn't see this in our tests so far...
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Re: [PATCH] ipipe: Fix ipipe level irq end
In reply to Gunter GrauQuoted 28 lines · Gunter Grau via Xenomai
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in
mask_irq():
bf22ff45bed6("genirq: Avoid unnecessary low level irq function calls")This means if the flag is not serviced correctly
the real bit in the hardware interrupt controller may not be cleared or set.
The__ipipe_end_level_irq()function does not follow this rule. It unmasks the bit in the hardware without setting the cached flags accordingly. So after the first level interrupt is finished the mask cache has a wrong state. If now the next interrupt fires, themask_irq()function will not really mask the interrupt in the hardware which causes a interrupt storm after reenabeling the hard irqs.
The fix now callsunmask_irq()which is handling the cached flags correctly.Signed-off-by Gunter Grau <[email protected]>--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/irq/chip.c +0
-0
kernel/irq/chip.c void __ipipe_ack_level_irq(struct irq_desc *desc) · line 990
Quoted 5 lines
kernel/irq/chip.c +1
-1@@ -987,7 +987,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { - desc->irq_data.chip->irq_unmask (&desc->irq_data); +unmask_irq (desc);
Finally looked at this: Issue confirmed, solution if fine, just not optimal. I would also suggest to simply add irq_state_clr_masked(). unmask_irq is overkill because all the extra checks there are needless in the end-irq case, and also hard_irq_disable is redundant.
Thanks,
Jan
Quoted 5 lines
kernel/irq/chip.c +0
-1}void __ipipe_ack_fasteoi_irq (struct irq_desc *desc) --2.25.1
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
PATCH 1/1 ipipe: Fix ipipe level irq end
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in mask_irq():
bf22ff45bed6 ("genirq: Avoid unnecessary low level irq function calls")
This means if the flag is not serviced correctly
the real bit in the hardware interrupt controller may not be cleared or set.
The __ipipe_end_level_irq() function does not follow this rule. It unmasks the bit in the hardware without setting the cached flags accordingly. So after the first level interrupt is finished the mask cache has a wrong state. If now the next interrupt fires, the mask_irq() function will not really mask the interrupt in the hardware which causes a interrupt storm after reenabeling the hard irqs.
The fix now also updates the shadow flag correctly.
--- kernel/irq/chip.c | 1 + 1 file changed, 1 insertion(+)
kernel/irq/chip.c +1 -0
@@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { desc->irq_data.chip->irq_unmask (&desc->irq_data); +irq_state_clr_masked (desc); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc)
--
2.25.1
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
Jan Kiszka
AppliedRe: [PATCH] ipipe: Fix ipipe level irq end
Quoted 33 lines · Gunter Grau via Xenomai
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in
mask_irq():
bf22ff45bed6("genirq: Avoid unnecessary low level irq function calls")This means if the flag is not serviced correctly
the real bit in the hardware interrupt controller may not be cleared or set.
The__ipipe_end_level_irq()function does not follow this rule. It unmasks the bit in the hardware without setting the cached flags accordingly. So after the first level interrupt is finished the mask cache has a wrong state. If now the next interrupt fires, themask_irq()function will not really mask the interrupt in the hardware which causes a interrupt storm after reenabeling the hard irqs.
The fix now also updates the shadow flag correctly.--- kernel/irq/chip.c | 1 + 1 file changed, 1 insertion(+)kernel/irq/chip.c +1
-1@@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { desc->irq_data.chip->irq_unmask (&desc->irq_data); +irq_state_clr_masked (desc); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc) --
Quoted 2 lines
2.25.1
Thanks, applied to ipipe-noarch. I had to do that manually as you email client managed the patch (tabs->spaces, trailing spaces removed). Use git-send-email or a client that avoids this mangling.
Greg, I will apply this to ipipe-x86 (4.19-cip and 5.4), could you do the same for arm and arm64?
Thanks,
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
RE: [PATCH] ipipe: Fix ipipe level irq end
Quoted 52 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Donnerstag, 17. Februar 2022 10:16
To: Grau, Gunter <[email protected]>; [email protected]; Greg Gallagher <[email protected]>
Subject: Re: [PATCH] ipipe: Fix ipipe level irq endCaution: This e-mail originated from outside of Philips, be careful for phishing.
Quoted 31 lines · Gunter Grau via Xenomai
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in
mask_irq():
bf22ff45bed6("genirq: Avoid unnecessary low level irq function calls")This means if the flag is not serviced correctly the real bit in the hardware interrupt controller may not be cleared or set. The
__ipipe_end_level_irq()function does not follow this rule. It unmasks the bit in the hardware without setting the cached flags accordingly. So after the first level interrupt is finished the mask cache has a wrong state. If now the next interrupt fires, themask_irq()function will not really mask the interrupt in the hardware which causes a interrupt storm after reenabeling the hard irqs. The fix now also updates the shadow flag correctly.--- kernel/irq/chip.c | 1 + 1 file changed, 1 insertion(+)kernel/irq/chip.c index renamed from kernel/irq/chip.c +0
-0
7c03e2931189..ff9a8b3f33db100644kernel/irq/chip.c +1
-1@@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { desc->irq_data.chip->irq_unmask (&desc->irq_data); +irq_state_clr_masked (desc); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc) --Quoted 2 lines
2.25.1
Thanks, applied to ipipe-noarch. I had to do that manually as you email client managed the patch (
tabs->spaces, trailing spaces removed). Use git-send- email or a client that avoids this mangling.
Quoted 5 lines
Greg, I will apply this to ipipe-x86 (4.19-cip and 5.4), could you do the same for arm and arm64?
Thanks,
Jan
Hi,
That’s weird, because I used git send-email for this. Maybe something in the mail server configuration. Same patch for ipipe-arm64 will follow, but I don't know how to make it better than using git send-email ☹.
Thanks for applying.
Gunter
Quoted 4 lines
--
Siemens AG, Technology
Competence Center Embedded Linux
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
Re: [PATCH] ipipe: Fix ipipe level irq end
Quoted 55 lines · Gunter
Quoted 55 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Donnerstag, 17. Februar 2022 10:16
To: Grau, Gunter <[email protected]>; [email protected]; Greg Gallagher <[email protected]>
Subject: Re: [PATCH] ipipe: Fix ipipe level irq endCaution: This e-mail originated from outside of Philips, be careful for phishing.
Quoted 31 lines · Gunter Grau via Xenomai
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in
mask_irq():
bf22ff45bed6("genirq: Avoid unnecessary low level irq function calls")This means if the flag is not serviced correctly the real bit in the hardware interrupt controller may not be cleared or set. The
__ipipe_end_level_irq()function does not follow this rule. It unmasks the bit in the hardware without setting the cached flags accordingly. So after the first level interrupt is finished the mask cache has a wrong state. If now the next interrupt fires, themask_irq()function will not really mask the interrupt in the hardware which causes a interrupt storm after reenabeling the hard irqs. The fix now also updates the shadow flag correctly.--- kernel/irq/chip.c | 1 + 1 file changed, 1 insertion(+)kernel/irq/chip.c index renamed from kernel/irq/chip.c +0
-0
7c03e2931189..ff9a8b3f33db100644kernel/irq/chip.c +1
-1@@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { desc->irq_data.chip->irq_unmask (&desc->irq_data); +irq_state_clr_masked (desc); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc) --Quoted 2 lines
2.25.1
Thanks, applied to ipipe-noarch. I had to do that manually as you email client managed the patch (
tabs->spaces, trailing spaces removed). Use git-send- email or a client that avoids this mangling.Greg, I will apply this to ipipe-x86 (4.19-cip and 5.4), could you do the same for arm and arm64?
Quoted 8 lines
Quoted 2 lines
Thanks,
JanHi,
That’s weird, because I used git send-email for this. Maybe something in the mail server configuration. Same patch for ipipe-arm64 will follow, but I don't know how to make it better than using git send-email ☹.
Strange indeed. You can see what reached the list here:
https://xenomai.org/pipermail/xenomai/2022-February/047217.html
Maybe worth to take to your IT with this. I know from own painful experiences that professional mail servers trying to modify email, eg. to filter out information that should not leave an org, can decide to re-encode the content, and that rather unprofessionally.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Re: [PATCH] ipipe: Fix ipipe level irq end
In reply to Jan KiszkaQuoted 44 lines · Jan Kiszka
Quoted 33 lines · Gunter Grau via Xenomai
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in
mask_irq():
bf22ff45bed6("genirq: Avoid unnecessary low level irq function calls")This means if the flag is not serviced correctly
the real bit in the hardware interrupt controller may not be cleared or set.
The__ipipe_end_level_irq()function does not follow this rule. It unmasks the bit in the hardware without setting the cached flags accordingly. So after the first level interrupt is finished the mask cache has a wrong state. If now the next interrupt fires, themask_irq()function will not really mask the interrupt in the hardware which causes a interrupt storm after reenabeling the hard irqs.
The fix now also updates the shadow flag correctly.--- kernel/irq/chip.c | 1 + 1 file changed, 1 insertion(+)kernel/irq/chip.c +1
-1@@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { desc->irq_data.chip->irq_unmask (&desc->irq_data); +irq_state_clr_masked (desc); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc) --Quoted 2 lines
2.25.1
Thanks, applied to ipipe-noarch. I had to do that manually as you email client managed the patch (
tabs->spaces, trailing spaces removed). Use git-send-email or a client that avoids this mangling.Greg, I will apply this to ipipe-x86 (4.19-cip and 5.4), could you do the same for arm and arm64?
Quoted 8 lines
Thanks,
Jan--
Siemens AG, TechnologyCompetence Center Embedded Linux
Yep, I’ve applied the patch locally, I’ll update arm and arm64 shortly.
-Greg
Quoted 2 lines
Re: [PATCH] ipipe: Fix ipipe level irq end
Quoted 53 lines · Greg Gallagher
On Thu, Feb 17, 2022 at 4:15 AM Jan Kiszka <[email protected] <mailto:[email protected]>> wrote:
On 17.02.22 09:48, Gunter Grau via Xenomai wrote:
> The following commit in the vanilla kernel introduced
> a check for the cached interrupt mask flag inmask_irq():
>
>bf22ff45bed6("genirq: Avoid unnecessary low level irq function calls")
>
> This means if the flag is not serviced correctly
> the real bit in the hardware interrupt controller may not be > cleared or set.
> The__ipipe_end_level_irq()function does not follow this rule. > It unmasks the bit in the hardware without setting the cached flags > accordingly. So after the first level interrupt is finished the > mask cache has a wrong state. If now the next interrupt fires, > themask_irq()function will not really mask the interrupt in > the hardware which causes a interrupt storm after reenabeling > the hard irqs.
> The fix now also updates the shadow flag correctly.
> ---
>kernel/irq/chip.c| 1 +
> 1 file changed, 1 insertion(+)
>
> diff --gita/kernel/irq/chip.cb/kernel/irq/chip.c
> index7c03e2931189..ff9a8b3f33db100644
> ---a/kernel/irq/chip.c
> +++b/kernel/irq/chip.c
> @@ -988,6 +988,7 @@ void__ipipe_ack_level_irq(struct irq_desc *desc)> void__ipipe_end_level_irq(struct irq_desc *desc)
> {
> desc->irq_data.chip->irq_unmask(&desc->irq_data); > + irq_state_clr_masked(desc);
> }
>
> void__ipipe_ack_fasteoi_irq(struct irq_desc *desc)
> --
> 2.25.1
>Thanks, applied to ipipe-noarch. I had to do that manually as you email client managed the patch (
tabs->spaces, trailing spaces removed). Use git-send-email or a client that avoids this mangling.Greg, I will apply this to ipipe-x86 (4.19-cip and 5.4), could you do the same for arm and arm64?
Thanks,
Jan
Quoted 9 lines
--
Siemens AG, TechnologyCompetence Center Embedded Linux
Yep, I’ve applied the patch locally, I’ll update arm and arm64 shortly.
Just force-updated ipipe/noarch to have Gunter's address and signed-off fixed up. Please use that version.
Thanks,
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Re: [PATCH] ipipe: Fix ipipe level irq end
Quoted 69 lines · Jan Kiszka
Quoted 27 lines · Greg Gallagher
On Thu, Feb 17, 2022 at 4:15 AM Jan Kiszka <[email protected] <mailto:[email protected]>> wrote:
On 17.02.22 09:48, Gunter Grau via Xenomai wrote:
> The following commit in the vanilla kernel introduced
> a check for the cached interrupt mask flag inmask_irq():
>
>bf22ff45bed6("genirq: Avoid unnecessary low level irq function calls")
>
> This means if the flag is not serviced correctly
> the real bit in the hardware interrupt controller may not be > cleared or set.
> The__ipipe_end_level_irq()function does not follow this rule. > It unmasks the bit in the hardware without setting the cached flags > accordingly. So after the first level interrupt is finished the > mask cache has a wrong state. If now the next interrupt fires, > themask_irq()function will not really mask the interrupt in > the hardware which causes a interrupt storm after reenabeling > the hard irqs.
> The fix now also updates the shadow flag correctly.
> ---
>kernel/irq/chip.c| 1 +
> 1 file changed, 1 insertion(+)
>Quoted 5 lines
> diff --git
a/kernel/irq/chip.cb/kernel/irq/chip.c> index7c03e2931189..ff9a8b3f33db100644
> ---a/kernel/irq/chip.c
> +++b/kernel/irq/chip.c
> @@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(structirq_desc*desc)
Quoted 6 lines
Quoted 6 lines
void
__ipipe_end_level_irq(struct irq_desc *desc){ desc->irq_data.chip->irq_unmask(&desc->irq_data);+
irq_state_clr_masked(desc);
}Quoted 6 lines
Quoted 4 lines
void
__ipipe_ack_fasteoi_irq(struct irq_desc *desc)
--
2.25.1Thanks, applied to ipipe-noarch. I had to do that manually as you
Quoted 9 lines
client managed the patch (
tabs->spaces, trailing spaces removed). Use git-send-email or a client that avoids this mangling.Greg, I will apply this to ipipe-x86 (4.19-cip and 5.4), could you do the same for arm and arm64?
Thanks,
JanQuoted 9 lines
--
Siemens AG, TechnologyCompetence Center Embedded Linux
Yep, I’ve applied the patch locally, I’ll update arm and arm64 shortly.
Just force-updated ipipe/noarch to have Gunter's address and signed-off fixed up. Please use that version.
Quoted 6 lines
Thanks,
Jan--
Siemens AG, Technology
Competence Center Embedded Linux
Ack
Quoted 2 lines
RE: [PATCH] ipipe: Fix ipipe level irq end
Hi,
Unfortunately I have to come back to this.
On Thu, Feb 17, 2022 at 10:12 AM Jan Kiszka <mailto:[email protected]> wrote:
Quoted 34 lines · Greg Gallagher
On Thu, Feb 17, 2022 at 4:15 AM Jan Kiszka <mailto:[email protected] <mailto:mailto:[email protected]>> wrote:
On 17.02.22 09:48, Gunter Grau via Xenomai wrote: > The following commit in the vanilla kernel introduced > a check for the cached interrupt mask flag in mask_irq(): > > bf22ff45bed6 ("genirq: Avoid unnecessary low level irq function calls") > > This means if the flag is not serviced correctly > the real bit in the hardware interrupt controller may not be > cleared or set. > The __ipipe_end_level_irq() function does not follow this rule. > It unmasks the bit in the hardware without setting the cached flags > accordingly. So after the first level interrupt is finished the > mask cache has a wrong state. If now the next interrupt fires, > the mask_irq() function will not really mask the interrupt in > the hardware which causes a interrupt storm after reenabeling > the hard irqs. > The fix now also updates the shadow flag correctly. > --- > kernel/irq/chip.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c > index 7c03e2931189..ff9a8b3f33db 100644 > --- a/kernel/irq/chip.c > +++ b/kernel/irq/chip.c > @@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc) > void __ipipe_end_level_irq(struct irq_desc *desc) > {
Quoted 8 lines
> desc->irq_data.chip->irq_unmask(&desc->irq_data);
> + irq_state_clr_masked(desc);
> }
>
> void __ipipe_ack_fasteoi_irq(struct irq_desc *desc)
> --
> 2.25.1
>We discovered some situations (with iio drivers) where this fix seem not to work.
Obviously in the moment where the irq is unmasked, the new interrupt seems to fire again and the irq_ack() code of the new interrupt runs before the irq_stats_clr_masked() is called. When I wrote the patch I thought the irqs are disabled at this moment. Looks like this is not the case. At least when I change the order to:
irq_state_clr_masked(desc);desc->irq_data.chip->irq_unmask(&desc->irq_data);
My use case works again.
Now I am unsure if the above reordering is the correct solution or maybe just calling unmask_irq(); which was the first proposal is better? We dropped unmask_irq() proposal because it does additionally some locking, but maybe this is needed. I am unsure.
Do you have some advice?
Thanks in advance,
Gunter
Quoted 11 lines
Thanks, applied to ipipe-noarch. I had to do that manually as you email client managed the patch (
tabs->spaces, trailing spaces removed). Use git-send-email or a client that avoids this mangling.Greg, I will apply this to ipipe-x86 (4.19-cip and 5.4), could you do the same for arm and arm64?
Thanks,
Jan
Quoted 9 lines
--
Siemens AG, TechnologyCompetence Center Embedded Linux
Yep, I’ve applied the patch locally, I’ll update arm and arm64 shortly.
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
Re: [PATCH] ipipe: Fix ipipe level irq end
Quoted 54 lines · Gunter
Hi,
Unfortunately I have to come back to this.
On Thu, Feb 17, 2022 at 10:12 AM Jan Kiszka <mailto:[email protected]> wrote:
Quoted 34 lines · Greg Gallagher
On Thu, Feb 17, 2022 at 4:15 AM Jan Kiszka <mailto:[email protected] <mailto:mailto:[email protected]>> wrote:
On 17.02.22 09:48, Gunter Grau via Xenomai wrote: > The following commit in the vanilla kernel introduced > a check for the cached interrupt mask flag in mask_irq(): > > bf22ff45bed6 ("genirq: Avoid unnecessary low level irq function calls") > > This means if the flag is not serviced correctly > the real bit in the hardware interrupt controller may not be > cleared or set. > The __ipipe_end_level_irq() function does not follow this rule. > It unmasks the bit in the hardware without setting the cached flags > accordingly. So after the first level interrupt is finished the > mask cache has a wrong state. If now the next interrupt fires, > the mask_irq() function will not really mask the interrupt in > the hardware which causes a interrupt storm after reenabeling > the hard irqs. > The fix now also updates the shadow flag correctly. > --- > kernel/irq/chip.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c > index 7c03e2931189..ff9a8b3f33db 100644 > --- a/kernel/irq/chip.c > +++ b/kernel/irq/chip.c > @@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc) > void __ipipe_end_level_irq(struct irq_desc *desc) > {Quoted 8 lines
> desc->irq_data.chip->irq_unmask(&desc->irq_data); > + irq_state_clr_masked(desc); > } > > void __ipipe_ack_fasteoi_irq(struct irq_desc *desc) > -- > 2.25.1 >We discovered some situations (with iio drivers) where this fix seem not to work.
Obviously in the moment where the irq is unmasked, the new interrupt seems to fire again and theirq_ack()code of the new interrupt runs before theirq_stats_clr_masked()is called. When I wrote the patch I thought the irqs are disabled at this moment. Looks like this is not the case. At least when I change the order to:
Quoted 8 lines
irq_state_clr_masked(desc);desc->irq_data.chip->irq_unmask(&desc->irq_data);My use case works again.
Now I am unsure if the above reordering is the correct solution or maybe just callingunmask_irq(); which was the first proposal is better? We droppedunmask_irq()proposal because it does additionally some locking, but maybe this is needed. I am unsure.Do you have some advice?
I didn't wrap my head fully around this again yet, but if you can't ensure a correct, race-free behavior by ordering, you need locking. Maybe have a look again how dovetail works in this context as it should have logically the same thing to do.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
RE: [PATCH] ipipe: Fix ipipe level irq end
Hi,
Quoted 79 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Montag, 15. August 2022 08:19
To: Grau, Gunter <[email protected]>; [email protected]
Subject: Re: [PATCH] ipipe: Fix ipipe level irq endCaution: This e-mail originated from outside of Philips, be careful for phishing.
Quoted 6 lines · Gunter
Hi,
Unfortunately I have to come back to this.
On Thu, Feb 17, 2022 at 10:12 AM Jan Kiszka
Quoted 5 lines · <mailto:[email protected]> wrote:
Quoted 4 lines · Greg Gallagher
On Thu, Feb 17, 2022 at 4:15 AM Jan Kiszka
<mailto:[email protected]Quoted 23 lines · <mailto:mailto:[email protected]>> wrote:
Quoted 23 lines · Gunter Grau via Xenomai
Quoted 4 lines
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in
mask_irq():
bf22ff45bed6("genirq: Avoid unnecessary low level irq functioncalls")
>
> This means if the flag is not serviced correctly
> the real bit in the hardware interrupt controller may not be > cleared or set.
> The__ipipe_end_level_irq()function does not follow this rule. > It unmasks the bit in the hardware without setting the cached flags > accordingly. So after the first level interrupt is finished the > mask cache has a wrong state. If now the next interrupt fires, > themask_irq()function will not really mask the interrupt in > the hardware which causes a interrupt storm after reenabeling > the hard irqs.
> The fix now also updates the shadow flag correctly.
> ---
>kernel/irq/chip.c| 1 +
> 1 file changed, 1 insertion(+)
>Quoted 5 lines
Quoted 5 lines
kernel/irq/chip.c void __ipipe_ack_level_irq(struct irq_desc
Quoted 5 lines
kernel/irq/chip.c +0
-0@@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(struct irq_desc*desc)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
kernel/irq/chip.c +1
-0void __ipipe_end_level_irq (struct irq_desc *desc) { desc->irq_data.chip->irq_unmask (&desc->irq_data); +irq_state_clr_masked (desc); }Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
kernel/irq/chip.c +0
-1void __ipipe_ack_fasteoi_irq (struct irq_desc *desc) --2.25.1
We discovered some situations (with iio drivers) where this fix seem not to
work.
Quoted 1 line
Obviously in the moment where the irq is unmasked, the new interrupt
seems to fire again and the
irq_ack()code of the new interrupt runs before theirq_stats_clr_masked()is called.Quoted 1 line
When I wrote the patch I thought the irqs are disabled at this moment.
Looks like this is not the case. At least when I change the order to:
Quoted 6 lines
irq_state_clr_masked(desc);desc->irq_data.chip->irq_unmask(&desc->irq_data);My use case works again.
Now I am unsure if the above reordering is the correct solution or maybejust calling
unmask_irq(); which was the first proposal is better?Quoted 1 line
We dropped
unmask_irq()proposal because it does additionally some
Quoted 9 lines
locking, but maybe this is needed. I am unsure.
Quoted 2 lines
Do you have some advice?
I didn't wrap my head fully around this again yet, but if you can't ensure a correct, race-free behavior by ordering, you need locking.
Maybe have a look again how dovetail works in this context as it should have logically the same thing to do.
It looks like in dovetail the masked bit in the description is also not cleared (missing irq_state_clr_masked(desc)).
This might work because the corresponding mask function here seems also sourced from the dovetail patch and is not checking the bit before masking the irq. No guaranties here, I am not firm with dovetail and that’s what it looks like when checking handle_percpu_irq().
Since your last comment about the first fix pointed out that unmask_irq() is way too much in this context I will send a patch with the commands reordered and no extra locking. That should work.
Thanks,
Gunter
Quoted 5 lines
Jan
--
Siemens AG, Technology
Competence Center Embedded Linux
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
Re: [PATCH] ipipe: Fix ipipe level irq end
Quoted 91 lines · Gunter
Hi,
Quoted 79 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Montag, 15. August 2022 08:19
To: Grau, Gunter <[email protected]>; [email protected]
Subject: Re: [PATCH] ipipe: Fix ipipe level irq endCaution: This e-mail originated from outside of Philips, be careful for phishing.
Quoted 6 lines · Gunter
Hi,
Unfortunately I have to come back to this.
On Thu, Feb 17, 2022 at 10:12 AM Jan Kiszka
Quoted 5 lines · <mailto:[email protected]> wrote:
Quoted 4 lines · Greg Gallagher
On Thu, Feb 17, 2022 at 4:15 AM Jan Kiszka
<mailto:[email protected]Quoted 23 lines · <mailto:mailto:[email protected]>> wrote:
Quoted 23 lines · Gunter Grau via Xenomai
Quoted 4 lines
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in
mask_irq():
bf22ff45bed6("genirq: Avoid unnecessary low level irq functioncalls")
>
> This means if the flag is not serviced correctly
> the real bit in the hardware interrupt controller may not be > cleared or set.
> The__ipipe_end_level_irq()function does not follow this rule. > It unmasks the bit in the hardware without setting the cached flags > accordingly. So after the first level interrupt is finished the > mask cache has a wrong state. If now the next interrupt fires, > themask_irq()function will not really mask the interrupt in > the hardware which causes a interrupt storm after reenabeling > the hard irqs.
> The fix now also updates the shadow flag correctly.
> ---
>kernel/irq/chip.c| 1 +
> 1 file changed, 1 insertion(+)
>Quoted 5 lines
Quoted 5 lines
kernel/irq/chip.c void __ipipe_ack_level_irq(struct irq_desc
Quoted 5 lines
kernel/irq/chip.c +0
-0@@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(struct irq_desc*desc)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
kernel/irq/chip.c +1
-0void __ipipe_end_level_irq (struct irq_desc *desc) { desc->irq_data.chip->irq_unmask (&desc->irq_data); +irq_state_clr_masked (desc); }Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
kernel/irq/chip.c +0
-1void __ipipe_ack_fasteoi_irq (struct irq_desc *desc) --2.25.1
We discovered some situations (with iio drivers) where this fix seem not to
work.
Quoted 1 line
Obviously in the moment where the irq is unmasked, the new interrupt
seems to fire again and the
irq_ack()code of the new interrupt runs before theirq_stats_clr_masked()is called.Quoted 1 line
When I wrote the patch I thought the irqs are disabled at this moment.
Looks like this is not the case. At least when I change the order to:
Quoted 6 lines
irq_state_clr_masked(desc);desc->irq_data.chip->irq_unmask(&desc->irq_data);My use case works again.
Now I am unsure if the above reordering is the correct solution or maybejust calling
unmask_irq(); which was the first proposal is better?Quoted 1 line
We dropped
unmask_irq()proposal because it does additionally someQuoted 9 lines
locking, but maybe this is needed. I am unsure.
Quoted 2 lines
Do you have some advice?
I didn't wrap my head fully around this again yet, but if you can't ensure a correct, race-free behavior by ordering, you need locking.
Maybe have a look again how dovetail works in this context as it should have logically the same thing to do.
Quoted 4 lines
It looks like in dovetail the masked bit in the description is also not cleared (missing
irq_state_clr_masked(desc)).
This might work because the corresponding mask function here seems also sourced from the dovetail patch and is not checking the bit before masking the irq. No guaranties here, I am not firm with dovetail and that’s what it
looks like when checkinghandle_percpu_irq().
Dovetail does not work the I-pipe did, __ipipe_end_level_irq() is now handled internally. The only way to re-enable interrupts in this path would be to reschedule a real-time task, which cannot happen until irq_exit_pipeline() is called when unwinding the interrupt frame, at which point the companion core may reschedule, never before. So unless the core enables back hard IRQs in the handler, which would be 100% broken behavior, there is no issue.
IOW, both the interrupt flow and event handlers run with (hard) IRQs masked in the CPU all the way, preventing any interrupt storm, whether the guard bit is set prior to or after unmasking. Also, the vanilla [un]mask_irq() logic is kept, testing and setting irqd_irq_masked() as appropriate, i.e. when using the state cache is applicable.
handle_percpu_irq() is a special case, the vanilla code does not have to use a state cache because you do not mask per-CPU irqs, you might disable them entirely if not handled.
This is tricky stuff, so a bug can never be excluded, but I don't think the I-pipe scenario applies to Dovetail.
Signature · 1 line
Philippe.
PATCH 1/1 ] ipipe: noarch: Fix ipipe level end interrupt
In reply to Grau, GunterFrom: Gunter Grau <[email protected]>
There is the possibility that a new level triggered interrupt is already waiting when __ipipe_end_level_irq() is called.
In this case at the moment when the irq is unmasked it may already fire and call __ipipe_ack_level_irq() before the masked state is cleared in the irq description. If this happens mask_irq() called by __ipipe_ack_level_irq() will not mask the interrupt and the system my stall.
To prevent this, the masked state will now be cleared before unmasking the interrupt. A following direct interrupt handler call will then correctly mask the hardware interrupt as needed.
--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/irq/chip.c +1 -1
@@ -1048,8 +1048,8 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { - desc->irq_data.chip->irq_unmask (&desc->irq_data);irq_state_clr_masked (desc); + desc->irq_data.chip->irq_unmask (&desc->irq_data); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc)
Signature · 1 line
2.25.1
Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interrupt
Quoted 23 lines · Gunter Grau
From: Gunter Grau <[email protected]>
There is the possibility that a new level triggered interrupt is already waiting when
__ipipe_end_level_irq()is called.
In this case at the moment when the irq is unmasked it may already fire and call__ipipe_ack_level_irq()before the masked state is cleared in the irq description. If this happensmask_irq()called by__ipipe_ack_level_irq()will not mask the interrupt and the system my stall.
To prevent this, the masked state will now be cleared before unmasking the interrupt. A following direct interrupt handler call will then correctly mask the hardware interrupt as needed.Signed-off-by Gunter Grau <[email protected]>--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/irq/chip.c +0
-0
kernel/irq/chip.c void __ipipe_ack_level_irq(struct irq_desc *desc) · line 1055
Quoted 9 lines
kernel/irq/chip.c +1
-1@@ -1048,8 +1048,8 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { - desc->irq_data.chip->irq_unmask (&desc->irq_data);irq_state_clr_masked (desc); + desc->irq_data.chip->irq_unmask (&desc->irq_data); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc)
OK, but if we need this ordering here, why didn't we need it before for unmask_irq()? There, it was sufficient so far to disable local irqs around unmask + clr.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
RE: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interrupt
Hi,
Quoted 42 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Montag, 15. August 2022 13:56
To: Grau, Gunter <[email protected]>; [email protected]
Subject: Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interruptCaution: This e-mail originated from outside of Philips, be careful for phishing.
Quoted 31 lines · Gunter Grau
From: Gunter Grau <[email protected]>
There is the possibility that a new level triggered interrupt is already waiting when
__ipipe_end_level_irq()is called.
In this case at the moment when the irq is unmasked it may already fire and call__ipipe_ack_level_irq()before the masked state is cleared in the irq description. If this happensmask_irq()called by__ipipe_ack_level_irq()will not mask the interrupt and the system my stall.
To prevent this, the masked state will now be cleared before unmasking the interrupt. A following direct interrupt handler call will then correctly mask the hardware interrupt as needed.Signed-off-by Gunter Grau <[email protected]>--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/irq/chip.c index renamed from kernel/irq/chip.c +0
-0
6a883a4cee87..25d0942b592a100644kernel/irq/chip.c +1
-1@@ -1048,8 +1048,8 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { - desc->irq_data.chip->irq_unmask (&desc->irq_data);irq_state_clr_masked (desc); + desc->irq_data.chip->irq_unmask (&desc->irq_data); }
Quoted 7 lines
kernel/irq/chip.c void __ipipe_ack_level_irq(struct irq_desc *desc) · line 1055
Quoted 1 line
kernel/irq/chip.c +0
-0void __ipipe_ack_fasteoi_irq (struct irq_desc *desc)OK, but if we need this ordering here, why didn't we need it before for
unmask_irq()? There, it was sufficient so far to disable local irqs around unmask + clr.Jan
Interesting, I thought the disabling of the local irqs is exact the reason why it works in contrast to __ipipe_end_level_irq() without disabling. So did I miss something? Should I add a local disable here, too?
Thanks,
Gunter
Quoted 4 lines
--
Siemens AG, Technology
Competence Center Embedded Linux
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interrupt
Quoted 50 lines · Gunter
Hi,
Quoted 48 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Montag, 15. August 2022 13:56
To: Grau, Gunter <[email protected]>; [email protected]
Subject: Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interruptCaution: This e-mail originated from outside of Philips, be careful for phishing.
Quoted 23 lines · Gunter Grau
From: Gunter Grau <[email protected]>
There is the possibility that a new level triggered interrupt is already waiting when
__ipipe_end_level_irq()is called.
In this case at the moment when the irq is unmasked it may already fire and call__ipipe_ack_level_irq()before the masked state is cleared in the irq description. If this happensmask_irq()called by__ipipe_ack_level_irq()will not mask the interrupt and the system my stall.
To prevent this, the masked state will now be cleared before unmasking the interrupt. A following direct interrupt handler call will then correctly mask the hardware interrupt as needed.Signed-off-by Gunter Grau <[email protected]>--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/irq/chip.c index renamed from kernel/irq/chip.c +0
-0
6a883a4cee87..25d0942b592a100644kernel/irq/chip.c void __ipipe_ack_level_irq(struct irq_desc · line 1055
Quoted 9 lines
kernel/irq/chip.c +1
-1@@ -1048,8 +1048,8 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { - desc->irq_data.chip->irq_unmask (&desc->irq_data);irq_state_clr_masked (desc); + desc->irq_data.chip->irq_unmask (&desc->irq_data); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc)OK, but if we need this ordering here, why didn't we need it before for
unmask_irq()? There, it was sufficient so far to disable local irqs around unmask + clr.
Quoted 4 lines
Quoted 1 line
Jan
Interesting, I thought the disabling of the local irqs is exact the reason why it works in contrast to
__ipipe_end_level_irq()without disabling. So did I miss something? Should I add a local disable here, too?
That's not yet what I suggest. I just first of all try to understand the boundary conditions for the issue here and if those may apply elsewhere.
If I look at the caller of ipipe_end_irq in Xenomai, none should have hard irqs on when invoking this. And that means, when local irq disabling is not sufficient, unmasq_irq may have the same issue you are trying to fix here by reordering.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
RE: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interrupt
Quoted 66 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Subject: Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interruptQuoted 51 lines · Gunter
Hi,
Quoted 49 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Montag, 15. August 2022 13:56
To: Grau, Gunter <[email protected]>; [email protected]
Subject: Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interruptCaution: This e-mail originated from outside of Philips, be careful for phishing.
Quoted 23 lines · Gunter Grau
From: Gunter Grau <[email protected]>
There is the possibility that a new level triggered interrupt is already waiting when
__ipipe_end_level_irq()is called. In this case at the moment when the irq is unmasked it may already fire and call__ipipe_ack_level_irq()before the masked state is cleared in the irq description. If this happensmask_irq()called by__ipipe_ack_level_irq()will not mask the interrupt and the system my stall.
To prevent this, the masked state will now be cleared before unmasking the interrupt. A following direct interrupt handler call will then correctly mask the hardware interrupt as needed.Signed-off-by Gunter Grau <[email protected]>--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/irq/chip.c index renamed from kernel/irq/chip.c +0
-0
6a883a4cee87..25d0942b592a100644kernel/irq/chip.c void __ipipe_ack_level_irq(struct irq_desc · line 1055
Quoted 9 lines
kernel/irq/chip.c +1
-1@@ -1048,8 +1048,8 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { - desc->irq_data.chip->irq_unmask (&desc->irq_data);irq_state_clr_masked (desc); + desc->irq_data.chip->irq_unmask (&desc->irq_data); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc)OK, but if we need this ordering here, why didn't we need it before for
unmask_irq()? There, it was sufficient so far to disable local irqs around unmask + clr.Quoted 3 lines
Quoted 1 line
Jan
Interesting, I thought the disabling of the local irqs is exact the reason why
it works in contrast to
__ipipe_end_level_irq()without disabling.Quoted 1 line
So did I miss something? Should I add a local disable here, too?
That's not yet what I suggest. I just first of all try to understand the boundary conditions for the issue here and if those may apply elsewhere.
Quoted 7 lines
If I look at the caller of
ipipe_end_irqin Xenomai, none should have hard irqs on when invoking this. And that means, when local irq disabling is not sufficient,unmasq_irqmay have the same issue you are trying to fix here by reordering.Jan
I tried to follow my issue by dumping the stacktrace in __ipipe_end_level_irq(). Kernel is still 5.4:
[ 34.590806] [<8010f314>] (unwind_backtrace) from [<8010b824>] (show_stack+0x10/0x14) [ 34.598601] [<8010b824>] (show_stack) from [<8084724c>] (dump_stack+0xd8/0xf4) [ 34.605877] [<8084724c>] (dump_stack) from [<8017c160>] (__ipipe_end_level_irq+0x20/0x30) [ 34.618312] [<8017c160>] (__ipipe_end_level_irq) from [<80177f90>] (irq_finalize_oneshot.part.1+0x78/0xf8) [ 34.628031] [<80177f90>] (irq_finalize_oneshot.part.1) from [<80178080>] (irq_thread_fn+0x70/0x78) [ 34.637044] [<80178080>] (irq_thread_fn) from [<80177e44>] (irq_thread+0x170/0x244) [ 34.646751] [<80177e44>] (irq_thread) from [<80148fa8>] (kthread+0x14c/0x150) [ 34.654879] [<80148fa8>] (kthread) from [<80101118>] (ret_from_fork+0x18/0x24)
I also thought the irqs are always off here. But I cannot explain the current issue otherwise.
Thanks,
Gunter
Quoted 3 lines
--
Siemens AG, Technology
Competence Center Embedded Linux
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interrupt
Quoted 85 lines · Gunter
Quoted 66 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Subject: Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interruptQuoted 51 lines · Gunter
Hi,
Quoted 49 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Montag, 15. August 2022 13:56
To: Grau, Gunter <[email protected]>; [email protected]
Subject: Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interruptCaution: This e-mail originated from outside of Philips, be careful for phishing.
Quoted 23 lines · Gunter Grau
From: Gunter Grau <[email protected]>
There is the possibility that a new level triggered interrupt is already waiting when
__ipipe_end_level_irq()is called. In this case at the moment when the irq is unmasked it may already fire and call__ipipe_ack_level_irq()before the masked state is cleared in the irq description. If this happensmask_irq()called by__ipipe_ack_level_irq()will not mask the interrupt and the system my stall.
To prevent this, the masked state will now be cleared before unmasking the interrupt. A following direct interrupt handler call will then correctly mask the hardware interrupt as needed.Signed-off-by Gunter Grau <[email protected]>--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/irq/chip.c index renamed from kernel/irq/chip.c +0
-0
6a883a4cee87..25d0942b592a100644kernel/irq/chip.c void __ipipe_ack_level_irq(struct irq_desc · line 1055
Quoted 9 lines
kernel/irq/chip.c +1
-1@@ -1048,8 +1048,8 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { - desc->irq_data.chip->irq_unmask (&desc->irq_data);irq_state_clr_masked (desc); + desc->irq_data.chip->irq_unmask (&desc->irq_data); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc)OK, but if we need this ordering here, why didn't we need it before for
unmask_irq()? There, it was sufficient so far to disable local irqs around unmask + clr.Quoted 3 lines
Quoted 1 line
Jan
Interesting, I thought the disabling of the local irqs is exact the reason why
it works in contrast to
__ipipe_end_level_irq()without disabling.Quoted 1 line
So did I miss something? Should I add a local disable here, too?
That's not yet what I suggest. I just first of all try to understand the boundary conditions for the issue here and if those may apply elsewhere.
Quoted 7 lines
If I look at the caller of
ipipe_end_irqin Xenomai, none should have hard irqs on when invoking this. And that means, when local irq disabling is not sufficient,unmasq_irqmay have the same issue you are trying to fix here by reordering.Jan
I tried to follow my issue by dumping the stacktrace in
__ipipe_end_level_irq(). Kernel is still 5.4:[ 34.590806] [<8010f314>] (unwind_backtrace) from [<8010b824>] (show_stack+0x10/0x14) [ 34.598601] [<8010b824>] (show_stack) from [<8084724c>] (dump_stack+0xd8/0xf4) [ 34.605877] [<8084724c>] (dump_stack) from [<8017c160>] (__ipipe_end_level_irq+0x20/0x30) [ 34.618312] [<8017c160>] (__ipipe_end_level_irq) from [<80177f90>] (irq_finalize_oneshot.part.1+0x78/0xf8) [ 34.628031] [<80177f90>] (irq_finalize_oneshot.part.1) from [<80178080>] (irq_thread_fn+0x70/0x78) [ 34.637044] [<80178080>] (irq_thread_fn) from [<80177e44>] (irq_thread+0x170/0x244) [ 34.646751] [<80177e44>] (irq_thread) from [<80148fa8>] (kthread+0x14c/0x150) [ 34.654879] [<80148fa8>] (kthread) from [<80101118>] (ret_from_fork+0x18/0x24)
Quoted 1 line
I also thought the irqs are always off here. But I cannot explain the current issue otherwise.
In that path, hard-IRQs are NOT off in fact. I only checked the Xenomai code paths but forgot about the kernel ones.
But even if we disable hard-IRQs here as well, that would only protect us if that physical interrupt can only be raised on the local CPU. I don't think we can blindly rely on such an assumption (except for percpu irqs).
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
RE: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interrupt
Quoted 107 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Subject: Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interruptQuoted 60 lines · Gunter
Quoted 60 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Subject: Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level endQuoted 54 lines · Gunter
Hi,
Quoted 51 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Montag, 15. August 2022 13:56
To: Grau, Gunter <[email protected]>; [email protected]
Subject: Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interruptCaution: This e-mail originated from outside of Philips, be careful for phishing.
Quoted 24 lines · Gunter Grau
From: Gunter Grau <[email protected]>
There is the possibility that a new level triggered interrupt is already waiting when
__ipipe_end_level_irq()is called. In this case at the moment when the irq is unmasked it may already fire and call__ipipe_ack_level_irq()before the masked state is cleared in the irq description. If this happensmask_irq()called by__ipipe_ack_level_irq()will not mask the interrupt and the system my stall.
To prevent this, the masked state will now be cleared before unmasking the interrupt. A following direct interrupt handler call will then correctly mask the hardware interrupt as needed.Signed-off-by Gunter Grau <[email protected]>--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/irq/chip.c index renamed from kernel/irq/chip.c +0
-0
6a883a4cee87..25d0942b592a100644kernel/irq/chip.c void __ipipe_ack_level_irq(struct irq_desc · line 1055
Quoted 9 lines
kernel/irq/chip.c +1
-1@@ -1048,8 +1048,8 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { - desc->irq_data.chip->irq_unmask (&desc->irq_data);irq_state_clr_masked (desc); + desc->irq_data.chip->irq_unmask (&desc->irq_data); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc)OK, but if we need this ordering here, why didn't we need it before for
unmask_irq()? There, it was sufficient so far to disable local irqs around unmask + clr.Jan
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Interesting, I thought the disabling of the local irqs is exact the reason why
it works in contrast to
__ipipe_end_level_irq()without disabling.Quoted 1 line
So did I miss something? Should I add a local disable here, too?
That's not yet what I suggest. I just first of all try to understand the boundary conditions for the issue here and if those may apply
elsewhere.
Quoted 10 lines
Quoted 8 lines
If I look at the caller of
ipipe_end_irqin Xenomai, none should have hard irqs on when invoking this. And that means, when local irq disabling is not sufficient,unmasq_irqmay have the same issue you are trying to fix here by reordering.Jan
I tried to follow my issue by dumping the stacktrace in
__ipipe_end_level_irq(). Kernel is still 5.4:Quoted 2 lines
[ 34.590806] [<8010f314>] (unwind_backtrace) from [<8010b824>](
show_stack+0x10/0x14)Quoted 1 line
[ 34.598601] [<8010b824>] (show_stack) from [<8084724c>](
dump_stack+0xd8/0xf4)Quoted 1 line
[ 34.605877] [<8084724c>] (dump_stack) from [<8017c160>](
__ipipe_end_level_irq+0x20/0x30)Quoted 1 line
[ 34.618312] [<8017c160>] (__ipipe_end_level_irq) from [<80177f90>](irq_finalize_oneshot.part.1+0x78/0xf8)
Quoted 1 line
[ 34.628031] [<80177f90>] (irq_finalize_oneshot.part.1) from [<80178080>](
irq_thread_fn+0x70/0x78)Quoted 1 line
[ 34.637044] [<80178080>] (irq_thread_fn) from [<80177e44>](
irq_thread+0x170/0x244)Quoted 1 line
[ 34.646751] [<80177e44>] (irq_thread) from [<80148fa8>](
kthread+0x14c/0x150)Quoted 1 line
[ 34.654879] [<80148fa8>] (kthread) from [<80101118>](
ret_from_fork+0x18/0x24)Quoted 2 lines
I also thought the irqs are always off here. But I cannot explain the current
issue otherwise.
Quoted 9 lines
In that path, hard-IRQs are NOT off in fact. I only checked the Xenomai code paths but forgot about the kernel ones.
But even if we disable hard-IRQs here as well, that would only protect us if that physical interrupt can only be raised on the local CPU. I don't think we can blindly rely on such an assumption (except for percpu irqs).
Jan
[Grau, Gunter]
Hi,
So there is an explanation why the reordering is working. Using unmask_irq() would not be enough. At least on arm32 the interrupts are usually routed to cpu0 if you don't change the affinity settings and mostly also the irq thread keeps that cpu. So that would explain why unmask_irq() also worked for me. So is the suggested patch acceptable or do we need a solution where the two operations are really atomic? Is there an issue hidden in unmask_irq() where ipipe is using hard_cond_local_irq_save()?
Regards,
Gunter
Quoted 3 lines
--
Siemens AG, Technology
Competence Center Embedded Linux
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interrupt
In reply to Jan KiszkaHi all,
Quoted 88 lines · Jan Kiszka
Quoted 85 lines · Gunter
Quoted 66 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Subject: Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interruptQuoted 51 lines · Gunter
Hi,
Quoted 49 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Montag, 15. August 2022 13:56
To: Grau, Gunter <[email protected]>; [email protected]
Subject: Re: [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interruptCaution: This e-mail originated from outside of Philips, be careful for phishing.
Quoted 23 lines · Gunter Grau
From: Gunter Grau <[email protected]>
There is the possibility that a new level triggered interrupt is already waiting when
__ipipe_end_level_irq()is called. In this case at the moment when the irq is unmasked it may already fire and call__ipipe_ack_level_irq()before the masked state is cleared in the irq description. If this happensmask_irq()called by__ipipe_ack_level_irq()will not mask the interrupt and the system my stall.
To prevent this, the masked state will now be cleared before unmasking the interrupt. A following direct interrupt handler call will then correctly mask the hardware interrupt as needed.Signed-off-by Gunter Grau <[email protected]>--- kernel/irq/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/irq/chip.c index renamed from kernel/irq/chip.c +0
-0
6a883a4cee87..25d0942b592a100644kernel/irq/chip.c void __ipipe_ack_level_irq(struct irq_desc · line 1055
Quoted 9 lines
kernel/irq/chip.c +1
-1@@ -1048,8 +1048,8 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { - desc->irq_data.chip->irq_unmask (&desc->irq_data);irq_state_clr_masked (desc); + desc->irq_data.chip->irq_unmask (&desc->irq_data); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc)OK, but if we need this ordering here, why didn't we need it before for
unmask_irq()? There, it was sufficient so far to disable local irqs around unmask + clr.Quoted 3 lines
Quoted 1 line
Jan
Interesting, I thought the disabling of the local irqs is exact the reason why
it works in contrast to
__ipipe_end_level_irq()without disabling.Quoted 1 line
So did I miss something? Should I add a local disable here, too?
That's not yet what I suggest. I just first of all try to understand the boundary conditions for the issue here and if those may apply elsewhere.
Quoted 7 lines
If I look at the caller of
ipipe_end_irqin Xenomai, none should have hard irqs on when invoking this. And that means, when local irq disabling is not sufficient,unmasq_irqmay have the same issue you are trying to fix here by reordering.Jan
I tried to follow my issue by dumping the stacktrace in
__ipipe_end_level_irq(). Kernel is still 5.4:[ 34.590806] [<8010f314>] (unwind_backtrace) from [<8010b824>] (show_stack+0x10/0x14) [ 34.598601] [<8010b824>] (show_stack) from [<8084724c>] (dump_stack+0xd8/0xf4) [ 34.605877] [<8084724c>] (dump_stack) from [<8017c160>] (__ipipe_end_level_irq+0x20/0x30) [ 34.618312] [<8017c160>] (__ipipe_end_level_irq) from [<80177f90>] (irq_finalize_oneshot.part.1+0x78/0xf8) [ 34.628031] [<80177f90>] (irq_finalize_oneshot.part.1) from [<80178080>] (irq_thread_fn+0x70/0x78) [ 34.637044] [<80178080>] (irq_thread_fn) from [<80177e44>] (irq_thread+0x170/0x244) [ 34.646751] [<80177e44>] (irq_thread) from [<80148fa8>] (kthread+0x14c/0x150) [ 34.654879] [<80148fa8>] (kthread) from [<80101118>] (ret_from_fork+0x18/0x24)Quoted 1 line
I also thought the irqs are always off here. But I cannot explain the current issue otherwise.
Quoted 7 lines
In that path, hard-IRQs are NOT off in fact. I only checked the Xenomai code paths but forgot about the kernel ones.
But even if we disable hard-IRQs here as well, that would only protect us if that physical interrupt can only be raised on the local CPU. I don't think we can blindly rely on such an assumption (except for percpu irqs).
While trying to update our CI images to latest Debian testing/bookworm and with that updating from gcc 10 to gcc 12 I ran into a similar problem.
The problem seems to be limited to the arm64 ipipe-4.19-cip for now, but that might be due to limited testing / small race windows.
With ipipe 4.19-cip "as is" I run into a kernel stack overflow. Logs can be found at [1] for example. Searching for "handle_arch_irq_pipelined" brings up the interesting stuff.
I tried:
- Applied the proposal from Gunter, moving the irq_state_clr_masked(desc) call in __ipipe_end_level_irq() in front of the desc->irq_data.chip->irq_unmask(&desc->irq_data) call.
No success. No stack overflow anymore, but system hang.
- Removed the recently added irq_state_clr_masked(desc) call in __ipipe_end_level_irq(). No success. No stack overflow anymore, but system hang.
- Moved to unmask_irq(). I ended up in the kernel stack overflow
again [2].
I can't reproduce with qemu and I don't have a board at hand. The only thing I can do is triggering CI jobs which have long round trip times, so debugging isn't really possible. If you have ideas, let me know. I will do my best to help.
[1] https://lava.xenomai.org/scheduler/job/5069
[2] https://lava.xenomai.org/scheduler/job/5199
Florian
Quoted 3 lines
Jan
Re: [PATCH] ipipe: Fix ipipe level irq end
In reply to Gunter GrauQuoted 5 lines · Gunter Grau via Xenomai
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in
mask_irq():
bf22ff45bed6("genirq: Avoid unnecessary low level irq function calls")
Quoted 11 lines
This means if the flag is not serviced correctly
the real bit in the hardware interrupt controller may not be cleared or set.
The__ipipe_end_level_irq()function does not follow this rule. It unmasks the bit in the hardware without setting the cached flags accordingly. So after the first level interrupt is finished the mask cache has a wrong state. If now the next interrupt fires, themask_irq()function will not really mask the interrupt in the hardware which causes a interrupt storm after reenabeling the hard irqs.
The fix now also updates the shadow flag correctly.
Missed that your "signed-of-by" was not here. Mind to follow up to confirm
https://developercertificate.org/
? A reply with that line would suffice (need to fix up the patch anyway, wrong send address).
Thanks,
Jan
Quoted 18 lines
--- kernel/irq/chip.c | 1 + 1 file changed, 1 insertion(+)kernel/irq/chip.c +1
-1@@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { desc->irq_data.chip->irq_unmask (&desc->irq_data); +irq_state_clr_masked (desc); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc) --2.25.1
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Re: [PATCH] ipipe: Fix ipipe level irq end
Quoted 18 lines · Jan Kiszka via Xenomai
Quoted 5 lines · Gunter Grau via Xenomai
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in
mask_irq():
bf22ff45bed6("genirq: Avoid unnecessary low level irq function calls")Quoted 11 lines
This means if the flag is not serviced correctly
the real bit in the hardware interrupt controller may not be cleared or set.
The__ipipe_end_level_irq()function does not follow this rule. It unmasks the bit in the hardware without setting the cached flags accordingly. So after the first level interrupt is finished the mask cache has a wrong state. If now the next interrupt fires, themask_irq()function will not really mask the interrupt in the hardware which causes a interrupt storm after reenabeling the hard irqs.
The fix now also updates the shadow flag correctly.
Quoted 2 lines
Missed that your "signed-of-by" was not here. Mind to follow up to confirm
Quoted 26 lines
https://developercertificate.org/
? A reply with that line would suffice (need to fix up the patch anyway, wrong send address).
Thanks,
JanQuoted 18 lines
--- kernel/irq/chip.c | 1 + 1 file changed, 1 insertion(+)kernel/irq/chip.c +1
-1@@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { desc->irq_data.chip->irq_unmask (&desc->irq_data); +irq_state_clr_masked (desc); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc) --2.25.1
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
PATCH 1/1 ipipe: Fix ipipe level irq end
The following commit in the vanilla kernel introduced a check for the cached interrupt mask flag in mask_irq():
bf22ff45bed6 ("genirq: Avoid unnecessary low level irq function calls")
This means if the flag is not serviced correctly
the real bit in the hardware interrupt controller may not be cleared or set.
The __ipipe_end_level_irq() function does not follow this rule. It unmasks the bit in the hardware without setting the cached flags accordingly. So after the first level interrupt is finished the mask cache has a wrong state. If now the next interrupt fires, the mask_irq() function will not really mask the interrupt in the hardware which causes a interrupt storm after reenabeling the hard irqs.
The fix now also updates the shadow flag correctly.
--- kernel/irq/chip.c | 1 + 1 file changed, 1 insertion(+)
kernel/irq/chip.c +1 -0
@@ -988,6 +988,7 @@ void __ipipe_ack_level_irq(struct irq_desc *desc)void __ipipe_end_level_irq (struct irq_desc *desc) { desc->irq_data.chip->irq_unmask (&desc->irq_data); +irq_state_clr_masked (desc); }void __ipipe_ack_fasteoi_irq (struct irq_desc *desc)
--
2.25.1
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
Quoted 22 lines · Gunter Grau via Xenomai
Hi,
during our development on imx6 with kernel 5.4 and Xenomai 3.1 we discovered complete system stalls when using phylib with phy irqs level triggerd. This irq is connected on the imx-gpio.
Investigation showed that it seems to be an issue in the ipipe irq end function for level interrupts. Please review the patch proposal. I am not sure if just calling
unmask_irq()is ok here since this functin also does some locking. The other way would be to just call additionally theirq_state_clr_masked(desc)in the level end function itself.The patch applies on ipipe/master in ipipe-arm.
It looks like this is an issue in all ipipe patches, but is triggered by the introduction of a check inunmask_irq().Thanks in advance,
Gunter Grau
Quoted 9 lines
________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
I’ll integrate and test this patch out over the weekend, I can’t say off the top of my head what is the better solution. I’ll have feedback in a few days.
Thanks for the patch :)
Greg