From: Petr Cvek <petrcvekcz@gmail.com>
To: Marc Zyngier <marc.zyngier@arm.com>,
hdegoede@redhat.com, tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org, philipp.zabel@gmail.com
Subject: Re: regression in irq sharing caused by genirq: Use irqd_get_trigger_type to compare the trigger type for shared IRQs
Date: Wed, 8 Nov 2017 14:35:47 +0100 [thread overview]
Message-ID: <41355cbe-e27d-2710-9395-a1c765aa8906@gmail.com> (raw)
In-Reply-To: <7a3a89f5-41ea-6c15-72fc-0f62bf748074@arm.com>
Dne 8.11.2017 v 14:11 Marc Zyngier napsal(a):
> On 08/11/17 13:09, Marc Zyngier wrote:
>> On 07/11/17 23:41, Petr Cvek wrote:
>>> Hello,
>>>
>>> Commit 382bd4de61827 ("genirq: Use irqd_get_trigger_type to compare the
>>> trigger type for shared IRQs") causes a regression for pda-power driver
>>> and Magician machine (mach-pxa/magician.c).
>>>
>>> unsigned int oldtype = irqd_get_trigger_type(&desc->irq_data);
>>>
>>> ... assert:
>>> oldtype == 0 //new code
>>> old->flags == 0x83 //old code
>>> new->flags & IRQF_TRIGGER_MASK == 3
>>>
>>> if (!((old->flags & new->flags) & IRQF_SHARED) ||
>>> (oldtype != (new->flags & IRQF_TRIGGER_MASK)) ||
>>> ((old->flags ^ new->flags) & IRQF_ONESHOT))
>>> goto mismatch;
>>>
>>> The assert shows the new code will trigger the jump for "mismatch" error
>>> the old variant of code works fine.
>>>
>>> The case for Magician machine is specific as the same interrupt line is
>>> requested twice from the same driver (pda-power). But it still could
>>> point to some hidden problem in the IRQ setup code.
>>>
>>> I wasn't able to trace the code when desc->irq_data is getting set. The
>>> flags values should be (as with old->flags):
>>>
>>> IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
>>>
>>> It could be a problem with a weird IRQ sharing in magician code, but
>>> it's still failing the driver and the start of the charging system.
>>>
>>> IRQ definition in arch/arm/mach-pxa/magician.c looks like this:
>>>
>>> static struct resource power_supply_resources[] = {
>>> [0] = {
>>> .name = "ac",
>>> .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
>>> IORESOURCE_IRQ_LOWEDGE,
>>> .start = IRQ_MAGICIAN_VBUS,
>>> .end = IRQ_MAGICIAN_VBUS,
>>> },
>>> [1] = {
>>> .name = "usb",
>>> .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
>>> IORESOURCE_IRQ_LOWEDGE,
>>> .start = IRQ_MAGICIAN_VBUS,
>>> .end = IRQ_MAGICIAN_VBUS,
>>> },
>>> };
>>>
>>> and IRQ requests from drivers/power/supply/pda_power.c look like this:
>>>
>>> if (ac_irq) {
>>> ret = request_irq(ac_irq->start, power_changed_isr,
>>> get_irq_flags(ac_irq), ac_irq->name,
>>> pda_psy_ac);
>>> ...
>>> if (usb_irq) {
>>> ret = request_irq(usb_irq->start, power_changed_isr,
>>> get_irq_flags(usb_irq),
>>> usb_irq->name, pda_psy_usb);
>>>
>>> I could rewrite the part in the magician code so it would use only one
>>> interrupt, but it doesn't solve why oldtype == 0 problem.
>>
>> Yeah, this is a pretty ugly corner case that crops up because we more
>> and more assume things like DT, which is going to configure the expected
>> trigger type ahead of the interrupt being requested... Of course, PXA is
>> not converted to DT, and unlikely to ever be.
>>
>> Could you please give the following hack a go and let us know if it
>> solves your problem? If it does, I'll think of a more generic solution.
Hi,
yeah it works now and the assert is oldtype == 3 and old->flags == 3 so
neither versions of condition won't trigger goto mismatch.
>>
>> Thanks,
>>
>> M.
>>
>> diff --git a/drivers/power/supply/pda_power.c b/drivers/power/supply/pda_power.c
>> index 922a86787c5c..a32ae240ef7d 100644
>> --- a/drivers/power/supply/pda_power.c
>> +++ b/drivers/power/supply/pda_power.c
>> @@ -24,7 +24,15 @@
>>
>> static inline unsigned int get_irq_flags(struct resource *res)
>> {
>> - return IRQF_SHARED | (res->flags & IRQF_TRIGGER_MASK);
>> + struct irq_data *d = irq_get_irq_data(res->start);
>> + unsigned int trig = res->flags & IRQF_TRIGGER_MASK;
>> +
>> + BUG_ON(!d);
>> +
>> + if (!irqd_get_trigger_type(d))
>> + irqd_set_trigger_type(trig);
>
> Of course, this should be
>
> irqd_set_trigger_type(d, trig);
>
and (in case anyone other want to try)
#include <linux/irq.h>
>> +
>> + return IRQF_SHARED | trig;
>> }
>>
>> static struct device *dev;
>>
>>
>
> M.
>
cheers,
Petr
next prev parent reply other threads:[~2017-11-08 13:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-07 23:41 regression in irq sharing caused by genirq: Use irqd_get_trigger_type to compare the trigger type for shared IRQs Petr Cvek
2017-11-08 13:09 ` Marc Zyngier
2017-11-08 13:11 ` Marc Zyngier
2017-11-08 13:35 ` Petr Cvek [this message]
2017-11-08 13:55 ` Marc Zyngier
2017-11-09 14:50 ` Marc Zyngier
2017-11-09 16:47 ` Petr Cvek
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=41355cbe-e27d-2710-9395-a1c765aa8906@gmail.com \
--to=petrcvekcz@gmail.com \
--cc=hdegoede@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=philipp.zabel@gmail.com \
--cc=tglx@linutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).