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

[xen staging] tools/ocaml/xc: Address ABI issues with physinfo arch flags



commit 0823d57d71c7023bea94d483f69f7b5e62820102
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Mon Jul 25 18:36:29 2022 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Thu Oct 13 11:45:19 2022 +0100

    tools/ocaml/xc: Address ABI issues with physinfo arch flags
    
    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>
    Acked-by: Christian Lindig <christian.lindig@xxxxxxxxxx>
    Release-acked-by: 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 | 21 +++++++++++----------
 3 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml
index 0c71e5eef3..28ed642231 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 a8458e19ca..c2076d60c9 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 fe9c00ce00..a8789d19be 100644
--- a/tools/ocaml/libs/xc/xenctrl_stubs.c
+++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -716,9 +716,9 @@ 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);
+       CAMLlocal4(physinfo, cap_list, 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 +748,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);
 }
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

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