From nobody Wed May 8 08:57:02 2024 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=1639516616; cv=none; d=zohomail.com; s=zohoarc; b=l2j7wwf/lKdVkNQZ90YoNCc3uUJSyuR7g/fuOL1gVHWlkBSg3QrRozgWPkLIy55UErY6UOBg4JGzNuMWvWL+R7TjwooE1XZizo+wqh3irAS4yj+rSz04i+Kf3k6lebrkre+dnWcrOAuFlDvJxSCVIhg4t0UOxVxshJ7x4ZXEU8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639516616; 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; bh=b34E2uJcpMAWj5JIT4mNbHbLIG9lu9T1RGLOoqwsSe4=; b=Zz95/tIsQ3yVI47ibEj8mP4kSzVezRLhq6oTk1akU+wju2zdgnnrMGbOOgGIi12KCj0sjBUvcyJb59d4kP2L6K/1lBWpmEH5XiuC3ha2S8zcWQC9kPorpfoUTb7fcwBermByIUTwxuLctIgRjUQn9Fbk6EETeTSPwjFKLNnau7Q= 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 1639516616413555.5397787406639; Tue, 14 Dec 2021 13:16:56 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.247093.426100 (Exim 4.92) (envelope-from ) id 1mxF9z-00074C-5O; Tue, 14 Dec 2021 21:16:31 +0000 Received: by outflank-mailman (output) from mailman id 247093.426100; Tue, 14 Dec 2021 21:16:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mxF9z-000745-2A; Tue, 14 Dec 2021 21:16:31 +0000 Received: by outflank-mailman (input) for mailman id 247093; Tue, 14 Dec 2021 21:16:29 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mxF9x-00073z-MW for xen-devel@lists.xenproject.org; Tue, 14 Dec 2021 21:16:29 +0000 Received: from esa5.hc3370-68.iphmx.com (esa5.hc3370-68.iphmx.com [216.71.155.168]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 186a4ff5-5d23-11ec-85d3-df6b77346a89; Tue, 14 Dec 2021 22:16:27 +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: 186a4ff5-5d23-11ec-85d3-df6b77346a89 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1639516587; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=4bkx3TwcUrdcOyHKGlZDOQ8jcimHx5KjsB2hX06YZ+w=; b=AgLLQ+KQAt41mgyXx9dUvi4XV7IHlV13/6e0E7x2MpoLngbP7lNPJMvH YD35wOyiqb22FIGadLXpRs0g4E0j6c7SlowXx/ILgdHWShd2bzFOz7Naw PyRbnPFjZR659f+DdyuerpQwgBRQ2tS1kk7f2fzNfa9OUXIvd02R/Zl4A k=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: yc5EX/TepT8qErSTbH/kFzv5IVH8vEsdsFvwsICzdzgm10SRZ3YIityZwzlHWnvAEuu6xgGSid HhEPWmJSJ1ILt6qO3xIIEaiR8IEPXQKJgQcjoOLIf0F4202xU4YjnUiBIQIvQlOXIEjCKVqSNo B+UVDRfTZKE7slYjerzBprF+Fc5jHuglBg63U4XC/br4QD0gQidqki4aNmI31YSRJx/Gx27aQX VNrk0aYz21dU4lT4f37rT2sxxzA6LZtXZTgJYSwG2HSlY/vIGOoZCLfE9j5oojfD8jHXAO3ES8 4u6bWytdbS6s6i2LQm3DvdRM X-SBRS: 5.1 X-MesageID: 59527717 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:vXI7KKwAh+y7lO7SoiV6t+fUwSrEfRIJ4+MujC+fZmUNrF6WrkUAx mNLWGHSbviNZGXxLtgja4+1p0gCvpbdmNU3TlQ++yAxQypGp/SeCIXCJC8cHc8zwu4v7q5Dx 59DAjUVBJlsFhcwnvopW1TYhSEUOZugH9IQM8aZfHAhLeNYYH1500s6wbdl2tUAbeWRWGthh /uj+6UzB3f9s9JEGjp8B3Wr8U4HUFza4Vv0j3RmDRx5lAa2e0o9VfrzEZqZPXrgKrS4K8bhL wr1IBNVyUuCl/slIovNfr8W6STmSJaKVeSFoiI+t6RPHnGuD8H9u0o2HKN0VKtZt9mGt49Py tJ1v5aQcws0H7HXmcocbDpzIwgraMWq+JefSZS+mcmazkmAeHrw2fR+SkoxOOX0+M4uXzsIr 6ZBbmlQMFbT3Ipaw5riIgVoru0lINPmI8U0vXZ4wCuCJf0nXYrCU+PB4towMDIY25ETR6mBP pVxhTxHcRjYeDBTan4rI7UvmLf4mz6jcGJSgQfAzUYwyzeKl1EguFT3C/LKfvSaSMM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drOrdr: A9a23:8VTiFaiP3Yf/k4tTvngCoGDglXBQXtYji2hC6mlwRA09TySZ// rBoB19726StN9xYgBFpTnuAsm9qB/nmaKdgrNhWItKPjOW21dARbsKheCJrgEIcxeOkNK1vp 0AT0ERMrLN5CBB/KTH3DU= X-IronPort-AV: E=Sophos;i="5.88,206,1635220800"; d="scan'208";a="59527717" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Daniel Smith Subject: [PATCH] x86/cpuid: Introduce dom0-cpuid command line option Date: Tue, 14 Dec 2021 21:16:00 +0000 Message-ID: <20211214211600.2751-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 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: 1639516617813100001 Specifically, this lets the user opt in to non-default for dom0. Split features[] out of parse_xen_cpuid(), giving it a lightly more appropraite name, so it can be shared with parse_xen_cpuid(). Collect all dom0 settings together in dom0_{en,dis}able_feat[], and apply it to dom0's policy when other tweaks are being made. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Daniel Smith RFC, because I think we've got a preexisting error with late hwdom here. We really should not be cobbering a late hwdom's settings (which were provided= in the usual way by the toolstack in dom0). Furthermore, the distinction gets more murky in a hyperlaunch future where multiple domains may be constructed by Xen, and there is reason to expect t= hat a full toolstack-like configuration is made available for them. One option might be to remove the special case from init_domain_cpuid_polic= y() and instead make a call into the cpuid code from create_dom0(). It would h= ave to be placed between domain_create() and alloc_dom0_vcpu0() for dynamic siz= ing of the FPU block to work. Thoughts? --- docs/misc/xen-command-line.pandoc | 16 ++++++ xen/arch/x86/cpuid.c | 114 +++++++++++++++++++++++++++++++++-= ---- 2 files changed, 115 insertions(+), 15 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index f7797ea233f9..1278f9c27597 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -801,6 +801,22 @@ Controls for how dom0 is constructed on x86 systems. =20 If using this option is necessary to fix an issue, please report a bug. =20 +### dom0-cpuid + =3D List of comma separated booleans + + Applicability: x86 + +This option allows for fine tuning of the facilities dom0 will use, after +accounting for hardware capabilities and Xen settings as enumerated via CP= UID. + +Options are accepted in positive and negative form, to enable or disable +specific features. All selections via this mechanism are subject to normal +CPU Policy safety logic. + +This option is intended for developers to opt dom0 into non-default featur= es, +and is not intended for use in production circumstances. If using this op= tion +is necessary to fix an issue, please report a bug. + ### dom0-iommu =3D List of [ passthrough=3D, strict=3D, map-inclusive=3D<= bool>, map-reserved=3D, none ] diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index 151944f65702..896bc1595317 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -26,17 +26,18 @@ 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 const struct feature_name { + const char *name; + unsigned int bit; +} feature_names[] __initconstrel =3D INIT_FEATURE_NAMES; + static int __init parse_xen_cpuid(const char *s) { 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 +50,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 ) { @@ -97,6 +98,73 @@ static int __init parse_xen_cpuid(const char *s) } custom_param("cpuid", parse_xen_cpuid); =20 +static uint32_t __hwdom_initdata dom0_enable_feat[FSCAPINTS]; +static uint32_t __hwdom_initdata dom0_disable_feat[FSCAPINTS]; + +static int __init parse_dom0_cpuid(const char *s) +{ + const char *ss; + int val, rc =3D 0; + + do { + const struct feature_name *lhs, *rhs, *mid =3D NULL /* GCC... */; + const char *feat; + + ss =3D strchr(s, ','); + if ( !ss ) + ss =3D strchr(s, '\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 feature_names; + rhs =3D feature_names + ARRAY_SIZE(feature_names); + + while ( lhs < rhs ) + { + 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 ) + { + __set_bit(mid->bit, + val ? dom0_enable_feat : dom0_disable_feat); + mid =3D NULL; + } + + break; + } + + /* + * Mid being NULL means that the name and boolean were successfully + * identified. Everything else is an error. + */ + if ( mid ) + rc =3D -EINVAL; + + s =3D ss + 1; + } while ( *ss ); + + return rc; +} +custom_param("dom0-cpuid", parse_dom0_cpuid); + #define EMPTY_LEAF ((struct cpuid_leaf){}) static void zero_leaves(struct cpuid_leaf *l, unsigned int first, unsigned int last) @@ -727,17 +795,33 @@ int init_domain_cpuid_policy(struct domain *d) if ( !p ) return -ENOMEM; =20 - /* The hardware domain can't migrate. Give it ITSC if available. */ if ( is_hardware_domain(d) ) + { + uint32_t fs[FSCAPINTS]; + unsigned int i; + + /* The hardware domain can't migrate. Give it ITSC if available. = */ p->extd.itsc =3D cpu_has_itsc; =20 - /* - * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to do= m0, - * so dom0 can turn off workarounds as appropriate. Temporary, until = the - * domain policy logic gains a better understanding of MSRs. - */ - if ( is_hardware_domain(d) && cpu_has_arch_caps ) - p->feat.arch_caps =3D true; + /* + * Expose the "hardware speculation behaviour" bits of ARCH_CAPS to + * dom0, so dom0 can turn off workarounds as appropriate. Tempora= ry, + * until the domain policy logic gains a better understanding of M= SRs. + */ + if ( cpu_has_arch_caps ) + p->feat.arch_caps =3D true; + + /* Apply dom0-cpuid=3D command line settings. */ + cpuid_policy_to_featureset(p, fs); + + for ( i =3D 0; i < ARRAY_SIZE(fs); ++i ) + { + fs[i] |=3D dom0_enable_feat[i]; + fs[i] &=3D ~dom0_disable_feat[i]; + } + + cpuid_featureset_to_policy(fs, p); + } =20 d->arch.cpuid =3D p; =20 --=20 2.11.0