From patchwork Fri Jun 21 11:29:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="g8Sre7Qk"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcB86p8tz9s4V for ; Fri, 21 Jun 2019 21:37:52 +1000 (AEST) Received: from localhost ([::1]:59876 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHra-0005cc-WE for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:37:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48969) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkT-0000b0-IA for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkQ-0005Fa-Ex for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:29 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:36805) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkQ-0005Ax-9Y for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:26 -0400 Received: by mail-wm1-x336.google.com with SMTP id u8so6232710wmm.1 for ; Fri, 21 Jun 2019 04:30:24 -0700 (PDT) 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=rF5i6pzq9tNlUQhJFdaXZR//yZxu/EIyRbH8FbNdhFc=; b=g8Sre7QknNHtFtphUdMs5eL54QdJdNbHLa5ErO8JLxbX93KhpcQqd2/yOgY3u3cz5w KWsqlBm8HFnQbtip5ineBCESCiPEFrTQBLxbXBacw46bcS5Y6ICkJdkg9ukD2tDmC575 HF7UAAsBZofU5Z8WOJrpbflq09ukSkeOWU5VYQzKcj5TE9d+TEiLB42hF8PG69Zr3MNc pQYumcb3z0LSDKonfHeLgoSFP1L8KFpt64w2M4niBtIgUO44zY++p47YU4BQkMHea8GF qqzuxEqmz+WYwxzEy5C3D/kN8LwsmGs3WDHxs1NQ77GwT+XwUeXVUQcMLbqE4zaP5YTf F1EA== 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=rF5i6pzq9tNlUQhJFdaXZR//yZxu/EIyRbH8FbNdhFc=; b=g7YnlWcg32FB5CZ0z4EscpCf2mD2EJR+55OYBBvkSLFQqQYidAFuMQGP99QiyZzLEk iuaS6g9RrrWZshkHdvbuZ5B0AtOTk9DWakTSPOgRv295geJirR/m6I4ZIeJZ2cV5GS1j gC9UoQUcT3acnx8nXBjuP57RM8unu2RSH1wRdlislEksa/Fj0Fa2N+uAp5c6CVm7iLJu kZOpVRSCEa+BFTwdJmRLhDaK9Wr6SNzs8nB6/LN8nFD90rP1gmXkbvWSvykvFZsvOAK5 13FRzbct2rEsgKigY/KXM7uQnv0NWGnFuI0M+WLebdalb859PgXMEmdGFtjw8Fzz7gQJ 91Ig== X-Gm-Message-State: APjAAAVpfZx6Dw5ER0w++Qfini880/3O4SqW61fTc6XsHZshBTNFy61C i+0VysX9X+JQwUfE+hugLwlVcMgZ X-Google-Smtp-Source: APXvYqxPeiv7kTBkZkbvR3QsBfWkHJN6a+axIiGTt7CVpNX35ck1sxbGjtJ256JsZ75CY+E166IZUw== X-Received: by 2002:a1c:6156:: with SMTP id v83mr4043366wmb.81.1561116623218; Fri, 21 Jun 2019 04:30:23 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:22 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:29:56 +0200 Message-Id: <1561116620-22245-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::336 Subject: [Qemu-devel] [PULL 01/25] kvm-all: Add/update fprintf's for kvm_*_ioeventfd_del X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yury Kotov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Yury Kotov Signed-off-by: Yury Kotov Message-Id: <20190607090830.18807-1-yury-kotov@yandex-team.ru> Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index b0c4bed..d2f481a 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -863,8 +863,8 @@ static void kvm_mem_ioeventfd_add(MemoryListener *listener, data, true, int128_get64(section->size), match_data); if (r < 0) { - fprintf(stderr, "%s: error adding ioeventfd: %s\n", - __func__, strerror(-r)); + fprintf(stderr, "%s: error adding ioeventfd: %s (%d)\n", + __func__, strerror(-r), -r); abort(); } } @@ -881,6 +881,8 @@ static void kvm_mem_ioeventfd_del(MemoryListener *listener, data, false, int128_get64(section->size), match_data); if (r < 0) { + fprintf(stderr, "%s: error deleting ioeventfd: %s (%d)\n", + __func__, strerror(-r), -r); abort(); } } @@ -897,8 +899,8 @@ static void kvm_io_ioeventfd_add(MemoryListener *listener, data, true, int128_get64(section->size), match_data); if (r < 0) { - fprintf(stderr, "%s: error adding ioeventfd: %s\n", - __func__, strerror(-r)); + fprintf(stderr, "%s: error adding ioeventfd: %s (%d)\n", + __func__, strerror(-r), -r); abort(); } } @@ -916,6 +918,8 @@ static void kvm_io_ioeventfd_del(MemoryListener *listener, data, false, int128_get64(section->size), match_data); if (r < 0) { + fprintf(stderr, "%s: error deleting ioeventfd: %s (%d)\n", + __func__, strerror(-r), -r); abort(); } } From patchwork Fri Jun 21 11:29:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ICy7sHW5"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Vc9R6xpZz9s4V for ; Fri, 21 Jun 2019 21:37:15 +1000 (AEST) Received: from localhost ([::1]:59870 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHqz-0004Vg-Vy for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:37:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48963) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkT-0000ar-Fh for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkQ-0005Ev-Bu for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:29 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:38544) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkQ-0005Cn-42 for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:26 -0400 Received: by mail-wm1-x341.google.com with SMTP id s15so6220186wmj.3 for ; Fri, 21 Jun 2019 04:30:25 -0700 (PDT) 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=ke6hwa+fUFiQaqvIXIEK/11GyBhYea2HOMTU01E3LaM=; b=ICy7sHW5samAXJ7/H8BTDY1DCLswqB7AegKSlPf4opmnZtESAMSlHM81f2Apcj+kVs 2L2gEQgWet/3V+UkxfNj/r3pk5h5L1jhyZaPssTkmAg9WtzaJAixE5PUr9EDyT4qM3mH 0vZpL4nYLFomhC/jthDJxrKjhGd1O0D7QMQEq9phdFphKiH10dUVkYUa7xhv3pTRtjmw 481/vO99Z/Z7OhuTo5uhFQuyWWpFRfk7Y8LUZ+Pej1MHOgep3sOZ0WulmyVb3fNyMVUR Jp7atNdCP+9js/qzmV30yw+rDw3nL6fwtKTp9deFbDSwstKplmLRfbM2beaS8QiK6S8Y luLQ== 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=ke6hwa+fUFiQaqvIXIEK/11GyBhYea2HOMTU01E3LaM=; b=gw9K1KMr1L8xD97Z3wYO3cUugTehWandVZUFVaQEnfTOMjI9NP0RFghx6occgGOvh+ gdszCflNB6wJdCZJKf9g+r+bA4j19qzzCU0kaiZ9irVkHr0s1S1D+7kxipM+rKm0/qzg l4qsWstlmswkaFYML8llugYBvn3cWxiqXVpk5U1zTi+JZ+y2R+4ZcK9oesP25LGxShrJ DStQgiC6M0dAarWgNJoZ7yhgikJkdpDdhsKnxYeK9sIZapYX682204VroNmjHG2YTRm2 vsg4NWMOEYNttxB9ypOS8DQrK3jun9Oq5NYN7qCE/gPGrpAJdEr+Thg1b9SOE8RSH/lw bRYw== X-Gm-Message-State: APjAAAUx9mdGHBtANiE3IsoqR5cNieI7np0CGjdgmfQye3LlhOJHuILv iATpr6oBcpkBpbFQGHDVdaAjvZAe X-Google-Smtp-Source: APXvYqzs5bQBhvJk07wBq1ilqh66P6ED7DpRePxiIYfEagBtxpEVvAS4d3qjQcPgcanWWaewn20WZw== X-Received: by 2002:a1c:9a53:: with SMTP id c80mr3609041wme.173.1561116624284; Fri, 21 Jun 2019 04:30:24 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:29:57 +0200 Message-Id: <1561116620-22245-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::341 Subject: [Qemu-devel] [PULL 02/25] hax: Honor CPUState::halted X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Colin Xu , Yu Ning , Chuanxiao Dong Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Colin Xu QEMU tracks whether a vcpu is halted using CPUState::halted. E.g., after initialization or reset, halted is 0 for the BSP (vcpu 0) and 1 for the APs (vcpu 1, 2, ...). A halted vcpu should not be handed to the hypervisor to run (e.g. hax_vcpu_run()). Under HAXM, Android Emulator sometimes boots into a "vcpu shutdown request" error while executing in SeaBIOS, with the HAXM driver logging a guest triple fault in vcpu 1, 2, ... at RIP 0x3. That is ultimately because the HAX accelerator asks HAXM to run those APs when they are still in the halted state. Normally, the vcpu thread for an AP will start by looping in qemu_wait_io_event(), until the BSP kicks it via a pair of IPIs (INIT followed by SIPI). But because the HAX accelerator does not honor cpu->halted, it allows the AP vcpu thread to proceed to hax_vcpu_run() as soon as it receives any kick, even if the kick does not come from the BSP. It turns out that emulator has a worker thread which periodically kicks every vcpu thread (possibly to collect CPU usage data), and if one of these kicks comes before those by the BSP, the AP will start execution from the wrong RIP, resulting in the aforementioned SMP boot failure. The solution is inspired by the KVM accelerator (credit to Chuanxiao Dong for the pointer): 1. Get rid of questionable logic that unconditionally resets cpu->halted before hax_vcpu_run(). Instead, only reset it at the right moments (there are only a few "unhalt" events). 2. Add a check for cpu->halted before hax_vcpu_run(). Note that although the non-Unrestricted Guest (!ug_platform) code path also forcibly resets cpu->halted, it is left untouched, because only the UG code path supports SMP guests. The patch is first merged to android emulator with Change-Id: I9c5752cc737fd305d7eace1768ea12a07309d716 Cc: Yu Ning Cc: Chuanxiao Dong Signed-off-by: Colin Xu Message-Id: <20190610021939.13669-1-colin.xu@intel.com> --- cpus.c | 1 - target/i386/hax-all.c | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/cpus.c b/cpus.c index dde3b7b..1af51b7 100644 --- a/cpus.c +++ b/cpus.c @@ -1594,7 +1594,6 @@ static void *qemu_hax_cpu_thread_fn(void *arg) cpu->thread_id = qemu_get_thread_id(); cpu->created = true; - cpu->halted = 0; current_cpu = cpu; hax_init_vcpu(cpu); diff --git a/target/i386/hax-all.c b/target/i386/hax-all.c index 64fd51a..9e7b779 100644 --- a/target/i386/hax-all.c +++ b/target/i386/hax-all.c @@ -471,13 +471,35 @@ static int hax_vcpu_hax_exec(CPUArchState *env) return 0; } - cpu->halted = 0; - if (cpu->interrupt_request & CPU_INTERRUPT_POLL) { cpu->interrupt_request &= ~CPU_INTERRUPT_POLL; apic_poll_irq(x86_cpu->apic_state); } + /* After a vcpu is halted (either because it is an AP and has just been + * reset, or because it has executed the HLT instruction), it will not be + * run (hax_vcpu_run()) until it is unhalted. The next few if blocks check + * for events that may change the halted state of this vcpu: + * a) Maskable interrupt, when RFLAGS.IF is 1; + * Note: env->eflags may not reflect the current RFLAGS state, because + * it is not updated after each hax_vcpu_run(). We cannot afford + * to fail to recognize any unhalt-by-maskable-interrupt event + * (in which case the vcpu will halt forever), and yet we cannot + * afford the overhead of hax_vcpu_sync_state(). The current + * solution is to err on the side of caution and have the HLT + * handler (see case HAX_EXIT_HLT below) unconditionally set the + * IF_MASK bit in env->eflags, which, in effect, disables the + * RFLAGS.IF check. + * b) NMI; + * c) INIT signal; + * d) SIPI signal. + */ + if (((cpu->interrupt_request & CPU_INTERRUPT_HARD) && + (env->eflags & IF_MASK)) || + (cpu->interrupt_request & CPU_INTERRUPT_NMI)) { + cpu->halted = 0; + } + if (cpu->interrupt_request & CPU_INTERRUPT_INIT) { DPRINTF("\nhax_vcpu_hax_exec: handling INIT for %d\n", cpu->cpu_index); @@ -493,6 +515,16 @@ static int hax_vcpu_hax_exec(CPUArchState *env) hax_vcpu_sync_state(env, 1); } + if (cpu->halted) { + /* If this vcpu is halted, we must not ask HAXM to run it. Instead, we + * break out of hax_smp_cpu_exec() as if this vcpu had executed HLT. + * That way, this vcpu thread will be trapped in qemu_wait_io_event(), + * until the vcpu is unhalted. + */ + cpu->exception_index = EXCP_HLT; + return 0; + } + do { int hax_ret; From patchwork Fri Jun 21 11:29:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qAgpOt+G"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Vc3D6FdCz9sBr for ; Fri, 21 Jun 2019 21:31:52 +1000 (AEST) Received: from localhost ([::1]:59834 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHlm-0000jN-Qi for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:31:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48972) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkT-0000bY-So for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkQ-0005GL-QD for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:29 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:37976) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkQ-0005D4-IF for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:26 -0400 Received: by mail-wm1-x331.google.com with SMTP id s15so6220245wmj.3 for ; Fri, 21 Jun 2019 04:30:26 -0700 (PDT) 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=jRxVFuHpbr4EI8miJwJfPa6C/23qivxTRXPqmbxVszk=; b=qAgpOt+GYspSoaEc+aCABlIrln/fOdwPZkCCKveplfs2PIvdM8P/9zF/Mm3IqAAoXt anUAOs2xeBBEFUGILUMSEMhi5gnHs2w1aMKvuJyZmRIP1cfw2HN21S5ZmlD4YLrw1UBf nH3PXG0MXberv9bfiYURGL70IWaFc0dwIi6vUrt6r5jln+uOpwj1xeh2hdQkdItEld+M NNnitOhnCXmQNrpK+qSoi5SyKJcbt7+kVykaI//M6hW7bkznM6/0Fo55Kxpl12gpj6Q6 bYCmdYQe3WVJRP/zv+7byYj+Zrr/R6c6n7dSQpMO63KlCo5imvBKh8GoDUTlU03upmsA XUFg== 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=jRxVFuHpbr4EI8miJwJfPa6C/23qivxTRXPqmbxVszk=; b=lEI/9lc1UuDv4/VF8oFzKPGCL0fd7l8oDtDBqn9aWYzHjL8ERqPYz6fuz8dPTkrS8H yGW9wzB45ggZqOI20XmGScWFJM/y655fw3zRvTm/fxVWuIyYnUMcsj3Dxnv3c3/BP47d AKPUWEtFv4f1DrJvyhtZb54k9gMPoGKwhrb6pQmt28J/YX7D0o9pPuCxfzMEE6fgQrO+ hLeMa0n5UIm58BGCamaseff0ahSfC88SvCa7Kv9uq90o8gqKwwSNRR1hdxJCzxN32K/x b5xZ3XnQA9OSrmJn4cLlbGEaq+TpBj2N4kX3bUsSbTMeauRCDPHjG0ZABlBOUHe7YAg8 re9w== X-Gm-Message-State: APjAAAU7887cN+4s2h7iAf8AvSTovNxQC1a4KA/uo/G6htAJ12UL9BH3 BpidAbJ3e2CSSSy3ERBQXK44KcAr X-Google-Smtp-Source: APXvYqxPJDl8cLHyEOWanQ/KJ35uIK2wbjBITMC2nbCilS1VHlS46fJDyi8goOue+1iaFej+t+hQQg== X-Received: by 2002:a7b:cb94:: with SMTP id m20mr3694250wmi.144.1561116625230; Fri, 21 Jun 2019 04:30:25 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:29:58 +0200 Message-Id: <1561116620-22245-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::331 Subject: [Qemu-devel] [PULL 03/25] i386/kvm: convert hyperv enlightenments properties from bools to bits X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vitaly Kuznetsov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Vitaly Kuznetsov Representing Hyper-V properties as bits will allow us to check features and dependencies between them in a natural way. Suggested-by: Roman Kagan Signed-off-by: Vitaly Kuznetsov Message-Id: <20190517141924.19024-2-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 3 +- target/i386/cpu.c | 44 ++++++++++++++++++--------- target/i386/cpu.h | 37 ++++++++++++++--------- target/i386/hyperv.c | 2 +- target/i386/kvm.c | 83 +++++++++++++++++++++------------------------------ target/i386/machine.c | 2 +- 6 files changed, 91 insertions(+), 80 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 2c5446b..e41192b 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2386,7 +2386,8 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, } cpu->thread_id = topo.smt_id; - if (cpu->hyperv_vpindex && !kvm_hv_vpindex_settable()) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX) && + !kvm_hv_vpindex_settable()) { error_setg(errp, "kernel doesn't allow setting HyperV VP_INDEX"); return; } diff --git a/target/i386/cpu.c b/target/i386/cpu.c index fbed2eb..e90c1ac 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5853,21 +5853,37 @@ static Property x86_cpu_properties[] = { #endif DEFINE_PROP_INT32("node-id", X86CPU, node_id, CPU_UNSET_NUMA_NODE_ID), DEFINE_PROP_BOOL("pmu", X86CPU, enable_pmu, false), + { .name = "hv-spinlocks", .info = &qdev_prop_spinlocks }, - DEFINE_PROP_BOOL("hv-relaxed", X86CPU, hyperv_relaxed_timing, false), - DEFINE_PROP_BOOL("hv-vapic", X86CPU, hyperv_vapic, false), - DEFINE_PROP_BOOL("hv-time", X86CPU, hyperv_time, false), - DEFINE_PROP_BOOL("hv-crash", X86CPU, hyperv_crash, false), - DEFINE_PROP_BOOL("hv-reset", X86CPU, hyperv_reset, false), - DEFINE_PROP_BOOL("hv-vpindex", X86CPU, hyperv_vpindex, false), - DEFINE_PROP_BOOL("hv-runtime", X86CPU, hyperv_runtime, false), - DEFINE_PROP_BOOL("hv-synic", X86CPU, hyperv_synic, false), - DEFINE_PROP_BOOL("hv-stimer", X86CPU, hyperv_stimer, false), - DEFINE_PROP_BOOL("hv-frequencies", X86CPU, hyperv_frequencies, false), - DEFINE_PROP_BOOL("hv-reenlightenment", X86CPU, hyperv_reenlightenment, false), - DEFINE_PROP_BOOL("hv-tlbflush", X86CPU, hyperv_tlbflush, false), - DEFINE_PROP_BOOL("hv-evmcs", X86CPU, hyperv_evmcs, false), - DEFINE_PROP_BOOL("hv-ipi", X86CPU, hyperv_ipi, false), + DEFINE_PROP_BIT64("hv-relaxed", X86CPU, hyperv_features, + HYPERV_FEAT_RELAXED, 0), + DEFINE_PROP_BIT64("hv-vapic", X86CPU, hyperv_features, + HYPERV_FEAT_VAPIC, 0), + DEFINE_PROP_BIT64("hv-time", X86CPU, hyperv_features, + HYPERV_FEAT_TIME, 0), + DEFINE_PROP_BIT64("hv-crash", X86CPU, hyperv_features, + HYPERV_FEAT_CRASH, 0), + DEFINE_PROP_BIT64("hv-reset", X86CPU, hyperv_features, + HYPERV_FEAT_RESET, 0), + DEFINE_PROP_BIT64("hv-vpindex", X86CPU, hyperv_features, + HYPERV_FEAT_VPINDEX, 0), + DEFINE_PROP_BIT64("hv-runtime", X86CPU, hyperv_features, + HYPERV_FEAT_RUNTIME, 0), + DEFINE_PROP_BIT64("hv-synic", X86CPU, hyperv_features, + HYPERV_FEAT_SYNIC, 0), + DEFINE_PROP_BIT64("hv-stimer", X86CPU, hyperv_features, + HYPERV_FEAT_STIMER, 0), + DEFINE_PROP_BIT64("hv-frequencies", X86CPU, hyperv_features, + HYPERV_FEAT_FREQUENCIES, 0), + DEFINE_PROP_BIT64("hv-reenlightenment", X86CPU, hyperv_features, + HYPERV_FEAT_REENLIGHTENMENT, 0), + DEFINE_PROP_BIT64("hv-tlbflush", X86CPU, hyperv_features, + HYPERV_FEAT_TLBFLUSH, 0), + DEFINE_PROP_BIT64("hv-evmcs", X86CPU, hyperv_features, + HYPERV_FEAT_EVMCS, 0), + DEFINE_PROP_BIT64("hv-ipi", X86CPU, hyperv_features, + HYPERV_FEAT_IPI, 0), + DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true), DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false), DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true), diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 0732e05..30cd1a0 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -734,6 +734,22 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; #define MSR_ARCH_CAP_SKIP_L1DFL_VMENTRY (1U << 3) #define MSR_ARCH_CAP_SSB_NO (1U << 4) +/* Supported Hyper-V Enlightenments */ +#define HYPERV_FEAT_RELAXED 0 +#define HYPERV_FEAT_VAPIC 1 +#define HYPERV_FEAT_TIME 2 +#define HYPERV_FEAT_CRASH 3 +#define HYPERV_FEAT_RESET 4 +#define HYPERV_FEAT_VPINDEX 5 +#define HYPERV_FEAT_RUNTIME 6 +#define HYPERV_FEAT_SYNIC 7 +#define HYPERV_FEAT_STIMER 8 +#define HYPERV_FEAT_FREQUENCIES 9 +#define HYPERV_FEAT_REENLIGHTENMENT 10 +#define HYPERV_FEAT_TLBFLUSH 11 +#define HYPERV_FEAT_EVMCS 12 +#define HYPERV_FEAT_IPI 13 + #ifndef HYPERV_SPINLOCK_NEVER_RETRY #define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF #endif @@ -1370,23 +1386,11 @@ struct X86CPU { CPUNegativeOffsetState neg; CPUX86State env; - bool hyperv_vapic; - bool hyperv_relaxed_timing; int hyperv_spinlock_attempts; char *hyperv_vendor_id; - bool hyperv_time; - bool hyperv_crash; - bool hyperv_reset; - bool hyperv_vpindex; - bool hyperv_runtime; - bool hyperv_synic; bool hyperv_synic_kvm_only; - bool hyperv_stimer; - bool hyperv_frequencies; - bool hyperv_reenlightenment; - bool hyperv_tlbflush; - bool hyperv_evmcs; - bool hyperv_ipi; + uint64_t hyperv_features; + bool check_cpuid; bool enforce_cpuid; bool expose_kvm; @@ -1906,4 +1910,9 @@ void x86_cpu_xrstor_all_areas(X86CPU *cpu, const X86XSaveArea *buf); void x86_cpu_xsave_all_areas(X86CPU *cpu, X86XSaveArea *buf); void x86_update_hflags(CPUX86State* env); +static inline bool hyperv_feat_enabled(X86CPU *cpu, int feat) +{ + return !!(cpu->hyperv_features & BIT(feat)); +} + #endif /* I386_CPU_H */ diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index b264a28..26efc1e 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -52,7 +52,7 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) switch (exit->type) { case KVM_EXIT_HYPERV_SYNIC: - if (!cpu->hyperv_synic) { + if (!hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC)) { return -1; } diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 6899061..b34eb81 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -634,28 +634,12 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs) #define KVM_CPUID_SIGNATURE_NEXT 0x40000100 #endif -static bool hyperv_hypercall_available(X86CPU *cpu) -{ - return cpu->hyperv_vapic || - (cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY); -} - static bool hyperv_enabled(X86CPU *cpu) { CPUState *cs = CPU(cpu); return kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0 && - (hyperv_hypercall_available(cpu) || - cpu->hyperv_time || - cpu->hyperv_relaxed_timing || - cpu->hyperv_crash || - cpu->hyperv_reset || - cpu->hyperv_vpindex || - cpu->hyperv_runtime || - cpu->hyperv_synic || - cpu->hyperv_stimer || - cpu->hyperv_reenlightenment || - cpu->hyperv_tlbflush || - cpu->hyperv_ipi); + ((cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY) || + cpu->hyperv_features); } static int kvm_arch_set_tsc_khz(CPUState *cs) @@ -704,14 +688,14 @@ static int hyperv_handle_properties(CPUState *cs) X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; - if (cpu->hyperv_relaxed_timing) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_RELAXED)) { env->features[FEAT_HYPERV_EAX] |= HV_HYPERCALL_AVAILABLE; } - if (cpu->hyperv_vapic) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VAPIC)) { env->features[FEAT_HYPERV_EAX] |= HV_HYPERCALL_AVAILABLE; env->features[FEAT_HYPERV_EAX] |= HV_APIC_ACCESS_AVAILABLE; } - if (cpu->hyperv_time) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_TIME)) { if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_TIME) <= 0) { fprintf(stderr, "Hyper-V clocksources " "(requested by 'hv-time' cpu flag) " @@ -722,7 +706,7 @@ static int hyperv_handle_properties(CPUState *cs) env->features[FEAT_HYPERV_EAX] |= HV_TIME_REF_COUNT_AVAILABLE; env->features[FEAT_HYPERV_EAX] |= HV_REFERENCE_TSC_AVAILABLE; } - if (cpu->hyperv_frequencies) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_FREQUENCIES)) { if (!has_msr_hv_frequencies) { fprintf(stderr, "Hyper-V frequency MSRs " "(requested by 'hv-frequencies' cpu flag) " @@ -732,7 +716,7 @@ static int hyperv_handle_properties(CPUState *cs) env->features[FEAT_HYPERV_EAX] |= HV_ACCESS_FREQUENCY_MSRS; env->features[FEAT_HYPERV_EDX] |= HV_FREQUENCY_MSRS_AVAILABLE; } - if (cpu->hyperv_crash) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_CRASH)) { if (!has_msr_hv_crash) { fprintf(stderr, "Hyper-V crash MSRs " "(requested by 'hv-crash' cpu flag) " @@ -741,7 +725,7 @@ static int hyperv_handle_properties(CPUState *cs) } env->features[FEAT_HYPERV_EDX] |= HV_GUEST_CRASH_MSR_AVAILABLE; } - if (cpu->hyperv_reenlightenment) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_REENLIGHTENMENT)) { if (!has_msr_hv_reenlightenment) { fprintf(stderr, "Hyper-V Reenlightenment MSRs " @@ -752,7 +736,7 @@ static int hyperv_handle_properties(CPUState *cs) env->features[FEAT_HYPERV_EAX] |= HV_ACCESS_REENLIGHTENMENTS_CONTROL; } env->features[FEAT_HYPERV_EDX] |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE; - if (cpu->hyperv_reset) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_RESET)) { if (!has_msr_hv_reset) { fprintf(stderr, "Hyper-V reset MSR " "(requested by 'hv-reset' cpu flag) " @@ -761,7 +745,7 @@ static int hyperv_handle_properties(CPUState *cs) } env->features[FEAT_HYPERV_EAX] |= HV_RESET_AVAILABLE; } - if (cpu->hyperv_vpindex) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX)) { if (!has_msr_hv_vpindex) { fprintf(stderr, "Hyper-V VP_INDEX MSR " "(requested by 'hv-vpindex' cpu flag) " @@ -770,7 +754,7 @@ static int hyperv_handle_properties(CPUState *cs) } env->features[FEAT_HYPERV_EAX] |= HV_VP_INDEX_AVAILABLE; } - if (cpu->hyperv_runtime) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_RUNTIME)) { if (!has_msr_hv_runtime) { fprintf(stderr, "Hyper-V VP_RUNTIME MSR " "(requested by 'hv-runtime' cpu flag) " @@ -779,10 +763,10 @@ static int hyperv_handle_properties(CPUState *cs) } env->features[FEAT_HYPERV_EAX] |= HV_VP_RUNTIME_AVAILABLE; } - if (cpu->hyperv_synic) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC)) { unsigned int cap = KVM_CAP_HYPERV_SYNIC; if (!cpu->hyperv_synic_kvm_only) { - if (!cpu->hyperv_vpindex) { + if (!hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX)) { fprintf(stderr, "Hyper-V SynIC " "(requested by 'hv-synic' cpu flag) " "requires Hyper-V VP_INDEX ('hv-vpindex')\n"); @@ -799,20 +783,20 @@ static int hyperv_handle_properties(CPUState *cs) env->features[FEAT_HYPERV_EAX] |= HV_SYNIC_AVAILABLE; } - if (cpu->hyperv_stimer) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_STIMER)) { if (!has_msr_hv_stimer) { fprintf(stderr, "Hyper-V timers aren't supported by kernel\n"); return -ENOSYS; } env->features[FEAT_HYPERV_EAX] |= HV_SYNTIMERS_AVAILABLE; } - if (cpu->hyperv_relaxed_timing) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_RELAXED)) { env->features[FEAT_HV_RECOMM_EAX] |= HV_RELAXED_TIMING_RECOMMENDED; } - if (cpu->hyperv_vapic) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VAPIC)) { env->features[FEAT_HV_RECOMM_EAX] |= HV_APIC_ACCESS_RECOMMENDED; } - if (cpu->hyperv_tlbflush) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_TLBFLUSH)) { if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_TLBFLUSH) <= 0) { fprintf(stderr, "Hyper-V TLB flush support " @@ -823,7 +807,7 @@ static int hyperv_handle_properties(CPUState *cs) env->features[FEAT_HV_RECOMM_EAX] |= HV_REMOTE_TLB_FLUSH_RECOMMENDED; env->features[FEAT_HV_RECOMM_EAX] |= HV_EX_PROCESSOR_MASKS_RECOMMENDED; } - if (cpu->hyperv_ipi) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_IPI)) { if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_SEND_IPI) <= 0) { fprintf(stderr, "Hyper-V IPI send support " @@ -834,7 +818,7 @@ static int hyperv_handle_properties(CPUState *cs) env->features[FEAT_HV_RECOMM_EAX] |= HV_CLUSTER_IPI_RECOMMENDED; env->features[FEAT_HV_RECOMM_EAX] |= HV_EX_PROCESSOR_MASKS_RECOMMENDED; } - if (cpu->hyperv_evmcs) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS)) { uint16_t evmcs_version; if (kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0, @@ -856,7 +840,7 @@ static int hyperv_init_vcpu(X86CPU *cpu) CPUState *cs = CPU(cpu); int ret; - if (cpu->hyperv_vpindex && !hv_vpindex_settable) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX) && !hv_vpindex_settable) { /* * the kernel doesn't support setting vp_index; assert that its value * is in sync @@ -881,7 +865,7 @@ static int hyperv_init_vcpu(X86CPU *cpu) } } - if (cpu->hyperv_synic) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC)) { uint32_t synic_cap = cpu->hyperv_synic_kvm_only ? KVM_CAP_HYPERV_SYNIC : KVM_CAP_HYPERV_SYNIC2; ret = kvm_vcpu_enable_cap(cs, synic_cap, 0); @@ -972,7 +956,7 @@ int kvm_arch_init_vcpu(CPUState *cs) memset(signature, 0, 12); memcpy(signature, cpu->hyperv_vendor_id, len); } - c->eax = cpu->hyperv_evmcs ? + c->eax = hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) ? HV_CPUID_NESTED_FEATURES : HV_CPUID_IMPLEMENT_LIMITS; c->ebx = signature[0]; c->ecx = signature[1]; @@ -1016,7 +1000,7 @@ int kvm_arch_init_vcpu(CPUState *cs) kvm_base = KVM_CPUID_SIGNATURE_NEXT; has_msr_hv_hypercall = true; - if (cpu->hyperv_evmcs) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS)) { __u32 function; /* Create zeroed 0x40000006..0x40000009 leaves */ @@ -1360,7 +1344,7 @@ void kvm_arch_reset_vcpu(X86CPU *cpu) env->mp_state = KVM_MP_STATE_RUNNABLE; } - if (cpu->hyperv_synic) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC)) { int i; for (i = 0; i < ARRAY_SIZE(env->msr_hv_synic_sint); i++) { env->msr_hv_synic_sint[i] = HV_SINT_MASKED; @@ -2100,11 +2084,11 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_add(cpu, HV_X64_MSR_HYPERCALL, env->msr_hv_hypercall); } - if (cpu->hyperv_time) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_TIME)) { kvm_msr_entry_add(cpu, HV_X64_MSR_REFERENCE_TSC, env->msr_hv_tsc); } - if (cpu->hyperv_reenlightenment) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_REENLIGHTENMENT)) { kvm_msr_entry_add(cpu, HV_X64_MSR_REENLIGHTENMENT_CONTROL, env->msr_hv_reenlightenment_control); kvm_msr_entry_add(cpu, HV_X64_MSR_TSC_EMULATION_CONTROL, @@ -2113,7 +2097,7 @@ static int kvm_put_msrs(X86CPU *cpu, int level) env->msr_hv_tsc_emulation_status); } } - if (cpu->hyperv_vapic) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VAPIC)) { kvm_msr_entry_add(cpu, HV_X64_MSR_APIC_ASSIST_PAGE, env->msr_hv_vapic); } @@ -2129,11 +2113,12 @@ static int kvm_put_msrs(X86CPU *cpu, int level) if (has_msr_hv_runtime) { kvm_msr_entry_add(cpu, HV_X64_MSR_VP_RUNTIME, env->msr_hv_runtime); } - if (cpu->hyperv_vpindex && hv_vpindex_settable) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX) + && hv_vpindex_settable) { kvm_msr_entry_add(cpu, HV_X64_MSR_VP_INDEX, hyperv_vp_index(CPU(cpu))); } - if (cpu->hyperv_synic) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC)) { int j; kvm_msr_entry_add(cpu, HV_X64_MSR_SVERSION, HV_SYNIC_VERSION); @@ -2473,13 +2458,13 @@ static int kvm_get_msrs(X86CPU *cpu) kvm_msr_entry_add(cpu, HV_X64_MSR_HYPERCALL, 0); kvm_msr_entry_add(cpu, HV_X64_MSR_GUEST_OS_ID, 0); } - if (cpu->hyperv_vapic) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VAPIC)) { kvm_msr_entry_add(cpu, HV_X64_MSR_APIC_ASSIST_PAGE, 0); } - if (cpu->hyperv_time) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_TIME)) { kvm_msr_entry_add(cpu, HV_X64_MSR_REFERENCE_TSC, 0); } - if (cpu->hyperv_reenlightenment) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_REENLIGHTENMENT)) { kvm_msr_entry_add(cpu, HV_X64_MSR_REENLIGHTENMENT_CONTROL, 0); kvm_msr_entry_add(cpu, HV_X64_MSR_TSC_EMULATION_CONTROL, 0); kvm_msr_entry_add(cpu, HV_X64_MSR_TSC_EMULATION_STATUS, 0); @@ -2494,7 +2479,7 @@ static int kvm_get_msrs(X86CPU *cpu) if (has_msr_hv_runtime) { kvm_msr_entry_add(cpu, HV_X64_MSR_VP_RUNTIME, 0); } - if (cpu->hyperv_synic) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC)) { uint32_t msr; kvm_msr_entry_add(cpu, HV_X64_MSR_SCONTROL, 0); diff --git a/target/i386/machine.c b/target/i386/machine.c index 4aff1a7..a39ce7f 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -634,7 +634,7 @@ static bool hyperv_runtime_enable_needed(void *opaque) X86CPU *cpu = opaque; CPUX86State *env = &cpu->env; - if (!cpu->hyperv_runtime) { + if (!hyperv_feat_enabled(cpu, HYPERV_FEAT_RUNTIME)) { return false; } From patchwork Fri Jun 21 11:30:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XEp1kIV2"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcGW0Gsxz9sNk for ; Fri, 21 Jun 2019 21:41:39 +1000 (AEST) Received: from localhost ([::1]:59902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHvF-0000tP-2K for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:41:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49018) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkW-0000f2-FG for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkT-0005Na-CR for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:32 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:35977) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkT-0005L4-4a for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:29 -0400 Received: by mail-wm1-x343.google.com with SMTP id u8so6232947wmm.1 for ; Fri, 21 Jun 2019 04:30:29 -0700 (PDT) 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=Qznel7g6fB8yvYmlOFOQWGexcJCqwQlz1eNoYvx8nfE=; b=XEp1kIV2RKEqVva3kHtsGlNrWGkhKrDoZfI6amrsfsYyGbp41lzu1CcbhW9Mt2GAxa MMrWwm07050bsvoRTATsx1iG2LfzwIbrVPj6KQVTsH9tlMusUq8v8mIx5WGd8Z1E5UWI t8LxpcT/Fa4XL/XRC2mkdIzSUoHCqXMgVRO8nLQyBXo1b8YtlPfDH6pBT0vpgmvcinZg /dnR9fOC8VIFC/rq7dETeyx+5LYGCxgstYCJin1S0NYsZ7Zn38rLZ4q7rajy6HungFeV U/82R6rwYkVhOYQ32TqwBL54LOgKNL314Bm8MuSeusp3PrcCaWT7QdSfVJUZC7pDQiF/ LEjQ== 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=Qznel7g6fB8yvYmlOFOQWGexcJCqwQlz1eNoYvx8nfE=; b=jsFdMlIMOxXXE5D/6aMsPnKdsR2LSCpArncs5J2J0rOinnyf1peJ29yeJ2fUztC7PN 2wg5mrKo8uBBI0O1SWHDMqDcSSOoX7pNK1Go0G7B4qvxJgzZSm67knIKH+rZ5sz/ckis +mW5urC8mb8cM4AKpR6afHe8iYqujlWW3m7LjFVU7P58tw3YANV1sKjuZ0NCS8bJxcVF KpfQa8PXD57fry26jrN6ObTucTBKQ+e0vMmTP6FTch6mBVgec6Meu29oPrYy5q7LyYOZ TS2oGHgB8ugLlo6FnfAgAbQmSdKqjjetS/cWbkRW1WSlJdl91tKHYBMcnbMelOW7sRB7 F5Dw== X-Gm-Message-State: APjAAAWJrK/oQsDrsbi9bXwWEjf8FHklLexN/p/Rhqd4gViTp9y7oHbG ZNymAkzBorBXcx90ZiTWZCTsZ0NO X-Google-Smtp-Source: APXvYqyDcm3kg3tpN+lS35uSaqnBr6e3ENbqLZKcKdqZeNd3daF3XBVsFxrOVvE0TnDoHc2Fa4SOMQ== X-Received: by 2002:a1c:6a17:: with SMTP id f23mr3810261wmc.91.1561116627720; Fri, 21 Jun 2019 04:30:27 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:00 +0200 Message-Id: <1561116620-22245-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::343 Subject: [Qemu-devel] [PULL 05/25] i386/kvm: move Hyper-V CPUID filling to hyperv_handle_properties() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vitaly Kuznetsov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Vitaly Kuznetsov Let's consolidate Hyper-V features handling in hyperv_handle_properties(). The change is necessary to support 'hv-passthrough' mode as we'll be just copying CPUIDs from KVM instead of filling them in. Signed-off-by: Vitaly Kuznetsov Message-Id: <20190517141924.19024-4-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 163 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 90 insertions(+), 73 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index cd492d4..a041b4d 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1013,13 +1013,25 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid, return 0; } -static int hyperv_handle_properties(CPUState *cs) +/* + * Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_ent in + * case of success, errno < 0 in case of failure and 0 when no Hyper-V + * extentions are enabled. + */ +static int hyperv_handle_properties(CPUState *cs, + struct kvm_cpuid_entry2 *cpuid_ent) { X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; struct kvm_cpuid2 *cpuid; + struct kvm_cpuid_entry2 *c; + uint32_t signature[3]; + uint32_t cpuid_i = 0; int r = 0; + if (!hyperv_enabled(cpu)) + return 0; + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS)) { uint16_t evmcs_version; @@ -1068,9 +1080,80 @@ static int hyperv_handle_properties(CPUState *cs) /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ env->features[FEAT_HYPERV_EDX] |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE; + if (r) { + r = -ENOSYS; + goto free; + } + + c = &cpuid_ent[cpuid_i++]; + c->function = HV_CPUID_VENDOR_AND_MAX_FUNCTIONS; + if (!cpu->hyperv_vendor_id) { + memcpy(signature, "Microsoft Hv", 12); + } else { + size_t len = strlen(cpu->hyperv_vendor_id); + + if (len > 12) { + error_report("hv-vendor-id truncated to 12 characters"); + len = 12; + } + memset(signature, 0, 12); + memcpy(signature, cpu->hyperv_vendor_id, len); + } + c->eax = hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) ? + HV_CPUID_NESTED_FEATURES : HV_CPUID_IMPLEMENT_LIMITS; + c->ebx = signature[0]; + c->ecx = signature[1]; + c->edx = signature[2]; + + c = &cpuid_ent[cpuid_i++]; + c->function = HV_CPUID_INTERFACE; + memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12); + c->eax = signature[0]; + c->ebx = 0; + c->ecx = 0; + c->edx = 0; + + c = &cpuid_ent[cpuid_i++]; + c->function = HV_CPUID_VERSION; + c->eax = 0x00001bbc; + c->ebx = 0x00060001; + + c = &cpuid_ent[cpuid_i++]; + c->function = HV_CPUID_FEATURES; + c->eax = env->features[FEAT_HYPERV_EAX]; + c->ebx = env->features[FEAT_HYPERV_EBX]; + c->edx = env->features[FEAT_HYPERV_EDX]; + + c = &cpuid_ent[cpuid_i++]; + c->function = HV_CPUID_ENLIGHTMENT_INFO; + c->eax = env->features[FEAT_HV_RECOMM_EAX]; + c->ebx = cpu->hyperv_spinlock_attempts; + + c = &cpuid_ent[cpuid_i++]; + c->function = HV_CPUID_IMPLEMENT_LIMITS; + c->eax = cpu->hv_max_vps; + c->ebx = 0x40; + + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS)) { + __u32 function; + + /* Create zeroed 0x40000006..0x40000009 leaves */ + for (function = HV_CPUID_IMPLEMENT_LIMITS + 1; + function < HV_CPUID_NESTED_FEATURES; function++) { + c = &cpuid_ent[cpuid_i++]; + c->function = function; + } + + c = &cpuid_ent[cpuid_i++]; + c->function = HV_CPUID_NESTED_FEATURES; + c->eax = env->features[FEAT_HV_NESTED_EAX]; + } + r = cpuid_i; + +free: g_free(cpuid); - return r ? -ENOSYS : 0; + return r; } static int hyperv_init_vcpu(X86CPU *cpu) @@ -1179,79 +1262,13 @@ int kvm_arch_init_vcpu(CPUState *cs) } /* Paravirtualization CPUIDs */ - if (hyperv_enabled(cpu)) { - c = &cpuid_data.entries[cpuid_i++]; - c->function = HV_CPUID_VENDOR_AND_MAX_FUNCTIONS; - if (!cpu->hyperv_vendor_id) { - memcpy(signature, "Microsoft Hv", 12); - } else { - size_t len = strlen(cpu->hyperv_vendor_id); - - if (len > 12) { - error_report("hv-vendor-id truncated to 12 characters"); - len = 12; - } - memset(signature, 0, 12); - memcpy(signature, cpu->hyperv_vendor_id, len); - } - c->eax = hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) ? - HV_CPUID_NESTED_FEATURES : HV_CPUID_IMPLEMENT_LIMITS; - c->ebx = signature[0]; - c->ecx = signature[1]; - c->edx = signature[2]; - - c = &cpuid_data.entries[cpuid_i++]; - c->function = HV_CPUID_INTERFACE; - memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12); - c->eax = signature[0]; - c->ebx = 0; - c->ecx = 0; - c->edx = 0; - - c = &cpuid_data.entries[cpuid_i++]; - c->function = HV_CPUID_VERSION; - c->eax = 0x00001bbc; - c->ebx = 0x00060001; - - c = &cpuid_data.entries[cpuid_i++]; - c->function = HV_CPUID_FEATURES; - r = hyperv_handle_properties(cs); - if (r) { - return r; - } - c->eax = env->features[FEAT_HYPERV_EAX]; - c->ebx = env->features[FEAT_HYPERV_EBX]; - c->edx = env->features[FEAT_HYPERV_EDX]; - - c = &cpuid_data.entries[cpuid_i++]; - c->function = HV_CPUID_ENLIGHTMENT_INFO; - - c->eax = env->features[FEAT_HV_RECOMM_EAX]; - c->ebx = cpu->hyperv_spinlock_attempts; - - c = &cpuid_data.entries[cpuid_i++]; - c->function = HV_CPUID_IMPLEMENT_LIMITS; - - c->eax = cpu->hv_max_vps; - c->ebx = 0x40; - + r = hyperv_handle_properties(cs, cpuid_data.entries); + if (r < 0) { + return r; + } else if (r > 0) { + cpuid_i = r; kvm_base = KVM_CPUID_SIGNATURE_NEXT; has_msr_hv_hypercall = true; - - if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS)) { - __u32 function; - - /* Create zeroed 0x40000006..0x40000009 leaves */ - for (function = HV_CPUID_IMPLEMENT_LIMITS + 1; - function < HV_CPUID_NESTED_FEATURES; function++) { - c = &cpuid_data.entries[cpuid_i++]; - c->function = function; - } - - c = &cpuid_data.entries[cpuid_i++]; - c->function = HV_CPUID_NESTED_FEATURES; - c->eax = env->features[FEAT_HV_NESTED_EAX]; - } } if (cpu->expose_kvm) { From patchwork Fri Jun 21 11:30:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KEn+RO9j"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Vc9T1KKgz9sND for ; Fri, 21 Jun 2019 21:37:17 +1000 (AEST) Received: from localhost ([::1]:59872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHr1-0004W4-2W for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:37:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49029) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkY-0000fj-Ai for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkU-0005Qk-CV for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:34 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:45647) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkU-0005OJ-6A for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:30 -0400 Received: by mail-wr1-x42d.google.com with SMTP id f9so6189824wre.12 for ; Fri, 21 Jun 2019 04:30:30 -0700 (PDT) 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=Iq0W4QsPIXfjOn4JNS6Kd8bNeG3F7+GRE1ESQz9CIvE=; b=KEn+RO9jA57d9xQy63pdzqzckOOwhKNmBSxlZAWjWyy8a4kWGeUZbLm+4R7hA8eeVI NTQN1fULRyFxe2WBPveCWcTEsSTztQ8eP2VuS/pOfjJQ3E2yIA3NJOEo2zYmTlOG6jYs d8UM/v/CGL+4yyYt7H4edWkot6A9O/dMPkHLy5s+ALo8NGC+h2DNJgX9OBfmDo3GnbCJ yHnrUZlY8MZj4kt6LY2qN9Mx/fpptkLqt5wU9j9t3e/RhsB9l4aAq166K1BNvWCVmqvn fTJB3yQszDPzsLuUcXJuFsMxYr3ymoirKnfRjXHbCIYE/yOceEVjpKUshu1yV9zdzZyj TX1w== 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=Iq0W4QsPIXfjOn4JNS6Kd8bNeG3F7+GRE1ESQz9CIvE=; b=Bk30HC6WTiIcod7DBuJyaI4mhr5kehg73tBId+z2jZlIirgTJbobtqGbvLKPKI7152 lO51E25ctEsJm09ERuKHiQnKhOP7sfst9wxfkgM5czqoh7tuPXuhrGI8BzO5lv8s97s5 YWbbCcR1N35Ir/ABMISNSqTevk1iSXnkoUyyzXRjkqy6D4BfwA1RIDI95tQN/UNqUPRl MPUuI6ykmkqO5tJgp1b1A1F6k+uQd0p4ZOa3xt2xbdS/3pHAn83kdMjv0eTtgePqw/MY La4KGQvXAkVS/GgL6hJVXD/Z9i+hMiWeV0mFTG4Sg3wjoRn4smhHgBtzau+QbwHuD4Nv OnkA== X-Gm-Message-State: APjAAAVDri+nYchrSUx3PY1uY4VpNfvgLYGfQs+/bCp/a7BroGPu2Yla eGrQ3MDS0lr03si1xH75sXnXhA7g X-Google-Smtp-Source: APXvYqxAARNKzFKDIO9jej04MkvryfmnCHMpL/lX/j6Ca2FsMPjjEnmYtiTZUWGrg11wo/ZoVNPotA== X-Received: by 2002:adf:eb4e:: with SMTP id u14mr49657531wrn.168.1561116628781; Fri, 21 Jun 2019 04:30:28 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:01 +0200 Message-Id: <1561116620-22245-7-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::42d Subject: [Qemu-devel] [PULL 06/25] i386/kvm: document existing Hyper-V enlightenments X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vitaly Kuznetsov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Vitaly Kuznetsov Currently, there is no doc describing hv-* CPU flags, people are encouraged to get the information from Microsoft Hyper-V Top Level Functional specification (TLFS). There is, however, a bit of QEMU specifics. Signed-off-by: Vitaly Kuznetsov Message-Id: <20190517141924.19024-5-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini --- docs/hyperv.txt | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 docs/hyperv.txt diff --git a/docs/hyperv.txt b/docs/hyperv.txt new file mode 100644 index 0000000..c423e0f --- /dev/null +++ b/docs/hyperv.txt @@ -0,0 +1,181 @@ +Hyper-V Enlightenments +====================== + + +1. Description +=============== +In some cases when implementing a hardware interface in software is slow, KVM +implements its own paravirtualized interfaces. This works well for Linux as +guest support for such features is added simultaneously with the feature itself. +It may, however, be hard-to-impossible to add support for these interfaces to +proprietary OSes, namely, Microsoft Windows. + +KVM on x86 implements Hyper-V Enlightenments for Windows guests. These features +make Windows and Hyper-V guests think they're running on top of a Hyper-V +compatible hypervisor and use Hyper-V specific features. + + +2. Setup +========= +No Hyper-V enlightenments are enabled by default by either KVM or QEMU. In +QEMU, individual enlightenments can be enabled through CPU flags, e.g: + + qemu-system-x86_64 --enable-kvm --cpu host,hv_relaxed,hv_vpindex,hv_time, ... + +Sometimes there are dependencies between enlightenments, QEMU is supposed to +check that the supplied configuration is sane. + +When any set of the Hyper-V enlightenments is enabled, QEMU changes hypervisor +identification (CPUID 0x40000000..0x4000000A) to Hyper-V. KVM identification +and features are kept in leaves 0x40000100..0x40000101. + + +3. Existing enlightenments +=========================== + +3.1. hv-relaxed +================ +This feature tells guest OS to disable watchdog timeouts as it is running on a +hypervisor. It is known that some Windows versions will do this even when they +see 'hypervisor' CPU flag. + +3.2. hv-vapic +============== +Provides so-called VP Assist page MSR to guest allowing it to work with APIC +more efficiently. In particular, this enlightenment allows paravirtualized +(exit-less) EOI processing. + +3.3. hv-spinlocks=xxx +====================== +Enables paravirtualized spinlocks. The parameter indicates how many times +spinlock acquisition should be attempted before indicating the situation to the +hypervisor. A special value 0xffffffff indicates "never to retry". + +3.4. hv-vpindex +================ +Provides HV_X64_MSR_VP_INDEX (0x40000002) MSR to the guest which has Virtual +processor index information. This enlightenment makes sense in conjunction with +hv-synic, hv-stimer and other enlightenments which require the guest to know its +Virtual Processor indices (e.g. when VP index needs to be passed in a +hypercall). + +3.5. hv-runtime +================ +Provides HV_X64_MSR_VP_RUNTIME (0x40000010) MSR to the guest. The MSR keeps the +virtual processor run time in 100ns units. This gives guest operating system an +idea of how much time was 'stolen' from it (when the virtual CPU was preempted +to perform some other work). + +3.6. hv-crash +============== +Provides HV_X64_MSR_CRASH_P0..HV_X64_MSR_CRASH_P5 (0x40000100..0x40000105) and +HV_X64_MSR_CRASH_CTL (0x40000105) MSRs to the guest. These MSRs are written to +by the guest when it crashes, HV_X64_MSR_CRASH_P0..HV_X64_MSR_CRASH_P5 MSRs +contain additional crash information. This information is outputted in QEMU log +and through QAPI. +Note: unlike under genuine Hyper-V, write to HV_X64_MSR_CRASH_CTL causes guest +to shutdown. This effectively blocks crash dump generation by Windows. + +3.7. hv-time +============= +Enables two Hyper-V-specific clocksources available to the guest: MSR-based +Hyper-V clocksource (HV_X64_MSR_TIME_REF_COUNT, 0x40000020) and Reference TSC +page (enabled via MSR HV_X64_MSR_REFERENCE_TSC, 0x40000021). Both clocksources +are per-guest, Reference TSC page clocksource allows for exit-less time stamp +readings. Using this enlightenment leads to significant speedup of all timestamp +related operations. + +3.8. hv-synic +============== +Enables Hyper-V Synthetic interrupt controller - an extension of a local APIC. +When enabled, this enlightenment provides additional communication facilities +to the guest: SynIC messages and Events. This is a pre-requisite for +implementing VMBus devices (not yet in QEMU). Additionally, this enlightenment +is needed to enable Hyper-V synthetic timers. SynIC is controlled through MSRs +HV_X64_MSR_SCONTROL..HV_X64_MSR_EOM (0x40000080..0x40000084) and +HV_X64_MSR_SINT0..HV_X64_MSR_SINT15 (0x40000090..0x4000009F) + +Requires: hv-vpindex + +3.9. hv-stimer +=============== +Enables Hyper-V synthetic timers. There are four synthetic timers per virtual +CPU controlled through HV_X64_MSR_STIMER0_CONFIG..HV_X64_MSR_STIMER3_COUNT +(0x400000B0..0x400000B7) MSRs. These timers can work either in single-shot or +periodic mode. It is known that certain Windows versions revert to using HPET +(or even RTC when HPET is unavailable) extensively when this enlightenment is +not provided; this can lead to significant CPU consumption, even when virtual +CPU is idle. + +Requires: hv-vpindex, hv-synic, hv-time + +3.10. hv-tlbflush +================== +Enables paravirtualized TLB shoot-down mechanism. On x86 architecture, remote +TLB flush procedure requires sending IPIs and waiting for other CPUs to perform +local TLB flush. In virtualized environment some virtual CPUs may not even be +scheduled at the time of the call and may not require flushing (or, flushing +may be postponed until the virtual CPU is scheduled). hv-tlbflush enlightenment +implements TLB shoot-down through hypervisor enabling the optimization. + +Requires: hv-vpindex + +3.11. hv-ipi +============= +Enables paravirtualized IPI send mechanism. HvCallSendSyntheticClusterIpi +hypercall may target more than 64 virtual CPUs simultaneously, doing the same +through APIC requires more than one access (and thus exit to the hypervisor). + +Requires: hv-vpindex + +3.12. hv-vendor-id=xxx +======================= +This changes Hyper-V identification in CPUID 0x40000000.EBX-EDX from the default +"Microsoft Hv". The parameter should be no longer than 12 characters. According +to the specification, guests shouldn't use this information and it is unknown +if there is a Windows version which acts differently. +Note: hv-vendor-id is not an enlightenment and thus doesn't enable Hyper-V +identification when specified without some other enlightenment. + +3.13. hv-reset +=============== +Provides HV_X64_MSR_RESET (0x40000003) MSR to the guest allowing it to reset +itself by writing to it. Even when this MSR is enabled, it is not a recommended +way for Windows to perform system reboot and thus it may not be used. + +3.14. hv-frequencies +============================================ +Provides HV_X64_MSR_TSC_FREQUENCY (0x40000022) and HV_X64_MSR_APIC_FREQUENCY +(0x40000023) allowing the guest to get its TSC/APIC frequencies without doing +measurements. + +3.15 hv-reenlightenment +======================== +The enlightenment is nested specific, it targets Hyper-V on KVM guests. When +enabled, it provides HV_X64_MSR_REENLIGHTENMENT_CONTROL (0x40000106), +HV_X64_MSR_TSC_EMULATION_CONTROL (0x40000107)and HV_X64_MSR_TSC_EMULATION_STATUS +(0x40000108) MSRs allowing the guest to get notified when TSC frequency changes +(only happens on migration) and keep using old frequency (through emulation in +the hypervisor) until it is ready to switch to the new one. This, in conjunction +with hv-frequencies, allows Hyper-V on KVM to pass stable clocksource (Reference +TSC page) to its own guests. + +Recommended: hv-frequencies + +3.16. hv-evmcs +=============== +The enlightenment is nested specific, it targets Hyper-V on KVM guests. When +enabled, it provides Enlightened VMCS feature to the guest. The feature +implements paravirtualized protocol between L0 (KVM) and L1 (Hyper-V) +hypervisors making L2 exits to the hypervisor faster. The feature is Intel-only. +Note: some virtualization features (e.g. Posted Interrupts) are disabled when +hv-evmcs is enabled. It may make sense to measure your nested workload with and +without the feature to find out if enabling it is beneficial. + +Requires: hv-vapic + + +4. Useful links +================ +Hyper-V Top Level Functional specification and other information: +https://github.com/MicrosoftDocs/Virtualization-Documentation From patchwork Fri Jun 21 11:30:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Bvzdz/Z5"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcPB2RThz9s4V for ; Fri, 21 Jun 2019 21:47:26 +1000 (AEST) Received: from localhost ([::1]:59946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heI0q-0005Dp-8h for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:47:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49031) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkY-0000fp-Ct for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkV-0005TU-8b for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:34 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:54498) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkV-0005Qp-1U for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:31 -0400 Received: by mail-wm1-x332.google.com with SMTP id g135so5999995wme.4 for ; Fri, 21 Jun 2019 04:30:30 -0700 (PDT) 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=rLWxEjPZN+ttDy6470/jW3LY13Gz8VOEZike0sn0oXQ=; b=Bvzdz/Z513MYyxRbWwsxtM4IvKkQurc5MqVNLcsp4dDHTFAuGttSkA3OgieFIvxXeJ q5LO1OOZxPLmCV2WUbSsb+LCxSwx31K6Ym2L/i80vxKwEZFfSfJU4TN7KCxVMoP9uqYg JxHJB+5L68IaGs+YschFkoiMkXc5UdTyPlsG7rxCxF3Puqg/kX+eUwzK4pgrtu3frIcO hTwUXVSwFXouKBpWtnwAgHqClPBfg9nyNMwNUu6olSm9WeyNhFvVgeBL3QuKnVN4vCNC u9BtkmWYDnaITpEfok+pBtD7vbl/YFc9ti7i0XC+79seJvLC+NRMUSCDf9z4GxN5thrk qp4Q== 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=rLWxEjPZN+ttDy6470/jW3LY13Gz8VOEZike0sn0oXQ=; b=BiRMCsKhQcRsojlEtXLDuA/ocll2+MRoD6RDd3f2LHcgsutMF35a7dGDp704m573On Fh7QRpED+90lZrXtwGRbv/pN8qdd4QJPEW1I1oaPeSWCJ6pqyhm/EyfjkuEZlo4eB5ly JvTrSmfw/PHNHUjQ/iLB0joTFXPxD3l9ksfndd33uieiYQZ8MkDrUkl4r0vCC5rnvQPq yjHoHubneYn0lwMLc9LdiTMhqhXtCECVJtd+/r83BQ3qJAoZS0Q4GhPMF/opQW7ksBhl YFwGH12sa3e2YAGH1G9hvSc2hdRr1ao4OW+oUA6c509YYz5a/EnhXVtf/gA+eE3Rj0dX 4yvQ== X-Gm-Message-State: APjAAAXcLm+BO7UIm/AA0D92V3tKNwMJRmYoccMjVRh/y2VuGWLVp/j4 zQGkKRWwBr2fUOt0ZpzeuKrhSiGQ X-Google-Smtp-Source: APXvYqwg8RHNJTJxZ6E+4Ov0SQTcWQxjYDlMCn20/q4lXJ6XWiopmJkeQoUWsz8mw59ot6L+RprW5Q== X-Received: by 2002:a7b:cb94:: with SMTP id m20mr3694471wmi.144.1561116629737; Fri, 21 Jun 2019 04:30:29 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:02 +0200 Message-Id: <1561116620-22245-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::332 Subject: [Qemu-devel] [PULL 07/25] i386/kvm: implement 'hv-passthrough' mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vitaly Kuznetsov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Vitaly Kuznetsov In many case we just want to give Windows guests all currently supported Hyper-V enlightenments and that's where this new mode may come handy. We pass through what was returned by KVM_GET_SUPPORTED_HV_CPUID. hv_cpuid_check_and_set() is modified to also set cpu->hyperv_* flags as we may want to check them later (and we actually do for hv_runtime, hv_synic,...). 'hv-passthrough' is a development only feature, a migration blocker is added to prevent issues while migrating between hosts with different feature sets. Signed-off-by: Vitaly Kuznetsov Message-Id: <20190517141924.19024-6-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini --- docs/hyperv.txt | 10 +++++++ target/i386/cpu.c | 1 + target/i386/cpu.h | 1 + target/i386/kvm.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 87 insertions(+), 14 deletions(-) diff --git a/docs/hyperv.txt b/docs/hyperv.txt index c423e0f..beadb2d 100644 --- a/docs/hyperv.txt +++ b/docs/hyperv.txt @@ -175,6 +175,16 @@ without the feature to find out if enabling it is beneficial. Requires: hv-vapic +4. Development features +======================== +In some cases (e.g. during development) it may make sense to use QEMU in +'pass-through' mode and give Windows guests all enlightenments currently +supported by KVM. This pass-through mode is enabled by "hv-passthrough" CPU +flag. +Note: enabling this flag effectively prevents migration as supported features +may differ between target and destination. + + 4. Useful links ================ Hyper-V Top Level Functional specification and other information: diff --git a/target/i386/cpu.c b/target/i386/cpu.c index e90c1ac..e07996c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5883,6 +5883,7 @@ static Property x86_cpu_properties[] = { HYPERV_FEAT_EVMCS, 0), DEFINE_PROP_BIT64("hv-ipi", X86CPU, hyperv_features, HYPERV_FEAT_IPI, 0), + DEFINE_PROP_BOOL("hv-passthrough", X86CPU, hyperv_passthrough, false), DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true), DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false), diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 30cd1a0..86edbf5 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1390,6 +1390,7 @@ struct X86CPU { char *hyperv_vendor_id; bool hyperv_synic_kvm_only; uint64_t hyperv_features; + bool hyperv_passthrough; bool check_cpuid; bool enforce_cpuid; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index a041b4d..93ac6ba 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -639,7 +639,7 @@ static bool hyperv_enabled(X86CPU *cpu) CPUState *cs = CPU(cpu); return kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0 && ((cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY) || - cpu->hyperv_features); + cpu->hyperv_features || cpu->hyperv_passthrough); } static int kvm_arch_set_tsc_khz(CPUState *cs) @@ -985,10 +985,10 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid, { X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; - uint32_t r, fw, bits;; + uint32_t r, fw, bits; int i; - if (!hyperv_feat_enabled(cpu, feature)) { + if (!hyperv_feat_enabled(cpu, feature) && !cpu->hyperv_passthrough) { return 0; } @@ -1001,15 +1001,23 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid, } if (hv_cpuid_get_fw(cpuid, fw, &r) || (r & bits) != bits) { - fprintf(stderr, - "Hyper-V %s is not supported by kernel\n", - kvm_hyperv_properties[feature].desc); - return 1; + if (hyperv_feat_enabled(cpu, feature)) { + fprintf(stderr, + "Hyper-V %s is not supported by kernel\n", + kvm_hyperv_properties[feature].desc); + return 1; + } else { + return 0; + } } env->features[fw] |= bits; } + if (cpu->hyperv_passthrough) { + cpu->hyperv_features |= BIT(feature); + } + return 0; } @@ -1027,22 +1035,29 @@ static int hyperv_handle_properties(CPUState *cs, struct kvm_cpuid_entry2 *c; uint32_t signature[3]; uint32_t cpuid_i = 0; - int r = 0; + int r; if (!hyperv_enabled(cpu)) return 0; - if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS)) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) || + cpu->hyperv_passthrough) { uint16_t evmcs_version; - if (kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0, - (uintptr_t)&evmcs_version)) { + r = kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0, + (uintptr_t)&evmcs_version); + + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) && r) { fprintf(stderr, "Hyper-V %s is not supported by kernel\n", kvm_hyperv_properties[HYPERV_FEAT_EVMCS].desc); return -ENOSYS; } - env->features[FEAT_HV_RECOMM_EAX] |= HV_ENLIGHTENED_VMCS_RECOMMENDED; - env->features[FEAT_HV_NESTED_EAX] = evmcs_version; + + if (!r) { + env->features[FEAT_HV_RECOMM_EAX] |= + HV_ENLIGHTENED_VMCS_RECOMMENDED; + env->features[FEAT_HV_NESTED_EAX] = evmcs_version; + } } if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_CPUID) > 0) { @@ -1051,8 +1066,33 @@ static int hyperv_handle_properties(CPUState *cs, cpuid = get_supported_hv_cpuid_legacy(cs); } + if (cpu->hyperv_passthrough) { + memcpy(cpuid_ent, &cpuid->entries[0], + cpuid->nent * sizeof(cpuid->entries[0])); + + c = cpuid_find_entry(cpuid, HV_CPUID_FEATURES, 0); + if (c) { + env->features[FEAT_HYPERV_EAX] = c->eax; + env->features[FEAT_HYPERV_EBX] = c->ebx; + env->features[FEAT_HYPERV_EDX] = c->eax; + } + c = cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); + if (c) { + env->features[FEAT_HV_RECOMM_EAX] = c->eax; + + /* hv-spinlocks may have been overriden */ + if (cpu->hyperv_spinlock_attempts != HYPERV_SPINLOCK_NEVER_RETRY) { + c->ebx = cpu->hyperv_spinlock_attempts; + } + } + c = cpuid_find_entry(cpuid, HV_CPUID_NESTED_FEATURES, 0); + if (c) { + env->features[FEAT_HV_NESTED_EAX] = c->eax; + } + } + /* Features */ - r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_RELAXED); + r = hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_RELAXED); r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_VAPIC); r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_TIME); r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_CRASH); @@ -1085,6 +1125,12 @@ static int hyperv_handle_properties(CPUState *cs, goto free; } + if (cpu->hyperv_passthrough) { + /* We already copied all feature words from KVM as is */ + r = cpuid->nent; + goto free; + } + c = &cpuid_ent[cpuid_i++]; c->function = HV_CPUID_VENDOR_AND_MAX_FUNCTIONS; if (!cpu->hyperv_vendor_id) { @@ -1156,11 +1202,26 @@ free: return r; } +static Error *hv_passthrough_mig_blocker; + static int hyperv_init_vcpu(X86CPU *cpu) { CPUState *cs = CPU(cpu); + Error *local_err = NULL; int ret; + if (cpu->hyperv_passthrough && hv_passthrough_mig_blocker == NULL) { + error_setg(&hv_passthrough_mig_blocker, + "'hv-passthrough' CPU flag prevents migration, use explicit" + " set of hv-* flags instead"); + ret = migrate_add_blocker(hv_passthrough_mig_blocker, &local_err); + if (local_err) { + error_report_err(local_err); + error_free(hv_passthrough_mig_blocker); + return ret; + } + } + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX) && !hv_vpindex_settable) { /* * the kernel doesn't support setting vp_index; assert that its value From patchwork Fri Jun 21 11:30:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aRsQOzfF"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcSr5ymLz9sBr for ; Fri, 21 Jun 2019 21:50:36 +1000 (AEST) Received: from localhost ([::1]:59984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heI3u-0000DO-Ts for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:50:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49044) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHka-0000hb-CI for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkW-0005YJ-8p for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:36 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:51021) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkW-0005V5-15 for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:32 -0400 Received: by mail-wm1-x32a.google.com with SMTP id c66so6035179wmf.0 for ; Fri, 21 Jun 2019 04:30:31 -0700 (PDT) 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=HAAne3y/gROX4bU2C72LMlD4mSuvEZFb/lzmz3j4hms=; b=aRsQOzfFlJ7SUog+PSDnEfue3a52L44GPhkTjV8O6fCWQJO/0ZsyH6UmjtOA16VnMT t7W3MOho8lw8W1tXHGFwzRrSOXCWJnoYF41SFR9qdb7c7CYGPSeNtVl7oKNUY4hYSQ0g oPKNknuc1t5VCDnliamzLRFPL+1XCCbbB7Lorc8TNF/+LxFkp7UCOPZR8vkYzB744Pgn HrvPfIdTI3twTapZPDGuHneyBNfTCXRyaH5ynVKhaWdfRbqF+PuqcmxSK8oz09HGTr9t PhnkjgByNEC3HgwZmA0AnAXuqp2x9DpnNW/AmdoTNHuJlgv+3onoEB6Ua+6hLtoUM+Kw DOfA== 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=HAAne3y/gROX4bU2C72LMlD4mSuvEZFb/lzmz3j4hms=; b=Pc/5tiSfIs2w0jBC602v83SEDSkfjao+BOM5zyh/ANipfR3rkkn+/Nn/Y387ZMTKwV wVmiIXuNl0prOZYPUIpPe++EI4yJX1PdoogPZGXQkujxZhLKFy46tUBFEdzEejV33Apf dJMCXJ+u44ovVnIrV1XMfQ4NirOWTk8yjvbhuCR+0wHIdJIAIMeX108ECpXxPMx9uUUH BjdB43AxgRt+NcQfVl90naW3v0uYOgSHD9VEhSkrAbkH+VpGJWI570A2np20iTzJ0Ycl leezsO/LDIbFHISlII3HGhajB4ascOGDekDmVUA3j8eCQzT7fWkG33Uj4o9mOz71z2aD hrsQ== X-Gm-Message-State: APjAAAW1zfUgOj5BYZL0XVVGx+lK+I8K7gWt+kfxnAvUbGnP8GWObzBM 68uLQ0OwXR7j/EDfF+aWnq3bwbY3 X-Google-Smtp-Source: APXvYqyG5BrQN1PUI/eKhI1tgGenUMLv3s8wYiseKBj/N1e94pZZvVflVS9nuijn3DP6M//+LRl3/Q== X-Received: by 2002:a7b:c3d5:: with SMTP id t21mr3480297wmj.87.1561116630797; Fri, 21 Jun 2019 04:30:30 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:30 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:03 +0200 Message-Id: <1561116620-22245-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::32a Subject: [Qemu-devel] [PULL 08/25] i386/kvm: hv-stimer requires hv-time and hv-synic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vitaly Kuznetsov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Vitaly Kuznetsov Synthetic timers operate in hv-time time and Windows won't use these without SynIC. Add .dependencies field to kvm_hyperv_properties[] and a generic mechanism to check dependencies between features. Signed-off-by: Vitaly Kuznetsov Message-Id: <20190517141924.19024-7-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 93ac6ba..58afa31 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -689,6 +689,7 @@ static struct { uint32_t fw; uint32_t bits; } flags[2]; + uint64_t dependencies; } kvm_hyperv_properties[] = { [HYPERV_FEAT_RELAXED] = { .desc = "relaxed timing (hv-relaxed)", @@ -756,7 +757,8 @@ static struct { .flags = { {.fw = FEAT_HYPERV_EAX, .bits = HV_SYNTIMERS_AVAILABLE} - } + }, + .dependencies = BIT(HYPERV_FEAT_SYNIC) | BIT(HYPERV_FEAT_TIME) }, [HYPERV_FEAT_FREQUENCIES] = { .desc = "frequency MSRs (hv-frequencies)", @@ -986,12 +988,25 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid, X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; uint32_t r, fw, bits; - int i; + uint64_t deps; + int i, dep_feat = 0; if (!hyperv_feat_enabled(cpu, feature) && !cpu->hyperv_passthrough) { return 0; } + deps = kvm_hyperv_properties[feature].dependencies; + while ((dep_feat = find_next_bit(&deps, 64, dep_feat)) < 64) { + if (!(hyperv_feat_enabled(cpu, dep_feat))) { + fprintf(stderr, + "Hyper-V %s requires Hyper-V %s\n", + kvm_hyperv_properties[feature].desc, + kvm_hyperv_properties[dep_feat].desc); + return 1; + } + dep_feat++; + } + for (i = 0; i < ARRAY_SIZE(kvm_hyperv_properties[feature].flags); i++) { fw = kvm_hyperv_properties[feature].flags[i].fw; bits = kvm_hyperv_properties[feature].flags[i].bits; @@ -1107,11 +1122,11 @@ static int hyperv_handle_properties(CPUState *cs, r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_EVMCS); r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_IPI); - /* Dependencies */ + /* Additional dependencies not covered by kvm_hyperv_properties[] */ if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC) && !cpu->hyperv_synic_kvm_only && !hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX)) { - fprintf(stderr, "Hyper-V %s requires %s\n", + fprintf(stderr, "Hyper-V %s requires Hyper-V %s\n", kvm_hyperv_properties[HYPERV_FEAT_SYNIC].desc, kvm_hyperv_properties[HYPERV_FEAT_VPINDEX].desc); r |= 1; From patchwork Fri Jun 21 11:30:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120194 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lqUPF8DE"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcdB5QFcz9sBr for ; Fri, 21 Jun 2019 21:57:50 +1000 (AEST) Received: from localhost ([::1]:60068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heIAu-0006Js-Rc for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:57:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49084) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHke-0000l0-G5 for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHka-0005jZ-Bc for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:40 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:54490) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkY-0005Yh-Au for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:36 -0400 Received: by mail-wm1-x329.google.com with SMTP id g135so6000133wme.4 for ; Fri, 21 Jun 2019 04:30:32 -0700 (PDT) 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=bNCR6BSZrVAsd51s0wYru1/heSmPhGDxRbakfLjjL5g=; b=lqUPF8DEj0x9oC3vQD68TqYZaBfQvBn+2p+u8AaxKfUTtUKLrTmnVZfYuuoa9IabhF p7FJ/3T9MYNtCYDbOZVBrsl3vLoaLn1B0Nz8Dwp2KGgQkZ0sadmFxcJtQrBOUUWfcs9Z BQGDEMRQYGXyeestjR/l08ILDIapq+IMgSZ8mvHsdFqZvD77hLlnD0DpQnjANSjfOKjQ njNC+aep7B/N0j4UMavnAN9q8g949yRFQc1xw3gqm4L/aB+evbDWiu2xKB0FcGTQ/aPH WNG1jRv38aGlV6p8vn8TsIZZG+jhmZIl2z5j8/s7OR0FnUF79/gAwzWrJIDhqXDmXlaE QVWQ== 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=bNCR6BSZrVAsd51s0wYru1/heSmPhGDxRbakfLjjL5g=; b=kGHRYuHlZ18vm3EVolB9w9Xew84lzGtlZeF3aSiOGmY0gUNpoFTsqkZ1AqsDYk2CoQ 29KNH5actrCO5SK67WbbCD9CMCIdeIvZl+sqR/JStj2ualRnHx0JH+h1xpAaAuQe5xFd d7G8pvtsYl5hwJ7+8uS4Z70tb7FVN9NCh/pCBGt7YaNSOW/6slJt2o6WtrM1F+83bfpO xGXamxce2BCzGuMc1whsCbvkK4DltvPaDO0XNG3rdmCQ8qgvGp5JH/VQ8Tc3WtHHPpNb du16f888LNp9ONOjLAZRSgH1R1lQne/0DBtRzH25aOsEnfmMG4sg/djxiqmBGsU090ri nzUA== X-Gm-Message-State: APjAAAUS79BOx6TwoCNJkHKvY0lpbDdH9i2IyzJC95hlj2PU/xxZFDYU 6FVaquqMvI5A5MPNYTUaeQj1Ydyy X-Google-Smtp-Source: APXvYqxA63/Ji+nLiab2a//vfVdX2782XThRYa9NQjZbtNzArvJDcYYfFqH2LWGJBCq3xKxwQvsllw== X-Received: by 2002:a1c:a1c1:: with SMTP id k184mr4027146wme.81.1561116631750; Fri, 21 Jun 2019 04:30:31 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:31 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:04 +0200 Message-Id: <1561116620-22245-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::329 Subject: [Qemu-devel] [PULL 09/25] i386/kvm: hv-tlbflush/ipi require hv-vpindex X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vitaly Kuznetsov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Vitaly Kuznetsov The corresponding hypercalls require using VP indexes. Signed-off-by: Vitaly Kuznetsov Message-Id: <20190517141924.19024-8-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 58afa31..1dfa282 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -782,7 +782,8 @@ static struct { {.fw = FEAT_HV_RECOMM_EAX, .bits = HV_REMOTE_TLB_FLUSH_RECOMMENDED | HV_EX_PROCESSOR_MASKS_RECOMMENDED} - } + }, + .dependencies = BIT(HYPERV_FEAT_VPINDEX) }, [HYPERV_FEAT_EVMCS] = { .desc = "enlightened VMCS (hv-evmcs)", @@ -797,7 +798,8 @@ static struct { {.fw = FEAT_HV_RECOMM_EAX, .bits = HV_CLUSTER_IPI_RECOMMENDED | HV_EX_PROCESSOR_MASKS_RECOMMENDED} - } + }, + .dependencies = BIT(HYPERV_FEAT_VPINDEX) }, }; From patchwork Fri Jun 21 11:30:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120189 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="IaCWdHW4"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcZ304DRz9sBr for ; Fri, 21 Jun 2019 21:55:07 +1000 (AEST) Received: from localhost ([::1]:60010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heI8H-0003TK-0J for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:55:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49062) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkc-0000jn-B1 for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkY-0005gX-FB for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:38 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:33987) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkY-0005d5-8c for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:34 -0400 Received: by mail-wr1-x42d.google.com with SMTP id k11so6260972wrl.1 for ; Fri, 21 Jun 2019 04:30:33 -0700 (PDT) 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=pHLIgPBm+zklyrM5916BeOxRgjfHZTPjTZ6RZlLuMzk=; b=IaCWdHW4IV7dCwDpC1hZplAfSnDdD3bV0VCJPYoqJvcllvjhgIoQtNZdxdVVXl23FS A9iX/Yq7snHAxu38V1kkoDNnfqIt/Y8XgliYs0DTgtsVS4ot8mJqeeQYiiKXwaQNBfij Rm/uXkENuWIZoI9NTNIZ1NpMFWkUTmp/M7XofDld6Bh+xawDFGAFoqpaFOyqRN4+3gOL HdrSg7u7mNAutQMAY92UcKrwMRGfbOdiVVQTAbc4AF9W0csLZoohpcR9yappuc7Ex1Qt 1BZqQHsq5hnf576gTEU/mieRmRujgaYD440VYwzRQ8tjzkGMPneu1MAMVMtNHp+1JbHf p12w== 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=pHLIgPBm+zklyrM5916BeOxRgjfHZTPjTZ6RZlLuMzk=; b=QHeO+mktBC59GYSYNHWk9Kc2T8WzWIwDkepwjq+KtGpvDj5BBxa7VZE0/Gz0K1yVih wOojEXx9weF55uIigGnddI7rTY+6HiRNYM0/ad4R99XK6QX8MmlMCqdYJKikUqBNoRz5 07kke+2cZYP1f2FKKg90T+09sW9C4sfLdGLa4BAdgYsiUhuAuhAMs6m0l458yq+9q5zC CN6ZZaJXePyougz3gVUMNRIFamzdJW/YTqaTbxWFsoyQteqpAPOERSdGeiE3s8jVPUTP 7MCWFWjAj+Zw5euZB8aHeovMmlmWah4v8wBVnzuuPJo43/bDe8d7Q4ND08hVafdT4MvO wFZw== X-Gm-Message-State: APjAAAXjD8c6737hpTZtczDwLOvOtiB8GEEior088kSv1vl4Iurli9tv zy2lHOqeN6vCH6VIDsMVAgUMN7E9 X-Google-Smtp-Source: APXvYqzWBcfNvKlZG8fV0mRlLqUDMHOENXFgGIjkemHT8hsIkXcTLSVOsiLoEZ38qFA647kQgxppJw== X-Received: by 2002:a5d:42c5:: with SMTP id t5mr79007378wrr.5.1561116632584; Fri, 21 Jun 2019 04:30:32 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:32 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:05 +0200 Message-Id: <1561116620-22245-11-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::42d Subject: [Qemu-devel] [PULL 10/25] i386/kvm: hv-evmcs requires hv-vapic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vitaly Kuznetsov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Vitaly Kuznetsov Enlightened VMCS is enabled by writing to a field in VP assist page and these require virtual APIC. Signed-off-by: Vitaly Kuznetsov Message-Id: <20190517141924.19024-9-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 1dfa282..86de510 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -790,7 +790,8 @@ static struct { .flags = { {.fw = FEAT_HV_RECOMM_EAX, .bits = HV_ENLIGHTENED_VMCS_RECOMMENDED} - } + }, + .dependencies = BIT(HYPERV_FEAT_VAPIC) }, [HYPERV_FEAT_IPI] = { .desc = "paravirtualized IPI (hv-ipi)", From patchwork Fri Jun 21 11:30:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120196 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gWLfH+xb"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Vcjg17s9z9sND for ; Fri, 21 Jun 2019 22:01:43 +1000 (AEST) Received: from localhost ([::1]:60168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heIEf-0000p6-5X for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 08:01:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49104) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkf-0000lF-IZ for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkc-0005rV-Ek for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:41 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:39048) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkc-0005fu-8Q for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:38 -0400 Received: by mail-wr1-x442.google.com with SMTP id x4so6228519wrt.6 for ; Fri, 21 Jun 2019 04:30:34 -0700 (PDT) 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=rRyKyx29XW5YjtibDxKmJQDBBERS19STiC5lOwnEoTA=; b=gWLfH+xbFIXTdQ7wAVfukxJqFcrRIUB53jXQglFYvS8OOAJJGr/gLAAkT7p/UUv9KA TBPmiyUpO9ev6T/Wd3RH83eU2ZVI04vtta+Vz2O2/0fg22HG2eYHVG40aSa3D1jqejhK 7OB5c794iOeHEDnUseX1eU7/gpnVJedxFlITmMMjt7dizcNRD4phPlABMtKWXO4j3E5x I3CM2OWfjSyObYUMdFS7u+GqhtNWOKlCM0/ycATfZmpHQWB5SrZsTnzzxyopveX/Wbk4 /XXNa1wWGx2dQIfz538MZoYhZJpM/HztzrXtlQDEH1ELuXm6U/wfb+WMJnhcNTSbTRkL fRmQ== 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=rRyKyx29XW5YjtibDxKmJQDBBERS19STiC5lOwnEoTA=; b=P66DoJSsfStmwrOXdkc15u7nKMeMfm9J42NtwzRKmffN1vVlgicVFfS0XUuLHB+VJZ 92elfNaOwVsHIlsj5n9OOTnBeQb85UYSJ0UnEcSy3EvqdVTNMeOimbBTtAQ0VmjB+i6I GWX5zhc0cF2ZEjhfBetERXNMEeglWIfGAEJ5aGLPDlbaZf/GQ1g7t2nRsSkcxOpM6Ozv W1vmOmCoTZ5eVI5/iqFXUU5esfGFdb5RyKhF8xceb66MjVSOc+ogTHCWYRqrUr8bGu1/ LzZWQHGNRlA5AAo9Tfna363mWTbA3jgBwilNBrYsYW6bJt5s1wKfDnPcwe/a35A94VM9 C4Yw== X-Gm-Message-State: APjAAAW0LAlyaxJGZZJDmHASR47jz+NlS6bZ1lX/FzsyKsXeV40/6QwL Qi9F1ZMMwSVIWElgnUHlNKrzrheO X-Google-Smtp-Source: APXvYqzdXMbH2zdH/r3FTd2EiHXtHtBoMDnlapwBqvexNVvCIy2M3bfBVXPmiJtEXvuMYwobJF20sg== X-Received: by 2002:adf:f050:: with SMTP id t16mr77096796wro.99.1561116633570; Fri, 21 Jun 2019 04:30:33 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:32 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:06 +0200 Message-Id: <1561116620-22245-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::442 Subject: [Qemu-devel] [PULL 11/25] i386/kvm: add support for Direct Mode for Hyper-V synthetic timers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vitaly Kuznetsov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Vitaly Kuznetsov Hyper-V on KVM can only use Synthetic timers with Direct Mode (opting for an interrupt instead of VMBus message). This new capability is only announced in KVM_GET_SUPPORTED_HV_CPUID. Signed-off-by: Vitaly Kuznetsov Message-Id: <20190517141924.19024-10-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini --- docs/hyperv.txt | 10 ++++++++++ target/i386/cpu.c | 2 ++ target/i386/cpu.h | 1 + target/i386/hyperv-proto.h | 1 + target/i386/kvm.c | 9 +++++++++ 5 files changed, 23 insertions(+) diff --git a/docs/hyperv.txt b/docs/hyperv.txt index beadb2d..8fdf25c 100644 --- a/docs/hyperv.txt +++ b/docs/hyperv.txt @@ -174,6 +174,16 @@ without the feature to find out if enabling it is beneficial. Requires: hv-vapic +3.17. hv-stimer-direct +======================= +Hyper-V specification allows synthetic timer operation in two modes: "classic", +when expiration event is delivered as SynIC message and "direct", when the event +is delivered via normal interrupt. It is known that nested Hyper-V can only +use synthetic timers in direct mode and thus 'hv-stimer-direct' needs to be +enabled. + +Requires: hv-vpindex, hv-synic, hv-time, hv-stimer + 4. Development features ======================== diff --git a/target/i386/cpu.c b/target/i386/cpu.c index e07996c..7beb8ab 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5883,6 +5883,8 @@ static Property x86_cpu_properties[] = { HYPERV_FEAT_EVMCS, 0), DEFINE_PROP_BIT64("hv-ipi", X86CPU, hyperv_features, HYPERV_FEAT_IPI, 0), + DEFINE_PROP_BIT64("hv-stimer-direct", X86CPU, hyperv_features, + HYPERV_FEAT_STIMER_DIRECT, 0), DEFINE_PROP_BOOL("hv-passthrough", X86CPU, hyperv_passthrough, false), DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true), diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 86edbf5..7470acf 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -749,6 +749,7 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; #define HYPERV_FEAT_TLBFLUSH 11 #define HYPERV_FEAT_EVMCS 12 #define HYPERV_FEAT_IPI 13 +#define HYPERV_FEAT_STIMER_DIRECT 14 #ifndef HYPERV_SPINLOCK_NEVER_RETRY #define HYPERV_SPINLOCK_NEVER_RETRY 0xFFFFFFFF diff --git a/target/i386/hyperv-proto.h b/target/i386/hyperv-proto.h index c0272b3..cffac10 100644 --- a/target/i386/hyperv-proto.h +++ b/target/i386/hyperv-proto.h @@ -49,6 +49,7 @@ #define HV_GUEST_IDLE_STATE_AVAILABLE (1u << 5) #define HV_FREQUENCY_MSRS_AVAILABLE (1u << 8) #define HV_GUEST_CRASH_MSR_AVAILABLE (1u << 10) +#define HV_STIMER_DIRECT_MODE_AVAILABLE (1u << 19) /* * HV_CPUID_ENLIGHTMENT_INFO.EAX bits diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 86de510..a323b1f 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -802,6 +802,14 @@ static struct { }, .dependencies = BIT(HYPERV_FEAT_VPINDEX) }, + [HYPERV_FEAT_STIMER_DIRECT] = { + .desc = "direct mode synthetic timers (hv-stimer-direct)", + .flags = { + {.fw = FEAT_HYPERV_EDX, + .bits = HV_STIMER_DIRECT_MODE_AVAILABLE} + }, + .dependencies = BIT(HYPERV_FEAT_STIMER) + }, }; static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max) @@ -1124,6 +1132,7 @@ static int hyperv_handle_properties(CPUState *cs, r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_TLBFLUSH); r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_EVMCS); r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_IPI); + r |= hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_STIMER_DIRECT); /* Additional dependencies not covered by kvm_hyperv_properties[] */ if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC) && From patchwork Fri Jun 21 11:30:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Wsy7NQPE"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Vcpp0M8sz9sBr for ; Fri, 21 Jun 2019 22:06:06 +1000 (AEST) Received: from localhost ([::1]:60328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heIIu-00051d-5J for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 08:06:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49137) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkh-0000mu-JS for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHke-0005uf-G9 for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:43 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:55526) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkc-0005hI-Ci for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:40 -0400 Received: by mail-wm1-x343.google.com with SMTP id a15so6005383wmj.5 for ; Fri, 21 Jun 2019 04:30:35 -0700 (PDT) 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=yJQvGCIAx/7TCPsH6MnF6RRvIVhWqu77d3ySjfEx700=; b=Wsy7NQPEWK0RolMo9fdHrp9tqDQiAVnTbitD6kAmMkrbVgQz+Datifdpc+mC3Vefm8 Df7DEYzKOEQ8x8FHeuLKwTpzA7stcUDDN9oII2BEcmaS8LJj0/xKEKbn087yFK+59c0/ +KlxM5UgLDaM0dQ2PRS19c5Gdnh3+MBl/bp8ZW+8zAmZ+rnqEYqOKS7PHU5cOkdDRn84 Nf+iPPdS4IKQUXvIA7rMkKNBkDx05063CmFccTQHBPWTJyoRRYjZdnBuebDUwrQNed8I 0uZIiPd2FhVQuXbKBXyNV//1XZL6IopR3cdNEuEjIN7RBwx9wwIiBShWeUKNd+ygEf9v Mzww== 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=yJQvGCIAx/7TCPsH6MnF6RRvIVhWqu77d3ySjfEx700=; b=ZSd0NyzHbRzt+ZSZKgO0Rn2UWBVqA2ipTMPsn4oMvP5JgDHKGIY4LCsAtajW78s5FG /ooZ6l/X+upX/4hbVgdwPg/s3BECQSzHexOF2iiZiT6AqKmVtSBxckFMBDu57StRogGf KfgSrXwQx5YgnJ6WmFLlDUkVDxFaipgdJH0+eThBmwYoC2HUcAWkpjtLGQi8xawPsYQl cgVnx9I+s2NJvg0id93WjLhluTK98hw4aKzL0DWtdWobw73u4QgUHg1i0l4hB75TBRbd 2zPipJecDLZg9/R2Ar59dEWaJM1JE5ew9I87EPbQtBroH3Gmv1mtU8aoWI2f5afxQfCF 29rQ== X-Gm-Message-State: APjAAAVWfXLkxxelSV3XqRQ9JLFFw1UW9L6wyh+0W2CFQMi+8cVMz77g jAelYA0605kY8AApdJOFrmt/1mpy X-Google-Smtp-Source: APXvYqx/Xu75/HMWQqpFerPLQ9i4eqnCZNjKoJZ4nWuhvIn6saX66B0atMixq9M1ZCkMznGJaXVCZQ== X-Received: by 2002:a1c:7f54:: with SMTP id a81mr3896341wmd.170.1561116634470; Fri, 21 Jun 2019 04:30:34 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:33 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:07 +0200 Message-Id: <1561116620-22245-13-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::343 Subject: [Qemu-devel] [PULL 12/25] target/i386: define a new MSR based feature word - FEAT_CORE_CAPABILITY X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Xiaoyao Li Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Xiaoyao Li MSR IA32_CORE_CAPABILITY is a feature-enumerating MSR, which only enumerates the feature split lock detection (via bit 5) by now. The existence of MSR IA32_CORE_CAPABILITY is enumerated by CPUID.7_0:EDX[30]. The latest kernel patches about them can be found here: https://lkml.org/lkml/2019/4/24/1909 Signed-off-by: Xiaoyao Li Message-Id: <20190617153654.916-1-xiaoyao.li@linux.intel.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 22 +++++++++++++++++++++- target/i386/cpu.h | 5 +++++ target/i386/kvm.c | 9 +++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 7beb8ab..c330fd9 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1085,7 +1085,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "spec-ctrl", "stibp", - NULL, "arch-capabilities", NULL, "ssbd", + NULL, "arch-capabilities", "core-capability", "ssbd", }, .cpuid = { .eax = 7, @@ -1203,6 +1203,26 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = { } }, }, + [FEAT_CORE_CAPABILITY] = { + .type = MSR_FEATURE_WORD, + .feat_names = { + NULL, NULL, NULL, NULL, + NULL, "split-lock-detect", NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + }, + .msr = { + .index = MSR_IA32_CORE_CAPABILITY, + .cpuid_dep = { + FEAT_7_0_EDX, + CPUID_7_0_EDX_CORE_CAPABILITY, + }, + }, + }, }; typedef struct X86RegisterInfo32 { diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 7470acf..7f48136 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -345,6 +345,7 @@ typedef enum X86Seg { #define MSR_IA32_SPEC_CTRL 0x48 #define MSR_VIRT_SSBD 0xc001011f #define MSR_IA32_PRED_CMD 0x49 +#define MSR_IA32_CORE_CAPABILITY 0xcf #define MSR_IA32_ARCH_CAPABILITIES 0x10a #define MSR_IA32_TSCDEADLINE 0x6e0 @@ -496,6 +497,7 @@ typedef enum FeatureWord { FEAT_XSAVE_COMP_LO, /* CPUID[EAX=0xd,ECX=0].EAX */ FEAT_XSAVE_COMP_HI, /* CPUID[EAX=0xd,ECX=0].EDX */ FEAT_ARCH_CAPABILITIES, + FEAT_CORE_CAPABILITY, FEATURE_WORDS, } FeatureWord; @@ -687,6 +689,7 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; #define CPUID_7_0_EDX_AVX512_4FMAPS (1U << 3) /* AVX512 Multiply Accumulation Single Precision */ #define CPUID_7_0_EDX_SPEC_CTRL (1U << 26) /* Speculation Control */ #define CPUID_7_0_EDX_ARCH_CAPABILITIES (1U << 29) /*Arch Capabilities*/ +#define CPUID_7_0_EDX_CORE_CAPABILITY (1U << 30) /*Core Capability*/ #define CPUID_7_0_EDX_SPEC_CTRL_SSBD (1U << 31) /* Speculative Store Bypass Disable */ #define CPUID_8000_0008_EBX_WBNOINVD (1U << 9) /* Write back and @@ -734,6 +737,8 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; #define MSR_ARCH_CAP_SKIP_L1DFL_VMENTRY (1U << 3) #define MSR_ARCH_CAP_SSB_NO (1U << 4) +#define MSR_CORE_CAP_SPLIT_LOCK_DETECT (1U << 5) + /* Supported Hyper-V Enlightenments */ #define HYPERV_FEAT_RELAXED 0 #define HYPERV_FEAT_VAPIC 1 diff --git a/target/i386/kvm.c b/target/i386/kvm.c index a323b1f..279f99a 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -95,6 +95,7 @@ static bool has_msr_spec_ctrl; static bool has_msr_virt_ssbd; static bool has_msr_smi_count; static bool has_msr_arch_capabs; +static bool has_msr_core_capabs; static uint32_t has_architectural_pmu_version; static uint32_t num_architectural_pmu_gp_counters; @@ -1842,6 +1843,9 @@ static int kvm_get_supported_msrs(KVMState *s) case MSR_IA32_ARCH_CAPABILITIES: has_msr_arch_capabs = true; break; + case MSR_IA32_CORE_CAPABILITY: + has_msr_core_capabs = true; + break; } } } @@ -2368,6 +2372,11 @@ static int kvm_put_msrs(X86CPU *cpu, int level) env->features[FEAT_ARCH_CAPABILITIES]); } + if (has_msr_core_capabs) { + kvm_msr_entry_add(cpu, MSR_IA32_CORE_CAPABILITY, + env->features[FEAT_CORE_CAPABILITY]); + } + /* * The following MSRs have side effects on the guest or are too heavy * for normal writeback. Limit them to reset or full state updates. From patchwork Fri Jun 21 11:30:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120180 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ETuZ9czV"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcH571kwz9s4V for ; Fri, 21 Jun 2019 21:42:09 +1000 (AEST) Received: from localhost ([::1]:59904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHvd-0001cl-1D for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:42:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49136) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkh-0000mt-JV for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHke-0005uU-G4 for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:43 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:35980) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkc-0005iZ-Dc for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:40 -0400 Received: by mail-wm1-x344.google.com with SMTP id u8so6233411wmm.1 for ; Fri, 21 Jun 2019 04:30:36 -0700 (PDT) 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=99rkvJmjgZNHPGZCddK8znZ7niUUbuJAuf+Rk2/QtO8=; b=ETuZ9czVUM9QoW0n8GyxMVbnsF/IT9BI9bDUX+Y+4eiUFZk/rdLfxAKTjTDXw+yG2M hOmjifn2vdgXN4fMHoz6EnGuffvirhz+sUO3UWbYqDEPBFFKfEsEOjSVglIAaXB/NRba x+J1ASqGsydLoLPyB7zOfaa4qSMKZvl4g3dpw5bGLW7sGDuFYNh2/8A3zZRpefzwD3rC NwNeijdiAJ5ifOcwIFSfaL3v0bwzSv20/ZfjjIdsagzjqqoGT4urJ2pGDLunQF79Ll8j lvvE+N9h9EmOH2anawha2IATNUFqVe9+/MwuzqIxjOlYfQrD3H/Bo/4ABTIUBNa3dnb0 3q/w== 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=99rkvJmjgZNHPGZCddK8znZ7niUUbuJAuf+Rk2/QtO8=; b=EQdiD+NBQrdxdSiWm2qixkxin0Is7XTvaM1YVR8VvMTc5qt+q6bW59wwFEZLojSlb6 9agDpTxYB30noVMwzH733BcPx/kLDUi2qn1U0O1sgS8DyfNW2SBTtHts7NNLXkT7j+4n I0Ujyhta+dqoXBs6e3CrMFOTy3DWHx7ei/7RISOEXj69NZHHceGA4XXd9fkI+BtxY/xf WjJctuKu5n5VCXpd8esNvEhK1TD6dULycnMuky/JVj67xZJrZKTZN2ADclhnzivlHpT9 r7sDZL/CSl1IGlXujt1o1mRxH2skyEeHTV92hY0hqs+SThvZ2qtPNv0jxx4pmSJjWFQ5 BDfw== X-Gm-Message-State: APjAAAUA+y6p+Q9EuUGMiFWD/t//XPXEVGkYAeqI+h/oxQY21O48ZKP3 P9Osy9JH9jPn4GSkzU9opB1UYor5 X-Google-Smtp-Source: APXvYqwZCG8ueP1BpgML4Ecnqhh4gjqkh2ZDmrittIJg7lJY2n5dvFGaMrNLmZWr6ESZ5yxW/LTHDw== X-Received: by 2002:a1c:238e:: with SMTP id j136mr3594829wmj.4.1561116635418; Fri, 21 Jun 2019 04:30:35 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:34 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:08 +0200 Message-Id: <1561116620-22245-14-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::344 Subject: [Qemu-devel] [PULL 13/25] target/i386: kvm: Delete VMX migration blocker on vCPU init failure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Liran Alon Commit d98f26073beb ("target/i386: kvm: add VMX migration blocker") added migration blocker for vCPU exposed with Intel VMX because QEMU doesn't yet contain code to support migration of nested virtualization workloads. However, that commit missed adding deletion of the migration blocker in case init of vCPU failed. Similar to invtsc_mig_blocker. This commit fix that issue. Fixes: d98f26073beb ("target/i386: kvm: add VMX migration blocker") Signed-off-by: Liran Alon Reviewed-by: Maran Wilson Message-Id: <20190619162140.133674-2-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 279f99a..c5cbead 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1333,7 +1333,7 @@ int kvm_arch_init_vcpu(CPUState *cs) r = kvm_arch_set_tsc_khz(cs); if (r < 0) { - goto fail; + return r; } /* vcpu's TSC frequency is either specified by user, or following @@ -1622,7 +1622,7 @@ int kvm_arch_init_vcpu(CPUState *cs) if (local_err) { error_report_err(local_err); error_free(invtsc_mig_blocker); - return r; + goto fail2; } } } @@ -1673,6 +1673,9 @@ int kvm_arch_init_vcpu(CPUState *cs) fail: migrate_del_blocker(invtsc_mig_blocker); + fail2: + migrate_del_blocker(vmx_mig_blocker); + return r; } From patchwork Fri Jun 21 11:30:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120201 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TFPAMP0v"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcxF5brQz9sBr for ; Fri, 21 Jun 2019 22:11:45 +1000 (AEST) Received: from localhost ([::1]:60366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heION-0008Sc-LX for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 08:11:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49133) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkh-0000ms-JH for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHke-0005uN-Fo for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:43 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:36799) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkc-0005lr-CI for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:40 -0400 Received: by mail-wm1-x32d.google.com with SMTP id u8so6233444wmm.1 for ; Fri, 21 Jun 2019 04:30:37 -0700 (PDT) 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=6T+CvKxhIT/wD43F8C6X0mfQEc7rDvNDe6JNobc9BRE=; b=TFPAMP0vaKeogxMyW16FMWXC2XE55AU9NaaFBmNrCnf9pOaA3Awp2uPgmSA/ATjhWN ceJMZxwBOYYSN/msRVDXu1Obee4owYDUdPBR795iPnN8Lmk6VDoIE21K5YDcGDDGmr5O a6HMb27/fmI2nrc5oSslwyxiC2qPb3YC6gpCJESIkp7rUZTAFZgK/mcjHhgsv102vgXa L0h0WxFMdtXso39iLE3qfW23xHg1+pGXJmu7sSVA0jHnJCqFy2iK1R3CdI57YXM6ogIn d75WLTEj06QSkKnyEhXfM0Dti1VYsUgdNxD3tlQ0lDu4yt8Rz+lgvmgwJNzsSP0jNJrf hjdA== 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=6T+CvKxhIT/wD43F8C6X0mfQEc7rDvNDe6JNobc9BRE=; b=hWBSm1l45Fqvi5YfX6zozhZf3o+b5tpaNv/hnAeEFUC2RxeNHaAcae90TRt67wINAY ET0tczUN6nFJG9CtO8q5kEjfP33mhl6cJfYEA8mTpizePeJAKiAJFgFD22I5PEkpWbII amD6uv6iJY6KHRQJsIpxyQt91XCnW0LrBhxBA7b/ETz8XhFW6kjRCJQsnqrDwu7HvX8J 8pQPE7U1iqLlquYPWZHTKAwxWvUS8hsOR4cPdCOkDFMzk697/pgYJz46mXlwv96djbC/ xbaDsasHi2s1bBu8goiD89d+0NzCCo2LLacpESKltI0eh6Vbbl5QBr9bN8GdMRClEABo zQ4Q== X-Gm-Message-State: APjAAAWb/iMmI4tBXpovc7ypOJMx7gKj3zMHSSCy4bXIGIiNzvov/F0V RpxVXX5uJe0YFYPhELUT651WNBn9 X-Google-Smtp-Source: APXvYqz7Pce7OFwypJLOSTBwDgyffKgjU77hMV049nta2c+kkS//hAaXVuUhc+NTisXDJJonxPGzyQ== X-Received: by 2002:a1c:a848:: with SMTP id r69mr3750914wme.12.1561116636277; Fri, 21 Jun 2019 04:30:36 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:35 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:09 +0200 Message-Id: <1561116620-22245-15-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::32d Subject: [Qemu-devel] [PULL 14/25] KVM: Introduce kvm_arch_destroy_vcpu() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Liran Alon Simiar to how kvm_init_vcpu() calls kvm_arch_init_vcpu() to perform arch-dependent initialisation, introduce kvm_arch_destroy_vcpu() to be called from kvm_destroy_vcpu() to perform arch-dependent destruction. This was added because some architectures (Such as i386) currently do not free memory that it have allocated in kvm_arch_init_vcpu(). Suggested-by: Maran Wilson Reviewed-by: Maran Wilson Signed-off-by: Liran Alon Message-Id: <20190619162140.133674-3-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 5 +++++ include/sysemu/kvm.h | 1 + target/arm/kvm32.c | 5 +++++ target/arm/kvm64.c | 5 +++++ target/i386/kvm.c | 12 ++++++++++++ target/mips/kvm.c | 5 +++++ target/ppc/kvm.c | 5 +++++ target/s390x/kvm.c | 10 ++++++++++ 8 files changed, 48 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index d2f481a..f0f5ab8 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -291,6 +291,11 @@ int kvm_destroy_vcpu(CPUState *cpu) DPRINTF("kvm_destroy_vcpu\n"); + ret = kvm_arch_destroy_vcpu(cpu); + if (ret < 0) { + goto err; + } + mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0); if (mmap_size < 0) { ret = mmap_size; diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index a6d1cd1..64f55e5 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -371,6 +371,7 @@ int kvm_arch_put_registers(CPUState *cpu, int level); int kvm_arch_init(MachineState *ms, KVMState *s); int kvm_arch_init_vcpu(CPUState *cpu); +int kvm_arch_destroy_vcpu(CPUState *cpu); bool kvm_vcpu_id_is_valid(int vcpu_id); diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c index 4e54e37..51f78f7 100644 --- a/target/arm/kvm32.c +++ b/target/arm/kvm32.c @@ -240,6 +240,11 @@ int kvm_arch_init_vcpu(CPUState *cs) return kvm_arm_init_cpreg_list(cpu); } +int kvm_arch_destroy_vcpu(CPUState *cs) +{ + return 0; +} + typedef struct Reg { uint64_t id; int offset; diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index 998d21f..22d19c9 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -654,6 +654,11 @@ int kvm_arch_init_vcpu(CPUState *cs) return kvm_arm_init_cpreg_list(cpu); } +int kvm_arch_destroy_vcpu(CPUState *cs) +{ + return 0; +} + bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx) { /* Return true if the regidx is a register we should synchronize diff --git a/target/i386/kvm.c b/target/i386/kvm.c index c5cbead..26d8c61 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1679,6 +1679,18 @@ int kvm_arch_init_vcpu(CPUState *cs) return r; } +int kvm_arch_destroy_vcpu(CPUState *cs) +{ + X86CPU *cpu = X86_CPU(cs); + + if (cpu->kvm_msr_buf) { + g_free(cpu->kvm_msr_buf); + cpu->kvm_msr_buf = NULL; + } + + return 0; +} + void kvm_arch_reset_vcpu(X86CPU *cpu) { CPUX86State *env = &cpu->env; diff --git a/target/mips/kvm.c b/target/mips/kvm.c index 8e72850..938f8f1 100644 --- a/target/mips/kvm.c +++ b/target/mips/kvm.c @@ -91,6 +91,11 @@ int kvm_arch_init_vcpu(CPUState *cs) return ret; } +int kvm_arch_destroy_vcpu(CPUState *cs) +{ + return 0; +} + void kvm_mips_reset_vcpu(MIPSCPU *cpu) { CPUMIPSState *env = &cpu->env; diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index d4107dd..4b4989c 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -521,6 +521,11 @@ int kvm_arch_init_vcpu(CPUState *cs) return ret; } +int kvm_arch_destroy_vcpu(CPUState *cs) +{ + return 0; +} + static void kvm_sw_tlb_put(PowerPCCPU *cpu) { CPUPPCState *env = &cpu->env; diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index bcec979..0267c6c 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -368,6 +368,16 @@ int kvm_arch_init_vcpu(CPUState *cs) return 0; } +int kvm_arch_destroy_vcpu(CPUState *cs) +{ + S390CPU *cpu = S390_CPU(cs); + + g_free(cpu->irqstate); + cpu->irqstate = NULL; + + return 0; +} + void kvm_s390_reset_vcpu(S390CPU *cpu) { CPUState *cs = CPU(cpu); From patchwork Fri Jun 21 11:30:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120204 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jwmQLb55"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Vd2C3hljz9sNR for ; Fri, 21 Jun 2019 22:16:03 +1000 (AEST) Received: from localhost ([::1]:60394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heISW-0004Gz-QG for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 08:16:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49159) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHki-0000nm-MY for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkf-0005x4-FP for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:44 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:45652) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHke-0005qQ-Fm for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:41 -0400 Received: by mail-wr1-x431.google.com with SMTP id f9so6190291wre.12 for ; Fri, 21 Jun 2019 04:30:38 -0700 (PDT) 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=HWP1ufHEPv6v1c0xa0Nf5LyDIweD+0VGMlRLkFfhXBk=; b=jwmQLb558yMNTSCC1JxVy+VjofeQO+iOJq5GQgPpnQr90Znn39sthCoNfFRINNEpw5 +3lPwf2k+PMhjz0ZUxBcKp4+S+10Hj3jtmuTRFyXD/bwMXzPgKV94n7DzL7EXM6tU3VF B41Q4eBR1uEI8Z8YaRL29m0SbfPexjDBbpd4jOffU/h0T5QGYhZyM0uUlp7Nvx8zxMg0 iWwtMzdO1CIYFU95O11iKFQn1wlZgH5nrR0YKByXmRudIQHgGCDz1yh4lOTaBEPBen1w 1rI7FcHUhWIr/oWKIaLY5h7DhK0vdIqJAETuB5gD2GsnEeN6+BSvtXwEmKyvyuk53eXL uQZg== 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=HWP1ufHEPv6v1c0xa0Nf5LyDIweD+0VGMlRLkFfhXBk=; b=DPJOXtzFD0g4OTrhjnE4v67QM8drW7mzjICbp/4T7jtCXpkc8j3bT2yaphRjHoSYYb VccCL41JfJhcrTMrGPJ+AysX3zMX0B6+xrs2YrOW+KokEMBAqIcjpisTm+IWTp7IIX74 0didQH/VOyF4CiYfJ+RqUt/cvKEbmn/SHPtufDtw/LqVKA7FIUjKr89/tWATlpCtTO9L 7c3C/ywlTcE8uy8aZ3/+Fpunzg4z8qqcZ8qeyMv/zmDNkS44UZ0OG3w1yfN4eFX1Np43 eQefyDZGf83QjGe9xL764wzjcUHhWcDOLg/qV4lcfUsMpP99oGgkRNIUOAcSfEjaf5BT 2SxQ== X-Gm-Message-State: APjAAAUc26vtLfLzmsOwf0ZvgyyZ8zRf/HnjXfKrdOo8Hl/1S8wYmvLP C76TT/wleyXqDx3enVlWoDnDqfdI X-Google-Smtp-Source: APXvYqyoKuwyjDWAb/MmD5o+F6LNuQfOm/l0GkSmXK1SqUlrbWo5TurVvtN2jguyXEju8yf13/lhyg== X-Received: by 2002:adf:c541:: with SMTP id s1mr81085189wrf.44.1561116637325; Fri, 21 Jun 2019 04:30:37 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:36 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:10 +0200 Message-Id: <1561116620-22245-16-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::431 Subject: [Qemu-devel] [PULL 15/25] target/i386: kvm: Use symbolic constant for #DB/#BP exception constants X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Liran Alon Reviewed-by: Nikita Leshenko Reviewed-by: Krish Sadhukhan Signed-off-by: Liran Alon Message-Id: <20190619162140.133674-4-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 26d8c61..c763643 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -3345,9 +3345,9 @@ static int kvm_guest_debug_workarounds(X86CPU *cpu) unsigned long reinject_trap = 0; if (!kvm_has_vcpu_events()) { - if (env->exception_injected == 1) { + if (env->exception_injected == EXCP01_DB) { reinject_trap = KVM_GUESTDBG_INJECT_DB; - } else if (env->exception_injected == 3) { + } else if (env->exception_injected == EXCP03_INT3) { reinject_trap = KVM_GUESTDBG_INJECT_BP; } env->exception_injected = -1; @@ -3859,8 +3859,8 @@ static int kvm_handle_debug(X86CPU *cpu, int ret = 0; int n; - if (arch_info->exception == 1) { - if (arch_info->dr6 & (1 << 14)) { + if (arch_info->exception == EXCP01_DB) { + if (arch_info->dr6 & DR6_BS) { if (cs->singlestep_enabled) { ret = EXCP_DEBUG; } From patchwork Fri Jun 21 11:30:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pgD0HWrO"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcFD3M5Qz9s4V for ; Fri, 21 Jun 2019 21:40:31 +1000 (AEST) Received: from localhost ([::1]:59896 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHu9-0008Jx-Lg for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:40:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49160) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHki-0000nn-MV for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkf-0005wy-FH for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:44 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:39049) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHke-0005sg-Eo for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:41 -0400 Received: by mail-wr1-x441.google.com with SMTP id x4so6228814wrt.6 for ; Fri, 21 Jun 2019 04:30:40 -0700 (PDT) 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=r43n33nGY2axkM37zxfub6AARNJoo1eQ/uWxCMQ4hvk=; b=pgD0HWrOZPOtt3FOskFG89w8+4xDiM5azTIxrvmQDn5dLdmykuQ53OgZKET9cOPoDW M+F2s4pEXaXsDLrv4bfZDSguEQ5LPMcgCdOmkxN8xM7XQSJC0XHqdIFcFkDPkWyObavp 3wt3wrjKCKdvnjQjTDqFgcYZJn6F4hbmhEur+MTsBksi7ik7DitHSWOrypu6KXSNt9d3 5Reu3stbXrQc8n0twQ6UVe8+zaYWidDhYq7mFRXGng9kWwyekuQE6lwWxMBqpXOOMzAK SHjW1FunmO91pSLRrKV8LuUxOLU/Kvw3UfQ1GqUv6XCO4OnLkTVrLB7zPhnGSIUcUTUq vtbA== 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=r43n33nGY2axkM37zxfub6AARNJoo1eQ/uWxCMQ4hvk=; b=eeMOLQcHbujBhxcevZZ4FeupL20WhBL7DxgDb670ch8LLfLnzpz+Rvj30JqZQw/MD7 pZ6bM+093i8aMVnZUHXU2maGu7+nFt1uVcaP1ye9cCC3B9rfZkaCHte2TmxkmLPIqbaU LMrdkUjeHm7FFNGarcy080XUcQOzl9mxUy/udDu35UyqR3iSDYyXXjVV3zND6ZoxMoxl raV9RnopOyXjDWiHGnx5cw3tVA4dKVXivH4qF8WLAoFgHT6a56zucCLMQ1G9iRmzBjoy S5OJvWTPOj0JxP54M3GtJHbEet7mSMmN7gsMCBT7mCaYopqNfh+SQ/m26aTPaNY80WXu nQBw== X-Gm-Message-State: APjAAAVnQCXmJiSU9E2k4cTSLSrvsUuwzekUHMIxDIQlgFhx8DewFicg loKf4EzVj/Eio3YlvZ4lV+S5t0Yr X-Google-Smtp-Source: APXvYqxxYzIy1xfgpI7+xU+AkIPVfJzjYyL79wrY5tbrzsdAWm4SPTPzhB0Atd7FtaR76CLRylPy1w== X-Received: by 2002:a5d:6050:: with SMTP id j16mr26260588wrt.20.1561116638916; Fri, 21 Jun 2019 04:30:38 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:37 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:11 +0200 Message-Id: <1561116620-22245-17-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::441 Subject: [Qemu-devel] [PULL 16/25] target/i386: kvm: Re-inject #DB to guest with updated DR6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Liran Alon If userspace (QEMU) debug guest, when #DB is raised in guest and intercepted by KVM, KVM forwards information on #DB to userspace instead of injecting #DB to guest. While doing so, KVM don't update vCPU DR6 but instead report the #DB DR6 value to userspace for further handling. See KVM's handle_exception() DB_VECTOR handler. QEMU handler for this case is kvm_handle_debug(). This handler basically checks if #DB is related to one of user set hardware breakpoints and if not, it re-inject #DB into guest. The re-injection is done by setting env->exception_injected to #DB which will later be passed as events.exception.nr to KVM_SET_VCPU_EVENTS ioctl by kvm_put_vcpu_events(). However, in case userspace re-injects #DB, KVM expects userspace to set vCPU DR6 as reported to userspace when #DB was intercepted! Otherwise, KVM_REQ_EVENT handler will inject #DB with wrong DR6 to guest. Fix this issue by updating vCPU DR6 appropriately when re-inject #DB to guest. Reviewed-by: Nikita Leshenko Reviewed-by: Krish Sadhukhan Signed-off-by: Liran Alon Message-Id: <20190619162140.133674-5-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index c763643..9864aa0 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -3897,6 +3897,9 @@ static int kvm_handle_debug(X86CPU *cpu, /* pass to guest */ env->exception_injected = arch_info->exception; env->has_error_code = 0; + if (arch_info->exception == EXCP01_DB) { + env->dr[6] = arch_info->dr6; + } } return ret; From patchwork Fri Jun 21 11:30:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120183 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LsxcLYib"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcQW6M35z9sND for ; Fri, 21 Jun 2019 21:48:35 +1000 (AEST) Received: from localhost ([::1]:59956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heI1x-0005Zc-VG for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:48:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49164) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHki-0000no-OS for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkf-0005xi-MI for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:44 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:37201) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkf-0005vX-Gb for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:41 -0400 Received: by mail-wm1-x32b.google.com with SMTP id f17so6233318wme.2 for ; Fri, 21 Jun 2019 04:30:41 -0700 (PDT) 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=jGOTUhh33OOT1Enfmvtwgh0euyeueOCeP1kgbRTa4fI=; b=LsxcLYibqiJwqVVPEgMPe6DHkUaueCP51KdnuJZk3tuNhPrfndHQaUte9pjKJqrs0e 1VL+rykF7gh+Ed2lzc5qouKZcY9G6gUL6fTAmcMUZRQ4Jef++JtXlJ2nqdcYJHvarMdP 6BXLIBrKNT9ekStqKF/tRTh/0FzMdxGZSL6XG0fsOsDqs91o6Ni2kNXoS9EkSAdVA2NY EifdbT2bh0J/85h6I68upQ/BB2ZCn/JceGldPgIMUwc4/LkhZrbzTo1vy7HLL5WqnwzT TPTsF6gzrB8sgq+ZFui1mXEhaQrPkkGN+vDFysCjUMZrjpKCMh3tYEUC2vzL3Mngcrsr VmDg== 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=jGOTUhh33OOT1Enfmvtwgh0euyeueOCeP1kgbRTa4fI=; b=moYBTKGMBp78bw2ybfKKP/VQgSSPv4nQCI0DHA2y462dvBdHd8C0e1a8gbVdzjzTIk 3Xo9NmHBXRA3hi6WkeAI9DJ28diGvaGPEYKu/cQS6gBSyUGhJ7abEyZv9Gtm/G5PI0C0 Sk5vUCj2Y/+aYE8tsvAjyblaR3VkxeZWRVf66HBqDCFAqwdpbZn8V9tjF4jUQjMV4rK/ EUhS5IT5JE9N6ArxjOIS56Wn8PjWCRHXX2D6+VODClu4nYlB2JJzNuPXAzs9Hn3TscFU MNzZQwaxFkgBb4XjPFF0c1V51hGYG5aIpSfAcwLENAvi9Fzkqhq8SlhzkDqHeLXYjSXG 0hWA== X-Gm-Message-State: APjAAAW8gESPS+nOMqcjmc6S6YYOl1OPwjGtdqSZnjI3byRY1gV3SoJM GKBeHlcNuUMksefSRM5NY/NeiJqX X-Google-Smtp-Source: APXvYqwx3PQfJse8vvms+8JS91gnEzw7tfxRRGjQx1usJmrz7eZ33+SCFuihYGkwl2Lx/OhjP3/uMA== X-Received: by 2002:a7b:c748:: with SMTP id w8mr3645177wmk.36.1561116639913; Fri, 21 Jun 2019 04:30:39 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:12 +0200 Message-Id: <1561116620-22245-18-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::32b Subject: [Qemu-devel] [PULL 17/25] target/i386: kvm: Block migration for vCPUs exposed with nested virtualization X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Liran Alon Commit d98f26073beb ("target/i386: kvm: add VMX migration blocker") added a migration blocker for vCPU exposed with Intel VMX. However, migration should also be blocked for vCPU exposed with AMD SVM. Both cases should be blocked because QEMU should extract additional vCPU state from KVM that should be migrated as part of vCPU VMState. E.g. Whether vCPU is running in guest-mode or host-mode. Fixes: d98f26073beb ("target/i386: kvm: add VMX migration blocker") Reviewed-by: Maran Wilson Signed-off-by: Liran Alon Message-Id: <20190619162140.133674-6-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 6 ------ target/i386/cpu.h | 12 ++++++++++++ target/i386/kvm.c | 14 +++++++------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c330fd9..61e44cb 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5215,12 +5215,6 @@ static int x86_cpu_filter_features(X86CPU *cpu) return rv; } -#define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \ - (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \ - (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3) -#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \ - (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \ - (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3) static void x86_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 7f48136..bf0c9c2 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -722,6 +722,13 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS]; #define CPUID_VENDOR_HYGON "HygonGenuine" +#define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \ + (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \ + (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3) +#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \ + (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \ + (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3) + #define CPUID_MWAIT_IBE (1U << 1) /* Interrupts can exit capability */ #define CPUID_MWAIT_EMX (1U << 0) /* enumeration supported */ @@ -1848,6 +1855,11 @@ static inline int32_t x86_get_a20_mask(CPUX86State *env) } } +static inline bool cpu_has_vmx(CPUX86State *env) +{ + return env->features[FEAT_1_ECX] & CPUID_EXT_VMX; +} + /* fpu_helper.c */ void update_fp_status(CPUX86State *env); void update_mxcsr_status(CPUX86State *env); diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 9864aa0..f9872f1 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1299,7 +1299,7 @@ static int hyperv_init_vcpu(X86CPU *cpu) } static Error *invtsc_mig_blocker; -static Error *vmx_mig_blocker; +static Error *nested_virt_mig_blocker; #define KVM_MAX_CPUID_ENTRIES 100 @@ -1597,13 +1597,13 @@ int kvm_arch_init_vcpu(CPUState *cs) !!(c->ecx & CPUID_EXT_SMX); } - if ((env->features[FEAT_1_ECX] & CPUID_EXT_VMX) && !vmx_mig_blocker) { - error_setg(&vmx_mig_blocker, - "Nested VMX virtualization does not support live migration yet"); - r = migrate_add_blocker(vmx_mig_blocker, &local_err); + if (cpu_has_nested_virt(env) && !nested_virt_mig_blocker) { + error_setg(&nested_virt_mig_blocker, + "Nested virtualization does not support live migration yet"); + r = migrate_add_blocker(nested_virt_mig_blocker, &local_err); if (local_err) { error_report_err(local_err); - error_free(vmx_mig_blocker); + error_free(nested_virt_mig_blocker); return r; } } @@ -1674,7 +1674,7 @@ int kvm_arch_init_vcpu(CPUState *cs) fail: migrate_del_blocker(invtsc_mig_blocker); fail2: - migrate_del_blocker(vmx_mig_blocker); + migrate_del_blocker(nested_virt_mig_blocker); return r; } From patchwork Fri Jun 21 11:30:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OCYJBFje"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcLk4wM4z9s4V for ; Fri, 21 Jun 2019 21:45:17 +1000 (AEST) Received: from localhost ([::1]:59942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHyf-0004Lq-Dy for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:45:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49169) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkj-0000o0-IJ for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkg-0005zy-Fz for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:45 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:35370) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkg-0005wk-AZ for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:42 -0400 Received: by mail-wm1-x341.google.com with SMTP id c6so6258800wml.0 for ; Fri, 21 Jun 2019 04:30:41 -0700 (PDT) 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=46R01TlppRnc8fuF4nJaB/BSCYQl7BxcBYUaCW1Ujrw=; b=OCYJBFje81z8YsWV/eaa3U+OdyC4JMc6PkN2YO2W0k9IoCtHkUNHliAdgut0X8T8vY 4ngbJK0p4HW43Oy0/t8AdxbsG2X5Wp3/a8BELvZWnOPHSswQylObo1uMfAaApqfpJl7q Rwam7D0WHJ7976P7FJnV+Itn/HfuviAsWumElxSxEFfHpXV2jPskTi/aS1yP7Z1mHxnp 2A0zm5lM5tHh+Gjhe+fYQOUyEtW8ey4eRgp6OIQR9xe3EImPcbO2dlwRNmwqfv6NF7EN 0OXifCTRNYhs70XMl5lPUIVxXrK8bw9K5Vmr/Q65gYWx48P+BOwDWoYfmaL1pscQsFpD yQhg== 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=46R01TlppRnc8fuF4nJaB/BSCYQl7BxcBYUaCW1Ujrw=; b=MAt6A6+yKzPxUGwC5Ga8W6UYcJqiVC10t0APzKIm5oGevCXB3IX8UNoM0NMw4URI+l khP/0cv58GaFwZp7DbZRSZokE0YX2EWQZltQeMoi92L92qnvsigIxt6cL0r4ufZMUqQs W67i4jNeMc6l5cD0cILC7nbtaNcg4CNIsAKojgIpnZpm8DUd8uxeDZS88hzcSmL5bxBW tIlKPpb2E10voOho8Pbe07UET3VlIHQ0+hHD1SzS0jhZYryYS2OZ5YDwhKKa60BkwGfH cnbEHaiiZe1cdI9xJAqQ97hKX4mmCyZ+iGncNj9fwt72D4/zl73cuq6jpzsGCoOmixKW upLg== X-Gm-Message-State: APjAAAUHCTylmcRxzl89SN9MPlLRnRSdiAXc7S7DDBEYwJSeHyb+GOTN nSAfZHAP/yH8bDi8aF2Wvg8aknxp X-Google-Smtp-Source: APXvYqw1QbpuyfKBP/VBHVEfR+tQUL3N5raQgG24Dskegx0dNhqHoBuyuT5MQTJGC03gV5DQ1FToOQ== X-Received: by 2002:a7b:c3d5:: with SMTP id t21mr3480723wmj.87.1561116640822; Fri, 21 Jun 2019 04:30:40 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:40 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:13 +0200 Message-Id: <1561116620-22245-19-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::341 Subject: [Qemu-devel] [PULL 18/25] linux-headers: sync with latest KVM headers from Linux 5.2 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Liran Alon Improve the KVM_{GET,SET}_NESTED_STATE structs by detailing the format of VMX nested state data in a struct. In order to avoid changing the ioctl values of KVM_{GET,SET}_NESTED_STATE, there is a need to preserve sizeof(struct kvm_nested_state). This is done by defining the data struct as "data.vmx[0]". It was the most elegant way I found to preserve struct size while still keeping struct readable and easy to maintain. It does have a misfortunate side-effect that now it has to be accessed as "data.vmx[0]" rather than just "data.vmx". Because we are already modifying these structs, I also modified the following: * Define the "format" field values as macros. * Rename vmcs_pa to vmcs12_pa for better readability. Signed-off-by: Liran Alon Reviewed-by: Maran Wilson Message-Id: <20190619162140.133674-7-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- linux-headers/asm-x86/kvm.h | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h index 7a0e64c..6e7dd79 100644 --- a/linux-headers/asm-x86/kvm.h +++ b/linux-headers/asm-x86/kvm.h @@ -383,16 +383,26 @@ struct kvm_sync_regs { #define KVM_X86_QUIRK_LAPIC_MMIO_HOLE (1 << 2) #define KVM_X86_QUIRK_OUT_7E_INC_RIP (1 << 3) +#define KVM_STATE_NESTED_FORMAT_VMX 0 +#define KVM_STATE_NESTED_FORMAT_SVM 1 + #define KVM_STATE_NESTED_GUEST_MODE 0x00000001 #define KVM_STATE_NESTED_RUN_PENDING 0x00000002 #define KVM_STATE_NESTED_EVMCS 0x00000004 +#define KVM_STATE_NESTED_VMX_VMCS_SIZE 0x1000 + #define KVM_STATE_NESTED_SMM_GUEST_MODE 0x00000001 #define KVM_STATE_NESTED_SMM_VMXON 0x00000002 -struct kvm_vmx_nested_state { +struct kvm_vmx_nested_state_data { + __u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE]; + __u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE]; +}; + +struct kvm_vmx_nested_state_hdr { __u64 vmxon_pa; - __u64 vmcs_pa; + __u64 vmcs12_pa; struct { __u16 flags; @@ -401,24 +411,25 @@ struct kvm_vmx_nested_state { /* for KVM_CAP_NESTED_STATE */ struct kvm_nested_state { - /* KVM_STATE_* flags */ __u16 flags; - - /* 0 for VMX, 1 for SVM. */ __u16 format; - - /* 128 for SVM, 128 + VMCS size for VMX. */ __u32 size; union { - /* VMXON, VMCS */ - struct kvm_vmx_nested_state vmx; + struct kvm_vmx_nested_state_hdr vmx; /* Pad the header to 128 bytes. */ __u8 pad[120]; - }; + } hdr; - __u8 data[0]; + /* + * Define data region as 0 bytes to preserve backwards-compatability + * to old definition of kvm_nested_state in order to avoid changing + * KVM_{GET,PUT}_NESTED_STATE ioctl values. + */ + union { + struct kvm_vmx_nested_state_data vmx[0]; + } data; }; #endif /* _ASM_X86_KVM_H */ From patchwork Fri Jun 21 11:30:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120205 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HuA40D2j"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Vd7S0zpYz9s4Y for ; Fri, 21 Jun 2019 22:20:35 +1000 (AEST) Received: from localhost ([::1]:60712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heIWv-0008LN-3G for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 08:20:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49180) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkk-0000pJ-7z for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkh-00061X-51 for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:46 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:53216) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkg-0005zl-Vh for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:43 -0400 Received: by mail-wm1-x32f.google.com with SMTP id s3so6017565wms.2 for ; Fri, 21 Jun 2019 04:30:42 -0700 (PDT) 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=lELKDL0Qi4GxKG0TXKbAlktFhWCNneWOViNCGmw6D1c=; b=HuA40D2jrvC8pxF9AE6mX0sBKns0bDMZLTDVjtqhrEER1p1KPdnAucWv3FfGIEDWr3 GQ/c5nG6v0Ygoi3QzYBbwwleuD9EJQtdd+5f9TDvlIOf1eJn+7IbaaKlg6Sfwb6esC7D AKBG82ScRZO9OthnPFM/yL6Dud0KOOcRH5sypjnqpAp6Psc40NGCQB7swoscZoLE+Gqo mDQ8oaVm/HajGwdXXB0IBy7/tYSGsdjcBgC0/iyPEJvzVcMdZ/24I8m8EZI83EjVCPGE LAgnOhnYAA31arxY/yENbegKWUcfSn7jo1IamDe0pehar4bD7X+rzunPC+amK0aHrlQP tVyQ== 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=lELKDL0Qi4GxKG0TXKbAlktFhWCNneWOViNCGmw6D1c=; b=NIVreFodUTbeR87+wp64zqLvhy4ns1H1OZzc7R4RBHK1fMkuBc8bEwsyOwJaT/YeEw xjIIOk+wsDiCPwkiWBf18SEx6MFB6Uox/QwM1rWYFXx7pyYOFQmd/l2lEkl4VvE2RnbL Yy4mzulkocI1aBkKmSagKne7kEeW8Z1+kn7Zk0+awdlq+i9bHm1aMAvakgxmaZbKag9K qx174TpYijkvYhBgZp0D+25HiAvxFR64Fk4s/UmmirlwAnTqB/sOlVG/91uU4af44hrK ZPNNlsRbrtVkOwcgHqHMkk9cjAN389OQbTz3I/P6xdJnHHa51ymYXi3Gw3mj+c8P9CMG y8gQ== X-Gm-Message-State: APjAAAUJeGuByrhNysIqVb86bcqhPgJHB7vX7TlmqOr2SCTe/koNQfEh DDZybQvH9YUL/+jJXSUErdz6GPzn X-Google-Smtp-Source: APXvYqxA8xjTQiPYUSJ9Zz0SXFptQJuYwpnjp+BVAzx36+NTWZdIBTFtJuTxrrNtiohfv7DrzffkRQ== X-Received: by 2002:a7b:c5d1:: with SMTP id n17mr3872338wmk.84.1561116641763; Fri, 21 Jun 2019 04:30:41 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:14 +0200 Message-Id: <1561116620-22245-20-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::32f Subject: [Qemu-devel] [PULL 19/25] vmstate: Add support for kernel integer types X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Liran Alon Reviewed-by: Nikita Leshenko Reviewed-by: Maran Wilson Signed-off-by: Liran Alon Reviewed-by: Dr. David Alan Gilbert Message-Id: <20190619162140.133674-8-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- include/migration/vmstate.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 9224370..ca68584 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -797,6 +797,19 @@ extern const VMStateInfo vmstate_info_qtailq; #define VMSTATE_UINT64_V(_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, uint64_t) +#ifdef CONFIG_LINUX + +#define VMSTATE_U8_V(_f, _s, _v) \ + VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint8, __u8) +#define VMSTATE_U16_V(_f, _s, _v) \ + VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint16, __u16) +#define VMSTATE_U32_V(_f, _s, _v) \ + VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint32, __u32) +#define VMSTATE_U64_V(_f, _s, _v) \ + VMSTATE_SINGLE(_f, _s, _v, vmstate_info_uint64, __u64) + +#endif + #define VMSTATE_BOOL(_f, _s) \ VMSTATE_BOOL_V(_f, _s, 0) @@ -818,6 +831,19 @@ extern const VMStateInfo vmstate_info_qtailq; #define VMSTATE_UINT64(_f, _s) \ VMSTATE_UINT64_V(_f, _s, 0) +#ifdef CONFIG_LINUX + +#define VMSTATE_U8(_f, _s) \ + VMSTATE_U8_V(_f, _s, 0) +#define VMSTATE_U16(_f, _s) \ + VMSTATE_U16_V(_f, _s, 0) +#define VMSTATE_U32(_f, _s) \ + VMSTATE_U32_V(_f, _s, 0) +#define VMSTATE_U64(_f, _s) \ + VMSTATE_U64_V(_f, _s, 0) + +#endif + #define VMSTATE_UINT8_EQUAL(_f, _s, _err_hint) \ VMSTATE_SINGLE_FULL(_f, _s, 0, 0, \ vmstate_info_uint8_equal, uint8_t, _err_hint) From patchwork Fri Jun 21 11:30:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="c3rsz9fU"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcS96bzTz9sBr for ; Fri, 21 Jun 2019 21:50:01 +1000 (AEST) Received: from localhost ([::1]:59980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heI3L-0007xz-W0 for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:50:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49197) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkl-0000t0-Rh for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:31:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHki-00063m-KJ for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:47 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:50685) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHki-00061o-6c for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:44 -0400 Received: by mail-wm1-x343.google.com with SMTP id c66so6035703wmf.0 for ; Fri, 21 Jun 2019 04:30:43 -0700 (PDT) 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=Qg8kQpqZzF9XETIfQB6QGbrUFX5sJufHSNIhV3GqhK0=; b=c3rsz9fUtBY9GlsdgFSgNr4/pw7g/1mOLrFxpa+pCwieqaIE9uBX8YXDFeTuDG8R80 n6nte7a0EI0UoXH/oWT62pmk+d43bdkFOb3Z/aU4ytcO7W4HlejpC+vNr61J8aef8g6I jAZIZVCEM0slUbP2eb2jJmsn7Fpkyv3oqmEtiSo/rY35pikwl1Iykq8I3gLX6gw3zrbC XKEXcR0B9RBnVVwO2DXhTwDbhRGu2tDqDWD/84vtx8kDvJPR9dma0bHrAGT7dKHcLBMQ NVJuCor4333CucnSj2nIBV9TFeBEuZVDPS8uUsXb251m+pWAA2LY+yOur2GnrhbCl+9n zYEA== 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=Qg8kQpqZzF9XETIfQB6QGbrUFX5sJufHSNIhV3GqhK0=; b=kALiz9lub3NuFCoGXekckLKVnhGnNQ1QYiNEeVm/HMr2h6zpIGkWpsgD8dPja2ZAtH FjUoaKK0Lo+bD7GYR1q3SJSy3WPd6z3ovytAyvNRJ6n+/sz5kLIjYxl688e8chv2HfyD zQEz9c5ihTH/rOrjmo3LN+thuY93O0tckeb6DH5Mw4IEv2oge9Faem1oPT/6hpbvn+GU CDFJCMoO/jw6EpMf8ulft3KAuBnWOZo2YobtZvCbDOzJRCIVKIgdhjPWwEy8v5JQ30JH d8bAFFPL/trnkPfg+5WwB258nFbGrOuWMbxjFIbECsV2d/bGx+ZUdJK/7iT9L8FpQVV4 q/cA== X-Gm-Message-State: APjAAAWKBnfm9sQWdhcOPp0gZeylVyo/Zw4ggqKTixojr+9GBrhPrTcm qDRPFa11d+wjcWxYUl7gvYLQ46qU X-Google-Smtp-Source: APXvYqz1q2mHtUKho6Sc8TbQxSJoWtyREqoko3UeQ76I0WSlLVXAdlE9ps7yqmzcuB6LG0sq3MGByQ== X-Received: by 2002:a1c:a483:: with SMTP id n125mr3751959wme.3.1561116642681; Fri, 21 Jun 2019 04:30:42 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:15 +0200 Message-Id: <1561116620-22245-21-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::343 Subject: [Qemu-devel] [PULL 20/25] target/i386: kvm: Add support for save and restore nested state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Liran Alon Kernel commit 8fcc4b5923af ("kvm: nVMX: Introduce KVM_CAP_NESTED_STATE") introduced new IOCTLs to extract and restore vCPU state related to Intel VMX & AMD SVM. Utilize these IOCTLs to add support for migration of VMs which are running nested hypervisors. Reviewed-by: Nikita Leshenko Reviewed-by: Maran Wilson Tested-by: Maran Wilson Signed-off-by: Liran Alon Message-Id: <20190619162140.133674-9-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 8 ++ include/sysemu/kvm.h | 1 + target/i386/cpu.h | 3 + target/i386/kvm.c | 80 ++++++++++++++++++++ target/i386/machine.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 290 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index f0f5ab8..e3cf728 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -87,6 +87,7 @@ struct KVMState #ifdef KVM_CAP_SET_GUEST_DEBUG QTAILQ_HEAD(, kvm_sw_breakpoint) kvm_sw_breakpoints; #endif + int max_nested_state_len; int many_ioeventfds; int intx_set_mask; bool sync_mmu; @@ -1681,6 +1682,8 @@ static int kvm_init(MachineState *ms) s->debugregs = kvm_check_extension(s, KVM_CAP_DEBUGREGS); #endif + s->max_nested_state_len = kvm_check_extension(s, KVM_CAP_NESTED_STATE); + #ifdef KVM_CAP_IRQ_ROUTING kvm_direct_msi_allowed = (kvm_check_extension(s, KVM_CAP_SIGNAL_MSI) > 0); #endif @@ -2248,6 +2251,11 @@ int kvm_has_debugregs(void) return kvm_state->debugregs; } +int kvm_max_nested_state_length(void) +{ + return kvm_state->max_nested_state_len; +} + int kvm_has_many_ioeventfds(void) { if (!kvm_enabled()) { diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 64f55e5..acd90ae 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -210,6 +210,7 @@ bool kvm_has_sync_mmu(void); int kvm_has_vcpu_events(void); int kvm_has_robust_singlestep(void); int kvm_has_debugregs(void); +int kvm_max_nested_state_length(void); int kvm_has_pit_state2(void); int kvm_has_many_ioeventfds(void); int kvm_has_gsi_routing(void); diff --git a/target/i386/cpu.h b/target/i386/cpu.h index bf0c9c2..17116ef 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1360,6 +1360,9 @@ typedef struct CPUX86State { #if defined(CONFIG_KVM) || defined(CONFIG_HVF) void *xsave_buf; #endif +#if defined(CONFIG_KVM) + struct kvm_nested_state *nested_state; +#endif #if defined(CONFIG_HVF) HVFX86EmulatorState *hvf_emul; #endif diff --git a/target/i386/kvm.c b/target/i386/kvm.c index f9872f1..e924663 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1324,6 +1324,7 @@ int kvm_arch_init_vcpu(CPUState *cs) struct kvm_cpuid_entry2 *c; uint32_t signature[3]; int kvm_base = KVM_CPUID_SIGNATURE; + int max_nested_state_len; int r; Error *local_err = NULL; @@ -1658,6 +1659,24 @@ int kvm_arch_init_vcpu(CPUState *cs) if (has_xsave) { env->xsave_buf = qemu_memalign(4096, sizeof(struct kvm_xsave)); } + + max_nested_state_len = kvm_max_nested_state_length(); + if (max_nested_state_len > 0) { + assert(max_nested_state_len >= offsetof(struct kvm_nested_state, data)); + env->nested_state = g_malloc0(max_nested_state_len); + + env->nested_state->size = max_nested_state_len; + + if (IS_INTEL_CPU(env)) { + struct kvm_vmx_nested_state_hdr *vmx_hdr = + &env->nested_state->hdr.vmx; + + env->nested_state->format = KVM_STATE_NESTED_FORMAT_VMX; + vmx_hdr->vmxon_pa = -1ull; + vmx_hdr->vmcs12_pa = -1ull; + } + } + cpu->kvm_msr_buf = g_malloc0(MSR_BUF_SIZE); if (!(env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_RDTSCP)) { @@ -1682,12 +1701,18 @@ int kvm_arch_init_vcpu(CPUState *cs) int kvm_arch_destroy_vcpu(CPUState *cs) { X86CPU *cpu = X86_CPU(cs); + CPUX86State *env = &cpu->env; if (cpu->kvm_msr_buf) { g_free(cpu->kvm_msr_buf); cpu->kvm_msr_buf = NULL; } + if (env->nested_state) { + g_free(env->nested_state); + env->nested_state = NULL; + } + return 0; } @@ -3411,6 +3436,52 @@ static int kvm_get_debugregs(X86CPU *cpu) return 0; } +static int kvm_put_nested_state(X86CPU *cpu) +{ + CPUX86State *env = &cpu->env; + int max_nested_state_len = kvm_max_nested_state_length(); + + if (max_nested_state_len <= 0) { + return 0; + } + + assert(env->nested_state->size <= max_nested_state_len); + return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_NESTED_STATE, env->nested_state); +} + +static int kvm_get_nested_state(X86CPU *cpu) +{ + CPUX86State *env = &cpu->env; + int max_nested_state_len = kvm_max_nested_state_length(); + int ret; + + if (max_nested_state_len <= 0) { + return 0; + } + + /* + * It is possible that migration restored a smaller size into + * nested_state->hdr.size than what our kernel support. + * We preserve migration origin nested_state->hdr.size for + * call to KVM_SET_NESTED_STATE but wish that our next call + * to KVM_GET_NESTED_STATE will use max size our kernel support. + */ + env->nested_state->size = max_nested_state_len; + + ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_NESTED_STATE, env->nested_state); + if (ret < 0) { + return ret; + } + + if (env->nested_state->flags & KVM_STATE_NESTED_GUEST_MODE) { + env->hflags |= HF_GUEST_MASK; + } else { + env->hflags &= ~HF_GUEST_MASK; + } + + return ret; +} + int kvm_arch_put_registers(CPUState *cpu, int level) { X86CPU *x86_cpu = X86_CPU(cpu); @@ -3418,6 +3489,11 @@ int kvm_arch_put_registers(CPUState *cpu, int level) assert(cpu_is_stopped(cpu) || qemu_cpu_is_self(cpu)); + ret = kvm_put_nested_state(x86_cpu); + if (ret < 0) { + return ret; + } + if (level >= KVM_PUT_RESET_STATE) { ret = kvm_put_msr_feature_control(x86_cpu); if (ret < 0) { @@ -3533,6 +3609,10 @@ int kvm_arch_get_registers(CPUState *cs) if (ret < 0) { goto out; } + ret = kvm_get_nested_state(cpu); + if (ret < 0) { + goto out; + } ret = 0; out: cpu_sync_bndcs_hflags(&cpu->env); diff --git a/target/i386/machine.c b/target/i386/machine.c index a39ce7f..a6afdf8 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -231,6 +231,15 @@ static int cpu_pre_save(void *opaque) env->segs[R_SS].flags &= ~(env->segs[R_SS].flags & DESC_DPL_MASK); } +#ifdef CONFIG_KVM + /* Verify we have nested virtualization state from kernel if required */ + if (cpu_has_nested_virt(env) && !env->nested_state) { + error_report("Guest enabled nested virtualization but kernel " + "does not support saving of nested state"); + return -EINVAL; + } +#endif + return 0; } @@ -278,6 +287,16 @@ static int cpu_post_load(void *opaque, int version_id) env->hflags &= ~HF_CPL_MASK; env->hflags |= (env->segs[R_SS].flags >> DESC_DPL_SHIFT) & HF_CPL_MASK; +#ifdef CONFIG_KVM + if ((env->hflags & HF_GUEST_MASK) && + (!env->nested_state || + !(env->nested_state->flags & KVM_STATE_NESTED_GUEST_MODE))) { + error_report("vCPU set in guest-mode inconsistent with " + "migrated kernel nested state"); + return -EINVAL; + } +#endif + env->fpstt = (env->fpus_vmstate >> 11) & 7; env->fpus = env->fpus_vmstate & ~0x3800; env->fptag_vmstate ^= 0xff; @@ -851,6 +870,182 @@ static const VMStateDescription vmstate_tsc_khz = { } }; +#ifdef CONFIG_KVM + +static bool vmx_vmcs12_needed(void *opaque) +{ + struct kvm_nested_state *nested_state = opaque; + return (nested_state->size > + offsetof(struct kvm_nested_state, data.vmx[0].vmcs12)); +} + +static const VMStateDescription vmstate_vmx_vmcs12 = { + .name = "cpu/kvm_nested_state/vmx/vmcs12", + .version_id = 1, + .minimum_version_id = 1, + .needed = vmx_vmcs12_needed, + .fields = (VMStateField[]) { + VMSTATE_UINT8_ARRAY(data.vmx[0].vmcs12, + struct kvm_nested_state, + KVM_STATE_NESTED_VMX_VMCS_SIZE), + VMSTATE_END_OF_LIST() + } +}; + +static bool vmx_shadow_vmcs12_needed(void *opaque) +{ + struct kvm_nested_state *nested_state = opaque; + return (nested_state->size > + offsetof(struct kvm_nested_state, data.vmx[0].shadow_vmcs12)); +} + +static const VMStateDescription vmstate_vmx_shadow_vmcs12 = { + .name = "cpu/kvm_nested_state/vmx/shadow_vmcs12", + .version_id = 1, + .minimum_version_id = 1, + .needed = vmx_shadow_vmcs12_needed, + .fields = (VMStateField[]) { + VMSTATE_UINT8_ARRAY(data.vmx[0].shadow_vmcs12, + struct kvm_nested_state, + KVM_STATE_NESTED_VMX_VMCS_SIZE), + VMSTATE_END_OF_LIST() + } +}; + +static bool vmx_nested_state_needed(void *opaque) +{ + struct kvm_nested_state *nested_state = opaque; + + return ((nested_state->format == KVM_STATE_NESTED_FORMAT_VMX) && + ((nested_state->hdr.vmx.vmxon_pa != -1ull) || + (nested_state->hdr.vmx.smm.flags & KVM_STATE_NESTED_SMM_VMXON))); +} + +static const VMStateDescription vmstate_vmx_nested_state = { + .name = "cpu/kvm_nested_state/vmx", + .version_id = 1, + .minimum_version_id = 1, + .needed = vmx_nested_state_needed, + .fields = (VMStateField[]) { + VMSTATE_U64(hdr.vmx.vmxon_pa, struct kvm_nested_state), + VMSTATE_U64(hdr.vmx.vmcs12_pa, struct kvm_nested_state), + VMSTATE_U16(hdr.vmx.smm.flags, struct kvm_nested_state), + VMSTATE_END_OF_LIST() + }, + .subsections = (const VMStateDescription*[]) { + &vmstate_vmx_vmcs12, + &vmstate_vmx_shadow_vmcs12, + NULL, + } +}; + +static bool svm_nested_state_needed(void *opaque) +{ + struct kvm_nested_state *nested_state = opaque; + + return (nested_state->format == KVM_STATE_NESTED_FORMAT_SVM); +} + +static const VMStateDescription vmstate_svm_nested_state = { + .name = "cpu/kvm_nested_state/svm", + .version_id = 1, + .minimum_version_id = 1, + .needed = svm_nested_state_needed, + .fields = (VMStateField[]) { + VMSTATE_END_OF_LIST() + } +}; + +static bool nested_state_needed(void *opaque) +{ + X86CPU *cpu = opaque; + CPUX86State *env = &cpu->env; + + return (env->nested_state && + (vmx_nested_state_needed(env->nested_state) || + svm_nested_state_needed(env->nested_state))); +} + +static int nested_state_post_load(void *opaque, int version_id) +{ + X86CPU *cpu = opaque; + CPUX86State *env = &cpu->env; + struct kvm_nested_state *nested_state = env->nested_state; + int min_nested_state_len = offsetof(struct kvm_nested_state, data); + int max_nested_state_len = kvm_max_nested_state_length(); + + /* + * If our kernel don't support setting nested state + * and we have received nested state from migration stream, + * we need to fail migration + */ + if (max_nested_state_len <= 0) { + error_report("Received nested state when kernel cannot restore it"); + return -EINVAL; + } + + /* + * Verify that the size of received nested_state struct + * at least cover required header and is not larger + * than the max size that our kernel support + */ + if (nested_state->size < min_nested_state_len) { + error_report("Received nested state size less than min: " + "len=%d, min=%d", + nested_state->size, min_nested_state_len); + return -EINVAL; + } + if (nested_state->size > max_nested_state_len) { + error_report("Recieved unsupported nested state size: " + "nested_state->size=%d, max=%d", + nested_state->size, max_nested_state_len); + return -EINVAL; + } + + /* Verify format is valid */ + if ((nested_state->format != KVM_STATE_NESTED_FORMAT_VMX) && + (nested_state->format != KVM_STATE_NESTED_FORMAT_SVM)) { + error_report("Received invalid nested state format: %d", + nested_state->format); + return -EINVAL; + } + + return 0; +} + +static const VMStateDescription vmstate_kvm_nested_state = { + .name = "cpu/kvm_nested_state", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_U16(flags, struct kvm_nested_state), + VMSTATE_U16(format, struct kvm_nested_state), + VMSTATE_U32(size, struct kvm_nested_state), + VMSTATE_END_OF_LIST() + }, + .subsections = (const VMStateDescription*[]) { + &vmstate_vmx_nested_state, + &vmstate_svm_nested_state, + NULL + } +}; + +static const VMStateDescription vmstate_nested_state = { + .name = "cpu/nested_state", + .version_id = 1, + .minimum_version_id = 1, + .needed = nested_state_needed, + .post_load = nested_state_post_load, + .fields = (VMStateField[]) { + VMSTATE_STRUCT_POINTER(env.nested_state, X86CPU, + vmstate_kvm_nested_state, + struct kvm_nested_state), + VMSTATE_END_OF_LIST() + } +}; + +#endif + static bool mcg_ext_ctl_needed(void *opaque) { X86CPU *cpu = opaque; @@ -1113,6 +1308,9 @@ VMStateDescription vmstate_x86_cpu = { #ifndef TARGET_X86_64 &vmstate_efer32, #endif +#ifdef CONFIG_KVM + &vmstate_nested_state, +#endif NULL } }; From patchwork Fri Jun 21 11:30:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120176 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Kl8sBg6+"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcBg1mxDz9s4V for ; Fri, 21 Jun 2019 21:38:19 +1000 (AEST) Received: from localhost ([::1]:59884 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHs1-0006aO-9L for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:38:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49206) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkn-0000tn-0i for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:31:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkj-00064p-GX for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:48 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:50686) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkj-000643-9v for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:45 -0400 Received: by mail-wm1-x344.google.com with SMTP id c66so6035741wmf.0 for ; Fri, 21 Jun 2019 04:30:45 -0700 (PDT) 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=l72mkXaCMqefx2/Q6hSWGat//IXZlxTetqrucDXPp9Q=; b=Kl8sBg6+Yo4WJq2CfaZiJB7C+DmNNOWCV1lC3uJqW0kBbRiOWHLMwDgqk9iF4rC+QP A9fSQwO1zKLXghUYJ/keMdSn8nUepL1lbwGD4QCYko2xLVZ5kTZNBAB9dwxhG/vJy/Xj /HUDXFeA+mBEc1zFwtz9e44KakKznMMUWpSVj3pS25zDFra+JSRjuIgz0JgGTurChqDn 9wG0rl350H+GkHuWWwG6wquzLvVWKAfZBtstve2DZ9mfQwWdtpm9LrU7MsCWvk1cMk/8 K2hFp5VhTvDy3Ho3mT/W4N+ALLrgaqg+2y7HStJFb+0w5P20N/rsgWsa1v94R0YRK9sm npDg== 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=l72mkXaCMqefx2/Q6hSWGat//IXZlxTetqrucDXPp9Q=; b=j2zg22lgX8Pw9CNUHxaw6yW0fxJ9dUjgYRAK870YU6oxJJ+Y7asIxPieTC606iMva7 ddj0oplr8kctDCx8w6gDdLTPLMfIAtzEpYiD5M2J/u5k2dHcXqD4wXjKh2tZdIRNkfbc tuDPymBzWLpcwmZ9sbDoQ43NyaVAFwsn9vBgLJxqOQaMovQhL61p2k1Bx0NX26WgVFhE FmsEpCuXbDZon2OMkaEXj6QCTtLWgC47peB2glkTL2PoqOaRldVWEb76iIwnGVwfbe3w 2Li+1rSqSjd3j2gtEfKDUzMVyWe5vBIM3sTR3+fJQjyz94uCD+uPMVr5nK33/BUvgQ2s lnMw== X-Gm-Message-State: APjAAAVGJq5h2rZYEMwmFQn3dIUUVCyKWBM92gfpXaMCmIZGsjZqllFe Ea43XGQVtjMpQuaLdcjlpP3UIlzr X-Google-Smtp-Source: APXvYqyEhWdGgarzIVvB0ZmBipV4HSZLeFvmmUhsBXJ47cX0glsKP9xU7Z+F2qA143ssqPZ1N6JBaw== X-Received: by 2002:a1c:3c8a:: with SMTP id j132mr3779434wma.172.1561116643955; Fri, 21 Jun 2019 04:30:43 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:16 +0200 Message-Id: <1561116620-22245-22-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::344 Subject: [Qemu-devel] [PULL 21/25] target/i386: kvm: Add support for KVM_CAP_EXCEPTION_PAYLOAD X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Liran Alon Kernel commit c4f55198c7c2 ("kvm: x86: Introduce KVM_CAP_EXCEPTION_PAYLOAD") introduced a new KVM capability which allows userspace to correctly distinguish between pending and injected exceptions. This distinguish is important in case of nested virtualization scenarios because a L2 pending exception can still be intercepted by the L1 hypervisor while a L2 injected exception cannot. Furthermore, when an exception is attempted to be injected by QEMU, QEMU should specify the exception payload (CR2 in case of #PF or DR6 in case of #DB) instead of having the payload already delivered in the respective vCPU register. Because in case exception is injected to L2 guest and is intercepted by L1 hypervisor, then payload needs to be reported to L1 intercept (VMExit handler) while still preserving respective vCPU register unchanged. This commit adds support for QEMU to properly utilise this new KVM capability (KVM_CAP_EXCEPTION_PAYLOAD). Reviewed-by: Nikita Leshenko Signed-off-by: Liran Alon Message-Id: <20190619162140.133674-10-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 6 ++- target/i386/cpu.h | 6 ++- target/i386/hvf/hvf.c | 10 +++-- target/i386/hvf/x86hvf.c | 4 +- target/i386/kvm.c | 101 +++++++++++++++++++++++++++++++++++++++-------- target/i386/machine.c | 84 ++++++++++++++++++++++++++++++++++++++- 6 files changed, 187 insertions(+), 24 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 61e44cb..da6eb67 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4819,7 +4819,11 @@ static void x86_cpu_reset(CPUState *s) memset(env->mtrr_fixed, 0, sizeof(env->mtrr_fixed)); env->interrupt_injected = -1; - env->exception_injected = -1; + env->exception_nr = -1; + env->exception_pending = 0; + env->exception_injected = 0; + env->exception_has_payload = false; + env->exception_payload = 0; env->nmi_injected = false; #if !defined(CONFIG_USER_ONLY) /* We hard-wire the BSP to the first CPU. */ diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 17116ef..9334579 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1348,10 +1348,14 @@ typedef struct CPUX86State { /* For KVM */ uint32_t mp_state; - int32_t exception_injected; + int32_t exception_nr; int32_t interrupt_injected; uint8_t soft_interrupt; + uint8_t exception_pending; + uint8_t exception_injected; uint8_t has_error_code; + uint8_t exception_has_payload; + uint64_t exception_payload; uint32_t ins_len; uint32_t sipi_vector; bool tsc_valid; diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index 2751c81..dc4bb63 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -605,7 +605,9 @@ static void hvf_store_events(CPUState *cpu, uint32_t ins_len, uint64_t idtvec_in X86CPU *x86_cpu = X86_CPU(cpu); CPUX86State *env = &x86_cpu->env; - env->exception_injected = -1; + env->exception_nr = -1; + env->exception_pending = 0; + env->exception_injected = 0; env->interrupt_injected = -1; env->nmi_injected = false; if (idtvec_info & VMCS_IDT_VEC_VALID) { @@ -619,7 +621,8 @@ static void hvf_store_events(CPUState *cpu, uint32_t ins_len, uint64_t idtvec_in break; case VMCS_IDT_VEC_HWEXCEPTION: case VMCS_IDT_VEC_SWEXCEPTION: - env->exception_injected = idtvec_info & VMCS_IDT_VEC_VECNUM; + env->exception_nr = idtvec_info & VMCS_IDT_VEC_VECNUM; + env->exception_injected = 1; break; case VMCS_IDT_VEC_PRIV_SWEXCEPTION: default: @@ -912,7 +915,8 @@ int hvf_vcpu_exec(CPUState *cpu) macvm_set_rip(cpu, rip + ins_len); break; case VMX_REASON_VMCALL: - env->exception_injected = EXCP0D_GPF; + env->exception_nr = EXCP0D_GPF; + env->exception_injected = 1; env->has_error_code = true; env->error_code = 0; break; diff --git a/target/i386/hvf/x86hvf.c b/target/i386/hvf/x86hvf.c index df8e946..e0ea02d 100644 --- a/target/i386/hvf/x86hvf.c +++ b/target/i386/hvf/x86hvf.c @@ -362,8 +362,8 @@ bool hvf_inject_interrupts(CPUState *cpu_state) if (env->interrupt_injected != -1) { vector = env->interrupt_injected; intr_type = VMCS_INTR_T_SWINTR; - } else if (env->exception_injected != -1) { - vector = env->exception_injected; + } else if (env->exception_nr != -1) { + vector = env->exception_nr; if (vector == EXCP03_INT3 || vector == EXCP04_INTO) { intr_type = VMCS_INTR_T_SWEXCEPTION; } else { diff --git a/target/i386/kvm.c b/target/i386/kvm.c index e924663..c931e9d 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -104,6 +104,7 @@ static uint32_t num_architectural_pmu_fixed_counters; static int has_xsave; static int has_xcrs; static int has_pit_state2; +static int has_exception_payload; static bool has_msr_mcg_ext_ctl; @@ -584,15 +585,56 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr) /* Hope we are lucky for AO MCE */ } +static void kvm_reset_exception(CPUX86State *env) +{ + env->exception_nr = -1; + env->exception_pending = 0; + env->exception_injected = 0; + env->exception_has_payload = false; + env->exception_payload = 0; +} + +static void kvm_queue_exception(CPUX86State *env, + int32_t exception_nr, + uint8_t exception_has_payload, + uint64_t exception_payload) +{ + assert(env->exception_nr == -1); + assert(!env->exception_pending); + assert(!env->exception_injected); + assert(!env->exception_has_payload); + + env->exception_nr = exception_nr; + + if (has_exception_payload) { + env->exception_pending = 1; + + env->exception_has_payload = exception_has_payload; + env->exception_payload = exception_payload; + } else { + env->exception_injected = 1; + + if (exception_nr == EXCP01_DB) { + assert(exception_has_payload); + env->dr[6] = exception_payload; + } else if (exception_nr == EXCP0E_PAGE) { + assert(exception_has_payload); + env->cr[2] = exception_payload; + } else { + assert(!exception_has_payload); + } + } +} + static int kvm_inject_mce_oldstyle(X86CPU *cpu) { CPUX86State *env = &cpu->env; - if (!kvm_has_vcpu_events() && env->exception_injected == EXCP12_MCHK) { + if (!kvm_has_vcpu_events() && env->exception_nr == EXCP12_MCHK) { unsigned int bank, bank_num = env->mcg_cap & 0xff; struct kvm_x86_mce mce; - env->exception_injected = -1; + kvm_reset_exception(env); /* * There must be at least one bank in use if an MCE is pending. @@ -1943,6 +1985,16 @@ int kvm_arch_init(MachineState *ms, KVMState *s) hv_vpindex_settable = kvm_check_extension(s, KVM_CAP_HYPERV_VP_INDEX); + has_exception_payload = kvm_check_extension(s, KVM_CAP_EXCEPTION_PAYLOAD); + if (has_exception_payload) { + ret = kvm_vm_enable_cap(s, KVM_CAP_EXCEPTION_PAYLOAD, 0, true); + if (ret < 0) { + error_report("kvm: Failed to enable exception payload cap: %s", + strerror(-ret)); + return ret; + } + } + ret = kvm_get_supported_msrs(s); if (ret < 0) { return ret; @@ -3253,8 +3305,16 @@ static int kvm_put_vcpu_events(X86CPU *cpu, int level) return 0; } - events.exception.injected = (env->exception_injected >= 0); - events.exception.nr = env->exception_injected; + events.flags = 0; + + if (has_exception_payload) { + events.flags |= KVM_VCPUEVENT_VALID_PAYLOAD; + events.exception.pending = env->exception_pending; + events.exception_has_payload = env->exception_has_payload; + events.exception_payload = env->exception_payload; + } + events.exception.nr = env->exception_nr; + events.exception.injected = env->exception_injected; events.exception.has_error_code = env->has_error_code; events.exception.error_code = env->error_code; @@ -3267,7 +3327,6 @@ static int kvm_put_vcpu_events(X86CPU *cpu, int level) events.nmi.masked = !!(env->hflags2 & HF2_NMI_MASK); events.sipi_vector = env->sipi_vector; - events.flags = 0; if (has_msr_smbase) { events.smi.smm = !!(env->hflags & HF_SMM_MASK); @@ -3317,8 +3376,19 @@ static int kvm_get_vcpu_events(X86CPU *cpu) if (ret < 0) { return ret; } - env->exception_injected = - events.exception.injected ? events.exception.nr : -1; + + if (events.flags & KVM_VCPUEVENT_VALID_PAYLOAD) { + env->exception_pending = events.exception.pending; + env->exception_has_payload = events.exception_has_payload; + env->exception_payload = events.exception_payload; + } else { + env->exception_pending = 0; + env->exception_has_payload = false; + } + env->exception_injected = events.exception.injected; + env->exception_nr = + (env->exception_pending || env->exception_injected) ? + events.exception.nr : -1; env->has_error_code = events.exception.has_error_code; env->error_code = events.exception.error_code; @@ -3370,12 +3440,12 @@ static int kvm_guest_debug_workarounds(X86CPU *cpu) unsigned long reinject_trap = 0; if (!kvm_has_vcpu_events()) { - if (env->exception_injected == EXCP01_DB) { + if (env->exception_nr == EXCP01_DB) { reinject_trap = KVM_GUESTDBG_INJECT_DB; } else if (env->exception_injected == EXCP03_INT3) { reinject_trap = KVM_GUESTDBG_INJECT_BP; } - env->exception_injected = -1; + kvm_reset_exception(env); } /* @@ -3751,13 +3821,13 @@ int kvm_arch_process_async_events(CPUState *cs) kvm_cpu_synchronize_state(cs); - if (env->exception_injected == EXCP08_DBLE) { + if (env->exception_nr == EXCP08_DBLE) { /* this means triple fault */ qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); cs->exit_request = 1; return 0; } - env->exception_injected = EXCP12_MCHK; + kvm_queue_exception(env, EXCP12_MCHK, 0, 0); env->has_error_code = 0; cs->halted = 0; @@ -3972,14 +4042,13 @@ static int kvm_handle_debug(X86CPU *cpu, } if (ret == 0) { cpu_synchronize_state(cs); - assert(env->exception_injected == -1); + assert(env->exception_nr == -1); /* pass to guest */ - env->exception_injected = arch_info->exception; + kvm_queue_exception(env, arch_info->exception, + arch_info->exception == EXCP01_DB, + arch_info->dr6); env->has_error_code = 0; - if (arch_info->exception == EXCP01_DB) { - env->dr[6] = arch_info->dr6; - } } return ret; diff --git a/target/i386/machine.c b/target/i386/machine.c index a6afdf8..fc49e5a 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -240,6 +240,41 @@ static int cpu_pre_save(void *opaque) } #endif + /* + * When vCPU is running L2 and exception is still pending, + * it can potentially be intercepted by L1 hypervisor. + * In contrast to an injected exception which cannot be + * intercepted anymore. + * + * Furthermore, when a L2 exception is intercepted by L1 + * hypervisor, it's exception payload (CR2/DR6 on #PF/#DB) + * should not be set yet in the respective vCPU register. + * Thus, in case an exception is pending, it is + * important to save the exception payload seperately. + * + * Therefore, if an exception is not in a pending state + * or vCPU is not in guest-mode, it is not important to + * distinguish between a pending and injected exception + * and we don't need to store seperately the exception payload. + * + * In order to preserve better backwards-compatabile migration, + * convert a pending exception to an injected exception in + * case it is not important to distingiush between them + * as described above. + */ + if (env->exception_pending && !(env->hflags & HF_GUEST_MASK)) { + env->exception_pending = 0; + env->exception_injected = 1; + + if (env->exception_has_payload) { + if (env->exception_nr == EXCP01_DB) { + env->dr[6] = env->exception_payload; + } else if (env->exception_nr == EXCP0E_PAGE) { + env->cr[2] = env->exception_payload; + } + } + } + return 0; } @@ -297,6 +332,23 @@ static int cpu_post_load(void *opaque, int version_id) } #endif + /* + * There are cases that we can get valid exception_nr with both + * exception_pending and exception_injected being cleared. + * This can happen in one of the following scenarios: + * 1) Source is older QEMU without KVM_CAP_EXCEPTION_PAYLOAD support. + * 2) Source is running on kernel without KVM_CAP_EXCEPTION_PAYLOAD support. + * 3) "cpu/exception_info" subsection not sent because there is no exception + * pending or guest wasn't running L2 (See comment in cpu_pre_save()). + * + * In those cases, we can just deduce that a valid exception_nr means + * we can treat the exception as already injected. + */ + if ((env->exception_nr != -1) && + !env->exception_pending && !env->exception_injected) { + env->exception_injected = 1; + } + env->fpstt = (env->fpus_vmstate >> 11) & 7; env->fpus = env->fpus_vmstate & ~0x3800; env->fptag_vmstate ^= 0xff; @@ -342,6 +394,35 @@ static bool steal_time_msr_needed(void *opaque) return cpu->env.steal_time_msr != 0; } +static bool exception_info_needed(void *opaque) +{ + X86CPU *cpu = opaque; + CPUX86State *env = &cpu->env; + + /* + * It is important to save exception-info only in case + * we need to distingiush between a pending and injected + * exception. Which is only required in case there is a + * pending exception and vCPU is running L2. + * For more info, refer to comment in cpu_pre_save(). + */ + return env->exception_pending && (env->hflags & HF_GUEST_MASK); +} + +static const VMStateDescription vmstate_exception_info = { + .name = "cpu/exception_info", + .version_id = 1, + .minimum_version_id = 1, + .needed = exception_info_needed, + .fields = (VMStateField[]) { + VMSTATE_UINT8(env.exception_pending, X86CPU), + VMSTATE_UINT8(env.exception_injected, X86CPU), + VMSTATE_UINT8(env.exception_has_payload, X86CPU), + VMSTATE_UINT64(env.exception_payload, X86CPU), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_steal_time_msr = { .name = "cpu/steal_time_msr", .version_id = 1, @@ -1251,7 +1332,7 @@ VMStateDescription vmstate_x86_cpu = { VMSTATE_INT32(env.interrupt_injected, X86CPU), VMSTATE_UINT32(env.mp_state, X86CPU), VMSTATE_UINT64(env.tsc, X86CPU), - VMSTATE_INT32(env.exception_injected, X86CPU), + VMSTATE_INT32(env.exception_nr, X86CPU), VMSTATE_UINT8(env.soft_interrupt, X86CPU), VMSTATE_UINT8(env.nmi_injected, X86CPU), VMSTATE_UINT8(env.nmi_pending, X86CPU), @@ -1275,6 +1356,7 @@ VMStateDescription vmstate_x86_cpu = { /* The above list is not sorted /wrt version numbers, watch out! */ }, .subsections = (const VMStateDescription*[]) { + &vmstate_exception_info, &vmstate_async_pf_msr, &vmstate_pv_eoi_msr, &vmstate_steal_time_msr, From patchwork Fri Jun 21 11:30:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120193 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="h+lU+NQO"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VccN1djfz9sBr for ; Fri, 21 Jun 2019 21:57:08 +1000 (AEST) Received: from localhost ([::1]:60060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heIAE-0005dU-5S for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:57:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49223) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHkz-0000wi-CN for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:31:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkk-00066E-Is for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:52 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:42528) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkk-00065H-Cu for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:46 -0400 Received: by mail-wr1-x430.google.com with SMTP id x17so6205870wrl.9 for ; Fri, 21 Jun 2019 04:30:46 -0700 (PDT) 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=kXfByX7LWMudNMbfoxt6/9xb5IJTtcMJHhGnMirNo+g=; b=h+lU+NQOdr+2kOx1yPMb232eQGGb5CiqxSQr20VrTCZBl89Jm+0fLHhl+83xi4bHIF SjcpybdXreecfqoG6meVUW0h677GCwh426/56TvEr1jhi6IGp4FiWaBAeHshUUwOY04z Z/dkl2DnVirGaptx83uqXd826+CGchcBSVco1BEYe5qYbHlEVPxcVfqzH7WWPxSMt7pg gReZCxrWfaFGzQi2FLp3XYSyOwpltOeEyB95wKkgz67OmNgRJzwidH/+hcQdprloFxYx 1NnVtgkiJfyVNQI9DlwpYfQ/M51kiHxv+YqqdWCbx6NR4UZNh0xhC+tURL2s9cPnNS3Q rKJw== 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=kXfByX7LWMudNMbfoxt6/9xb5IJTtcMJHhGnMirNo+g=; b=esYi8ZwvRDDjHU8HmpRvZy3Mx2tBiTGWOhRHLM5UgDIBGaUONH4gGVmprKdQo+9SK/ GdxX5BVzTf/CO5d+H7qKn8psq98KFPQxC4tZyx+IYrqCXilms96nIRpC64Mwu6SV+kgd Ugucs7eRvD55Gs/917mHbUoR51ocaEepZx4jYJ2fMJedhvIPRmxRtzlc1AF8yp/Fxcfy 1ej2VP808JP2yayCIr/OUpNK7K9FBzqqNi64HXjrv+pkFu2vnAxfcSp2lPbYo0SJmjoR PdpjA7IJOcDU2oYQVmahzOkm3gGJce5d7RqP2FUN3rGpa60OQc7Pu/6gDPMOEx0b50Xq ntsw== X-Gm-Message-State: APjAAAUvRRJysHy8eT7+HGok6JAVrhAore1Gd/SwW4dXtG7sL3Ug/hum dibfynyebhLLuL7DasRhLRnGbGFT X-Google-Smtp-Source: APXvYqwMMWgrqB8vhrFEVlD3JfxN+ZDRvWrGe47LyWlu3F5v/T3MIsA6LiQ6UQ6ra0s5EiVLCoua+w== X-Received: by 2002:a5d:4489:: with SMTP id j9mr52585019wrq.15.1561116645008; Fri, 21 Jun 2019 04:30:45 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:17 +0200 Message-Id: <1561116620-22245-23-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::430 Subject: [Qemu-devel] [PULL 22/25] target/i386: kvm: Add nested migration blocker only when kernel lacks required capabilities X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liran Alon Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Liran Alon Previous commits have added support for migration of nested virtualization workloads. This was done by utilising two new KVM capabilities: KVM_CAP_NESTED_STATE and KVM_CAP_EXCEPTION_PAYLOAD. Both which are required in order to correctly migrate such workloads. Therefore, change code to add a migration blocker for vCPUs exposed with Intel VMX or AMD SVM in case one of these kernel capabilities is missing. Signed-off-by: Liran Alon Reviewed-by: Maran Wilson Message-Id: <20190619162140.133674-11-liran.alon@oracle.com> Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 9 +++++++-- target/i386/machine.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index c931e9d..e4b4f57 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1640,9 +1640,14 @@ int kvm_arch_init_vcpu(CPUState *cs) !!(c->ecx & CPUID_EXT_SMX); } - if (cpu_has_nested_virt(env) && !nested_virt_mig_blocker) { + if (cpu_has_vmx(env) && !nested_virt_mig_blocker && + ((kvm_max_nested_state_length() <= 0) || !has_exception_payload)) { error_setg(&nested_virt_mig_blocker, - "Nested virtualization does not support live migration yet"); + "Kernel do not provide required capabilities for " + "nested virtualization migration. " + "(CAP_NESTED_STATE=%d, CAP_EXCEPTION_PAYLOAD=%d)", + kvm_max_nested_state_length() > 0, + has_exception_payload); r = migrate_add_blocker(nested_virt_mig_blocker, &local_err); if (local_err) { error_report_err(local_err); diff --git a/target/i386/machine.c b/target/i386/machine.c index fc49e5a..851b249 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -233,7 +233,7 @@ static int cpu_pre_save(void *opaque) #ifdef CONFIG_KVM /* Verify we have nested virtualization state from kernel if required */ - if (cpu_has_nested_virt(env) && !env->nested_state) { + if (kvm_enabled() && cpu_has_vmx(env) && !env->nested_state) { error_report("Guest enabled nested virtualization but kernel " "does not support saving of nested state"); return -EINVAL; From patchwork Fri Jun 21 11:30:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="e3490pY5"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcYC4PPdz9sN6 for ; Fri, 21 Jun 2019 21:54:23 +1000 (AEST) Received: from localhost ([::1]:60000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heI7Z-0002KK-5B for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:54:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49230) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHl1-0000wp-99 for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:31:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkl-00067B-Op for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:55 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:53539) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkl-00066I-AJ for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:47 -0400 Received: by mail-wm1-x335.google.com with SMTP id x15so5999187wmj.3 for ; Fri, 21 Jun 2019 04:30:47 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=H+GIX/ew7P3W1KtFZyQEoH7Aekz0PvrQKasKssVk2dE=; b=e3490pY53AyTGdnzLusrPW1DhvfbMRppGiwbKOfQMLHdcP3aP2llaPJI48NTDyyA8U CAQjvDkaHdVwqGHE4D9QXer0uV+oVVF5xCQqFnT+Oz94lt8z9oPztfV0X+YEo6tipfbH gzEFgw/sHb6zu+hrOh25hWbjsiS1y6ZqTZDrxcKqRmvuWM6wcCM9MstWDunn9tKvXB6W R5cL5g+TbEvMecGaBsOo5k+RivyeqCbPmc1QeYh92+Kopa+Emmz0+m8a7rNKQnOcrPBc 1cvOzU2DjxOnRQx9rQv69rALlS8PuHtZqD/NXM50SkNh/I3pAAqrFPZpmYSSF1fXl81F MUCA== 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:mime-version:content-transfer-encoding; bh=H+GIX/ew7P3W1KtFZyQEoH7Aekz0PvrQKasKssVk2dE=; b=L1H4q8ifJkoPGIlMmEx3F/A78xdLUJrBF+MqYdQW+No4kdQHVWxXresQOpRF7se+Cf EEMQ0MtXaqXo8FFxvEB/0Kz8aTy0ZtDGw/79A30TKifZSKpjctzyRxbxsmrHEmJt4kCa Vda52Aqc1f0hMD00Z3Vwd0OnBLRVOzVNH1S8i2tXR+GsXLi0W3thMA/NMpf7eNM/py2x eQej/WPj9n4xt4paq7WsEEP+avvH+CHAn+44uTrfI0udImkdbcKucxRrDF2JBhj1jBa4 Jc2OaRI1X+e/0/dg8MnMPCNfbtr8Cr5EihZtJBOXBQeHjbLDrIXQbWGx3iwL3kWScVbL e6uQ== X-Gm-Message-State: APjAAAUej13A6eS2NYfHJycD6+FHKYsKA0UQd7JkAdeR7lVPOrrNVaA7 sn3kspZmXp/5SwuID8qDjGj9tru9 X-Google-Smtp-Source: APXvYqw78QfeB8EWm76XpNXcEi9/Yq23E6X/cR6dtxqTrBJHKMJGGklY+qIcdVmAfPM7GBC0IHWgIA== X-Received: by 2002:a05:600c:2549:: with SMTP id e9mr3946555wma.46.1561116646000; Fri, 21 Jun 2019 04:30:46 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:18 +0200 Message-Id: <1561116620-22245-24-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::335 Subject: [Qemu-devel] [PULL 23/25] sd: Fix out-of-bounds assertions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lidong Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Lidong Chen Due to an off-by-one error, the assert statements allow an out-of-bound array access. This doesn't happen in practice, but the static analyzer notices. Signed-off-by: Lidong Chen Reviewed-by: Liam Merwick Reviewed-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Li Qiang Reviewed-by: Darren Kenny Message-Id: <6b19cb7359a10a6bedc3ea0fce22fed3ef93c102.1560806687.git.lidong.chen@oracle.com> Signed-off-by: Paolo Bonzini --- hw/sd/sd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 60500ec..917195a6 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -145,7 +145,7 @@ static const char *sd_state_name(enum SDCardStates state) if (state == sd_inactive_state) { return "inactive"; } - assert(state <= ARRAY_SIZE(state_name)); + assert(state < ARRAY_SIZE(state_name)); return state_name[state]; } @@ -166,7 +166,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp) if (rsp == sd_r1b) { rsp = sd_r1; } - assert(rsp <= ARRAY_SIZE(response_name)); + assert(rsp < ARRAY_SIZE(response_name)); return response_name[rsp]; } From patchwork Fri Jun 21 11:30:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vfnsTVvp"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VcTP0206z9sBr for ; Fri, 21 Jun 2019 21:51:05 +1000 (AEST) Received: from localhost ([::1]:59988 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heI4N-0000T2-0T for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 07:51:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49229) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHl1-0000wo-99 for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:31:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkm-00067Y-9c for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:55 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:51500) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkm-00066q-34 for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:48 -0400 Received: by mail-wm1-x341.google.com with SMTP id 207so6031510wma.1 for ; Fri, 21 Jun 2019 04:30:48 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=a3VGuwnoGM9LiZBZHhLPfux9Kyat183XzMS8uuGHjKk=; b=vfnsTVvpoLsCV3J9zxaZqMHgDbWFpYiznQGay7eixnslFrrXf6aaHfu/LuUcQ3zzUQ iSKdr2mNqA8+lC+FALXYH/E2iUegO5ESxvOvCYo5J2ITcYKqwkMoQUaTnLoI0Lb7wPzl YzFfu8WE95I9HTJHx4Oc1J0bnQOAFqrfFXMPGKhiyXwJtGvpOtMiuLP1a3URV8bXmTR8 Lk8Uklm02kAI+plAP6R7VHwfQxtqsrQSohd4Dl0Dl04V4DB4dV+UiwkHZimhZnp1y23d 8qshSMOOgs9pIkbtjux5AKVg2hbqif0+pai00AevWUAAgQM+yNMCAXWBcYpEzyvUMzB0 VUkw== 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:mime-version:content-transfer-encoding; bh=a3VGuwnoGM9LiZBZHhLPfux9Kyat183XzMS8uuGHjKk=; b=gYoEtvlK9hi3DRqPzqU+B492pZvRIxDzs5XV4Sf7NEzqNVr68W6SSSS/+BI6wg7wQL yvgyEPIjjiXTeyc2P6hNwUaYPVRle0Yer4o+RMyYBcYbT5TEgcSB/BjxoVCNyb7GzGRx O0PLgVrQ4QT6RTturzUikg79i4kHdgNSw2xBJhmOx+IsFd1xDQE20Ai7mSW6bVOCe2Id XUnvFCVnkYPSDoglVqVeJkhHox6IqgDmqenZ7TtzA1lRDMCfNfhaKaK3LzG70Ld77z92 4qcbUrgomsP/JOhUbHGIfeae+T/05yE7VWqxHzTNiol48H/dBiG8R0/VMhCyf/zRLb0E 4lDw== X-Gm-Message-State: APjAAAVZ6riUeHYMv53RRFaoJVjifrWXnM21Zy36y67jJVRfVRdOkq7i +Bk4A0Ht4C+VRc7tGVz1Z4dcb9sN X-Google-Smtp-Source: APXvYqykY5Odf/j/xE+rxPQq1QqQ6UYmgViZuKeBIK6KH4Iz3JOnPODDY2Ri9Y90KAwqSXcAOoyxBQ== X-Received: by 2002:a7b:cc97:: with SMTP id p23mr4031210wma.120.1561116646861; Fri, 21 Jun 2019 04:30:46 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:19 +0200 Message-Id: <1561116620-22245-25-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PULL 24/25] util/main-loop: Fix incorrect assertion X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lidong Chen Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Lidong Chen The check for poll_fds in g_assert() was incorrect. The correct assertion should check "n_poll_fds + w->num <= ARRAY_SIZE(poll_fds)" because the subsequent for-loop is doing access to poll_fds[n_poll_fds + i] where i is in [0, w->num). This could happen with a very high number of file descriptors and/or wait objects. Signed-off-by: Lidong Chen Suggested-by: Peter Maydell Suggested-by: Liam Merwick Reviewed-by: Liran Alon Reviewed-by: Darren Kenny Reviewed-by: Li Qiang Reviewed-by: Philippe Mathieu-Daudé Message-Id: Signed-off-by: Paolo Bonzini --- util/main-loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/main-loop.c b/util/main-loop.c index e1e349c..a9f4e8d 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -422,7 +422,7 @@ static int os_host_main_loop_wait(int64_t timeout) g_main_context_prepare(context, &max_priority); n_poll_fds = g_main_context_query(context, max_priority, &poll_timeout, poll_fds, ARRAY_SIZE(poll_fds)); - g_assert(n_poll_fds <= ARRAY_SIZE(poll_fds)); + g_assert(n_poll_fds + w->num <= ARRAY_SIZE(poll_fds)); for (i = 0; i < w->num; i++) { poll_fds[n_poll_fds + i].fd = (DWORD_PTR)w->events[i]; From patchwork Fri Jun 21 11:30:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1120206 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="t+Vd0Tmk"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45VdBc2w2wz9s4Y for ; Fri, 21 Jun 2019 22:23:20 +1000 (AEST) Received: from localhost ([::1]:60925 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heIZa-0002Z5-Gn for incoming@patchwork.ozlabs.org; Fri, 21 Jun 2019 08:23:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49242) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1heHl6-0000xN-PF for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:31:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1heHkt-0006BO-NP for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:31:01 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:43231) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1heHkn-00067f-26 for qemu-devel@nongnu.org; Fri, 21 Jun 2019 07:30:49 -0400 Received: by mail-wr1-x441.google.com with SMTP id p13so6208405wru.10 for ; Fri, 21 Jun 2019 04:30:48 -0700 (PDT) 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=9dmj/U5AqjA5GQ9gcpPTO1P5uO7lsSOgQoq/OntyvQ4=; b=t+Vd0TmkPSQxWcfr98T9fe1ubQXA2JJ//o8Sy71LVW6aKwZ8ZGji2KwoyVUrhigsAE DMnT0YqgLA+Zb/nRH6ZF1HzxVUFbEOCbKhMUnvdGRddocSPLeYGQmaxtZGg9xf15wcn6 KhvbZdEr+LPBH2umfSwFBaQDHPbIYTrMysryAhZeMpBtMaZngkB7LT6/i5GF8H6kLgRn AkXrZKoSMsna3GSx5KnPklog7Q9iELpXjIdNde0RxD7b/ibLAiUFt6Y55EvAVxgmQ4UU ZvOcdo6YTXWaJ3f1L2uqTQFwdr8gq0chgSIWXcnhUzANbaVJDAu4j3bGCNh9aLblUsgm Wkyw== 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=9dmj/U5AqjA5GQ9gcpPTO1P5uO7lsSOgQoq/OntyvQ4=; b=SnnLg5cv20HgK67u6vy6BnbriKxwqAi/pV6+UdsbVeY3njsr65d5JFnHbg0UH2r1hT F/RSnNJbfLgLcJI4z6O7ax9rGhhpOCacozzKTtd3kQxOukDNjrxCA0lKplCtVqYPztIY jvdtJPZ/WTA0zUsMKwUt4Tffjk53DOkK2rt4M2YYqxETanZ4kIyHdINTDdj0Pm768AqZ v5BEpBsXgxSr1a610HeiM5iGBfVW0SFn7/95zCWkbY08T+d0Ym02XtD+WwjdqptwpgXC /DV3ZhS1IavZpfL9kto4LE7HRg5IBb1xttZRjBtb71uOZs+uDAWjd1IX7JOP8zvy+L3u sOtQ== X-Gm-Message-State: APjAAAWRn4DAhICtEshL23TjP6mOrauc4aqVNG0YObhJSh5A1FOMuece If5mH+x1zm2opucAmrJgEwwrbGBK X-Google-Smtp-Source: APXvYqz4joCmMA8FD2EDhAKeliMkQPOxym9VuhoMMe7m6LnyzmijWzDr0dYomkqv4s2e2Bep8j3RKQ== X-Received: by 2002:adf:fc91:: with SMTP id g17mr6709705wrr.194.1561116647853; Fri, 21 Jun 2019 04:30:47 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id r3sm2712851wrr.61.2019.06.21.04.30.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 04:30:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 21 Jun 2019 13:30:20 +0200 Message-Id: <1561116620-22245-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1561116620-22245-1-git-send-email-pbonzini@redhat.com> References: <1561116620-22245-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:4864:20::441 Subject: [Qemu-devel] [PULL 25/25] hw: Nuke hw_compat_4_0_1 and pc_compat_4_0_1 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kurz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Greg Kurz Commit c87759ce876a fixed a regression affecting pc-q35 machines by introducing a new pc-q35-4.0.1 machine version to be used instead of pc-q35-4.0. The only purpose was to revert the default behaviour of not using split irqchip, but the change also introduced the usual hw_compat and pc_compat bits, and wired them for pc-q35 only. This raises questions when it comes to add new compat properties for 4.0* machine versions of any architecture. Where to add them ? In 4.0, 4.0.1 or both ? Error prone. Another possibility would be to teach all other architectures about 4.0.1. This solution isn't satisfying, especially since this is a pc-q35 specific issue. It turns out that the split irqchip default is handled in the machine option function and doesn't involve compat lists at all. Drop all the 4.0.1 compat lists and use the 4.0 ones instead in the 4.0.1 machine option function. Move the compat props that were added to the 4.0.1 since c87759ce876a to 4.0. Even if only hw_compat_4_0_1 had an impact on other architectures, drop pc_compat_4_0_1 as well for consistency. Fixes: c87759ce876a "q35: Revert to kernel irqchip" Suggested-by: Dr. David Alan Gilbert Signed-off-by: Greg Kurz Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Message-Id: <156051774276.244890.8660277280145466396.stgit@bahia.lan> Signed-off-by: Paolo Bonzini --- hw/core/machine.c | 5 +---- hw/i386/pc.c | 3 --- hw/i386/pc_q35.c | 12 ++++++++---- include/hw/boards.h | 3 --- include/hw/i386/pc.h | 3 --- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 84ebb8d..ea5a01a 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -24,16 +24,13 @@ #include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" -GlobalProperty hw_compat_4_0_1[] = { +GlobalProperty hw_compat_4_0[] = { { "VGA", "edid", "false" }, { "secondary-vga", "edid", "false" }, { "bochs-display", "edid", "false" }, { "virtio-vga", "edid", "false" }, { "virtio-gpu-pci", "edid", "false" }, }; -const size_t hw_compat_4_0_1_len = G_N_ELEMENTS(hw_compat_4_0_1); - -GlobalProperty hw_compat_4_0[] = {}; const size_t hw_compat_4_0_len = G_N_ELEMENTS(hw_compat_4_0); GlobalProperty hw_compat_3_1[] = { diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e41192b..e96360b 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -111,9 +111,6 @@ struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX}; /* Physical Address of PVH entry point read from kernel ELF NOTE */ static size_t pvh_start_addr; -GlobalProperty pc_compat_4_0_1[] = {}; -const size_t pc_compat_4_0_1_len = G_N_ELEMENTS(pc_compat_4_0_1); - GlobalProperty pc_compat_4_0[] = {}; const size_t pc_compat_4_0_len = G_N_ELEMENTS(pc_compat_4_0); diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index dcddc64..57232ae 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -378,8 +378,13 @@ static void pc_q35_4_0_1_machine_options(MachineClass *m) { pc_q35_4_1_machine_options(m); m->alias = NULL; - compat_props_add(m->compat_props, hw_compat_4_0_1, hw_compat_4_0_1_len); - compat_props_add(m->compat_props, pc_compat_4_0_1, pc_compat_4_0_1_len); + /* + * This is the default machine for the 4.0-stable branch. It is basically + * a 4.0 that doesn't use split irqchip by default. It MUST hence apply the + * 4.0 compat props. + */ + compat_props_add(m->compat_props, hw_compat_4_0, hw_compat_4_0_len); + compat_props_add(m->compat_props, pc_compat_4_0, pc_compat_4_0_len); } DEFINE_Q35_MACHINE(v4_0_1, "pc-q35-4.0.1", NULL, @@ -390,8 +395,7 @@ static void pc_q35_4_0_machine_options(MachineClass *m) pc_q35_4_0_1_machine_options(m); m->default_kernel_irqchip_split = true; m->alias = NULL; - compat_props_add(m->compat_props, hw_compat_4_0, hw_compat_4_0_len); - compat_props_add(m->compat_props, pc_compat_4_0, pc_compat_4_0_len); + /* Compat props are applied by the 4.0.1 machine */ } DEFINE_Q35_MACHINE(v4_0, "pc-q35-4.0", NULL, diff --git a/include/hw/boards.h b/include/hw/boards.h index b7362af..eaa050a 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -293,9 +293,6 @@ struct MachineState { } \ type_init(machine_initfn##_register_types) -extern GlobalProperty hw_compat_4_0_1[]; -extern const size_t hw_compat_4_0_1_len; - extern GlobalProperty hw_compat_4_0[]; extern const size_t hw_compat_4_0_len; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index a7d0b87..c54cc54 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -293,9 +293,6 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t); int e820_get_num_entries(void); bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); -extern GlobalProperty pc_compat_4_0_1[]; -extern const size_t pc_compat_4_0_1_len; - extern GlobalProperty pc_compat_4_0[]; extern const size_t pc_compat_4_0_len;