From patchwork Thu Sep 5 19:49:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11133881 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 964C1112B for ; Thu, 5 Sep 2019 19:50:53 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4892D20640 for ; Thu, 5 Sep 2019 19:50:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="EYiT5/DH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4892D20640 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Inumbo-ID: 3c5ce21c-d016-11e9-abda-12813bfff9fa 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) 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 (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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 equals signs as well. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné 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[] = INIT_DEEP_FEATURES; static int __init parse_xen_cpuid(const char *s) { + static const struct feature { + const char *name; + unsigned int bit; + } features[] __initconst = INIT_FEATURE_NAMES, *lhs, *mid, *rhs; const char *ss; int val, rc = 0; do { + const char *feat; + ss = strchr(s, ','); if ( !ss ) ss = strchr(s, '\0'); - if ( (val = parse_boolean("md-clear", s, ss)) >= 0 ) - { - if ( !val ) - setup_clear_cpu_cap(X86_FEATURE_MD_CLEAR); - } - else if ( (val = parse_boolean("ibpb", s, ss)) >= 0 ) - { - if ( !val ) - setup_clear_cpu_cap(X86_FEATURE_IBPB); - } - else if ( (val = parse_boolean("ibrsb", s, ss)) >= 0 ) - { - if ( !val ) - setup_clear_cpu_cap(X86_FEATURE_IBRSB); - } - else if ( (val = parse_boolean("stibp", s, ss)) >= 0 ) - { - if ( !val ) - setup_clear_cpu_cap(X86_FEATURE_STIBP); - } - else if ( (val = parse_boolean("l1d-flush", s, ss)) >= 0 ) - { - if ( !val ) - setup_clear_cpu_cap(X86_FEATURE_L1D_FLUSH); - } - else if ( (val = parse_boolean("ssbd", s, ss)) >= 0 ) + /* Skip the 'no-' prefix for name comparisons. */ + feat = s; + if ( strncmp(s, "no-", 3) == 0 ) + feat += 3; + + /* (Re)initalise lhs and rhs for binary search. */ + lhs = features; + rhs = features + ARRAY_SIZE(features); + + while ( lhs < rhs ) { - if ( !val ) - setup_clear_cpu_cap(X86_FEATURE_SSBD); + int res; + + mid = lhs + (rhs - lhs) / 2; + res = cmdline_strcmp(feat, mid->name); + + if ( res < 0 ) + { + rhs = mid; + continue; + } + if ( res > 0 ) + { + lhs = mid + 1; + continue; + } + + if ( (val = parse_boolean(mid->name, s, ss)) >= 0 ) + { + if ( !val ) + setup_clear_cpu_cap(mid->bit); + mid = NULL; + } + + break; } - else + + /* + * Mid being NULL means that the name and boolean were successfully + * identified. Everything else is an error. + */ + if ( mid ) rc = -EINVAL; s = 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 == '\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 == '\0' && (f == ',' || f == ':' || f == ';') ) + if ( n == '\0' && (f == ',' || f == ':' || f == ';' || f == '=') ) res = 0; 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); /** * 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); 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 = open_file_or_fd(output, "w", 2) # State parsed from input - self.names = {} # Name => value mapping + self.names = {} # Value => Name mapping + self.values = {} # Name => Value mapping self.raw_special = set() self.raw_pv = set() self.raw_hvm_shadow = set() @@ -76,8 +77,9 @@ def parse_definitions(state): this_name = name setattr(this, this_name, val) - # Construct a reverse mapping of value to name + # Construct forward and reverse mappings between name and value state.names[val] = name + state.values[name.lower().replace("_", "-")] = val for a in attr: @@ -403,6 +405,22 @@ def write_results(state): state.output.write( """} +#define INIT_FEATURE_NAMES { \\ +""") + + try: + _tmp = state.values.iteritems() + except AttributeError: + _tmp = state.values.items() + + for name, bit in sorted(_tmp): + state.output.write( + ' { "%s", %sU },\\\n' % (name, bit) + ) + + state.output.write( +"""} + """) for idx, text in enumerate(state.bitfields):