From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwpRq-00063Y-Tx for qemu-devel@nongnu.org; Thu, 12 Nov 2015 05:49:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZwpRn-0002xS-NL for qemu-devel@nongnu.org; Thu, 12 Nov 2015 05:49:46 -0500 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:32879) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwpRn-0002wn-C5 for qemu-devel@nongnu.org; Thu, 12 Nov 2015 05:49:43 -0500 Received: by wmec201 with SMTP id c201so26413309wme.0 for ; Thu, 12 Nov 2015 02:49:42 -0800 (PST) Received: from [10.0.0.11] ([188.120.148.251]) by smtp.gmail.com with ESMTPSA id z10sm25178627wmg.4.2015.11.12.02.49.41 for (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Nov 2015 02:49:41 -0800 (PST) From: Assaf Gordon Content-Type: multipart/mixed; boundary="Apple-Mail=_FDF531DE-D09C-4549-AE39-5F31C41039B3" Message-Id: <784C0637-DC5D-45CA-B989-AF76378201D4@gmail.com> Date: Thu, 12 Nov 2015 12:49:39 +0200 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2102\)) Subject: [Qemu-devel] Attempt at Mac OS X acceleration using "Hypervisor.Framwork" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --Apple-Mail=_FDF531DE-D09C-4549-AE39-5F31C41039B3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hello, Starting with Mac OS X version 10.10.3, Apple provides a system-level = hypervisor framework (similar to KVM's kernel driver functionality on = Linux). a good write-up here: http://www.pagetable.com/?p=3D764 http://www.pagetable.com/?p=3D831 a working hypervisor (forked from BSD's bhyve) is here: https://github.com/mist64/xhyve This attached patch attempts to provide the infrastructure glue for qemu = to use this framework (when compiled on Mac OS X). It is not yet = functional, but enables the following: ./configure --enable-hvf --target-list=3Dx86_64-softmmu qemu-system-x86_64 -machine accel=3Dhvf [...] Please advise as to whether this is the right approach, and whether it's = worth pursuing. Comments welcomed, - assaf --Apple-Mail=_FDF531DE-D09C-4549-AE39-5F31C41039B3 Content-Disposition: attachment; filename=accel-hvf.patch Content-Type: application/octet-stream; name="accel-hvf.patch" Content-Transfer-Encoding: quoted-printable =46rom=205825d45140cc7a935d5c35198d4ae41d961252c9=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Assaf=20Gordon=20=0A= Date:=20Thu,=2012=20Nov=202015=2012:33:12=20+0200=0ASubject:=20[PATCH]=20= STUB=20for=20Mac=20OS=20X=20Hypervisor.Framework=20accelerator=0A=0AAn=20= attempt=20to=20add=20stub=20code=20for=20future=20support=20of=0AMac=20= OS=20X=20Hypervisor.Framework=20(avaialble=20on=20OS=20X>=3D10.10.3).=0A=0A= Usage=20will=20be:=0A=20=20./configure=20--enable-hvf=20= --target-list=3Dx86_64-softmmu=0A=20=20qemu-system-x86_64=20-machine=20= accel=3Dhvf=20[...]=0A=0A*=20configure:=20new=20variable=20'hvf'.=0A=20=20= =20accept=20--{enable,disable}-hvf.=0A=20=20=20write=20CONFIG_HVF=3Dy=20= to=20/config-target.mak=20files.=0A=20=20=20(During=20= development,=20don't=20limit=20to=20Darwin=20hosts.)=0A*=20= Makefile.target:=20compile=20and=20link=20either=20hvf-stub.o=20or=20= hvf-all.o=0A=20=20=20based=20on=20CONFIG_HVF.=0A*=20cpus.c:=20= qemu_init_vcpu():=20use=20hvf=20functions.=0A=20=20=20= qemu_hvf_start_vcpu(),=20qemu_hvf_cpu_thread_fn()=20-=20use=20hvf=0A=20=20= =20accelerator.=0A*=20include/sysemu/hvf{-int}.h:=20stub=20header=20= files=20for=20hvf.=0A*=20hvf-stub.c:=20mimic=20kvm-stub.c,=20to=20be=20= compiled=20with=20CONFIG_HVF=3Dn=20.=0A*=20hvf-all.c:=20stub=20for=20= Hypervisor.Framework=20accelerator.=0A---=0A=20Makefile.target=20=20=20=20= =20=20=20=20=20=20|=20=20=202=20+=0A=20configure=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20|=20=2042=20+++++++++++=0A=20cpus.c=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20|=20=2057=20+++++++++++++++=0A=20= hvf-all.c=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20|=20179=20= +++++++++++++++++++++++++++++++++++++++++++++++=0A=20hvf-stub.c=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20|=20=2030=20++++++++=0A=20= include/qom/cpu.h=20=20=20=20=20=20=20=20|=20=20=204=20++=0A=20= include/sysemu/hvf.h=20=20=20=20=20|=20=2049=20+++++++++++++=0A=20= include/sysemu/hvf_int.h=20|=20=2021=20++++++=0A=208=20files=20changed,=20= 384=20insertions(+)=0A=20create=20mode=20100644=20hvf-all.c=0A=20create=20= mode=20100644=20hvf-stub.c=0A=20create=20mode=20100644=20= include/sysemu/hvf.h=0A=20create=20mode=20100644=20= include/sysemu/hvf_int.h=0A=0Adiff=20--git=20a/Makefile.target=20= b/Makefile.target=0Aindex=20962d004..5bba20a=20100644=0A---=20= a/Makefile.target=0A+++=20b/Makefile.target=0A@@=20-96,6=20+96,7=20@@=20= obj-y=20+=3D=20target-$(TARGET_BASE_ARCH)/=0A=20obj-y=20+=3D=20disas.o=0A= =20obj-$(call=20notempty,$(TARGET_XML_FILES))=20+=3D=20gdbstub-xml.o=0A=20= obj-$(call=20lnot,$(CONFIG_KVM))=20+=3D=20kvm-stub.o=0A+obj-$(call=20= lnot,$(CONFIG_HVF))=20+=3D=20hvf-stub.o=0A=20=0A=20= obj-$(CONFIG_LIBDECNUMBER)=20+=3D=20libdecnumber/decContext.o=0A=20= obj-$(CONFIG_LIBDECNUMBER)=20+=3D=20libdecnumber/decNumber.o=0A@@=20= -135,6=20+136,7=20@@=20obj-y=20+=3D=20arch_init.o=20cpus.o=20monitor.o=20= gdbstub.o=20balloon.o=20ioport.o=20numa.o=0A=20obj-y=20+=3D=20qtest.o=20= bootdevice.o=0A=20obj-y=20+=3D=20hw/=0A=20obj-$(CONFIG_KVM)=20+=3D=20= kvm-all.o=0A+obj-$(CONFIG_HVF)=20+=3D=20hvf-all.o=0A=20obj-y=20+=3D=20= memory.o=20cputlb.o=0A=20obj-y=20+=3D=20memory_mapping.o=0A=20obj-y=20+=3D= =20dump.o=0Adiff=20--git=20a/configure=20b/configure=0Aindex=20= 46fd8bd..e46a945=20100755=0A---=20a/configure=0A+++=20b/configure=0A@@=20= -346,6=20+346,9=20@@=20numa=3D""=0A=20tcmalloc=3D"no"=0A=20jemalloc=3D"no"= =0A=20=0A+#=20Mac=20OS=20X>=3D10.10.3=20Hypervisor.Framework=20(hvf)=0A= +hvf=3D"no"=0A+=0A=20#=20parse=20CC=20options=20first=0A=20for=20opt=20= do=0A=20=20=20optarg=3D`expr=20"x$opt"=20:=20'x[^=3D]*=3D\(.*\)'`=0A@@=20= -937,6=20+940,10=20@@=20for=20opt=20do=0A=20=20=20;;=0A=20=20=20= --enable-kvm)=20kvm=3D"yes"=0A=20=20=20;;=0A+=20=20--disable-hvf)=20= hvf=3D"no"=0A+=20=20;;=0A+=20=20--enable-hvf)=20hvf=3D"yes"=0A+=20=20;;=0A= =20=20=20--disable-tcg-interpreter)=20tcg_interpreter=3D"no"=0A=20=20=20= ;;=0A=20=20=20--enable-tcg-interpreter)=20tcg_interpreter=3D"yes"=0A@@=20= -1360,6=20+1367,7=20@@=20disabled=20with=20--disable-FEATURE,=20default=20= is=20enabled=20if=20available:=0A=20=20=20fdt=20=20=20=20=20=20=20=20=20=20= =20=20=20fdt=20device=20tree=0A=20=20=20bluez=20=20=20=20=20=20=20=20=20=20= =20bluez=20stack=20connectivity=0A=20=20=20kvm=20=20=20=20=20=20=20=20=20= =20=20=20=20KVM=20acceleration=20support=0A+=20=20hvf=20=20=20=20=20=20=20= =20=20=20=20=20=20Mac=20OS=20X=20Hypervisor.Framework=0A=20=20=20rdma=20=20= =20=20=20=20=20=20=20=20=20=20RDMA-based=20migration=20support=0A=20=20=20= uuid=20=20=20=20=20=20=20=20=20=20=20=20uuid=20support=0A=20=20=20vde=20=20= =20=20=20=20=20=20=20=20=20=20=20support=20for=20vde=20network=0A@@=20= -4456,6=20+4464,29=20@@=20elif=20test=20"$debug"=20=3D=20"no";=20then=0A=20= fi=0A=20=0A=20##########################################=0A+#=20= Hypervisor.Framework=20check=0A+=0A+if=20test=20"$hvf"=20!=3D=20"no"=20;=20= then=0A+=20=20=20=20if=20test=20"$darwin"=20!=3D=20yes=20;=20then=0A+=20=20= =20=20=20=20=20=20=20=20=20=20feature_not_found=20"hvf"=20= "Hypervisor.Framework=20requires=20Mac/Darwin"=0A+=20=20=20=20fi=0A+=20=20= =20=20cat=20>=20$TMPC=20<<=20EOF=0A+#include=20=0A= +#include=20=0A+int=20main(void)=20{=20= hv_vm_create(HV_VM_DEFAULT);=20return=200;=20}=0A+EOF=0A+=20=20=20=20if=20= compile_prog=20""=20"-framework=20Hypervisor"=20;=20then=0A+=20=20=20=20=20= =20=20=20libs_softmmu=3D"$libs_softmmu=20-framework=20Hypervisor"=0A+=20=20= =20=20=20=20=20=20hvf=3D"yes"=0A+=20=20=20=20else=0A+=20=20=20=20=20=20=20= =20if=20test=20"$hvf"=20=3D=20"yes";=20then=0A+=20=20=20=20=20=20=20=20=20= =20=20=20feature_not_found=20"hvf"=20"Hypervisor.Framework=20not=20= found"=0A+=20=20=20=20=20=20=20=20fi=0A+=20=20=20=20=20=20=20=20hvf=3D"no"= =0A+=20=20=20=20fi=0A+fi=0A+=0A= +##########################################=0A=20#=20Do=20we=20have=20= libnfs=0A=20if=20test=20"$libnfs"=20!=3D=20"no"=20;=20then=0A=20=20=20if=20= $pkg_config=20--atleast-version=3D1.9.3=20libnfs;=20then=0A@@=20-4741,6=20= +4772,7=20@@=20echo=20"Linux=20AIO=20support=20$linux_aio"=0A=20echo=20= "ATTR/XATTR=20support=20$attr"=0A=20echo=20"Install=20blobs=20=20=20=20=20= $blobs"=0A=20echo=20"KVM=20support=20=20=20=20=20=20=20$kvm"=0A+echo=20= "HVF=20support=20=20=20=20=20=20=20$hvf"=0A=20echo=20"RDMA=20support=20=20= =20=20=20=20$rdma"=0A=20echo=20"TCG=20interpreter=20=20=20= $tcg_interpreter"=0A=20echo=20"fdt=20support=20=20=20=20=20=20=20$fdt"=0A= @@=20-5646,6=20+5678,16=20@@=20case=20"$target_name"=20in=0A=20=20=20*)=0A= =20esac=0A=20case=20"$target_name"=20in=0A+=20=20i386|x86_64)=0A+=20=20=20= =20if=20test=20"$hvf"=20=3D=20yes;=20then=0A+=20=20=20=20=20=20echo=20= "CONFIG_HVF=3Dy"=20>>=20$config_target_mak=0A+=20=20=20=20=20=20#TODO:=20= avoid=20writing=20'CONFIG_VHOST_NET=3Dy'=20twice=20(below=20in=20kvm)=0A= +=20=20=20=20=20=20if=20test=20"$vhost_net"=20=3D=20"yes"=20;=20then=0A+=20= =20=20=20=20=20=20=20echo=20"CONFIG_VHOST_NET=3Dy"=20>>=20= $config_target_mak=0A+=20=20=20=20=20=20fi=0A+=20=20=20=20fi=0A+esac=0A= +case=20"$target_name"=20in=0A=20=20=20= aarch64|arm|i386|x86_64|ppcemb|ppc|ppc64|s390x|mipsel|mips)=0A=20=20=20=20= =20#=20Make=20sure=20the=20target=20and=20host=20cpus=20are=20compatible=0A= =20=20=20=20=20if=20test=20"$kvm"=20=3D=20"yes"=20-a=20"$target_softmmu"=20= =3D=20"yes"=20-a=20\=0Adiff=20--git=20a/cpus.c=20b/cpus.c=0Aindex=20= 877bd70..e578221=20100644=0A---=20a/cpus.c=0A+++=20b/cpus.c=0A@@=20-32,6=20= +32,7=20@@=0A=20#include=20"exec/gdbstub.h"=0A=20#include=20= "sysemu/dma.h"=0A=20#include=20"sysemu/kvm.h"=0A+#include=20= "sysemu/hvf.h"=0A=20#include=20"qmp-commands.h"=0A=20=0A=20#include=20= "qemu/thread.h"=0A@@=20-1058,6=20+1059,44=20@@=20static=20void=20= *qemu_kvm_cpu_thread_fn(void=20*arg)=0A=20=20=20=20=20return=20NULL;=0A=20= }=0A=20=0A+static=20void=20*qemu_hvf_cpu_thread_fn(void=20*arg)=0A+{=0A+=20= =20=20=20CPUState=20*cpu=20=3D=20arg;=0A+=20=20=20=20int=20r;=0A+=0A+=20=20= =20=20qemu_mutex_lock_iothread();=0A+=20=20=20=20= qemu_thread_get_self(cpu->thread);=0A+=20=20=20=20cpu->thread_id=20=3D=20= qemu_get_thread_id();=0A+=20=20=20=20cpu->can_do_io=20=3D=201;=0A+=20=20=20= =20current_cpu=20=3D=20cpu;=0A+=0A+=20=20=20=20r=20=3D=20= hvf_init_vcpu(cpu)=20;=0A+=20=20=20=20if=20(r=20<=200)=20{=0A+=20=20=20=20= =20=20=20=20fprintf(stderr,=20"hvf_init_vcpu=20failed:=20%s\n",=20= strerror(-r));=0A+=20=20=20=20=20=20=20=20exit(1);=0A+=20=20=20=20}=0A+=0A= +=20=20=20=20//TODO:=20implement=20with=20hvf=0A+=20=20=20=20= //qemu_kvm_init_cpu_signals(cpu);=0A+=0A+=20=20=20=20/*=20signal=20CPU=20= creation=20*/=0A+=20=20=20=20cpu->created=20=3D=20true;=0A+=20=20=20=20= qemu_cond_signal(&qemu_cpu_cond);=0A+=0A+=20=20=20=20while=20(1)=20{=0A+=20= =20=20=20=20=20=20=20if=20(cpu_can_run(cpu))=20{=0A+=20=20=20=20=20=20=20= =20=20=20=20=20r=20=3D=20hvf_cpu_exec(cpu);=0A+=20=20=20=20=20=20=20=20=20= =20=20=20if=20(r=20=3D=3D=20EXCP_DEBUG)=20{=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20cpu_handle_guest_debug(cpu);=0A+=20=20=20=20=20=20=20= =20=20=20=20=20}=0A+=20=20=20=20=20=20=20=20}=0A+=20=20=20=20=20=20=20=20= //TODO:=20implement=20with=20hvf=0A+=20=20=20=20=20=20=20=20= //qemu_kvm_wait_io_event(cpu);=0A+=20=20=20=20}=0A+=0A+=20=20=20=20= return=20NULL;=0A+}=0A+=0A=20static=20void=20= *qemu_dummy_cpu_thread_fn(void=20*arg)=0A=20{=0A=20#ifdef=20_WIN32=0A@@=20= -1367,6=20+1406,22=20@@=20static=20void=20qemu_dummy_start_vcpu(CPUState=20= *cpu)=0A=20=20=20=20=20}=0A=20}=0A=20=0A+static=20void=20= qemu_hvf_start_vcpu(CPUState=20*cpu)=0A+{=0A+=20=20=20=20char=20= thread_name[VCPU_THREAD_NAME_SIZE];=0A+=0A+=20=20=20=20cpu->thread=20=3D=20= g_malloc0(sizeof(QemuThread));=0A+=20=20=20=20cpu->halt_cond=20=3D=20= g_malloc0(sizeof(QemuCond));=0A+=20=20=20=20= qemu_cond_init(cpu->halt_cond);=0A+=20=20=20=20snprintf(thread_name,=20= VCPU_THREAD_NAME_SIZE,=20"CPU=20%d/HVF",=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20cpu->cpu_index);=0A+=20=20=20=20qemu_thread_create(cpu->thread,=20= thread_name,=20qemu_hvf_cpu_thread_fn,=20cpu,=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20QEMU_THREAD_JOINABLE);=0A+=20= =20=20=20while=20(!cpu->created)=20{=0A+=20=20=20=20=20=20=20=20= qemu_cond_wait(&qemu_cpu_cond,=20&qemu_global_mutex);=0A+=20=20=20=20}=0A= +}=0A+=0A=20void=20qemu_init_vcpu(CPUState=20*cpu)=0A=20{=0A=20=20=20=20=20= cpu->nr_cores=20=3D=20smp_cores;=0A@@=20-1374,6=20+1429,8=20@@=20void=20= qemu_init_vcpu(CPUState=20*cpu)=0A=20=20=20=20=20cpu->stopped=20=3D=20= true;=0A=20=20=20=20=20if=20(kvm_enabled())=20{=0A=20=20=20=20=20=20=20=20= =20qemu_kvm_start_vcpu(cpu);=0A+=20=20=20=20}=20else=20if=20= (hvf_enabled())=20{=0A+=20=20=20=20=20=20=20=20qemu_hvf_start_vcpu(cpu);=0A= =20=20=20=20=20}=20else=20if=20(tcg_enabled())=20{=0A=20=20=20=20=20=20=20= =20=20qemu_tcg_init_vcpu(cpu);=0A=20=20=20=20=20}=20else=20{=0Adiff=20= --git=20a/hvf-all.c=20b/hvf-all.c=0Anew=20file=20mode=20100644=0Aindex=20= 0000000..23e8aa1=0A---=20/dev/null=0A+++=20b/hvf-all.c=0A@@=20-0,0=20= +1,179=20@@=0A+/*=0A+=20*=20QEMU=20HVF=20support=0A+=20*=0A+=20*=20= Copyright=20(C)=202015=20Assaf=20Gordon=0A+=20*=0A+=20*=20Based=20on=20= kvm-all.c:=0A+=20*=20=20=20=20Copyright=20IBM,=20Corp.=202008=0A+=20*=20=20= =20=20=20=20=20=20=20=20=20=20=20=20Red=20Hat,=20Inc.=202008=0A+=20*=20=20= =20=20Authors:=0A+=20*=20=20=20=20=20=20Anthony=20Liguori=20=20=20= =0A+=20*=20=20=20=20=20=20Glauber=20Costa=20=20=20=20= =20=0A+=20*=0A+=20*=20This=20work=20is=20licensed=20= under=20the=20terms=20of=20the=20GNU=20GPL,=20version=202=20or=20later.=0A= +=20*=20See=20the=20COPYING=20file=20in=20the=20top-level=20directory.=0A= +=20*=0A+=20*/=0A+=0A+#include=20=0A+#include=20= =0A+#include=20=0A+#include=20=0A+=0A= +#include=20"sysemu/hvf_int.h"=0A+#include=20"qemu/bswap.h"=0A+#include=20= "exec/memory.h"=0A+#include=20"exec/ram_addr.h"=0A+#include=20= "exec/address-spaces.h"=0A+#include=20"qemu/event_notifier.h"=0A= +#include=20"trace.h"=0A+#include=20"hw/irq.h"=0A+=0A+#include=20= "hw/boards.h"=0A+=0A+#define=20DEBUG_HVF=0A+=0A+#ifdef=20DEBUG_HVF=0A= +#define=20DPRINTF(fmt,=20...)=20\=0A+=20=20=20=20do=20{=20= fprintf(stderr,=20fmt,=20##=20__VA_ARGS__);=20}=20while=20(0)=0A+#else=0A= +#define=20DPRINTF(fmt,=20...)=20\=0A+=20=20=20=20do=20{=20}=20while=20= (0)=0A+#endif=0A+=0A+#define=20KVM_MSI_HASHTAB_SIZE=20=20=20=20256=0A+=0A= +struct=20HVFState=0A+{=0A+=20=20=20=20AccelState=20parent_obj;=0A+=0A+=20= =20=20=20/*=20get=20hypervisor=20enforced=20capabilities=20of=20the=20= machine,=20(see=20Intel=20docs)=20*/=0A+=20=20=20=20uint64_t=20= vmx_cap_pinbased;=0A+=20=20=20=20uint64_t=20vmx_cap_procbased;=0A+=20=20=20= =20uint64_t=20vmx_cap_procbased2;=0A+=20=20=20=20uint64_t=20= vmx_cap_entry;=0A+=0A+=20=20=20=20/*=20TODO:=20move=20this=20to=20= CPUState,=20allow=20multiple=20CPUs=20*/=0A+=20=20=20=20hv_vcpuid_t=20= vcpu;=0A+=0A+=20=20=20=20/*=20TODO:=20use=20qemu's=20memory=20management=20= instead=20of=20this=20hack=20*/=0A+=20=20=20=20void=20*mem;=0A+};=0A+=0A= +HVFState=20*hvf_state;=0A+bool=20hvf_allowed;=0A+=0A+int=20= hvf_init_vcpu(CPUState=20*cpu)=0A+{=0A+=20=20=20=20HVFState=20*s=20=3D=20= hvf_state;=0A+=20=20=20=20int=20ret;=0A+=0A+=20=20=20=20= DPRINTF("hvf_init_vcpu\n");=0A+=0A+=20=20=20=20/*=20TODO:=0A+=20=20=20=20= =20=20=20Use=20Hypervisor.Framework,=20as=20described=20here:=0A+=20=20=20= =20=20=20=20=20http://www.pagetable.com/?p=3D764=0A+=20=20=20=20=20=20=20= =20http://www.pagetable.com/?p=3D831=0A+=20=20=20=20*/=0A+=20=20=20=20= cpu->hvf_state=20=3D=20s;=0A+=0A+=20=20=20=20if=20(=20(ret=20=3D=20= hv_vcpu_create(&s->vcpu,=20HV_VCPU_DEFAULT))=20)=20{=0A+=20=20=20=20=20=20= =20=20DPRINTF("hv_vcpu_create=20failed=20(err=3D%d)\n",=20ret);=0A+=20=20= =20=20=20=20=20=20goto=20err;=0A+=20=20=20=20}=0A+=0A+=20=20=20=20/*=20= TODO:=20Allocate=20memory=20the=20QEMU=20way=20*/=0A+#define=20= VM_MEM_SIZE=20(1=20*=201024=20*=201024)=0A+=20=20=20=20void=20*vm_mem=20= =3D=20valloc(VM_MEM_SIZE);=0A+=20=20=20=20if=20(vm_mem=20=3D=3D=20NULL)=20= {=0A+=20=20=20=20=20=20=20=20DPRINTF("valloc=20failed,=20= errno=3D%d\n",errno);=0A+=20=20=20=20=20=20=20=20goto=20err;=0A+=20=20=20= =20}=0A+=20=20=20=20s->mem=20=3D=20vm_mem;=0A+=0A+=20=20=20=20if=20(=20= (ret=20=3D=20hv_vm_map(vm_mem,=200,=20VM_MEM_SIZE,=20HV_MEMORY_READ=20|=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= HV_MEMORY_WRITE=20|=20HV_MEMORY_EXEC))=20)=20{=0A+=20=20=20=20=20=20=20=20= DPRINTF("hv_vm_map=20failed=20(err=3D%d)\n",=20ret);=0A+=20=20=20=20=20=20= =20=20goto=20err;=0A+=20=20=20=20}=0A+=0A+=20=20=20=20= DPRINTF("hvf_init_vcpu=20-=20done\n");=0A+=20=20=20=20ret=20=3D=200;=0A+=0A= +err:=0A+=20=20=20=20return=20ret;=0A+}=0A+=0A+int=20= hvf_cpu_exec(CPUState=20*cpu)=0A+{=0A+=20=20=20=20= DPRINTF("hvf_cpu_exec()\n");=0A+=0A+=20=20=20=20return=20-1;=0A+}=0A+=0A= +static=20int=20hvf_init(MachineState=20*ms)=0A+{=0A+=20=20=20=20= HVFState=20*s;=0A+=20=20=20=20int=20ret;=0A+=0A+=20=20=20=20= DPRINTF("hvf_init\n");=0A+=20=20=20=20s=20=3D=20= HVF_STATE(ms->accelerator);=0A+=0A+=0A+=20=20=20=20/*=20TODO:=20should=20= 'ret'=20be=20modified/update=20errno?=20*/=0A+=20=20=20=20if=20(=20(ret=20= =3D=20hv_vm_create(HV_VM_DEFAULT))=20)=20{=0A+=20=20=20=20=20=20=20=20= DPRINTF("hv_vm_create=20failed=20(err=3D%d)\n",ret);=0A+=20=20=20=20=20=20= =20=20goto=20err;=0A+=20=20=20=20}=0A+=0A+=20=20=20=20if=20(=20(ret=20=3D=20= hv_vmx_read_capability(HV_VMX_CAP_PINBASED,=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20&s->vmx_cap_pinbased))=20)=20{=0A+=20=20=20=20=20=20=20=20= DPRINTF("v_vmx_read_cap(PINBASED)=20failed=20(err=3D%d)\n",=20ret);=0A+=20= =20=20=20=20=20=20=20goto=20err;=0A+=20=20=20=20}=0A+=20=20=20=20if=20(=20= (ret=20=3D=20hv_vmx_read_capability(HV_VMX_CAP_PROCBASED,=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20&s->vmx_cap_procbased))=20)=20{=0A+=20=20=20= =20=20=20=20=20DPRINTF("v_vmx_read_cap(PROCBASED)=20failed=20= (err=3D%d)\n",=20ret);=0A+=20=20=20=20=20=20=20=20goto=20err;=0A+=20=20=20= =20}=0A+=20=20=20=20if=20(=20(ret=20=3D=20= hv_vmx_read_capability(HV_VMX_CAP_PROCBASED2,=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20&s->vmx_cap_procbased2))=20)=20{=0A+=20=20=20=20=20=20=20= =20DPRINTF("v_vmx_read_cap(PROCBASED2)=20failed=20(err=3D%d)\n",=20ret);=0A= +=20=20=20=20=20=20=20=20goto=20err;=0A+=20=20=20=20}=0A+=20=20=20=20if=20= (=20(ret=20=3D=20hv_vmx_read_capability(HV_VMX_CAP_ENTRY,=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20&s->vmx_cap_entry))=20)=20{=0A+=20=20=20=20= =20=20=20=20DPRINTF("v_vmx_read_cap(CAP_ENTRY)=20failed=20(err=3D%d)\n",=20= ret);=0A+=20=20=20=20=20=20=20=20goto=20err;=0A+=20=20=20=20}=0A+=0A+=20=20= =20=20hvf_state=20=3D=20s;=0A+=0A+=20=20=20=20DPRINTF("hvf_init=20-=20= done\n");=0A+=20=20=20=20return=200;=0A+=0A+err:=0A+=20=20=20=20return=20= ret;=0A+}=0A+=0A+static=20void=20hvf_accel_class_init(ObjectClass=20*oc,=20= void=20*data)=0A+{=0A+=20=20=20=20AccelClass=20*ac=20=3D=20= ACCEL_CLASS(oc);=0A+=20=20=20=20ac->name=20=3D=20"HVF";=0A+=20=20=20=20= ac->init_machine=20=3D=20hvf_init;=0A+=20=20=20=20ac->allowed=20=3D=20= &hvf_allowed;=0A+}=0A+=0A+static=20const=20TypeInfo=20hvf_accel_type=20=3D= =20{=0A+=20=20=20=20.name=20=3D=20TYPE_HVF_ACCEL,=0A+=20=20=20=20.parent=20= =3D=20TYPE_ACCEL,=0A+=20=20=20=20.class_init=20=3D=20= hvf_accel_class_init,=0A+=20=20=20=20.instance_size=20=3D=20= sizeof(HVFState),=0A+};=0A+=0A+static=20void=20hvf_type_init(void)=0A+{=0A= +=20=20=20=20type_register_static(&hvf_accel_type);=0A+}=0A+=0A= +type_init(hvf_type_init);=0Adiff=20--git=20a/hvf-stub.c=20b/hvf-stub.c=0A= new=20file=20mode=20100644=0Aindex=200000000..8ba0371=0A---=20/dev/null=0A= +++=20b/hvf-stub.c=0A@@=20-0,0=20+1,30=20@@=0A+/*=0A+=20*=20QEMU=20HVF=20= stub=0A+=20*=0A+=20*=20Copyright=20(C)=202015=20Assaf=20Gordon=0A+=20*=0A= +=20*=20Based=20on=20kvm-stub.c:=0A+=20*=20=20=20Copyright=20Red=20Hat,=20= Inc.=202010=0A+=20*=20=20=20Author:=20Paolo=20Bonzini=20=20=20=20=20= =0A+=20*=0A+=20*=20This=20work=20is=20licensed=20= under=20the=20terms=20of=20the=20GNU=20GPL,=20version=202=20or=20later.=0A= +=20*=20See=20the=20COPYING=20file=20in=20the=20top-level=20directory.=0A= +=20*=0A+=20*/=0A+=0A+#include=20"qemu-common.h"=0A+#include=20"hw/hw.h"=0A= +#include=20"cpu.h"=0A+#include=20"sysemu/hvf.h"=0A+=0A+bool=20= hvf_allowed;=0A+=0A+int=20hvf_init_vcpu(CPUState=20*cpu)=0A+{=0A+=20=20=20= =20return=20-ENOSYS;=0A+}=0A+=0A+int=20hvf_cpu_exec(CPUState=20*cpu)=0A= +{=0A+=20=20=20=20abort();=0A+}=0Adiff=20--git=20a/include/qom/cpu.h=20= b/include/qom/cpu.h=0Aindex=2051a1323..544f8d8=20100644=0A---=20= a/include/qom/cpu.h=0A+++=20b/include/qom/cpu.h=0A@@=20-207,6=20+207,8=20= @@=20typedef=20struct=20CPUWatchpoint=20{=0A=20struct=20KVMState;=0A=20= struct=20kvm_run;=0A=20=0A+struct=20HVFState;=0A+=0A=20#define=20= TB_JMP_CACHE_BITS=2012=0A=20#define=20TB_JMP_CACHE_SIZE=20(1=20<<=20= TB_JMP_CACHE_BITS)=0A=20=0A@@=20-314,6=20+316,8=20@@=20struct=20CPUState=20= {=0A=20=20=20=20=20struct=20KVMState=20*kvm_state;=0A=20=20=20=20=20= struct=20kvm_run=20*kvm_run;=0A=20=0A+=20=20=20=20struct=20HVFState=20= *hvf_state;=0A+=0A=20=20=20=20=20/*=20TODO=20Move=20common=20fields=20= from=20CPUArchState=20here.=20*/=0A=20=20=20=20=20int=20cpu_index;=20/*=20= used=20by=20alpha=20TCG=20*/=0A=20=20=20=20=20uint32_t=20halted;=20/*=20= used=20by=20alpha,=20cris,=20ppc=20TCG=20*/=0Adiff=20--git=20= a/include/sysemu/hvf.h=20b/include/sysemu/hvf.h=0Anew=20file=20mode=20= 100644=0Aindex=200000000..cf51c6c=0A---=20/dev/null=0A+++=20= b/include/sysemu/hvf.h=0A@@=20-0,0=20+1,49=20@@=0A+/*=0A+=20*=20QEMU=20= HVF=20support=0A+=20*=0A+=20*=20Copyright=20(C)=202015=20Assaf=20Gordon=0A= +=20*=0A+=20*=20Based=20on=20./include/sysemu/kvm.h:=0A+=20*=20=20=20=20= Copyright=20IBM,=20Corp.=202008=0A+=20*=20=20=20=20Authors:=0A+=20*=20=20= =20=20=20=20Anthony=20Liguori=20=20=20=0A+=20*=0A+=20= *=20This=20work=20is=20licensed=20under=20the=20terms=20of=20the=20GNU=20= GPL,=20version=202=20or=20later.=0A+=20*=20See=20the=20COPYING=20file=20= in=20the=20top-level=20directory.=0A+=20*=0A+=20*/=0A+=0A+#ifndef=20= QEMU_HVF_H=0A+#define=20QEMU_HVF_H=0A+=0A+#include=20=0A= +#include=20"config-host.h"=0A+#include=20"qemu/queue.h"=0A+#include=20= "qom/cpu.h"=0A+#include=20"exec/memattrs.h"=0A+#include=20"hw/irq.h"=0A+=0A= +#ifdef=20CONFIG_HVF=0A+#include=20=0A+#include=20= =0A+#include=20=0A+#endif=0A= +=0A+extern=20bool=20hvf_allowed;=0A+=0A+#if=20defined=20CONFIG_HVF=20||=20= !defined=20NEED_CPU_H=0A+#define=20hvf_enabled()=20=20=20=20=20=20=20=20=20= =20=20(hvf_allowed)=0A+#else=0A+#define=20hvf_enabled()=20=20=20=20=20=20= =20=20=20=20=20(0)=0A+#endif=0A+=0A+struct=20HVFState;=0A+typedef=20= struct=20HVFState=20HVFState;=0A+extern=20HVFState=20*hvf_state;=0A+=0A= +/*=20external=20API=20*/=0A+=0A+int=20hvf_init_vcpu(CPUState=20*cpu);=0A= +int=20hvf_cpu_exec(CPUState=20*cpu);=0A+=0A+#endif=0Adiff=20--git=20= a/include/sysemu/hvf_int.h=20b/include/sysemu/hvf_int.h=0Anew=20file=20= mode=20100644=0Aindex=200000000..ffab64a=0A---=20/dev/null=0A+++=20= b/include/sysemu/hvf_int.h=0A@@=20-0,0=20+1,21=20@@=0A+/*=0A+=20*=20= Internal=20definitions=20for=20a=20target's=20HVF=20support=0A+=20*=0A+=20= *=20This=20work=20is=20licensed=20under=20the=20terms=20of=20the=20GNU=20= GPL,=20version=202=20or=20later.=0A+=20*=20See=20the=20COPYING=20file=20= in=20the=20top-level=20directory.=0A+=20*=0A+=20*/=0A+=0A+#ifndef=20= QEMU_HVF_INT_H=0A+#define=20QEMU_HVF_INT_H=0A+=0A+#include=20= "sysemu/sysemu.h"=0A+#include=20"sysemu/accel.h"=0A+#include=20= "sysemu/hvf.h"=0A+=0A+#define=20TYPE_HVF_ACCEL=20ACCEL_CLASS_NAME("hvf")=0A= +=0A+#define=20HVF_STATE(obj)=20\=0A+=20=20=20=20OBJECT_CHECK(HVFState,=20= (obj),=20TYPE_HVF_ACCEL)=0A+=0A+#endif=0A--=20=0A2.4.3=0A=0A= --Apple-Mail=_FDF531DE-D09C-4549-AE39-5F31C41039B3--