From nobody Sat Nov 15 12:47:44 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752493017; cv=none; d=zohomail.com; s=zohoarc; b=e5x8bPkW3g0WKfErVNyzMVZvJyAW93mhwtbyUSzncJXbuoFhVWNQRqm5d376yNn1RE45UTd2rKhKAINom4h6ZuUAdGY7DJWOqz+PeNJ613z+/Jqqu4f9ZXgCnA/l+tIYd0paE+j5Y4eC1HVMeSlyuqs48PikSrAgO2eT2HalFk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752493017; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GSC6MhPny2SkCa7TrS1WIVTnb/rmAA/k5Ngtv+6fNHE=; b=K4mHOM9f/bw6xLhHYBjgIvtoLeWbtpEcUbAUqq/Wyj4S2LSStXnCP/IeIul35XAyCsOfpcWAxGzhBaM37m3c7sEEmdyYijYbtkAPIlBMrvpS5pqf/3Ol//INWgTPWz+cJCrAHdpB3CMB+GJKQXN7lIroOVtvJyQ7sGbhFw7MmG4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752493017387306.304511790107; Mon, 14 Jul 2025 04:36:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubHEO-0007Cm-8m; Mon, 14 Jul 2025 07:20:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH11-0001in-5P for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubH0s-00026P-Rh for qemu-devel@nongnu.org; Mon, 14 Jul 2025 07:06:29 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-76-ysrjcmqvO3e1xg46t3hN3Q-1; Mon, 14 Jul 2025 07:06:20 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4561a196f70so4839705e9.1 for ; Mon, 14 Jul 2025 04:06:19 -0700 (PDT) Received: from [192.168.10.48] ([151.49.73.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45613c2d84dsm45545515e9.5.2025.07.14.04.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 04:06:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752491184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GSC6MhPny2SkCa7TrS1WIVTnb/rmAA/k5Ngtv+6fNHE=; b=eK1po8i6QpcX18ckJLdPz4w4hSKQH6c20ghbFrUwOfGPAWAfupMu80IodAtOPXg0PXZXOS bRPKHRkKgBLR8ZxoIPTAAKwrxxrCAwbndv0N6hKn8ez7gbGEvg3FAfmaWwQrRhuV+2uN3X 8P37UD7g/PNeaIeV76XKtY6019rB5bk= X-MC-Unique: ysrjcmqvO3e1xg46t3hN3Q-1 X-Mimecast-MFC-AGG-ID: ysrjcmqvO3e1xg46t3hN3Q_1752491178 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752491177; x=1753095977; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GSC6MhPny2SkCa7TrS1WIVTnb/rmAA/k5Ngtv+6fNHE=; b=FXNP6p7SEPuguEBYTgROouZh9BTyj4hYEQMmooNi2emRWCN8q+kUbR/6h+vFEPyOqI pwZvLlVhBI/SIBizr2ElzqK7TCL8ZPpBW207+leXOfuu4q6t8TCFD91g7nhdBwcNmjrV j0wd7VVNR8MDFi5aLvZaqjT41b3SXkhsB6ocJeU84HXShBOi1A38W0VqWnG8mJod4mfS irPPuKaMYNVmkPSJ2e3iW7ypaRp0cnKFMpp1Avu78J26GftyyKR8san5LuG6TGMGRZvN TuShi1InzS+LSTBYxaD0BCseD54BN+KSQGK/5s/xOWzuML9LWArh6LuppHlum2rDRar7 nhYw== X-Gm-Message-State: AOJu0Yx7yFkoQ4XZ9d1xJX9Wgo9bF2u7II0uajXojOG8n+9GyDc4QjaN R/yg6V9HdJ0zCL3QQbJf9Pz1jFxK85r1OgGE6m/eWNmrqkSwjU4oc4aXG0jUAezj6Az+m/LN/gp 7luhmrNK3rIaUuk4FdwV2IMEID197dQuC+1lBn+Qf7KiiRjBhNJt2pSBkEV0XmGzYLYwxXZ1LVe 1CU6jdn7L/hlFX5wGCGdOHhpyVdXxSHDtXtpFfRPgU X-Gm-Gg: ASbGncuIIeDUFaAEA7l0PFBxh29gAoV9cnLORBZMGy/CFX4kC2qxsPOK7Jnr3HyxfBT UeIGQk3eF8tfiScbOIZw3TmGzI9GJBS4Tv2OVuJhdvT+6KPrJBRKyYn2V5pgSLCYgYAOu4d5Kr9 cYy0lgn/DkW+aI4hZDB6mqXXOxdOUjLkIoIlKNpPvcATd0AkqI/ySdcxfJgvCrJ7yYiu8J03uGB qdcLGJvjGSGAem+iedqdIibdB3CIxgSkcWMcaS62pLS0ImDYpQ3FN99Gwb1kTHjs0pO8rySTv7k JbMc3awe1Zn2M9PySztXA1t8OFjx4/O21M9m3A9FDtI= X-Received: by 2002:a05:600c:c0c1:b0:453:84a:8cf1 with SMTP id 5b1f17b1804b1-45576aab8a3mr76235725e9.33.1752491177130; Mon, 14 Jul 2025 04:06:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZhdZw6QvFPipKgiclRUgJCtpW3ES2Ctlo2UUOorliEWEfdM/2KvJu6PhJjAEec3UBxHNY7Q== X-Received: by 2002:a05:600c:c0c1:b0:453:84a:8cf1 with SMTP id 5b1f17b1804b1-45576aab8a3mr76235485e9.33.1752491176571; Mon, 14 Jul 2025 04:06:16 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zhao Liu , Yi Lai Subject: [PULL 49/77] i386/cpu: Fix CPUID[0x80000006] for Intel CPU Date: Mon, 14 Jul 2025 13:03:38 +0200 Message-ID: <20250714110406.117772-50-pbonzini@redhat.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250714110406.117772-1-pbonzini@redhat.com> References: <20250714110406.117772-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752493017828116600 Content-Type: text/plain; charset="utf-8" From: Zhao Liu Per SDM, Intel supports CPUID[0x80000006]. But only L2 information is encoded in ECX (note that L2 associativity field encodings rules consistent with AMD are used), all other fields are reserved. Therefore, make the following changes to CPUID[0x80000006]: * Check the vendor in CPUID[0x80000006] and just encode L2 to ECX for Intel. * Drop the lines_per_tag assertion, since AMD supports this field but Intel doesn't. And this field can be easily checked via cpuid tool in Guest. * Apply the encoding change of Intel for Zhaoxin as well [1]. This fix also resolves the FIXME of legacy_l2_cache_amd: /*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */ In addition, per AMD's APM, update the comment of CPUID[0x80000006]. [1]: https://lore.kernel.org/qemu-devel/c522ebb5-04d5-49c6-9ad8-d755b899898= 8@zhaoxin.com/ Tested-by: Yi Lai Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20250711102143.1622339-11-zhao1.liu@intel.c= om Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 8a97272b4a4..6a0e8592bbe 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -531,16 +531,15 @@ static void encode_cache_cpuid80000006(CPUCacheInfo *= l2, { assert(l2->size % 1024 =3D=3D 0); assert(l2->associativity > 0); - assert(l2->lines_per_tag > 0); assert(l2->line_size > 0); *ecx =3D ((l2->size / 1024) << 16) | (X86_ENC_ASSOC(l2->associativity) << 12) | (l2->lines_per_tag << 8) | (l2->line_size); =20 + /* For Intel, EDX is reserved. */ if (l3) { assert(l3->size % (512 * 1024) =3D=3D 0); assert(l3->associativity > 0); - assert(l3->lines_per_tag > 0); assert(l3->line_size > 0); *edx =3D ((l3->size / (512 * 1024)) << 18) | (X86_ENC_ASSOC(l3->associativity) << 12) | @@ -712,7 +711,6 @@ static CPUCacheInfo legacy_l2_cache =3D { .share_level =3D CPU_TOPOLOGY_LEVEL_CORE, }; =20 -/*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */ static CPUCacheInfo legacy_l2_cache_amd =3D { .type =3D UNIFIED_CACHE, .level =3D 2, @@ -7900,11 +7898,20 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index= , uint32_t count, *edx =3D encode_cache_cpuid80000005(env->cache_info_amd.l1i_cache); break; case 0x80000006: - /* cache info (L2 cache) */ + /* cache info (L2 cache/TLB/L3 cache) */ if (cpu->cache_info_passthrough) { x86_cpu_get_cache_cpuid(index, 0, eax, ebx, ecx, edx); break; } + + if (cpu->vendor_cpuid_only_v2 && + (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) { + *eax =3D *ebx =3D 0; + encode_cache_cpuid80000006(env->cache_info_cpuid4.l2_cache, + NULL, ecx, edx); + break; + } + *eax =3D (X86_ENC_ASSOC(L2_DTLB_2M_ASSOC) << 28) | (L2_DTLB_2M_ENTRIES << 16) | (X86_ENC_ASSOC(L2_ITLB_2M_ASSOC) << 12) | @@ -7913,6 +7920,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, = uint32_t count, (L2_DTLB_4K_ENTRIES << 16) | (X86_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | (L2_ITLB_4K_ENTRIES); + encode_cache_cpuid80000006(env->cache_info_amd.l2_cache, cpu->enable_l3_cache ? env->cache_info_amd.l3_cache : NULL, --=20 2.50.0