Skip to contentSkip to conversation

phy: phy-twl4030-usb: fix denied runtime access

PATCH RESEND Superseded Andreas Kemnade 2 participants 6 messages Sep 17, 2018 – Sep 18, 2018 Generic PHY framework

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 phy: phy-twl4030-usb: fix denied runtime access

When runtime is not enabled, pm_runtime_get_sync() returns -EACCESS, the counter will be incremented but the resume callback not called, so enumeration and charging will not start properly.
To avoid that happen, wait and try again later.

Practically this happens when the device is woken up from suspend by plugging in usb.

---
 drivers/phy/ti/phy-twl4030-usb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/phy/ti/phy-twl4030-usb.c +9 -0
index a44680d64f9b..1f3cf4e48383 100644
@@ -552,6 +552,15 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 
 	status = twl4030_usb_linkstat(twl);
 
+	/* we might get here too early when runtime is not ready yet
+	 * and we will get an EACCESS later, so try again later
+	 */
+	if (!pm_runtime_enabled(twl->dev)) {
+		cancel_delayed_work(&twl->id_workaround_work);
+		schedule_delayed_work(&twl->id_workaround_work, HZ);
+		return IRQ_HANDLED;
+	}
+
 	mutex_lock(&twl->lock);
 	if (status >= 0 && status != twl->linkstat) {
 		status_changed =
Signature · 1 line
2.11.0
#1 lore raw

Hi Andreas,

Quoted 18 lines · Andreas Kemnade

When runtime is not enabled, pm_runtime_get_sync() returns -EACCESS, the counter will be incremented but the resume callback not called, so enumeration and charging will not start properly.
To avoid that happen, wait and try again later.

Practically this happens when the device is woken up from suspend by plugging in usb.

---
 drivers/phy/ti/phy-twl4030-usb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/phy/ti/phy-twl4030-usb.c +0 -0
index a44680d64f9b..1f3cf4e48383 100644

drivers/phy/ti/phy-twl4030-usb.c static irqreturn_t twl4030_usb_irq(int irq, void *_twl) · line 557

Quoted 6 lines
drivers/phy/ti/phy-twl4030-usb.c +3 -0
@@ -552,6 +552,15 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 
 	status = twl4030_usb_linkstat(twl);
 
+	/* we might get here too early when runtime is not ready yet
+	 * and we will get an EACCESS later, so try again later
+	 */

How exactly can this happen? What disables (and later re-enables) runtime PM? How can we guarantee that the interrupt will be re-triggered?

Quoted 12 lines
drivers/phy/ti/phy-twl4030-usb.c +6 -0
+	if (!pm_runtime_enabled(twl->dev)) {
+		cancel_delayed_work(&twl->id_workaround_work);
+		schedule_delayed_work(&twl->id_workaround_work, HZ);
+		return IRQ_HANDLED;
+	}
+
 	mutex_lock(&twl->lock);
 	if (status >= 0 && status != twl->linkstat) {
 		status_changed =
Signature · 1 line
2.11.0

Thanks.

Signature · 1 line
Dmitry
#2 lore raw

Hi Dmitry,

Quoted 22 lines · On Mon, 17 Sep 2018 10:51:31 -0700 Dmitry Torokhov <[email protected]>…

Hi Andreas,

Quoted 19 lines · Andreas Kemnade

When runtime is not enabled, pm_runtime_get_sync() returns -EACCESS, the counter will be incremented but the resume callback not called, so enumeration and charging will not start properly.
To avoid that happen, wait and try again later.

Practically this happens when the device is woken up from suspend by plugging in usb.

---
 drivers/phy/ti/phy-twl4030-usb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/phy/ti/phy-twl4030-usb.c +0 -0
index a44680d64f9b..1f3cf4e48383 100644
@@ -552,6 +552,15 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 
Quoted 8 lines

drivers/phy/ti/phy-twl4030-usb.c static irqreturn_t twl4030_usb_irq(int irq, void *_twl) · line 557

Quoted 5 lines
drivers/phy/ti/phy-twl4030-usb.c +3 -0
 	status = twl4030_usb_linkstat(twl);
 
+	/* we might get here too early when runtime is not ready yet
+	 * and we will get an EACCESS later, so try again later
+	 */  

How exactly can this happen? What disables (and later re-enables) runtime PM?

If the whole resume process is started by plugging in usb, the interrupt will be triggered still in the resume process so that runtime resume is not yet possible, pm_runtime_get_sync() returns EACCESS

Quoted 3 lines

How can we guarantee that the interrupt will be
re-triggered?

The interrupt will not be re-triggered but the handler will be called at some other places...

Quoted 6 lines

drivers/phy/ti/phy-twl4030-usb.c static irqreturn_t twl4030_usb_irq(int irq, void *_twl) · line 563

Quoted 6 lines
drivers/phy/ti/phy-twl4030-usb.c +6 -0
+	if (!pm_runtime_enabled(twl->dev)) {
+		cancel_delayed_work(&twl->id_workaround_work);
+		schedule_delayed_work(&twl->id_workaround_work, HZ);
+		return IRQ_HANDLED;
+	}
+

... for example by this delayed work which is already there.

Regards,
Andreas

#3 lore raw
Quoted 35 lines · Andreas Kemnade

Hi Dmitry,

Quoted 22 lines · On Mon, 17 Sep 2018 10:51:31 -0700 Dmitry Torokhov <[email protected]>…

Hi Andreas,

Quoted 19 lines · Andreas Kemnade

When runtime is not enabled, pm_runtime_get_sync() returns -EACCESS, the counter will be incremented but the resume callback not called, so enumeration and charging will not start properly.
To avoid that happen, wait and try again later.

Practically this happens when the device is woken up from suspend by plugging in usb.

---
 drivers/phy/ti/phy-twl4030-usb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/phy/ti/phy-twl4030-usb.c +0 -0
index a44680d64f9b..1f3cf4e48383 100644
@@ -552,6 +552,15 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 
Quoted 8 lines

drivers/phy/ti/phy-twl4030-usb.c static irqreturn_t twl4030_usb_irq(int irq, void *_twl) · line 557

Quoted 5 lines
drivers/phy/ti/phy-twl4030-usb.c +3 -0
 	status = twl4030_usb_linkstat(twl);
 
+	/* we might get here too early when runtime is not ready yet
+	 * and we will get an EACCESS later, so try again later
+	 */  

How exactly can this happen? What disables (and later re-enables) runtime PM?

Quoted 4 lines

If the whole resume process is started by plugging in usb, the interrupt will be triggered still in the resume process so that runtime resume is not yet possible, pm_runtime_get_sync() returns EACCESS

I see. This all seems a bit wonky, to be honest. I would expect that the driver would have a suspend routine that disables interrupt and also configure interrupt for wakeup (enable_irq_wake) and kick bus scanning from there instead of aborting interrupt handler...

Quoted 7 lines
Quoted 4 lines

How can we guarantee that the interrupt will be
re-triggered?

The interrupt will not be re-triggered but the handler will be called at some other places...

Quoted 7 lines
Quoted 6 lines

drivers/phy/ti/phy-twl4030-usb.c static irqreturn_t twl4030_usb_irq(int irq, void *_twl) · line 563

Quoted 6 lines
drivers/phy/ti/phy-twl4030-usb.c +6 -0
+	if (!pm_runtime_enabled(twl->dev)) {
+		cancel_delayed_work(&twl->id_workaround_work);
+		schedule_delayed_work(&twl->id_workaround_work, HZ);
+		return IRQ_HANDLED;
+	}
+

... for example by this delayed work which is already there.

If we decide to keep this, it should be mod_delayed_work() I think.

Thanks.

Signature · 1 line
Dmitry
#4 lore raw

Hi,

Quoted 41 lines · On Mon, 17 Sep 2018 15:23:45 -0700 Dmitry Torokhov <[email protected]>…
Quoted 35 lines · Andreas Kemnade

Hi Dmitry,

Quoted 22 lines · On Mon, 17 Sep 2018 10:51:31 -0700 Dmitry Torokhov <[email protected]>…

Hi Andreas,

Quoted 19 lines · Andreas Kemnade

When runtime is not enabled, pm_runtime_get_sync() returns -EACCESS, the counter will be incremented but the resume callback not called, so enumeration and charging will not start properly.
To avoid that happen, wait and try again later.

Practically this happens when the device is woken up from suspend by plugging in usb.

---
 drivers/phy/ti/phy-twl4030-usb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/phy/ti/phy-twl4030-usb.c +0 -0
index a44680d64f9b..1f3cf4e48383 100644
@@ -552,6 +552,15 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 
Quoted 8 lines

drivers/phy/ti/phy-twl4030-usb.c static irqreturn_t twl4030_usb_irq(int irq, void *_twl) · line 557

Quoted 5 lines
drivers/phy/ti/phy-twl4030-usb.c +3 -0
 	status = twl4030_usb_linkstat(twl);
 
+	/* we might get here too early when runtime is not ready yet
+	 * and we will get an EACCESS later, so try again later
+	 */    

How exactly can this happen? What disables (and later re-enables) runtime PM?

Quoted 4 lines

If the whole resume process is started by plugging in usb, the interrupt will be triggered still in the resume process so that runtime resume is not yet possible, pm_runtime_get_sync() returns EACCESS

Quoted 5 lines

I see. This all seems a bit wonky, to be honest. I would expect that the driver would have a suspend routine that disables interrupt and also configure interrupt for wakeup (enable_irq_wake) and kick bus scanning from there instead of aborting interrupt handler...

well, that seems doable. So there will be a v2.

Quoted 15 lines
Quoted 7 lines
Quoted 4 lines

How can we guarantee that the interrupt will be
re-triggered?

The interrupt will not be re-triggered but the handler will be called at some other places...

Quoted 7 lines
Quoted 6 lines

drivers/phy/ti/phy-twl4030-usb.c static irqreturn_t twl4030_usb_irq(int irq, void *_twl) · line 563

Quoted 6 lines
drivers/phy/ti/phy-twl4030-usb.c +6 -0
+	if (!pm_runtime_enabled(twl->dev)) {
+		cancel_delayed_work(&twl->id_workaround_work);
+		schedule_delayed_work(&twl->id_workaround_work, HZ);
+		return IRQ_HANDLED;
+	}
+  

... for example by this delayed work which is already there.

Quoted 2 lines

If we decide to keep this, it should be mod_delayed_work() I think.

Well, is that valid for the other uses of id_workaround_work() (which are clearly required)? So there should be a second, independent cleanup patch for the existing uses?

Regards,
Andreas

#5 lore raw
Quoted 68 lines · Andreas Kemnade

Hi,

Quoted 41 lines · On Mon, 17 Sep 2018 15:23:45 -0700 Dmitry Torokhov <[email protected]>…
Quoted 35 lines · Andreas Kemnade

Hi Dmitry,

Quoted 22 lines · On Mon, 17 Sep 2018 10:51:31 -0700 Dmitry Torokhov <[email protected]>…

Hi Andreas,

Quoted 19 lines · Andreas Kemnade

When runtime is not enabled, pm_runtime_get_sync() returns -EACCESS, the counter will be incremented but the resume callback not called, so enumeration and charging will not start properly.
To avoid that happen, wait and try again later.

Practically this happens when the device is woken up from suspend by plugging in usb.

---
 drivers/phy/ti/phy-twl4030-usb.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/phy/ti/phy-twl4030-usb.c +0 -0
index a44680d64f9b..1f3cf4e48383 100644
@@ -552,6 +552,15 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 
Quoted 8 lines

drivers/phy/ti/phy-twl4030-usb.c static irqreturn_t twl4030_usb_irq(int irq, void *_twl) · line 557

Quoted 5 lines
drivers/phy/ti/phy-twl4030-usb.c +3 -0
 	status = twl4030_usb_linkstat(twl);
 
+	/* we might get here too early when runtime is not ready yet
+	 * and we will get an EACCESS later, so try again later
+	 */    

How exactly can this happen? What disables (and later re-enables) runtime PM?

Quoted 4 lines

If the whole resume process is started by plugging in usb, the interrupt will be triggered still in the resume process so that runtime resume is not yet possible, pm_runtime_get_sync() returns EACCESS

Quoted 5 lines

I see. This all seems a bit wonky, to be honest. I would expect that the driver would have a suspend routine that disables interrupt and also configure interrupt for wakeup (enable_irq_wake) and kick bus scanning from there instead of aborting interrupt handler...

well, that seems doable. So there will be a v2.

Quoted 15 lines
Quoted 14 lines
Quoted 4 lines

How can we guarantee that the interrupt will be
re-triggered?

The interrupt will not be re-triggered but the handler will be called at some other places...

Quoted 6 lines

drivers/phy/ti/phy-twl4030-usb.c static irqreturn_t twl4030_usb_irq(int irq, void *_twl) · line 563

Quoted 6 lines
drivers/phy/ti/phy-twl4030-usb.c +6 -0
+	if (!pm_runtime_enabled(twl->dev)) {
+		cancel_delayed_work(&twl->id_workaround_work);
+		schedule_delayed_work(&twl->id_workaround_work, HZ);
+		return IRQ_HANDLED;
+	}
+  

... for example by this delayed work which is already there.

Quoted 5 lines
Quoted 2 lines

If we decide to keep this, it should be mod_delayed_work() I think.

Well, is that valid for the other uses of id_workaround_work() (which are clearly required)? So there should be a second, independent cleanup patch for the existing uses?

Yes, mod_delayed_work() is replacement for cancel + reschedule. I guess this driver was created before mod_delayed_work() was added to the kernel.

Thanks.

Signature · 1 line
Dmitry