From nobody Tue May 7 13:56:02 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; 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=ucloud.cn ARC-Seal: i=1; a=rsa-sha256; t=1566448863; cv=none; d=zoho.com; s=zohoarc; b=nkpmeJtZZUWs1KBrVwZ0fj/T9kFE6FpIzd4eCdU8rWMC5t2t5WM5lMh5dN+vrS0GqIAMJWTh7A34/5IaXXb0rtfA/KalVJtrOp7HP69BrCstlxZLpwgY8/NqzrkGwUQR10Dos2ycJl3Gzr1CGcOXCWaFBIbm8JuCYoOsauijLjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566448863; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=zXdNHGsIJLmRfeEJ8g5IwUT0at2QrNsaH0Zz1Wv1Idg=; b=i0cAvqDxz9eQEg6PFMuifW+wjA1Rn1SgmRf14As/qV58Fbrnm+5LGbT3hQwii3F2rarRRTvDt33Ydw3SCTZS99UfT5GCtKnRuYYQBSXuCLl9P1qHNA/pzAyOyxVCJIwfVvUaIbjvoR2FbkVaotkfLkvOsxy+P78pU+CCpu6wXNE= ARC-Authentication-Results: i=1; mx.zoho.com; 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 1566448863149118.96358194203117; Wed, 21 Aug 2019 21:41:03 -0700 (PDT) Received: from localhost ([::1]:38072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0eu7-0002lT-Bs for importer@patchew.org; Thu, 22 Aug 2019 00:40:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51181) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0etD-0001yZ-N0 for qemu-devel@nongnu.org; Thu, 22 Aug 2019 00:40:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0etC-0001vN-4a for qemu-devel@nongnu.org; Thu, 22 Aug 2019 00:39:59 -0400 Received: from m9785.mail.qiye.163.com ([220.181.97.85]:36084) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1i0etB-0001qw-ID for qemu-devel@nongnu.org; Thu, 22 Aug 2019 00:39:58 -0400 Received: from localhost.localdomain (unknown [120.132.1.230]) by m9785.mail.qiye.163.com (Hmail) with ESMTPA id 68AAD5C167D; Thu, 22 Aug 2019 12:39:43 +0800 (CST) From: Bingsong Si To: qemu-devel@nongnu.org Date: Thu, 22 Aug 2019 12:29:01 +0800 Message-Id: <20190822042901.16858-1-owen.si@ucloud.cn> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZSFVOTk5CQkJMTk5DTkJIQ1lXWShZQU lCN1dZLVlBSVdZCQ4XHghZQVk1NCk2OjckKS43PlkG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6KzY6MCo4Szg4Fz4VLREqQiow IUkwFEtVSlVKTk1NT09DTENITElMVTMWGhIXVRQMHhVVCBI7DhgXFA4fVRgVRVlXWRILWUFZSklL VUpISVVKVUlIS1lXWQgBWUFPTU1INwY+ X-HM-Tid: 0a6cb79f90842087kuqy68aad5c167d Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.97.85 Subject: [Qemu-devel] [PATCH] i386: Fix legacy guest with xsave panic on host kvm without update cpuid. 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: ehabkost@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" without kvm commit 412a3c41, CPUID(EAX=3D0xd,ECX=3D0).EBX always equal to 0= even through guest update xcr0, this will crash legacy guest(e.g., CentOS 6). Below is the call trace on the guest. [ 0.000000] kernel BUG at mm/bootmem.c:469! [ 0.000000] invalid opcode: 0000 [#1] SMP [ 0.000000] last sysfs file: [ 0.000000] CPU 0 [ 0.000000] Modules linked in: [ 0.000000] [ 0.000000] Pid: 0, comm: swapper Tainted: G --------------- H= 2.6.32-279#2 Red Hat KVM [ 0.000000] RIP: 0010:[] [] alloc_b= ootmem_core+0x7b/0x29e [ 0.000000] RSP: 0018:ffffffff81a01cd8 EFLAGS: 00010046 [ 0.000000] RAX: ffffffff81cb1748 RBX: ffffffff81cb1720 RCX: 00000000010= 00000 [ 0.000000] RDX: 0000000000000040 RSI: 0000000000000000 RDI: ffffffff81c= b1720 [ 0.000000] RBP: ffffffff81a01d38 R08: 0000000000000000 R09: 00000000000= 01000 [ 0.000000] R10: 02008921da802087 R11: 00000000ffff8800 R12: 00000000000= 00000 [ 0.000000] R13: 0000000000000000 R14: 0000000000000000 R15: 00000000010= 00000 [ 0.000000] FS: 0000000000000000(0000) GS:ffff880002200000(0000) knlGS:= 0000000000000000 [ 0.000000] CS: 0010 DS: 0018 ES: 0018 CR0: 0000000080050033 [ 0.000000] CR2: 0000000000000000 CR3: 0000000001a85000 CR4: 00000000001= 406b0 [ 0.000000] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 00000000000= 00000 [ 0.000000] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 00000000000= 00400 [ 0.000000] Process swapper (pid: 0, threadinfo ffffffff81a00000, task f= fffffff81a8d020) [ 0.000000] Stack: [ 0.000000] 0000000000000002 81a01dd881eaf060 000000007e5fe227 00000000= 00001001 [ 0.000000] 0000000000000040 0000000000000001 0000006cffffffff 00000= 00001000000 [ 0.000000] ffffffff81cb1720 0000000000000000 0000000000000000 00000= 00000000000 [ 0.000000] Call Trace: [ 0.000000] [] ___alloc_bootmem_nopanic+0x8d/0xca [ 0.000000] [] ___alloc_bootmem+0x11/0x39 [ 0.000000] [] __alloc_bootmem+0xb/0xd [ 0.000000] [] xsave_cntxt_init+0x249/0x2c0 [ 0.000000] [] init_thread_xstate+0x17/0x25 [ 0.000000] [] fpu_init+0x79/0xaa [ 0.000000] [] cpu_init+0x301/0x344 [ 0.000000] [] ? sort+0x155/0x230 [ 0.000000] [] trap_init+0x24e/0x25f [ 0.000000] [] start_kernel+0x21c/0x430 [ 0.000000] [] x86_64_start_reservations+0x125/0x129 [ 0.000000] [] x86_64_start_kernel+0xfa/0x109 [ 0.000000] Code: 03 48 89 f1 49 c1 e8 0c 48 0f af d0 48 c7 c6 00 a6 61 = 81 48 c7 c7 00 e5 79 81 31 c0 4c 89 74 24 08 e8 f2 d7 89 ff 4d 85 e4 75 04 = <0f> 0b eb fe 48 8b 45 c0 48 83 e8 01 48 85 45 c0 74 04 0f 0b eb Signed-off-by: Bingsong Si --- target/i386/cpu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ff65e11008..77510cdacd 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4416,7 +4416,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *ecx =3D xsave_area_size(x86_cpu_xsave_components(cpu)); *eax =3D env->features[FEAT_XSAVE_COMP_LO]; *edx =3D env->features[FEAT_XSAVE_COMP_HI]; - *ebx =3D xsave_area_size(env->xcr0); + /* + * The initial value of xcr0 and ebx =3D=3D 0, On host without= kvm + * commit 412a3c41(e.g., CentOS 6), the ebx's value always =3D= =3D 0 + * even through guest update xcr0, this will crash some legacy= guest + * (e.g., CentOS 6), So set ebx =3D=3D ecx to workaroud it. + */ + *ebx =3D kvm_enabled() ? *ecx : xsave_area_size(env->xcr0); } else if (count =3D=3D 1) { *eax =3D env->features[FEAT_XSAVE]; } else if (count < ARRAY_SIZE(x86_ext_save_areas)) { --=20 2.22.0