From nobody Tue Apr 23 14:29:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562866026; cv=none; d=zoho.com; s=zohoarc; b=b2F5MrppHa9eiLarWVWMw/+Y2WkwABQnAtkwBkEd7JgOIPQiMRmBD8gcZbVdvwEsQbTGQiwNtPyDw4gl2RVUFMFo/s7yAXEos4J2Wu9xFp1XCw2Jg/Epc4C8UjBFJp4qbK1tMgtp8GNJ5YBzLQHqBSW0+oY8nYfiK9B4oWxQmF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562866026; h=Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=iUgof65FlBg0LXx+uLyqSdziWBu7F3VhET5Hbgi+8Ac=; b=lLDov9GJd7l5q3lvbDEZkocN/aIhckfbO5N0aGX6hGFG3pfwqaAHsHGnf+LqhUGbjF3ga6bc0UQJOWQQLwJZLQwGBI25coiyOGs6FGd7OmkuAyNEZeRjo291MDD0tElkO1QEYyOwWQM2y+46Te7e70E+SyIiVLZ6aYhp8tC3rHk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15628660261221006.6763569058371; Thu, 11 Jul 2019 10:27:06 -0700 (PDT) Received: from localhost ([::1]:43756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlcqW-0000mM-TU for importer@patchew.org; Thu, 11 Jul 2019 13:27:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33036) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlcqM-0000MU-E1 for qemu-devel@nongnu.org; Thu, 11 Jul 2019 13:26:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlcqL-0007wM-An for qemu-devel@nongnu.org; Thu, 11 Jul 2019 13:26:54 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:38614) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hlcqL-0007v1-4e for qemu-devel@nongnu.org; Thu, 11 Jul 2019 13:26:53 -0400 Received: by mail-wm1-x343.google.com with SMTP id s15so6458533wmj.3 for ; Thu, 11 Jul 2019 10:26:53 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id a64sm9701910wmf.1.2019.07.11.10.26.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jul 2019 10:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id; bh=iUgof65FlBg0LXx+uLyqSdziWBu7F3VhET5Hbgi+8Ac=; b=nSnmul48Fsa+bnPIajSKakOIIRERqIcXICBJrNOidlOdb9JtgvR3sWzRbaOin1J7Rw dN4O/vaXuTn46LPy4CpJN9NBCHddyZUTFGI9MrdK0cGhBDhpxa0tJrqgF65D9uwmsOSE 5v/Blh83dnjHwuHIxGaT9dpGQGXQHk4whTrlJ/+xPF9iR9KoZMZCoPL+prpQcWoBTw54 CuYHA7yGY6g7DpNa0ici10G7qsGiSlHSZcQAXG2lqvKtxnTt7hV8UhHosisbhuKbA+Sj B4ajztMrP8zYcnkknl3o/w09+2vzXu/v8NVWEm4uqIHiYTSrlQq4aqrFzzVFhccd8Z8P /DKA== 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:subject:date:message-id; bh=iUgof65FlBg0LXx+uLyqSdziWBu7F3VhET5Hbgi+8Ac=; b=fMJ50tvNa6a8TXLiqPr9ZX1G1m1U8LxzUSdT/LwX6digFO4Dbs4C1K+u+/87gpIGK2 0qiJN/UogIBuu9LbDaX+uQyiWdcZTXBA0v/Itrj1sCvkNisV15n4DWUunQIUM9tdI1qE vvzTSDiXsqzjNsyNuBkZZ17risQsyKaGdmy49s6NhP7rvGwxt18NbmpuuzoMLDiYvLtS buEOjdcGUihDuTt7Y0rR0F1GD4fiTxRh7YqrsN6U1660FvzBA2fURy/XXifSWk3nBHil oTbpHRRiJ3wZ/v1hHfQ3NeM8nEXGCCRnqzFwQMLtQ3j9q9Y6Fk7rW7IVTGVSF5It4TwF RVxQ== X-Gm-Message-State: APjAAAXA58tbDZeH3e6Fcvhkh+yWKoG9zA1yfxEsSjct6VkX9K7YmKcm 6ObLovpqFiNeyOwPkjdzvTokUSJ6Twk= X-Google-Smtp-Source: APXvYqySaaMIc18XW+avIJRv2JwmlqD0GzcldyRxJyr+lgqQeF04nDKYUwiMW63fbm5cFZlQMNCgAw== X-Received: by 2002:a1c:f914:: with SMTP id x20mr5344997wmh.142.1562866011732; Thu, 11 Jul 2019 10:26:51 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 11 Jul 2019 19:26:50 +0200 Message-Id: <1562866010-5355-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 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] [PATCH] target/i386: skip KVM_GET/SET_NESTED_STATE if VMX disabled, or for SVM 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Do not allocate env->nested_state unless we later need to migrate the nested virtualization state. With this change, nested_state_needed() will return false if the VMX flag is not included in the virtual machine. KVM_GET/SET_NESTED_STATE is also disabled for SVM which is safer (we know that at least the NPT root and paging mode have to be saved/loaded), and thus the corresponding subsection can go away as well. Inspired by a patch from Liran Alon. Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 11 +++++------ target/i386/machine.c | 21 +-------------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 5035092..73ab102 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1748,14 +1748,13 @@ int kvm_arch_init_vcpu(CPUState *cs) max_nested_state_len =3D kvm_max_nested_state_length(); if (max_nested_state_len > 0) { assert(max_nested_state_len >=3D offsetof(struct kvm_nested_state,= data)); - env->nested_state =3D g_malloc0(max_nested_state_len); =20 - env->nested_state->size =3D max_nested_state_len; - - if (IS_INTEL_CPU(env)) { + if (cpu_has_vmx(env)) { struct kvm_vmx_nested_state_hdr *vmx_hdr =3D &env->nested_state->hdr.vmx; =20 + env->nested_state =3D g_malloc0(max_nested_state_len); + env->nested_state->size =3D max_nested_state_len; env->nested_state->format =3D KVM_STATE_NESTED_FORMAT_VMX; vmx_hdr->vmxon_pa =3D -1ull; vmx_hdr->vmcs12_pa =3D -1ull; @@ -3682,7 +3681,7 @@ static int kvm_put_nested_state(X86CPU *cpu) CPUX86State *env =3D &cpu->env; int max_nested_state_len =3D kvm_max_nested_state_length(); =20 - if (max_nested_state_len <=3D 0) { + if (!env->nested_state) { return 0; } =20 @@ -3696,7 +3695,7 @@ static int kvm_get_nested_state(X86CPU *cpu) int max_nested_state_len =3D kvm_max_nested_state_length(); int ret; =20 - if (max_nested_state_len <=3D 0) { + if (!env->nested_state) { return 0; } =20 diff --git a/target/i386/machine.c b/target/i386/machine.c index ac2d1d1..b114609 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -1035,31 +1035,13 @@ static const VMStateDescription vmstate_vmx_nested_= state =3D { } }; =20 -static bool svm_nested_state_needed(void *opaque) -{ - struct kvm_nested_state *nested_state =3D opaque; - - return (nested_state->format =3D=3D KVM_STATE_NESTED_FORMAT_SVM); -} - -static const VMStateDescription vmstate_svm_nested_state =3D { - .name =3D "cpu/kvm_nested_state/svm", - .version_id =3D 1, - .minimum_version_id =3D 1, - .needed =3D svm_nested_state_needed, - .fields =3D (VMStateField[]) { - VMSTATE_END_OF_LIST() - } -}; - static bool nested_state_needed(void *opaque) { X86CPU *cpu =3D opaque; CPUX86State *env =3D &cpu->env; =20 return (env->nested_state && - (vmx_nested_state_needed(env->nested_state) || - svm_nested_state_needed(env->nested_state))); + vmx_nested_state_needed(env->nested_state)); } =20 static int nested_state_post_load(void *opaque, int version_id) @@ -1121,7 +1103,6 @@ static const VMStateDescription vmstate_kvm_nested_st= ate =3D { }, .subsections =3D (const VMStateDescription*[]) { &vmstate_vmx_nested_state, - &vmstate_svm_nested_state, NULL } }; --=20 1.8.3.1