From patchwork Thu May 24 15:43:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10425033 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0855560327 for ; Thu, 24 May 2018 15:44:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6746296AD for ; Thu, 24 May 2018 15:44:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB0FE296D5; Thu, 24 May 2018 15:44:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26AC6296AD for ; Thu, 24 May 2018 15:44:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968419AbeEXPoL (ORCPT ); Thu, 24 May 2018 11:44:11 -0400 Received: from mail-bl2nam02on0059.outbound.protection.outlook.com ([104.47.38.59]:26944 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S968188AbeEXPoC (ORCPT ); Thu, 24 May 2018 11:44:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dUQ9MgbnqPznGvXYthuIgrEQzY0fc8igTA6VURO/D5s=; b=O8PWCE//0tfzz16W14XK5I5VniWyrn1OI3O77pzopN9Qzo78FsKuucTzCyra/LfacutYW3N/lRaDJ5+as3PrM3p4uqHb35Q9Pc3ZRuufH4SUCsmr3LZuBZgqipJqUajxMbn40SCvdG1uTcbp03Woz0AQBi+sLl/CSPMF5UOUCD8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from linux-h3ml.amd.com (165.204.77.1) by DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.797.11; Thu, 24 May 2018 15:43:50 +0000 From: Babu Moger To: mst@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, ehabkost@redhat.com, mtosatti@redhat.com Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, babu.moger@amd.com, kash@tripleback.net, geoff@hostfission.com Subject: [PATCH v11 4/5] i386: Enable TOPOEXT feature on AMD EPYC CPU Date: Thu, 24 May 2018 11:43:33 -0400 Message-Id: <1527176614-26271-5-git-send-email-babu.moger@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1527176614-26271-1-git-send-email-babu.moger@amd.com> References: <1527176614-26271-1-git-send-email-babu.moger@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0501CA0024.namprd05.prod.outlook.com (2603:10b6:803:40::37) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:DM5PR12MB2471; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB2471; 3:QXp1MgE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otql2jxmapdVJhn8nI4lsZyT8UH6k3IuNiO2Pf1s9wArB2bp3xYAoW7cdHV/xtcL+0t0brfTdeIWvI08z9wf65jTQqZsYCD4qgnJ0xf3hCpOwkiXWtGsUxPvlmdjrf+7u6yqtHpcmYRWYwjWnNiL/RYNMUjs6/Cetxgmzw8JomJvb38sjKV3hSzjpfca0HB4/OEpKocBfY1wHgjDt+J5JUcynRtDtmO8LDcwMvinxAXTImKL/LPz8DQkqUicJte9lLD6UIV9cWddH22vOvykQLExrUHPhZhgvLKuHw+Xo5VS5EIcuEaALYhOSicOofsSvlaWigt3yr7FrFIxuA/+1IH5XbNoXgo; 4:3IZJ0EvE8XbXk7mcQu50/BvIX+NEIazjpa1zw1zir/79imfoIUnzinb2Bg7idgpf+RHI/zGUM2iQeYBE+ZBoDStFlmRNpPKXx67e0/GhXhBOzbElnUS/Rjs14+4gLSMRDhpACKglcmhRRITIybDmKBzMtpbT/Fs8iBZ6gswMi+lfDXIAlL53d7Ea3RxvSTqAxYfJEgX6vFL/Fpr61KJjddud1R2vzHDgvuu1N2qf0p+8cjpPJ6Int2Np5Y3V+EVVeEtz5J3rOSaWQQN5v0v+rOwhW7z6PsqYbU2/3wrmihc7F8V820x5cLSEZzgEmm7n X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:DM5PR12MB2471; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB2471; X-Forefront-PRVS: 0682FC00E8 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39380400002)(366004)(39860400002)(396003)(376002)(189003)(199004)(5660300001)(53416004)(6666003)(2616005)(446003)(11346002)(956004)(476003)(59450400001)(486006)(44832011)(16586007)(7416002)(4326008)(25786009)(478600001)(53936002)(39060400002)(26005)(47776003)(316002)(186003)(16526019)(386003)(575784001)(86362001)(7696005)(51416003)(52116002)(66066001)(68736007)(76176011)(97736004)(2906002)(50466002)(3846002)(6116002)(72206003)(4720700003)(7736002)(6486002)(305945005)(36756003)(48376002)(50226002)(8676002)(8936002)(81166006)(81156014)(105586002)(106356001)(217873001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB2471; H:linux-h3ml.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR12MB2471; 23:xzZmMwHbkisGT7o9uvPH2Zz7edL+SaUNIrm+6I2sq?= =?us-ascii?Q?FboAVO3yx0ywpY2Xc3d++eIXCN2KkGADoyhm+ST40PBM9Ho7DUp57ZKYjADk?= =?us-ascii?Q?7FzBUSucyOiU/CShsOnkOTNIn03fOjNcSWFUZTM1WXDpcyEEto+ZoD1Jv0/W?= =?us-ascii?Q?QZL2QoGX2vsBSvWlthVKM3LRqTCxP55xiIgQ6KKDJgzNw9BAVik+hquBArVV?= =?us-ascii?Q?kYRpPmlvIM15nTs5FWT6pIePwQ/BaVAQJZzv6RoNI7GY+I2Wyi7oUMiAHTPa?= =?us-ascii?Q?j+A9WMWV0IMLAM88IYxydyecrakKlQ/Dd8hfHV0S1ZkL9qPwBent+8wyJRDS?= =?us-ascii?Q?cfRgdFH7LBNUw0gq9fwPyxZ6ZCW22WjuEZAf+HRMYt+h7oFZEDj40GVNLYzc?= =?us-ascii?Q?5C45OEB5OmhBwGgZDX1/JnPiUuS8tY8txWvVsnrBK2LfboIB3qd5oTtFNXbM?= =?us-ascii?Q?+XF5WqVZNniqoYtXnrC34JYh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q=3D=3D?= X-Microsoft-Antispam-Message-Info: HlOw2vmLx/iyiKq7hB0/M8O6VHyBHznmpatKMyCliz0DvnHp39MvCbIKYJn0B1jhRybN96cleMu/+YLZ7HDhjsrssvFRCrpZh6q78lRaMCcsg2ppqllt1BakLBen4T/WrLxd2RbSd7ucaBzkM04uJV+Qs70SSPcNjtybxQsNVkPf1euV3vLbcDNDdQOo+QfK X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB2471; 6:ODWh6znFOeVGNUptI5us1VNSAeEaLecKUb6tG2YoQ4SlPvcVf1Z707wCOkP5qt7nd8+hSobGyVv1u+AHCRMFbNnBkmeYTPy7wO9VdfBFcttyiYc+ulEzGFg5KYtrx9bj45uXoF37FXrLgvyHPj9JkRu/YM0lkUQdGfUTLIjmje5S+GsVdpwmNsoAJg2eLYN60v2K/izFIGA3i4Md/Yp+iJFPV3i89qBMpEKN5QGxRvf1I0ijhlbIbB1YdlQCROIvBmV1fCBDqADZ/UCqaik4wT7S9azyxmga2LIcVZtFZ5EeZnBICypAAJ3afIoqh6odLcf6hTO0Dhqxk8UE4F+ysBGuEur5aNp5J5JHnJYWcgHG82R+ozmHSFQm4X4gH/cTI4gLcYgeYiHdsSZ89GtnQGfOGxNugARumu8D6pU+KEue2DU1ap89xLDG4A2xwD0dQVY1odzrrDzwg3v3rwcqwQ==; 5:0qc+ea5Jz2GEyAn7x2F4wY1M86jmQ/eakqa72V/PAo9sv3e5AOqHecSJlX7ts/YzT+P/cFYE+8j77IyQVYgharAqdfYiaHiq/Exbr3MBkIlgrtVpo3zs+Nh0oi8c1+jB53e8yJgSFyN4j8caRjtL3Ic679MOaOQ2JZRDATWXsUQ=; 24:83aE6hTnm1bV7hXuQVDOfUbxQafMtgIuNc1Pc9trDESa7+V7c3AWwYqrBrfRwEB7vWDS8ovcW/WWDbt8hcLwdzUzvYPhhLYE9wDSqloh3A0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB2471; 7:V08H71Dlt500sRQ3qv2xpaeR2xmeeP7T3UMIfX0DQWGrpC5cjJP4EknSR1QSIQPTfBQ//wAGk/1zGimCn83GC9kQg/Vp9+DywSBHqh/S1Q5zjmOkTHeQq0c6hSulyRVHCOE147OWr+cpwDTAipKuW2c50fIrQnOGNdCr/mR3cO/PZXjcCs4GylvVqx4Ik6JB1SX177HGxFCw4qXEB70/lKQqzpFhek81JTEUmBLtxE+0v4yfYSRGcgGxVONZP+48; 20:xAY9aTWeVDF6NBEKLpOzTh3yF5C6ZyXF5+uv0Yr69qv1yksxOsZ6Aa/7+M3wJMAliPUL/M/mFJ+WYW62N63eeOatQW2eu+fdrDObEV1pud/Xb3idk5bhRzwe3RZcSqbmhZ2+uaUgNsUQm6aomlpwWyF9k8skY51zlwgVZolp2z6kHp6+tYDMgvmeClqieDjjDf6XtHUmMJe9Ulsuvul7RxJtB3OdJjxRmxvDGhum+F86jdzvn11V86f2qqaRiOcC X-MS-Office365-Filtering-Correlation-Id: f50070b0-55c8-4a68-830c-08d5c18d25ad X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2018 15:43:50.2908 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f50070b0-55c8-4a68-830c-08d5c18d25ad X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2471 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Enable TOPOEXT feature on EPYC CPU. This is required to support hyperthreading on VM guests. Also extend xlevel to 0x8000001E. Disable TOPOEXT feature for legacy machines and also disable TOPOEXT feature if the config cannot be supported. Signed-off-by: Babu Moger --- include/hw/i386/pc.h | 4 ++++ target/i386/cpu.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index a0c269f..9c8db3d 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -302,6 +302,10 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); .driver = TYPE_X86_CPU,\ .property = "legacy-cache",\ .value = "on",\ + },{\ + .driver = "EPYC-" TYPE_X86_CPU,\ + .property = "topoext",\ + .value = "off",\ }, #define PC_COMPAT_2_11 \ diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 9f8bad9..0b62356 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -486,6 +486,20 @@ static void encode_topo_cpuid8000001e(CPUState *cs, X86CPU *cpu, } /* + * Check if we can support this topology + * Fail if number of cores are beyond the supported config + * or nr_threads is more than 2 + */ +static int verify_topology(int nr_cores, int nr_threads) +{ + if ((nr_cores > (MAX_CORES_IN_NODE * MAX_NODES_PER_SOCKET)) || + (nr_threads > 2)) { + return 0; + } + return 1; +} + +/* * Definitions of the hardcoded cache entries we expose: * These are legacy cache values. If there is a need to change any * of these values please use builtin_x86_defs @@ -2531,7 +2545,8 @@ static X86CPUDefinition builtin_x86_defs[] = { .features[FEAT_8000_0001_ECX] = CPUID_EXT3_OSVW | CPUID_EXT3_3DNOWPREFETCH | CPUID_EXT3_MISALIGNSSE | CPUID_EXT3_SSE4A | CPUID_EXT3_ABM | - CPUID_EXT3_CR8LEG | CPUID_EXT3_SVM | CPUID_EXT3_LAHF_LM, + CPUID_EXT3_CR8LEG | CPUID_EXT3_SVM | CPUID_EXT3_LAHF_LM | + CPUID_EXT3_TOPOEXT, .features[FEAT_7_0_EBX] = CPUID_7_0_EBX_FSGSBASE | CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_AVX2 | CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_RDSEED | @@ -2576,7 +2591,8 @@ static X86CPUDefinition builtin_x86_defs[] = { .features[FEAT_8000_0001_ECX] = CPUID_EXT3_OSVW | CPUID_EXT3_3DNOWPREFETCH | CPUID_EXT3_MISALIGNSSE | CPUID_EXT3_SSE4A | CPUID_EXT3_ABM | - CPUID_EXT3_CR8LEG | CPUID_EXT3_SVM | CPUID_EXT3_LAHF_LM, + CPUID_EXT3_CR8LEG | CPUID_EXT3_SVM | CPUID_EXT3_LAHF_LM | + CPUID_EXT3_TOPOEXT, .features[FEAT_8000_0008_EBX] = CPUID_8000_0008_EBX_IBPB, .features[FEAT_7_0_EBX] = @@ -4156,6 +4172,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, break; case 0x8000001D: *eax = 0; + /* Check if we can support this topology */ + if (!verify_topology(cs->nr_cores, cs->nr_threads)) { + /* Disable topology extention */ + env->features[FEAT_8000_0001_ECX] &= !CPUID_EXT3_TOPOEXT; + break; + } switch (count) { case 0: /* L1 dcache info */ encode_cache_cpuid8000001d(env->cache_info_amd.l1d_cache, cs, @@ -4180,6 +4202,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, break; case 0x8000001E: assert(cpu->core_id <= 255); + /* Check if we can support this topology */ + if (!verify_topology(cs->nr_cores, cs->nr_threads)) { + /* Disable topology extention */ + env->features[FEAT_8000_0001_ECX] &= !CPUID_EXT3_TOPOEXT; + break; + } encode_topo_cpuid8000001e(cs, cpu, eax, ebx, ecx, edx); break; @@ -4644,6 +4672,11 @@ static void x86_cpu_expand_features(X86CPU *cpu, Error **errp) x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000000A); } + /* TOPOEXT feature requires 0x8000001E */ + if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT) { + x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000001E); + } + /* SEV requires CPUID[0x8000001F] */ if (sev_enabled()) { x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000001F);