Skip to contentSkip to conversation

Build fixes for minimal microvm

PATCH Superseded Ani Sinha 2 participants 6 messages Mar 19 KVM

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ani Sinha

author
#0 lore raw

cover Build fixes for minimal microvm

Some build fixes for building a minmal qemu for microvm

cc -m64 @qemu-system-x86_64.rsp
ld: libqemu-x86_64-softmmu.a.p/target_i386_kvm_kvm.c.o: in function `hyperv_init_vcpu':
target/i386/kvm/kvm.c:1757:(.text+0x5d83): undefined reference to `hyperv_is_synic_enabled'
ld: libqemu-x86_64-softmmu.a.p/hw_i386_x86-common.c.o: in function `x86_bios_rom_reload':
hw/i386/x86-common.c:1104:(.text+0x240d): undefined reference to `x86_firmware_configure'
collect2: error: ld returned 1 exit status

The build is done with the devices file:

CONFIG_PCI_DEVICES=n
CONFIG_MICROVM=y
CONFIG_VIRTIO_BLK=y
CONFIG_VIRTIO_SERIAL=y
CONFIG_VIRTIO_INPUT=y
CONFIG_VIRTIO_INPUT_HOST=y
CONFIG_VHOST_USER_INPUT=y
CONFIG_VIRTIO_NET=y
CONFIG_VIRTIO_SCSI=y
CONFIG_VIRTIO_RNG=y
CONFIG_VIRTIO_CRYPTO=y
CONFIG_VIRTIO_BALLOON=y
CONFIG_VIRTIO_GPU=y
CONFIG_VHOST_USER_GPU=y

and with these confiure options:

../../configure ${common_configure_opts} \
              --without-default-features \
              --target-list=x86_64-softmmu --enable-kvm --disable-tcg \
              --enable-pixman --enable-vnc \
              --enable-virtfs \
              --enable-linux-aio --enable-linux-io-uring \
              --enable-numa \
              --enable-attr \
              --enable-coroutine-pool \
              --audio-drv-list="" \
              --without-default-devices \
              --with-devices-x86_64=microvm \
              --enable-vhost-kernel --enable-vhost-net \
              --enable-vhost-vdpa \
              --enable-vhost-user --enable-vhost-user-blk-server \
              --enable-vhost-crypto \
              --enable-seccomp

Ani Sinha (2):
i386/pc_sysfw: stub out x86_firmware_configure
i386/hyperv: add stubs for synic enablement

 hw/i386/pc_sysfw_ovmf-stubs.c |  5 +++++
 target/i386/kvm/hyperv-stub.c |  5 +++++
 target/i386/kvm/hyperv.c      |  9 +++++++++
 target/i386/kvm/hyperv.h      |  1 +
 target/i386/kvm/kvm.c         | 12 +++++-------
 5 files changed, 25 insertions(+), 7 deletions(-)
Signature · 1 line
2.42.0
author
#1 lore raw

PATCH 1/2 i386/pc_sysfw: stub out x86_firmware_configure

x86_firmware_configure requires ovmf support. Add a stub for this function call for cases where OVMF is not supported.

---
 hw/i386/pc_sysfw_ovmf-stubs.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/i386/pc_sysfw_ovmf-stubs.c +5 -0
index aabe78b271..b53906a052 100644
@@ -24,3 +24,8 @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size)
 {
     g_assert_not_reached();
 }
+
+void x86_firmware_configure(hwaddr gpa, void *ptr, int size)
+{
+    g_assert_not_reached();
+}
Signature · 1 line
2.42.0
author
#2 lore raw

Re: [PATCH for-11.0 1/2] i386/pc_sysfw: stub out x86_firmware_configure

Quoted 18 lines · Ani Sinha

x86_firmware_configure requires ovmf support. Add a stub for this function call for cases where OVMF is not supported.

---
hw/i386/pc_sysfw_ovmf-stubs.c | 5 +++++

1 file changed, 5 insertions(+)
hw/i386/pc_sysfw_ovmf-stubs.c +0 -0
index aabe78b271..b53906a052 100644

hw/i386/pc_sysfw_ovmf-stubs.c void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size) · line 31

Quoted 8 lines
hw/i386/pc_sysfw_ovmf-stubs.c +5 -0
@@ -24,3 +24,8 @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size)
 {
    g_assert_not_reached();
 }
+
+void x86_firmware_configure(hwaddr gpa, void *ptr, int size)
+{
+    g_assert_not_reached();
+}

This change alone won’t work for the CONFIG_PC case. I need to move x86_firmware_configure() to pc_sysfw_ovmf.c Will fix in v2 after I run my changes through CI.

Quoted 3 lines
Signature · 1 line
2.42.0
author
#3 lore raw

PATCH 2/2 i386/hyperv: add stubs for synic enablement

In reply to Ani Sinha

Add a new call hyperv_enable_synic() that can be called whether or not CONFIG_HYPERV is enabled. This way genetic code in i396/kvm.c can call this function to enable synic for hyperv. For non-hyperv cases, the stub will be a noop.

---
 target/i386/kvm/hyperv-stub.c |  5 +++++
 target/i386/kvm/hyperv.c      |  9 +++++++++
 target/i386/kvm/hyperv.h      |  1 +
 target/i386/kvm/kvm.c         | 12 +++++-------
 4 files changed, 20 insertions(+), 7 deletions(-)
target/i386/kvm/hyperv-stub.c +5 -0
index 5836f53c23..767a4c7e1a 100644
@@ -61,3 +61,8 @@ uint64_t hyperv_syndbg_query_options(void)
 {
     return 0;
 }
+
+int hyperv_enable_synic(X86CPU *cpu)
+{
+    return 0;
+}
target/i386/kvm/hyperv.c +9 -0
index f7a81bd270..bd3c26d02b 100644
@@ -24,6 +24,15 @@ int hyperv_x86_synic_add(X86CPU *cpu)
     return 0;
 }
 
+int hyperv_enable_synic(X86CPU *cpu)
+{
+    int ret = 0;
+    if (!hyperv_is_synic_enabled()) {
+        ret = hyperv_x86_synic_add(cpu);
+    }
+    return ret;
+}
+
 /*
  * All devices possibly using SynIC have to be reset before calling this to let
  * them remove their SINT routes first.
target/i386/kvm/hyperv.h +1 -0
index e45a4512fe..a393a5d428 100644
@@ -23,6 +23,7 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit);
 #endif
 
 int hyperv_x86_synic_add(X86CPU *cpu);
+int hyperv_enable_synic(X86CPU *cpu);
 void hyperv_x86_synic_reset(X86CPU *cpu);
 void hyperv_x86_synic_update(X86CPU *cpu);
 
target/i386/kvm/kvm.c +5 -7
index a29f757c16..9e352882c8 100644
@@ -1754,13 +1754,11 @@ static int hyperv_init_vcpu(X86CPU *cpu)
             return ret;
         }
 
-        if (!hyperv_is_synic_enabled()) {
-            ret = hyperv_x86_synic_add(cpu);
-            if (ret < 0) {
-                error_report("failed to create HyperV SynIC: %s",
-                             strerror(-ret));
-                return ret;
-            }
+        ret = hyperv_enable_synic(cpu);
+        if (ret < 0) {
+            error_report("failed to create HyperV SynIC: %s",
+                         strerror(-ret));
+            return ret;
         }
     }
 
Signature · 1 line
2.42.0
#4 lore raw

Re: [PATCH for-11.0 2/2] i386/hyperv: add stubs for synic enablement

Hi Ani,

Quoted 72 lines · Ani Sinha

Add a new call hyperv_enable_synic() that can be called whether or not CONFIG_HYPERV is enabled. This way genetic code in i396/kvm.c can call this function to enable synic for hyperv. For non-hyperv cases, the stub will be a noop.

---
  target/i386/kvm/hyperv-stub.c |  5 +++++
  target/i386/kvm/hyperv.c      |  9 +++++++++
  target/i386/kvm/hyperv.h      |  1 +
  target/i386/kvm/kvm.c         | 12 +++++-------
  4 files changed, 20 insertions(+), 7 deletions(-)
target/i386/kvm/hyperv-stub.c +5 -0
index 5836f53c23..767a4c7e1a 100644
@@ -61,3 +61,8 @@ uint64_t hyperv_syndbg_query_options(void)
  {
      return 0;
  }
+
+int hyperv_enable_synic(X86CPU *cpu)
+{
+    return 0;
+}
target/i386/kvm/hyperv.c +9 -0
index f7a81bd270..bd3c26d02b 100644
@@ -24,6 +24,15 @@ int hyperv_x86_synic_add(X86CPU *cpu)
      return 0;
  }
 
+int hyperv_enable_synic(X86CPU *cpu)
+{
+    int ret = 0;
+    if (!hyperv_is_synic_enabled()) {
+        ret = hyperv_x86_synic_add(cpu);
+    }
+    return ret;
+}
+
  /*
   * All devices possibly using SynIC have to be reset before calling this to let
   * them remove their SINT routes first.
target/i386/kvm/hyperv.h +1 -0
index e45a4512fe..a393a5d428 100644
@@ -23,6 +23,7 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit);
  #endif
 
  int hyperv_x86_synic_add(X86CPU *cpu);
+int hyperv_enable_synic(X86CPU *cpu);
  void hyperv_x86_synic_reset(X86CPU *cpu);
  void hyperv_x86_synic_update(X86CPU *cpu);
 
target/i386/kvm/kvm.c +0 -5
index a29f757c16..9e352882c8 100644
@@ -1754,13 +1754,11 @@ static int hyperv_init_vcpu(X86CPU *cpu)
              return ret;
          }
 
-        if (!hyperv_is_synic_enabled()) {
-            ret = hyperv_x86_synic_add(cpu);
-            if (ret < 0) {
-                error_report("failed to create HyperV SynIC: %s",
-                             strerror(-ret));

target/i386/kvm/kvm.c static int hyperv_init_vcpu(X86CPU *cpu) · line 1764

Quoted 10 lines
target/i386/kvm/kvm.c +5 -2
-                return ret;
-            }
+        ret = hyperv_enable_synic(cpu);
+        if (ret < 0) {
+            error_report("failed to create HyperV SynIC: %s",
+                         strerror(-ret));
+            return ret;
          }
      }
 

Why not simply add a hyperv_is_synic_enabled() stub?

author
#5 lore raw

Re: [PATCH for-11.0 2/2] i386/hyperv: add stubs for synic enablement

Quoted 77 lines · Philippe Mathieu-Daudé

Hi Ani,

Quoted 70 lines · Ani Sinha

Add a new call hyperv_enable_synic() that can be called whether or not CONFIG_HYPERV is enabled. This way genetic code in i396/kvm.c can call this function to enable synic for hyperv. For non-hyperv cases, the stub will be a noop.

---
 target/i386/kvm/hyperv-stub.c |  5 +++++
 target/i386/kvm/hyperv.c      |  9 +++++++++
 target/i386/kvm/hyperv.h      |  1 +
 target/i386/kvm/kvm.c         | 12 +++++-------
 4 files changed, 20 insertions(+), 7 deletions(-)
target/i386/kvm/hyperv-stub.c +5 -0
index 5836f53c23..767a4c7e1a 100644
@@ -61,3 +61,8 @@ uint64_t hyperv_syndbg_query_options(void)
 {
     return 0;
 }
+
+int hyperv_enable_synic(X86CPU *cpu)
+{
+    return 0;
+}
target/i386/kvm/hyperv.c +8 -0
index f7a81bd270..bd3c26d02b 100644
@@ -24,6 +24,15 @@ int hyperv_x86_synic_add(X86CPU *cpu)
     return 0;
 }
 +int hyperv_enable_synic(X86CPU *cpu)
+{
+    int ret = 0;
+    if (!hyperv_is_synic_enabled()) {
+        ret = hyperv_x86_synic_add(cpu);
+    }
+    return ret;
+}
+
 /*
  * All devices possibly using SynIC have to be reset before calling this to let
  * them remove their SINT routes first.
target/i386/kvm/hyperv.h +1 -0
index e45a4512fe..a393a5d428 100644
@@ -23,6 +23,7 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit);
 #endif
   int hyperv_x86_synic_add(X86CPU *cpu);
+int hyperv_enable_synic(X86CPU *cpu);
 void hyperv_x86_synic_reset(X86CPU *cpu);
 void hyperv_x86_synic_update(X86CPU *cpu);
 diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c

index a29f757c16..9e352882c8 100644

target/i386/kvm/kvm.c +2 -6
@@ -1754,13 +1754,11 @@ static int hyperv_init_vcpu(X86CPU *cpu)
             return ret;
         }
 -        if (!hyperv_is_synic_enabled()) {
-            ret = hyperv_x86_synic_add(cpu);
-            if (ret < 0) {
-                error_report("failed to create HyperV SynIC: %s",
-                             strerror(-ret));
-                return ret;
-            }
+        ret = hyperv_enable_synic(cpu);
+        if (ret < 0) {
Quoted 8 lines

target/i386/kvm/kvm.c static int hyperv_init_vcpu(X86CPU *cpu) · line 1764

Quoted 6 lines
target/i386/kvm/kvm.c +3 -0
+            error_report("failed to create HyperV SynIC: %s",
+                         strerror(-ret));
+            return ret;
         }
     }
 

Why not simply add a hyperv_is_synic_enabled() stub?

That would be wrong unless I assert in hyperv_is_synic_enabled() stub function which would break minimal microvms?
The other reason is I do not like hyperv_x86_synic_add() returning -ENOSYS. If hyperv is not enabled we do not need to call those functions at all.