From nobody Mon Feb 9 19:30:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1639606940; cv=none; d=zohomail.com; s=zohoarc; b=g0zfNKjs7vspQ0rPJEMXVQz2WhQfFRnW5GSUpXMNmd4tqIOiCqld5z0aYl4bootoUD5V08o2ErisgWud+j95BFJz8d1SQrmpzTtPCY/LGksLVuV2J2Kg1E0GOggnMCAa2ZCsHgCGkKRKFySbVpOYMxqu4Z023YdHDntUqUX9Ciw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639606940; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lct/efNtDFjn2LwVR3W1kW13PfqkR3qYBxTvjyUj8pM=; b=CsrGn0F9NtnV6b+PFXq836pQGr+U7mQSSwJOQLSQ416LpedpH3PHY633XO8+qYK+oS5AUE3jXngAW9G2sYrvOPuJeJnqsBr66m/AA35YKG17hF4GF9vtCeCpZaVsfJUzOVkclM0KNk68sqtxlkehbdKsaYDact/ThI6Pd+o1Rmc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1639606940863860.3750191565922; Wed, 15 Dec 2021 14:22:20 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.247619.427007 (Exim 4.92) (envelope-from ) id 1mxceg-0005ut-Pa; Wed, 15 Dec 2021 22:21:46 +0000 Received: by outflank-mailman (output) from mailman id 247619.427007; Wed, 15 Dec 2021 22:21:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mxceg-0005ug-Jk; Wed, 15 Dec 2021 22:21:46 +0000 Received: by outflank-mailman (input) for mailman id 247619; Wed, 15 Dec 2021 22:21:45 +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 1mxcef-0005ZJ-Mx for xen-devel@lists.xenproject.org; Wed, 15 Dec 2021 22:21:45 +0000 Received: from esa5.hc3370-68.iphmx.com (esa5.hc3370-68.iphmx.com [216.71.155.168]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 620a7ecf-5df5-11ec-9e60-abaf8a552007; Wed, 15 Dec 2021 23:21:43 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 620a7ecf-5df5-11ec-9e60-abaf8a552007 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1639606904; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=x7dgLyygTieu5IPGh9PaNnQdDucWMUK0ck0vN46ZQe0=; b=byCEMiZw4MKNEKkANXCa6N9y3etkM51+1/2PWZ6mi5+0G/A6QIOlHVmY E1qi3qCqUCiM/wDLF0c3wn4p3UD1U+NIp+OQk/E9je0cfn/P7fM9OY5rz m7wClo85gFnXEeVA/pxYGvReUehJgmTAzvPJtBpFQql1y474SbQektdZr A=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: B+uNPfy2nMfU3sOoyVOiRequXFFuiYR57zcsfX2zsEcXeV68gNmZpJ8hf+DjDYi84FjSZkA7EN fX9y/MZDBnh91QVIJ4g1gnpdApt7WTW65Aq7kCLPhD8YCKzOQlxF4tkSTA3l7hHRGSwW9mRO91 QczXBawPOQlibfduiGaw2ChaSIigxA2RJd/5qoTyRoFM7Nt0eX9JvhNA8FsKuqDijlOcoeEmcA rRKr17PS16a+RL9fQ8d0DQuch+QAeMzo911F+WJbzt1mo9OA7pPc5J88ggAjFGwUNs843GXe5v pvaYM8ySv+2IoasRIEjZr9GX X-SBRS: 5.1 X-MesageID: 59629092 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:iQAcgKAEp/YpWxVW/+Tkw5YqxClBgxIJ4kV8jS/XYbTApG5z1TAAx mQcUDrVPfiKZzakKY0jPIXi9E5QvpDcnIBnQQY4rX1jcSlH+JHPbTi7wuYcHM8wwunrFh8PA xA2M4GYRCwMo/u1Si6FatANl1ElvU2zbue6WL6s1hxZH1c+EX570E87wIbVv6Yz6TSHK1LV0 T/Ni5W31G+Ng1aY5UpNtspvADs21BjDkGtwUm4WPJinj3eH/5UhN7oNJLnZEpfNatI88thW5 Qr05OrREmvxp3/BAz4++1rxWhVirrX6ZWBihpfKMkQLb9crSiEai84G2PQghUh/kinYkvpek 4l2v4GOeTcwHPyUm6MSTEwNe81+FfUuFL7vJHG+tYqYzlHccmuqyPJrZK00FdRGoKAtWzgIr KFGbmBWBvyAr7veLLaTY+9gnMk8auLsO5sSoCpIxjDFF/c2B5vERs0m4PcFjWlq15gfR54yY eIcZDxXMlffRCFjPws4JYM8meGCunrWJmgwRFW9+vNsvjm7IBZK+KfpGMrYfJqNX8o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9Y04lQ7vn2YSXRuHPBw8P re5cjztCWE7gr5N0tBpTntAsW9qDbnhPtICOoqTNCftWvdyQiVxehZhOOIqVDd8m/Fh4pgPM 9bAtBD4bbLbGSS4/yU3ODBKadD/OW6 X-IronPort-AV: E=Sophos;i="5.88,209,1635220800"; d="scan'208";a="59629092" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [PATCH v2 2/4] x86/cpuid: Factor common parsing out of parse_xen_cpuid() Date: Wed, 15 Dec 2021 22:21:13 +0000 Message-ID: <20211215222115.6829-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20211215222115.6829-1-andrew.cooper3@citrix.com> References: <20211215222115.6829-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1639606941711100002 dom0-cpuid=3D is going to want to reuse the common parsing loop, so factor = it out into parse_cpuid(). Irritatingly, despite being static const, the features[] array gets duplica= ted each time parse_cpuid() is inlined. As it is a large (and ever growing with new CPU features) datastructure, move it to being file scope so all inlines use the same single object. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu v2: * New We probably want to be wary of fallout from this pattern elsewhere. I only noticed it by chance. --- xen/arch/x86/cpuid.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index f63f5efc17f5..e11f5a3c9a6b 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -26,17 +26,26 @@ static const uint32_t __initconst hvm_hap_def_featurema= sk[] =3D INIT_HVM_HAP_DEF_FEATURES; static const uint32_t deep_features[] =3D INIT_DEEP_FEATURES; =20 -static int __init parse_xen_cpuid(const char *s) +static const struct feature_name { + const char *name; + unsigned int bit; +} feature_names[] __initconstrel =3D INIT_FEATURE_NAMES; + +/* + * Parse a list of cpuid feature names -> bool, calling the callback for a= ny + * matches found. + * + * always_inline, because this is init code only and we really don't want a + * function pointer call in the middle of the loop. + */ +static int __init always_inline parse_cpuid( + const char *s, void (*callback)(unsigned int feat, bool val)) { const char *ss; int val, rc =3D 0; =20 do { - static const struct feature { - const char *name; - unsigned int bit; - } features[] __initconstrel =3D INIT_FEATURE_NAMES; - const struct feature *lhs, *rhs, *mid =3D NULL /* GCC... */; + const struct feature_name *lhs, *rhs, *mid =3D NULL /* GCC... */; const char *feat; =20 ss =3D strchr(s, ','); @@ -49,8 +58,8 @@ static int __init parse_xen_cpuid(const char *s) feat +=3D 3; =20 /* (Re)initalise lhs and rhs for binary search. */ - lhs =3D features; - rhs =3D features + ARRAY_SIZE(features); + lhs =3D feature_names; + rhs =3D feature_names + ARRAY_SIZE(feature_names); =20 while ( lhs < rhs ) { @@ -72,11 +81,7 @@ static int __init parse_xen_cpuid(const char *s) =20 if ( (val =3D parse_boolean(mid->name, s, ss)) >=3D 0 ) { - if ( !val ) - setup_clear_cpu_cap(mid->bit); - else if ( mid->bit =3D=3D X86_FEATURE_RDRAND && - (cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_RDRAND)= ) ) - setup_force_cpu_cap(X86_FEATURE_RDRAND); + callback(mid->bit, val); mid =3D NULL; } =20 @@ -95,6 +100,20 @@ static int __init parse_xen_cpuid(const char *s) =20 return rc; } + +static void __init _parse_xen_cpuid(unsigned int feat, bool val) +{ + if ( !val ) + setup_clear_cpu_cap(feat); + else if ( feat =3D=3D X86_FEATURE_RDRAND && + (cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_RDRAND)) ) + setup_force_cpu_cap(X86_FEATURE_RDRAND); +} + +static int __init parse_xen_cpuid(const char *s) +{ + return parse_cpuid(s, _parse_xen_cpuid); +} custom_param("cpuid", parse_xen_cpuid); =20 #define EMPTY_LEAF ((struct cpuid_leaf){}) --=20 2.11.0