Skip to contentSkip to conversation

softmmu: Make various objects target agnostic

PATCH Superseded Philippe Mathieu-Daudé via 4 participants 39 messages Feb 3, 2022 – Feb 5, 2022

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover softmmu: Make various objects target agnostic

This is a re-org accel/ and softmmu/ to have more target-agnostic objects.

Since RFC:
- Rework accel/meson (Richard)
- Use vaddr in cpu_memory_rw_debug (Richard)
- Introduce CONFIG_HAX_IS_POSSIBLE (Richard)
- Introduce AccelOpsClass::cpu_thread_is_idle (Richard)
- Introduce AccelOpsClass::cpus_are_resettable (Richard)
- Add qemu_init_arch_modules (new)

Philippe Mathieu-Daudé (21):
accel: Restrict sysemu stubs to system emulation accel/meson: Only build hw virtualization with system emulation
exec: Declare vaddr as a generic target-agnostic type
exec: Make cpu_memory_rw_debug() target agnostic sysemu/memory_mapping: Become target-agnostic
sysemu/kvm: Make kvm_on_sigbus() / kvm_on_sigbus_vcpu() target
agnostic
accel/kvm: Simplify user-mode #ifdef'ry
accel/hax: Introduce CONFIG_HAX_IS_POSSIBLE
softmmu/cpus: Code movement
accel: Introduce AccelOpsClass::cpu_thread_is_idle()
accel: Introduce AccelOpsClass::cpus_are_resettable() softmmu/globals: Remove unused 'hw/i386/*' headers softmmu/runstate: Clean headers
softmmu/physmem: Remove unnecessary include softmmu/cpu-timers: Remove unused 'exec/exec-all.h' header
misc: Remove unnecessary "sysemu/cpu-timers.h" include
misc: Add missing "sysemu/cpu-timers.h" include exec/gdbstub: Make gdb_exit() / gdb_set_stop_cpu() target agnostic exec/cpu: Make address_space_init/reloading_memory_map target agnostic
softmmu: Add qemu_init_arch_modules()
softmmu: Build target-agnostic objects once

 accel/kvm/kvm-accel-ops.c         | 12 ++++++++++
 accel/meson.build                 | 12 ++++++----
 accel/qtest/qtest.c               |  1 -
 accel/stubs/hax-stub.c            |  2 ++
 accel/stubs/kvm-stub.c            |  5 ----
 accel/stubs/meson.build           | 11 +++++----
 accel/tcg/tcg-accel-ops-icount.c  |  1 +
 accel/tcg/tcg-accel-ops-mttcg.c   |  1 +
 accel/tcg/tcg-accel-ops-rr.c      |  1 +
 accel/tcg/tcg-accel-ops.c         |  1 +
 cpu.c                             |  6 ++---
 include/exec/cpu-all.h            |  4 ----
 include/exec/cpu-common.h         | 39 +++++++++++++++++++++++++++++++
 include/exec/exec-all.h           | 26 ---------------------
 include/exec/gdbstub.h            | 23 +++++++++---------
 include/hw/core/cpu.h             | 13 +----------
 include/sysemu/accel-ops.h        |  3 +++
 include/sysemu/arch_init.h        |  2 ++
 include/sysemu/hax.h              | 18 +++++++++-----
 include/sysemu/hw_accel.h         |  5 ----
 include/sysemu/kvm.h              |  6 ++---
 include/sysemu/memory_mapping.h   |  5 ++--
 softmmu/arch_init.c               |  9 +++++++
 softmmu/cpu-timers.c              |  1 -
 softmmu/cpus.c                    | 23 +++++++++++-------
 softmmu/globals.c                 |  2 --
 softmmu/memory_mapping.c          |  1 +
 softmmu/meson.build               | 24 +++++++++----------
 softmmu/physmem.c                 |  7 +++---
 softmmu/runstate.c                |  2 +-
 softmmu/vl.c                      |  5 +---
 target/alpha/translate.c          |  1 -
 target/i386/hax/hax-all.c         |  7 +-----
 target/i386/whpx/whpx-accel-ops.c |  6 +++++
 target/riscv/csr.c                |  1 +
 tests/unit/ptimer-test-stubs.c    |  1 -
 36 files changed, 158 insertions(+), 129 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/21 accel: Restrict sysemu stubs to system emulation

---
 accel/stubs/meson.build | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
accel/stubs/meson.build +7 -4
index 12dd1539af..0249b9258f 100644
@@ -1,4 +1,7 @@
-specific_ss.add(when: 'CONFIG_HAX', if_false: files('hax-stub.c'))
-specific_ss.add(when: 'CONFIG_XEN', if_false: files('xen-stub.c'))
-specific_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
-specific_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c'))
+sysemu_stubs_ss = ss.source_set()
+sysemu_stubs_ss.add(when: 'CONFIG_HAX', if_false: files('hax-stub.c'))
+sysemu_stubs_ss.add(when: 'CONFIG_XEN', if_false: files('xen-stub.c'))
+sysemu_stubs_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
+sysemu_stubs_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c'))
+
+specific_ss.add_all(when: ['CONFIG_SOFTMMU'], if_true: sysemu_stubs_ss)
Signature · 1 line
2.34.1
Reviewed-by on v2 1/21
#2 lore raw

Re: [PATCH v2 01/21] accel: Restrict sysemu stubs to system emulation

Quoted 11 lines · Philippe Mathieu-Daudé
---
  accel/stubs/meson.build | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
accel/stubs/meson.build +0 -1
index 12dd1539af..0249b9258f 100644
@@ -1,4 +1,7 @@
-specific_ss.add(when: 'CONFIG_HAX', if_false: files('hax-stub.c'))

accel/stubs/meson.build line 7

Quoted 10 lines
accel/stubs/meson.build +7 -3
-specific_ss.add(when: 'CONFIG_XEN', if_false: files('xen-stub.c'))
-specific_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
-specific_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c'))
+sysemu_stubs_ss = ss.source_set()
+sysemu_stubs_ss.add(when: 'CONFIG_HAX', if_false: files('hax-stub.c'))
+sysemu_stubs_ss.add(when: 'CONFIG_XEN', if_false: files('xen-stub.c'))
+sysemu_stubs_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
+sysemu_stubs_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c'))
+
+specific_ss.add_all(when: ['CONFIG_SOFTMMU'], if_true: sysemu_stubs_ss)
Reviewed-by on v2 1/21
#3 lore raw

Re: [PATCH v2 01/21] accel: Restrict sysemu stubs to system emulation

In reply to Philippe Mathieu-Daudé via
Quoted 11 lines · Philippe Mathieu-Daudé
---
  accel/stubs/meson.build | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
accel/stubs/meson.build +0 -1
index 12dd1539af..0249b9258f 100644
@@ -1,4 +1,7 @@
-specific_ss.add(when: 'CONFIG_HAX', if_false: files('hax-stub.c'))

accel/stubs/meson.build line 7

Quoted 10 lines
accel/stubs/meson.build +7 -3
-specific_ss.add(when: 'CONFIG_XEN', if_false: files('xen-stub.c'))
-specific_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
-specific_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c'))
+sysemu_stubs_ss = ss.source_set()
+sysemu_stubs_ss.add(when: 'CONFIG_HAX', if_false: files('hax-stub.c'))
+sysemu_stubs_ss.add(when: 'CONFIG_XEN', if_false: files('xen-stub.c'))
+sysemu_stubs_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
+sysemu_stubs_ss.add(when: 'CONFIG_TCG', if_false: files('tcg-stub.c'))
+
+specific_ss.add_all(when: ['CONFIG_SOFTMMU'], if_true: sysemu_stubs_ss)

r~

#4 lore raw

PATCH v2 2/21 accel/meson: Only build hw virtualization with system emulation

In reply to Philippe Mathieu-Daudé via
---
 accel/meson.build | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
accel/meson.build +7 -5
index dfd808d2c8..b9a963cf80 100644
@@ -2,12 +2,14 @@ specific_ss.add(files('accel-common.c'))
 softmmu_ss.add(files('accel-softmmu.c'))
 user_ss.add(files('accel-user.c'))
 
-subdir('hvf')
-subdir('qtest')
-subdir('kvm')
 subdir('tcg')
-subdir('xen')
-subdir('stubs')
+if have_system
+  subdir('hvf')
+  subdir('qtest')
+  subdir('kvm')
+  subdir('xen')
+  subdir('stubs')
+endif
 
 dummy_ss = ss.source_set()
 dummy_ss.add(files(
Signature · 1 line
2.34.1
Reviewed-by on v2 2/21
#5 lore raw

Re: [PATCH v2 02/21] accel/meson: Only build hw virtualization with system emulation

Quoted 16 lines · Philippe Mathieu-Daudé
---
  accel/meson.build | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
accel/meson.build +0 -2
index dfd808d2c8..b9a963cf80 100644
@@ -2,12 +2,14 @@ specific_ss.add(files('accel-common.c'))
  softmmu_ss.add(files('accel-softmmu.c'))
  user_ss.add(files('accel-user.c'))
 
-subdir('hvf')
-subdir('qtest')

accel/meson.build specific_ss.add(files('accel-common.c')) · line 11

Quoted 10 lines
accel/meson.build +6 -3
-subdir('kvm')
  subdir('tcg')
-subdir('xen')
-subdir('stubs')
+if have_system
+  subdir('hvf')
+  subdir('qtest')
+  subdir('kvm')
+  subdir('xen')
+  subdir('stubs')

Doesn't this render your first patch useless?

accel/meson.build specific_ss.add(files('accel-common.c')) · line 15

Quoted 4 lines
accel/meson.build +1 -0
+endif
 
  dummy_ss = ss.source_set()
  dummy_ss.add(files(
#6 lore raw

Re: [PATCH v2 02/21] accel/meson: Only build hw virtualization with system emulation

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

---
  accel/meson.build | 12 +++++++-----

  1 file changed, 7 insertions(+), 5 deletions(-)
accel/meson.build +0 -5
index dfd808d2c8..b9a963cf80 100644
@@ -2,12 +2,14 @@ specific_ss.add(files('accel-common.c'))
   softmmu_ss.add(files('accel-softmmu.c'))
   user_ss.add(files('accel-user.c'))
-subdir('hvf')
-subdir('qtest')
-subdir('kvm')
   subdir('tcg')
-subdir('xen')
-subdir('stubs')
Quoted 8 lines

accel/meson.build specific_ss.add(files('accel-common.c')) · line 11

Quoted 6 lines
accel/meson.build +6 -0
+if have_system
+  subdir('hvf')
+  subdir('qtest')
+  subdir('kvm')
+  subdir('xen')
+  subdir('stubs')

Doesn't this render your first patch useless?

No, we don't want to build non-TCG stubs in user-mode ;)

Quoted 6 lines
Quoted 3 lines
accel/meson.build +1 -0
+endif
   dummy_ss = ss.source_set()

  dummy_ss.add(files(

#7 lore raw

Re: [PATCH v2 02/21] accel/meson: Only build hw virtualization with system emulation

Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 20 lines · Thomas Huth
Quoted 19 lines · Philippe Mathieu-Daudé

---
  accel/meson.build | 12 +++++++-----

  1 file changed, 7 insertions(+), 5 deletions(-)
accel/meson.build +0 -5
index dfd808d2c8..b9a963cf80 100644
@@ -2,12 +2,14 @@ specific_ss.add(files('accel-common.c'))
   softmmu_ss.add(files('accel-softmmu.c'))
   user_ss.add(files('accel-user.c'))
-subdir('hvf')
-subdir('qtest')
-subdir('kvm')
   subdir('tcg')
-subdir('xen')
-subdir('stubs')
Quoted 8 lines

accel/meson.build specific_ss.add(files('accel-common.c')) · line 11

Quoted 6 lines
accel/meson.build +6 -0
+if have_system
+  subdir('hvf')
+  subdir('qtest')
+  subdir('kvm')
+  subdir('xen')
+  subdir('stubs')

Doesn't this render your first patch useless?

Quoted 1 line

No, we don't want to build non-TCG stubs in user-mode ;)

Ah, well, looking at this twice, I think it's ok, indeed. I was confused by the fact that "have_system" and the "CONFIG_SOFTMMU" from patch 01 can have two different meanings if the QEMU build has been configured with both, softmmu and user targets. So never mind, please!

Thomas

#8 lore raw

PATCH v2 3/21 exec: Declare vaddr as a generic target-agnostic type

In reply to Philippe Mathieu-Daudé via

Move vaddr type declaration to the generic "exec/cpu-common.h" header.

---
 include/exec/cpu-common.h | 12 ++++++++++++
 include/hw/core/cpu.h     | 13 +------------
 2 files changed, 13 insertions(+), 12 deletions(-)
include/exec/cpu-common.h +12 -0
index de5f444b19..cd1d7328a1 100644
@@ -7,6 +7,18 @@
 #include "exec/hwaddr.h"
 #endif
 
+/**
+ * vaddr:
+ * Type wide enough to contain any #target_ulong virtual address.
+ */
+typedef uint64_t vaddr;
+#define VADDR_PRId PRId64
+#define VADDR_PRIu PRIu64
+#define VADDR_PRIo PRIo64
+#define VADDR_PRIx PRIx64
+#define VADDR_PRIX PRIX64
+#define VADDR_MAX UINT64_MAX
+
 /* Using intptr_t ensures that qemu_*_page_mask is sign-extended even
  * when intptr_t is 32-bit and we are aligning a long long.
  */
include/hw/core/cpu.h +1 -12
index 76ab3b851c..3f2b681281 100644
@@ -22,6 +22,7 @@
 
 #include "hw/qdev-core.h"
 #include "disas/dis-asm.h"
+#include "exec/cpu-common.h"
 #include "exec/hwaddr.h"
 #include "exec/memattrs.h"
 #include "qapi/qapi-types-run-state.h"
@@ -35,18 +36,6 @@
 typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
                                      void *opaque);
 
-/**
- * vaddr:
- * Type wide enough to contain any #target_ulong virtual address.
- */
-typedef uint64_t vaddr;
-#define VADDR_PRId PRId64
-#define VADDR_PRIu PRIu64
-#define VADDR_PRIo PRIo64
-#define VADDR_PRIx PRIx64
-#define VADDR_PRIX PRIX64
-#define VADDR_MAX UINT64_MAX
-
 /**
  * SECTION:cpu
  * @section_id: QEMU-cpu
Signature · 1 line
2.34.1
Reviewed-by on v2 3/21
#9 lore raw

Re: [PATCH v2 03/21] exec: Declare vaddr as a generic target-agnostic type

Quoted 7 lines · Philippe Mathieu-Daudé

Move vaddr type declaration to the generic "exec/cpu-common.h" header.

---
  include/exec/cpu-common.h | 12 ++++++++++++
  include/hw/core/cpu.h     | 13 +------------
  2 files changed, 13 insertions(+), 12 deletions(-)

r~

#10 lore raw

PATCH v2 4/21 exec: Make cpu_memory_rw_debug() target agnostic

In reply to Philippe Mathieu-Daudé via

cpu_memory_rw_debug() is declared in "exec/cpu-all.h" which contains target-specific declarations. To be able to use it from target agnostic source, move the declaration to the generic "exec/cpu-common.h" header.

Replace the target-specific 'target_ulong' type by 'vaddr' which better reflects the argument type, and is target agnostic.

---
 cpu.c                     | 6 +++---
 include/exec/cpu-all.h    | 4 ----
 include/exec/cpu-common.h | 4 ++++
 softmmu/cpus.c            | 2 +-
 softmmu/physmem.c         | 6 +++---
 5 files changed, 11 insertions(+), 11 deletions(-)
cpu.c +3 -3
index 016bf06a1a..97d42b6b2a 100644
@@ -395,11 +395,11 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...)
 
 /* physical memory access (slow version, mainly for debug) */
 #if defined(CONFIG_USER_ONLY)
-int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
-                        void *ptr, target_ulong len, bool is_write)
+int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
+                        void *ptr, size_t len, bool is_write)
 {
     int flags;
-    target_ulong l, page;
+    vaddr l, page;
     void * p;
     uint8_t *buf = ptr;
 
include/exec/cpu-all.h +0 -4
index 84caf5c3d9..c0f0fab28a 100644
@@ -433,10 +433,6 @@ int cpu_exec(CPUState *cpu);
 void tcg_exec_realizefn(CPUState *cpu, Error **errp);
 void tcg_exec_unrealizefn(CPUState *cpu);
 
-/* Returns: 0 on success, -1 on error */
-int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
-                        void *ptr, target_ulong len, bool is_write);
-
 /**
  * cpu_set_cpustate_pointers(cpu)
  * @cpu: The cpu object
include/exec/cpu-common.h +4 -0
index cd1d7328a1..8031ebc680 100644
@@ -128,6 +128,10 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length);
 
 #endif
 
+/* Returns: 0 on success, -1 on error */
+int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
+                        void *ptr, size_t len, bool is_write);
+
 /* vl.c */
 extern int singlestep;
 
softmmu/cpus.c +1 -1
index 23bca46b07..7f15106dd9 100644
@@ -32,7 +32,7 @@
 #include "qapi/qmp/qerror.h"
 #include "exec/gdbstub.h"
 #include "sysemu/hw_accel.h"
-#include "exec/exec-all.h"
+#include "exec/cpu-common.h"
 #include "qemu/thread.h"
 #include "qemu/plugin.h"
 #include "sysemu/cpus.h"
softmmu/physmem.c +3 -3
index dddf70edf5..eb4b3bcae7 100644
@@ -3435,11 +3435,11 @@ address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr,
 #include "memory_ldst.c.inc"
 
 /* virtual memory access for debug (includes writing to ROM) */
-int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
-                        void *ptr, target_ulong len, bool is_write)
+int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
+                        void *ptr, size_t len, bool is_write)
 {
     hwaddr phys_addr;
-    target_ulong l, page;
+    vaddr l, page;
     uint8_t *buf = ptr;
 
     cpu_synchronize_state(cpu);
Signature · 1 line
2.34.1
Reviewed-by on v2 4/21
#11 lore raw

Re: [PATCH v2 04/21] exec: Make cpu_memory_rw_debug() target agnostic

Quoted 10 lines · Philippe Mathieu-Daudé

cpu_memory_rw_debug() is declared in "exec/cpu-all.h" which contains target-specific declarations. To be able to use it from target agnostic source, move the declaration to the generic "exec/cpu-common.h" header.

Replace the target-specific 'target_ulong' type by 'vaddr' which better reflects the argument type, and is target agnostic.

Quoted 7 lines
---
  cpu.c                     | 6 +++---
  include/exec/cpu-all.h    | 4 ----
  include/exec/cpu-common.h | 4 ++++
  softmmu/cpus.c            | 2 +-
  softmmu/physmem.c         | 6 +++---
  5 files changed, 11 insertions(+), 11 deletions(-)

r~

#12 lore raw

PATCH v2 5/21 sysemu/memory_mapping: Become target-agnostic

In reply to Philippe Mathieu-Daudé via

target_ulong is target-specific, while vaddr isn't.

Remove the unnecessary "exec/cpu-defs.h" target-speficic header from "memory_mapping.h" and use the target-agnostic "hw/core/cpu.h" locally in memory_mapping.c.

Remove "exec/memory.h" since MemoryRegion is forward-declared in "qemu/typedefs.h".

---
 include/sysemu/memory_mapping.h | 5 ++---
 softmmu/memory_mapping.c        | 1 +
 2 files changed, 3 insertions(+), 3 deletions(-)
include/sysemu/memory_mapping.h +2 -3
index 4b20f1a639..3bbeb1bcb4 100644
@@ -15,8 +15,7 @@
 #define MEMORY_MAPPING_H
 
 #include "qemu/queue.h"
-#include "exec/cpu-defs.h"
-#include "exec/memory.h"
+#include "exec/cpu-common.h"
 
 typedef struct GuestPhysBlock {
     /* visible to guest, reflects PCI hole, etc */
@@ -43,7 +42,7 @@ typedef struct GuestPhysBlockList {
 /* The physical and virtual address in the memory mapping are contiguous. */
 typedef struct MemoryMapping {
     hwaddr phys_addr;
-    target_ulong virt_addr;
+    vaddr virt_addr;
     ram_addr_t length;
     QTAILQ_ENTRY(MemoryMapping) next;
 } MemoryMapping;
softmmu/memory_mapping.c +1 -0
index a62eaa49cc..8320165ea2 100644
@@ -17,6 +17,7 @@
 #include "sysemu/memory_mapping.h"
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
+#include "hw/core/cpu.h"
 
 //#define DEBUG_GUEST_PHYS_REGION_ADD
 
Signature · 1 line
2.34.1
#13 lore raw

PATCH v2 6/21 sysemu/kvm: Make kvm_on_sigbus() / kvm_on_sigbus_vcpu() target agnostic

In reply to Philippe Mathieu-Daudé via

kvm_on_sigbus() and kvm_on_sigbus_vcpu() prototypes don't have to be target specific. Remove this limitation to be able to build softmmu/cpus.c once for all targets.

---
 include/sysemu/kvm.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/sysemu/kvm.h +3 -3
index 6eb39a088b..a5bec96fb0 100644
@@ -249,6 +249,9 @@ int kvm_has_intx_set_mask(void);
 bool kvm_arm_supports_user_irq(void);
 
 
+int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr);
+int kvm_on_sigbus(int code, void *addr);
+
 #ifdef NEED_CPU_H
 #include "cpu.h"
 
@@ -261,9 +264,6 @@ int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
 void kvm_remove_all_breakpoints(CPUState *cpu);
 int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap);
 
-int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr);
-int kvm_on_sigbus(int code, void *addr);
-
 /* internal API */
 
 int kvm_ioctl(KVMState *s, int type, ...);
Signature · 1 line
2.34.1
#14 lore raw

PATCH v2 7/21 accel/kvm: Simplify user-mode #ifdef'ry

In reply to Philippe Mathieu-Daudé via

Now than we only build this stub with system emulation, remove the user-mode #ifdef'ry.

---
 accel/stubs/kvm-stub.c | 5 -----
 1 file changed, 5 deletions(-)
accel/stubs/kvm-stub.c +0 -5
index 5319573e00..7e0fb884b9 100644
@@ -12,10 +12,7 @@
 
 #include "qemu/osdep.h"
 #include "sysemu/kvm.h"
-
-#ifndef CONFIG_USER_ONLY
 #include "hw/pci/msi.h"
-#endif
 
 KVMState *kvm_state;
 bool kvm_kernel_irqchip;
@@ -80,7 +77,6 @@ int kvm_on_sigbus(int code, void *addr)
     return 1;
 }
 
-#ifndef CONFIG_USER_ONLY
 int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev)
 {
     return -ENOSYS;
@@ -152,4 +148,3 @@ bool kvm_dirty_ring_enabled(void)
 {
     return false;
 }
-#endif
Signature · 1 line
2.34.1
#15 lore raw

PATCH v2 8/21 accel/hax: Introduce CONFIG_HAX_IS_POSSIBLE

In reply to Philippe Mathieu-Daudé via

Mirror "sysemu/kvm.h" #ifdef'ry to define CONFIG_HAX_IS_POSSIBLE, expose hax_allowed to hax_enabled() macro.

---
 accel/stubs/hax-stub.c    |  2 ++
 include/sysemu/hax.h      | 18 ++++++++++++------
 target/i386/hax/hax-all.c |  7 +------
 3 files changed, 15 insertions(+), 12 deletions(-)
accel/stubs/hax-stub.c +2 -0
index 49077f88e3..2fe31aaa9a 100644
@@ -16,6 +16,8 @@
 #include "qemu/osdep.h"
 #include "sysemu/hax.h"
 
+bool hax_allowed;
+
 int hax_sync_vcpus(void)
 {
     return 0;
include/sysemu/hax.h +12 -6
index 247f0661d1..bf8f99a824 100644
@@ -25,17 +25,23 @@
 int hax_sync_vcpus(void);
 
 #ifdef NEED_CPU_H
+# ifdef CONFIG_HAX
+#  define CONFIG_HAX_IS_POSSIBLE
+# endif
+#else /* !NEED_CPU_H */
+# define CONFIG_HAX_IS_POSSIBLE
+#endif
 
-#ifdef CONFIG_HAX
+#ifdef CONFIG_HAX_IS_POSSIBLE
 
-int hax_enabled(void);
+extern bool hax_allowed;
 
-#else /* CONFIG_HAX */
+#define hax_enabled()               (hax_allowed)
 
-#define hax_enabled() (0)
+#else /* !CONFIG_HAX_IS_POSSIBLE */
 
-#endif /* CONFIG_HAX */
+#define hax_enabled()               (0)
 
-#endif /* NEED_CPU_H */
+#endif /* CONFIG_HAX_IS_POSSIBLE */
 
 #endif /* QEMU_HAX_H */
target/i386/hax/hax-all.c +1 -6
index bf65ed6fa9..ccdcb6afab 100644
@@ -49,18 +49,13 @@ const uint32_t hax_cur_version = 0x4; /* API v4: unmapping and MMIO moves */
 /* Minimum HAX kernel version */
 const uint32_t hax_min_version = 0x4; /* API v4: supports unmapping */
 
-static bool hax_allowed;
+bool hax_allowed;
 
 struct hax_state hax_global;
 
 static void hax_vcpu_sync_state(CPUArchState *env, int modified);
 static int hax_arch_get_registers(CPUArchState *env);
 
-int hax_enabled(void)
-{
-    return hax_allowed;
-}
-
 int valid_hax_tunnel_size(uint16_t size)
 {
     return size >= sizeof(struct hax_tunnel);
Signature · 1 line
2.34.1
Reviewed-by on v2 8/21
#16 lore raw

Re: [PATCH v2 08/21] accel/hax: Introduce CONFIG_HAX_IS_POSSIBLE

Quoted 10 lines · Philippe Mathieu-Daudé

Mirror "sysemu/kvm.h" #ifdef'ry to define CONFIG_HAX_IS_POSSIBLE, expose hax_allowed to hax_enabled() macro.

---
  accel/stubs/hax-stub.c    |  2 ++
  include/sysemu/hax.h      | 18 ++++++++++++------
  target/i386/hax/hax-all.c |  7 +------
  3 files changed, 15 insertions(+), 12 deletions(-)

r~

#17 lore raw

PATCH v2 9/21 softmmu/cpus: Code movement

In reply to Philippe Mathieu-Daudé via

We want cpu_thread_is_idle() to use cpus_accel, so declare this variable earlier.

---
 softmmu/cpus.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
softmmu/cpus.c +5 -5
index 7f15106dd9..538e1714af 100644
@@ -66,6 +66,11 @@
 
 static QemuMutex qemu_global_mutex;
 
+/*
+ * The chosen accelerator is supposed to register this.
+ */
+static const AccelOpsClass *cpus_accel;
+
 bool cpu_is_stopped(CPUState *cpu)
 {
     return cpu->stopped || !runstate_is_running();
@@ -126,11 +131,6 @@ void hw_error(const char *fmt, ...)
     abort();
 }
 
-/*
- * The chosen accelerator is supposed to register this.
- */
-static const AccelOpsClass *cpus_accel;
-
 void cpu_synchronize_all_states(void)
 {
     CPUState *cpu;
Signature · 1 line
2.34.1
#19 lore raw

PATCH v2 10/21 accel: Introduce AccelOpsClass::cpu_thread_is_idle()

In reply to Philippe Mathieu-Daudé via

Add cpu_thread_is_idle() to AccelOps, and implement it for the KVM / WHPX accelerators.

---
 accel/kvm/kvm-accel-ops.c         | 6 ++++++
 include/sysemu/accel-ops.h        | 1 +
 softmmu/cpus.c                    | 6 ++++--
 target/i386/whpx/whpx-accel-ops.c | 6 ++++++
 4 files changed, 17 insertions(+), 2 deletions(-)
accel/kvm/kvm-accel-ops.c +6 -0
index 7516c67a3f..95b7b08020 100644
@@ -74,11 +74,17 @@ static void kvm_start_vcpu_thread(CPUState *cpu)
                        cpu, QEMU_THREAD_JOINABLE);
 }
 
+static bool kvm_vcpu_thread_is_idle(CPUState *cpu)
+{
+    return !kvm_halt_in_kernel();
+}
+
 static void kvm_accel_ops_class_init(ObjectClass *oc, void *data)
 {
     AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
 
     ops->create_vcpu_thread = kvm_start_vcpu_thread;
+    ops->cpu_thread_is_idle = kvm_vcpu_thread_is_idle;
     ops->synchronize_post_reset = kvm_cpu_synchronize_post_reset;
     ops->synchronize_post_init = kvm_cpu_synchronize_post_init;
     ops->synchronize_state = kvm_cpu_synchronize_state;
include/sysemu/accel-ops.h +1 -0
index 032f6979d7..50c72540c7 100644
@@ -30,6 +30,7 @@ struct AccelOpsClass {
 
     void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */
     void (*kick_vcpu_thread)(CPUState *cpu);
+    bool (*cpu_thread_is_idle)(CPUState *cpu);
 
     void (*synchronize_post_reset)(CPUState *cpu);
     void (*synchronize_post_init)(CPUState *cpu);
softmmu/cpus.c +4 -2
index 538e1714af..5b0bcb8c65 100644
@@ -94,10 +94,12 @@ bool cpu_thread_is_idle(CPUState *cpu)
     if (cpu_is_stopped(cpu)) {
         return true;
     }
-    if (!cpu->halted || cpu_has_work(cpu) ||
-        kvm_halt_in_kernel() || whpx_apic_in_platform()) {
+    if (!cpu->halted || cpu_has_work(cpu)) {
         return false;
     }
+    if (cpus_accel->cpu_thread_is_idle) {
+        return cpus_accel->cpu_thread_is_idle(cpu);
+    }
     return true;
 }
 
target/i386/whpx/whpx-accel-ops.c +6 -0
index 6bc47c5309..1d30e4e2ed 100644
@@ -83,12 +83,18 @@ static void whpx_kick_vcpu_thread(CPUState *cpu)
     }
 }
 
+static bool whpx_vcpu_thread_is_idle(CPUState *cpu)
+{
+    return !whpx_apic_in_platform();
+}
+
 static void whpx_accel_ops_class_init(ObjectClass *oc, void *data)
 {
     AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
 
     ops->create_vcpu_thread = whpx_start_vcpu_thread;
     ops->kick_vcpu_thread = whpx_kick_vcpu_thread;
+    ops->cpu_thread_is_idle = whpx_vcpu_thread_is_idle;
 
     ops->synchronize_post_reset = whpx_cpu_synchronize_post_reset;
     ops->synchronize_post_init = whpx_cpu_synchronize_post_init;
Signature · 1 line
2.34.1
Reviewed-by on v2 10/21
#20 lore raw

Re: [PATCH v2 10/21] accel: Introduce AccelOpsClass::cpu_thread_is_idle()

Quoted 11 lines · Philippe Mathieu-Daudé

Add cpu_thread_is_idle() to AccelOps, and implement it for the KVM / WHPX accelerators.

---
  accel/kvm/kvm-accel-ops.c         | 6 ++++++
  include/sysemu/accel-ops.h        | 1 +
  softmmu/cpus.c                    | 6 ++++--
  target/i386/whpx/whpx-accel-ops.c | 6 ++++++
  4 files changed, 17 insertions(+), 2 deletions(-)

r~

#21 lore raw

PATCH v2 11/21 accel: Introduce AccelOpsClass::cpus_are_resettable()

In reply to Philippe Mathieu-Daudé via

Add cpus_are_resettable() to AccelOps, and implement it for the KVM accelerator.

---
 accel/kvm/kvm-accel-ops.c  | 6 ++++++
 include/sysemu/accel-ops.h | 2 ++
 include/sysemu/hw_accel.h  | 5 -----
 softmmu/cpus.c             | 5 ++++-
 4 files changed, 12 insertions(+), 6 deletions(-)
accel/kvm/kvm-accel-ops.c +6 -0
index 95b7b08020..cd4d4a06a7 100644
@@ -79,12 +79,18 @@ static bool kvm_vcpu_thread_is_idle(CPUState *cpu)
     return !kvm_halt_in_kernel();
 }
 
+static bool kvm_cpus_are_resettable(void)
+{
+    return kvm_enabled() ? kvm_cpu_check_are_resettable() : true;
+}
+
 static void kvm_accel_ops_class_init(ObjectClass *oc, void *data)
 {
     AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
 
     ops->create_vcpu_thread = kvm_start_vcpu_thread;
     ops->cpu_thread_is_idle = kvm_vcpu_thread_is_idle;
+    ops->cpus_are_resettable = kvm_cpus_are_resettable;
     ops->synchronize_post_reset = kvm_cpu_synchronize_post_reset;
     ops->synchronize_post_init = kvm_cpu_synchronize_post_init;
     ops->synchronize_state = kvm_cpu_synchronize_state;
include/sysemu/accel-ops.h +2 -0
index 50c72540c7..6013c9444c 100644
@@ -28,6 +28,8 @@ struct AccelOpsClass {
     /* initialization function called when accel is chosen */
     void (*ops_init)(AccelOpsClass *ops);
 
+    bool (*cpus_are_resettable)(void);
+
     void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */
     void (*kick_vcpu_thread)(CPUState *cpu);
     bool (*cpu_thread_is_idle)(CPUState *cpu);
include/sysemu/hw_accel.h +0 -5
index 01b5ebf442..22903a55f7 100644
@@ -23,9 +23,4 @@ void cpu_synchronize_post_reset(CPUState *cpu);
 void cpu_synchronize_post_init(CPUState *cpu);
 void cpu_synchronize_pre_loadvm(CPUState *cpu);
 
-static inline bool cpu_check_are_resettable(void)
-{
-    return kvm_enabled() ? kvm_cpu_check_are_resettable() : true;
-}
-
 #endif /* QEMU_HW_ACCEL_H */
softmmu/cpus.c +4 -1
index 5b0bcb8c65..79e7d7a608 100644
@@ -199,7 +199,10 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu)
 
 bool cpus_are_resettable(void)
 {
-    return cpu_check_are_resettable();
+    if (cpus_accel->cpus_are_resettable) {
+        return cpus_accel->cpus_are_resettable();
+    }
+    return true;
 }
 
 int64_t cpus_get_virtual_clock(void)
Signature · 1 line
2.34.1
Reviewed-by on v2 11/21
#22 lore raw

Re: [PATCH v2 11/21] accel: Introduce AccelOpsClass::cpus_are_resettable()

Quoted 17 lines · Philippe Mathieu-Daudé

Add cpus_are_resettable() to AccelOps, and implement it for the KVM accelerator.

---
  accel/kvm/kvm-accel-ops.c  | 6 ++++++
  include/sysemu/accel-ops.h | 2 ++
  include/sysemu/hw_accel.h  | 5 -----
  softmmu/cpus.c             | 5 ++++-
  4 files changed, 12 insertions(+), 6 deletions(-)
accel/kvm/kvm-accel-ops.c +0 -0
index 95b7b08020..cd4d4a06a7 100644

accel/kvm/kvm-accel-ops.c static bool kvm_vcpu_thread_is_idle(CPUState *cpu) · line 85

Quoted 7 lines
accel/kvm/kvm-accel-ops.c +4 -0
@@ -79,12 +79,18 @@ static bool kvm_vcpu_thread_is_idle(CPUState *cpu)
      return !kvm_halt_in_kernel();
  }
 
+static bool kvm_cpus_are_resettable(void)
+{
+    return kvm_enabled() ? kvm_cpu_check_are_resettable() : true;
+}

Hrm. This is code movement, but this calls out to be rewritten with proper logical operations:

    !kvm_enabled() || kvm_cpu_check_are_resettable();

Anyway,

r~

#23 lore raw

PATCH v2 12/21 softmmu/globals: Remove unused 'hw/i386/*' headers

In reply to Philippe Mathieu-Daudé via
---
 softmmu/globals.c | 2 --
 1 file changed, 2 deletions(-)
softmmu/globals.c +0 -2
index 7d0fc81183..3ebd718e35 100644
@@ -25,8 +25,6 @@
 #include "qemu/osdep.h"
 #include "exec/cpu-common.h"
 #include "hw/display/vga.h"
-#include "hw/i386/pc.h"
-#include "hw/i386/x86.h"
 #include "hw/loader.h"
 #include "hw/xen/xen.h"
 #include "net/net.h"
Signature · 1 line
2.34.1
#24 lore raw

PATCH v2 13/21 softmmu/runstate: Clean headers

In reply to Philippe Mathieu-Daudé via

Add the missing 'qemu/log.h' header and remove the unused 'exec/exec-all.h' one.

---
 softmmu/runstate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
softmmu/runstate.c +1 -1
index 10d9b7365a..3cb2758b33 100644
@@ -30,7 +30,6 @@
 #include "crypto/cipher.h"
 #include "crypto/init.h"
 #include "exec/cpu-common.h"
-#include "exec/exec-all.h"
 #include "exec/gdbstub.h"
 #include "hw/boards.h"
 #include "migration/misc.h"
@@ -44,6 +43,7 @@
 #include "qemu-common.h"
 #include "qemu/error-report.h"
 #include "qemu/job.h"
+#include "qemu/log.h"
 #include "qemu/module.h"
 #include "qemu/plugin.h"
 #include "qemu/sockets.h"
Signature · 1 line
2.34.1
Reviewed-by on v2 14/21
#26 lore raw

Re: [PATCH v2 14/21] softmmu/physmem: Remove unnecessary include

Quoted 10 lines · Philippe Mathieu-Daudé
---
  softmmu/physmem.c | 1 -
  1 file changed, 1 deletion(-)
softmmu/physmem.c +0 -0
index eb4b3bcae7..09951c0996 100644

softmmu/physmem.c line 65

Quoted 7 lines
softmmu/physmem.c +0 -1
@@ -60,7 +60,6 @@
 
  #include "exec/memory-internal.h"
  #include "exec/ram_addr.h"
-#include "exec/log.h"
 
  #include "qemu/pmem.h"
 

r~

#27 lore raw

PATCH v2 15/21 softmmu/cpu-timers: Remove unused 'exec/exec-all.h' header

In reply to Philippe Mathieu-Daudé via
---
 softmmu/cpu-timers.c | 1 -
 1 file changed, 1 deletion(-)
softmmu/cpu-timers.c +0 -1
index 34ddfa02f1..204d946a17 100644
@@ -28,7 +28,6 @@
 #include "migration/vmstate.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
-#include "exec/exec-all.h"
 #include "sysemu/cpus.h"
 #include "qemu/main-loop.h"
 #include "qemu/option.h"
Signature · 1 line
2.34.1
#28 lore raw

PATCH v2 16/21 misc: Remove unnecessary "sysemu/cpu-timers.h" include

In reply to Philippe Mathieu-Daudé via
---
 accel/qtest/qtest.c            | 1 -
 target/alpha/translate.c       | 1 -
 tests/unit/ptimer-test-stubs.c | 1 -
 3 files changed, 3 deletions(-)
accel/qtest/qtest.c +0 -1
index 7e6b8110d5..f6056ac836 100644
@@ -20,7 +20,6 @@
 #include "qemu/accel.h"
 #include "sysemu/qtest.h"
 #include "sysemu/cpus.h"
-#include "sysemu/cpu-timers.h"
 #include "qemu/guest-random.h"
 #include "qemu/main-loop.h"
 #include "hw/core/cpu.h"
target/alpha/translate.c +0 -1
index ca78a0faed..66768ab47a 100644
@@ -20,7 +20,6 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "sysemu/cpus.h"
-#include "sysemu/cpu-timers.h"
 #include "disas/disas.h"
 #include "qemu/host-utils.h"
 #include "exec/exec-all.h"
tests/unit/ptimer-test-stubs.c +0 -1
index 2a3ef58799..f5e75a96b6 100644
@@ -12,7 +12,6 @@
 #include "qemu/main-loop.h"
 #include "sysemu/replay.h"
 #include "migration/vmstate.h"
-#include "sysemu/cpu-timers.h"
 
 #include "ptimer-test.h"
 
Signature · 1 line
2.34.1
#30 lore raw

PATCH v2 17/21 misc: Add missing "sysemu/cpu-timers.h" include

In reply to Philippe Mathieu-Daudé via
---
 accel/tcg/tcg-accel-ops-icount.c | 1 +
 accel/tcg/tcg-accel-ops-mttcg.c  | 1 +
 accel/tcg/tcg-accel-ops-rr.c     | 1 +
 accel/tcg/tcg-accel-ops.c        | 1 +
 include/exec/exec-all.h          | 1 -
 target/riscv/csr.c               | 1 +
 6 files changed, 5 insertions(+), 1 deletion(-)
accel/tcg/tcg-accel-ops-icount.c +1 -0
index ea42d1d51b..bdaf2c943b 100644
@@ -27,6 +27,7 @@
 #include "qemu-common.h"
 #include "sysemu/tcg.h"
 #include "sysemu/replay.h"
+#include "sysemu/cpu-timers.h"
 #include "qemu/main-loop.h"
 #include "qemu/guest-random.h"
 #include "exec/exec-all.h"
accel/tcg/tcg-accel-ops-mttcg.c +1 -0
index 29632bd4c0..dc421c8fd7 100644
@@ -27,6 +27,7 @@
 #include "qemu-common.h"
 #include "sysemu/tcg.h"
 #include "sysemu/replay.h"
+#include "sysemu/cpu-timers.h"
 #include "qemu/main-loop.h"
 #include "qemu/notify.h"
 #include "qemu/guest-random.h"
accel/tcg/tcg-accel-ops-rr.c +1 -0
index bf59f53dbc..a805fb6bdd 100644
@@ -27,6 +27,7 @@
 #include "qemu-common.h"
 #include "sysemu/tcg.h"
 #include "sysemu/replay.h"
+#include "sysemu/cpu-timers.h"
 #include "qemu/main-loop.h"
 #include "qemu/notify.h"
 #include "qemu/guest-random.h"
accel/tcg/tcg-accel-ops.c +1 -0
index 1a8e8390bd..ea7dcad674 100644
@@ -29,6 +29,7 @@
 #include "qemu-common.h"
 #include "sysemu/tcg.h"
 #include "sysemu/replay.h"
+#include "sysemu/cpu-timers.h"
 #include "qemu/main-loop.h"
 #include "qemu/guest-random.h"
 #include "exec/exec-all.h"
include/exec/exec-all.h +0 -1
index 35d8e93976..87df70fa8f 100644
@@ -24,7 +24,6 @@
 #ifdef CONFIG_TCG
 #include "exec/cpu_ldst.h"
 #endif
-#include "sysemu/cpu-timers.h"
 
 /* allow to see translation results - the slowdown should be negligible, so we leave it */
 #define DEBUG_DISAS
target/riscv/csr.c +1 -0
index e5f9d4ef93..a4db40769b 100644
@@ -22,6 +22,7 @@
 #include "cpu.h"
 #include "qemu/main-loop.h"
 #include "exec/exec-all.h"
+#include "sysemu/cpu-timers.h"
 
 /* CSR function table public API */
 void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops)
Signature · 1 line
2.34.1
Reviewed-by on v2 17/21
#31 lore raw

Re: [PATCH v2 17/21] misc: Add missing "sysemu/cpu-timers.h" include

Quoted 9 lines · Philippe Mathieu-Daudé
---
  accel/tcg/tcg-accel-ops-icount.c | 1 +
  accel/tcg/tcg-accel-ops-mttcg.c  | 1 +
  accel/tcg/tcg-accel-ops-rr.c     | 1 +
  accel/tcg/tcg-accel-ops.c        | 1 +
  include/exec/exec-all.h          | 1 -
  target/riscv/csr.c               | 1 +
  6 files changed, 5 insertions(+), 1 deletion(-)

r~

#32 lore raw

PATCH v2 18/21 exec/gdbstub: Make gdb_exit() / gdb_set_stop_cpu() target agnostic

In reply to Philippe Mathieu-Daudé via

gdb_exit() and gdb_set_stop_cpu() prototypes don't have to be target specific. Remove this limitation to be able to build softmmu/cpus.c and softmmu/runstate.c once for all targets.

---
 include/exec/gdbstub.h | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
include/exec/gdbstub.h +12 -11
index a024a0350d..84b1f2ff2a 100644
@@ -45,17 +45,6 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...);
  */
 void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va);
 int use_gdb_syscalls(void);
-void gdb_set_stop_cpu(CPUState *cpu);
-
-/**
- * gdb_exit: exit gdb session, reporting inferior status
- * @code: exit code reported
- *
- * This closes the session and sends a final packet to GDB reporting
- * the exit status of the program. It also cleans up any connections
- * detritus before returning.
- */
-void gdb_exit(int code);
 
 #ifdef CONFIG_USER_ONLY
 /**
@@ -177,6 +166,18 @@ static inline uint8_t * gdb_get_reg_ptr(GByteArray *buf, int len)
  */
 int gdbserver_start(const char *port_or_device);
 
+/**
+ * gdb_exit: exit gdb session, reporting inferior status
+ * @code: exit code reported
+ *
+ * This closes the session and sends a final packet to GDB reporting
+ * the exit status of the program. It also cleans up any connections
+ * detritus before returning.
+ */
+void gdb_exit(int code);
+
+void gdb_set_stop_cpu(CPUState *cpu);
+
 /**
  * gdb_has_xml:
  * This is an ugly hack to cope with both new and old gdb.
Signature · 1 line
2.34.1
#33 lore raw

PATCH v2 19/21 exec/cpu: Make address_space_init/reloading_memory_map target agnostic

In reply to Philippe Mathieu-Daudé via

cpu_address_space_init() and cpu_reloading_memory_map() are target-agnostic, but are declared in "exec/exec-all.h" which contains target-specific declarations. Any target-agnostic source including "exec/exec-all.h" becomes target-specific and we have to compile it N times for the N targets built. In order to avoid that, move the declarations to "exec/cpu-common.h" which only contains target-agnostic declarations.

---
 include/exec/cpu-common.h | 23 +++++++++++++++++++++++
 include/exec/exec-all.h   | 25 -------------------------
 2 files changed, 23 insertions(+), 25 deletions(-)
include/exec/cpu-common.h +23 -0
index 8031ebc680..7f7b5943c7 100644
@@ -90,6 +90,28 @@ void qemu_ram_unset_migratable(RAMBlock *rb);
 size_t qemu_ram_pagesize(RAMBlock *block);
 size_t qemu_ram_pagesize_largest(void);
 
+/**
+ * cpu_address_space_init:
+ * @cpu: CPU to add this address space to
+ * @asidx: integer index of this address space
+ * @prefix: prefix to be used as name of address space
+ * @mr: the root memory region of address space
+ *
+ * Add the specified address space to the CPU's cpu_ases list.
+ * The address space added with @asidx 0 is the one used for the
+ * convenience pointer cpu->as.
+ * The target-specific code which registers ASes is responsible
+ * for defining what semantics address space 0, 1, 2, etc have.
+ *
+ * Before the first call to this function, the caller must set
+ * cpu->num_ases to the total number of address spaces it needs
+ * to support.
+ *
+ * Note that with KVM only one address space is supported.
+ */
+void cpu_address_space_init(CPUState *cpu, int asidx,
+                            const char *prefix, MemoryRegion *mr);
+
 void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             hwaddr len, bool is_write);
 static inline void cpu_physical_memory_read(hwaddr addr,
@@ -102,6 +124,7 @@ static inline void cpu_physical_memory_write(hwaddr addr,
 {
     cpu_physical_memory_rw(addr, (void *)buf, len, true);
 }
+void cpu_reloading_memory_map(void);
 void *cpu_physical_memory_map(hwaddr addr,
                               hwaddr *plen,
                               bool is_write);
include/exec/exec-all.h +0 -25
index 87df70fa8f..199fd49e5d 100644
@@ -82,31 +82,6 @@ static inline bool cpu_loop_exit_requested(CPUState *cpu)
     return (int32_t)qatomic_read(&cpu_neg(cpu)->icount_decr.u32) < 0;
 }
 
-#if !defined(CONFIG_USER_ONLY)
-void cpu_reloading_memory_map(void);
-/**
- * cpu_address_space_init:
- * @cpu: CPU to add this address space to
- * @asidx: integer index of this address space
- * @prefix: prefix to be used as name of address space
- * @mr: the root memory region of address space
- *
- * Add the specified address space to the CPU's cpu_ases list.
- * The address space added with @asidx 0 is the one used for the
- * convenience pointer cpu->as.
- * The target-specific code which registers ASes is responsible
- * for defining what semantics address space 0, 1, 2, etc have.
- *
- * Before the first call to this function, the caller must set
- * cpu->num_ases to the total number of address spaces it needs
- * to support.
- *
- * Note that with KVM only one address space is supported.
- */
-void cpu_address_space_init(CPUState *cpu, int asidx,
-                            const char *prefix, MemoryRegion *mr);
-#endif
-
 #if !defined(CONFIG_USER_ONLY) && defined(CONFIG_TCG)
 /* cputlb.c */
 /**
Signature · 1 line
2.34.1
Reviewed-by on v2 19/21
#34 lore raw

Re: [PATCH v2 19/21] exec/cpu: Make address_space_init/reloading_memory_map target agnostic

Quoted 8 lines · Philippe Mathieu-Daudé

cpu_address_space_init() and cpu_reloading_memory_map() are target-agnostic, but are declared in "exec/exec-all.h" which contains target-specific declarations. Any target-agnostic source including "exec/exec-all.h" becomes target-specific and we have to compile it N times for the N targets built. In order to avoid that, move the declarations to "exec/cpu-common.h" which only contains target-agnostic declarations.

Quoted 5 lines
---
  include/exec/cpu-common.h | 23 +++++++++++++++++++++++
  include/exec/exec-all.h   | 25 -------------------------
  2 files changed, 23 insertions(+), 25 deletions(-)

r~

#35 lore raw

PATCH v2 20/21 softmmu: Add qemu_init_arch_modules()

In reply to Philippe Mathieu-Daudé via

module_allow_arch() is the single target-specific call in the whole vl.c file. Move the module initialization out to arch_init.c, that way we'll be able to build vl.o once for all targets (the next commit).

---
 include/sysemu/arch_init.h | 2 ++
 softmmu/arch_init.c        | 9 +++++++++
 softmmu/vl.c               | 5 +----
 3 files changed, 12 insertions(+), 4 deletions(-)
include/sysemu/arch_init.h +2 -0
index 70c579560a..79c2591425 100644
@@ -28,4 +28,6 @@ enum {
 
 extern const uint32_t arch_type;
 
+void qemu_init_arch_modules(void);
+
 #endif
softmmu/arch_init.c +9 -0
index 8919405c7b..79716f959b 100644
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
+#include "qemu/module.h"
 #include "sysemu/arch_init.h"
 
 #ifdef TARGET_SPARC
@@ -39,3 +40,11 @@ int graphic_depth = 32;
 #endif
 
 const uint32_t arch_type = QEMU_ARCH;
+
+void qemu_init_arch_modules(void)
+{
+#ifdef CONFIG_MODULES
+    module_init_info(qemu_modinfo);
+    module_allow_arch(TARGET_NAME);
+#endif
+}
softmmu/vl.c +1 -4
index 5e1b35ba48..08ff97f4e0 100644
@@ -2814,10 +2814,7 @@ void qemu_init(int argc, char **argv, char **envp)
     error_init(argv[0]);
     qemu_init_exec_dir(argv[0]);
 
-#ifdef CONFIG_MODULES
-    module_init_info(qemu_modinfo);
-    module_allow_arch(TARGET_NAME);
-#endif
+    qemu_init_arch_modules();
 
     qemu_init_subsystems();
 
Signature · 1 line
2.34.1
Reviewed-by on v2 20/21
#36 lore raw

Re: [PATCH v2 20/21] softmmu: Add qemu_init_arch_modules()

Quoted 11 lines · Philippe Mathieu-Daudé

module_allow_arch() is the single target-specific call in the whole vl.c file. Move the module initialization out to arch_init.c, that way we'll be able to build vl.o once for all targets (the next commit).

---
  include/sysemu/arch_init.h | 2 ++
  softmmu/arch_init.c        | 9 +++++++++
  softmmu/vl.c               | 5 +----
  3 files changed, 12 insertions(+), 4 deletions(-)

r~

#37 lore raw

PATCH v2 21/21 softmmu: Build target-agnostic objects once

In reply to Philippe Mathieu-Daudé via

Various softmmu objects aren't target specific. Move them to the generic softmmu source set.

For our 31 softmmu targets, this is in total 330 objects less to build!

---
 softmmu/meson.build | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
softmmu/meson.build +12 -12
index d8e03018ab..d2badf203b 100644
@@ -1,20 +1,9 @@
 specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files(
   'arch_init.c',
-  'balloon.c',
-  'cpus.c',
-  'cpu-throttle.c',
-  'datadir.c',
-  'globals.c',
-  'physmem.c',
   'ioport.c',
-  'rtc.c',
-  'runstate.c',
   'memory.c',
-  'memory_mapping.c',
+  'physmem.c',
   'qtest.c',
-  'vl.c',
-  'cpu-timers.c',
-  'runstate-action.c',
 )])
 
 specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: [files(
@@ -22,9 +11,20 @@ specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: [files(
 )])
 
 softmmu_ss.add(files(
+  'balloon.c',
   'bootdevice.c',
+  'cpus.c',
+  'cpu-throttle.c',
+  'cpu-timers.c',
+  'datadir.c',
   'dma-helpers.c',
+  'globals.c',
+  'memory_mapping.c',
   'qdev-monitor.c',
+  'rtc.c',
+  'runstate-action.c',
+  'runstate.c',
+  'vl.c',
 ), sdl, libpmem, libdaxctl)
 
 softmmu_ss.add(when: 'CONFIG_TPM', if_true: files('tpm.c'))
Signature · 1 line
2.34.1
Reviewed-by on the v2 series
#38 lore raw
In reply to Philippe Mathieu-Daudé via
Quoted 2 lines · Philippe Mathieu-Daudé via

This is a re-org accel/ and softmmu/ to have more target-agnostic objects.

Neat! vl.c in particular bothered me.

Paolo

Quoted 70 lines

Since RFC:
- Rework accel/meson (Richard)
- Use vaddr in cpu_memory_rw_debug (Richard)
- Introduce CONFIG_HAX_IS_POSSIBLE (Richard)
- Introduce AccelOpsClass::cpu_thread_is_idle (Richard)
- Introduce AccelOpsClass::cpus_are_resettable (Richard)
- Add qemu_init_arch_modules (new)

Philippe Mathieu-Daudé (21):
accel: Restrict sysemu stubs to system emulation accel/meson: Only build hw virtualization with system emulation
exec: Declare vaddr as a generic target-agnostic type
exec: Make cpu_memory_rw_debug() target agnostic sysemu/memory_mapping: Become target-agnostic
sysemu/kvm: Make kvm_on_sigbus() / kvm_on_sigbus_vcpu() target
agnostic
accel/kvm: Simplify user-mode #ifdef'ry
accel/hax: Introduce CONFIG_HAX_IS_POSSIBLE
softmmu/cpus: Code movement
accel: Introduce AccelOpsClass::cpu_thread_is_idle()
accel: Introduce AccelOpsClass::cpus_are_resettable() softmmu/globals: Remove unused 'hw/i386/*' headers softmmu/runstate: Clean headers
softmmu/physmem: Remove unnecessary include softmmu/cpu-timers: Remove unused 'exec/exec-all.h' header
misc: Remove unnecessary "sysemu/cpu-timers.h" include
misc: Add missing "sysemu/cpu-timers.h" include exec/gdbstub: Make gdb_exit() / gdb_set_stop_cpu() target agnostic exec/cpu: Make address_space_init/reloading_memory_map target agnostic
softmmu: Add qemu_init_arch_modules()
softmmu: Build target-agnostic objects once

  accel/kvm/kvm-accel-ops.c         | 12 ++++++++++
  accel/meson.build                 | 12 ++++++----
  accel/qtest/qtest.c               |  1 -
  accel/stubs/hax-stub.c            |  2 ++
  accel/stubs/kvm-stub.c            |  5 ----
  accel/stubs/meson.build           | 11 +++++----
  accel/tcg/tcg-accel-ops-icount.c  |  1 +
  accel/tcg/tcg-accel-ops-mttcg.c   |  1 +
  accel/tcg/tcg-accel-ops-rr.c      |  1 +
  accel/tcg/tcg-accel-ops.c         |  1 +
  cpu.c                             |  6 ++---
  include/exec/cpu-all.h            |  4 ----
  include/exec/cpu-common.h         | 39 +++++++++++++++++++++++++++++++
  include/exec/exec-all.h           | 26 ---------------------
  include/exec/gdbstub.h            | 23 +++++++++---------
  include/hw/core/cpu.h             | 13 +----------
  include/sysemu/accel-ops.h        |  3 +++
  include/sysemu/arch_init.h        |  2 ++
  include/sysemu/hax.h              | 18 +++++++++-----
  include/sysemu/hw_accel.h         |  5 ----
  include/sysemu/kvm.h              |  6 ++---
  include/sysemu/memory_mapping.h   |  5 ++--
  softmmu/arch_init.c               |  9 +++++++
  softmmu/cpu-timers.c              |  1 -
  softmmu/cpus.c                    | 23 +++++++++++-------
  softmmu/globals.c                 |  2 --
  softmmu/memory_mapping.c          |  1 +
  softmmu/meson.build               | 24 +++++++++----------
  softmmu/physmem.c                 |  7 +++---
  softmmu/runstate.c                |  2 +-
  softmmu/vl.c                      |  5 +---
  target/alpha/translate.c          |  1 -
  target/i386/hax/hax-all.c         |  7 +-----
  target/i386/whpx/whpx-accel-ops.c |  6 +++++
  target/riscv/csr.c                |  1 +
  tests/unit/ptimer-test-stubs.c    |  1 -
  36 files changed, 158 insertions(+), 129 deletions(-)