From nobody Thu May 2 18:08:44 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566514410; cv=none; d=zoho.com; s=zohoarc; b=MVF7ZMh/XG8DDcMu6YuDoc41hT6GFIG4WBMFhYgQCCVHbg+1KoI1CgRe/NK6yHKIAcT/328gFgO7thKcRyNlvI8o/PAQ8DNNgzuo+/08IhWwgbYm/ITjee9qxuEY0EnJA7uEw+rpWyJXPWsrI57yfVBKcgm9Oc4tyvxpy9t9qoA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566514410; 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=MixplU2bLh5lBfidQSg89SitAr+D3dwM8KWe/yjvWsU=; b=nEobWRjvrtfL8G8oeSfLctY70OquBuGeBqKlZ07H4wzQl5IRoffh9jezI6VwU0hhp0EMdKkx3k5EGbnPoMmwuzlrkU4l8Yb8R1aNz5vcpK5KTcLBnAQzLT4b1q3EqOqRCiLM4DW6aP//gpdBk0DWVJKqfk6CW7IqN7TJuJC2Dq8= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566514410651940.8977806761092; Thu, 22 Aug 2019 15:53:30 -0700 (PDT) Received: from localhost ([::1]:48504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0vxL-0005WW-Dx for importer@patchew.org; Thu, 22 Aug 2019 18:53:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51078) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0vwF-00057h-HA for qemu-devel@nongnu.org; Thu, 22 Aug 2019 18:52:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0vwE-0003Xb-4v for qemu-devel@nongnu.org; Thu, 22 Aug 2019 18:52:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46584) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0vwD-0003XM-W6 for qemu-devel@nongnu.org; Thu, 22 Aug 2019 18:52:14 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 173A387633; Thu, 22 Aug 2019 22:52:13 +0000 (UTC) Received: from localhost (ovpn-116-73.gru2.redhat.com [10.97.116.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D6BB600CD; Thu, 22 Aug 2019 22:52:12 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Thu, 22 Aug 2019 19:52:10 -0300 Message-Id: <20190822225210.32541-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 22 Aug 2019 22:52:13 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] i386: Omit all-zeroes entries from KVM CPUID table 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: Yumei Huang , Eduardo Habkost , kvm@vger.kernel.org, Marcelo Tosatti , Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" KVM has a 80-entry limit at KVM_SET_CPUID2. With the introduction of CPUID[0x1F], it is now possible to hit this limit with unusual CPU configurations, e.g.: $ ./x86_64-softmmu/qemu-system-x86_64 \ -smp 1,dies=3D2,maxcpus=3D2 \ -cpu EPYC,check=3Doff,enforce=3Doff \ -machine accel=3Dkvm qemu-system-x86_64: kvm_init_vcpu failed: Argument list too long This happens because QEMU adds a lot of all-zeroes CPUID entries for unused CPUID leaves. In the example above, we end up creating 48 all-zeroes CPUID entries. KVM already returns all-zeroes when emulating the CPUID instruction if an entry is missing, so the all-zeroes entries are redundant. Skip those entries. This reduces the CPUID table size by half while keeping CPUID output unchanged. Reported-by: Yumei Huang Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1741508 Signed-off-by: Eduardo Habkost Acked-by: Paolo Bonzini --- target/i386/kvm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 8023c679ea..4e3df2867d 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1529,6 +1529,13 @@ int kvm_arch_init_vcpu(CPUState *cs) c->function =3D i; c->flags =3D 0; cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); + if (!c->eax && !c->ebx && !c->ecx && !c->edx) { + /* + * KVM already returns all zeroes if a CPUID entry is miss= ing, + * so we can omit it and avoid hitting KVM's 80-entry limi= t. + */ + cpuid_i--; + } break; } } @@ -1593,6 +1600,13 @@ int kvm_arch_init_vcpu(CPUState *cs) c->function =3D i; c->flags =3D 0; cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); + if (!c->eax && !c->ebx && !c->ecx && !c->edx) { + /* + * KVM already returns all zeroes if a CPUID entry is miss= ing, + * so we can omit it and avoid hitting KVM's 80-entry limi= t. + */ + cpuid_i--; + } break; } } --=20 2.21.0