From patchwork Fri Jun 8 22:56:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10455295 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 4938260318 for ; Fri, 8 Jun 2018 22:56:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C6601FF40 for ; Fri, 8 Jun 2018 22:56:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30A102943D; Fri, 8 Jun 2018 22:56:47 +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 9CFD429439 for ; Fri, 8 Jun 2018 22:56:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752974AbeFHW4o (ORCPT ); Fri, 8 Jun 2018 18:56:44 -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 S1752774AbeFHW4m (ORCPT ); Fri, 8 Jun 2018 18:56:42 -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=aovYtRZzVTFw14prY0pRWoKsMuvXFCY6cTeHmkPt/+OQ077upyvHZeJTGlKedkhS7pwsNfd1TBfq4Z4DtuVUzbo290+aBGSEIOeFETSRGXQx+fFizZ2yIdRUmIbK2RTXQSxxex9SjD6rIhL/uaFR+bxZEXUeDZQsDE8gNoxtp4o= 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:37 +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 1/5] i386: Add support for CPUID_8000_001E for AMD Date: Fri, 8 Jun 2018 18:56:17 -0400 Message-Id: <1528498581-131037-2-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; MW2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tMV7UzPnUArV1q3Zj/nW4n3R3rs1U7X/iT+++CaGnA3EmBfsFVrehrfE6TXiRxxaE5jo7MWGW++z334mSAULFtlDpvXr6hdqe9ayqW9OOysUFJNXtDWWbsDtvaHxARkuJbguCa8YIvbc7tKZB+sgK8jk1ogq72yEG3jU+bviP8Z2+Oa7pfzTb76V5FgCgOGMHwNo9xZnLtYuQmj7sOTrzSF2okpBmUlPUShA2uBKgrOq4Ko1u6JOQK1493R7xMQHtJFaZvAJCezYkWI7SRlwF4yOLMZ9CEYHT9rcLEpK07VPTkmqo6yOQOOkfpi0nmz1XDseAIb2fEtTC/iv1xy+N1UyN; 4:KpY/lD9zdrjlkNpVuz1yBknQQnY783UqUndbD+fK92y1xjCtfna6R//Fj1sAkWxcR+B9UC2BL8hpzhxp9UgKRoNTCgXPCpsG2aleysetW2o8orgM7UL9B6N67yTFMsheZPTMZwi4zkmh8s9NLyxLt7HCru/+q2T8KeYP7Jcr3jrMXbJOVmehoK9tMWelJ/1mo2e1THLoROvcluqtJq2BzFgc3KgJ79WuI1E8glu0cOI0Q9fAAo1zBb2q0pqtL+fGcRsJlr59mZgMMxXr1gwyqutc8zay3XQ5JQYhUO5O4nRDVKKa8V6IqSTA2aic2g1z 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:KEy5A2tW5Lz/xicSk9cI0TkLEXH3bD5qRhq8+dWAY?= =?us-ascii?Q?gCB9SYKyzSANx+6vEOUt3NNCbIwwQHdlMEwtirkiCu5HWtVNkEAQ+u2LrAPi?= =?us-ascii?Q?AW6qriGwoE+d83z4cAmGdll1LziSsQmg2ELH1AsrQDtICIUpWlZNLVUeUnOc?= =?us-ascii?Q?Kq1PtdZ2FqMs4kfbOhWzvURa2BcR8QIsDo38t5LwiUPSJ72DYeTjUMRSKMgz?= =?us-ascii?Q?ath60q5jnsFYPO9x9+4ccmO+XtPgcy+FhgpyRk3NU9roXqBhd3EhA82j4KFu?= =?us-ascii?Q?lqDo319DQPkn9wvq0P3tQJzVXr0n17Ty1hb9ojqhnW+sPNCOdBzcw0LGTfwY?= =?us-ascii?Q?VkV2FGVVqdT0qu7MPmaHaTR4sY2R5u42h52/19mtziCr+IsR4ECPgND9dsGY?= =?us-ascii?Q?2I2uCVwwSKrsIGkHX5gj/ctKMGztxOTcPLpyfQqze08ODMfZt8PdH+i/eu/G?= =?us-ascii?Q?ohcIOZNEZPzSuYlBVkq6/6WDALTfnU4Hbl59fxHJsbdgCyTi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HuHKcTMx8iPBJprRDKabtQ+mYJtVZslkAp9VMS4I54aId7P3YjJgRZDA0Gq9WM2XNeGYMEu53W3POwIgr/uwc4hMLEUPMY5xzGrFYdYbPmZN/wJ/vlR7tpJ9pxCBEqQJhf9Ps9BHQGSqrRzjLGsfDhwCKBQN; 20:HkvoYxGVl822BJ185czPjFJ0Bo7LhcGRIOse+UtFXVR47ZEKWhNMiG08WrghKMg8GeZHu0GCQuxxBNYA8qZUWWtI6BR34u+REgvqazwKmE1NmrRIvjI40q2bG5GFNS3k03HzSDCBktXtYb59+4zRwzAA08LhPT3/l8z/IHrEKQekiCLcZVrbXMlmKHJwDBZIJFS+sxQL7/9hz0P9C/1RqzjtygKUkUP5+oeFxmAlk+WH3tPSak+wJQzGHh6EvLkd X-MS-Office365-Filtering-Correlation-Id: ab95a4c7-7f88-451b-05a0-08d5cd9317e1 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2018 22:56:37.7806 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab95a4c7-7f88-451b-05a0-08d5cd9317e1 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 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;