Skip to contentSkip to conversation

x86/domctl: Improve XEN_DOMCTL_hypercall_init error handling

PATCH Superseded Andrew Cooper 3 participants 7 messages Mar 11, 2015 – Mar 13, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/domctl: Improve XEN_DOMCTL_hypercall_init error handling

EACCES cannot be distinguished against an incorrect DOMCTL_INTERFACE_VERSION, and will cause an incorrect "need to rebuild the user-space tool set?" message from libxc. EINVAL is a perfectly reasonable alternative.

On the libxc side, put the useful piece of information in the error message, rathe than the -1 from do_domctl().

CC Jan Beulich <[email protected]>
CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
CC Wei Liu <[email protected]>
---
 tools/libxc/xc_dom_boot.c |    6 +++---
 xen/arch/x86/domctl.c     |    4 +---
 2 files changed, 4 insertions(+), 6 deletions(-)
tools/libxc/xc_dom_boot.c +3 -3
index a141eb5..f82db2d 100644
@@ -57,9 +57,9 @@ static int setup_hypercall_page(struct xc_dom_image *dom)
     domctl.u.hypercall_init.gmfn = xc_dom_p2m_guest(dom, pfn);
     rc = do_domctl(dom->xch, &domctl);
     if ( rc != 0 )
-        xc_dom_panic(dom->xch,
-                     XC_INTERNAL_ERROR, "%s: HYPERCALL_INIT failed (rc=%d)",
-                     __FUNCTION__, rc);
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: HYPERCALL_INIT failed: %d - %s)",
+                     __FUNCTION__, errno, strerror(errno));
     return rc;
 }
 
xen/arch/x86/domctl.c +1 -3
index 3e5bef1..3ffb083 100644
@@ -386,16 +386,14 @@ long arch_do_domctl(
 
         page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);
 
-        ret = -EACCES;
         if ( !page || !get_page_type(page, PGT_writable_page) )
         {
+            ret = -EINVAL;
             if ( page )
                 put_page(page);
             break;
         }
 
-        ret = 0;
-
         hypercall_page = __map_domain_page(page);
         hypercall_page_initialise(d, hypercall_page);
         unmap_domain_page(hypercall_page);
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 11.03.15 at 13:56, <[email protected]> wrote:

EACCES cannot be distinguished against an incorrect DOMCTL_INTERFACE_VERSION, and will cause an incorrect "need to rebuild the user-space tool set?" message
from libxc. EINVAL is a perfectly reasonable alternative.

I'm okay with this for the !page case, but I think -EPERM or some such would be better suited when the page is non-writable but otherwise valid.

Jan

#2 lore raw

PATCH v2 1/6 tools/libxl: Introduce min and max macros

This is the same set used by libxc.

---
v2: Don't use reserved identifiers in min_t/max_t

---
 tools/libxl/libxl_internal.h |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
tools/libxl/libxl_internal.h +16 -0
index 934465a..fcbec7f 100644
@@ -108,6 +108,22 @@
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 
+#define min(X, Y) ({                             \
+            const typeof (X) _x = (X);           \
+            const typeof (Y) _y = (Y);           \
+            (void) (&_x == &_y);                 \
+            (_x < _y) ? _x : _y; })
+#define max(X, Y) ({                             \
+            const typeof (X) _x = (X);           \
+            const typeof (Y) _y = (Y);           \
+            (void) (&_x == &_y);                 \
+            (_x > _y) ? _x : _y; })
+
+#define min_t(type, x, y)                                               \
+    ({ const type _x = (x); const type _y = (y); _x < _y ? _x: _y; })
+#define max_t(type, x, y)                                               \
+    ({ const type _x = (x); const type _y = (y); _x > _y ? _x: _y; })
+
 #define LIBXL__LOGGING_ENABLED
 
 #ifdef LIBXL__LOGGING_ENABLED
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH v2 1/6] tools/libxl: Introduce min and max macros

Quoted 2 lines · Andrew Cooper

This is the same set used by libxc.

Please ignore this - I had an accident with git-send-email.

~Andrew

#4 lore raw

PATCH v2 1/1 x86/domctl: Improve XEN_DOMCTL_hypercall_init error handling

In reply to Jan Beulich

EACCES cannot be distinguished against an incorrect DOMCTL_INTERFACE_VERSION, and will cause an incorrect "need to rebuild the user-space tool set?" message from libxc.

On the libxc side, put the useful piece of information in the error message, rathe than the -1 from do_domctl().

CC Jan Beulich <[email protected]>
CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
CC Wei Liu <[email protected]>

---
v2: Split error between "no such frame" and "bad type"

---
 tools/libxc/xc_dom_boot.c |    6 +++---
 xen/arch/x86/domctl.c     |    8 +++++---
 2 files changed, 8 insertions(+), 6 deletions(-)
tools/libxc/xc_dom_boot.c +3 -3
index a141eb5..f82db2d 100644
@@ -57,9 +57,9 @@ static int setup_hypercall_page(struct xc_dom_image *dom)
     domctl.u.hypercall_init.gmfn = xc_dom_p2m_guest(dom, pfn);
     rc = do_domctl(dom->xch, &domctl);
     if ( rc != 0 )
-        xc_dom_panic(dom->xch,
-                     XC_INTERNAL_ERROR, "%s: HYPERCALL_INIT failed (rc=%d)",
-                     __FUNCTION__, rc);
+        xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+                     "%s: HYPERCALL_INIT failed: %d - %s)",
+                     __FUNCTION__, errno, strerror(errno));
     return rc;
 }
 
xen/arch/x86/domctl.c +5 -3
index 3e5bef1..d4f6ccf 100644
@@ -386,16 +386,18 @@ long arch_do_domctl(
 
         page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);
 
-        ret = -EACCES;
         if ( !page || !get_page_type(page, PGT_writable_page) )
         {
             if ( page )
+            {
+                ret = -EPERM;
                 put_page(page);
+            }
+            else
+                ret = -EINVAL;
             break;
         }
 
-        ret = 0;
-
         hypercall_page = __map_domain_page(page);
         hypercall_page_initialise(d, hypercall_page);
         unmap_domain_page(hypercall_page);
Signature · 1 line
1.7.10.4
Reviewed-by on v2 1/1
#5 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 12.03.15 at 12:03, <[email protected]> wrote:

EACCES cannot be distinguished against an incorrect DOMCTL_INTERFACE_VERSION, and will cause an incorrect "need to rebuild the user-space tool set?" message
from libxc.

On the libxc side, put the useful piece of information in the error message, rathe than the -1 from do_domctl().

Acked-by on v2 1/1
#6 lore raw
In reply to Andrew Cooper
Quoted 4 lines · Andrew Cooper

EACCES cannot be distinguished against an incorrect DOMCTL_INTERFACE_VERSION, and will cause an incorrect "need to rebuild the user-space tool set?" message from libxc.

Quoted 9 lines

On the libxc side, put the useful piece of information in the error message, rathe than the -1 from do_domctl().

CC Jan Beulich <[email protected]>
CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
CC Wei Liu <[email protected]>