qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RAMBlock: use return value of ram_block_discard_require() as errno
@ 2024-07-16  6:42 Zhenzhong Duan
  2024-07-16  8:54 ` Philippe Mathieu-Daudé
  2024-07-16  9:50 ` David Hildenbrand
  0 siblings, 2 replies; 3+ messages in thread
From: Zhenzhong Duan @ 2024-07-16  6:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: chao.p.peng, Zhenzhong Duan, Paolo Bonzini, Peter Xu,
	David Hildenbrand, Philippe Mathieu-Daudé

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")
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 system/physmem.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/system/physmem.c b/system/physmem.c
index 2154432cb6..9a3b3a7636 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-16  9:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-16  6:42 [PATCH] RAMBlock: use return value of ram_block_discard_require() as errno Zhenzhong Duan
2024-07-16  8:54 ` Philippe Mathieu-Daudé
2024-07-16  9:50 ` David Hildenbrand

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).