[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] tools/ocaml/xc: Address ABI issues with physinfo arch flags


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Wed, 12 Oct 2022 19:25:52 +0100
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Christian Lindig <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Edwin Torok <edvin.torok@xxxxxxxxxx>, Rob Hoes <Rob.Hoes@xxxxxxxxxx>, Henry Wang <Henry.Wang@xxxxxxx>
  • Delivery-date: Wed, 12 Oct 2022 18:26:26 +0000
  • Ironport-data: A9a23:ILbUX61R0z4PK7LKzvbDix16xbzCYnBdZch4hdh9DyJ0z/GscokSnZKBI4ySk/ScjpLhhS12IhzijssjrW0y4farjUk4fX+vycz0/4boJhEnr1zCI2gG7gzYZWLLPCORpyD9k8JlqGXvc9aH1vMoz8hiHpjUs15WsCX/TMy6HEBfafa+1+CbQpGhXXZnCPipiUYQtFP9HyrjnezApG3JgOzM6rm1rSFyQBbgMd90gmYkf6nft1TSJOM/+uYLf8P/MzntOFiBOdpJkV9GAk8cU1Rg160lknFhwiLghV38brwctft7jkhbmLGOrKfeFE95aSUdZcp+P4yXjfEJBNbqZjD3Wr38ehHUndMDq10ZX7QDVsw0W7NFewUZETuD/It64HTeBhWgE3Fsul9FcLnOBpyQOcaxWR+q2sMoWLKXROolj2Flj2vQoAZbFEnq+QasiP+Vpk73CPm9O/n+laQbJALyYcFUTaaeX+k7GDMYhaYw3qbFVBodN5uSW79UYzAbhnUq+p2oiEITIdn7mhu6plCe11P1v1cDocToKk45YhaOUiOR5dEqDiKfG/Oiaptdxm7eJ9fIxbWy16+VD9mzG+w5dPprfZ09PgGO8gXBIuFeeKiRfXjGOl2jOgxI92vly59x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devel.lists.xenproject.org>

The current bindings function, but the preexisting

  type physinfo_arch_cap_flag =
         | X86 of x86_physinfo_arch_cap_flag

is a special case in the Ocaml type system with an unusual indirection, and
will break when a second option, e.g. `| ARM of ...` is added.

Also, the position the list is logically wrong.  Currently, the types express
a list of elements which might be an x86 flag or an arm flag (and can
intermix), whereas what we actually want is either a list of x86 flags, or a
list of ARM flags (that cannot intermix).

Rework the Ocaml types to avoid the ABI special case and move the list
primitive, and adjust the C bindings to match.

Fixes: 2ce11ce249a3 ("x86/HVM: allow per-domain usage of hardware virtualized 
APIC")
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Christian Lindig <christian.lindig@xxxxxxxxxx>
CC: David Scott <dave@xxxxxxxxxx>
CC: Edwin Torok <edvin.torok@xxxxxxxxxx>
CC: Rob Hoes <Rob.Hoes@xxxxxxxxxx>
CC: Henry Wang <Henry.Wang@xxxxxxx>
---
 tools/ocaml/libs/xc/xenctrl.ml      | 10 ++++++----
 tools/ocaml/libs/xc/xenctrl.mli     | 11 +++++++----
 tools/ocaml/libs/xc/xenctrl_stubs.c | 22 ++++++++++++----------
 3 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml
index 0c71e5eef3c7..28ed6422317c 100644
--- a/tools/ocaml/libs/xc/xenctrl.ml
+++ b/tools/ocaml/libs/xc/xenctrl.ml
@@ -130,13 +130,15 @@ type physinfo_cap_flag =
        | CAP_Gnttab_v1
        | CAP_Gnttab_v2
 
+type arm_physinfo_cap_flag
 
-type x86_physinfo_arch_cap_flag =
+type x86_physinfo_cap_flag =
        | CAP_X86_ASSISTED_XAPIC
        | CAP_X86_ASSISTED_X2APIC
 
-type physinfo_arch_cap_flag =
-       | X86 of x86_physinfo_arch_cap_flag
+type arch_physinfo_cap_flags =
+       | ARM of arm_physinfo_cap_flag list
+       | X86 of x86_physinfo_cap_flag list
 
 type physinfo =
 {
@@ -151,7 +153,7 @@ type physinfo =
        (* XXX hw_cap *)
        capabilities     : physinfo_cap_flag list;
        max_nr_cpus      : int;
-       arch_capabilities : physinfo_arch_cap_flag list;
+       arch_capabilities : arch_physinfo_cap_flags;
 }
 
 type version =
diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.mli
index a8458e19ca4b..c2076d60c970 100644
--- a/tools/ocaml/libs/xc/xenctrl.mli
+++ b/tools/ocaml/libs/xc/xenctrl.mli
@@ -115,12 +115,15 @@ type physinfo_cap_flag =
   | CAP_Gnttab_v1
   | CAP_Gnttab_v2
 
-type x86_physinfo_arch_cap_flag =
+type arm_physinfo_cap_flag
+
+type x86_physinfo_cap_flag =
   | CAP_X86_ASSISTED_XAPIC
   | CAP_X86_ASSISTED_X2APIC
 
-type physinfo_arch_cap_flag =
-  | X86 of x86_physinfo_arch_cap_flag
+type arch_physinfo_cap_flags =
+  | ARM of arm_physinfo_cap_flag list
+  | X86 of x86_physinfo_cap_flag list
 
 type physinfo = {
   threads_per_core : int;
@@ -133,7 +136,7 @@ type physinfo = {
   scrub_pages      : nativeint;
   capabilities     : physinfo_cap_flag list;
   max_nr_cpus      : int; (** compile-time max possible number of nr_cpus *)
-  arch_capabilities : physinfo_arch_cap_flag list;
+  arch_capabilities : arch_physinfo_cap_flags;
 }
 type version = { major : int; minor : int; extra : string; }
 type compile_info = {
diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c 
b/tools/ocaml/libs/xc/xenctrl_stubs.c
index fe9c00ce008a..03f4cbf93cd3 100644
--- a/tools/ocaml/libs/xc/xenctrl_stubs.c
+++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -716,9 +716,10 @@ CAMLprim value stub_xc_send_debug_keys(value xch, value 
keys)
 CAMLprim value stub_xc_physinfo(value xch)
 {
        CAMLparam1(xch);
-       CAMLlocal4(physinfo, cap_list, x86_arch_cap_list, arch_cap_list);
+       CAMLlocal2(physinfo, cap_list);
+       CAMLlocal2(arch_cap_flags, arch_cap_list);
        xc_physinfo_t c_physinfo;
-       int r;
+       int r, arch_cap_flags_tag;
 
        caml_enter_blocking_section();
        r = xc_physinfo(_H(xch), &c_physinfo);
@@ -748,18 +749,19 @@ CAMLprim value stub_xc_physinfo(value xch)
        Store_field(physinfo, 9, Val_int(c_physinfo.max_cpu_id + 1));
 
 #if defined(__i386__) || defined(__x86_64__)
-       x86_arch_cap_list = c_bitmap_to_ocaml_list
-               /* ! x86_physinfo_arch_cap_flag CAP_X86_ none */
+       arch_cap_list = c_bitmap_to_ocaml_list
+               /* ! x86_physinfo_cap_flag CAP_X86_ none */
                /* ! XEN_SYSCTL_PHYSCAP_X86_ XEN_SYSCTL_PHYSCAP_X86_MAX max */
                (c_physinfo.arch_capabilities);
-       /*
-        * arch_capabilities: physinfo_arch_cap_flag list;
-        */
-       arch_cap_list = x86_arch_cap_list;
+
+       arch_cap_flags_tag = 1; /* tag x86 */
 #else
-       arch_cap_list = Val_emptylist;
+       caml_failwith("Unhandled architecture");
 #endif
-       Store_field(physinfo, 10, arch_cap_list);
+
+       arch_cap_flags = caml_alloc_small(1, arch_cap_flags_tag);
+       Store_field(arch_cap_flags, 0, arch_cap_list);
+       Store_field(physinfo, 10, arch_cap_flags);
 
        CAMLreturn(physinfo);
 }
-- 
2.11.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.