From nobody Tue Nov 11 14:25:36 2025 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=1563636008; cv=none; d=zoho.com; s=zohoarc; b=LS2+FU7M0G9LDfjNlleKyYj9ZXFV8rODbnm+v3UGi5A7f0U1WB92Nfd6zJUJLiR3QTuij21I6IvPKOPcLShEa/AOpWqw8slIetOW3V9cjcdPFvtKdj/BoXQE7ystiqK9XUYAQ+y4dplK2YLuOf3UPgzK7L6dneorVUpl0GjL0Z8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563636008; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Arm9ZHazdpD84Li58k4dV1gofBpEGq70Z3WCUo90whY=; b=fIKgbLF2J4kWjH/StPdelhBkBNzXHmjpC6m2PMt2JHQemlKlYI18f8ROQotgC/FX8MClEGOph7zyUIIg5cQ8oo4AKltGIMzGlDOKta1sXACrjZZ86k+2AWMzEz9Eiwpycq0gWPIAdygdQ+ghlPNjyjvJN+yzWieVGVZ2NQbijWw= 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 1563636008604428.5993767584472; Sat, 20 Jul 2019 08:20:08 -0700 (PDT) Received: from localhost ([::1]:51616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hor9b-0001nD-1r for importer@patchew.org; Sat, 20 Jul 2019 11:20:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39798) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hor8Q-0005n2-IB for qemu-devel@nongnu.org; Sat, 20 Jul 2019 11:18:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hor8P-00084y-4Z for qemu-devel@nongnu.org; Sat, 20 Jul 2019 11:18:54 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:36376) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hor8O-00084W-UP for qemu-devel@nongnu.org; Sat, 20 Jul 2019 11:18:53 -0400 Received: by mail-wm1-x329.google.com with SMTP id g67so27401685wme.1 for ; Sat, 20 Jul 2019 08:18:52 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:8501:6b03:f18c:74f8]) by smtp.gmail.com with ESMTPSA id 4sm77517291wro.78.2019.07.20.08.18.50 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 20 Jul 2019 08:18:50 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=Arm9ZHazdpD84Li58k4dV1gofBpEGq70Z3WCUo90whY=; b=b3uMLfT5BbE9Ky2kA4f993N5IyqstzcRm5aTa3ilU2F0anVRGJCbKxRYTWa9VtXq1z Kw8/acwP2O5mFWyuc16F1T3IEVgQ3H48ViJe/sb91xg+Wtz3yo+Ln00gAw/UTsS4zUOS d7XWEbM/+PYq8rdin3UCkjgxSKbQh0Elc/gM9SVDX9cXxPZMztAq6VFRDilvg/lbYFyL P7LtHXA7AUprXBP/Be8JnnMjnUzPBhePgZnwBEe1/Ywy/iGyQAw2m4XjnkPQXIcmcxSX ElkaE8RuI/BlGonIQlpuvlRIrYXm5D6MHfBw7OqioYxDtmjInP7ctHCO5bPA/8DbEwfO CBvQ== 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 :in-reply-to:references:mime-version:content-transfer-encoding; bh=Arm9ZHazdpD84Li58k4dV1gofBpEGq70Z3WCUo90whY=; b=n39b5ze9I8+ygdXB2p6urJWFdTT/VHhO/zQPGB+TE6aUwcFfL+cKvMnT4QTuLVSB8x cwQa8wrRysm5WZoalyBDw2XQ1QZJVfJqQWxodbzY74Udx0vxu9UzoNW1C2OTKwz/CK54 V5DDuqdJ3RYO2RlFvF/BS2AHzqo+hVp7StM306QYsIiP7qTXKKKF+MgM9LJlBUrW3ZwS daTMdvSo5H2s9ar+rD53/tRr3XuNb2UHRjW2USeDiDcZcT5vZxXStJBpCYSaVurG/HcP 0hpjT5qDDuDRCqCloWBoZIHjB/KNswRit/cCPr8OXChoTAvj1x6k76LedFwRnuofiAPF HUVA== X-Gm-Message-State: APjAAAU4OR71fasDX4PQTnfTG/i4mt3WwvbWNj8uxtJk3P1wlPL0+WFJ IPOuFlLkoHI1RbO1kI3+excAanq4oSA= X-Google-Smtp-Source: APXvYqyLEuoTihZrzSCOGFXsIdar8OD2sXowEbZ1dQqj/Fs7FC65BmRrmq1MBGWkuh1+1BSRawe9yg== X-Received: by 2002:a1c:3:: with SMTP id 3mr54334214wma.6.1563635931703; Sat, 20 Jul 2019 08:18:51 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sat, 20 Jul 2019 17:18:36 +0200 Message-Id: <20190720151846.7450-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190720151846.7450-1-pbonzini@redhat.com> References: <20190720151846.7450-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 02/12] 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-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 | 16 ++++++++-------- target/i386/machine.c | 21 +-------------------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 4542f0f..ada89d2 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1711,15 +1711,15 @@ 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)) { - struct kvm_vmx_nested_state_hdr *vmx_hdr =3D - &env->nested_state->hdr.vmx; + if (cpu_has_vmx(env)) { + struct kvm_vmx_nested_state_hdr *vmx_hdr; =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 =3D &env->nested_state->hdr.vmx; vmx_hdr->vmxon_pa =3D -1ull; vmx_hdr->vmcs12_pa =3D -1ull; } @@ -3515,7 +3515,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 @@ -3529,7 +3529,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