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

[Xen-devel] [PATCH RFC 08/31] tools/stubs: Expose host featureset to userspace



Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
CC: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
CC: Wei Liu <wei.liu2@xxxxxxxxxx>
CC: David Scott <dave@xxxxxxxxxx>
CC: Rob Hoes <Rob.Hoes@xxxxxxxxxx>
---
 tools/libxc/include/xenctrl.h       |  3 +++
 tools/libxc/xc_misc.c               | 27 +++++++++++++++++++++++++++
 tools/ocaml/libs/xc/xenctrl.ml      |  3 +++
 tools/ocaml/libs/xc/xenctrl.mli     |  4 ++++
 tools/ocaml/libs/xc/xenctrl_stubs.c | 35 +++++++++++++++++++++++++++++++++++
 5 files changed, 72 insertions(+)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 37205c2..27e1f45 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -2839,6 +2839,9 @@ int xc_psr_cat_get_domain_data(xc_interface *xch, 
uint32_t domid,
                                uint64_t *data);
 int xc_psr_cat_get_l3_info(xc_interface *xch, uint32_t socket,
                            uint32_t *cos_max, uint32_t *cbm_len);
+
+int xc_get_featureset(xc_interface *xch, uint32_t index,
+                      uint32_t *nr_features, uint32_t *featureset);
 #endif
 
 #endif /* XENCTRL_H */
diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
index c613545..4d7af3d 100644
--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -718,6 +718,33 @@ int xc_hvm_inject_trap(
     return rc;
 }
 
+int xc_get_featureset(xc_interface *xch, uint32_t index,
+                      uint32_t *nr_features, uint32_t *featureset)
+{
+    DECLARE_SYSCTL;
+    DECLARE_HYPERCALL_BOUNCE(featureset,
+                             *nr_features * sizeof(*featureset),
+                             XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+    int ret;
+
+    if ( xc_hypercall_bounce_pre(xch, featureset) )
+        return -1;
+
+    sysctl.cmd = XEN_SYSCTL_get_featureset;
+    sysctl.u.featureset.index = index;
+    sysctl.u.featureset.nr_features = *nr_features;
+    set_xen_guest_handle(sysctl.u.featureset.features, featureset);
+
+    ret = do_sysctl(xch, &sysctl);
+
+    xc_hypercall_bounce_post(xch, featureset);
+
+    if ( !ret )
+        *nr_features = sysctl.u.featureset.nr_features;
+
+    return ret;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml
index b7ba8b7..15c7eb0 100644
--- a/tools/ocaml/libs/xc/xenctrl.ml
+++ b/tools/ocaml/libs/xc/xenctrl.ml
@@ -244,6 +244,9 @@ external version_changeset: handle -> string = 
"stub_xc_version_changeset"
 external version_capabilities: handle -> string =
   "stub_xc_version_capabilities"
 
+type featureset_index = Featureset_host | Featureset_pv | Featureset_hvm
+external get_featureset : handle -> featureset_index -> int64 array = 
"stub_xc_get_featureset"
+
 external watchdog : handle -> int -> int32 -> int
   = "stub_xc_watchdog"
 
diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.mli
index bc4af56..42d6199 100644
--- a/tools/ocaml/libs/xc/xenctrl.mli
+++ b/tools/ocaml/libs/xc/xenctrl.mli
@@ -148,6 +148,10 @@ external version_compile_info : handle -> compile_info
 external version_changeset : handle -> string = "stub_xc_version_changeset"
 external version_capabilities : handle -> string
   = "stub_xc_version_capabilities"
+
+type featureset_index = Featureset_host | Featureset_pv | Featureset_hvm
+external get_featureset : handle -> featureset_index -> int64 array = 
"stub_xc_get_featureset"
+
 type core_magic = Magic_hvm | Magic_pv
 type core_header = {
   xch_magic : core_magic;
diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c 
b/tools/ocaml/libs/xc/xenctrl_stubs.c
index b7de615..a47473b 100644
--- a/tools/ocaml/libs/xc/xenctrl_stubs.c
+++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -1220,6 +1220,41 @@ CAMLprim value stub_xc_domain_deassign_device(value xch, 
value domid, value desc
        CAMLreturn(Val_unit);
 }
 
+CAMLprim value stub_xc_get_featureset(value xch, value idx)
+{
+       CAMLparam2(xch, idx);
+       CAMLlocal1(bitmap_val);
+
+       /* Safe, because of the global ocaml lock. */
+       static uint32_t fs_len;
+
+       if (fs_len == 0)
+       {
+               int ret = xc_get_featureset(_H(xch), 0, &fs_len, NULL);
+
+               if (ret || (fs_len == 0))
+                       failwith_xc(_H(xch));
+       }
+
+       {
+               /* To/from hypervisor to retrieve actual featureset */
+               uint32_t fs[fs_len], len = fs_len;
+               unsigned int i;
+
+               int ret = xc_get_featureset(_H(xch), Int_val(idx), &len, fs);
+
+               if (ret)
+                       failwith_xc(_H(xch));
+
+               bitmap_val = caml_alloc(len, 0);
+
+               for (i = 0; i < len; ++i)
+                       Store_field(bitmap_val, i, caml_copy_int64(fs[i]));
+       }
+
+       CAMLreturn(bitmap_val);
+}
+
 CAMLprim value stub_xc_watchdog(value xch, value domid, value timeout)
 {
        CAMLparam3(xch, domid, timeout);
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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