From dbf9a090ba3df0df10971d29f47b080a44cf8178 Mon Sep 17 00:00:00 2001 From: Andrii Sultanov Date: Thu, 22 Oct 2026 10:40:06 +0200 Subject: [PATCH] tools/ocaml: implement stub_xc_domain_create() for ARM stub_xc_domain_create() fails unconditionally with "Unhandled: ARM" for the ARM variant of arch_domainconfig, so no OCaml toolstack (e.g. xenopsd) can create an ARM domain. To fix this, convert the two fields of xen_arm_arch_domainconfig, gic_version and nr_spis, into the corresponding fields of struct xen_arch_domainconfig and reject values that do not fit, as is already done for other parameters. The remaining fields (sve_vl, tee_type, arm_sci_type and v8r_el1_msa) aren't exposed to OCaml yet, so they stay zero. Also add a BUILD_BUG_ON() on the size of the createdomain struct, just like the x86 case, to catch future ABI changes. Signed-off-by: Andrii Sultanov Signed-off-by: Julian Vetter Reviewed-by: Andrew Cooper --- tools/ocaml/libs/xc/xenctrl_stubs.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c index 180f2fbf45..c15a3428da 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -257,8 +257,34 @@ CAMLprim value stub_xc_domain_create(value xch_val, value wanted_domid, value co arch_domconfig = Field(VAL_ARCH, 0); switch ( Tag_val(VAL_ARCH) ) { - case 0: /* ARM - nothing to do */ + case 0: /* ARM */ +#if defined(__arm__) || defined(__aarch64__) + { + /* Quick & dirty check for ABI changes. */ + BUILD_BUG_ON(sizeof(cfg) != 72); + + /* Mnemonics for the named fields inside xen_arm_arch_domainconfig */ +#define VAL_GIC_VERSION Field(arch_domconfig, 0) +#define VAL_NR_SPIS Field(arch_domconfig, 1) + + uint8_t gic_version = Long_val(VAL_GIC_VERSION); + uint32_t nr_spis = Long_val(VAL_NR_SPIS); + + if ( gic_version != Long_val(VAL_GIC_VERSION) ) + caml_invalid_argument("gic_version"); + + if ( nr_spis != Long_val(VAL_NR_SPIS) ) + caml_invalid_argument("nr_spis"); + + cfg.arch.gic_version = gic_version; + cfg.arch.nr_spis = nr_spis; + +#undef VAL_NR_SPIS +#undef VAL_GIC_VERSION + } +#else caml_failwith("Unhandled: ARM"); +#endif break; case 1: /* X86 - emulation flags in the block */