From nobody Fri Nov 29 22:49:57 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1620385631; cv=pass; d=zohomail.com; s=zohoarc; b=Qy81vSSiz7WV/e/9xBMxKWmbEgPWpJbuA4y9ZExh3vcf9ce5IIqAumACYTlhyWDqgBKGRbHVp3+N/NYfAV5pAQpK/CyEzTYrf0D4cMH0OoHDzKUFeHEIdlFMIbMTJ3hZn/fa9x8Dy7FwlvkOKwsPysHsinl7+G3xzcvUwSZuwtA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620385631; 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=64awfqRB5ESkjIM24i+z107CJ81OENwIGfRhEqoVoZE=; b=ZBfb/AtSu93cmS/c9hfsWBOfj8XzmbIVMHaf5/AhbBIxcrEjkyMGk0EXi9UiDfDHWXL2FqYol0nHxtPyv78HsDaIxQAFmqFhmme2VqY+0F07LyaHfn0zBDzAzVLpcG8FWdVUyK6LffW2pbNEYHKj1rMkJB6kj7varHLy71ndTVU= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620385631714738.7947286755301; Fri, 7 May 2021 04:07:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.123956.233926 (Exim 4.92) (envelope-from ) id 1leyJt-0002wm-MI; Fri, 07 May 2021 11:06:57 +0000 Received: by outflank-mailman (output) from mailman id 123956.233926; Fri, 07 May 2021 11:06:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leyJt-0002wc-Gy; Fri, 07 May 2021 11:06:57 +0000 Received: by outflank-mailman (input) for mailman id 123956; Fri, 07 May 2021 11:06:56 +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.92) (envelope-from ) id 1leyJs-0002vm-3t for xen-devel@lists.xenproject.org; Fri, 07 May 2021 11:06:56 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c89341f9-f751-4ab8-8fb3-44538a7d9b43; Fri, 07 May 2021 11:06:54 +0000 (UTC) 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: c89341f9-f751-4ab8-8fb3-44538a7d9b43 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620385614; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=0X8TxPH7KufbkpJ3x7eqxsup3Sr7s5HEON67QQy9Z/I=; b=Fu1P4DFRv+cZ94asXtr8nn1RSsO5YhL5tou5AI2AfSGp2ocMKy4AA3lj ziA6XKBx3Mfj9nvQMACaMJZeUXh2uYwLVW3RLqyFeWyi1DZ8AVSeJQ/Co E98mVlcJXSTGrC8+J/qLrH6bb1UKmhlwcARvrwh9h3Fo88sfT7L914Ccj A=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: BOFMUJfSWYClqkoGCme7WkfTfBpjZ1XbTDCxp7MzIlLmTKnlNaopmaf9cCqRXi8UhXn4JQZ1J1 /khIlyAukr19Akzqj3Dk4j+kvvOzIZD0twqyO2/1gIOdfZw0hLsXuxL6bwiI45DmhtunE4Vt/S WHpcEyV2YE8RRXmsu/+Fmz1PFNJW4qEgQfAbPfCtAKkPI7Vd+4Inj2MTP+4SGUvgmD3YXCpKC2 v2o+M3hRFsSK1WLIk2U7bAcjnyZJhDPu64loX2+emqyaE7GNS8lUzT3srRamhz8TXnGNxv3EaG Vds= X-SBRS: 5.1 X-MesageID: 43096201 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:v2wSUqHQ4un4coLKpLqEEseALOsnbusQ8zAXPiBKJCC9vPb5qy nOpoV+6faQslwssR4b9uxoVJPvfZq+z+8R3WByB8bAYOCOggLBQL2KhbGI/9SKIVydygcy78 Zdm6gVMqyMMbB55/yKnDVRxbwbsaa6GKPDv5ah8590JzsaDJ2Jd21Ce32m+ksdfnghObMJUK Cyy+BgvDSadXEefq2AdwM4t7iqnayzqHr+CyR2fyIa1A== X-IronPort-AV: E=Sophos;i="5.82,280,1613451600"; d="scan'208";a="43096201" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OpljV9Bfwb8R7D/1BiqmW3b2N1q6g6sFvB1gND0540ZiWICWsyJNqLCdN8KDkTCcPNx+NdQXdaCoz8xsQxjT5sTB6EuQ7V7aPrDA4PCyEC6SvGGRsr7F8TTVSWS3ESF93tcr95lywdrpLa6pHPAajwyVR5XV8WxqPLPSsfxMNiOgsrVL4Bz7HDCyiiY6EHeoY95Dgefv12UVmD78jTQWpDJh8iA2r3GuGJVrTjWh5JcGcdxkw1gkpREYobQ8eke6WxETIHZMwnIn8rRFGkNtVSeUR+pQEnsajZ1HsKQ7+MqccCcRPRd2x8aEp31xM2bMLqF67IczWVBVJZIj+DjqTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=64awfqRB5ESkjIM24i+z107CJ81OENwIGfRhEqoVoZE=; b=OTCWx9kZDsrDaaYDwl845walkFvK8QKtVoRrMB1h0V9WCXQEFxsZxhO9sjASD85kmhY5/SkVAnAy9KO7QvYfPjDKhNeBhng3rWlBq6RNejyVfrydjrPNnEjzJiIfNSdfaXLuVw/1W9pANmuBEhLOsUb3BDX8wz4FKINJLAUtnLr7CkVBYYTx5pORaEygxn4Gj6tD14OmrP+/hX6QS+7zM99KJj1jxw4F3L1Wbjrx32p/4Yy/hhwvp/hexDog/e3kOhiYR7hxOsXOByZCWB7LLuQViF4Fl6Vi2XABPhjfNpBicBGhEUKx91g6Ay3EjinBYCstajNu4O8U9pU0570XkA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=64awfqRB5ESkjIM24i+z107CJ81OENwIGfRhEqoVoZE=; b=IxLaZG7RffYOeOdF/Qr3PNSFCKNgt9hJZ+Nbl3SNue6QtZX8DeOt58M43OABlLRAfxuYCO8T+/VeMLlTyVzi8t5120XCgki27j0Y+Ocz2i89Ek9YrdLumOfNiKtlWeJWCA2kIYdyw4hIuVnZ3sSQQFmz8FMt8A+w/o0uqXMXTSI= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Jan Beulich , Wei Liu , Ian Jackson Subject: [PATCH v4 01/10] libx86: introduce helper to fetch cpuid leaf Date: Fri, 7 May 2021 13:04:13 +0200 Message-ID: <20210507110422.24608-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507110422.24608-1-roger.pau@citrix.com> References: <20210507110422.24608-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR2P264CA0154.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:1::17) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 03aa3151-bb8f-41a5-8ce8-08d911483614 X-MS-TrafficTypeDiagnostic: DM6PR03MB4475: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:530; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: saP422w1aJ5dYAWn1ezGpYjTDRrutZ43B66BzYku2uCir1XyZoe5UrQUan9Qt9XIvPjq5yBaZXcNaDLNF0PMCCPPNZdVzNWyLa3LI7A8GTFo2PmB8vMFnbvCf7z+ooaP10ekRz0IjjvF2CzRc+1LJNrSJyJc6jjhOcqEzgX1nU4gQhT/geG3CpVKEOYCEgecoBBlOPdPaFew0GaTcdmbD/YQhNkvUId2iSdnjhvJawzt3wCwHvD4XVGD5YwiH6avuFB7pmohYSVNsMxXj7MSUynIH0QxBo8xuocuwwac7BxonSmKLjVAJlZ8oQQbhI9ZkQ3y7R4JuhAQoiquiBFGwtM5FuV64lrr5JogHDFY0v7Q1p7HqDqQRjyvEMeyxCT/84dpxCRJ7DiV2LgU+DWbDvdZs4Ug0bux73UhqTbB1wfujcw41b9Bxhpar2cgCijBWiLTNPjjmdwVhPh3HQeggTkvU+iWAtCAo+8owUDrsgoGCNtopkE5LJdWG4oYck87H754vB56WcH/PCU1rdA5FJHQQ27MoNlRYR2Y7clERmo6DoUzYK3RknSSRfHKUBi3RaawkkzAw52suMHbHWDFv3CwRMUho3QFHL66ovmA9gw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(376002)(346002)(39860400002)(366004)(8676002)(6496006)(26005)(66946007)(5660300002)(66556008)(66476007)(83380400001)(478600001)(956004)(1076003)(6916009)(316002)(38100700002)(54906003)(6486002)(2616005)(86362001)(8936002)(36756003)(6666004)(4326008)(186003)(16526019)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?WklZc25IaExpV2h4SVk0TEtPU3N2cnBxK2J2MElJb1JBaDVnQkNxc3JPSThC?= =?utf-8?B?ZVBZdGNvQllDMFBwNlpyWGYrMlBMdDNQNkhmaURnRnJvUnpwRjRmbTVsTzJx?= =?utf-8?B?YVFuYy9pZ1pUbklEeXYvUkVWRmNLc1JBOFZhMmh2R3VFRzBieW5Dd2JrODU4?= =?utf-8?B?NlhFQU5CcHpqcFFpbmpQWnBxTU54SDZpZGN2QjVOaVp4R1RraEpWVVJldzAx?= =?utf-8?B?RUFwa3NPREtucjBuRys3WENoOHJoNEVZWGdlMlpldmtlNnBCQmxxVTg4SFha?= =?utf-8?B?djhsUUdEUk9wc3JqYVdkajIwZEFYRWczR0FLTjM1a05VQWowb0oyU0h6V2Mw?= =?utf-8?B?UW42ZHVUZnR5c1IxNUJFc0tuQVJPNC9zb3dFSURsZ3E1am5vTzNmTS9rb0Rq?= =?utf-8?B?ZnNPT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SVzdv?= =?utf-8?B?YUpjREczNUQ2ODJQcE41Rk1XY01pVlJPVW8vNFUxUUZOM2lhNEJXVHhGL1N4?= =?utf-8?B?aFlxMlFvdkVFNndZSUV4MHM4WUN5UklMUjkzZE1wMzZDVWtLOWxYaGVNVzZP?= =?utf-8?B?SkozbEZHSFM3aVRjS3MrekhSYlpCQ09md0xINnRvVGZEcnRxT21Wa2NTMmts?= =?utf-8?B?Q2pldGxTbGNNRkZSdERRYnhnNEVGb0hYVVlGUUhERTUzZGFNMWF6WUF1K08y?= =?utf-8?B?QWY0d3JsZWJGdDBlRTBIWEZHaDZWanF6KzQ2QncxeTNvM2VwM051SUR5NHpN?= =?utf-8?B?YVVyZ3Bud2pnNDlEa1dkczJQaEtZaVNBYmhleFlINTFja3JqQjJhNXZza2cv?= =?utf-8?B?Y1lqMUljSGZuUWFsYU5TRUY4TTdTc0xjR09LQ0diTFFpTWtoZVZGVHRoMGlK?= =?utf-8?Q?TKPqt+26jDcdMTf2LvFzcsx9z14eriLkVe9h528?= X-MS-Exchange-CrossTenant-Network-Message-Id: 03aa3151-bb8f-41a5-8ce8-08d911483614 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 11:06:49.7148 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lKZKwf/VV/yFNlrPEhUSzYDsEMiW9ZSFhsCH0/04nozO7xLRoAycDRPzdp+mXYt8m1GLi/Ko9Vl0jhaV8IFCHQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4475 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) Introduce a helper based on the current Xen guest_cpuid code in order to fetch a cpuid leaf from a policy. The newly introduced function in cpuid.c should not be directly called and instead the provided x86_cpuid_get_leaf macro should be used that will properly deal with const and non-const inputs. Also add a test to check that the introduced helper doesn't go over the bounds of the policy. Note the code in x86_cpuid_copy_from_buffer is not switched to use the new function because of the boundary checks against the max fields of the policy, which might not be properly set at the point where x86_cpuid_copy_from_buffer get called, for example when filling an empty policy from scratch. Suggested-by: Andrew Cooper Signed-off-by: Roger Pau Monn=C3=A9 --- Changes since v3: - New in this version. --- Regarding safety of the usage of array_access_nospec to obtain a pointer to an element of an array, there are already other instances of this usage, for example in viridian_time_wrmsr, so I would assume this is fine. --- tools/tests/cpu-policy/test-cpu-policy.c | 75 ++++++++++++++++++++++++ xen/arch/x86/cpuid.c | 55 +++-------------- xen/include/xen/lib/x86/cpuid.h | 18 ++++++ xen/lib/x86/cpuid.c | 51 ++++++++++++++++ 4 files changed, 151 insertions(+), 48 deletions(-) diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-pol= icy/test-cpu-policy.c index 75973298dfd..81de9720c8d 100644 --- a/tools/tests/cpu-policy/test-cpu-policy.c +++ b/tools/tests/cpu-policy/test-cpu-policy.c @@ -670,6 +670,80 @@ static void test_cpuid_maximum_leaf_shrinking(void) } } =20 +static void test_cpuid_get_leaf_failure(void) +{ + static const struct test { + struct cpuid_policy p; + const char *name; + uint32_t leaf, subleaf; + } tests[] =3D { + /* Bound checking logic. */ + { + .name =3D "Basic max leaf >=3D array size", + .p =3D { + .basic.max_leaf =3D CPUID_GUEST_NR_BASIC, + }, + }, + { + .name =3D "Feature max leaf >=3D array size", + .p =3D { + .basic.max_leaf =3D CPUID_GUEST_NR_BASIC - 1, + .feat.max_subleaf =3D CPUID_GUEST_NR_FEAT, + }, + .leaf =3D 0x00000007, + }, + { + .name =3D "Extended max leaf >=3D array size", + .p =3D { + .extd.max_leaf =3D 0x80000000 + CPUID_GUEST_NR_EXTD, + }, + .leaf =3D 0x80000000, + }, + + { + .name =3D "Basic leaf >=3D max leaf", + .p =3D { + .basic.max_leaf =3D CPUID_GUEST_NR_BASIC - 1, + }, + .leaf =3D CPUID_GUEST_NR_BASIC, + }, + { + .name =3D "Feature leaf >=3D max leaf", + .p =3D { + .basic.max_leaf =3D CPUID_GUEST_NR_BASIC - 1, + .feat.max_subleaf =3D CPUID_GUEST_NR_FEAT - 1, + }, + .leaf =3D 0x00000007, + .subleaf =3D CPUID_GUEST_NR_FEAT, + }, + { + .name =3D "Extended leaf >=3D max leaf", + .p =3D { + .extd.max_leaf =3D 0x80000000 + CPUID_GUEST_NR_EXTD - 1, + }, + .leaf =3D 0x80000000 + CPUID_GUEST_NR_EXTD, + }, + }; + const struct cpuid_policy pc; + const struct cpuid_leaf *lc; + struct cpuid_policy p; + struct cpuid_leaf *l; + + /* Constness build test. */ + lc =3D x86_cpuid_get_leaf(&pc, 0, 0); + l =3D x86_cpuid_get_leaf(&p, 0, 0); + + printf("Testing CPUID get leaf bound checking:\n"); + + for ( size_t i =3D 0; i < ARRAY_SIZE(tests); ++i ) + { + const struct test *t =3D &tests[i]; + + if ( x86_cpuid_get_leaf(&t->p, t->leaf, t->subleaf) ) + fail(" Test %s get leaf fail\n", t->name); + } +} + static void test_is_compatible_success(void) { static struct test { @@ -786,6 +860,7 @@ int main(int argc, char **argv) test_cpuid_deserialise_failure(); test_cpuid_out_of_range_clearing(); test_cpuid_maximum_leaf_shrinking(); + test_cpuid_get_leaf_failure(); =20 test_msr_serialise_success(); test_msr_deserialise_failure(); diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index 752bf244ea3..f7481c3168d 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -779,48 +779,16 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf, switch ( leaf ) { case 0 ... CPUID_GUEST_NR_BASIC - 1: - ASSERT(p->basic.max_leaf < ARRAY_SIZE(p->basic.raw)); - if ( leaf > min_t(uint32_t, p->basic.max_leaf, - ARRAY_SIZE(p->basic.raw) - 1) ) - return; - - switch ( leaf ) - { - case 0x4: - if ( subleaf >=3D ARRAY_SIZE(p->cache.raw) ) - return; - - *res =3D array_access_nospec(p->cache.raw, subleaf); - break; - - case 0x7: - ASSERT(p->feat.max_subleaf < ARRAY_SIZE(p->feat.raw)); - if ( subleaf > min_t(uint32_t, p->feat.max_subleaf, - ARRAY_SIZE(p->feat.raw) - 1) ) - return; - - *res =3D array_access_nospec(p->feat.raw, subleaf); - break; - - case 0xb: - if ( subleaf >=3D ARRAY_SIZE(p->topo.raw) ) - return; - - *res =3D array_access_nospec(p->topo.raw, subleaf); - break; - - case XSTATE_CPUID: - if ( !p->basic.xsave || subleaf >=3D ARRAY_SIZE(p->xstate.raw)= ) - return; + case 0x80000000 ... 0x80000000 + CPUID_GUEST_NR_EXTD - 1: + { + const struct cpuid_leaf *tmp =3D x86_cpuid_get_leaf(p, leaf, suble= af); =20 - *res =3D array_access_nospec(p->xstate.raw, subleaf); - break; + if ( !tmp ) + return; =20 - default: - *res =3D array_access_nospec(p->basic.raw, leaf); - break; - } + *res =3D *tmp; break; + } =20 case 0x40000000 ... 0x400000ff: if ( is_viridian_domain(d) ) @@ -835,15 +803,6 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf, case 0x40000100 ... 0x400001ff: return cpuid_hypervisor_leaves(v, leaf, subleaf, res); =20 - case 0x80000000 ... 0x80000000 + CPUID_GUEST_NR_EXTD - 1: - ASSERT((p->extd.max_leaf & 0xffff) < ARRAY_SIZE(p->extd.raw)); - if ( (leaf & 0xffff) > min_t(uint32_t, p->extd.max_leaf & 0xffff, - ARRAY_SIZE(p->extd.raw) - 1) ) - return; - - *res =3D array_access_nospec(p->extd.raw, leaf & 0xffff); - break; - default: return; } diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpui= d.h index 2300faf03e2..4e8797f9f5f 100644 --- a/xen/include/xen/lib/x86/cpuid.h +++ b/xen/include/xen/lib/x86/cpuid.h @@ -438,6 +438,24 @@ int x86_cpuid_copy_from_buffer(struct cpuid_policy *po= licy, uint32_t nr_entries, uint32_t *err_leaf, uint32_t *err_subleaf); =20 +/** + * Get a cpuid leaf from a policy object. + * + * @param policy The cpuid_policy object. + * @param leaf The leaf index. + * @param subleaf The subleaf index. + * @returns a pointer to the requested leaf or NULL in case of error. + * + * The function will perform out of bound checks. Do not call this function + * directly and instead use x86_cpuid_get_leaf that will deal with both co= nst + * and non-const policies returning a pointer with constness matching that= of + * the input. + */ +const struct cpuid_leaf *_x86_cpuid_get_leaf(const struct cpuid_policy *p, + uint32_t leaf, uint32_t suble= af); +#define x86_cpuid_get_leaf(p, l, s) \ + ((__typeof__(&(p)->basic.raw[0]))_x86_cpuid_get_leaf(p, l, s)) + #endif /* !XEN_LIB_X86_CPUID_H */ =20 /* diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c index 1409c254c8e..3637466ff9f 100644 --- a/xen/lib/x86/cpuid.c +++ b/xen/lib/x86/cpuid.c @@ -532,6 +532,57 @@ int x86_cpuid_copy_from_buffer(struct cpuid_policy *p, return -ERANGE; } =20 +const struct cpuid_leaf *_x86_cpuid_get_leaf(const struct cpuid_policy *p, + uint32_t leaf, uint32_t suble= af) +{ + switch ( leaf ) + { + case 0 ... CPUID_GUEST_NR_BASIC - 1: + if ( p->basic.max_leaf >=3D ARRAY_SIZE(p->basic.raw) || + leaf > p->basic.max_leaf ) + return NULL; + + switch ( leaf ) + { + case 0x4: + if ( subleaf >=3D ARRAY_SIZE(p->cache.raw) ) + return NULL; + + return &array_access_nospec(p->cache.raw, subleaf); + + case 0x7: + if ( p->feat.max_subleaf >=3D ARRAY_SIZE(p->feat.raw) || + subleaf > p->feat.max_subleaf ) + return NULL; + + return &array_access_nospec(p->feat.raw, subleaf); + + case 0xb: + if ( subleaf >=3D ARRAY_SIZE(p->topo.raw) ) + return NULL; + + return &array_access_nospec(p->topo.raw, subleaf); + + case 0xd: + if ( !p->basic.xsave || subleaf >=3D ARRAY_SIZE(p->xstate.raw)= ) + return NULL; + + return &array_access_nospec(p->xstate.raw, subleaf); + } + + return &array_access_nospec(p->basic.raw, leaf); + + case 0x80000000 ... 0x80000000 + CPUID_GUEST_NR_EXTD - 1: + if ( (p->extd.max_leaf & 0xffff) >=3D ARRAY_SIZE(p->extd.raw) || + leaf > p->extd.max_leaf ) + return NULL; + + return &array_access_nospec(p->extd.raw, leaf & 0xffff); + } + + return NULL; +} + /* * Local variables: * mode: C --=20 2.31.1 From nobody Fri Nov 29 22:49:57 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1620385639; cv=pass; d=zohomail.com; s=zohoarc; b=YPuwhsuQQufRA7JEII2I4rCVOSfPjd0MWcMslM3K4W18SugbyosSpNFQJSSTnZBEODIYQj5z2PmqWIaCou4pGZX9ECs46CwLXWrlQWFn79RoL+fqXtZh7YioQPgnVv7K1eQpGOg/2NABVfG+y+oHS09tCBsTAtiTe//cejHWAO0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620385639; 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=ZdUXkdSYmtbpTEHoBo3BerLgBTlLuL2N/x2tV5e9+AQ=; b=bjMVPVR4stglyJSjEH76ndyFj6skYoTVA/kP5hO9xhQ79LuInBg2vJZTgR3RkYlCQ56ruZGi66vlSJZyQptflfMSv4OEC6pse/k3C1nl+7f3JZPszbXAdygkf2Yzyz3ZZsFLuTM4xjL5WAuHqDxRnzC7EgJTNxqbhdN2rnzcsxU= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620385639483429.497037354157; Fri, 7 May 2021 04:07:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.123958.233938 (Exim 4.92) (envelope-from ) id 1leyK0-0003M7-W7; Fri, 07 May 2021 11:07:04 +0000 Received: by outflank-mailman (output) from mailman id 123958.233938; Fri, 07 May 2021 11:07:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leyK0-0003Lz-SF; Fri, 07 May 2021 11:07:04 +0000 Received: by outflank-mailman (input) for mailman id 123958; Fri, 07 May 2021 11:07:03 +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.92) (envelope-from ) id 1leyJz-0003Kd-IM for xen-devel@lists.xenproject.org; Fri, 07 May 2021 11:07:03 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f6424572-4684-4312-959c-930c5b1c21bf; Fri, 07 May 2021 11:07:02 +0000 (UTC) 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: f6424572-4684-4312-959c-930c5b1c21bf DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620385622; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Elil3Dm30+598w9fi/VGaVFUHkrCfnckvWeQZr64YXI=; b=UULqZ6spiIjRziwfhlh+wTrPLkL+VBUIQ98ZvgeTnPQYYWx4Tz2/cbkz vNr7ycO9HM5eNNygjq9uXdahrA+GrX1bG9CFDnhPYKzsoy5SFaNsd0FVM pssuLOsHU2PEw2vqyLsPA8aZu1jsIinXjdVU+5EaumXxLX1t0/5yEzXw4 g=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: bcF+QtuDdJx+VJ6xD91c+1BdMz65+Hm75orNzZDBrpBs/GjqCy3MF/fSJV8BSL8SxFeMLOWWh/ fXdINb9JzQMv6yFo+pPXKzqBslav8Vhi0vtk4kDyuSj4d/oujFYnEBXQ8oaDv3BlHlpwUVAdE4 jMIycqOYsZvRzlsXY8XVjmEtNnnAgMpkyqcYMYu1hUSAj5xmFH3xP7+iPPpl6GvggrSK+d6lOp Ikr7ta5AymAqx6RPgIok2WrcQKK9Ic+DNxHyTSWr2fdZwhNvJTHfnqfJtyNirAQ/xLdkJiiH0F tzU= X-SBRS: 5.1 X-MesageID: 43304404 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:rdygc6/9Z1MpzR2XNR1uk+Eddb1zdoMgy1knxilNoERuA6ulfr OV7ZImPH7P+XMssR4b6LW90cW7L080lqQFpbX5X43SODUO0VHAROsOgeTfKlbbexEWg9Qtt5 uIBJIOa+EYY2IasS6kizPSLz9q+qj/zEnhv5an857Gd3AsV0go1XYCNu5HencGBzWv1fICZd qhz9sCqDy6dXsNaMOnQnEDQujYvtXO0InreBgcGnccmXyzZJyTmc/H+jWjr2Qjugl0sMUfGG P+4njEz7Tmt+v+xg7X1mfV4ZgTktPlxtxPDNfJkMQPKjn3zgaufploXLeP+DA5ydvflWoCgZ 3JuVMtLs5z43TeciW+uh32wRTt1z4o9jvr1UKYiWGLm72OeBsqT85awY5JeBrQ7EQt+Ntm1r hQwm6fv51LSRvdgSXm4cTSXR0CrDv8nZJq+dRjxUC2J+MlGfJsRaJ1xjIYLH9AdBiKoLzOZ4 FVfYrhDNY8SyLUU5ir1lMfjuBEe05DaStubnJyxfB94gIm7EyRlXFov/D3tk1wiq7UnPF/lq X524pT5c1zps1/V9M+ONs8 X-IronPort-AV: E=Sophos;i="5.82,280,1613451600"; d="scan'208";a="43304404" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hjzPXbhvnFEbXX7cCcIyoBTT0QLqD49qzP+6v9RGBX61kHFIEwMaJX51BGs3AnIB7pdH2jowxTo5F+rrircmWgvPnd3drnF3pW5tuGIZc65unwuDR4CL443wHSU7xMGkfHwqcUzVcsZsAIO+3WuMpwOd+e+dy2Dpn0l8k2OHuqyO+HpH5d1n+TWaZKoBQgI/ByshAtEsrrn14rWAsYposbjKist2a5p2Sn8KHCHg6qV+mOaYHjLqAdfpeUIhbhD45Kh23/cnJ+PFuBL9b/uNKWpUWUPdxCAQN9InR2g2NiLZ4GtN7M0LFqs2yR4GRzkT/sA0Pra9s6LdcDX9wtBeTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZdUXkdSYmtbpTEHoBo3BerLgBTlLuL2N/x2tV5e9+AQ=; b=S+ARTF047uxONLDRhH+ir5109MsbWv4kMQ1dBVb3+ws7oRjxTQBpT2iU4HXhhqOGNzIzMfJ2v0G1kOemsxTuYlJ3vk2lkVZRkMI37lqYoSF/YTy/GFWrToUJrQTJFV39w5R6rTlfKD1oDqYQ0JGP/ErjjF3FoiZNqWsrP9Kqd/rVvdR4Td1nwAbR7nmhuR1/yhctt1VSQilbq9M5Tki8WYaDy1hS3NZMbzloT+gBBwtXD8I56b6GflfHapl5Ladvi23jGiLnrr+T44giujWCjyIoN62g4MIh4bniMqkrKWyte88AWu/sAvgHQ5V0RWyAbh/hL1YPijbQhuCBPfS3QQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZdUXkdSYmtbpTEHoBo3BerLgBTlLuL2N/x2tV5e9+AQ=; b=Zp7tvoYPIdo1qkvtXBIg1YcWqGAxRtlk6URixiw07JRefZvTtscp03sOZvs0ZO60lUO9iKPip12m7Cbhjfx8WLLy9++nnAKCepAKjig4D9fTcy6y5XUi34cu+eTClwNuGp0XpnwgpDgFUn7HNHqok1acBKHUj+uJvl/rF8orWOE= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH v4 02/10] libs/guest: allow fetching a specific CPUID leaf from a cpu policy Date: Fri, 7 May 2021 13:04:14 +0200 Message-ID: <20210507110422.24608-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507110422.24608-1-roger.pau@citrix.com> References: <20210507110422.24608-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR2P264CA0125.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:30::17) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 50ed9f27-5c71-4d82-33bf-08d91148392c X-MS-TrafficTypeDiagnostic: DM6PR03MB4475: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1u00ywYucUyhVcGpKT+DCgkXkqg4vi11x2ZKwGMnFA+sVUCRn/oJInvOxR6j2JnmdzdcEoM6K+pdTBUH7gvC1Jf/PahP1WsvKtDX4LgcKoeLQYsC8q/6PgZsgVcLphnDiVAo6rWS8VKJIvhVaV0oqHC/QEEMCR6QrnIxF2vFholApGDt1Lqyi0pw/qo7afZiTGgiZxMpXjM2bYkj42XZmVFpLbhQ7wrZLu+oTXe/rUGfvDrtWMeU9i6x9ywjDcMdun3jGDiC2QCMCscJYeosz3gL37RYAytXgXYieb7z6xVICVRCfUqLhPSiujhVvIhYimqBv/bEzLN/j3DXj2wuRlr6UBd05REnNjAFEK8QRlh8uOKmneLeIBTsS22LoDLKhzq6/zJ9c3voOE/jXX26X9LoqAC5tBiyRPcq2qUwgWyeo5Wd6ezUq49nGT98/rxxuzDzmQSyvjgTTrCCJbnYPJsCnbicdYgmHA/v6F9JipDGSAZho8+1WXDq9db8d77S/oKTEgWYj03TVdoXoiL/zWQrqOLefjMgsb6rlGC/3DLgrPL6yiwfao4GC+bpSfGyILfE47ltlUfpB3nVuXQf19f2X+sYHzPVBUgm93FK4As= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(376002)(346002)(39860400002)(366004)(8676002)(6496006)(26005)(66946007)(5660300002)(66556008)(66476007)(83380400001)(478600001)(956004)(1076003)(6916009)(316002)(38100700002)(54906003)(6486002)(2616005)(86362001)(8936002)(36756003)(6666004)(4326008)(186003)(16526019)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?d1REOHlZa3ljVkdGNTBXZWZDMTBVK2ZCUFpLRHU0VWJ3Q2dGTGM3aXZkamFG?= =?utf-8?B?VXpBZzhVZXRyTStDb3VSekFWbHVYdXV4eUV4aTNQS0tQTXdQYStrRW9GNzR3?= =?utf-8?B?Y2Qwa01tams1LzB5RzRTUmZwbEZjQ0NpQWlOaXRqcWt4Smp2S3VBZHdrT3Ew?= =?utf-8?B?dWdkSE05eW5qbHlUWTJMUUhqMWtYWE9ORE5tQzB4RndmejFUZlRNLzhKSW1T?= =?utf-8?B?d25NbVpXSUw1Sndva01nRWdWdEl1VGZma1R6akJRSy82ZUVBNnZEaGM2ZVZ5?= =?utf-8?B?RnFiNXJuNUxJY0hMUmJFY0U2WDdDTXZvVDBGNkdEb3RzOUxMTWk5ZnRIMkJn?= =?utf-8?B?VHJtUUJJMUcvUWJkY0FVeENKdDNyWEppcmlWUEtlaFViNjJ5ZnNibDc1TGFE?= =?utf-8?B?aUREYnA4c1crclJqbXVoYUN5K3ZvOWsySFRSZENpbHFnTVZNOE9wVFJDK3RJ?= =?utf-8?B?U0x5ZDFISVZESmVLQzZFcUNtV2pMTHBhQkwrMDl2VU9LaE9LbEhBTFpibVAw?= =?utf-8?B?TWg1NFNwQ2VrTk1ETTFIenB6Q0ZURXJPdFJlQXVFZjZMT29KcE5OaXpkKyt5?= =?utf-8?B?NW50ZXhxK1Y0b0RZRDRIY3U3RThGa003M1lBSjNGR21Iaklpd003TEZYT05i?= =?utf-8?B?ZXZRckw1SEVGZG1zNmhmdy9nNis1cGVyTTlEMWlva0VRMEZUUWhCOVg4bjR4?= =?utf-8?B?aGRFZ2xjWnE5c2ZhNFIrTERIbnhTUTNOaVA5VVV4LytZNDJ4cllNR1U5YnVE?= =?utf-8?B?YWNlVnA1UHBDNk9vRjBzNThWVUFEaUhjM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1puTXB0dEpzeU1uKzJpWkZsd3RBYmh5?= =?utf-8?Q?ruxwbb3ZKgsjar30JJy6C4Y0LtxTMrY0Bbut76Z?= X-MS-Exchange-CrossTenant-Network-Message-Id: 50ed9f27-5c71-4d82-33bf-08d91148392c X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 11:06:54.6063 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WYfdFJTREafTERBYaPJkpspV5/KM5VJ5giTlA5p7XwO3gFZ69ni0HbsYXmy2A0FBry9v//loTLAB0bSi80dVIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4475 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) Introduce an interface that returns a specific leaf/subleaf from a cpu policy in xen_cpuid_leaf_t format. This is useful to callers can peek data from the opaque xc_cpu_policy_t type. No caller of the interface introduced on this patch. Note that callers of find_leaf need to be slightly adjusted to use the new helper parameters. Signed-off-by: Roger Pau Monn=C3=A9 --- Changes since v3: - Use x86_cpuid_get_leaf. Changes since v1: - Use find leaf. --- tools/include/xenguest.h | 3 +++ tools/libs/guest/xg_cpuid_x86.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h index 03c813a0d78..7001e04e88d 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -744,6 +744,9 @@ int xc_cpu_policy_update_cpuid(xc_interface *xch, xc_cp= u_policy_t *policy, uint32_t nr); int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t *policy, const xen_msr_entry_t *msrs, uint32_t nr); +int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t *poli= cy, + uint32_t leaf, uint32_t subleaf, + xen_cpuid_leaf_t *out); =20 /* Compatibility calculations. */ bool xc_cpu_policy_is_compatible(xc_interface *xch, xc_cpu_policy_t *host, diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x8= 6.c index 144b5a5aee6..460512d063b 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -860,6 +860,29 @@ int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cp= u_policy_t *policy, return rc; } =20 +int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t *poli= cy, + uint32_t leaf, uint32_t subleaf, + xen_cpuid_leaf_t *out) +{ + const struct cpuid_leaf *tmp; + + tmp =3D x86_cpuid_get_leaf(&policy->cpuid, leaf, subleaf); + if ( !tmp ) + { + /* Unable to find a matching leaf. */ + errno =3D ENOENT; + return -1; + } + + out->leaf =3D leaf; + out->subleaf =3D subleaf; + out->a =3D tmp->a; + out->b =3D tmp->b; + out->c =3D tmp->c; + out->d =3D tmp->d; + return 0; +} + bool xc_cpu_policy_is_compatible(xc_interface *xch, xc_cpu_policy_t *host, xc_cpu_policy_t *guest) { --=20 2.31.1 From nobody Fri Nov 29 22:49:57 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1620385641; cv=pass; d=zohomail.com; s=zohoarc; b=Xjlvm4fXCOxIATeltyvE6tOic+BBnv7jBqFqTHGzrlYEB6484jFw/1JXbdALY3Pvywyy2X+oIOw/Opw7ZqwF6GdQW2VugO/jaAu3zuIvURfUXEs9CYJXnayQpLCpiC2pNBOmNX4UrkJHtwdJMu+1Brzf0IxRhQ42Q/Gu3Vw0vGQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620385641; 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=L6y66yUxlQCuDtTKUVE0naL1zKUgsBlYMEUqArZCk+0=; b=hxrHqofVt+TLKjcODH0tBmLHlm1Hx0CmcAJvcREAfzS6maqZLpCbgGTLzJuA7hYFI4uSglZC13r2jCrvYFDBlKwrIKcFDLXjWGwU7gSrtrubYDudkKtH3KVbQ1/9qKkhzsLgwFwSeMZf2zP4lzmNtUGB+TlMYF5IdlJMahb5x+Y= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620385641100441.5156427463621; Fri, 7 May 2021 04:07:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.123960.233950 (Exim 4.92) (envelope-from ) id 1leyK3-0003hX-FN; Fri, 07 May 2021 11:07:07 +0000 Received: by outflank-mailman (output) from mailman id 123960.233950; Fri, 07 May 2021 11:07: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 1leyK3-0003hH-Bp; Fri, 07 May 2021 11:07:07 +0000 Received: by outflank-mailman (input) for mailman id 123960; Fri, 07 May 2021 11:07:05 +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.92) (envelope-from ) id 1leyK1-0003Kd-EV for xen-devel@lists.xenproject.org; Fri, 07 May 2021 11:07:05 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7635f833-24cd-44d3-b015-a594af157653; Fri, 07 May 2021 11:07:04 +0000 (UTC) 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: 7635f833-24cd-44d3-b015-a594af157653 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620385624; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=41gCcCU9e+JnlIhloGR5SydFBIlo+duLNASfJYuUK20=; b=FNwfgpIMIWdg/roSyxH9L4gGsD4m9TCPP7dEmBCTmyY3x3n3g6E/aPlY r10OAEgG/MixRgDJqYYEqi9VWxnWJlpgOlCa9qXuotr3HAg2N1G6NM7gQ ov+TGZy9e92HxxcJ+9GzR6xXwuD0zdpyN7E4oRnWoF+YNxA9Ij5gxGv+5 8=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: Jyi1DOdmM5VRxq7JvscwCSqhYN/ret+O7+iU/hNmm2OVbYY3v3y/0mvtDlfukQQYusrMZgqUrP 2XjsIvzxSeUkV9940qfR/VRuaDiE8Hj8FpJJlm6NTAQ0vC7G8zqobPhtcaf+bkkQ3KvZh0o48i AYQGQw4avSd2M+YN6UrDQQZaLF7OGmOn3T05AeSw2xuInuXgHOtYQ1rvuAvFxoqZAjF+CiSP5C YedQUhv/kYxaboFsvV3lm6Xdll28Ve3y3XoFBH7V5PgovlhRmd1SuD6GUjCzP5ZhRxj7viC766 kqg= X-SBRS: 5.1 X-MesageID: 43678467 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:AhWnyKr9vHU6BBSU4iranfwaV5sZL9V00zEX/kB9WHVpm5Oj+v xGzc5w6farsl0ssSkb6Ki90dq7MAjhHP9OkMIs1NKZMDUO11HYSL2KgbGC/9SkIVyGygc/79 YrT0EdMqyWMbESt6+Tj2eF+pQbsb+6GcuT9ITjJgJWPGRXgtZbnmVE42igcnFedU1jP94UBZ Cc7s1Iq36LYnIMdPm2AXEDQqzqu8DLvIiOW29LOzcXrC21yR+44r/zFBaVmj0EVSlU/Lsk+W /Z1yTk+6SYte2hwBO07R6d030Woqqu9jJwPr3NtiEnEESutu9uXvUiZ1S2hkF1nAho0idurD CDmWZlAy050QKqQoj8m2qR5+Cn6kdi15aq8y7lvVLz5cP+Xz40EMxHmMZQdQbY8VMpuJVm3L tMxH/xjesgMfrsplWI2zHzbWAcqqN0mwtQrQcZtQ0XbWLfUs4lkWU7xjIcLH4tJlOK1GkXKp gdMCiH3ocpTbqzVQGogoBA+q3SYkgO X-IronPort-AV: E=Sophos;i="5.82,280,1613451600"; d="scan'208";a="43678467" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VEDFK8KY3HK8vtTwJ82fAQ+Dn3nGKiart75Tto7tuZ4o9cMshnilVbLfFTLeataXxofkdNndJh5HY1iw0TVspcSAhAsr3rfUMFqg19LvnO2wNa2wfd2WfFC1GKhBtjQCyM1OtxR4cO2dNLxoY0MPQ4RMEXzbJFyXmFN27l0fh1qXr3EyvLDgwCCzZvVQ0nQzTa3rM07Q06thw8+SnW3igJ5RNskXzc0lY7ppGvRulfsBzOqbT0CdWtt3+Wpo1413rv1FK5BbprH9YGQi8MawTs1g8k/65Vw98eGEwYJXgii3CC2uGd0NrFV6UoazXrlFepQxEeFEwcrk1l7GWQmN8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L6y66yUxlQCuDtTKUVE0naL1zKUgsBlYMEUqArZCk+0=; b=HJTfbB6QyFwl8v8/ogg6w+rOqd05aSTLbiy0O6gvz7pRtv9gdlYi3+EJMqxSRsbhoyoFp6rUCIL1sx/5SxAMFm5EJjTD0HutakUYYfHCQ7pDUvh/61WZJdp/OJ1ytD38ef6bnH8HCofo1b8rP2VzKZpRUboWNtEfiDYEcIN9gDIdrDD9xXVVh0LzpFrlMo16QeyNMl071OCWMt6ektyIZA31w/OLGFEX28RBuFEkABeXEIS+G0z89b5g74gYDUU+bsQTk7R6aYXkCIUKZ+byQdc0C8LwdsNQN8w7FSiwGKEL4GyNVGCqUHMxKaV8rsMeLE8do3Bo5GVFSkcMhVwdmg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=L6y66yUxlQCuDtTKUVE0naL1zKUgsBlYMEUqArZCk+0=; b=nN0oeOsZfMEXjzHD5GgXtM0IOGCoHGUAYJfAMNZQoJSSyPxVSnaxvQbBV9z18eY7AqhZqcVpMMrrzob3hpP7607x8JM4m67thuoXloEu9L2xGO1HrFckNItgSaJ3TlZdc+rd7Aom5mU2OQJaSBLewdl8jgUAFhiFNk8QEk7b+H0= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Jan Beulich , Wei Liu , Ian Jackson Subject: [PATCH v4 03/10] libx86: introduce helper to fetch msr entry Date: Fri, 7 May 2021 13:04:15 +0200 Message-ID: <20210507110422.24608-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507110422.24608-1-roger.pau@citrix.com> References: <20210507110422.24608-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR1P264CA0033.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:2f::20) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d63b2104-3c98-4d8d-78f3-08d911483cf3 X-MS-TrafficTypeDiagnostic: DM6PR03MB4475: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +fLTYR7VAYF6vSGYm6LkCqeim9ofqX/o4hrAOZC5351Bkzd1DFwMvEourJeqWSraE1PHUyAte79lwra51hJFlJtszWHPZvNdkXLcFvlmQHNP5toY2OOgmY/qjNo9/a/Ro5bbO+wp4ie7mlaY+tZLw6kv615vfY3CbxRUExIGAA7FiUVk4prqo9wOHetMJeTy6t/VApNznl0uqAvuUun3yHzUV6WPdHG18PKbj4Ru510uEZmWYuYgiLghxwSasJNwrADDjKdQ8HGsJj8Eka5nJI8TS6k55/wiSi0ARjkQX/+kxcj07LdQ7mAJKhfMR/4aRqMNhpkRjKoYTV47dzdkUftih7/rXxzPTXWvLe2ByJDdy+oOmEyEiQSA2o3S3GYuxx8sThiEOg+G3lbpa1Vmv/NxQAtmoojZRhHmluMcNYuk6mDGkF4U3iV5BJXKExfE5WIJxFa2iv37Z+OuOD9ocY28aP+7rzIfrwQYckftpMJiv3zrHoFl5tHjR26kLhOZotmMnlWTDrO0X3y0d5X9dwYVRvhKo+3uU8+h0laie/KCtlrSSUMgbEm0JJ2r4HE9geuZlZ1XYCgKevCw9to9Ue/ZHf0Id+cYYf0EkqVr4evTXcPdEj9JX7eg/JUKKoh+dgCxEtMmkb3FtGHCIukXy4g4wr5VqyGENzLb/47pbOU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(376002)(346002)(39860400002)(366004)(8676002)(6496006)(26005)(66946007)(5660300002)(66556008)(66476007)(83380400001)(478600001)(956004)(1076003)(6916009)(316002)(38100700002)(54906003)(6486002)(2616005)(86362001)(8936002)(36756003)(6666004)(4326008)(186003)(16526019)(2906002)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?SzZ3Tm41NGViTjA4UUliYzBRV0hScjJ2WWFUTFgzWExOSit4N1dJSjJPc2sy?= =?utf-8?B?UXBldWlzNGZHamNqTHBUN2Z1c3JJQlRhczBOWEVjQ3hSMFA0MVl2T3BNMU12?= =?utf-8?B?YmpJWXBnWFozY2p2blFPREJHYlRJdU9QWEpXVlRWd2lhM0ptNmJ2UldDWERr?= =?utf-8?B?OWNGMmx0bHpPdzZkTlpzbEtvVEdxalhDUGRyVkpGdUZOZ1YyWlp4bEZlcDZV?= =?utf-8?B?TzNHNGFESU5yVkRtaWgvZTdtWjlwNjdoR2tYRWZWa084YmxhNUg5Qzc2YU8r?= =?utf-8?B?K1RKdG9oZ0dYS1Y2ZTJ0dE84dGxxUlhXaXFidTFFWXJyRS8vZXBXNkZaUUR2?= =?utf-8?B?bnVTNkFnTURwUVFwY2UxRjdCV01vR3FvYXFTMkdjU0VlaU1HbCtNM2w3WHEz?= =?utf-8?B?Tm5GdUh5NDVsYU9ITmxh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51eWorYzZJZS84Y0pHdnp1Sy9nVXJ6d0F0d1Y0ZktvTERDQ2pUQ0VFdCsw?= =?utf-8?B?cXdPNlJlV1VRdlNFcUhGVlNld21FcVZUUFVHN0RHdnE4c3Uvam1aZ0NXazZD?= =?utf-8?B?VDFqVXFNSWJLREpuVG0vdDNOMloyL0JUdmVvUlFBZG9mclFNcXByejJXYUlB?= =?utf-8?B?M3E4c2RVNWdHY0sxb3dkSVhHM0hncnFSL0NNQWMrWjdVd1hPWVVQRFMwcjhw?= =?utf-8?B?bEJjb1RyWWVBVlBRb2tzYXZGbUNyNC9IQ2N0dmdxS2RvakJzck9Hd0p4OWZV?= =?utf-8?B?QlZXNDNGdi9jMFFSSkpNbFZJT2I1Sy9NcGo2ck1pL0JjNUZsbWJBbWdqOXFI?= =?utf-8?B?M2pkSTF6WmJoRTJCRHVWeHN5bjlSZGlDZmJxckN2VkFRMHFCTXJsalFCTkxs?= =?utf-8?Q?0jZpzPDs4one0c+/y5rwuHQBpD2XObrqQKFnZkW?= X-MS-Exchange-CrossTenant-Network-Message-Id: d63b2104-3c98-4d8d-78f3-08d911483cf3 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 11:07:00.9543 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: L9wg+0jwBTtXn9ER+EzgzyXGOOmDjbLhmZEAd8SuDWccrzQoRYEab4i/sTipZVV4Ca4PJjWZbnABxLeZHOUziQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4475 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) Use such helper in order to replace the code in x86_msr_copy_from_buffer. Note the introduced helper should not be directly called and instead x86_msr_get_entry should be used that will properly deal with const and non-const inputs. Note this requires making the raw fields uint64_t so that it can accommodate the maximum size of MSRs values, and in turn removing the truncation tests. Suggested-by: Andrew Cooper Signed-off-by: Roger Pau Monn=C3=A9 --- Changes since v3: - New in this version. --- tools/tests/cpu-policy/test-cpu-policy.c | 48 +++++++++++++++++++----- xen/include/xen/lib/x86/msr.h | 19 +++++++++- xen/lib/x86/msr.c | 41 ++++++++++---------- 3 files changed, 75 insertions(+), 33 deletions(-) diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-pol= icy/test-cpu-policy.c index 81de9720c8d..854883fbb39 100644 --- a/tools/tests/cpu-policy/test-cpu-policy.c +++ b/tools/tests/cpu-policy/test-cpu-policy.c @@ -389,16 +389,6 @@ static void test_msr_deserialise_failure(void) .msr =3D { .idx =3D 0xce, .flags =3D 1 }, .rc =3D -EINVAL, }, - { - .name =3D "truncated val", - .msr =3D { .idx =3D 0xce, .val =3D ~0ull }, - .rc =3D -EOVERFLOW, - }, - { - .name =3D "truncated val", - .msr =3D { .idx =3D 0x10a, .val =3D ~0ull }, - .rc =3D -EOVERFLOW, - }, }; =20 printf("Testing MSR deserialise failure:\n"); @@ -744,6 +734,43 @@ static void test_cpuid_get_leaf_failure(void) } } =20 +static void test_msr_get_entry(void) +{ + static const struct test { + const char *name; + unsigned int idx; + bool success; + } tests[] =3D { + { + .name =3D "bad msr index", + .idx =3D -1, + }, + { + .name =3D "good msr index", + .idx =3D 0xce, + .success =3D true, + }, + }; + const struct msr_policy pc; + const uint64_t *ec; + struct msr_policy p; + uint64_t *e; + + /* Constness build test. */ + ec =3D x86_msr_get_entry(&pc, 0); + e =3D x86_msr_get_entry(&p, 0); + + printf("Testing MSR get leaf:\n"); + + for ( size_t i =3D 0; i < ARRAY_SIZE(tests); ++i ) + { + const struct test *t =3D &tests[i]; + + if ( !!x86_msr_get_entry(&pc, t->idx) !=3D t->success ) + fail(" Test %s failed\n", t->name); + } +} + static void test_is_compatible_success(void) { static struct test { @@ -864,6 +891,7 @@ int main(int argc, char **argv) =20 test_msr_serialise_success(); test_msr_deserialise_failure(); + test_msr_get_entry(); =20 test_is_compatible_success(); test_is_compatible_failure(); diff --git a/xen/include/xen/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h index 48ba4a59c03..9d5bcfad886 100644 --- a/xen/include/xen/lib/x86/msr.h +++ b/xen/include/xen/lib/x86/msr.h @@ -17,7 +17,7 @@ struct msr_policy * is dependent on real hardware support. */ union { - uint32_t raw; + uint64_t raw; struct { uint32_t :31; bool cpuid_faulting:1; @@ -32,7 +32,7 @@ struct msr_policy * fixed in hardware. */ union { - uint32_t raw; + uint64_t raw; struct { bool rdcl_no:1; bool ibrs_all:1; @@ -91,6 +91,21 @@ int x86_msr_copy_from_buffer(struct msr_policy *policy, const msr_entry_buffer_t msrs, uint32_t nr_en= tries, uint32_t *err_msr); =20 +/** + * Get a MSR entry from a policy object. + * + * @param policy The msr_policy object. + * @param idx The index. + * @returns a pointer to the requested leaf or NULL in case of error. + * + * Do not call this function directly and instead use x86_msr_get_entry th= at + * will deal with both const and non-const policies returning a pointer wi= th + * constness matching that of the input. + */ +const uint64_t *_x86_msr_get_entry(const struct msr_policy *policy, + uint32_t idx); +#define x86_msr_get_entry(p, i) \ + ((__typeof__(&(p)->platform_info.raw))_x86_msr_get_entry(p, i)) #endif /* !XEN_LIB_X86_MSR_H */ =20 /* diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c index 7d71e92a380..4b5e3553e34 100644 --- a/xen/lib/x86/msr.c +++ b/xen/lib/x86/msr.c @@ -74,6 +74,8 @@ int x86_msr_copy_from_buffer(struct msr_policy *p, =20 for ( i =3D 0; i < nr_entries; i++ ) { + uint64_t *val; + if ( copy_from_buffer_offset(&data, msrs, i, 1) ) return -EFAULT; =20 @@ -83,31 +85,13 @@ int x86_msr_copy_from_buffer(struct msr_policy *p, goto err; } =20 - switch ( data.idx ) + val =3D x86_msr_get_entry(p, data.idx); + if ( !val ) { - /* - * Assign data.val to p->field, checking for truncation if the - * backing storage for field is smaller than uint64_t - */ -#define ASSIGN(field) \ -({ \ - if ( (typeof(p->field))data.val !=3D data.val ) \ - { \ - rc =3D -EOVERFLOW; \ - goto err; \ - } \ - p->field =3D data.val; \ -}) - - case MSR_INTEL_PLATFORM_INFO: ASSIGN(platform_info.raw); break; - case MSR_ARCH_CAPABILITIES: ASSIGN(arch_caps.raw); break; - -#undef ASSIGN - - default: rc =3D -ERANGE; goto err; } + *val =3D data.val; } =20 return 0; @@ -119,6 +103,21 @@ int x86_msr_copy_from_buffer(struct msr_policy *p, return rc; } =20 +const uint64_t *_x86_msr_get_entry(const struct msr_policy *policy, + uint32_t idx) +{ + switch ( idx ) + { + case MSR_INTEL_PLATFORM_INFO: + return &policy->platform_info.raw; + + case MSR_ARCH_CAPABILITIES: + return &policy->arch_caps.raw; + } + + return NULL; +} + /* * Local variables: * mode: C --=20 2.31.1 From nobody Fri Nov 29 22:49:57 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1620385648; cv=pass; d=zohomail.com; s=zohoarc; b=kmSbqtcWubrOm8+6GgSILeh+IXsZT4Dyb2/jzoC+5hGrcrlqhRcV/Q8c3h2OIWaigaSRKjSoahs3chCZVUUmLmAxysr7YE1+vsDmwvzzUREKNWsPq8bXbU7BYCyMzgj+Qs38ELKr8oAjVLtQvuDJtzwhpp59p/9GSi6GY62VPc8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620385648; 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=ZFiEJE/7tweLfCqiWGwMSdcuoNYoTfrGmGb2P+8nYGc=; b=O3gPP3mfFzkGGLTJXkIOupeExDxw9YoaEaA/y3lxhiBcW35Fu8WZPv4ElmSlocqRHtIhvm5PTewAIoXGNSbZ0MPTLTeO4xS4Qamk+/0tIO9UecERAzkrrxFEPkOTITy/iHKSwic1syTtU7t5xnlQ92q6tENBXMYqTFHcy8N1FAw= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620385648293376.0608290683059; Fri, 7 May 2021 04:07:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.123963.233962 (Exim 4.92) (envelope-from ) id 1leyKA-0004Iq-Qc; Fri, 07 May 2021 11:07:14 +0000 Received: by outflank-mailman (output) from mailman id 123963.233962; Fri, 07 May 2021 11:07:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leyKA-0004Id-Mj; Fri, 07 May 2021 11:07:14 +0000 Received: by outflank-mailman (input) for mailman id 123963; Fri, 07 May 2021 11:07:13 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leyK9-0004Ft-9F for xen-devel@lists.xenproject.org; Fri, 07 May 2021 11:07:13 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d44f0357-35f2-497e-9f5d-e0d4b2da5183; Fri, 07 May 2021 11:07:12 +0000 (UTC) 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: d44f0357-35f2-497e-9f5d-e0d4b2da5183 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620385632; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=gLlCE9etf3gr9KUeqpSgZ+qsCzt5Isc3p8Bma0wZMcA=; b=V31Xg3E7EXRueT539etYQesTh0S6n2vxkEi6ID7/nn/YiG3NmNvtQtHq Fq/jWEt7jtQbX/lPWh8jxHLvBsjxHdeA9F9wr8q6xL+pu+gscGXRqYGCH FkEiDh4A6C4cghVYNuf39l0+iEqf1qbUeJE0aspu0V5S6Qrarqqbe2Nfz U=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: 0XEVxeCkgPP3MJ8zvkOM9bW3fa7tRXOPah6AlJsP6IJK/7PSvjmNkIANF+uJHcu9GdVauWf2/R 2uX+pmAc4MJneBqeE7IH8o6XMAI4xRSCOQbB0b6bDopLeWSm4i9UFIJKmU4Wqm+81oyV4s3KgH n2etB9Y6HwLrxv5xowRZPmKu7sSViByCYndlIsegkhTAi5oJu/+nZHaEP2QJR9DuHEbynlALPL yhsCZD5CzjKtaqTQoimhgAw4hgSpuO1gDVNgf3m8GzELCUuJAOtSMjRv6pG3j9UDxrFfpbSKpl NtA= X-SBRS: 5.1 X-MesageID: 43096222 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:gXwzZ6zyPKc9zSPfDdMmKrPw1r1zdoMgy1knxilNoHxuH/BwWf rPoB17726RtN91YhsdcL+7V5VoLUmzyXcX2/h1AV7BZniEhILAFugLgbcKqweKJ8SUzJ8+6U 4PSclD4N2bNykGsS75ijPIb+rJFrO8gd+VbeS19QYScelzAZsQiDuQkmygYzZLrA8tP+teKL OsovBpihCHYnotYsGyFhA+LpL+T42iruOeXfYebSRXkDWzsQ== X-IronPort-AV: E=Sophos;i="5.82,280,1613451600"; d="scan'208";a="43096222" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TtBUQR/5Vfr9FzBxfvpAet6RymtnqRWfcpqg4BtAiwED9JhDre5rvgf+jBR8qsu3KMdHccTgmxod7yMLwRllWXM/dXMmrzTSzDbWrPUTwEkyHRkEPwNl8yHS3WlGtea34p/kXzbk9KsqNsYNKR2ggItS00HNgCT1t2ADYonFf4qRt89nnxQIOuAqftwSlTFTtT6PdhML6XVgFytOHq5atn/TjcXtHyaEu0OiLQHYHDv5A+X8Rrb4FxCfwkm+soJ858clzQa8K9Jn+zjAhQcSChXqDi9EdKNo1t5Qy571E7u4AeKDmGPsvEYVQKr9w1HfO3B+lqeVvueQOavd9bWw+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZFiEJE/7tweLfCqiWGwMSdcuoNYoTfrGmGb2P+8nYGc=; b=lhP3T70AXPGiR/NGd+UtLjlkgEAHJfirCuYZGnMLdbRfRWrDvUjT3poFh/w2WCCkqA4L0x1A2W3b06v7uCG4Q+DrIExAJu2WV9/0foygMMFoaC6Rhhi9IBgNW4QrAeC6Zw81h8IzPWwdK6BfcNcfxfwcRVjxVO//dDN4M1Y6+rHHImVfT6W0yH+YwV+oYr+ilcUL4EQIfjm04iYNHa2N4j0HSRtVrlBMKd896Nli49b7kwfVAUQ6VfRRVbQCpu5gGrokLBj3ZZZb+/CutfLc7zNTM6BtPvd+jfbE6cBAnTTSQ/lftJsAMzT5AXiJ0lmjtd4v1thutKLAfkXZpaUluQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZFiEJE/7tweLfCqiWGwMSdcuoNYoTfrGmGb2P+8nYGc=; b=Hnz1VIO9BchCJEoq8j5sJ+hRvrx32LDiNL/JfzFk7naRAXN6s+FMT0zLhOHMtORX29J8enBPYqDGfG1hv0gyVthFThIr/z3T5Kh3VVVHvtHASpEVVRXQQSdP63bpgumBQV1n1dJjh60eU/CQQAlLsIeIF7IHESiCUEQn0tTEp5g= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH v4 04/10] libs/guest: allow fetching a specific MSR entry from a cpu policy Date: Fri, 7 May 2021 13:04:16 +0200 Message-ID: <20210507110422.24608-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507110422.24608-1-roger.pau@citrix.com> References: <20210507110422.24608-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR2P264CA0055.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:31::19) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5beccb37-55fd-4398-1d13-08d911484079 X-MS-TrafficTypeDiagnostic: DM6PR03MB4475: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nJCs3J1vTBEQoX5ebu6k19yYh4Ob6MZgsWaVZPjPR2zUt6SNMJAwSppNgFotJ/lxrTj/QMxY5EXf01v4O9ZOlSUvSTAT0WVyVhj5Pwgr31+C/QeEueCUgTvYty/5p1bkWzyPXSJvzoqfq0zRL9xQxf+gx48TawzZWRAJf2+4MnOji+L+f1Tt8JVnjnD2jj3nofUx8VnwmVY0ZckJJ+Rdvx6r2Q/JJU9nyWwUbC8tT5WaQ8KryNYGYjf5Vlwiz7wzVpmD3I5wTiPKIr/pwv15d36uqBMPqtc9HvSvkKbQ9RE2FV+6slg6pGKImf9BRUvz/IG+L/pneHr6srw5G3teKAUfUXM4KNUh+8tKe4BDqM0akTg4lACsSWyL5JccEzzRZpFI6hjiWO8yuycuc4WuWLotvhfP5IKXgX2hILK2OkyDCG8i2jbV58LWuLHQeSuoo1v92cQRcnKavP3ICIrd5WxrVk6GM9ZyKdGf/afogaDiGRZKPe/21X6KZ0P5KQ2GUtd+V3V0l44dKFgD4edzp+btlJ37qSozVIS3Jbp3alnaaItDEKDMSCk3sHKXuGLplmaeOpZi3uG77TJz4b+WREmDhfLGLOLx3cXMi+zIXRA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(376002)(346002)(39860400002)(366004)(8676002)(6496006)(26005)(66946007)(5660300002)(66556008)(66476007)(83380400001)(478600001)(956004)(1076003)(6916009)(316002)(38100700002)(54906003)(6486002)(2616005)(86362001)(8936002)(36756003)(6666004)(4326008)(186003)(16526019)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-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iexQIQWgckxacQNvtiQo7nraFn0UEbD8u?= X-MS-Exchange-CrossTenant-Network-Message-Id: 5beccb37-55fd-4398-1d13-08d911484079 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 11:07:06.8474 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: q7nbra2GcX7zG0CQF8deHXrdv9YigLlAXYqIGkqIFsFrsf2CuelA/FRg8Qf3KXEv7sL7VfCKqaVZwClQP75c/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4475 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) Introduce an interface that returns a specific MSR entry from a cpu policy in xen_msr_entry_t format. This is useful to callers can peek data from the opaque xc_cpu_policy_t type. No caller of the interface introduced on this patch. Signed-off-by: Roger Pau Monn=C3=A9 --- Changes since v3: - Use x86_msr_get_entry. Changes since v1: - Introduce a helper to perform a binary search of the MSR entries array. --- tools/include/xenguest.h | 2 ++ tools/libs/guest/xg_cpuid_x86.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h index 7001e04e88d..8e8461b0660 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -747,6 +747,8 @@ int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu= _policy_t *policy, int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t *poli= cy, uint32_t leaf, uint32_t subleaf, xen_cpuid_leaf_t *out); +int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t *policy, + uint32_t msr, xen_msr_entry_t *out); =20 /* Compatibility calculations. */ bool xc_cpu_policy_is_compatible(xc_interface *xch, xc_cpu_policy_t *host, diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x8= 6.c index 460512d063b..cdfc79a86e7 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -883,6 +883,26 @@ int xc_cpu_policy_get_cpuid(xc_interface *xch, const x= c_cpu_policy_t *policy, return 0; } =20 +int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t *policy, + uint32_t msr, xen_msr_entry_t *out) +{ + const uint64_t *val; + + *out =3D (xen_msr_entry_t){}; + + val =3D x86_msr_get_entry(&policy->msr, msr); + if ( !val ) + { + errno =3D ENOENT; + return -1; + } + + out->idx =3D msr; + out->val =3D *val; + + return 0; +} + bool xc_cpu_policy_is_compatible(xc_interface *xch, xc_cpu_policy_t *host, xc_cpu_policy_t *guest) { --=20 2.31.1 From nobody Fri Nov 29 22:49:57 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1620385653; cv=pass; d=zohomail.com; s=zohoarc; b=SaGBISfiTixhLK2EtdsYZ3guwWrBLYAfUCNG8Q7DvPJ8EUllyBcPE9ysKDgPLBO8PnUGOcDsKLbEaQvxIe/fM7PDREboVEOnc7xpHWkXxAa22uqNg8LAHKFLSRBDPVoC8+xxhmRugDr1EcjU9Vr5kE4A+FGDooLkK5ZYDk+Dn9c= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620385653; 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=v1TbxRetccB3cqkr4MGIU/LGmnU1UmJDCQ3gYxtvhWg=; b=lR3bZyfndyAC37Fp6YI3HEI+5n8Pb00wV+5lL2MiWDvS/czSuTORP9wQbTUVzn1/GNaJ8SVU4bAHynSsT8V1ElQ5yXdt2asuvAYwTL8LRoZwbG0FNBbX3DHhqHp61FbMB0u0hyLcrQNobT84xYEGtsZ8SLKzNvyWmi0JAy5/joc= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620385653051711.0457379495015; Fri, 7 May 2021 04:07:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.123966.233974 (Exim 4.92) (envelope-from ) id 1leyKF-0004pB-5c; Fri, 07 May 2021 11:07:19 +0000 Received: by outflank-mailman (output) from mailman id 123966.233974; Fri, 07 May 2021 11:07:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leyKF-0004ox-1r; Fri, 07 May 2021 11:07:19 +0000 Received: by outflank-mailman (input) for mailman id 123966; Fri, 07 May 2021 11:07:18 +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.92) (envelope-from ) id 1leyKE-0004jI-1X for xen-devel@lists.xenproject.org; Fri, 07 May 2021 11:07:18 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3f452d81-4586-43ab-b104-aa97b66944c0; Fri, 07 May 2021 11:07:17 +0000 (UTC) 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: 3f452d81-4586-43ab-b104-aa97b66944c0 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620385636; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=DK5Oj288zwi/pAzruQfeshpv1Ya6qkXUi9NgpMqGtpg=; b=R7tY8x0G4c2mpGV0JrgGN5/sF/hFILVOrCqtoOwtMot4ZXzKjG6FVmLx j0agdiTrkrKmF0M3cJHIo6qHWpCePJGu/BX7zEx0oNQaLpN2ghB7otl+E 4nPGhSBRpU7TFpHXFj4267QIiXQku7hpJaiAifqkA8T5tlgTvqyzxAqWq w=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: wBLs1wbGBlphFIMXsJra93bid4GkQexU8WJqk2kgcZC+JcxMxYIUsQW5WyMab5z+kY4Bm/1F6P AIxsXPswh9K1ClVbsKYj+z6sy4aQWSMIi1WEHNJI0JRvEgOdA06qvhUYt42l11lur6Wi/kIcBS y65/M3lZKyEU/TfgcEp5dwEouxFAYQunc+3Sht4qCMTfuZy6YRMMaqh9634ye1enSfMCOIpjjK i7w/faXl7Nf6s+sedB19DtbS4eSOBZ89vJ8IWRtYJOoekh9boOB1yY12AkZ56Si/AY05zqHtGp ut0= X-SBRS: 5.1 X-MesageID: 43304421 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:/50QaKs7KHJAbbCB6XXX9Z807skCRIMji2hC6mlwRA09TyXGra 2TdaUgvyMc1gx7ZJh5o6H5BEDyewKmyXcV2/hbAV7GZmXbUQSTXeVfBOfZogEIXheOj9K1tp 0QOZSWaueAamSS5PySiGbXLz9j+qjgzEnCv5a8854Zd3AOV0gW1XYaNu/0KC1LbTgDIaB8OI uX58JBqTblU28QdN6HCn4MWPWGj8HXlbr9CCR2SyIP2U2rt3eF+bT6Gx+X0lM1SDVU24ov9m DDjkjQ+rijifem0RXRvlWjoKi+2eGRhOerNvb8yvT9GQ+cyTpAo74RGYFqiQpF4d1HLmxa1e Uk7S1Qe/iboEmhBF1d6SGdpjUIlgxepkMKgGXo/UfLsIj3Qik3BNFGgp8cehzF61A4tNU5y6 5T2XmF3qAney8osR6Nk+QgbSsa4XZcYEBS4tL7hEYvGLf2qIUh2LD32XklWKvoMBiKmbzPId Mefv00vswmD29yR0qpzlWH7ubcIUgOIg== X-IronPort-AV: E=Sophos;i="5.82,280,1613451600"; d="scan'208";a="43304421" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SwW2R73A/0+ioVdnKEkHQHsR7vMSjrqBtJ2MkI6uowitw7PkCupMOUGHkwBa8SlzfIxB1dawC9P3Rn/WnwdP3+dF1wdEWXT9vrP5JDuE1JTxvxeMF5w5vEBKKcB8WHBJQvuv4HW1cgbyAVaiQsEkDTWpaUXuCFYOQDY5GZjFcubOn5iP/qoYQvagpH4BRGvsByQ+WIggs+KgipPiZiJy9/i2psHr8EyGSEFKTHouZEsAAyZ//W63rvax7QvAsosYzAIG0Hy4TGvTIdlWRGpI6Ay7k2QRC465ltySk+bn3RIzerzXaJe3zeUPI89v/HObxrrFnKeXWkW5eHH1Di137A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v1TbxRetccB3cqkr4MGIU/LGmnU1UmJDCQ3gYxtvhWg=; b=KNl9EbkDfJ/eVyq90odXqQsnEOIVgKOv6PGczUZtpQpMsyyyeKCg78P+kITAfCHnS60zGpUCS0E9SCUVNKYs2R9VpEV+Jemz7dtsbymu7/YVYoqQMuSDZTgBAxDikrpQho8xqdLuWf+Wo2CXdlLEgmDq8RZVgtlPuFweAc8EhwRdenprJljyebef673uBmTBXrID7YS8JPzvzV/wUfkJJAM9IJWPFXjdh9bAXFsviKBXdYYiM5vaJP2cq45TKiVLLNAX086XA3G+4R3ZcDiRfBvrxjozHHLvfveh5p8X0JIDNg8oa1QzzrtEIeMoobrGsk18TmmeWtpvTNwpC/qw3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v1TbxRetccB3cqkr4MGIU/LGmnU1UmJDCQ3gYxtvhWg=; b=SrwvTE9EKfw1wqlj6BuH9oAidxpkVESk8I76+y0nfOkpKYHYT66bkZ/JKjMn6vrMWMat7hZMvG8SULUQx8LJKXQSsr5r4YDoXf7SthpTnJy7uWuHNB1HEWBz6XswLN4DVcZdSrNYgobbHWi+Lw4B84HU1XplpCKKBd1icJ7Zn8A= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH v4 05/10] libs/guest: make a cpu policy compatible with older Xen versions Date: Fri, 7 May 2021 13:04:17 +0200 Message-ID: <20210507110422.24608-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507110422.24608-1-roger.pau@citrix.com> References: <20210507110422.24608-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR2P264CA0062.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:31::26) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 79327a89-74ea-48ae-fe47-08d91148444c X-MS-TrafficTypeDiagnostic: DM6PR03MB4475: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Nji8Zv8BmCfGnXxEJYveZmQ11ipTMPUIcDHyEsm9HmvEw0LrtFWogjMd01JCagj/IJ35FZDQJQi6f45rhiIn5/BTfI0eDkPaokwjHxI8V+qHUlcEKyE03DtFGew4t2NOKy7TMvdWM8hMl6hYTT3PL8rnlxRPvgMIY6NhYpYu+Cj7jQyp1soEp57v8VD6JpC2OhDExL0ukS5V31yaxddSNJcg2a7DZF9RphrWHoK1DON2OLQwHuyI5sZBYDgqb3oAc5Aux7iiClrd2y8HyMgqOvsGvBhPhayQnU0KrY4wWB1PnmpLzH2LZ82bsZJJ77aMYw/XOe5DhOsNroUVjlE5MN1rwyhtSLLoqr46yIUa9ymYAVFe5HQokFT4G8/H2j8Gw9kjVIJM32Mxqt82mItWtEzr8YJFl0vAfrKa7TK96JuqlV3s0aK60giLaSdcPF/N0jY+3iyy4/i4+StHz3RBceWJB5f2KylzVYdIZY2VeS0bCQUQ6Z+gBSfpsgA17VhqQrUxBew7X87N8MnqPIHH/EurP/YPef1j+2F50tz2uSFKRznbNxaB2p3H3p9HK181pEtfQnuZWT74A1axnjWPMw7+LcRUPOznJTXF/YQs2KE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(376002)(346002)(39860400002)(366004)(8676002)(6496006)(26005)(66946007)(5660300002)(66556008)(66476007)(83380400001)(478600001)(956004)(1076003)(6916009)(316002)(38100700002)(54906003)(6486002)(2616005)(86362001)(8936002)(36756003)(4326008)(186003)(16526019)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?dytKaFpFZ2tyWkU1aGY1bXA4d1l1UGFxaHdIRktjYmgwZDBsNVBoQWRWN2U1?= =?utf-8?B?dm81R3JUNWk2cmJnQnhtZEZVbi9DOWNCQ255VkNLL0RzMjAxcWhXWW5wTzNI?= =?utf-8?B?Q01aNUx6NjAvcGpNdHhRYlR6cDV1RTMvM2VxMmVaUzZHQVZOaDZWS3U5N1Fq?= =?utf-8?B?eUltaXQrTWxiSExtUDZ1Z0ZNMU44Lzg3V3RRZGRqVHozR20zbm85eVZaWUsz?= =?utf-8?B?eDZ5TEh5SzF2ZEVRamxtZ1pXNkg0cE1ZSlBQaUdjNmhJeExwdGVkSjZMQkw5?= =?utf-8?B?bHRPdTFSTWtSRjF0ZHVrZElOL2VJOStwNzNjNFUzNkhDdGdHVGlMbVpHVm91?= =?utf-8?B?alpsZG1PWlBqQnVPaDByUUUyL05vckw0Q0x5QkVydUwvQ2ZnUUFWWGpkd2h1?= =?utf-8?B?SkJ3R2VNeXBONnpaVnFOZFlReW42SUdFMXhhaUQ5L0xMcmFSQXdoaEp5bVZh?= =?utf-8?B?b3NCTEY2RXhXUG9uRFFGZURWNTg1N1NDMXo4cXhjazFlN1IxK3F2NXllUmhP?= =?utf-8?B?emU3S3NNcFJnUXo5WFJvZUJqcm5yYW9hY0tubzVrdE54dVN1WGxkRDlDVjRV?= =?utf-8?B?VGgreDhmUytkUGtnSk9CNHB1OThwRG90d2ljbWltZFlRQkZiTHphODlPNHgx?= =?utf-8?B?c3FObzh6ZHZwNldkaG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?= =?utf-8?B?Ym5DU0FxdGNzRlM0TnB4NVlWcURRbjFrU244RWZkcElML1VWUW1TeUNsZ2F2?= =?utf-8?B?akptM01vdDVmc2poZm56ZGNrdURSdGlWZU1nVjk2TWdrN3Znbnd2VVY3U1hP?= =?utf-8?B?Qk1PaFEwYlJrT1Urd3B1RTNwTEczeHo4M2FPa2RHQi83RW9WUXNJWVRrd2dk?= =?utf-8?Q?kZAxIrzSXt1bxsSVqzBZ/8AP0ZgeEIc7PgAYxgS?= X-MS-Exchange-CrossTenant-Network-Message-Id: 79327a89-74ea-48ae-fe47-08d91148444c X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 11:07:13.2691 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1MQwioud98NuvP4W1aNsUynhRKCtLm7wRUBkg0xjHdS54zRjy5DFzN3Eb+tWL6SfWhMAaNPr9iCunGcNN371Jw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4475 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) Older Xen versions used to expose some CPUID bits which are no longer exposed by default. In order to keep a compatible behavior with guests migrated from versions of Xen that don't encode the CPUID data on the migration stream introduce a function that sets the same bits as older Xen versions. This is pulled out from xc_cpuid_apply_policy which already has this logic present. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 --- Changes since v3: - Rename function to xc_cpu_policy_make_compat_4_12. Changes since v1: - Move comments and explicitly mention pre-4.13 Xen. --- tools/include/xenguest.h | 4 +++ tools/libs/guest/xg_cpuid_x86.c | 58 ++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h index 8e8461b0660..576e976d069 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -754,6 +754,10 @@ int xc_cpu_policy_get_msr(xc_interface *xch, const xc_= cpu_policy_t *policy, bool xc_cpu_policy_is_compatible(xc_interface *xch, xc_cpu_policy_t *host, xc_cpu_policy_t *guest); =20 +/* Make a policy compatible with pre-4.13 Xen versions. */ +int xc_cpu_policy_make_compat_4_12(xc_interface *xch, xc_cpu_policy_t *pol= icy, + bool hvm); + int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps); int xc_get_cpu_featureset(xc_interface *xch, uint32_t index, uint32_t *nr_features, uint32_t *featureset); diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x8= 6.c index cdfc79a86e7..fccbc54a400 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -441,6 +441,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t d= omid, bool restore, unsigned int i, nr_leaves, nr_msrs; xen_cpuid_leaf_t *leaves =3D NULL; struct cpuid_policy *p =3D NULL; + struct xc_cpu_policy policy =3D { }; uint32_t err_leaf =3D -1, err_subleaf =3D -1, err_msr =3D -1; uint32_t host_featureset[FEATURESET_NR_ENTRIES] =3D {}; uint32_t len =3D ARRAY_SIZE(host_featureset); @@ -505,21 +506,9 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t = domid, bool restore, =20 if ( restore ) { - /* - * Account for feature which have been disabled by default since X= en 4.13, - * so migrated-in VM's don't risk seeing features disappearing. - */ - p->basic.rdrand =3D test_bit(X86_FEATURE_RDRAND, host_featureset); - - if ( di.hvm ) - { - p->feat.mpx =3D test_bit(X86_FEATURE_MPX, host_featureset); - } - - /* Clamp maximum leaves to the ones supported on 4.12. */ - p->basic.max_leaf =3D min(p->basic.max_leaf, 0xdu); - p->feat.max_subleaf =3D 0; - p->extd.max_leaf =3D min(p->extd.max_leaf, 0x1cu); + policy.cpuid =3D *p; + xc_cpu_policy_make_compat_4_12(xch, &policy, di.hvm); + *p =3D policy.cpuid; } =20 if ( featureset ) @@ -921,3 +910,42 @@ bool xc_cpu_policy_is_compatible(xc_interface *xch, xc= _cpu_policy_t *host, =20 return false; } + +int xc_cpu_policy_make_compat_4_12(xc_interface *xch, xc_cpu_policy_t *pol= icy, + bool hvm) +{ + xc_cpu_policy_t *host; + int rc; + + host =3D xc_cpu_policy_init(); + if ( !host ) + { + errno =3D ENOMEM; + return -1; + } + + rc =3D xc_cpu_policy_get_system(xch, XEN_SYSCTL_cpu_policy_host, host); + if ( rc ) + { + ERROR("Failed to get host policy"); + goto out; + } + + /* + * Account for features which have been disabled by default since Xen = 4.13, + * so migrated-in VM's don't risk seeing features disappearing. + */ + policy->cpuid.basic.rdrand =3D host->cpuid.basic.rdrand; + + if ( hvm ) + policy->cpuid.feat.mpx =3D host->cpuid.feat.mpx; + + /* Clamp maximum leaves to the ones supported on pre-4.13. */ + policy->cpuid.basic.max_leaf =3D min(policy->cpuid.basic.max_leaf, 0xd= u); + policy->cpuid.feat.max_subleaf =3D 0; + policy->cpuid.extd.max_leaf =3D min(policy->cpuid.extd.max_leaf, 0x1cu= ); + + out: + xc_cpu_policy_destroy(host); + return rc; +} --=20 2.31.1 From nobody Fri Nov 29 22:49:57 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1620385666; cv=pass; d=zohomail.com; s=zohoarc; b=J92oO0BiDBhjDCGqvq15F1big3/NyD0k1FBYV4jBiDNibkIqzAelETAt5tAHzBkZBqfMb7upZedR0gSye45HmTB/ySAP3udt0regs17iRyq8ppXay4ntnuUgjrFKRl6Ii0+qDz9VbEDU1RjX/MstmJckobnhRxNdaQ29bA3QDt8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620385666; 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=kNLcteEg52/2FZe+Swj7NwnygUOC6JFeRCiZi3dQW6s=; b=CHSVcxBH4d70+l2B/auMYVXUgXB1CaiHOks/CeWQkFY2h2gD71vDWpnW+04MzSLQBrisUzoLcP09az+uFVson0AKjtFr6j1fy+bL5/z07Zt6hVyRoBtGxQ+LYMA7IwkifkRY+V7+LyN0prkQ3d0xTOApb719rlhiSqMHHXsvLSc= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620385666486782.7214121023247; Fri, 7 May 2021 04:07:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.123969.233986 (Exim 4.92) (envelope-from ) id 1leyKM-0005W4-O0; Fri, 07 May 2021 11:07:26 +0000 Received: by outflank-mailman (output) from mailman id 123969.233986; Fri, 07 May 2021 11:07:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leyKM-0005Vp-KI; Fri, 07 May 2021 11:07:26 +0000 Received: by outflank-mailman (input) for mailman id 123969; Fri, 07 May 2021 11:07:24 +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.92) (envelope-from ) id 1leyKK-0004jI-Bh for xen-devel@lists.xenproject.org; Fri, 07 May 2021 11:07:24 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c0c0e2fe-2e4b-4ac0-add2-deba8a8c49ac; Fri, 07 May 2021 11:07:23 +0000 (UTC) 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: c0c0e2fe-2e4b-4ac0-add2-deba8a8c49ac DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620385643; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=t57/ixwUki9bA5ay9uC2e1ZSSlVDTWnCzfy83CT1KWI=; b=cjilg0uq7HyTFE6dFoRv90P8m6jP9ib+gBgLeqsJajLt4/wnFj6TV43i vXHvuesBiCVhU+b8OE65jtjKKhgCzgjMkhtFqoLpKN272tn7CoVquSP61 onk+XZ775x4w2V3n5T2sdWtuxUbehr9k7K9+CEuoKawo7tZwxaRN2Wph6 w=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: qGDFAcDFgm/sItkJgbJlWxBnHS8sQh5BU0nuZEXQ2/BK52qUIzURyAA2jR4/J2+a632WmT3oT/ AesPYv35r1nfyuocTc6BCzYPxjIjPCrhemlJvwBQFpJPiGZSoIk9HaYluHHtBZ/gySXW7azYZh ovlQEjSGIETLP8Brr66Z+7orkQng565sQ34Qld7rqeg0k+KnSk4rZQEwIkYVe1Zcfr/7PIEFh3 ihq7nW3e3vjrpRj7nqlrxUuWFC5nvgXddYgskCtxaR4khERvpNz34OB4MG4EegS2xAOSfB1X5m wks= X-SBRS: 5.1 X-MesageID: 43403575 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:LIgl8K140I0oRdy59ZU15AqjBYByeYIsimQD101hICG9Lfb0qy n+pp4mPEHP4wr5AEtQ4exoS5PwOk80lKQFqrX5WI3PYOCIghrNEGgP1+rfKnjbalTDH41mpO 1dmspFebrN5DFB5K6UjjVQUexQpuVvm5rY5ts2uk0dKD2CHJsQjTuRZDz6LmRGAC19QbYpHp uV4cRK4xC6f24MU8i9Dn4ZG8DeutzijvvdEFI7Li9izDPLoSKj6bb8HRTd9AwZSSlzzbAr9n WAuxDl55+kr+qwxnbnpiDuBtVt6ZXcI+l4dYyxY/suW3bRY8GTFcZcsoi5zXEISSeUmRMXeZ f30lMd1o9ImgnslymO0GbQMk/boXsTAjbZuCOlqGqmrsrjSD0gDc1dwYpfbxvC8kIl+Mpxya RRwguixuxq5D777VDADuLzJmZXf4uP0AkfeOUo/jViuEslGcpsRKkkjQto+bs7bVPHAbEcYZ tT5ZvnlYhrmHuhHgDkV0dUsaORYkg= X-IronPort-AV: E=Sophos;i="5.82,280,1613451600"; d="scan'208";a="43403575" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PxRfu4w3h0ZZrzPVF6oKFTfyGZW4ANJAE8TIFNS9LkOGMZkfqNyba8H5av/kn/aMFqEs/P1KoY36cNlTB0nocuJrGFPx+9CTw1G9PCHsTMdrgUgszSvHZ2LAZN/d2ordhKpzPqjptPXUBmb4G6kvRTAQV5N77UNf75pi7ktXNXt1sfPri7CcR7rYMda9OzyJYlv7NQnn3SRMIzJNUySicwFiRxEW2m68yXPEr2SHmqRqXPNamFrStqiSbP12zyI6INziFN4kYTYShrHB8ZhavVRS+UygGy34nrPYfU3/e+dz0Il5dTPZxdPG+5VQgdtosItySFM4IUa5CTHit6CjVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kNLcteEg52/2FZe+Swj7NwnygUOC6JFeRCiZi3dQW6s=; b=Ua2vYJCR5wOMfeovySQRhKmGZWIbHhNl4k/gfLkavL+T4Yem6FIfP5lqWYuDVX+NX4q1ZSBGFe9BB5vHhogjpwDTmwkWz+OioVatbpZpQIHmrSRO0SfLqRaPespec+O/j7Rbheh4S+Pk8AAMsabk+EalThAKii+U8G8j7EleCU5u+bMJsi9iY2Z91ZjH6gdnkjEPY9lXqoowoWNoARzkqgw4gJC5mPtO/RAeRdFVZVTAWwzlM7L+keZliEvRFfzGvXGoou43V44Z8ru6wU90C2nhAfqob6aUvy7bvKp05Rv6+eEbUuzizhBWcafEW7Aw68eYer5xpjksZP9aLdgZLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kNLcteEg52/2FZe+Swj7NwnygUOC6JFeRCiZi3dQW6s=; b=iqVgg4aDLQd2k51ckx9ReRwlnQvui8oBph0vVoAMW2cgz12gpA5yc2xOwsjwaGwratVgJY4/aBk+fJSaljXlOLbIbKqjEQGIBW118zoqSvtOhm41vIMR83qUAAeqltJkwRs/jaBydb0m+TKd4N7bkNr3twGgxv3PIwcJzmJi9B8= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH v4 06/10] libs/guest: introduce helper set cpu topology in cpu policy Date: Fri, 7 May 2021 13:04:18 +0200 Message-ID: <20210507110422.24608-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507110422.24608-1-roger.pau@citrix.com> References: <20210507110422.24608-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR2P264CA0078.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:32::18) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e316ac50-33bc-4c4c-1eb9-08d911484850 X-MS-TrafficTypeDiagnostic: DM6PR03MB4475: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1169; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h5/6rjML9zy/FQ6tNvLhI6DttyGBiloW5xNAAh3EKyT14vOTFjfBZp3G4IvtiO7saAsS1nvQScUhy8HVqPH9R87+evndX1cT2sLIo9nUbVd7ba6EckzeoXV3olRQftS7zfCitKFQThh/STwyrFOL7Nc2tdqoK1jeRcgEWFM5omlTYnui4PkvwL7pN+GXX1z3QqmztsQJnsdTwRo6LiXNMgvLHqzqnf6/aec2pzjArRVdDWFpx6M87g/TriDvQ00bG8AUikcEuj1qU+DRtBCp6AuceKehHlId7n/dORN9WmTe4ui7p9hQmAwcUbl4avURJIfMcpkceuRBtDb4rlCOtAMDU7t5gxcE/lv49YU5D895pDu7KHCBh0Ln4UWzNDdkbyRMNwkL4avxusAn5aPqp6uaBy/aR65Uc7v9ZWP+Gb1YykV0geDqsFSEA2Og3TYyFNK7CKIBTmPOOD8gnxqdrvTxEaolhKXILStB1WlG3lg+5ID4yAvO2P8RPJy4gl5i+SRIaud5FVGlC82IjVOuOpiQog0nPfgOcjBMG9SNi1esVZLPOPTuxH0r9c6k4CbT1o40SlKxdsvjXyWxnQpyUqLOeuTamdO6gp42Kjs80bs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(376002)(346002)(39860400002)(366004)(8676002)(6496006)(26005)(66946007)(5660300002)(66556008)(66476007)(83380400001)(478600001)(956004)(1076003)(6916009)(316002)(38100700002)(54906003)(6486002)(2616005)(86362001)(8936002)(36756003)(4326008)(186003)(16526019)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?MmlRL1VZVUdmeHlsU0NzSk9FS1YrM2FXM3lldjg1ZDQ2R24yYlJPbUFOMlZX?= =?utf-8?B?UFpUbWY0NVRQRTVWR0tXSUJvSkhISzB1dG53R2doZFdTZVZyNndVNzdndzha?= =?utf-8?B?UVZRcVZmWUMyczJXOVNQU1lqdG1qRU1raVpWTFJObjFRRm9GU0VuZ25VS1lI?= =?utf-8?B?QU1nYk9MNktFVy9Xdm1laFVic3U0ekYrMVpXRHJWOWRxcTBwR2xUdmsvWG5F?= =?utf-8?B?WHRBcGlsOUNST1pINHcxOXJuOXA2QTVNWW51TURiRVVhbWJBMzJnSkpRUkdV?= =?utf-8?B?eDlYMzM0a3ZqNStZbW52VlZPVFFLcXNqc3dlcjJJYjNiQTJxWkNTNmU2dm5n?= =?utf-8?B?NE10Ky9EclFUMHRSQ2t4cUJmay83NUxKTkJtK2syT2d0UlA1Yjl5MFhkQ0ZF?= =?utf-8?B?cXZKZEt5RmY1WGNXdEpXV2JFanNIY1RVMWFMRHJsWVFVTENzY2xMdVRURlNT?= =?utf-8?B?OTBhZUpDbkdheUo3QlhBY1hoMkcwZUdNOXZEWkNJbUk0c2ovNXlDUk5meU4x?= =?utf-8?B?L1d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OSEh6ZDBCVGNQSkNs?= =?utf-8?B?OWpqVUtNR0RVbWJrZkp6WjJMOG9UTXFzbGJ2NlNQblZERDlrdG5LVUZpZTFr?= =?utf-8?B?U0FSeTRhVmdZYzRzYlJRRElUVHN3MHEyUTBLUy9OLzcwdTRuN3JtOE5CZTFv?= =?utf-8?B?aVFZTFdFWU9TRTR1Y1ZGNHhEMXdlUW5TUEIyVGVPYzdPRFpTWHpNWmd3Q0lP?= =?utf-8?B?dHluVzR1ZDA4Vnc1UGVXSC82dlZjbEx1MUgrUGZlSUNqV2FPKzl2VWtONEJL?= =?utf-8?B?dng0TUtmNGJhaTRtbzJJcy9PNVY5ZDV1ZFdUVElkOFN2L3AwMlJYbmdwVHYx?= =?utf-8?Q?WulZ533t3M4I8CEPqOAw2Benli9wTfGZMxdmQy5?= X-MS-Exchange-CrossTenant-Network-Message-Id: e316ac50-33bc-4c4c-1eb9-08d911484850 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 11:07:19.9428 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gdGm4fyEJdqKZwxigS956n9Srmfl9QH5ZbtGqZl1Wa+yf7paMNgzavY1+Genjv1hkmPU0EDQouKM2lsATSoDmQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4475 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) This logic is pulled out from xc_cpuid_apply_policy and placed into a separate helper. Note the legacy part of the introduced function, as long term Xen will require a proper topology setter function capable of expressing a more diverse set of topologies. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 --- - s/xc_cpu_policy_topology/xc_cpu_policy_legacy_topology/ --- tools/include/xenguest.h | 4 + tools/libs/guest/xg_cpuid_x86.c | 182 +++++++++++++++++--------------- 2 files changed, 103 insertions(+), 83 deletions(-) diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h index 576e976d069..6fe01ae292b 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -758,6 +758,10 @@ bool xc_cpu_policy_is_compatible(xc_interface *xch, xc= _cpu_policy_t *host, int xc_cpu_policy_make_compat_4_12(xc_interface *xch, xc_cpu_policy_t *pol= icy, bool hvm); =20 +/* Setup the legacy policy topology. */ +int xc_cpu_policy_legacy_topology(xc_interface *xch, xc_cpu_policy_t *poli= cy, + bool hvm); + int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps); int xc_get_cpu_featureset(xc_interface *xch, uint32_t index, uint32_t *nr_features, uint32_t *featureset); diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x8= 6.c index fccbc54a400..2c89c59cccb 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -438,13 +438,11 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t= domid, bool restore, { int rc; xc_dominfo_t di; - unsigned int i, nr_leaves, nr_msrs; + unsigned int nr_leaves, nr_msrs; xen_cpuid_leaf_t *leaves =3D NULL; struct cpuid_policy *p =3D NULL; struct xc_cpu_policy policy =3D { }; uint32_t err_leaf =3D -1, err_subleaf =3D -1, err_msr =3D -1; - uint32_t host_featureset[FEATURESET_NR_ENTRIES] =3D {}; - uint32_t len =3D ARRAY_SIZE(host_featureset); =20 if ( xc_domain_getinfo(xch, domid, 1, &di) !=3D 1 || di.domid !=3D domid ) @@ -467,22 +465,6 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t = domid, bool restore, (p =3D calloc(1, sizeof(*p))) =3D=3D NULL ) goto out; =20 - /* Get the host policy. */ - rc =3D xc_get_cpu_featureset(xch, XEN_SYSCTL_cpu_featureset_host, - &len, host_featureset); - if ( rc ) - { - /* Tolerate "buffer too small", as we've got the bits we need. */ - if ( errno =3D=3D ENOBUFS ) - rc =3D 0; - else - { - PERROR("Failed to obtain host featureset"); - rc =3D -errno; - goto out; - } - } - /* Get the domain's default policy. */ nr_msrs =3D 0; rc =3D get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_d= efault @@ -566,70 +548,11 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t= domid, bool restore, } } =20 - if ( !di.hvm ) - { - /* - * On hardware without CPUID Faulting, PV guests see real topology. - * As a consequence, they also need to see the host htt/cmp fields. - */ - p->basic.htt =3D test_bit(X86_FEATURE_HTT, host_featureset); - p->extd.cmp_legacy =3D test_bit(X86_FEATURE_CMP_LEGACY, host_featu= reset); - } - else - { - /* - * Topology for HVM guests is entirely controlled by Xen. For now= , we - * hardcode APIC_ID =3D vcpu_id * 2 to give the illusion of no SMT. - */ - p->basic.htt =3D true; - p->extd.cmp_legacy =3D false; - - /* - * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package. - * Update to reflect vLAPIC_ID =3D vCPU_ID * 2, but make sure to a= void - * overflow. - */ - if ( !(p->basic.lppp & 0x80) ) - p->basic.lppp *=3D 2; - - switch ( p->x86_vendor ) - { - case X86_VENDOR_INTEL: - for ( i =3D 0; (p->cache.subleaf[i].type && - i < ARRAY_SIZE(p->cache.raw)); ++i ) - { - p->cache.subleaf[i].cores_per_package =3D - (p->cache.subleaf[i].cores_per_package << 1) | 1; - p->cache.subleaf[i].threads_per_cache =3D 0; - } - break; - - case X86_VENDOR_AMD: - case X86_VENDOR_HYGON: - /* - * Leaf 0x80000008 ECX[15:12] is ApicIdCoreSize. - * Leaf 0x80000008 ECX[7:0] is NumberOfCores (minus one). - * Update to reflect vLAPIC_ID =3D vCPU_ID * 2. But avoid - * - overflow, - * - going out of sync with leaf 1 EBX[23:16], - * - incrementing ApicIdCoreSize when it's zero (which changes= the - * meaning of bits 7:0). - * - * UPDATE: I addition to avoiding overflow, some - * proprietary operating systems have trouble with - * apic_id_size values greater than 7. Limit the value to - * 7 for now. - */ - if ( p->extd.nc < 0x7f ) - { - if ( p->extd.apic_id_size !=3D 0 && p->extd.apic_id_size <= 0x7 ) - p->extd.apic_id_size++; - - p->extd.nc =3D (p->extd.nc << 1) | 1; - } - break; - } - } + policy.cpuid =3D *p; + rc =3D xc_cpu_policy_legacy_topology(xch, &policy, di.hvm); + if ( rc ) + goto out; + *p =3D policy.cpuid; =20 rc =3D x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves); if ( rc ) @@ -949,3 +872,96 @@ int xc_cpu_policy_make_compat_4_12(xc_interface *xch, = xc_cpu_policy_t *policy, xc_cpu_policy_destroy(host); return rc; } + +int xc_cpu_policy_legacy_topology(xc_interface *xch, xc_cpu_policy_t *poli= cy, + bool hvm) +{ + if ( !hvm ) + { + xc_cpu_policy_t *host; + int rc; + + host =3D xc_cpu_policy_init(); + if ( !host ) + { + errno =3D ENOMEM; + return -1; + } + + rc =3D xc_cpu_policy_get_system(xch, XEN_SYSCTL_cpu_policy_host, h= ost); + if ( rc ) + { + ERROR("Failed to get host policy"); + xc_cpu_policy_destroy(host); + return rc; + } + + + /* + * On hardware without CPUID Faulting, PV guests see real topology. + * As a consequence, they also need to see the host htt/cmp fields. + */ + policy->cpuid.basic.htt =3D host->cpuid.basic.htt; + policy->cpuid.extd.cmp_legacy =3D host->cpuid.extd.cmp_legacy; + } + else + { + unsigned int i; + + /* + * Topology for HVM guests is entirely controlled by Xen. For now= , we + * hardcode APIC_ID =3D vcpu_id * 2 to give the illusion of no SMT. + */ + policy->cpuid.basic.htt =3D true; + policy->cpuid.extd.cmp_legacy =3D false; + + /* + * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package. + * Update to reflect vLAPIC_ID =3D vCPU_ID * 2, but make sure to a= void + * overflow. + */ + if ( !(policy->cpuid.basic.lppp & 0x80) ) + policy->cpuid.basic.lppp *=3D 2; + + switch ( policy->cpuid.x86_vendor ) + { + case X86_VENDOR_INTEL: + for ( i =3D 0; (policy->cpuid.cache.subleaf[i].type && + i < ARRAY_SIZE(policy->cpuid.cache.raw)); ++i ) + { + policy->cpuid.cache.subleaf[i].cores_per_package =3D + (policy->cpuid.cache.subleaf[i].cores_per_package << 1) = | 1; + policy->cpuid.cache.subleaf[i].threads_per_cache =3D 0; + } + break; + + case X86_VENDOR_AMD: + case X86_VENDOR_HYGON: + /* + * Leaf 0x80000008 ECX[15:12] is ApicIdCoreSize. + * Leaf 0x80000008 ECX[7:0] is NumberOfCores (minus one). + * Update to reflect vLAPIC_ID =3D vCPU_ID * 2. But avoid + * - overflow, + * - going out of sync with leaf 1 EBX[23:16], + * - incrementing ApicIdCoreSize when it's zero (which changes= the + * meaning of bits 7:0). + * + * UPDATE: I addition to avoiding overflow, some + * proprietary operating systems have trouble with + * apic_id_size values greater than 7. Limit the value to + * 7 for now. + */ + if ( policy->cpuid.extd.nc < 0x7f ) + { + if ( policy->cpuid.extd.apic_id_size !=3D 0 && + policy->cpuid.extd.apic_id_size < 0x7 ) + policy->cpuid.extd.apic_id_size++; + + policy->cpuid.extd.nc =3D (policy->cpuid.extd.nc << 1) | 1; + } + break; + } + } + + return 0; +} --=20 2.31.1 From nobody Fri Nov 29 22:49:57 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1620385674; cv=pass; d=zohomail.com; s=zohoarc; b=Mh9x6Q7qyt5lmhzIuToVSLy39g3iBCuGfX8kRau/9v0CAqZrObZzlNGfr1hAteBnBH/xbS9te4axbaigXIeujqbiTYFwCMGXAoYRNMfGv2nO1LpUkVwyUsKFNKvLzrDA8NSTL0IE7xuwMS3KG13Wl84qczPcgo0u3jzh8mOnE9s= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620385674; 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=7afhcgom3dSGOWUu5uK4ZZv4DipC5W8MhkjaH97+CUQ=; b=Czv8GRyRu5LuWSGmh49ESKAOr1rTi2Kq3CtIqcyqb6lc5JsTWSWYGgUy7oO40UMbYBwreZ+wiP6VNHiCKykpJ03DsFeJuKVLpCIoLftp/jv6xJ/chUX0UhP4S5vHQYjn+6UM36y66BnkVtL3CzJKxSKAT3ulTgoYEVPr8SjFLTE= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162038567473758.06880057013268; Fri, 7 May 2021 04:07:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.123978.234010 (Exim 4.92) (envelope-from ) id 1leyKa-0006nP-G4; Fri, 07 May 2021 11:07:40 +0000 Received: by outflank-mailman (output) from mailman id 123978.234010; Fri, 07 May 2021 11:07:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leyKa-0006nB-Cn; Fri, 07 May 2021 11:07:40 +0000 Received: by outflank-mailman (input) for mailman id 123978; Fri, 07 May 2021 11:07:38 +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.92) (envelope-from ) id 1leyKY-0004jI-Hc for xen-devel@lists.xenproject.org; Fri, 07 May 2021 11:07:38 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 39bce5a7-9878-4bd5-ae1e-c25afcadf535; Fri, 07 May 2021 11:07:29 +0000 (UTC) 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: 39bce5a7-9878-4bd5-ae1e-c25afcadf535 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620385649; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=oDJ6glkCLlfUuzvIT1EjKxHZukaOvVKn/CkwxDpr4as=; b=GjW/cvxBlKVgFyv7Nx/XCLhT9xlEGXxZJiLKRG3RIVwN+64fwF0YVlSJ MY7pgyW8OKCzc8L2m0Uvir5s8d8tmu3QPjg2NlaFWP01htTkQsrdszI/S VIl5/IOk+aOxb9gYWi1P+XzqHzb1HdJNmrKbiuQCa8ckDXpR9j2wNZfsG Y=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: XcOi2GSrpuv1xWnr7iV2sYsOi4hpzu/Ka0As0x4vD5yeD0G/Uct25IaWISTy0S3ooDi8pdsIAL QUWXj2hZ0Pz1nBhj93yQsm/OTDtoaUuKkoIYZYsvOunT4C8jsdcdwL37YjMANs6Xw0DWeyGUGN ya62LCM1AGDuP+lOB7CJy1cn6xSYr6Wwy+REivUMf2cSVHU4R35yR2fueK4yExuzE+xZ4MeDD1 DIh3ajNBbyWutKJOKwNmjReGRs6ImYOHwK+MnNiVPS6hvgViYDvRPWbYQs/vQfG9oG8dJs8QOW z1g= X-SBRS: 5.1 X-MesageID: 43096246 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:ee+tS6+ufxdpXJXjkfluk+Hqdb1zdoMgy1knxilNoENuH/Bwxv rFoB1E73TJYW4qKQkdcKO7SdK9qBLnhNVICOwqUYtKMzOW3FdAQLsC0WKm+UyYJ8SczJ8W6U 4DSdkYNDSYNzET4qjHCUuDYrAdKbK8gcOVbJLlvhJQpHZRGsNdBmlCajqzIwlTfk1rFJA5HJ 2T6o5svDy7Y0kaacy9Gz0sQ/XDj8ejruOrXTc2QzocrCWehzKh77D3VzKC2A0Fbj9JybA+tU DYjg3C4Lm5uf3T8G6S64aT1eUZpDLS8KoCOCW+sLlXFtwqsHfrWG1VYczCgNnympDr1L9lqq iJn/5qBbUI15qYRBDJnfKq4Xis7N9m0Q6f9XaIxXTkusD3XzQ8Fo5Igp9YaALQ7w46sMh7y7 8j5RPui3N7N2K1oM3G3am+a/iqrDvGnZMoq59bs5Wea/pqVFZ1l/1WwKp4KuZwIMvK0vFULA A1NrCj2B9/SyLrU5n2hBgR/OCR X-IronPort-AV: E=Sophos;i="5.82,280,1613451600"; d="scan'208";a="43096246" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GdGea/Sn/56bOKfif6mDtTKvRKys3iJaZ8PDCKXxHrKKNaVIAm6FJl96kr1QZKnb1HNQUGO6XSKl+eQ4UtRd0GpT0dsQfDAECLUG86uS4aWftqhXeU6KF+LXBhbvP8RpqWokixy8AcxcfpvbqgcfdVMazrcW6w0L2xjlkKRtjwtg1jIRIjpTVYbWBzHjtBHifmGR59aQdfM2LmBQsLoD7s0ffP4AsLbz4sx2NW6NNNx6eW2EIQe31GlbG0qhFMZ7Ro36MxREZ17yjXYC6UeCior9ac5EaRiQz7znxIkvJfZycLAoEqTGSKkMqdKe3HtEeu51SjRNQimj8/Y3o05+Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7afhcgom3dSGOWUu5uK4ZZv4DipC5W8MhkjaH97+CUQ=; b=FfMfXSi/HE7kJEytKuIm4ndS26djosVP9JJCkSJKnX1gG2d4Z4iXAT8bxVOHK8ePk+hnLaqcoQn6CeSkjnyAxdKSJizy8Nfyg5Qx+s2a5aO++yhucQezOWysqMuFgNaj0YeGrDQ2+2VzpQUYSdr+ufbng19KhwDWL+gZVXJRbPBu4ZXLdU9FBFpqqDxhQ9WVtV0qPWXeR/2Ge5koTYps+vzb3BUX42nMDoU1xajCKMatQWVKt5RKI9pHj7pFudRRl3XBtGddep0gxBPdkSRks0rfw9YK64atSg0oaj0VF8Wh0DtyJZJq32KbrdVAT6orjic+t8rdGJgGbmKT6arzAw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7afhcgom3dSGOWUu5uK4ZZv4DipC5W8MhkjaH97+CUQ=; b=vnGuDC3jLESEN0kBm1T8iGtBylf0/+KXsv+XDYtAWnZd+fQYhvDu5VuzZ5JlE/hsmXUJgPA8TRhDouugbD6jUPeXzMlMSKPQcj6yM6JVlgY8J6E1vPdpEX/iUp8ypXJpKz6ysW44gk/VAVmrM3nkqeSysnC78089T3iAxwAtiEY= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH v4 07/10] libs/guest: rework xc_cpuid_xend_policy Date: Fri, 7 May 2021 13:04:19 +0200 Message-ID: <20210507110422.24608-8-roger.pau@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507110422.24608-1-roger.pau@citrix.com> References: <20210507110422.24608-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR2P264CA0079.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:32::19) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5d4ff7b6-5865-4937-93a7-08d911484ae5 X-MS-TrafficTypeDiagnostic: DM6PR03MB4475: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:65; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Aij6rlKiWijTiTV7DBdQe++PiZyMcSpgPb+tt+GQ+Dhadg4vmNtDPrflPhjW9n/LiYMg4Jke/wF9v842+KZtPOJ7+V51SnuRicSWIygvtL5utHkGrrzeXslwCtL6KLHNCuovWCA6ovMuV7jGRpWu891DzpUwM3mVmC6rGayUxqjOCRobNNOkb8o7jugfVN1JxAWpgTWoGxgKkin2eg7IDHgQDOy85zN3iQjeMwlAI+OtooG8I6gbciWczphfXvR1VPRBMpZLlE8JXPFfN8xeY6FA5Fyiu7LmD8wrSPySVPrYT3eoip7gB9IdEXg5OfKlMl5QKKOSGDmzTtC2b6NG4VS2M27IIycCc3Hp1LgO8SR15wOwRO+kx6awpGYEXHR0kmNovRNTe2oZZ2evEd+xGyDc1R3kB0wsNHYIBc6bKEa+HynkAAIpVuvZel0uEOM9krg5/jykbixe0ESEh2pUJLMDQnry+RcHRf3bXMRml5FRYClqbP26jGMbxPpfLrrwvoUuYjGJ6+qlyldrW5nVBGGyMw6PHAfdxmcP4LUXzvdO2F6LdG+wJ6I6DAvJbBjKIFvgwmed0eE4DsK7gEbMUBQ3g5H4XMmF02/6jfvNnNc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(376002)(346002)(39860400002)(366004)(8676002)(6496006)(26005)(66946007)(5660300002)(66556008)(66476007)(83380400001)(478600001)(956004)(1076003)(6916009)(316002)(38100700002)(54906003)(6486002)(2616005)(86362001)(8936002)(36756003)(6666004)(4326008)(186003)(16526019)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?Q29zVnhUY3MyaVplc3E1empjbW1lNUx3MTZOeDl0QTl1MlgveWdlQUxPR2xI?= =?utf-8?B?bDVWckRGaU4yeS8yakdLQ2VVUGc1RDY0SEV4NFl1bHU5eVhkTElPc1RSTVRH?= =?utf-8?B?N3pUMm5kNzA2cC9MY25iT3ArbnJvMXdkaFFGb1IxMjZWRXBxQjZlUHV3OVJH?= =?utf-8?B?b1hJNzg5WWxLL3B2ZzN4UW0wbFZVYmIzcXM4d0ROSEtzNGJPNHRLeG1sWmpS?= =?utf-8?B?eUFPakNBM0Z5ZUw4WTlxc1FxdlY0SUJmMDF6QXFDbWNWZUZwYkE0cXlDaXVS?= =?utf-8?B?ZXh3UGlOWkVrcDlPbWZ2Z0VVandiUUhSbnp4bFc0YmxlL2hKQ0lCTkVaSnFC?= =?utf-8?B?UUs3SDBlK0gvcFBaOGdTeVJ4YzF1dFRIbys2VktTcnFmaDBiNTd1UnFyZnND?= =?utf-8?B?S00zR25vOURhUFkrWjVkR3JMWnFOc2gwTk1Od1RSdHNrZHVQSW1FUVppa2lw?= =?utf-8?B?bEtJc3M1UDBlZ3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1p3MCtoVGFidks3eHBzdWorSGZtSmRXSG9PZm8zbHlVdlI0dGRUMXQx?= =?utf-8?B?czVDaFlFd0E2Q0czcUgvUEJ0cGg2UXVxbXN2Y0t4WUd6N2h2NXlTVW5oTVBx?= =?utf-8?B?UWI2R3g4N0FQaURxUS9rYjFrbkhzNnNwTlJ5SUNQVmQ4azlUcm15S3ZwTlMw?= =?utf-8?B?c2RxclBrWHNhTFgwbGhacWEza0NFMXpza3Y4YkdrN0hZWVUrY2tBZjhaZkxl?= =?utf-8?B?V2dMWVNFUkRVS1dpUFlhU0pXZlNwS3FoMkFTS0RHWGt1WlJjclloNXAzZWg2?= =?utf-8?B?ckppNW1mb1ZVNVJqMStxWUgwT3ozOERnUVUzZjVZWWMzT1J5WEVJY2NSdWdw?= =?utf-8?Q?jVQMBeHfqjPrGNT+oBrjQbFXYeMTLMWGiDS/L/F?= X-MS-Exchange-CrossTenant-Network-Message-Id: 5d4ff7b6-5865-4937-93a7-08d911484ae5 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 11:07:24.2817 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: G9aDeQb/0NbiazOuZBiFXOYFwActkUD9NuWiO+6uJbDLdDBQOxZ2rFXtNWXEi9bct/BW+yJ2mH7Mp5lNoCKbfw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4475 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) Rename xc_cpuid_xend_policy to xc_cpu_policy_apply_cpuid and make it public. Modify the function internally to use the new xc_cpu_policy_* set of functions. Also don't apply the passed policy to a domain directly, and instead modify the provided xc_cpu_policy_t. The caller will be responsible of applying the modified cpu policy to the domain. Note that further patches will end up removing this function, as the callers should have the necessary helpers to modify an xc_cpu_policy_t themselves. The find_leaf helper and related comparison function is also removed, as it's no longer needed to search for cpuid leafs as finding the matching leaves is now done using xc_cpu_policy_get_cpuid. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 --- Changes since v3: - Drop find_leaf and comparison helper. --- tools/include/xenguest.h | 4 + tools/libs/guest/xg_cpuid_x86.c | 200 +++++++++++++------------------- 2 files changed, 83 insertions(+), 121 deletions(-) diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h index 6fe01ae292b..3e2fe7f3654 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -762,6 +762,10 @@ int xc_cpu_policy_make_compat_4_12(xc_interface *xch, = xc_cpu_policy_t *policy, int xc_cpu_policy_legacy_topology(xc_interface *xch, xc_cpu_policy_t *poli= cy, bool hvm); =20 +/* Apply an xc_xend_cpuid object to the policy. */ +int xc_cpu_policy_apply_cpuid(xc_interface *xch, xc_cpu_policy_t *policy, + const struct xc_xend_cpuid *cpuid, bool hvm); + int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps); int xc_get_cpu_featureset(xc_interface *xch, uint32_t index, uint32_t *nr_features, uint32_t *featureset); diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x8= 6.c index 2c89c59cccb..65b49753d3e 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -263,144 +263,107 @@ int xc_set_domain_cpu_policy(xc_interface *xch, uin= t32_t domid, return ret; } =20 -static int compare_leaves(const void *l, const void *r) -{ - const xen_cpuid_leaf_t *lhs =3D l; - const xen_cpuid_leaf_t *rhs =3D r; - - if ( lhs->leaf !=3D rhs->leaf ) - return lhs->leaf < rhs->leaf ? -1 : 1; - - if ( lhs->subleaf !=3D rhs->subleaf ) - return lhs->subleaf < rhs->subleaf ? -1 : 1; - - return 0; -} - -static xen_cpuid_leaf_t *find_leaf( - xen_cpuid_leaf_t *leaves, unsigned int nr_leaves, - const struct xc_xend_cpuid *xend) -{ - const xen_cpuid_leaf_t key =3D { xend->leaf, xend->subleaf }; - - return bsearch(&key, leaves, nr_leaves, sizeof(*leaves), compare_leave= s); -} - -static int xc_cpuid_xend_policy( - xc_interface *xch, uint32_t domid, const struct xc_xend_cpuid *xend) +int xc_cpu_policy_apply_cpuid(xc_interface *xch, xc_cpu_policy_t *policy, + const struct xc_xend_cpuid *cpuid, bool hvm) { int rc; - xc_dominfo_t di; - unsigned int nr_leaves, nr_msrs; - uint32_t err_leaf =3D -1, err_subleaf =3D -1, err_msr =3D -1; - /* - * Three full policies. The host, default for the domain type, - * and domain current. - */ - xen_cpuid_leaf_t *host =3D NULL, *def =3D NULL, *cur =3D NULL; - unsigned int nr_host, nr_def, nr_cur; + xc_cpu_policy_t *host =3D NULL, *def =3D NULL; =20 - if ( xc_domain_getinfo(xch, domid, 1, &di) !=3D 1 || - di.domid !=3D domid ) - { - ERROR("Failed to obtain d%d info", domid); - rc =3D -ESRCH; - goto fail; - } - - rc =3D xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); - if ( rc ) - { - PERROR("Failed to obtain policy info size"); - rc =3D -errno; - goto fail; - } - - rc =3D -ENOMEM; - if ( (host =3D calloc(nr_leaves, sizeof(*host))) =3D=3D NULL || - (def =3D calloc(nr_leaves, sizeof(*def))) =3D=3D NULL || - (cur =3D calloc(nr_leaves, sizeof(*cur))) =3D=3D NULL ) - { - ERROR("Unable to allocate memory for %u CPUID leaves", nr_leaves); - goto fail; - } - - /* Get the domain's current policy. */ - nr_msrs =3D 0; - nr_cur =3D nr_leaves; - rc =3D get_domain_cpu_policy(xch, domid, &nr_cur, cur, &nr_msrs, NULL); - if ( rc ) + host =3D xc_cpu_policy_init(); + def =3D xc_cpu_policy_init(); + if ( !host || !def ) { - PERROR("Failed to obtain d%d current policy", domid); - rc =3D -errno; - goto fail; + PERROR("Failed to init policies"); + rc =3D -ENOMEM; + goto out; } =20 /* Get the domain type's default policy. */ - nr_msrs =3D 0; - nr_def =3D nr_leaves; - rc =3D get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_d= efault + rc =3D xc_cpu_policy_get_system(xch, hvm ? XEN_SYSCTL_cpu_policy_hvm_d= efault : XEN_SYSCTL_cpu_policy_pv_defa= ult, - &nr_def, def, &nr_msrs, NULL); + def); if ( rc ) { - PERROR("Failed to obtain %s def policy", di.hvm ? "hvm" : "pv"); - rc =3D -errno; - goto fail; + PERROR("Failed to obtain %s def policy", hvm ? "hvm" : "pv"); + goto out; } =20 /* Get the host policy. */ - nr_msrs =3D 0; - nr_host =3D nr_leaves; - rc =3D get_system_cpu_policy(xch, XEN_SYSCTL_cpu_policy_host, - &nr_host, host, &nr_msrs, NULL); + rc =3D xc_cpu_policy_get_system(xch, XEN_SYSCTL_cpu_policy_host, host); if ( rc ) { PERROR("Failed to obtain host policy"); - rc =3D -errno; - goto fail; + goto out; } =20 rc =3D -EINVAL; - for ( ; xend->leaf !=3D XEN_CPUID_INPUT_UNUSED; ++xend ) + for ( ; cpuid->leaf !=3D XEN_CPUID_INPUT_UNUSED; ++cpuid ) { - xen_cpuid_leaf_t *cur_leaf =3D find_leaf(cur, nr_cur, xend); - const xen_cpuid_leaf_t *def_leaf =3D find_leaf(def, nr_def, xend); - const xen_cpuid_leaf_t *host_leaf =3D find_leaf(host, nr_host, xen= d); + xen_cpuid_leaf_t cur_leaf; + xen_cpuid_leaf_t def_leaf; + xen_cpuid_leaf_t host_leaf; =20 - if ( cur_leaf =3D=3D NULL || def_leaf =3D=3D NULL || host_leaf =3D= =3D NULL ) + rc =3D xc_cpu_policy_get_cpuid(xch, policy, cpuid->leaf, cpuid->su= bleaf, + &cur_leaf); + if ( rc ) + { + ERROR("Failed to get current policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + goto out; + } + rc =3D xc_cpu_policy_get_cpuid(xch, def, cpuid->leaf, cpuid->suble= af, + &def_leaf); + if ( rc ) + { + ERROR("Failed to get def policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + goto out; + } + rc =3D xc_cpu_policy_get_cpuid(xch, host, cpuid->leaf, cpuid->subl= eaf, + &host_leaf); + if ( rc ) { - ERROR("Missing leaf %#x, subleaf %#x", xend->leaf, xend->suble= af); - goto fail; + ERROR("Failed to get host policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + goto out; } =20 - for ( unsigned int i =3D 0; i < ARRAY_SIZE(xend->policy); i++ ) + for ( unsigned int i =3D 0; i < ARRAY_SIZE(cpuid->policy); i++ ) { - uint32_t *cur_reg =3D &cur_leaf->a + i; - const uint32_t *def_reg =3D &def_leaf->a + i; - const uint32_t *host_reg =3D &host_leaf->a + i; + uint32_t *cur_reg =3D &cur_leaf.a + i; + const uint32_t *def_reg =3D &def_leaf.a + i; + const uint32_t *host_reg =3D &host_leaf.a + i; =20 - if ( xend->policy[i] =3D=3D NULL ) + if ( cpuid->policy[i] =3D=3D NULL ) continue; =20 for ( unsigned int j =3D 0; j < 32; j++ ) { bool val; =20 - if ( xend->policy[i][j] =3D=3D '1' ) + switch ( cpuid->policy[i][j] ) + { + case '1': val =3D true; - else if ( xend->policy[i][j] =3D=3D '0' ) + break; + + case '0': val =3D false; - else if ( xend->policy[i][j] =3D=3D 'x' ) + break; + + case 'x': val =3D test_bit(31 - j, def_reg); - else if ( xend->policy[i][j] =3D=3D 'k' || - xend->policy[i][j] =3D=3D 's' ) + break; + + case 'k': + case 's': val =3D test_bit(31 - j, host_reg); - else - { + break; + + default: ERROR("Bad character '%c' in policy[%d] string '%s'", - xend->policy[i][j], i, xend->policy[i]); - goto fail; + cpuid->policy[i][j], i, cpuid->policy[i]); + goto out; } =20 clear_bit(31 - j, cur_reg); @@ -408,25 +371,19 @@ static int xc_cpuid_xend_policy( set_bit(31 - j, cur_reg); } } - } =20 - /* Feed the transformed currrent policy back up to Xen. */ - rc =3D xc_set_domain_cpu_policy(xch, domid, nr_cur, cur, 0, NULL, - &err_leaf, &err_subleaf, &err_msr); - if ( rc ) - { - PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr= %#x)", - domid, err_leaf, err_subleaf, err_msr); - rc =3D -errno; - goto fail; + rc =3D xc_cpu_policy_update_cpuid(xch, policy, &cur_leaf, 1); + if ( rc ) + { + PERROR("Failed to set policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + goto out; + } } =20 - /* Success! */ - - fail: - free(cur); - free(def); - free(host); + out: + xc_cpu_policy_destroy(def); + xc_cpu_policy_destroy(host); =20 return rc; } @@ -434,7 +391,7 @@ static int xc_cpuid_xend_policy( int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, const uint32_t *featureset, unsigned int nr_feat= ures, bool pae, bool itsc, bool nested_virt, - const struct xc_xend_cpuid *xend) + const struct xc_xend_cpuid *cpuid) { int rc; xc_dominfo_t di; @@ -554,6 +511,10 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t = domid, bool restore, goto out; *p =3D policy.cpuid; =20 + rc =3D xc_cpu_policy_apply_cpuid(xch, &policy, cpuid, di.hvm); + if ( rc ) + goto out; + rc =3D x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves); if ( rc ) { @@ -571,9 +532,6 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t d= omid, bool restore, goto out; } =20 - if ( xend && (rc =3D xc_cpuid_xend_policy(xch, domid, xend)) ) - goto out; - rc =3D 0; =20 out: --=20 2.31.1 From nobody Fri Nov 29 22:49:57 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1620385668; cv=pass; d=zohomail.com; s=zohoarc; b=Hkp0cfJ7rN/rDZD+WARijO3NfRnozkLXgv66dZKHpKP/3oXI1zEKNG2bdmaNX5UDKTnLmGOUmsZ2rw7kgHNhHLT/ry5pYM7g3iRtjBvjUKL0n2rDY7wHraGLfwGiqI7yA8JXNkEe1aKPjr0Gh6ZiGoX8HQfzXDFWSXvixIGHxCs= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620385668; 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=CYJG3uGJ8VJ4S+hSZ2uLPR8RulmRHjZIhZJGRk11WH8=; b=Jj9/9NISFAMOOTiTvURS72mynkgysRa1G+bMJQdLOeKO44DiPLS8ShaWtuU1ujpsOs44+mkPVPHvxSX4fcea+I+Jcx7oPcIyRXWPWcHWcCrTNEZ3g3hqfH8Lzdsch0QaJQfltSIFJcSdgM+ds6At3LyZ+STOnGDRxRdpPiP1Puk= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620385668859770.9359940104665; Fri, 7 May 2021 04:07:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.123976.233998 (Exim 4.92) (envelope-from ) id 1leyKV-0006DH-2G; Fri, 07 May 2021 11:07:35 +0000 Received: by outflank-mailman (output) from mailman id 123976.233998; Fri, 07 May 2021 11:07:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leyKU-0006DA-Ur; Fri, 07 May 2021 11:07:34 +0000 Received: by outflank-mailman (input) for mailman id 123976; Fri, 07 May 2021 11:07:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leyKU-0006BB-Ab for xen-devel@lists.xenproject.org; Fri, 07 May 2021 11:07:34 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e8e08e22-de8c-465f-abc5-46fac93e55e4; Fri, 07 May 2021 11:07:32 +0000 (UTC) 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: e8e08e22-de8c-465f-abc5-46fac93e55e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620385652; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=fJ0HrS/eGncbeQacqXx7DubhiLIztaxtWhjNuopSA/A=; b=Ipag6eX9mVNFChhCyI/A1arQf3dAopb/2eze2me/bW0GwVX8jr2s2Jsy IGbHYjzy4nchfqtC/CLF5j4yxf93LkSaG3r1endE0H9h9rKK3deIw4GMw /iSPifjDjxXbvzqZJ2A9VpdC0zuYVXhN7zieEPeEXNel5Wt/Wu5i3hX9O o=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: N6aP19wmrD1YDIrtmwNfPSrWKF5/xg8+zwz37FME2TSW4kPRByOFxUJ5GsbSgiQVNEDBC2+gz3 MC8pY5SZ+dEnWAsQtY+QIOY3dJLITxZBLxhfq7zRjOKyk0IorPqM5cjb8L/y0BAOXWdJX2JjcP PJvDFZ8JjVVSHG7iV3Lqgnhh1v/dC4cxviES7UupkswTqazOqsh3ClDdweW2pFq9/gyVT+ap5a 5Hh3T6ii29EQQ708EtTAUjFrNovIG7DyQBgH8J1mkMsbGkQympZ8zC75ao09RhOhAujTuFf+7m IyI= X-SBRS: 5.1 X-MesageID: 43304436 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:zZ7Tnq88WbA8Az7uU3Ruk+Hqdb1zdoMgy1knxilNoENuH/Bwxv rFoB1E73TJYW4qKQkdcKO7SdK9qBLnhNVICOwqUYtKMzOW3FdAQLsC0WKm+UyYJ8SczJ8W6U 4DSdkYNDSYNzET4qjHCUuDYrAdKbK8gcOVbJLlvhJQpHZRGsNdBmlCajqzIwlTfk1rFJA5HJ 2T6o5svDy7Y0kaacy9Gz0sQ/XDj8ejruOrXTc2QzocrCWehzKh77D3VzKC2A0Fbj9JybA+tU DYjg3C4Lm5uf3T8G6S64aT1eUZpDLS8KoCOCW+sLlXFtwqsHfrWG1VYczCgNnympDr1L9lqq iJn/5qBbUI15qYRBDJnfKq4Xis7N9m0Q6f9XaIxXTkusD3XzQ8Fo5Igp9YaALQ7w46sMh7y7 8j5RPui3N7N2K1oM3G3am+a/iqrDvGnZMoq59bs5Wea/pqVFZ1l/1WwKp4KuZwIMvK0vFULA A1NrCj2B9/SyLrU5n2hBgR/OCR X-IronPort-AV: E=Sophos;i="5.82,280,1613451600"; d="scan'208";a="43304436" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b3rBJT9rk31XDIsaUct6yEdAVlNNl2VOR14Rwl1F6hgTlhXXv8h1kRCQWrfp/nV6iRDUWzC/gE4fl0ZJ62DZxlWpQd2kikXf+fkxpTLoikJub31eMI95o5cu//SndnusaSLA6Q13vJo0CDw+jK7lndisUpGeL9hsk4Qxw7xkEVof7ydm85POm08tgTcWXG046BW09wV62OOLayOACgS+eAjoy9OEnQlxXpsu3MeAPQKoeD2hjv17S71CotC+dshQpF8yooXoj2mE6xZmtj6EoV0L5BVftJCUkZ8bYXzsJWm31a8LgzMTaoyzU7obf6zTvhZDTyG9HhauXeZUyiweRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CYJG3uGJ8VJ4S+hSZ2uLPR8RulmRHjZIhZJGRk11WH8=; b=hQn5JGXs+KtWTxzm72+qH65tBbKiPbv9afUtGFR88nQkkyhq5Ch9DMLEPwldkJSKGg8oUoGa6E4L19jRcPLrUb9Mi7lThns+XkbItzfDVuApi/Ip9Vffae9qLibSP4JNDNhg9Vwxkq7Z5dM4rHRQKc2elR1cb3iJx3LbqS0jrwfWCtSIlPe/AfH7HRnEkVFwBQmb7sm0wXlfcqi3BasUcEAg5dZKhMqV/ENrTSvwnw/6PfQo525Pxt54ZfFxULSjAtlc2ywryyKvJbaMFOAQYmrPTpFrqLlQQ2aa41H0ArPhCPBYhRehUKCOl/jE2vdZdEgvO+dSkmIHESLAqm/cpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CYJG3uGJ8VJ4S+hSZ2uLPR8RulmRHjZIhZJGRk11WH8=; b=IW++bpdtOGiSFNQlytppBQqA9oZXp9OFTIb9zA6lil/GBQ3JsndO8JytyQ1/uz9+Xe/oLwR6BhBSgfqySpieVFwX9LFBRWd7deIqCJxYURcWoiQgEbE0so+P/xZbDwXtn2niMNhO7TU15VZkRzQPnG6REZLGcUa26rRQtWlIprw= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH v4 08/10] libs/guest: apply a featureset into a cpu policy Date: Fri, 7 May 2021 13:04:20 +0200 Message-ID: <20210507110422.24608-9-roger.pau@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507110422.24608-1-roger.pau@citrix.com> References: <20210507110422.24608-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR2P264CA0087.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:32::27) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e294e9f9-9a1e-4c33-8f91-08d911484db8 X-MS-TrafficTypeDiagnostic: DM6PR03MB4475: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Fkw5qYLfxVXp0wPO+PkezqWitov+kCl4L4dbi4j/5XFb44Th5QiYMH+GDQ70xe5hhie/I0/M0YSayt0XKo4KgaxMFPuGa1Qn7iiQLmUDrPRSKr7uc5uTJTleGVa5SVlxIlFJyM0zt+ZmNCFdYf9cBem/s3k4fiRcHmz4dEO6TdK2gD2k7Mc2EvD44xUvArEDc8dlHeEP/T2N8li5tPC1SIJnEMG4ZjlAKN65UJX89QAI1WKUbTSEB2n1sUg3ZprmZ+3mPBOQQA8jRNK/O4bQg8S12OsEf47+rvRf55dCL6GqyU/4dLX4etJhfwHJjuFTx9Zj364+EDeWsoFgDtqSFySsu/xKUVGyvP2FBG6wmSyVG8MhwHO13jM6zcfvn4o7a89N1hcmdqH56l6tlWrg/O/itHx/ilQMOh/1++b+s7EcCkR/npocnEFDKP9PAe3mv4La74oiYa12EFmT5LsrtCX2PvBa70owmeYOC/VDILG2KZjvENuL/mm8LAdQHARVbmLhDdfCzx88BuisBeCKdUlRMuEj06qSg3iFngRs9pG4lAN2hL0tH6Kt0HAD/rZK2PPilNP2NkuirzHjTj3426EKFns109NDksRHikCFoAo= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(376002)(346002)(39860400002)(366004)(8676002)(6496006)(26005)(66946007)(5660300002)(66556008)(66476007)(83380400001)(478600001)(956004)(1076003)(6916009)(316002)(38100700002)(54906003)(6486002)(2616005)(86362001)(8936002)(36756003)(6666004)(4326008)(186003)(16526019)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?ZVJ6dnptVkRGbmFrSXhoR0NGZ1A1eG4yQ1dYM3FDUk9GUjFTRlVZTkdiTk1S?= =?utf-8?B?TzdNN1duVnQ1WUZ6RzhpMGVCZ1AvMXBPR2RUaUVjOUluOFlvcVpEUkoxODRN?= =?utf-8?B?ZmVvQ3l5czF0a3FuSk1YazlpeXI5d0dQU0ZLVkJLQmRkaVRPYTduTW9razUv?= =?utf-8?B?UVdXVU5obSs4NWR4SHNhd0YxUDR1TFhhNkNtUy9tZUg3QTllUW5GclNLN2xt?= =?utf-8?B?U2VLTTY3N0kvQWs3VFdHYXJwWmIxM1dMdWZsR0ZCM25ZR1NObzA5b0VSdmpp?= =?utf-8?B?cGU0YlpvV3F6eHllSGVjOHEwRmlLVDhsTGYxZ0FxSVArVGkweWk5bVE1TW5R?= =?utf-8?B?M2JqT0g4ZVpKUG44VE9ZaTVkZ1N5RU1U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YwWEZyaERNZ3JIWmJ4czFTQmdqOXdZdjBoY2s2UE91MkJCZkxHVjVs?= =?utf-8?B?ZlgxMndKcElGYU93YTRtdnFmZjlWQVAwZDMvb21uendTREZFQ1AzbEV6ZG1h?= =?utf-8?B?ejA3dWdteG4yanZxSStWU1dtQVEyQkVwYmN0aFA5Qm9NaXhiY1ZVaGpCNldH?= =?utf-8?B?OGdQTWhVUUJUZTkzTDBJYWxsTzBqajFYbHdkeGtJTDdkaDVuWGk4MCtDZmJn?= =?utf-8?B?ZXA1dDBUUGV0cFBHcFBrdTc0WFl5THp2RmJOaDQvdlJwUzZkWjg0R1RNRHVN?= =?utf-8?B?MkVZc1hiR0w1YmR0VGM4NDVpRngxRWMyNDFzTzlneE9WOFBQMWR0R2FXSER5?= =?utf-8?B?SC96NlNTOURUTm5IazFOWC9oUkNVK0ZIQ1ZxbWlxYkJHTmdBNjdWNHhZQW01?= =?utf-8?B?d2kyb24zemF4RTlKbW5aNFduZWU5SmQ2cmFKSURDOVpVek4vNFFRRm1vUUxl?= =?utf-8?Q?KJVfGo1xxRGYTUEBlH+31syjacRN7uTOJPoGGZQ?= X-MS-Exchange-CrossTenant-Network-Message-Id: e294e9f9-9a1e-4c33-8f91-08d911484db8 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 11:07:28.9790 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9QBrs7kbBLG9FsmolxDSdOYItsZsowvwYs/oacMf7euY3KrpsFhk/rCx27+8LpH2fVOS6mpQ8rQf/QgtfME3Qw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4475 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) Pull out the code from xc_cpuid_apply_policy that applies a featureset to a cpu policy and place it on it's own standalone function that's part of the public interface. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 --- tools/include/xenguest.h | 5 ++ tools/libs/guest/xg_cpuid_x86.c | 95 ++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 38 deletions(-) diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h index 3e2fe7f3654..134c00f29a0 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -766,6 +766,11 @@ int xc_cpu_policy_legacy_topology(xc_interface *xch, x= c_cpu_policy_t *policy, int xc_cpu_policy_apply_cpuid(xc_interface *xch, xc_cpu_policy_t *policy, const struct xc_xend_cpuid *cpuid, bool hvm); =20 +/* Apply a featureset to the policy. */ +int xc_cpu_policy_apply_featureset(xc_interface *xch, xc_cpu_policy_t *pol= icy, + const uint32_t *featureset, + unsigned int nr_features); + int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps); int xc_get_cpu_featureset(xc_interface *xch, uint32_t index, uint32_t *nr_features, uint32_t *featureset); diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x8= 6.c index 65b49753d3e..778bc2130ea 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -452,46 +452,15 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t= domid, bool restore, =20 if ( featureset ) { - uint32_t disabled_features[FEATURESET_NR_ENTRIES], - feat[FEATURESET_NR_ENTRIES] =3D {}; - static const uint32_t deep_features[] =3D INIT_DEEP_FEATURES; - unsigned int i, b; - - /* - * The user supplied featureset may be shorter or longer than - * FEATURESET_NR_ENTRIES. Shorter is fine, and we will zero-exten= d. - * Longer is fine, so long as it only padded with zeros. - */ - unsigned int user_len =3D min(FEATURESET_NR_ENTRIES + 0u, nr_featu= res); - - /* Check for truncated set bits. */ - rc =3D -EOPNOTSUPP; - for ( i =3D user_len; i < nr_features; ++i ) - if ( featureset[i] !=3D 0 ) - goto out; - - memcpy(feat, featureset, sizeof(*featureset) * user_len); - - /* Disable deep dependencies of disabled features. */ - for ( i =3D 0; i < ARRAY_SIZE(disabled_features); ++i ) - disabled_features[i] =3D ~feat[i] & deep_features[i]; - - for ( b =3D 0; b < sizeof(disabled_features) * CHAR_BIT; ++b ) + policy.cpuid =3D *p; + rc =3D xc_cpu_policy_apply_featureset(xch, &policy, featureset, + nr_features); + if ( rc ) { - const uint32_t *dfs; - - if ( !test_bit(b, disabled_features) || - !(dfs =3D x86_cpuid_lookup_deep_deps(b)) ) - continue; - - for ( i =3D 0; i < ARRAY_SIZE(disabled_features); ++i ) - { - feat[i] &=3D ~dfs[i]; - disabled_features[i] &=3D ~dfs[i]; - } + ERROR("Failed to apply featureset to policy"); + goto out; } - - cpuid_featureset_to_policy(feat, p); + *p =3D policy.cpuid; } else { @@ -923,3 +892,53 @@ int xc_cpu_policy_legacy_topology(xc_interface *xch, x= c_cpu_policy_t *policy, =20 return 0; } + +int xc_cpu_policy_apply_featureset(xc_interface *xch, xc_cpu_policy_t *pol= icy, + const uint32_t *featureset, + unsigned int nr_features) +{ + uint32_t disabled_features[FEATURESET_NR_ENTRIES], + feat[FEATURESET_NR_ENTRIES] =3D {}; + static const uint32_t deep_features[] =3D INIT_DEEP_FEATURES; + unsigned int i, b; + + /* + * The user supplied featureset may be shorter or longer than + * FEATURESET_NR_ENTRIES. Shorter is fine, and we will zero-extend. + * Longer is fine, so long as it only padded with zeros. + */ + unsigned int user_len =3D min(FEATURESET_NR_ENTRIES + 0u, nr_features); + + /* Check for truncated set bits. */ + for ( i =3D user_len; i < nr_features; ++i ) + if ( featureset[i] !=3D 0 ) + { + errno =3D EOPNOTSUPP; + return -1; + } + + memcpy(feat, featureset, sizeof(*featureset) * user_len); + + /* Disable deep dependencies of disabled features. */ + for ( i =3D 0; i < ARRAY_SIZE(disabled_features); ++i ) + disabled_features[i] =3D ~feat[i] & deep_features[i]; + + for ( b =3D 0; b < sizeof(disabled_features) * CHAR_BIT; ++b ) + { + const uint32_t *dfs; + + if ( !test_bit(b, disabled_features) || + !(dfs =3D x86_cpuid_lookup_deep_deps(b)) ) + continue; + + for ( i =3D 0; i < ARRAY_SIZE(disabled_features); ++i ) + { + feat[i] &=3D ~dfs[i]; + disabled_features[i] &=3D ~dfs[i]; + } + } + + cpuid_featureset_to_policy(feat, &policy->cpuid); + + return 0; +} --=20 2.31.1 From nobody Fri Nov 29 22:49:58 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1620385685; cv=pass; d=zohomail.com; s=zohoarc; b=KBwL0aslU8pVOf3HDqrUxktCVa6ETZD5xsXMUgt7GzG6M+So+R+ssLWU54Q/CX6FD3j+Dv5hN76a1l/POZlcIrwr02Rt/MY6T0LBIYuNRflXirApyovXPHclq0vn3vPeg7jqrZMlNgI7NeBSp/AAundq8+Demqb/WOHCOBIAAL0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620385685; 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=X77vzMLRLsKKyts6CxSqYJMt1Y+/JSMerGrc8DZVgSU=; b=m3xwa6ZjH5CZZdJVGFeuFK48Vv5UUHPoKrlNlanhLUGXXY/19KpO/pPat05FYoBNb+pguZY2SywGTExOESy0nabhVOXyLFWwwAG3JGfhInXcgT/Hq408Lp+9IR41N3Zxlkx4ZCEr0yjgtzJZvsNLCqziP3+KBqm3vlTkSeQwAYc= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620385685858363.83190042149863; Fri, 7 May 2021 04:08:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.123985.234022 (Exim 4.92) (envelope-from ) id 1leyKk-0007WI-RG; Fri, 07 May 2021 11:07:50 +0000 Received: by outflank-mailman (output) from mailman id 123985.234022; Fri, 07 May 2021 11:07:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leyKk-0007W0-Mu; Fri, 07 May 2021 11:07:50 +0000 Received: by outflank-mailman (input) for mailman id 123985; Fri, 07 May 2021 11:07:48 +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.92) (envelope-from ) id 1leyKi-0004jI-Hm for xen-devel@lists.xenproject.org; Fri, 07 May 2021 11:07:48 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f10407cf-ab0f-401c-b5ea-c8dc30e6d001; Fri, 07 May 2021 11:07:38 +0000 (UTC) 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: f10407cf-ab0f-401c-b5ea-c8dc30e6d001 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620385658; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=mKFJUuT1DfiU2bFrYOWaYqhY+twLBUQuutnIPTuVTF8=; b=gA896gEShFtF+q+s89g8W2KVIweD4gnwxGXtrxY7Cc337S5Kg0xXMpe2 cXB4sjryum2xdR47t8PPyX7bO9GHMGUsCFTbwx1FeTUYpgJL2h1rdyIUM Zc7oHTFs+14Evr5UaKkxz94d+ER6t3ixN1MiPqqWY/hddBOmpS3bvRnB6 k=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: +TTd36LPnTQFDlpLfZqXMBapv77s17XPSisAPBhf6+6xlWWiuNzaL+ONepsOdr1r+OZNuPDDJu 6Gy3dt6nC0YfB1suNUcszC/M1ivpnjySCnATvZFojt51VtC9tb/DU7PB4JYXCLik6bBHDVliup bZ73tVzXmKo4AiJVzyEHHzr/4ZcZF8b8WbKgEwKDI3JVx/TvotQWWEyxa9GNdp3KRIIOUm1VxV SO44ShcFPXerUHQrzKQRrvNkHRNKKSfnRjARnOn7LH07esNPx29Mh1KTdQbxg+zfPFmgWrmxsc 0lA= X-SBRS: 5.1 X-MesageID: 43678507 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:bCNwlaHiIuwDMPU4pLqF2pHXdLJyesId70hD6qkvc3Fom52j/f xGws5x6fatskdoZJhSo6H6BEDgewKWyXcR2+Us1NiZLW3bUQeTTb2KqLGSugEIeBeOvNK1t5 0QFJSWYeeYZTcVsS+52njfLz9K+qjlzEncv5a6854bd3AJV0gP1WdEIzfeNnczaBhNBJI/Gp bZzNFAvSCcdXMeadn+LmUZXsDYzue72K7OUFojPVoK+QOOhTSn5PrRCB6DxCoTVDtJ3PML7X XFqQrk/a+u2svLhSM0llWjoai+quGRiuerN/b8yfT97Q+cyDpAUb4RGoFqegpF5d1Hpmxa1O Uk6C1QRfibo0mhA11d5yGdljUImQxel0PK2BuWh2Durtf+Qy9/A81dhZhBeh+c8EY4uspguZ g7qV5xmqAneS8oph6NkOQglisa5XZcqkBS2NL7T0YvJLf2TYUh5bD30HklYavoLRiKmrzPSt Mecv00zMwmAW9yQUqpwVVS/A== X-IronPort-AV: E=Sophos;i="5.82,280,1613451600"; d="scan'208";a="43678507" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jbe/vkyg2jmcItUftLykdM1mu/+Ahbj5MvpGPG7FvOeaD3+1S7afgN9+ZdNi4syTrDRMkZQ8S9kxZtZfgMRs8+88AVIoSmM9VfiyfFo689nO6TarcR1BUiMGbCCCR2TncBEazpcufuoUXja3M4vYKfuW17EItNbMcLNzyoO4l13EQa64Lu7SA8qeQTHrTS3MM9K39AKATToq3LGWw1NP7QEBh0TzIZL2RRa/4bPvCnTOP9FPnuJDVvQ0cgp2rMnbcjwwWX5ZH3lH041yNB6D4lnwGRS41aelZJRm44TpECJWfCiAi1jpFdrJOotC+N2pHlOepTbZhsen3LfDNc+a2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=X77vzMLRLsKKyts6CxSqYJMt1Y+/JSMerGrc8DZVgSU=; b=Ju6vcmGOYHKi0GCwmIGAESRdtK+x4jXPkvNdoy1PJY7O8RZUJ27BSqN/RGkwGkTTKwJsq7gYMiL/3Li15rSiw+ycPzNq96tNzliO9MT1FsUjTwUNtGaYJNNzyX8YAWAd6tuOTKcc92MlJwRKqGRZV5SVf8FI9ndHbORXmY6K6E896zLh1GxMDCBT8c6724X55FC2onU2FDM34TTtTHP/T4wj5QMQloWiNoUwfUboVF2n9ODMlGsWOaajPtp1BxzyeoOdCvKK9HlTGli72S19LtfLPjm4ULq3dapnWLYFU94zbg9f4Sp6M6jr+jhzvNe6pXZVgP3z0UHu3hxiBghV2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=X77vzMLRLsKKyts6CxSqYJMt1Y+/JSMerGrc8DZVgSU=; b=faYj9ZGzEXYOk+d93DhUiaUipsZlhii/+/LuuuKo39bbWDLGa69lkEj8KR4rn6WDE8/Ic+QK4JYH7ol8jXr1lQbMWPMFwd35bgOFE7rjsrfiojpooBn77TwZJCpe/PzrJ86j28CsS+hTAnPvpzPWDFRtxV854iD5jCwfkskxJcM= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v4 09/10] libs/{light,guest}: implement xc_cpuid_apply_policy in libxl Date: Fri, 7 May 2021 13:04:21 +0200 Message-ID: <20210507110422.24608-10-roger.pau@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507110422.24608-1-roger.pau@citrix.com> References: <20210507110422.24608-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR2P264CA0035.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500::23) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 86790a1e-306c-4b22-25b6-08d91148511e X-MS-TrafficTypeDiagnostic: DM6PR03MB4683: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:164; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DPR+0u6OaEX0vcfP0V1K/sVKoPitJaP9+sd1YJIE2RDDwTNDp61l39qsviJZ7az3jc0rHVqoeACtEVFZY5PO396iYHmlkDmH8W2O9IUlHG8/NTM7Ss4Yi+FbvENN1jvTA0KLzepIL5PxceNaAk2W4wlyt7JF7tnn65q0tEPJAlcryR4WIngxx0aPboo1qsx4O03QAqyUGHdGjsesth3SxqkdyElY7yxCCwyCopvahb/CwdGFsdS0jAq+OHs+S+draeyCm9CVxiCF0ZFSbzEg84qekI+TphhURkpKTudcG2YwllcVKD1uxoztiZJLsXCoZYx3bFgnvQsao68y2Bbj77Pda9MjUonmHg+4r0ttml3371eBcxFKYe2vLjsRR7E2WmBtNF841bF56rqSREZg0CpNQlisoUbubD9UKRYqIzMhPniUI7saz8pYJEh2LoJ61Rd1ikVUgUNdtnfsdqBTZVCxTryYPlRZWA1AM2Z8V/5I95R8CTaubO/9jworKeUzyP33UH6VRA0hVxgqcrHsIZxByNxvWNt1gAnxq7fmL32D8xmQA0o97D4y4Ywy3Z8QaepMAadYZ95xtUp4mUVjfszpoN25hTD75C8ucKlrP6I= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(136003)(346002)(396003)(39860400002)(8936002)(478600001)(6666004)(956004)(2616005)(2906002)(6496006)(6486002)(26005)(1076003)(8676002)(16526019)(38100700002)(5660300002)(6916009)(316002)(66476007)(66556008)(83380400001)(66946007)(186003)(54906003)(107886003)(4326008)(36756003)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?S3U5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M20/6DGOvuMF7uiszB+?= X-MS-Exchange-CrossTenant-Network-Message-Id: 86790a1e-306c-4b22-25b6-08d91148511e X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 11:07:34.8063 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QtzKYhA3tJ5qutpjS5y3jGVM69KnKLBsdP8cEznMLkoSIdg+mnExlAyZ9MLlnMR8cQ9GX0uOTl/QqRoGzrFgtA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4683 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) With the addition of the xc_cpu_policy_* now libxl can have better control over the cpu policy, this allows removing the xc_cpuid_apply_policy function and instead coding the required bits by libxl in libxl__cpuid_legacy directly. Remove xc_cpuid_apply_policy. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Anthony PERARD --- Changes since v2: - Use 'r' for libxc return values. - Fix comment about making a cpu policy compatible. - Use LOG*D macros. --- tools/include/xenctrl.h | 18 ----- tools/libs/guest/xg_cpuid_x86.c | 122 -------------------------------- tools/libs/light/libxl_cpuid.c | 94 ++++++++++++++++++++++-- 3 files changed, 87 insertions(+), 147 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index e894c5c392d..17fa3734800 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1890,24 +1890,6 @@ struct xc_xend_cpuid { char *policy[4]; }; =20 -/* - * Make adjustments to the CPUID settings for a domain. - * - * This path is used in two cases. First, for fresh boots of the domain, = and - * secondly for migrate-in/restore of pre-4.14 guests (where CPUID data was - * missing from the stream). The @restore parameter distinguishes these - * cases, and the generated policy must be compatible with a 4.13. - * - * Either pass a full new @featureset (and @nr_features), or adjust indivi= dual - * features (@pae, @itsc, @nested_virt). - * - * Then (optionally) apply legacy XEND overrides (@xend) to the result. - */ -int xc_cpuid_apply_policy(xc_interface *xch, - uint32_t domid, bool restore, - const uint32_t *featureset, - unsigned int nr_features, bool pae, bool itsc, - bool nested_virt, const struct xc_xend_cpuid *xe= nd); int xc_mca_op(xc_interface *xch, struct xen_mc *mc); int xc_mca_op_inject_v2(xc_interface *xch, unsigned int flags, xc_cpumap_t cpumap, unsigned int nr_cpus); diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x8= 6.c index 778bc2130ea..8c62c3ac360 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -388,128 +388,6 @@ int xc_cpu_policy_apply_cpuid(xc_interface *xch, xc_c= pu_policy_t *policy, return rc; } =20 -int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, - const uint32_t *featureset, unsigned int nr_feat= ures, - bool pae, bool itsc, bool nested_virt, - const struct xc_xend_cpuid *cpuid) -{ - int rc; - xc_dominfo_t di; - unsigned int nr_leaves, nr_msrs; - xen_cpuid_leaf_t *leaves =3D NULL; - struct cpuid_policy *p =3D NULL; - struct xc_cpu_policy policy =3D { }; - uint32_t err_leaf =3D -1, err_subleaf =3D -1, err_msr =3D -1; - - if ( xc_domain_getinfo(xch, domid, 1, &di) !=3D 1 || - di.domid !=3D domid ) - { - ERROR("Failed to obtain d%d info", domid); - rc =3D -ESRCH; - goto out; - } - - rc =3D xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); - if ( rc ) - { - PERROR("Failed to obtain policy info size"); - rc =3D -errno; - goto out; - } - - rc =3D -ENOMEM; - if ( (leaves =3D calloc(nr_leaves, sizeof(*leaves))) =3D=3D NULL || - (p =3D calloc(1, sizeof(*p))) =3D=3D NULL ) - goto out; - - /* Get the domain's default policy. */ - nr_msrs =3D 0; - rc =3D get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_d= efault - : XEN_SYSCTL_cpu_policy_pv_defa= ult, - &nr_leaves, leaves, &nr_msrs, NULL); - if ( rc ) - { - PERROR("Failed to obtain %s default policy", di.hvm ? "hvm" : "pv"= ); - rc =3D -errno; - goto out; - } - - rc =3D x86_cpuid_copy_from_buffer(p, leaves, nr_leaves, - &err_leaf, &err_subleaf); - if ( rc ) - { - ERROR("Failed to deserialise CPUID (err leaf %#x, subleaf %#x) (%d= =3D %s)", - err_leaf, err_subleaf, -rc, strerror(-rc)); - goto out; - } - - if ( restore ) - { - policy.cpuid =3D *p; - xc_cpu_policy_make_compat_4_12(xch, &policy, di.hvm); - *p =3D policy.cpuid; - } - - if ( featureset ) - { - policy.cpuid =3D *p; - rc =3D xc_cpu_policy_apply_featureset(xch, &policy, featureset, - nr_features); - if ( rc ) - { - ERROR("Failed to apply featureset to policy"); - goto out; - } - *p =3D policy.cpuid; - } - else - { - p->extd.itsc =3D itsc; - - if ( di.hvm ) - { - p->basic.pae =3D pae; - p->basic.vmx =3D nested_virt; - p->extd.svm =3D nested_virt; - } - } - - policy.cpuid =3D *p; - rc =3D xc_cpu_policy_legacy_topology(xch, &policy, di.hvm); - if ( rc ) - goto out; - *p =3D policy.cpuid; - - rc =3D xc_cpu_policy_apply_cpuid(xch, &policy, cpuid, di.hvm); - if ( rc ) - goto out; - - rc =3D x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves); - if ( rc ) - { - ERROR("Failed to serialise CPUID (%d =3D %s)", -rc, strerror(-rc)); - goto out; - } - - rc =3D xc_set_domain_cpu_policy(xch, domid, nr_leaves, leaves, 0, NULL, - &err_leaf, &err_subleaf, &err_msr); - if ( rc ) - { - PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr= %#x)", - domid, err_leaf, err_subleaf, err_msr); - rc =3D -errno; - goto out; - } - - rc =3D 0; - -out: - free(p); - free(leaves); - - return rc; -} - xc_cpu_policy_t *xc_cpu_policy_init(void) { return calloc(1, sizeof(struct xc_cpu_policy)); diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index eb6feaa96d1..6d17e89191f 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -430,9 +430,11 @@ int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid= , bool restore, libxl_domain_build_info *info) { GC_INIT(ctx); + xc_cpu_policy_t *policy =3D NULL; + bool hvm =3D info->type =3D=3D LIBXL_DOMAIN_TYPE_HVM; bool pae =3D true; bool itsc; - int r; + int r, rc =3D 0; =20 /* * Gross hack. Using libxl_defbool_val() here causes libvirt to crash= in @@ -443,6 +445,41 @@ int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid= , bool restore, */ bool nested_virt =3D info->nested_hvm.val > 0; =20 + policy =3D xc_cpu_policy_init(); + if (!policy) { + LOGED(ERROR, domid, "Failed to init CPU policy"); + rc =3D ERROR_FAIL; + goto out; + } + + r =3D xc_cpu_policy_get_domain(ctx->xch, domid, policy); + if (r) { + LOGED(ERROR, domid, "Failed to fetch domain CPU policy"); + rc =3D ERROR_FAIL; + goto out; + } + + if (restore) { + /* + * Make sure the policy is compatible with pre Xen 4.13. Note that + * newer Xen versions will pass policy data on the restore stream,= so + * any adjustments done here will be superseded. + */ + r =3D xc_cpu_policy_make_compat_4_12(ctx->xch, policy, hvm); + if (r) { + LOGED(ERROR, domid, "Failed to setup compatible CPU policy"); + rc =3D ERROR_FAIL; + goto out; + } + } + + r =3D xc_cpu_policy_legacy_topology(ctx->xch, policy, hvm); + if (r) { + LOGED(ERROR, domid, "Failed to setup CPU policy topology"); + rc =3D ERROR_FAIL; + goto out; + } + /* * For PV guests, PAE is Xen-controlled (it is the 'p' that differenti= ates * the xen-3.0-x86_32 and xen-3.0-x86_32p ABIs). It is mandatory as X= en @@ -453,8 +490,15 @@ int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid= , bool restore, * * HVM guests get a top-level choice of whether PAE is available. */ - if (info->type =3D=3D LIBXL_DOMAIN_TYPE_HVM) + if (hvm) pae =3D libxl_defbool_val(info->u.hvm.pae); + rc =3D libxl_cpuid_parse_config(&info->cpuid, GCSPRINTF("pae=3D%d", pa= e)); + if (rc) { + LOGD(ERROR, domid, "Failed to set PAE CPUID flag"); + rc =3D ERROR_FAIL; + goto out; + } + =20 /* * Advertising Invariant TSC to a guest means that the TSC frequency w= on't @@ -470,14 +514,50 @@ int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domi= d, bool restore, */ itsc =3D (libxl_defbool_val(info->disable_migrate) || info->tsc_mode =3D=3D LIBXL_TSC_MODE_ALWAYS_EMULATE); + rc =3D libxl_cpuid_parse_config(&info->cpuid, GCSPRINTF("invtsc=3D%d",= itsc)); + if (rc) { + LOGD(ERROR, domid, "Failed to set Invariant TSC CPUID flag"); + rc =3D ERROR_FAIL; + goto out; + } =20 - r =3D xc_cpuid_apply_policy(ctx->xch, domid, restore, NULL, 0, - pae, itsc, nested_virt, info->cpuid); - if (r) - LOGEVD(ERROR, -r, domid, "Failed to apply CPUID policy"); + /* Set Nested virt CPUID bits for HVM. */ + if (hvm) { + rc =3D libxl_cpuid_parse_config(&info->cpuid, GCSPRINTF("vmx=3D%d", + nested_virt)= ); + if (rc) { + LOGD(ERROR, domid, "Failed to set VMX CPUID flag"); + rc =3D ERROR_FAIL; + goto out; + } + + rc =3D libxl_cpuid_parse_config(&info->cpuid, GCSPRINTF("svm=3D%d", + nested_virt)= ); + if (rc) { + LOGD(ERROR, domid, "Failed to set SVM CPUID flag"); + rc =3D ERROR_FAIL; + goto out; + } + } + + /* Apply the bits from info->cpuid if any. */ + r =3D xc_cpu_policy_apply_cpuid(ctx->xch, policy, info->cpuid, hvm); + if (r) { + LOGEVD(ERROR, domid, -r, "Failed to apply CPUID changes"); + rc =3D ERROR_FAIL; + goto out; + } + + r =3D xc_cpu_policy_set_domain(ctx->xch, domid, policy); + if (r) { + LOGED(ERROR, domid, "Failed to set domain CPUID policy"); + rc =3D ERROR_FAIL; + } =20 + out: + xc_cpu_policy_destroy(policy); GC_FREE; - return r ? ERROR_FAIL : 0; + return rc; } =20 static const char *input_names[2] =3D { "leaf", "subleaf" }; --=20 2.31.1 From nobody Fri Nov 29 22:49:58 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1620385686; cv=pass; d=zohomail.com; s=zohoarc; b=RoBw36wEDroDXU/U4ubLwQBEtAxdVV7b87IHyb2bR23oi/t5J0BDhZUyxpJPLFuWoAiRh0tsYh3UpwYDDPgrjaokOrT/oWEt9FKbxw2yzvimNk8wYGcUmpTVBI7ckf0mn3wLx/ld8qyz76EgTTV1mlc4ejXeOuq1iP522o7L+3U= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620385686; 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=0j8xIBD2PCCfKzL4UmHaXF4HJIPd/gVUnY3X5MNUNFM=; b=Rq6E2Yb9IHEcHjVd8S44OruhdG7QCrj3B4nvcTo5gGBIUVOioKubrEoO73xAjh17EM4JaIQy2busk5R7rHB2PJa5t32WJh8QWN3aNPW4/wOOpaNNHDdIDGGHjwSmQuXIve0P2tRNBJWDP5gYn0SRj4Btg/+gO4xVqjn8CPGZU30= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 162038568680277.75310307123834; Fri, 7 May 2021 04:08:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.123986.234028 (Exim 4.92) (envelope-from ) id 1leyKl-0007bO-AR; Fri, 07 May 2021 11:07:51 +0000 Received: by outflank-mailman (output) from mailman id 123986.234028; Fri, 07 May 2021 11:07:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leyKl-0007ar-2G; Fri, 07 May 2021 11:07:51 +0000 Received: by outflank-mailman (input) for mailman id 123986; Fri, 07 May 2021 11:07:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1leyKj-0006BB-AC for xen-devel@lists.xenproject.org; Fri, 07 May 2021 11:07:49 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e83dcd7a-a08d-402d-ba4d-1137a022d6f3; Fri, 07 May 2021 11:07:44 +0000 (UTC) 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: e83dcd7a-a08d-402d-ba4d-1137a022d6f3 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620385664; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=kRHn8rtOSU6R7rJjGVkU/jbvyzLsjPcrTWylK9efHNg=; b=C30Lv6qVaITbQxVUfM+kpI4WHE2E+mw8Hoz1QpLeqWYzyvDWP4i9Mdbd 1W401rJnu8MOkOzluUi1W9Ro71/cavF0Wn4pAALwxDkNc7Ge4KCC0GFHP A3vz9u+rpE1rJ9UcQXj0Im2rNTOoWBlkLlNQo7c5wlB1kt5s6VoNNMY/d o=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: 6YwB6C8YKZQ4983hdCzyEI5GbzrjOKmyaIGAPD/MX5wEnFxsQQc5uB6+9R6gAmaE86mOPOqxcz LfJH6l7lpq9FS/BdLeo4GBeYM7kZbWfQQXWQkYe3EgUONNyj4B3nfYW7qxPDrbx6q8zKANzaho EFgXaBO1K8HyEAW96cQs7sL3Hkm7w3FXY7dbKOLZQ8cPD9xIypZ1aNP7gGoDUMM83i8S0tEPyj 9z0iCs8DXfpFZmNEn8fcWyisx/wv8QEfVtLtQx1OJEryhptoCvwgxFnbjCaOU3mBXcbFhvu1V7 +Vw= X-SBRS: 5.1 X-MesageID: 43286703 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:LWAzX6P1HSFLssBcT/P155DYdb4zR+YMi2TDiHoddfUFSKalfp 6V98jzjSWE8Ar5K0tQ4uxoWZPwCk80kKQY3WB/B8bHYOCLggqVxcRZnPLfKl7bamfDH4xmpM BdmsFFYbWeY2SSz/yKhjVQeOxQo+VvhZrY4Ns2uE0dLz2CBZsB0y5JTiKgVmFmTghPApQ0UL CG4NBcmjamcXMLKuymG3gsRYH41pH2vaOjRSRDKw8s6QGIgz/twqX9CQKk0hAXVC4K6as+8F LCjxfy6syYwr6GI17npiHuBqZt6ZvcI+h4dY+xYw8uW3fRYzOTFcVcsnu5zXUISa+UmRIXeZ L30m0d1oxImg7slyeO0FbQMkDboUoTwm6nxlmCjXT5p8vlADo8FspanIpcNgDU8kw6obhHod R2Nk+ixu5q5Cn77VPADhnzJmJXf0GP0DMfeC4o/gliuK4lGfdsRKAkjTJo+aY7bVDHAdocYZ dT5ennlYZrmH2hHg/kglU= X-IronPort-AV: E=Sophos;i="5.82,280,1613451600"; d="scan'208";a="43286703" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RYyQw1WYCvzj+RuO9/5EVmK2pFDLlFrFqNG28lAvJOotKMy+a7pDNJAt8Td5tJBMhQexZYcLQOFRukT1uTv3l/m4TsAfm1Dqcor+9tkTcExSdKPz800ZoVyNUZ5EZJVeJU357hduPXGlFvFpxWVCKo1Mv/I8HJ86xII9Jhe180EYwhKroXQRrdcaPvWQiBgfcSrCpm8rwtFxZG7IdtaMgSsIYA8lQAKzj8cxfDQAycATuqLxxw2opr/XRMSby7jXPxUdh1kRQ8VzczRU27MoCHZY6GjdV5AoP4OVp0QSq74CtfjOcd9n62fJrR0axn7/fudO3GqvcIYhZgM8VSdp5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0j8xIBD2PCCfKzL4UmHaXF4HJIPd/gVUnY3X5MNUNFM=; b=gACgwAELYeoTbLFkYOybt3AE+y5ZO9+kYIJfkTXQTcFNjuG3JebQy/iuNFr8g+2NDJ2RJtNGZIvDH/clUO0NSm2/n6r7H9EMs8maXbJxgRBCsKCOpRvdtxBRBio2vqzqTsb0bw7vYcUQaS8h8XwDwDyEfLhOhgXlV9LdU7IZirWSxb0xN2UkB0wmqG3CFAoJ1YWyHcqixEIlHBJsHJa0WJH5BYHAi0UiHzCX6bi7RcrEf4jipyaeAMxvLfsutZL3mwvcXgUwzfJgPXJ/SXjkiVYSozY5RVdWmhU/eUozI6TdkbobZp/T8t+SjoqxtzM6uNuLcEXZjOyFBu9Q08nIlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0j8xIBD2PCCfKzL4UmHaXF4HJIPd/gVUnY3X5MNUNFM=; b=NBSEpIHX1CCE4U5iQkyVcPVKl4eGwOKzEJERupLWq/9Z57Lj0xMpwyHhDWELZGLkFeOs0B30NOg7H4UYX0X/77CwSGE1I9TFOHMxvbSmtXL51SGPhgyJK2IJ376vpvuL9KMeP49hb1DcevkmfB4EtrS4bsjpaMPTGe84GZAn1qg= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v4 10/10] libs/guest: (re)move xc_cpu_policy_apply_cpuid Date: Fri, 7 May 2021 13:04:22 +0200 Message-ID: <20210507110422.24608-11-roger.pau@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210507110422.24608-1-roger.pau@citrix.com> References: <20210507110422.24608-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR2P264CA0180.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501::19) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cef9262e-8699-4ac0-25be-08d9114854c4 X-MS-TrafficTypeDiagnostic: DM6PR03MB4683: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:272; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Uiz4KtnoHjaEGWI03B6cV6r9dFQm5S156UCWfpd/WEErYYzrVq8OmghiiCK5b5F6GCH3m4jNdOlisYbx581ov9WLHy+z55EbmWqg6Atka83tXv87FCVcCqlc1eU9sGRAXvMZcRu3+B24ycY5oLXUJQengvdnx57QEkDxh0okIGSENCkFGilzrP+M7AYeqswNBPTCz+9JNys6qX4Sxm4kXRDdUnmaH9G8GH+LYP/lgZZqrVyscIIlvQVtJgue0d/054mBI26b8ze3c9za1ZeLf44VQDrdOls9sW61n/V76M74ZrcXNextz5fizrr5xF7GHUQukkZFmpduW17Qe2NfR7fWFo2zwQo9me++utOmTm+E2uyBtGyFLXHZwr3WiJAvK1MvrSDdc1hxuN4qjvitxcCd9++C8tUBocv+aZOHLaSUsSnJ4pVfMIiRdtZouP7f+RKnwvFivPDW5w8dY64WbVq4jzCv6PA2KvnGRm/p2x5ftve1a8h4iYJc6cV4SzH4RJo8BNq1oObH2jXURph2EKJgIS0Z30uK7d0dJdMKCqd9P/DmzSvaC+OcZXQx/ihYzSuRWzJ7NLy8a4vzhy0PLQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(136003)(346002)(396003)(39860400002)(8936002)(478600001)(6666004)(956004)(2616005)(2906002)(6496006)(6486002)(26005)(30864003)(1076003)(8676002)(16526019)(38100700002)(5660300002)(6916009)(316002)(66476007)(66556008)(83380400001)(66946007)(186003)(54906003)(107886003)(4326008)(36756003)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?cEFtSEFUckZ0Ly9vT2FmNFl2OTVEbmQvOGdITDJoWWlUMFc3d3hzZTNrVGJi?= =?utf-8?B?S2hE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DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 11:07:40.9712 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3r/zga9Nt+m2kmvOyBpbeT+ZZTfOCrbgy/JbXJvKKXAleDyGjc4+TdqDF21RGj7ocMlWBody3ruYPLRC5FvKLg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4683 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) Move the logic from xc_cpu_policy_apply_cpuid into libxl, now that the xc_cpu_policy_* helpers allow modifying a cpu policy. By moving such parsing into libxl directly we can get rid of xc_xend_cpuid, as libxl will now implement it's own private type for storing CPUID information, which currently matches xc_xend_cpuid. Note the function logic is moved as-is, but requires adapting to the libxl coding style. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Anthony PERARD --- Changes since v2: - Use LOG*D. - Pass a gc to apply_policy. - Use 'r' for libxc return values. --- tools/include/libxl.h | 6 +- tools/include/xenctrl.h | 26 ------ tools/include/xenguest.h | 4 - tools/libs/guest/xg_cpuid_x86.c | 125 -------------------------- tools/libs/light/libxl_cpuid.c | 142 ++++++++++++++++++++++++++++-- tools/libs/light/libxl_internal.h | 26 ++++++ 6 files changed, 165 insertions(+), 164 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index ae7fe27c1f2..150b7ba85ac 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -1375,10 +1375,10 @@ void libxl_bitmap_init(libxl_bitmap *map); void libxl_bitmap_dispose(libxl_bitmap *map); =20 /* - * libxl_cpuid_policy is opaque in the libxl ABI. Users of both libxl and - * libxc may not make assumptions about xc_xend_cpuid. + * libxl_cpuid_policy is opaque in the libxl ABI. Users of libxl may not m= ake + * assumptions about libxl__cpuid_policy. */ -typedef struct xc_xend_cpuid libxl_cpuid_policy; +typedef struct libxl__cpuid_policy libxl_cpuid_policy; typedef libxl_cpuid_policy * libxl_cpuid_policy_list; void libxl_cpuid_dispose(libxl_cpuid_policy_list *cpuid_list); int libxl_cpuid_policy_list_length(const libxl_cpuid_policy_list *l); diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 17fa3734800..30c2a5f5284 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1864,32 +1864,6 @@ int xc_domain_debug_control(xc_interface *xch, =20 #if defined(__i386__) || defined(__x86_64__) =20 -/* - * CPUID policy data, expressed in the legacy XEND format. - * - * Policy is an array of strings, 32 chars long: - * policy[0] =3D eax - * policy[1] =3D ebx - * policy[2] =3D ecx - * policy[3] =3D edx - * - * The format of the string is the following: - * '1' -> force to 1 - * '0' -> force to 0 - * 'x' -> we don't care (use default) - * 'k' -> pass through host value - * 's' -> legacy alias for 'k' - */ -struct xc_xend_cpuid { - union { - struct { - uint32_t leaf, subleaf; - }; - uint32_t input[2]; - }; - char *policy[4]; -}; - int xc_mca_op(xc_interface *xch, struct xen_mc *mc); int xc_mca_op_inject_v2(xc_interface *xch, unsigned int flags, xc_cpumap_t cpumap, unsigned int nr_cpus); diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h index 134c00f29a0..414baa30171 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -762,10 +762,6 @@ int xc_cpu_policy_make_compat_4_12(xc_interface *xch, = xc_cpu_policy_t *policy, int xc_cpu_policy_legacy_topology(xc_interface *xch, xc_cpu_policy_t *poli= cy, bool hvm); =20 -/* Apply an xc_xend_cpuid object to the policy. */ -int xc_cpu_policy_apply_cpuid(xc_interface *xch, xc_cpu_policy_t *policy, - const struct xc_xend_cpuid *cpuid, bool hvm); - /* Apply a featureset to the policy. */ int xc_cpu_policy_apply_featureset(xc_interface *xch, xc_cpu_policy_t *pol= icy, const uint32_t *featureset, diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x8= 6.c index 8c62c3ac360..e0fff98fe77 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -263,131 +263,6 @@ int xc_set_domain_cpu_policy(xc_interface *xch, uint3= 2_t domid, return ret; } =20 -int xc_cpu_policy_apply_cpuid(xc_interface *xch, xc_cpu_policy_t *policy, - const struct xc_xend_cpuid *cpuid, bool hvm) -{ - int rc; - xc_cpu_policy_t *host =3D NULL, *def =3D NULL; - - host =3D xc_cpu_policy_init(); - def =3D xc_cpu_policy_init(); - if ( !host || !def ) - { - PERROR("Failed to init policies"); - rc =3D -ENOMEM; - goto out; - } - - /* Get the domain type's default policy. */ - rc =3D xc_cpu_policy_get_system(xch, hvm ? XEN_SYSCTL_cpu_policy_hvm_d= efault - : XEN_SYSCTL_cpu_policy_pv_defa= ult, - def); - if ( rc ) - { - PERROR("Failed to obtain %s def policy", hvm ? "hvm" : "pv"); - goto out; - } - - /* Get the host policy. */ - rc =3D xc_cpu_policy_get_system(xch, XEN_SYSCTL_cpu_policy_host, host); - if ( rc ) - { - PERROR("Failed to obtain host policy"); - goto out; - } - - rc =3D -EINVAL; - for ( ; cpuid->leaf !=3D XEN_CPUID_INPUT_UNUSED; ++cpuid ) - { - xen_cpuid_leaf_t cur_leaf; - xen_cpuid_leaf_t def_leaf; - xen_cpuid_leaf_t host_leaf; - - rc =3D xc_cpu_policy_get_cpuid(xch, policy, cpuid->leaf, cpuid->su= bleaf, - &cur_leaf); - if ( rc ) - { - ERROR("Failed to get current policy leaf %#x subleaf %#x", - cpuid->leaf, cpuid->subleaf); - goto out; - } - rc =3D xc_cpu_policy_get_cpuid(xch, def, cpuid->leaf, cpuid->suble= af, - &def_leaf); - if ( rc ) - { - ERROR("Failed to get def policy leaf %#x subleaf %#x", - cpuid->leaf, cpuid->subleaf); - goto out; - } - rc =3D xc_cpu_policy_get_cpuid(xch, host, cpuid->leaf, cpuid->subl= eaf, - &host_leaf); - if ( rc ) - { - ERROR("Failed to get host policy leaf %#x subleaf %#x", - cpuid->leaf, cpuid->subleaf); - goto out; - } - - for ( unsigned int i =3D 0; i < ARRAY_SIZE(cpuid->policy); i++ ) - { - uint32_t *cur_reg =3D &cur_leaf.a + i; - const uint32_t *def_reg =3D &def_leaf.a + i; - const uint32_t *host_reg =3D &host_leaf.a + i; - - if ( cpuid->policy[i] =3D=3D NULL ) - continue; - - for ( unsigned int j =3D 0; j < 32; j++ ) - { - bool val; - - switch ( cpuid->policy[i][j] ) - { - case '1': - val =3D true; - break; - - case '0': - val =3D false; - break; - - case 'x': - val =3D test_bit(31 - j, def_reg); - break; - - case 'k': - case 's': - val =3D test_bit(31 - j, host_reg); - break; - - default: - ERROR("Bad character '%c' in policy[%d] string '%s'", - cpuid->policy[i][j], i, cpuid->policy[i]); - goto out; - } - - clear_bit(31 - j, cur_reg); - if ( val ) - set_bit(31 - j, cur_reg); - } - } - - rc =3D xc_cpu_policy_update_cpuid(xch, policy, &cur_leaf, 1); - if ( rc ) - { - PERROR("Failed to set policy leaf %#x subleaf %#x", - cpuid->leaf, cpuid->subleaf); - goto out; - } - } - - out: - xc_cpu_policy_destroy(def); - xc_cpu_policy_destroy(host); - - return rc; -} - xc_cpu_policy_t *xc_cpu_policy_init(void) { return calloc(1, sizeof(struct xc_cpu_policy)); diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index 6d17e89191f..6c11b7a7c1f 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -298,7 +298,7 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *c= puid, const char* str) char *sep, *val, *endptr; int i; const struct cpuid_flags *flag; - struct xc_xend_cpuid *entry; + struct libxl__cpuid_policy *entry; unsigned long num; char flags[33], *resstr; =20 @@ -376,7 +376,7 @@ int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_li= st *cpuid, char *endptr; unsigned long value; uint32_t leaf, subleaf =3D XEN_CPUID_INPUT_UNUSED; - struct xc_xend_cpuid *entry; + struct libxl__cpuid_policy *entry; =20 /* parse the leaf number */ value =3D strtoul(str, &endptr, 0); @@ -426,6 +426,137 @@ int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_= list *cpuid, return 0; } =20 +static int apply_cpuid(libxl__gc *gc, xc_cpu_policy_t *policy, + libxl_cpuid_policy_list cpuid, bool hvm, domid_t do= mid) +{ + int r, rc =3D 0; + xc_cpu_policy_t *host =3D NULL, *def =3D NULL; + + host =3D xc_cpu_policy_init(); + def =3D xc_cpu_policy_init(); + if (!host || !def) { + LOGD(ERROR, domid, "Failed to init policies"); + rc =3D ERROR_FAIL; + goto out; + } + + /* Get the domain type's default policy. */ + r =3D xc_cpu_policy_get_system(CTX->xch, + hvm ? XEN_SYSCTL_cpu_policy_hvm_default + : XEN_SYSCTL_cpu_policy_pv_default, + def); + if (r) { + LOGED(ERROR, domid, "Failed to obtain %s def policy", + hvm ? "hvm" : "pv"); + rc =3D ERROR_FAIL; + goto out; + } + + /* Get the host policy. */ + r =3D xc_cpu_policy_get_system(CTX->xch, XEN_SYSCTL_cpu_policy_host, h= ost); + if (r) { + LOGED(ERROR, domid, "Failed to obtain host policy"); + rc =3D ERROR_FAIL; + goto out; + } + + for (; cpuid->leaf !=3D XEN_CPUID_INPUT_UNUSED; ++cpuid) { + xen_cpuid_leaf_t cur_leaf; + xen_cpuid_leaf_t def_leaf; + xen_cpuid_leaf_t host_leaf; + + r =3D xc_cpu_policy_get_cpuid(CTX->xch, policy, cpuid->leaf, + cpuid->subleaf, &cur_leaf); + if (r) { + LOGED(ERROR, domid, + "Failed to get current policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + r =3D ERROR_FAIL; + goto out; + } + r =3D xc_cpu_policy_get_cpuid(CTX->xch, def, cpuid->leaf, cpuid->s= ubleaf, + &def_leaf); + if (r) { + LOGED(ERROR, domid, + "Failed to get def policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + rc =3D ERROR_FAIL; + goto out; + } + r =3D xc_cpu_policy_get_cpuid(CTX->xch, host, cpuid->leaf, + cpuid->subleaf, &host_leaf); + if (r) { + LOGED(ERROR, domid, + "Failed to get host policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + rc =3D ERROR_FAIL; + goto out; + } + + for (unsigned int i =3D 0; i < ARRAY_SIZE(cpuid->policy); i++) { + uint32_t *cur_reg =3D &cur_leaf.a + i; + const uint32_t *def_reg =3D &def_leaf.a + i; + const uint32_t *host_reg =3D &host_leaf.a + i; + + if (cpuid->policy[i] =3D=3D NULL) + continue; + +#define test_bit(i, r) !!(*(r) & (1u << (i))) +#define set_bit(i, r) (*(r) |=3D (1u << (i))) +#define clear_bit(i, r) (*(r) &=3D ~(1u << (i))) + for (unsigned int j =3D 0; j < 32; j++) { + bool val; + + switch (cpuid->policy[i][j]) { + case '1': + val =3D true; + break; + + case '0': + val =3D false; + break; + + case 'x': + val =3D test_bit(31 - j, def_reg); + break; + + case 'k': + case 's': + val =3D test_bit(31 - j, host_reg); + break; + + default: + LOGD(ERROR, domid, + "Bad character '%c' in policy[%d] string '%s'", + cpuid->policy[i][j], i, cpuid->policy[i]); + rc =3D ERROR_FAIL; + goto out; + } + + clear_bit(31 - j, cur_reg); + if (val) + set_bit(31 - j, cur_reg); + } +#undef clear_bit +#undef set_bit +#undef test_bit + } + + r =3D xc_cpu_policy_update_cpuid(CTX->xch, policy, &cur_leaf, 1); + if (r) { + LOGED(ERROR, domid, "Failed to set policy leaf %#x subleaf %#x= ", + cpuid->leaf, cpuid->subleaf); + rc =3D ERROR_FAIL; + goto out; + } + } + + out: + xc_cpu_policy_destroy(def); + xc_cpu_policy_destroy(host); + return rc; +} + int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, libxl_domain_build_info *info) { @@ -541,10 +672,9 @@ int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid= , bool restore, } =20 /* Apply the bits from info->cpuid if any. */ - r =3D xc_cpu_policy_apply_cpuid(ctx->xch, policy, info->cpuid, hvm); - if (r) { - LOGEVD(ERROR, domid, -r, "Failed to apply CPUID changes"); - rc =3D ERROR_FAIL; + rc =3D apply_cpuid(gc, policy, info->cpuid, hvm, domid); + if (rc) { + LOGD(ERROR, domid, "Failed to apply CPUID changes"); goto out; } =20 diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 44a2f3c8fe3..f271a729fa7 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -2052,6 +2052,32 @@ typedef yajl_gen_status (*libxl__gen_json_callback)(= yajl_gen hand, void *); _hidden char *libxl__object_to_json(libxl_ctx *ctx, const char *type, libxl__gen_json_callback gen, void *p); =20 +/* + * CPUID policy data, expressed in the internal libxl format. + * + * Policy is an array of strings, 32 chars long: + * policy[0] =3D eax + * policy[1] =3D ebx + * policy[2] =3D ecx + * policy[3] =3D edx + * + * The format of the string is the following: + * '1' -> force to 1 + * '0' -> force to 0 + * 'x' -> we don't care (use default) + * 'k' -> pass through host value + * 's' -> legacy alias for 'k' + */ +struct libxl__cpuid_policy { + union { + struct { + uint32_t leaf, subleaf; + }; + uint32_t input[2]; + }; + char *policy[4]; +}; + _hidden int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool retor= e, libxl_domain_build_info *info); =20 --=20 2.31.1