From patchwork Mon May 14 16:41:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Babu Moger X-Patchwork-Id: 10398891 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 BAF3B6038F for ; Mon, 14 May 2018 16:42:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A802028390 for ; Mon, 14 May 2018 16:42:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C6EA283AD; Mon, 14 May 2018 16:42:26 +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 BC68128390 for ; Mon, 14 May 2018 16:42:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932277AbeENQmX (ORCPT ); Mon, 14 May 2018 12:42:23 -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 S932214AbeENQmV (ORCPT ); Mon, 14 May 2018 12:42:21 -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=Gj3qdQciwkLKaWEL9VXYh1E1JowNLUCHT3w4zNhoEmg=; b=fti11lDjO0XhDE8ly0Se95jcfVtdHVQPqiQXW9pXTCQe/xWvLViqZa8g9kDFhhogPU4ZBV193GMLxZHUwf9XiSIqIcIhCAcLzMgpDtt48QonQdpO5w4fE7ZwHJP5DOUzxVvPWWiDYny7HsRwRJ4FheuBhMcm6C+mZIXHl9M+pRU= 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:17 +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 4/7] i386: Clean up cache CPUID code Date: Mon, 14 May 2018 11:41:53 -0500 Message-Id: <20180514164156.27034-5-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:/boBwEa6yVHuRyHBShORLT0dUIXmvWFwccqaYrDk8A3p4juMo2eAUKgKtKQq6jG+5kZV8FpNJuZtuNXLsgPU5C7sbldBCNXzK+KnXd4k+CZ2i9B/PjxtFmJQEpgXfpZvQXA6BePSvHYC6GZpiL43aZrYILKvfBeXeQ9lsOOaCwQ/LQ9wQpHymjyuqWutOBpV5/XUvUX/KvjBDMwwBSyuR1LZ7NZYQa/oQwlDjyFNbenFI5ttShaC+leTmOAWtFym; 25:YgGY0cMe+uz1mZHq/EGUST82PnTItY5IYaGcZ+uCzFCR+xUnA5LIoG4C3ZGI5Cv13uPOquYO7Sy6UJ8IRSzY+jDxGMeJf5i/aO7PNQ3OX93Qq3EB11Fu4Po922F0+peMzgHm6QU1fiRJCPnYSlCqJ4HWVs9SN3rydIdS0o4MD4tzvHXhf2i1BdvKCgp1hni9vowEPq3h/OCoTtpqWomu7L7GY5QUJOrGsghAI7qDMd8fVpH3dL6+JNOpqHX1GXw+uQNQeNmWGuvtJApl94pOoFw5pys6vufiG77QmcO3suMH3mqHs7KVlsiZVoxW8B9IwLM5mnfCOiHgRhZ5n8jZyA==; 31:szutXyK/WvcVLuiMzJdnLIYWpB0fLZG5NBjCn4djReK/jl5SkEd/tMu21SChkHXvzPbu9wYIDDC7jAYXtFq3dZbClA/wqwo6EjfNeiPZhxxa+IJXDd1ELXhNlgB8u0tr3YGv9kepscnBCPNR5U9oMQSzFTjPoJ8sa2Z9nutS8hO8oulvxuIclm0Owa0TCKFv6XXYy1g/j1Y/Ot7+kvIu0JQm7kZtXNwxZJcmVcKnpzU= X-MS-TrafficTypeDiagnostic: MW2PR12MB2476: X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2476; 20:LFLcNPy4T+y4+wYIAcq6WtkwdROUMAdtG2X8nGTwbZUrMW+RNVHaMgiINzEMcy295UGOiL+TYvKIhwA2T9ILH2matXeiFifvH+GRABoJnZaSDEzgErAkxcAq5ARKsfxG7kYHLtyvuHn5XsmF9Mjpe5G7ejy/l6BLDtESH7RbkUBCuAEn2tuyV6grZ0Uw+V7jy6VpUidcnrWFM9Nm/80O5gAlBEcxG8/0ONZwbpLX7PzYBB/0I9Fu/x4GB9e2oHzbdiFABgfie+HBFFtVCLPB46zD8kNcgQ7vdVqqN0NnqJKDq2Vq6vPF0qgZ4CnGKSywpF/wWJyL8310gT+ZauUXnXGl0sAYlDUeOO98mtTgyEF1cktbnFHqP+bqQ0bOtGIkYnMVUGOyBKm6EHV9lP3OGQMtGLh7Z3fyChiFq/orhlr3T0KdTn0SDOWefYYhD2h6TN/SLHzWyWeV1g1HO1zsIdsX1ycXqwam2rMU64T/HaW2s4ixJjDQTqQvgE6C13+4; 4:z8CTdRjnE7FofEaY941fGtzZpHx+hVnC4lwcX1sgHuJHFuG4OxEVSjxPX0GfKBGIEgLwboKAVfV9hYEbq6qPp8cKrDefGxrmIHCuQUBVLVRZgkIHNdZJ5u6lKYa5c99mT4MS1l/zME1bPZYrGBi+2xI+HrT9Zn2GEOViidaFzkZ76YxDWehKTRIKR2eiue9lil18j97NLgPb61e2Hfy5R9vy7Dk5CeNom2m9FhuQkX6a5uxMoz5ZgSpk47YNWwA8U/kMjmNTANGSXO2Nzv6KgPrgF13h6/1L/25ywUM7eFKowpRmwNSrJ+2WQqjQoNr6XcdA60uVmtdZkY/iRIPz4w== 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)(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)(59450400001)(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:G5SR7UAX3Qcz/c8tbPAGTjgs/hl+WY87iSLKtG/QD?= =?us-ascii?Q?s/Xipy51AnayLY9P53hKQYs6CuxqeeFYhRTIIw6ld3U6Hx7pBDlC80HxEho8?= =?us-ascii?Q?gT2IPpEfwtHmDw+g0KZjnLuy/I4Zf8eKmc47pVGbWIQ5Ao8n410yJ0WTlp+m?= =?us-ascii?Q?1KENq4cENYINWuuxfTjFoFn4rNM2OHkblAq4E87ganAE954AABEHVPP5xYgt?= =?us-ascii?Q?c5nAQ4MiczDf7eiw5hrZ6whUHRCgZiQ22ULyY620C78o9qYwYjMhUt8Z8Enq?= =?us-ascii?Q?X2rPo3lF++vkF2esUw9RHiZgmotDG22s8msuLlkzaZlDu8AbUlXf8nT80iGP?= =?us-ascii?Q?UoLr8sJD47Htgp7K6AffiQcT6rkFu9caS7BnWHq1rvo6UPMamq6IOIO2HUAU?= =?us-ascii?Q?AK81Ago9CJEuK6Q7mkSJegYcVCUDm7aG141bHAO6tUv/SdtBrgmK7ggTh47l?= =?us-ascii?Q?d/mlXM+7GOgH2lmfbgJ8uUKwep5WO7MC08LmbVkMBUMlFI+5OljS8Y5E8+7r?= =?us-ascii?Q?pXrGQEuPH3JqAGuEUrnwUdBaGwQtHrGpy+p4DO92cYipp6XfeNvuqmo0C5GC?= =?us-ascii?Q?b+o5HsJs5gSCl1TCycuJHlHD87KX/RlnI29u5CxcfebVOqBlV8xod9DIUXCg?= =?us-ascii?Q?dEp3tgoTMxxrLWCD8AsXHFl2K5OuNVV/vCEu0c3Gly6364UDoj2YKN+5evXl?= =?us-ascii?Q?DIdLnnfErBjwxf8OFVmDd8e/RkNIQnOlrC68naRxjchI6lvLSwY9vR+9x/bN?= =?us-ascii?Q?KYAJVc75+QntuZwSq3g0+sPdfa+B9Re3/3ZxWfTfacvw894qc6o2m5vbK/vQ?= =?us-ascii?Q?H8BdouDHvSmY2zZ03sICC2krhlj3Ex8La6agLjlIN2TMw8WcGjDuCWHIVNXj?= =?us-ascii?Q?42QNTdDzpRnwTqqSnwm1QMDWfTB/hDCVcETATLVg1JR3dYxn5xBQcDtmb9YJ?= =?us-ascii?Q?odk8W/L5vym/LOm22WBc0J236g5ebcV6TpMivzlG7NJmNwKpRm8E6WvoJ/b+?= =?us-ascii?Q?wG8DjUdNy59vo/sa96mwQPuRqI2zB0bNsgkr/aHzo1qxtwm+QqPp9QPtm2v3?= =?us-ascii?Q?pzRBLrAwxZY8VGQTkPOvPAtzezcxdzB0aLl6CP5rU3qccvxRPAEBnpQsUuLP?= =?us-ascii?Q?cRyB4ubS2xMvzEDECwNQ5FjbtYybeKCgotbTaT0IV1eh20PyUank9TaUhpnP?= =?us-ascii?Q?TQCquvfZLhOG9YyYphyN/dQeTs+45aJgqbK5SxeahrGgdY0eXqBRX8H1EfTE?= =?us-ascii?Q?wC98LOufJk2SQz+yIXT6nLR4bwbH5Wd3hW2+o/bsImI0XU6Vojtz1adTJUc1?= =?us-ascii?Q?DPwm9w5XsjNA8lkWfx5Da8=3D?= X-Microsoft-Antispam-Message-Info: PzZMPzEnLst6e3XHPrIBv9uFegtgrFNBVpCzrYdGSDqdYBTA1BrQd0lVySeR29ix9vd5JX//Z5Fj00jKgHOlrNYW7YeE7u/psaGDdAOT25XDIn1lM7C09C1KSbJH33T7o1gS/on9Q6oJ3PyY4o7+WQ4lkwBffN+Le0M+pOwjKF1i7L5wrBRxWoInrmUpuE3E X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2476; 6:aj7oFtnxt48kghnpZa5aiOCkDz5ybzCZ2bB8s/EvgQDVtTrRQAa8XX82cPeHWmOTuIno9fGaD32s7tB3OMk2NsxnK66ZKE2/xh8uOmtJuwm77c+VvG00d01ZPznZPXSnCVitBc4Nq0Zk6a7wfwgs+W514MM7mThIvbiCxVXr4Ejf2g1kP3LnGEvrJIklIghnv1vIvfSmc8qXYZWN36tHKJxDdvOg2tC395lvang6+LMwaaVyLqKUR/9nLyfEMsH2uPjDbzC+sH4MrzfEl552e5RJIuHqHRC4Yiw05mEe6vYq5rB5SEZmvPdpTTrAxxiIKGZRUU5cKxP10qovMWuFD+ATSfxVW+qNNVaoEXfbnhHuKXzknQ1pzB0TC3jSxxaxGXn4838vBkKKZE+t4zx2qcePIODILY/4MNHI77g/YrKLE3xSmbw4TxI6wqd44XaknL3waM4xETITvBI0F3R98A==; 5:rAQkJuL2wrbHCpZ1HctN+i53brdwDYRLZCu5oA+dRG/6OJSl/DxETPDBLbzrxnHPiWFFuPFR8vVfCx+MU+R12bRR+zuwY2ZweUid6nInc8OWu3iUM3qPLwNeSk3yuEplP8G0J4SRbjqqsHt+X5ZpBJUsosdOlcllwVsL1ZitM4g=; 24:GCOT/BWHYbeVIijpi2UTvkWvW0mPzA7hqQ05UR3UT+oZHKd6ZULQy9FRpfhU3IH5yCDILxExH4sjjySRZCE9KDDAthBNSyVwL9ZxOlq1OUs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MW2PR12MB2476; 7:2Mu1fnnRpBsdtMSEV9d5I7mO9i6zKKIIvtRwv+n6Jq9uB7iCnYQGyG1QcNRHH6MHP7xBrXP1FPQulACjadH4NmEk6vj9ayHT9LOeoFOIOOdxJqiR1IBJBKhFZXVk5bdEpO96ywMd1ez3pOt1db1c6M3XtnrNwoj+O8w2c3NpfOfmf9e3b6bSGD2ujRS1IgfQZkbvauJZJWiSUyjgcuNkHl89SEN5OCpE0iC5ay9WjXB3UuJGUaon9Xe6Joq5aWa0; 20:VqmTHG/4xf+E52WFQueZtjAKPiLq6jOkTgyUT+FXps6w6dBQpeiHIvEr4SSlBvktA2bLhxPYOM+piMERab4iHI+szKMOuFfS4uPAc6iCWIrceQzpVrTVfXj0aneNimvLkplBzl5N0XHzV8sbIDhXz+JZhhi4Abgh44oF5JZQoSOdcbIIeu0Vj34csY625rFNJjAswk8UTgFwZygggoKahWKHlPALDWAIzMyWgKAiiUXtVR3XeODXcWV6wclKaZ89 X-MS-Office365-Filtering-Correlation-Id: 1032e145-ae42-479c-e92c-08d5b9b9a815 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2018 16:42:17.3670 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1032e145-ae42-479c-e92c-08d5b9b9a815 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 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 | 145 +++++++++++++++++++++------------------------- target/i386/cpu.h | 14 +++-- 2 files changed, 75 insertions(+), 84 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 7f40241786..c06a9f5ebe 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1156,7 +1156,7 @@ struct X86CPUDefinition { }; static CPUCaches epyc_cache_info = { - .l1d_cache = { + .l1d_cache = &(CPUCacheInfo) { .type = DCACHE, .level = 1, .size = 32 * KiB, @@ -1168,7 +1168,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, @@ -1180,7 +1180,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, @@ -1190,7 +1190,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, @@ -3384,9 +3384,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 */ @@ -3737,21 +3736,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 */ @@ -3764,35 +3753,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; } @@ -4005,13 +3986,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) */ @@ -4027,17 +4003,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; @@ -4080,34 +4049,22 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, break; case 0x8000001D: *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_amd; - l1i = &legacy_l1i_cache_amd; - l2 = &legacy_l2_cache_amd; - l3 = &legacy_l3_cache; - } switch (count) { case 0: /* L1 dcache info */ - encode_cache_cpuid8000001d(l1d, cs->nr_threads, - eax, ebx, ecx, edx); + encode_cache_cpuid8000001d(env->cache_info_amd.l1d_cache, + cs->nr_threads, eax, ebx, ecx, edx); break; case 1: /* L1 icache info */ - encode_cache_cpuid8000001d(l1i, cs->nr_threads, - eax, ebx, ecx, edx); + encode_cache_cpuid8000001d(env->cache_info_amd.l1i_cache, + cs->nr_threads, eax, ebx, ecx, edx); break; case 2: /* L2 cache info */ - encode_cache_cpuid8000001d(l2, cs->nr_threads, - eax, ebx, ecx, edx); + encode_cache_cpuid8000001d(env->cache_info_amd.l2_cache, + cs->nr_threads, eax, ebx, ecx, edx); break; case 3: /* L3 cache info */ - encode_cache_cpuid8000001d(l3, cs->nr_threads, - eax, ebx, ecx, edx); + encode_cache_cpuid8000001d(env->cache_info_amd.l3_cache, + cs->nr_threads, eax, ebx, ecx, edx); break; default: /* end of info */ *eax = *ebx = *ecx = *edx = 0; @@ -4770,6 +4727,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); @@ -5252,11 +5240,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 1f9ccd47d9..e64b7da997 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 { @@ -1289,7 +1289,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];