All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: "Grau, Gunter" <gunter.grau@philips.com>,
	"xenomai@lists.linux.dev" <xenomai@lists.linux.dev>
Subject: Re: [PATCH] ipipe: Fix ipipe level irq end
Date: Mon, 15 Aug 2022 09:19:29 +0300	[thread overview]
Message-ID: <86ca964e-62d8-2bc9-80f9-97097f1dedc7@siemens.com> (raw)
In-Reply-To: <AM7P122MB022912B3CD5B49D168974AD7F2649@AM7P122MB0229.EURP122.PROD.OUTLOOK.COM>

On 11.08.22 16:05, Grau, Gunter wrote:
> 
> Hi,
> 
> Unfortunately I have to come back to this.
> 
> On Thu, Feb 17, 2022 at 10:12 AM Jan Kiszka <mailto:jan.kiszka@siemens.com> wrote:
> On 17.02.22 15:11, Greg Gallagher wrote:
>>
>>
>> On Thu, Feb 17, 2022 at 4:15 AM Jan Kiszka <mailto:jan.kiszka@siemens.com
>> <mailto:mailto:jan.kiszka@siemens.com>> 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)
>>     >  {
>>     >         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?

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

-- 
Siemens AG, Technology
Competence Center Embedded Linux

  reply	other threads:[~2022-08-15  6:19 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-10 15:33 Issue with linux threaded level triggered interrupts Gunter Grau
2022-02-10 15:33 ` [PATCH] ipipe: Fix ipipe level irq end Gunter Grau
2022-02-10 15:37   ` Greg Gallagher
2022-02-10 15:53   ` Jan Kiszka
2022-02-16 21:03   ` Jan Kiszka
2022-02-17  8:48     ` Gunter Grau
2022-02-17  9:15       ` Jan Kiszka
2022-02-17 12:16         ` Grau, Gunter
2022-02-17 12:36           ` Jan Kiszka
2022-02-17 14:11         ` Greg Gallagher
2022-02-17 15:12           ` Jan Kiszka
2022-02-17 15:13             ` Greg Gallagher
2022-08-11 13:05               ` Grau, Gunter
2022-08-15  6:19                 ` Jan Kiszka [this message]
2022-08-15  9:13                   ` Grau, Gunter
2022-08-15  9:34                     ` Philippe Gerum
2022-08-15 10:27                     ` [[I-PIPE PATCH]] ipipe: noarch: Fix ipipe level end interrupt Gunter Grau
2022-08-15 11:56                       ` Jan Kiszka
2022-08-15 12:31                         ` Grau, Gunter
2022-08-15 13:54                           ` Jan Kiszka
2022-08-15 15:24                             ` Grau, Gunter
2022-08-16  6:23                               ` Jan Kiszka
2022-08-17 16:09                                 ` Grau, Gunter
2022-09-02  7:48                                 ` Bezdeka, Florian
2022-02-17 14:05       ` [PATCH] ipipe: Fix ipipe level irq end Jan Kiszka
2022-02-17 14:08         ` Jan Kiszka
2022-02-17 14:12           ` Gunter Grau
2022-02-10 15:39 ` Issue with linux threaded level triggered interrupts Greg Gallagher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86ca964e-62d8-2bc9-80f9-97097f1dedc7@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=gunter.grau@philips.com \
    --cc=xenomai@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.