Skip to contentSkip to conversation

Fix compilation with --disable-kvm

PATCH Applied Glauber Costa 4 participants 13 messages Jul 7, 2009 – Jul 9, 2009 KVM

lore
Share & tools
lore
#0 lore raw

cover Fix compilation with --disable-kvm

I just came across two errors in --disable-kvm builds.

here's the patches to fix it.

#1 lore raw

PATCH 1/2 surround kvm function with kvm_enabled

otherwise, compilation breaks with kvm disabled.

---
 hw/pc.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
hw/pc.c +3 -1
index cf84416..afab0ad 100644
@@ -1131,7 +1131,9 @@ static void pc_init1(ram_addr_t ram_size,
 #endif
     }
 
-    kvm_set_boot_cpu_id(0);
+    if (kvm_enabled()) {
+        kvm_set_boot_cpu_id(0);
+    }
     for (i = 0; i < smp_cpus; i++) {
         env = pc_new_cpu(cpu_model);
     }
Signature · 1 line
1.6.2.2
#2 lore raw

PATCH 2/2 fix compilation with kvm disabled

---
 hw/msix.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
hw/msix.c +14 -0
index b6f3948..8636f69 100644
@@ -63,6 +63,7 @@
 /* Flag for interrupt controller to declare MSI-X support */
 int msix_supported;
 
+#ifdef USE_KVM
 /* KVM specific MSIX helpers */
 static void kvm_msix_free(PCIDevice *dev)
 {
@@ -157,6 +158,14 @@ static void kvm_msix_del(PCIDevice *dev, unsigned vector)
     kvm_del_routing_entry(kvm_context, &dev->msix_irq_entries[vector]);
     kvm_commit_irq_routes(kvm_context);
 }
+#else
+
+static void kvm_msix_free(PCIDevice *dev) {}
+static void kvm_msix_update(PCIDevice *dev, int vector,
+                            int was_masked, int is_masked) {}
+static int kvm_msix_add(PCIDevice *dev, unsigned vector) { return -1; }
+static void kvm_msix_del(PCIDevice *dev, unsigned vector) {}
+#endif
 
 /* Add MSI-X capability to the config space for the device. */
 /* Given a bar and its size, add MSI-X table on top of it
@@ -337,10 +346,12 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
     if (nentries > MSIX_MAX_ENTRIES)
         return -EINVAL;
 
+#ifdef KVM_CAP_IRQCHIP
     if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) {
         dev->msix_irq_entries = qemu_malloc(nentries *
                                             sizeof *dev->msix_irq_entries);
     }
+#endif
     dev->msix_entry_used = qemu_mallocz(MSIX_MAX_ENTRIES *
                                         sizeof *dev->msix_entry_used);
 
@@ -454,10 +465,13 @@ void msix_notify(PCIDevice *dev, unsigned vector)
         msix_set_pending(dev, vector);
         return;
     }
+
+#ifdef KVM_CAP_IRQCHIP
     if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) {
         kvm_set_irq(dev->msix_irq_entries[vector].gsi, 1, NULL);
         return;
     }
+#endif
 
     address = pci_get_long(table_entry + MSIX_MSG_UPPER_ADDR);
     address = (address << 32) | pci_get_long(table_entry + MSIX_MSG_ADDR);
Signature · 1 line
1.6.2.2
#11 lore raw
In reply to Glauber Costa
Quoted 3 lines · Glauber Costa

I just came across two errors in --disable-kvm builds.

here's the patches to fix it.

Builds fine for me, too, resolving both issues I just reported.

Jan

#3 lore raw

Re: [PATCH 2/2] fix compilation with kvm disabled

In reply to Glauber Costa
Quoted 22 lines · Glauber Costa
---
 hw/msix.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
hw/msix.c +2 -0
index b6f3948..8636f69 100644
@@ -63,6 +63,7 @@
 /* Flag for interrupt controller to declare MSI-X support */
 int msix_supported;
 
+#ifdef USE_KVM
 /* KVM specific MSIX helpers */
 static void kvm_msix_free(PCIDevice *dev)
 {
@@ -157,6 +158,14 @@ static void kvm_msix_del(PCIDevice *dev, unsigned vector)
     kvm_del_routing_entry(kvm_context, &dev->msix_irq_entries[vector]);
     kvm_commit_irq_routes(kvm_context);
 }
+#else

hw/msix.c static void kvm_msix_del(PCIDevice *dev, unsigned vector) · line 171

Quoted 10 lines
hw/msix.c +7 -0
+
+static void kvm_msix_free(PCIDevice *dev) {}
+static void kvm_msix_update(PCIDevice *dev, int vector,
+                            int was_masked, int is_masked) {}
+static int kvm_msix_add(PCIDevice *dev, unsigned vector) { return -1; }
+static void kvm_msix_del(PCIDevice *dev, unsigned vector) {}
+#endif
 
 /* Add MSI-X capability to the config space for the device. */
 /* Given a bar and its size, add MSI-X table on top of it

Thanks for fix!

Quoted 17 lines
hw/msix.c +2 -0
@@ -337,10 +346,12 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
     if (nentries > MSIX_MAX_ENTRIES)
         return -EINVAL;
 
+#ifdef KVM_CAP_IRQCHIP
     if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) {
         dev->msix_irq_entries = qemu_malloc(nentries *
                                             sizeof *dev->msix_irq_entries);
     }
+#endif
     dev->msix_entry_used = qemu_mallocz(MSIX_MAX_ENTRIES *
                                         sizeof *dev->msix_entry_used);
 
@@ -454,10 +465,13 @@ void msix_notify(PCIDevice *dev, unsigned vector)
         msix_set_pending(dev, vector);
         return;
     }

hw/msix.c void msix_notify(PCIDevice *dev, unsigned vector) · line 477

Quoted 10 lines
hw/msix.c +3 -0
+
+#ifdef KVM_CAP_IRQCHIP
     if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) {
         kvm_set_irq(dev->msix_irq_entries[vector].gsi, 1, NULL);
         return;
     }
+#endif
 
     address = pci_get_long(table_entry + MSIX_MSG_UPPER_ADDR);
     address = (address << 32) | pci_get_long(table_entry + MSIX_MSG_ADDR);

I think it's time we stopped worrying about builds against old kernel headers or without them. What do we gain from it?

I believe that the right thing to do is to define kvm_enabled as a macro returning 0, and let compiler optimize the code out.

Avi?

Signature · 1 line
MST
#4 lore raw

Re: [PATCH 2/2] fix compilation with kvm disabled

Quoted 61 lines · Michael S. Tsirkin
Quoted 22 lines · Glauber Costa
---
 hw/msix.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
hw/msix.c +2 -0
index b6f3948..8636f69 100644
@@ -63,6 +63,7 @@
 /* Flag for interrupt controller to declare MSI-X support */
 int msix_supported;
 
+#ifdef USE_KVM
 /* KVM specific MSIX helpers */
 static void kvm_msix_free(PCIDevice *dev)
 {
@@ -157,6 +158,14 @@ static void kvm_msix_del(PCIDevice *dev, unsigned vector)
     kvm_del_routing_entry(kvm_context, &dev->msix_irq_entries[vector]);
     kvm_commit_irq_routes(kvm_context);
 }
+#else

hw/msix.c static void kvm_msix_del(PCIDevice *dev, unsigned vector) · line 171

Quoted 10 lines
hw/msix.c +7 -0
+
+static void kvm_msix_free(PCIDevice *dev) {}
+static void kvm_msix_update(PCIDevice *dev, int vector,
+                            int was_masked, int is_masked) {}
+static int kvm_msix_add(PCIDevice *dev, unsigned vector) { return -1; }
+static void kvm_msix_del(PCIDevice *dev, unsigned vector) {}
+#endif
 
 /* Add MSI-X capability to the config space for the device. */
 /* Given a bar and its size, add MSI-X table on top of it

Thanks for fix!

Quoted 25 lines
hw/msix.c +5 -0
@@ -337,10 +346,12 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
     if (nentries > MSIX_MAX_ENTRIES)
         return -EINVAL;
 
+#ifdef KVM_CAP_IRQCHIP
     if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) {
         dev->msix_irq_entries = qemu_malloc(nentries *
                                             sizeof *dev->msix_irq_entries);
     }
+#endif
     dev->msix_entry_used = qemu_mallocz(MSIX_MAX_ENTRIES *
                                         sizeof *dev->msix_entry_used);
 
@@ -454,10 +465,13 @@ void msix_notify(PCIDevice *dev, unsigned vector)
         msix_set_pending(dev, vector);
         return;
     }
+
+#ifdef KVM_CAP_IRQCHIP
     if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) {
         kvm_set_irq(dev->msix_irq_entries[vector].gsi, 1, NULL);
         return;
     }
+#endif
 
Quoted 8 lines

hw/msix.c void msix_notify(PCIDevice *dev, unsigned vector) · line 477

Quoted 2 lines
hw/msix.c +0 -0
     address = pci_get_long(table_entry + MSIX_MSG_UPPER_ADDR);
     address = (address << 32) | pci_get_long(table_entry + MSIX_MSG_ADDR);

I think it's time we stopped worrying about builds against old kernel headers or without them. What do we gain from it?

I believe that the right thing to do is to define kvm_enabled as a macro returning 0, and let compiler optimize the code out.

that already happens with kvm_enabled().
I have no idea why the compiler do not rip of code when we also test for qemu_kvm_irqchip_in_kernel() or other things.

what we could do, is to only test for qemu_kvm_irqchip_in_kernel(), using the hidden assumption that if kvm is not enabled, irqchip tests will always return false.

It is a little bit messy, though.

#5 lore raw

Re: [PATCH 2/2] fix compilation with kvm disabled

Quoted 8 lines · Glauber Costa
Quoted 4 lines

I believe that the right thing to do is to define kvm_enabled as a macro returning 0, and let compiler optimize the code out.

that already happens with kvm_enabled().
I have no idea why the compiler do not rip of code when we also test for qemu_kvm_irqchip_in_kernel() or other things.

Quoted 5 lines

what we could do, is to only test for qemu_kvm_irqchip_in_kernel(), using the hidden assumption that if kvm is not enabled, irqchip tests will always return false.

It is a little bit messy, though

We should make the call unconditional and do the kvm_enabled/irqchip_in_kernel checks in the kvm-specific function. This way common code is only minimally affected.

Signature · 1 line
error compiling committee.c: too many arguments to function
#6 lore raw

Re: [PATCH 2/2] fix compilation with kvm disabled

In reply to Michael S. Tsirkin
Quoted 26 lines · Michael S. Tsirkin
Quoted 26 lines
hw/msix.c +5 -0
@@ -337,10 +346,12 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
      if (nentries>  MSIX_MAX_ENTRIES)
          return -EINVAL;
 
+#ifdef KVM_CAP_IRQCHIP
      if (kvm_enabled()&&  qemu_kvm_irqchip_in_kernel()) {
          dev->msix_irq_entries = qemu_malloc(nentries *
                                              sizeof *dev->msix_irq_entries);
      }
+#endif
      dev->msix_entry_used = qemu_mallocz(MSIX_MAX_ENTRIES *
                                          sizeof *dev->msix_entry_used);
 
@@ -454,10 +465,13 @@ void msix_notify(PCIDevice *dev, unsigned vector)
          msix_set_pending(dev, vector);
          return;
      }
+
+#ifdef KVM_CAP_IRQCHIP
      if (kvm_enabled()&&  qemu_kvm_irqchip_in_kernel()) {
          kvm_set_irq(dev->msix_irq_entries[vector].gsi, 1, NULL);
          return;
      }
+#endif
 
Quoted 7 lines

Review void msix_notify(PCIDevice *dev, unsigned vector) · line 477

Quoted 3 lines
(quoted diff) +0 -0
      address = pci_get_long(table_entry + MSIX_MSG_UPPER_ADDR);
      address = (address<<  32) | pci_get_long(table_entry + MSIX_MSG_ADDR);

I think it's time we stopped worrying about builds against old kernel headers or without them. What do we gain from it?

qemu upstream doesn't carry its own headers, so it we want to merge, we need to work against old headers.

Quoted 3 lines

I believe that the right thing to do is to define kvm_enabled as a macro returning 0, and let compiler optimize the code out.

Doesn't work with -O0 (or if it does, we can't count on it).

Signature · 1 line
error compiling committee.c: too many arguments to function
Applied
#12 lore raw
In reply to Glauber Costa
Quoted 4 lines · Glauber Costa

I just came across two errors in --disable-kvm builds.

here's the patches to fix it.

Applied, thanks.

Signature · 1 line
error compiling committee.c: too many arguments to function
#7 lore raw

Re: [PATCH 2/2] fix compilation with kvm disabled

In reply to Avi Kivity
Quoted 35 lines · Avi Kivity
Quoted 26 lines · Michael S. Tsirkin
Quoted 26 lines
hw/msix.c +5 -0
@@ -337,10 +346,12 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
      if (nentries>  MSIX_MAX_ENTRIES)
          return -EINVAL;
 
+#ifdef KVM_CAP_IRQCHIP
      if (kvm_enabled()&&  qemu_kvm_irqchip_in_kernel()) {
          dev->msix_irq_entries = qemu_malloc(nentries *
                                              sizeof *dev->msix_irq_entries);
      }
+#endif
      dev->msix_entry_used = qemu_mallocz(MSIX_MAX_ENTRIES *
                                          sizeof *dev->msix_entry_used);
 
@@ -454,10 +465,13 @@ void msix_notify(PCIDevice *dev, unsigned vector)
          msix_set_pending(dev, vector);
          return;
      }
+
+#ifdef KVM_CAP_IRQCHIP
      if (kvm_enabled()&&  qemu_kvm_irqchip_in_kernel()) {
          kvm_set_irq(dev->msix_irq_entries[vector].gsi, 1, NULL);
          return;
      }
+#endif
 
Quoted 7 lines

Review void msix_notify(PCIDevice *dev, unsigned vector) · line 477

Quoted 3 lines
(quoted diff) +0 -0
      address = pci_get_long(table_entry + MSIX_MSG_UPPER_ADDR);
      address = (address<<  32) | pci_get_long(table_entry + MSIX_MSG_ADDR);

I think it's time we stopped worrying about builds against old kernel headers or without them. What do we gain from it?

Quoted 2 lines

qemu upstream doesn't carry its own headers, so it we want to merge, we need to work against old headers.

Was there ever discussion on this? I think the right thing to do is to add own headers to qemu upstream.

Quoted 5 lines
Quoted 3 lines

I believe that the right thing to do is to define kvm_enabled as a macro returning 0, and let compiler optimize the code out.

Doesn't work with -O0 (or if it does, we can't count on it).

With -O0 you get a ton of dead code anyway. Who cares?

Signature · 1 line
MST
#8 lore raw

Re: [PATCH 2/2] fix compilation with kvm disabled

Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines
Quoted 4 lines

I think it's time we stopped worrying about builds against old kernel headers or without them. What do we gain from it?

qemu upstream doesn't carry its own headers, so it we want to merge, we need to work against old headers.

Was there ever discussion on this? I think the right thing to do is to add own headers to qemu upstream.

Discussion yes, conclusion no.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

I believe that the right thing to do is to define kvm_enabled as a macro returning 0, and let compiler optimize the code out.

Doesn't work with -O0 (or if it does, we can't count on it).

With -O0 you get a ton of dead code anyway. Who cares

People who debug (though -O1 works fine most of the time). It also feels unclean to rely on optimization for correctness.

Signature · 1 line
error compiling committee.c: too many arguments to function
#9 lore raw

Re: [PATCH 2/2] fix compilation with kvm disabled

Quoted 19 lines · Avi Kivity
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines
Quoted 4 lines

I think it's time we stopped worrying about builds against old kernel headers or without them. What do we gain from it?

qemu upstream doesn't carry its own headers, so it we want to merge, we need to work against old headers.

Was there ever discussion on this? I think the right thing to do is to add own headers to qemu upstream.

Discussion yes, conclusion no.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

I believe that the right thing to do is to define kvm_enabled as a macro returning 0, and let compiler optimize the code out.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Doesn't work with -O0 (or if it does, we can't count on it).

With -O0 you get a ton of dead code anyway. Who cares

People who debug (though -O1 works fine most of the time). It also feels unclean to rely on optimization for correctness.

I do not propoise to rely on optimization for correctness. The code under if (0) will get compiled with -O0 (and we need to carry our headers for this) but will never run.

Signature · 1 line
MST
#10 lore raw

Re: [PATCH 2/2] fix compilation with kvm disabled

In reply to Glauber Costa
Quoted 22 lines · Glauber Costa
---
 hw/msix.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
hw/msix.c +2 -0
index b6f3948..8636f69 100644
@@ -63,6 +63,7 @@
 /* Flag for interrupt controller to declare MSI-X support */
 int msix_supported;
 
+#ifdef USE_KVM
 /* KVM specific MSIX helpers */
 static void kvm_msix_free(PCIDevice *dev)
 {
@@ -157,6 +158,14 @@ static void kvm_msix_del(PCIDevice *dev, unsigned vector)
     kvm_del_routing_entry(kvm_context, &dev->msix_irq_entries[vector]);
     kvm_commit_irq_routes(kvm_context);
 }
+#else

hw/msix.c static void kvm_msix_del(PCIDevice *dev, unsigned vector) · line 171

Quoted 10 lines
hw/msix.c +7 -0
+
+static void kvm_msix_free(PCIDevice *dev) {}
+static void kvm_msix_update(PCIDevice *dev, int vector,
+                            int was_masked, int is_masked) {}
+static int kvm_msix_add(PCIDevice *dev, unsigned vector) { return -1; }
+static void kvm_msix_del(PCIDevice *dev, unsigned vector) {}
+#endif
 
 /* Add MSI-X capability to the config space for the device. */
 /* Given a bar and its size, add MSI-X table on top of it

Avi, let's apply this first bit so that people can build with kvm-disabled, and think a bit about the second one?

Quoted 34 lines
hw/msix.c +5 -0
@@ -337,10 +346,12 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,
     if (nentries > MSIX_MAX_ENTRIES)
         return -EINVAL;
 
+#ifdef KVM_CAP_IRQCHIP
     if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) {
         dev->msix_irq_entries = qemu_malloc(nentries *
                                             sizeof *dev->msix_irq_entries);
     }
+#endif
     dev->msix_entry_used = qemu_mallocz(MSIX_MAX_ENTRIES *
                                         sizeof *dev->msix_entry_used);
 
@@ -454,10 +465,13 @@ void msix_notify(PCIDevice *dev, unsigned vector)
         msix_set_pending(dev, vector);
         return;
     }
+
+#ifdef KVM_CAP_IRQCHIP
     if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) {
         kvm_set_irq(dev->msix_irq_entries[vector].gsi, 1, NULL);
         return;
     }
+#endif
 
     address = pci_get_long(table_entry + MSIX_MSG_UPPER_ADDR);
     address = (address << 32) | pci_get_long(table_entry + MSIX_MSG_ADDR);
Signature · 6 lines
1.6.2.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html