From patchwork Wed Aug 9 12:29:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 13347882 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A6C9EB64DD for ; Wed, 9 Aug 2023 12:30:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.581039.909547 (Exim 4.92) (envelope-from ) id 1qTiJx-0000Wk-CI; Wed, 09 Aug 2023 12:29:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 581039.909547; Wed, 09 Aug 2023 12:29:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qTiJx-0000Wd-9b; Wed, 09 Aug 2023 12:29:49 +0000 Received: by outflank-mailman (input) for mailman id 581039; Wed, 09 Aug 2023 12:29:47 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qTiJv-0000WR-PM for xen-devel@lists.xenproject.org; Wed, 09 Aug 2023 12:29:47 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2060f.outbound.protection.outlook.com [2a01:111:f400:7e1a::60f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6cc5f5b0-36b0-11ee-b280-6b7b168915f2; Wed, 09 Aug 2023 14:29:46 +0200 (CEST) Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by DU2PR04MB8792.eurprd04.prod.outlook.com (2603:10a6:10:2e3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.25; Wed, 9 Aug 2023 12:29:44 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::e5cf:5743:ab60:b14e]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::e5cf:5743:ab60:b14e%5]) with mapi id 15.20.6652.025; Wed, 9 Aug 2023 12:29:44 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6cc5f5b0-36b0-11ee-b280-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U7sGYmwSz5Wa0LUVrmfr0xxJ7Ngy/9ayMytBl/nykxdwou5fWxq52x8g+y94tMN+vvXvXG9v+aVQ3FwNrDhXb4YnzFS/LsDs3CaTv7Jj3I56a5iw/wSUKoiTVBt29KA7fRlIQ01gWGoZN/nIgG/TRuhtB/YjgQaWeVxJcWcpS2IaqN2iLMfXmow/XMXMt7e2TT+4C31sANGTlMkdwTd8wljSHSQZ9SAgIe0ZMv8oLRNa3Q2kZqPowCGZR1ORIDxA/mZGVYwN6wo34pG0vNBiveioj38j2H0+RYr6bBV52QHTko/wZXdRvJTXsNR3jgFTmaMR6RCp3eO5GQR3qM3MRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LELKa6p2/OKxQTGmguNp2vkQIbLmcSv+nDELPfyHX3Y=; b=gGJ82yNCR2LEMpVVcCFkfrGA6drxkegawsZ6Wg6HtZZpujN111RzldSRXQUTwZL5ZxXC9bAf9Nbrie79xEcRGgmf7eDWBTIUMvXnSgWY9qPVLX5xxtBG1m1U4QQmjVhZ4hpIzpmZ/m2/YefIhwEoj6d1d8wx+/M1fBmz8OG6fAEO1FmwYeV7HT3B/csq1nXTqiNMjbAJki7i2BPQd4qLiW2P2DW/UCxBALAZyJSzDfyUYd6HuSbp/sG/6Qkpch51gAMum23fjp7nqjgBq8Z/WlmbyvHCWQWjDmnE/8ZpwHKW76F+NHk9vkew9pXfBuN5USJHH9C+cjUCdcZuBHZZ7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LELKa6p2/OKxQTGmguNp2vkQIbLmcSv+nDELPfyHX3Y=; b=bleYAoSlVQPUrrr/NnBT18l+lb1dnHOxHPSScWhx+9Izw912Kv7o48p1+vWWsPtS1CwUcp8kCNChNXCeah42/tgB876+LTbu/NkoGSlxqaVWDLfQTl/vO82WpBzwbV0yNpq+DqUK84AMdFr8znD8R5TkVD88cO5KLADlcUUKrHsgJ6R3IYOgvBBTdxaaEqGbu4tu2Uak/wOAXJVLYmMyTeAFLPmVyFmiZtNVEf57WENpMqKfe1CP9iWYKldCMweUbszgMeXNV6UpuNWqcLSu8YVEnF1Wpu7FKaDqPcyn1VAO83A2Y51Gloiv/nIKpWkYiAxp2O/TywYCu1+rekc2yQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <9c310f74-e6c3-f86e-8044-0e078ad00254@suse.com> Date: Wed, 9 Aug 2023 14:29:42 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Content-Language: en-US To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= From: Jan Beulich Subject: [PATCH] x86: implement cpuid() in terms of cpuid_count() X-ClientProxiedBy: FR0P281CA0053.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:48::17) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|DU2PR04MB8792:EE_ X-MS-Office365-Filtering-Correlation-Id: ae78f145-0cc8-475b-8e72-08db98d44f97 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6lkCR7uR07mgRP4dtBnkED1EVZQ9/jTzt8NvNexrIrAeu4xLnmzhtCtSEvW2XNAh9FjDc+uB8jCkiza8lJZwuXBOhbv1S8psu/SSR0ejJHv/vyYzj9woCmNisMa+wWivxOoUHJuzyLyHEwHmTfLhqrF/iMO5G/J5vUR+8n74Rq2lNtF1QbMFzpiJXZaRM+hd6gGYutGv/KSYtVqzmk1YQA4q1pI/Qy1yllktP3/1AhZJvGLk8q0VlEgH49yF5V0D8tX4nZiNFXqhKb86iU8ZaxpS3WQ3wdbT1S1V0BSeCdrMQdNoFqqfcb0iAc4dswfKzFx3NZfcAETVSkgtV6GdIWoS7veXvlta9Va2C4X4aWcei8F1ADv2uCCZkVqXVnVqhamokf9NGEU/IwmBUmrCsRvll+qzj//Cr9BnCmLvTZbnfL66QGDcTvCRhLwRZatiULgWjG6OW2FugxxZ0vwgGE7v6SItpiJ/IocMYVsJHqRZ0/+W1HQcs0pKbjym6bhFxkNzmYnLTYaakF+jZgL/PkduyZl5vh7lTK2lzx2k0mpSxde6Jva1MWde0P2s31SWDPZoo21INX0brjxHI6ib+tFXlHrI1ckz6OpVm31zbRn7nvuXUBh9rTYmhWJCYF4nqHnYsdEYVGtowKc32nGbjw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(366004)(136003)(396003)(39860400002)(376002)(346002)(1800799006)(186006)(451199021)(8936002)(8676002)(54906003)(478600001)(5660300002)(31686004)(41300700001)(6916009)(316002)(4326008)(38100700002)(66476007)(66946007)(66556008)(86362001)(6506007)(31696002)(26005)(2906002)(6486002)(36756003)(6512007)(83380400001)(2616005)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?UkvpctmOg0fAPYG9X7wam79+SvUQ?= =?utf-8?q?qr1m1xH4FtPd2mcOZQpWKUZe49VjKMlvz+na58DSkUqI3xQv1+0yz6E2J6ZV1vm+o?= =?utf-8?q?a/1Z0mbHBCoKDnUcxsAF8W1Gv10SxysSKIcBreFy2wPuGyKvk7gYSCYvL/l5k5Fcs?= =?utf-8?q?Gg4TWXNZXPce7/Ya0vpHkX+L8PklAhWsv8sdOCBas9V419bNAW78ZZEXiSH4d40pn?= =?utf-8?q?Cxxj+RlJPyaSc0ekKaMzuLacBAHmyG1igWOEy2n+D3jWZUTMAMwC5HFyZ046x/Wyc?= =?utf-8?q?+2D9n6pGQTPJEwka9t/ODxurIZAgUptRaXvU03X9UCbKSUzrRpAYnY6pxR7dD7bRH?= =?utf-8?q?yQPXxNbcXJujBayMeKg85d+HmQs5GgpDG3HMQSjJro+OdAK91IsvKAz8aUC5gDlwr?= =?utf-8?q?ElBVmqPyZunT2YtQ3QDY1JNoQba3LpqgxQj3mJkC8L7tefqpSYtt3b/EJGkBUUHdN?= =?utf-8?q?YR5IgD8+d42c5qa+iEmNJ41dL6qWoHQ44BEXKy5tiuVsTbp7jjoRuw14Un1lUGQ8O?= =?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klHWknfwYw45Ex3zGWUe7Bt7gPcuMvULMilFh7o2wJxRoPkNQ/ca89ZKb3l4O?= =?utf-8?q?Iai6+CANjIlSzWEeeudHY+pAIUE9v+d8ksj5oC0/l6uIO0f0pC2Ngg9uGywJpYvK7?= =?utf-8?q?WO1YLz+7zeOU?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ae78f145-0cc8-475b-8e72-08db98d44f97 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2023 12:29:43.9984 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lhKpWYnX0TH78yS0snOnl5XE8xC02Qny6um8pJ51NbRAsaQCRtNxHOid/KlSXtJhRSPfugiAM63iAnLzoz+Jnw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8792 Since as a bug workaround (likely inapplicable to any 64-bit CPUs, but it probably doesn't hurt to keep this) we clear %ecx on input anyway, we can as well fall back to cpuid_count(). This allows getting rid of four risky casts and makes things type-safe. The latter aspect requires two type adjustments elsewhere. While adjusting init_intel_cacheinfo(), convert three other local variables there as well. For the struct cpuinfo_x86 change it is relevant to note that no 64-bit CPU comes without CPUID support, and hence cpuid_level is never set to -1; the comment there was simply stale. No functional change intended, yet of course generated code isn't identical. Signed-off-by: Jan Beulich --- It may also be interesting to see whether this addresses issues Coverity recently spotted (in error), in spec-ctrl.c:print_details(). Andrew considers cpuid() being (just) a macro as a possible reason. I'm willing to switch to an inline function, but I chose the macro route because this way it's less code (and hence less redundancy) overall, without any loss of functionality. --- a/xen/arch/x86/cpu/intel_cacheinfo.c +++ b/xen/arch/x86/cpu/intel_cacheinfo.c @@ -172,8 +172,7 @@ void init_intel_cacheinfo(struct cpuinfo c->x86_vendor != X86_VENDOR_SHANGHAI) { /* supports eax=2 call */ - int i, j, n; - int regs[4]; + unsigned int i, j, n, regs[4]; unsigned char *dp = (unsigned char *)regs; int only_trace = 0; --- a/xen/arch/x86/include/asm/cpufeature.h +++ b/xen/arch/x86/include/asm/cpufeature.h @@ -23,7 +23,7 @@ struct cpuinfo_x86 { unsigned char x86_vendor; /* CPU vendor */ unsigned char x86_model; unsigned char x86_mask; - int cpuid_level; /* Maximum supported CPUID level, -1=no CPUID */ + unsigned int cpuid_level; /* Maximum supported CPUID level */ unsigned int extended_cpuid_level; /* Maximum supported CPUID extended level */ unsigned int x86_capability[NCAPINTS]; char x86_vendor_id[16]; --- a/xen/arch/x86/include/asm/processor.h +++ b/xen/arch/x86/include/asm/processor.h @@ -131,13 +131,8 @@ static inline int cpu_nr_siblings(unsign * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx * resulting in stale register contents being returned. */ -#define cpuid(_op,_eax,_ebx,_ecx,_edx) \ - asm volatile ( "cpuid" \ - : "=a" (*(int *)(_eax)), \ - "=b" (*(int *)(_ebx)), \ - "=c" (*(int *)(_ecx)), \ - "=d" (*(int *)(_edx)) \ - : "0" (_op), "2" (0) ) +#define cpuid(op, eax, ebx, ecx, edx) \ + cpuid_count(op, 0, eax, ebx, ecx, edx) /* Some CPUID calls want 'count' to be placed in ecx */ static inline void cpuid_count(