Skip to contentSkip to conversation

PoC: libxc+ocaml: add interface to detect PV drivers in HVM guests

PATCH New Andrew Cooper 2 participants 5 messages Mar 13, 2013 2 messages not in the archive

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 PoC: libxc+ocaml: add interface to detect PV drivers in HVM guests

In reply to a message not in the archive

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1294742832 0
# Node ID 59aaebc4ef6422e5ff4a3ad54d05597e646cfc92
# Parent a38d8f70a79bf368c1498f2a08894068f504bff7
PoC: libxc+ocaml: add interface to detect PV drivers in HVM guests

Required by xapi.

Taken from xen-api-libs.hg/xc and adjusted for upstream libxc+ocaml.

Rebased on top of xen-unstable.

tools/libxc/xc_misc.c +20 -0
diff -r a38d8f70a79b -r 59aaebc4ef64 tools/libxc/xc_misc.c
@@ -684,6 +684,26 @@ int xc_hvm_inject_trap(
     return rc;
 }
 
+int xc_hvm_check_pvdriver(xc_interface *xch, unsigned int domid)
+{
+    int ret;
+    unsigned long irq = 0;
+    xc_domaininfo_t info;
+
+    ret = xc_domain_getinfolist(xch, domid, 1, &info);
+    if (ret != 1) {
+        PERROR("domain getinfo failed");
+        return -1;
+    }
+
+    if ((!info.flags) & XEN_DOMINF_hvm_guest) {
+        ERROR("domain is not hvm");
+        return -1;
+    }
+    xc_get_hvm_param(xch, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
+    return irq;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxc/xenctrl.h +2 -0
diff -r a38d8f70a79b -r 59aaebc4ef64 tools/libxc/xenctrl.h
@@ -1631,6 +1631,8 @@ int xc_hvm_inject_trap(
     uint32_t type, uint32_t error_code, uint32_t insn_len,
     uint64_t cr2);
 
+int xc_hvm_check_pvdriver(xc_interface *xch, unsigned int domid);
+
 /*
  *  LOGGING AND ERROR REPORTING
  */
tools/ocaml/libs/xc/xenctrl.ml +4 -0
diff -r a38d8f70a79b -r 59aaebc4ef64 tools/ocaml/libs/xc/xenctrl.ml
@@ -237,6 +237,10 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
+(** check if some hvm domain got pv driver or not *)
+external hvm_check_pvdriver: handle -> domid -> bool
+       = "stub_xc_hvm_check_pvdriver"
+
 external version: handle -> version = "stub_xc_version_version"
 external version_compile_info: handle -> compile_info
        = "stub_xc_version_compile_info"
tools/ocaml/libs/xc/xenctrl.mli +2 -0
diff -r a38d8f70a79b -r 59aaebc4ef64 tools/ocaml/libs/xc/xenctrl.mli
@@ -142,6 +142,8 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
+external hvm_check_pvdriver : handle -> domid -> bool
+  = "stub_xc_hvm_check_pvdriver"
 external version : handle -> version = "stub_xc_version_version"
 external version_compile_info : handle -> compile_info
   = "stub_xc_version_compile_info"
tools/ocaml/libs/xc/xenctrl_stubs.c +11 -0
diff -r a38d8f70a79b -r 59aaebc4ef64 tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -1112,6 +1112,17 @@ static uint32_t encode_sbdf(int domain, 
 		((uint32_t)func   &    0x7);
 }
 
+CAMLprim value stub_xc_hvm_check_pvdriver(value xch, value domid)
+{
+	CAMLparam2(xch, domid);
+	int ret;
+
+	ret = xc_hvm_check_pvdriver(_H(xch), _D(domid));
+	if (ret < 0)
+		failwith_xc(_H(xch));
+	CAMLreturn(Val_bool(ret));
+}
+
 CAMLprim value stub_xc_domain_test_assign_device(value xch, value domid, value desc)
 {
 	CAMLparam3(xch, domid, desc);
#2 lore raw

PATCH 1/1 PoC: libxc+ocaml: add interfaces to manipulate various properties of HVM guests

In reply to a message not in the archive

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1294742832 0
# Node ID b279ec057736ead1d7061f8ec8a29a8676dd56b4
# Parent 59aaebc4ef6422e5ff4a3ad54d05597e646cfc92
PoC: libxc+ocaml: add interfaces to manipulate various properties of HVM guests

* set timer mode
* set hpet
* set vpt align
* get ACPI
* set/get ACPI S state (allows send s3resume)

Taken from xen-api-libs.hg/xc and adjusted for upstream libxc+ocaml.

Rebased on top of xen-unstable.

tools/libxc/xc_domain.c +32 -0
diff -r 59aaebc4ef64 -r b279ec057736 tools/libxc/xc_domain.c
@@ -1530,6 +1530,38 @@ int xc_domain_set_virq_handler(xc_interf
     return do_domctl(xch, &domctl);
 }
 
+int xc_domain_send_s3resume(xc_interface *xch, unsigned int domid)
+{
+    return xc_set_hvm_param(xch, domid, HVM_PARAM_ACPI_S_STATE, 0);
+}
+
+int xc_domain_set_timer_mode(xc_interface *xch, unsigned int domid, int mode)
+{
+    return xc_set_hvm_param(xch, domid,
+                            HVM_PARAM_TIMER_MODE, (unsigned long) mode);
+}
+
+int xc_domain_set_hpet(xc_interface *xch, unsigned int domid, int hpet)
+{
+    return xc_set_hvm_param(xch, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) hpet);
+}
+
+int xc_domain_set_vpt_align(xc_interface *xch, unsigned int domid, int vpt_align)
+{
+    return xc_set_hvm_param(xch, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) vpt_align);
+}
+
+int xc_domain_get_acpi_s_state(xc_interface *xch, unsigned int domid)
+{
+    int ret;
+    unsigned long value;
+
+    ret = xc_get_hvm_param(xch, domid, HVM_PARAM_ACPI_S_STATE, &value);
+    if (ret != 0)
+        ERROR("get acpi s-state");
+    return value;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxc/xenctrl.h +6 -0
diff -r 59aaebc4ef64 -r b279ec057736 tools/libxc/xenctrl.h
@@ -632,6 +632,12 @@ int xc_domain_hvm_setcontext(xc_interfac
                              uint8_t *hvm_ctxt,
                              uint32_t size);
 
+int xc_domain_send_s3resume(xc_interface *xch, unsigned int domid);
+int xc_domain_set_timer_mode(xc_interface *xch, unsigned int domid, int mode);
+int xc_domain_set_hpet(xc_interface *xch, unsigned int domid, int hpet);
+int xc_domain_set_vpt_align(xc_interface *xch, unsigned int domid, int vpt_align);
+int xc_domain_get_acpi_s_state(xc_interface *xch, unsigned int domid);
+
 /**
  * This function returns information about the execution context of a
  * particular vcpu of a domain.
tools/ocaml/libs/xc/xenctrl.ml +7 -0
diff -r 59aaebc4ef64 -r b279ec057736 tools/ocaml/libs/xc/xenctrl.ml
@@ -237,6 +237,13 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
+external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
+external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
+external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
+
+external domain_send_s3resume: handle -> domid -> unit = "stub_xc_domain_send_s3resume"
+external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
+
 (** check if some hvm domain got pv driver or not *)
 external hvm_check_pvdriver: handle -> domid -> bool
        = "stub_xc_hvm_check_pvdriver"
tools/ocaml/libs/xc/xenctrl.mli +8 -0
diff -r 59aaebc4ef64 -r b279ec057736 tools/ocaml/libs/xc/xenctrl.mli
@@ -142,6 +142,14 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
+external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
+external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
+external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
+
+external domain_send_s3resume: handle -> domid -> unit
+  = "stub_xc_domain_send_s3resume"
+external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
+
 external hvm_check_pvdriver : handle -> domid -> bool
   = "stub_xc_hvm_check_pvdriver"
 external version : handle -> version = "stub_xc_version_version"
tools/ocaml/libs/xc/xenctrl_stubs.c +53 -0

59 lines not on this page · raw message

#3 lore raw

PATCH 1/1 PoC: libxc+ocaml: add interfaces to send triggers to HVM guests

In reply to a message not in the archive

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1294742832 0
# Node ID 03997417771be2aa122d7dac31256399f854c5b1
# Parent b279ec057736ead1d7061f8ec8a29a8676dd56b4
PoC: libxc+ocaml: add interfaces to send triggers to HVM guests

* ACPI power button event
* ACPI sleep button event

Required by xapi.

Taken from xen-api-libs.hg/xc and adjusted for upstream libxc+ocaml.

Rebased on top of xen-unstable.

tools/libxc/xc_domain.c +30 -0
diff -r b279ec057736 -r 03997417771b tools/libxc/xc_domain.c
@@ -1562,6 +1562,36 @@ int xc_domain_get_acpi_s_state(xc_interf
     return value;
 }
 
+int xc_domain_trigger_power(xc_interface *xch, unsigned int domid)
+{
+    int ret;
+    DECLARE_DOMCTL;
+
+    domctl.cmd = XEN_DOMCTL_sendtrigger;
+    domctl.domain = domid;
+    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_POWER;
+
+    ret = do_domctl(xch, &domctl);
+    if (ret != 0)
+        ERROR("power button failed");
+    return ret;
+}
+
+int xc_domain_trigger_sleep(xc_interface *xch, unsigned int domid)
+{
+    int ret;
+    DECLARE_DOMCTL;
+
+    domctl.cmd = XEN_DOMCTL_sendtrigger;
+    domctl.domain = domid;
+    domctl.u.sendtrigger.trigger = XEN_DOMCTL_SENDTRIGGER_SLEEP;
+
+    ret = do_domctl(xch, &domctl);
+    if (ret != 0)
+        ERROR("sleep button failed");
+    return ret;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxc/xenctrl.h +3 -0
diff -r b279ec057736 -r 03997417771b tools/libxc/xenctrl.h
@@ -638,6 +638,9 @@ int xc_domain_set_hpet(xc_interface *xch
 int xc_domain_set_vpt_align(xc_interface *xch, unsigned int domid, int vpt_align);
 int xc_domain_get_acpi_s_state(xc_interface *xch, unsigned int domid);
 
+int xc_domain_trigger_power(xc_interface *xch, unsigned int domid);
+int xc_domain_trigger_sleep(xc_interface *xch, unsigned int domid);
+
 /**
  * This function returns information about the execution context of a
  * particular vcpu of a domain.
tools/ocaml/libs/xc/xenctrl.ml +3 -0
diff -r b279ec057736 -r 03997417771b tools/ocaml/libs/xc/xenctrl.ml
@@ -244,6 +244,9 @@ external domain_set_vpt_align: handle ->
 external domain_send_s3resume: handle -> domid -> unit = "stub_xc_domain_send_s3resume"
 external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
 
+external domain_trigger_power: handle -> domid -> unit = "stub_xc_domain_trigger_power"
+external domain_trigger_sleep: handle -> domid -> unit = "stub_xc_domain_trigger_sleep"
+
 (** check if some hvm domain got pv driver or not *)
 external hvm_check_pvdriver: handle -> domid -> bool
        = "stub_xc_hvm_check_pvdriver"
tools/ocaml/libs/xc/xenctrl.mli +5 -0
diff -r b279ec057736 -r 03997417771b tools/ocaml/libs/xc/xenctrl.mli
@@ -150,6 +150,11 @@ external domain_send_s3resume: handle ->
   = "stub_xc_domain_send_s3resume"
 external domain_get_acpi_s_state: handle -> domid -> int = "stub_xc_domain_get_acpi_s_state"
 
+external domain_trigger_power: handle -> domid -> unit
+  = "stub_xc_domain_trigger_power"
+external domain_trigger_sleep: handle -> domid -> unit
+  = "stub_xc_domain_trigger_sleep"
+
 external hvm_check_pvdriver : handle -> domid -> bool
   = "stub_xc_hvm_check_pvdriver"
 external version : handle -> version = "stub_xc_version_version"
tools/ocaml/libs/xc/xenctrl_stubs.c +14 -0
diff -r b279ec057736 -r 03997417771b tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -1247,6 +1247,20 @@ CAMLprim value stub_xc_domain_set_vpt_al
         CAMLreturn(Val_unit);
 }
 
+CAMLprim value stub_xc_domain_trigger_power(value xch, value domid)
+{
+	CAMLparam2(xch, domid);
+	xc_domain_trigger_power(_H(xch), _D(domid));
+	CAMLreturn(Val_unit);
+}
+
+CAMLprim value stub_xc_domain_trigger_sleep(value xch, value domid)
+{
+	CAMLparam2(xch, domid);
+	xc_domain_trigger_sleep(_H(xch), _D(domid));
+	CAMLreturn(Val_unit);
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: t
#4 lore raw

PATCH 1/1 PoC: ocaml: add binding to xc_domain_suppress_spurious_page_faults

In reply to a message not in the archive

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1294742832 0
# Node ID 6c7218be49d86a2c4741c7bdf2b8b2cd0187746c
# Parent 03997417771be2aa122d7dac31256399f854c5b1
PoC: ocaml: add binding to xc_domain_suppress_spurious_page_faults

Required by xapi.

Taken from xen-api-libs.hg/xc and adjusted for upstream libxc+ocaml.

Rebased on top of xen-unstable.

tools/ocaml/libs/xc/xenctrl.ml +3 -0
diff -r 03997417771b -r 6c7218be49d8 tools/ocaml/libs/xc/xenctrl.ml
@@ -237,6 +237,9 @@ external domain_deassign_device: handle 
 external domain_test_assign_device: handle -> domid -> (int * int * int * int) -> bool
        = "stub_xc_domain_test_assign_device"
 
+external domain_suppress_spurious_page_faults: handle -> domid -> unit
+       = "stub_xc_domain_suppress_spurious_page_faults"
+
 external domain_set_timer_mode: handle -> domid -> int -> unit = "stub_xc_domain_set_timer_mode"
 external domain_set_hpet: handle -> domid -> int -> unit = "stub_xc_domain_set_hpet"
 external domain_set_vpt_align: handle -> domid -> int -> unit = "stub_xc_domain_set_vpt_align"
tools/ocaml/libs/xc/xenctrl.mli +3 -0
diff -r 03997417771b -r 6c7218be49d8 tools/ocaml/libs/xc/xenctrl.mli
@@ -185,6 +185,9 @@ external domain_set_machine_address_size
 external domain_get_machine_address_size: handle -> domid -> int
        = "stub_xc_domain_get_machine_address_size"
 
+external domain_suppress_spurious_page_faults: handle -> domid -> unit
+       = "stub_xc_domain_suppress_spurious_page_faults"
+
 external domain_cpuid_set: handle -> domid -> (int64 * (int64 option))
                         -> string option array
                         -> string option array
tools/ocaml/libs/xc/xenctrl_stubs.c +11 -0
diff -r 03997417771b -r 6c7218be49d8 tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -731,6 +731,17 @@ CAMLprim value stub_xc_domain_get_machin
 	CAMLreturn(Val_int(retval));
 }
 
+CAMLprim value stub_xc_domain_suppress_spurious_page_faults(value xch,
+							    value domid)
+{
+	CAMLparam2(xch, domid);
+
+	int retval = xc_domain_suppress_spurious_page_faults(_H(xch), _D(domid));
+	if (retval)
+		failwith_xc(_H(xch));
+	CAMLreturn(Val_unit);
+}
+
 CAMLprim value stub_xc_domain_cpuid_set(value xch, value domid,
                                         value input,
                                         value config)
#6 lore raw
In reply to a message not in the archive
Quoted 6 lines · Andrew Cooper

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1294742832 0
# Node ID 59aaebc4ef6422e5ff4a3ad54d05597e646cfc92
# Parent a38d8f70a79bf368c1498f2a08894068f504bff7
PoC: libxc+ocaml: add interface to detect PV drivers in HVM guests

libxl already has such an interface IIRC, I'm not sure we want to also add it to libxc at this stage.

I expect this is why I left the PoC tag on it.

Skimming the other 3 I think they are in the same boat.

Ian.