From nobody Mon May 20 00:56:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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 (zohomail.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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1575647713; cv=none; d=zohomail.com; s=zohoarc; b=crYHoMbRmoaUmLtzpi5vs9fiWtuPhHUCvY71sle2u7x5AbdhFoUNq9wVFmks5qct5iEC6WI1Wx43btgVn66nJwTLDcBL+iu6lc863W0uHHJIVpLRc4XzgqaR37zVJgts3p6U0M5olRnL9b03AoAKw6kyA4PpFpljX9+fYNihgJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575647713; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=poU4coC1wpEnGRHnApg5z8cKyUslXoAMtkEQeEix3YE=; b=AkbxkxNLsKuH7031WJHQo76oMKEOuVqrnOfr5SYsUdCqEeW/ZygQu52WE7U3Br5DOUI3vwNg3Z+S7UdloM/lfM74Ix7qSE+42a0P4Rdj+S3OshlzKswSIH9NStw9wEosEo7obfi6ccwu8sLBBofaS6hKufY5SMRascprdubPWQw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1575647713611491.6406264338817; Fri, 6 Dec 2019 07:55:13 -0800 (PST) Received: from localhost ([::1]:40172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idFwl-0002wy-Ss for importer@patchew.org; Fri, 06 Dec 2019 10:55:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53741) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1idEmR-0001sA-Ua for qemu-devel@nongnu.org; Fri, 06 Dec 2019 09:40:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1idEmF-00037b-Qh for qemu-devel@nongnu.org; Fri, 06 Dec 2019 09:40:19 -0500 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]:43300) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1idEmF-00035N-4m for qemu-devel@nongnu.org; Fri, 06 Dec 2019 09:40:15 -0500 Received: by mail-qk1-x743.google.com with SMTP id t129so1633944qke.10 for ; Fri, 06 Dec 2019 06:40:14 -0800 (PST) Received: from host.localdomain (104.129.187.94.16clouds.com. [104.129.187.94]) by smtp.gmail.com with ESMTPSA id o7sm2117654qkd.119.2019.12.06.02.25.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Dec 2019 02:25:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=poU4coC1wpEnGRHnApg5z8cKyUslXoAMtkEQeEix3YE=; b=OfA4h5x466F13+EJ6RAM3rEK2XQXeqRQWVoYD9x7iKGEqTUVkJVKX2xdBb0uK7Wiy8 +K3lV6Ttr9mWyHEWzqLfsOXpVaoyIgO0Z7sucDUc5ml8tWFEQx/VSTgDfzKC/7ts+9tw Uo0K8cEOVQCNU+30QTyVLUHJ2glanPx6QqbpFY+xVb6A3XF0oMul+CpcqSe8Z35w2dZo ewoSVe3v+Tq8NBBaubsauIIlFA/zUxnBp8Pw/r37SJwO+aI5dxmsVQ7EzGHFv/9Bo/ks M4iMFTRX1g39U7AWBmfcXeI9aiBakRBcEVi2x8Bs2FWOfBsJCaLVK7xPUmK3LcBKuPUg 94Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=poU4coC1wpEnGRHnApg5z8cKyUslXoAMtkEQeEix3YE=; b=ovqfMxZJ6yHbzgMjk1LdMNSr2HnY/r0QehRs2x3DlSGMzjgzDSpZ74gzMxTg40RRWF otqySnhmKCq4wUHjUufhCWEtMoA1UF40Zb24+ryCDlXiIFvXu8jykV7rQh1rDcyAOb+B 7NW2xrtzpOzoeZKgQ+XDu4rAzioZO2+9RkS1kQxzeAYAac92FOoBSvXoZCb4WT0f40i/ Htiw1AQU2vBVXpx42Xlhtr0shq67a9bWEE9208cUjO+xTXFE5wkkPHH8K873gfgde3xp JTRGyRSPOJSLryxIfnZuSoE8A5Q4Ki0OThVRQXZ/iDNLudvleLGSgwWskb/J0a4lhAX1 tH9Q== X-Gm-Message-State: APjAAAVol5+FdWIdSjCfeK6lr/0qveSkOZYw0ifdQUB2gAXrgobLb8HO 8AldXbUtrGjfNz/ifZpUHAe/H7uNaLw= X-Google-Smtp-Source: APXvYqyHAGUvqCWHS5evYFAogikSLDtFd1xrmclCYnoYpwWw+dIWtypuzUWGf2XoUfxoQEICD0mGNQ== X-Received: by 2002:a37:a257:: with SMTP id l84mr13084095qke.22.1575627933529; Fri, 06 Dec 2019 02:25:33 -0800 (PST) From: Catherine Ho To: Paolo Bonzini , Marcelo Tosatti , qemu-devel@nongnu.org Subject: [PATCH] target/i386: skip kvm_msr_entry_add when kvm_vmx_basic is 0 Date: Fri, 6 Dec 2019 05:23:37 -0500 Message-Id: <1575627817-24625-1-git-send-email-catherine.hecx@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <3a1c97b2-789f-dd21-59ba-f780cf3bad92@redhat.com> References: <3a1c97b2-789f-dd21-59ba-f780cf3bad92@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::743 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: Paolo Bonzini , Catherine Ho , Eduardo Habkost , kvm@vger.kernel.org, Richard Henderson 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" Commit 1389309c811b ("KVM: nVMX: expose VMX capabilities for nested hypervisors to userspace") expands the msr_based_features with MSR_IA32_VMX_BASIC and others. Then together with an old kernel before 1389309c811b, the qemu call KVM_GET_MSR_FEATURE_INDEX_LIST and got the smaller kvm_feature_msrs. Then in kvm_arch_get_supported_msr_feature(), searching VMX_BASIC will be failed and return 0. At last kvm_vmx_basic will be assigned to 0. Without this patch, it will cause a qemu crash (host kernel 4.15 ubuntu 18.04+qemu 4.1): qemu-system-x86_64: error: failed to set MSR 0x480 to 0x0 target/i386/kvm.c:2932: kvm_put_msrs: Assertion `ret =3D=3D cpu->kvm_msr_buf->nmsrs' failed. This fixes it by skipping kvm_msr_entry_add when kvm_vmx_basic is 0 Cc: Paolo Bonzini Signed-off-by: Catherine Ho --- target/i386/kvm.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index a8c44bf..8cf84a2 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -2632,8 +2632,13 @@ static void kvm_msr_entry_add_vmx(X86CPU *cpu, Featu= reWordArray f) f[FEAT_VMX_SECONDARY_CTLS])); kvm_msr_entry_add(cpu, MSR_IA32_VMX_EPT_VPID_CAP, f[FEAT_VMX_EPT_VPID_CAPS] | fixed_vmx_ept_vpid); - kvm_msr_entry_add(cpu, MSR_IA32_VMX_BASIC, + + if (kvm_vmx_basic) { + /* Only add the entry when host supports it */ + kvm_msr_entry_add(cpu, MSR_IA32_VMX_BASIC, f[FEAT_VMX_BASIC] | fixed_vmx_basic); + } + kvm_msr_entry_add(cpu, MSR_IA32_VMX_MISC, f[FEAT_VMX_MISC] | fixed_vmx_misc); if (has_msr_vmx_vmfunc) { --=20 1.7.1