Skip to contentSkip to conversation

tools/ocaml: Fix xenctrl ABI and introduce build-time checks

PATCH Superseded Andrew Cooper 1 participant 2 messages Sep 9, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/ocaml: Fix xenctrl ABI and introduce build-time checks

c/s f089fddd941 broke the Ocaml ABI by renumering XEN_SYSCTL_PHYSCAP_directio without adjusting the Ocaml physinfo_cap_flag enumeration. Fix this by inserting CAP_PV between CAP_HVM and CAP_DirectIO.

c/s 82239182eb3 extended the XEN_SYSCTL_PHYSCAP_* ABI with a HAP bit. Extend the physinfo_cap_flag enumeration to match.

Factor out the bitmap-to-list conversion logic into a helper, to avoid an opencoded truncation of the bitmap. To cover this, add BUILD_BUG_ON()'s at the caller for each constant in the C-to-Ocaml conversion, and for the the applicable max/all constant.

This will result in a compile time failure whenever constants get renumbered/added without a compatible adjustment to the Ocaml ABI.

---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Christian Lindig <[email protected]>
CC: Rob Hoes <[email protected]>

A patch along these lines wants backporting to at least 4.12, but without the HAP constant. I'm happy to do the backport.

---
 tools/ocaml/libs/xc/xenctrl.ml      |  2 +
 tools/ocaml/libs/xc/xenctrl.mli     |  6 ++-
 tools/ocaml/libs/xc/xenctrl_stubs.c | 78 +++++++++++++++++++++++++++----------
 xen/include/public/sysctl.h         |  3 ++
 4 files changed, 68 insertions(+), 21 deletions(-)
tools/ocaml/libs/xc/xenctrl.ml +2 -0
index 35958b94d5..5da7c96cee 100644
@@ -99,7 +99,9 @@ type sched_control =
 
 type physinfo_cap_flag =
 	| CAP_HVM
+	| CAP_PV
 	| CAP_DirectIO
+	| CAP_HAP
 
 type physinfo =
 {
tools/ocaml/libs/xc/xenctrl.mli +5 -1
index 6c4268d453..b4e76b827e 100644
@@ -82,7 +82,11 @@ type domaininfo = {
   arch_config : arch_domainconfig;
 }
 type sched_control = { weight : int; cap : int; }
-type physinfo_cap_flag = CAP_HVM | CAP_DirectIO
+type physinfo_cap_flag =
+  | CAP_HVM
+  | CAP_PV
+  | CAP_DirectIO
+  | CAP_HAP
 type physinfo = {
   threads_per_core : int;
   cores_per_socket : int;
tools/ocaml/libs/xc/xenctrl_stubs.c +58 -20

108 lines not on this page · raw message

xen/include/public/sysctl.h +3 -0
index e02d7ce4c6..d4b455619c 100644
@@ -94,6 +94,9 @@ struct xen_sysctl_tbuf_op {
 #define _XEN_SYSCTL_PHYSCAP_hap          3
 #define XEN_SYSCTL_PHYSCAP_hap           (1u<<_XEN_SYSCTL_PHYSCAP_hap)
 
+/* Max XEN_SYSCTL_PHYSCAP_* constant.  Used for ABI checking. */
+#define XEN_SYSCTL_PHYSCAP_MAX XEN_SYSCTL_PHYSCAP_hap
+
 struct xen_sysctl_physinfo {
     uint32_t threads_per_core;
     uint32_t cores_per_socket;
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 12 lines · Andrew Cooper

c/s f089fddd941 broke the Ocaml ABI by renumering XEN_SYSCTL_PHYSCAP_directio without adjusting the Ocaml physinfo_cap_flag enumeration. Fix this by inserting CAP_PV between CAP_HVM and CAP_DirectIO.

c/s 82239182eb3 extended the XEN_SYSCTL_PHYSCAP_* ABI with a HAP bit. Extend the physinfo_cap_flag enumeration to match.

Factor out the bitmap-to-list conversion logic into a helper, to avoid an opencoded truncation of the bitmap. To cover this, add BUILD_BUG_ON()'s at the caller for each constant in the C-to-Ocaml conversion, and for the the applicable max/all constant.

Quoted 4 lines

This will result in a compile time failure whenever constants get renumbered/added without a compatible adjustment to the Ocaml ABI.

Sorry - please ignore this.  It is based incorrectly WRT Roger's series.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel