From patchwork Wed Jun 6 14:36:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10450329 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 3213760234 for ; Wed, 6 Jun 2018 14:37:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21F5128F4A for ; Wed, 6 Jun 2018 14:37:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1630129575; Wed, 6 Jun 2018 14:37:07 +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 A702528F4A for ; Wed, 6 Jun 2018 14:37:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752155AbeFFOhC (ORCPT ); Wed, 6 Jun 2018 10:37:02 -0400 Received: from mail-bl2nam02on0057.outbound.protection.outlook.com ([104.47.38.57]:49407 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752114AbeFFOhA (ORCPT ); Wed, 6 Jun 2018 10:37:00 -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=7DRAiQkTbxUQ9S7Z8lVbl092MtmrJlwApwbSVC+pnYA=; b=0bjpB/y7bw6t6TZg78tF3CNuQkKh41RJ3A46XE09ZmsRfPl+KGyq4VXhsiDWfkY8oqCmUmQGxamsoWEpWuPMCAbdm7sNfV9CIRgl60H8GUnyYCuIejegrXhtmyYkLBEPcS1dHlLQTzfLRoCfg0IyLZzgDUe5pPhyvBIlrNLIRV0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from linux-h3ml.amd.com (165.204.77.1) by MW2PR12MB2476.namprd12.prod.outlook.com (2603:10b6:907:9::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.820.15; Wed, 6 Jun 2018 14:36:56 +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 v12 1/4] i386: Add support for CPUID_8000_001E for AMD Date: Wed, 6 Jun 2018 10:36:43 -0400 Message-Id: <1528295806-90593-2-git-send-email-babu.moger@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1528295806-90593-1-git-send-email-babu.moger@amd.com> References: <1528295806-90593-1-git-send-email-babu.moger@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0501CA0082.namprd05.prod.outlook.com (2603:10b6:803:22::20) To MW2PR12MB2476.namprd12.prod.outlook.com (2603:10b6:907:9::15) 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:MW2PR12MB2476; X-Microsoft-Exchange-Diagnostics: 1; MW2PR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xu+Ogzm8w558pGzHZvmVL8CThG3fug9d3BSP6+c1nRkeZbrrhW7osqJuVBC7tLXDiMFUzEwBf7/dOziAsk2xIzFZPjkwqYbX/bT0c8Xl5ICOq1sP8aMIDhiZJNl7ihryFxDSkXrWkj7HcbOuLa8JPZp7wl+CO5Z13QxoECJmgiYEPpvKrKzVWMZo24uEOc06/16eVQu2HfWm4wKxdYeaEPtUbv3nWzATZ3pjy56hvnvk/kuKTsMS8CDPWKLtQvCXKFYrIEZ1hcfBku780L5WNNG4iI9Cjd6N8dub7r9iI8FDJj6CJewPJSsKg9pheEkvQoaw8YsThcESqJnlGFn2KPkd; 4:OoLlvKHjFRwS3zScAC6vmowJRyNVaPrWeCbgQFQmdAy0nGTh/fSeOOMvBRvfnucRHYpAmDP+qeSfjRjyMHLSvTzAjhumWvuOV7H/zJ849OYORJkuR9xbDos6/oUOSEczcuzKzQRRgF6s4vi9rN4S6CstzP7D6Q4WA/crdd/eDw3UJqV1wy4VWBH+7jH5rD0IpXHuXS8ot4tZWuuuv8lwgq7ouyZ1l6vuzJ57K8oEcdiTZqrwVdV7tJD+Da6/C8Il2MVDdcDKHenPSbaAMBCm94D7tpwqwL9MTr2TdzUupuH3jTCBXoFnbsjsBZOovMc9 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)(10201501046)(93006095)(93001095)(3002001)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:MW2PR12MB2476; BCL:0; PCL:0; RULEID:; SRVR:MW2PR12MB2476; X-Forefront-PRVS: 06952FC175 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(346002)(396003)(39860400002)(39380400002)(366004)(189003)(199004)(4720700003)(97736004)(26005)(50466002)(4326008)(39060400002)(7416002)(25786009)(3846002)(72206003)(6116002)(52116002)(47776003)(7696005)(386003)(478600001)(76176011)(66066001)(51416003)(5660300001)(81166006)(2906002)(446003)(11346002)(305945005)(8936002)(86362001)(6666003)(81156014)(16526019)(8676002)(53416004)(186003)(956004)(7736002)(44832011)(486006)(476003)(316002)(68736007)(36756003)(48376002)(105586002)(50226002)(16586007)(6486002)(106356001)(2616005)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:MW2PR12MB2476; 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; MW2PR12MB2476; 23:krvnpD/abfOiFUB1h0lNGze8lKPDPgveCRI/atSLk?= =?us-ascii?Q?oGBqvlAPZ3aHqP/4Nd0jfeiS2xIjrgX3LSGS54rdvx/1ka9stUJ6A25COC3G?= =?us-ascii?Q?IHAGsCxgwVuoGcXWLt7AkgL5+REGblW6qGZnBMq5/jPJkgjVqPRyj9cEFkOg?= =?us-ascii?Q?L1Z7HOa981kuh5dVwUmE7Ywxh66bEZS9fiRTLUHL3/J6KsLJ/nRTDHgfXarf?= =?us-ascii?Q?0APl5b0aZDMSodUxpfEmJNXyyANyFyHtna9YZ2eCrXY244m0GbkOYOH9EXBF?= =?us-ascii?Q?Z2V2zS0cL3EtZNEVhch+PYaJIgUNuXTcn4RbztaLVpsUaooSaXLSV6aB/HhY?= =?us-ascii?Q?mVukAvCahEBoUiL++2/WzUtHTJNX8t+MZ/KOhNuKpuzCN3O9Ghv2IanOSiCy?= =?us-ascii?Q?xvzI/QpwFZrZp/a8o3vz3D19fHMVjOutEcH9JsI6MXAmp3PAdZQgLMcdc5xi?= =?us-ascii?Q?++erOgoqLWP3nA6ElfrM/qBT1PVUK7E4vkmXGo3SzDCJWCqV3hxUDVpuvA+8?= =?us-ascii?Q?32c2LBFLQZhWHoMYrcZ4osxYe6bPZRWyvKMZ95r13ph1BS4hDaYS2D35lZYq?= =?us-ascii?Q?r38fVf7bdNFhMwzOtiTem/Lv/WB/WHDmNRPz+ak2XkqCaDyfSKxVpIhNcmU8?= =?us-ascii?Q?m5pCY4qZ0P3mfSJJ4ox7JteNbUHoVhPR1HNjC3XkJgGYXLzKdEPSqKarBo8f?= =?us-ascii?Q?e5Akyx1M/xjJHqWAe9zb7x0KWRf7lvMnWbAfhTonErRTfjx8WxuBOVdErAc6?= =?us-ascii?Q?X7fUusPpf7o3g3unnK44AXcAnAVGp+p9HrH/Yy89flOMtejR+EIqTOY3cwOP?= =?us-ascii?Q?pD/MLjxPZfY0hckPZyhTBIKe/hKmhEUHamLdp3boGdiaLuLAuXb9uFtzcATR?= =?us-ascii?Q?HWia1QjTSzpyfQGvkH7bjpxy9qG4eS7ZLb81Od2jCE77+WM9m8hdB94w1fJg?= =?us-ascii?Q?vD3yy/XCqeUBzJzbsryNkuUhOIhcncmoA31p+17+Pk8NSreG7AEPfUjK7btK?= =?us-ascii?Q?E25m/YeJX1rOo/oALDe1RSDccC4M8uoKGIdr0Bv9viHLatTlhyeBNoFy04za?= =?us-ascii?Q?CNlzOXjnvVIih9JZgR91q/1OKoO+i75yQ27qTu7giSvceTpIZ2toylhssDYS?= =?us-ascii?Q?qGquFlOpJllqJA3AyvA24wAzJgZ3US4Dmynq5F7d1+eq40Ri9yJZPKIkA+k3?= =?us-ascii?Q?A9CTfZDaXwtwDaMw52HjAb+lQlI4W5eVg1B/FYzuuS5cuhK6qTzjwWByrOqB?= =?us-ascii?Q?UMV2IlBKhRFPnGeOQkRU2wQ3ypbbD94OBx0HYXp?= X-Microsoft-Antispam-Message-Info: PCiWynsR1w593a90VUe9i1FUfYLs6JoY0YPEggAvaazBpImE4DE0fRHIbPyWV5WkjGLOkbK76zG40KnIt1mLf6Q+l7O07BajhVKCKqDy5ejydbIGw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M9MP8VlkS7SMGNrwD0WFkMSr0+bbgaaDnxUJ2GwV16luyEDHISEMTmeMZu47nDdz6JVjpIREKqnfH52p/xKAgJmxHneHAcGfUD3X5VBy3g1TgJOIUyMK6jRub8Rw82bIS3Mnc8WhY; 20:rTyHgsD3PUUyMb8pLv4wEKsARxF0PD1VZwwGwnsjeQ/r7+qAd8NJlZBdtIh0xjEwD3nDjNTR1mu4smOhfjcvND8gjl/sB1OQudoEDIBVNoNTwOh3pG3h+31wL84+jyc7VSzqP5rzOcEPcc3bhVbvWxvmK93Xw5XuK2v4njiaA+5jNU4TCT/3+Vi9jiR4qhbAgHdRLvMnMLNinOu3Eae8xvCMwvO+JIhVQMo+Gn6CoNbcdU1Bre+zWedX9aa7cKUJ X-MS-Office365-Filtering-Correlation-Id: 7c5dac3d-c4ed-4ab5-3128-08d5cbbaf4d4 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2018 14:36:56.2352 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7c5dac3d-c4ed-4ab5-3128-08d5cbbaf4d4 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB2476 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for cpuid leaf CPUID_8000_001E. Build the config that closely match the underlying hardware. Please refer to the Processor Programming Reference (PPR) for AMD Family 17h Model for more details. Signed-off-by: Babu Moger --- target/i386/cpu.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 1e69e68..86fb1a4 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -427,6 +427,87 @@ static void encode_cache_cpuid8000001d(CPUCacheInfo *cache, CPUState *cs, (cache->complex_indexing ? CACHE_COMPLEX_IDX : 0); } +/* Data structure to hold the configuration info for a given core index */ +struct core_topology { + /* core complex id of the current core index */ + int ccx_id; + /* + * Adjusted core index for this core in the topology + * This can be 0,1,2,3 with max 4 cores in a core complex + */ + int core_id; + /* Node id for this core index */ + int node_id; + /* Number of nodes in this config */ + int num_nodes; +}; + +/* + * Build the configuration closely match the EPYC hardware. Using the EPYC + * hardware configuration values (MAX_CCX, MAX_CORES_IN_CCX, MAX_CORES_IN_NODE) + * right now. This could change in future. + * nr_cores : Total number of cores in the config + * core_id : Core index of the current CPU + * topo : Data structure to hold all the config info for this core index + */ +static void build_core_topology(int nr_cores, int core_id, + struct core_topology *topo) +{ + int nodes, cores_in_ccx; + + /* First get the number of nodes required */ + nodes = nodes_in_socket(nr_cores); + + cores_in_ccx = cores_in_core_complex(nr_cores); + + topo->node_id = core_id / (cores_in_ccx * MAX_CCX); + topo->ccx_id = (core_id % (cores_in_ccx * MAX_CCX)) / cores_in_ccx; + topo->core_id = core_id % cores_in_ccx; + topo->num_nodes = nodes; +} + +/* Encode cache info for CPUID[8000001E] */ +static void encode_topo_cpuid8000001e(CPUState *cs, X86CPU *cpu, + uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) +{ + struct core_topology topo = {0}; + + build_core_topology(cs->nr_cores, cpu->core_id, &topo); + *eax = cpu->apic_id; + /* + * CPUID_Fn8000001E_EBX + * 31:16 Reserved + * 15:8 Threads per core (The number of threads per core is + * Threads per core + 1) + * 7:0 Core id (see bit decoding below) + * SMT: + * 4:3 node id + * 2 Core complex id + * 1:0 Core id + * Non SMT: + * 5:4 node id + * 3 Core complex id + * 1:0 Core id + */ + if (cs->nr_threads - 1) { + *ebx = ((cs->nr_threads - 1) << 8) | (topo.node_id << 3) | + (topo.ccx_id << 2) | topo.core_id; + } else { + *ebx = (topo.node_id << 4) | (topo.ccx_id << 3) | topo.core_id; + } + /* + * CPUID_Fn8000001E_ECX + * 31:11 Reserved + * 10:8 Nodes per processor (Nodes per processor is number of nodes + 1) + * 7:0 Node id (see bit decoding below) + * 2 Socket id + * 1:0 Node id + */ + *ecx = ((topo.num_nodes - 1) << 8) | (cpu->socket_id << 2) | topo.node_id; + *edx = 0; +} + /* * Definitions of the hardcoded cache entries we expose: * These are legacy cache values. If there is a need to change any @@ -4120,6 +4201,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, break; } break; + case 0x8000001E: + assert(cpu->core_id <= 255); + encode_topo_cpuid8000001e(cs, cpu, + eax, ebx, ecx, edx); + break; case 0xC0000000: *eax = env->cpuid_xlevel2; *ebx = 0;