Skip to contentSkip to conversation

PM: runtime: Unify error handling during suspend and resume

PATCH Superseded Rafael J. Wysocki 3 participants 6 messages Feb 20, 2025 – Feb 24, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM: runtime: Unify error handling during suspend and resume

From: Rafael J. Wysocki <[email protected]>

There is a confusing difference in error handling between rpm_suspend() and rpm_resume() related to the special way in which the -EAGAIN and -EBUSY error values are treated by the former. Also, converting -EACCES coming from the callback to an I/O error, which it quite likely is not, may confuse runtime PM users a bit.

To address the above, modify rpm_callback() to convert -EACCES coming from the driver to -EAGAIN and to set power.runtime_error only if the return value is not -EAGAIN or -EBUSY.

This will cause the error handling in rpm_resume() and rpm_suspend() to work consistently, so drop the no longer needed -EAGAIN or -EBUSY special case from the latter and make it retry autosuspend if power.runtime_error is unset.

---
 drivers/base/power/runtime.c |   34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
drivers/base/power/runtime.c +18 -16
@@ -448,8 +448,13 @@
 		retval = __rpm_callback(cb, dev);
 	}
 
-	dev->power.runtime_error = retval;
-	return retval != -EACCES ? retval : -EIO;
+	if (retval == -EACCES)
+		retval = -EAGAIN;
+
+	if (retval != -EAGAIN && retval != -EBUSY)
+		dev->power.runtime_error = retval;
+
+	return retval;
 }
 
 /**
@@ -725,21 +730,18 @@
 	dev->power.deferred_resume = false;
 	wake_up_all(&dev->power.wait_queue);
 
-	if (retval == -EAGAIN || retval == -EBUSY) {
-		dev->power.runtime_error = 0;
+	/*
+	 * On transient errors, if the callback routine failed an autosuspend,
+	 * and if the last_busy time has been updated so that there is a new
+	 * autosuspend expiration time, automatically reschedule another
+	 * autosuspend.
+	 */
+	if (!dev->power.runtime_error && (rpmflags & RPM_AUTO) &&
+	    pm_runtime_autosuspend_expiration(dev) != 0)
+		goto repeat;
+
+	pm_runtime_cancel_pending(dev);
 
-		/*
-		 * If the callback routine failed an autosuspend, and
-		 * if the last_busy time has been updated so that there
-		 * is a new autosuspend expiration time, automatically
-		 * reschedule another autosuspend.
-		 */
-		if ((rpmflags & RPM_AUTO) &&
-		    pm_runtime_autosuspend_expiration(dev) != 0)
-			goto repeat;
-	} else {
-		pm_runtime_cancel_pending(dev);
-	}
 	goto out;
 }
 
#1 lore raw
Quoted 26 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

There is a confusing difference in error handling between rpm_suspend() and rpm_resume() related to the special way in which the -EAGAIN and

(quoted diff) +0 -2
-EBUSY error values are treated by the former.  Also, converting
-EACCES coming from the callback to an I/O error, which it quite likely

is not, may confuse runtime PM users a bit.

To address the above, modify rpm_callback() to convert -EACCES coming from the driver to -EAGAIN and to set power.runtime_error only if the return value is not -EAGAIN or -EBUSY.

This will cause the error handling in rpm_resume() and rpm_suspend() to work consistently, so drop the no longer needed -EAGAIN or -EBUSY special case from the latter and make it retry autosuspend if power.runtime_error is unset.

---
 drivers/base/power/runtime.c |   34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

drivers/base/power/runtime.c line 452

Quoted 7 lines
drivers/base/power/runtime.c +2 -2
@@ -448,8 +448,13 @@
 		retval = __rpm_callback(cb, dev);
 	}
 
-	dev->power.runtime_error = retval;
-	return retval != -EACCES ? retval : -EIO;
+	if (retval == -EACCES)
+		retval = -EAGAIN;

While this is one way to address the problem, are we opening the door to changing error codes when convenient? This might lead to different kind of confusion from user standpoint.

Raag

#2 lore raw
Quoted 31 lines · Raag Jadav
Quoted 29 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

There is a confusing difference in error handling between rpm_suspend() and rpm_resume() related to the special way in which the -EAGAIN and

(quoted diff) +0 -2
-EBUSY error values are treated by the former.  Also, converting
-EACCES coming from the callback to an I/O error, which it quite likely

is not, may confuse runtime PM users a bit.

To address the above, modify rpm_callback() to convert -EACCES coming from the driver to -EAGAIN and to set power.runtime_error only if the return value is not -EAGAIN or -EBUSY.

This will cause the error handling in rpm_resume() and rpm_suspend() to work consistently, so drop the no longer needed -EAGAIN or -EBUSY special case from the latter and make it retry autosuspend if power.runtime_error is unset.

---
 drivers/base/power/runtime.c |   34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
drivers/base/power/runtime.c +0 -0
@@ -448,8 +448,13 @@
              retval = __rpm_callback(cb, dev);
      }
 
Quoted 8 lines

drivers/base/power/runtime.c line 452

Quoted 4 lines
drivers/base/power/runtime.c +2 -2
-     dev->power.runtime_error = retval;
-     return retval != -EACCES ? retval : -EIO;
+     if (retval == -EACCES)
+             retval = -EAGAIN;

While this is one way to address the problem, are we opening the door to changing error codes when convenient? This might lead to different kind of confusion from user standpoint.

Are you saying that if a mistake was made sufficiently long ago, it can't be fixed any more because someone may be confused?

In that case, I'd like to know who may be confused and why.

Thanks!

#3 lore raw
Quoted 41 lines · Rafael J. Wysocki
Quoted 31 lines · Raag Jadav
Quoted 29 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

There is a confusing difference in error handling between rpm_suspend() and rpm_resume() related to the special way in which the -EAGAIN and

(quoted diff) +0 -2
-EBUSY error values are treated by the former.  Also, converting
-EACCES coming from the callback to an I/O error, which it quite likely

is not, may confuse runtime PM users a bit.

To address the above, modify rpm_callback() to convert -EACCES coming from the driver to -EAGAIN and to set power.runtime_error only if the return value is not -EAGAIN or -EBUSY.

This will cause the error handling in rpm_resume() and rpm_suspend() to work consistently, so drop the no longer needed -EAGAIN or -EBUSY special case from the latter and make it retry autosuspend if power.runtime_error is unset.

---
 drivers/base/power/runtime.c |   34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
drivers/base/power/runtime.c +0 -0
@@ -448,8 +448,13 @@
              retval = __rpm_callback(cb, dev);
      }
 
Quoted 8 lines

drivers/base/power/runtime.c line 452

Quoted 4 lines
drivers/base/power/runtime.c +2 -2
-     dev->power.runtime_error = retval;
-     return retval != -EACCES ? retval : -EIO;
+     if (retval == -EACCES)
+             retval = -EAGAIN;

While this is one way to address the problem, are we opening the door to changing error codes when convenient? This might lead to different kind of confusion from user standpoint.

Quoted 2 lines

Are you saying that if a mistake was made sufficiently long ago, it can't be fixed any more because someone may be confused?

Nothing against the fix but "sufficiently long ago" is why we might have users that rely on it. As long as we don't break anything I don't see a problem.

Messing with error codes is usually received with mixed feelings and coming across such a code raises more questions than answers. Perhaps a small explanation might do the trick?

Raag

#4 lore raw
Quoted 46 lines · Raag Jadav
Quoted 41 lines · Rafael J. Wysocki
Quoted 31 lines · Raag Jadav
Quoted 29 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

There is a confusing difference in error handling between rpm_suspend() and rpm_resume() related to the special way in which the -EAGAIN and

(quoted diff) +0 -2
-EBUSY error values are treated by the former.  Also, converting
-EACCES coming from the callback to an I/O error, which it quite likely

is not, may confuse runtime PM users a bit.

To address the above, modify rpm_callback() to convert -EACCES coming from the driver to -EAGAIN and to set power.runtime_error only if the return value is not -EAGAIN or -EBUSY.

This will cause the error handling in rpm_resume() and rpm_suspend() to work consistently, so drop the no longer needed -EAGAIN or -EBUSY special case from the latter and make it retry autosuspend if power.runtime_error is unset.

---
 drivers/base/power/runtime.c |   34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
drivers/base/power/runtime.c +0 -0
@@ -448,8 +448,13 @@
              retval = __rpm_callback(cb, dev);
      }
 
Quoted 8 lines

drivers/base/power/runtime.c line 452

Quoted 4 lines
drivers/base/power/runtime.c +2 -2
-     dev->power.runtime_error = retval;
-     return retval != -EACCES ? retval : -EIO;
+     if (retval == -EACCES)
+             retval = -EAGAIN;

While this is one way to address the problem, are we opening the door to changing error codes when convenient? This might lead to different kind of confusion from user standpoint.

Quoted 2 lines

Are you saying that if a mistake was made sufficiently long ago, it can't be fixed any more because someone may be confused?

Quoted 7 lines

Nothing against the fix but "sufficiently long ago" is why we might have users that rely on it. As long as we don't break anything I don't see a problem.

Messing with error codes is usually received with mixed feelings and coming across such a code raises more questions than answers. Perhaps a small explanation might do the trick?

Do you mean an explanation why -EACCES needs to be converted to something else?

That's because -EACCES has a special meaning in runtime PM: it means that runtime PM is disabled for the given device.

Thanks!

#5 lore raw
Quoted 51 lines · Rafael J. Wysocki
Quoted 50 lines · Raag Jadav
Quoted 41 lines · Rafael J. Wysocki
Quoted 31 lines · Raag Jadav
Quoted 29 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

There is a confusing difference in error handling between rpm_suspend() and rpm_resume() related to the special way in which the -EAGAIN and

(quoted diff) +0 -2
-EBUSY error values are treated by the former.  Also, converting
-EACCES coming from the callback to an I/O error, which it quite likely

is not, may confuse runtime PM users a bit.

To address the above, modify rpm_callback() to convert -EACCES coming from the driver to -EAGAIN and to set power.runtime_error only if the return value is not -EAGAIN or -EBUSY.

This will cause the error handling in rpm_resume() and rpm_suspend() to work consistently, so drop the no longer needed -EAGAIN or -EBUSY special case from the latter and make it retry autosuspend if power.runtime_error is unset.

---
 drivers/base/power/runtime.c |   34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
drivers/base/power/runtime.c +0 -0
@@ -448,8 +448,13 @@
              retval = __rpm_callback(cb, dev);
      }
 
Quoted 8 lines

drivers/base/power/runtime.c line 452

Quoted 4 lines
drivers/base/power/runtime.c +2 -2
-     dev->power.runtime_error = retval;
-     return retval != -EACCES ? retval : -EIO;
+     if (retval == -EACCES)
+             retval = -EAGAIN;

While this is one way to address the problem, are we opening the door to changing error codes when convenient? This might lead to different kind of confusion from user standpoint.

Quoted 2 lines

Are you saying that if a mistake was made sufficiently long ago, it can't be fixed any more because someone may be confused?

Nothing against the fix but "sufficiently long ago" is why we might have users that rely on it. As long as we don't break anything I don't see a problem.

Quoted 8 lines
Quoted 3 lines

Messing with error codes is usually received with mixed feelings and coming across such a code raises more questions than answers. Perhaps a small explanation might do the trick?

Do you mean an explanation why -EACCES needs to be converted to something else?

That's because -EACCES has a special meaning in runtime PM: it means that runtime PM is disabled for the given device.

I meant a small comment above for those who may not see it as an obvious thing, but whatever you think is best.

Raag