tools/ocaml/xc: Fix xc_physinfo() bindings
PATCH v2 1/1 tools/ocaml/xc: Fix xc_physinfo() bindings
The original change doesn't compile on ARM:
xenctrl_stubs.c: In function 'stub_xc_physinfo':
xenctrl_stubs.c:821:16: error: unused variable 'arch_cap_flags_tag' [-Werror=unused-variable]
821 | int r, arch_cap_flags_tag;
| ^~~~~~~~~~~~~~~~~~cc1: all warnings being treated as errors
but it was buggy too.
First, it tried storing an int in a pointer slot, causing heap corruption.
Next, it is not legitimate to exclude arm32 in the toolstack as it explicitly can operate an arm64 toolstack and build arm64 domains. That in turn means that you can't stash a C uint32_t in an OCaml int.
Rewrite the arch_capabilities handling from scratch. Break it out into a separate function, and make the construction of arch_physinfo_cap_flags common to prevent other indirection bugs.
Reintroduce arm_physinfo_caps with the fields broken out.
---
CC: Christian Lindig <[email protected]>
CC: Edwin Török <[email protected]>
CC: Rob Hoes <[email protected]>
CC: Luca Fancellu <[email protected]>
v2:
* CAMLreturn().
Tested on x86 locally. Tested on arm64 with:
https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/4447272476
and a tweaked form of my local ocaml smoke test for these kinds of things:
# osmoke
Xen version: 4.18-unstable
Physinfo:
threads_per_core 1
SVE len: 0
Starting GC.compact()
DoneI didn't get this working for arm32, because that's all Yocto, but the arm64 test is good enough IMO.
--- tools/ocaml/libs/xc/xenctrl.ml | 7 +++- tools/ocaml/libs/xc/xenctrl.mli | 7 +++- tools/ocaml/libs/xc/xenctrl_stubs.c | 52 ++++++++++++++++++++--------- 3 files changed, 48 insertions(+), 18 deletions(-)
tools/ocaml/libs/xc/xenctrl.ml +6 -1
@@ -128,10 +128,15 @@ type physinfo_cap_flag = | CAP_Gnttab_v1 | CAP_Gnttab_v2 +type arm_physinfo_caps = + { + sve_vl: int; + } + type x86_physinfo_cap_flag type arch_physinfo_cap_flags = - | ARM of int + | ARM of arm_physinfo_caps | X86 of x86_physinfo_cap_flag list type physinfo =
tools/ocaml/libs/xc/xenctrl.mli +6 -1
@@ -113,10 +113,15 @@ type physinfo_cap_flag = | CAP_Gnttab_v1 | CAP_Gnttab_v2 +type arm_physinfo_caps = + { + sve_vl: int; + } + type x86_physinfo_cap_flag type arch_physinfo_cap_flags = - | ARM of int + | ARM of arm_physinfo_caps | X86 of x86_physinfo_cap_flag list type physinfo = {
tools/ocaml/libs/xc/xenctrl_stubs.c +36 -16
69 lines not on this page · raw message
Signature · 1 line
2.30.2