The %ignore_memory_transaction_failures flag is meant for legacy machines, and is defined once per machine, then applied to all vCPUs such machine creates, to be eventually only used by the TCG soft MMU layer. We can decouple it of the vCPU layer by making it a global, setting it once when the machine is initialized, allowing to remove machine code in the common vCPU Realize() handler.
Signed-off-by: Philippe Mathieu-Daudé <[email protected]> --- Even better is to make it an accelerator property. --- include/hw/core/cpu.h | 2 -- include/system/tcg.h | 2 ++ accel/stubs/tcg-stub.c | 1 + accel/tcg/cputlb.c | 9 +++++++-- hw/core/cpu-common.c | 15 --------------- hw/core/machine.c | 5 +++++ 6 files changed, 15 insertions(+), 19 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 59d601465b4..72666189774 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -575,8 +575,6 @@ struct CPUState { */ int64_t throttle_us_per_full; - bool ignore_memory_transaction_failures; - /* Used for user-only emulation of prctl(PR_SET_UNALIGN). */ bool prctl_unalign_sigbus; diff --git a/include/system/tcg.h b/include/system/tcg.h index 7622dcea302..0c5af81b511 100644 --- a/include/system/tcg.h +++ b/include/system/tcg.h @@ -25,4 +25,6 @@ extern bool tcg_allowed; */ bool qemu_tcg_mttcg_enabled(void); +extern bool tcg_ignore_memory_transaction_failures; + #endif diff --git a/accel/stubs/tcg-stub.c b/accel/stubs/tcg-stub.c index 77055e39644..855e5d43171 100644 --- a/accel/stubs/tcg-stub.c +++ b/accel/stubs/tcg-stub.c @@ -11,6 +11,7 @@ */ #include "qemu/osdep.h" +#include "system/tcg.h" #include "exec/cpu-common.h" G_NORETURN void cpu_loop_exit(CPUState *cpu) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index d6115bbb0a4..31c8351231a 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -26,6 +26,7 @@ #include "exec/page-protection.h" #include "system/memory.h" #include "system/physmem.h" +#include "system/tcg.h" #include "accel/tcg/cpu-ldst-common.h" #include "accel/tcg/cpu-mmu-index.h" #include "exec/cputlb.h" @@ -90,6 +91,8 @@ */ QEMU_BUILD_BUG_ON(sizeof(vaddr) > sizeof(run_on_cpu_data)); +bool tcg_ignore_memory_transaction_failures; + #define ALL_MMUIDX_BITS ((1 << NB_MMU_MODES) - 1) static inline size_t tlb_n_entries(CPUTLBDescFast *fast) @@ -1291,8 +1294,10 @@ static void io_failed(CPUState *cpu, CPUTLBEntryFull *full, vaddr addr, unsigned size, MMUAccessType access_type, int mmu_idx, MemTxResult response, uintptr_t retaddr) { - if (!cpu->ignore_memory_transaction_failures - && cpu->cc->tcg_ops->do_transaction_failed) { + if (unlikely(tcg_ignore_memory_transaction_failures)) { + return; + } + if (cpu->cc->tcg_ops->do_transaction_failed) { hwaddr physaddr = full->phys_addr | (addr & ~TARGET_PAGE_MASK); cpu->cc->tcg_ops->do_transaction_failed(cpu, physaddr, addr, size, diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index e314f916f84..b74a39c96ac 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -32,7 +32,6 @@ #include "exec/log.h" #include "exec/gdbstub.h" #include "system/tcg.h" -#include "hw/core/boards.h" #include "hw/core/qdev-properties.h" #include "trace.h" #ifdef CONFIG_PLUGIN @@ -247,20 +246,6 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp) static void cpu_common_realizefn(DeviceState *dev, Error **errp) { CPUState *cpu = CPU(dev); - Object *machine = qdev_get_machine(); - - /* 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. - */ - if (object_dynamic_cast(machine, TYPE_MACHINE)) { - MachineClass *mc = MACHINE_GET_CLASS(machine); - - if (mc) { - cpu->ignore_memory_transaction_failures = - mc->ignore_memory_transaction_failures; - } - } if (dev->hotplugged) { cpu_synchronize_post_init(cpu); diff --git a/hw/core/machine.c b/hw/core/machine.c index 4d8b15d99e9..bc388dd8442 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -29,6 +29,7 @@ #include "system/runstate.h" #include "system/xen.h" #include "system/qtest.h" +#include "system/tcg.h" #include "hw/pci/pci_bridge.h" #include "hw/mem/nvdimm.h" #include "migration/global_state.h" @@ -1213,6 +1214,10 @@ static void machine_class_base_init(ObjectClass *oc, const void *data) strlen(cname) - strlen(TYPE_MACHINE_SUFFIX)); mc->compat_props = g_ptr_array_new(); } + if (tcg_enabled()) { + tcg_ignore_memory_transaction_failures + = mc->ignore_memory_transaction_failures; + } } static void machine_initfn(Object *obj) -- 2.53.0
