From: Paolo Bonzini Date: Tue, 10 May 2011 11:24:14 +0000 (+0200) Subject: xen: parse and generate hpet item in sxpr X-Git-Tag: CVE-2011-2178~266 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e547e44cb0f3d3b556ca94de899b1dcedd878afd;p=thirdparty%2Flibvirt.git xen: parse and generate hpet item in sxpr Recent versions of Xen disable the virtual HPET by default. This is usually more precise because tick policies are not implemented for the HPET in Xen. However, there may be several reasons to control the HPET manually: 1) to test the emulation; 2) because distros may provide the knob while leaving the default to "enabled" for compatibility reasons. This patch provides support for the hpet item in both sexpr and xm formats, and translates it to a element. Signed-off-by: Paolo Bonzini --- diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index 86902865d6..72fb81aeed 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -1175,6 +1175,23 @@ xenParseSxpr(const struct sexpr *root, /* Old XenD only allows localtime here for HVM */ if (sexpr_int(root, "domain/image/hvm/localtime")) def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME; + + if (sexpr_lookup(root, "domain/image/hvm/hpet")) { + virDomainTimerDefPtr timer; + + if (VIR_ALLOC_N(def->clock.timers, 1) < 0 || + VIR_ALLOC(timer) < 0) { + virReportOOMError(); + goto error; + } + + timer->name = VIR_DOMAIN_TIMER_NAME_HPET; + timer->present = sexpr_int(root, "domain/image/hvm/hpet"); + timer->tickpolicy = -1; + + def->clock.ntimers = 1; + def->clock.timers[0] = timer; + } } /* Current XenD allows localtime here, for PV and HVM */ @@ -2220,6 +2237,15 @@ xenFormatSxpr(virConnectPtr conn, if (def->emulator && (hvm || xendConfigVersion >= 3)) virBufferEscapeSexpr(&buf, "(device_model '%s')", def->emulator); + /* look for HPET in order to override the hypervisor/xend default */ + for (i = 0; i < def->clock.ntimers; i++) { + if (def->clock.timers[i]->name == VIR_DOMAIN_TIMER_NAME_HPET && + def->clock.timers[i]->present != -1) { + virBufferAsprintf(&buf, "(hpet %d)", + def->clock.timers[i]->present); + break; + } + } /* PV graphics for xen <= 3.0.4, or HVM graphics for xen <= 3.1.0 */ if ((!hvm && xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF) || diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 7f67ae289e..accf5f4c44 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -369,6 +369,25 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; else if (val) def->features |= (1 << VIR_DOMAIN_FEATURE_HAP); + + if (xenXMConfigGetBool(conf, "hpet", &val, -1) < 0) + goto cleanup; + else if (val != -1) { + virDomainTimerDefPtr timer; + + if (VIR_ALLOC_N(def->clock.timers, 1) < 0 || + VIR_ALLOC(timer) < 0) { + virReportOOMError(); + goto cleanup; + } + + timer->name = VIR_DOMAIN_TIMER_NAME_HPET; + timer->present = val; + timer->tickpolicy = -1; + + def->clock.ntimers = 1; + def->clock.timers[0] = timer; + } } if (xenXMConfigGetBool(conf, "localtime", &vmlocaltime, 0) < 0) goto cleanup; @@ -1514,6 +1533,13 @@ virConfPtr xenFormatXM(virConnectPtr conn, goto cleanup; } + for (i = 0; i < def->clock.ntimers; i++) { + if (def->clock.timers[i]->name == VIR_DOMAIN_TIMER_NAME_HPET && + def->clock.timers[i]->present != -1 && + xenXMConfigSetInt(conf, "hpet", def->clock.timers[i]->present) < 0) + break; + } + if (xendConfigVersion == 1) { for (i = 0 ; i < def->ndisks ; i++) { if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM && diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-force-hpet.sexpr b/tests/sexpr2xmldata/sexpr2xml-fv-force-hpet.sexpr new file mode 100644 index 0000000000..d52214f3ab --- /dev/null +++ b/tests/sexpr2xmldata/sexpr2xml-fv-force-hpet.sexpr @@ -0,0 +1,9 @@ +(domain (domid 1)(name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)\ +(uuid 'b5d70dd275cdaca517769660b059d8bc')(on_poweroff 'destroy')\ +(on_reboot 'restart')(on_crash 'restart')\ +(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')(vcpus 1)(boot c)\ +(cdrom '/root/boot.iso')(acpi 1)(usb 1)(parallel none)(serial none)\ +(device_model '/usr/lib64/xen/bin/qemu-dm')(hpet 1)(vnc 1)))\ +(device (vbd (dev 'ioemu:hda')(uname 'file:/root/foo.img')(mode 'w')))\ +(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')\ +(model 'e1000')(type ioemu))))\ diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-force-hpet.xml b/tests/sexpr2xmldata/sexpr2xml-fv-force-hpet.xml new file mode 100644 index 0000000000..d0ead27cc2 --- /dev/null +++ b/tests/sexpr2xmldata/sexpr2xml-fv-force-hpet.xml @@ -0,0 +1,44 @@ + + fvtest + b5d70dd2-75cd-aca5-1776-9660b059d8bc + 409600 + 409600 + 1 + + hvm + /usr/lib/xen/boot/hvmloader + + + + + + + + + destroy + restart + restart + + /usr/lib64/xen/bin/qemu-dm + + + + + + + + + + + + + + +