From patchwork Thu May 24 15:43:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10425029 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 282E660327 for ; Thu, 24 May 2018 15:44:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3C92296AD for ; Thu, 24 May 2018 15:43:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E86EB296D5; Thu, 24 May 2018 15:43:59 +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 040E1296AD for ; Thu, 24 May 2018 15:43:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967998AbeEXPn4 (ORCPT ); Thu, 24 May 2018 11:43:56 -0400 Received: from mail-bl2nam02on0059.outbound.protection.outlook.com ([104.47.38.59]:26944 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S967929AbeEXPnw (ORCPT ); Thu, 24 May 2018 11:43:52 -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=YOnBjpYfUSZRhkEOawGJQ2Oxwo6ibgMf+3h7+ej8gTE=; b=OjXIs0uVNyIxv2DCaABD0RmoVrMCDSGopDagEQZnSFfzkQH00XTd5/V4+6VXoaF0OLbauGhPxgcnymf7T1GxS3v8d4U1HJHMN1zU/pT6AqbqAfixop+QdKiSMl2yWuC5kTic4ht1DpeOqATan5/istJYMqGbWtZTA+kCnEMUQbo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from linux-h3ml.amd.com (165.204.77.1) by DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.797.11; Thu, 24 May 2018 15:43:46 +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 v11 1/5] i386: Clean up cache CPUID code Date: Thu, 24 May 2018 11:43:30 -0400 Message-Id: <1527176614-26271-2-git-send-email-babu.moger@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1527176614-26271-1-git-send-email-babu.moger@amd.com> References: <1527176614-26271-1-git-send-email-babu.moger@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0501CA0024.namprd05.prod.outlook.com (2603:10b6:803:40::37) To DM5PR12MB2471.namprd12.prod.outlook.com (2603:10b6:4:b5::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:DM5PR12MB2471; X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB2471; 3:Ad04UatlG+WdQm53x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rA9K90+PGx3wqSfPoD3HfMN//gBQBrwP0UpDQnw5n8hMIxJebHlAypq+5xUpvA1GyoMsjcTj6ZNwnFGcaITC/sBEyrpB8DOxyGIjcdaAEzNglEqJwyAQP5Y5uT8+VsVW4zVgPz5fQBtZpNM7AKjB3HHXDEugSmVv98EthInQgAnsZk/4DniNh7NAlI1BzZIB4WJ3hGoiBHKt4+5aPOkpBVcopf3RIutTMR3DIHhHKWUAI9Hrw153m2O8i5fsG/v918LHzSReVKVyUBsiLJ8iOkJCmsKWUSlCNpLskjJB/4AoKoYh45M+BqgTVAWMu7IRJoJVA9oPU8PlKuU9; 4:HwKAha3E1N70gF6ehVWSSOM3gpUtztkAMcWDDIsLKgCBYjpfUY37BvSkao8HPK3LuzwrfpGlnpJprHhninu0xk25M0hSxlSe38r9vsZqNAwI0rkfYXfBG1tQ7UEkDggxUos9PMSMnaAsAqr3DZNpZ/za8/tnvNtcUE45HJSeZ3YR7oL7zjrhfauDVx+uSTc2eAfpq951YJdLOtfgGR3cpFVepS9hrhV9t+bL+m5aEf2oiBrfx5DZxfg9s5l2FRJBtOfc+lVkH3Q3y0uRW4kdwQXDM94YJU8h9EFmBmJjyKccSiRlth2Jxn1z2lM7m0e0xDmSNkPxaegpROltXgem1g== 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)(3002001)(10201501046)(93006095)(93001095)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:DM5PR12MB2471; BCL:0; PCL:0; RULEID:; SRVR:DM5PR12MB2471; X-Forefront-PRVS: 0682FC00E8 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39380400002)(366004)(39860400002)(396003)(376002)(189003)(199004)(5660300001)(53416004)(6666003)(2616005)(446003)(11346002)(956004)(476003)(59450400001)(486006)(44832011)(16586007)(7416002)(4326008)(25786009)(478600001)(45080400002)(53936002)(39060400002)(26005)(47776003)(316002)(186003)(16526019)(386003)(575784001)(86362001)(7696005)(51416003)(52116002)(66066001)(68736007)(76176011)(97736004)(2906002)(50466002)(3846002)(6116002)(72206003)(4720700003)(7736002)(6486002)(305945005)(36756003)(48376002)(50226002)(8676002)(8936002)(81166006)(81156014)(105586002)(106356001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR12MB2471; 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; DM5PR12MB2471; 23:Hb5Fef7BLi6/IWK8iyPcwYCV5eKrQg9wJE3pTjkVt?= =?us-ascii?Q?6MrCdEOtr8bCtRGmjqJ1sfpd/6SILd9ba2GXcro/afQ/CRd6qcjqtUEuCv23?= =?us-ascii?Q?D8EN70z5YLBoZ2vpU8q88T7thyqiG9zkW6F8FtQkBdEI4GAPXPGlmgKEJbDm?= =?us-ascii?Q?1Za/MfoDg3iBv45fS1CiLMoIs33kDJM9az3T4a3XCG/Gbcp+Y85YR/BSQtjz?= =?us-ascii?Q?oqm93NVNLAtB2rBmnL55FfGnmlLGi/OdCfv/vJYbh/ENzzPRm8cHTaqWa3rH?= =?us-ascii?Q?S3cpcdVQeJxs7wHVK5FG7BmkNTF5evHHtwNp6b7mZdggBNAbnNeZIWlHzd7K?= =?us-ascii?Q?+rm8+SSx4X0hfIOKsNO5blApYNx4Krv2ns7P3eYBj3wJfHnAHxCuBSwHL+yJ?= =?us-ascii?Q?QHIIhJUQ0+DNt/Zq9GRtFE9ZJGBg3KHm+AfF0RWAAPSKZVt2TuzT8Ci2jSRq?= =?us-ascii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0NQ/M9FNchQluD?= =?us-ascii?Q?TJCxQ=3D=3D?= X-Microsoft-Antispam-Message-Info: xLIlh8bw7j7bE7Opi/w6vtiNbiLWyWisE1xG4vdT/5B4ybrlbiLd2Lp/EubQ72QSoXIHu9jpe8ZV4gxLURST9BEskgbZLytfFlt+/ya6uWL6IE+l3L+QbpTITC0uBGY4XWV3xE6Fki4oV6fr6Pi1FKi+iXLj2QK438cwpmc9haj0Bd6EYMeBhpzY1ZHjJ/5R X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB2471; 6:+azAbanafA36ZNxpWzziOZqM6C4nebL66BYXt9w7QncCYliNDd82zYNg/HE7bpBcAxeEwpbZBwMJZY6iOU83J69Hm3lXtgp4QnIir4ROtn/APXuS765/drEByyITSQxC/yFp69OipLX63uH+0QImldD4fAfCogf/Md29hCTdJral2WDpRGcVOIjWU+e2P/+Y6xdogaOGbgjrJtTphiTPHiJiWQPIefyrHv7cNS24eTjurX3Z/M3FAxlI/pwKiKs4FtWNwb5pBQfQSDZqAi7z2YYcOiOJ1MaPIYGKxMsLALR8qn0Da3YNB1+hO0vi3ZkzPTDWzUFAg/gJm/L14lOXQoRHh+qnkIWF1GxrqhRWdBrkdgGqxUEM5La6CnkDkuJygYaqBdVvh4ehtYwrknJteUnFZLHtLAGlRRcGpNIYdPcFlWOleVSFrQoMEu3UG49L/VEXfmpZi2ViR61tuViDfg==; 5:MOt+CfTJogqq5Ca+CbRGMFrolGNkVOfuL1OihvGxbQl7nLAW5IJ43TzBeMLQAsychrjidionLfRGW15nwSd5XgzNDPz/wyir/Falx//JZ+AqEqDoi8sYV2CDiI91Ut3HJoMiMqLuJc0aJqoOI4JdmhXmEytzGAg168YQIddfGDA=; 24:s9t5gQXAYR0N/imjD4RTrlshiGs3NGjKWkslbNeilmu8YlrC0g/RMUe1MQFKBoM6I7yYI5sYdYodKD/VhrUIA1ZA55dHh6H7wRTa0zKrsko= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR12MB2471; 7:+00P2kaoOO6rV9FcUWSsEGciFvf4cs7Rw6wHKu8ssclE1yDDQhBab9YgHM+HtJPFLprBn3eQGCYxfKkVOsOCH2OHi6jSzgS1fFxrgTBuZZR1lX4KeepStsAarpL9ov0mFH0dvgfK8L9KLSsWOD7j7D46+zi9J3D+EnHmZ5rgijczr77ZG/tbFN42dgux6sx9bnCsMw0FvUnIYpDGQyjZx0aXQki/bwHjJI8dkBylB/NkmwotHkJGrhcfQA5LJU+r; 20:4lbw3GEi9GSTyTgc7320lwB6ZJpIdXUK4JFRhEIKlVdkjP1XKkmNwwe/BPct6yqRR9HMmaBYkmubwVuQk54ZZEXbPnjghi281Q9f36u6HUOhfBChaw1XMS1ChhFXDfNACz310ybPVrqQDl7MsEglucVzITGNxG+hkDwWyX6p63BqKWPXhfORX4yXU5aZGIqPWeQ1yniA8wk9J8G1Qeel2KPscrrKPN6m0+TLgVuGbjwXTf3mu+oI0X6dFtLJnCzC X-MS-Office365-Filtering-Correlation-Id: bbf2b868-db74-4ec7-5e76-08d5c18d23a3 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2018 15:43:46.8689 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bbf2b868-db74-4ec7-5e76-08d5c18d23a3 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2471 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 d95310f..5c9bdc9 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 8ac13f6..5ddb0e6 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1100,10 +1100,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 { @@ -1295,7 +1295,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];