From patchwork Tue May 22 00:41:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10417155 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 A519B6032B for ; Tue, 22 May 2018 00:41:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92E3628AF9 for ; Tue, 22 May 2018 00:41:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86FB528B02; Tue, 22 May 2018 00:41:35 +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 8E0C128AF9 for ; Tue, 22 May 2018 00:41:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751958AbeEVAlc (ORCPT ); Mon, 21 May 2018 20:41:32 -0400 Received: from mail-co1nam03on0042.outbound.protection.outlook.com ([104.47.40.42]:64128 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751746AbeEVAl2 (ORCPT ); Mon, 21 May 2018 20:41:28 -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=RKrnVwvkBI+E6MHFr8pryB77NX+7WwzHRiOhpGZM3AU=; b=g3d6bHIksxr0lxcTVCYz+baTP3OicMH0lqMTsKJoOlOGq3YUnkCfq0hxCpWGUA3s454wOFl7ITkbqPR898VhfNRWhvggF513aSuvf/iaQe+WL7xN/kjp9KJbXw8ukpRxNtpGh4U+USoLIWsj/ASmMDImOKoH0brGAEo5xGB6OVs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from linux-h3ml.amd.com (165.204.77.1) by SN1PR12MB2479.namprd12.prod.outlook.com (2603:10b6:802:29::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.776.11; Tue, 22 May 2018 00:41:24 +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 v10 1/5] i386: Clean up cache CPUID code Date: Mon, 21 May 2018 20:41:11 -0400 Message-Id: <1526949675-106737-2-git-send-email-babu.moger@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1526949675-106737-1-git-send-email-babu.moger@amd.com> References: <1526949675-106737-1-git-send-email-babu.moger@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN1PR12CA0071.namprd12.prod.outlook.com (2603:10b6:802:20::42) To SN1PR12MB2479.namprd12.prod.outlook.com (2603:10b6:802:29::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:SN1PR12MB2479; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB2479; 3:EfzGr6op1+b1Yk98Z3vxFCYZhm1YASIwjxD7jkIE00EM1C64E223dj4/+D8S2fP7gnWIO8isj/7OrcxtR4NS3/L5FTQEF+Eg9QbNqCkUnY8pDq/rcgd4MXLp9DVVhgYBuOrRb4ROcPvxKsVQdo6I04mWZq2aTi7o5pjjSFgrCmdYRWb3x0gwSUji7UsqH3T1oWlpjUVDf187rs5HkTgjZA4k5QxmxA8hGHXu5LFeJZXqVSLJUn5cDVKnu0i85qR8; 25:FLtc0PGaxJh48zrEhecggBmj6h6lsKT2k7Qp9xNTih5fK+dxXZmCSWX0bbT2z1qJ/tRycaWlJa/MO8nvTlZ9zGGHkB1DysESE0iiDi6G0NouMi0BZJIFKumXJ1NmUIYaNkmFs6KGFWnkhsRq9STnPWsnEspBA50n+IaNxP0KGpkqGhgdg4fSn7EF1wb/nKlK7NN9EQHeyZxlrzAwQqj4/7u/zlYmnskOtBupafAgdtSrg3mx7108htvVo0O6zF9AdUvJOlbTeCyYKBWiSXMrByBRVAJsKjmruly4I0slVQxp4b33vZojwNmoKyI2dymOZp44u9x/Oy8hSDDVXEA/Tw==; 31:KKsfzT/K8QxQRoDqAu9sBS+G0jOYmrV+2RZafxS2FuViDcCJ3TNPALKowEhFzHdFcatq5v/CWKQUtlxARPNRwnwqEOzBvJZnxgSjnMi/9NA1fX+27F9EUjDkJ58AI/NPId7+WnQaDNgGD0BgXAWzhDPjAqUkd84lu87ksoYxmHN/1ql42ihbu8JjITgOGr7+atzQSID0nhZTOKBZuKBjLS9PxGPdQeHDm3dWDtkLOIo= X-MS-TrafficTypeDiagnostic: SN1PR12MB2479: X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB2479; 20:pu0hmRMR4UOVQjId4TfpbnxIWZ7LAj50QzO5SLaMqq4BQWCho86aQqVJ55+sY6BNoZi8r35jYqUJxrGgiXNyFsCXUMeJEkScjqrRacye0OqlSAdPsgBRAOEtRuLfwyQeXu64wMlekWe+RUekXs+QsIqDZQg/CVFDMl84axX9O31S+rjhjfawNQqw7FIIuZNQvfvIplNXUjORSCQniqbu2XwOZzj9I8WiA3tjMWHkIwsao3Ns0HLb/0ZPqQUAX1udi29t0eOXiH/uN6gGehAr8mYIjzJ+6y3BY/FgcWx29cimvjlZB+k1A8P9Tip0/skUugVEpLKt03GiKr3BoY5qv5aNWBm05uAcpUncI9iErj4UMsP+rZeCfqHgzju2bHl/yonf8caNqDYcMNiSArzLJHFO5zvfVtvuIuPcI2fCZpo0iyRkpIv8Udkw+t9xzjOcu2Sjrn3rpReBbLRAV4ZH6/HIu8AVj9FNh+8q/VwEKs/6WrisMEMPNxPwHf+9fYvb; 4:sTBo+0TDaYcjmnnl33KctGN8iG2FiXsol+umZ0LZKwdcQkgiIPk4k/OZjTAsFrhlqua2DjO4K5DMq2v4O3mr0Mk/luc9xevrNNscKr/wS521NrNsdApq6M2/x2mhJ620r7E1Fm9gp8qqVYvdW2sZHoIwqojXTGqjNCIQr78Unw0YBOHZghsdfjCaOGalFBgzb4UjnLg9IIC6Eh5hnwLG4pGMDVA279K+nK7jyR89wLL7RgJ81Rgie9X/fXH1v0vciilO/Rzn1J17D0P7RYePBpJ1QiS3YJ/vc3JNE6PrEqgDvmYWFkvNhiyHPV1cJYV+GuTXsh5tDVmUfNGHILrduw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(17755550239193); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231254)(944501410)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:SN1PR12MB2479; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB2479; X-Forefront-PRVS: 0680FADD48 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(366004)(346002)(39860400002)(376002)(39380400002)(199004)(189003)(16586007)(66066001)(25786009)(6666003)(36756003)(316002)(305945005)(48376002)(2616005)(486006)(3846002)(4720700003)(68736007)(956004)(47776003)(7736002)(53936002)(44832011)(50466002)(2906002)(6116002)(446003)(476003)(11346002)(8676002)(26005)(81166006)(8936002)(106356001)(7416002)(81156014)(386003)(105586002)(86362001)(97736004)(72206003)(5660300001)(478600001)(7696005)(186003)(39060400002)(50226002)(51416003)(59450400001)(53416004)(6486002)(16526019)(52116002)(45080400002)(76176011)(4326008); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB2479; H:linux-h3ml.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR12MB2479; 23:0GzM9XPMros/7GBhsRjwHzI+KoaAwnLAmBU7wn+XF?= =?us-ascii?Q?H4+r4Vf9Bgd1Qz4qN/uJ64fL4Su5RarUuIkmlYl883A438LiRYW3eMJICUEj?= =?us-ascii?Q?fewvg+8Xl4cFklx4kiMjWSi6mH2qRts6ZhANMF8HYR+kXMPBrMx5RohDqmlJ?= =?us-ascii?Q?7F0A4ptnljeAyQ5B8rY/9Ii0HoNAFkyyxtb70ET3UGCElDx6lBqbuus9IfSi?= =?us-ascii?Q?wDCscdM1c11J97xd7l0Rr9y73nDdRWxxIM3ihY63DiDVGqukfbyBQ0YCP+/t?= =?us-ascii?Q?NzLO+3eP/9N8oUQc9Kwuu53PsGG/RUZ3byfZSgu7EXwzl802aAyBZmj2jnoG?= =?us-ascii?Q?MkAZHs+HjspoGLhocGhG1992vbwynRWMmCFXKkmvJcIDOsCY1RK1dBFxsWom?= =?us-ascii?Q?/kAvESW2+a9nFkUOfPMq9woncS0dR48jMV3UPQ55Voxhb0C/bRa08KjmrQv6?= =?us-ascii?Q?WbnzpV1VOJC7LvvvqtNdWjjTUY2ATFhUwkGZ3BEtftFe3Meyk82mVJFM+n8v?= =?us-ascii?Q?uEr68b4LWnCa408TBx0hHMNGrsm+E3UyJuO4va/+VO6ZREjTtVHFL62Ayk6k?= =?us-ascii?Q?OA5z/XVSBzZXqMqaTpN2w9RsKqoczNcuDYq3iB6dV5QJWkNur2F4PpgdwRBA?= =?us-ascii?Q?JZTjf2MWmCiMuMe+iJRT8K7IcUvbRbPLOe4ddMbSkTYhDSVT1ocT/bt3TaQj?= =?us-ascii?Q?0B9T2Xo6ROYjvycQGBiiWskeMh0cuMW40Z8RoPgkcSuW9teP+92qvw36N2rl?= =?us-ascii?Q?CTeIHy9DoG2YRFcRRhUmFdFAh/lOMdKDBuwUi/uClKfjagRPHWcglT0bzpU+?= =?us-ascii?Q?fxlre7eTX5ODqR9eb0ER8OBQBnp8srXNcio+L5NZ02hNkm2ZEYEEez5e3XRZ?= =?us-ascii?Q?tXvKCVBSPW8B1QxavXjYZMrX+KubMBGGU+rLz1W3qMfF0Cem5haX818wEOcT?= =?us-ascii?Q?WXJ84adXqTuVtxXgr1+wxBweU1Ef/ejh+M+RzbvbkMwFZOT3btDNa9bxFDbC?= =?us-ascii?Q?/FXPgO/GbNu3qhrRmME9qO8ksX1dyQmb1kdSx/FQhuSG6sfAZyHFRPNnM9St?= =?us-ascii?Q?aiVGXo+iTo8TJdo/9hSy031R20CPWsSBdIxFmwTIPxK3AsZC9xEP058o1Q60?= =?us-ascii?Q?MLvUxzlSsPrhXsIqxj6ARAQLha6SQ0D9S4GQJOCWq0+gspHNfbjNAz8PV6eZ?= =?us-ascii?Q?fSynGKa3Ggub6VZJAptX1jVb+g2CiXk25WNpBVVeBqobbVuGUNEHRLUjNc2d?= =?us-ascii?Q?4037YowQTLEfXE1elArNlKkIO+O67dt8FUGc1nIXt83/likeHs+QXz0rwAqo?= =?us-ascii?Q?jWppgrKdAtylJHQ7Z5Pgcd7jrTT3Fc+KO6utLOC27/6?= X-Microsoft-Antispam-Message-Info: yKklgrVVSnrtFHGfCNtUjH4sJ/qQjWxAdFSCIm5IQStsF63aKyREDXotL5zriWm/ZmiQBgG2r5kWRjYISX3MSjna2Y445C1Ka+nD6XuVWU6VOFfO9uka7279/lcPlRUv7h09HSkVM29kEnUO4F7dif0b59BxCWJ+xDcfHg4x0jKbkBrp+KwU/o0e9O4Rl8WJ X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB2479; 6:KBxWUwLd6b/6cu+AGw5mxhqBdGWoVEq112qQLKGrJRjqb0WpDCuds6bUZd2S7QR/6FTfdcYUQzmf/LWsOK32xiYt0JR7JIdZtlvYMTb3UjY+Yik5mkIUkk+ZdvcNZMzpCoQvoRIeIDkUvbNOv93E2GnEhtJ9ZBLe6Xqvqyea8VR6UTWIu9cHLl57MYE0vSCEDR0NL1AVK2FpqoYsV31WL7kJZ2R7Ia5sIlezujn2puWcFRkaEqgIbVYcRz8FcufuQNGXqMy4K7571sd+RaZay9MDERCqzt/YsSurRLsyvkOg9aCL0L6xzdvjqnjvy5LmcwfowkVDR1nIl0V5/onNE13to69eCfCWQ2kR5H5XGSn4hTib16+l2UQZNC+a3hMIJMeWGBfVHlG0636d54tN6leW0zZDU8NxzTt3XAbXEjMgO3H4+osvoMDlrjvNkodtGxCFuL1N8Sw0A0olJhFV3Q==; 5:365R0hDdXJrhmvr4zbpmgfOLix0H9Fm7onts10Yi2e86GmdKaebq4hdOvLhMwVz5pSl9d27T8UplMaNs089TX1zqqtFp/EsIVZOPX7GJ2veVHH4eAQaHsDm0yFre/5NKDN2bOlRAotg2L8xC3WF4GeKMDIV2wA0neDnShX7AyPg=; 24:A0FbIumagbLN6D8iWyi5ommNwRUNn0nny5pLoFtzlZKPhCFkf+wP/awJb3dX1ssNfIj1oSMi/e581EaVqOKveVMRiPLRf1lDdWrM8LkwZiw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB2479; 7:EnJRI4GnVXV0CufS5Zz3LIMPHHk5UtdhkPB+svDHOregk9KUq88EDXTOZ6lh8QrDoJ7h5oGnirHFmLWWgtdbvptDgsx6J+p/cIdx6kVpZRmNC4yvycoFDRf0soS8Fsg3m4Mqy9aMmBlGkkKUbZMG96vVtDpI1r85BiQ8YKIwP8AYsBt2anhX7QLjmeivNmp1sbBUi7RStePrKTOcky+DyMG76+CiLNSsSSGTHIE9bPWSyCLjOCNDv7GbzEqwYN2r; 20:IoSJiTkWm8VxH8K0FgJ32uUZtAHU0M0hY1oL/L9LIdnecmNB0q1rtXnfKoOZvESJ0ypUD46uAiMwrKXtXinJ5ORb/8h4SEVEB9CcjmTXiNKimK98bTTSH6qqR1oFe4iHRTj5ivfGiHZbbBR4Jec7s3B2s3ZDDKPe8y0VPpPc2shbow19vItPAJmqnNT4M32dWuTV1vCAgcAPnQlhNDq125teSJZjoESEniLz1I7QlzqpGpfHjCn/tjUMiMhRmuxe X-MS-Office365-Filtering-Correlation-Id: 03a4b1d6-3243-4a12-cc72-08d5bf7cbef7 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2018 00:41:24.0272 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 03a4b1d6-3243-4a12-cc72-08d5bf7cbef7 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2479 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eduardo Habkost Always initialize CPUCaches structs with cache information, even if legacy_cache=true. Use different CPUCaches struct for CPUID[2], CPUID[4], and the AMD CPUID leaves. This will simplify a lot the logic inside cpu_x86_cpuid(). Signed-off-by: Eduardo Habkost Signed-off-by: Babu Moger --- target/i386/cpu.c | 117 +++++++++++++++++++++++++++--------------------------- target/i386/cpu.h | 14 ++++--- 2 files changed, 67 insertions(+), 64 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index e5e66a7..d9773b6 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1114,7 +1114,7 @@ struct X86CPUDefinition { }; static CPUCaches epyc_cache_info = { - .l1d_cache = { + .l1d_cache = &(CPUCacheInfo) { .type = DCACHE, .level = 1, .size = 32 * KiB, @@ -1126,7 +1126,7 @@ static CPUCaches epyc_cache_info = { .self_init = 1, .no_invd_sharing = true, }, - .l1i_cache = { + .l1i_cache = &(CPUCacheInfo) { .type = ICACHE, .level = 1, .size = 64 * KiB, @@ -1138,7 +1138,7 @@ static CPUCaches epyc_cache_info = { .self_init = 1, .no_invd_sharing = true, }, - .l2_cache = { + .l2_cache = &(CPUCacheInfo) { .type = UNIFIED_CACHE, .level = 2, .size = 512 * KiB, @@ -1148,7 +1148,7 @@ static CPUCaches epyc_cache_info = { .sets = 1024, .lines_per_tag = 1, }, - .l3_cache = { + .l3_cache = &(CPUCacheInfo) { .type = UNIFIED_CACHE, .level = 3, .size = 8 * MiB, @@ -3342,9 +3342,8 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp) env->features[w] = def->features[w]; } - /* Store Cache information from the X86CPUDefinition if available */ - env->cache_info = def->cache_info; - cpu->legacy_cache = def->cache_info ? 0 : 1; + /* legacy-cache defaults to 'off' if CPU model provides cache info */ + cpu->legacy_cache = !def->cache_info; /* Special cases not set in the X86CPUDefinition structs: */ /* TODO: in-kernel irqchip for hvf */ @@ -3695,21 +3694,11 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, if (!cpu->enable_l3_cache) { *ecx = 0; } else { - if (env->cache_info && !cpu->legacy_cache) { - *ecx = cpuid2_cache_descriptor(&env->cache_info->l3_cache); - } else { - *ecx = cpuid2_cache_descriptor(&legacy_l3_cache); - } - } - if (env->cache_info && !cpu->legacy_cache) { - *edx = (cpuid2_cache_descriptor(&env->cache_info->l1d_cache) << 16) | - (cpuid2_cache_descriptor(&env->cache_info->l1i_cache) << 8) | - (cpuid2_cache_descriptor(&env->cache_info->l2_cache)); - } else { - *edx = (cpuid2_cache_descriptor(&legacy_l1d_cache) << 16) | - (cpuid2_cache_descriptor(&legacy_l1i_cache) << 8) | - (cpuid2_cache_descriptor(&legacy_l2_cache_cpuid2)); + *ecx = cpuid2_cache_descriptor(env->cache_info_cpuid2.l3_cache); } + *edx = (cpuid2_cache_descriptor(env->cache_info_cpuid2.l1d_cache) << 16) | + (cpuid2_cache_descriptor(env->cache_info_cpuid2.l1i_cache) << 8) | + (cpuid2_cache_descriptor(env->cache_info_cpuid2.l2_cache)); break; case 4: /* cache info: needed for Core compatibility */ @@ -3722,35 +3711,27 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } } else { *eax = 0; - CPUCacheInfo *l1d, *l1i, *l2, *l3; - if (env->cache_info && !cpu->legacy_cache) { - l1d = &env->cache_info->l1d_cache; - l1i = &env->cache_info->l1i_cache; - l2 = &env->cache_info->l2_cache; - l3 = &env->cache_info->l3_cache; - } else { - l1d = &legacy_l1d_cache; - l1i = &legacy_l1i_cache; - l2 = &legacy_l2_cache; - l3 = &legacy_l3_cache; - } switch (count) { case 0: /* L1 dcache info */ - encode_cache_cpuid4(l1d, 1, cs->nr_cores, + encode_cache_cpuid4(env->cache_info_cpuid4.l1d_cache, + 1, cs->nr_cores, eax, ebx, ecx, edx); break; case 1: /* L1 icache info */ - encode_cache_cpuid4(l1i, 1, cs->nr_cores, + encode_cache_cpuid4(env->cache_info_cpuid4.l1i_cache, + 1, cs->nr_cores, eax, ebx, ecx, edx); break; case 2: /* L2 cache info */ - encode_cache_cpuid4(l2, cs->nr_threads, cs->nr_cores, + encode_cache_cpuid4(env->cache_info_cpuid4.l2_cache, + cs->nr_threads, cs->nr_cores, eax, ebx, ecx, edx); break; case 3: /* L3 cache info */ pkg_offset = apicid_pkg_offset(cs->nr_cores, cs->nr_threads); if (cpu->enable_l3_cache) { - encode_cache_cpuid4(l3, (1 << pkg_offset), cs->nr_cores, + encode_cache_cpuid4(env->cache_info_cpuid4.l3_cache, + (1 << pkg_offset), cs->nr_cores, eax, ebx, ecx, edx); break; } @@ -3963,13 +3944,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, (L1_ITLB_2M_ASSOC << 8) | (L1_ITLB_2M_ENTRIES); *ebx = (L1_DTLB_4K_ASSOC << 24) | (L1_DTLB_4K_ENTRIES << 16) | \ (L1_ITLB_4K_ASSOC << 8) | (L1_ITLB_4K_ENTRIES); - if (env->cache_info && !cpu->legacy_cache) { - *ecx = encode_cache_cpuid80000005(&env->cache_info->l1d_cache); - *edx = encode_cache_cpuid80000005(&env->cache_info->l1i_cache); - } else { - *ecx = encode_cache_cpuid80000005(&legacy_l1d_cache_amd); - *edx = encode_cache_cpuid80000005(&legacy_l1i_cache_amd); - } + *ecx = encode_cache_cpuid80000005(env->cache_info_amd.l1d_cache); + *edx = encode_cache_cpuid80000005(env->cache_info_amd.l1i_cache); break; case 0x80000006: /* cache info (L2 cache) */ @@ -3985,17 +3961,10 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, (L2_DTLB_4K_ENTRIES << 16) | \ (AMD_ENC_ASSOC(L2_ITLB_4K_ASSOC) << 12) | \ (L2_ITLB_4K_ENTRIES); - if (env->cache_info && !cpu->legacy_cache) { - encode_cache_cpuid80000006(&env->cache_info->l2_cache, - cpu->enable_l3_cache ? - &env->cache_info->l3_cache : NULL, - ecx, edx); - } else { - encode_cache_cpuid80000006(&legacy_l2_cache_amd, - cpu->enable_l3_cache ? - &legacy_l3_cache : NULL, - ecx, edx); - } + encode_cache_cpuid80000006(env->cache_info_amd.l2_cache, + cpu->enable_l3_cache ? + env->cache_info_amd.l3_cache : NULL, + ecx, edx); break; case 0x80000007: *eax = 0; @@ -4692,6 +4661,37 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) cpu->phys_bits = 32; } } + + /* Cache information initialization */ + if (!cpu->legacy_cache) { + if (!xcc->cpu_def || !xcc->cpu_def->cache_info) { + char *name = x86_cpu_class_get_model_name(xcc); + error_setg(errp, + "CPU model '%s' doesn't support legacy-cache=off", name); + g_free(name); + return; + } + env->cache_info_cpuid2 = env->cache_info_cpuid4 = env->cache_info_amd = + *xcc->cpu_def->cache_info; + } else { + /* Build legacy cache information */ + env->cache_info_cpuid2.l1d_cache = &legacy_l1d_cache; + env->cache_info_cpuid2.l1i_cache = &legacy_l1i_cache; + env->cache_info_cpuid2.l2_cache = &legacy_l2_cache_cpuid2; + env->cache_info_cpuid2.l3_cache = &legacy_l3_cache; + + env->cache_info_cpuid4.l1d_cache = &legacy_l1d_cache; + env->cache_info_cpuid4.l1i_cache = &legacy_l1i_cache; + env->cache_info_cpuid4.l2_cache = &legacy_l2_cache; + env->cache_info_cpuid4.l3_cache = &legacy_l3_cache; + + env->cache_info_amd.l1d_cache = &legacy_l1d_cache_amd; + env->cache_info_amd.l1i_cache = &legacy_l1i_cache_amd; + env->cache_info_amd.l2_cache = &legacy_l2_cache_amd; + env->cache_info_amd.l3_cache = &legacy_l3_cache; + } + + cpu_exec_realizefn(cs, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); @@ -5175,11 +5175,10 @@ static Property x86_cpu_properties[] = { DEFINE_PROP_BOOL("vmware-cpuid-freq", X86CPU, vmware_cpuid_freq, true), DEFINE_PROP_BOOL("tcg-cpuid", X86CPU, expose_tcg, true), /* - * lecacy_cache defaults to CPU model being chosen. This is set in - * x86_cpu_load_def based on cache_info which is initialized in - * builtin_x86_defs + * lecacy_cache defaults to true unless the CPU model provides its + * own cache information (see x86_cpu_load_def()). */ - DEFINE_PROP_BOOL("legacy-cache", X86CPU, legacy_cache, false), + DEFINE_PROP_BOOL("legacy-cache", X86CPU, legacy_cache, true), /* * From "Requirements for Implementing the Microsoft diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 8bc54d7..5098a12 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1098,10 +1098,10 @@ typedef struct CPUCacheInfo { typedef struct CPUCaches { - CPUCacheInfo l1d_cache; - CPUCacheInfo l1i_cache; - CPUCacheInfo l2_cache; - CPUCacheInfo l3_cache; + CPUCacheInfo *l1d_cache; + CPUCacheInfo *l1i_cache; + CPUCacheInfo *l2_cache; + CPUCacheInfo *l3_cache; } CPUCaches; typedef struct CPUX86State { @@ -1292,7 +1292,11 @@ typedef struct CPUX86State { /* Features that were explicitly enabled/disabled */ FeatureWordArray user_features; uint32_t cpuid_model[12]; - CPUCaches *cache_info; + /* Cache information for CPUID. When legacy-cache=on, the cache data + * on each CPUID leaf will be different, because we keep compatibility + * with old QEMU versions. + */ + CPUCaches cache_info_cpuid2, cache_info_cpuid4, cache_info_amd; /* MTRRs */ uint64_t mtrr_fixed[11];