From nobody Tue Nov 26 20:19:36 2024 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; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1704237828; cv=pass; d=zohomail.com; s=zohoarc; b=YwBqORyCNrkzh8v7K5K211nzk6IsPGhzaBrT4FYmS35CjDB7d861WYBJBQye2a3I0gze2nlvbkxH1J8Tle2YZFLrbPPLrVvpaqi5vCdguDiGcfYk+VXd9/nwliHYPTXXC0AvbJkFaQ6LKyp6+SH4wjlHuzOV47+H1o5a6JMXLQQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704237828; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WynkN7U2JmduBf8YTYAa+Wx7B0uuUTbhGBXJc1kBmUc=; b=d8pcaDzf6XHJ7trUs5ItGkmw59Y48RBY6BGQoTIPX8J8MB1CaojxMDSLJLx3wGT9J1qbcsGbTlcd1OK+Yf39h8NAgwysmojRtNZjekx5XqkzyXunaLEkhkxqKlvfSMRctyidsPozUvrXQ3WLL3HK1SoEXo9N2NO+GpgfPoIHBdU= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=amd.com); 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 1704237828564549.2487799959744; Tue, 2 Jan 2024 15:23:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rKo6D-00010a-Tb; Tue, 02 Jan 2024 18:23:05 -0500 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 1rKo6B-00010K-V2 for qemu-devel@nongnu.org; Tue, 02 Jan 2024 18:23:03 -0500 Received: from mail-bn8nam04on2087.outbound.protection.outlook.com ([40.107.100.87] helo=NAM04-BN8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rKo69-0003ch-5Y for qemu-devel@nongnu.org; Tue, 02 Jan 2024 18:23:03 -0500 Received: from DS7PR03CA0017.namprd03.prod.outlook.com (2603:10b6:5:3b8::22) by IA1PR12MB8222.namprd12.prod.outlook.com (2603:10b6:208:3f2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.13; Tue, 2 Jan 2024 23:17:55 +0000 Received: from DS1PEPF00017099.namprd05.prod.outlook.com (2603:10b6:5:3b8:cafe::d) by DS7PR03CA0017.outlook.office365.com (2603:10b6:5:3b8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.25 via Frontend Transport; Tue, 2 Jan 2024 23:17:55 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF00017099.mail.protection.outlook.com (10.167.18.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7159.9 via Frontend Transport; Tue, 2 Jan 2024 23:17:55 +0000 Received: from bmoger-ubuntu.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Tue, 2 Jan 2024 17:17:54 -0600 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yfhc/zOK33h/lCCpUSwA+UahsUivuNpge+Bc02+eAGuNFsGkebxyuYyzlR2N6GwlyKGoecrGJ3Ad5afNS6F35XKewSbO3Tua/QVfb6YToSc6VzXEmSyIv3+2ua476oLubBnKFOTta81OXqtbI1Ze7RIlJmADm3I0ZOEsI8KGpoiVRjB1MDVzJk64YsfOTJYvHIU5/RzoFS/e7y1nseDocz6SKXw3nparDOoYXfCSLo45IoZT9vjEwWvPmyjdJpgBSNTKDyvGuw351rqQFkcyyW4CY7z0vnh2B9srlpSeDqRzr8ZGFRx6cYI81a7vdwfyww8DVWSQITqeQVcd4N8mfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WynkN7U2JmduBf8YTYAa+Wx7B0uuUTbhGBXJc1kBmUc=; b=maydPzkIx4FGc/2q++e9ksT8HkUY1/9NULGM03epBD971znLgQFoDJgRMpHxBXTsN/+nysja4vs/bVaclW0nhukZ2IBfQyJQYxJP9ZXxN8290eft3RIRJrjY3s7pAXIovckeq2WDTfIC1YcTTgKrM84eXgfiw+y1p0ds9l+Pbg1bgJ3aA7zhqTFfiCo7SxPmpE5dsD2flaJR7f7BdL2Ex3XpmqzeVDwEL/WAEkMr0fTCTXAfblHB0Ef7/i5FNb09fGGPQlDeg49wOumwa/FKzFOUHoCRUE4tVk557hGr5bmVSGCmRDaS5+D0y4rxmoJjFp9jCt3O3WrDcWwMUYH0Qw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WynkN7U2JmduBf8YTYAa+Wx7B0uuUTbhGBXJc1kBmUc=; b=ch71h+Fw/IL8vuZiYoTMoSPhexcp8yeRQu/Uw3AhepA924Y1LmKQepZKsOIoqDhhGt2/wZpZEcKPy9jiJDNDZ2E781gfomyrZ9JhZlx7ThPsD78DDA8T2FtqtVCikS6r00vZKQLAAoIPBJO4kEYgvguBMFwj4GvuX6hMjYQ0GZg= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; 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 (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Babu Moger To: , CC: , , , , , , , , , , , , , , , , , Subject: [PATCH v2] target/i386: Fix CPUID encoding of Fn8000001E_ECX Date: Tue, 2 Jan 2024 17:17:38 -0600 Message-ID: <20240102231738.46553-1-babu.moger@amd.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017099:EE_|IA1PR12MB8222:EE_ X-MS-Office365-Filtering-Correlation-Id: 7e87214f-5b09-4b35-daa0-08dc0be90d00 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WPnmAwBOHhdn04eGPevDrw2QlJgk5wkZmnGzBL5U3w3vgQfalLCSnvj/6vK4hsHys5a+40cS1eCRZ/nyO5SbLWR8dz+zEcnUANFZCdF+ou42KBGEtDH0PgXARgBVeTFWo81NzBtDFRpzIsAJk2JSypbJKwYugbjfk7w/GDcbpePv5bFMEXg4efGTUcensB77g9bu8U+N7H3BxG5QaWUXQX+ruAQ2NKg+YheL3X/srzEWvYJm8HgNxdvuyj1jKT5RWhP8hP/mjqw+9VeDjr7BN+Cl7KtyZP18BrbUKU7TSRHlxXzcbVdef4o7vXAzMRUzQIcjuUAft12P55J1Tqwmpctf2VKZmMz1ryPVoCQGuSPqTiKjJClJyMfDLEIEZBEpoFQu22cLsweXjPzcuSPaGcFIG1WGunvzycEGvcQynTySQwt+/sXINjwiCNBmP+U8neiL7ZHBSSK9k3Zys0oJVoaGtjXFRj/tByt1I/JZkkXxT7lWdKkwnjQR8VLM88ULkviml9T5IkAG+XQ/CxlSq4+dhiW8nX2KCQdr9X+jHqOwXCEv0bYhwV6crpadg/DAdrkMPizaXBLt8Q8/r9RlTobU7i7SeF+icW2aWIZEdbaw2VCbOV63eEGRqChsepF6PEH0EIqbmB+pcUC6M47qwtbLekBZyTFUrq5qKq8fMuGJLiTsuAYJ9WCRU07rGlzNX6SmO5GtAPNi5/Yjv7oPFSowuGugkfh264ohnQ3yMg5FciNTQ3vVoRiqL9sRXiQkAauGVAOUAm70iOAN5LEN9g== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(346002)(39860400002)(136003)(376002)(396003)(230922051799003)(186009)(64100799003)(82310400011)(451199024)(1800799012)(46966006)(40470700004)(36840700001)(36756003)(40480700001)(40460700003)(70206006)(70586007)(86362001)(336012)(16526019)(81166007)(356005)(82740400003)(1076003)(5660300002)(26005)(47076005)(41300700001)(83380400001)(2616005)(2906002)(6666004)(426003)(44832011)(7416002)(478600001)(7696005)(4326008)(966005)(110136005)(8936002)(54906003)(316002)(36860700001)(8676002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jan 2024 23:17:55.2431 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7e87214f-5b09-4b35-daa0-08dc0be90d00 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017099.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8222 Received-SPF: softfail client-ip=40.107.100.87; envelope-from=Babu.Moger@amd.com; helo=NAM04-BN8-obe.outbound.protection.outlook.com X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.178, 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_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @amd.com) X-ZM-MESSAGEID: 1704237829638100001 Content-Type: text/plain; charset="utf-8" Observed the following failure while booting the SEV-SNP guest and the guest fails to boot with the smp parameters: "-smp 192,sockets=3D1,dies=3D12,cores=3D8,threads=3D2". qemu-system-x86_64: sev_snp_launch_update: SNP_LAUNCH_UPDATE ret=3D-5 fw_er= ror=3D22 'Invalid parameter' qemu-system-x86_64: SEV-SNP: CPUID validation failed for function 0x8000001= e, index: 0x0. provided: eax:0x00000000, ebx: 0x00000100, ecx: 0x00000b00, edx: 0x00000000 expected: eax:0x00000000, ebx: 0x00000100, ecx: 0x00000300, edx: 0x00000000 qemu-system-x86_64: SEV-SNP: failed update CPUID page Reason for the failure is due to overflowing of bits used for "Node per processor" in CPUID Fn8000001E_ECX. This field's width is 3 bits wide and can hold maximum value 0x7. With dies=3D12 (0xB), it overflows and spills over into the reserved bits. In the case of SEV-SNP, this causes CPUID enforcement failure and guest fails to boot. The PPR documentation for CPUID_Fn8000001E_ECX [Node Identifiers] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Bits Description 31:11 Reserved. 10:8 NodesPerProcessor: Node per processor. Read-only. ValidValues: Value Description 0h 1 node per processor. 7h-1h Reserved. 7:0 NodeId: Node ID. Read-only. Reset: Fixed,XXh. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D As in the spec, the valid value for "node per processor" is 0 and rest are reserved. Looking back at the history of decoding of CPUID_Fn8000001E_ECX, noticed that there were cases where "node per processor" can be more than 1. It is valid only for pre-F17h (pre-EPYC) architectures. For EPYC or later CPUs, the linux kernel does not use this information to build the L3 topology. Also noted that the CPUID Function 0x8000001E_ECX is available only when TOPOEXT feature is enabled. This feature is enabled only for EPYC(F17h) or later processors. So, previous generation of processors do not not enumerate 0x8000001E_ECX leaf. There could be some corner cases where the older guests could enable the TOPOEXT feature by running with -cpu host, in which case legacy guests might notice the topology change. To address those cases introduced a new CPU property "legacy-multi-node". It will be true for older machine types to maintain compatibility. By default, it will be false, so new decoding will be used going forward. The documentation is taken from Preliminary Processor Programming Reference (PPR) for AMD Family 19h Model 11h, Revision B1 Processors 55901 Rev 0.25 - Oct 6, 2022. Cc: qemu-stable@nongnu.org Fixes: 31ada106d891 ("Simplify CPUID_8000_001E for AMD") Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D206537 Signed-off-by: Babu Moger Reviewed-by: Zhao Liu --- v2: Rebased to the latest tree. Updated the pc_compat_8_2 for the new flag. Added the comment for new property legacy_multi_node. Added Reviwed-by from Zhao. --- hw/i386/pc.c | 4 +++- target/i386/cpu.c | 18 ++++++++++-------- target/i386/cpu.h | 6 ++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 496498df3a..a504e05e62 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -78,7 +78,9 @@ { "qemu64-" TYPE_X86_CPU, "model-id", "QEMU Virtual CPU version " v, }= ,\ { "athlon-" TYPE_X86_CPU, "model-id", "QEMU Virtual CPU version " v, }, =20 -GlobalProperty pc_compat_8_2[] =3D {}; +GlobalProperty pc_compat_8_2[] =3D { + { TYPE_X86_CPU, "legacy-multi-node", "on" }, +}; const size_t pc_compat_8_2_len =3D G_N_ELEMENTS(pc_compat_8_2); =20 GlobalProperty pc_compat_8_1[] =3D {}; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 95d5f16cd5..2cc84e8500 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -398,12 +398,9 @@ static void encode_topo_cpuid8000001e(X86CPU *cpu, X86= CPUTopoInfo *topo_info, * 31:11 Reserved. * 10:8 NodesPerProcessor: Node per processor. Read-only. Reset: XXXb. * ValidValues: - * Value Description - * 000b 1 node per processor. - * 001b 2 nodes per processor. - * 010b Reserved. - * 011b 4 nodes per processor. - * 111b-100b Reserved. + * Value Description + * 0h 1 node per processor. + * 7h-1h Reserved. * 7:0 NodeId: Node ID. Read-only. Reset: XXh. * * NOTE: Hardware reserves 3 bits for number of nodes per processor. @@ -412,8 +409,12 @@ static void encode_topo_cpuid8000001e(X86CPU *cpu, X86= CPUTopoInfo *topo_info, * NodeId is combination of node and socket_id which is already decoded * in apic_id. Just use it by shifting. */ - *ecx =3D ((topo_info->dies_per_pkg - 1) << 8) | - ((cpu->apic_id >> apicid_die_offset(topo_info)) & 0xFF); + if (cpu->legacy_multi_node) { + *ecx =3D ((topo_info->dies_per_pkg - 1) << 8) | + ((cpu->apic_id >> apicid_die_offset(topo_info)) & 0xFF); + } else { + *ecx =3D (cpu->apic_id >> apicid_pkg_offset(topo_info)) & 0xFF; + } =20 *edx =3D 0; } @@ -7895,6 +7896,7 @@ static Property x86_cpu_properties[] =3D { * own cache information (see x86_cpu_load_def()). */ DEFINE_PROP_BOOL("legacy-cache", X86CPU, legacy_cache, true), + DEFINE_PROP_BOOL("legacy-multi-node", X86CPU, legacy_multi_node, false= ), DEFINE_PROP_BOOL("xen-vapic", X86CPU, xen_vapic, false), =20 /* diff --git a/target/i386/cpu.h b/target/i386/cpu.h index ef987f344c..6ef4396fc5 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1989,6 +1989,12 @@ struct ArchCPU { */ bool legacy_cache; =20 + /* Compatibility bits for old machine types. + * If true decode the CPUID Function 0x8000001E_ECX to support multiple + * nodes per processor + */ + bool legacy_multi_node; + /* Compatibility bits for old machine types: */ bool enable_cpuid_0xb; =20 --=20 2.34.1