accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF)
cover accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF)
This series is part of the single binary effort.
All accelerator will share their per-vCPU context in an opaque 'accel' pointer within the CPUState.
First handle HAX/NVMM/WHPX/HVF. KVM and TCG will follow as two different (bigger) follow-up series.
Philippe Mathieu-Daudé (14):
accel: Document generic accelerator headers
accel: Remove unused hThread variable on TCG/WHPX
accel: Fix a leak on Windows HAX
accel: Destroy HAX vCPU threads once done
accel: Rename 'hax_vcpu' as 'accel' in CPUState
accel: Use a typedef for struct hax_vcpu_state
accel: Rename struct hax_vcpu_state -> struct AccelvCPUState
accel: Move HAX hThread to accelerator context
accel: Allocate NVMM vCPU using g_try_FOO()
accel: Rename NVMM struct qemu_vcpu -> struct AccelvCPUState
accel: Inline NVMM get_qemu_vcpu()
accel: Rename WHPX struct whpx_vcpu -> struct AccelvCPUState
accel: Inline WHPX get_whpx_vcpu()
accel: Rename HVF struct hvf_vcpu_state -> struct AccelvCPUState
include/hw/core/cpu.h | 11 ++--- include/sysemu/hax.h | 2 + include/sysemu/hvf_int.h | 2 +- include/sysemu/kvm.h | 2 + include/sysemu/nvmm.h | 2 + include/sysemu/tcg.h | 2 + include/sysemu/whpx.h | 2 + include/sysemu/xen.h | 2 + target/i386/hax/hax-i386.h | 14 ++++--- accel/hvf/hvf-accel-ops.c | 16 +++---- accel/tcg/tcg-accel-ops-mttcg.c | 4 -- accel/tcg/tcg-accel-ops-rr.c | 3 -- target/arm/hvf/hvf.c | 70 +++++++++++++++---------------- target/i386/hax/hax-accel-ops.c | 5 ++- target/i386/hax/hax-all.c | 26 +++++++----- target/i386/hax/hax-posix.c | 4 +- target/i386/hax/hax-windows.c | 6 +-- target/i386/nvmm/nvmm-all.c | 38 +++++++---------- target/i386/whpx/whpx-accel-ops.c | 3 -- target/i386/whpx/whpx-all.c | 39 +++++++---------- 20 files changed, 123 insertions(+), 130 deletions(-)
Signature · 1 line
2.38.1
PATCH 1/14 accel: Document generic accelerator headers
These headers are meant to be include by any file to check the availability of accelerators, thus are not accelerator specific.
--- include/sysemu/hax.h | 2 ++ include/sysemu/kvm.h | 2 ++ include/sysemu/nvmm.h | 2 ++ include/sysemu/tcg.h | 2 ++ include/sysemu/whpx.h | 2 ++ include/sysemu/xen.h | 2 ++ 6 files changed, 12 insertions(+)
include/sysemu/hax.h +2 -0
@@ -19,6 +19,8 @@* */ +/* header to be included in non-HAX-specific code */ +#ifndef QEMU_HAX_H #define QEMU_HAX_H
include/sysemu/kvm.h +2 -0
@@ -11,6 +11,8 @@* */ +/* header to be included in non-KVM-specific code */ +#ifndef QEMU_KVM_H #define QEMU_KVM_H
include/sysemu/nvmm.h +2 -0
@@ -7,6 +7,8 @@* See the COPYING file in the top-level directory. */ +/* header to be included in non-NVMM-specific code */ +#ifndef QEMU_NVMM_H #define QEMU_NVMM_H
include/sysemu/tcg.h +2 -0
@@ -5,6 +5,8 @@* See the COPYING file in the top-level directory. */ +/* header to be included in non-TCG-specific code */ +#ifndef SYSEMU_TCG_H #define SYSEMU_TCG_H
include/sysemu/whpx.h +2 -0
@@ -10,6 +10,8 @@* */ +/* header to be included in non-WHPX-specific code */ +#ifndef QEMU_WHPX_H #define QEMU_WHPX_H
include/sysemu/xen.h +2 -0
@@ -5,6 +5,8 @@* See the COPYING file in the top-level directory. */ +/* header to be included in non-Xen-specific code */ +#ifndef SYSEMU_XEN_H #define SYSEMU_XEN_H
Signature · 1 line
2.38.1
Re: [PATCH 01/14] accel: Document generic accelerator headers
Quoted 5 lines · Philippe Mathieu-Daudé
These headers are meant to be include by any file to check the availability of accelerators, thus are not accelerator specific.
Signed-off-by Philippe Mathieu-Daudé<[email protected]>
Quoted 8 lines
--- include/sysemu/hax.h | 2 ++ include/sysemu/kvm.h | 2 ++ include/sysemu/nvmm.h | 2 ++ include/sysemu/tcg.h | 2 ++ include/sysemu/whpx.h | 2 ++ include/sysemu/xen.h | 2 ++ 6 files changed, 12 insertions(+)
r~
PATCH 2/14 accel: Remove unused hThread variable on TCG/WHPX
In reply to Philippe Mathieu-DaudéOn Windows hosts, cpu->hThread is assigned but never accessed:
remove it.
--- accel/tcg/tcg-accel-ops-mttcg.c | 4 ---- accel/tcg/tcg-accel-ops-rr.c | 3 --- target/i386/whpx/whpx-accel-ops.c | 3 --- 3 files changed, 10 deletions(-)
accel/tcg/tcg-accel-ops-mttcg.c +0 -4
@@ -152,8 +152,4 @@ void mttcg_start_vcpu_thread(CPUState *cpu)qemu_thread_create (cpu->thread, thread_name, mttcg_cpu_thread_fn, cpu,QEMU_THREAD_JOINABLE ); - -#ifdef _WIN32 - cpu->hThread =qemu_thread_get_handle (cpu->thread); -#endif }
accel/tcg/tcg-accel-ops-rr.c +0 -3
@@ -291,9 +291,6 @@ void rr_start_vcpu_thread(CPUState *cpu) single_tcg_halt_cond = cpu->halt_cond; single_tcg_cpu_thread = cpu->thread; -#ifdef _WIN32 - cpu->hThread =qemu_thread_get_handle (cpu->thread); -#endif }else {/* we share the thread */ cpu->thread = single_tcg_cpu_thread;
target/i386/whpx/whpx-accel-ops.c +0 -3
@@ -71,9 +71,6 @@ static void whpx_start_vcpu_thread(CPUState *cpu) cpu->cpu_index);qemu_thread_create (cpu->thread, thread_name, whpx_cpu_thread_fn, cpu,QEMU_THREAD_JOINABLE ); -#ifdef _WIN32 - cpu->hThread =qemu_thread_get_handle (cpu->thread); -#endif }static void whpx_kick_vcpu_thread (CPUState *cpu)
Signature · 1 line
2.38.1
Re: [PATCH 02/14] accel: Remove unused hThread variable on TCG/WHPX
Quoted 9 lines · Philippe Mathieu-Daudé
On Windows hosts,
cpu->hThreadis assigned but never accessed:
remove it.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- accel/tcg/tcg-accel-ops-mttcg.c | 4 ---- accel/tcg/tcg-accel-ops-rr.c | 3 --- target/i386/whpx/whpx-accel-ops.c | 3 --- 3 files changed, 10 deletions(-)
r~
PATCH 3/14 accel: Fix a leak on Windows HAX
In reply to Philippe Mathieu-DaudéhThread is only used on the error path in hax_kick_vcpu_thread().
--- target/i386/hax/hax-all.c | 3 +++ 1 file changed, 3 insertions(+)
target/i386/hax/hax-all.c +3 -0
@@ -205,6 +205,9 @@ int hax_vcpu_destroy(CPUState *cpu)*/ hax_close_fd (vcpu->fd); hax_global.vm->vcpus[vcpu->vcpu_id] =NULL ; +#ifdef _WIN32 +CloseHandle (cpu->hThread); +#endif g_free (vcpu);return 0 ; }
Signature · 1 line
2.38.1
Re: [PATCH 03/14] accel: Fix a leak on Windows HAX
Quoted 7 lines · Philippe Mathieu-Daudé
hThread is only used on the error path in
hax_kick_vcpu_thread().Fixes b0cb0a66d6 ("Plumb the HAXM-based hardware acceleration support")Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/i386/hax/hax-all.c | 3 +++ 1 file changed, 3 insertions(+)
r~
PATCH 4/14 accel: Destroy HAX vCPU threads once done
In reply to Philippe Mathieu-DaudéWhen the vCPU thread finished its processing, destroy it and signal its destruction to generic vCPU management layer.
Add a sanity check for the vCPU accelerator context.
--- target/i386/hax/hax-accel-ops.c | 3 +++ target/i386/hax/hax-all.c | 1 + 2 files changed, 4 insertions(+)
target/i386/hax/hax-accel-ops.c +3 -0
@@ -53,6 +53,8 @@ static void *hax_cpu_thread_fn(void *arg)qemu_wait_io_event (cpu); }while (!cpu->unplug ||cpu_can_run (cpu)); +hax_vcpu_destroy (cpu); +cpu_thread_signal_destroyed (cpu);rcu_unregister_thread ();return NULL ; }
@@ -69,6 +71,7 @@ static void hax_start_vcpu_thread(CPUState *cpu) cpu->cpu_index);qemu_thread_create (cpu->thread, thread_name, hax_cpu_thread_fn, cpu,QEMU_THREAD_JOINABLE ); +assert (cpu->hax_vcpu);#ifdef _WIN32 cpu->hThread =qemu_thread_get_handle (cpu->thread);#endif
target/i386/hax/hax-all.c +1 -0
@@ -209,6 +209,7 @@ int hax_vcpu_destroy(CPUState *cpu)CloseHandle (cpu->hThread);#endif g_free (vcpu); + cpu->hax_vcpu =NULL ;return 0 ; }
Signature · 1 line
2.38.1
PATCH 5/14 accel: Rename 'hax_vcpu' as 'accel' in CPUState
In reply to Philippe Mathieu-DaudéAll accelerators will share a single opaque context in CPUState. Start by renaming 'hax_vcpu' as 'accelCPUState'.
--- include/hw/core/cpu.h | 2 +- target/i386/hax/hax-accel-ops.c | 2 +- target/i386/hax/hax-all.c | 18 +++++++++--------- target/i386/nvmm/nvmm-all.c | 6 +++--- target/i386/whpx/whpx-all.c | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-)
include/hw/core/cpu.h +1 -1
@@ -442,7 +442,7 @@ struct CPUState {/* Used for user-only emulation of prctl(PR_SET_UNALIGN). */ bool prctl_unalign_sigbus; -struct hax_vcpu_state *hax_vcpu; +struct hax_vcpu_state *accel;struct hvf_vcpu_state *hvf;
target/i386/hax/hax-accel-ops.c +1 -1
@@ -71,7 +71,7 @@ static void hax_start_vcpu_thread(CPUState *cpu) cpu->cpu_index);qemu_thread_create (cpu->thread, thread_name, hax_cpu_thread_fn, cpu,QEMU_THREAD_JOINABLE ); -assert (cpu->hax_vcpu); +assert (cpu->accel);#ifdef _WIN32 cpu->hThread =qemu_thread_get_handle (cpu->thread);#endif
target/i386/hax/hax-all.c +9 -9
@@ -62,7 +62,7 @@ int valid_hax_tunnel_size(uint16_t size)hax_fd hax_vcpu_get_fd (CPUArchState *env) { -struct hax_vcpu_state *vcpu =env_cpu (env)->hax_vcpu; +struct hax_vcpu_state *vcpu =env_cpu (env)->accel;if (!vcpu) {return HAX_INVALID_FD ; }
@@ -188,7 +188,7 @@ int hax_vcpu_create(int id)int hax_vcpu_destroy (CPUState *cpu) { -struct hax_vcpu_state *vcpu = cpu->hax_vcpu; +struct hax_vcpu_state *vcpu = cpu->accel;if (!hax_global.vm) {fprintf (stderr,"vcpu %x destroy failed, vm is null\n" , vcpu->vcpu_id);
@@ -209,7 +209,7 @@ int hax_vcpu_destroy(CPUState *cpu)CloseHandle (cpu->hThread);#endif g_free (vcpu); - cpu->hax_vcpu =NULL ; + cpu->accel =NULL ;return 0 ; }
@@ -223,7 +223,7 @@ int hax_init_vcpu(CPUState *cpu)exit (-1 ); } - cpu->hax_vcpu = hax_global.vm->vcpus[cpu->cpu_index]; + cpu->accel = hax_global.vm->vcpus[cpu->cpu_index]; cpu->vcpu_dirty = true;qemu_register_reset (hax_reset_vcpu_state, cpu->env_ptr);
@@ -415,7 +415,7 @@ static int hax_handle_io(CPUArchState *env, uint32_t df, uint16_t port,static int hax_vcpu_interrupt (CPUArchState *env) {CPUState *cpu =env_cpu (env); -struct hax_vcpu_state *vcpu = cpu->hax_vcpu; +struct hax_vcpu_state *vcpu = cpu->accel;struct hax_tunnel *ht = vcpu->tunnel;/*
@@ -447,7 +447,7 @@ static int hax_vcpu_interrupt(CPUArchState *env)void hax_raise_event (CPUState *cpu) { -struct hax_vcpu_state *vcpu = cpu->hax_vcpu; +struct hax_vcpu_state *vcpu = cpu->accel;if (!vcpu) {return ;
@@ -468,7 +468,7 @@ static int hax_vcpu_hax_exec(CPUArchState *env)int ret =0 ;CPUState *cpu =env_cpu (env);X86CPU *x86_cpu =X86_CPU (cpu); -struct hax_vcpu_state *vcpu = cpu->hax_vcpu; +struct hax_vcpu_state *vcpu = cpu->accel;struct hax_tunnel *ht = vcpu->tunnel;if (!hax_enabled ()) {
@@ -1114,8 +1114,8 @@ void hax_reset_vcpu_state(void *opaque) {CPUState *cpu;for (cpu = first_cpu; cpu !=NULL ; cpu =CPU_NEXT (cpu)) { - cpu->hax_vcpu->tunnel->user_event_pending =0 ; - cpu->hax_vcpu->tunnel->ready_for_interrupt_injection =0 ; + cpu->accel->tunnel->user_event_pending =0 ; + cpu->accel->tunnel->ready_for_interrupt_injection =0 ; } }
target/i386/nvmm/nvmm-all.c +3 -3
@@ -52,7 +52,7 @@ static struct qemu_machine qemu_mach;static struct qemu_vcpu *get_qemu_vcpu (CPUState *cpu) { -return (struct qemu_vcpu *)cpu->hax_vcpu; +return (struct qemu_vcpu *)cpu->accel; } static struct nvmm_machine *
@@ -995,7 +995,7 @@ nvmm_init_vcpu(CPUState *cpu) } cpu->vcpu_dirty = true; - cpu->hax_vcpu = (struct hax_vcpu_state *)qcpu; + cpu->accel = (struct hax_vcpu_state *)qcpu;return 0 ; }
@@ -1030,7 +1030,7 @@ nvmm_destroy_vcpu(CPUState *cpu)struct qemu_vcpu *qcpu =get_qemu_vcpu (cpu);nvmm_vcpu_destroy (mach, &qcpu->vcpu); -g_free (cpu->hax_vcpu); +g_free (cpu->accel); }/* -------------------------------------------------------------------------- */
target/i386/whpx/whpx-all.c +3 -3
@@ -262,7 +262,7 @@ static bool whpx_has_xsave(void)static struct whpx_vcpu *get_whpx_vcpu (CPUState *cpu) { -return (struct whpx_vcpu *)cpu->hax_vcpu; +return (struct whpx_vcpu *)cpu->accel; } static WHV_X64_SEGMENT_REGISTER whpx_seg_q2h(const SegmentCache *qs, int v86,
@@ -2258,7 +2258,7 @@ int whpx_init_vcpu(CPUState *cpu) vcpu->interruptable = true; cpu->vcpu_dirty = true; - cpu->hax_vcpu = (struct hax_vcpu_state *)vcpu; + cpu->accel = (struct hax_vcpu_state *)vcpu; max_vcpu_index =max (max_vcpu_index, cpu->cpu_index);qemu_add_vm_change_state_handler (whpx_cpu_update_state, cpu->env_ptr);
@@ -2300,7 +2300,7 @@ void whpx_destroy_vcpu(CPUState *cpu) whp_dispatch.WHvDeleteVirtualProcessor (whpx->partition, cpu->cpu_index); whp_dispatch.WHvEmulatorDestroyEmulator (vcpu->emulator); -g_free (cpu->hax_vcpu); +g_free (cpu->accel);return ; }
Signature · 1 line
2.38.1
Re: [PATCH 05/14] accel: Rename 'hax_vcpu' as 'accel' in CPUState
Quoted 2 lines · Philippe Mathieu-Daudé
All accelerators will share a single opaque context in CPUState. Start by renaming '
hax_vcpu' as 'accelCPUState'.
Pasto in 'accel' here.
r~
PATCH 6/14 accel: Use a typedef for struct hax_vcpu_state
In reply to Philippe Mathieu-DaudéUse a type definition instead of explicit structure.
--- target/i386/hax/hax-i386.h | 10 +++++----- target/i386/hax/hax-all.c | 16 ++++++++-------- target/i386/hax/hax-posix.c | 4 ++-- target/i386/hax/hax-windows.c | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-)
target/i386/hax/hax-i386.h +5 -5
@@ -25,12 +25,12 @@ typedef HANDLE hax_fd;#endif extern struct hax_state hax_global; -struct hax_vcpu_state { +typedef struct hax_vcpu_state {hax_fd fd;int vcpu_id;struct hax_tunnel *tunnel;unsigned char *iobuf; -}; +}hax_vcpu_state ;struct hax_state {hax_fd fd;/* the global hax device interface */
@@ -46,7 +46,7 @@ struct hax_vm {hax_fd fd;int id;int numvcpus; -struct hax_vcpu_state **vcpus; +hax_vcpu_state **vcpus; };/* Functions exported to host specific mode */
@@ -57,7 +57,7 @@ int valid_hax_tunnel_size(uint16_t size);int hax_mod_version (struct hax_state *hax,struct hax_module_version *version);int hax_inject_interrupt (CPUArchState *env,int vector);struct hax_vm *hax_vm_create (struct hax_state *hax,int max_cpus); -int hax_vcpu_run (struct hax_vcpu_state *vcpu); +int hax_vcpu_run (hax_vcpu_state *vcpu);int hax_vcpu_create (int id);void hax_kick_vcpu_thread (CPUState *cpu);
@@ -76,7 +76,7 @@ int hax_host_create_vm(struct hax_state *hax, int *vm_id);hax_fd hax_host_open_vm (struct hax_state *hax,int vm_id);int hax_host_create_vcpu (hax_fd vm_fd,int vcpuid);hax_fd hax_host_open_vcpu (int vmid,int vcpuid); -int hax_host_setup_vcpu_channel (struct hax_vcpu_state *vcpu); +int hax_host_setup_vcpu_channel (hax_vcpu_state *vcpu);hax_fd hax_mod_open (void );void hax_memory_init (void );
target/i386/hax/hax-all.c +8 -8
@@ -62,7 +62,7 @@ int valid_hax_tunnel_size(uint16_t size)hax_fd hax_vcpu_get_fd (CPUArchState *env) { -struct hax_vcpu_state *vcpu =env_cpu (env)->accel; +hax_vcpu_state *vcpu =env_cpu (env)->accel;if (!vcpu) {return HAX_INVALID_FD ; }
@@ -136,7 +136,7 @@ static int hax_version_support(struct hax_state *hax)int hax_vcpu_create (int id) { -struct hax_vcpu_state *vcpu =NULL ; +hax_vcpu_state *vcpu =NULL ;int ret;if (!hax_global.vm) {
@@ -149,7 +149,7 @@ int hax_vcpu_create(int id)return 0 ; } - vcpu = g_new0(struct hax_vcpu_state, 1); + vcpu =g_new0 (hax_vcpu_state,1 ); ret =hax_host_create_vcpu (hax_global.vm->fd, id);if (ret) {
@@ -188,7 +188,7 @@ int hax_vcpu_create(int id)int hax_vcpu_destroy (CPUState *cpu) { -struct hax_vcpu_state *vcpu = cpu->accel; +hax_vcpu_state *vcpu = cpu->accel;if (!hax_global.vm) {fprintf (stderr,"vcpu %x destroy failed, vm is null\n" , vcpu->vcpu_id);
@@ -263,7 +263,7 @@ struct hax_vm *hax_vm_create(struct hax_state *hax, int max_cpus) } vm->numvcpus = max_cpus; - vm->vcpus = g_new0(struct hax_vcpu_state *, vm->numvcpus); + vm->vcpus = g_new0(hax_vcpu_state *, vm->numvcpus);for (i =0 ; i < vm->numvcpus; i++) { vm->vcpus[i] =NULL ; }
@@ -415,7 +415,7 @@ static int hax_handle_io(CPUArchState *env, uint32_t df, uint16_t port,static int hax_vcpu_interrupt (CPUArchState *env) {CPUState *cpu =env_cpu (env); -struct hax_vcpu_state *vcpu = cpu->accel; +hax_vcpu_state *vcpu = cpu->accel;struct hax_tunnel *ht = vcpu->tunnel;/*
@@ -447,7 +447,7 @@ static int hax_vcpu_interrupt(CPUArchState *env)void hax_raise_event (CPUState *cpu) { -struct hax_vcpu_state *vcpu = cpu->accel; +hax_vcpu_state *vcpu = cpu->accel;if (!vcpu) {return ;
@@ -468,7 +468,7 @@ static int hax_vcpu_hax_exec(CPUArchState *env)int ret =0 ;CPUState *cpu =env_cpu (env);X86CPU *x86_cpu =X86_CPU (cpu); -struct hax_vcpu_state *vcpu = cpu->accel; +hax_vcpu_state *vcpu = cpu->accel;struct hax_tunnel *ht = vcpu->tunnel;if (!hax_enabled ()) {
target/i386/hax/hax-posix.c +2 -2
@@ -205,7 +205,7 @@ hax_fd hax_host_open_vcpu(int vmid, int vcpuid)return fd; } -int hax_host_setup_vcpu_channel (struct hax_vcpu_state *vcpu) +int hax_host_setup_vcpu_channel (hax_vcpu_state *vcpu) {int ret;struct hax_tunnel_info info;
@@ -227,7 +227,7 @@ int hax_host_setup_vcpu_channel(struct hax_vcpu_state *vcpu)return 0 ; } -int hax_vcpu_run (struct hax_vcpu_state *vcpu) +int hax_vcpu_run (hax_vcpu_state *vcpu) {return ioctl (vcpu->fd,HAX_VCPU_IOCTL_RUN ,NULL ); }
target/i386/hax/hax-windows.c +2 -2
@@ -301,7 +301,7 @@ hax_fd hax_host_open_vcpu(int vmid, int vcpuid)return hDeviceVCPU; } -int hax_host_setup_vcpu_channel (struct hax_vcpu_state *vcpu) +int hax_host_setup_vcpu_channel (hax_vcpu_state *vcpu) {hax_fd hDeviceVCPU = vcpu->fd;int ret;
@@ -327,7 +327,7 @@ int hax_host_setup_vcpu_channel(struct hax_vcpu_state *vcpu)return 0 ; } -int hax_vcpu_run (struct hax_vcpu_state *vcpu) +int hax_vcpu_run (hax_vcpu_state *vcpu) {int ret;HANDLE hDeviceVCPU = vcpu->fd;
Signature · 1 line
2.38.1
PATCH 7/14 accel: Rename struct hax_vcpu_state -> struct AccelvCPUState
In reply to Philippe Mathieu-DaudéWe want all accelerators to share the same opaque pointer in CPUState. Start with the HAX context, renaming its forward declarated structure 'hax_vcpu_state' as 'AccelvCPUState'.
--- include/hw/core/cpu.h | 7 +++---- target/i386/hax/hax-i386.h | 3 ++- target/i386/nvmm/nvmm-all.c | 2 +- target/i386/whpx/whpx-all.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)
include/hw/core/cpu.h +3 -4
@@ -235,8 +235,7 @@ typedef struct SavedIOTLB {struct KVMState ;struct kvm_run ; - -struct hax_vcpu_state ; +struct AccelvCPUState ;struct hvf_vcpu_state ;/* work queue */
@@ -305,6 +304,7 @@ struct qemu_work_item;* @next_cpu: Next CPU sharing TB cache. * @opaque: User data. * @mem_io_pc: Host Program Counter at which the memory was accessed. +* @accel: Pointer to accelerator specific state. * @kvm_fd: vCPU file descriptor for KVM. * @work_mutex: Lock to prevent multiple access to @work_list. * @work_list: List of pending asynchronous work.
@@ -423,6 +423,7 @@ struct CPUState {uint32_t can_do_io;int32_t exception_index; +struct AccelvCPUState *accel;/* shared by kvm, hax and hvf */ bool vcpu_dirty;
@@ -442,8 +443,6 @@ struct CPUState {/* Used for user-only emulation of prctl(PR_SET_UNALIGN). */ bool prctl_unalign_sigbus; -struct hax_vcpu_state *accel; -struct hvf_vcpu_state *hvf;/* track IOMMUs whose translations we've cached in the TCG TLB */
target/i386/hax/hax-i386.h +2 -1
@@ -25,7 +25,8 @@ typedef HANDLE hax_fd;#endif extern struct hax_state hax_global; -typedef struct hax_vcpu_state { + +typedef struct AccelvCPUState { hax_fd fd; int vcpu_id; struct hax_tunnel *tunnel;
target/i386/nvmm/nvmm-all.c +1 -1
@@ -995,7 +995,7 @@ nvmm_init_vcpu(CPUState *cpu) } cpu->vcpu_dirty = true; - cpu->accel = (struct hax_vcpu_state *)qcpu; + cpu->accel = (struct AccelvCPUState *)qcpu;return 0 ; }
target/i386/whpx/whpx-all.c +1 -1
@@ -2258,7 +2258,7 @@ int whpx_init_vcpu(CPUState *cpu) vcpu->interruptable = true; cpu->vcpu_dirty = true; - cpu->accel = (struct hax_vcpu_state *)vcpu; + cpu->accel = (struct AccelvCPUState *)vcpu; max_vcpu_index =max (max_vcpu_index, cpu->cpu_index);qemu_add_vm_change_state_handler (whpx_cpu_update_state, cpu->env_ptr);
Signature · 1 line
2.38.1
Re: [PATCH 07/14] accel: Rename struct hax_vcpu_state -> struct AccelvCPUState
Quoted 11 lines · Philippe Mathieu-Daudé
We want all accelerators to share the same opaque pointer in CPUState. Start with the HAX context, renaming its forward declarated structure '
hax_vcpu_state' as 'AccelvCPUState'.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- include/hw/core/cpu.h | 7 +++---- target/i386/hax/hax-i386.h | 3 ++- target/i386/nvmm/nvmm-all.c | 2 +- target/i386/whpx/whpx-all.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)
Can this be squashed with previous? It seems odd to change the name twice in a row. Is the "v" in AccelvCPUState helpful?
Quoted 3 lines
+ struct AccelvCPUState *accel;
/* shared by kvm, hax and hvf */
bool vcpu_dirty;Move below the comment? Or is that later?
r~
Re: [PATCH 07/14] accel: Rename struct hax_vcpu_state -> struct AccelvCPUState
In reply to Philippe Mathieu-DaudéQuoted 1 line · Philippe Mathieu-Daudé
+struct AccelvCPUState;
Missing typedef?
r~
PATCH 8/14 accel: Move HAX hThread to accelerator context
In reply to Philippe Mathieu-DaudéhThread variable is only used by the HAX accelerator, so move it to the accelerator specific context.
--- include/hw/core/cpu.h | 1 - target/i386/hax/hax-i386.h | 3 +++ target/i386/hax/hax-accel-ops.c | 2 +- target/i386/hax/hax-all.c | 2 +- target/i386/hax/hax-windows.c | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-)
include/hw/core/cpu.h +0 -1
@@ -334,7 +334,6 @@ struct CPUState {struct QemuThread *thread;#ifdef _WIN32 -HANDLE hThread;QemuSemaphore sem;#endif int thread_id;
target/i386/hax/hax-i386.h +3 -0
@@ -27,6 +27,9 @@ typedef HANDLE hax_fd;extern struct hax_state hax_global; typedef struct AccelvCPUState { +#ifdef _WIN32 + HANDLE hThread; +#endif hax_fd fd; int vcpu_id; struct hax_tunnel *tunnel;
target/i386/hax/hax-accel-ops.c +1 -1
@@ -73,7 +73,7 @@ static void hax_start_vcpu_thread(CPUState *cpu) cpu, QEMU_THREAD_JOINABLE);assert (cpu->accel);#ifdef _WIN32 - cpu->hThread =qemu_thread_get_handle (cpu->thread); + cpu->accel->hThread =qemu_thread_get_handle (cpu->thread);#endif }
target/i386/hax/hax-all.c +1 -1
@@ -206,7 +206,7 @@ int hax_vcpu_destroy(CPUState *cpu)hax_close_fd (vcpu->fd); hax_global.vm->vcpus[vcpu->vcpu_id] =NULL ;#ifdef _WIN32 -CloseHandle (cpu->hThread); +CloseHandle (vcpu->hThread);#endif g_free (vcpu); cpu->accel =NULL ;
target/i386/hax/hax-windows.c +1 -1
@@ -476,7 +476,7 @@ void hax_kick_vcpu_thread(CPUState *cpu)*/ cpu->exit_request =1 ;if (!qemu_cpu_is_self (cpu)) { -if (!QueueUserAPC (dummy_apc_func, cpu->hThread,0 )) { +if (!QueueUserAPC (dummy_apc_func, cpu->accel->hThread,0 )) {fprintf (stderr,"%s: QueueUserAPC failed with error %lu\n" , __func__,GetLastError ());exit (1 );
Signature · 1 line
2.38.1
Re: [PATCH 08/14] accel: Move HAX hThread to accelerator context
Quoted 11 lines · Philippe Mathieu-Daudé
hThread variable is only used by the HAX accelerator, so move it to the accelerator specific context.
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- include/hw/core/cpu.h | 1 - target/i386/hax/hax-i386.h | 3 +++ target/i386/hax/hax-accel-ops.c | 2 +- target/i386/hax/hax-all.c | 2 +- target/i386/hax/hax-windows.c | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-)
r~
PATCH 9/14 accel: Allocate NVMM vCPU using g_try_FOO()
In reply to Philippe Mathieu-Daudég_malloc0() can not fail. Use g_try_malloc0() instead.
--- target/i386/nvmm/nvmm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/nvmm/nvmm-all.c +1 -1
@@ -942,7 +942,7 @@ nvmm_init_vcpu(CPUState *cpu) } } - qcpu =g_malloc0 (sizeof (*qcpu)); + qcpu =g_try_malloc0 (sizeof (*qcpu));if (qcpu ==NULL ) {error_report ("NVMM: Failed to allocate VCPU context." );return -ENOMEM ;
Signature · 1 line
2.38.1
Re: [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO()
Quoted 14 lines · Philippe Mathieu-Daudé
g_malloc0()can not fail. Useg_try_malloc0()instead.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/i386/nvmm/nvmm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/i386/nvmm/nvmm-all.c +0
-0
target/i386/nvmm/nvmm-all.c nvmm_init_vcpu(CPUState *cpu) · line 948
Quoted 8 lines
target/i386/nvmm/nvmm-all.c +1
-1@@ -942,7 +942,7 @@ nvmm_init_vcpu(CPUState *cpu) } } - qcpu =g_malloc0 (sizeof (*qcpu)); + qcpu =g_try_malloc0 (sizeof (*qcpu));if (qcpu ==NULL ) {error_report ("NVMM: Failed to allocate VCPU context." );return -ENOMEM ;
Why - if we fail to allocate the vCPU context its game over anyway any established QEMU practice is its ok to assert fail on a malloc when there isn't enough memory. IOW keep the g_malloc0 and remove the error handling case.
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO()
Quoted 20 lines · Alex Bennée
Quoted 17 lines · Philippe Mathieu-Daudé
g_malloc0()can not fail. Useg_try_malloc0()instead.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/i386/nvmm/nvmm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/i386/nvmm/nvmm-all.c +0
-0@@ -942,7 +942,7 @@ nvmm_init_vcpu(CPUState *cpu) } }
Quoted 10 lines
target/i386/nvmm/nvmm-all.c nvmm_init_vcpu(CPUState *cpu) · line 948
Quoted 5 lines
target/i386/nvmm/nvmm-all.c +1
-1- qcpu =g_malloc0 (sizeof (*qcpu)); + qcpu =g_try_malloc0 (sizeof (*qcpu));if (qcpu ==NULL ) {error_report ("NVMM: Failed to allocate VCPU context." );return -ENOMEM ;Why - if we fail to allocate the vCPU context its game over anyway any established QEMU practice is its ok to assert fail on a malloc when there isn't enough memory. IOW keep the
g_malloc0and remove the error handling case.
This was my first approach but then I realized the author took care to warn / return ENOMEM, so I went for _try_; but you are right, since this is "game over" let's simply remove the check.
PATCH 10/14 accel: Rename NVMM struct qemu_vcpu -> struct AccelvCPUState
In reply to Philippe Mathieu-DaudéWe want all accelerators to share the same opaque pointer in CPUState. Rename NVMM 'qemu_vcpu' as 'AccelvCPUState'.
Replace g_try_malloc0() by g_try_new0() for readability.
--- target/i386/nvmm/nvmm-all.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
target/i386/nvmm/nvmm-all.c +17 -17
@@ -26,7 +26,7 @@#include <nvmm.h> -struct qemu_vcpu { +struct AccelvCPUState {struct nvmm_vcpu vcpu;uint8_t tpr;bool stop;
@@ -49,10 +49,10 @@ struct qemu_machine {static bool nvmm_allowed;static struct qemu_machine qemu_mach; -static struct qemu_vcpu * +static struct AccelvCPUState *get_qemu_vcpu (CPUState *cpu) { -return (struct qemu_vcpu *)cpu->accel; +return cpu->accel; } static struct nvmm_machine *
@@ -86,7 +86,7 @@ nvmm_set_registers(CPUState *cpu) {CPUX86State *env = cpu->env_ptr;struct nvmm_machine *mach =get_nvmm_mach (); -struct qemu_vcpu *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu);struct nvmm_vcpu *vcpu = &qcpu->vcpu;struct nvmm_x64_state *state = vcpu->state;uint64_t bitmap;
@@ -223,7 +223,7 @@ nvmm_get_registers(CPUState *cpu) {CPUX86State *env = cpu->env_ptr;struct nvmm_machine *mach =get_nvmm_mach (); -struct qemu_vcpu *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu);struct nvmm_vcpu *vcpu = &qcpu->vcpu;X86CPU *x86_cpu =X86_CPU (cpu);struct nvmm_x64_state *state = vcpu->state;
@@ -347,7 +347,7 @@ static bool nvmm_can_take_int(CPUState *cpu) {CPUX86State *env = cpu->env_ptr; -struct qemu_vcpu *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu);struct nvmm_vcpu *vcpu = &qcpu->vcpu;struct nvmm_machine *mach =get_nvmm_mach ();
@@ -372,7 +372,7 @@ nvmm_can_take_int(CPUState *cpu)static bool nvmm_can_take_nmi (CPUState *cpu) { -struct qemu_vcpu *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu);/* * Contrary to INTs, NMIs always schedule an exit when they are
@@ -395,7 +395,7 @@ nvmm_vcpu_pre_run(CPUState *cpu) {CPUX86State *env = cpu->env_ptr;struct nvmm_machine *mach =get_nvmm_mach (); -struct qemu_vcpu *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu);struct nvmm_vcpu *vcpu = &qcpu->vcpu;X86CPU *x86_cpu =X86_CPU (cpu);struct nvmm_x64_state *state = vcpu->state;
@@ -478,7 +478,7 @@ nvmm_vcpu_pre_run(CPUState *cpu)static void nvmm_vcpu_post_run (CPUState *cpu,struct nvmm_vcpu_exit *exit) { -struct qemu_vcpu *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu);CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu);uint64_t tpr;
@@ -565,7 +565,7 @@ static int nvmm_handle_rdmsr(struct nvmm_machine *mach, CPUState *cpu, struct nvmm_vcpu_exit *exit) { - struct qemu_vcpu *qcpu = get_qemu_vcpu(cpu); + struct AccelvCPUState *qcpu = get_qemu_vcpu(cpu);struct nvmm_vcpu *vcpu = &qcpu->vcpu;X86CPU *x86_cpu =X86_CPU (cpu);struct nvmm_x64_state *state = vcpu->state;
@@ -610,7 +610,7 @@ static int nvmm_handle_wrmsr(struct nvmm_machine *mach, CPUState *cpu, struct nvmm_vcpu_exit *exit) { - struct qemu_vcpu *qcpu = get_qemu_vcpu(cpu); + struct AccelvCPUState *qcpu = get_qemu_vcpu(cpu);struct nvmm_vcpu *vcpu = &qcpu->vcpu;X86CPU *x86_cpu =X86_CPU (cpu);struct nvmm_x64_state *state = vcpu->state;
@@ -686,7 +686,7 @@ nvmm_vcpu_loop(CPUState *cpu) {CPUX86State *env = cpu->env_ptr;struct nvmm_machine *mach =get_nvmm_mach (); -struct qemu_vcpu *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu);struct nvmm_vcpu *vcpu = &qcpu->vcpu;X86CPU *x86_cpu =X86_CPU (cpu);struct nvmm_vcpu_exit *exit = vcpu->exit;
@@ -892,7 +892,7 @@ static void nvmm_ipi_signal(int sigcpu) {if (current_cpu) { -struct qemu_vcpu *qcpu =get_qemu_vcpu (current_cpu); +struct AccelvCPUState *qcpu =get_qemu_vcpu (current_cpu);#if NVMM_USER_VERSION >=2 struct nvmm_vcpu *vcpu = &qcpu->vcpu;nvmm_vcpu_stop (vcpu);
@@ -926,7 +926,7 @@ nvmm_init_vcpu(CPUState *cpu)struct nvmm_vcpu_conf_cpuid cpuid;struct nvmm_vcpu_conf_tpr tpr;Error *local_error =NULL ; -struct qemu_vcpu *qcpu; +struct AccelvCPUState *qcpu;int ret, err;nvmm_init_cpu_signals ();
@@ -942,7 +942,7 @@ nvmm_init_vcpu(CPUState *cpu) } } - qcpu =g_try_malloc0 (sizeof (*qcpu)); + qcpu = g_try_new0(struct AccelvCPUState, 1);if (qcpu ==NULL ) {error_report ("NVMM: Failed to allocate VCPU context." );return -ENOMEM ;
@@ -995,7 +995,7 @@ nvmm_init_vcpu(CPUState *cpu) } cpu->vcpu_dirty = true; - cpu->accel = (struct AccelvCPUState *)qcpu; + cpu->accel = qcpu;return 0 ; }
@@ -1027,7 +1027,7 @@ void nvmm_destroy_vcpu(CPUState *cpu) {struct nvmm_machine *mach =get_nvmm_mach (); -struct qemu_vcpu *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu);nvmm_vcpu_destroy (mach, &qcpu->vcpu);g_free (cpu->accel);
Signature · 1 line
2.38.1
Re: [PATCH 10/14] accel: Rename NVMM struct qemu_vcpu -> struct AccelvCPUState
Review
Quoted 2 lines · Philippe Mathieu-Daudé
(quoted diff) +1
-1- struct qemu_vcpu *qcpu = get_qemu_vcpu(cpu); + struct AccelvCPUState *qcpu = get_qemu_vcpu(cpu);
With the typedef in hw/core/cpu.h, you can drop the 'struct' at the same time.
Otherwise,
target/i386/nvmm/nvmm-all.c nvmm_init_vcpu(CPUState *cpu) · line 945
Quoted 2 lines
target/i386/nvmm/nvmm-all.c +1
-1- qcpu =g_try_malloc0 (sizeof (*qcpu)); + qcpu = g_try_new0(struct AccelvCPUState, 1);
Another 'try' to clean up. :-)
r~
PATCH 11/14 accel: Inline NVMM get_qemu_vcpu()
In reply to Philippe Mathieu-DaudéNo need for this helper to access the CPUState::accel field.
--- target/i386/nvmm/nvmm-all.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
target/i386/nvmm/nvmm-all.c +11 -17
@@ -49,12 +49,6 @@ struct qemu_machine {static bool nvmm_allowed;static struct qemu_machine qemu_mach; -static struct AccelvCPUState * -get_qemu_vcpu (CPUState *cpu) -{ -return cpu->accel; -} -static struct nvmm_machine *get_nvmm_mach (void ) {
@@ -86,7 +80,7 @@ nvmm_set_registers(CPUState *cpu) {CPUX86State *env = cpu->env_ptr;struct nvmm_machine *mach =get_nvmm_mach (); -struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu = cpu->accel;struct nvmm_vcpu *vcpu = &qcpu->vcpu;struct nvmm_x64_state *state = vcpu->state;uint64_t bitmap;
@@ -223,7 +217,7 @@ nvmm_get_registers(CPUState *cpu) {CPUX86State *env = cpu->env_ptr;struct nvmm_machine *mach =get_nvmm_mach (); -struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu = cpu->accel;struct nvmm_vcpu *vcpu = &qcpu->vcpu;X86CPU *x86_cpu =X86_CPU (cpu);struct nvmm_x64_state *state = vcpu->state;
@@ -347,7 +341,7 @@ static bool nvmm_can_take_int(CPUState *cpu) {CPUX86State *env = cpu->env_ptr; -struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu = cpu->accel;struct nvmm_vcpu *vcpu = &qcpu->vcpu;struct nvmm_machine *mach =get_nvmm_mach ();
@@ -372,7 +366,7 @@ nvmm_can_take_int(CPUState *cpu)static bool nvmm_can_take_nmi (CPUState *cpu) { -struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu = cpu->accel;/* * Contrary to INTs, NMIs always schedule an exit when they are
@@ -395,7 +389,7 @@ nvmm_vcpu_pre_run(CPUState *cpu) {CPUX86State *env = cpu->env_ptr;struct nvmm_machine *mach =get_nvmm_mach (); -struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu = cpu->accel;struct nvmm_vcpu *vcpu = &qcpu->vcpu;X86CPU *x86_cpu =X86_CPU (cpu);struct nvmm_x64_state *state = vcpu->state;
@@ -478,7 +472,7 @@ nvmm_vcpu_pre_run(CPUState *cpu)static void nvmm_vcpu_post_run (CPUState *cpu,struct nvmm_vcpu_exit *exit) { -struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu = cpu->accel;CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu);uint64_t tpr;
@@ -565,7 +559,7 @@ static int nvmm_handle_rdmsr(struct nvmm_machine *mach, CPUState *cpu, struct nvmm_vcpu_exit *exit) { - struct AccelvCPUState *qcpu = get_qemu_vcpu(cpu); + struct AccelvCPUState *qcpu = cpu->accel;struct nvmm_vcpu *vcpu = &qcpu->vcpu;X86CPU *x86_cpu =X86_CPU (cpu);struct nvmm_x64_state *state = vcpu->state;
@@ -610,7 +604,7 @@ static int nvmm_handle_wrmsr(struct nvmm_machine *mach, CPUState *cpu, struct nvmm_vcpu_exit *exit) { - struct AccelvCPUState *qcpu = get_qemu_vcpu(cpu); + struct AccelvCPUState *qcpu = cpu->accel;struct nvmm_vcpu *vcpu = &qcpu->vcpu;X86CPU *x86_cpu =X86_CPU (cpu);struct nvmm_x64_state *state = vcpu->state;
@@ -686,7 +680,7 @@ nvmm_vcpu_loop(CPUState *cpu) {CPUX86State *env = cpu->env_ptr;struct nvmm_machine *mach =get_nvmm_mach (); -struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu = cpu->accel;struct nvmm_vcpu *vcpu = &qcpu->vcpu;X86CPU *x86_cpu =X86_CPU (cpu);struct nvmm_vcpu_exit *exit = vcpu->exit;
@@ -892,7 +886,7 @@ static void nvmm_ipi_signal(int sigcpu) {if (current_cpu) { -struct AccelvCPUState *qcpu =get_qemu_vcpu (current_cpu); +struct AccelvCPUState *qcpu = current_cpu->accel;#if NVMM_USER_VERSION >=2 struct nvmm_vcpu *vcpu = &qcpu->vcpu;nvmm_vcpu_stop (vcpu);
@@ -1027,7 +1021,7 @@ void nvmm_destroy_vcpu(CPUState *cpu) {struct nvmm_machine *mach =get_nvmm_mach (); -struct AccelvCPUState *qcpu =get_qemu_vcpu (cpu); +struct AccelvCPUState *qcpu = cpu->accel;nvmm_vcpu_destroy (mach, &qcpu->vcpu);g_free (cpu->accel);
Signature · 1 line
2.38.1
Re: [PATCH 11/14] accel: Inline NVMM get_qemu_vcpu()
Quoted 6 lines · Philippe Mathieu-Daudé
No need for this helper to access the
CPUState::accelfield.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/i386/nvmm/nvmm-all.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
r~
PATCH 12/14 accel: Rename WHPX struct whpx_vcpu -> struct AccelvCPUState
In reply to Philippe Mathieu-DaudéWe want all accelerators to share the same opaque pointer in CPUState. Rename WHPX 'whpx_vcpu' as 'AccelvCPUState'.
--- target/i386/whpx/whpx-all.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
target/i386/whpx/whpx-all.c +15 -15
@@ -229,7 +229,7 @@ typedef enum WhpxStepMode {WHPX_STEP_EXCLUSIVE , } WhpxStepMode; -struct whpx_vcpu { +struct AccelvCPUState {WHV_EMULATOR_HANDLE emulator;bool window_registered;bool interruptable;
@@ -260,9 +260,9 @@ static bool whpx_has_xsave(void)* VP support */ -static struct whpx_vcpu *get_whpx_vcpu (CPUState *cpu) +static struct AccelvCPUState *get_whpx_vcpu (CPUState *cpu) { -return (struct whpx_vcpu *)cpu->accel; +return (struct AccelvCPUState *)cpu->accel; } static WHV_X64_SEGMENT_REGISTER whpx_seg_q2h(const SegmentCache *qs, int v86,
@@ -390,7 +390,7 @@ static uint64_t whpx_cr8_to_apic_tpr(uint64_t cr8)static void whpx_set_registers (CPUState *cpu,int level) {struct whpx_state *whpx = &whpx_global; -struct whpx_vcpu *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu);CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu);struct whpx_register_set vcxt;
@@ -609,7 +609,7 @@ static void whpx_get_xcrs(CPUState *cpu)static void whpx_get_registers (CPUState *cpu) {struct whpx_state *whpx = &whpx_global; -struct whpx_vcpu *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu);CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu);struct whpx_register_set vcxt;
@@ -892,7 +892,7 @@ static const WHV_EMULATOR_CALLBACKS whpx_emu_callbacks = {static int whpx_handle_mmio (CPUState *cpu,WHV_MEMORY_ACCESS_CONTEXT *ctx) {HRESULT hr; -struct whpx_vcpu *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu);WHV_EMULATOR_STATUS emu_status; hr = whp_dispatch.WHvEmulatorTryMmioEmulation(
@@ -917,7 +917,7 @@ static int whpx_handle_portio(CPUState *cpu, WHV_X64_IO_PORT_ACCESS_CONTEXT *ctx) {HRESULT hr; -struct whpx_vcpu *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu);WHV_EMULATOR_STATUS emu_status; hr = whp_dispatch.WHvEmulatorTryIoEmulation(
@@ -1417,7 +1417,7 @@ static vaddr whpx_vcpu_get_pc(CPUState *cpu, bool exit_context_valid)* of QEMU, nor this port by calling WHvSetVirtualProcessorRegisters(). * This is the most common case. */ -struct whpx_vcpu *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu);return vcpu->exit_ctx.VpContext.Rip; }else {/*
@@ -1468,7 +1468,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) {HRESULT hr;struct whpx_state *whpx = &whpx_global; -struct whpx_vcpu *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu);CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu);int irq;
@@ -1590,7 +1590,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu)static void whpx_vcpu_post_run (CPUState *cpu) { -struct whpx_vcpu *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu);CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu);
@@ -1617,7 +1617,7 @@ static void whpx_vcpu_process_async_events(CPUState *cpu) {CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu); -struct whpx_vcpu *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu);if ((cpu->interrupt_request &CPU_INTERRUPT_INIT ) && !(env->hflags &HF_SMM_MASK )) {
@@ -1656,7 +1656,7 @@ static int whpx_vcpu_run(CPUState *cpu) {HRESULT hr;struct whpx_state *whpx = &whpx_global; -struct whpx_vcpu *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu);struct whpx_breakpoint *stepped_over_bp =NULL ;WhpxStepMode exclusive_step_mode =WHPX_STEP_NONE ;int ret;
@@ -2154,7 +2154,7 @@ int whpx_init_vcpu(CPUState *cpu) {HRESULT hr;struct whpx_state *whpx = &whpx_global; -struct whpx_vcpu *vcpu =NULL ; +struct AccelvCPUState *vcpu =NULL ;Error *local_error =NULL ;CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu);
@@ -2177,7 +2177,7 @@ int whpx_init_vcpu(CPUState *cpu) } } - vcpu = g_new0(struct whpx_vcpu, 1); + vcpu = g_new0(struct AccelvCPUState, 1);if (!vcpu) {error_report ("WHPX: Failed to allocte VCPU context." );
@@ -2296,7 +2296,7 @@ int whpx_vcpu_exec(CPUState *cpu)void whpx_destroy_vcpu (CPUState *cpu) {struct whpx_state *whpx = &whpx_global; -struct whpx_vcpu *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu); whp_dispatch.WHvDeleteVirtualProcessor (whpx->partition, cpu->cpu_index); whp_dispatch.WHvEmulatorDestroyEmulator (vcpu->emulator);
Signature · 1 line
2.38.1
Re: [PATCH 12/14] accel: Rename WHPX struct whpx_vcpu -> struct AccelvCPUState
Quoted 22 lines · Philippe Mathieu-Daudé
We want all accelerators to share the same opaque pointer in CPUState. Rename WHPX '
whpx_vcpu' as 'AccelvCPUState'.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/i386/whpx/whpx-all.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)target/i386/whpx/whpx-all.c +1
-1@@ -229,7 +229,7 @@ typedef enum WhpxStepMode {WHPX_STEP_EXCLUSIVE , } WhpxStepMode; -struct whpx_vcpu { +struct AccelvCPUState {WHV_EMULATOR_HANDLE emulator;bool window_registered;bool interruptable;
target/i386/whpx/whpx-all.c static bool whpx_has_xsave(void) · line 265
Quoted 8 lines
target/i386/whpx/whpx-all.c +2
-2@@ -260,9 +260,9 @@ static bool whpx_has_xsave(void)* VP support */ -static struct whpx_vcpu *get_whpx_vcpu (CPUState *cpu) +static struct AccelvCPUState *get_whpx_vcpu (CPUState *cpu) { -return (struct whpx_vcpu *)cpu->accel; +return (struct AccelvCPUState *)cpu->accel;
Same comment about removing 'struct'.
Quoted 5 lines
target/i386/whpx/whpx-all.c +1
-1- vcpu = g_new0(struct whpx_vcpu, 1); + vcpu = g_new0(struct AccelvCPUState, 1);if (!vcpu) {error_report("WHPX: Failed to allocte VCPU context.");
Hah. And a "can't happen" error_report, since we're not actually using try here. :-P
r~
PATCH 13/14 accel: Inline WHPX get_whpx_vcpu()
In reply to Philippe Mathieu-DaudéNo need for this helper to access the CPUState::accel field.
--- target/i386/whpx/whpx-all.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-)
target/i386/whpx/whpx-all.c +10 -19
@@ -256,15 +256,6 @@ static bool whpx_has_xsave(void)return whpx_xsave_cap.XsaveSupport; } -/* -* VP support -*/ - -static struct AccelvCPUState *get_whpx_vcpu (CPUState *cpu) -{ -return (struct AccelvCPUState *)cpu->accel; -} -static WHV_X64_SEGMENT_REGISTER whpx_seg_q2h (const SegmentCache *qs,int v86,int r86) {
@@ -390,7 +381,7 @@ static uint64_t whpx_cr8_to_apic_tpr(uint64_t cr8)static void whpx_set_registers (CPUState *cpu,int level) {struct whpx_state *whpx = &whpx_global; -struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu = cpu->accel;CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu);struct whpx_register_set vcxt;
@@ -609,7 +600,7 @@ static void whpx_get_xcrs(CPUState *cpu)static void whpx_get_registers (CPUState *cpu) {struct whpx_state *whpx = &whpx_global; -struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu = cpu->accel;CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu);struct whpx_register_set vcxt;
@@ -892,7 +883,7 @@ static const WHV_EMULATOR_CALLBACKS whpx_emu_callbacks = {static int whpx_handle_mmio (CPUState *cpu,WHV_MEMORY_ACCESS_CONTEXT *ctx) {HRESULT hr; -struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu = cpu->accel;WHV_EMULATOR_STATUS emu_status; hr = whp_dispatch.WHvEmulatorTryMmioEmulation(
@@ -917,7 +908,7 @@ static int whpx_handle_portio(CPUState *cpu, WHV_X64_IO_PORT_ACCESS_CONTEXT *ctx) {HRESULT hr; -struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu = cpu->accel;WHV_EMULATOR_STATUS emu_status; hr = whp_dispatch.WHvEmulatorTryIoEmulation(
@@ -1417,7 +1408,7 @@ static vaddr whpx_vcpu_get_pc(CPUState *cpu, bool exit_context_valid)* of QEMU, nor this port by calling WHvSetVirtualProcessorRegisters(). * This is the most common case. */ -struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu = cpu->accel;return vcpu->exit_ctx.VpContext.Rip; }else {/*
@@ -1468,7 +1459,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) {HRESULT hr;struct whpx_state *whpx = &whpx_global; -struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu = cpu->accel;CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu);int irq;
@@ -1590,7 +1581,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu)static void whpx_vcpu_post_run (CPUState *cpu) { -struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu = cpu->accel;CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu);
@@ -1617,7 +1608,7 @@ static void whpx_vcpu_process_async_events(CPUState *cpu) {CPUX86State *env = cpu->env_ptr;X86CPU *x86_cpu =X86_CPU (cpu); -struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu = cpu->accel;if ((cpu->interrupt_request &CPU_INTERRUPT_INIT ) && !(env->hflags &HF_SMM_MASK )) {
@@ -1656,7 +1647,7 @@ static int whpx_vcpu_run(CPUState *cpu) {HRESULT hr;struct whpx_state *whpx = &whpx_global; -struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu = cpu->accel;struct whpx_breakpoint *stepped_over_bp =NULL ;WhpxStepMode exclusive_step_mode =WHPX_STEP_NONE ;int ret;
@@ -2296,7 +2287,7 @@ int whpx_vcpu_exec(CPUState *cpu)void whpx_destroy_vcpu (CPUState *cpu) {struct whpx_state *whpx = &whpx_global; -struct AccelvCPUState *vcpu =get_whpx_vcpu (cpu); +struct AccelvCPUState *vcpu = cpu->accel; whp_dispatch.WHvDeleteVirtualProcessor (whpx->partition, cpu->cpu_index); whp_dispatch.WHvEmulatorDestroyEmulator (vcpu->emulator);
Signature · 1 line
2.38.1
Re: [PATCH 13/14] accel: Inline WHPX get_whpx_vcpu()
Quoted 6 lines · Philippe Mathieu-Daudé
No need for this helper to access the
CPUState::accelfield.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/i386/whpx/whpx-all.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-)
r~
PATCH 14/14 accel: Rename HVF struct hvf_vcpu_state -> struct AccelvCPUState
In reply to Philippe Mathieu-DaudéWe want all accelerators to share the same opaque pointer in CPUState.
Rename the 'hvf_vcpu_state' structure as 'AccelvCPUState'.
Use the generic 'accel' field of CPUState instead of 'hvf'.
Replace g_malloc0() by g_new0() for readability.
--- include/hw/core/cpu.h | 3 -- include/sysemu/hvf_int.h | 2 +- accel/hvf/hvf-accel-ops.c | 16 ++++----- target/arm/hvf/hvf.c | 70 +++++++++++++++++++-------------------- 4 files changed, 44 insertions(+), 47 deletions(-)
include/hw/core/cpu.h +0 -3
@@ -236,7 +236,6 @@ typedef struct SavedIOTLB {struct KVMState ;struct kvm_run ;struct AccelvCPUState ; -struct hvf_vcpu_state ;/* work queue */
@@ -442,8 +441,6 @@ struct CPUState {/* Used for user-only emulation of prctl(PR_SET_UNALIGN). */ bool prctl_unalign_sigbus; -struct hvf_vcpu_state *hvf; -/* track IOMMUs whose translations we've cached in the TCG TLB */ GArray *iommu_notifiers; };
include/sysemu/hvf_int.h +1 -1
@@ -48,7 +48,7 @@ struct HVFState { };extern HVFState *hvf_state; -struct hvf_vcpu_state { +struct AccelvCPUState {uint64_t fd;void *exit;bool vtimer_masked;
accel/hvf/hvf-accel-ops.c +8 -8
@@ -363,19 +363,19 @@ type_init(hvf_type_init);static void hvf_vcpu_destroy (CPUState *cpu) { -hv_return_t ret =hv_vcpu_destroy (cpu->hvf->fd); +hv_return_t ret =hv_vcpu_destroy (cpu->accel->fd);assert_hvf_ok (ret);hvf_arch_vcpu_destroy (cpu); -g_free (cpu->hvf); - cpu->hvf =NULL ; +g_free (cpu->accel); + cpu->accel =NULL ; }static int hvf_init_vcpu (CPUState *cpu) {int r; - cpu->hvf =g_malloc0 (sizeof (*cpu->hvf)); + cpu->accel = g_new0(struct AccelvCPUState, 1);/* init cpu signals */ struct sigaction sigact;
@@ -384,13 +384,13 @@ static int hvf_init_vcpu(CPUState *cpu) sigact.sa_handler = dummy_signal;sigaction (SIG_IPI , &sigact,NULL ); -pthread_sigmask (SIG_BLOCK ,NULL , &cpu->hvf->unblock_ipi_mask); -sigdelset (&cpu->hvf->unblock_ipi_mask,SIG_IPI ); +pthread_sigmask (SIG_BLOCK ,NULL , &cpu->accel->unblock_ipi_mask); +sigdelset (&cpu->accel->unblock_ipi_mask,SIG_IPI );#ifdef __aarch64__ - r =hv_vcpu_create (&cpu->hvf->fd, (hv_vcpu_exit_t **)&cpu->hvf->exit,NULL ); + r =hv_vcpu_create (&cpu->accel->fd, (hv_vcpu_exit_t **)&cpu->accel->exit,NULL );#else - r =hv_vcpu_create ((hv_vcpuid_t *)&cpu->hvf->fd,HV_VCPU_DEFAULT ); + r =hv_vcpu_create ((hv_vcpuid_t *)&cpu->accel->fd,HV_VCPU_DEFAULT );#endif cpu->vcpu_dirty =1 ;assert_hvf_ok (r);
target/arm/hvf/hvf.c +35 -35
234 lines not on this page · raw message
Signature · 1 line
2.38.1
Re: [PATCH 14/14] accel: Rename HVF struct hvf_vcpu_state -> struct AccelvCPUState
Quoted 9 lines · Philippe Mathieu-Daudé
We want all accelerators to share the same opaque pointer in CPUState.
Rename the '
hvf_vcpu_state' structure as 'AccelvCPUState'.Use the generic 'accel' field of CPUState instead of 'hvf'.
Replace
g_malloc0()byg_new0()for readability.
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- include/hw/core/cpu.h | 3 -- include/sysemu/hvf_int.h | 2 +- accel/hvf/hvf-accel-ops.c | 16 ++++----- target/arm/hvf/hvf.c | 70 +++++++++++++++++++-------------------- 4 files changed, 44 insertions(+), 47 deletions(-)
r~