Skip to contentSkip to conversation

target/s390x: Header cleanups around "cpu.h"

PATCH Superseded Philippe Mathieu-Daudé 2 participants 12 messages Dec 16, 2022 – Dec 17, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover target/s390x: Header cleanups around "cpu.h"

These patches are part of a big refactor cleanup around "cpu.h". Most changes should be trivial IMHO.

Philippe Mathieu-Daudé (5):
exec/memory: Expose memory_region_access_valid() hw/s390x/pv: Un-inline s390_pv_init()
hw/s390x/pv: Simplify s390_is_pv() for user emulation target/s390x/tcg/misc_helper: Remove unused "memory.h" include target/s390x/tcg/excp_helper: Restrict system headers to sysemu

 hw/s390x/pv.c                  | 13 +++++++++++++
 hw/s390x/s390-pci-inst.c       |  2 +-
 include/exec/memory-internal.h |  4 ----
 include/exec/memory.h          |  4 ++++
 include/hw/s390x/pv.h          | 20 ++++++++------------
 target/s390x/tcg/excp_helper.c | 10 +++++-----
 target/s390x/tcg/misc_helper.c |  1 -
 7 files changed, 31 insertions(+), 23 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/5 exec/memory: Expose memory_region_access_valid()

Instead of having hardware device poking into memory internal API, expose memory_region_access_valid().

---
 hw/s390x/s390-pci-inst.c       | 2 +-
 include/exec/memory-internal.h | 4 ----
 include/exec/memory.h          | 4 ++++
 3 files changed, 5 insertions(+), 5 deletions(-)
hw/s390x/s390-pci-inst.c +1 -1
index 66e764f901..35db7777e4 100644
@@ -13,7 +13,7 @@
 
 #include "qemu/osdep.h"
 #include "exec/memop.h"
-#include "exec/memory-internal.h"
+#include "exec/memory.h"
 #include "qemu/error-report.h"
 #include "sysemu/hw_accel.h"
 #include "hw/s390x/s390-pci-inst.h"
include/exec/memory-internal.h +0 -4
index 9fcc2af25c..100c1237ac 100644
@@ -38,10 +38,6 @@ void flatview_unref(FlatView *view);
 
 extern const MemoryRegionOps unassigned_mem_ops;
 
-bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr,
-                                unsigned size, bool is_write,
-                                MemTxAttrs attrs);
-
 void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section);
 AddressSpaceDispatch *address_space_dispatch_new(FlatView *fv);
 void address_space_dispatch_compact(AddressSpaceDispatch *d);
include/exec/memory.h +4 -0
index 91f8a2395a..c37ffdbcd1 100644
@@ -2442,6 +2442,10 @@ void memory_global_dirty_log_stop(unsigned int flags);
 
 void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled);
 
+bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr,
+                                unsigned size, bool is_write,
+                                MemTxAttrs attrs);
+
 /**
  * memory_region_dispatch_read: perform a read directly to the specified
  * MemoryRegion.
Signature · 1 line
2.38.1
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] exec/memory: Expose memory_region_access_valid()

Quoted 9 lines · Philippe Mathieu-Daudé

Instead of having hardware device poking into memory internal API, expose memory_region_access_valid().

---
  hw/s390x/s390-pci-inst.c       | 2 +-
  include/exec/memory-internal.h | 4 ----
  include/exec/memory.h          | 4 ++++
  3 files changed, 5 insertions(+), 5 deletions(-)

r~

#3 lore raw

PATCH 2/5 hw/s390x/pv: Un-inline s390_pv_init()

In reply to Philippe Mathieu-Daudé

There is no point in having s390_pv_init() inlined.

---
 hw/s390x/pv.c         | 13 +++++++++++++
 include/hw/s390x/pv.h | 14 +-------------
 2 files changed, 14 insertions(+), 13 deletions(-)
hw/s390x/pv.c +13 -0
index 8dfe92d8df..9c511369b2 100644
@@ -26,6 +26,19 @@ static bool info_valid;
 static struct kvm_s390_pv_info_vm info_vm;
 static struct kvm_s390_pv_info_dump info_dump;
 
+int s390_pv_init(ConfidentialGuestSupport *cgs, Error **errp)
+{
+    if (!cgs) {
+        return 0;
+    }
+    if (kvm_enabled()) {
+        return s390_pv_kvm_init(cgs, errp);
+    }
+
+    error_setg(errp, "Protected Virtualization requires KVM");
+    return -1;
+}
+
 static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
 {
     struct kvm_pv_cmd pv_cmd = {
include/hw/s390x/pv.h +1 -13
index 9360aa1091..5bca5bcaf1 100644
@@ -12,7 +12,6 @@
 #ifndef HW_S390_PV_H
 #define HW_S390_PV_H
 
-#include "qapi/error.h"
 #include "sysemu/kvm.h"
 
 #ifdef CONFIG_KVM
@@ -78,17 +77,6 @@ static inline int kvm_s390_dump_completion_data(void *buff) { return 0; }
 #endif /* CONFIG_KVM */
 
 int s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
-static inline int s390_pv_init(ConfidentialGuestSupport *cgs, Error **errp)
-{
-    if (!cgs) {
-        return 0;
-    }
-    if (kvm_enabled()) {
-        return s390_pv_kvm_init(cgs, errp);
-    }
-
-    error_setg(errp, "Protected Virtualization requires KVM");
-    return -1;
-}
+int s390_pv_init(ConfidentialGuestSupport *cgs, Error **errp);
 
 #endif /* HW_S390_PV_H */
Signature · 1 line
2.38.1
#4 lore raw

Re: [PATCH 2/5] hw/s390x/pv: Un-inline s390_pv_init()

Quoted 28 lines · Philippe Mathieu-Daudé

There is no point in having s390_pv_init() inlined.

---
  hw/s390x/pv.c         | 13 +++++++++++++
  include/hw/s390x/pv.h | 14 +-------------
  2 files changed, 14 insertions(+), 13 deletions(-)
include/hw/s390x/pv.h +0 -4
index 9360aa1091..5bca5bcaf1 100644
@@ -12,7 +12,6 @@
  #ifndef HW_S390_PV_H
  #define HW_S390_PV_H
 
-#include "qapi/error.h"
  #include "sysemu/kvm.h"
 
  #ifdef CONFIG_KVM
@@ -78,17 +77,6 @@ static inline int kvm_s390_dump_completion_data(void *buff) { return 0; }
  #endif /* CONFIG_KVM */
 
  int s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
-static inline int s390_pv_init(ConfidentialGuestSupport *cgs, Error **errp)
-{
-    if (!cgs) {

include/hw/s390x/pv.h static inline int kvm_s390_dump_completion_data(void *buff) { return 0; } · line 80

Quoted 10 lines
include/hw/s390x/pv.h +1 -9
-        return 0;
-    }
-    if (kvm_enabled()) {
-        return s390_pv_kvm_init(cgs, errp);
-    }
-
-    error_setg(errp, "Protected Virtualization requires KVM");
-    return -1;
-}
+int s390_pv_init(ConfidentialGuestSupport *cgs, Error **errp);

OK I understood why this function is inlined. It is called from:

$ git grep s390_pv_init
hw/s390x/pv.c:29:int s390_pv_init(ConfidentialGuestSupport *cgs, Error **errp)
hw/s390x/s390-virtio-ccw.c:259:    s390_pv_init(machine->cgs, &error_fatal);
include/hw/s390x/pv.h:86:int s390_pv_init(ConfidentialGuestSupport *cgs, Error **errp);

Now note in meson.build:

s390x_ss.add(when: 'CONFIG_KVM', if_true: files(
'tod-kvm.c',
's390-skeys-kvm.c',
's390-stattrib-kvm.c',
'pv.c',
's390-pci-kvm.c',
))

So when CONFIG_KVM=false s390-virtio-ccw.c doesn't have to link with the kvm-specific pv.o.

I'll rework this patch.

#5 lore raw

PATCH 3/5 hw/s390x/pv: Simplify s390_is_pv() for user emulation

In reply to Philippe Mathieu-Daudé

Protected Virtualization is irrelevant in user emulation.

---
 include/hw/s390x/pv.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/hw/s390x/pv.h +8 -0
index 5bca5bcaf1..a4814ce303 100644
@@ -12,6 +12,12 @@
 #ifndef HW_S390_PV_H
 #define HW_S390_PV_H
 
+#ifdef CONFIG_USER_ONLY
+
+static inline bool s390_is_pv(void) { return false; }
+
+#else /* !CONFIG_USER_ONLY */
+
 #include "sysemu/kvm.h"
 
 #ifdef CONFIG_KVM
@@ -79,4 +85,6 @@ static inline int kvm_s390_dump_completion_data(void *buff) { return 0; }
 int s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Error **errp);
 int s390_pv_init(ConfidentialGuestSupport *cgs, Error **errp);
 
+#endif /* CONFIG_USER_ONLY */
+
 #endif /* HW_S390_PV_H */
Signature · 1 line
2.38.1
#6 lore raw

Re: [PATCH 3/5] hw/s390x/pv: Simplify s390_is_pv() for user emulation

Quoted 12 lines · Philippe Mathieu-Daudé

Protected Virtualization is irrelevant in user emulation.

---
  include/hw/s390x/pv.h | 8 ++++++++
  1 file changed, 8 insertions(+)
include/hw/s390x/pv.h +0 -0
index 5bca5bcaf1..a4814ce303 100644

include/hw/s390x/pv.h line 17

Quoted 6 lines
include/hw/s390x/pv.h +3 -0
@@ -12,6 +12,12 @@
  #ifndef HW_S390_PV_H
  #define HW_S390_PV_H
 
+#ifdef CONFIG_USER_ONLY
+
+static inline bool s390_is_pv(void) { return false; }

This change is because I'm trying to get ride of:

../target/s390x/cpu_features.c: In function ‘s390_fill_feat_block’:
../target/s390x/cpu_features.c:112:10: error: implicit declaration of function ‘s390_is_pv’ [-Werror=implicit-function-declaration]

  112 |     if (!s390_is_pv()) {
      |          ^~~~~~~~~~

../target/s390x/cpu_features.c:112:10: error: nested extern declaration of ‘s390_is_pv’ [-Werror=nested-externs]

../target/s390x/cpu_models.c: In function ‘s390_has_feat’:
../target/s390x/cpu_models.c:239:9: error: implicit declaration of function ‘s390_is_pv’ [-Werror=implicit-function-declaration]

  239 |     if (s390_is_pv()) {
      |         ^~~~~~~~~~

../target/s390x/cpu_models.c:239:9: error: nested extern declaration of ‘s390_is_pv’ [-Werror=nested-externs]

without including <sysemu/kvm.h> in common code. Common code shouldn't include hw/ header...

I'll respin guarding more code against CONFIG_USER_ONLY.

#7 lore raw

PATCH 4/5 target/s390x/tcg/misc_helper: Remove unused "memory.h" include

In reply to Philippe Mathieu-Daudé
---
 target/s390x/tcg/misc_helper.c | 1 -
 1 file changed, 1 deletion(-)
target/s390x/tcg/misc_helper.c +0 -1
index 71388a7119..576157b1f3 100644
@@ -23,7 +23,6 @@
 #include "qemu/main-loop.h"
 #include "cpu.h"
 #include "s390x-internal.h"
-#include "exec/memory.h"
 #include "qemu/host-utils.h"
 #include "exec/helper-proto.h"
 #include "qemu/timer.h"
Signature · 1 line
2.38.1
#9 lore raw

PATCH 5/5 target/s390x/tcg/excp_helper: Restrict system headers to sysemu

In reply to Philippe Mathieu-Daudé
---
 target/s390x/tcg/excp_helper.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
target/s390x/tcg/excp_helper.c +5 -5
index fe02d82201..e9eb7c455e 100644
@@ -21,15 +21,15 @@
 #include "qemu/osdep.h"
 #include "qemu/log.h"
 #include "cpu.h"
-#include "s390x-internal.h"
 #include "exec/helper-proto.h"
-#include "qemu/timer.h"
 #include "exec/exec-all.h"
-#include "exec/cpu_ldst.h"
-#include "hw/s390x/ioinst.h"
-#include "exec/address-spaces.h"
+#include "s390x-internal.h"
 #include "tcg_s390x.h"
 #ifndef CONFIG_USER_ONLY
+#include "qemu/timer.h"
+#include "exec/cpu_ldst.h"
+#include "exec/address-spaces.h"
+#include "hw/s390x/ioinst.h"
 #include "hw/s390x/s390_flic.h"
 #include "hw/boards.h"
 #endif
Signature · 1 line
2.38.1
#10 lore raw

Re: [PATCH 5/5] target/s390x/tcg/excp_helper: Restrict system headers to sysemu

Quoted 15 lines · Philippe Mathieu-Daudé
---
  target/s390x/tcg/excp_helper.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
target/s390x/tcg/excp_helper.c +0 -1
index fe02d82201..e9eb7c455e 100644
@@ -21,15 +21,15 @@
  #include "qemu/osdep.h"
  #include "qemu/log.h"
  #include "cpu.h"
-#include "s390x-internal.h"
  #include "exec/helper-proto.h"

target/s390x/tcg/excp_helper.c line 30

Quoted 10 lines
target/s390x/tcg/excp_helper.c +3 -4
-#include "qemu/timer.h"
  #include "exec/exec-all.h"
-#include "exec/cpu_ldst.h"
-#include "hw/s390x/ioinst.h"
-#include "exec/address-spaces.h"
+#include "s390x-internal.h"
  #include "tcg_s390x.h"
  #ifndef CONFIG_USER_ONLY
+#include "qemu/timer.h"
+#include "exec/cpu_ldst.h"

cpu_ldst.h is not a system header. The others look plausible.

r~

Quoted 5 lines
target/s390x/tcg/excp_helper.c +2 -0
+#include "exec/address-spaces.h"
+#include "hw/s390x/ioinst.h"
  #include "hw/s390x/s390_flic.h"
  #include "hw/boards.h"
  #endif
#11 lore raw

Re: [PATCH 5/5] target/s390x/tcg/excp_helper: Restrict system headers to sysemu

Quoted 20 lines · Richard Henderson
Quoted 19 lines · Philippe Mathieu-Daudé

---
  target/s390x/tcg/excp_helper.c | 10 +++++-----

  1 file changed, 5 insertions(+), 5 deletions(-)
target/s390x/tcg/excp_helper.c +0 -4
index fe02d82201..e9eb7c455e 100644
@@ -21,15 +21,15 @@
   #include "qemu/osdep.h"
   #include "qemu/log.h"
   #include "cpu.h"
-#include "s390x-internal.h"
   #include "exec/helper-proto.h"
-#include "qemu/timer.h"
   #include "exec/exec-all.h"
-#include "exec/cpu_ldst.h"
-#include "hw/s390x/ioinst.h"
Quoted 8 lines

target/s390x/tcg/excp_helper.c line 30

Quoted 6 lines
target/s390x/tcg/excp_helper.c +3 -1
-#include "exec/address-spaces.h"
+#include "s390x-internal.h"
   #include "tcg_s390x.h"
   #ifndef CONFIG_USER_ONLY
+#include "qemu/timer.h"
+#include "exec/cpu_ldst.h"

cpu_ldst.h is not a system header.  The others look plausible.

Oops, correct.