From patchwork Fri Apr 30 15:52:01 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: 12233713 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 DDC45C43460 for ; Fri, 30 Apr 2021 15:54:02 +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 6A3B361468 for ; Fri, 30 Apr 2021 15:54:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6A3B361468 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.120599.228105 (Exim 4.92) (envelope-from ) id 1lcVSk-0000es-LX; Fri, 30 Apr 2021 15:53:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 120599.228105; Fri, 30 Apr 2021 15:53:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lcVSk-0000eh-I8; Fri, 30 Apr 2021 15:53:54 +0000 Received: by outflank-mailman (input) for mailman id 120599; Fri, 30 Apr 2021 15:53:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lcVSi-0000cv-OZ for xen-devel@lists.xenproject.org; Fri, 30 Apr 2021 15:53:52 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 383de63e-048e-4b57-b395-a2ed92b46ed9; Fri, 30 Apr 2021 15:53:51 +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: 383de63e-048e-4b57-b395-a2ed92b46ed9 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1619798031; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=3QI6nIHICm7IiETY4sabstkRIAffc6tHvTWeY2+r5kw=; b=Bjbn7xNSZyDmgG7BKVjdfIjwwiuWTknYp0iW8RcyzUy/mUXraxbVj54U CtdNvgVIjRZyaVl0XNQ+KG4GN0nEtqzzUhXAlhjjJyszAnUSh0bSQ63gl BB2Z/e6XeNV+gPYY/cWU+uiIIUz1NjyhwdWDWk2H7Gt4TwxqPBHLv9sRf s=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: b+jLvBzF4coDP6O8VQIKJdH7/COxxvA8D13kuMeQ0d+c6M7BfrpeMEwgQ/08XK+eXFAqODhGBs w4iLc93OKiJRqHpXlDvJGOdNTvtQ92K5oSifGwK65VkDRGYaFXfVZpEfN7LtOBH7laHVRe4sVC nmr3yJlNVCejG1FcC+KOTlPaGF3DhiReFMODiZYVYwOqhw9DrxCSMoLi0o97IvNPm0KtNXATeu y0aZ5dVT+T+SBab/yPAy8oO9CeTW7mh/vAX6gc3ghWbbP3BI3d53eZZ9fXq05+cS5x93womncf t2A= X-SBRS: 5.1 X-MesageID: 43199232 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:4mjqk6zUzNbHoIIWf9mMKrPxvu4kLtp033Aq2lEZdDV8Sebdv9 yynfgdyB//gCsQXnZlotybJKycWxrnmKJdybI6eZOvRhPvtmftFoFt6oP+3ybtcheVysd07o 0lSaR3DbTLZmRSpczx7BCkV/Mpx9ea+K6l7N2utktFZwdsdq1m8kNdAgGUDkV5SGB9dOIEPb Cb4ddKoCflRGQPYq2AdzI4dsXKutGjruOCXTcoHBgigTPhsRqJ7/rAHwGczlMiVVp0sNEf2E zktyC82am5qfG8zXbnpiXuxrBbgsHoxNcGJOHksLlwFhzWhgylZJtsVtS51VhYz92H01oknM LBpB0tJa1ImhTsV1uoqhjg0RSI6lYTwkLi0lORjD/CpsH0VVsBeqh8rL9ZaRfQ5g4cush92s twrgGknqdQZCmgoA3No/zzEz16nEu9pnQv1cQJiWZEbIcYYLhN6aQC4UJ8Cv47bW7HwbFiNN MrINDX5f5Qf1/fRWvepHNTzNulWWl2NguaQ3IFptee31Ft7T9E5npd4PZasmYL9Zo7RZUBzf /DKL5UmLZHSdJTSq5hGuEbQ4+SBnbWSRzBdEKeSG6XWp0vCjbokdra8b817OaldNgj150pgq nMV1teqCo8YETrBcqS3IBa8xzETWmnNA6div121txcgPnRVbDrOSqMRBQFiM27ucgSBcXdRr KyNfttcrzeBFqrPbwM8xz1WpFUJ3VbetYSoMwHV1WHpd+OLoXrs+fcYevCPbaFK0dnZkrPRl 84GBTjLsRJ6U6mHlXihgLKZn/rckvjuZRqEKbb+OAXwJMXNpJFtxUUjVjR3LDLFRRy9ogNOG duKrLula224UOs+3zT0mlvMh1BSlpO7K74SHNMrw8SO0byebIO0u/vPFx67T+iHFtSXsnWGA lQqxBL4qqxNYWX3j1nIcmgKHimg3wao2+qQ58QlraY39rsfoo1A/8dKehMPDSOMyYwuA5x7E 9fdQcPRybkZ0jToJTgqKZROcbyWJ1XhhyxLctdtHTF3H/s3/0Hdz88RD6hUcmenAA0YSFb72 cBvpM3iKacmDqpNGs0iPk5NloJc2iMHLdaFm2+Ffhps6GudwdqQWiQgzuGzxk1Z2rx7k0Xwn fsNCuOZJjwcxNgk2Ed1qbh61VvcGqBO0p2d3BhqIV4fF62zUpbwKuOZqCp1XGWZUZHyuYBMC vdaT9XJg913di42FqUnzmFfE9WsKkGL6jYDL45davU1W7oIIqUlbseF/sR5Y17LrnVw5w2eP PafxXQICLzCusv1QDQrnE5ODNsoH1hlf/zwhXq4GWxwXZXO4ubHH12A7UAZ92M5WntQPiFlI 90it84puO8OGT8YNzu89CiUxdTbhfI5WKmReAhrp5Z+b8ovLxoBp/BTH/G0mpE0BhWFraFqG oOBKBgpLbPNY9kc5ZMJ2ZX/l81mM+OK0VuuArsGeM6dUwsiXieP97h2cu3lZM/Rkma4A33Mh 2D9icY+fHPVS6Kz6QbBKI9On4+UjlI1F1yuOeZM5TNAwCrffxZ9FW0MnWhYKZQIZL1Zok4v1 J/+ZWUhOeZeCrzxRDIsTZ6KqxI9Xy7QcnaOnP8JcdYt9qgOVqNhaO24Mm8yDfvIAHLF3gwlM lCaVEaaNhFh30rkJA3uxLCOJDKng== X-IronPort-AV: E=Sophos;i="5.82,263,1613451600"; d="scan'208";a="43199232" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gx8PbYQeGFznCJLGvd1TDRysETJAgN+yBr/NvxucF2bquHkGsB1zocYjqwEVGWfnu5wu1XC2y5JsnB0AM6L66yNKAyjPFH6O/XErj1aj/xDyIcyhhEKd1LsqnL/2tsWEpuSnHVL/Spb6q9CaLqewvQzDpqWywemkCKreitEe8eqxeAeqOQzbaGkUGmOkHhazEfeTk/p/shypTxCzcFXaJAUTuvCeOTlqbr7rJh9THMTnlvfYysXvyXHZWrICC+9N1lgGHyDVcwhLUFRPMgICZZfrawI+OKG4K8hqL/N+L/rr3XYSfM+37SDHahkclrZJzE388C3PX7sLtUlSC8C10A== 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=ReYtIhfneceED5ekYrJYnGrommG0WKr3NQgh92cs/8w=; b=icTsCbe+UVNYdBLCQTWMeQKJm0/psLBXHZEaeNYx49KVLkZ9ButF0GYANcvuASYmSuy1S9YVb9oVo0nyA4d7G8ncdkQJ2DNcxJEzJCoQZ6QtK5K7uPFzxW3DLz39vfuICKIctSDZdJnmQdRQoH9xIqSNcsQD7AXIegFNZwAq0sg9m2AeAyMHq7XRfw+sH9irRtbN+CB7JINZ1v52L8QkdhnvUGYqEss7mJYM1UH8g0w/OjExwn+C+6iqNxC7R1pUgjAs8Qmnz0GcCMy7ldJjqOIatHVOaBm6ZhiRcqEfzs7BYziOKGoGP0s4xmsv+PxYY1pMWooATMaMBvO8WGiZpA== 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=ReYtIhfneceED5ekYrJYnGrommG0WKr3NQgh92cs/8w=; b=OIFBmtJH+57JqD5P/CZIXmTSH6PzLn8Xft847pmnZWwSS6tH3ZxPLq0bUGRgcnaaumgHUniqlTZ8p+zS6T0+Ad4NN2Y39A5VC0MVnLCfZ2i6xXVcKnHJM4vIF1FNTsMh8kZgwlcg4RVA1VbRshmqXip+Wiue4VQfzkXGVxFW4OY= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH v3 03/13] libs/guest: allow fetching a specific MSR entry from a cpu policy Date: Fri, 30 Apr 2021 17:52:01 +0200 Message-ID: <20210430155211.3709-4-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: MR2P264CA0017.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:1::29) 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: 20912c23-6269-496a-e325-08d90bf02424 X-MS-TrafficTypeDiagnostic: DM5PR03MB2923: 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: m5aITIx3FG28L2Et90HdUdi94T6lHdCsO+sUeQ95p0vyieQ/EPjFmrAE+xy02rpbJZ3EfgjM3D24SMwgvOfSgOm7EeTmnA+fXqzpgfgJqCWZAhAT5ojw8I9U1PU8CxQ1o4J1VFIen3nkVjPYBZSayHyZcUYo6WB7pmyUfybyLqzzwDxDIqyVK+W/U9SCSUhZLtUpJsj2P5J22GOkezc6/r5ddkXQtYi+FXa9X1TDHNSJ0GJlIUfTHSe7U7SWbGx4/j7ZT+QioAi2esa0dG+m/NPyw6Yjem0rwwkyuk9yuvc5Y8ATkd5I3wvGJZdLXIS0lfolNpfwi96x5bKe6W76tg+c09DYo4p5xiPyIgksmgvT20MpYzyWtQaiAk8+QO5kXhScMcEvoiXOT+i0x9bkKsySVBKl9pjM9JPvs7tTxl8vP16pcMlcjKH9fnkpj+RAE36ER5os5CQyel8QX+QLyKD1o7YfAuAm6IZ+FEykKR3P7WjUgjAtAnZ1yF2nHM+Et1W6BzCKgwmdZs3gJuMdMIuVPzHNpebT2vJ98WNk50TGeMpbAg19fLNsgZkIMfJKK6bhooMWv7YASKz7Tn+1iXBjIEiacV0mzmXaXamm198= 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)(136003)(366004)(396003)(346002)(376002)(39860400002)(956004)(186003)(16526019)(86362001)(4326008)(8936002)(1076003)(6486002)(2906002)(5660300002)(26005)(66946007)(316002)(2616005)(38100700002)(66476007)(478600001)(6496006)(66556008)(6916009)(36756003)(6666004)(54906003)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?Matd73YjnrfcVXX1fsCLh3IleSgTOV?= =?utf-8?q?P1ys0x/lKIFgimH+TCDwzZCQPEZf6POM23ZXyfiq7MEfGBSVehcQEJUHV5SyjX2d6?= =?utf-8?q?oHT0xRY/GOoyS+WtZWl4RgXNXZIarx2tTjS65U4KdkdEbvTDOZWKl3I0xmFh35XBl?= =?utf-8?q?KE9Dpr1KvhSgbcri+9KRvtNASNqeqq8cZuGc97kVzEniJ4U9eqZmdxVg3H9ovY6u6?= =?utf-8?q?j5UGUN/3lPVgAEOwIX77mGc9BfhZx3qlE6Fz9wPe8H5KRu8wZsbHqU3UCv3eZ5hBr?= =?utf-8?q?hi5Izv9NrlfB+GJMi7SU2K2PGwiRaKEMmATQJnl5KOwirPLXSHpwrRZXhF1hxI4Du?= =?utf-8?q?vXJ2JVaE5Sh5cEEFSOHulZkT6xomZTJ6Uz+KakAqUtYm6zdpbYQGC00OwFhQvmN3O?= =?utf-8?q?8TpRZXAUTOkZe/vb3xr8xr6DNdS/3x8lVc4TcgWYsi4dmFpZORj3MdYkcl4poYNDX?= =?utf-8?q?gLSPtQAjCM9zngStvRUz8vrie4cn+7PcW128TUlZZQ8808NCZHkyQww6HOe4M9bB9?= =?utf-8?q?wX/oeUmYmtbMXPBCqt5YLGtPEfw2RJuJxwZ1sdpzOEi4zjxZBrdqNjAydcwyFmSgZ?= =?utf-8?q?2+1wQI1QPt8zDrmy7vlmL/SnwMg+KmrlVn0I92lAHH2vZ9VNB9FkXZC3+BEo37SUi?= =?utf-8?q?elzMvo/+KCfPIcDBRFjXlDBmCopRWs2XEik4PuuUDGnphhoZgm50Td/mvjQ6GQncR?= =?utf-8?q?B4yh31UTuQDyRr/PTGW3JUd8yIyxlX4B/vAvhKcKmSU7UYjKKq/KYKWBcBrKzowco?= =?utf-8?q?68tqQ8zy8Qbd24CpfkEGQaaQqgACchv+bgcXtojrWcbM/Q9XyAyo4f8HZGzHsSLVC?= =?utf-8?q?/peitohnORnQdH6JbAchNv5QiRezAH5WERfqdIzXpVSGzrK42Z4dAAX+WB8LoTZZv?= =?utf-8?q?vKQBLMbrBY3F9lje55l5PxRItBntQpHSmfwbEiBirJlZOI1VZBtqAwm7rL09gniM3?= =?utf-8?q?pO9/8U+J+QrVKRfDfAEYjsDhWDvmavHnXhr4UGcuRt8Za+6mQDuUxX6/A0DPI4YHs?= =?utf-8?q?sRk/QQUzmHOyb+ucqcpNtecxfjEnRb/aORBf1cKHFgHWXmJto0VbclveHZHglWijx?= =?utf-8?q?WWJt/6vFAahwx2yG/fpkN1mI5jKdv5bz0yWa6wiO3VI6st1cLdqUIzZuBVOO+IjML?= =?utf-8?q?1htWG9h0r6u8yKGRSm2z7A5pmy9EUe/qwHATUvJm7oltdNDD3oSQgm85UO18JFtSk?= =?utf-8?q?B+Pv0mno+ek7LQvefVH5J8T9RR49BXRiu2+6mTzJMddXE/3vQuhJvaBIFocTp9rkR?= =?utf-8?q?OrBjgoTxzxzWUA?= X-MS-Exchange-CrossTenant-Network-Message-Id: 20912c23-6269-496a-e325-08d90bf02424 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:53:47.7981 (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: j6jBqpnSLD/DNbJEGZagIN2YG8DEMk0Yxf5BeeaSySkK4ft3RQvEwyPmYF+2xLxpqtHgeTFQojS+0h9ozOyNUA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2923 X-OriginatorOrg: citrix.com Introduce an interface that returns a specific MSR entry from a cpu policy in xen_msr_entry_t format. Provide a helper to perform a binary search against an array of MSR entries. 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é --- Changes since v1: - Introduce a helper to perform a binary search of the MSR entries array. --- tools/include/xenctrl.h | 2 ++ tools/libs/guest/xg_cpuid_x86.c | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index cbca7209e34..605c632cf30 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2611,6 +2611,8 @@ int xc_cpu_policy_serialise(xc_interface *xch, const xc_cpu_policy_t policy, 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); +int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t policy, + uint32_t msr, xen_msr_entry_t *out); int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps); int xc_get_cpu_featureset(xc_interface *xch, uint32_t index, diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c index de27826f415..9e83daca0e6 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -850,3 +850,45 @@ int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t policy, *out = *tmp; return 0; } + +static int compare_entries(const void *l, const void *r) +{ + const xen_msr_entry_t *lhs = l; + const xen_msr_entry_t *rhs = r; + + if ( lhs->idx == rhs->idx ) + return 0; + return lhs->idx < rhs->idx ? -1 : 1; +} + +static xen_msr_entry_t *find_entry(xen_msr_entry_t *entries, + unsigned int nr_entries, unsigned int index) +{ + const xen_msr_entry_t key = { index }; + + return bsearch(&key, entries, nr_entries, sizeof(*entries), compare_entries); +} + +int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t policy, + uint32_t msr, xen_msr_entry_t *out) +{ + unsigned int nr_entries = ARRAY_SIZE(policy->entries); + xen_msr_entry_t *tmp; + int rc; + + rc = xc_cpu_policy_serialise(xch, policy, NULL, 0, + policy->entries, &nr_entries); + if ( rc ) + return rc; + + tmp = find_entry(policy->entries, nr_entries, msr); + if ( !tmp ) + { + /* Unable to find a matching MSR. */ + errno = ENOENT; + return -1; + } + + *out = *tmp; + return 0; +}