system/physmem: 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: 852f0048f3 ("make guest_memfd require uncoordinated discard")
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
Message-ID: <20240716064213.290696-1-zhenzhong.duan@intel.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
Zhenzhong Duan 2024-07-16 14:42:12 +08:00 committed by Philippe Mathieu-Daudé
parent a99dc9cd61
commit 644a52778a

View File

@ -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;