From nobody Mon Feb 9 20:34:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517860713683752.7110508461508; Mon, 5 Feb 2018 11:58:33 -0800 (PST) Received: from localhost ([::1]:54978 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eimuO-00065Q-RH for importer@patchew.org; Mon, 05 Feb 2018 14:58:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eimSp-00053I-DZ for qemu-devel@nongnu.org; Mon, 05 Feb 2018 14:30:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eimSo-0005Fo-5Q for qemu-devel@nongnu.org; Mon, 05 Feb 2018 14:30:03 -0500 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:35844) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eimSn-0005En-RC for qemu-devel@nongnu.org; Mon, 05 Feb 2018 14:30:02 -0500 Received: by mail-wm0-x242.google.com with SMTP id f3so28132387wmc.1 for ; Mon, 05 Feb 2018 11:30:01 -0800 (PST) Received: from 640k.lan ([82.84.122.246]) by smtp.gmail.com with ESMTPSA id g8sm20029891wra.18.2018.02.05.11.29.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Feb 2018 11:29:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=EQ63Km+3XgvzI4DjglpFWxH3jTTpA0ZNuGcMcMJX7Ys=; b=GATT/0BjgKo8+nSsZ/dDTqpyAw2f4ehwF7WAcfo2lFZqHnDnYyLI/maAOk9Lr5vnT7 5hXQu4PQ9NYinBPFBlahYhAbdj0axUUADDp4j+12DLl3y1snR+y+L73WiGflmgnQkLln OInchFXZrm9ijFGP7t4S2UNY6Pj3vDKgc9qDYsiIFi5hYnv6KeAHQ6Q/ITk/eF0qV7GZ aOFurx7JOaB604lb01ySaRZvoFj4yhSKn60lhuxqA2Kbm2Rg1A5pWiUDkIteXb9RNlla tXcWWq95teoK+tzTm4VMQC1ehskqEuvywuUWhk8z+r7iIv1Q5s5/huxu19dR9ZHT+GrB dPEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=EQ63Km+3XgvzI4DjglpFWxH3jTTpA0ZNuGcMcMJX7Ys=; b=XooWsMqf5ZfeMWy6zgqDmzro1o02m2pujaqLvBagez5I3sOcEfcCclJD/EBXVshC3L HXpbaVfJsq+KCfV16KdE75d8xnyscrZTnMp/gw8YpRZedd7PWwIinwfs93cI5iVvdy0q ItU9QH8HCxQef37qng0LlFgONPk/iyB7YOD8FUeXwhr3zgkMG3sJ01w6UFtE+kZ3wSa9 ewszAUTGBuejJIR3lU4+biJ8z5/pgkJaIyT+wMmlwx2WYI4R2VeNjK/G4Glc8h+C3nbT iIu+FB1twmnMox+jeekVqwGD3JYko8d0LpC4/hqq+pSmCX0bvhUWd8Ir7ehF5G+rbGnz P1nw== X-Gm-Message-State: APf1xPBT7AFlBZsqYo5EUJ2+s4fFnXFwwsyPhNBLiwgrTip5nJckyt0B +GBZpEHuwHBnUbvzSZHGEq4/Skf6 X-Google-Smtp-Source: AH8x227Bqym/i6xd3WG7MVt/BBI7FyQO9ZK2OoMgaB5YQUiX+SkTwkXr8Ls1JEdauqFm9lrHnUFQ3A== X-Received: by 10.28.29.81 with SMTP id d78mr328238wmd.65.1517859000465; Mon, 05 Feb 2018 11:30:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 20:29:01 +0100 Message-Id: <1517858941-5538-48-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1517858941-5538-1-git-send-email-pbonzini@redhat.com> References: <1517858941-5538-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PULL 47/47] Add the WHPX acceleration enlightenments X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Justin Terry \(VM\)" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Justin Terry (VM)" Implements the WHPX accelerator cpu enlightenments to actually use the whpx= -all accelerator on Windows platforms. Signed-off-by: Justin Terry (VM) Message-Id: <1516655269-1785-5-git-send-email-juterry@microsoft.com> [Register/unregister VCPU thread with RCU. - Paolo] Signed-off-by: Paolo Bonzini --- cpus.c | 69 +++++++++++++++++++++++++++++++++++++++++++= +++- include/sysemu/hw_accel.h | 13 +++++++++ target/i386/helper.c | 2 +- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/cpus.c b/cpus.c index 8d8bb7c..6825fe1 100644 --- a/cpus.c +++ b/cpus.c @@ -38,6 +38,7 @@ #include "sysemu/kvm.h" #include "sysemu/hax.h" #include "sysemu/hvf.h" +#include "sysemu/whpx.h" #include "qmp-commands.h" #include "exec/exec-all.h" =20 @@ -1545,6 +1546,49 @@ static void *qemu_hvf_cpu_thread_fn(void *arg) return NULL; } =20 +static void *qemu_whpx_cpu_thread_fn(void *arg) +{ + CPUState *cpu =3D arg; + int r; + + rcu_register_thread(); + + qemu_mutex_lock_iothread(); + qemu_thread_get_self(cpu->thread); + cpu->thread_id =3D qemu_get_thread_id(); + current_cpu =3D cpu; + + r =3D whpx_init_vcpu(cpu); + if (r < 0) { + fprintf(stderr, "whpx_init_vcpu failed: %s\n", strerror(-r)); + exit(1); + } + + /* signal CPU creation */ + cpu->created =3D true; + qemu_cond_signal(&qemu_cpu_cond); + + do { + if (cpu_can_run(cpu)) { + r =3D whpx_vcpu_exec(cpu); + if (r =3D=3D EXCP_DEBUG) { + cpu_handle_guest_debug(cpu); + } + } + while (cpu_thread_is_idle(cpu)) { + qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex); + } + qemu_wait_io_event_common(cpu); + } while (!cpu->unplug || cpu_can_run(cpu)); + + whpx_destroy_vcpu(cpu); + cpu->created =3D false; + qemu_cond_signal(&qemu_cpu_cond); + qemu_mutex_unlock_iothread(); + rcu_unregister_thread(); + return NULL; +} + #ifdef _WIN32 static void CALLBACK dummy_apc_func(ULONG_PTR unused) { @@ -1635,7 +1679,9 @@ static void qemu_cpu_kick_thread(CPUState *cpu) } #else /* _WIN32 */ if (!qemu_cpu_is_self(cpu)) { - if (!QueueUserAPC(dummy_apc_func, cpu->hThread, 0)) { + if (whpx_enabled()) { + whpx_vcpu_kick(cpu); + } else if (!QueueUserAPC(dummy_apc_func, cpu->hThread, 0)) { fprintf(stderr, "%s: QueueUserAPC failed with error %lu\n", __func__, GetLastError()); exit(1); @@ -1877,6 +1923,25 @@ static void qemu_hvf_start_vcpu(CPUState *cpu) } } =20 +static void qemu_whpx_start_vcpu(CPUState *cpu) +{ + char thread_name[VCPU_THREAD_NAME_SIZE]; + + cpu->thread =3D g_malloc0(sizeof(QemuThread)); + cpu->halt_cond =3D g_malloc0(sizeof(QemuCond)); + qemu_cond_init(cpu->halt_cond); + snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX", + cpu->cpu_index); + qemu_thread_create(cpu->thread, thread_name, qemu_whpx_cpu_thread_fn, + cpu, QEMU_THREAD_JOINABLE); +#ifdef _WIN32 + cpu->hThread =3D qemu_thread_get_handle(cpu->thread); +#endif + while (!cpu->created) { + qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); + } +} + static void qemu_dummy_start_vcpu(CPUState *cpu) { char thread_name[VCPU_THREAD_NAME_SIZE]; @@ -1915,6 +1980,8 @@ void qemu_init_vcpu(CPUState *cpu) qemu_hvf_start_vcpu(cpu); } else if (tcg_enabled()) { qemu_tcg_init_vcpu(cpu); + } else if (whpx_enabled()) { + qemu_whpx_start_vcpu(cpu); } else { qemu_dummy_start_vcpu(cpu); } diff --git a/include/sysemu/hw_accel.h b/include/sysemu/hw_accel.h index 469ffda..d2ddfb5 100644 --- a/include/sysemu/hw_accel.h +++ b/include/sysemu/hw_accel.h @@ -14,6 +14,7 @@ #include "qom/cpu.h" #include "sysemu/hax.h" #include "sysemu/kvm.h" +#include "sysemu/whpx.h" =20 static inline void cpu_synchronize_state(CPUState *cpu) { @@ -23,6 +24,9 @@ static inline void cpu_synchronize_state(CPUState *cpu) if (hax_enabled()) { hax_cpu_synchronize_state(cpu); } + if (whpx_enabled()) { + whpx_cpu_synchronize_state(cpu); + } } =20 static inline void cpu_synchronize_post_reset(CPUState *cpu) @@ -33,6 +37,9 @@ static inline void cpu_synchronize_post_reset(CPUState *c= pu) if (hax_enabled()) { hax_cpu_synchronize_post_reset(cpu); } + if (whpx_enabled()) { + whpx_cpu_synchronize_post_reset(cpu); + } } =20 static inline void cpu_synchronize_post_init(CPUState *cpu) @@ -43,6 +50,9 @@ static inline void cpu_synchronize_post_init(CPUState *cp= u) if (hax_enabled()) { hax_cpu_synchronize_post_init(cpu); } + if (whpx_enabled()) { + whpx_cpu_synchronize_post_init(cpu); + } } =20 static inline void cpu_synchronize_pre_loadvm(CPUState *cpu) @@ -53,6 +63,9 @@ static inline void cpu_synchronize_pre_loadvm(CPUState *c= pu) if (hax_enabled()) { hax_cpu_synchronize_pre_loadvm(cpu); } + if (whpx_enabled()) { + whpx_cpu_synchronize_pre_loadvm(cpu); + } } =20 #endif /* QEMU_HW_ACCEL_H */ diff --git a/target/i386/helper.c b/target/i386/helper.c index f63eb3d..9fba146 100644 --- a/target/i386/helper.c +++ b/target/i386/helper.c @@ -986,7 +986,7 @@ void cpu_report_tpr_access(CPUX86State *env, TPRAccess = access) X86CPU *cpu =3D x86_env_get_cpu(env); CPUState *cs =3D CPU(cpu); =20 - if (kvm_enabled()) { + if (kvm_enabled() || whpx_enabled()) { env->tpr_access_type =3D access; =20 cpu_interrupt(cs, CPU_INTERRUPT_TPR); --=20 1.8.3.1