Skip to contentSkip to conversation

hvmloader: Use xen/errno.h rather than the host systems errno.h

PATCH In review Andrew Cooper 2 participants 4 messages Feb 19, 2016 – Feb 22, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hvmloader: Use xen/errno.h rather than the host systems errno.h

hvmloader is unhosted, and shouldn't use the system errno.h. It already has to use Xen's errno.h for other hypercalls.

---
CC: Jan Beulich <[email protected]>
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Doug Goldstein <[email protected]>

v2: Fix compilation. I am not sure how v1 compiled, but I did definitely check it before posting.

Furthermore, this patch provies that attempting to combine two header files from the Xen public interface is an utter disaster...

---
 tools/firmware/hvmloader/util.h   | 15 +++++++++++++++
 tools/firmware/hvmloader/vnuma.c  |  3 +--
 tools/firmware/hvmloader/xenbus.c |  1 -
 3 files changed, 16 insertions(+), 3 deletions(-)
tools/firmware/hvmloader/util.h +15 -0
index 132d915..052de1a 100644
@@ -9,6 +9,21 @@
 #include <xen/hvm/hvm_info_table.h>
 #include "e820.h"
 
+/* Persuade errno.h to give us some un-prefixed values. */
+#define __XEN_PUBLIC_ERRNO_H__
+#define XEN_ERRNO(name, value) name = value,
+enum {
+#include <xen/errno.h>
+};
+
+/* Cause xs_wire.h to give us xsd_errors[]. */
+#define EINVAL EINVAL
+
+/* Fill in errno values needed by xs_wire.h, missing from errno.h. */
+#define EISDIR    21
+#define EROFS     30
+#define ENOTEMPTY 39
+
 #define __STR(...) #__VA_ARGS__
 #define STR(...) __STR(__VA_ARGS__)
 
tools/firmware/hvmloader/vnuma.c +1 -2
index 4121cc6..85c1a79 100644
@@ -28,7 +28,6 @@
 #include "util.h"
 #include "hypercall.h"
 #include "vnuma.h"
-#include <xen/errno.h>
 
 unsigned int nr_vnodes, nr_vmemranges;
 unsigned int *vcpu_to_vnode, *vdistance;
@@ -40,7 +39,7 @@ void init_vnuma_info(void)
     struct xen_vnuma_topology_info vnuma_topo = { .domid = DOMID_SELF };
 
     rc = hypercall_memory_op(XENMEM_get_vnumainfo, &vnuma_topo);
-    if ( rc != -XEN_ENOBUFS )
+    if ( rc != -ENOBUFS )
         return;
 
     ASSERT(vnuma_topo.nr_vcpus == hvm_info->nr_vcpus);
tools/firmware/hvmloader/xenbus.c +0 -1
index d0ed993..448157d 100644
@@ -27,7 +27,6 @@
 
 #include "util.h"
 #include "hypercall.h"
-#include <errno.h>
 #include <xen/sched.h>
 #include <xen/event_channel.h>
 #include <xen/hvm/params.h>
Signature · 1 line
2.1.4
#1 lore raw

tools/firmware/hvmloader/util.h line 13

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 19.02.16 at 19:59, <[email protected]> wrote:
tools/firmware/hvmloader/util.h +2 -0
@@ -9,6 +9,21 @@
 #include <xen/hvm/hvm_info_table.h>
 #include "e820.h"
 
+/* Persuade errno.h to give us some un-prefixed values. */
+#define __XEN_PUBLIC_ERRNO_H__

That's ugly. You would probably better include it the "normal" way once (giving you the XEN_* values), and then a second time ...

tools/firmware/hvmloader/util.h line 17

Quoted 4 lines
tools/firmware/hvmloader/util.h +4 -0
+#define XEN_ERRNO(name, value) name = value,
+enum {
+#include <xen/errno.h>
+};

... this way. Albeit ...

tools/firmware/hvmloader/util.h line 25

Quoted 7 lines
tools/firmware/hvmloader/util.h +7 -0
+/* Cause xs_wire.h to give us xsd_errors[]. */
+#define EINVAL EINVAL
+
+/* Fill in errno values needed by xs_wire.h, missing from errno.h. */
+#define EISDIR    21
+#define EROFS     30
+#define ENOTEMPTY 39

... hmm, I don't think xs_wire.h means to use XEN errno values, which the reference to these three seems to support. Instead I'm afraid this is a third number space, established for the communication with xenstore, which itself doesn't use Xen's errno.h either. There should be XSD_E* values getting defined in xs_wire.h (or a newly introduced helper header).

Quoted 11 lines
tools/firmware/hvmloader/vnuma.c +0 -1
@@ -28,7 +28,6 @@
 #include "util.h"
 #include "hypercall.h"
 #include "vnuma.h"
-#include <xen/errno.h>
 
 unsigned int nr_vnodes, nr_vmemranges;
 unsigned int *vcpu_to_vnode, *vdistance;

tools/firmware/hvmloader/vnuma.c void init_vnuma_info(void) · line 42

Quoted 5 lines
tools/firmware/hvmloader/vnuma.c +1 -1
@@ -40,7 +39,7 @@ void init_vnuma_info(void)
     struct xen_vnuma_topology_info vnuma_topo = { .domid = DOMID_SELF };
 
     rc = hypercall_memory_op(XENMEM_get_vnumainfo, &vnuma_topo);
-    if ( rc != -XEN_ENOBUFS )
+    if ( rc != -ENOBUFS )

This change would also be unnecessary if you included xen/errno.h the "ordinary" way first above.

Jan

#2 lore raw
Quoted 18 lines · Jan Beulich

tools/firmware/hvmloader/util.h line 13

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 19.02.16 at 19:59, <[email protected]> wrote:
tools/firmware/hvmloader/util.h +2 -0
@@ -9,6 +9,21 @@
 #include <xen/hvm/hvm_info_table.h>
 #include "e820.h"
 
+/* Persuade errno.h to give us some un-prefixed values. */
+#define __XEN_PUBLIC_ERRNO_H__

That's ugly. You would probably better include it the "normal" way once (giving you the XEN_* values), and then a second time ...

tools/firmware/hvmloader/util.h line 17

Quoted 4 lines
tools/firmware/hvmloader/util.h +4 -0
+#define XEN_ERRNO(name, value) name = value,
+enum {
+#include <xen/errno.h>
+};

... this way. Albeit ...

Quoted 13 lines

tools/firmware/hvmloader/util.h line 25

Quoted 7 lines
tools/firmware/hvmloader/util.h +7 -0
+/* Cause xs_wire.h to give us xsd_errors[]. */
+#define EINVAL EINVAL
+
+/* Fill in errno values needed by xs_wire.h, missing from errno.h. */
+#define EISDIR    21
+#define EROFS     30
+#define ENOTEMPTY 39

... hmm, I don't think xs_wire.h means to use XEN errno values, which the reference to these three seems to support. Instead I'm afraid this is a third number space, established for the communication with xenstore, which itself doesn't use Xen's errno.h either. There should be XSD_E* values getting defined in xs_wire.h (or a newly introduced helper header).

The entire point of xsd_errors[] is to turn the errno strings used in the xenstore protocol back into the local representation, whatever that representation is.

HVMLoader already has to use XEN errno values for vnuma. It shouldn't be using two different sources of errno...

Quoted 14 lines
Quoted 14 lines
tools/firmware/hvmloader/vnuma.c +0 -1
@@ -28,7 +28,6 @@
 #include "util.h"
 #include "hypercall.h"
 #include "vnuma.h"
-#include <xen/errno.h>
 
 unsigned int nr_vnodes, nr_vmemranges;
 unsigned int *vcpu_to_vnode, *vdistance;
@@ -40,7 +39,7 @@ void init_vnuma_info(void)
     struct xen_vnuma_topology_info vnuma_topo = { .domid = DOMID_SELF };
 
Quoted 5 lines

tools/firmware/hvmloader/vnuma.c void init_vnuma_info(void) · line 42

Quoted 3 lines
tools/firmware/hvmloader/vnuma.c +1 -1
     rc = hypercall_memory_op(XENMEM_get_vnumainfo, &vnuma_topo);
-    if ( rc != -XEN_ENOBUFS )
+    if ( rc != -ENOBUFS )

This change would also be unnecessary if you included xen/errno.h the "ordinary" way first above.

...or indeed, two different representations of the same errno.

~Andrew

#3 lore raw
Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 22.02.16 at 12:24, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich

tools/firmware/hvmloader/util.h line 13

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 19.02.16 at 19:59, <[email protected]> wrote:
tools/firmware/hvmloader/util.h +2 -0
@@ -9,6 +9,21 @@
 #include <xen/hvm/hvm_info_table.h>
 #include "e820.h"
 
+/* Persuade errno.h to give us some un-prefixed values. */
+#define __XEN_PUBLIC_ERRNO_H__

That's ugly. You would probably better include it the "normal" way once (giving you the XEN_* values), and then a second time ...

tools/firmware/hvmloader/util.h line 17

Quoted 4 lines
tools/firmware/hvmloader/util.h +4 -0
+#define XEN_ERRNO(name, value) name = value,
+enum {
+#include <xen/errno.h>
+};

... this way. Albeit ...

Quoted 13 lines

tools/firmware/hvmloader/util.h line 25

Quoted 7 lines
tools/firmware/hvmloader/util.h +7 -0
+/* Cause xs_wire.h to give us xsd_errors[]. */
+#define EINVAL EINVAL
+
+/* Fill in errno values needed by xs_wire.h, missing from errno.h. */
+#define EISDIR    21
+#define EROFS     30
+#define ENOTEMPTY 39

... hmm, I don't think xs_wire.h means to use XEN errno values, which the reference to these three seems to support. Instead I'm afraid this is a third number space, established for the communication with xenstore, which itself doesn't use Xen's errno.h either. There should be XSD_E* values getting defined in xs_wire.h (or a newly introduced helper header).

Quoted 3 lines

The entire point of xsd_errors[] is to turn the errno strings used in the xenstore protocol back into the local representation, whatever that representation is.

Oh, right.

Quoted 17 lines

HVMLoader already has to use XEN errno values for vnuma. It shouldn't be using two different sources of errno...

Quoted 14 lines
Quoted 14 lines
tools/firmware/hvmloader/vnuma.c +0 -1
@@ -28,7 +28,6 @@
 #include "util.h"
 #include "hypercall.h"
 #include "vnuma.h"
-#include <xen/errno.h>
 
 unsigned int nr_vnodes, nr_vmemranges;
 unsigned int *vcpu_to_vnode, *vdistance;
@@ -40,7 +39,7 @@ void init_vnuma_info(void)
     struct xen_vnuma_topology_info vnuma_topo = { .domid = DOMID_SELF };
 
Quoted 7 lines
Quoted 5 lines

tools/firmware/hvmloader/vnuma.c void init_vnuma_info(void) · line 42

Quoted 3 lines
tools/firmware/hvmloader/vnuma.c +1 -1
     rc = hypercall_memory_op(XENMEM_get_vnumainfo, &vnuma_topo);
-    if ( rc != -XEN_ENOBUFS )
+    if ( rc != -ENOBUFS )

This change would also be unnecessary if you included xen/errno.h the "ordinary" way first above.

...or indeed, two different representations of the same errno.

Okay then. But I'd still prefer to see this

#define __XEN_PUBLIC_ERRNO_H__

gone. Even if you don't mean to use XEN_E* values, there's no harm having them declared.

Jan