accel: Add new @dirty field on HVF/NVMM/WHPX
cover accel: Add new @dirty field on HVF/NVMM/WHPX
We want CPUState to only contain fields used by common code. Start using a specific @dirty field for HVF/NVMM/WHPX (TCG then KVM will follow).
Philippe Mathieu-Daudé (3):
accel/whpx: Use accel-specific per-vcpu @dirty field accel/nvmm: Use accel-specific per-vcpu @dirty field accel/hvf: Use accel-specific per-vcpu @dirty field
include/hw/core/cpu.h | 3 +-- include/sysemu/hvf_int.h | 1 + accel/hvf/hvf-accel-ops.c | 10 +++++----- target/arm/hvf/hvf.c | 4 ++-- target/i386/hvf/hvf.c | 4 ++-- target/i386/hvf/x86hvf.c | 2 +- target/i386/nvmm/nvmm-all.c | 21 +++++++++++---------- target/i386/whpx/whpx-all.c | 23 ++++++++++++----------- 8 files changed, 35 insertions(+), 33 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/3 accel/whpx: Use accel-specific per-vcpu @dirty field
WHPX has a specific use of the CPUState::vcpu_dirty field (CPUState::vcpu_dirty is not used by common code). To make this field accel-specific, add and use a new @dirty variable in the AccelCPUState structure.
--- target/i386/whpx/whpx-all.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
target/i386/whpx/whpx-all.c +12 -11
@@ -237,6 +237,7 @@ struct AccelCPUState {uint64_t tpr;uint64_t apic_base;bool interruption_pending; +bool dirty;/* Must be the last field as it may have a tail */ WHV_RUN_VP_EXIT_CONTEXT exit_ctx;
@@ -839,7 +840,7 @@ static HRESULT CALLBACK whpx_emu_setreg_callback(* The emulator just successfully wrote the register state. We clear the * dirty state so we avoid the double write on resume of the VP. */ - cpu->vcpu_dirty = false; + cpu->accel->dirty = false;return hr; }
@@ -1394,7 +1395,7 @@ static int whpx_last_vcpu_stopping(CPUState *cpu)/* Returns the address of the next instruction that is about to be executed. */ static vaddr whpx_vcpu_get_pc (CPUState *cpu,bool exit_context_valid) { -if (cpu->vcpu_dirty) { +if (cpu->accel->dirty) {/* The CPU registers have been modified by other parts of QEMU. */ return cpu_env (cpu)->eip; }else if (exit_context_valid) {
@@ -1713,9 +1714,9 @@ static int whpx_vcpu_run(CPUState *cpu) } do { - if (cpu->vcpu_dirty) { + if (cpu->accel->dirty) { whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE); - cpu->vcpu_dirty = false; + cpu->accel->dirty = false; } if (exclusive_step_mode == WHPX_STEP_NONE) {
@@ -2063,9 +2064,9 @@ static int whpx_vcpu_run(CPUState *cpu)static void do_whpx_cpu_synchronize_state (CPUState *cpu,run_on_cpu_data arg) { -if (!cpu->vcpu_dirty) { +if (!cpu->accel->dirty) {whpx_get_registers (cpu); - cpu->vcpu_dirty = true; + cpu->accel->dirty = true; } }
@@ -2073,20 +2074,20 @@ static void do_whpx_cpu_synchronize_post_reset(CPUState *cpu, run_on_cpu_data arg) {whpx_set_registers (cpu,WHPX_SET_RESET_STATE ); - cpu->vcpu_dirty = false; + cpu->accel->dirty = false; }static void do_whpx_cpu_synchronize_post_init (CPUState *cpu,run_on_cpu_data arg) {whpx_set_registers (cpu,WHPX_SET_FULL_STATE ); - cpu->vcpu_dirty = false; + cpu->accel->dirty = false; }static void do_whpx_cpu_synchronize_pre_loadvm (CPUState *cpu,run_on_cpu_data arg) { - cpu->vcpu_dirty = true; + cpu->accel->dirty = true; }/*
@@ -2095,7 +2096,7 @@ static void do_whpx_cpu_synchronize_pre_loadvm(CPUState *cpu,void whpx_cpu_synchronize_state (CPUState *cpu) { -if (!cpu->vcpu_dirty) { +if (!cpu->accel->dirty) {run_on_cpu (cpu, do_whpx_cpu_synchronize_state,RUN_ON_CPU_NULL ); } }
@@ -2235,7 +2236,7 @@ int whpx_init_vcpu(CPUState *cpu) } vcpu->interruptable = true; - cpu->vcpu_dirty = true; + cpu->accel->dirty = true; cpu->accel = vcpu; max_vcpu_index =max (max_vcpu_index, cpu->cpu_index);qemu_add_vm_change_state_handler (whpx_cpu_update_state, env);
Signature · 1 line
2.41.0
PATCH 2/3 accel/nvmm: Use accel-specific per-vcpu @dirty field
In reply to Philippe Mathieu-DaudéNVMM has a specific use of the CPUState::vcpu_dirty field (CPUState::vcpu_dirty is not used by common code). To make this field accel-specific, add and use a new @dirty variable in the AccelCPUState structure.
--- target/i386/nvmm/nvmm-all.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
target/i386/nvmm/nvmm-all.c +11 -10
@@ -30,6 +30,7 @@ struct AccelCPUState {struct nvmm_vcpu vcpu;uint8_t tpr;bool stop; +bool dirty;/* Window-exiting for INTs/NMIs. */ bool int_window_exit;
@@ -507,7 +508,7 @@ nvmm_io_callback(struct nvmm_io *io) }/* Needed, otherwise infinite loop. */ - current_cpu->vcpu_dirty = false; + current_cpu->accel->dirty = false; } static void
@@ -516,7 +517,7 @@ nvmm_mem_callback(struct nvmm_mem *mem)cpu_physical_memory_rw (mem->gpa, mem->data, mem->size, mem->write);/* Needed, otherwise infinite loop. */ - current_cpu->vcpu_dirty = false; + current_cpu->accel->dirty = false; }static struct nvmm_assist_callbacks nvmm_callbacks = {
@@ -726,9 +727,9 @@ nvmm_vcpu_loop(CPUState *cpu)* Inner VCPU loop. */ do { - if (cpu->vcpu_dirty) { + if (cpu->accel->dirty) { nvmm_set_registers(cpu); - cpu->vcpu_dirty = false; + cpu->accel->dirty = false; } if (qcpu->stop) {
@@ -826,32 +827,32 @@ static void do_nvmm_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg) {nvmm_get_registers (cpu); - cpu->vcpu_dirty = true; + cpu->accel->dirty = true; }static void do_nvmm_cpu_synchronize_post_reset (CPUState *cpu,run_on_cpu_data arg) {nvmm_set_registers (cpu); - cpu->vcpu_dirty = false; + cpu->accel->dirty = false; }static void do_nvmm_cpu_synchronize_post_init (CPUState *cpu,run_on_cpu_data arg) {nvmm_set_registers (cpu); - cpu->vcpu_dirty = false; + cpu->accel->dirty = false; }static void do_nvmm_cpu_synchronize_pre_loadvm (CPUState *cpu,run_on_cpu_data arg) { - cpu->vcpu_dirty = true; + cpu->accel->dirty = true; }void nvmm_cpu_synchronize_state (CPUState *cpu) { -if (!cpu->vcpu_dirty) { +if (!cpu->accel->dirty) {run_on_cpu (cpu, do_nvmm_cpu_synchronize_state,RUN_ON_CPU_NULL ); } }
@@ -981,7 +982,7 @@ nvmm_init_vcpu(CPUState *cpu) } } - cpu->vcpu_dirty = true; + cpu->accel->dirty = true; cpu->accel = qcpu;return 0 ;
Signature · 1 line
2.41.0
PATCH 3/3 accel/hvf: Use accel-specific per-vcpu @dirty field
In reply to Philippe Mathieu-DaudéHVF has a specific use of the CPUState::vcpu_dirty field (CPUState::vcpu_dirty is not used by common code). To make this field accel-specific, add and use a new @dirty variable in the AccelCPUState structure.
--- include/hw/core/cpu.h | 3 +-- include/sysemu/hvf_int.h | 1 + accel/hvf/hvf-accel-ops.c | 10 +++++----- target/arm/hvf/hvf.c | 4 ++-- target/i386/hvf/hvf.c | 4 ++-- target/i386/hvf/x86hvf.c | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-)
include/hw/core/cpu.h +1 -2
@@ -505,6 +505,7 @@ struct CPUState {uint32_t kvm_fetch_index;uint64_t dirty_pages;int kvm_vcpu_stats_fd; +bool vcpu_dirty;/* Use by accel-block: CPU is executing an ioctl() */ QemuLockCnt in_ioctl_lock;
@@ -526,8 +527,6 @@ struct CPUState {int32_t exception_index;AccelCPUState *accel; -/* shared by kvm and hvf */ -bool vcpu_dirty;/* Used to keep track of an outstanding cpu throttle thread for migration * autoconverge
include/sysemu/hvf_int.h +1 -0
@@ -55,6 +55,7 @@ struct AccelCPUState {bool vtimer_masked;sigset_t unblock_ipi_mask;bool guest_debug_enabled; +bool dirty; };void assert_hvf_ok (hv_return_t ret);
accel/hvf/hvf-accel-ops.c +5 -5
@@ -204,15 +204,15 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)static void do_hvf_cpu_synchronize_state (CPUState *cpu,run_on_cpu_data arg) { -if (!cpu->vcpu_dirty) { +if (!cpu->accel->dirty) {hvf_get_registers (cpu); - cpu->vcpu_dirty = true; + cpu->accel->dirty = true; } }static void hvf_cpu_synchronize_state (CPUState *cpu) { -if (!cpu->vcpu_dirty) { +if (!cpu->accel->dirty) {run_on_cpu (cpu, do_hvf_cpu_synchronize_state,RUN_ON_CPU_NULL ); } }
@@ -221,7 +221,7 @@ static void do_hvf_cpu_synchronize_set_dirty(CPUState *cpu, run_on_cpu_data arg) {/* QEMU state is the reference, push it to HVF now and on next entry */ - cpu->vcpu_dirty = true; + cpu->accel->dirty = true; }static void hvf_cpu_synchronize_post_reset (CPUState *cpu)
@@ -402,7 +402,7 @@ static int hvf_init_vcpu(CPUState *cpu)#else r =hv_vcpu_create ((hv_vcpuid_t *)&cpu->accel->fd,HV_VCPU_DEFAULT );#endif - cpu->vcpu_dirty =1 ; + cpu->accel->dirty = true;assert_hvf_ok (r); cpu->accel->guest_debug_enabled = false;
target/arm/hvf/hvf.c +2 -2
@@ -806,9 +806,9 @@ int hvf_put_registers(CPUState *cpu)static void flush_cpu_state (CPUState *cpu) { -if (cpu->vcpu_dirty) { +if (cpu->accel->dirty) {hvf_put_registers (cpu); - cpu->vcpu_dirty = false; + cpu->accel->dirty = false; } }
target/i386/hvf/hvf.c +2 -2
@@ -419,9 +419,9 @@ int hvf_vcpu_exec(CPUState *cpu) } do { - if (cpu->vcpu_dirty) { + if (cpu->accel->dirty) { hvf_put_registers(cpu); - cpu->vcpu_dirty = false; + cpu->accel->dirty = false; } if (hvf_inject_interrupts(cpu)) {
target/i386/hvf/x86hvf.c +1 -1
@@ -427,7 +427,7 @@ int hvf_process_events(CPUState *cs)X86CPU *cpu =X86_CPU (cs);CPUX86State *env = &cpu->env; -if (!cs->vcpu_dirty) { +if (!cs->accel->dirty) {/* light weight sync for CPU_INTERRUPT_HARD and IF_MASK */ env->eflags =rreg (cs->accel->fd,HV_X86_RFLAGS ); }
Signature · 1 line
2.41.0
Quoted 4 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (3):
accel/whpx: Use accel-specific per-vcpu @dirty field accel/nvmm: Use accel-specific per-vcpu @dirty field accel/hvf: Use accel-specific per-vcpu @dirty field
r~
Quoted 8 lines · Philippe Mathieu-Daudé
We want CPUState to only contain fields used by common code. Start using a specific @dirty field for HVF/NVMM/WHPX (TCG then KVM will follow).
Philippe Mathieu-Daudé (3):
accel/whpx: Use accel-specific per-vcpu @dirty field accel/nvmm: Use accel-specific per-vcpu @dirty field accel/hvf: Use accel-specific per-vcpu @dirty field
Thanks, queued.