From patchwork Mon Mar 12 21:00:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10277477 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 7BAF560211 for ; Mon, 12 Mar 2018 21:01:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CBE6286EE for ; Mon, 12 Mar 2018 21:01:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6112728B59; Mon, 12 Mar 2018 21:01:12 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 9647E286EE for ; Mon, 12 Mar 2018 21:01:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932548AbeCLVBJ (ORCPT ); Mon, 12 Mar 2018 17:01:09 -0400 Received: from mail-co1nam03on0067.outbound.protection.outlook.com ([104.47.40.67]:26368 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932302AbeCLVBH (ORCPT ); Mon, 12 Mar 2018 17:01:07 -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; bh=09ho2Eguwu0d3WQSnpvViAhA3wZCAjasBADFX7Z27Ts=; b=OV5ZWIAGGwh6T1wmh9DlJsOUsdaLYLt7OrFqa32z6Q6/60ohWVhIFfxrGlnPPyt1rvCKS01X2anTuuLY7H0oSuS0g1KSLfSbsDmlSt2jjZZAACpNV7FtRbcEjZ9SA4q5OV8MY08M4bkIPqZe2Rzr627lhQ/tmd9mPb9VAIZypJM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from linux-pyp0.amd.com (165.204.77.1) by MWHPR12MB1774.namprd12.prod.outlook.com (2603:10b6:300:112::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.567.14; Mon, 12 Mar 2018 21:01:04 +0000 From: Babu Moger To: pbonzini@redhat.com, rth@twiddle.net, ehabkost@redhat.com, rkrcmar@redhat.com Cc: mtosatti@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, Gary.Hook@amd.com, Thomas.Lendacky@amd.com, brijesh.singh@amd.com, babu.moger@amd.com, kash@tripleback.net Subject: [PATCH v4 2/5] target/i386: Populate AMD Processor Cache Information Date: Mon, 12 Mar 2018 17:00:46 -0400 Message-Id: <1520888449-4352-3-git-send-email-babu.moger@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1520888449-4352-1-git-send-email-babu.moger@amd.com> References: <1520888449-4352-1-git-send-email-babu.moger@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: BN6PR1201CA0019.namprd12.prod.outlook.com (2603:10b6:405:4c::29) To MWHPR12MB1774.namprd12.prod.outlook.com (2603:10b6:300:112::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f381d8fc-7074-4092-7233-08d5885c5f3e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:MWHPR12MB1774; X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1774; 3:yatI9cC/8qWHZraT48WdYWx/JvtwNCk8P8jr4kSbqoTv8DdOaQafi64uQKdx0SIE+SE/oaFaXu+j95BUhcr+m/NfD7NP3KT5liegLHpe2J5/nmtHCBEOm2PFBZ6SfA25b2tW5BPZP63C/8C7182II1Wjw3RwAWZXoWkhAOb8TimswqISlNkSoLMHM+5uSQ80waRpiGCHWX3ku4Dt8fKqp+hLjFng9dSZUS+HU1nnixm2jB5V66nCtJzpf6BUiPi9; 25:6IPuZdW7s+cdqY+d3xf0UxcwqKoVSZMAWf+yesjoEfT6IG7YuZ1y+l8tQ/ogJYztyCcX/l6IRmiH9GkmKLzNRmqLvjriLsxhRY2NBipZTAHn3pV1yRdqidsJtNCwV3cKPCKJ9ObZzzrV2QKdkMsQHCTgHFv/hjSMSJQ4KC+dix1zZJ6mnPNQTpx5npGCvNuF2qOd9gbjtOiIMi9BiGn2DxWrZ+hmUdi04mVmfLJXtsIHBYS7aPUzZCVYF8L69oeS2Xo0wDv22JS9Sc1cbhoMHLr2BwXvcvP8TZ4SINM158Ahg0V7VQxCHymxOllh/RPCKH2K7no06NgzbzeT5eqGbw==; 31:RFXek2KBZX8yGhpn4pdnuBro6VFsSDBcIPZGqHxgc+Na6lQpxDlSNTUnqLdUPcH81nFk858RUl54FZz0YdZcdINYLmB/e8aPcDEyqRyAo/2mohmZFDCgOMM//EUD9tZfuP8a2Mq6SAJsiNSB/8C5l1JtvP/ARydQnT49j7/OUuDdhrmnEspv8NJAIwdQNkzXk1fF13/xf4Aka2nxX9x3slnLfwthbH7WnexcmZ7xedg= X-MS-TrafficTypeDiagnostic: MWHPR12MB1774: X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1774; 20:877gRElorbW9tW0uQzZXE5KmmA3t9+eyvMoEcAGJzbQSLEe40I7JelIlA4irhzcJD5r1G8JL+NKKosBUwjo3bGdA87prUgvVZfGUAXB9Co+Bg3JaeV/E05wvEeTl+JYFIwBhbt83a/tuN0XCkP8zcwTkT6yzvQLqwVbiVlZFXVEHUYGOl30R3JOr/8w2k4UJf1CcWGOlMKOW0DJq6SSnpLfn344pA9VKoEEOPhK9vkPj88QaDuen5TFwj5/no3bn5+zjssFcX/KSIcz7F1EGNKxDTR6tekoEwwVQ47/XqwS4dN17oofprd+BNVwGupAZdMCFKxNzBx6BxujfLEFpZaS6ENr31du5vUvS3B79OFWd/V8f2YtAx1zTU3I3skbQ6Lq/OGIX+LLImGDA0yVdcv8/izo9HvJ7ky/LKjtzbajpig7Y8qBZSAbDElGcBOfkT4sVxjHPrls1liyo7p8fcQ72wTw9Mr7loKQ86rmlAwiXLlyIDqm3F4RQXDldYAUc; 4:tEWkqh5BAMWbFZ4DubvxL4v3RBLQyMwfBSOt1TP6EddncuKtKCckX0EF2H6FON5qr/BRU8qt5wHrZ1kvZok1ZKT/tE8/p0S4kHpsxGCW+n/lkT3anSycZyNEVQL1rzQSP73NE2/CPzcOesqq5yOVmHUk7nQ2wh0IFLZ2px/exx+zKqNfWGXZ7vVN6DMG1tF3f8u8+JvFxrAd54B0uVfzaUNq5XSnhMb+xX6YRbzHRFNB8Bu1hvdrXpVcmyUVKzwR4KZr3p5PVTc1OP3gkkeIgR3aHOIa+XePOIWzJPZpojyFxHNZICoub/kO+MOTgUMU X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501244)(52105095)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041310)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(6072148)(201708071742011); SRVR:MWHPR12MB1774; BCL:0; PCL:0; RULEID:; SRVR:MWHPR12MB1774; X-Forefront-PRVS: 06098A2863 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(376002)(366004)(39860400002)(39380400002)(346002)(199004)(189003)(6486002)(66066001)(8676002)(81156014)(76176011)(50466002)(316002)(47776003)(4720700003)(6666003)(50226002)(6116002)(8936002)(106356001)(2906002)(2950100002)(3846002)(48376002)(16586007)(25786009)(53936002)(81166006)(7696005)(4326008)(386003)(51416003)(52116002)(478600001)(72206003)(186003)(97736004)(5660300001)(68736007)(26005)(7736002)(305945005)(105586002)(16526019)(36756003)(86362001)(53416004); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR12MB1774; H:linux-pyp0.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR12MB1774; 23:U5CnULbE8ugB+UlZIfw4WAWk/GC2PEKbOXQCVb24u?= =?us-ascii?Q?nCEGBQfNmiegRfXCH+O8LTnnHAmIRl9skJNS8gejO4kLKaLIb5zCHgC1vwLQ?= =?us-ascii?Q?eNPG90Nlt3a2ebO8+h+3Ma0WeUU0EHWtWbEZCuVbC4xk3/JhezJ/oorZnMTP?= =?us-ascii?Q?3pkNSffho7/GJC0aSRdKxrjwAwnVBGQ8wktRapPW60B189QMkC6eEoEd4g2O?= =?us-ascii?Q?O6BedZC6Gx/ns2UgNJw1fuVjwCeCF8vo/c2F7Kp+fyd/rrj10ADEplG1WfHY?= =?us-ascii?Q?W1KhDFKjaMdpdsJvwdVoc1Efgd173JW8XYlyZE8uje1pLasPprWzfqnwD+B+?= =?us-ascii?Q?QTuCss4xTcLcEA2W3AfqcNPNcGXWD4kynJSXCqwVj210s3UG+49v5PBQmDeS?= =?us-ascii?Q?2kaV1AbKMAfe9zTcoDFb7XPciI30wLy/lkqZOBGwFOX7+GTtu3DAfbGfvtKY?= =?us-ascii?Q?bEs2agWbcHQK0sHur8HrGz5GUR/hWVlrlvWXEVe/r4dYOU7GJPDX/r/z/gl0?= =?us-ascii?Q?7fbEK5KXxNg2RB0z5R+n/GM/AhAsoSAHdqs19N1cqWd8Obg/O2Xmna0rUZMY?= =?us-ascii?Q?C5Sm8LMxs4lb1XvB2VDAIwY9KUvGrRWrGXaCmNq08T+berEJufp8SY/F9Bii?= =?us-ascii?Q?0dVVUwMZ9SpOujFmE9imx1ZW1W5jomFQflNRvYFMKcaIcx5DeY7S2dTxVnKZ?= =?us-ascii?Q?otngnnKGXAIt3YaR43DOJVZ/WdrRfXIMxJQ4zeKSc+GTLRVsutHUkbN+TeT/?= =?us-ascii?Q?cD72jVK/qg39O3lahqS70BcQShCDCFBu5RmH+p1yzsDzASG/47lv2OyuYSIV?= =?us-ascii?Q?ONxTNUuYSVsAuhmwWi9TZUFzKaywIa9DuAv4xIDSLoRzw98CODUFhTZxIxJn?= =?us-ascii?Q?y1+0XC81pCUu3Bmny1ARSAEj8f6Qp0EFiPXXTSmQOpwDXWDIETuqYAxyHvf3?= =?us-ascii?Q?1K8KS7Cxvz0khx2QvzR8RKUlUxUL8a6l1BIs8yqRfPgwbv6uC3t9yILsMSKJ?= =?us-ascii?Q?Qd1wqoyAz7Y7DhAhRRXdmUEdUX+VyMP9iXkyeRdgtJHiKlcJKI/Emck3tDXu?= =?us-ascii?Q?yHL+6FdI8HxVSANCGIPbAFn3eydI9hVoXyZyvvUBE0DqRxA+0K56adANmzvL?= =?us-ascii?Q?orEbW6Oq/Bz/2osXlgJjSuoLV6LdaqZ?= X-Microsoft-Antispam-Message-Info: 054svuWEFb8rEusBooL+BVc4ibOfL3dOj1Fd2s0IqMAgJl/zNwoj0FHszXPM4pEbNewieX8+dyEj8PD2oFCxwAnZfcvbY/kylps2THzCQj9wheZQyubGwW+b8PR2vmzvZMUmTNy5xGRlh2z07faFsVKE6ltGot18rwh25Zkwe9YYGcPTZIR3aNGFYdVpRNaX X-Microsoft-Exchange-Diagnostics: 1; MWHPR12MB1774; 6:Olli/iceGOfF1w5QTflSgkH3hElQcaqFxJ2Bjl2bcrVs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9tthw2k7R5Qv/zpZZIjxgrrD4oUeyQ5tMvN0N5htOXKCKxIqezMye3U3tl+2BhhHU5nzcHCSRegNlXhVpXx6vJMhzV4zn4HMJ88Qv80xkl/aWzRYd8LaB0zxYnv X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2018 21:01:04.2059 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f381d8fc-7074-4092-7233-08d5885c5f3e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1774 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Stanislav Lanci Add information for cpuid 0x8000001D leaf. Populate cache topology information for different cache types(Data Cache, Instruction Cache, L2 and L3) supported by 0x8000001D leaf. Please refer Processor Programming Reference (PPR) for AMD Family 17h Model for more details. Signed-off-by: Stanislav Lanci Signed-off-by: Babu Moger --- target/i386/cpu.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ target/i386/kvm.c | 29 ++++++++++++++++++++++--- 2 files changed, 91 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 42dd381..5fdbedd 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -118,6 +118,7 @@ #define L1I_LINE_SIZE 64 #define L1I_ASSOCIATIVITY 8 #define L1I_SETS 64 +#define L1I_SETS_AMD 256 #define L1I_PARTITIONS 1 /* Size = LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS = 32KiB */ #define L1I_DESCRIPTOR CPUID_2_L1I_32KB_8WAY_64B @@ -129,7 +130,9 @@ /* Level 2 unified cache: */ #define L2_LINE_SIZE 64 #define L2_ASSOCIATIVITY 16 +#define L2_ASSOCIATIVITY_AMD 8 #define L2_SETS 4096 +#define L2_SETS_AMD 1024 #define L2_PARTITIONS 1 /* Size = LINE_SIZE*ASSOCIATIVITY*SETS*PARTITIONS = 4MiB */ /*FIXME: CPUID leaf 2 descriptor is inconsistent with CPUID leaf 4 */ @@ -146,6 +149,7 @@ #define L3_N_LINE_SIZE 64 #define L3_N_ASSOCIATIVITY 16 #define L3_N_SETS 16384 +#define L3_N_SETS_AMD 8192 #define L3_N_PARTITIONS 1 #define L3_N_DESCRIPTOR CPUID_2_L3_16MB_16WAY_64B #define L3_N_LINES_PER_TAG 1 @@ -3590,6 +3594,67 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, *edx = 0; } break; + case 0x8000001D: /* AMD TOPOEXT cache info */ + switch (count) { + case 0: /* L1 dcache info */ + *eax |= TYPE_DCACHE | \ + CACHE_LEVEL(1) | \ + CACHE_SELF_INIT_LEVEL | \ + ((cs->nr_threads - 1) << 14); + *ebx = (L1D_LINE_SIZE - 1) | \ + ((L1D_PARTITIONS - 1) << 12) | \ + ((L1D_ASSOCIATIVITY - 1) << 22); + *ecx = L1D_SETS - 1; + *edx = 0; + break; + case 1: /* L1 icache info */ + *eax |= TYPE_ICACHE | \ + CACHE_LEVEL(1) | \ + CACHE_SELF_INIT_LEVEL | \ + ((cs->nr_threads - 1) << 14); + *ebx = (L1I_LINE_SIZE - 1) | \ + ((L1I_PARTITIONS - 1) << 12) | \ + ((L1I_ASSOCIATIVITY_AMD - 1) << 22); + *ecx = L1I_SETS_AMD - 1; + *edx = 0; + break; + case 2: /* L2 cache info */ + *eax |= TYPE_UNIFIED | \ + CACHE_LEVEL(2) | \ + CACHE_SELF_INIT_LEVEL | \ + ((cs->nr_threads - 1) << 14); + *ebx = (L2_LINE_SIZE - 1) | \ + ((L2_PARTITIONS - 1) << 12) | \ + ((L2_ASSOCIATIVITY_AMD - 1) << 22); + *ecx = L2_SETS_AMD - 1; + *edx = CACHE_INCLUSIVE; + break; + case 3: /* L3 cache info */ + if (cpu->enable_l3_cache) { + *eax |= TYPE_UNIFIED | \ + CACHE_LEVEL(3) | \ + CACHE_SELF_INIT_LEVEL | \ + ((cs->nr_cores * cs->nr_threads - 1) << 14); + *ebx = (L3_N_LINE_SIZE - 1) | \ + ((L3_N_PARTITIONS - 1) << 12) | \ + ((L3_N_ASSOCIATIVITY - 1) << 22); + *ecx = L3_N_SETS_AMD - 1; + *edx = CACHE_NO_INVD_SHARING; + } else { + *eax = 0; + *ebx = 0; + *ecx = 0; + *edx = 0; + } + break; + default: /* end of info */ + *eax = 0; + *ebx = 0; + *ecx = 0; + *edx = 0; + break; + } + break; case 0xC0000000: *eax = env->cpuid_xlevel2; *ebx = 0; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index ad4b159..0eb39b52 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -909,9 +909,32 @@ int kvm_arch_init_vcpu(CPUState *cs) } c = &cpuid_data.entries[cpuid_i++]; - c->function = i; - c->flags = 0; - cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); + switch (i) { + case 0x8000001d: + /* Query for all AMD cache information leaves */ + for (j = 0; ; j++) { + c->function = i; + c->flags = KVM_CPUID_FLAG_SIGNIFCANT_INDEX; + c->index = j; + cpu_x86_cpuid(env, i, j, &c->eax, &c->ebx, &c->ecx, &c->edx); + + if (c->eax == 0) { + break; + } + if (cpuid_i == KVM_MAX_CPUID_ENTRIES) { + fprintf(stderr, "cpuid_data is full, no space for " + "cpuid(eax:0x%x,ecx:0x%x)\n", i, j); + abort(); + } + c = &cpuid_data.entries[cpuid_i++]; + } + break; + default: + c->function = i; + c->flags = 0; + cpu_x86_cpuid(env, i, 0, &c->eax, &c->ebx, &c->ecx, &c->edx); + break; + } } /* Call Centaur's CPUID instructions they are supported. */