Skip to contentSkip to conversation

accel/kvm: Spring cleaning

PATCH In review Philippe Mathieu-Daudé 9 participants 33 messages Apr 5, 2023 – Jun 6, 2023

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

cover accel/kvm: Spring cleaning

Misc KVM-related cleanup patches split from a bigger "extract KVM specific fields from CPUState" series.

Philippe Mathieu-Daudé (10):
sysemu/kvm: Remove unused headers
accel/kvm: Declare kvm_direct_msi_allowed in stubs hw/intc/arm_gic: Un-inline GIC*/ITS class_name() helpers hw/intc/arm_gic: Rename 'first_cpu' argument hw/arm/sbsa-ref: Include missing 'sysemu/kvm.h' header target/arm: Reduce QMP header pressure by not including 'kvm_arm.h' target/arm: Restrict KVM-specific fields from ArchCPU target/ppc: Restrict KVM-specific field from ArchCPU target/riscv: Restrict KVM-specific fields from ArchCPU hw/s390x: Rename pv.c -> pv-kvm.c

 include/hw/intc/arm_gic.h              |  2 ++
 include/hw/intc/arm_gicv3_common.h     | 10 ++++++
 include/hw/intc/arm_gicv3_its_common.h |  9 ++++++
 include/sysemu/kvm.h                   |  3 --
 target/arm/cpu.h                       |  2 ++
 target/arm/kvm_arm.h                   | 45 --------------------------
 target/ppc/cpu.h                       |  2 ++
 target/riscv/cpu.h                     |  2 ++
 accel/stubs/kvm-stub.c                 |  1 +
 hw/arm/sbsa-ref.c                      |  1 +
 hw/arm/virt-acpi-build.c               |  2 +-
 hw/arm/virt.c                          |  1 +
 hw/intc/arm_gic_common.c               | 12 +++++--
 hw/intc/arm_gicv3_common.c             | 14 ++++++++
 hw/intc/arm_gicv3_its_common.c         | 12 +++++++
 hw/s390x/{pv.c => pv-kvm.c}            |  0
 target/arm/arm-qmp-cmds.c              |  3 +-
 target/ppc/mmu_common.c                |  4 +++
 target/riscv/machine.c                 |  4 +++
 hw/s390x/meson.build                   |  2 +-
 20 files changed, 78 insertions(+), 53 deletions(-)
 rename hw/s390x/{pv.c => pv-kvm.c} (100%)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/10 sysemu/kvm: Remove unused headers

All types used are forward-declared in "qemu/typedefs.h".

---
 include/sysemu/kvm.h | 3 ---
 1 file changed, 3 deletions(-)
include/sysemu/kvm.h +0 -3
index cc6c678ed8..7902acdfd9 100644
@@ -16,9 +16,6 @@
 #ifndef QEMU_KVM_H
 #define QEMU_KVM_H
 
-#include "qemu/queue.h"
-#include "hw/core/cpu.h"
-#include "exec/memattrs.h"
 #include "qemu/accel.h"
 #include "qom/object.h"
 
Signature · 1 line
2.38.1
#4 lore raw

Re: [PATCH 01/10] sysemu/kvm: Remove unused headers

In reply to Philippe Mathieu-Daudé
Quoted 12 lines · Philippe Mathieu-Daudé

All types used are forward-declared in "qemu/typedefs.h".

---
  include/sysemu/kvm.h | 3 ---
  1 file changed, 3 deletions(-)
include/sysemu/kvm.h +0 -0
index cc6c678ed8..7902acdfd9 100644

include/sysemu/kvm.h line 21

Quoted 6 lines
include/sysemu/kvm.h +0 -3
@@ -16,9 +16,6 @@
  #ifndef QEMU_KVM_H
  #define QEMU_KVM_H
 
-#include "qemu/queue.h"
-#include "hw/core/cpu.h"
-#include "exec/memattrs.h"

Oops this is incorrect...

  MemTxAttrs kvm_arch_post_run(CPUState *cpu, struct kvm_run *run);

MemTxAttrs is not:
- forward-declared
- used as pointer

Since this is now merged as commit 1e05888ab5 I'll send a fix.

Quoted 3 lines
include/sysemu/kvm.h +0 -0
  #include "qemu/accel.h"
  #include "qom/object.h"
 
#5 lore raw

PATCH 2/10 accel/kvm: Declare kvm_direct_msi_allowed in stubs

In reply to Philippe Mathieu-Daudé

Avoid when calling kvm_direct_msi_enabled() from
arm_gicv3_its_common.c the next commit:

Undefined symbols for architecture arm64:
"_kvm_direct_msi_allowed", referenced from:
_its_class_name in hw_intc_arm_gicv3_its_common.c.o
ld: symbol(s) not found for architecture arm64

---
 accel/stubs/kvm-stub.c | 1 +
 1 file changed, 1 insertion(+)
accel/stubs/kvm-stub.c +1 -0
index 5d2dd8f351..235dc661bc 100644
@@ -27,6 +27,7 @@ bool kvm_allowed;
 bool kvm_readonly_mem_allowed;
 bool kvm_ioeventfd_any_length_allowed;
 bool kvm_msi_use_devid;
+bool kvm_direct_msi_allowed;
 
 void kvm_flush_coalesced_mmio_buffer(void)
 {
Signature · 1 line
2.38.1
Reviewed-by on v1 2/10
#6 lore raw

Re: [PATCH 02/10] accel/kvm: Declare kvm_direct_msi_allowed in stubs

Quoted 9 lines · Philippe Mathieu-Daudé

Avoid when calling kvm_direct_msi_enabled() from
arm_gicv3_its_common.c the next commit:

Undefined symbols for architecture arm64:
"_kvm_direct_msi_allowed", referenced from:
_its_class_name in hw_intc_arm_gicv3_its_common.c.o
ld: symbol(s) not found for architecture arm64

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
Reviewed-by on v1 2/10
#7 lore raw

Re: [PATCH 02/10] accel/kvm: Declare kvm_direct_msi_allowed in stubs

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

Avoid when calling kvm_direct_msi_enabled() from
arm_gicv3_its_common.c the next commit:

Undefined symbols for architecture arm64:
"_kvm_direct_msi_allowed", referenced from:
_its_class_name in hw_intc_arm_gicv3_its_common.c.o
ld: symbol(s) not found for architecture arm64

Quoted 4 lines
---
  accel/stubs/kvm-stub.c | 1 +
  1 file changed, 1 insertion(+)

r~

#8 lore raw

PATCH 3/10 hw/intc/arm_gic: Un-inline GIC*/ITS class_name() helpers

In reply to Philippe Mathieu-Daudé

"kvm_arm.h" contains external and internal prototype declarations. Files under the hw/ directory should only access the KVM external API.

In order to avoid machine / device models to include "kvm_arm.h" simply to get the QOM GIC/ITS class name, un-inline each class name getter to the proper device model file.

---
 include/hw/intc/arm_gic.h              |  2 ++
 include/hw/intc/arm_gicv3_common.h     | 10 ++++++
 include/hw/intc/arm_gicv3_its_common.h |  9 ++++++
 target/arm/kvm_arm.h                   | 45 --------------------------
 hw/arm/virt-acpi-build.c               |  2 +-
 hw/arm/virt.c                          |  1 +
 hw/intc/arm_gic_common.c               |  7 ++++
 hw/intc/arm_gicv3_common.c             | 14 ++++++++
 hw/intc/arm_gicv3_its_common.c         | 12 +++++++
 9 files changed, 56 insertions(+), 46 deletions(-)
include/hw/intc/arm_gic.h +2 -0
index 116ccbb5a9..48f6a51a70 100644
@@ -86,4 +86,6 @@ struct ARMGICClass {
     DeviceRealize parent_realize;
 };
 
+const char *gic_class_name(void);
+
 #endif
include/hw/intc/arm_gicv3_common.h +10 -0
index ab5182a28a..4e2fb518e7 100644
@@ -329,4 +329,14 @@ struct ARMGICv3CommonClass {
 void gicv3_init_irqs_and_mmio(GICv3State *s, qemu_irq_handler handler,
                               const MemoryRegionOps *ops);
 
+/**
+ * gicv3_class_name
+ *
+ * Return name of GICv3 class to use depending on whether KVM acceleration is
+ * in use. May throw an error if the chosen implementation is not available.
+ *
+ * Returns: class name to use
+ */
+const char *gicv3_class_name(void);
+
 #endif
include/hw/intc/arm_gicv3_its_common.h +9 -0
index a11a0f6654..7dc712b38d 100644
@@ -122,5 +122,14 @@ struct GICv3ITSCommonClass {
     void (*post_load)(GICv3ITSState *s);
 };
 
+/**
+ * its_class_name:
+ *
+ * Return the ITS class name to use depending on whether KVM acceleration
+ * and KVM CAP_SIGNAL_MSI are supported
+ *
+ * Returns: class name to use or NULL
+ */
+const char *its_class_name(void);
 
 #endif
target/arm/kvm_arm.h +0 -45

55 lines not on this page · raw message

hw/arm/virt-acpi-build.c +1 -1
index 4156111d49..e8bab19847 100644
@@ -48,12 +48,12 @@
 #include "hw/pci/pci_bus.h"
 #include "hw/pci-host/gpex.h"
 #include "hw/arm/virt.h"
+#include "hw/intc/arm_gicv3_its_common.h"
 #include "hw/mem/nvdimm.h"
 #include "hw/platform-bus.h"
 #include "sysemu/numa.h"
 #include "sysemu/reset.h"
 #include "sysemu/tpm.h"
-#include "kvm_arm.h"
 #include "migration/vmstate.h"
 #include "hw/acpi/ghes.h"
 #include "hw/acpi/viot.h"
hw/arm/virt.c +1 -0
index 1fe39c6683..dbbe639e61 100644
@@ -63,6 +63,7 @@
 #include "hw/arm/fdt.h"
 #include "hw/intc/arm_gic.h"
 #include "hw/intc/arm_gicv3_common.h"
+#include "hw/intc/arm_gicv3_its_common.h"
 #include "hw/irq.h"
 #include "kvm_arm.h"
 #include "hw/firmware/smbios.h"
hw/intc/arm_gic_common.c +7 -0
index a379cea395..9702197856 100644
@@ -21,10 +21,12 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
+#include "qemu/error-report.h"
 #include "gic_internal.h"
 #include "hw/arm/linux-boot-if.h"
 #include "hw/qdev-properties.h"
 #include "migration/vmstate.h"
+#include "sysemu/kvm.h"
 
 static int gic_pre_save(void *opaque)
 {
@@ -393,3 +395,8 @@ static void register_types(void)
 }
 
 type_init(register_types)
+
+const char *gic_class_name(void)
+{
+    return kvm_irqchip_in_kernel() ? "kvm-arm-gic" : "arm_gic";
+}
hw/intc/arm_gicv3_common.c +14 -0
index 642a8243ed..2ebf880ead 100644
@@ -24,6 +24,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
+#include "qemu/error-report.h"
 #include "hw/core/cpu.h"
 #include "hw/intc/arm_gicv3_common.h"
 #include "hw/qdev-properties.h"
@@ -608,3 +609,16 @@ static void register_types(void)
 }
 
 type_init(register_types)
+
+const char *gicv3_class_name(void)
+{
+    if (kvm_irqchip_in_kernel()) {
+        return "kvm-arm-gicv3";
+    } else {
+        if (kvm_enabled()) {
+            error_report("Userspace GICv3 is not supported with KVM");
+            exit(1);
+        }
+        return "arm-gicv3";
+    }
+}
hw/intc/arm_gicv3_its_common.c +12 -0
index d7532a7a89..abaf77057e 100644
@@ -24,6 +24,7 @@
 #include "hw/intc/arm_gicv3_its_common.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
+#include "sysemu/kvm.h"
 
 static int gicv3_its_pre_save(void *opaque)
 {
@@ -158,3 +159,14 @@ static void gicv3_its_common_register_types(void)
 }
 
 type_init(gicv3_its_common_register_types)
+
+const char *its_class_name(void)
+{
+    if (kvm_irqchip_in_kernel()) {
+        /* KVM implementation requires this capability */
+        return kvm_direct_msi_enabled() ? "arm-its-kvm" : NULL;
+    } else {
+        /* Software emulation based model */
+        return "arm-gicv3-its";
+    }
+}
Signature · 1 line
2.38.1
Reviewed-by on v1 3/10
#9 lore raw

Re: [PATCH 03/10] hw/intc/arm_gic: Un-inline GIC*/ITS class_name() helpers

Quoted 9 lines · Philippe Mathieu-Daudé

"kvm_arm.h" contains external and internal prototype declarations. Files under the hw/ directory should only access the KVM external API.

In order to avoid machine / device models to include "kvm_arm.h" simply to get the QOM GIC/ITS class name, un-inline each class name getter to the proper device model file.

Quoted 11 lines
---
  include/hw/intc/arm_gic.h              |  2 ++
  include/hw/intc/arm_gicv3_common.h     | 10 ++++++
  include/hw/intc/arm_gicv3_its_common.h |  9 ++++++
  target/arm/kvm_arm.h                   | 45 --------------------------
  hw/arm/virt-acpi-build.c               |  2 +-
  hw/arm/virt.c                          |  1 +
  hw/intc/arm_gic_common.c               |  7 ++++
  hw/intc/arm_gicv3_common.c             | 14 ++++++++
  hw/intc/arm_gicv3_its_common.c         | 12 +++++++
  9 files changed, 56 insertions(+), 46 deletions(-)

r~

#10 lore raw

PATCH 4/10 hw/intc/arm_gic: Rename 'first_cpu' argument

In reply to Philippe Mathieu-Daudé

"hw/core/cpu.h" defines 'first_cpu' as QTAILQ_FIRST_RCU(&cpus).

arm_gic_common_reset_irq_state() calls its second argument 'first_cpu', producing a build failure when "hw/core/cpu.h" is included:

hw/intc/arm_gic_common.c:238:68: warning: omitting the parameter name in a function definition is a C2x extension [-Wc2x-extensions]
static inline void arm_gic_common_reset_irq_state(GICState *s, int first_cpu,
^
include/hw/core/cpu.h:451:26: note: expanded from macro 'first_cpu'

    #define first_cpu        QTAILQ_FIRST_RCU(&cpus)
                             ^

KISS, rename the function argument.

---
 hw/intc/arm_gic_common.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/intc/arm_gic_common.c +3 -2
index 9702197856..889327a8cf 100644
@@ -235,12 +235,13 @@ static void arm_gic_common_realize(DeviceState *dev, Error **errp)
     }
 }
 
-static inline void arm_gic_common_reset_irq_state(GICState *s, int first_cpu,
+static inline void arm_gic_common_reset_irq_state(GICState *s,
+                                                  int first_cpu_index,
                                                   int resetprio)
 {
     int i, j;
 
-    for (i = first_cpu; i < first_cpu + s->num_cpu; i++) {
+    for (i = first_cpu_index; i < first_cpu_index + s->num_cpu; i++) {
         if (s->revision == REV_11MPCORE) {
             s->priority_mask[i] = 0xf0;
         } else {
Signature · 1 line
2.38.1
#11 lore raw

Re: [PATCH 04/10] hw/intc/arm_gic: Rename 'first_cpu' argument

Quoted 13 lines · Philippe Mathieu-Daudé

"hw/core/cpu.h" defines 'first_cpu' as QTAILQ_FIRST_RCU(&cpus).

arm_gic_common_reset_irq_state() calls its second argument 'first_cpu', producing a build failure when "hw/core/cpu.h" is included:

hw/intc/arm_gic_common.c:238:68: warning: omitting the parameter name in a function definition is a C2x extension [-Wc2x-extensions]
static inline void arm_gic_common_reset_irq_state(GICState *s, int first_cpu,
^
include/hw/core/cpu.h:451:26: note: expanded from macro 'first_cpu'

     #define first_cpu        QTAILQ_FIRST_RCU(&cpus)
                              ^
Quoted 6 lines

KISS, rename the function argument.

---
  hw/intc/arm_gic_common.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

Wow, that's ugly. But a reasonable work-around.

r~

Reviewed-by
#12 lore raw

Re: [PATCH 04/10] hw/intc/arm_gic: Rename 'first_cpu' argument

Quoted 14 lines · Richard Henderson
Quoted 13 lines · Philippe Mathieu-Daudé

"hw/core/cpu.h" defines 'first_cpu' as QTAILQ_FIRST_RCU(&cpus).

arm_gic_common_reset_irq_state() calls its second argument 'first_cpu', producing a build failure when "hw/core/cpu.h" is included:

   hw/intc/arm_gic_common.c:238:68: warning: omitting the parameter name in a function definition is a C2x extension [-Wc2x-extensions] static inline void arm_gic_common_reset_irq_state(GICState *s, int first_cpu,
                                                                        ^
   include/hw/core/cpu.h:451:26: note: expanded from macro 'first_cpu'
     #define first_cpu        QTAILQ_FIRST_RCU(&cpus)
                              ^

Quoted 8 lines
Quoted 6 lines

KISS, rename the function argument.

---
  hw/intc/arm_gic_common.c | 5 +++--

  1 file changed, 3 insertions(+), 2 deletions(-)

Wow, that's ugly.  But a reasonable work-around.

Duh.

r~

Reviewed-by on v1 4/10
#13 lore raw

Re: [PATCH 04/10] hw/intc/arm_gic: Rename 'first_cpu' argument

In reply to Philippe Mathieu-Daudé
Quoted 25 lines · Philippe Mathieu-Daudé

"hw/core/cpu.h" defines 'first_cpu' as QTAILQ_FIRST_RCU(&cpus).

arm_gic_common_reset_irq_state() calls its second argument 'first_cpu', producing a build failure when "hw/core/cpu.h" is included:

hw/intc/arm_gic_common.c:238:68: warning: omitting the parameter name in a function definition is a C2x extension [-Wc2x-extensions]
static inline void arm_gic_common_reset_irq_state(GICState *s, int first_cpu,
^
include/hw/core/cpu.h:451:26: note: expanded from macro 'first_cpu'

    #define first_cpu        QTAILQ_FIRST_RCU(&cpus)
                             ^

KISS, rename the function argument.

---
 hw/intc/arm_gic_common.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/intc/arm_gic_common.c +0 -0
index 9702197856..889327a8cf 100644

hw/intc/arm_gic_common.c static void arm_gic_common_realize(DeviceState *dev, Error **errp) · line 240

Quoted 7 lines
hw/intc/arm_gic_common.c +2 -1
@@ -235,12 +235,13 @@ static void arm_gic_common_realize(DeviceState *dev, Error **errp)
     }
 }
 
-static inline void arm_gic_common_reset_irq_state(GICState *s, int first_cpu,
+static inline void arm_gic_common_reset_irq_state(GICState *s,
+                                                  int
 first_cpu_index,

I'd have gone for a shorter name like cidx maybe, naming things is hard.

Anyway:

Quoted 9 lines
hw/intc/arm_gic_common.c +1 -1
                                                   int resetprio)
 {
     int i, j;
 
-    for (i = first_cpu; i < first_cpu + s->num_cpu; i++) {
+    for (i = first_cpu_index; i < first_cpu_index + s->num_cpu; i++) {
         if (s->revision == REV_11MPCORE) {
             s->priority_mask[i] = 0xf0;
         } else {
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#14 lore raw

PATCH 5/10 hw/arm/sbsa-ref: Include missing 'sysemu/kvm.h' header

In reply to Philippe Mathieu-Daudé

"sysemu/kvm.h" is indirectly pulled in. Explicit its inclusion to avoid when refactoring include/:

hw/arm/sbsa-ref.c:693:9: error: implicit declaration of function 'kvm_enabled' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

    if (kvm_enabled()) {
        ^
---
 hw/arm/sbsa-ref.c | 1 +
 1 file changed, 1 insertion(+)
hw/arm/sbsa-ref.c +1 -0
index 0b93558dde..7df4d7b712 100644
@@ -26,6 +26,7 @@
 #include "sysemu/numa.h"
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/kvm.h"
 #include "exec/hwaddr.h"
 #include "kvm_arm.h"
 #include "hw/arm/boot.h"
Signature · 1 line
2.38.1
Reviewed-by on v1 5/10
#15 lore raw

Re: [PATCH 05/10] hw/arm/sbsa-ref: Include missing 'sysemu/kvm.h' header

Quoted 17 lines · Philippe Mathieu-Daudé

"sysemu/kvm.h" is indirectly pulled in. Explicit its inclusion to avoid when refactoring include/:

hw/arm/sbsa-ref.c:693:9: error: implicit declaration of function 'kvm_enabled' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

    if (kvm_enabled()) {
        ^
---
 hw/arm/sbsa-ref.c | 1 +
 1 file changed, 1 insertion(+)
hw/arm/sbsa-ref.c +0 -0
index 0b93558dde..7df4d7b712 100644

hw/arm/sbsa-ref.c line 29

Quoted 4 lines
hw/arm/sbsa-ref.c +1 -0
@@ -26,6 +26,7 @@
 #include "sysemu/numa.h"
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/kvm.h"

Can I do my traditional nitpick and ask this to be added above sysemu/numa.h in order to maintain alphabetical ordering within the sysemu block?

With that:

Quoted 6 lines
hw/arm/sbsa-ref.c +0 -0
 #include "exec/hwaddr.h"
 #include "kvm_arm.h"
 #include "hw/arm/boot.h"
Signature · 1 line
2.38.1
Reviewed-by on v1 5/10
#16 lore raw

Re: [PATCH 05/10] hw/arm/sbsa-ref: Include missing 'sysemu/kvm.h' header

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

"sysemu/kvm.h" is indirectly pulled in. Explicit its inclusion to avoid when refactoring include/:

   hw/arm/sbsa-ref.c:693:9: error: implicit declaration of function 'kvm_enabled' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
     if (kvm_enabled()) {
         ^
---
  hw/arm/sbsa-ref.c | 1 +
  1 file changed, 1 insertion(+)

r~

#17 lore raw

PATCH 6/10 target/arm: Reduce QMP header pressure by not including 'kvm_arm.h'

In reply to Philippe Mathieu-Daudé

We only need "sysemu/kvm.h" for kvm_enabled() and "cpu.h" for the QOM type definitions (TYPE_ARM_CPU). Avoid including the heavy "kvm_arm.h" header.

---
 target/arm/arm-qmp-cmds.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/arm/arm-qmp-cmds.c +2 -1
index c8fa524002..91eb450565 100644
@@ -22,7 +22,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/boards.h"
-#include "kvm_arm.h"
+#include "sysemu/kvm.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "qapi/qobject-input-visitor.h"
@@ -31,6 +31,7 @@
 #include "qapi/qmp/qerror.h"
 #include "qapi/qmp/qdict.h"
 #include "qom/qom-qobject.h"
+#include "target/arm/cpu.h"
 
 static GICCapability *gic_cap_new(int version)
 {
Signature · 1 line
2.38.1
Reviewed-by on v1 6/10
#18 lore raw

Re: [PATCH 06/10] target/arm: Reduce QMP header pressure by not including 'kvm_arm.h'

Quoted 8 lines · Philippe Mathieu-Daudé

We only need "sysemu/kvm.h" for kvm_enabled() and "cpu.h" for the QOM type definitions (TYPE_ARM_CPU). Avoid including the heavy "kvm_arm.h" header.

---
  target/arm/arm-qmp-cmds.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

r~

#19 lore raw

PATCH 7/10 target/arm: Restrict KVM-specific fields from ArchCPU

In reply to Philippe Mathieu-Daudé

These fields shouldn't be accessed when KVM is not available.

---
 target/arm/cpu.h | 2 ++
 1 file changed, 2 insertions(+)
target/arm/cpu.h +2 -0
index c097cae988..efd1b010d5 100644
@@ -945,6 +945,7 @@ struct ArchCPU {
      */
     uint32_t kvm_target;
 
+#ifdef CONFIG_KVM
     /* KVM init features for this CPU */
     uint32_t kvm_init_features[7];
 
@@ -957,6 +958,7 @@ struct ArchCPU {
 
     /* KVM steal time */
     OnOffAuto kvm_steal_time;
+#endif /* CONFIG_KVM */
 
     /* Uniprocessor system with MP extensions */
     bool mp_is_up;
Signature · 1 line
2.38.1
#21 lore raw

PATCH 8/10 target/ppc: Restrict KVM-specific field from ArchCPU

In reply to Philippe Mathieu-Daudé

The 'kvm_sw_tlb' field shouldn't be accessed when KVM is not available.

---
 target/ppc/cpu.h        | 2 ++
 target/ppc/mmu_common.c | 4 ++++
 2 files changed, 6 insertions(+)
target/ppc/cpu.h +2 -0
index 557d736dab..0ec3957397 100644
@@ -1148,7 +1148,9 @@ struct CPUArchState {
     int tlb_type;    /* Type of TLB we're dealing with */
     ppc_tlb_t tlb;   /* TLB is optional. Allocate them only if needed */
     bool tlb_dirty;  /* Set to non-zero when modifying TLB */
+#ifdef CONFIG_KVM
     bool kvm_sw_tlb; /* non-zero if KVM SW TLB API is active */
+#endif /* CONFIG_KVM */
     uint32_t tlb_need_flush; /* Delayed flush needed */
 #define TLB_NEED_LOCAL_FLUSH   0x1
 #define TLB_NEED_GLOBAL_FLUSH  0x2
target/ppc/mmu_common.c +4 -0
index 7235a4befe..21843c69f6 100644
@@ -917,10 +917,12 @@ static void mmubooke_dump_mmu(CPUPPCState *env)
     ppcemb_tlb_t *entry;
     int i;
 
+#ifdef CONFIG_KVM
     if (kvm_enabled() && !env->kvm_sw_tlb) {
         qemu_printf("Cannot access KVM TLB\n");
         return;
     }
+#endif
 
     qemu_printf("\nTLB:\n");
     qemu_printf("Effective          Physical           Size PID   Prot     "
@@ -1008,10 +1010,12 @@ static void mmubooke206_dump_mmu(CPUPPCState *env)
     int offset = 0;
     int i;
 
+#ifdef CONFIG_KVM
     if (kvm_enabled() && !env->kvm_sw_tlb) {
         qemu_printf("Cannot access KVM TLB\n");
         return;
     }
+#endif
 
     for (i = 0; i < BOOKE206_MAX_TLBN; i++) {
         int size = booke206_tlb_size(env, i);
Signature · 1 line
2.38.1
Reviewed-by on v1 8/10
#22 lore raw

Re: [PATCH 08/10] target/ppc: Restrict KVM-specific field from ArchCPU

Quoted 4 lines · Philippe Mathieu-Daudé

The 'kvm_sw_tlb' field shouldn't be accessed when KVM is not available.

---

Quoted 48 lines
  target/ppc/cpu.h        | 2 ++
  target/ppc/mmu_common.c | 4 ++++
  2 files changed, 6 insertions(+)
target/ppc/cpu.h +2 -0
index 557d736dab..0ec3957397 100644
@@ -1148,7 +1148,9 @@ struct CPUArchState {
      int tlb_type;    /* Type of TLB we're dealing with */
      ppc_tlb_t tlb;   /* TLB is optional. Allocate them only if needed */
      bool tlb_dirty;  /* Set to non-zero when modifying TLB */
+#ifdef CONFIG_KVM
      bool kvm_sw_tlb; /* non-zero if KVM SW TLB API is active */
+#endif /* CONFIG_KVM */
      uint32_t tlb_need_flush; /* Delayed flush needed */
  #define TLB_NEED_LOCAL_FLUSH   0x1
  #define TLB_NEED_GLOBAL_FLUSH  0x2
target/ppc/mmu_common.c +4 -0
index 7235a4befe..21843c69f6 100644
@@ -917,10 +917,12 @@ static void mmubooke_dump_mmu(CPUPPCState *env)
      ppcemb_tlb_t *entry;
      int i;
 
+#ifdef CONFIG_KVM
      if (kvm_enabled() && !env->kvm_sw_tlb) {
          qemu_printf("Cannot access KVM TLB\n");
          return;
      }
+#endif
 
      qemu_printf("\nTLB:\n");
      qemu_printf("Effective          Physical           Size PID   Prot     "
@@ -1008,10 +1010,12 @@ static void mmubooke206_dump_mmu(CPUPPCState *env)
      int offset = 0;
      int i;
 
+#ifdef CONFIG_KVM
      if (kvm_enabled() && !env->kvm_sw_tlb) {
          qemu_printf("Cannot access KVM TLB\n");
          return;
      }
+#endif
 
      for (i = 0; i < BOOKE206_MAX_TLBN; i++) {
          int size = booke206_tlb_size(env, i);
#23 lore raw

Re: [PATCH 08/10] target/ppc: Restrict KVM-specific field from ArchCPU

In reply to Philippe Mathieu-Daudé

Hello Philippe

Quoted 13 lines · Philippe Mathieu-Daudé

The 'kvm_sw_tlb' field shouldn't be accessed when KVM is not available.

---
  target/ppc/cpu.h        | 2 ++
  target/ppc/mmu_common.c | 4 ++++
  2 files changed, 6 insertions(+)
target/ppc/cpu.h +0 -0
index 557d736dab..0ec3957397 100644

target/ppc/cpu.h struct CPUArchState { · line 1150

Quoted 3 lines
target/ppc/cpu.h +0 -0
@@ -1148,7 +1148,9 @@ struct CPUArchState {
      int tlb_type;    /* Type of TLB we're dealing with */
      ppc_tlb_t tlb;   /* TLB is optional. Allocate them only if needed */
      bool tlb_dirty;  /* Set to non-zero when modifying TLB */

'tlb_dirty' was part of the same commit 93dd5e852c ("kvm: ppc: booke206:
use MMU API"). So we might as well include it in the #ifdef section.

Thanks,

C.

Quoted 36 lines
target/ppc/cpu.h +2 -0
+#ifdef CONFIG_KVM
      bool kvm_sw_tlb; /* non-zero if KVM SW TLB API is active */
+#endif /* CONFIG_KVM */
      uint32_t tlb_need_flush; /* Delayed flush needed */
  #define TLB_NEED_LOCAL_FLUSH   0x1
  #define TLB_NEED_GLOBAL_FLUSH  0x2
target/ppc/mmu_common.c +4 -0
index 7235a4befe..21843c69f6 100644
@@ -917,10 +917,12 @@ static void mmubooke_dump_mmu(CPUPPCState *env)
      ppcemb_tlb_t *entry;
      int i;
 
+#ifdef CONFIG_KVM
      if (kvm_enabled() && !env->kvm_sw_tlb) {
          qemu_printf("Cannot access KVM TLB\n");
          return;
      }
+#endif
 
      qemu_printf("\nTLB:\n");
      qemu_printf("Effective          Physical           Size PID   Prot     "
@@ -1008,10 +1010,12 @@ static void mmubooke206_dump_mmu(CPUPPCState *env)
      int offset = 0;
      int i;
 
+#ifdef CONFIG_KVM
      if (kvm_enabled() && !env->kvm_sw_tlb) {
          qemu_printf("Cannot access KVM TLB\n");
          return;
      }
+#endif
 
      for (i = 0; i < BOOKE206_MAX_TLBN; i++) {
          int size = booke206_tlb_size(env, i);
#24 lore raw

RFC PATCH 9/10 target/riscv: Restrict KVM-specific fields from ArchCPU

In reply to Philippe Mathieu-Daudé

These fields shouldn't be accessed when KVM is not available.

---
RFC: The migration part is likely invalid...

kvmtimer_needed() is defined in target/riscv/machine.c as

  static bool kvmtimer_needed(void *opaque)
  {
      return kvm_enabled();
  }

which depends on a host feature.

---
 target/riscv/cpu.h     | 2 ++
 target/riscv/machine.c | 4 ++++
 2 files changed, 6 insertions(+)
target/riscv/cpu.h +2 -0
index 638e47c75a..82939235ab 100644
@@ -377,12 +377,14 @@ struct CPUArchState {
     hwaddr kernel_addr;
     hwaddr fdt_addr;
 
+#ifdef CONFIG_KVM
     /* kvm timer */
     bool kvm_timer_dirty;
     uint64_t kvm_timer_time;
     uint64_t kvm_timer_compare;
     uint64_t kvm_timer_state;
     uint64_t kvm_timer_frequency;
+#endif /* CONFIG_KVM */
 };
 
 OBJECT_DECLARE_CPU_TYPE(RISCVCPU, RISCVCPUClass, RISCV_CPU)
target/riscv/machine.c +4 -0
index 9c455931d8..e45d564ec3 100644
@@ -201,10 +201,12 @@ static bool kvmtimer_needed(void *opaque)
 
 static int cpu_post_load(void *opaque, int version_id)
 {
+#ifdef CONFIG_KVM
     RISCVCPU *cpu = opaque;
     CPURISCVState *env = &cpu->env;
 
     env->kvm_timer_dirty = true;
+#endif
     return 0;
 }
 
@@ -215,9 +217,11 @@ static const VMStateDescription vmstate_kvmtimer = {
     .needed = kvmtimer_needed,
     .post_load = cpu_post_load,
     .fields = (VMStateField[]) {
+#ifdef CONFIG_KVM
         VMSTATE_UINT64(env.kvm_timer_time, RISCVCPU),
         VMSTATE_UINT64(env.kvm_timer_compare, RISCVCPU),
         VMSTATE_UINT64(env.kvm_timer_state, RISCVCPU),
+#endif
         VMSTATE_END_OF_LIST()
     }
 };
Signature · 1 line
2.38.1
Reviewed-by on v1 9/10
#25 lore raw

Re: [RFC PATCH 09/10] target/riscv: Restrict KVM-specific fields from ArchCPU

Quoted 6 lines · Philippe Mathieu-Daudé

These fields shouldn't be accessed when KVM is not available.

---
RFC: The migration part is likely invalid...

Quoted 8 lines

kvmtimer_needed() is defined in target/riscv/machine.c as

   static bool kvmtimer_needed(void *opaque)
   {
       return kvm_enabled();
   }

which depends on a host feature.

kvm_enabled() can be false even when CONFIG_KVM is true when a KVM capable host is running a TCG guest, for example. In that case env->kvm_timer_* states exist but aren't initialized, and shouldn't be migrated.

Thus it's not just a host feature, but a host feature + accel option. I think this is fine.

Quoted 42 lines
---
  target/riscv/cpu.h     | 2 ++
  target/riscv/machine.c | 4 ++++
  2 files changed, 6 insertions(+)
target/riscv/cpu.h +2 -0
index 638e47c75a..82939235ab 100644
@@ -377,12 +377,14 @@ struct CPUArchState {
      hwaddr kernel_addr;
      hwaddr fdt_addr;
 
+#ifdef CONFIG_KVM
      /* kvm timer */
      bool kvm_timer_dirty;
      uint64_t kvm_timer_time;
      uint64_t kvm_timer_compare;
      uint64_t kvm_timer_state;
      uint64_t kvm_timer_frequency;
+#endif /* CONFIG_KVM */
  };
 
  OBJECT_DECLARE_CPU_TYPE(RISCVCPU, RISCVCPUClass, RISCV_CPU)
target/riscv/machine.c +2 -0
index 9c455931d8..e45d564ec3 100644
@@ -201,10 +201,12 @@ static bool kvmtimer_needed(void *opaque)
 
  static int cpu_post_load(void *opaque, int version_id)
  {
+#ifdef CONFIG_KVM
      RISCVCPU *cpu = opaque;
      CPURISCVState *env = &cpu->env;
 
      env->kvm_timer_dirty = true;
+#endif
      return 0;
  }
 

target/riscv/machine.c static const VMStateDescription vmstate_kvmtimer = { · line 224

Quoted 8 lines
target/riscv/machine.c +2 -0
@@ -215,9 +217,11 @@ static const VMStateDescription vmstate_kvmtimer = {
      .needed = kvmtimer_needed,
      .post_load = cpu_post_load,
      .fields = (VMStateField[]) {
+#ifdef CONFIG_KVM
          VMSTATE_UINT64(env.kvm_timer_time, RISCVCPU),
          VMSTATE_UINT64(env.kvm_timer_compare, RISCVCPU),
          VMSTATE_UINT64(env.kvm_timer_state, RISCVCPU),
+#endif

Here you're creating an empty 'cpu/kvmtimer' vmstate that won't be migrated anyway because kvmtimer_needed (== kvm_enabled()) will be always false if CONFIG_KVM=n.

I'd say it's better to just get rid of the whole vmstate in this case, but I don't like the precedence of having vmstates being gated by build flags.

Quoted 3 lines
target/riscv/machine.c +0 -0
          VMSTATE_END_OF_LIST()
      }
  };
#26 lore raw

Re: [RFC PATCH 09/10] target/riscv: Restrict KVM-specific fields from ArchCPU

In reply to Philippe Mathieu-Daudé
Quoted 13 lines · Philippe Mathieu-Daudé

These fields shouldn't be accessed when KVM is not available.

---
RFC: The migration part is likely invalid...

kvmtimer_needed() is defined in target/riscv/machine.c as

   static bool kvmtimer_needed(void *opaque)
   {
       return kvm_enabled();
   }
Quoted 5 lines

which depends on a host feature.

---
  target/riscv/cpu.h     | 2 ++
  target/riscv/machine.c | 4 ++++
  2 files changed, 6 insertions(+)

Yeah, the kvm parts need to be extracted to their own subsection.

r~

#27 lore raw

Re: [RFC PATCH 09/10] target/riscv: Restrict KVM-specific fields from ArchCPU

Quoted 14 lines · Richard Henderson
Quoted 13 lines · Philippe Mathieu-Daudé

These fields shouldn't be accessed when KVM is not available.

---
RFC: The migration part is likely invalid...

kvmtimer_needed() is defined in target/riscv/machine.c as

   static bool kvmtimer_needed(void *opaque)
   {
       return kvm_enabled();
   }

Quoted 7 lines
Quoted 5 lines

which depends on a host feature.
---
  target/riscv/cpu.h     | 2 ++
  target/riscv/machine.c | 4 ++++

  2 files changed, 6 insertions(+)

Yeah, the kvm parts need to be extracted to their own subsection.

Oh, but they are. Ho hum, it's getting late.

r~

#28 lore raw

PATCH 10/10 hw/s390x: Rename pv.c -> pv-kvm.c

In reply to Philippe Mathieu-Daudé

Protected Virtualization is specific to KVM. Rename the file as 'pv-kvm.c' to make this clearer.

---
 hw/s390x/{pv.c => pv-kvm.c} | 0
 hw/s390x/meson.build        | 2 +-
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename hw/s390x/{pv.c => pv-kvm.c} (100%)
hw/s390x/pv-kvm.c renamed from hw/s390x/pv.c +0 -0
similarity index 100%
rename from hw/s390x/pv.c
rename to hw/s390x/pv-kvm.c
hw/s390x/meson.build +1 -1
index f291016fee..2f43b6c473 100644
@@ -22,7 +22,7 @@ s390x_ss.add(when: 'CONFIG_KVM', if_true: files(
   'tod-kvm.c',
   's390-skeys-kvm.c',
   's390-stattrib-kvm.c',
-  'pv.c',
+  'pv-kvm.c',
   's390-pci-kvm.c',
 ))
 s390x_ss.add(when: 'CONFIG_TCG', if_true: files(
Signature · 1 line
2.38.1
#29 lore raw

Re: [PATCH 10/10] hw/s390x: Rename pv.c -> pv-kvm.c

Quoted 19 lines · Philippe Mathieu-Daudé

Protected Virtualization is specific to KVM. Rename the file as 'pv-kvm.c' to make this clearer.

---
  hw/s390x/{pv.c => pv-kvm.c} | 0
  hw/s390x/meson.build        | 2 +-
  2 files changed, 1 insertion(+), 1 deletion(-)

rename hw/s390x/{pv.c => pv-kvm.c} (100%)

hw/s390x/pv-kvm.c renamed from hw/s390x/pv.c +0 -0
similarity index 100%
rename from hw/s390x/pv.c
rename to hw/s390x/pv-kvm.c
hw/s390x/meson.build +0 -0
index f291016fee..2f43b6c473 100644

hw/s390x/meson.build s390x_ss.add(when: 'CONFIG_KVM', if_true: files( · line 28

Quoted 8 lines
hw/s390x/meson.build +1 -1
@@ -22,7 +22,7 @@ s390x_ss.add(when: 'CONFIG_KVM', if_true: files(
    'tod-kvm.c',
    's390-skeys-kvm.c',
    's390-stattrib-kvm.c',
-  'pv.c',
+  'pv-kvm.c',
    's390-pci-kvm.c',
  ))
  s390x_ss.add(when: 'CONFIG_TCG', if_true: files(

Hmmm, maybe we should rather move it to target/s390x/kvm/ instead?

Janosch, what's your opinion?

Thomas

#30 lore raw

Re: [PATCH 10/10] hw/s390x: Rename pv.c -> pv-kvm.c

Quoted 31 lines · Thomas Huth
Quoted 19 lines · Philippe Mathieu-Daudé

Protected Virtualization is specific to KVM. Rename the file as 'pv-kvm.c' to make this clearer.

---
   hw/s390x/{pv.c => pv-kvm.c} | 0
   hw/s390x/meson.build        | 2 +-
   2 files changed, 1 insertion(+), 1 deletion(-)

rename hw/s390x/{pv.c => pv-kvm.c} (100%)

hw/s390x/pv-kvm.c renamed from hw/s390x/pv.c +0 -0
similarity index 100%
rename from hw/s390x/pv.c
rename to hw/s390x/pv-kvm.c
hw/s390x/meson.build +0 -0
index f291016fee..2f43b6c473 100644

hw/s390x/meson.build s390x_ss.add(when: 'CONFIG_KVM', if_true: files( · line 28

Quoted 8 lines
hw/s390x/meson.build +1 -1
@@ -22,7 +22,7 @@ s390x_ss.add(when: 'CONFIG_KVM', if_true: files(
     'tod-kvm.c',
     's390-skeys-kvm.c',
     's390-stattrib-kvm.c',
-  'pv.c',
+  'pv-kvm.c',
     's390-pci-kvm.c',
   ))
   s390x_ss.add(when: 'CONFIG_TCG', if_true: files(

Hmmm, maybe we should rather move it to target/s390x/kvm/ instead?

Quoted 5 lines

Janosch, what's your opinion?

Thomas

Don't care as long as the file is not deleted :)

#31 lore raw

Re: [PATCH 10/10] hw/s390x: Rename pv.c -> pv-kvm.c

Quoted 32 lines · Janosch Frank
Quoted 31 lines · Thomas Huth
Quoted 26 lines · Philippe Mathieu-Daudé

Protected Virtualization is specific to KVM. Rename the file as 'pv-kvm.c' to make this clearer.

---
   hw/s390x/{pv.c => pv-kvm.c} | 0
   hw/s390x/meson.build        | 2 +-

   2 files changed, 1 insertion(+), 1 deletion(-)

   rename hw/s390x/{pv.c => pv-kvm.c} (100%)

hw/s390x/pv-kvm.c renamed from hw/s390x/pv.c +0 -0
similarity index 100%
rename from hw/s390x/pv.c
rename to hw/s390x/pv-kvm.c
hw/s390x/meson.build +1 -1
index f291016fee..2f43b6c473 100644
@@ -22,7 +22,7 @@ s390x_ss.add(when: 'CONFIG_KVM', if_true: files(
      'tod-kvm.c',
      's390-skeys-kvm.c',
      's390-stattrib-kvm.c',
-  'pv.c',
+  'pv-kvm.c',
      's390-pci-kvm.c',
    ))
Quoted 1 line

   s390x_ss.add(when: 'CONFIG_TCG', if_true: files(

Hmmm, maybe we should rather move it to target/s390x/kvm/ instead?

Quoted 7 lines
Quoted 5 lines

Janosch, what's your opinion?

   Thomas

Don't care as long as the file is not deleted :)

I followed the current pattern:

$ ls -1 hw/s390x/*kvm*
hw/s390x/s390-pci-kvm.c
hw/s390x/s390-skeys-kvm.c
hw/s390x/s390-stattrib-kvm.c
hw/s390x/tod-kvm.c

I'm still unsure where is the best place to put hw files which are arch (and accel) specific.

#32 lore raw

Re: [PATCH 10/10] hw/s390x: Rename pv.c -> pv-kvm.c

Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 32 lines · Janosch Frank
Quoted 31 lines · Thomas Huth
Quoted 26 lines · Philippe Mathieu-Daudé

Protected Virtualization is specific to KVM. Rename the file as 'pv-kvm.c' to make this clearer.

---
   hw/s390x/{pv.c => pv-kvm.c} | 0
   hw/s390x/meson.build        | 2 +-

   2 files changed, 1 insertion(+), 1 deletion(-)

   rename hw/s390x/{pv.c => pv-kvm.c} (100%)

hw/s390x/pv-kvm.c renamed from hw/s390x/pv.c +0 -0
similarity index 100%
rename from hw/s390x/pv.c
rename to hw/s390x/pv-kvm.c
hw/s390x/meson.build +1 -1
index f291016fee..2f43b6c473 100644
@@ -22,7 +22,7 @@ s390x_ss.add(when: 'CONFIG_KVM', if_true: files(
      'tod-kvm.c',
      's390-skeys-kvm.c',
      's390-stattrib-kvm.c',
-  'pv.c',
+  'pv-kvm.c',
      's390-pci-kvm.c',
    ))
Quoted 1 line

   s390x_ss.add(when: 'CONFIG_TCG', if_true: files(

Hmmm, maybe we should rather move it to target/s390x/kvm/ instead?

Quoted 7 lines
Quoted 5 lines

Janosch, what's your opinion?

   Thomas

Don't care as long as the file is not deleted :)

Quoted 7 lines

I followed the current pattern:

$ ls -1 hw/s390x/*kvm*
hw/s390x/s390-pci-kvm.c
hw/s390x/s390-skeys-kvm.c
hw/s390x/s390-stattrib-kvm.c
hw/s390x/tod-kvm.c

There's a differences for those: First, these devices have an implementation that works with TCG, too. Second, protected virtualization (pv) is not a real hardware device, it's a feature of the firmware on s390x that is exposed to userspace via the KVM interface. So target/s390x/kvm/ slightly sounds like a better place to me ... no strong opinion, though.

Thomas