From patchwork Fri Jun 8 22:56:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10455301 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 E474C60318 for ; Fri, 8 Jun 2018 22:56:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D66F51FF40 for ; Fri, 8 Jun 2018 22:56:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9DDF2943D; Fri, 8 Jun 2018 22:56:55 +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 595501FF40 for ; Fri, 8 Jun 2018 22:56:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753104AbeFHW4u (ORCPT ); Fri, 8 Jun 2018 18:56:50 -0400 Received: from mail-bl2nam02on0052.outbound.protection.outlook.com ([104.47.38.52]:52759 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753026AbeFHW4q (ORCPT ); Fri, 8 Jun 2018 18:56:46 -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=seqlIV0Dc2ch7wkwEmh4Ogs5GXyjyRMpz4UZlKL6rQ0=; b=gXZeP/ds0QQDOFOS52tv6XPfqqiGSqp6BaG5L1ZfXXhH9ckLacv6tQabCi0GkCHT4ZmvPoDHuJhpbCM+nvPjCrMB6dyd2+/OxU88hvnVb1YRZP2yNfv5cuuAOqxgC4+sFYRwCZbTu6jx8nym9kkVamIONVlxZzW2aocAHOrU5IU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from linux-h3ml.amd.com (165.204.77.1) by MW2PR12MB2473.namprd12.prod.outlook.com (2603:10b6:907:9::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.841.14; Fri, 8 Jun 2018 22:56:41 +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 v13 4/5] i386: Verify and enable topoext feature if supported Date: Fri, 8 Jun 2018 18:56:20 -0400 Message-Id: <1528498581-131037-5-git-send-email-babu.moger@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1528498581-131037-1-git-send-email-babu.moger@amd.com> References: <1528498581-131037-1-git-send-email-babu.moger@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0401CA0034.namprd04.prod.outlook.com (2603:10b6:803:2a::20) To MW2PR12MB2473.namprd12.prod.outlook.com (2603:10b6:907:9::12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:MW2PR12MB2473; X-Microsoft-Exchange-Diagnostics: 1; M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IvP2c9AzipCN+gdO9ZdPR3DXibud2DphgtsyoqIp1ekudt8US9ZkxGJs9uoc7GpJ2DXeW0f5oEPb+UqFkbU2jwR0sukRSeoUu8bLR229cZGaae3li8LYy4S51mdU4n04Tivjq4rI/55JXCPZuKTCM3+EfXCNZpFC0FReMEAIo/dlnP+r0zvw7GtxxpKp3eRKeaeTxGslQgm4jqlqBlV+LPwiyjswqWwgVQczuG+wU80ZsYvBrJe2Tzv1FsUwMebgfOruJwuO3be2ASF/Xd0xvDhAPreuwQ2EW0IyMMoVWetGtoeoG9LXnOeYgZhgCNCqFwEyV7WMBEc64ave+yvOvqKi5KxAOP+6; 4:MrwLEtUOd3O0z69sYJSeaF/m60Zkqvz6pWVRO7FxmGXX/zoneh51r9xjSMOB/OX4zRHSbf4dyPjcBTY1oUq1iDNl7rz0WHl3nX3POYIo0VGD1BnR7ATBBt7Ns0TEb0hc9gk5Pa2rmdkbyj5wS1f+ibPr6cpAcZkCQlKwLUae+tOgewHYgEabFFDcfrrbysCaubaqm0RJ0E8idlzkmKZ5KXPGfSYWbqiqpnZ++Ikf3AjcMd4nnbxMqLntEWaWXS3AZ5S43VuH0XhUYlNGiZaUNYps6HlriVyHsRsUCcWMMsTo03Bc8I/XYXd8wGPhM5vM 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)(5005006)(8121501046)(3002001)(3231254)(944501410)(52105095)(10201501046)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:MW2PR12MB2473; BCL:0; PCL:0; RULEID:; SRVR:MW2PR12MB2473; X-Forefront-PRVS: 06973FFAD3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(376002)(39380400002)(396003)(39850400004)(366004)(189003)(199004)(956004)(7416002)(305945005)(6666003)(4720700003)(7736002)(53416004)(53936002)(48376002)(26005)(16526019)(105586002)(16586007)(106356001)(386003)(316002)(186003)(7696005)(52116002)(39060400002)(50226002)(51416003)(66066001)(47776003)(50466002)(446003)(8676002)(11346002)(8936002)(81166006)(81156014)(76176011)(4326008)(44832011)(486006)(2616005)(36756003)(476003)(25786009)(5660300001)(97736004)(6486002)(3846002)(6116002)(2906002)(86362001)(478600001)(68736007)(72206003); DIR:OUT; SFP:1101; SCL:1; SRVR:MW2PR12MB2473; 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; MW2PR12MB2473; 23:EWu//VL5XtYis34+hTUdEbldDSbAjLUhU9cjMnekV?= =?us-ascii?Q?z4rCiwqDUq9eDXrPpJwBD8ls2w+3zCRlCgQ1dHpNK5AvMKZCQ7SC72MGWoW9?= =?us-ascii?Q?0hZqwauR7miaK0alzHx5MKXMDra+t0PznKkHO6edfXOFjoh+g5Amg//MqjMU?= =?us-ascii?Q?TM9vOkGO6t8fUfz9QW3GwZcDUCJgEvjE3e/jtMRNlR0fJNegtsAwz2eEXQ3T?= =?us-ascii?Q?R77lb2+ty1iaWVA61CfHLpAiGYjmX4v6uBE8X53svkn0dhezeGsbXezoPk+t?= =?us-ascii?Q?i+JIS2EtvJkeRlFvdQzjMPtQntCN7vC6Xsf0gQd1N84MBf5xSwyOzq5dswTc?= =?us-ascii?Q?zCQKmCZUZM2BugPn/LlTiNEF+NYK/JXI0R4jla3KksKzlWV26S/wj10lGSwt?= =?us-ascii?Q?aT8VKtzuPWBNaNsbpFsfrt28Z57shL9fzWhWSlj4E7uDUK6rCWipPbGq2IC5?= =?us-ascii?Q?G3hMBpSkWOA2m2vGj7t35eLMiXh/Sq2rnjwDgqFp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Y0F7X4dTcZ5zmXnVnqfMoUsQkzv+eRjWzHgt50ujhDbHcIjVHRYUcNLet6y3kbWyy2HLr1GwqMrxcEVjUNx1k+Nn22LWKNfUmyf X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2473; 6:EFK+nFEwqHUl32UrOdUFdANdQ9kmkPqVkSR9zjjkEhuZrz5zVaadQ/Lsv4peHeAuFSasrIakD+3a5mJnb2SI1h7I3Pffe6fySLIrl27N6HI1k7sun43iT7PWGy/6x9P9CqeSoATINM0lhv5vjFwynVdm2Yj6R7UoHutjKLl8OCee5Nz3/gIe64e4aDWpZUbF8AdlRdAOhXq6jDrF13bRkLANbqp7BbHDZMm82vsw+6ZtUwkdODRT/YS74lKuScJF4ZnGfIp+1JCdvA2nRs9MRgH0Hue2gzXdaM2VPmSUlGqnL42PY++P7xs5605qrTPkT+lsjMetFiF2rqEFTUImb4hrPZ1NzDM23bahCfIBZXHxiBKnfHfQktcBhda2Lu+YmbnQSEOPixm/5SXuz7cMcWP2CdKkVSaAA53QextLAv6IQJu2AAp1T/9ylIOdI6GgwPODoApHi783vWvbaQ66Ag==; 5:mq6+28NjUsV4cOpC7z54zbbAyRqH3Hesa5eIZ+Mg7T74mYzslHYTLp1G5h0j42aL/cyADLhCD5HDkeRlk57pquw+okS6Wlq9/zjZW3jLrGkaDuBbzBxsRlMQvX/cFfgBq/ZX7mnSLKHHmmarizliIJsKjmDQe2Ee3qvvSMAcjaI=; 24:ipn85GF6QJBpIad110+kwnF1xON+5R851ICxog/D0c7LGBluwjkP3815tixLQNxzfQMBMcTIGswR/2vpdH5J4ek4yTdFFtH5OXG9f1n4u4Y= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2473; 7:8AynhE98VWQBz9w0vuzsNjMyYsiuRM588HKySpqeh76srYAh4XBoW1x1h8gmJV1jT3GB6tEc4zhes56jigc1q6FByhDoSAxqXpwKYgGeAoEN0cSUxq5xni2Vq09Bej89ZdHZdkoO4j0jAT7ZcCgMq/hVZX027IwLe/Uu8VbOteu65UPlPmo8Vo6J+uEBVv+ZC6Hc2KIA58uKDH+JhIaUzvJ4ZNDp1BEsYBsoSon8br+m9iBl7mqsYabDgZAB5KA8; 20:rnCNVn5pMM0GWwZ3ypHgOl/T6pOF5qSoPT9ds4mMaO7A3633oVieoe60bdiqnmzOejMwnWqJeCOrFrqUQUu3wmbauYsTLIQPS/sSCmlLBnfPhZavR4tdz2G4CP3cHqSUrSwZuqeEr76L+3n52bcdjPXG0nNCRdZGWd+h/W3b/EZnEMXRXGA49j0IKNOMF1ZJu9Q+4jskbxTtglD0h+d2uPwjCfHnGuNqr0ybyD7CZw7p7FkcjxTxqmPQavrIFGQc X-MS-Office365-Filtering-Correlation-Id: 476dda97-bb69-4002-7290-08d5cd931a40 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2018 22:56:41.7584 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 476dda97-bb69-4002-7290-08d5cd931a40 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB2473 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the CPU model supports topoext feature, enabled the feature automatically if it can be supported. Signed-off-by: Babu Moger --- target/i386/cpu.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4dd9a82..88bc73d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4763,6 +4763,33 @@ static int x86_cpu_filter_features(X86CPU *cpu) #define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \ (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \ (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3) +/* + * 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 topology_supports_topoext(int nr_cores, int nr_threads, + Error **errp) +{ + if (nr_cores > (MAX_CORES_IN_NODE * MAX_NODES_PER_SOCKET)) { + error_setg(errp, "TOPOEXT unsupported with %d cores per socket", + nr_cores); + error_append_hint(errp, "TOPOEXT supports only up to %d cores per" + " socket\n", + (MAX_CORES_IN_NODE * MAX_NODES_PER_SOCKET)); + return false; + } + + if (nr_threads > 2) { + error_setg(errp, "TOPOEXT unsupported with %d threads per core", + nr_threads); + error_append_hint(errp, "TOPOEXT supports only up to 2 threads" + " per core\n"); + return false; + } + return true; +} + static void x86_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs = CPU(dev); @@ -4953,6 +4980,19 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) qemu_init_vcpu(cs); + if (cpu->auto_topoext && + !(env->user_features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT)) { + if (cs->nr_cores <= (MAX_CORES_IN_NODE * MAX_NODES_PER_SOCKET) && + (cs->nr_threads <= 2)) { + env->features[FEAT_8000_0001_ECX] |= CPUID_EXT3_TOPOEXT; + } + } + + if ((env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT) && + !topology_supports_topoext(cs->nr_cores, cs->nr_threads, errp)) { + return; + } + /* Only Intel CPUs support hyperthreading. Even though QEMU fixes this * issue by adjusting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX * based on inputs (sockets,cores,threads), it is still better to gives