From nobody Thu Apr 25 07:24:14 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=1637788359; cv=none; d=zohomail.com; s=zohoarc; b=jybjk+xBwWujSqU7GAD/I2AkZ7yx1cZoBqeaexsiqCpeLaHVC9rhq1i88yASKwFjT7K5XTqE0F25tjgkCRuI2dF5rQYuS7PVcVXfRn3bpFByI9jjucaUNe3euMbVky+vhSHSm9zwjczJvm8fMT/3bASeU3e+BxmOeUX3DBXVr64= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637788359; 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=2I3KxLtPLpy7pBeQkBHQBvtAh5+iTqQIwLGYEOdFkZc=; b=OufdpNz5NY50SN1zM40SsLZgbosPJcVNfuhhLZnAqr6dzjytCD5IxLEKqRDJW6RYdyA0BHp5Ha07tOVz+14bCb33nMuIhOWUKikMW1S+Fe333MGInZactwc/mMzYnbazzXVgUtncfDXb1nx3p0XtTpk/owCnzLacTAUz2elGRZk= 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 1637788359284695.1184867678073; Wed, 24 Nov 2021 13:12:39 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.230577.398617 (Exim 4.92) (envelope-from ) id 1mpzYl-0003rx-Oy; Wed, 24 Nov 2021 21:12:07 +0000 Received: by outflank-mailman (output) from mailman id 230577.398617; Wed, 24 Nov 2021 21:12:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mpzYl-0003rq-LC; Wed, 24 Nov 2021 21:12:07 +0000 Received: by outflank-mailman (input) for mailman id 230577; Wed, 24 Nov 2021 21:12:06 +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 1mpzYk-0003rk-Kt for xen-devel@lists.xenproject.org; Wed, 24 Nov 2021 21:12:06 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2b115bd2-4d6b-11ec-9787-a32c541c8605; Wed, 24 Nov 2021 22:12:04 +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: 2b115bd2-4d6b-11ec-9787-a32c541c8605 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1637788324; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=LrisarM+zh4xGyEaCTVkU64TlzUug60nIJTVDqVZ8Ik=; b=bfFmUM2xY9UYL6lAmOSKLM9EKAbxdHTf/KLdpYtwkbtDKKQ/hNh/jxx/ jl+Sa+pWZOnC9cIbPiXNQXjtZJOTx6l9MsECKp0zLAH0hd+gf1qb7oZQx DELQNFg8VU3Mb9shLKK/5nzAJ/9nN9le7uDItAdnPTvCThnddSJZznKDZ 0=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: 20ObPTLwTJ46KltzQ0Kcgcx8Gn3h0eI5spFskynwBr1ZoxsessY+BMVTFR5Pt4cgOcz/GLKqQ+ GvOa0WVvaHd7UY3cn9oCwyIwGUl5lTY8p9RWoXM9yE7AEeju/fW6sLozuXQYhW/GMwfujWrPzt QtsBWU0iirO2bt4ZS0sCqneH7Sjve34BDJ7a/FjEapLe4lDsilKXnVPP7TUrU0ce81MaJ78HIq /k+ogBhXO2Pv4StNKim15/Avm5ctFFRlIF/2rN0TGeOLmS1KObamUPAQniDDA/X+fmUMkqyY/f TwwDSE7tok6UnVxzAtsRHC0u X-SBRS: 5.1 X-MesageID: 58595209 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:vOVV0KCqy5NcnBVW//zkw5YqxClBgxIJ4kV8jS/XYbTApDsq32ZSx zEbW2zVPqyOYmH9LdEga4uz9E4CvZXQnIBjQQY4rX1jcSlH+JHPbTi7wuYcHM8wwunrFh8PA xA2M4GYRCwMo/u1Si6FatANl1ElvU2zbue6WLGs1hxZH1c+EX540047wIbVv6Yz6TSHK1LV0 T/Ni5W31G+Ng1aY5UpNtspvADs21BjDkGtwUm4WPJinj3eH/5UhN7oNJLnZEpfNatI88thW5 Qr05OrREmvxp3/BAz4++1rxWhVirrX6ZWBihpfKMkQLb9crSiEai84G2PQghUh/sR+1n9NBj /x0nMbgEiE4BbTsmMUUekwNe81+FfUuFL7vJHG+tYqYzlHccmuqyPJrZK00FdRGoKAtWzgIr KFGbmBWBvyAr7veLLaTY+9gnMk8auLsO5sSoCpIxjDFF/c2B5vERs0m4PcFjGph25oWTJ4yY eJCOX1eaRjjbCdqGXEZMZkGoeKWhz7wJmgwRFW9+vNsvjm7IBZK+KfpGMrYfJqNX8o9tk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MTXdLJyesId70hD6qhwISY6TiX+rb HIoB17726RtN9/YhEdcLy7VJVoIkmskKKdg7NhXotKNTOO0ADDQb2KhbGSpQEIcBeeygcy78 hdmtBFeb/NMWQ= X-IronPort-AV: E=Sophos;i="5.87,261,1631592000"; d="scan'208";a="58595209" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Ian Jackson Subject: [PATCH for-4.16] Revert "x86/CPUID: shrink max_{,sub}leaf fields according to actual leaf contents" Date: Wed, 24 Nov 2021 21:11:52 +0000 Message-ID: <20211124211152.1142-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: 1637788360303100003 OSSTest has identified a 3rd regression caused by this change. Migration between Xen 4.15 and 4.16 on the nocera pair of machines (AMD Opteron 4133) fails with: xc: error: Failed to set CPUID policy: leaf 00000000, subleaf ffffffff, m= sr ffffffff (22 =3D Invalid argument): Internal error xc: error: Restore failed (22 =3D Invalid argument): Internal error which is a safety check to prevent resuming the guest when the CPUID data h= as been truncated. The problem is caused by shrinking of the max policies, wh= ich is an ABI that needs handling compatibly between different versions of Xen. Furthermore, shrinking of the default policies also breaks things in some cases, because certain cpuid=3D settings in a VM config file which used to = have an effect will now be silently discarded. This reverts commit 540d911c2813c3d8f4cdbb3f5672119e5e768a3d, as well as the partial fix attempt in 81da2b544cbb003a5447c9b14d275746ad22ab37 (which added one new case where cpuid=3D settings might not apply correctly) and restore= s the same behaviour as Xen 4.15. Fixes: 540d911c2813 ("x86/CPUID: shrink max_{,sub}leaf fields according to = actual leaf contents") Fixes: 81da2b544cbb ("x86/cpuid: prevent shrinking migrated policies max le= aves") Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Acked-by: Roger Pau Monn=C3=A9 --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Ian Jackson Passing CI runs: https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/415822110 https://cirrus-ci.com/build/4915643318272000 This supercedes https://lore.kernel.org/xen-devel/20211124161649.83189-1-roger.pau@citrix.c= om/ which is a step in the right direction (it fixes the OSSTest breakage), but incomplete (doesn't fix the potential cpuid=3D breakage). For 4.16. This is the 3rd breakage caused by 540d911c2813, and there is no reasonable workaround. Obviously, this revert isn't completely without ris= k, but going wholesale back to the 4.15 behaviour is by far the safest option = at this point. --- tools/libs/guest/xg_cpuid_x86.c | 7 --- tools/tests/cpu-policy/test-cpu-policy.c | 101 ---------------------------= ---- xen/arch/x86/cpuid.c | 10 --- xen/include/xen/lib/x86/cpuid.h | 7 --- xen/lib/x86/cpuid.c | 39 ------------ 5 files changed, 164 deletions(-) diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x8= 6.c index 3ffd5f683bec..198892ebdf45 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -638,13 +638,6 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t = domid, bool restore, } } =20 - /* - * Do not try to shrink the policy if restoring, as that could cause - * guest visible changes in the maximum leaf fields. - */ - if ( !restore ) - x86_cpuid_policy_shrink_max_leaves(p); - rc =3D x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves); if ( rc ) { diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-pol= icy/test-cpu-policy.c index 75973298dfd5..ed450a099709 100644 --- a/tools/tests/cpu-policy/test-cpu-policy.c +++ b/tools/tests/cpu-policy/test-cpu-policy.c @@ -8,13 +8,10 @@ #include =20 #include -#include #include #include #include =20 -#define XSTATE_FP_SSE (X86_XCR0_FP | X86_XCR0_SSE) - static unsigned int nr_failures; #define fail(fmt, ...) \ ({ \ @@ -573,103 +570,6 @@ static void test_cpuid_out_of_range_clearing(void) } } =20 -static void test_cpuid_maximum_leaf_shrinking(void) -{ - static const struct test { - const char *name; - struct cpuid_policy p; - } tests[] =3D { - { - .name =3D "basic", - .p =3D { - /* Very basic information only. */ - .basic.max_leaf =3D 1, - .basic.raw_fms =3D 0xc2, - }, - }, - { - .name =3D "cache", - .p =3D { - /* Cache subleaves present. */ - .basic.max_leaf =3D 4, - .cache.subleaf[0].type =3D 1, - }, - }, - { - .name =3D "feat#0", - .p =3D { - /* Subleaf 0 only with some valid bit. */ - .basic.max_leaf =3D 7, - .feat.max_subleaf =3D 0, - .feat.fsgsbase =3D 1, - }, - }, - { - .name =3D "feat#1", - .p =3D { - /* Subleaf 1 only with some valid bit. */ - .basic.max_leaf =3D 7, - .feat.max_subleaf =3D 1, - .feat.avx_vnni =3D 1, - }, - }, - { - .name =3D "topo", - .p =3D { - /* Topology subleaves present. */ - .basic.max_leaf =3D 0xb, - .topo.subleaf[0].type =3D 1, - }, - }, - { - .name =3D "xstate", - .p =3D { - /* First subleaf always valid (and then non-zero). */ - .basic.max_leaf =3D 0xd, - .xstate.xcr0_low =3D XSTATE_FP_SSE, - }, - }, - { - .name =3D "extd", - .p =3D { - /* Commonly available information only. */ - .extd.max_leaf =3D 0x80000008, - .extd.maxphysaddr =3D 0x28, - .extd.maxlinaddr =3D 0x30, - }, - }, - }; - - printf("Testing CPUID maximum leaf shrinking:\n"); - - for ( size_t i =3D 0; i < ARRAY_SIZE(tests); ++i ) - { - const struct test *t =3D &tests[i]; - struct cpuid_policy *p =3D memdup(&t->p); - - p->basic.max_leaf =3D ARRAY_SIZE(p->basic.raw) - 1; - p->feat.max_subleaf =3D ARRAY_SIZE(p->feat.raw) - 1; - p->extd.max_leaf =3D 0x80000000 | (ARRAY_SIZE(p->extd.raw) - 1); - - x86_cpuid_policy_shrink_max_leaves(p); - - /* Check the the resulting max (sub)leaf values against expecation= s. */ - if ( p->basic.max_leaf !=3D t->p.basic.max_leaf ) - fail(" Test %s basic fail - expected %#x, got %#x\n", - t->name, t->p.basic.max_leaf, p->basic.max_leaf); - - if ( p->extd.max_leaf !=3D t->p.extd.max_leaf ) - fail(" Test %s extd fail - expected %#x, got %#x\n", - t->name, t->p.extd.max_leaf, p->extd.max_leaf); - - if ( p->feat.max_subleaf !=3D t->p.feat.max_subleaf ) - fail(" Test %s feat fail - expected %#x, got %#x\n", - t->name, t->p.feat.max_subleaf, p->feat.max_subleaf); - - free(p); - } -} - static void test_is_compatible_success(void) { static struct test { @@ -785,7 +685,6 @@ int main(int argc, char **argv) test_cpuid_serialise_success(); test_cpuid_deserialise_failure(); test_cpuid_out_of_range_clearing(); - test_cpuid_maximum_leaf_shrinking(); =20 test_msr_serialise_success(); test_msr_deserialise_failure(); diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index 8ac55f0806d0..151944f65702 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -353,8 +353,6 @@ static void __init calculate_host_policy(void) p->extd.raw[0xa].d |=3D ((1u << SVM_FEATURE_VMCBCLEAN) | (1u << SVM_FEATURE_TSCRATEMSR)); } - - x86_cpuid_policy_shrink_max_leaves(p); } =20 static void __init guest_common_default_feature_adjustments(uint32_t *fs) @@ -434,8 +432,6 @@ static void __init calculate_pv_max_policy(void) recalculate_xstate(p); =20 p->extd.raw[0xa] =3D EMPTY_LEAF; /* No SVM for PV guests. */ - - x86_cpuid_policy_shrink_max_leaves(p); } =20 static void __init calculate_pv_def_policy(void) @@ -456,8 +452,6 @@ static void __init calculate_pv_def_policy(void) sanitise_featureset(pv_featureset); cpuid_featureset_to_policy(pv_featureset, p); recalculate_xstate(p); - - x86_cpuid_policy_shrink_max_leaves(p); } =20 static void __init calculate_hvm_max_policy(void) @@ -523,8 +517,6 @@ static void __init calculate_hvm_max_policy(void) sanitise_featureset(hvm_featureset); cpuid_featureset_to_policy(hvm_featureset, p); recalculate_xstate(p); - - x86_cpuid_policy_shrink_max_leaves(p); } =20 static void __init calculate_hvm_def_policy(void) @@ -549,8 +541,6 @@ static void __init calculate_hvm_def_policy(void) sanitise_featureset(hvm_featureset); cpuid_featureset_to_policy(hvm_featureset, p); recalculate_xstate(p); - - x86_cpuid_policy_shrink_max_leaves(p); } =20 void __init init_guest_cpuid(void) diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpui= d.h index 2300faf03e2b..a4d254ea96e0 100644 --- a/xen/include/xen/lib/x86/cpuid.h +++ b/xen/include/xen/lib/x86/cpuid.h @@ -386,13 +386,6 @@ void x86_cpuid_policy_fill_native(struct cpuid_policy = *p); */ void x86_cpuid_policy_clear_out_of_range_leaves(struct cpuid_policy *p); =20 -/** - * Shrink max leaf/subleaf values such that the last respective valid entry - * isn't all blank. While permitted by the spec, such extraneous leaves m= ay - * provide undue "hints" to guests. - */ -void x86_cpuid_policy_shrink_max_leaves(struct cpuid_policy *p); - #ifdef __XEN__ #include typedef XEN_GUEST_HANDLE_64(xen_cpuid_leaf_t) cpuid_leaf_buffer_t; diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c index 1409c254c8ea..8eb88314f53c 100644 --- a/xen/lib/x86/cpuid.c +++ b/xen/lib/x86/cpuid.c @@ -236,45 +236,6 @@ void x86_cpuid_policy_clear_out_of_range_leaves(struct= cpuid_policy *p) ARRAY_SIZE(p->extd.raw) - 1); } =20 -void x86_cpuid_policy_shrink_max_leaves(struct cpuid_policy *p) -{ - unsigned int i; - - p->basic.raw[0x4] =3D p->cache.raw[0]; - - for ( i =3D p->feat.max_subleaf; i; --i ) - if ( p->feat.raw[i].a | p->feat.raw[i].b | - p->feat.raw[i].c | p->feat.raw[i].d ) - break; - p->feat.max_subleaf =3D i; - p->basic.raw[0x7] =3D p->feat.raw[i]; - - p->basic.raw[0xb] =3D p->topo.raw[0]; - - /* - * Due to the way xstate gets handled in the hypervisor (see - * recalculate_xstate()) there is (for now at least) no need to fiddle - * with the xstate subleaves (IOW we assume they're already in consist= ent - * shape, for coming from either hardware or recalculate_xstate()). - */ - p->basic.raw[0xd] =3D p->xstate.raw[0]; - - for ( i =3D p->basic.max_leaf; i; --i ) - if ( p->basic.raw[i].a | p->basic.raw[i].b | - p->basic.raw[i].c | p->basic.raw[i].d ) - break; - p->basic.max_leaf =3D i; - - for ( i =3D p->extd.max_leaf & 0xffff; i; --i ) - if ( p->extd.raw[i].a | p->extd.raw[i].b | - p->extd.raw[i].c | p->extd.raw[i].d ) - break; - if ( i | p->extd.raw[0].b | p->extd.raw[0].c | p->extd.raw[0].d ) - p->extd.max_leaf =3D 0x80000000 | i; - else - p->extd.max_leaf =3D 0; -} - const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature) { static const uint32_t deep_features[] =3D INIT_DEEP_FEATURES; --=20 2.11.0