Skip to contentSkip to conversation

qemu-kvm.git uq/master queue

GIT PULL New Marcelo Tosatti 2 participants 7 messages Mar 8, 2012 – Mar 9, 2012

Subsystems (2)
lore
Share & tools
lore
#2 lore raw

PATCH 2/5 i8254: Open-code timer restore

In reply to Marcelo Tosatti

From: Jan Kiszka <[email protected]>

Same as for the APIC: To enable migration between accelerated and non-accelerated models, we need to arm the channel 0 timer only inside the emulated PIT model. The common code just saves/restores that timer to the the next_transition_time field.

---
 hw/i8254.c        |   12 ++++++++++++
 hw/i8254_common.c |   10 +++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)
hw/i8254.c +12 -0
index 9fde344..77bd5e8 100644
@@ -300,6 +300,17 @@ static const MemoryRegionOps pit_ioport_ops = {
     .old_portio = pit_portio
 };
 
+static void pit_post_load(PITCommonState *s)
+{
+    PITChannelState *sc = &s->channels[0];
+
+    if (sc->next_transition_time != -1) {
+        qemu_mod_timer(sc->irq_timer, sc->next_transition_time);
+    } else {
+        qemu_del_timer(sc->irq_timer);
+    }
+}
+
 static int pit_initfn(PITCommonState *pit)
 {
     PITChannelState *s;
@@ -329,6 +340,7 @@ static void pit_class_initfn(ObjectClass *klass, void *data)
     k->init = pit_initfn;
     k->set_channel_gate = pit_set_channel_gate;
     k->get_channel_info = pit_get_channel_info_common;
+    k->post_load = pit_post_load;
     dc->reset = pit_reset;
     dc->props = pit_properties;
 }
hw/i8254_common.c +7 -3
index 6373e87..a03d7cd 100644
@@ -211,6 +211,7 @@ static const VMStateDescription vmstate_pit_channel = {
 static int pit_load_old(QEMUFile *f, void *opaque, int version_id)
 {
     PITCommonState *pit = opaque;
+    PITCommonClass *c = PIT_COMMON_GET_CLASS(pit);
     PITChannelState *s;
     int i;
 
@@ -234,11 +235,13 @@ static int pit_load_old(QEMUFile *f, void *opaque, int version_id)
         qemu_get_8s(f, &s->gate);
         s->count_load_time = qemu_get_be64(f);
         s->irq_disabled = 0;
-        if (s->irq_timer) {
+        if (i == 0) {
             s->next_transition_time = qemu_get_be64(f);
-            qemu_get_timer(f, s->irq_timer);
         }
     }
+    if (c->post_load) {
+        c->post_load(pit);
+    }
     return 0;
 }
 
@@ -275,7 +278,8 @@ static const VMStateDescription vmstate_pit_common = {
         VMSTATE_UINT32_V(channels[0].irq_disabled, PITCommonState, 3),
         VMSTATE_STRUCT_ARRAY(channels, PITCommonState, 3, 2,
                              vmstate_pit_channel, PITChannelState),
-        VMSTATE_TIMER(channels[0].irq_timer, PITCommonState),
+        VMSTATE_INT64(channels[0].next_transition_time,
+                      PITCommonState), /* formerly irq_timer */
         VMSTATE_END_OF_LIST()
     }
 };
Signature · 1 line
1.7.6.4
#0 lore raw

The following changes since commit e32605062cd62c2a958ad28a6ad7de4eeab12027:

xilinx_zynq: machine model initial version (2012-03-07 02:20:19 +0100)

are available in the git repository at:
git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git uq/master

Jan Kiszka (4):
i8254: Factor out base class for KVM reuse
i8254: Open-code timer restore
kvm: Add kvm_has_pit_state2 helper
kvm: x86: Add user space part for in-kernel i8254

Michael S. Tsirkin (1):
kvm: fill in padding to help valgrind

 Makefile.objs       |    2 +-
 Makefile.target     |    2 +-
 hw/i8254.c          |  281 +++++++---------------------------------------
 hw/i8254.h          |   11 ++
 hw/i8254_common.c   |  311 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/i8254_internal.h |   85 ++++++++++++++
 hw/kvm/i8254.c      |  254 +++++++++++++++++++++++++++++++++++++++++
 hw/pc.c             |   14 ++-
 kvm-all.c           |   12 ++
 kvm-stub.c          |    5 +
 kvm.h               |    1 +
 target-i386/kvm.c   |    6 +
 12 files changed, 742 insertions(+), 242 deletions(-)
 create mode 100644 hw/i8254_common.c
 create mode 100644 hw/i8254_internal.h
 create mode 100644 hw/kvm/i8254.c
#4 lore raw

PATCH 4/5 kvm: x86: Add user space part for in-kernel i8254

From: Jan Kiszka <[email protected]>

This provides the required user space stubs to enable the in-kernel i8254 emulation of KVM.

The in-kernel model supports lost tick compensation according to the "delay" policy. This is enabled by default and can be switched off via a device property.

Depending on the feature set of the host kernel (before 2.6.32), we may have to disable the HPET or lack sound output from the PC speaker.

---
 Makefile.target |    2 +-
 hw/i8254.h      |   11 +++
 hw/kvm/i8254.c  |  254 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pc.c         |   14 +++-
 4 files changed, 278 insertions(+), 3 deletions(-)
 create mode 100644 hw/kvm/i8254.c
Makefile.target +1 -1
index 5f3fc40..1bd25a8 100644
@@ -244,7 +244,7 @@ obj-i386-y += pci-hotplug.o smbios.o wdt_ib700.o
 obj-i386-y += debugcon.o multiboot.o
 obj-i386-y += pc_piix.o
 obj-i386-y += pc_sysfw.o
-obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o kvm/i8259.o kvm/ioapic.o
+obj-i386-$(CONFIG_KVM) += kvm/clock.o kvm/apic.o kvm/i8259.o kvm/ioapic.o kvm/i8254.o
 obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
 
 # shared objects
hw/i8254.h +11 -0
index a1d2e98..ba6b598 100644
@@ -51,6 +51,17 @@ static inline ISADevice *pit_init(ISABus *bus, int base, int isa_irq,
     return dev;
 }
 
+static inline ISADevice *kvm_pit_init(ISABus *bus, int base)
+{
+    ISADevice *dev;
+
+    dev = isa_create(bus, "kvm-pit");
+    qdev_prop_set_uint32(&dev->qdev, "iobase", base);
+    qdev_init_nofail(&dev->qdev);
+
+    return dev;
+}
+
 void pit_set_gate(ISADevice *dev, int channel, int val);
 void pit_get_channel_info(ISADevice *dev, int channel, PITChannelInfo *info);
 
hw/kvm/i8254.c new file +254 -0

254 lines not on this page · raw message

hw/pc.c +12 -2
index 12c02f2..bb9867b 100644
@@ -1096,7 +1096,13 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
 
     register_ioport_write(0xf0, 1, 1, ioportF0_write, NULL);
 
-    if (!no_hpet) {
+    /*
+     * Check if an HPET shall be created.
+     *
+     * Without KVM_CAP_PIT_STATE2, we cannot switch off the in-kernel PIT
+     * when the HPET wants to take over. Thus we have to disable the latter.
+     */
+    if (!no_hpet && (!kvm_irqchip_in_kernel() || kvm_has_pit_state2())) {
         hpet = sysbus_try_create_simple("hpet", HPET_BASE, NULL);
 
         if (hpet) {
@@ -1112,7 +1118,11 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
 
     qemu_register_boot_set(pc_boot_set, *rtc_state);
 
-    pit = pit_init(isa_bus, 0x40, pit_isa_irq, pit_alt_irq);
+    if (kvm_irqchip_in_kernel()) {
+        pit = kvm_pit_init(isa_bus, 0x40);
+    } else {
+        pit = pit_init(isa_bus, 0x40, pit_isa_irq, pit_alt_irq);
+    }
     if (hpet) {
         /* connect PIT to output control line of the HPET */
         qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(&pit->qdev, 0));
Signature · 1 line
1.7.6.4
#3 lore raw

PATCH 3/5 kvm: Add kvm_has_pit_state2 helper

In reply to Marcelo Tosatti

From: Jan Kiszka <[email protected]>

To be used for in-kernel PIT emulation.

---
 kvm-all.c  |   10 ++++++++++
 kvm-stub.c |    5 +++++
 kvm.h      |    1 +
 3 files changed, 16 insertions(+), 0 deletions(-)
kvm-all.c +10 -0
index 77eadf6..278085f 100644
@@ -76,6 +76,7 @@ struct KVMState
     struct kvm_sw_breakpoint_head kvm_sw_breakpoints;
 #endif
     int pit_in_kernel;
+    int pit_state2;
     int xsave, xcrs;
     int many_ioeventfds;
     int irqchip_inject_ioctl;
@@ -1058,6 +1059,10 @@ int kvm_init(void)
     s->xcrs = kvm_check_extension(s, KVM_CAP_XCRS);
 #endif
 
+#ifdef KVM_CAP_PIT_STATE2
+    s->pit_state2 = kvm_check_extension(s, KVM_CAP_PIT_STATE2);
+#endif
+
     ret = kvm_arch_init(s);
     if (ret < 0) {
         goto err;
@@ -1390,6 +1395,11 @@ int kvm_has_xcrs(void)
     return kvm_state->xcrs;
 }
 
+int kvm_has_pit_state2(void)
+{
+    return kvm_state->pit_state2;
+}
+
 int kvm_has_many_ioeventfds(void)
 {
     if (!kvm_enabled()) {
kvm-stub.c +5 -0
index f63a0d2..1f1c686 100644
@@ -78,6 +78,11 @@ int kvm_allows_irq0_override(void)
     return 1;
 }
 
+int kvm_has_pit_state2(void)
+{
+    return 0;
+}
+
 void kvm_setup_guest_memory(void *start, size_t size)
 {
 }
kvm.h +1 -0
index f9f1dc8..8ef4476 100644
@@ -54,6 +54,7 @@ int kvm_has_robust_singlestep(void);
 int kvm_has_debugregs(void);
 int kvm_has_xsave(void);
 int kvm_has_xcrs(void);
+int kvm_has_pit_state2(void);
 int kvm_has_many_ioeventfds(void);
 int kvm_has_gsi_routing(void);
 
Signature · 1 line
1.7.6.4
#1 lore raw

PATCH 1/5 i8254: Factor out base class for KVM reuse

In reply to Marcelo Tosatti

From: Jan Kiszka <[email protected]>

Applying the concept used for the *PICs once again: establish a base class for the i8254 that can be used both by the current user space emulation and the upcoming KVM in-kernel version. We share most of the public interface of the i8254, specifically to the pcspk, vmstate, reset and certain init parts.

---
 Makefile.objs       |    2 +-
 hw/i8254.c          |  269 +++++---------------------------------------
 hw/i8254_common.c   |  307 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/i8254_internal.h |   85 ++++++++++++++
 4 files changed, 424 insertions(+), 239 deletions(-)
 create mode 100644 hw/i8254_common.c
 create mode 100644 hw/i8254_internal.h
Makefile.objs +1 -1
index 808de6a..b39d76c 100644
@@ -210,7 +210,7 @@ hw-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
 
 hw-obj-$(CONFIG_SERIAL) += serial.o
 hw-obj-$(CONFIG_PARALLEL) += parallel.o
-hw-obj-$(CONFIG_I8254) += i8254.o
+hw-obj-$(CONFIG_I8254) += i8254_common.o i8254.o
 hw-obj-$(CONFIG_PCSPK) += pcspk.o
 hw-obj-$(CONFIG_PCKBD) += pckbd.o
 hw-obj-$(CONFIG_USB_UHCI) += usb-uhci.o
hw/i8254.c +31 -238

365 lines not on this page · raw message

hw/i8254_common.c new file +307 -0

307 lines not on this page · raw message

hw/i8254_internal.h new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
1.7.6.4
#5 lore raw

PATCH 5/5 kvm: fill in padding to help valgrind

In reply to Marcelo Tosatti

From: "Michael S. Tsirkin" <[email protected]>

valgrind warns about padding fields which are passed to vcpu ioctls uninitialized.
This is not an error in practice because kvm ignored padding. Since the ioctls in question are off data path and the cost is zero anyway, initialize padding to 0
to suppress these errors.

---
 kvm-all.c         |    2 ++
 target-i386/kvm.c |    6 ++++++
 2 files changed, 8 insertions(+), 0 deletions(-)
kvm-all.c +2 -0
index 278085f..21c7dd2 100644
@@ -448,6 +448,7 @@ int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size)
 
         zone.addr = start;
         zone.size = size;
+        zone.pad = 0;
 
         ret = kvm_vm_ioctl(s, KVM_REGISTER_COALESCED_MMIO, &zone);
     }
@@ -465,6 +466,7 @@ int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size)
 
         zone.addr = start;
         zone.size = size;
+        zone.pad = 0;
 
         ret = kvm_vm_ioctl(s, KVM_UNREGISTER_COALESCED_MMIO, &zone);
     }
target-i386/kvm.c +6 -0
index 9a73207..619d773 100644
@@ -555,6 +555,7 @@ int kvm_arch_init_vcpu(CPUState *env)
 
     qemu_add_vm_change_state_handler(cpu_update_state, env);
 
+    cpuid_data.cpuid.padding = 0;
     r = kvm_vcpu_ioctl(env, KVM_SET_CPUID2, &cpuid_data);
     if (r) {
         return r;
@@ -740,6 +741,7 @@ static void set_seg(struct kvm_segment *lhs, const SegmentCache *rhs)
     lhs->g = (flags & DESC_G_MASK) != 0;
     lhs->avl = (flags & DESC_AVL_MASK) != 0;
     lhs->unusable = 0;
+    lhs->padding = 0;
 }
 
 static void get_seg(SegmentCache *lhs, const struct kvm_segment *rhs)
@@ -919,8 +921,10 @@ static int kvm_put_sregs(CPUState *env)
 
     sregs.idt.limit = env->idt.limit;
     sregs.idt.base = env->idt.base;
+    memset(sregs.idt.padding, 0, sizeof sregs.idt.padding);
     sregs.gdt.limit = env->gdt.limit;
     sregs.gdt.base = env->gdt.base;
+    memset(sregs.gdt.padding, 0, sizeof sregs.gdt.padding);
 
     sregs.cr0 = env->cr[0];
     sregs.cr2 = env->cr[2];
@@ -1392,6 +1396,7 @@ static int kvm_put_vcpu_events(CPUState *env, int level)
     events.exception.nr = env->exception_injected;
     events.exception.has_error_code = env->has_error_code;
     events.exception.error_code = env->error_code;
+    events.exception.pad = 0;
 
     events.interrupt.injected = (env->interrupt_injected >= 0);
     events.interrupt.nr = env->interrupt_injected;
@@ -1400,6 +1405,7 @@ static int kvm_put_vcpu_events(CPUState *env, int level)
     events.nmi.injected = env->nmi_injected;
     events.nmi.pending = env->nmi_pending;
     events.nmi.masked = !!(env->hflags2 & HF2_NMI_MASK);
+    events.nmi.pad = 0;
 
     events.sipi_vector = env->sipi_vector;
 
Signature · 1 line
1.7.6.4
#6 lore raw
In reply to Marcelo Tosatti
Quoted 3 lines · Marcelo Tosatti

The following changes since commit e32605062cd62c2a958ad28a6ad7de4eeab12027:

   xilinx_zynq: machine model initial version (2012-03-07 02:20:19 +0100)

Pulled. Thanks.

Regards,

Anthony Liguori

Quoted 31 lines

are available in the git repository at:
git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git uq/master

Jan Kiszka (4):
i8254: Factor out base class for KVM reuse
i8254: Open-code timer restore
kvm: Add kvm_has_pit_state2 helper
kvm: x86: Add user space part for in-kernel i8254

Michael S. Tsirkin (1):
kvm: fill in padding to help valgrind

  Makefile.objs       |    2 +-
  Makefile.target     |    2 +-
  hw/i8254.c          |  281 +++++++---------------------------------------
  hw/i8254.h          |   11 ++
  hw/i8254_common.c   |  311 +++++++++++++++++++++++++++++++++++++++++++++++++++
  hw/i8254_internal.h |   85 ++++++++++++++
  hw/kvm/i8254.c      |  254 +++++++++++++++++++++++++++++++++++++++++
  hw/pc.c             |   14 ++-
  kvm-all.c           |   12 ++
  kvm-stub.c          |    5 +
  kvm.h               |    1 +
  target-i386/kvm.c   |    6 +
  12 files changed, 742 insertions(+), 242 deletions(-)

create mode 100644 hw/i8254_common.c
create mode 100644 hw/i8254_internal.h
create mode 100644 hw/kvm/i8254.c