* [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF)
@ 2023-04-05 10:17 Philippe Mathieu-Daudé
2023-04-05 10:17 ` [PATCH 01/14] accel: Document generic accelerator headers Philippe Mathieu-Daudé
` (13 more replies)
0 siblings, 14 replies; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:17 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé
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(-)
--
2.38.1
^ permalink raw reply [flat|nested] 29+ messages in thread
* [PATCH 01/14] accel: Document generic accelerator headers
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
@ 2023-04-05 10:17 ` Philippe Mathieu-Daudé
2023-04-07 23:01 ` Richard Henderson
2023-04-05 10:17 ` [PATCH 02/14] accel: Remove unused hThread variable on TCG/WHPX Philippe Mathieu-Daudé
` (12 subsequent siblings)
13 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:17 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé, Reinoud Zandijk, Richard Henderson,
Sunil Muthuswamy, Stefano Stabellini, Anthony Perard,
Paul Durrant
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é <philmd@linaro.org>
---
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(+)
diff --git a/include/sysemu/hax.h b/include/sysemu/hax.h
index bf8f99a824..80fc716f80 100644
--- a/include/sysemu/hax.h
+++ b/include/sysemu/hax.h
@@ -19,6 +19,8 @@
*
*/
+/* header to be included in non-HAX-specific code */
+
#ifndef QEMU_HAX_H
#define QEMU_HAX_H
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index c8281c07a7..cc6c678ed8 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -11,6 +11,8 @@
*
*/
+/* header to be included in non-KVM-specific code */
+
#ifndef QEMU_KVM_H
#define QEMU_KVM_H
diff --git a/include/sysemu/nvmm.h b/include/sysemu/nvmm.h
index 833670fccb..be7bc9a62d 100644
--- a/include/sysemu/nvmm.h
+++ b/include/sysemu/nvmm.h
@@ -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
diff --git a/include/sysemu/tcg.h b/include/sysemu/tcg.h
index 53352450ff..5e2ca9aab3 100644
--- a/include/sysemu/tcg.h
+++ b/include/sysemu/tcg.h
@@ -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
diff --git a/include/sysemu/whpx.h b/include/sysemu/whpx.h
index 2889fa2278..781ca5b2b6 100644
--- a/include/sysemu/whpx.h
+++ b/include/sysemu/whpx.h
@@ -10,6 +10,8 @@
*
*/
+/* header to be included in non-WHPX-specific code */
+
#ifndef QEMU_WHPX_H
#define QEMU_WHPX_H
diff --git a/include/sysemu/xen.h b/include/sysemu/xen.h
index 0ca25697e4..bc13ad5692 100644
--- a/include/sysemu/xen.h
+++ b/include/sysemu/xen.h
@@ -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
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 02/14] accel: Remove unused hThread variable on TCG/WHPX
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
2023-04-05 10:17 ` [PATCH 01/14] accel: Document generic accelerator headers Philippe Mathieu-Daudé
@ 2023-04-05 10:17 ` Philippe Mathieu-Daudé
2023-04-07 23:01 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 03/14] accel: Fix a leak on Windows HAX Philippe Mathieu-Daudé
` (11 subsequent siblings)
13 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:17 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé, Richard Henderson, Sunil Muthuswamy
On Windows hosts, cpu->hThread is assigned but never accessed:
remove it.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
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(-)
diff --git a/accel/tcg/tcg-accel-ops-mttcg.c b/accel/tcg/tcg-accel-ops-mttcg.c
index d50239e0e2..19cfb26c02 100644
--- a/accel/tcg/tcg-accel-ops-mttcg.c
+++ b/accel/tcg/tcg-accel-ops-mttcg.c
@@ -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
}
diff --git a/accel/tcg/tcg-accel-ops-rr.c b/accel/tcg/tcg-accel-ops-rr.c
index 290833a37f..dafff71530 100644
--- a/accel/tcg/tcg-accel-ops-rr.c
+++ b/accel/tcg/tcg-accel-ops-rr.c
@@ -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;
diff --git a/target/i386/whpx/whpx-accel-ops.c b/target/i386/whpx/whpx-accel-ops.c
index e8dc4b3a47..67cad86720 100644
--- a/target/i386/whpx/whpx-accel-ops.c
+++ b/target/i386/whpx/whpx-accel-ops.c
@@ -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)
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 03/14] accel: Fix a leak on Windows HAX
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
2023-04-05 10:17 ` [PATCH 01/14] accel: Document generic accelerator headers Philippe Mathieu-Daudé
2023-04-05 10:17 ` [PATCH 02/14] accel: Remove unused hThread variable on TCG/WHPX Philippe Mathieu-Daudé
@ 2023-04-05 10:18 ` Philippe Mathieu-Daudé
2023-04-07 23:01 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 04/14] accel: Destroy HAX vCPU threads once done Philippe Mathieu-Daudé
` (10 subsequent siblings)
13 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:18 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
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é <philmd@linaro.org>
---
target/i386/hax/hax-all.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/target/i386/hax/hax-all.c b/target/i386/hax/hax-all.c
index 3e5992a63b..a2321a1eff 100644
--- a/target/i386/hax/hax-all.c
+++ b/target/i386/hax/hax-all.c
@@ -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;
}
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 04/14] accel: Destroy HAX vCPU threads once done
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2023-04-05 10:18 ` [PATCH 03/14] accel: Fix a leak on Windows HAX Philippe Mathieu-Daudé
@ 2023-04-05 10:18 ` Philippe Mathieu-Daudé
2023-04-05 10:18 ` [PATCH 05/14] accel: Rename 'hax_vcpu' as 'accel' in CPUState Philippe Mathieu-Daudé
` (9 subsequent siblings)
13 siblings, 0 replies; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:18 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
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.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/i386/hax/hax-accel-ops.c | 3 +++
target/i386/hax/hax-all.c | 1 +
2 files changed, 4 insertions(+)
diff --git a/target/i386/hax/hax-accel-ops.c b/target/i386/hax/hax-accel-ops.c
index 18114fe34d..0157a628a3 100644
--- a/target/i386/hax/hax-accel-ops.c
+++ b/target/i386/hax/hax-accel-ops.c
@@ -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
diff --git a/target/i386/hax/hax-all.c b/target/i386/hax/hax-all.c
index a2321a1eff..38a4323a3c 100644
--- a/target/i386/hax/hax-all.c
+++ b/target/i386/hax/hax-all.c
@@ -209,6 +209,7 @@ int hax_vcpu_destroy(CPUState *cpu)
CloseHandle(cpu->hThread);
#endif
g_free(vcpu);
+ cpu->hax_vcpu = NULL;
return 0;
}
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 05/14] accel: Rename 'hax_vcpu' as 'accel' in CPUState
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2023-04-05 10:18 ` [PATCH 04/14] accel: Destroy HAX vCPU threads once done Philippe Mathieu-Daudé
@ 2023-04-05 10:18 ` Philippe Mathieu-Daudé
2023-04-07 23:03 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 06/14] accel: Use a typedef for struct hax_vcpu_state Philippe Mathieu-Daudé
` (8 subsequent siblings)
13 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:18 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé, Eduardo Habkost, Marcel Apfelbaum,
Yanan Wang, Reinoud Zandijk, Sunil Muthuswamy
All accelerators will share a single opaque context
in CPUState. Start by renaming 'hax_vcpu' as 'accelCPUState'.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
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(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 397fd3ac68..193494cde4 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -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;
diff --git a/target/i386/hax/hax-accel-ops.c b/target/i386/hax/hax-accel-ops.c
index 0157a628a3..a8512efcd5 100644
--- a/target/i386/hax/hax-accel-ops.c
+++ b/target/i386/hax/hax-accel-ops.c
@@ -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
diff --git a/target/i386/hax/hax-all.c b/target/i386/hax/hax-all.c
index 38a4323a3c..3865ff9419 100644
--- a/target/i386/hax/hax-all.c
+++ b/target/i386/hax/hax-all.c
@@ -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;
}
}
diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
index b75738ee9c..cf4f0af24b 100644
--- a/target/i386/nvmm/nvmm-all.c
+++ b/target/i386/nvmm/nvmm-all.c
@@ -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);
}
/* -------------------------------------------------------------------------- */
diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c
index 52af81683c..d1ad6f156a 100644
--- a/target/i386/whpx/whpx-all.c
+++ b/target/i386/whpx/whpx-all.c
@@ -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;
}
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 06/14] accel: Use a typedef for struct hax_vcpu_state
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2023-04-05 10:18 ` [PATCH 05/14] accel: Rename 'hax_vcpu' as 'accel' in CPUState Philippe Mathieu-Daudé
@ 2023-04-05 10:18 ` Philippe Mathieu-Daudé
2023-04-05 10:18 ` [PATCH 07/14] accel: Rename struct hax_vcpu_state -> struct AccelvCPUState Philippe Mathieu-Daudé
` (7 subsequent siblings)
13 siblings, 0 replies; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:18 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé
Use a type definition instead of explicit structure.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
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(-)
diff --git a/target/i386/hax/hax-i386.h b/target/i386/hax/hax-i386.h
index 409ebdb4af..3cb3b9bbd0 100644
--- a/target/i386/hax/hax-i386.h
+++ b/target/i386/hax/hax-i386.h
@@ -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);
diff --git a/target/i386/hax/hax-all.c b/target/i386/hax/hax-all.c
index 3865ff9419..a55b18f353 100644
--- a/target/i386/hax/hax-all.c
+++ b/target/i386/hax/hax-all.c
@@ -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()) {
diff --git a/target/i386/hax/hax-posix.c b/target/i386/hax/hax-posix.c
index ac1a51096e..8ee247845b 100644
--- a/target/i386/hax/hax-posix.c
+++ b/target/i386/hax/hax-posix.c
@@ -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);
}
diff --git a/target/i386/hax/hax-windows.c b/target/i386/hax/hax-windows.c
index 59afa213a6..08ec93a256 100644
--- a/target/i386/hax/hax-windows.c
+++ b/target/i386/hax/hax-windows.c
@@ -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;
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 07/14] accel: Rename struct hax_vcpu_state -> struct AccelvCPUState
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2023-04-05 10:18 ` [PATCH 06/14] accel: Use a typedef for struct hax_vcpu_state Philippe Mathieu-Daudé
@ 2023-04-05 10:18 ` Philippe Mathieu-Daudé
2023-04-07 23:07 ` Richard Henderson
2023-04-07 23:09 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 08/14] accel: Move HAX hThread to accelerator context Philippe Mathieu-Daudé
` (6 subsequent siblings)
13 siblings, 2 replies; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:18 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé, Eduardo Habkost, Marcel Apfelbaum,
Yanan Wang, Reinoud Zandijk, Sunil Muthuswamy
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é <philmd@linaro.org>
---
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(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 193494cde4..173f47d24e 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -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 */
diff --git a/target/i386/hax/hax-i386.h b/target/i386/hax/hax-i386.h
index 3cb3b9bbd0..d11d43e857 100644
--- a/target/i386/hax/hax-i386.h
+++ b/target/i386/hax/hax-i386.h
@@ -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;
diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
index cf4f0af24b..3c7bdd560f 100644
--- a/target/i386/nvmm/nvmm-all.c
+++ b/target/i386/nvmm/nvmm-all.c
@@ -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;
}
diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c
index d1ad6f156a..70eadb7f05 100644
--- a/target/i386/whpx/whpx-all.c
+++ b/target/i386/whpx/whpx-all.c
@@ -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);
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 08/14] accel: Move HAX hThread to accelerator context
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2023-04-05 10:18 ` [PATCH 07/14] accel: Rename struct hax_vcpu_state -> struct AccelvCPUState Philippe Mathieu-Daudé
@ 2023-04-05 10:18 ` Philippe Mathieu-Daudé
2023-04-07 23:07 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO() Philippe Mathieu-Daudé
` (5 subsequent siblings)
13 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:18 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé, Eduardo Habkost, Marcel Apfelbaum,
Yanan Wang
hThread variable is only used by the HAX accelerator,
so move it to the accelerator specific context.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
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(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 173f47d24e..8d27861ed5 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -334,7 +334,6 @@ struct CPUState {
struct QemuThread *thread;
#ifdef _WIN32
- HANDLE hThread;
QemuSemaphore sem;
#endif
int thread_id;
diff --git a/target/i386/hax/hax-i386.h b/target/i386/hax/hax-i386.h
index d11d43e857..15d16772db 100644
--- a/target/i386/hax/hax-i386.h
+++ b/target/i386/hax/hax-i386.h
@@ -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;
diff --git a/target/i386/hax/hax-accel-ops.c b/target/i386/hax/hax-accel-ops.c
index a8512efcd5..5031096760 100644
--- a/target/i386/hax/hax-accel-ops.c
+++ b/target/i386/hax/hax-accel-ops.c
@@ -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
}
diff --git a/target/i386/hax/hax-all.c b/target/i386/hax/hax-all.c
index a55b18f353..c9ccc411e9 100644
--- a/target/i386/hax/hax-all.c
+++ b/target/i386/hax/hax-all.c
@@ -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;
diff --git a/target/i386/hax/hax-windows.c b/target/i386/hax/hax-windows.c
index 08ec93a256..b907953321 100644
--- a/target/i386/hax/hax-windows.c
+++ b/target/i386/hax/hax-windows.c
@@ -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);
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO()
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
` (7 preceding siblings ...)
2023-04-05 10:18 ` [PATCH 08/14] accel: Move HAX hThread to accelerator context Philippe Mathieu-Daudé
@ 2023-04-05 10:18 ` Philippe Mathieu-Daudé
2023-04-05 13:55 ` Alex Bennée
2023-04-05 10:18 ` [PATCH 10/14] accel: Rename NVMM struct qemu_vcpu -> struct AccelvCPUState Philippe Mathieu-Daudé
` (4 subsequent siblings)
13 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:18 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé, Reinoud Zandijk
g_malloc0() can not fail. Use g_try_malloc0() instead.
https://developer-old.gnome.org/glib/stable/glib-Memory-Allocation.html#glib-Memory-Allocation.description
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/i386/nvmm/nvmm-all.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
index 3c7bdd560f..45fd318d23 100644
--- a/target/i386/nvmm/nvmm-all.c
+++ b/target/i386/nvmm/nvmm-all.c
@@ -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;
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 10/14] accel: Rename NVMM struct qemu_vcpu -> struct AccelvCPUState
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
` (8 preceding siblings ...)
2023-04-05 10:18 ` [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO() Philippe Mathieu-Daudé
@ 2023-04-05 10:18 ` Philippe Mathieu-Daudé
2023-04-07 23:11 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 11/14] accel: Inline NVMM get_qemu_vcpu() Philippe Mathieu-Daudé
` (3 subsequent siblings)
13 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:18 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé, Reinoud Zandijk
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.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/i386/nvmm/nvmm-all.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
index 45fd318d23..97a7225598 100644
--- a/target/i386/nvmm/nvmm-all.c
+++ b/target/i386/nvmm/nvmm-all.c
@@ -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);
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 11/14] accel: Inline NVMM get_qemu_vcpu()
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
` (9 preceding siblings ...)
2023-04-05 10:18 ` [PATCH 10/14] accel: Rename NVMM struct qemu_vcpu -> struct AccelvCPUState Philippe Mathieu-Daudé
@ 2023-04-05 10:18 ` Philippe Mathieu-Daudé
2023-04-07 23:11 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 12/14] accel: Rename WHPX struct whpx_vcpu -> struct AccelvCPUState Philippe Mathieu-Daudé
` (2 subsequent siblings)
13 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:18 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé, Reinoud Zandijk
No need for this helper to access the CPUState::accel field.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/i386/nvmm/nvmm-all.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
index 97a7225598..1c0168d83c 100644
--- a/target/i386/nvmm/nvmm-all.c
+++ b/target/i386/nvmm/nvmm-all.c
@@ -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);
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 12/14] accel: Rename WHPX struct whpx_vcpu -> struct AccelvCPUState
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
` (10 preceding siblings ...)
2023-04-05 10:18 ` [PATCH 11/14] accel: Inline NVMM get_qemu_vcpu() Philippe Mathieu-Daudé
@ 2023-04-05 10:18 ` Philippe Mathieu-Daudé
2023-04-07 23:13 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 13/14] accel: Inline WHPX get_whpx_vcpu() Philippe Mathieu-Daudé
2023-04-05 10:18 ` [PATCH 14/14] accel: Rename HVF struct hvf_vcpu_state -> struct AccelvCPUState Philippe Mathieu-Daudé
13 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:18 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé, Sunil Muthuswamy
We want all accelerators to share the same opaque pointer in
CPUState. Rename WHPX 'whpx_vcpu' as 'AccelvCPUState'.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/i386/whpx/whpx-all.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c
index 70eadb7f05..2372c4227a 100644
--- a/target/i386/whpx/whpx-all.c
+++ b/target/i386/whpx/whpx-all.c
@@ -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);
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 13/14] accel: Inline WHPX get_whpx_vcpu()
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
` (11 preceding siblings ...)
2023-04-05 10:18 ` [PATCH 12/14] accel: Rename WHPX struct whpx_vcpu -> struct AccelvCPUState Philippe Mathieu-Daudé
@ 2023-04-05 10:18 ` Philippe Mathieu-Daudé
2023-04-07 23:13 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 14/14] accel: Rename HVF struct hvf_vcpu_state -> struct AccelvCPUState Philippe Mathieu-Daudé
13 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:18 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé, Sunil Muthuswamy
No need for this helper to access the CPUState::accel field.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/i386/whpx/whpx-all.c | 29 ++++++++++-------------------
1 file changed, 10 insertions(+), 19 deletions(-)
diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c
index 2372c4227a..2cca6bc004 100644
--- a/target/i386/whpx/whpx-all.c
+++ b/target/i386/whpx/whpx-all.c
@@ -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);
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [PATCH 14/14] accel: Rename HVF struct hvf_vcpu_state -> struct AccelvCPUState
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
` (12 preceding siblings ...)
2023-04-05 10:18 ` [PATCH 13/14] accel: Inline WHPX get_whpx_vcpu() Philippe Mathieu-Daudé
@ 2023-04-05 10:18 ` Philippe Mathieu-Daudé
2023-04-07 23:14 ` Richard Henderson
13 siblings, 1 reply; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 10:18 UTC (permalink / raw)
To: qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm,
Philippe Mathieu-Daudé, Cameron Esfahani, Roman Bolshakov,
Eduardo Habkost, Marcel Apfelbaum, Yanan Wang, Alexander Graf,
Peter Maydell, qemu-arm
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.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
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(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 8d27861ed5..1dc5efe650 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -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;
};
diff --git a/include/sysemu/hvf_int.h b/include/sysemu/hvf_int.h
index 6545f7cd61..96ef51f4df 100644
--- a/include/sysemu/hvf_int.h
+++ b/include/sysemu/hvf_int.h
@@ -48,7 +48,7 @@ struct HVFState {
};
extern HVFState *hvf_state;
-struct hvf_vcpu_state {
+struct AccelvCPUState {
uint64_t fd;
void *exit;
bool vtimer_masked;
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index 24913ca9c4..06ca1d59a4 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -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);
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index ad65603445..b85648b61c 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -366,29 +366,29 @@ int hvf_get_registers(CPUState *cpu)
int i;
for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) {
- ret = hv_vcpu_get_reg(cpu->hvf->fd, hvf_reg_match[i].reg, &val);
+ ret = hv_vcpu_get_reg(cpu->accel->fd, hvf_reg_match[i].reg, &val);
*(uint64_t *)((void *)env + hvf_reg_match[i].offset) = val;
assert_hvf_ok(ret);
}
for (i = 0; i < ARRAY_SIZE(hvf_fpreg_match); i++) {
- ret = hv_vcpu_get_simd_fp_reg(cpu->hvf->fd, hvf_fpreg_match[i].reg,
+ ret = hv_vcpu_get_simd_fp_reg(cpu->accel->fd, hvf_fpreg_match[i].reg,
&fpval);
memcpy((void *)env + hvf_fpreg_match[i].offset, &fpval, sizeof(fpval));
assert_hvf_ok(ret);
}
val = 0;
- ret = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_FPCR, &val);
+ ret = hv_vcpu_get_reg(cpu->accel->fd, HV_REG_FPCR, &val);
assert_hvf_ok(ret);
vfp_set_fpcr(env, val);
val = 0;
- ret = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_FPSR, &val);
+ ret = hv_vcpu_get_reg(cpu->accel->fd, HV_REG_FPSR, &val);
assert_hvf_ok(ret);
vfp_set_fpsr(env, val);
- ret = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_CPSR, &val);
+ ret = hv_vcpu_get_reg(cpu->accel->fd, HV_REG_CPSR, &val);
assert_hvf_ok(ret);
pstate_write(env, val);
@@ -397,7 +397,7 @@ int hvf_get_registers(CPUState *cpu)
continue;
}
- ret = hv_vcpu_get_sys_reg(cpu->hvf->fd, hvf_sreg_match[i].reg, &val);
+ ret = hv_vcpu_get_sys_reg(cpu->accel->fd, hvf_sreg_match[i].reg, &val);
assert_hvf_ok(ret);
arm_cpu->cpreg_values[hvf_sreg_match[i].cp_idx] = val;
@@ -420,24 +420,24 @@ int hvf_put_registers(CPUState *cpu)
for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) {
val = *(uint64_t *)((void *)env + hvf_reg_match[i].offset);
- ret = hv_vcpu_set_reg(cpu->hvf->fd, hvf_reg_match[i].reg, val);
+ ret = hv_vcpu_set_reg(cpu->accel->fd, hvf_reg_match[i].reg, val);
assert_hvf_ok(ret);
}
for (i = 0; i < ARRAY_SIZE(hvf_fpreg_match); i++) {
memcpy(&fpval, (void *)env + hvf_fpreg_match[i].offset, sizeof(fpval));
- ret = hv_vcpu_set_simd_fp_reg(cpu->hvf->fd, hvf_fpreg_match[i].reg,
+ ret = hv_vcpu_set_simd_fp_reg(cpu->accel->fd, hvf_fpreg_match[i].reg,
fpval);
assert_hvf_ok(ret);
}
- ret = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_FPCR, vfp_get_fpcr(env));
+ ret = hv_vcpu_set_reg(cpu->accel->fd, HV_REG_FPCR, vfp_get_fpcr(env));
assert_hvf_ok(ret);
- ret = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_FPSR, vfp_get_fpsr(env));
+ ret = hv_vcpu_set_reg(cpu->accel->fd, HV_REG_FPSR, vfp_get_fpsr(env));
assert_hvf_ok(ret);
- ret = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_CPSR, pstate_read(env));
+ ret = hv_vcpu_set_reg(cpu->accel->fd, HV_REG_CPSR, pstate_read(env));
assert_hvf_ok(ret);
aarch64_save_sp(env, arm_current_el(env));
@@ -449,11 +449,11 @@ int hvf_put_registers(CPUState *cpu)
}
val = arm_cpu->cpreg_values[hvf_sreg_match[i].cp_idx];
- ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, hvf_sreg_match[i].reg, val);
+ ret = hv_vcpu_set_sys_reg(cpu->accel->fd, hvf_sreg_match[i].reg, val);
assert_hvf_ok(ret);
}
- ret = hv_vcpu_set_vtimer_offset(cpu->hvf->fd, hvf_state->vtimer_offset);
+ ret = hv_vcpu_set_vtimer_offset(cpu->accel->fd, hvf_state->vtimer_offset);
assert_hvf_ok(ret);
return 0;
@@ -474,7 +474,7 @@ static void hvf_set_reg(CPUState *cpu, int rt, uint64_t val)
flush_cpu_state(cpu);
if (rt < 31) {
- r = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_X0 + rt, val);
+ r = hv_vcpu_set_reg(cpu->accel->fd, HV_REG_X0 + rt, val);
assert_hvf_ok(r);
}
}
@@ -487,7 +487,7 @@ static uint64_t hvf_get_reg(CPUState *cpu, int rt)
flush_cpu_state(cpu);
if (rt < 31) {
- r = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_X0 + rt, &val);
+ r = hv_vcpu_get_reg(cpu->accel->fd, HV_REG_X0 + rt, &val);
assert_hvf_ok(r);
}
@@ -629,22 +629,22 @@ int hvf_arch_init_vcpu(CPUState *cpu)
assert(write_cpustate_to_list(arm_cpu, false));
/* Set CP_NO_RAW system registers on init */
- ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, HV_SYS_REG_MIDR_EL1,
+ ret = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_MIDR_EL1,
arm_cpu->midr);
assert_hvf_ok(ret);
- ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, HV_SYS_REG_MPIDR_EL1,
+ ret = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_MPIDR_EL1,
arm_cpu->mp_affinity);
assert_hvf_ok(ret);
- ret = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_ID_AA64PFR0_EL1, &pfr);
+ ret = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_ID_AA64PFR0_EL1, &pfr);
assert_hvf_ok(ret);
pfr |= env->gicv3state ? (1 << 24) : 0;
- ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, HV_SYS_REG_ID_AA64PFR0_EL1, pfr);
+ ret = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_ID_AA64PFR0_EL1, pfr);
assert_hvf_ok(ret);
/* We're limited to underlying hardware caps, override internal versions */
- ret = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_ID_AA64MMFR0_EL1,
+ ret = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_ID_AA64MMFR0_EL1,
&arm_cpu->isar.id_aa64mmfr0);
assert_hvf_ok(ret);
@@ -654,7 +654,7 @@ int hvf_arch_init_vcpu(CPUState *cpu)
void hvf_kick_vcpu_thread(CPUState *cpu)
{
cpus_kick_thread(cpu);
- hv_vcpus_exit(&cpu->hvf->fd, 1);
+ hv_vcpus_exit(&cpu->accel->fd, 1);
}
static void hvf_raise_exception(CPUState *cpu, uint32_t excp,
@@ -1191,13 +1191,13 @@ static int hvf_inject_interrupts(CPUState *cpu)
{
if (cpu->interrupt_request & CPU_INTERRUPT_FIQ) {
trace_hvf_inject_fiq();
- hv_vcpu_set_pending_interrupt(cpu->hvf->fd, HV_INTERRUPT_TYPE_FIQ,
+ hv_vcpu_set_pending_interrupt(cpu->accel->fd, HV_INTERRUPT_TYPE_FIQ,
true);
}
if (cpu->interrupt_request & CPU_INTERRUPT_HARD) {
trace_hvf_inject_irq();
- hv_vcpu_set_pending_interrupt(cpu->hvf->fd, HV_INTERRUPT_TYPE_IRQ,
+ hv_vcpu_set_pending_interrupt(cpu->accel->fd, HV_INTERRUPT_TYPE_IRQ,
true);
}
@@ -1231,7 +1231,7 @@ static void hvf_wait_for_ipi(CPUState *cpu, struct timespec *ts)
*/
qatomic_mb_set(&cpu->thread_kicked, false);
qemu_mutex_unlock_iothread();
- pselect(0, 0, 0, 0, ts, &cpu->hvf->unblock_ipi_mask);
+ pselect(0, 0, 0, 0, ts, &cpu->accel->unblock_ipi_mask);
qemu_mutex_lock_iothread();
}
@@ -1252,7 +1252,7 @@ static void hvf_wfi(CPUState *cpu)
return;
}
- r = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_CNTV_CTL_EL0, &ctl);
+ r = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, &ctl);
assert_hvf_ok(r);
if (!(ctl & 1) || (ctl & 2)) {
@@ -1261,7 +1261,7 @@ static void hvf_wfi(CPUState *cpu)
return;
}
- r = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_CNTV_CVAL_EL0, &cval);
+ r = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, &cval);
assert_hvf_ok(r);
ticks_to_sleep = cval - hvf_vtimer_val();
@@ -1294,12 +1294,12 @@ static void hvf_sync_vtimer(CPUState *cpu)
uint64_t ctl;
bool irq_state;
- if (!cpu->hvf->vtimer_masked) {
+ if (!cpu->accel->vtimer_masked) {
/* We will get notified on vtimer changes by hvf, nothing to do */
return;
}
- r = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_CNTV_CTL_EL0, &ctl);
+ r = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, &ctl);
assert_hvf_ok(r);
irq_state = (ctl & (TMR_CTL_ENABLE | TMR_CTL_IMASK | TMR_CTL_ISTATUS)) ==
@@ -1308,8 +1308,8 @@ static void hvf_sync_vtimer(CPUState *cpu)
if (!irq_state) {
/* Timer no longer asserting, we can unmask it */
- hv_vcpu_set_vtimer_mask(cpu->hvf->fd, false);
- cpu->hvf->vtimer_masked = false;
+ hv_vcpu_set_vtimer_mask(cpu->accel->fd, false);
+ cpu->accel->vtimer_masked = false;
}
}
@@ -1317,7 +1317,7 @@ int hvf_vcpu_exec(CPUState *cpu)
{
ARMCPU *arm_cpu = ARM_CPU(cpu);
CPUARMState *env = &arm_cpu->env;
- hv_vcpu_exit_t *hvf_exit = cpu->hvf->exit;
+ hv_vcpu_exit_t *hvf_exit = cpu->accel->exit;
hv_return_t r;
bool advance_pc = false;
@@ -1332,7 +1332,7 @@ int hvf_vcpu_exec(CPUState *cpu)
flush_cpu_state(cpu);
qemu_mutex_unlock_iothread();
- assert_hvf_ok(hv_vcpu_run(cpu->hvf->fd));
+ assert_hvf_ok(hv_vcpu_run(cpu->accel->fd));
/* handle VMEXIT */
uint64_t exit_reason = hvf_exit->reason;
@@ -1346,7 +1346,7 @@ int hvf_vcpu_exec(CPUState *cpu)
break;
case HV_EXIT_REASON_VTIMER_ACTIVATED:
qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], 1);
- cpu->hvf->vtimer_masked = true;
+ cpu->accel->vtimer_masked = true;
return 0;
case HV_EXIT_REASON_CANCELED:
/* we got kicked, no exit to process */
@@ -1457,10 +1457,10 @@ int hvf_vcpu_exec(CPUState *cpu)
flush_cpu_state(cpu);
- r = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_PC, &pc);
+ r = hv_vcpu_get_reg(cpu->accel->fd, HV_REG_PC, &pc);
assert_hvf_ok(r);
pc += 4;
- r = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_PC, pc);
+ r = hv_vcpu_set_reg(cpu->accel->fd, HV_REG_PC, pc);
assert_hvf_ok(r);
}
--
2.38.1
^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO()
2023-04-05 10:18 ` [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO() Philippe Mathieu-Daudé
@ 2023-04-05 13:55 ` Alex Bennée
2023-04-05 15:18 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 29+ messages in thread
From: Alex Bennée @ 2023-04-05 13:55 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Paolo Bonzini, xen-devel, kvm, Reinoud Zandijk
Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> g_malloc0() can not fail. Use g_try_malloc0() instead.
>
> https://developer-old.gnome.org/glib/stable/glib-Memory-Allocation.html#glib-Memory-Allocation.description
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> target/i386/nvmm/nvmm-all.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
> index 3c7bdd560f..45fd318d23 100644
> --- a/target/i386/nvmm/nvmm-all.c
> +++ b/target/i386/nvmm/nvmm-all.c
> @@ -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.
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO()
2023-04-05 13:55 ` Alex Bennée
@ 2023-04-05 15:18 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-04-05 15:18 UTC (permalink / raw)
To: Alex Bennée
Cc: qemu-devel, Paolo Bonzini, xen-devel, kvm, Reinoud Zandijk
On 5/4/23 15:55, Alex Bennée wrote:
>
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
>
>> g_malloc0() can not fail. Use g_try_malloc0() instead.
>>
>> https://developer-old.gnome.org/glib/stable/glib-Memory-Allocation.html#glib-Memory-Allocation.description
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>> target/i386/nvmm/nvmm-all.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c
>> index 3c7bdd560f..45fd318d23 100644
>> --- a/target/i386/nvmm/nvmm-all.c
>> +++ b/target/i386/nvmm/nvmm-all.c
>> @@ -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.
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.
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 01/14] accel: Document generic accelerator headers
2023-04-05 10:17 ` [PATCH 01/14] accel: Document generic accelerator headers Philippe Mathieu-Daudé
@ 2023-04-07 23:01 ` Richard Henderson
0 siblings, 0 replies; 29+ messages in thread
From: Richard Henderson @ 2023-04-07 23:01 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm, Reinoud Zandijk,
Sunil Muthuswamy, Stefano Stabellini, Anthony Perard,
Paul Durrant
On 4/5/23 03:17, Philippe Mathieu-Daudé wrote:
> 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é<philmd@linaro.org>
> ---
> 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(+)
Acked-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 02/14] accel: Remove unused hThread variable on TCG/WHPX
2023-04-05 10:17 ` [PATCH 02/14] accel: Remove unused hThread variable on TCG/WHPX Philippe Mathieu-Daudé
@ 2023-04-07 23:01 ` Richard Henderson
0 siblings, 0 replies; 29+ messages in thread
From: Richard Henderson @ 2023-04-07 23:01 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm, Sunil Muthuswamy
On 4/5/23 03:17, Philippe Mathieu-Daudé wrote:
> On Windows hosts, cpu->hThread is assigned but never accessed:
> remove it.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> 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(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 03/14] accel: Fix a leak on Windows HAX
2023-04-05 10:18 ` [PATCH 03/14] accel: Fix a leak on Windows HAX Philippe Mathieu-Daudé
@ 2023-04-07 23:01 ` Richard Henderson
0 siblings, 0 replies; 29+ messages in thread
From: Richard Henderson @ 2023-04-07 23:01 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm
On 4/5/23 03:18, Philippe Mathieu-Daudé wrote:
> 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é<philmd@linaro.org>
> ---
> target/i386/hax/hax-all.c | 3 +++
> 1 file changed, 3 insertions(+)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 05/14] accel: Rename 'hax_vcpu' as 'accel' in CPUState
2023-04-05 10:18 ` [PATCH 05/14] accel: Rename 'hax_vcpu' as 'accel' in CPUState Philippe Mathieu-Daudé
@ 2023-04-07 23:03 ` Richard Henderson
0 siblings, 0 replies; 29+ messages in thread
From: Richard Henderson @ 2023-04-07 23:03 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm, Eduardo Habkost,
Marcel Apfelbaum, Yanan Wang, Reinoud Zandijk, Sunil Muthuswamy
On 4/5/23 03:18, Philippe Mathieu-Daudé wrote:
> All accelerators will share a single opaque context
> in CPUState. Start by renaming 'hax_vcpu' as 'accelCPUState'.
Pasto in 'accel' here.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 07/14] accel: Rename struct hax_vcpu_state -> struct AccelvCPUState
2023-04-05 10:18 ` [PATCH 07/14] accel: Rename struct hax_vcpu_state -> struct AccelvCPUState Philippe Mathieu-Daudé
@ 2023-04-07 23:07 ` Richard Henderson
2023-04-07 23:09 ` Richard Henderson
1 sibling, 0 replies; 29+ messages in thread
From: Richard Henderson @ 2023-04-07 23:07 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm, Eduardo Habkost,
Marcel Apfelbaum, Yanan Wang, Reinoud Zandijk, Sunil Muthuswamy
On 4/5/23 03:18, Philippe Mathieu-Daudé wrote:
> 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é<philmd@linaro.org>
> ---
> 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?
> + struct AccelvCPUState *accel;
> /* shared by kvm, hax and hvf */
> bool vcpu_dirty;
Move below the comment? Or is that later?
r~
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 08/14] accel: Move HAX hThread to accelerator context
2023-04-05 10:18 ` [PATCH 08/14] accel: Move HAX hThread to accelerator context Philippe Mathieu-Daudé
@ 2023-04-07 23:07 ` Richard Henderson
0 siblings, 0 replies; 29+ messages in thread
From: Richard Henderson @ 2023-04-07 23:07 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm, Eduardo Habkost,
Marcel Apfelbaum, Yanan Wang
On 4/5/23 03:18, Philippe Mathieu-Daudé wrote:
> hThread variable is only used by the HAX accelerator,
> so move it to the accelerator specific context.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> 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(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 07/14] accel: Rename struct hax_vcpu_state -> struct AccelvCPUState
2023-04-05 10:18 ` [PATCH 07/14] accel: Rename struct hax_vcpu_state -> struct AccelvCPUState Philippe Mathieu-Daudé
2023-04-07 23:07 ` Richard Henderson
@ 2023-04-07 23:09 ` Richard Henderson
1 sibling, 0 replies; 29+ messages in thread
From: Richard Henderson @ 2023-04-07 23:09 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm, Eduardo Habkost,
Marcel Apfelbaum, Yanan Wang, Reinoud Zandijk, Sunil Muthuswamy
On 4/5/23 03:18, Philippe Mathieu-Daudé wrote:
> +struct AccelvCPUState;
Missing typedef?
r~
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 10/14] accel: Rename NVMM struct qemu_vcpu -> struct AccelvCPUState
2023-04-05 10:18 ` [PATCH 10/14] accel: Rename NVMM struct qemu_vcpu -> struct AccelvCPUState Philippe Mathieu-Daudé
@ 2023-04-07 23:11 ` Richard Henderson
0 siblings, 0 replies; 29+ messages in thread
From: Richard Henderson @ 2023-04-07 23:11 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm, Reinoud Zandijk
On 4/5/23 03:18, Philippe Mathieu-Daudé wrote:
> - 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,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> - qcpu = g_try_malloc0(sizeof(*qcpu));
> + qcpu = g_try_new0(struct AccelvCPUState, 1);
Another 'try' to clean up. :-)
r~
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 11/14] accel: Inline NVMM get_qemu_vcpu()
2023-04-05 10:18 ` [PATCH 11/14] accel: Inline NVMM get_qemu_vcpu() Philippe Mathieu-Daudé
@ 2023-04-07 23:11 ` Richard Henderson
0 siblings, 0 replies; 29+ messages in thread
From: Richard Henderson @ 2023-04-07 23:11 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm, Reinoud Zandijk
On 4/5/23 03:18, Philippe Mathieu-Daudé wrote:
> No need for this helper to access the CPUState::accel field.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> target/i386/nvmm/nvmm-all.c | 28 +++++++++++-----------------
> 1 file changed, 11 insertions(+), 17 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 12/14] accel: Rename WHPX struct whpx_vcpu -> struct AccelvCPUState
2023-04-05 10:18 ` [PATCH 12/14] accel: Rename WHPX struct whpx_vcpu -> struct AccelvCPUState Philippe Mathieu-Daudé
@ 2023-04-07 23:13 ` Richard Henderson
0 siblings, 0 replies; 29+ messages in thread
From: Richard Henderson @ 2023-04-07 23:13 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm, Sunil Muthuswamy
On 4/5/23 03:18, Philippe Mathieu-Daudé wrote:
> We want all accelerators to share the same opaque pointer in
> CPUState. Rename WHPX 'whpx_vcpu' as 'AccelvCPUState'.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> target/i386/whpx/whpx-all.c | 30 +++++++++++++++---------------
> 1 file changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c
> index 70eadb7f05..2372c4227a 100644
> --- a/target/i386/whpx/whpx-all.c
> +++ b/target/i386/whpx/whpx-all.c
> @@ -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;
Same comment about removing 'struct'.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> - 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~
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 13/14] accel: Inline WHPX get_whpx_vcpu()
2023-04-05 10:18 ` [PATCH 13/14] accel: Inline WHPX get_whpx_vcpu() Philippe Mathieu-Daudé
@ 2023-04-07 23:13 ` Richard Henderson
0 siblings, 0 replies; 29+ messages in thread
From: Richard Henderson @ 2023-04-07 23:13 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm, Sunil Muthuswamy
On 4/5/23 03:18, Philippe Mathieu-Daudé wrote:
> No need for this helper to access the CPUState::accel field.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> target/i386/whpx/whpx-all.c | 29 ++++++++++-------------------
> 1 file changed, 10 insertions(+), 19 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [PATCH 14/14] accel: Rename HVF struct hvf_vcpu_state -> struct AccelvCPUState
2023-04-05 10:18 ` [PATCH 14/14] accel: Rename HVF struct hvf_vcpu_state -> struct AccelvCPUState Philippe Mathieu-Daudé
@ 2023-04-07 23:14 ` Richard Henderson
0 siblings, 0 replies; 29+ messages in thread
From: Richard Henderson @ 2023-04-07 23:14 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Paolo Bonzini, Alex Bennée, xen-devel, kvm, Cameron Esfahani,
Roman Bolshakov, Eduardo Habkost, Marcel Apfelbaum, Yanan Wang,
Alexander Graf, Peter Maydell, qemu-arm
On 4/5/23 03:18, Philippe Mathieu-Daudé wrote:
> 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.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
> 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(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 29+ messages in thread
end of thread, other threads:[~2023-04-07 23:14 UTC | newest]
Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-05 10:17 [PATCH 00/14] accel: Share CPUState accel context (HAX/NVMM/WHPX/HVF) Philippe Mathieu-Daudé
2023-04-05 10:17 ` [PATCH 01/14] accel: Document generic accelerator headers Philippe Mathieu-Daudé
2023-04-07 23:01 ` Richard Henderson
2023-04-05 10:17 ` [PATCH 02/14] accel: Remove unused hThread variable on TCG/WHPX Philippe Mathieu-Daudé
2023-04-07 23:01 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 03/14] accel: Fix a leak on Windows HAX Philippe Mathieu-Daudé
2023-04-07 23:01 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 04/14] accel: Destroy HAX vCPU threads once done Philippe Mathieu-Daudé
2023-04-05 10:18 ` [PATCH 05/14] accel: Rename 'hax_vcpu' as 'accel' in CPUState Philippe Mathieu-Daudé
2023-04-07 23:03 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 06/14] accel: Use a typedef for struct hax_vcpu_state Philippe Mathieu-Daudé
2023-04-05 10:18 ` [PATCH 07/14] accel: Rename struct hax_vcpu_state -> struct AccelvCPUState Philippe Mathieu-Daudé
2023-04-07 23:07 ` Richard Henderson
2023-04-07 23:09 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 08/14] accel: Move HAX hThread to accelerator context Philippe Mathieu-Daudé
2023-04-07 23:07 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 09/14] accel: Allocate NVMM vCPU using g_try_FOO() Philippe Mathieu-Daudé
2023-04-05 13:55 ` Alex Bennée
2023-04-05 15:18 ` Philippe Mathieu-Daudé
2023-04-05 10:18 ` [PATCH 10/14] accel: Rename NVMM struct qemu_vcpu -> struct AccelvCPUState Philippe Mathieu-Daudé
2023-04-07 23:11 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 11/14] accel: Inline NVMM get_qemu_vcpu() Philippe Mathieu-Daudé
2023-04-07 23:11 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 12/14] accel: Rename WHPX struct whpx_vcpu -> struct AccelvCPUState Philippe Mathieu-Daudé
2023-04-07 23:13 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 13/14] accel: Inline WHPX get_whpx_vcpu() Philippe Mathieu-Daudé
2023-04-07 23:13 ` Richard Henderson
2023-04-05 10:18 ` [PATCH 14/14] accel: Rename HVF struct hvf_vcpu_state -> struct AccelvCPUState Philippe Mathieu-Daudé
2023-04-07 23:14 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).