From patchwork Fri Apr 30 15:52:04 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: 12233721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF7C1C433B4 for ; Fri, 30 Apr 2021 15:54:23 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 648D26145D for ; Fri, 30 Apr 2021 15:54:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 648D26145D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.120615.228141 (Exim 4.92) (envelope-from ) id 1lcVT5-0000xc-Ry; Fri, 30 Apr 2021 15:54:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 120615.228141; Fri, 30 Apr 2021 15:54:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lcVT5-0000xS-Oc; Fri, 30 Apr 2021 15:54:15 +0000 Received: by outflank-mailman (input) for mailman id 120615; Fri, 30 Apr 2021 15:54:14 +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 1lcVT4-0000wV-7X for xen-devel@lists.xenproject.org; Fri, 30 Apr 2021 15:54:14 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7fd02742-d0ab-4975-80cf-ed15e4814c4c; Fri, 30 Apr 2021 15:54:13 +0000 (UTC) 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: 7fd02742-d0ab-4975-80cf-ed15e4814c4c DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1619798052; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=dLIQdWJ/rQq9cDoz+VNpuFqWNGmZaFJFYqKXFPnGBS8=; b=cp0G8zCIEYZcxYNrXsZcbu3Q4yqWENgiRsfabbw35MWAhrZX9pnRUW5W vKn3D78UTrlAbUS2lIxzhEejWJEBKvKBTrin9esQsuuSMwVhC5+bkily2 E+rJlLo7meHMZXd80LKELaWvleDmptQX1w8zywke9noSKDEMwRm+N0G0j Q=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: GXDbTmUi5a8h5yVbRaks+E/+qwLElnwWb7+Cnm6AuJvx5JNX8mk3Rqo8KxeBQ5taRBDlAFuP6V TOEb+ha2huWJzOGZNwjZQos1ZLq4U6uT6IoyPfFRkwsLm6ACvousNU5X7B9uznU6MtprQ36h0Z c3lPLnN6zR2vKUxn5UUpDulMU4C24uCk4nxOjOaHW/6MdKXdWwsZCm8TErNJzGUloVWNLbiy9O nRWujPiwxKnV2IhmmoI5MR65uIXJBnHT+35KGmqR54LsKdk8xyu4Ms/5yOYIQxzkCWJ54C+8h+ k2g= X-SBRS: 5.1 X-MesageID: 42810466 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:Gjb25q3sLNzHGcVMVP0NJgqjBFUkLtp033Aq2lEZdDV+dMuEm8 ey2MkB3RjvhzoLHF0mk9aMOK6PKEmslqJdy48XILukQU3aqHKlRbsD0aLOyyDtcheRysdzzq FlGpITNPTVLXxXyfn3+xO5FdFI+rS62YSln/3XwXsobSwCUdAD0y5DBgyWElJ7SWB9bPJTfq a03cZbuyGmPU0ec8XTPAhgY8H4u9bJmJj6CCRmOzcb7mC14g+A2frdCBiX3hAXVhtV2rc8+W 35kwj0j5/T1s2G9g== X-IronPort-AV: E=Sophos;i="5.82,263,1613451600"; d="scan'208";a="42810466" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i4jbpHFmQOSJ0EwigzyZ3kF3kYDDV2PF9e7ekH57NEtBB+AYUnNSBQ3J7ikHshLKtP1KWIIABnet19YeP6/X/XC8ynOd9CzJPA4CAzyjid0eZgc4tQ3PrbCi652Ttr+Uk08K7wng5P3rewtpQBzX2lHVqsOjw5lks9rCxsLZ2jPU6XMjjSI4shId1L7TuFPObrdcX28mmMine/cKnGd0tWDuDbc6P8UsSMnj+Yw49AX8KEbr8nXj9JA2WRxMUBG1KxzgIUN58pI3145RVqgt+IQusAnckmoUPLXo/XE9mgNfFvKEcecYGoML2lXkUHN5vvdBM8kZK8ZjlKEhU07uEg== 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=V3o2QvcoZ6aVqm325GW0WaeCjiv2jnbCGTc6SoBmmbE=; b=ZDOhf/CnobaI/sHY4v/HWSFP7AI+quIGyMIPh89cS+ts9KM9kVv+Xnx/OmpVsYkjPpXAkr799q9TbYLZu0b8+yjwdUjJm5yLc086nfObykT/SIenOJ5ZpAAa0QIyiHNP0zzJMM5m5opwnYAjpTEJhr+PZeEvben5RnClvX/3c+ZEkv+1btekXhVKIxw0IqVu62du16Rjpd3qWIVK1aukkJi3wlq3bSvZ22/kNF0pwYNGsupApnm4X2Ob6wH3/oRhcwsCeR1z1ht2ACwQsKy++qzgGy8UUG+wgrwfAtJqDy4MuCLAd8iOJycP6AaY+plFthvJW0hyzRyoFcT3rqosmg== 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=V3o2QvcoZ6aVqm325GW0WaeCjiv2jnbCGTc6SoBmmbE=; b=snApkINHTQZsUTWq6Oz2mccat3V2G4Rf9Tz+b+NKO6j2doa3uulLY4P0WWty+0yJduQMWEjHj2jRRfF0WLsHSs1rRM0JwPJDc1GpZupVVolUat5pxpMyWNfG9zEoT/VnwpED42tqGgQReX+QgSYd/wcnjtpKCAOobEDP8G6DbHM= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH v3 06/13] libs/guest: introduce helper to check cpu policy compatibility Date: Fri, 30 Apr 2021 17:52:04 +0200 Message-ID: <20210430155211.3709-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210430155211.3709-1-roger.pau@citrix.com> References: <20210430155211.3709-1-roger.pau@citrix.com> X-ClientProxiedBy: MRXP264CA0015.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:15::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: 857750d9-21da-4aaa-d6cd-08d90bf03154 X-MS-TrafficTypeDiagnostic: DM6PR03MB4218: 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: 85htbtuOZalFc37kbvL2rPXTedPrHMsTtSlWO4jWSruLnycgBuQUc1YOuOjlvHknMehxyhwY40xCyKbDecZzwNUBBJmDU6+71d4GpDuNyDXvyYwxAr4OJegb0nIlhCKR/zNtesOsj4NAhJXuDtJvHwS96q57cCnvPsaF9K34r2NrYmM41uJXZZm3wQrMe6kkPqPrdU4IHdc4A1x+KASnd+tPZQWI5znj07/UTJWCp4JPSrIkKnq0S37QETNnkG07Oy50E2uTgsi+WfMRFEnwzEvNmb+WnPVM/D87s1AjZVx+88itz1ThDcLpdn5JfhdW0U3UsBJflxMJWMRxrmxnRkWmjQU1WViKbibuZrWTTVQBAZWX0vtm/q//6yS2W9PQn2K3XZdtRIzpF/rEO6r0Nm49g7kkCg1NPsPqKxKLmRTh9nyWmxs7fhljhsrBIKJvsS9F7rQJhk2aR744s/jb9O8X2n/VOgbm9g/RftBCOv58MIcHZNVxADdZHULqnMVRpjQbKIaAk5t3+9OqoWBczCe/YxmdHJKpDg/R3JEGoRLTLNMDBAG51W4tEBFORaDgC8QZpK2NaMnzM96laQJeI/qYIxrSkAxNcdT+08azFCw= 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)(366004)(136003)(39860400002)(346002)(376002)(478600001)(54906003)(36756003)(316002)(186003)(26005)(66476007)(6666004)(6496006)(4326008)(83380400001)(1076003)(2616005)(66556008)(2906002)(8936002)(66946007)(38100700002)(6916009)(6486002)(956004)(5660300002)(16526019)(8676002)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?a49SHhJBxtantbP8MBsQ0aBTd34UHb?= =?utf-8?q?yMJ50q7npj0lpHyZoLIg+VK0lts6vXcjp8pVMOdlVk9Liw+p7nSxUTqoA3uE+voat?= =?utf-8?q?oU/XlKWTsuOl7HH7DnW67JePZ+96Ar6uSA7Z1JtTTWZr3amFFwsNdinrGd442XDax?= =?utf-8?q?nTKIBR3jr/SD10S5zmFlJE0Myo6rftqkgCHY1eA7IEqJheMu+2fFJoDEGItHGcfCg?= =?utf-8?q?tvDAYUcN+L+4xbaw9NAseeX4UYKV/iGHx4pBrgByxi3wPxTIz6f2T/qbCG1d+TGaQ?= =?utf-8?q?FcT+7KRAitYqpXSTIfz0wt7RgN2fsRps9XaxEwwDHocsviD6mRObiwJnhVouDfEAR?= =?utf-8?q?v76uRHozXz4NVGzDqaElfVa7FIHIKmV0zs6UJKXoffs7WmiB/nEJT1/mEDMhiLHLO?= =?utf-8?q?xHzVN7IpJklJWlvQb4VssJ+FxayML1pP/Liqx3EpM3fFaZiQhtnS13VgxCO3Ax3Rl?= =?utf-8?q?S85EqylLDnSjH1BvLu9rUvPsN1uzP7LDrKmKw0xQ4j+hQcv6AqGFmnN08FOK2ACuk?= =?utf-8?q?G2gvIegt+P7LVDd2qI2144ETKAa+h9fJ/9erwtRostxzU8NbhcBKWUSC6GBX5C1Jp?= =?utf-8?q?xaWkv9ShGg11ci2RoPrpApbrc6B1ikvUYYC9sFc6QygXfggQzNG8/8mCYzUdgMpsa?= =?utf-8?q?IfZgZa1OLbF8aQ8fjJ064QDNa6qybaAlN80e24vBMcc6mXdk88R8dSayBlcTFyLrC?= =?utf-8?q?B0shKyiWE3nrsQQuP09Vqb4GZCMYv6jhA1BZ8JW8XmrKOc3wFc85y6A5ZXslEllo4?= =?utf-8?q?uj1DwljOieqh969CqwOA/Mf1DfyaoXYip7Wh/DcuDQMksyu+uXYkscumFp0ZlNoD6?= =?utf-8?q?+x8kD6s06pZJlm7oqS43lUL5RL7biuMR3azqCNF5MxT+9htLcYwWQ/XpZbtLbLKUD?= =?utf-8?q?Gppuz5cWxdE/chisedGRKMG8MfIwjIG5tT4RpwuFJBqIsy0W+b+2vA7AwByElncxf?= =?utf-8?q?4a1K/XKI7Pf7/h6k6ryUDnIU3ObnXQakwxJbYoMqevJCU84TtFzSoXmTGdqa92Dpo?= =?utf-8?q?PnLQUDTritcsE4KqMOovg+eOiefserEAkP1sRfZh3OB4K//q8snVyQ8n+xv2upUhA?= =?utf-8?q?DbYFV03mr2FcfA2SAMqNH7vC9V6s0vWuoczDmnWDN4+L0rY3EyYWJWF+17V8Q7CO+?= =?utf-8?q?ev0/wvadq5AVpkAm/vJgKTdpQFz6bs0WLXJBM/xwxb/qxO7XW3RUCisr5jbljEwQ2?= =?utf-8?q?YmqSNlixknDcpU0N9JO+5PZTy1NN5ydwE0kx341VoftVUJt2PJQU3GSlDkepJrjTr?= =?utf-8?q?0LytIyZl2Qnid5?= X-MS-Exchange-CrossTenant-Network-Message-Id: 857750d9-21da-4aaa-d6cd-08d90bf03154 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2021 15:54:09.9277 (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: /3IJ6of9v+s+6DZ0YbqhjWmA+ua7V7glEQbpOOcbdcjP3dHnWyk/BJFpDH9+BeB6losb1ke7BAVE9N91Hy09hg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4218 X-OriginatorOrg: citrix.com Such helpers is just a wrapper to the existing x86_cpu_policies_are_compatible function. This requires building policy.c from libx86 on user land also. No user of the interface introduced. Signed-off-by: Roger Pau Monné Acked-by: Andrew Cooper --- Changes since v1: - Initialize err. - Explicitly name parameters as host and guest. --- tools/include/xenctrl.h | 4 ++++ tools/libs/guest/Makefile | 2 +- tools/libs/guest/xg_cpuid_x86.c | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 9a6d1b126d8..5f699c09509 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2619,6 +2619,10 @@ int xc_cpu_policy_update_cpuid(xc_interface *xch, xc_cpu_policy_t policy, int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t policy, const xen_msr_entry_t *msrs, uint32_t nr); +/* Compatibility calculations. */ +bool xc_cpu_policy_is_compatible(xc_interface *xch, const xc_cpu_policy_t host, + const xc_cpu_policy_t guest); + 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/Makefile b/tools/libs/guest/Makefile index 604e1695d6a..6d2a1d5bbc0 100644 --- a/tools/libs/guest/Makefile +++ b/tools/libs/guest/Makefile @@ -40,7 +40,7 @@ $(patsubst %.c,%.opic,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign ifeq ($(CONFIG_X86),y) # Add libx86 to the build vpath %.c ../../../xen/lib/x86 -SRCS-y += cpuid.c msr.c +SRCS-y += cpuid.c msr.c policy.c endif # new domain builder diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c index 37e55279ffe..6b8bae00334 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -930,3 +930,22 @@ int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t policy, return rc; } + +bool xc_cpu_policy_is_compatible(xc_interface *xch, const xc_cpu_policy_t host, + const xc_cpu_policy_t guest) +{ + struct cpu_policy_errors err = INIT_CPU_POLICY_ERRORS; + struct cpu_policy h = { &host->cpuid, &host->msr }; + struct cpu_policy g = { &guest->cpuid, &guest->msr }; + int rc = x86_cpu_policies_are_compatible(&h, &g, &err); + + if ( !rc ) + return true; + + if ( err.leaf != -1 ) + ERROR("Leaf %#x subleaf %#x is not compatible", err.leaf, err.subleaf); + if ( err.msr != -1 ) + ERROR("MSR index %#x is not compatible", err.msr); + + return false; +}