i386 cleanup PART 2
Subsystems (2)
v11 cover i386 cleanup PART 2
Hello, this is version 11 of the cleanup, PART 2.
The series has been split into two separate parts; to find PART 1, see the series "i386 cleanup PART 1"
v10 -> v11: split off PART 2,
no further changes to PART 2 other than the split.
v9 -> v10: minor tweaks and fixes
* in "i386: split cpu accelerators from cpu.c",
use kvm/kvm-cpu.c, hvf/hvf-cpu.c, tcg/tcg-cpu.c. Easier to understand compared to editing multiple cpu.c files, and matches the header files if needed (kvm-cpu.h).
* in "accel: replace struct CpusAccel with AccelOpsClass",
make it a bit more consistent, by naming the files defining the AccelOpsClass types "...-accel-ops.c" instead of the old naming "...-cpus.c".
* in "cpu: move cc->transaction_failed to tcg_ops",
protect with CONFIG_TCG the use of tcg_ops for hw/misc/jazz.c,
#include "exec/memattrs.h" (Philippe, Eduardo)
* in "cpu: Move synchronize_from_tb() to tcg_ops",
#include "hw/core/cpu.h" (Philippe, Eduardo)
do not remove the comment about struct TcgCpuOperations (Philippe)
* in "accel/tcg: split TCG-only code from cpu_exec_realizefn",
invert tcg_target_initialized set order (Alex)
* in "i386: move TCG cpu class initialization out of helper.c",
extract helper-tcg.h, tcg-cpu.c, and tcg-cpu.h directly into tcg/, avoiding the extra move later to tcg/ (Alex)
v8 -> v9: move additional methods to CPUClass->tcg_ops
do_unaligned_access, transaction_failed and do_interrupt.
do_interrupt is a bit tricky, as the same code is reused (albeit not usually directly) for KVM under certain odd conditions.
Change arm, as the only user of do_interrupt callback for KVM, to instead call the target function directly arm_do_interrupt.
v7 -> v8: add missing CONFIG_TCGs, fix bugs
* add the prerequisite patches for "3 tcg" at the beginning of the series for convenience (already reviewed, queued by RH).
* add CONFIG_TCG to TCGCpuOperations and tcg_ops variable use
* reduce the scope of the realizefn refactoring, do not introduce a separate cpu_accel_realize, and instead use the existing cpu_exec_realizefn, there is not enough benefit to introduce a new function.
* fix bugs in user mode due to attempt to move the tcg_region_init() early, so it could be done just once in tcg_init() for both softmmu and user mode. Unfortunately it needs to remain deferred for user mode, as it needs to be done after prologue init and after the GUEST_BASE has been set.
v6 -> v7: integrate TCGCpuOperations, refactored cpu_exec_realizefn
* integrate TCGCpuOperations (Eduardo)
Taken some refactoring from Eduardo for Tcg-only operations on CPUClass.
* refactored cpu_exec_realizefn
The other main change is a refactoring of cpu_exec_realizefn, directly linked to the effort of making many cpu_exec operations TCG-only (Eduardo series above):
cpu_exec_realizefn is actually a TCG-only thing, with the exception of a couple things that can be done in base cpu code.
This changes all targets realizefn, so I guess I have to Cc:
the Multiverse? (Universe was already CCed for all accelerators).
v5 -> v6: remove MODULE_INIT_ACCEL_CPU
instead, use a call to accel_init_interfaces().
* The class lookups are now general and performed in accel/
new AccelCPUClass for new archs are supported as new ones appear in the class hierarchy, no need for stubs.
* Split the code a bit better
v4 -> v5: centralized and simplified initializations
I put in Cc: Emilio G. Cota, specifically because in patch 8 I (re)moved for user-mode the call to tcg_regions_init().
The call happens now inside the tcg AccelClass machine_init, (so earlier). This seems to work fine, but thought to get the author opinion on this.
Rebased on "tcg-cpus: split into 3 tcg variants" series (queued by Richard), to avoid some code churn:
https://lists.gnu.org/archive/html/qemu-devel/2020-10/msg04356.html
* Extended AccelClass to user-mode.
user-mode now does not call tcg_exec_init directly, instead it uses the tcg accel class, and its init_machine method.
Since user-mode does not define or use a machine state, the machine is just passed as NULL.
The immediate advantage is that now we can call current_accel() from both user mode and softmmu, so we can work out the correct class to use for accelerator initializations.
* QOMification of CpusAccelOps
simple QOMification of CpusAccelOps abstract class.
* Centralized all accel_cpu_init, so only one per cpu-arch, plus one for all accels will remain.
So we can expect accel_cpu_init() to be limited to:
softmmu/cpus.c - initializes the chosen softmmu accel ops for the cpus module. target/ARCH/cpu.c - initializes the chosen arch-specific cpu accelerator.
These changes are meant to address concerns/issues (Paolo):
1) the use of if (tcg_enabled()) and similar in the module_init call path
2) the excessive number of accel_cpu_init() to hunt down in the codebase.
* Fixed wrong use of host_cpu_class_init (Eduardo)
v3 -> v4: QOMification of X86CPUAccelClass
In this version I basically QOMified X86CPUAccel, taking the suggestions from Eduardo as the starting point,
but stopping just short of making it an actual QOM interface, using a plain abstract class, and then subclasses for the actual objects.
Initialization is still using the existing qemu initialization framework (module_call_init), which is I still think is better than the alternatives proposed, in the current state.
Possibly some improvements could be developed in the future here. In this case, effort should be put in keeping things extendible, in order not to be blocked once accelerators also become modules.
Motivation and higher level steps:
https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg04628.html
Looking forward to your comments on this proposal,
Ciao,
Claudio
Claudio Fontana (7):
accel: extend AccelState and AccelClass to user-mode
accel: replace struct CpusAccel with AccelOpsClass
accel: introduce AccelCPUClass extending CPUClass
i386: split cpu accelerators from cpu.c, using AccelCPUClass
cpu: call AccelCPUClass::cpu_realizefn in cpu_exec_realizefn hw/core/cpu: call qemu_init_vcpu in cpu_common_realizefn
cpu: introduce cpu_accel_instance_init
accel/accel-softmmu.h | 15 +
accel/kvm/kvm-cpus.h | 2 -
...g-cpus-icount.h => tcg-accel-ops-icount.h} | 2 +
accel/tcg/tcg-accel-ops-mttcg.h | 19 +
.../tcg/{tcg-cpus-rr.h => tcg-accel-ops-rr.h} | 0
accel/tcg/{tcg-cpus.h => tcg-accel-ops.h} | 6 +-
include/hw/boards.h | 2 +-
include/hw/core/accel-cpu.h | 25 ++
include/hw/core/cpu.h | 19 +
include/{sysemu => qemu}/accel.h | 16 +-
include/sysemu/accel-ops.h | 45 ++
include/sysemu/cpus.h | 26 +-
include/sysemu/hvf.h | 2 +-
include/sysemu/kvm.h | 2 +-
include/sysemu/kvm_int.h | 2 +-
target/i386/cpu.h | 20 +-
.../i386/hax/{hax-cpus.h => hax-accel-ops.h} | 2 -
target/i386/hax/hax-windows.h | 2 +-
target/i386/host-cpu.h | 19 +
.../i386/hvf/{hvf-cpus.h => hvf-accel-ops.h} | 2 -
target/i386/hvf/hvf-i386.h | 2 +-
target/i386/kvm/kvm-cpu.h | 41 ++
target/i386/tcg/tcg-cpu.h | 15 -
.../whpx/{whpx-cpus.h => whpx-accel-ops.h} | 2 -
accel/accel-common.c | 105 +++++
accel/{accel.c => accel-softmmu.c} | 60 ++-
accel/accel-user.c | 24 ++
accel/kvm/{kvm-cpus.c => kvm-accel-ops.c} | 26 +-
accel/kvm/kvm-all.c | 2 -
accel/qtest/qtest.c | 25 +-
...g-cpus-icount.c => tcg-accel-ops-icount.c} | 21 +-
...tcg-cpus-mttcg.c => tcg-accel-ops-mttcg.c} | 14 +-
.../tcg/{tcg-cpus-rr.c => tcg-accel-ops-rr.c} | 13 +-
accel/tcg/{tcg-cpus.c => tcg-accel-ops.c} | 47 ++-
accel/tcg/tcg-all.c | 17 +-
accel/xen/xen-all.c | 24 +-
bsd-user/main.c | 11 +-
cpu.c | 5 +
hw/core/cpu.c | 11 +
hw/i386/pc_piix.c | 1 +
linux-user/main.c | 7 +-
softmmu/cpus.c | 12 +-
softmmu/memory.c | 2 +-
softmmu/qtest.c | 2 +-
softmmu/vl.c | 8 +-
target/alpha/cpu.c | 5 +-
target/arm/cpu.c | 4 +-
target/avr/cpu.c | 3 +-
target/cris/cpu.c | 2 -
target/hppa/cpu.c | 1 -
target/i386/cpu.c | 393 ++----------------
.../i386/hax/{hax-cpus.c => hax-accel-ops.c} | 31 +-
target/i386/hax/hax-all.c | 7 +-
target/i386/hax/hax-mem.c | 2 +-
target/i386/hax/hax-posix.c | 2 +-
target/i386/hax/hax-windows.c | 2 +-
target/i386/host-cpu.c | 198 +++++++++
.../i386/hvf/{hvf-cpus.c => hvf-accel-ops.c} | 29 +-
target/i386/hvf/hvf-cpu.c | 65 +++
target/i386/hvf/hvf.c | 5 +-
target/i386/hvf/x86_task.c | 2 +-
target/i386/hvf/x86hvf.c | 2 +-
target/i386/kvm/kvm-cpu.c | 148 +++++++
target/i386/kvm/kvm.c | 3 +-
target/i386/tcg/tcg-cpu.c | 116 +++++-
.../whpx/{whpx-cpus.c => whpx-accel-ops.c} | 31 +-
target/i386/whpx/whpx-all.c | 6 +-
target/lm32/cpu.c | 3 -
target/m68k/cpu.c | 2 -
target/microblaze/cpu.c | 9 +-
target/mips/cpu.c | 2 -
target/moxie/cpu.c | 4 +-
target/nios2/cpu.c | 4 +-
target/openrisc/cpu.c | 4 +-
target/riscv/cpu.c | 8 +-
target/rx/cpu.c | 8 +-
target/s390x/cpu.c | 3 +-
target/sh4/cpu.c | 2 -
target/sparc/cpu.c | 4 +-
target/tilegx/cpu.c | 2 -
target/tricore/cpu.c | 2 -
target/unicore32/cpu.c | 6 +-
target/xtensa/cpu.c | 2 -
MAINTAINERS | 8 +-
accel/kvm/meson.build | 2 +-
accel/meson.build | 4 +-
accel/tcg/meson.build | 10 +-
target/i386/hax/meson.build | 2 +-
target/i386/hvf/meson.build | 3 +-
target/i386/kvm/meson.build | 7 +-
target/i386/meson.build | 6 +-
target/i386/whpx/meson.build | 2 +-
target/ppc/translate_init.c.inc | 5 +-
93 files changed, 1230 insertions(+), 666 deletions(-)
create mode 100644 accel/accel-softmmu.h
rename accel/tcg/{tcg-cpus-icount.h => tcg-accel-ops-icount.h} (88%)
create mode 100644 accel/tcg/tcg-accel-ops-mttcg.h
rename accel/tcg/{tcg-cpus-rr.h => tcg-accel-ops-rr.h} (100%)
rename accel/tcg/{tcg-cpus.h => tcg-accel-ops.h} (72%)
create mode 100644 include/hw/core/accel-cpu.h
rename include/{sysemu => qemu}/accel.h (94%)
create mode 100644 include/sysemu/accel-ops.h
rename target/i386/hax/{hax-cpus.h => hax-accel-ops.h} (95%)
create mode 100644 target/i386/host-cpu.h
rename target/i386/hvf/{hvf-cpus.h => hvf-accel-ops.h} (94%)
create mode 100644 target/i386/kvm/kvm-cpu.h
delete mode 100644 target/i386/tcg/tcg-cpu.h
rename target/i386/whpx/{whpx-cpus.h => whpx-accel-ops.h} (96%)
create mode 100644 accel/accel-common.c
rename accel/{accel.c => accel-softmmu.c} (64%)
create mode 100644 accel/accel-user.c
rename accel/kvm/{kvm-cpus.c => kvm-accel-ops.c} (72%)
rename accel/tcg/{tcg-cpus-icount.c => tcg-accel-ops-icount.c} (89%)
rename accel/tcg/{tcg-cpus-mttcg.c => tcg-accel-ops-mttcg.c} (92%)
rename accel/tcg/{tcg-cpus-rr.c => tcg-accel-ops-rr.c} (97%)
rename accel/tcg/{tcg-cpus.c => tcg-accel-ops.c} (63%)
rename target/i386/hax/{hax-cpus.c => hax-accel-ops.c} (69%)
create mode 100644 target/i386/host-cpu.c
rename target/i386/hvf/{hvf-cpus.c => hvf-accel-ops.c} (84%)
create mode 100644 target/i386/hvf/hvf-cpu.c
create mode 100644 target/i386/kvm/kvm-cpu.c
rename target/i386/whpx/{whpx-cpus.c => whpx-accel-ops.c} (72%)Signature · 1 line
2.26.2
PATCH v11 1/7 accel: extend AccelState and AccelClass to user-mode
---
include/hw/boards.h | 2 +-
include/{sysemu => qemu}/accel.h | 14 +++++----
include/sysemu/hvf.h | 2 +-
include/sysemu/kvm.h | 2 +-
include/sysemu/kvm_int.h | 2 +-
target/i386/hvf/hvf-i386.h | 2 +-
accel/accel-common.c | 50 ++++++++++++++++++++++++++++++
accel/{accel.c => accel-softmmu.c} | 27 ++--------------
accel/accel-user.c | 24 ++++++++++++++
accel/qtest/qtest.c | 2 +-
accel/tcg/tcg-all.c | 13 ++++++--
accel/xen/xen-all.c | 2 +-
bsd-user/main.c | 6 +++-
linux-user/main.c | 6 +++-
softmmu/memory.c | 2 +-
softmmu/qtest.c | 2 +-
softmmu/vl.c | 2 +-
target/i386/hax/hax-all.c | 2 +-
target/i386/hvf/hvf.c | 2 +-
target/i386/hvf/x86_task.c | 2 +-
target/i386/whpx/whpx-all.c | 2 +-
MAINTAINERS | 2 +-
accel/meson.build | 4 ++-
accel/tcg/meson.build | 2 +-
24 files changed, 124 insertions(+), 52 deletions(-)
rename include/{sysemu => qemu}/accel.h (95%)
create mode 100644 accel/accel-common.c
rename accel/{accel.c => accel-softmmu.c} (75%)
create mode 100644 accel/accel-user.cinclude/hw/boards.h +1 -1
@@ -6,7 +6,7 @@#include "exec/memory.h" #include "sysemu/hostmem.h" #include "sysemu/blockdev.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "qapi/qapi-types-machine.h" #include "qemu/module.h" #include "qom/object.h"
include/qemu/accel.h renamed from include/sysemu/accel.h +8 -6
@@ -20,8 +20,8 @@* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#ifndef HW_ACCEL_H -#define HW_ACCEL_H +#ifndef QEMU_ACCEL_H +#define QEMU_ACCEL_H #include "qom/object.h" #include "exec/hwaddr.h"
@@ -37,8 +37,8 @@ typedef struct AccelClass {/*< public >*/ const char *name; -#ifndef CONFIG_USER_ONLY int (*init_machine)(MachineState *ms); +#ifndef CONFIG_USER_ONLY void (*setup_post)(MachineState *ms,AccelState *accel);bool (*has_memory)(MachineState *ms,AddressSpace *as,hwaddr start_addr,hwaddr size);
@@ -67,11 +67,13 @@ typedef struct AccelClass { OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL)AccelClass *accel_find (const char *opt_name); +AccelState *current_accel (void ); + +#ifndef CONFIG_USER_ONLY int accel_init_machine (AccelState *accel,MachineState *ms);/* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post (MachineState *ms); +#endif /* !CONFIG_USER_ONLY */ -AccelState *current_accel (void ); - -#endif +#endif /* QEMU_ACCEL_H */
include/sysemu/hvf.h +1 -1
@@ -13,7 +13,7 @@#ifndef HVF_H #define HVF_H -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "qom/object.h" #ifdef CONFIG_HVF
include/sysemu/kvm.h +1 -1
@@ -17,7 +17,7 @@#include "qemu/queue.h" #include "hw/core/cpu.h" #include "exec/memattrs.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "qom/object.h" #ifdef NEED_CPU_H
include/sysemu/kvm_int.h +1 -1
@@ -10,7 +10,7 @@#define QEMU_KVM_INT_H #include "exec/memory.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "sysemu/kvm.h" typedef struct KVMSlot
target/i386/hvf/hvf-i386.h +1 -1
@@ -16,7 +16,7 @@#ifndef HVF_I386_H #define HVF_I386_H -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "sysemu/hvf.h" #include "cpu.h" #include "x86.h"
accel/accel-common.c new file +50 -0
50 lines not on this page · raw message
accel/accel-softmmu.c renamed from accel/accel.c +2 -25
@@ -1,5 +1,5 @@/* -* QEMU System Emulator, accelerator interfaces +* QEMU accel class, system emulation components * * Copyright (c) 2003-2008 Fabrice Bellard * Copyright (c) 2014 Red Hat Inc.
@@ -24,28 +24,12 @@*/ #include "qemu/osdep.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "hw/boards.h" #include "sysemu/arch_init.h" #include "sysemu/sysemu.h" #include "qom/object.h" -static const TypeInfo accel_type = { - .name =TYPE_ACCEL , - .parent =TYPE_OBJECT , - .class_size =sizeof (AccelClass), - .instance_size =sizeof (AccelState), -}; - -/* Lookup AccelClass from opt_name. Returns NULL if not found */ -AccelClass *accel_find (const char *opt_name) -{ -char *class_name =g_strdup_printf (ACCEL_CLASS_NAME ("%s" ), opt_name); -AccelClass *ac =ACCEL_CLASS (object_class_by_name (class_name)); -g_free (class_name); -return ac; -} -int accel_init_machine (AccelState *accel,MachineState *ms) {AccelClass *acc =ACCEL_GET_CLASS (accel);
@@ -76,10 +60,3 @@ void accel_setup_post(MachineState *ms) acc->setup_post (ms, accel); } } - -static void register_accel_types (void ) -{ -type_register_static (&accel_type); -} - -type_init (register_accel_types);
accel/accel-user.c new file +24 -0
@@ -0,0 +1,24 @@ +/* +* QEMU accel class, user-mode components +* +* Copyright 2020 SUSE LLC +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu/accel.h" + +AccelState *current_accel (void ) +{ +static AccelState *accel; + +if (!accel) { +AccelClass *ac =accel_find ("tcg" ); + +g_assert (ac !=NULL ); + accel =ACCEL (object_new_with_class (OBJECT_CLASS (ac))); + } +return accel; +}
accel/qtest/qtest.c +1 -1
@@ -17,7 +17,7 @@#include "qemu/module.h" #include "qemu/option.h" #include "qemu/config-file.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "sysemu/qtest.h" #include "sysemu/cpus.h" #include "sysemu/cpu-timers.h"
accel/tcg/tcg-all.c +11 -2
@@ -30,9 +30,12 @@#include "tcg/tcg.h" #include "qapi/error.h" #include "qemu/error-report.h" -#include "hw/boards.h" +#include "qemu/accel.h" #include "qapi/qapi-builtin-visit.h" + +#ifndef CONFIG_USER_ONLY #include "tcg-cpus.h" +#endif /* CONFIG_USER_ONLY */ struct TCGState {AccelState parent_obj;
@@ -106,8 +109,12 @@ static int tcg_init(MachineState *ms) mttcg_enabled = s->mttcg_enabled;/* -* Initialize TCG regions +* Initialize TCG regions only for softmmu. +* +* This needs to be done later for user mode, because the prologue +* generation needs to be delayed so that GUEST_BASE is already set. */ +#ifndef CONFIG_USER_ONLY tcg_region_init ();if (mttcg_enabled) {
@@ -117,6 +124,8 @@ static int tcg_init(MachineState *ms) } else {cpus_register_accel (&tcg_cpus_rr); } +#endif /* !CONFIG_USER_ONLY */ +return 0 ; }
accel/xen/xen-all.c +1 -1
@@ -15,7 +15,7 @@#include "hw/xen/xen-legacy-backend.h" #include "hw/xen/xen_pt.h" #include "chardev/char.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "sysemu/cpus.h" #include "sysemu/xen.h" #include "sysemu/runstate.h"
bsd-user/main.c +5 -1
@@ -20,6 +20,7 @@#include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/units.h" +#include "qemu/accel.h" #include "sysemu/tcg.h" #include "qemu-version.h" #include <machine/trap.h>
@@ -908,8 +909,11 @@ int main(int argc, char **argv) }/* init tcg before creating CPUs and to get qemu_host_page_size */ -tcg_exec_init (0 ); + { +AccelClass *ac =ACCEL_GET_CLASS (current_accel ()); + ac->init_machine (NULL ); + } cpu_type =parse_cpu_option (cpu_model); cpu =cpu_create (cpu_type); env = cpu->env_ptr;
linux-user/main.c +5 -1
@@ -20,6 +20,7 @@#include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/units.h" +#include "qemu/accel.h" #include "sysemu/tcg.h" #include "qemu-version.h" #include <sys/syscall.h>
@@ -703,8 +704,11 @@ int main(int argc, char **argv, char **envp) cpu_type =parse_cpu_option (cpu_model);/* init tcg before creating CPUs and to get qemu_host_page_size */ -tcg_exec_init (0 ); + { +AccelClass *ac =ACCEL_GET_CLASS (current_accel ()); + ac->init_machine (NULL ); + } cpu =cpu_create (cpu_type); env = cpu->env_ptr;cpu_reset (cpu);
softmmu/memory.c +1 -1
@@ -32,7 +32,7 @@#include "sysemu/kvm.h" #include "sysemu/runstate.h" #include "sysemu/tcg.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "hw/boards.h" #include "migration/vmstate.h"
softmmu/qtest.c +1 -1
@@ -20,7 +20,7 @@#include "exec/ioport.h" #include "exec/memory.h" #include "hw/irq.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "sysemu/cpu-timers.h" #include "qemu/config-file.h" #include "qemu/option.h"
softmmu/vl.c +1 -1
@@ -40,7 +40,7 @@#include "qemu/error-report.h" #include "qemu/sockets.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "hw/usb.h" #include "hw/isa/isa.h" #include "hw/scsi/scsi.h"
target/i386/hax/hax-all.c +1 -1
@@ -28,7 +28,7 @@#include "exec/address-spaces.h" #include "qemu-common.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "sysemu/reset.h" #include "sysemu/runstate.h" #include "hw/boards.h"
target/i386/hvf/hvf.c +1 -1
@@ -69,7 +69,7 @@#include "exec/address-spaces.h" #include "hw/i386/apic_internal.h" #include "qemu/main-loop.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "target/i386/cpu.h" #include "hvf-cpus.h"
target/i386/hvf/x86_task.c +1 -1
@@ -28,7 +28,7 @@#include "hw/i386/apic_internal.h" #include "qemu/main-loop.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "target/i386/cpu.h" // TODO: taskswitch handling
target/i386/whpx/whpx-all.c +1 -1
@@ -13,7 +13,7 @@#include "exec/address-spaces.h" #include "exec/ioport.h" #include "qemu-common.h" -#include "sysemu/accel.h" +#include "qemu/accel.h" #include "sysemu/whpx.h" #include "sysemu/cpus.h" #include "sysemu/runstate.h"
MAINTAINERS +1 -1
@@ -434,7 +434,7 @@ Overall M: Richard Henderson <[email protected]> R: Paolo Bonzini <[email protected]> S: Maintained -F: include/sysemu/accel.h +F: include/qemu/accel.h F: accel/accel.c F: accel/Makefile.objs F: accel/stubs/Makefile.objs
accel/meson.build +3 -1
@@ -1,4 +1,6 @@ -softmmu_ss.add(files('accel.c')) +specific_ss.add(files('accel-common.c')) +softmmu_ss.add(files('accel-softmmu.c')) +user_ss.add(files('accel-user.c')) subdir('qtest') subdir('kvm')
accel/tcg/meson.build +1 -1
@@ -1,5 +1,6 @@ tcg_ss = ss.source_set() tcg_ss.add(files( + 'tcg-all.c', 'cpu-exec-common.c', 'cpu-exec.c', 'tcg-runtime-gvec.c',
@@ -13,7 +14,6 @@ tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: [files('plugin-gen.c'), libdl]) specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss) specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files( - 'tcg-all.c', 'cputlb.c', 'tcg-cpus.c', 'tcg-cpus-mttcg.c',
Signature · 1 line
2.26.2
PATCH v11 2/7 accel: replace struct CpusAccel with AccelOpsClass
In reply to Claudio Fontanaalso centralize the registration of the cpus.c module accelerator operations in accel/accel-softmmu.c
Consequently, rename all tcg-cpus.c, kvm-cpus.c etc to tcg-accel-ops.c, kvm-accel-ops.c etc, also matching the object type names.
---
accel/accel-softmmu.h | 15 ++++++
accel/kvm/kvm-cpus.h | 2 -
...g-cpus-icount.h => tcg-accel-ops-icount.h} | 2 +
accel/tcg/tcg-accel-ops-mttcg.h | 19 ++++++++
.../tcg/{tcg-cpus-rr.h => tcg-accel-ops-rr.h} | 0
accel/tcg/{tcg-cpus.h => tcg-accel-ops.h} | 6 +--
include/qemu/accel.h | 2 +
include/sysemu/accel-ops.h | 45 ++++++++++++++++++
include/sysemu/cpus.h | 26 ++--------
.../i386/hax/{hax-cpus.h => hax-accel-ops.h} | 2 -
target/i386/hax/hax-windows.h | 2 +-
.../i386/hvf/{hvf-cpus.h => hvf-accel-ops.h} | 2 -
.../whpx/{whpx-cpus.h => whpx-accel-ops.h} | 2 -
accel/accel-common.c | 11 +++++
accel/accel-softmmu.c | 43 +++++++++++++++--
accel/kvm/{kvm-cpus.c => kvm-accel-ops.c} | 26 +++++++---
accel/kvm/kvm-all.c | 2 -
accel/qtest/qtest.c | 23 ++++++---
...g-cpus-icount.c => tcg-accel-ops-icount.c} | 21 +++------
...tcg-cpus-mttcg.c => tcg-accel-ops-mttcg.c} | 14 ++----
.../tcg/{tcg-cpus-rr.c => tcg-accel-ops-rr.c} | 13 ++---
accel/tcg/{tcg-cpus.c => tcg-accel-ops.c} | 47 ++++++++++++++++++-
accel/tcg/tcg-all.c | 12 -----
accel/xen/xen-all.c | 22 ++++++---
bsd-user/main.c | 3 +-
linux-user/main.c | 1 +
softmmu/cpus.c | 12 ++---
softmmu/vl.c | 6 ++-
.../i386/hax/{hax-cpus.c => hax-accel-ops.c} | 31 ++++++++----
target/i386/hax/hax-all.c | 5 +-
target/i386/hax/hax-mem.c | 2 +-
target/i386/hax/hax-posix.c | 2 +-
target/i386/hax/hax-windows.c | 2 +-
.../i386/hvf/{hvf-cpus.c => hvf-accel-ops.c} | 29 +++++++++---
target/i386/hvf/hvf.c | 3 +-
target/i386/hvf/x86hvf.c | 2 +-
.../whpx/{whpx-cpus.c => whpx-accel-ops.c} | 31 ++++++++----
target/i386/whpx/whpx-all.c | 4 +-
MAINTAINERS | 3 +-
accel/kvm/meson.build | 2 +-
accel/tcg/meson.build | 8 ++--
target/i386/hax/meson.build | 2 +-
target/i386/hvf/meson.build | 2 +-
target/i386/whpx/meson.build | 2 +-
44 files changed, 349 insertions(+), 162 deletions(-)
create mode 100644 accel/accel-softmmu.h
rename accel/tcg/{tcg-cpus-icount.h => tcg-accel-ops-icount.h} (88%)
create mode 100644 accel/tcg/tcg-accel-ops-mttcg.h
rename accel/tcg/{tcg-cpus-rr.h => tcg-accel-ops-rr.h} (100%)
rename accel/tcg/{tcg-cpus.h => tcg-accel-ops.h} (72%)
create mode 100644 include/sysemu/accel-ops.h
rename target/i386/hax/{hax-cpus.h => hax-accel-ops.h} (95%)
rename target/i386/hvf/{hvf-cpus.h => hvf-accel-ops.h} (94%)
rename target/i386/whpx/{whpx-cpus.h => whpx-accel-ops.h} (96%)
rename accel/kvm/{kvm-cpus.c => kvm-accel-ops.c} (72%)
rename accel/tcg/{tcg-cpus-icount.c => tcg-accel-ops-icount.c} (89%)
rename accel/tcg/{tcg-cpus-mttcg.c => tcg-accel-ops-mttcg.c} (92%)
rename accel/tcg/{tcg-cpus-rr.c => tcg-accel-ops-rr.c} (97%)
rename accel/tcg/{tcg-cpus.c => tcg-accel-ops.c} (63%)
rename target/i386/hax/{hax-cpus.c => hax-accel-ops.c} (69%)
rename target/i386/hvf/{hvf-cpus.c => hvf-accel-ops.c} (84%)
rename target/i386/whpx/{whpx-cpus.c => whpx-accel-ops.c} (72%)accel/accel-softmmu.h new file +15 -0
@@ -0,0 +1,15 @@ +/* +* QEMU System Emulation accel internal functions +* +* Copyright 2020 SUSE LLC +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef ACCEL_SOFTMMU_H +#define ACCEL_SOFTMMU_H + +void accel_init_ops_interfaces (AccelClass *ac); + +#endif /* ACCEL_SOFTMMU_H */
accel/kvm/kvm-cpus.h +0 -2
@@ -12,8 +12,6 @@#include "sysemu/cpus.h" -extern const CpusAccel kvm_cpus; -int kvm_init_vcpu (CPUState *cpu,Error **errp);int kvm_cpu_exec (CPUState *cpu);void kvm_destroy_vcpu (CPUState *cpu);
accel/tcg/tcg-accel-ops-icount.h renamed from accel/tcg/tcg-cpus-icount.h +2 -0
@@ -14,4 +14,6 @@ void icount_handle_deadline(void);void icount_prepare_for_run (CPUState *cpu);void icount_process_data (CPUState *cpu); +void icount_handle_interrupt (CPUState *cpu,int mask); +#endif /* TCG_CPUS_ICOUNT_H */
accel/tcg/tcg-accel-ops-mttcg.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* QEMU TCG Multi Threaded vCPUs implementation +* +* Copyright 2020 SUSE LLC +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef TCG_CPUS_MTTCG_H +#define TCG_CPUS_MTTCG_H + +/* kick MTTCG vCPU thread */ +void mttcg_kick_vcpu_thread (CPUState *cpu); + +/* start an mttcg vCPU thread */ +void mttcg_start_vcpu_thread (CPUState *cpu); + +#endif /* TCG_CPUS_MTTCG_H */
accel/tcg/tcg-accel-ops-rr.h renamed from accel/tcg/tcg-cpus-rr.h +0 -0
accel/tcg/tcg-accel-ops.h renamed from accel/tcg/tcg-cpus.h +1 -5
@@ -14,12 +14,8 @@#include "sysemu/cpus.h" -extern const CpusAccel tcg_cpus_mttcg; -extern const CpusAccel tcg_cpus_icount; -extern const CpusAccel tcg_cpus_rr; -void tcg_cpus_destroy (CPUState *cpu);int tcg_cpus_exec (CPUState *cpu); -void tcg_cpus_handle_interrupt (CPUState *cpu,int mask); +void tcg_handle_interrupt (CPUState *cpu,int mask);#endif /* TCG_CPUS_H */
include/qemu/accel.h +2 -0
@@ -69,6 +69,8 @@ typedef struct AccelClass {AccelClass *accel_find (const char *opt_name);AccelState *current_accel (void ); +void accel_init_interfaces (AccelClass *ac); +#ifndef CONFIG_USER_ONLY int accel_init_machine (AccelState *accel,MachineState *ms);
include/sysemu/accel-ops.h new file +45 -0
45 lines not on this page · raw message
include/sysemu/cpus.h +5 -21
@@ -2,30 +2,14 @@#define QEMU_CPUS_H #include "qemu/timer.h" +#include "sysemu/accel-ops.h" -/* cpus.c */ +/* register accel-specific operations */ +void cpus_register_accel (const AccelOpsClass *i); -/* CPU execution threads */ +/* accel/dummy-cpus.c */ -typedef struct CpusAccel { -void (*create_vcpu_thread)(CPUState *cpu);/* MANDATORY */ -void (*kick_vcpu_thread)(CPUState *cpu); - -void (*synchronize_post_reset)(CPUState *cpu); -void (*synchronize_post_init)(CPUState *cpu); -void (*synchronize_state)(CPUState *cpu); -void (*synchronize_pre_loadvm)(CPUState *cpu); - -void (*handle_interrupt)(CPUState *cpu,int mask); - -int64_t (*get_virtual_clock)(void ); -int64_t (*get_elapsed_ticks)(void ); -}CpusAccel ; - -/* register accel-specific cpus interface implementation */ -void cpus_register_accel (const CpusAccel *i); - -/* Create a dummy vcpu for CpusAccel->create_vcpu_thread */ +/* Create a dummy vcpu for AccelOpsClass->create_vcpu_thread */ void dummy_start_vcpu_thread (CPUState *);/* interface available for cpus accelerator threads */
target/i386/hax/hax-accel-ops.h renamed from target/i386/hax/hax-cpus.h +0 -2
@@ -12,8 +12,6 @@#include "sysemu/cpus.h" -extern const CpusAccel hax_cpus; -#include "hax-interface.h" #include "hax-i386.h"
target/i386/hax/hax-windows.h +1 -1
@@ -23,7 +23,7 @@#include <winioctl.h> #include <windef.h> -#include "hax-cpus.h" +#include "hax-accel-ops.h" #define HAX_INVALID_FD INVALID_HANDLE_VALUE
target/i386/hvf/hvf-accel-ops.h renamed from target/i386/hvf/hvf-cpus.h +0 -2
@@ -12,8 +12,6 @@#include "sysemu/cpus.h" -extern const CpusAccel hvf_cpus; -int hvf_init_vcpu (CPUState *);int hvf_vcpu_exec (CPUState *);void hvf_cpu_synchronize_state (CPUState *);
target/i386/whpx/whpx-accel-ops.h renamed from target/i386/whpx/whpx-cpus.h +0 -2
@@ -12,8 +12,6 @@#include "sysemu/cpus.h" -extern const CpusAccel whpx_cpus; -int whpx_init_vcpu (CPUState *cpu);int whpx_vcpu_exec (CPUState *cpu);void whpx_destroy_vcpu (CPUState *cpu);
accel/accel-common.c +11 -0
@@ -26,6 +26,10 @@#include "qemu/osdep.h" #include "qemu/accel.h" +#ifndef CONFIG_USER_ONLY +#include "accel-softmmu.h" +#endif /* !CONFIG_USER_ONLY */ +static const TypeInfo accel_type = { .name =TYPE_ACCEL , .parent =TYPE_OBJECT ,
@@ -42,6 +46,13 @@ AccelClass *accel_find(const char *opt_name)return ac; } +void accel_init_interfaces (AccelClass *ac) +{ +#ifndef CONFIG_USER_ONLY +accel_init_ops_interfaces (ac); +#endif /* !CONFIG_USER_ONLY */ +} +static void register_accel_types (void ) {type_register_static (&accel_type);
accel/accel-softmmu.c +40 -3
52 lines not on this page · raw message
accel/kvm/kvm-accel-ops.c renamed from accel/kvm/kvm-cpus.c +20 -6
@@ -74,11 +74,25 @@ static void kvm_start_vcpu_thread(CPUState *cpu) cpu, QEMU_THREAD_JOINABLE); } -const CpusAccel kvm_cpus = { - .create_vcpu_thread = kvm_start_vcpu_thread, +static void kvm_accel_ops_class_init (ObjectClass *oc,void *data) +{ +AccelOpsClass *ops =ACCEL_OPS_CLASS (oc); - .synchronize_post_reset = kvm_cpu_synchronize_post_reset, - .synchronize_post_init = kvm_cpu_synchronize_post_init, - .synchronize_state = kvm_cpu_synchronize_state, - .synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm, + ops->create_vcpu_thread = kvm_start_vcpu_thread; + 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; + ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm; }; +static const TypeInfo kvm_accel_ops_type = { + .name =ACCEL_OPS_NAME ("kvm" ), + + .parent =TYPE_ACCEL_OPS , + .class_init = kvm_accel_ops_class_init, + .abstract = true, +}; +static void kvm_accel_ops_register_types (void ) +{ +type_register_static (&kvm_accel_ops_type); +} +type_init (kvm_accel_ops_register_types);
accel/kvm/kvm-all.c +0 -2
@@ -2253,8 +2253,6 @@ static int kvm_init(MachineState *ms) ret =ram_block_discard_disable (true);assert (!ret); } - -cpus_register_accel (&kvm_cpus);return 0 ; err:
accel/qtest/qtest.c +17 -6
@@ -25,14 +25,8 @@#include "qemu/main-loop.h" #include "hw/core/cpu.h" -const CpusAccel qtest_cpus = { - .create_vcpu_thread = dummy_start_vcpu_thread, - .get_virtual_clock = qtest_get_virtual_clock, -}; -static int qtest_init_accel (MachineState *ms) { -cpus_register_accel (&qtest_cpus);return 0 ; }
@@ -52,9 +46,26 @@ static const TypeInfo qtest_accel_type = { .class_init = qtest_accel_class_init, }; +static void qtest_accel_ops_class_init (ObjectClass *oc,void *data) +{ +AccelOpsClass *ops =ACCEL_OPS_CLASS (oc); + + ops->create_vcpu_thread = dummy_start_vcpu_thread; + ops->get_virtual_clock = qtest_get_virtual_clock; +}; + +static const TypeInfo qtest_accel_ops_type = { + .name =ACCEL_OPS_NAME ("qtest" ), + + .parent =TYPE_ACCEL_OPS , + .class_init = qtest_accel_ops_class_init, + .abstract = true, +}; +static void qtest_type_init (void ) {type_register_static (&qtest_accel_type); +type_register_static (&qtest_accel_ops_type); }type_init (qtest_type_init);
accel/tcg/tcg-accel-ops-icount.c renamed from accel/tcg/tcg-cpus-icount.c +6 -15
@@ -32,9 +32,9 @@#include "exec/exec-all.h" #include "hw/boards.h" -#include "tcg-cpus.h" -#include "tcg-cpus-icount.h" -#include "tcg-cpus-rr.h" +#include "tcg-accel-ops.h" +#include "tcg-accel-ops-icount.h" +#include "tcg-accel-ops-rr.h" static int64_t icount_get_limit (void ) {
@@ -93,7 +93,7 @@ void icount_prepare_for_run(CPUState *cpu)/* * These should always be cleared by icount_process_data after * each vCPU execution. However u16.high can be raised -* asynchronously by cpu_exit/cpu_interrupt/tcg_cpus_handle_interrupt +* asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt */ g_assert (cpu_neg (cpu)->icount_decr.u16.low ==0 );g_assert (cpu->icount_extra ==0 );
@@ -125,23 +125,14 @@ void icount_process_data(CPUState *cpu)replay_mutex_unlock (); } -static void icount_handle_interrupt (CPUState *cpu,int mask) +void icount_handle_interrupt (CPUState *cpu,int mask) {int old_mask = cpu->interrupt_request; -tcg_cpus_handle_interrupt (cpu, mask); +tcg_handle_interrupt (cpu, mask);if (qemu_cpu_is_self (cpu) && !cpu->can_do_io && (mask & ~old_mask) !=0 ) {cpu_abort (cpu,"Raised interrupt while not in I/O function" ); } } - -const CpusAccel tcg_cpus_icount = { - .create_vcpu_thread = rr_start_vcpu_thread, - .kick_vcpu_thread = rr_kick_vcpu_thread, - - .handle_interrupt = icount_handle_interrupt, - .get_virtual_clock = icount_get, - .get_elapsed_ticks = icount_get, -};
accel/tcg/tcg-accel-ops-mttcg.c renamed from accel/tcg/tcg-cpus-mttcg.c +4 -10
@@ -32,7 +32,8 @@#include "exec/exec-all.h" #include "hw/boards.h" -#include "tcg-cpus.h" +#include "tcg-accel-ops.h" +#include "tcg-accel-ops-mttcg.h" /* * In the multi-threaded case each vCPU has its own thread. The TLS
@@ -103,12 +104,12 @@ static void *mttcg_cpu_thread_fn(void *arg)return NULL ; } -static void mttcg_kick_vcpu_thread (CPUState *cpu) +void mttcg_kick_vcpu_thread (CPUState *cpu) {cpu_exit (cpu); } -static void mttcg_start_vcpu_thread (CPUState *cpu) +void mttcg_start_vcpu_thread (CPUState *cpu) {char thread_name[VCPU_THREAD_NAME_SIZE ];
@@ -131,10 +132,3 @@ static void mttcg_start_vcpu_thread(CPUState *cpu) cpu->hThread =qemu_thread_get_handle (cpu->thread);#endif } - -const CpusAccel tcg_cpus_mttcg = { - .create_vcpu_thread = mttcg_start_vcpu_thread, - .kick_vcpu_thread = mttcg_kick_vcpu_thread, - - .handle_interrupt = tcg_cpus_handle_interrupt, -};
accel/tcg/tcg-accel-ops-rr.c renamed from accel/tcg/tcg-cpus-rr.c +3 -10
@@ -32,9 +32,9 @@#include "exec/exec-all.h" #include "hw/boards.h" -#include "tcg-cpus.h" -#include "tcg-cpus-rr.h" -#include "tcg-cpus-icount.h" +#include "tcg-accel-ops.h" +#include "tcg-accel-ops-rr.h" +#include "tcg-accel-ops-icount.h" /* Kick all RR vCPUs */ void rr_kick_vcpu_thread (CPUState *unused)
@@ -296,10 +296,3 @@ void rr_start_vcpu_thread(CPUState *cpu) cpu->created = true; } } - -const CpusAccel tcg_cpus_rr = { - .create_vcpu_thread = rr_start_vcpu_thread, - .kick_vcpu_thread = rr_kick_vcpu_thread, - - .handle_interrupt = tcg_cpus_handle_interrupt, -};
accel/tcg/tcg-accel-ops.c renamed from accel/tcg/tcg-cpus.c +45 -2
62 lines not on this page · raw message
accel/tcg/tcg-all.c +0 -12
@@ -33,10 +33,6 @@#include "qemu/accel.h" #include "qapi/qapi-builtin-visit.h" -#ifndef CONFIG_USER_ONLY -#include "tcg-cpus.h" -#endif /* CONFIG_USER_ONLY */ -struct TCGState {AccelState parent_obj;
@@ -116,14 +112,6 @@ static int tcg_init(MachineState *ms)*/ #ifndef CONFIG_USER_ONLY tcg_region_init (); - -if (mttcg_enabled) { -cpus_register_accel (&tcg_cpus_mttcg); - }else if (icount_enabled ()) { -cpus_register_accel (&tcg_cpus_icount); - }else { -cpus_register_accel (&tcg_cpus_rr); - }#endif /* !CONFIG_USER_ONLY */ return 0 ;
accel/xen/xen-all.c +15 -7
@@ -154,10 +154,6 @@ static void xen_setup_post(MachineState *ms, AccelState *accel) } } -const CpusAccel xen_cpus = { - .create_vcpu_thread = dummy_start_vcpu_thread, -}; -static int xen_init (MachineState *ms) {MachineClass *mc =MACHINE_GET_CLASS (ms);
@@ -185,9 +181,6 @@ static int xen_init(MachineState *ms)* opt out of system RAM being allocated by generic code */ mc->default_ram_id =NULL ; - -cpus_register_accel (&xen_cpus); -return 0 ; }
@@ -222,9 +215,24 @@ static const TypeInfo xen_accel_type = { .class_init = xen_accel_class_init, }; +static void xen_accel_ops_class_init (ObjectClass *oc,void *data) +{ +AccelOpsClass *ops =ACCEL_OPS_CLASS (oc); + + ops->create_vcpu_thread = dummy_start_vcpu_thread; +}; +static const TypeInfo xen_accel_ops_type = { + .name =ACCEL_OPS_NAME ("xen" ), + + .parent =TYPE_ACCEL_OPS , + .class_init = xen_accel_ops_class_init, + .abstract = true, +}; +static void xen_type_init (void ) {type_register_static (&xen_accel_type); +type_register_static (&xen_accel_ops_type); }type_init (xen_type_init);
bsd-user/main.c +2 -1
@@ -908,13 +908,14 @@ int main(int argc, char **argv)#endif } + cpu_type =parse_cpu_option (cpu_model);/* init tcg before creating CPUs and to get qemu_host_page_size */ {AccelClass *ac =ACCEL_GET_CLASS (current_accel ()); ac->init_machine (NULL ); +accel_init_interfaces (ac); } - cpu_type =parse_cpu_option (cpu_model); cpu =cpu_create (cpu_type); env = cpu->env_ptr;#if defined(TARGET_SPARC ) || defined(TARGET_PPC )
linux-user/main.c +1 -0
@@ -708,6 +708,7 @@ int main(int argc, char **argv, char **envp)AccelClass *ac =ACCEL_GET_CLASS (current_accel ()); ac->init_machine (NULL ); +accel_init_interfaces (ac); } cpu =cpu_create (cpu_type); env = cpu->env_ptr;
softmmu/cpus.c +6 -6
@@ -127,7 +127,7 @@ void hw_error(const char *fmt, ...)/* * The chosen accelerator is supposed to register this. */ -static const CpusAccel *cpus_accel; +static const AccelOpsClass *cpus_accel;void cpu_synchronize_all_states (void ) {
@@ -593,11 +593,11 @@ void cpu_remove_sync(CPUState *cpu)qemu_mutex_lock_iothread (); } -void cpus_register_accel (const CpusAccel *ca) +void cpus_register_accel (const AccelOpsClass *ops) { -assert (ca !=NULL ); -assert (ca->create_vcpu_thread !=NULL );/* mandatory */ - cpus_accel = ca; +assert (ops !=NULL ); +assert (ops->create_vcpu_thread !=NULL );/* mandatory */ + cpus_accel = ops; }void qemu_init_vcpu (CPUState *cpu)
@@ -617,7 +617,7 @@ void qemu_init_vcpu(CPUState *cpu)cpu_address_space_init (cpu,0 ,"cpu-memory" , cpu->memory); } -/* accelerators all implement the CpusAccel interface */ +/* accelerators all implement the AccelOpsClass */ g_assert (cpus_accel !=NULL && cpus_accel->create_vcpu_thread !=NULL ); cpus_accel->create_vcpu_thread (cpu);
softmmu/vl.c +4 -2
@@ -2558,7 +2558,7 @@ static bool object_create_initial(const char *type, QemuOpts *opts) }/* Memory allocation by backends needs to be done -* after configure_accelerator() (due to the tcg_enabled() +* after do_configure_accelerator() (due to the tcg_enabled() * checks at memory_region_init_*()). * * Also, allocation of large amounts of memory may delay
@@ -4186,7 +4186,7 @@ void qemu_init(int argc, char **argv, char **envp)* * Machine compat properties: object_set_machine_compat_props(). * Accelerator compat props: object_set_accelerator_compat_props(), -* called from configure_accelerator(). +* called from do_configure_accelerator(). */ if (!qtest_enabled () && machine_class->deprecation_reason) {
@@ -4321,6 +4321,8 @@ void qemu_init(int argc, char **argv, char **envp)if (cpu_option) { current_machine->cpu_type =parse_cpu_option (cpu_option); } +/* NB: for machine none cpu_type could STILL be NULL here! */ +accel_init_interfaces (ACCEL_GET_CLASS (current_machine->accelerator));if (current_machine->ram_memdev_id) {Object *backend;
target/i386/hax/hax-accel-ops.c renamed from target/i386/hax/hax-cpus.c +23 -8
@@ -26,7 +26,7 @@#include "sysemu/cpus.h" #include "qemu/guest-random.h" -#include "hax-cpus.h" +#include "hax-accel-ops.h" static void *hax_cpu_thread_fn (void *arg) {
@@ -74,12 +74,27 @@ static void hax_start_vcpu_thread(CPUState *cpu)#endif } -const CpusAccel hax_cpus = { - .create_vcpu_thread = hax_start_vcpu_thread, - .kick_vcpu_thread = hax_kick_vcpu_thread, +static void hax_accel_ops_class_init (ObjectClass *oc,void *data) +{ +AccelOpsClass *ops =ACCEL_OPS_CLASS (oc); - .synchronize_post_reset = hax_cpu_synchronize_post_reset, - .synchronize_post_init = hax_cpu_synchronize_post_init, - .synchronize_state = hax_cpu_synchronize_state, - .synchronize_pre_loadvm = hax_cpu_synchronize_pre_loadvm, + ops->create_vcpu_thread = hax_start_vcpu_thread; + ops->kick_vcpu_thread = hax_kick_vcpu_thread; + + ops->synchronize_post_reset = hax_cpu_synchronize_post_reset; + ops->synchronize_post_init = hax_cpu_synchronize_post_init; + ops->synchronize_state = hax_cpu_synchronize_state; + ops->synchronize_pre_loadvm = hax_cpu_synchronize_pre_loadvm; +}; +static const TypeInfo hax_accel_ops_type = { + .name =ACCEL_OPS_NAME ("hax" ), + + .parent =TYPE_ACCEL_OPS , + .class_init = hax_accel_ops_class_init, + .abstract = true, }; +static void hax_accel_ops_register_types (void ) +{ +type_register_static (&hax_accel_ops_type); +} +type_init (hax_accel_ops_register_types);
target/i386/hax/hax-all.c +1 -4
@@ -33,7 +33,7 @@#include "sysemu/runstate.h" #include "hw/boards.h" -#include "hax-cpus.h" +#include "hax-accel-ops.h" #define DEBUG_HAX 0
@@ -364,9 +364,6 @@ static int hax_accel_init(MachineState *ms) !ret ?"working" :"not working" , !ret ? "fast virt" : "emulation"); } -if (ret ==0 ) { -cpus_register_accel (&hax_cpus); - }return ret; }
target/i386/hax/hax-mem.c +1 -1
@@ -13,7 +13,7 @@#include "exec/address-spaces.h" #include "qemu/error-report.h" -#include "hax-cpus.h" +#include "hax-accel-ops.h" #include "qemu/queue.h" #define DEBUG_HAX_MEM 0
target/i386/hax/hax-posix.c +1 -1
@@ -15,7 +15,7 @@#include <sys/ioctl.h> #include "sysemu/cpus.h" -#include "hax-cpus.h" +#include "hax-accel-ops.h" hax_fd hax_mod_open (void ) {
target/i386/hax/hax-windows.c +1 -1
@@ -12,7 +12,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "hax-cpus.h" +#include "hax-accel-ops.h" /* * return 0 when success, -1 when driver not loaded,
target/i386/hvf/hvf-accel-ops.c renamed from target/i386/hvf/hvf-cpus.c +22 -7
@@ -55,7 +55,7 @@#include "target/i386/cpu.h" #include "qemu/guest-random.h" -#include "hvf-cpus.h" +#include "hvf-accel-ops.h" /* * The HVF-specific vCPU thread function. This one should only run when the host
@@ -121,11 +121,26 @@ static void hvf_start_vcpu_thread(CPUState *cpu) cpu, QEMU_THREAD_JOINABLE); } -const CpusAccel hvf_cpus = { - .create_vcpu_thread = hvf_start_vcpu_thread, +static void hvf_accel_ops_class_init (ObjectClass *oc,void *data) +{ +AccelOpsClass *ops =ACCEL_OPS_CLASS (oc); - .synchronize_post_reset = hvf_cpu_synchronize_post_reset, - .synchronize_post_init = hvf_cpu_synchronize_post_init, - .synchronize_state = hvf_cpu_synchronize_state, - .synchronize_pre_loadvm = hvf_cpu_synchronize_pre_loadvm, + ops->create_vcpu_thread = hvf_start_vcpu_thread; + + ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset; + ops->synchronize_post_init = hvf_cpu_synchronize_post_init; + ops->synchronize_state = hvf_cpu_synchronize_state; + ops->synchronize_pre_loadvm = hvf_cpu_synchronize_pre_loadvm; +}; +static const TypeInfo hvf_accel_ops_type = { + .name =ACCEL_OPS_NAME ("hvf" ), + + .parent =TYPE_ACCEL_OPS , + .class_init = hvf_accel_ops_class_init, + .abstract = true, }; +static void hvf_accel_ops_register_types (void ) +{ +type_register_static (&hvf_accel_ops_type); +} +type_init (hvf_accel_ops_register_types);
target/i386/hvf/hvf.c +1 -2
@@ -72,7 +72,7 @@#include "qemu/accel.h" #include "target/i386/cpu.h" -#include "hvf-cpus.h" +#include "hvf-accel-ops.h" HVFState *hvf_state;
@@ -887,7 +887,6 @@ static int hvf_accel_init(MachineState *ms) hvf_state = s;memory_listener_register (&hvf_memory_listener, &address_space_memory); -cpus_register_accel (&hvf_cpus);return 0 ; }
target/i386/hvf/x86hvf.c +1 -1
@@ -32,7 +32,7 @@#include <Hypervisor/hv.h> #include <Hypervisor/hv_vmx.h> -#include "hvf-cpus.h" +#include "hvf-accel-ops.h" void hvf_set_segment (struct CPUState *cpu,struct vmx_segment *vmx_seg,SegmentCache *qseg,bool is_tr)
target/i386/whpx/whpx-accel-ops.c renamed from target/i386/whpx/whpx-cpus.c +23 -8
@@ -15,7 +15,7 @@#include "qemu/guest-random.h" #include "sysemu/whpx.h" -#include "whpx-cpus.h" +#include "whpx-accel-ops.h" #include <WinHvPlatform.h> #include <WinHvEmulation.h>
@@ -85,12 +85,27 @@ static void whpx_kick_vcpu_thread(CPUState *cpu) } } -const CpusAccel whpx_cpus = { - .create_vcpu_thread = whpx_start_vcpu_thread, - .kick_vcpu_thread = whpx_kick_vcpu_thread, +static void whpx_accel_ops_class_init (ObjectClass *oc,void *data) +{ +AccelOpsClass *ops =ACCEL_OPS_CLASS (oc); - .synchronize_post_reset = whpx_cpu_synchronize_post_reset, - .synchronize_post_init = whpx_cpu_synchronize_post_init, - .synchronize_state = whpx_cpu_synchronize_state, - .synchronize_pre_loadvm = whpx_cpu_synchronize_pre_loadvm, + ops->create_vcpu_thread = whpx_start_vcpu_thread; + ops->kick_vcpu_thread = whpx_kick_vcpu_thread; + + ops->synchronize_post_reset = whpx_cpu_synchronize_post_reset; + ops->synchronize_post_init = whpx_cpu_synchronize_post_init; + ops->synchronize_state = whpx_cpu_synchronize_state; + ops->synchronize_pre_loadvm = whpx_cpu_synchronize_pre_loadvm; +}; +static const TypeInfo whpx_accel_ops_type = { + .name =ACCEL_OPS_NAME ("whpx" ), + + .parent =TYPE_ACCEL_OPS , + .class_init = whpx_accel_ops_class_init, + .abstract = true, }; +static void whpx_accel_ops_register_types (void ) +{ +type_register_static (&whpx_accel_ops_type); +} +type_init (whpx_accel_ops_register_types);
target/i386/whpx/whpx-all.c +1 -3
@@ -24,7 +24,7 @@#include "migration/blocker.h" #include "whp-dispatch.h" -#include "whpx-cpus.h" +#include "whpx-accel-ops.h" #include <WinHvPlatform.h> #include <WinHvEmulation.h>
@@ -1642,8 +1642,6 @@ static int whpx_accel_init(MachineState *ms)whpx_memory_init (); -cpus_register_accel (&whpx_cpus); -printf ("Windows Hypervisor Platform accelerator is operational\n" );return 0 ;
MAINTAINERS +2 -1
@@ -435,7 +435,8 @@ M: Richard Henderson <[email protected]> R: Paolo Bonzini <[email protected]> S: Maintained F: include/qemu/accel.h -F: accel/accel.c +F: include/sysemu/accel-ops.h +F: accel/accel-*.c F: accel/Makefile.objs F: accel/stubs/Makefile.objs
accel/kvm/meson.build +1 -1
@@ -1,7 +1,7 @@ kvm_ss = ss.source_set() kvm_ss.add(files( 'kvm-all.c', - 'kvm-cpus.c', + 'kvm-accel-ops.c', )) kvm_ss.add(when: 'CONFIG_SEV', if_false: files('sev-stub.c'))
accel/tcg/meson.build +4 -4
@@ -15,8 +15,8 @@ specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss) specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files( 'cputlb.c', - 'tcg-cpus.c', - 'tcg-cpus-mttcg.c', - 'tcg-cpus-icount.c', - 'tcg-cpus-rr.c' + 'tcg-accel-ops.c', + 'tcg-accel-ops-mttcg.c', + 'tcg-accel-ops-icount.c', + 'tcg-accel-ops-rr.c' ))
target/i386/hax/meson.build +1 -1
@@ -1,7 +1,7 @@ i386_softmmu_ss.add(when: 'CONFIG_HAX', if_true: files( 'hax-all.c', 'hax-mem.c', - 'hax-cpus.c', + 'hax-accel-ops.c', )) i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_POSIX'], if_true: files('hax-posix.c')) i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_WIN32'], if_true: files('hax-windows.c'))
target/i386/hvf/meson.build +1 -1
@@ -1,6 +1,6 @@ i386_softmmu_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: files( 'hvf.c', - 'hvf-cpus.c', + 'hvf-accel-ops.c', 'x86.c', 'x86_cpuid.c', 'x86_decode.c',
target/i386/whpx/meson.build +1 -1
@@ -1,4 +1,4 @@ i386_softmmu_ss.add(when: 'CONFIG_WHPX', if_true: files( 'whpx-all.c', - 'whpx-cpus.c', + 'whpx-accel-ops.c', ))
Signature · 1 line
2.26.2
PATCH v11 3/7 accel: introduce AccelCPUClass extending CPUClass
In reply to Claudio Fontanaadd a new optional interface to CPUClass, which allows accelerators to extend the CPUClass with additional accelerator-specific initializations.
--- include/hw/core/accel-cpu.h | 25 +++++++++++++++++++++ include/hw/core/cpu.h | 13 +++++++++++ accel/accel-common.c | 44 +++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 4 files changed, 83 insertions(+) create mode 100644 include/hw/core/accel-cpu.h
include/hw/core/accel-cpu.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Accelerator interface, specializes CPUClass +* +* Copyright 2020 SUSE LLC +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef ACCEL_CPU_H +#define ACCEL_CPU_H + +/* +* these defines cannot be in cpu.h, because we are using +* CPU_RESOLVING_TYPE here. +* Use this header to define your accelerator-specific +* cpu-specific accelerator interfaces. +*/ + +#define TYPE_ACCEL_CPU "accel-" CPU_RESOLVING_TYPE +#define ACCEL_CPU_NAME (name) (name "-" TYPE_ACCEL_CPU) +typedef struct AccelCPUClass AccelCPUClass ; +DECLARE_CLASS_CHECKERS(AccelCPUClass, ACCEL_CPU, TYPE_ACCEL_CPU) + +#endif /* ACCEL_CPU_H */
include/hw/core/cpu.h +13 -0
@@ -76,6 +76,17 @@ typedef struct CPUWatchpoint CPUWatchpoint;struct TranslationBlock ; +/* see also accel-cpu.h */ +typedef struct AccelCPUClass { +/*< private >*/ +ObjectClass parent_class; +/*< public >*/ + +void (*cpu_class_init)(CPUClass *cc); +void (*cpu_instance_init)(CPUState *cpu); +void (*cpu_realizefn)(CPUState *cpu,Error **errp); +}AccelCPUClass ; +#ifdef CONFIG_TCG #include "tcg-cpu-ops.h" #endif /* CONFIG_TCG */
@@ -196,6 +207,8 @@ struct CPUClass {#ifdef CONFIG_TCG TcgCpuOperations tcg_ops;#endif /* CONFIG_TCG */ + +AccelCPUClass *accel_cpu_interface; };/*
accel/accel-common.c +44 -0
66 lines not on this page · raw message
MAINTAINERS +1 -0
@@ -436,6 +436,7 @@ R: Paolo Bonzini <[email protected]> S: Maintained F: include/qemu/accel.h F: include/sysemu/accel-ops.h +F: include/hw/core/accel-cpu.h F: accel/accel-*.c F: accel/Makefile.objs F: accel/stubs/Makefile.objs
Signature · 1 line
2.26.2
PATCH v11 4/7 i386: split cpu accelerators from cpu.c, using AccelCPUClass
In reply to Claudio Fontanai386 is the first user of AccelCPUClass, allowing to split cpu.c into:
cpu.c cpuid and common x86 cpu functionality host-cpu.c host x86 cpu functions and "host" cpu type kvm/kvm-cpu.c KVM x86 AccelCPUClass hvf/hvf-cpu.c HVF x86 AccelCPUClass tcg/tcg-cpu.c TCG x86 AccelCPUClass
--- target/i386/cpu.h | 20 +- target/i386/host-cpu.h | 19 ++ target/i386/kvm/kvm-cpu.h | 41 ++++ target/i386/tcg/tcg-cpu.h | 15 -- hw/i386/pc_piix.c | 1 + target/i386/cpu.c | 386 ++++-------------------------------- target/i386/host-cpu.c | 198 ++++++++++++++++++ target/i386/hvf/hvf-cpu.c | 65 ++++++ target/i386/kvm/kvm-cpu.c | 148 ++++++++++++++ target/i386/kvm/kvm.c | 3 +- target/i386/tcg/tcg-cpu.c | 116 ++++++++++- MAINTAINERS | 2 +- target/i386/hvf/meson.build | 1 + target/i386/kvm/meson.build | 7 +- target/i386/meson.build | 6 +- 15 files changed, 644 insertions(+), 384 deletions(-) create mode 100644 target/i386/host-cpu.h create mode 100644 target/i386/kvm/kvm-cpu.h delete mode 100644 target/i386/tcg/tcg-cpu.h create mode 100644 target/i386/host-cpu.c create mode 100644 target/i386/hvf/hvf-cpu.c create mode 100644 target/i386/kvm/kvm-cpu.c
target/i386/cpu.h +8 -12
@@ -1905,13 +1905,20 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo, void *puc);/* cpu.c */ +void x86_cpu_vendor_words2str (char *dst,uint32_t vendor1, +uint32_t vendor2,uint32_t vendor3); +typedef struct PropValue { +const char *prop, *value; +}PropValue ; +void x86_cpu_apply_props (X86CPU *cpu,PropValue *props); + +/* cpu.c other functions (cpuid) */ void cpu_x86_cpuid (CPUX86State *env,uint32_t index,uint32_t count,uint32_t *eax,uint32_t *ebx,uint32_t *ecx,uint32_t *edx);void cpu_clear_apic_feature (CPUX86State *env);void host_cpuid (uint32_t function,uint32_t count,uint32_t *eax,uint32_t *ebx,uint32_t *ecx,uint32_t *edx); -void host_vendor_fms (char *vendor,int *family,int *model,int *stepping);/* helper.c */ void x86_cpu_set_a20 (X86CPU *cpu,int a20_state);
@@ -2111,17 +2118,6 @@ void cpu_report_tpr_access(CPUX86State *env, TPRAccess access);void apic_handle_tpr_access_report (DeviceState *d,target_ulong ip,TPRAccess access); - -/* Change the value of a KVM-specific default -* -* If value is NULL, no default will be set and the original -* value from the CPU model table will be kept. -* -* It is valid to call this function only for properties that -* are already present in the kvm_default_props table. -*/ -void x86_cpu_change_kvm_default (const char *prop,const char *value); -/* Special values for X86CPUVersion: */ /* Resolve to latest CPU version */
target/i386/host-cpu.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* x86 host CPU type initialization and host CPU functions +* +* Copyright 2020 SUSE LLC +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HOST_CPU_H +#define HOST_CPU_H + +void host_cpu_instance_init (X86CPU *cpu); +void host_cpu_max_instance_init (X86CPU *cpu); +void host_cpu_realizefn (CPUState *cs,Error **errp); + +void host_cpu_vendor_fms (char *vendor,int *family,int *model,int *stepping); + +#endif /* HOST_CPU_H */
target/i386/kvm/kvm-cpu.h new file +41 -0
41 lines not on this page · raw message
target/i386/tcg/tcg-cpu.h deleted +0 -15
@@ -1,15 +0,0 @@ -/* -* i386 TCG CPU class initialization -* -* Copyright 2020 SUSE LLC -* -* This work is licensed under the terms of the GNU GPL, version 2 or later. -* See the COPYING file in the top-level directory. -*/ - -#ifndef TCG_CPU_H -#define TCG_CPU_H - -void tcg_cpu_common_class_init (CPUClass *cc); - -#endif /* TCG_CPU_H */
hw/i386/pc_piix.c +1 -0
@@ -64,6 +64,7 @@#include "hw/hyperv/vmbus-bridge.h" #include "hw/mem/nvdimm.h" #include "hw/i386/acpi-build.h" +#include "kvm/kvm-cpu.h" #define MAX_IDE_BUS 2
target/i386/cpu.c +40 -346
550 lines not on this page · raw message
target/i386/host-cpu.c new file +198 -0
198 lines not on this page · raw message
target/i386/hvf/hvf-cpu.c new file +65 -0
65 lines not on this page · raw message
target/i386/kvm/kvm-cpu.c new file +148 -0
148 lines not on this page · raw message
target/i386/kvm/kvm.c +2 -1
@@ -22,6 +22,7 @@#include "standard-headers/asm-x86/kvm_para.h" #include "cpu.h" +#include "host-cpu.h" #include "sysemu/sysemu.h" #include "sysemu/hw_accel.h" #include "sysemu/kvm_int.h"
@@ -285,7 +286,7 @@ static bool host_tsx_broken(void)int family, model, stepping;\char vendor[CPUID_VENDOR_SZ +1 ]; -host_vendor_fms (vendor, &family, &model, &stepping); +host_cpu_vendor_fms (vendor, &family, &model, &stepping);/* Check if we are running on a Haswell host known to have broken TSX */ return !strcmp(vendor, CPUID_VENDOR_INTEL) &&
target/i386/tcg/tcg-cpu.c +109 -7
134 lines not on this page · raw message
MAINTAINERS +1 -1
@@ -337,7 +337,7 @@ M: Paolo Bonzini <[email protected]> M: Richard Henderson <[email protected]> M: Eduardo Habkost <[email protected]> S: Maintained -F: target/i386/ +F: target/i386/tcg/ F: tests/tcg/i386/ F: tests/tcg/x86_64/ F: hw/i386/
target/i386/hvf/meson.build +1 -0
@@ -10,4 +10,5 @@ i386_softmmu_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: files( 'x86_mmu.c', 'x86_task.c', 'x86hvf.c', + 'hvf-cpu.c', ))
target/i386/kvm/meson.build +6 -1
@@ -1,3 +1,8 @@ i386_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c')) -i386_softmmu_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c')) + +i386_softmmu_ss.add(when: 'CONFIG_KVM', if_true: files( + 'kvm.c', + 'kvm-cpu.c', +)) + i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c'))
target/i386/meson.build +5 -1
@@ -6,7 +6,11 @@ i386_ss.add(files( 'xsave_helper.c', 'cpu-dump.c', )) -i386_ss.add(when: 'CONFIG_SEV', if_true: files('sev.c'), if_false: files('sev-stub.c')) +i386_ss.add(when: 'CONFIG_SEV', if_true: files('host-cpu.c', 'sev.c'), if_false: files('sev-stub.c')) + +# x86 cpu type +i386_ss.add(when: 'CONFIG_KVM', if_true: files('host-cpu.c')) +i386_ss.add(when: 'CONFIG_HVF', if_true: files('host-cpu.c')) i386_softmmu_ss = ss.source_set() i386_softmmu_ss.add(files(
Signature · 1 line
2.26.2
PATCH v11 5/7 cpu: call AccelCPUClass::cpu_realizefn in cpu_exec_realizefn
In reply to Claudio Fontanamove the call to the accel_cpu_interface method to the general cpu_exec_realizefn from target/i386, so it does not need to be called for every target explicitly as we enable more targets.
--- cpu.c | 5 +++++ target/i386/cpu.c | 15 ++++----------- 2 files changed, 9 insertions(+), 11 deletions(-)
cpu.c +5 -0
@@ -130,6 +130,11 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)cpu_list_add (cpu); +if (cc->accel_cpu_interface) { +/* NB: errp parameter is unused currently */ + cc->accel_cpu_interface->cpu_realizefn (cpu, errp); + } +#ifdef CONFIG_TCG /* NB: errp parameter is unused currently */ if (tcg_enabled ()) {
target/i386/cpu.c +4 -11
@@ -6280,16 +6280,16 @@ static void x86_cpu_filter_features(X86CPU *cpu, bool verbose)static void x86_cpu_realizefn (DeviceState *dev,Error **errp) {CPUState *cs =CPU (dev); -CPUClass *cc =CPU_GET_CLASS (cs);X86CPU *cpu =X86_CPU (dev);X86CPUClass *xcc =X86_CPU_GET_CLASS (dev);CPUX86State *env = &cpu->env;Error *local_err =NULL ;static bool ht_warned; -/* The accelerator realizefn needs to be called first. */ -if (cc->accel_cpu_interface) { - cc->accel_cpu_interface->cpu_realizefn (cs, errp); +cpu_exec_realizefn (cs, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; }if (xcc->host_cpuid_required && !accel_uses_host_cpuid ()) {
@@ -6405,13 +6405,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) env->cache_info_amd.l3_cache = &legacy_l3_cache; } - -cpu_exec_realizefn (cs, &local_err); -if (local_err !=NULL ) { -error_propagate (errp, local_err); -return ; - } -#ifndef CONFIG_USER_ONLY MachineState *ms =MACHINE (qdev_get_machine ());qemu_register_reset (x86_cpu_machine_reset_cb, cpu);
Signature · 1 line
2.26.2
PATCH v11 6/7 hw/core/cpu: call qemu_init_vcpu in cpu_common_realizefn
In reply to Claudio Fontanamove the call to qemu_init_vcpu inside cpu_common_realizefn, so it does not need to be done explicitly in each target cpu.
This makes it a little bit better, but still the way realize is done continues to be bad; ideally the cpu_list_add would be done in common_cpu, and in this case we could avoid even more additional calls in target/xxx/cpu.c,
but this cannot happen because target cpu code, plugins, etc now all rely on cpu->index, since no particular order was defined previously, so we are stuck with the freak call order for the target cpu realizefn.
After this patch the target/xxx/cpu.c realizefn body is now:
void mycpu_realizefn(DeviceState *dev, Error **errp)
{
/* ... */
cpu_exec_realizefn(CPU_STATE(dev), errp);
/* ... anything that needs done pre-qemu_vcpu_init */
xcc->parent_realize(dev, errp); /* does qemu_vcpu_init */
/* ... anything that needs to be done after qemu_vcpu_init */
}Note: better do some testing for all targets for this.
--- hw/core/cpu.c | 2 ++ target/alpha/cpu.c | 5 +---- target/arm/cpu.c | 4 +--- target/avr/cpu.c | 3 +-- target/cris/cpu.c | 2 -- target/hppa/cpu.c | 1 - target/i386/cpu.c | 5 +---- target/lm32/cpu.c | 3 --- target/m68k/cpu.c | 2 -- target/microblaze/cpu.c | 9 +++------ target/mips/cpu.c | 2 -- target/moxie/cpu.c | 4 +--- target/nios2/cpu.c | 4 +--- target/openrisc/cpu.c | 4 +--- target/riscv/cpu.c | 8 +++----- target/rx/cpu.c | 8 +++----- target/s390x/cpu.c | 3 +-- target/sh4/cpu.c | 2 -- target/sparc/cpu.c | 4 +--- target/tilegx/cpu.c | 2 -- target/tricore/cpu.c | 2 -- target/unicore32/cpu.c | 6 +----- target/xtensa/cpu.c | 2 -- target/ppc/translate_init.c.inc | 5 ++--- 24 files changed, 23 insertions(+), 69 deletions(-)
hw/core/cpu.c +2 -0
@@ -318,6 +318,8 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)CPUState *cpu =CPU (dev);Object *machine =qdev_get_machine (); +qemu_init_vcpu (cpu); +/* qdev_get_machine() can return something that's not TYPE_MACHINE * if this is one of the user-only emulators; in that case there's * no need to check the ignore_memory_transaction_failures board flag.
target/alpha/cpu.c +1 -4
@@ -56,18 +56,15 @@ static void alpha_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)static void alpha_cpu_realizefn (DeviceState *dev,Error **errp) { -CPUState *cs =CPU (dev);AlphaCPUClass *acc =ALPHA_CPU_GET_CLASS (dev);Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_exec_realizefn (CPU (dev), &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ; } -qemu_init_vcpu (cs); - acc->parent_realize (dev, errp); }
target/arm/cpu.c +1 -3
@@ -1859,10 +1859,8 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) } } -qemu_init_vcpu (cs); -cpu_reset (cs); - acc->parent_realize (dev, errp); +cpu_reset (cs); }static ObjectClass *arm_cpu_class_by_name (const char *cpu_model)
target/avr/cpu.c +1 -2
@@ -97,10 +97,9 @@ static void avr_cpu_realizefn(DeviceState *dev, Error **errp)error_propagate (errp, local_err);return ; } -qemu_init_vcpu (cs); -cpu_reset (cs); mcc->parent_realize (dev, errp); +cpu_reset (cs); }static void avr_cpu_set_int (void *opaque,int irq,int level)
target/cris/cpu.c +0 -2
@@ -135,8 +135,6 @@ static void cris_cpu_realizefn(DeviceState *dev, Error **errp) }cpu_reset (cs); -qemu_init_vcpu (cs); - ccc->parent_realize (dev, errp); }
target/hppa/cpu.c +0 -1
@@ -101,7 +101,6 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error **errp)return ; } -qemu_init_vcpu (cs); acc->parent_realize (dev, errp);#ifndef CONFIG_USER_ONLY
target/i386/cpu.c +1 -4
@@ -6419,8 +6419,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)mce_init (cpu); -qemu_init_vcpu (cs); - + xcc->parent_realize (dev, &local_err);/* * Most Intel and certain AMD CPUs support hyperthreading. Even though QEMU * fixes this issue by adjusting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX
@@ -6447,8 +6446,6 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) }cpu_reset (cs); - xcc->parent_realize (dev, &local_err); - out:if (local_err !=NULL ) {error_propagate (errp, local_err);
target/lm32/cpu.c +0 -3
@@ -133,9 +133,6 @@ static void lm32_cpu_realizefn(DeviceState *dev, Error **errp) }cpu_reset (cs); - -qemu_init_vcpu (cs); - lcc->parent_realize (dev, errp); }
target/m68k/cpu.c +0 -2
@@ -248,8 +248,6 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)m68k_cpu_init_gdb (cpu);cpu_reset (cs); -qemu_init_vcpu (cs); - mcc->parent_realize (dev, errp); }
target/microblaze/cpu.c +3 -6
@@ -145,15 +145,14 @@ static void mb_disas_set_info(CPUState *cpu, disassemble_info *info)static void mb_cpu_realizefn (DeviceState *dev,Error **errp) { -CPUState *cs =CPU (dev);MicroBlazeCPUClass *mcc =MICROBLAZE_CPU_GET_CLASS (dev); -MicroBlazeCPU *cpu =MICROBLAZE_CPU (cs); +MicroBlazeCPU *cpu =MICROBLAZE_CPU (dev);uint8_t version_code =0 ;const char *version;int i =0 ;Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_exec_realizefn (CPU (dev), &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ;
@@ -165,7 +164,7 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp)return ; } -qemu_init_vcpu (cs); + mcc->parent_realize (dev, errp); version = cpu->cfg.version ? cpu->cfg.version :DEFAULT_CPU_VERSION ;for (i =0 ; mb_cpu_lookup[i].name && version; i++) {
@@ -231,8 +230,6 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp) cpu->cfg.mmu_tlb_access =3 ; cpu->cfg.mmu_zones =16 ; cpu->cfg.addr_mask =MAKE_64BIT_MASK (0 , cpu->cfg.addr_size); - - mcc->parent_realize (dev, errp); }static void mb_cpu_initfn (Object *obj)
target/mips/cpu.c +0 -2
@@ -184,8 +184,6 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp)cpu_mips_realize_env (&cpu->env);cpu_reset (cs); -qemu_init_vcpu (cs); - mcc->parent_realize (dev, errp); }
target/moxie/cpu.c +1 -3
@@ -66,10 +66,8 @@ static void moxie_cpu_realizefn(DeviceState *dev, Error **errp)return ; } -qemu_init_vcpu (cs); -cpu_reset (cs); - mcc->parent_realize (dev, errp); +cpu_reset (cs); }static void moxie_cpu_initfn (Object *obj)
target/nios2/cpu.c +1 -3
@@ -92,10 +92,8 @@ static void nios2_cpu_realizefn(DeviceState *dev, Error **errp)return ; } -qemu_init_vcpu (cs); -cpu_reset (cs); - ncc->parent_realize (dev, errp); +cpu_reset (cs); }static bool nios2_cpu_exec_interrupt (CPUState *cs,int interrupt_request)
target/openrisc/cpu.c +1 -3
@@ -77,10 +77,8 @@ static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp)return ; } -qemu_init_vcpu (cs); -cpu_reset (cs); - occ->parent_realize (dev, errp); +cpu_reset (cs); }static void openrisc_cpu_initfn (Object *obj)
target/riscv/cpu.c +3 -5
@@ -341,7 +341,7 @@ static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info)#endif } -static void riscv_cpu_realize (DeviceState *dev,Error **errp) +static void riscv_cpu_realizefn (DeviceState *dev,Error **errp) {CPUState *cs =CPU (dev);RISCVCPU *cpu =RISCV_CPU (dev);
@@ -486,10 +486,8 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)riscv_cpu_register_gdb_regs_for_features (cs); -qemu_init_vcpu (cs); -cpu_reset (cs); - mcc->parent_realize (dev, errp); +cpu_reset (cs); }static void riscv_cpu_init (Object *obj)
@@ -532,7 +530,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)CPUClass *cc =CPU_CLASS (c);DeviceClass *dc =DEVICE_CLASS (c); -device_class_set_parent_realize (dc, riscv_cpu_realize, +device_class_set_parent_realize (dc, riscv_cpu_realizefn, &mcc->parent_realize);device_class_set_parent_reset (dc, riscv_cpu_reset, &mcc->parent_reset);
target/rx/cpu.c +3 -5
@@ -105,7 +105,7 @@ static ObjectClass *rx_cpu_class_by_name(const char *cpu_model)return oc; } -static void rx_cpu_realize (DeviceState *dev,Error **errp) +static void rx_cpu_realizefn (DeviceState *dev,Error **errp) {CPUState *cs =CPU (dev);RXCPUClass *rcc =RX_CPU_GET_CLASS (dev);
@@ -117,10 +117,8 @@ static void rx_cpu_realize(DeviceState *dev, Error **errp)return ; } -qemu_init_vcpu (cs); -cpu_reset (cs); - rcc->parent_realize (dev, errp); +cpu_reset (cs); }static void rx_cpu_set_irq (void *opaque,int no,int request)
@@ -178,7 +176,7 @@ static void rx_cpu_class_init(ObjectClass *klass, void *data)CPUClass *cc =CPU_CLASS (klass);RXCPUClass *rcc =RX_CPU_CLASS (klass); -device_class_set_parent_realize (dc, rx_cpu_realize, +device_class_set_parent_realize (dc, rx_cpu_realizefn, &rcc->parent_realize);device_class_set_parent_reset (dc, rx_cpu_reset, &rcc->parent_reset);
target/s390x/cpu.c +1 -2
@@ -232,8 +232,8 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp)qemu_register_reset (s390_cpu_machine_reset_cb, cpu);#endif s390_cpu_gdb_init (cs); -qemu_init_vcpu (cs); + scc->parent_realize (dev, &err);/* * KVM requires the initial CPU reset ioctl to be executed on the target * CPU thread. CPU hotplug under single-threaded TCG will not work with
@@ -246,7 +246,6 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp)cpu_reset (cs); } - scc->parent_realize (dev, &err); out:error_propagate (errp, err); }
target/sh4/cpu.c +0 -2
@@ -185,8 +185,6 @@ static void superh_cpu_realizefn(DeviceState *dev, Error **errp) }cpu_reset (cs); -qemu_init_vcpu (cs); - scc->parent_realize (dev, errp); }
target/sparc/cpu.c +1 -3
@@ -738,9 +738,9 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp) {CPUState *cs =CPU (dev);SPARCCPUClass *scc =SPARC_CPU_GET_CLASS (dev); -Error *local_err =NULL ;SPARCCPU *cpu =SPARC_CPU (dev);CPUSPARCState *env = &cpu->env; +Error *local_err =NULL ;#if defined(CONFIG_USER_ONLY )if ((env->def.features &CPU_FEATURE_FLOAT )) {
@@ -768,8 +768,6 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)return ; } -qemu_init_vcpu (cs); - scc->parent_realize (dev, errp); }
target/tilegx/cpu.c +0 -2
@@ -93,8 +93,6 @@ static void tilegx_cpu_realizefn(DeviceState *dev, Error **errp) }cpu_reset (cs); -qemu_init_vcpu (cs); - tcc->parent_realize (dev, errp); }
target/tricore/cpu.c +0 -2
@@ -93,8 +93,6 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp)set_feature (env,TRICORE_FEATURE_13 ); }cpu_reset (cs); -qemu_init_vcpu (cs); - tcc->parent_realize (dev, errp); }
target/unicore32/cpu.c +1 -5
@@ -84,18 +84,14 @@ static void uc32_any_cpu_initfn(Object *obj)static void uc32_cpu_realizefn (DeviceState *dev,Error **errp) { -CPUState *cs =CPU (dev);UniCore32CPUClass *ucc =UNICORE32_CPU_GET_CLASS (dev);Error *local_err =NULL ; -cpu_exec_realizefn (cs, &local_err); +cpu_exec_realizefn (CPU (dev), &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ; } - -qemu_init_vcpu (cs); - ucc->parent_realize (dev, errp); }
target/xtensa/cpu.c +0 -2
@@ -153,8 +153,6 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp) cs->gdb_num_regs = xcc->config->gdb_regmap.num_regs; -qemu_init_vcpu (cs); - xcc->parent_realize (dev, errp); }
target/ppc/translate_init.c.inc +2 -3
@@ -10093,7 +10093,7 @@ static int ppc_fixup_cpu(PowerPCCPU *cpu) return 0; } -static void ppc_cpu_realize(DeviceState *dev, Error **errp) +static void ppc_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); PowerPCCPU *cpu = POWERPC_CPU(dev);
@@ -10143,7 +10143,6 @@ static void ppc_cpu_realize(DeviceState *dev, Error **errp) gdb_register_coprocessor(cs, gdb_get_spr_reg, gdb_set_spr_reg, pcc->gdb_num_sprs, "power-spr.xml", 0); #endif - qemu_init_vcpu(cs); pcc->parent_realize(dev, errp);
@@ -10898,7 +10897,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) CPUClass *cc = CPU_CLASS(oc); DeviceClass *dc = DEVICE_CLASS(oc); - device_class_set_parent_realize(dc, ppc_cpu_realize, + device_class_set_parent_realize(dc, ppc_cpu_realizefn, &pcc->parent_realize); device_class_set_parent_unrealize(dc, ppc_cpu_unrealize, &pcc->parent_unrealize);
Signature · 1 line
2.26.2
PATCH v11 7/7 cpu: introduce cpu_accel_instance_init
In reply to Claudio Fontanacentralize the calls to cpu->accel_cpu_interface
--- include/hw/core/cpu.h | 6 ++++++ hw/core/cpu.c | 9 +++++++++ target/i386/cpu.c | 9 ++------- 3 files changed, 17 insertions(+), 7 deletions(-)
include/hw/core/cpu.h +6 -0
@@ -664,6 +664,12 @@ void cpu_list_remove(CPUState *cpu);*/ void cpu_reset (CPUState *cpu); +/** +* cpu_accel_instance_init: +* @cpu: The CPU that needs to do accel-specific object initializations. +*/ +void cpu_accel_instance_init (CPUState *cpu); +/** * cpu_class_by_name: * @typename: The CPU base type.
hw/core/cpu.c +9 -0
@@ -242,6 +242,15 @@ void cpu_reset(CPUState *cpu)trace_guest_cpu_reset (cpu); } +void cpu_accel_instance_init (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->accel_cpu_interface) { + cc->accel_cpu_interface->cpu_instance_init (cpu); + } +} +static void cpu_common_reset (DeviceState *dev) {CPUState *cpu =CPU (dev);
target/i386/cpu.c +2 -7
@@ -28,7 +28,6 @@#include "sysemu/kvm.h" #include "sysemu/reset.h" #include "sysemu/hvf.h" -#include "hw/core/accel-cpu.h" #include "sysemu/xen.h" #include "kvm/kvm_i386.h" #include "sev_i386.h"
@@ -6621,8 +6620,6 @@ static void x86_cpu_initfn(Object *obj) {X86CPU *cpu =X86_CPU (obj);X86CPUClass *xcc =X86_CPU_GET_CLASS (obj); -CPUClass *cc =CPU_CLASS (xcc); -CPUX86State *env = &cpu->env;FeatureWord w;
@@ -6680,10 +6677,8 @@ static void x86_cpu_initfn(Object *obj)x86_cpu_load_model (cpu, xcc->model); } -/* if required, do the accelerator-specific cpu initialization */ -if (cc->accel_cpu_interface) { - cc->accel_cpu_interface->cpu_instance_init (CPU (obj)); - } +/* if required, do accelerator-specific cpu initializations */ +cpu_accel_instance_init (CPU (obj)); }static int64_t x86_cpu_get_arch_id (CPUState *cs)
Signature · 1 line
2.26.2
dangers of current NEED_CPU_H, CONFIG_SOFTMMU, CONFIG_USER_ONLY (was: [PATCH v11 7/7] cpu: introduce cpu_accel_instance_init)
Hi,
I would like to highlight the current dangerous state of NEED_CPU_H / CONFIG_SOFTMMU / CONFIG_USER_ONLY.
This patch of mine (the last in the i386 cleanup PART 2) breaks check-tcg.
The why is not obvious at all. I'll comment below it.
Quoted 71 lines · Claudio Fontana
centralize the calls to
cpu->accel_cpu_interfaceSigned-off-by Claudio Fontana <[email protected]>--- include/hw/core/cpu.h | 6 ++++++ hw/core/cpu.c | 9 +++++++++ target/i386/cpu.c | 9 ++------- 3 files changed, 17 insertions(+), 7 deletions(-)include/hw/core/cpu.h +6
-0@@ -664,6 +664,12 @@ void cpu_list_remove(CPUState *cpu);*/ void cpu_reset (CPUState *cpu); +/** +* cpu_accel_instance_init: +* @cpu: The CPU that needs to do accel-specific object initializations. +*/ +void cpu_accel_instance_init (CPUState *cpu); +/** * cpu_class_by_name: * @typename: The CPU base type. hw/core/cpu.c +9
-0@@ -242,6 +242,15 @@ void cpu_reset(CPUState *cpu)trace_guest_cpu_reset (cpu); } +void cpu_accel_instance_init (CPUState *cpu) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); + +if (cc->accel_cpu_interface) { + cc->accel_cpu_interface->cpu_instance_init (cpu); + } +} +static void cpu_common_reset (DeviceState *dev) {CPUState *cpu =CPU (dev);target/i386/cpu.c +0
-3@@ -28,7 +28,6 @@#include "sysemu/kvm.h" #include "sysemu/reset.h" #include "sysemu/hvf.h" -#include "hw/core/accel-cpu.h" #include "sysemu/xen.h" #include "kvm/kvm_i386.h" #include "sev_i386.h" @@ -6621,8 +6620,6 @@ static void x86_cpu_initfn(Object *obj) {X86CPU *cpu =X86_CPU (obj);X86CPUClass *xcc =X86_CPU_GET_CLASS (obj); -CPUClass *cc =CPU_CLASS (xcc); -CPUX86State *env = &cpu->env;FeatureWord w;@@ -6680,10 +6677,8 @@ static void x86_cpu_initfn(Object *obj)x86_cpu_load_model (cpu, xcc->model); }
target/i386/cpu.c static void x86_cpu_initfn(Object *obj) · line 6684
Quoted 10 lines
target/i386/cpu.c +2
-4-/* if required, do the accelerator-specific cpu initialization */ -if (cc->accel_cpu_interface) { - cc->accel_cpu_interface->cpu_instance_init (CPU (obj)); - } +/* if required, do accelerator-specific cpu initializations */ +cpu_accel_instance_init (CPU (obj)); }static int64_t x86_cpu_get_arch_id (CPUState *cs)
Seems a harmless change right?
Just extract the use of cc->accel_cpu_interface->cpu_instance_init from x86 so it can be a useful function for all architecture targets to start using, as we continue the refactoring past x86 into arm etc.
Instead, it breaks at least check-tcg (linux-user), if not more.
vvv spoiler below vvvv
The reason comes down in the end to the fact that we have moved code that is using CPUClass from target/i386 to hw/core/cpu.c.
If we look at hw/core/meson.build , we notice that cpu.c is in common_ss.
common_ss code does NOT see CONFIG_USER_ONLY, ever.
So our struct TcgCpuOperations in include/hw/core/cpu.h, which contains after this series:
#ifndef CONFIG_USER_ONLY
/**
* @do_transaction_failed: Callback for handling failed memory transactions
* (ie bus faults or external aborts; not MMU faults)
*/
void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr,
unsigned size, MMUAccessType access_type, int mmu_idx, MemTxAttrs attrs, MemTxResult response, uintptr_t retaddr);
/**
* @do_unaligned_access: Callback for unaligned access handling */
void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
MMUAccessType access_type,
int mmu_idx, uintptr_t retaddr);
#endif /* !CONFIG_USER_ONLY */
Now suddenly will have some of the objects (in target/...) seeing the struct as not having do_transaction_failed and do_unaligned_access, and some of the objects (common_ss stuff) not seeing CONFIG_USER_ONLY and therefore instead _seeing_ do_transaction_failed and do_unaligned_access.
Result is a set of segfaults.
The reason we went on and tried to protect with CONFIG_USER_ONLY was to make sure that it is a compile time error to try to use these for linux-user, but we end up making things worse.
Note that include/hw/core/cpu.h already uses CONFIG_USER_ONLY in other parts of the header file, and we might have hidden problems as a result we (or at least I) don't know about, because code is being compiled in for linux-user which explicitly should not be compiled there.
There are multiple workarounds / fixes possible for my short term problem, but would it not be a good idea to fix this problem at its root once and for all?
Otherwise, like I fell into this trap, others also probably will, and based on the existing cpu.h code already in mainline, indeed it seems already have.
Thoughts?
Thanks,
Claudio
Re: dangers of current NEED_CPU_H, CONFIG_SOFTMMU, CONFIG_USER_ONLY (was: [PATCH v11 7/7] cpu: introduce cpu_accel_instance_init)
Quoted 8 lines · Claudio Fontana
Hi,
I would like to highlight the current dangerous state of
NEED_CPU_H/CONFIG_SOFTMMU/CONFIG_USER_ONLY.So our struct TcgCpuOperations in
include/hw/core/cpu.h, which contains after this series:
Quoted 16 lines
#ifndef
CONFIG_USER_ONLY
/**
* @do_transaction_failed: Callback for handling failed memory transactions
* (ie bus faults or external aborts; not MMU faults)
*/
void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr,
unsigned size, MMUAccessTypeaccess_type, intmmu_idx, MemTxAttrs attrs, MemTxResult response,uintptr_tretaddr);
/**
* @do_unaligned_access: Callback for unaligned access handling */
void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
MMUAccessTypeaccess_type,
intmmu_idx,uintptr_tretaddr);
#endif /* !CONFIG_USER_ONLY */
Yeah, don't try to ifdef out struct fields in common-compiled code...
Quoted 2 lines
Note that
include/hw/core/cpu.halready usesCONFIG_USER_ONLYin other parts of the header file, and we might have hidden problems as a result we (or at least I) don't know about, because code is being compiled in for linux-user which explicitly should not be compiled there.
The other CONFIG_USER_ONLY checks in that file are only ifdeffing out prototypes for functions that exist only in the softmmu build, or providing do-nothing stubs for functions that are softmmu only. I think they're safe.
Quoted 2 lines
There are multiple workarounds / fixes possible for my short term problem, but would it not be a good idea to fix this problem at its root once and for all?
What's your proposal for fixing things ?
Incidentally, this should not be a problem for CONFIG_SOFTMMU, because that is listed in include/exec/poison.h so trying to use it in a common (not compiled-per-target) file will give you a compile error. (So in theory we could make CONFIG_USER_ONLY a poisoned identifier but that will require some work to adjust places where we currently use it in "safe" ways...)
thanks
-- PMM
Re: dangers of current NEED_CPU_H, CONFIG_SOFTMMU, CONFIG_USER_ONLY (was: [PATCH v11 7/7] cpu: introduce cpu_accel_instance_init)
Quoted 3 lines · Peter Maydell
(So in theory we could make
CONFIG_USER_ONLY
a poisoned identifier but that will require some work to adjust places where we currently use it in "safe" ways...)
Specifically, putting it in poison.h turns up these places that would need to be made to do what they're doing in a different way somehow:
../../hw/core/cpu.c:211:14: error: attempt to use poisoned "CONFIG_USER_ONLY" include/disas/disas.h:27:13: error: attempt to use poisoned "CONFIG_USER_ONLY" include/exec/address-spaces.h:24:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/cpu-common.h:20:14: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/cpu-common.h:6:9: error: attempt to use poisoned "CONFIG_USER_ONLY" include/exec/ioport.h:43:9: error: attempt to use poisoned "CONFIG_USER_ONLY" include/exec/memory.h:17:9: error: attempt to use poisoned "CONFIG_USER_ONLY" include/exec/ramblock.h:22:9: error: attempt to use poisoned "CONFIG_USER_ONLY" include/hw/core/cpu.h:1035:8: error: attempt to use poisoned "CONFIG_USER_ONLY" include/hw/core/cpu.h:518:14: error: attempt to use poisoned "CONFIG_USER_ONLY" include/hw/core/cpu.h:602:9: error: attempt to use poisoned "CONFIG_USER_ONLY" include/hw/hw.h:4:8: error: attempt to use poisoned "CONFIG_USER_ONLY" include/hw/semihosting/semihost.h:29:8: error: attempt to use poisoned "CONFIG_USER_ONLY"include/sysemu/accel.h:40:9: error: attempt to use poisoned "CONFIG_USER_ONLY" include/sysemu/cpus.h:65:9: error: attempt to use poisoned "CONFIG_USER_ONLY" include/sysemu/dma.h:34:9: error: attempt to use poisoned "CONFIG_USER_ONLY" include/sysemu/xen.h:27:9: error: attempt to use poisoned "CONFIG_USER_ONLY"
That cpu.c one is definitely dubious given it's in a C file, not a header.
thanks
-- PMM
Re: dangers of current NEED_CPU_H, CONFIG_SOFTMMU, CONFIG_USER_ONLY (was: [PATCH v11 7/7] cpu: introduce cpu_accel_instance_init)
I will take a look, CONFIG_USER_ONLY is definitely something that should be poisoned.
Paolo
Il gio 17 dic 2020, 21:26 Peter Maydell <[email protected]> ha scritto:
Quoted 51 lines
Quoted 3 lines · Peter Maydell
(So in theory we could make
CONFIG_USER_ONLY
a poisoned identifier but that will require some work to adjust places where we currently use it in "safe" ways...)Specifically, putting it in
poison.hturns up these places that would need to be made to do what they're doing in a different way somehow:
../../hw/core/cpu.c:211:14: error: attempt to use poisoned "CONFIG_USER_ONLY"include/disas/disas.h:27:13: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/address-spaces.h:24:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/cpu-common.h:20:14: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/cpu-common.h:6:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/ioport.h:43:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/memory.h:17:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/ramblock.h:22:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/hw/core/cpu.h:1035:8: error: attempt to use poisoned "CONFIG_USER_ONLY"include/hw/core/cpu.h:518:14: error: attempt to use poisoned "CONFIG_USER_ONLY"include/hw/core/cpu.h:602:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/hw/hw.h:4:8: error: attempt to use poisoned "CONFIG_USER_ONLY"include/hw/semihosting/semihost.h:29:8: error: attempt to use poisoned "CONFIG_USER_ONLY"include/sysemu/accel.h:40:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/sysemu/cpus.h:65:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/sysemu/dma.h:34:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/sysemu/xen.h:27:9: error: attempt to use poisoned "CONFIG_USER_ONLY"That
cpu.cone is definitely dubious given it's in a C file, not a header.thanks
-- PMM
Re: dangers of current NEED_CPU_H, CONFIG_SOFTMMU, CONFIG_USER_ONLY (was: [PATCH v11 7/7] cpu: introduce cpu_accel_instance_init)
Quoted 2 lines · Paolo Bonzini
I will take a look,
CONFIG_USER_ONLYis definitely something that should be poisoned.
Thanks! I started looking at it, but I gave up when I realized how much work it would required. :)
In any case, feel free to reuse the 2 small commits I've just pushed to
https://gitlab.com/ehabkost/qemu/-/commits/work/poison-user-only
Quoted 57 lines
Paolo
Il gio 17 dic 2020, 21:26 Peter Maydell <[email protected]> ha scritto:
Quoted 51 lines
Quoted 3 lines · Peter Maydell
(So in theory we could make
CONFIG_USER_ONLY
a poisoned identifier but that will require some work to adjust places where we currently use it in "safe" ways...)Specifically, putting it in
poison.hturns up these places that would need to be made to do what they're doing in a different way somehow:
../../hw/core/cpu.c:211:14: error: attempt to use poisoned "CONFIG_USER_ONLY"include/disas/disas.h:27:13: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/address-spaces.h:24:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/cpu-common.h:20:14: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/cpu-common.h:6:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/ioport.h:43:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/memory.h:17:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/exec/ramblock.h:22:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/hw/core/cpu.h:1035:8: error: attempt to use poisoned "CONFIG_USER_ONLY"include/hw/core/cpu.h:518:14: error: attempt to use poisoned "CONFIG_USER_ONLY"include/hw/core/cpu.h:602:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/hw/hw.h:4:8: error: attempt to use poisoned "CONFIG_USER_ONLY"include/hw/semihosting/semihost.h:29:8: error: attempt to use poisoned "CONFIG_USER_ONLY"include/sysemu/accel.h:40:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/sysemu/cpus.h:65:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/sysemu/dma.h:34:9: error: attempt to use poisoned "CONFIG_USER_ONLY"include/sysemu/xen.h:27:9: error: attempt to use poisoned "CONFIG_USER_ONLY"That
cpu.cone is definitely dubious given it's in a C file, not a header.thanks
-- PMM
Signature · 1 line
Eduardo
Re: dangers of current NEED_CPU_H, CONFIG_SOFTMMU, CONFIG_USER_ONLY (was: [PATCH v11 7/7] cpu: introduce cpu_accel_instance_init)
In reply to Peter MaydellQuoted 39 lines · Peter Maydell
Quoted 8 lines · Claudio Fontana
Hi,
I would like to highlight the current dangerous state of
NEED_CPU_H/CONFIG_SOFTMMU/CONFIG_USER_ONLY.So our struct TcgCpuOperations in
include/hw/core/cpu.h, which contains after this series:Quoted 16 lines
#ifndef
CONFIG_USER_ONLY
/**
* @do_transaction_failed: Callback for handling failed memory transactions
* (ie bus faults or external aborts; not MMU faults)
*/
void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr,
unsigned size, MMUAccessTypeaccess_type, intmmu_idx, MemTxAttrs attrs, MemTxResult response,uintptr_tretaddr);
/**
* @do_unaligned_access: Callback for unaligned access handling */
void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
MMUAccessTypeaccess_type,
intmmu_idx,uintptr_tretaddr);
#endif /* !CONFIG_USER_ONLY */Yeah, don't try to ifdef out struct fields in common-compiled code...
Quoted 2 lines
Note that
include/hw/core/cpu.halready usesCONFIG_USER_ONLYin other parts of the header file, and we might have hidden problems as a result we (or at least I) don't know about, because code is being compiled in for linux-user which explicitly should not be compiled there.The other
CONFIG_USER_ONLYchecks in that file are only ifdeffing out prototypes for functions that exist only in the softmmu build, or providing do-nothing stubs for functions that are softmmu only. I think they're safe.Quoted 2 lines
There are multiple workarounds / fixes possible for my short term problem, but would it not be a good idea to fix this problem at its root once and for all?
Quoted 8 lines
What's your proposal for fixing things ?
Incidentally, this should not be a problem for
CONFIG_SOFTMMU, because that is listed ininclude/exec/poison.hso trying to use it in a common (not compiled-per-target) file will give you a compile error. (So in theory we could makeCONFIG_USER_ONLYa poisoned identifier but that will require some work to adjust places where we currently use it in "safe" ways...)
The risk of introducing this kind of bug seem to outweigh the benefits of existing safe usage. Do we know how many of these cases we have?
Signature · 1 line
Eduardo
Re: dangers of current NEED_CPU_H, CONFIG_SOFTMMU, CONFIG_USER_ONLY
In reply to Peter MaydellHi Peter,
thanks for your answer,
Quoted 28 lines · Peter Maydell
Quoted 8 lines · Claudio Fontana
Hi,
I would like to highlight the current dangerous state of
NEED_CPU_H/CONFIG_SOFTMMU/CONFIG_USER_ONLY.So our struct TcgCpuOperations in
include/hw/core/cpu.h, which contains after this series:Quoted 16 lines
#ifndef
CONFIG_USER_ONLY
/**
* @do_transaction_failed: Callback for handling failed memory transactions
* (ie bus faults or external aborts; not MMU faults)
*/
void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr,
unsigned size, MMUAccessTypeaccess_type, intmmu_idx, MemTxAttrs attrs, MemTxResult response,uintptr_tretaddr);
/**
* @do_unaligned_access: Callback for unaligned access handling */
void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
MMUAccessTypeaccess_type,
intmmu_idx,uintptr_tretaddr);
#endif /* !CONFIG_USER_ONLY */Yeah, don't try to ifdef out struct fields in common-compiled code...
Quoted 7 lines
Quoted 2 lines
Note that
include/hw/core/cpu.halready usesCONFIG_USER_ONLYin other parts of the header file, and we might have hidden problems as a result we (or at least I) don't know about, because code is being compiled in for linux-user which explicitly should not be compiled there.The other
CONFIG_USER_ONLYchecks in that file are only ifdeffing out prototypes for functions that exist only in the softmmu build, or providing do-nothing stubs for functions that are softmmu only. I think they're safe.
right, in cpu.h the extra prototypes do not cause immediate harm, but they lead to believe someone editing the file that CONFIG_USER_ONLY can be used and is effective in the file; if CONFIG_USER_ONLY is ineffective, why use it?
In the same file, in other places
#ifdef NEED_CPU_H
#ifdef CONFIG_SOFTMMU
is used. Should this pattern be used instead consistently in header files? Is this guaranteed to always do the right thing, from wherever the header file is included?
Also in hw/core/cpu.c we see this:
#if !defined(CONFIG_USER_ONLY) GuestPanicInformation *cpu_get_crash_info(CPUState *cpu)
{
CPUClass *cc = CPU_GET_CLASS(cpu);
GuestPanicInformation *res = NULL;
if (cc->get_crash_info) {
res = cc->get_crash_info(cpu);
}
return res;
}#endif
If !CONFIG_USER_ONLY is always ineffective, why have it there? This code should probably then be in $(top_srcdir)/cpu.c ?
These things may be harmless by themselves, but it takes very little to make a false step, using the existing uses as a reference, as there is no other documentation (I know of).
CONFIG_USER_ONLY is used in a few other places outside of target/, including in other header files, as you noted in a follow up email.
Are all these uses harmless? Not sure how to determine that for sure..
Quoted 5 lines
Quoted 3 lines
There are multiple workarounds / fixes possible for my short term problem, but would it not be a good idea to fix this problem at its root once and for all?
What's your proposal for fixing things ?
I don't think I have the full picture yet, so I think the optimal solution can only be figured out together;
I will try to flail in the dark hoping to hit on something that sparks an idea.
- do we need both CONFIG_SOFTMMU and CONFIG_USER_ONLY? (I always wondered about the "ONLY" part of it, why not just CONFIG_USER?) Based on previous comments from Richard we might need both in the future, but I fail to detect which places are meaningful for the one or the other.
- Is the NEED_CPU_H + CONFIG_SOFTMMU check always the right thing to do? Is it always right in header files? ...
- is it possible to define very clearly where in the codebase they should be used? As an ignorant example from my side: only use CONFIG_USER_ONLY inside of target/,
Making the rule "don't use this for common_ss" is very difficult to stick to in practice,
with header files that end up being used from multiple sources, some in common_ss and some not, and it's so hidden from the day to day activities, one need to explicitly check.
Instead if it's something obvious like: only in this subtree, then it is at least realistic to try to stick to it.
- is it possible to check the [in]correct use of CONFIG_USER_ONLY and CONFIG_SOFTMMU during compilation or with a script in scripts/ ? I think you answered that already, adding it to "poison". Any downside to that?
Does it still make sense to restrict the uses more, in favor of clarity?
- once we figure out the solution, I would try to document the result of the whole experience clearly, in doc/devel/ for example?
Quoted 10 lines
Incidentally, this should not be a problem for
CONFIG_SOFTMMU, because that is listed ininclude/exec/poison.hso trying to use it in a common (not compiled-per-target) file will give you a compile error. (So in theory we could makeCONFIG_USER_ONLYa poisoned identifier but that will require some work to adjust places where we currently use it in "safe" ways...)thanks
-- PMM
Thanks!
Claudio
Re: dangers of current NEED_CPU_H, CONFIG_SOFTMMU, CONFIG_USER_ONLY
In reply to Peter MaydellQuoted 26 lines · Peter Maydell
Quoted 8 lines · Claudio Fontana
Hi,
I would like to highlight the current dangerous state of
NEED_CPU_H/CONFIG_SOFTMMU/CONFIG_USER_ONLY.So our struct TcgCpuOperations in
include/hw/core/cpu.h, which contains after this series:Quoted 16 lines
#ifndef
CONFIG_USER_ONLY
/**
* @do_transaction_failed: Callback for handling failed memory transactions
* (ie bus faults or external aborts; not MMU faults)
*/
void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr,
unsigned size, MMUAccessTypeaccess_type, intmmu_idx, MemTxAttrs attrs, MemTxResult response,uintptr_tretaddr);
/**
* @do_unaligned_access: Callback for unaligned access handling */
void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
MMUAccessTypeaccess_type,
intmmu_idx,uintptr_tretaddr);
#endif /* !CONFIG_USER_ONLY */
Quoted 1 line
Yeah, don't try to ifdef out struct fields in common-compiled code...
or should I? Using
#ifdef NEED_CPU_H
#ifdef CONFIG_SOFTMMU
seems to do what I expect. Is it wrong?
Thanks,
Claudio
Quoted 24 lines
Quoted 3 lines
Note that
include/hw/core/cpu.halready usesCONFIG_USER_ONLYin other parts of the header file, and we might have hidden problems as a result we (or at least I) don't know about, because code is being compiled in for linux-user which explicitly should not be compiled there.The other
CONFIG_USER_ONLYchecks in that file are only ifdeffing out prototypes for functions that exist only in the softmmu build, or providing do-nothing stubs for functions that are softmmu only. I think they're safe.Quoted 2 lines
There are multiple workarounds / fixes possible for my short term problem, but would it not be a good idea to fix this problem at its root once and for all?
What's your proposal for fixing things ?
Incidentally, this should not be a problem for
CONFIG_SOFTMMU, because that is listed ininclude/exec/poison.hso trying to use it in a common (not compiled-per-target) file will give you a compile error. (So in theory we could makeCONFIG_USER_ONLYa poisoned identifier but that will require some work to adjust places where we currently use it in "safe" ways...)thanks
-- PMM
Re: dangers of current NEED_CPU_H, CONFIG_SOFTMMU, CONFIG_USER_ONLY
Quoted 11 lines · Claudio Fontana
Quoted 2 lines · Peter Maydell
On Thu, 17 Dec 2020 at 19:46, Claudio Fontana <[email protected]> wrote:
Yeah, don't try to ifdef out struct fields in common-compiled code...or should I? Using
#ifdef
NEED_CPU_H
#ifdefCONFIG_SOFTMMUseems to do what I expect. Is it wrong?
I think that gives you two versions of the struct:
- one seen by compiled-once files and by compiled-per-target softmmu files
- one seen by compiled-per-target user-only files
Since the user-only target executables link both compiled-per-target and compiled-once files I think they end up with different C files thinking the same struct has a different layout/size which seems like it's going to cause problems.
thanks
-- PMM
Re: dangers of current NEED_CPU_H, CONFIG_SOFTMMU, CONFIG_USER_ONLY
Quoted 17 lines · Peter Maydell
Quoted 11 lines · Claudio Fontana
Quoted 2 lines · Peter Maydell
On Thu, 17 Dec 2020 at 19:46, Claudio Fontana <[email protected]> wrote:
Yeah, don't try to ifdef out struct fields in common-compiled code...or should I? Using
#ifdef
NEED_CPU_H
#ifdefCONFIG_SOFTMMUseems to do what I expect. Is it wrong?
I think that gives you two versions of the struct:
- one seen by compiled-once files and by compiled-per-target softmmu files
- one seen by compiled-per-target user-only files
Quoted 8 lines
Since the user-only target executables link both compiled-per-target and compiled-once files I think they end up with different C files thinking the same struct has a different layout/size which seems like it's going to cause problems.
thanks
-- PMM
It doesn't with
#ifdef NEED_CPU_H
#ifdef CONFIG_SOFTMMU
just double checked the pointers from both files compiled per target and "common"; also all tests are ok.
It immediately breaks if I replace those two defines with #ifndef CONFIG_USER_ONLY and recompile.
I thought it was by design, but I guess this is just a "lucky" accident?
Ciao,
Claudio
Re: dangers of current NEED_CPU_H, CONFIG_SOFTMMU, CONFIG_USER_ONLY
Quoted 29 lines · Claudio Fontana
Quoted 17 lines · Peter Maydell
Quoted 11 lines · Claudio Fontana
Quoted 2 lines · Peter Maydell
On Thu, 17 Dec 2020 at 19:46, Claudio Fontana <[email protected]> wrote:
Yeah, don't try to ifdef out struct fields in common-compiled code...or should I? Using
#ifdef
NEED_CPU_H
#ifdefCONFIG_SOFTMMUseems to do what I expect. Is it wrong?
I think that gives you two versions of the struct:
- one seen by compiled-once files and by compiled-per-target softmmu files
- one seen by compiled-per-target user-only filesQuoted 8 lines
Since the user-only target executables link both compiled-per-target and compiled-once files I think they end up with different C files thinking the same struct has a different layout/size which seems like it's going to cause problems.
thanks
-- PMMIt doesn't with
Quoted 8 lines
#ifdef
NEED_CPU_H
#ifdefCONFIG_SOFTMMUjust double checked the pointers from both files compiled per target and "common"; also all tests are ok.
It immediately breaks if I replace those two defines with #ifndef
CONFIG_USER_ONLYand recompile.I thought it was by design, but I guess this is just a "lucky" accident?
By lucky accident I mean that CONFIG_SOFTMMU is a check in the positive instead of the #if !defined(CONFIG_USER_ONLY), so it ends up working..
Quoted 5 lines
Ciao,
Claudio