Skip to contentSkip to conversation

xen: Log errno rather than return value

PATCH In review Ross Lagerwall 3 participants 4 messages Oct 11, 2017 – Oct 12, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: Log errno rather than return value

xen_modified_memory() sets errno to communicate what went wrong so log this rather than the return value which is not interesting.

---
 hw/i386/xen/xen-hvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/xen/xen-hvm.c +1 -1
index d9ccd5d..8028bed 100644
@@ -1446,7 +1446,7 @@ void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length)
         if (rc) {
             fprintf(stderr,
                     "%s failed for "RAM_ADDR_FMT" ("RAM_ADDR_FMT"): %i, %s\n",
-                    __func__, start, nb_pages, rc, strerror(-rc));
+                    __func__, start, nb_pages, errno, strerror(errno));
         }
     }
 }
Signature · 1 line
2.9.5
Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · Ross Lagerwall

xen_modified_memory() sets errno to communicate what went wrong so log this rather than the return value which is not interesting.

---
 hw/i386/xen/xen-hvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/xen/xen-hvm.c +0 -0
index d9ccd5d..8028bed 100644

hw/i386/xen/xen-hvm.c void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length) · line 1452

Quoted 8 lines
hw/i386/xen/xen-hvm.c +1 -1
@@ -1446,7 +1446,7 @@ void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length)
         if (rc) {
             fprintf(stderr,
                     "%s failed for "RAM_ADDR_FMT" ("RAM_ADDR_FMT"): %i, %s\n",
-                    __func__, start, nb_pages, rc, strerror(-rc));
+                    __func__, start, nb_pages, errno, strerror(errno));
         }
     }
 }

There is already a patch, not applied yet for it,
https://lists.nongnu.org/archive/html/qemu-devel/2017-09/msg07541.html
with the only difference is printing the value of rc and not errno (both patch user errno for strerror).

I guess this patch is better, so

Thanks,

Signature · 1 line
Anthony PERARD
#2 lore raw
In reply to Ross Lagerwall
Quoted 23 lines

-----Original Message-----
From: Qemu-devel [mailto:qemu-devel- [email protected]] On Behalf Of Ross Lagerwall
Sent: 11 October 2017 16:52
To: [email protected]
Cc: Anthony Perard <[email protected]>; Ross Lagerwall <[email protected]>; Stefano Stabellini <[email protected]>
Subject: [Qemu-devel] [PATCH] xen: Log errno rather than return value

xen_modified_memory() sets errno to communicate what went wrong so log
this rather than the return value which is not interesting.

---
 hw/i386/xen/xen-hvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/xen/xen-hvm.c +0 -0
index d9ccd5d..8028bed 100644

hw/i386/xen/xen-hvm.c void xen_hvm_modified_memory(ram_addr_t · line 1450

Quoted 6 lines
hw/i386/xen/xen-hvm.c +1 -1
@@ -1446,7 +1446,7 @@ void xen_hvm_modified_memory(ram_addr_t
 start, ram_addr_t length)
         if (rc) {
             fprintf(stderr,
                     "%s failed for "RAM_ADDR_FMT" ("RAM_ADDR_FMT"): %i, %s\n",
-                    __func__, start, nb_pages, rc, strerror(-rc));
+                    __func__, start, nb_pages, errno, strerror(errno));

I think this is actually a deeper problem. If QEMU is using compat code, which one way or another will go via xencall, then xen_modified_memory() will return a hypercall errno. However, if it goes via libxendevicemodel and an up-to-date privcmd, then it will return -1 and errno will be set. Thus I think the correct fix is not this patch, but a fix in xen_modified_memory() to return -errno and a fix in libxendevicemodel and the compat code in libxencntrl to behave consistently. It's all rather horrible.

Paul

Quoted 6 lines
hw/i386/xen/xen-hvm.c +0 -0
         }
     }

}
--
2.9.5

#3 lore raw
Quoted 38 lines

-----Original Message-----
From: Qemu-devel [mailto:qemu-devel- [email protected]] On Behalf Of Paul Durrant
Sent: 12 October 2017 10:47
To: Ross Lagerwall <[email protected]>; [email protected]
Cc: Anthony Perard <[email protected]>; Ross Lagerwall <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [Qemu-devel] [PATCH] xen: Log errno rather than return value

Quoted 3 lines

-----Original Message-----
From: Qemu-devel [mailto:qemu-devel- [email protected]] On Behalf Of Ross

Lagerwall

Quoted 20 lines

Sent: 11 October 2017 16:52
To: [email protected]
Cc: Anthony Perard <[email protected]>; Ross Lagerwall <[email protected]>; Stefano Stabellini <[email protected]>
Subject: [Qemu-devel] [PATCH] xen: Log errno rather than return value

xen_modified_memory() sets errno to communicate what went wrong so log
this rather than the return value which is not interesting.

---
 hw/i386/xen/xen-hvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/xen/xen-hvm.c +0 -0
index d9ccd5d..8028bed 100644

hw/i386/xen/xen-hvm.c void xen_hvm_modified_memory(ram_addr_t · line 1449

Quoted 4 lines
hw/i386/xen/xen-hvm.c +0 -0
@@ -1446,7 +1446,7 @@ void xen_hvm_modified_memory(ram_addr_t
 start, ram_addr_t length)
         if (rc) {
             fprintf(stderr,
                     "%s failed for "RAM_ADDR_FMT" ("RAM_ADDR_FMT"): %i,

%s\n",

Quoted 6 lines

hw/i386/xen/xen-hvm.c void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length) · line 1449

Quoted 2 lines
hw/i386/xen/xen-hvm.c +1 -1
-                    __func__, start, nb_pages, rc, strerror(-rc));
+                    __func__, start, nb_pages, errno, strerror(errno));

I think this is actually a deeper problem. If QEMU is using compat code, which one way or another will go via xencall, then xen_modified_memory() will return a hypercall errno.

Having waded through the code now it turns out that (for linux at least) xencall returns the value returned from the underlying ioctl() call so it will actually return -1 with errno set correctly, so the above statement is incorrect. Thus there is no inconsistency and the patch DTRT.

Sorry for the noise.

Paul

Quoted 15 lines

However, if it goes via libxendevicemodel and an
up-to-date privcmd, then it will return -1 and errno will be set. Thus I think the correct fix is not this patch, but a fix in xen_modified_memory() to return -errno and a fix in libxendevicemodel and the compat code in libxencntrl to behave consistently. It's all rather horrible.

Paul

Quoted 6 lines
hw/i386/xen/xen-hvm.c +0 -0
         }
     }

}
--
2.9.5