From patchwork Tue Jun 19 21:31:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10475495 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 079B76029B for ; Tue, 19 Jun 2018 21:32:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAC8928BDF for ; Tue, 19 Jun 2018 21:32:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBDBC28C8D; Tue, 19 Jun 2018 21:32:31 +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 6557328BDF for ; Tue, 19 Jun 2018 21:32:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030444AbeFSVc3 (ORCPT ); Tue, 19 Jun 2018 17:32:29 -0400 Received: from mail-sn1nam02on0042.outbound.protection.outlook.com ([104.47.36.42]:7378 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1030273AbeFSVcX (ORCPT ); Tue, 19 Jun 2018 17:32:23 -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=jR1LJUivIvmuobjR9V8AfqVQKNDqoGtRKBP47ylJSDs=; b=RQ3IKhI5dQV4k/eoDOgwxy6LPbAFBPyHD6yrqjSPmMTAFCOPT1DUQbNLlkTig57jjf91lpdo5XZgQ4KkSIjDj2FGkjVwDPzgdIPzWsI5OzwSnDBx/pk8fG6FTQNN23czn3FnbUOddhnk1wLV+UkMVcETC4BFHIARndEES+qT2Lo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from linux-h3ml.amd.com (165.204.77.1) by DM5PR12MB2469.namprd12.prod.outlook.com (2603:10b6:4:b4::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.863.16; Tue, 19 Jun 2018 21:32:13 +0000 From: Babu Moger To: mst@redhat.com, marcel.apfelbaum@gmail.com, pbonzini@redhat.com, rth@twiddle.net, ehabkost@redhat.com Cc: qemu-devel@nongnu.org, mtosatti@redhat.com, kvm@vger.kernel.org, kash@tripleback.net, geoff@hostfission.com, babu.moger@amd.com Subject: [PATCH v16 1/3] i386: Fix up the Node id for CPUID_8000_001E Date: Tue, 19 Jun 2018 17:31:57 -0400 Message-Id: <1529443919-67509-2-git-send-email-babu.moger@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1529443919-67509-1-git-send-email-babu.moger@amd.com> References: <1529443919-67509-1-git-send-email-babu.moger@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0701CA0016.namprd07.prod.outlook.com (2603:10b6:803:28::26) To DM5PR12MB2469.namprd12.prod.outlook.com (2603:10b6:4:b4::38) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1af72feb-5795-4284-6134-08d5d62c1f97 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(711020)(2017052603328)(7153060)(7193020); SRVR:DM5PR12MB2469; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB2469; 3:EjKlugjRJsHs2OskjlJZOcOWVKZJvTD9zt8ItRwjxqFexil0IyXASWQXiHCeVVLf85yB8An6Dlm3Sgt+wkx1WXJOOu8gF1JIXzuq5B54dz384FSENIdTgqqb2pecApJhFNTyvBlhtMBg2Y86uu5CGN+4TZuonaT7U257IuRHGyogxXqewSBzXqDCDd37ssoSgi/nStPaDss3mCqXGHiO7Z8Dm01U+V1l5dcRaHdRdxV5lZhgb/+n1sKvcoszNYIO; 25:mNINZdgrwEdDkXSIW97OHH+u8LvmEq2Fgrm1Pvy5Cz4l10NmDyHrLvYrmjGyHckv/czLNw7jfqIo3UynLUiYxDnBbpdKfJxw8E1XbIleJHLLnlUZwqeTI6KrarCmB/W8y3F3bFkbH7zqeASdw9UzrJTqOD0WV0fuuXWTCMaKtt6cW9IURY0b08oDtBd/jndwqZChBtTYEeJmVlbnbr+2dcc8jh//Z4dNXIQ1oRlUv63lRvmXo0aX/quyL0XlQB3rn9I/M8eyhggSk3gsQ/MnzmVNa6/OXGVc0E00/rOnHJL/OTn+xD2kfhn/F3mqbY8dgiRv8+EaLsNdten0ckSoYA==; 31:ZKeLss99/UHky+Hlt8cAz6aUkiX4DHxnweKFDOpD6S6fRkKOwZlgUEA2c34yRdoqMysHPjQpB2BERaiYKiJ5NlMrM9A/SC5ad6aUYQWw6Z70NraKlJK9/9N5d9H7vG77X/acaAC8rdYkvm3745qF8yUzfSIU+hYBIZH19AmwVIAMihd2QOzO5lNgp704WG+/H2NtXLbnuIrwjPkpeolvRZNcp5nPNV/M6qPkzkq0Cx4= X-MS-TrafficTypeDiagnostic: DM5PR12MB2469: X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB2469; 20:VTDzVe0lWp0lEzYWCVeNlHpaZPNj1nML2q3+wb+DIEJ3zMf+I4Z6WbHqQB9f6zfo16bBkw2N09UIyY1pig96Nk3zgEEP5DKrRzAy0C8WiwrrWrTnh21HcgszQwCxe6hEovZuKzpVxCKFP55iG42J3CbwvZ1iwZ8IaceoJAdidorRPNn6yrM3XxDeklkHoGf76TqIdp9nsOAhxyUj1MMtWmcS5k/I7KeGRXQNdM+JzhnWe86JcXjJ3WVThwFUV9x0FwviJ0opLODuZYIN4i4DptJERbNSEsogccZVu9uxL1+L2leZiyPxyQjm0xVhzbZUWvnRLTq/qV1ot/t1g698f8lUX7Zw2G0JCL6mE2qS3PV1Ljnes43e3E6xMrJfyV3XPfzBLH9AVCkAOy2VKTOqmXjCeiokBxeBD9jkKlPLZB/D0OSLm6uXGJs/g7A6xTucejhmdw4qnATUE6BquXt3g8EUyB82Q5Nv7c2ryRga2fgIjRPPSR8uo6I74yIJBUiW; 4:A8Vq+y0NSykGzN4UVvurVBiXr9+hQOUCHcqmItZdIJVqlzu3d5F/Y8QyaIR4CMsM8luwoz5tUZoOF4a7Pkz9K6ZRRgmK6uY+nOO0uLaE2MyEcO64xXuQyad6HdVLFXEsFPMXVRpP05Jf4KGF2NXmqEdVuI/6H6ApOtuTE5695ss+OJQmbn3a51cpiudy6pCUOusvo7Y8+5m/pNenWNhVxXzDgE16x4pH249yxK5FlwzW+EjnQ1+aQyCD3uc65ixhsAnfXaf4yWotlCdo3PCZpHzyTVG2QeXjk92m55sL9JPtpAXt5QpRnbj2M+NK1aJg 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)(10201501046)(93006095)(93001095)(3231254)(944501410)(52105095)(3002001)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:DM5PR12MB2469; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB2469; X-Forefront-PRVS: 07083FF734 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(39860400002)(366004)(396003)(376002)(346002)(189003)(199004)(106356001)(97736004)(26005)(386003)(76176011)(316002)(25786009)(4720700003)(16586007)(39060400002)(478600001)(59450400001)(6666003)(72206003)(186003)(16526019)(53936002)(66066001)(86362001)(105586002)(4326008)(48376002)(47776003)(50466002)(476003)(2616005)(5660300001)(53416004)(50226002)(7736002)(956004)(305945005)(36756003)(52116002)(2906002)(8936002)(7696005)(51416003)(81156014)(11346002)(446003)(81166006)(6486002)(486006)(7416002)(44832011)(6116002)(3846002)(68736007)(8676002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB2469; 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; DM5PR12MB2469; 23:WxIut5afwXJ4Y5S8p9L1Rm45cNSwWxmBdZO5wCOat?= =?us-ascii?Q?5Va/jvR09FbWf1pitCh3O2VaSpt/szH8pdWtrVDkD9gi5m3UmpdJudsB7+aO?= =?us-ascii?Q?RhuBU5jyyky37lAsAsA/Kkt7+cJPMWIFm1/2MCO26jByVRz9j/UsWMgh/3+9?= =?us-ascii?Q?HzsKxVwFPEnREa1/G/vm4fxkDWt0BZ/fkNbLfXRfWiWf8YBG7FDML6/i6Yos?= =?us-ascii?Q?gu27zD5QIdKZJiM8+rrFRYK4RvCH+zvMa/WKtCLM22nkd94dRZg1vl60BOIz?= =?us-ascii?Q?bMCGkNdL6nsTEE64joTJii0UAefjUWBZv+qP0qSdO6dGfO6UisFLnLhKYstC?= =?us-ascii?Q?OTIf/Rt6w2564u/nvQ1dlZhwrcOb54XATARfdIR2qME7ufRse8DTcoLtiJ6i?= =?us-ascii?Q?QxCoSLDJTx72+J/hR4WwZfgFvinF9SrQh4l/AvXDatTXI7Df761XxUO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SSl3KnkpUHgR2ecBH8arSkQpv5tqvRZtjKkH4Tt8fH6B4bvcYnnM6MN1nzA9ZZpRrGU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB2469; 7:QH0KeNCp6CjGV5C8DG3qqX0ST8QmPUYE40t6dIjt8inA4soSO1X+gyKX50RWOP74MocR5YQph0QCAMNuRytd5LU7yNQZCWq8asZOXoRoK/fKWJ6XvWckWRkxo8hiMuViAsCwH+139657PhWd/hLhfsv8xibGGRDm6+MLADsBLtubWQAVlXZs9yyD8Bl0sO1lqxphYk4RxHq6ymRUvLpoDD+qXXsZoabEllJQdBQpp77ZgxF9tUjtUEqB2H0f4x99; 20:isWC/NSYj3CX86kKncfesanFcA/TTNGFsEuDGgDDeXbai/fnOMfVZ3t2fcOmRen3Ne96s9LUmGbmvVdlHtW4tPyjnwITcol40b+PpHR5Q+FDnRwaq7FaFkBptBPhDiolSvetI6pKSlb4/qBVIqpL6aK3eSZPDTJylYDu5MUWmRDVfQ0Bmvz38FDA9+hRS07vJ57KBbOkNCQ73363YyLCNc+iCdL1yUfEgAe0EvMglmoIlaoJjPY/KXKpuxGcXXsV X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2018 21:32:13.3228 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1af72feb-5795-4284-6134-08d5d62c1f97 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2469 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is part of topoext support. To keep the compatibility, it is better we support all the combination of nr_cores and nr_threads currently supported. By allowing more nr_cores and nr_threads, we might end up with more nodes than we can actually support with the real hardware. We need to fix up the node id to make this work. We can achieve this by shifting the socket_id bits left to address more nodes. Signed-off-by: Babu Moger Reviewed-by: Eduardo Habkost --- target/i386/cpu.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 7a4484b..130391c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu/cutils.h" +#include "qemu/bitops.h" #include "cpu.h" #include "exec/exec-all.h" @@ -472,6 +473,8 @@ static void encode_topo_cpuid8000001e(CPUState *cs, X86CPU *cpu, uint32_t *ecx, uint32_t *edx) { struct core_topology topo = {0}; + unsigned long nodes; + int shift; build_core_topology(cs->nr_cores, cpu->core_id, &topo); *eax = cpu->apic_id; @@ -504,7 +507,28 @@ static void encode_topo_cpuid8000001e(CPUState *cs, X86CPU *cpu, * 2 Socket id * 1:0 Node id */ - *ecx = ((topo.num_nodes - 1) << 8) | (cpu->socket_id << 2) | topo.node_id; + if (topo.num_nodes <= 4) { + *ecx = ((topo.num_nodes - 1) << 8) | (cpu->socket_id << 2) | + topo.node_id; + } else { + /* + * Node id fix up. Actual hardware supports up to 4 nodes. But with + * more than 32 cores, we may end up with more than 4 nodes. + * Node id is a combination of socket id and node id. Only requirement + * here is that this number should be unique accross the system. + * Shift the socket id to accommodate more nodes. We dont expect both + * socket id and node id to be big number at the same time. This is not + * an ideal config but we need to to support it. Max nodes we can have + * is 32 (255/8) with 8 cores per node and 255 max cores. We only need + * 5 bits for nodes. Find the left most set bit to represent the total + * number of nodes. find_last_bit returns last set bit(0 based). Left + * shift(+1) the socket id to represent all the nodes. + */ + nodes = topo.num_nodes - 1; + shift = find_last_bit(&nodes, 8); + *ecx = ((topo.num_nodes - 1) << 8) | (cpu->socket_id << (shift + 1)) | + topo.node_id; + } *edx = 0; }