Skip to contentSkip to conversation

RAMBlock: use return value of ram_block_discard_require() as errno

PATCH In review Zhenzhong Duan 3 participants 3 messages Jul 16, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RAMBlock: use return value of ram_block_discard_require() as errno

When ram_block_discard_require() fails, errno is passed to error_setg_errno(). It's a stale value or 0 which is unrelated to ram_block_discard_require().

As ram_block_discard_require() already returns -EBUSY in failure case, use it as errno for error_setg_errno().

Fixes 852f0048f3ea ("make guest_memfd require uncoordinated discard")
---
 system/physmem.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
system/physmem.c +5 -2
index 2154432cb6..9a3b3a7636 100644
@@ -1845,11 +1845,14 @@ static void ram_block_add(RAMBlock *new_block, Error **errp)
     }
 
     if (new_block->flags & RAM_GUEST_MEMFD) {
+        int ret;
+
         assert(kvm_enabled());
         assert(new_block->guest_memfd < 0);
 
-        if (ram_block_discard_require(true) < 0) {
-            error_setg_errno(errp, errno,
+        ret = ram_block_discard_require(true);
+        if (ret < 0) {
+            error_setg_errno(errp, -ret,
                              "cannot set up private guest memory: discard currently blocked");
             error_append_hint(errp, "Are you using assigned devices?\n");
             goto out_free;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Zhenzhong Duan

When ram_block_discard_require() fails, errno is passed to error_setg_errno(). It's a stale value or 0 which is unrelated to ram_block_discard_require().

As ram_block_discard_require() already returns -EBUSY in failure case, use it as errno for error_setg_errno().

Fixes 852f0048f3ea ("make guest_memfd require uncoordinated discard")
---
  system/physmem.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)

and queued, thanks.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Zhenzhong Duan
Quoted 23 lines · Zhenzhong Duan

When ram_block_discard_require() fails, errno is passed to error_setg_errno(). It's a stale value or 0 which is unrelated to ram_block_discard_require().

As ram_block_discard_require() already returns -EBUSY in failure case, use it as errno for error_setg_errno().

Fixes 852f0048f3ea ("make guest_memfd require uncoordinated discard")
---
  system/physmem.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
system/physmem.c +2 -0
index 2154432cb6..9a3b3a7636 100644
@@ -1845,11 +1845,14 @@ static void ram_block_add(RAMBlock *new_block, Error **errp)
      }
 
      if (new_block->flags & RAM_GUEST_MEMFD) {
+        int ret;
+
          assert(kvm_enabled());

system/physmem.c static void ram_block_add(RAMBlock *new_block, Error **errp) · line 1858

Quoted 10 lines
system/physmem.c +3 -2
          assert(new_block->guest_memfd < 0);
 
-        if (ram_block_discard_require(true) < 0) {
-            error_setg_errno(errp, errno,
+        ret = ram_block_discard_require(true);
+        if (ret < 0) {
+            error_setg_errno(errp, -ret,
                               "cannot set up private guest memory: discard currently blocked");
              error_append_hint(errp, "Are you using assigned devices?\n");
              goto out_free;
Signature · 3 lines
Cheers,

David / dhildenb