[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/8] i386: hvf: Implement CPU kick
From: |
Roman Bolshakov |
Subject: |
[PATCH 4/8] i386: hvf: Implement CPU kick |
Date: |
Thu, 25 Jun 2020 01:58:47 +0300 |
HVF doesn't have a CPU kick and without it it's not possible to perform
an action on CPU thread until a VMEXIT happens. The kick is also needed
for timely interrupt delivery.
Existing implementation of CPU kick sends SIG_IPI (aka SIGUSR1) to vCPU
thread, but it's different from what hv_vcpu_interrupt does. The latter
one results in invocation of mp_cpus_kick() in XNU kernel [1].
While at it, correct type of hvf_fd to the type of hv_vcpuid_t to avoid
compilation warnings.
1. https://opensource.apple.com/source/xnu/xnu-6153.81.5/osfmk/i386/mp.c
Cc: Cameron Esfahani <dirty@apple.com>
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
---
cpus.c | 13 +++++++++----
include/hw/core/cpu.h | 2 +-
include/sysemu/hvf.h | 1 +
target/i386/hvf/hvf.c | 11 +++++++++++
4 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/cpus.c b/cpus.c
index 26709677d3..36f38ce5c8 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1783,10 +1783,15 @@ static void qemu_cpu_kick_thread(CPUState *cpu)
return;
}
cpu->thread_kicked = true;
- err = pthread_kill(cpu->thread->thread, SIG_IPI);
- if (err && err != ESRCH) {
- fprintf(stderr, "qemu:%s: %s", __func__, strerror(err));
- exit(1);
+
+ if (hvf_enabled()) {
+ hvf_vcpu_kick(cpu);
+ } else {
+ err = pthread_kill(cpu->thread->thread, SIG_IPI);
+ if (err && err != ESRCH) {
+ fprintf(stderr, "qemu:%s: %s", __func__, strerror(err));
+ exit(1);
+ }
}
#else /* _WIN32 */
if (!qemu_cpu_is_self(cpu)) {
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index b3f4b79318..288a2bd57e 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -438,7 +438,7 @@ struct CPUState {
struct hax_vcpu_state *hax_vcpu;
- int hvf_fd;
+ unsigned hvf_fd;
/* track IOMMUs whose translations we've cached in the TCG TLB */
GArray *iommu_notifiers;
diff --git a/include/sysemu/hvf.h b/include/sysemu/hvf.h
index 1d40a8ec01..aaa00cbf05 100644
--- a/include/sysemu/hvf.h
+++ b/include/sysemu/hvf.h
@@ -25,6 +25,7 @@ extern bool hvf_allowed;
int hvf_init_vcpu(CPUState *);
int hvf_vcpu_exec(CPUState *);
+void hvf_vcpu_kick(CPUState *);
void hvf_cpu_synchronize_state(CPUState *);
void hvf_cpu_synchronize_post_reset(CPUState *);
void hvf_cpu_synchronize_post_init(CPUState *);
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index efe9802962..4d254a477a 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -966,6 +966,17 @@ int hvf_vcpu_exec(CPUState *cpu)
return ret;
}
+void hvf_vcpu_kick(CPUState *cpu)
+{
+ hv_return_t err;
+
+ err = hv_vcpu_interrupt(&cpu->hvf_fd, 1);
+ if (err) {
+ fprintf(stderr, "qemu:%s error %#x\n", __func__, err);
+ exit(1);
+ }
+}
+
bool hvf_allowed;
static int hvf_accel_init(MachineState *ms)
--
2.26.1
- Re: [PATCH 2/8] i386: hvf: Move synchronize functions to sysemu, (continued)
[PATCH 5/8] i386: hvf: Don't duplicate register reset, Roman Bolshakov, 2020/06/24
[PATCH 4/8] i386: hvf: Implement CPU kick,
Roman Bolshakov <=
- Re: [PATCH 4/8] i386: hvf: Implement CPU kick, Claudio Fontana, 2020/06/25
- Re: [PATCH 4/8] i386: hvf: Implement CPU kick, Paolo Bonzini, 2020/06/25
- Re: [PATCH 4/8] i386: hvf: Implement CPU kick, Roman Bolshakov, 2020/06/25
- Re: [PATCH 4/8] i386: hvf: Implement CPU kick, Paolo Bonzini, 2020/06/25
- Re: [PATCH 4/8] i386: hvf: Implement CPU kick, Roman Bolshakov, 2020/06/29
- Re: [PATCH 4/8] i386: hvf: Implement CPU kick, Paolo Bonzini, 2020/06/29
- Re: [PATCH 4/8] i386: hvf: Implement CPU kick, Roman Bolshakov, 2020/06/29
- Re: [PATCH 4/8] i386: hvf: Implement CPU kick, Paolo Bonzini, 2020/06/29
- Re: [PATCH 4/8] i386: hvf: Implement CPU kick, Roman Bolshakov, 2020/06/29