From nobody Fri Mar 29 14:36:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1567713034; cv=none; d=zoho.com; s=zohoarc; b=ZhbaoIpO0AHedrKvqqLkEU7l3BeFlDU74j0lGlWj2ED4cMV3MoPVmpMYINxsvol19S5DOnSm1sf3jNFvCxSHQXHVu8vnueSZTJfXXWPb2aaoCVHI/YiAUz/LT6Ynr6QrI7w2Fu6YFjpFQeYmbohL2YM94GWAKVCT9ygu05bhFck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567713034; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=BCvcyxEc383obEb2aWs5n3dDOONbHaDHlVVV3ZD/MTw=; b=ebgfkyIkzk+PycVBDLPcuFyldhKbxNYAEvDXXVE2QchaoZA0/luRnwfAseLS/cWKJ8xHld2yqqBn70L4c/4tYwrvTDUIT6fmwNsZK59+D0/M0bH/IWycu/V0Xs/eg3tfs4QfIo7bRizxTBI1j1BA7ivKPPp5k+7iDrF6VpDlZeY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1567713033922196.2640412259475; Thu, 5 Sep 2019 12:50:33 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i5xku-0005rW-P6; Thu, 05 Sep 2019 19:49:20 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i5xkt-0005rR-IV for xen-devel@lists.xenproject.org; Thu, 05 Sep 2019 19:49:19 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3c5ce21c-d016-11e9-abda-12813bfff9fa; Thu, 05 Sep 2019 19:49:13 +0000 (UTC) X-Inumbo-ID: 3c5ce21c-d016-11e9-abda-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1567712954; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=FIhNO251hZMbaP7FsfIlSVyyIpWXXZaPXhtKgZGWtlI=; b=EYiT5/DH0tg34DXueG1FJQN3Sjfh+oB5RnDfAI+d5xlwuHmc0zm3aaCo j2I4m54bJQhR+33L8thOHKVKFKOFSvpNVlfis88jJkIIPHwGybEQ4Q9Q7 W4pgH0RVXDTVIi6SGz5IXx9lumcVJgmpnUazMYxgQE1ntzCrj46qpgL2r 8=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: H3qOUoz/3LtfCp8gymM9Y+SrcKmSuvWV9fUiNOTBDUcEVnzjuQM4FBHlxWXW7xIAmRjfOBIIRp NQ4s2jYtdPTGhalxm+9uzAUzDa9dymwRErebmLUiejV+9GKJ09ORfKNovyc8aJROdz+tl6mOoO 37ZMzqsHnhqwm+Xaat9RxxD77sSazZX5ck0O+DUI7YgEqDG+5O9JPoEapEeOeknk5Qve2YFCWw d9J5N4m2ozNFUmuA4Fy5ZHUq2ZkV1HCQt1QvBcaMtgrRyrxvPj3dWhlb8XP66L467036s5QXvQ Su0= X-SBRS: 2.7 X-MesageID: 5208238 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,471,1559534400"; d="scan'208";a="5208238" From: Andrew Cooper To: Xen-devel Date: Thu, 5 Sep 2019 20:49:09 +0100 Message-ID: <20190905194909.6811-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2] x86/cpuid: Extend the cpuid= option to support all named features X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) For gen-cpuid.py, fix a comment describing self.names, and generate the reverse mapping in self.values. Write out INIT_FEATURE_NAMES which maps a string name to a bit position. For parse_cpuid(), use cmdline_strcmp() and perform a binary search over INIT_FEATURE_NAMES. A tweak to cmdline_strcmp() is needed to break at equa= ls signs as well. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 v2: * Rebase over cmdline_strcmp() --- xen/arch/x86/cpuid.c | 75 +++++++++++++++++++++++++++++++---------------= ---- xen/common/kernel.c | 6 ++-- xen/include/xen/lib.h | 4 +-- xen/tools/gen-cpuid.py | 22 +++++++++++++-- 4 files changed, 71 insertions(+), 36 deletions(-) diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index ab1a48ff90..040c087689 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -21,45 +21,62 @@ static const uint32_t deep_features[] =3D INIT_DEEP_FEA= TURES; =20 static int __init parse_xen_cpuid(const char *s) { + static const struct feature { + const char *name; + unsigned int bit; + } features[] __initconst =3D INIT_FEATURE_NAMES, *lhs, *mid, *rhs; const char *ss; int val, rc =3D 0; =20 do { + const char *feat; + ss =3D strchr(s, ','); if ( !ss ) ss =3D strchr(s, '\0'); =20 - if ( (val =3D parse_boolean("md-clear", s, ss)) >=3D 0 ) - { - if ( !val ) - setup_clear_cpu_cap(X86_FEATURE_MD_CLEAR); - } - else if ( (val =3D parse_boolean("ibpb", s, ss)) >=3D 0 ) - { - if ( !val ) - setup_clear_cpu_cap(X86_FEATURE_IBPB); - } - else if ( (val =3D parse_boolean("ibrsb", s, ss)) >=3D 0 ) - { - if ( !val ) - setup_clear_cpu_cap(X86_FEATURE_IBRSB); - } - else if ( (val =3D parse_boolean("stibp", s, ss)) >=3D 0 ) - { - if ( !val ) - setup_clear_cpu_cap(X86_FEATURE_STIBP); - } - else if ( (val =3D parse_boolean("l1d-flush", s, ss)) >=3D 0 ) - { - if ( !val ) - setup_clear_cpu_cap(X86_FEATURE_L1D_FLUSH); - } - else if ( (val =3D parse_boolean("ssbd", s, ss)) >=3D 0 ) + /* Skip the 'no-' prefix for name comparisons. */ + feat =3D s; + if ( strncmp(s, "no-", 3) =3D=3D 0 ) + feat +=3D 3; + + /* (Re)initalise lhs and rhs for binary search. */ + lhs =3D features; + rhs =3D features + ARRAY_SIZE(features); + + while ( lhs < rhs ) { - if ( !val ) - setup_clear_cpu_cap(X86_FEATURE_SSBD); + int res; + + mid =3D lhs + (rhs - lhs) / 2; + res =3D cmdline_strcmp(feat, mid->name); + + if ( res < 0 ) + { + rhs =3D mid; + continue; + } + if ( res > 0 ) + { + lhs =3D mid + 1; + continue; + } + + if ( (val =3D parse_boolean(mid->name, s, ss)) >=3D 0 ) + { + if ( !val ) + setup_clear_cpu_cap(mid->bit); + mid =3D NULL; + } + + break; } - else + + /* + * Mid being NULL means that the name and boolean were successfully + * identified. Everything else is an error. + */ + if ( mid ) rc =3D -EINVAL; =20 s =3D ss + 1; diff --git a/xen/common/kernel.c b/xen/common/kernel.c index f7628d73ce..760917dab5 100644 --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -309,10 +309,10 @@ int cmdline_strcmp(const char *frag, const char *name) if ( res || n =3D=3D '\0' ) { /* - * NUL in 'name' matching a comma, colon or semicolon in 'frag' - * implies success. + * NUL in 'name' matching a comma, colon, semicolon or equals = in + * 'frag' implies success. */ - if ( n =3D=3D '\0' && (f =3D=3D ',' || f =3D=3D ':' || f =3D= =3D ';') ) + if ( n =3D=3D '\0' && (f =3D=3D ',' || f =3D=3D ':' || f =3D= =3D ';' || f =3D=3D '=3D') ) res =3D 0; =20 return res; diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h index ce231c5f4f..8fbe84032d 100644 --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -85,8 +85,8 @@ int parse_boolean(const char *name, const char *s, const = char *e); =20 /** * Very similar to strcmp(), but will declare a match if the NUL in 'name' - * lines up with comma, colon or semicolon in 'frag'. Designed for picking - * exact string matches out of a delimited command line list. + * lines up with comma, colon, semicolon or equals in 'frag'. Designed for + * picking exact string matches out of a delimited command line list. */ int cmdline_strcmp(const char *frag, const char *name); =20 diff --git a/xen/tools/gen-cpuid.py b/xen/tools/gen-cpuid.py index 836b010751..f76e80d690 100755 --- a/xen/tools/gen-cpuid.py +++ b/xen/tools/gen-cpuid.py @@ -19,7 +19,8 @@ def __init__(self, input, output): self.output =3D open_file_or_fd(output, "w", 2) =20 # State parsed from input - self.names =3D {} # Name =3D> value mapping + self.names =3D {} # Value =3D> Name mapping + self.values =3D {} # Name =3D> Value mapping self.raw_special =3D set() self.raw_pv =3D set() self.raw_hvm_shadow =3D set() @@ -76,8 +77,9 @@ def parse_definitions(state): this_name =3D name setattr(this, this_name, val) =20 - # Construct a reverse mapping of value to name + # Construct forward and reverse mappings between name and value state.names[val] =3D name + state.values[name.lower().replace("_", "-")] =3D val =20 for a in attr: =20 @@ -403,6 +405,22 @@ def write_results(state): state.output.write( """} =20 +#define INIT_FEATURE_NAMES { \\ +""") + + try: + _tmp =3D state.values.iteritems() + except AttributeError: + _tmp =3D state.values.items() + + for name, bit in sorted(_tmp): + state.output.write( + ' { "%s", %sU },\\\n' % (name, bit) + ) + + state.output.write( +"""} + """) =20 for idx, text in enumerate(state.bitfields): --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel