Skip to contentSkip to conversation

Fix building qemu-kvm for non KVM target

PATCH New [email protected] 1 participant 8 messages Jun 22, 2010

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

v4 cover Fix building qemu-kvm for non KVM target

From: Jes Sorensen <[email protected]>

Hi,

This set of patches fixes building qemu-kvm for non KVM targets, as reported in
http://sourceforge.net/tracker/?func=detail&atid=893831&aid=2984626&group_id=180599

One of the main problem is that we have a tendency to move things from Makefile.objs to Makefile.target in order to be able to use TARGET_I386 etc in hw/*.c files. IMHO we need to start clamping down on this harder and move things into separate files rather than the #ifdef hacks. Hence this patch fixes the short term problem, but there is more work to do for the longer term.

This version is just a rebase against the latest version of qemu-kvm, and I fixed up the commit messages a bit to remove a couple of duplicated statements.

Cheers,
Jes

Jes Sorensen (7):
Only call kvm_set_irqfd() if CONFIG_KVM is defined Remove duplicate kvm_init() stub from qemu-kvm.h time_drift_fix is x86 only, rather than !ia64
Build certain drivers for MIPS as well.
Only export phys_mem create functions for !CONFIG_USER_ONLY builds Only treat KVM specific cmdline options for KVM enabled builds Declare no_hpet variable for all targets

 Makefile.target |    2 ++
 hw/i8259.c      |    2 +-
 hw/virtio-pci.c |    4 ++++
 qemu-kvm.h      |   31 ++++++++++++++-----------------
 vl.c            |    4 ++--
 5 files changed, 23 insertions(+), 20 deletions(-)
#1 lore raw

PATCH v4 1/7 Only call kvm_set_irqfd() if CONFIG_KVM is defined

From: Jes Sorensen <[email protected]>

This avoids breaking the build for non KVM targets where kvm_set_irqfd() is not defined.

---
 hw/virtio-pci.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
hw/virtio-pci.c +4 -0
index d497eae..938937e 100644
@@ -430,6 +430,7 @@ static void virtio_pci_guest_notifier_read(void *opaque)
 static int virtio_pci_mask_notifier(PCIDevice *dev, unsigned vector,
                                     void *opaque, int masked)
 {
+#ifdef CONFIG_KVM
     VirtQueue *vq = opaque;
     EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
     int r = kvm_set_irqfd(dev->msix_irq_entries[vector].gsi,
@@ -446,6 +447,9 @@ static int virtio_pci_mask_notifier(PCIDevice *dev, unsigned vector,
                             NULL, NULL, NULL);
     }
     return 0;
+#else
+    return -ENOSYS;
+#endif
 }
 
 static int virtio_pci_set_guest_notifier(void *opaque, int n, bool assign)
Signature · 1 line
1.7.0.1
#2 lore raw

PATCH v4 2/7 Remove duplicate kvm_init() stub from qemu-kvm.h

In reply to [email protected]

From: Jes Sorensen <[email protected]>

Avoid build conflicts and move prototype out of CONFIG_KVM to make the stub in kvm-stub.c visible.

---
 qemu-kvm.h |   29 ++++++++++++-----------------
 1 files changed, 12 insertions(+), 17 deletions(-)
qemu-kvm.h +12 -17
index 3ace503..c9b93dc 100644
@@ -107,18 +107,6 @@ int kvm_set_mce(CPUState *env, struct kvm_x86_mce *mce);
 #endif
 
 /*!
- * \brief Create new KVM context
- *
- * This creates a new kvm_context. A KVM context is a small area of data that
- * holds information about the KVM instance that gets created by this call.\n
- * This should always be your first call to KVM.
- *
- * \param opaque Not used
- * \return NULL on failure
- */
-int kvm_init(int smp_cpus);
-
-/*!
  * \brief Disable the in-kernel IRQCHIP creation
  *
  * In-kernel irqchip is enabled by default. If userspace irqchip is to be used,
@@ -806,11 +794,6 @@ typedef struct kvm_vcpu_context *kvm_vcpu_context_t;
 struct kvm_pit_state {
 };
 
-static inline int kvm_init(int smp_cpus)
-{
-    return 0;
-}
-
 static inline void kvm_inject_x86_mce(CPUState *cenv, int bank,
                                       uint64_t status, uint64_t mcg_status,
                                       uint64_t addr, uint64_t misc,
@@ -823,6 +806,18 @@ static inline void kvm_inject_x86_mce(CPUState *cenv, int bank,
 #endif                          /* !CONFIG_KVM */
 
 
+/*!
+ * \brief Create new KVM context
+ *
+ * This creates a new kvm_context. A KVM context is a small area of data that
+ * holds information about the KVM instance that gets created by this call.\n
+ * This should always be your first call to KVM.
+ *
+ * \param opaque Not used
+ * \return NULL on failure
+ */
+int kvm_init(int smp_cpus);
+
 int kvm_main_loop(void);
 int kvm_init_ap(void);
 int kvm_vcpu_inited(CPUState *env);
Signature · 1 line
1.7.0.1
#3 lore raw

PATCH v4 3/7 time_drift_fix is x86 only, rather than !ia64

In reply to [email protected]

From: Jes Sorensen <[email protected]>

time_drift_fix is only present on x86, not just on !ia64. This allows the code to build for other archs, like MIPS.

---
 hw/i8259.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/i8259.c +1 -1
index a8ae069..e89d831 100644
@@ -237,7 +237,7 @@ int pic_read_irq(PicState2 *s)
     if (irq >= 0) {
 
         pic_intack(&s->pics[0], irq);
-#ifndef TARGET_IA64
+#ifdef TARGET_I386
 	if (time_drift_fix && irq == 0) {
 	    extern int64_t timer_acks, timer_ints_to_push;
 	    timer_acks++;
Signature · 1 line
1.7.0.1
#4 lore raw

PATCH v4 4/7 Build certain drivers for MIPS as well.

In reply to [email protected]

From: Jes Sorensen <[email protected]>

pcspk.o i8254.o acpi.o acpi_piix4.o are all required for MIPS as well, add them to Makefile.target accordingly.

---
 Makefile.target |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Makefile.target +2 -0
index b0bb434..730e392 100644
@@ -245,6 +245,8 @@ obj-ppc-$(CONFIG_KVM) += kvm_ppc.o
 obj-ppc-$(CONFIG_FDT) += device_tree.o
 
 obj-mips-y = mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o
+obj-mips-y += pcspk.o i8254.o
+obj-mips-y += acpi.o acpi_piix4.o
 obj-mips-y += mips_addr.o mips_timer.o mips_int.o
 obj-mips-y += vga.o i8259.o
 obj-mips-y += g364fb.o jazz_led.o
Signature · 1 line
1.7.0.1
#5 lore raw

PATCH v4 5/7 Only export phys_mem create functions for !CONFIG_USER_ONLY builds

In reply to [email protected]

From: Jes Sorensen <[email protected]>

---
 qemu-kvm.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
qemu-kvm.h +2 -0
index c9b93dc..6dd3a01 100644
@@ -835,6 +835,7 @@ void qemu_kvm_cpuid_on_env(CPUState *env);
 void kvm_inject_interrupt(CPUState *env, int mask);
 void kvm_update_after_sipi(CPUState *env);
 void kvm_update_interrupt_request(CPUState *env);
+#ifndef CONFIG_USER_ONLY
 void *kvm_cpu_create_phys_mem(target_phys_addr_t start_addr, unsigned long size,
                               int log, int writable);
 
@@ -842,6 +843,7 @@ void kvm_cpu_destroy_phys_mem(target_phys_addr_t start_addr,
                               unsigned long size);
 void kvm_qemu_log_memory(target_phys_addr_t start, target_phys_addr_t size,
                          int log);
+#endif
 int kvm_qemu_create_memory_alias(uint64_t phys_start, uint64_t len,
                                  uint64_t target_phys);
 int kvm_qemu_destroy_memory_alias(uint64_t phys_start);
Signature · 1 line
1.7.0.1
#6 lore raw

PATCH v4 6/7 Only treat KVM specific cmdline options for KVM enabled builds

In reply to [email protected]

From: Jes Sorensen <[email protected]>

This fixes build breakage for target MIPS etc.

---
 vl.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
vl.c +2 -0
index 0ee963c..79f91d5 100644
@@ -2459,6 +2459,7 @@ int main(int argc, char **argv, char **envp)
 	    case QEMU_OPTION_no_kvm:
 		kvm_allowed = 0;
 		break;
+#ifdef CONFIG_KVM
 	    case QEMU_OPTION_no_kvm_irqchip: {
 		kvm_irqchip = 0;
 		kvm_pit = 0;
@@ -2476,6 +2477,7 @@ int main(int argc, char **argv, char **envp)
 		kvm_nested = 1;
 		break;
 	    }
+#endif
 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
             case QEMU_OPTION_pcidevice:
 		if (assigned_devices_index >= MAX_DEV_ASSIGN_CMDLINE) {
Signature · 1 line
1.7.0.1
#7 lore raw

PATCH v4 7/7 Declare no_hpet variable for all targets

In reply to [email protected]

From: Jes Sorensen <[email protected]>

We need to declare 'int no_hpet' for all targets to avoid build failure on no x86 builds.

---
 vl.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
vl.c +0 -2
index 79f91d5..c2e99fc 100644
@@ -207,9 +207,7 @@ int smp_cores = 1;
 int smp_threads = 1;
 const char *vnc_display;
 int acpi_enabled = 1;
-#ifdef TARGET_I386
 int no_hpet = 0;
-#endif
 int fd_bootchk = 1;
 int no_reboot = 0;
 int no_shutdown = 0;
Signature · 1 line
1.7.0.1