From patchwork Mon Nov 29 15:33:46 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: 12645271 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 44321C433F5 for ; Mon, 29 Nov 2021 15:35:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.234635.407204 (Exim 4.92) (envelope-from ) id 1mrigl-0004rh-IW; Mon, 29 Nov 2021 15:35:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 234635.407204; Mon, 29 Nov 2021 15:35:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mrigl-0004rY-Dw; Mon, 29 Nov 2021 15:35:31 +0000 Received: by outflank-mailman (input) for mailman id 234635; Mon, 29 Nov 2021 15:35:31 +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 1mrigk-0004Rj-PB for xen-devel@lists.xenproject.org; Mon, 29 Nov 2021 15:35:30 +0000 Received: from esa6.hc3370-68.iphmx.com (esa6.hc3370-68.iphmx.com [216.71.155.175]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fa4cd6cf-5129-11ec-976b-d102b41d0961; Mon, 29 Nov 2021 16:35:29 +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: fa4cd6cf-5129-11ec-976b-d102b41d0961 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1638200129; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=yz/7WHXZdG8/P3IiQ6Qs4BL/Xb7Cfc20DDjQceoZCN8=; b=TElRmbUNJkrvbEEPYqFTIdDBLeHlsoRwgIPFXFxmw+zFCS9/W3VLVgXh QVItSOU86ng5Cr+B+BXOxDelLgxolv51CstVyHACCq5dWhS4pYvL3LClz eKdEw0gyeSkkRK479aX7IPh5caJsSR+WZTOCm5330LfMFB/4wk2KoESiH w=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: ekcI5uORet7Jwxrn6rsWpCStPe8tL2WUVcTjKREfIxZYEv1ndBhht+OlhgjUT03imn8oVkwOBL d2Zg9qZAsnrN1W0IESBFvYCKUuBOmE3cXiqwg5ex6a2gf7ltXT61XQboeQztKMrIhGEhOuWV3N aVq8zMQcIWq43T9GW0+9PKL73+kOoUW+Y5JB6ovZzvXEd8l4u95fJgdZjVzmqLayrEJfO45aAK MWYUHI8nmO7EShnV0I4IXs73OvvKRkfMonXntx3cVS5Q3lij2F3YUjm6OB5dScZdyRotnLYbbi ztmj0CZh9aOOgoRV9debsiCn X-SBRS: 5.1 X-MesageID: 58773259 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:ol4skqNMrgz5AiXvrR1GkMFynXyQoLVcMsEvi/4bfWQNrUpx0DYHz DYcXmCHbPeDZ2v3LdB/ao6yp00GsZHQmtIySwto+SlhQUwRpJueD7x1DKtR0wB+jCHnZBg6h ynLQoCYdKjYdpJYz/uUGuCJQUNUjMlkfZKhTr6bUsxNbVU8En540Egyw7dRbrNA2rBVPSvc4 bsenOWHULO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fFR96BcPbZav3nVO8tHQQgsxoWE7MLoUBcUng6tEyeSfwkuU2M4cHLhCanmmW0 AOfABE5o+jRotBqrImV1P7c94rwSrlwBEtXGWXf/I2aDyiC8zrx25JEXcaJYSvZCDH+9pK9a LgH1Pr7KvAGwgpH6tIuD7ZxwKsizNLzvLsGnB98FXDGYln3WLNtJn6KgZtGuqFXn+ILvAK3X gSE+8VAOKXPM8TgSQZDKA0gZ+WF9PcVhjiNsqhlfBSkvHd6rOidTEFfHxiQkygMfrJ6PbQsz folpMNLuRe0jQAnM4regy1Zn4hWwqfsj0nzWkkmPbLW IronPort-HdrOrdr: A9a23:Co9WK6sk4TzpeXhATTyT78PJ7skDG9V00zEX/kB9WHVpm6uj+f xG/c516faaslsssR0b8uxoW5PpfZq0z/dICOIqUYtKMjONhFeV X-IronPort-AV: E=Sophos;i="5.87,273,1631592000"; d="scan'208";a="58773259" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f55NV7oVqNkETdXKYfOD1m4cC8U4yAsYj1IHyEh4bbU/W1Bm85fm6RVM4puLQoLLU4cO3O2h4Kl2ptfz2ZGf1CMotN4WQhI47fpi9qTBmx76UQqv8cQD939iwJb1BZ9ni8dYCJTRuEJS4+lrkEfQt2eZ5ayn0G8pTnWnma1tCZv0nK32ZTVNyjG5SUmQIEHi6ZvcnXNPtKmm6UfLpnFgQ29giMcWrowfONV8v1TDsnrMp+TNImDgZ/Gogl+vc897mqc+P7vGoIk0vsWxajmgucYooCjuROn/xyPIqZSSzjutUC6u6lUMaAhG2f12aqwvImuwwzD66ld+31MSf7ZPuA== 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=m1+vUAFlvux2wXM0/t+OqbhuL51Rq/ENxTsQGJDXxM8=; b=jMTDTY9KwRBXc7Lw/GNPeO7RiG9RzZtTMKMrruVk0jF1GMQjS+3ubJfG5KJwG6L4rkhHXDhtO2d0pks3AZ/KdmbgP0V1dJRHJ5g3818koTZN9YQDuCjW5XwbKThV2mdNfjGoCUqGZqgUAc35HRMiZE1BZ3hk7DhU21atjn662C/0pAwOcWmAfonZTku3o8UyjtsTi9jbMW33Mk/x4Pb4saGIQw9K9eOWF1Y/CaOR4pSD0VcoQicKbf9fLJqX6whx91ZL2Ad9hHHfpWbMxWDTGJCXV2uivILhnDVQ2K51cTOemI4/JpVLjTzh5puL6f48EI8RynfNqdjbUra4U74hNw== 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=m1+vUAFlvux2wXM0/t+OqbhuL51Rq/ENxTsQGJDXxM8=; b=M5+JQ+ReDF0scKFpjAU4vWIAvSC2NEix+xcptabn1LFjxfyqnM/rI5iS5Fo8k7ILfTXX0sPu8EaKlmE1X6DeTOgJVMCPOmigeLf7Gb6rjxZDhZtQwUwUKg6fhiEnHPxyrSLQDvuMFHi/uRS7sbJsuMZwW3d3tjThWDuZhpZSU/c= From: Roger Pau Monne To: CC: Roger Pau Monne , Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v5 03/12] libs/guest: allow fetching a specific CPUID leaf from a cpu policy Date: Mon, 29 Nov 2021 16:33:46 +0100 Message-ID: <20211129153355.60338-4-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: MR2P264CA0164.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:1::27) 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: 0bcee822-ffa2-49e9-da5a-08d9b34ddb37 X-MS-TrafficTypeDiagnostic: DM6PR03MB4764: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Gz68Hx/n8hChPwCR91zcbuCUt3hrJE8voptcZEWcKVAk3RKOBU/CgXD6HfD0c3sjJgg3g6RX+8Yt95bxVYQ6PxGiGANUAzYByaO/vronzUNUEIZBGKQd8EjJtLR3aw0p/ksB9ULDjx/Ht8NgRg4H1+PYlW9nzmFzjuoeKpX0odbEPO/j6ycD5cykgmaiFMNg0iaLaid9pXCPFNABzxxKhBf5VkshkiPgvz1BcDQpEOFZcUmR+SEyAzm871rCBWQ+M/w786kR0Pn0t9HpJovcQ7MS4KPithOLKonCUedcOUYcf3aExqLBBQI8UQyN0nA+9AYV5LfoqMBaZs2wfVnCfAAXSl4Vjvr+RdqP0Q+oYxGZmCRU1J7uEAetq/Yl0HLpLT2TWZPNnidJ5ha3NCWi4Qf9TN3c0H0ju6GNeB74dWUx61zu7Ypttvx/QW8JFiF0ilPk3pnAjnbQaWtGgEOYVL0wYvxiz2svUrW6DdcpdVJYUyw5MRSit4fFgkEUiPCuvggeM2Tsc367ClH/59CynrOG2tva8+oeQaw5yAJX16QsBIHtGCXouP2H9rfP3IVeQdBfelRbubDNZlCgboroYHkFUJD9/1mUSnMz3ZbBnGn+0fCvXi6OxpdAnME0aLhnBehzTTN0lGwLt+UzcCOmOw== 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)(4326008)(2906002)(1076003)(66476007)(6486002)(82960400001)(38100700002)(186003)(83380400001)(956004)(2616005)(316002)(6496006)(6916009)(26005)(54906003)(6666004)(36756003)(66946007)(86362001)(508600001)(8676002)(8936002)(66556008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?lpd905B8hWpnAVc3qYVlTOH+K6lF?= =?utf-8?q?grbZdEpHjAeDFmAief4NxH/NNArgYDlN1KDW1WWxKgDD83b/Sk/CnhbEym/PdPIJt?= =?utf-8?q?sHHyobgwcOlZ9QcDLHUBjpq6YC17ZqrxiqWyS/5pbPKRx7Z7jPOMRH2VjsnnRYaLe?= =?utf-8?q?IReVVy2BHaEV8bwURsqE1cDNEYjpDVc5tLpnZdOxUeIx1OkVMbRzgcY0M7LeDPoFM?= =?utf-8?q?Stx6kNJLWiCTBLzqyZx5mvpcHdt7wNuAcx89QZuSt1/I0wbMr5e8/d+zF/fQw90bn?= =?utf-8?q?1bsw5rYy4+CV7onrMHTITBP3NXFW6xb6LUWglUX1d8cmTw1gjhG29upgXTL1vJvJN?= =?utf-8?q?x+6DGpU23SQFSQf0SefOgTCLrRMQg6xwzbyRTiA90DCQ5ZgbbXQmNzJYNS/iZiNF8?= =?utf-8?q?0y1C8CGfaqigwxRSDiAjVcz4TbRVesIaKD41XbRX8XuiKXZyVKXLWXTk5Mk+Mo7qy?= =?utf-8?q?l+eJNjg9qet/sFEsIH7zB3hAQasUWx0L1NMg+lqNAebxSDxO5g79XPZEb2lFDh1Rk?= =?utf-8?q?GiVdnLn/o9KXohTlmEm5aBqZGqRxEQPs0OarGMK1cFd3G75CvmMlwsqvYvvqGH0/j?= =?utf-8?q?bTkuh1oWTjFEq1SSJbLA7s55102zo3DZrBLg29NObO1ctW/gE9hjslaFqaT+bklrB?= =?utf-8?q?2NAwX0HpV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bZvLOHkuocaaHm4O+EO/IQvN/b0aLcANkcma2HbG+A=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 0bcee822-ffa2-49e9-da5a-08d9b34ddb37 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:22.2316 (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: d0PyNvdK0yvVlbi8SCWNkHJBPihDm+mK5KF32DO6IuXjCO6f897NbrmJQ/HnQta/iEATT79HC732IRpaYvMipw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4764 X-OriginatorOrg: 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é --- 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 e01f494b77..0a6fd99306 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -807,6 +807,9 @@ int xc_cpu_policy_update_cpuid(xc_interface *xch, xc_cpu_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 *policy, + uint32_t leaf, uint32_t subleaf, + xen_cpuid_leaf_t *out); /* 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_x86.c index b9e827ce7e..7779a3e1dd 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -855,6 +855,29 @@ int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t *policy, return rc; } +int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t *policy, + uint32_t leaf, uint32_t subleaf, + xen_cpuid_leaf_t *out) +{ + const struct cpuid_leaf *tmp; + + tmp = x86_cpuid_get_leaf(&policy->cpuid, leaf, subleaf); + if ( !tmp ) + { + /* Unable to find a matching leaf. */ + errno = ENOENT; + return -1; + } + + out->leaf = leaf; + out->subleaf = subleaf; + out->a = tmp->a; + out->b = tmp->b; + out->c = tmp->c; + out->d = tmp->d; + return 0; +} + bool xc_cpu_policy_is_compatible(xc_interface *xch, xc_cpu_policy_t *host, xc_cpu_policy_t *guest) {