Skip to contentSkip to conversation

public/domctl: Fix the struct xen_domctl ABI in 32bit builds

PATCH In review Andrew Cooper 3 participants 3 messages Jul 28, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 public/domctl: Fix the struct xen_domctl ABI in 32bit builds

The Xen domctl ABI currently relies on the union containing a field with alignment of 8.

32bit projects which only copy the used subset of functionality end up with an ABI breakage if they don't have at least one uint64_aligned_t field copied.

Insert explicit padding, and some build assertions to ensure it never changes moving forwards.

---
CC: George Dunlap <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>

Further proof that C isn't an appropriate way to desribe an ABI...

---
 xen/common/domctl.c         | 8 ++++++++
 xen/include/public/domctl.h | 1 +
 2 files changed, 9 insertions(+)
xen/common/domctl.c +8 -0
index a69b3b59a8..20ef8399bd 100644
@@ -959,6 +959,14 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     return ret;
 }
 
+static void __init __maybe_unused build_assertions(void)
+{
+    struct xen_domctl d;
+
+    BUILD_BUG_ON(sizeof(d) != 16 /* header */ + 128 /* union */);
+    BUILD_BUG_ON(offsetof(typeof(d), u) != 16);
+}
+
 /*
  * Local variables:
  * mode: C
xen/include/public/domctl.h +1 -0
index 59bdc28c89..9464a9058a 100644
@@ -1222,6 +1222,7 @@ struct xen_domctl {
 #define XEN_DOMCTL_gdbsx_domstatus             1003
     uint32_t interface_version; /* XEN_DOMCTL_INTERFACE_VERSION */
     domid_t  domain;
+    uint16_t _pad[3];
     union {
         struct xen_domctl_createdomain      createdomain;
         struct xen_domctl_getdomaininfo     getdomaininfo;
Signature · 1 line
2.11.0
Acked-by on v1 1/1
#1 lore raw

Hi Andrew,

Quoted 10 lines · Andrew Cooper

The Xen domctl ABI currently relies on the union containing a field with alignment of 8.

32bit projects which only copy the used subset of functionality end up with an ABI breakage if they don't have at least one uint64_aligned_t field copied.

Insert explicit padding, and some build assertions to ensure it never changes moving forwards.

Cheers,

Signature · 1 line
Julien Grall
#2 lore raw
In reply to Andrew Cooper
Quoted 5 lines · Andrew Cooper

The Xen domctl ABI currently relies on the union containing a field with alignment of 8.

32bit projects which only copy the used subset of functionality end up with an ABI breakage if they don't have at least one uint64_aligned_t field copied.

I'm entirely find with the change, but I'm struggling with this justification:
How can _any_ change to the header in our tree help people using custom derivations (i.e. including those defining only some of the union members)?

Quoted 1 line

Further proof that C isn't an appropriate way to desribe an ABI...

Further proof that it requires more careful writing in C to serve as an ABI description, I would say.

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 964

Quoted 9 lines
xen/common/domctl.c +3 -0
@@ -959,6 +959,14 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
      return ret;
  }
 
+static void __init __maybe_unused build_assertions(void)
+{
+    struct xen_domctl d;

Doesn't this also need __maybe_unused? Afaik ...

xen/common/domctl.c long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) · line 968

Quoted 3 lines
xen/common/domctl.c +3 -0
+    BUILD_BUG_ON(sizeof(d) != 16 /* header */ + 128 /* union */);
+    BUILD_BUG_ON(offsetof(typeof(d), u) != 16);
+}

... neither sizeof() nor typeof() count as actual uses.

Jan