From patchwork Mon May 14 16:41:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10398901 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 4C2C560536 for ; Mon, 14 May 2018 16:42:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B25828390 for ; Mon, 14 May 2018 16:42:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E921283AD; Mon, 14 May 2018 16:42:43 +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 3E71728390 for ; Mon, 14 May 2018 16:42:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932340AbeENQmj (ORCPT ); Mon, 14 May 2018 12:42:39 -0400 Received: from mail-cys01nam02on0080.outbound.protection.outlook.com ([104.47.37.80]:44837 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932218AbeENQmS (ORCPT ); Mon, 14 May 2018 12:42:18 -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=tNgVVCaE4C3Wvve9hl9V2bzBWBrtP/+//uhi04t3jGA=; b=a+aydoY2gc09p+itsFzwDJjxOCr3YMWuSTQHiVb0/AP9f1PNkUqXZilQLps6uECfAWTLrDc9R+7wj12gGGeCL41ewXKy+vRaRatTo6g+PsY/dLMW2ChTEaYqJQgjfCdx6VVEsIE+2gtu7LOqELvMAMzXbLCQSGW3vjaOaj4MxHs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Babu.Moger@amd.com; Received: from bmoger-ubuntu.amd.com (165.204.78.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_CBC_SHA384_P256) id 15.20.755.16; Mon, 14 May 2018 16:42:14 +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, geoff@hostfission.com, kash@tripleback.net, babu.moger@amd.com Subject: [PATCH v9 2/7] i386: Add new property to control cache info Date: Mon, 14 May 2018 11:41:51 -0500 Message-Id: <20180514164156.27034-3-babu.moger@amd.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514164156.27034-1-babu.moger@amd.com> References: <20180514164156.27034-1-babu.moger@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: SN4PR0701CA0008.namprd07.prod.outlook.com (2603:10b6:803:28::18) 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)(5600026)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:MW2PR12MB2476; X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2476; 3:uek4xg8k7Sf5I/i87jVrucaBKhhf7C/hXWRTXNUq5xeOB4PDMU46+7k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F8NaNrZYT/PIWGAcxtscYbU+FE3CGDwy3ZunDrhp0P0ZzW43Xfre0bIx0+9V5NnGabhfc36scNrtOSP6R6xFWaTE/kyN423dpL4Fv0QdWfTRAza0BKHlHENGMU6KYcRfc/5CluJ5vszBI7K4ScLfRkkQE1LkWaTbVCrOKk9q4bKD0F958tN6wUfklHYror7aO1ekl7Z5Fv8jONL3XRhj3K2mLWPAFoRgrSUanpKqAlYoq6v0eRvVcYxUPclBYLLsOfBAStwzq7phTWVdWrZ1LUlksV7uc1MmdD; 4:2zqzRK9AefzqZ/mgLJbwdJMszvT91VGkB7o9BqRhhV0s0udHCrBnRQohrY9Ehwa+i0U5l55z6RrDiVTwsoWs8vAmn5AISsqiwn1emk7oYjRFoat7UY3R+2qnjRFTp5w8Zz/udtcHEOTrOCfsHGpD5/8jIr5MQp1r12iitSp98IMkMl3H4/rdczBDFpCh67HcLVjenCrux5DqUw7WbfEhqL7HBUQA9iU5d+OixmgfPR9Y5cAJhLvv3O1Ou/5FSms+dPFAKqo25UkWVrbntPqY9JowH/Q7nliYMipF2xXLcskCc07tv/p72slgW2V+9GOY 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)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011); SRVR:MW2PR12MB2476; BCL:0; PCL:0; RULEID:; SRVR:MW2PR12MB2476; X-Forefront-PRVS: 067270ECAF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39380400002)(39860400002)(396003)(346002)(376002)(366004)(199004)(189003)(50226002)(53936002)(50466002)(8936002)(8676002)(39060400002)(48376002)(2616005)(486006)(476003)(305945005)(25786009)(7736002)(6666003)(446003)(11346002)(956004)(5660300001)(76176011)(186003)(36756003)(86362001)(16526019)(81166006)(26005)(4326008)(386003)(81156014)(7416002)(45080400002)(106356001)(53416004)(72206003)(97736004)(316002)(47776003)(478600001)(105586002)(51416003)(68736007)(6116002)(3846002)(16586007)(2906002)(6486002)(1076002)(44832011)(7696005)(66066001)(52116002); DIR:OUT; SFP:1101; SCL:1; SRVR:MW2PR12MB2476; H:bmoger-ubuntu.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; MW2PR12MB2476; 23:sOxRYmKPKQOwHqNnc2A+kMk6bh1k+fUGT227gPyhD?= =?us-ascii?Q?AkHQP9doLn+UyvwlAyU+YYHgATMLIG6YxuDeF6rhSuKTM6ybNfP0iWeO4/YH?= =?us-ascii?Q?xchol2mshvbFZ2Gt83Pe1un7BnDaHcJ6oO9wYQawDr38l3Gn7nGVo0lNv7VP?= =?us-ascii?Q?4kf9ILD0L1z+0DA8fOUnbPHUuhGj8NHinONgDeZHXEB8v0OaeN1d/8XBDipZ?= =?us-ascii?Q?4Hl3RlAhKeGzXX8cbetIvhZlE6enoazXgZj+eXvpmo/cKj+Ki/xCVvMfT/V1?= =?us-ascii?Q?aa2G9uPv3VJROCTS6VRm/1HBi7MJF8It2ZVLJaVDFZD20HB7cbvP3K38BgKr?= =?us-ascii?Q?mGLXI1Q3HqaZYxcLZNfZJmGNYBXcrhyt3wrxpKTAWWTRhMDV3t1+z2txLxxZ?= =?us-ascii?Q?rnlFwyU60tl3pYL2DNpv9Rws+VBVFdF7bz2+K5/qfl5RHbQQQGcQ1gF1woVi?= =?us-ascii?Q?sZrJDtuvAdjRX/CQoksoO1xxZcz80PO5XGgDmNstPODS0/6C1QN2W+s+Icxf?= =?us-ascii?Q?ehR47NlrTQwXkvoz/Vl6X+6Ut8v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6kXEDM4AWIWsMFN9MK9N249j3sWwVursnQDOBz2+L6kOh0mwQL3EDyZU9Aw2AiKSdBc6OSKMyYTXUtf X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2476; 6:PNUrn6MK28ZMqxMF2uUf9Ibpg2GT3WpMGnbjm96Psa2MQqwsA6hH5Xu6JnHrJ7/POHiVEiXg3tJt94rHmywkTmgb737GIDdNFT0ZZ26dVNwF/IvQGVlLOMMSM0qyCYszHldlOdQq6dn9P4/XgGHLDs6aYJPMRUBpYeJhxmALJjMU3ksCmhE40k7qwbr+mXbZmCIOBfHKMAk7dmeE/toRvqpeY5t/NUMPr+GCRZ700P1sgHsKzJEqWE8ki9dIUDPbW0WR3ztPWk077hKb8c+Yvp/gbGZO1SRah/itk4UgVSR098L7XRZbec2y/N5MofpPAHwaXc+NIx3YmI/FfLky6DjC2HFKNcF9QTivLjTzdBBOs5RTGcY1FY9Go/wb0cqeDwbfAd1el4riNFajs7WBmqN6qJcYDQo/BH368hZfY1WhuVdDOmOVER/demIC/++Wx38fA1g8AR/R8lMMtd2+Xg==; 5:H+tmjpsUSAw2oPC8g5m6zwuijyKEUSqbKXsrHSnHrlUk8y54/gVYHZxvRkxuytZXQbGUDE+f9NZ7xzuBszhYKtM25LSc/T0V2LbSoBaEU6FFChu75ONMPAmkF2hMRX2TjIsww4Fa2Yfki//lpBiv1InyKMj8nI+VpT1sg1ASLrE=; 24:H0ClkE+gmNYTcCByqMsz7A3hpGuV7SYP4PDahVlM+zQREL52CsyVWROCWDyZt//Nbuu5XlxPXNEuhQIQp4UCDssk1UGBaBVsXXggoPnPMTg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2476; 7:FV5As94vcfnjFkxwwcAuzawvM6OudpDvsnapsSA9fOtx8xSmdaVviYQmOh+LWD0zgVb158QYZDvGAXaOnODj743OdN8NpWsXQS5huIna1Jm9GahTgZqZoYn1pDnIhR26l39C+R88N1p/ZDYzUKto2ejXhJEtW22o5KpPQgnRjhEruvXVW1Ue3/BwylrL9IAKh6b47Dgt/TgW/tEazRguvxDcZkJmCvIeLWbpvtVCamLdvLOqnucb8Luk96AoeWrv; 20:op4HhewC39rBCbnnfOX1IIH5xec0eqe7pDIULNpiLwy9fuaBJhDTqH4BMrpQlXmbxjbrSpE4NRGmzYhB+e3f4XIom+8tH/AJhSqqVWcD5d9TMe2MUKOCnOFK7rSm8jO9U6ltDb+SHRbjjRx2RixpEaKMVuALrA2D8LCu5ZvGm2go8LgMfLWGBlD0hMpBF28F89j337UcAH6QWuGTVbaCHLRGaZlsvK4MGEWAgrTrS0b13MvACDjg+p54uR/68xgy X-MS-Office365-Filtering-Correlation-Id: c3a90c27-a0b6-4913-5cc4-08d5b9b9a685 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2018 16:42:14.4451 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c3a90c27-a0b6-4913-5cc4-08d5b9b9a685 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 The property legacy-cache will be used to control the cache information. If user passes "-cpu legacy-cache" then older information will be displayed even if the hardware supports new information. Otherwise use the statically loaded cache definitions if available. Renamed the previous cache structures to legacy_*. If there is any change in the cache information, then it needs to be initialized in builtin_x86_defs. Signed-off-by: Babu Moger Tested-by: Geoffrey McRae Reviewed-by: Eduardo Habkost --- include/hw/i386/pc.h | 5 +++ target/i386/cpu.c | 97 ++++++++++++++++++++++++++++++++------------ target/i386/cpu.h | 5 +++ 3 files changed, 81 insertions(+), 26 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 69fced9aea..df15deefca 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -306,6 +306,11 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); #define PC_COMPAT_2_12 \ HW_COMPAT_2_12 \ + {\ + .driver = TYPE_X86_CPU,\ + .property = "legacy-cache",\ + .value = "on",\ + }, #define PC_COMPAT_2_11 \ HW_COMPAT_2_11 \ diff --git a/target/i386/cpu.c b/target/i386/cpu.c index f9ebfcfe79..e1daff37ab 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -336,10 +336,14 @@ static void encode_cache_cpuid80000006(CPUCacheInfo *l2, } } -/* Definitions of the hardcoded cache entries we expose: */ +/* + * Definitions of the hardcoded cache entries we expose: + * These are legacy cache values. If there is a need to change any + * of these values please use builtin_x86_defs + */ /* L1 data cache: */ -static CPUCacheInfo l1d_cache = { +static CPUCacheInfo legacy_l1d_cache = { .type = DCACHE, .level = 1, .size = 32 * KiB, @@ -352,7 +356,7 @@ static CPUCacheInfo l1d_cache = { }; /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */ -static CPUCacheInfo l1d_cache_amd = { +static CPUCacheInfo legacy_l1d_cache_amd = { .type = DCACHE, .level = 1, .size = 64 * KiB, @@ -366,7 +370,7 @@ static CPUCacheInfo l1d_cache_amd = { }; /* L1 instruction cache: */ -static CPUCacheInfo l1i_cache = { +static CPUCacheInfo legacy_l1i_cache = { .type = ICACHE, .level = 1, .size = 32 * KiB, @@ -379,7 +383,7 @@ static CPUCacheInfo l1i_cache = { }; /*FIXME: CPUID leaf 0x80000005 is inconsistent with leaves 2 & 4 */ -static CPUCacheInfo l1i_cache_amd = { +static CPUCacheInfo legacy_l1i_cache_amd = { .type = ICACHE, .level = 1, .size = 64 * KiB, @@ -393,7 +397,7 @@ static CPUCacheInfo l1i_cache_amd = { }; /* Level 2 unified cache: */ -static CPUCacheInfo l2_cache = { +static CPUCacheInfo legacy_l2_cache = { .type = UNIFIED_CACHE, .level = 2, .size = 4 * MiB, @@ -406,7 +410,7 @@ static CPUCacheInfo l2_cache = { }; /*FIXME: CPUID leaf 2 descriptor is inconsistent with CPUID leaf 4 */ -static CPUCacheInfo l2_cache_cpuid2 = { +static CPUCacheInfo legacy_l2_cache_cpuid2 = { .type = UNIFIED_CACHE, .level = 2, .size = 2 * MiB, @@ -416,7 +420,7 @@ static CPUCacheInfo l2_cache_cpuid2 = { /*FIXME: CPUID leaf 0x80000006 is inconsistent with leaves 2 & 4 */ -static CPUCacheInfo l2_cache_amd = { +static CPUCacheInfo legacy_l2_cache_amd = { .type = UNIFIED_CACHE, .level = 2, .size = 512 * KiB, @@ -428,7 +432,7 @@ static CPUCacheInfo l2_cache_amd = { }; /* Level 3 unified cache: */ -static CPUCacheInfo l3_cache = { +static CPUCacheInfo legacy_l3_cache = { .type = UNIFIED_CACHE, .level = 3, .size = 16 * MiB, @@ -3337,6 +3341,10 @@ 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; + /* Special cases not set in the X86CPUDefinition structs: */ /* TODO: in-kernel irqchip for hvf */ if (kvm_enabled()) { @@ -3686,11 +3694,21 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, if (!cpu->enable_l3_cache) { *ecx = 0; } else { - *ecx = cpuid2_cache_descriptor(&l3_cache); + 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)); } - *edx = (cpuid2_cache_descriptor(&l1d_cache) << 16) | - (cpuid2_cache_descriptor(&l1i_cache) << 8) | - (cpuid2_cache_descriptor(&l2_cache_cpuid2)); break; case 4: /* cache info: needed for Core compatibility */ @@ -3703,27 +3721,35 @@ 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_cache, - 1, cs->nr_cores, + encode_cache_cpuid4(l1d, 1, cs->nr_cores, eax, ebx, ecx, edx); break; case 1: /* L1 icache info */ - encode_cache_cpuid4(&l1i_cache, - 1, cs->nr_cores, + encode_cache_cpuid4(l1i, 1, cs->nr_cores, eax, ebx, ecx, edx); break; case 2: /* L2 cache info */ - encode_cache_cpuid4(&l2_cache, - cs->nr_threads, cs->nr_cores, + encode_cache_cpuid4(l2, 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_cache, - (1 << pkg_offset), cs->nr_cores, + encode_cache_cpuid4(l3, (1 << pkg_offset), cs->nr_cores, eax, ebx, ecx, edx); break; } @@ -3936,8 +3962,13 @@ 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); - *ecx = encode_cache_cpuid80000005(&l1d_cache_amd); - *edx = encode_cache_cpuid80000005(&l1i_cache_amd); + 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); + } break; case 0x80000006: /* cache info (L2 cache) */ @@ -3953,9 +3984,17 @@ 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); - encode_cache_cpuid80000006(&l2_cache_amd, - cpu->enable_l3_cache ? &l3_cache : NULL, - ecx, edx); + 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); + } break; case 0x80000007: *eax = 0; @@ -5133,6 +5172,12 @@ static Property x86_cpu_properties[] = { false), 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 + */ + DEFINE_PROP_BOOL("legacy-cache", X86CPU, legacy_cache, false), /* * From "Requirements for Implementing the Microsoft diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 318e66108a..1f9ccd47d9 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1395,6 +1395,11 @@ struct X86CPU { */ bool enable_l3_cache; + /* Compatibility bits for old machine types. + * If true present the old cache topology information + */ + bool legacy_cache; + /* Compatibility bits for old machine types: */ bool enable_cpuid_0xb;