Skip to contentSkip to conversation

backends/cryptodev: Do not ignore throttle/backends Errors

PATCH Superseded Philippe Mathieu-Daudé 5 participants 5 messages Nov 20, 2023 – Jan 18, 2024

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 backends/cryptodev: Do not ignore throttle/backends Errors

Both cryptodev_backend_set_throttle() and CryptoDevBackendClass::init() can set their Error** argument. Do not ignore them, return early on failure. Use the ERRP_GUARD() macro as suggested in commit ae7c80a7bd ("error: New macro ERRP_GUARD()").

Fixes e7a775fd9f ("cryptodev: Account statistics")
Fixes 2580b452ff ("cryptodev: support QoS")
---
 backends/cryptodev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
backends/cryptodev.c +10 -0
index e5006bd215..fff89fd62a 100644
@@ -398,6 +398,7 @@ static void cryptodev_backend_set_ops(Object *obj, Visitor *v,
 static void
 cryptodev_backend_complete(UserCreatable *uc, Error **errp)
 {
+    ERRP_GUARD();
     CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc);
     CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc);
     uint32_t services;
@@ -406,11 +407,20 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp)
     QTAILQ_INIT(&backend->opinfos);
     value = backend->tc.buckets[THROTTLE_OPS_TOTAL].avg;
     cryptodev_backend_set_throttle(backend, THROTTLE_OPS_TOTAL, value, errp);
+    if (*errp) {
+        return;
+    }
     value = backend->tc.buckets[THROTTLE_BPS_TOTAL].avg;
     cryptodev_backend_set_throttle(backend, THROTTLE_BPS_TOTAL, value, errp);
+    if (*errp) {
+        return;
+    }
 
     if (bc->init) {
         bc->init(backend, errp);
+        if (*errp) {
+            return;
+        }
     }
 
     services = backend->conf.crypto_services;
Signature · 1 line
2.41.0
Reviewed-by on v2 1/1
#1 lore raw

Looks good to me. Thanks!

Quoted 46 lines · Philippe Mathieu-Daudé

Both cryptodev_backend_set_throttle() and CryptoDevBackendClass::init() can set their Error** argument. Do not ignore them, return early on failure. Use the ERRP_GUARD() macro as suggested in commit ae7c80a7bd ("error: New macro ERRP_GUARD()").

Fixes e7a775fd9f ("cryptodev: Account statistics")
Fixes 2580b452ff ("cryptodev: support QoS")
---
  backends/cryptodev.c | 10 ++++++++++
  1 file changed, 10 insertions(+)
backends/cryptodev.c +10 -0
index e5006bd215..fff89fd62a 100644
@@ -398,6 +398,7 @@ static void cryptodev_backend_set_ops(Object *obj, Visitor *v,
  static void
  cryptodev_backend_complete(UserCreatable *uc, Error **errp)
  {
+    ERRP_GUARD();
      CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc);
      CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc);
      uint32_t services;
@@ -406,11 +407,20 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp)
      QTAILQ_INIT(&backend->opinfos);
      value = backend->tc.buckets[THROTTLE_OPS_TOTAL].avg;
      cryptodev_backend_set_throttle(backend, THROTTLE_OPS_TOTAL, value, errp);
+    if (*errp) {
+        return;
+    }
      value = backend->tc.buckets[THROTTLE_BPS_TOTAL].avg;
      cryptodev_backend_set_throttle(backend, THROTTLE_BPS_TOTAL, value, errp);
+    if (*errp) {
+        return;
+    }
 
      if (bc->init) {
          bc->init(backend, errp);
+        if (*errp) {
+            return;
+        }
      }
 
      services = backend->conf.crypto_services;
Signature · 1 line
zhenwei pi
Reviewed-by Gonglei on v2 1/1
#2 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 18 lines

-----Original Message-----
From: Philippe Mathieu-Daudé [mailto:[email protected]]
Sent: Monday, November 20, 2023 11:04 PM
To: [email protected]
Cc: Zhenwei Pi <[email protected]>; Gonglei (Arei) <[email protected]>; Markus Armbruster <[email protected]>; Daniel P . Berrangé <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; [email protected]
Subject: [PATCH-for-8.2 v2] backends/cryptodev: Do not ignore throttle/backends Errors

Both cryptodev_backend_set_throttle() and CryptoDevBackendClass::init() can set their Error** argument. Do not ignore them, return early on failure. Use the ERRP_GUARD() macro as suggested in commit ae7c80a7bd ("error: New macro ERRP_GUARD()").

Quoted 5 lines
Fixes e7a775fd9f ("cryptodev: Account statistics")
Fixes 2580b452ff ("cryptodev: support QoS")

---

Regards,
-Gonglei

Reviewed-by on v2 1/1
#3 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 3 lines · Philippe Mathieu-Daudé

Both cryptodev_backend_set_throttle() and CryptoDevBackendClass::init() can set their Error** argument. Do not ignore them, return early on failure.

Let's mention why we need to: "Without that, running into another failure trips error_setv()'s assertion."

Quoted 34 lines

Use the ERRP_GUARD() macro as suggested in commit ae7c80a7bd
("error: New macro ERRP_GUARD()").

Fixes e7a775fd9f ("cryptodev: Account statistics")
Fixes 2580b452ff ("cryptodev: support QoS")
---
 backends/cryptodev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
backends/cryptodev.c +6 -0
index e5006bd215..fff89fd62a 100644
@@ -398,6 +398,7 @@ static void cryptodev_backend_set_ops(Object *obj, Visitor *v,
 static void
 cryptodev_backend_complete(UserCreatable *uc, Error **errp)
 {
+    ERRP_GUARD();
     CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc);
     CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc);
     uint32_t services;
@@ -406,11 +407,20 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp)
     QTAILQ_INIT(&backend->opinfos);
     value = backend->tc.buckets[THROTTLE_OPS_TOTAL].avg;
     cryptodev_backend_set_throttle(backend, THROTTLE_OPS_TOTAL, value, errp);
+    if (*errp) {
+        return;
+    }
     value = backend->tc.buckets[THROTTLE_BPS_TOTAL].avg;
     cryptodev_backend_set_throttle(backend, THROTTLE_BPS_TOTAL, value, errp);
+    if (*errp) {
+        return;

backends/cryptodev.c cryptodev_backend_complete(UserCreatable *uc, Error **errp) · line 426

Quoted 10 lines
backends/cryptodev.c +4 -0
+    }
 
     if (bc->init) {
         bc->init(backend, errp);
+        if (*errp) {
+            return;
+        }
     }
 
     services = backend->conf.crypto_services;

Preferably with the commit message improved:

#4 lore raw
In reply to Philippe Mathieu-Daudé

20.11.2023 18:04, Philippe Mathieu-Daudé:

Quoted 9 lines

Both cryptodev_backend_set_throttle() and CryptoDevBackendClass::init() can set their Error** argument. Do not ignore them, return early on failure. Use the ERRP_GUARD() macro as suggested in commit ae7c80a7bd ("error: New macro ERRP_GUARD()").

Fixes e7a775fd9f ("cryptodev: Account statistics")
Fixes 2580b452ff ("cryptodev: support QoS")

Ping?
Can we get this to master before Jan-27? :)
It's been reviewed by a few people already.

Thanks,

/mjt