From 74ea827a8d5c535e74557514142da85b68426b1b Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Thu, 28 Jan 2016 14:38:35 +0000 Subject: [PATCH] xen: begin using libxendevicemodel This library is intended to be a stable interface which device models can rely on in order to avoid a link time dependency on libxenctrl (which implies needing to rebuild QEMU when Xen is updated to a new release, which is a pain for distros) Rather than go the whole hog all in one go (which would be unrevieable) this patch adds the basic support and uses it for domain lifecycle operations. Further patches will add more support. As with previous patches to use stable libraries the QEMU code now uses the new stable API on all versions of Xen and stubs out the necessary code for the older versions. I had wanted to add the xendevicemodel_handle to the XenIOState struct, however it does not appear to be possible to get at the state pointer from all the places where it is needed, specifically the first such place I tripped over was xen_piix3_set_irq(). Signed-off-by: Ian Campbell --- configure | 22 ++++++++++++++++++++++ include/hw/xen/xen_common.h | 24 ++++++++++++++++++++++++ xen-hvm.c | 29 +++++++++++++++++++++-------- 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/configure b/configure index 1e861c185..21c276a3e 100755 --- a/configure +++ b/configure @@ -253,6 +253,7 @@ xen_ctrl_version="" xen_pv_domain_build="no" xen_pci_passthrough="" xen_restrict_target="no" +xen_libdevicemodel="no" linux_aio="" cap_ng="" attr="" @@ -2173,6 +2174,23 @@ EOF then xen_restrict_target="yes" fi + + if + cat > $TMPC < +int main(void) { + xendevicemodel_handle *dm; + + dm = xendevicemodel_open(NULL, 0, 0, NULL); + xendevicemodel_shutdown(dm); + return 0; +} +EOF + compile_prog "" "-lxendevicemodel" + then + xen_libdevicemodel="yes" + libs_softmmu="$libs_softmmu -lxendevicemodel" + fi fi @@ -4820,6 +4838,7 @@ echo "xen support $xen" if test "$xen" = "yes" ; then echo "xen ctrl version $xen_ctrl_version" echo "xen restricted $xen_restrict_target" + echo "xen dm lib $xen_libdevicemodel" echo "pv dom build $xen_pv_domain_build" fi echo "brlapi support $brlapi" @@ -5198,6 +5217,9 @@ if test "$xen" = "yes" ; then if test "$xen_restrict_target" = "yes" ; then echo "CONFIG_XEN_RESTRICT_TARGET=y" >> $config_host_mak fi + if test "$xen_libdevicemodel" = "yes" ; then + echo "CONFIG_XEN_LIBDEVICEMODEL=y" >> $config_host_mak + fi fi if test "$linux_aio" = "yes" ; then echo "CONFIG_LINUX_AIO=y" >> $config_host_mak diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 38502c752..803afd3bf 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -99,6 +99,30 @@ static inline int xen_get_vmport_regs_pfn(xc_interface *xc, domid_t dom, } #endif +#ifdef CONFIG_XEN_LIBDEVICEMODEL + +#include + +#else + +typedef xc_interface xendevicemodel_handle; + +/* Assumes r (returns restriction status of the handle) is non-NULL in + * all actual callers */ +#define xendevicemodel_open(l, d, f, r) ({ *r = ENOSYS; xen_xc; }) + +#define xendevicemodel_shutdown(h) \ + xc_domain_shutdown(h, xen_domid, SHUTDOWN_poweroff) +#define xendevicemodel_reboot(h) \ + xc_domain_shutdown(h, xen_domid, SHUTDOWN_reboot) + +#define xendevicemodel_s3_suspend(h) \ + xc_set_hvm_param(h, xen_domid, HVM_PARAM_ACPI_S_STATE, 3); +#define xendevicemodel_s3_awaken(h) \ + xc_set_hvm_param(h, xen_domid, HVM_PARAM_ACPI_S_STATE, 0); + +#endif + /* Xen before 4.6 */ #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 460 diff --git a/xen-hvm.c b/xen-hvm.c index 921269cc3..28514ccf5 100644 --- a/xen-hvm.c +++ b/xen-hvm.c @@ -42,6 +42,7 @@ static MemoryRegion ram_memory, ram_640k, ram_lo, ram_hi; static MemoryRegion *framebuffer; static bool xen_in_migration; +static xendevicemodel_handle *xen_dm = NULL; /* Compatibility with older version */ @@ -159,9 +160,9 @@ void xen_hvm_inject_msi(uint64_t addr, uint32_t data) xc_hvm_inject_msi(xen_xc, xen_domid, addr, data); } -static void xen_suspend_notifier(Notifier *notifier, void *data) +static void xen_suspend_notifier(Notifier *n, void *data) { - xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 3); + xendevicemodel_s3_suspend(xen_dm); } /* Xen Interrupt Controller */ @@ -1029,11 +1030,12 @@ static void destroy_hvm_domain(bool reboot) { int sts; - sts = xc_domain_shutdown(xen_xc, xen_domid, - reboot ? SHUTDOWN_reboot : SHUTDOWN_poweroff); + sts = (reboot ? + xendevicemodel_reboot(xen_dm) : + xendevicemodel_shutdown(xen_dm)); if (sts != 0) { - fprintf(stderr, "xc_domain_shutdown failed to issue %s, " - "sts %d, %s\n", reboot ? "reboot" : "poweroff", + fprintf(stderr, "failed to issue %s, sts %d, %s\n", + reboot ? "reboot" : "poweroff", sts, strerror(errno)); } else { fprintf(stderr, "Issued domain %d %s\n", xen_domid, @@ -1179,9 +1181,9 @@ static void xen_read_physmap(XenIOState *state) free(entries); } -static void xen_wakeup_notifier(Notifier *notifier, void *data) +static void xen_wakeup_notifier(Notifier *n, void *data) { - xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0); + xendevicemodel_s3_awaken(xen_dm); } static bool xen_restrict_targets = true; /* XXX configurable? */ @@ -1202,6 +1204,7 @@ static bool xen_restrict_target_failure_is_fatal(const char *which, int errnoval error_report("restricting %s handle failed: %d: %s", which, errnoval, strerror(errnoval)); + return true; } @@ -1212,6 +1215,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) xen_pfn_t bufioreq_pfn; evtchn_port_t bufioreq_evtchn; XenIOState *state; + int dm_restrict_errno; state = g_malloc0(sizeof (XenIOState)); @@ -1243,6 +1247,15 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) if (rc < 0 && xen_restrict_target_failure_is_fatal("xenforeignmemory", errno)) goto err; + xen_dm = xendevicemodel_open(NULL, xen_domid, 0, &dm_restrict_errno); + if (!xen_dm) { + perror("xen: dm handle create"); + goto err; + } + if (dm_restrict_errno && + xen_restrict_target_failure_is_fatal("xendevicemodel", dm_restrict_errno)) + goto err; + rc = xen_create_ioreq_server(xen_xc, xen_domid, &state->ioservid); if (rc < 0) { perror("xen: ioreq server create"); -- 2.39.5