* [PATCH net] net: phy: avoid clearing PHY interrupts twice in irq handler
@ 2020-03-01 20:36 Heiner Kallweit
2020-03-01 22:52 ` Michael Walle
2020-03-02 3:05 ` David Miller
0 siblings, 2 replies; 6+ messages in thread
From: Heiner Kallweit @ 2020-03-01 20:36 UTC (permalink / raw)
To: Andrew Lunn, Florian Fainelli, Russell King - ARM Linux, David Miller
Cc: netdev, Michael Walle
On all PHY drivers that implement did_interrupt() reading the interrupt
status bits clears them. This means we may loose an interrupt that
is triggered between calling did_interrupt() and phy_clear_interrupt().
As part of the fix make it a requirement that did_interrupt() clears
the interrupt.
The Fixes tag refers to the first commit where the patch applies
cleanly.
Fixes: 49644e68f472 ("net: phy: add callback for custom interrupt handler to struct phy_driver")
Reported-by: Michael Walle <michael@walle.cc>
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/phy/phy.c | 3 ++-
include/linux/phy.h | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index d76e038cf..16e3fb79e 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -727,7 +727,8 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
phy_trigger_machine(phydev);
}
- if (phy_clear_interrupt(phydev))
+ /* did_interrupt() may have cleared the interrupt already */
+ if (!phydev->drv->did_interrupt && phy_clear_interrupt(phydev))
goto phy_err;
return IRQ_HANDLED;
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 80f8b2158..8b299476b 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -557,6 +557,7 @@ struct phy_driver {
/*
* Checks if the PHY generated an interrupt.
* For multi-PHY devices with shared PHY interrupt pin
+ * Set interrupt bits have to be cleared.
*/
int (*did_interrupt)(struct phy_device *phydev);
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: phy: avoid clearing PHY interrupts twice in irq handler
2020-03-01 20:36 [PATCH net] net: phy: avoid clearing PHY interrupts twice in irq handler Heiner Kallweit
@ 2020-03-01 22:52 ` Michael Walle
2020-03-01 23:20 ` Heiner Kallweit
2020-03-02 3:05 ` David Miller
1 sibling, 1 reply; 6+ messages in thread
From: Michael Walle @ 2020-03-01 22:52 UTC (permalink / raw)
To: Heiner Kallweit
Cc: Andrew Lunn, Florian Fainelli, Russell King - ARM Linux,
David Miller, netdev
Am 2020-03-01 21:36, schrieb Heiner Kallweit:
> On all PHY drivers that implement did_interrupt() reading the interrupt
> status bits clears them. This means we may loose an interrupt that
> is triggered between calling did_interrupt() and phy_clear_interrupt().
> As part of the fix make it a requirement that did_interrupt() clears
> the interrupt.
Looks good. But how would you use did_interrupt() and handle_interrupt()
together? I guess you can't. At least not if handle_interrupt() has
to read the pending bits again. So you'd have to handle custom
interrupts in did_interrupt(). Any idea how to solve that?
[I know, this is only about fixing the lost interrupts.]
-michael
>
> The Fixes tag refers to the first commit where the patch applies
> cleanly.
>
> Fixes: 49644e68f472 ("net: phy: add callback for custom interrupt
> handler to struct phy_driver")
> Reported-by: Michael Walle <michael@walle.cc>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> drivers/net/phy/phy.c | 3 ++-
> include/linux/phy.h | 1 +
> 2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index d76e038cf..16e3fb79e 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -727,7 +727,8 @@ static irqreturn_t phy_interrupt(int irq, void
> *phy_dat)
> phy_trigger_machine(phydev);
> }
>
> - if (phy_clear_interrupt(phydev))
> + /* did_interrupt() may have cleared the interrupt already */
> + if (!phydev->drv->did_interrupt && phy_clear_interrupt(phydev))
> goto phy_err;
> return IRQ_HANDLED;
>
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 80f8b2158..8b299476b 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -557,6 +557,7 @@ struct phy_driver {
> /*
> * Checks if the PHY generated an interrupt.
> * For multi-PHY devices with shared PHY interrupt pin
> + * Set interrupt bits have to be cleared.
> */
> int (*did_interrupt)(struct phy_device *phydev);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: phy: avoid clearing PHY interrupts twice in irq handler
2020-03-01 22:52 ` Michael Walle
@ 2020-03-01 23:20 ` Heiner Kallweit
2020-03-04 12:13 ` Heiner Kallweit
0 siblings, 1 reply; 6+ messages in thread
From: Heiner Kallweit @ 2020-03-01 23:20 UTC (permalink / raw)
To: Michael Walle
Cc: Andrew Lunn, Florian Fainelli, Russell King - ARM Linux,
David Miller, netdev
On 01.03.2020 23:52, Michael Walle wrote:
> Am 2020-03-01 21:36, schrieb Heiner Kallweit:
>> On all PHY drivers that implement did_interrupt() reading the interrupt
>> status bits clears them. This means we may loose an interrupt that
>> is triggered between calling did_interrupt() and phy_clear_interrupt().
>> As part of the fix make it a requirement that did_interrupt() clears
>> the interrupt.
>
> Looks good. But how would you use did_interrupt() and handle_interrupt()
> together? I guess you can't. At least not if handle_interrupt() has
> to read the pending bits again. So you'd have to handle custom
> interrupts in did_interrupt(). Any idea how to solve that?
>
> [I know, this is only about fixing the lost interrupts.]
>
Right, this one is meant for stable to fix the issue with the potentially
lost interrupts. Based on it I will submit a patch for net-next that
tackles the issue that did_interrupt() has to read (and therefore clear)
irq status bits and therefore makes them unusable for handle_interrupt().
The basic idea is that did_interrupt() is called only if handle_interrupt()
isn't implemented. handle_interrupt() has to include the did_interrupt
functionality. It can read the irq status once and store it in a variable
for later use.
> -michael
>
>>
>> The Fixes tag refers to the first commit where the patch applies
>> cleanly.
>>
>> Fixes: 49644e68f472 ("net: phy: add callback for custom interrupt
>> handler to struct phy_driver")
>> Reported-by: Michael Walle <michael@walle.cc>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>> drivers/net/phy/phy.c | 3 ++-
>> include/linux/phy.h | 1 +
>> 2 files changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
>> index d76e038cf..16e3fb79e 100644
>> --- a/drivers/net/phy/phy.c
>> +++ b/drivers/net/phy/phy.c
>> @@ -727,7 +727,8 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
>> phy_trigger_machine(phydev);
>> }
>>
>> - if (phy_clear_interrupt(phydev))
>> + /* did_interrupt() may have cleared the interrupt already */
>> + if (!phydev->drv->did_interrupt && phy_clear_interrupt(phydev))
>> goto phy_err;
>> return IRQ_HANDLED;
>>
>> diff --git a/include/linux/phy.h b/include/linux/phy.h
>> index 80f8b2158..8b299476b 100644
>> --- a/include/linux/phy.h
>> +++ b/include/linux/phy.h
>> @@ -557,6 +557,7 @@ struct phy_driver {
>> /*
>> * Checks if the PHY generated an interrupt.
>> * For multi-PHY devices with shared PHY interrupt pin
>> + * Set interrupt bits have to be cleared.
>> */
>> int (*did_interrupt)(struct phy_device *phydev);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: phy: avoid clearing PHY interrupts twice in irq handler
2020-03-01 23:20 ` Heiner Kallweit
@ 2020-03-04 12:13 ` Heiner Kallweit
2020-03-04 13:02 ` Michael Walle
0 siblings, 1 reply; 6+ messages in thread
From: Heiner Kallweit @ 2020-03-04 12:13 UTC (permalink / raw)
To: Michael Walle
Cc: Andrew Lunn, Florian Fainelli, Russell King - ARM Linux,
David Miller, netdev
On 02.03.2020 00:20, Heiner Kallweit wrote:
> On 01.03.2020 23:52, Michael Walle wrote:
>> Am 2020-03-01 21:36, schrieb Heiner Kallweit:
>>> On all PHY drivers that implement did_interrupt() reading the interrupt
>>> status bits clears them. This means we may loose an interrupt that
>>> is triggered between calling did_interrupt() and phy_clear_interrupt().
>>> As part of the fix make it a requirement that did_interrupt() clears
>>> the interrupt.
>>
>> Looks good. But how would you use did_interrupt() and handle_interrupt()
>> together? I guess you can't. At least not if handle_interrupt() has
>> to read the pending bits again. So you'd have to handle custom
>> interrupts in did_interrupt(). Any idea how to solve that?
>>
>> [I know, this is only about fixing the lost interrupts.]
>>
> Right, this one is meant for stable to fix the issue with the potentially
> lost interrupts. Based on it I will submit a patch for net-next that
> tackles the issue that did_interrupt() has to read (and therefore clear)
> irq status bits and therefore makes them unusable for handle_interrupt().
> The basic idea is that did_interrupt() is called only if handle_interrupt()
> isn't implemented. handle_interrupt() has to include the did_interrupt
> functionality. It can read the irq status once and store it in a variable
> for later use.
>
In case you wait for this patch to base further own work on it:
I'm waiting for next merge of net into net-next, because my patch will
apply cleanly only after that. This merge should happen in the next days.
>> -michael
>>
>>>
>>> The Fixes tag refers to the first commit where the patch applies
>>> cleanly.
>>>
>>> Fixes: 49644e68f472 ("net: phy: add callback for custom interrupt
>>> handler to struct phy_driver")
>>> Reported-by: Michael Walle <michael@walle.cc>
>>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>>> ---
>>> drivers/net/phy/phy.c | 3 ++-
>>> include/linux/phy.h | 1 +
>>> 2 files changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
>>> index d76e038cf..16e3fb79e 100644
>>> --- a/drivers/net/phy/phy.c
>>> +++ b/drivers/net/phy/phy.c
>>> @@ -727,7 +727,8 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
>>> phy_trigger_machine(phydev);
>>> }
>>>
>>> - if (phy_clear_interrupt(phydev))
>>> + /* did_interrupt() may have cleared the interrupt already */
>>> + if (!phydev->drv->did_interrupt && phy_clear_interrupt(phydev))
>>> goto phy_err;
>>> return IRQ_HANDLED;
>>>
>>> diff --git a/include/linux/phy.h b/include/linux/phy.h
>>> index 80f8b2158..8b299476b 100644
>>> --- a/include/linux/phy.h
>>> +++ b/include/linux/phy.h
>>> @@ -557,6 +557,7 @@ struct phy_driver {
>>> /*
>>> * Checks if the PHY generated an interrupt.
>>> * For multi-PHY devices with shared PHY interrupt pin
>>> + * Set interrupt bits have to be cleared.
>>> */
>>> int (*did_interrupt)(struct phy_device *phydev);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: phy: avoid clearing PHY interrupts twice in irq handler
2020-03-04 12:13 ` Heiner Kallweit
@ 2020-03-04 13:02 ` Michael Walle
0 siblings, 0 replies; 6+ messages in thread
From: Michael Walle @ 2020-03-04 13:02 UTC (permalink / raw)
To: Heiner Kallweit
Cc: Andrew Lunn, Florian Fainelli, Russell King - ARM Linux,
David Miller, netdev
Am 2020-03-04 13:13, schrieb Heiner Kallweit:
> On 02.03.2020 00:20, Heiner Kallweit wrote:
>> On 01.03.2020 23:52, Michael Walle wrote:
>>> Am 2020-03-01 21:36, schrieb Heiner Kallweit:
>>>> On all PHY drivers that implement did_interrupt() reading the
>>>> interrupt
>>>> status bits clears them. This means we may loose an interrupt that
>>>> is triggered between calling did_interrupt() and
>>>> phy_clear_interrupt().
>>>> As part of the fix make it a requirement that did_interrupt() clears
>>>> the interrupt.
>>>
>>> Looks good. But how would you use did_interrupt() and
>>> handle_interrupt()
>>> together? I guess you can't. At least not if handle_interrupt() has
>>> to read the pending bits again. So you'd have to handle custom
>>> interrupts in did_interrupt(). Any idea how to solve that?
>>>
>>> [I know, this is only about fixing the lost interrupts.]
>>>
>> Right, this one is meant for stable to fix the issue with the
>> potentially
>> lost interrupts. Based on it I will submit a patch for net-next that
>> tackles the issue that did_interrupt() has to read (and therefore
>> clear)
>> irq status bits and therefore makes them unusable for
>> handle_interrupt().
>> The basic idea is that did_interrupt() is called only if
>> handle_interrupt()
>> isn't implemented. handle_interrupt() has to include the did_interrupt
>> functionality. It can read the irq status once and store it in a
>> variable
>> for later use.
>>
> In case you wait for this patch to base further own work on it:
> I'm waiting for next merge of net into net-next, because my patch will
> apply cleanly only after that. This merge should happen in the next
> days.
Ok, thanks for the information. I have enough other things to do ;)
-michael
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: phy: avoid clearing PHY interrupts twice in irq handler
2020-03-01 20:36 [PATCH net] net: phy: avoid clearing PHY interrupts twice in irq handler Heiner Kallweit
2020-03-01 22:52 ` Michael Walle
@ 2020-03-02 3:05 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2020-03-02 3:05 UTC (permalink / raw)
To: hkallweit1; +Cc: andrew, f.fainelli, linux, netdev, michael
From: Heiner Kallweit <hkallweit1@gmail.com>
Date: Sun, 1 Mar 2020 21:36:09 +0100
> On all PHY drivers that implement did_interrupt() reading the interrupt
> status bits clears them. This means we may loose an interrupt that
> is triggered between calling did_interrupt() and phy_clear_interrupt().
> As part of the fix make it a requirement that did_interrupt() clears
> the interrupt.
>
> The Fixes tag refers to the first commit where the patch applies
> cleanly.
>
> Fixes: 49644e68f472 ("net: phy: add callback for custom interrupt handler to struct phy_driver")
> Reported-by: Michael Walle <michael@walle.cc>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-03-04 13:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-01 20:36 [PATCH net] net: phy: avoid clearing PHY interrupts twice in irq handler Heiner Kallweit
2020-03-01 22:52 ` Michael Walle
2020-03-01 23:20 ` Heiner Kallweit
2020-03-04 12:13 ` Heiner Kallweit
2020-03-04 13:02 ` Michael Walle
2020-03-02 3:05 ` David Miller
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).