Skip to content

Commit

Permalink
hvf: Add Apple Silicon support
Browse files Browse the repository at this point in the history
With Apple Silicon available to the masses, it's a good time to add support
for driving its virtualization extensions from QEMU.

This patch adds all necessary architecture specific code to get basic VMs
working, including save/restore.

Known limitations:

  - WFI handling is missing (follows in later patch)
  - No watchpoint/breakpoint support

Signed-off-by: Alexander Graf <[email protected]>
Reviewed-by: Roman Bolshakov <[email protected]>
Reviewed-by: Sergio Lopez <[email protected]>
Reviewed-by: Peter Maydell <[email protected]>
Message-id: [email protected]
[PMM: added missing #include]
Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
agraf authored and pm215 committed Sep 20, 2021
1 parent ce7f5b1 commit a1477da
Show file tree
Hide file tree
Showing 7 changed files with 834 additions and 1 deletion.
5 changes: 5 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ F: accel/accel-*.c
F: accel/Makefile.objs
F: accel/stubs/Makefile.objs

Apple Silicon HVF CPUs
M: Alexander Graf <[email protected]>
S: Maintained
F: target/arm/hvf/

X86 HVF CPUs
M: Cameron Esfahani <[email protected]>
M: Roman Bolshakov <[email protected]>
Expand Down
9 changes: 9 additions & 0 deletions accel/hvf/hvf-accel-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@

HVFState *hvf_state;

#ifdef __aarch64__
#define HV_VM_DEFAULT NULL
#endif

/* Memory slots */

hvf_slot *hvf_find_overlap_slot(uint64_t start, uint64_t size)
Expand Down Expand Up @@ -376,7 +380,11 @@ static int hvf_init_vcpu(CPUState *cpu)
pthread_sigmask(SIG_BLOCK, NULL, &set);
sigdelset(&set, SIG_IPI);

#ifdef __aarch64__
r = hv_vcpu_create(&cpu->hvf->fd, (hv_vcpu_exit_t **)&cpu->hvf->exit, NULL);
#else
r = hv_vcpu_create((hv_vcpuid_t *)&cpu->hvf->fd, HV_VCPU_DEFAULT);
#endif
cpu->vcpu_dirty = 1;
assert_hvf_ok(r);

Expand Down Expand Up @@ -452,6 +460,7 @@ static void hvf_accel_ops_class_init(ObjectClass *oc, void *data)
AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);

ops->create_vcpu_thread = hvf_start_vcpu_thread;
ops->kick_vcpu_thread = hvf_kick_vcpu_thread;

ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset;
ops->synchronize_post_init = hvf_cpu_synchronize_post_init;
Expand Down
10 changes: 9 additions & 1 deletion include/sysemu/hvf_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
#ifndef HVF_INT_H
#define HVF_INT_H

#ifdef __aarch64__
#include <Hypervisor/Hypervisor.h>
#else
#include <Hypervisor/hv.h>
#endif

/* hvf_slot flags */
#define HVF_SLOT_LOG (1 << 0)
Expand Down Expand Up @@ -40,11 +44,14 @@ struct HVFState {
int num_slots;

hvf_vcpu_caps *hvf_caps;
uint64_t vtimer_offset;
};
extern HVFState *hvf_state;

struct hvf_vcpu_state {
int fd;
uint64_t fd;
void *exit;
bool vtimer_masked;
};

void assert_hvf_ok(hv_return_t ret);
Expand All @@ -55,5 +62,6 @@ int hvf_vcpu_exec(CPUState *);
hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
int hvf_put_registers(CPUState *);
int hvf_get_registers(CPUState *);
void hvf_kick_vcpu_thread(CPUState *cpu);

#endif
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,7 @@ if have_system or have_user
'accel/tcg',
'hw/core',
'target/arm',
'target/arm/hvf',
'target/hppa',
'target/i386',
'target/i386/kvm',
Expand Down
Loading

0 comments on commit a1477da

Please sign in to comment.