Skip to contentSkip to conversation

target/i386: Cleanups around KVM declarations

PATCH In review Philippe Mathieu-Daudé 3 participants 21 messages Sep 4, 2023 – Sep 9, 2023

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

cover target/i386: Cleanups around KVM declarations

Hi,

Mostly trivial cleanups.

We want to have QEMU core code accel-agnostic. (In particular, removing the KVM specific fields from CPUState).

This serie contains the x86 specific patches before starting with the generic KVM code.

FWIW, I couldn't test the 'HVF only' configuration since I don't have access to such host.

Regards,

Phil.

Philippe Mathieu-Daudé (13):
hw/i386/pc: Include missing 'sysemu/tcg.h' header hw/i386/pc: Include missing 'cpu.h' header
hw/i386/fw_cfg: Include missing 'cpu.h' header target/i386/helper: Restrict KVM declarations to system emulation target/i386/cpu-sysemu: Inline kvm_apic_in_kernel() target/i386: Remove unused KVM stubs
target/i386: Allow elision of kvm_enable_x2apic() target/i386: Allow elision of kvm_hv_vpindex_settable() target/i386: Restrict declarations specific to CONFIG_KVM sysemu/kvm: Restrict kvm_arch_get_supported_cpuid/msr() to x86 targets sysemu/kvm: Restrict kvm_get_apic_state() to x86 targets sysemu/kvm: Restrict kvm_has_pit_state2() to x86 targets sysemu/kvm: Restrict kvm_pc_setup_irq_routing() to x86 targets

 include/sysemu/kvm.h        | 10 --------
 target/i386/kvm/kvm_i386.h  | 36 ++++++++++++++++----------
 hw/i386/fw_cfg.c            |  1 +
 hw/i386/intel_iommu.c       |  2 +-
 hw/i386/kvm/i8254.c         |  1 +
 hw/i386/kvm/ioapic.c        |  1 +
 hw/i386/pc_piix.c           |  1 +
 hw/i386/pc_q35.c            |  2 ++
 hw/i386/x86.c               |  4 +--
 target/i386/cpu-sysemu.c    |  4 +--
 target/i386/helper.c        |  2 +-
 target/i386/kvm/kvm-stub.c  | 51 -------------------------------------
 target/i386/kvm/kvm.c       |  4 +--
 target/i386/kvm/meson.build |  2 --
 14 files changed, 37 insertions(+), 84 deletions(-)
 delete mode 100644 target/i386/kvm/kvm-stub.c
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/13 hw/i386/pc: Include missing 'sysemu/tcg.h' header

Since commit 6f529b7534 ("target/i386: move FERR handling to target/i386") pc_q35_init() calls tcg_enabled() which is declared in "sysemu/tcg.h".

---
 hw/i386/pc_q35.c | 1 +
 1 file changed, 1 insertion(+)
hw/i386/pc_q35.c +1 -0
index 37c4814bed..43413dd1ac 100644
@@ -34,6 +34,7 @@
 #include "hw/loader.h"
 #include "hw/i2c/smbus_eeprom.h"
 #include "hw/rtc/mc146818rtc.h"
+#include "sysemu/tcg.h"
 #include "sysemu/kvm.h"
 #include "hw/kvm/clock.h"
 #include "hw/pci-host/q35.h"
Signature · 1 line
2.41.0
#3 lore raw

PATCH 2/13 hw/i386/pc: Include missing 'cpu.h' header

In reply to Philippe Mathieu-Daudé

Both pc_piix.c and pc_q35.c files use CPU_VERSION_LEGACY which is defined in "target/i386/cpu.h".

---
 hw/i386/pc_piix.c | 1 +
 hw/i386/pc_q35.c  | 1 +
 2 files changed, 2 insertions(+)
hw/i386/pc_piix.c +1 -0
index ce1ac95274..f0df12f6fa 100644
@@ -69,6 +69,7 @@
 #include "hw/mem/nvdimm.h"
 #include "hw/i386/acpi-build.h"
 #include "kvm/kvm-cpu.h"
+#include "target/i386/cpu.h"
 
 #define MAX_IDE_BUS 2
 #define XEN_IOAPIC_NUM_PIRQS 128ULL
hw/i386/pc_q35.c +1 -0
index 43413dd1ac..8ecc78c822 100644
@@ -58,6 +58,7 @@
 #include "hw/hyperv/vmbus-bridge.h"
 #include "hw/mem/nvdimm.h"
 #include "hw/i386/acpi-build.h"
+#include "target/i386/cpu.h"
 
 /* ICH9 AHCI has 6 ports */
 #define MAX_SATA_PORTS     6
Signature · 1 line
2.41.0
#5 lore raw

PATCH 3/13 hw/i386/fw_cfg: Include missing 'cpu.h' header

In reply to Philippe Mathieu-Daudé

fw_cfg_build_feature_control() uses CPUID_EXT_VMX which is defined in "target/i386/cpu.h".

---
 hw/i386/fw_cfg.c | 1 +
 1 file changed, 1 insertion(+)
hw/i386/fw_cfg.c +1 -0
index 72a42f3c66..7362daa45a 100644
@@ -24,6 +24,7 @@
 #include "kvm/kvm_i386.h"
 #include "qapi/error.h"
 #include CONFIG_DEVICES
+#include "target/i386/cpu.h"
 
 struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX};
 
Signature · 1 line
2.41.0
#7 lore raw

PATCH 4/13 target/i386/helper: Restrict KVM declarations to system emulation

In reply to Philippe Mathieu-Daudé

User emulation doesn't need any KVM declarations.

---
 target/i386/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/helper.c +1 -1
index 89aa696c6d..2070dd0dda 100644
@@ -22,10 +22,10 @@
 #include "cpu.h"
 #include "exec/exec-all.h"
 #include "sysemu/runstate.h"
-#include "kvm/kvm_i386.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/hw_accel.h"
 #include "monitor/monitor.h"
+#include "kvm/kvm_i386.h"
 #endif
 #include "qemu/log.h"
 #ifdef CONFIG_TCG
Signature · 1 line
2.41.0
#9 lore raw

PATCH 5/13 target/i386/cpu-sysemu: Inline kvm_apic_in_kernel()

In reply to Philippe Mathieu-Daudé

In order to have cpu-sysemu.c become accelerator-agnostic, inline kvm_apic_in_kernel() -- which is a simple wrapper to kvm_irqchip_in_kernel() -- and use the generic "sysemu/kvm.h" header.

---
 target/i386/kvm/kvm_i386.h | 2 --
 target/i386/cpu-sysemu.c   | 4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)
target/i386/kvm/kvm_i386.h +0 -2
index e24753abfe..470627b750 100644
@@ -13,8 +13,6 @@
 
 #include "sysemu/kvm.h"
 
-#define kvm_apic_in_kernel() (kvm_irqchip_in_kernel())
-
 #ifdef CONFIG_KVM
 
 #define kvm_pit_in_kernel() \
target/i386/cpu-sysemu.c +2 -2
index 28115edf44..2375e48178 100644
@@ -19,9 +19,9 @@
 
 #include "qemu/osdep.h"
 #include "cpu.h"
+#include "sysemu/kvm.h"
 #include "sysemu/xen.h"
 #include "sysemu/whpx.h"
-#include "kvm/kvm_i386.h"
 #include "qapi/error.h"
 #include "qapi/qapi-visit-run-state.h"
 #include "qapi/qmp/qdict.h"
@@ -253,7 +253,7 @@ APICCommonClass *apic_get_class(Error **errp)
 
     /* TODO: in-kernel irqchip for hvf */
     if (kvm_enabled()) {
-        if (!kvm_apic_in_kernel()) {
+        if (!kvm_irqchip_in_kernel()) {
             error_setg(errp, "KVM does not support userspace APIC");
             return NULL;
         }
Signature · 1 line
2.41.0
Reviewed-by on v1 5/13
#10 lore raw

Re: [PATCH 05/13] target/i386/cpu-sysemu: Inline kvm_apic_in_kernel()

Quoted 10 lines · Philippe Mathieu-Daudé

In order to have cpu-sysemu.c become accelerator-agnostic, inline kvm_apic_in_kernel() -- which is a simple wrapper to kvm_irqchip_in_kernel() -- and use the generic "sysemu/kvm.h" header.

---
  target/i386/kvm/kvm_i386.h | 2 --
  target/i386/cpu-sysemu.c   | 4 ++--
  2 files changed, 2 insertions(+), 4 deletions(-)

r~

#11 lore raw

PATCH 6/13 target/i386: Remove unused KVM stubs

In reply to Philippe Mathieu-Daudé

All these functions:

- kvm_arch_get_supported_cpuid()
- kvm_has_smm(()
- kvm_hyperv_expand_features()
- kvm_set_max_apic_id()

are called after checking for kvm_enabled(), which is false when KVM is not built. Since the compiler elides these functions, their stubs are not used and can be removed.

---
 target/i386/kvm/kvm-stub.c | 26 --------------------------
 1 file changed, 26 deletions(-)
target/i386/kvm/kvm-stub.c +0 -26
index e052f1c7b0..f985d9a1d3 100644
@@ -10,42 +10,16 @@
  *
  */
 #include "qemu/osdep.h"
-#include "cpu.h"
 #include "kvm_i386.h"
 
 #ifndef __OPTIMIZE__
-bool kvm_has_smm(void)
-{
-    return 1;
-}
-
 bool kvm_enable_x2apic(void)
 {
     return false;
 }
-
-/* This function is only called inside conditionals which we
- * rely on the compiler to optimize out when CONFIG_KVM is not
- * defined.
- */
-uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
-                                      uint32_t index, int reg)
-{
-    abort();
-}
 #endif
 
 bool kvm_hv_vpindex_settable(void)
 {
     return false;
 }
-
-bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp)
-{
-    abort();
-}
-
-void kvm_set_max_apic_id(uint32_t max_apic_id)
-{
-    return;
-}
Signature · 1 line
2.41.0
#12 lore raw

PATCH 7/13 target/i386: Allow elision of kvm_enable_x2apic()

In reply to Philippe Mathieu-Daudé

Call kvm_enabled() before kvm_enable_x2apic() to
let the compiler elide its call.

---
 hw/i386/intel_iommu.c      | 2 +-
 hw/i386/x86.c              | 2 +-
 target/i386/kvm/kvm-stub.c | 7 -------
 3 files changed, 2 insertions(+), 9 deletions(-)
hw/i386/intel_iommu.c +1 -1
index 3ca71df369..c9961ef752 100644
@@ -4053,7 +4053,7 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp)
             error_setg(errp, "eim=on requires accel=kvm,kernel-irqchip=split");
             return false;
         }
-        if (!kvm_enable_x2apic()) {
+        if (kvm_enabled() && !kvm_enable_x2apic()) {
             error_setg(errp, "eim=on requires support on the KVM side"
                              "(X2APIC_API, first shipped in v4.7)");
             return false;
hw/i386/x86.c +1 -1
index a88a126123..d2920af792 100644
@@ -136,7 +136,7 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
      * With KVM's in-kernel lapic: only if X2APIC API is enabled.
      */
     if (x86ms->apic_id_limit > 255 && !xen_enabled() &&
-        (!kvm_irqchip_in_kernel() || !kvm_enable_x2apic())) {
+        kvm_enabled() && (!kvm_irqchip_in_kernel() || !kvm_enable_x2apic())) {
         error_report("current -smp configuration requires kernel "
                      "irqchip and X2APIC API support.");
         exit(EXIT_FAILURE);
target/i386/kvm/kvm-stub.c +0 -7
index f985d9a1d3..62cccebee4 100644
@@ -12,13 +12,6 @@
 #include "qemu/osdep.h"
 #include "kvm_i386.h"
 
-#ifndef __OPTIMIZE__
-bool kvm_enable_x2apic(void)
-{
-    return false;
-}
-#endif
-
 bool kvm_hv_vpindex_settable(void)
 {
     return false;
Signature · 1 line
2.41.0
maintainer
#13 lore raw

Re: [PATCH 07/13] target/i386: Allow elision of kvm_enable_x2apic()

Quoted 29 lines · Philippe Mathieu-Daudé

Call kvm_enabled() before kvm_enable_x2apic() to
let the compiler elide its call.

---
  hw/i386/intel_iommu.c      | 2 +-
  hw/i386/x86.c              | 2 +-
  target/i386/kvm/kvm-stub.c | 7 -------
  3 files changed, 2 insertions(+), 9 deletions(-)
hw/i386/intel_iommu.c +1 -1
index 3ca71df369..c9961ef752 100644
@@ -4053,7 +4053,7 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp)
              error_setg(errp, "eim=on requires accel=kvm,kernel-irqchip=split");
              return false;
          }
-        if (!kvm_enable_x2apic()) {
+        if (kvm_enabled() && !kvm_enable_x2apic()) {
              error_setg(errp, "eim=on requires support on the KVM side"
                               "(X2APIC_API, first shipped in v4.7)");
              return false;
hw/i386/x86.c +0 -0
index a88a126123..d2920af792 100644

hw/i386/x86.c void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) · line 139

Quoted 5 lines
hw/i386/x86.c +1 -1
@@ -136,7 +136,7 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
       * With KVM's in-kernel lapic: only if X2APIC API is enabled.
       */
      if (x86ms->apic_id_limit > 255 && !xen_enabled() &&
-        (!kvm_irqchip_in_kernel() || !kvm_enable_x2apic())) {
+        kvm_enabled() && (!kvm_irqchip_in_kernel() || !kvm_enable_x2apic())) {

This "!xen && kvm" expression can be simplified.

I am queuing the series with this squashed in:

hw/i386/x86.c +4 -7
index d2920af792d..3e86cf3060f 100644
@@ -129,14 +129,11 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
                                                       ms->smp.max_cpus - 1) + 1;
 
     /*
-     * Can we support APIC ID 255 or higher?
-     *
-     * Under Xen: yes.
-     * With userspace emulated lapic: no
-     * With KVM's in-kernel lapic: only if X2APIC API is enabled.
+     * Can we support APIC ID 255 or higher?  With KVM, that requires
+     * both in-kernel lapic and X2APIC userspace API.
      */
-    if (x86ms->apic_id_limit > 255 && !xen_enabled() &&
-        kvm_enabled() && (!kvm_irqchip_in_kernel() || !kvm_enable_x2apic())) {
+    if (x86ms->apic_id_limit > 255 && kvm_enabled() &&
+        (!kvm_irqchip_in_kernel() || !kvm_enable_x2apic())) {
         error_report("current -smp configuration requires kernel "
                      "irqchip and X2APIC API support.");
         exit(EXIT_FAILURE);

Paolo

Quoted 21 lines
hw/i386/x86.c +0 -0
          error_report("current -smp configuration requires kernel "
                       "irqchip and X2APIC API support.");
          exit(EXIT_FAILURE);
target/i386/kvm/kvm-stub.c +0 -7
index f985d9a1d3..62cccebee4 100644
@@ -12,13 +12,6 @@
  #include "qemu/osdep.h"
  #include "kvm_i386.h"
 
-#ifndef __OPTIMIZE__
-bool kvm_enable_x2apic(void)
-{
-    return false;
-}
-#endif
-
  bool kvm_hv_vpindex_settable(void)
  {
      return false;
#14 lore raw

Re: [PATCH 07/13] target/i386: Allow elision of kvm_enable_x2apic()

Quoted 57 lines · Paolo Bonzini
Quoted 20 lines · Philippe Mathieu-Daudé

Call kvm_enabled() before kvm_enable_x2apic() to
let the compiler elide its call.

---
  hw/i386/intel_iommu.c      | 2 +-
  hw/i386/x86.c              | 2 +-
  target/i386/kvm/kvm-stub.c | 7 -------

  3 files changed, 2 insertions(+), 9 deletions(-)
hw/i386/x86.c +0 -0
index a88a126123..d2920af792 100644
@@ -136,7 +136,7 @@ void x86_cpus_init(X86MachineState *x86ms, int 
 default_cpu_version)
        * With KVM's in-kernel lapic: only if X2APIC API is enabled.
        */
Quoted 4 lines

      if (x86ms->apic_id_limit > 255 && !xen_enabled() && -        (!kvm_irqchip_in_kernel() || !kvm_enable_x2apic())) { +        kvm_enabled() && (!kvm_irqchip_in_kernel() || !kvm_enable_x2apic())) {

This "!xen && kvm" expression can be simplified.

I am queuing the series with this squashed in:

hw/i386/x86.c +4 -8
index d2920af792d..3e86cf3060f 100644
@@ -129,14 +129,11 @@ void x86_cpus_init(X86MachineState *x86ms, int 
 default_cpu_version)
                                                        ms->smp.max_cpus 
- 1) + 1;
 
      /*
-     * Can we support APIC ID 255 or higher?
-     *
-     * Under Xen: yes.
-     * With userspace emulated lapic: no
-     * With KVM's in-kernel lapic: only if X2APIC API is enabled.
+     * Can we support APIC ID 255 or higher?  With KVM, that requires
+     * both in-kernel lapic and X2APIC userspace API.
       */
-    if (x86ms->apic_id_limit > 255 && !xen_enabled() &&
-        kvm_enabled() && (!kvm_irqchip_in_kernel() || 
 !kvm_enable_x2apic())) {
+    if (x86ms->apic_id_limit > 255 && kvm_enabled() &&
+        (!kvm_irqchip_in_kernel() || !kvm_enable_x2apic())) {
          error_report("current -smp configuration requires kernel "
                       "irqchip and X2APIC API support.");
          exit(EXIT_FAILURE);
Quoted 1 line

Paolo

Thank you!

#15 lore raw

PATCH 8/13 target/i386: Allow elision of kvm_hv_vpindex_settable()

In reply to Philippe Mathieu-Daudé

Call kvm_enabled() before kvm_hv_vpindex_settable() to let the compiler elide its call.

kvm-stub.c is now empty, remove it.

---
 hw/i386/x86.c               |  2 +-
 target/i386/kvm/kvm-stub.c  | 18 ------------------
 target/i386/kvm/meson.build |  2 --
 3 files changed, 1 insertion(+), 21 deletions(-)
 delete mode 100644 target/i386/kvm/kvm-stub.c
hw/i386/x86.c +1 -1
index d2920af792..ecf16ef402 100644
@@ -424,7 +424,7 @@ void x86_cpu_pre_plug(HotplugHandler *hotplug_dev,
     cpu->thread_id = topo_ids.smt_id;
 
     if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX) &&
-        !kvm_hv_vpindex_settable()) {
+        kvm_enabled() && !kvm_hv_vpindex_settable()) {
         error_setg(errp, "kernel doesn't allow setting HyperV VP_INDEX");
         return;
     }
target/i386/kvm/kvm-stub.c deleted +0 -18
deleted file mode 100644
index 62cccebee4..0000000000
@@ -1,18 +0,0 @@
-/*
- * QEMU KVM x86 specific function stubs
- *
- * Copyright Linaro Limited 2012
- *
- * Author: Peter Maydell <[email protected]>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- *
- */
-#include "qemu/osdep.h"
-#include "kvm_i386.h"
-
-bool kvm_hv_vpindex_settable(void)
-{
-    return false;
-}
target/i386/kvm/meson.build +0 -2
index 40fbde96ca..5d9174bbb5 100644
@@ -1,5 +1,3 @@
-i386_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
-
 i386_softmmu_kvm_ss = ss.source_set()
 
 i386_softmmu_kvm_ss.add(files(
Signature · 1 line
2.41.0
#16 lore raw

PATCH 9/13 target/i386: Restrict declarations specific to CONFIG_KVM

In reply to Philippe Mathieu-Daudé

Keep the function accessed by target/i386/ and hw/i386/ exposed, restrict the ones accessed by target/i386/kvm/.

---
 target/i386/kvm/kvm_i386.h | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
target/i386/kvm/kvm_i386.h +17 -12
index 470627b750..ff309bad25 100644
@@ -31,30 +31,35 @@
 #endif  /* CONFIG_KVM */
 
 bool kvm_has_smm(void);
-bool kvm_has_adjust_clock(void);
-bool kvm_has_adjust_clock_stable(void);
-bool kvm_has_exception_payload(void);
-void kvm_synchronize_all_tsc(void);
+bool kvm_enable_x2apic(void);
+bool kvm_hv_vpindex_settable(void);
+
+bool kvm_enable_sgx_provisioning(KVMState *s);
+bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp);
+
 void kvm_arch_reset_vcpu(X86CPU *cs);
 void kvm_arch_after_reset_vcpu(X86CPU *cpu);
 void kvm_arch_do_init_vcpu(X86CPU *cs);
 
+void kvm_set_max_apic_id(uint32_t max_apic_id);
+void kvm_request_xsave_components(X86CPU *cpu, uint64_t mask);
+
+#ifdef CONFIG_KVM
+
+bool kvm_has_adjust_clock(void);
+bool kvm_has_adjust_clock_stable(void);
+bool kvm_has_exception_payload(void);
+void kvm_synchronize_all_tsc(void);
+
 void kvm_put_apicbase(X86CPU *cpu, uint64_t value);
 
-bool kvm_enable_x2apic(void);
 bool kvm_has_x2apic_api(void);
 bool kvm_has_waitpkg(void);
 
-bool kvm_hv_vpindex_settable(void);
-bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp);
-
 uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address);
 void kvm_update_msi_routes_all(void *private, bool global,
                                uint32_t index, uint32_t mask);
 
-bool kvm_enable_sgx_provisioning(KVMState *s);
-void kvm_request_xsave_components(X86CPU *cpu, uint64_t mask);
-
 typedef bool QEMURDMSRHandler(X86CPU *cpu, uint32_t msr, uint64_t *val);
 typedef bool QEMUWRMSRHandler(X86CPU *cpu, uint32_t msr, uint64_t val);
 typedef struct kvm_msr_handlers {
@@ -66,6 +71,6 @@ typedef struct kvm_msr_handlers {
 bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdmsr,
                     QEMUWRMSRHandler *wrmsr);
 
-void kvm_set_max_apic_id(uint32_t max_apic_id);
+#endif /* CONFIG_KVM */
 
 #endif
Signature · 1 line
2.41.0
#17 lore raw

PATCH 10/13 sysemu/kvm: Restrict kvm_arch_get_supported_cpuid/msr() to x86 targets

In reply to Philippe Mathieu-Daudé

kvm_arch_get_supported_cpuid() / kvm_arch_get_supported_msr_feature() are only defined for x86 targets (in target/i386/kvm/kvm.c). Their declarations are pointless on other targets.

---
 include/sysemu/kvm.h       | 5 -----
 target/i386/kvm/kvm_i386.h | 3 +++
 2 files changed, 3 insertions(+), 5 deletions(-)
include/sysemu/kvm.h +0 -5
index ebdca41052..a578961a5e 100644
@@ -464,11 +464,6 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);
         kvm_vcpu_ioctl(cpu, KVM_ENABLE_CAP, &cap);                   \
     })
 
-uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
-                                      uint32_t index, int reg);
-uint64_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index);
-
-
 void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len);
 
 int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,
target/i386/kvm/kvm_i386.h +3 -0
index ff309bad25..b78e2feb49 100644
@@ -40,6 +40,9 @@ bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp);
 void kvm_arch_reset_vcpu(X86CPU *cs);
 void kvm_arch_after_reset_vcpu(X86CPU *cpu);
 void kvm_arch_do_init_vcpu(X86CPU *cs);
+uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
+                                      uint32_t index, int reg);
+uint64_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index);
 
 void kvm_set_max_apic_id(uint32_t max_apic_id);
 void kvm_request_xsave_components(X86CPU *cpu, uint64_t mask);
Signature · 1 line
2.41.0
#18 lore raw

PATCH 11/13 sysemu/kvm: Restrict kvm_get_apic_state() to x86 targets

In reply to Philippe Mathieu-Daudé

kvm_get_apic_state() is only defined for x86 targets (in hw/i386/kvm/apic.c). Its declaration is pointless on all other targets.

Since we include "linux-headers/asm-x86/kvm.h", no need to forward-declare 'struct kvm_lapic_state'.

---
 include/sysemu/kvm.h       | 3 ---
 target/i386/kvm/kvm_i386.h | 1 +
 2 files changed, 1 insertion(+), 3 deletions(-)
include/sysemu/kvm.h +0 -3
index a578961a5e..4326b53f90 100644
@@ -188,7 +188,6 @@ extern bool kvm_msi_use_devid;
 #endif  /* CONFIG_KVM_IS_POSSIBLE */
 
 struct kvm_run;
-struct kvm_lapic_state;
 struct kvm_irq_routing_entry;
 
 typedef struct KVMCapabilityInfo {
@@ -407,8 +406,6 @@ void kvm_irqchip_add_change_notifier(Notifier *n);
 void kvm_irqchip_remove_change_notifier(Notifier *n);
 void kvm_irqchip_change_notify(void);
 
-void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic);
-
 struct kvm_guest_debug;
 struct kvm_debug_exit_arch;
 
target/i386/kvm/kvm_i386.h +1 -0
index b78e2feb49..d4a1239c68 100644
@@ -54,6 +54,7 @@ bool kvm_has_adjust_clock_stable(void);
 bool kvm_has_exception_payload(void);
 void kvm_synchronize_all_tsc(void);
 
+void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic);
 void kvm_put_apicbase(X86CPU *cpu, uint64_t value);
 
 bool kvm_has_x2apic_api(void);
Signature · 1 line
2.41.0
#19 lore raw

PATCH 12/13 sysemu/kvm: Restrict kvm_has_pit_state2() to x86 targets

In reply to Philippe Mathieu-Daudé

kvm_has_pit_state2() is only defined for x86 targets (in target/i386/kvm/kvm.c). Its declaration is pointless on all other targets. Have it return a boolean.

---
 include/sysemu/kvm.h       | 1 -
 target/i386/kvm/kvm_i386.h | 1 +
 hw/i386/kvm/i8254.c        | 1 +
 target/i386/kvm/kvm.c      | 4 ++--
 4 files changed, 4 insertions(+), 3 deletions(-)
include/sysemu/kvm.h +0 -1
index 4326b53f90..147967422f 100644
@@ -221,7 +221,6 @@ int kvm_has_vcpu_events(void);
 int kvm_has_robust_singlestep(void);
 int kvm_has_debugregs(void);
 int kvm_max_nested_state_length(void);
-int kvm_has_pit_state2(void);
 int kvm_has_many_ioeventfds(void);
 int kvm_has_gsi_routing(void);
 int kvm_has_intx_set_mask(void);
target/i386/kvm/kvm_i386.h +1 -0
index d4a1239c68..76e8f952e5 100644
@@ -33,6 +33,7 @@
 bool kvm_has_smm(void);
 bool kvm_enable_x2apic(void);
 bool kvm_hv_vpindex_settable(void);
+bool kvm_has_pit_state2(void);
 
 bool kvm_enable_sgx_provisioning(KVMState *s);
 bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp);
hw/i386/kvm/i8254.c +1 -0
index 6a7383d877..a649b2b7ca 100644
@@ -34,6 +34,7 @@
 #include "hw/timer/i8254_internal.h"
 #include "hw/qdev-properties-system.h"
 #include "sysemu/kvm.h"
+#include "target/i386/kvm/kvm_i386.h"
 #include "qom/object.h"
 
 #define KVM_PIT_REINJECT_BIT 0
target/i386/kvm/kvm.c +2 -2
index 639a242ad8..e5cd7cc806 100644
@@ -154,9 +154,9 @@ static KVMMSRHandlers msr_handlers[KVM_MSR_FILTER_MAX_RANGES];
 static RateLimit bus_lock_ratelimit_ctrl;
 static int kvm_get_one_msr(X86CPU *cpu, int index, uint64_t *value);
 
-int kvm_has_pit_state2(void)
+bool kvm_has_pit_state2(void)
 {
-    return has_pit_state2;
+    return !!has_pit_state2;
 }
 
 bool kvm_has_smm(void)
Signature · 1 line
2.41.0
#20 lore raw

PATCH 13/13 sysemu/kvm: Restrict kvm_pc_setup_irq_routing() to x86 targets

In reply to Philippe Mathieu-Daudé

kvm_pc_setup_irq_routing() is only defined for x86 targets (in hw/i386/kvm/apic.c). Its declaration is pointless on all other targets.

---
 include/sysemu/kvm.h       | 1 -
 target/i386/kvm/kvm_i386.h | 2 ++
 hw/i386/kvm/ioapic.c       | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)
include/sysemu/kvm.h +0 -1
index 147967422f..ee9025f8e9 100644
@@ -514,7 +514,6 @@ int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
 int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n,
                                       qemu_irq irq);
 void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi);
-void kvm_pc_setup_irq_routing(bool pci_enabled);
 void kvm_init_irq_routing(KVMState *s);
 
 bool kvm_kernel_irqchip_allowed(void);
target/i386/kvm/kvm_i386.h +2 -0
index 76e8f952e5..55d4e68c34 100644
@@ -78,4 +78,6 @@ bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdmsr,
 
 #endif /* CONFIG_KVM */
 
+void kvm_pc_setup_irq_routing(bool pci_enabled);
+
 #endif
hw/i386/kvm/ioapic.c +1 -0
index cd5ea5d60b..409d0c8c76 100644
@@ -16,6 +16,7 @@
 #include "hw/intc/ioapic_internal.h"
 #include "hw/intc/kvm_irqcount.h"
 #include "sysemu/kvm.h"
+#include "kvm/kvm_i386.h"
 
 /* PC Utility function */
 void kvm_pc_setup_irq_routing(bool pci_enabled)
Signature · 1 line
2.41.0