accel/tcg: Move @plugin_mem_cbs from CPUState to CPUNegativeOffsetState

@plugin_mem_cbs is accessed by tcg generated code, move it
to CPUNegativeOffsetState.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20240429213050.55177-4-philmd@linaro.org>
This commit is contained in:
Philippe Mathieu-Daudé 2024-01-09 23:38:04 +01:00
parent fc44d592db
commit 80f034c5b2
5 changed files with 13 additions and 12 deletions

View File

@ -35,7 +35,7 @@ static inline bool cpu_in_serial_context(CPUState *cs)
static inline bool cpu_plugin_mem_cbs_enabled(const CPUState *cpu) static inline bool cpu_plugin_mem_cbs_enabled(const CPUState *cpu)
{ {
#ifdef CONFIG_PLUGIN #ifdef CONFIG_PLUGIN
return !!cpu->plugin_mem_cbs; return !!cpu->neg.plugin_mem_cbs;
#else #else
return false; return false;
#endif #endif

View File

@ -55,7 +55,7 @@ static void gen_enable_mem_helper(struct qemu_plugin_tb *ptb,
* Tracking memory accesses performed from helpers requires extra work. * Tracking memory accesses performed from helpers requires extra work.
* If an instruction is emulated with helpers, we do two things: * If an instruction is emulated with helpers, we do two things:
* (1) copy the CB descriptors, and keep track of it so that they can be * (1) copy the CB descriptors, and keep track of it so that they can be
* freed later on, and (2) point CPUState.plugin_mem_cbs to the * freed later on, and (2) point CPUState.neg.plugin_mem_cbs to the
* descriptors, so that we can read them at run-time * descriptors, so that we can read them at run-time
* (i.e. when the helper executes). * (i.e. when the helper executes).
* This run-time access is performed from qemu_plugin_vcpu_mem_cb. * This run-time access is performed from qemu_plugin_vcpu_mem_cb.
@ -90,14 +90,14 @@ static void gen_enable_mem_helper(struct qemu_plugin_tb *ptb,
qemu_plugin_add_dyn_cb_arr(arr); qemu_plugin_add_dyn_cb_arr(arr);
tcg_gen_st_ptr(tcg_constant_ptr((intptr_t)arr), tcg_env, tcg_gen_st_ptr(tcg_constant_ptr((intptr_t)arr), tcg_env,
offsetof(CPUState, plugin_mem_cbs) - offsetof(CPUState, neg.plugin_mem_cbs) -
offsetof(ArchCPU, env)); offsetof(ArchCPU, env));
} }
static void gen_disable_mem_helper(void) static void gen_disable_mem_helper(void)
{ {
tcg_gen_st_ptr(tcg_constant_ptr(0), tcg_env, tcg_gen_st_ptr(tcg_constant_ptr(0), tcg_env,
offsetof(CPUState, plugin_mem_cbs) - offsetof(CPUState, neg.plugin_mem_cbs) -
offsetof(ArchCPU, env)); offsetof(ArchCPU, env));
} }

View File

@ -342,9 +342,16 @@ typedef union IcountDecr {
* CPUNegativeOffsetState: Elements of CPUState most efficiently accessed * CPUNegativeOffsetState: Elements of CPUState most efficiently accessed
* from CPUArchState, via small negative offsets. * from CPUArchState, via small negative offsets.
* @can_do_io: True if memory-mapped IO is allowed. * @can_do_io: True if memory-mapped IO is allowed.
* @plugin_mem_cbs: active plugin memory callbacks
*/ */
typedef struct CPUNegativeOffsetState { typedef struct CPUNegativeOffsetState {
CPUTLB tlb; CPUTLB tlb;
#ifdef CONFIG_PLUGIN
/*
* The callback pointer are accessed via TCG (see gen_empty_mem_helper).
*/
GArray *plugin_mem_cbs;
#endif
IcountDecr icount_decr; IcountDecr icount_decr;
bool can_do_io; bool can_do_io;
} CPUNegativeOffsetState; } CPUNegativeOffsetState;
@ -416,7 +423,6 @@ struct qemu_work_item;
* @kvm_fd: vCPU file descriptor for KVM. * @kvm_fd: vCPU file descriptor for KVM.
* @work_mutex: Lock to prevent multiple access to @work_list. * @work_mutex: Lock to prevent multiple access to @work_list.
* @work_list: List of pending asynchronous work. * @work_list: List of pending asynchronous work.
* @plugin_mem_cbs: active plugin memory callbacks
* @plugin_state: per-CPU plugin state * @plugin_state: per-CPU plugin state
* @ignore_memory_transaction_failures: Cached copy of the MachineState * @ignore_memory_transaction_failures: Cached copy of the MachineState
* flag of the same name: allows the board to suppress calling of the * flag of the same name: allows the board to suppress calling of the
@ -511,11 +517,6 @@ struct CPUState {
QemuLockCnt in_ioctl_lock; QemuLockCnt in_ioctl_lock;
#ifdef CONFIG_PLUGIN #ifdef CONFIG_PLUGIN
/*
* The callback pointer stays in the main CPUState as it is
* accessed via TCG (see gen_empty_mem_helper).
*/
GArray *plugin_mem_cbs;
CPUPluginState *plugin_state; CPUPluginState *plugin_state;
#endif #endif

View File

@ -180,7 +180,7 @@ void qemu_plugin_add_dyn_cb_arr(GArray *arr);
static inline void qemu_plugin_disable_mem_helpers(CPUState *cpu) static inline void qemu_plugin_disable_mem_helpers(CPUState *cpu)
{ {
cpu->plugin_mem_cbs = NULL; cpu->neg.plugin_mem_cbs = NULL;
} }
/** /**

View File

@ -533,7 +533,7 @@ void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index)
void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr,
MemOpIdx oi, enum qemu_plugin_mem_rw rw) MemOpIdx oi, enum qemu_plugin_mem_rw rw)
{ {
GArray *arr = cpu->plugin_mem_cbs; GArray *arr = cpu->neg.plugin_mem_cbs;
size_t i; size_t i;
if (arr == NULL) { if (arr == NULL) {