From patchwork Mon Nov 29 15:33:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 12645277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3EDE9C433F5 for ; Mon, 29 Nov 2021 15:36:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.234638.407226 (Exim 4.92) (envelope-from ) id 1mrigy-0005xK-9w; Mon, 29 Nov 2021 15:35:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 234638.407226; Mon, 29 Nov 2021 15:35:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mrigy-0005x8-6L; Mon, 29 Nov 2021 15:35:44 +0000 Received: by outflank-mailman (input) for mailman id 234638; Mon, 29 Nov 2021 15:35:42 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mrigw-0004Rj-BF for xen-devel@lists.xenproject.org; Mon, 29 Nov 2021 15:35:42 +0000 Received: from esa5.hc3370-68.iphmx.com (esa5.hc3370-68.iphmx.com [216.71.155.168]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 018cf07c-512a-11ec-976b-d102b41d0961; Mon, 29 Nov 2021 16:35:41 +0100 (CET) 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: 018cf07c-512a-11ec-976b-d102b41d0961 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1638200142; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=LhjyiDF5LKmTNDh163h1NmBaoZfFCmFl7Wc/SQikn0I=; b=UAM7ph+FJIJSK4oXCjsPHTMMWazyJftZurjhvxReXSQxy3Pc6TSrN7cp 2NMBPMx2S2sxBPpLzDSkPV3eTruhWF9hAAbyT9svRr6a8jZRXCrQ8QloV BxADZN8DhogfeIkKYXab6ukzEbGETNk5MjE1xVy3FI7Cq7gDGe1wlRoav k=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: xHD3hhj+UiJhUNcAMyQWh+LDAKPr0F4m4CZbU+qxvnr9rkTweD99LLn8BgQ9In7wABF/Q6vFky gh5yEG45JDUKV/7omeNXXVW55fxgs2//Bqec4CAGZvvzO/nftgl48mHEuU++fxI0UmYeC3cj+A YUFEbuP3lgqjbH9GDcIqKzTlWc2C/6uLkW8+bl3RZr76Pb/pvo5hIKP9eOhpH1DHBadBMKBmxd OaqnOrj+KU5B/gwHYQmwVIICpFw7xn9arLHjxWS0iEpLOitA3inUhLvmfIaQQKG4jR7XDsi3GZ uZ14+M14+H3en7Anp+hSDotL X-SBRS: 5.1 X-MesageID: 58333467 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:sEYrqaj7KaYYKaZorcB8sEh7X161gxcKZh0ujC45NGQN5FlHY01je htvUGmPOv+LZWH1fdl1Ydi/8kgFv8OBx9ZiHgVuqC9jQSwb9cadCdqndUqhZCn6wu8v7a5EA 2fyTvGacajYm1eF/k/F3oAMKRCQ7InQLlbGILes1htZGEk0F0/NtTo5w7Rg29cy0IDga++wk YiaT/P3aQf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=arcselector9901; d=microsoft.com; cv=none; b=eRKdf7KKkrxDGMwsu5FSTEHYAtfqQdnkVt065obFHAna4G2DD7WoQe6BjMdHo3KRNCko9Lq490YvTSElJwVlp2RnzF3cLgE3pElH7XhEYvmT8dDwkttrLEQxykDyLiTKcdwo3P2TBo+PYXkGFhevVSKY+O19rpfqunxtlG2wrO8oA0i6KotvbFKQ7IBdKtai89X6D0LMDf2JDVBttrcaRs3zCYQ/vDaeeiXtUWmuRIr/KqFWLHxhSAs+ULbrjrCpZ9Ue4BRCzuwfLzz9g/G94KlGaTAelYXEDyVYwJTyE3GflOEDuRUocpzY/EvKdXGaiqrUwzkHuo9SHg36i45MUQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pRaYIUfkMkzZXE8d3moJMkHiUafesA///nNUwZGhtBY=; b=BZxhq1icNMM1CoGq/O/DCn/hcTQR1pjO1jIeglGADsUqvHWg3Omi160fA+6TiucuqhwBRmNYBT8CXFD+XsMhDWS5DX1BpPAwk1JUmDwecxsptfVqS4+UeZoaT7lDFnsd69RG0GL3zZzyRbpD8BMy4/O7+64XzJovUDoAWBD74flrj7mc07H4qatuQX8XnttbhLabxEWrCHt9ulaLyVhjvE2LJX/eCw6ncGmLOiVpUd04wpDfgUtz0edtqzBJw4/LKS5fh53+br+NtBiGoIThbOuJihG9kml7ioQQoMfaCP2WFhvzYJnLAyjm7tbSm0MdV5XeaK3RC1Mm1eH1kYEg/w== 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=pRaYIUfkMkzZXE8d3moJMkHiUafesA///nNUwZGhtBY=; b=Zl3VgODgX/KHkMVJjwOWxmUPcOkM1NySylF7FVh4sQFggYd7HsiHoW02cHKvTTq9Ppgt0z+9XVc7PGL1m/KZpy74qcTJ21oPsdL436C3gP15sQfjmWeMpG6YPhupYCWIMBKbiVy18L74NfdbUIZuhsnZeAki/i7iapbh2MMYC8g= From: Roger Pau Monne To: CC: Roger Pau Monne , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v5 06/12] libs/guest: make a cpu policy compatible with older Xen versions Date: Mon, 29 Nov 2021 16:33:49 +0100 Message-ID: <20211129153355.60338-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211129153355.60338-1-roger.pau@citrix.com> References: <20211129153355.60338-1-roger.pau@citrix.com> 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-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5d34d6d2-74ea-4534-dd15-08d9b34de3f4 X-MS-TrafficTypeDiagnostic: DM5PR03MB2842: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rqLlYHxjwOY6uVrO6MpidNNOA3iK1YoGdzwGYezHdQATvewCg8COK9yHDRcEH5hbY7UrRc0hIpuG3xJr1qzQ8IKCKxVduGj3yQOZWHOjSc5uswIBuEaxLG+9TKmbKRp2NslTL++p7FrgVgWNT3MdSCCBGGbJfeyOTlexb7JhlhDtfSOW3pJ/OSeF1LP7PLcG4WV0B+I1/knzPFVKeidKZ53aKw6hCmF7D5a+joLEAHwnal1cARragB11ffqYgBYJhuEw5lgXbpk2In40fP0fKG+Qq9wbTZK89CHBvnYIAb7XCs7HFB8JfN6eghf82YAzH7GVGqL98le11/Tz/a5grnOBRoRoMUmjP0Iv4eHt70CJE8K8IIErh7NzmJytmwwUNqzW0+jJKWq7+BomBYL28+TvzAmT63/wAkrZRRMokuDvH6N/31VAxltYEi29xgJJOwJuQodik6VTj0dqN48VDV3sl8W+IMlxoE8W10O7nTP+F1KF9J0UJUm43K3HLSG+p8JGTjFVb+z+kAab9TJBeL9c0fw2TNAudgZQhNwjuH9J0OjOzka3t4Uc7BYieZ0kyCMHlI8FuPk76yXOAn0aNcEGhNjEid1WYRW3YGu9+LdP0zaQ0XUz4DKW3cvU2qI03IKAtmNODhnJzD0hS5EBiQ== 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)(366004)(5660300002)(86362001)(54906003)(8936002)(2906002)(66946007)(6486002)(316002)(8676002)(956004)(6916009)(82960400001)(4326008)(6666004)(66476007)(66556008)(186003)(83380400001)(38100700002)(2616005)(26005)(508600001)(1076003)(36756003)(6496006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?LzywEfOMrurYKDjMI2m5POn8PRQt?= =?utf-8?q?W6shKg5dputqqSo/o+xTgFde6lwsldFhHfJNFqJb2rH99leZCohMePx6sgf2mSf2Z?= =?utf-8?q?80xVxlZ41FZZfZzhrpJC7QTYAHImu04OGQoAIaA/sB3DwXkmX+i86y3GABQCRqmpA?= =?utf-8?q?NDQGvQhIFKdTKEZnYt7lDjNYdaPC9ynkkHJh1JJSPZjbEKFWbzQxDLSJSWPaeYL2f?= =?utf-8?q?mfcBVT+NJ8XUvAM1HfXX0U6Hv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VBjtwj3Lc1uYhxT4kRVoJSXksCP1vR70G?= =?utf-8?q?rIjTYmD5GObg/cq8CezSbOtw+DdDw3scbHnXUlnP9iN6E/XBDsBGKs5OkLEl+ayjX?= =?utf-8?q?QH4yxgYbl499Li/7wTJ9Spg/46WJRR0oJ6f3nkuihwoVszntPoneiaj1OoXpEiLMk?= =?utf-8?q?/7WJsf3C3+/IWdc/P6eLXaWXFrGGWSJF/3Imy+33tbcvIpNQsHlGosqtS3FJNNdGw?= =?utf-8?q?JjG4GMrC0HJhgjhuTGr0kVRNDSHUlXcLcoF/TZ9vm0LSZKh5zP5Hrr/h0lsZNBapG?= =?utf-8?q?GZqQ3l58AT9Zox91IJrzcnvY1GklNh3oW99tdc/sNDBaEBZd59SFkcvg6AyK3uN82?= =?utf-8?q?UxAGZ3M4knqYBD5/6nz/F0phVR/maaHJIEt4pjCzZERQSmegG9/u9ID9uANKA51iN?= =?utf-8?q?9wlyXjv8RKRjHqSX/gHtuVXRysbdOJHjF7QGqXFlmmQ0FunAZxIVxfw=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 5d34d6d2-74ea-4534-dd15-08d9b34de3f4 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2021 15:35:36.8970 (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: xrFhBO2QQDJEnBWb2kj+0W0Y94+fxmzgwMQv3ks6wVhWSfReDrXdb0v9Ybf2vZSTPrYCPOPfZ8wMZvIgHYDxmQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2842 X-OriginatorOrg: 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é --- 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 | 62 ++++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h index 2672fd043c..281454dc60 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -817,6 +817,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); +/* 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 *policy, + 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_x86.c index 859c885c15..bcbf9576c4 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -432,6 +432,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, unsigned int i, nr_leaves, nr_msrs; xen_cpuid_leaf_t *leaves = NULL; struct cpuid_policy *p = NULL; + struct xc_cpu_policy policy = { }; uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1; uint32_t host_featureset[FEATURESET_NR_ENTRIES] = {}; uint32_t len = ARRAY_SIZE(host_featureset); @@ -496,23 +497,9 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, if ( restore ) { - /* - * Account for feature which have been disabled by default since Xen 4.13, - * so migrated-in VM's don't risk seeing features disappearing. - */ - p->basic.rdrand = test_bit(X86_FEATURE_RDRAND, host_featureset); - p->feat.hle = test_bit(X86_FEATURE_HLE, host_featureset); - p->feat.rtm = test_bit(X86_FEATURE_RTM, host_featureset); - - if ( di.hvm ) - { - p->feat.mpx = test_bit(X86_FEATURE_MPX, host_featureset); - } - - /* Clamp maximum leaves to the ones supported on 4.12. */ - p->basic.max_leaf = min(p->basic.max_leaf, 0xdu); - p->feat.max_subleaf = 0; - p->extd.max_leaf = min(p->extd.max_leaf, 0x8000001c); + policy.cpuid = *p; + xc_cpu_policy_make_compat_4_12(xch, &policy, di.hvm); + *p = policy.cpuid; } if ( featureset ) @@ -916,3 +903,44 @@ bool xc_cpu_policy_is_compatible(xc_interface *xch, xc_cpu_policy_t *host, return false; } + +int xc_cpu_policy_make_compat_4_12(xc_interface *xch, xc_cpu_policy_t *policy, + bool hvm) +{ + xc_cpu_policy_t *host; + int rc; + + host = xc_cpu_policy_init(); + if ( !host ) + { + errno = ENOMEM; + return -1; + } + + rc = 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 = host->cpuid.basic.rdrand; + policy->cpuid.feat.hle = host->cpuid.feat.hle; + policy->cpuid.feat.rtm = host->cpuid.feat.rtm; + + if ( hvm ) + policy->cpuid.feat.mpx = host->cpuid.feat.mpx; + + /* Clamp maximum leaves to the ones supported on pre-4.13. */ + policy->cpuid.basic.max_leaf = min(policy->cpuid.basic.max_leaf, 0xdu); + policy->cpuid.feat.max_subleaf = 0; + policy->cpuid.extd.max_leaf = min(policy->cpuid.extd.max_leaf, 0x8000001c); + + out: + xc_cpu_policy_destroy(host); + return rc; +}