From patchwork Tue Mar 23 09:58:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157325 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 9434AC433E0 for ; Tue, 23 Mar 2021 10:00:13 +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 1CE78619AB for ; Tue, 23 Mar 2021 10:00:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CE78619AB 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.100548.191614 (Exim 4.92) (envelope-from ) id 1lOdp3-0006Xq-Ka; Tue, 23 Mar 2021 09:59:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100548.191614; Tue, 23 Mar 2021 09:59:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdp3-0006Xj-Gj; Tue, 23 Mar 2021 09:59:37 +0000 Received: by outflank-mailman (input) for mailman id 100548; Tue, 23 Mar 2021 09:59:36 +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 1lOdp2-0006Vg-Ck for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 09:59:36 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8ab031c7-56d0-40b7-beaf-f6a45e2ad81a; Tue, 23 Mar 2021 09:59:34 +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: 8ab031c7-56d0-40b7-beaf-f6a45e2ad81a DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493574; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=PijAI5WJCS5+jGvyOmq8HEdjQLOsv2uzbAMVwnz4R4I=; b=dE96m4hI+fgdyp5soDR/SODvILKj+/1QYzaY+MiW9L73HUlHa6qdzVgm ieD2lvZrZ2IwESOws//fVHIyzuhdFCklRb99gE4iyCUoeDbhimNHn/MbG /m36OGSt6cgevSnaXAjzLUWSm105zPO5u8GN81543mF8XPmhnUBLU2SoF Q=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: ugGyEmGTlfRVXvU7KgMXiZsUkATpxf1Mf71f+f1Y9Wh3ALapg6EFF4qrRUluziSIuJankSqkBP u++H4XfNDT89ilDg5Xodb6pAHkbIx5gX+Enlt5iQrfQ7TQx9rbuB8amBbR0v2bJ7WvR1aRNVFd 8I3JVDxxrnI/dmvpG6LMsyABTXufjR7NxYjU7R64f2AAbyBtCPlu3V/rf/EfQldpvBjx3uBpKM 5jKTxAnejaGNRTI0I5MshCULWx8tlODci6CHFyEqyfj0rCK+3gjaePweUzLvfzuhM20k8AMCQJ cnk= X-SBRS: 5.2 X-MesageID: 40261118 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:wvcCTahyKw4yP/z1oeC+eX3h43BQXwh13DAbvn1ZSRFFG/Gwv9 yynfgdyB//gCsQXnZlotybJKycWxrnmKJdy4N5B9efdSPhv3alK5wn0Jv6z1TbaknD38N+9Y MlSahxD9XsEUN35PyR3CCUG8stqePpzImGnuHbpk0CcShPS4VNqzh0ERyaFEoefngiObMcGI CH7sRK4xqMEE5nDfiTPXUOU+jdq9CjrvuPDSIuPBI79BKIyQqh9b+SKXOl9y0DWDBCy6pKyx mmryXF4MyY0s2T+1vn+EL4q79Xn9bgzdUrPr3wtuElbg/CpyztSIBoW7iptC04rue1+D8R4a XxiiZlBetfwTf8eXy0vAvM1mDboUkTwk6n83C0qz/CptH0Xz0zAcYpv/MmTjLpr3AOkfs59Y Aj5RP/i7NnSSnusQ642v3zEzZtrUawqWpKq59ps1VvFbEwRZUUkZYS5ypuYfE9NRO/0q8LOs 90AvrR4f5HGGnqFUzxjy1UzNugUm9bJGb+fmEy/sic0z1hlHtk1UcvxMsGgnca9J4mIqM0n9 j5Dg== X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="40261118" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TUHFiOvalbjAJ1KRVujnpCGSDnBZx1m22DiTTQd9ad4t/rDrA+TkZIWu0QLPbJdpO91ANPbFXsSxk5fZTYZIkDOwxwk1HMhCMiQRk+kN8w/8fz8sV7ODckIVxyh225CXfHfhy7oa0wVQs2GigFuXwkvGLTpS/fSN/Svwsdq4Ith2ROEsee5K7dMENxQpEJQd82jcCMBPsfT/+OnTOWmvDmEWaFlLZAYJ9BgN3MZR4bXuAZ1wFWFqPspxxL3v3oFsWDRKsmvvWZ7H9T3Mnz5rBP4qyvD50RgJRaW2Cm7TCg+P/bWwgpvtm9jRX2AVRMmgEr3qCgjZCh9j1gxcT4aHEw== 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=fCYKj9xS+9yyRL8nU+5448nJ4c9TjD90m81OST2t//U=; b=TznS6BIuduPX0LyNwDULCZXItBI1PsB4mbubcohFIKVC2a6EJvMgi/StrESaEHizLk0GfoH9TsIBpspx9kelivCWeT+ymbhrtg+3GHmweKcSTcKvM9QuQQAjSzwN4a0dvcg7Ag//t2tSh1+aX+5Ur9U91GVvbEDfBtz0m/8jlm10locMeubOq+ggNYvksxRR7r/Rlox60izYslks9YJDH2QG+iwZ8lWEiLaotRMag2CrCI5ppw3GBHUlbSniZtqJBzguMirqVpxKHWbJtiWLHm9HPAvXZM/gwKxG1Tr1HYiprOazjfA3Suc6KrWuXsW4ntwzcEvDB8bPd9edao8yMg== 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=fCYKj9xS+9yyRL8nU+5448nJ4c9TjD90m81OST2t//U=; b=sdpK6Sxa5RWxwmUcpmUL6/H+O7BEyrppgxhFoXeMjfc2enBlJ1whaBqEIq9hSldW2cenbaSO6G06GiqsXL8Lq8S322SH48bYOA2nbLjRHk55f91EFI/rBPRpOn0Og8z9+c6+pXm3ZKAyC0zQo+Nzf5kJyiU062mfSSoSAYSytE8= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 01/21] libxl: don't ignore the return value from xc_cpuid_apply_policy Date: Tue, 23 Mar 2021 10:58:29 +0100 Message-ID: <20210323095849.37858-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR1P264CA0010.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:2e::15) 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: c8566e7d-f617-4e26-e009-08d8ede25a99 X-MS-TrafficTypeDiagnostic: DM5PR03MB2633: 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: 1Euvyp0dSa54nH95+HqYgiwNPuJMGbrFJLCG7pl/O2XAVKLqFEQH2LbiTF8joHYXiarrIKFFpkPEuWPjxKBEhCdXF6fnH2QVhXYsWqUAadTTH0A5wnS48kRlqwup//fUDu19kCnywo8sOARwLhPKGiaSIFQPivK0l7XNWUZAwmf6FcJQU05vbQYLfi41m6zkalLSyAdet9thD4TWPi4zlzQsbs/CjhvJynb8cZEe/pk/M4AEetUwvP/vaFLSm5W2G4MpTJNwveWGpPbev08hP6DgeZN8lc4Ogg6rt5YR4aO0wMoZTiBsj59JSAODcrco1pZ6oixyoo2Y9B+K5jwOMXVggI4f9e9Jmrau5RLUaLB6rwrlhbL51ccu6tQSSNGNKyzwkHtDLX7j/PnpxnEJiIIf2VlWlu/BEPNzetja+QOXn9hT67k+vhgEAMgIboL2KykLwiv8pVp9u7CVMokH8Gbh30ParHdn6J+ftsyBJUFqbjvAFHlPLgTKyWnMmTe1hDKRkBRqWHetHi7oiNaHEAn5LpudbpBbk/p7fY9fb/6esJUle4UoRX2izYam9akHmmr9FUK0UQPDZKrnN9YQ9b29FhTuDQiIyegQ3fgPTULMMw+VuedBC84O9c+sw1r9+4EWV5O0UAgdygdvcRDYeoeNLl3bjvlJ1NGVSs6uIX0= 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)(39860400002)(366004)(376002)(346002)(6486002)(6916009)(36756003)(6496006)(2906002)(8676002)(66476007)(5660300002)(186003)(66556008)(66946007)(8936002)(86362001)(4326008)(54906003)(83380400001)(1076003)(16526019)(316002)(2616005)(107886003)(38100700001)(956004)(478600001)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?nD+YryEfMO6jny/nV54Gbz15rCzeHM?= =?utf-8?q?X2y7+Xczm1ORKjUvTIzKxeVZ9F4vpg4SCy6Z/g4P5dLmAPrvu/JlWgd5W5/2r3c0X?= =?utf-8?q?psfJjuBA/g+Ib6v7qMxWsrqN1eDvwYuefg7jrBgN8FFsj4RosD4HTuyp6/QpXACoD?= =?utf-8?q?7O8KiMlamLVQYoO42upZkRbgRCtjXOiNA0gPUgwvKgh0gBQ1Uxc0aEx2R/GojsWpY?= =?utf-8?q?Dhe4dzc385akzYSrvz/xLPMvN3xgsirCA639V0anv9cXT/mUhbaWcZMzb8hMRX6DR?= =?utf-8?q?JvRyJfzTPEQLI9VEXs59o1K1TlAkC2kMefnUYVTAHShelpoxRDEbPqPIoWBHB+X9I?= =?utf-8?q?/P03M0VnVJj3uoL3aT+vjcvaS+kTGJe3bLvBNJhz02H3kAbQkzkdpPSCNpgcFHyFF?= =?utf-8?q?jOFtR1Q0TxnwpKMBE1JgSGg94Cm50zxYsKAdxuXz+//qmnP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c8566e7d-f617-4e26-e009-08d8ede25a99 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 09:59:31.3461 (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: 31M2cxtKkcMMBQwSRy1Z0j4Je1T0gzth5uwK/LT37pkvCrRU6YPwUsrXWePjqmYRAIu/otOX/tqsC5TQ0WD3bw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2633 X-OriginatorOrg: citrix.com Also change libxl__cpuid_legacy to propagate the error from xc_cpuid_apply_policy into callers. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- tools/libs/light/libxl_cpuid.c | 15 +++++++++++---- tools/libs/light/libxl_create.c | 5 +++-- tools/libs/light/libxl_dom.c | 2 +- tools/libs/light/libxl_internal.h | 4 ++-- tools/libs/light/libxl_nocpuid.c | 5 +++-- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index 289c59c7420..a7b33bbcd06 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -419,11 +419,13 @@ int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid, return 0; } -void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, - libxl_domain_build_info *info) +int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, + libxl_domain_build_info *info) { + GC_INIT(ctx); bool pae = true; bool itsc; + int rc; /* * Gross hack. Using libxl_defbool_val() here causes libvirt to crash in @@ -462,8 +464,13 @@ void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, itsc = (libxl_defbool_val(info->disable_migrate) || info->tsc_mode == LIBXL_TSC_MODE_ALWAYS_EMULATE); - xc_cpuid_apply_policy(ctx->xch, domid, restore, NULL, 0, - pae, itsc, nested_virt, info->cpuid); + rc = xc_cpuid_apply_policy(ctx->xch, domid, restore, NULL, 0, + pae, itsc, nested_virt, info->cpuid); + if (rc) + LOGE(ERROR, "Failed to apply CPUID policy"); + + GC_FREE; + return rc; } static const char *input_names[2] = { "leaf", "subleaf" }; diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c index 1131b2a733e..3b7474979de 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -1443,6 +1443,7 @@ int libxl__srm_callout_callback_static_data_done(unsigned int missing, libxl_domain_config *d_config = dcs->guest_config; libxl_domain_build_info *info = &d_config->b_info; + int rc = 0; /* * CPUID/MSR information is not present in pre Xen-4.14 streams. @@ -1452,9 +1453,9 @@ int libxl__srm_callout_callback_static_data_done(unsigned int missing, * stream doesn't contain any CPUID data. */ if (missing & XGR_SDD_MISSING_CPUID) - libxl__cpuid_legacy(ctx, dcs->guest_domid, true, info); + rc = libxl__cpuid_legacy(ctx, dcs->guest_domid, true, info); - return 0; + return rc; } void libxl__srm_callout_callback_restore_results(xen_pfn_t store_mfn, diff --git a/tools/libs/light/libxl_dom.c b/tools/libs/light/libxl_dom.c index 842a51c86cb..e9f58ee4b2b 100644 --- a/tools/libs/light/libxl_dom.c +++ b/tools/libs/light/libxl_dom.c @@ -384,7 +384,7 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid, * being migrated-in/restored have CPUID handled during the * static_data_done() callback. */ if (!state->restore) - libxl__cpuid_legacy(ctx, domid, false, info); + rc = libxl__cpuid_legacy(ctx, domid, false, info); return rc; } diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_internal.h index 028bc013d9c..22b1775b752 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -2052,8 +2052,8 @@ 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); -_hidden void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool retore, - libxl_domain_build_info *info); +_hidden int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool retore, + libxl_domain_build_info *info); /* Calls poll() again - useful to check whether a signaled condition * is still true. Cannot fail. Returns currently-true revents. */ diff --git a/tools/libs/light/libxl_nocpuid.c b/tools/libs/light/libxl_nocpuid.c index f47336565b9..0630959e760 100644 --- a/tools/libs/light/libxl_nocpuid.c +++ b/tools/libs/light/libxl_nocpuid.c @@ -34,9 +34,10 @@ int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid, return 0; } -void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, - libxl_domain_build_info *info) +int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, + libxl_domain_build_info *info) { + return 0; } yajl_gen_status libxl_cpuid_policy_list_gen_json(yajl_gen hand, From patchwork Tue Mar 23 09:58:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157335 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 B89BFC433C1 for ; Tue, 23 Mar 2021 10:00:26 +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 6860C619AB for ; Tue, 23 Mar 2021 10:00:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6860C619AB 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.100555.191662 (Exim 4.92) (envelope-from ) id 1lOdpY-0007Zg-3k; Tue, 23 Mar 2021 10:00:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100555.191662; Tue, 23 Mar 2021 10:00:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdpX-0007ZY-Vf; Tue, 23 Mar 2021 10:00:07 +0000 Received: by outflank-mailman (input) for mailman id 100555; Tue, 23 Mar 2021 10:00:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdpW-0006c2-UG for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:00:06 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 08a15162-6565-4df7-851b-84c50e21e68f; Tue, 23 Mar 2021 09:59:55 +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: 08a15162-6565-4df7-851b-84c50e21e68f DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493595; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=ZVYTmperKRV9McJzyxCAMKd6T4Q9wkkfiMKYTjTYp9w=; b=dkVnjy0gR4LrRC0Xasy3u9aB4z8bf17VBfDuLCLFqlNp9uf3r87S4jQv yDqug4n8kwN9fTNE0zyBv2cWzF48yIGD+evIrtFl+NZoj8eJ9Avvs0Sgr aENs14LfY7LQSVOk2gGe6TvLf3V05zu8bFAlJW4r3FYosV1TbO2lndvbP s=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: zsTGLXBLhxYbWYKXJA9GMzC2QetVFtT0b5xaIsrP9D/HyQnfLtQ6XqN3z9HZwqm3/0AQCZ6FcN 6w8f40D2C5G4ZKt9O0/BczjbtxGICu5/if5Fz+slxinUg7N028u4IS22pg3p/zTPk+Iv89dg/b DlGpVjWFgf/vliqOIXKk8Y8qha/cujY3pRbYAbuQ13dPjk6/Ye0zuQoyWQ8ZK2LOdgKlB+UXN/ Wqbkj4xuhbjkL0I6KSZsQbnWggwIg/VopWx0S3UKqyuIWDjgvO7q8DjMdku3O7FqZ2xqD39xjn 4Zw= X-SBRS: 5.2 X-MesageID: 41330285 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:L3wV46nGF5Al2XbVWrWsGRE9wuzpDfOpj2dD5ilNYBxZY6Wkvu iUtrAyyQL0hDENWHsphNCHP+26TWnB8INuiLN/AZ6LZyOjnGezNolt4c/ZwzPmEzDj7eI178 tdWoBEIpnLAVB+5PyW3CCRD8sgzN6b8KqhmOfZyDNXQRt3brx7hj0ZNi+wOCRNNW17LLA+E4 eR4dcCmiGpfm4ZYt/+Kn4OWeXCoNOjruObXTctARk75A6SyQ658bKSKWnk4j4ycRN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9aTq0LjXO2F1Z 1ljdQz+cu8W1+BHuKu+OXyVXpkLBiWnEudC8cPgrpQtbgptLRyE4LAOAG4nE1v7VEbFoPMiE gaQK5H+7jPNY9kQtwKd0tijy8UveXKCHFujxf/DeA/d2w8lnP3P9uG5LzTtLoka3fx0zfYCB 26+y1Z8+ytZVr66ZcqT4YxK39Rck4y9TBL+/6DbZTZDGyRBqt+1Wv/Fn+2a7lGTqeZXZ0Wsx Zh+tmN28uabTDx1gyVnTx1JMt1giuaaPL3JAKHAuhT9dOmfXyKn6ux+ca2yA7NdgHTUTVQua R1MWoKbspCjTE+jIo4lgiKI5aH3X4Noh95+jFollnkx468xnzUdHs2aDHkvg== X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="41330285" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oclrcvNmzj2wuqpOxjANgH8/TsyS9/JnZkgsXm9BC4kVqI4eztHg30VoxUVnpL4EhhCwr5fKNVOQkbjfIYSHi0XdXSohU/Lcd/8ENteNs5aViutq5fL9XxV6mVqREsdmz3VxE3weFaKfNdzDHpXIzPJ3jr+JujfWEClD5paVPXb0CcSvV0DX8dpthKeQa4Scs6dgm/6wPIHNORPO7cEKRvH7H3KocnqO/JpJTjf1uCPjl/7+ZR4Miq0l9X/AosSJQMBiXIV+XwUC3nDwDUNMaSPXqgnRyc49T6h4tJDKEB6AMBKp4RCgdnCZpyxDfz8SQQrb9srkVsAV7Ac2JJkXpg== 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=VWrNMyZoDfL7l68Ms6pfloMPkzoINCdhTAU0j0iWLHk=; b=S+vux3G4QMSmkxwzwh4gQ/lXm0X+iK8XXvWEw5busNVYFXlSOBoiM7bWr8YKzofRw85id6NxtjUjrmaXbwwXoxSBLRqJPB02z18zpy4trt211JGudVHU+F8z9u3hkFLjkMgBKa+AlYGWgAtFBW3RTgFUyk6+6+d6cxMYU/0q4Kr9I4tXmFmJfHeZE61M+a84HbbI4Ep5tGCGNTaPQCf4O6GbiHquR0DyKv8X1dRrHwlItJocjwofcSXHpX7zPhkO5Jgk2iIz2UgTCtFkkG9Ewy4+huah26I7Ev0H8zgfvQ191yfKknuX6FARy5kXj5VVETxPNC//4bwOevOVjo9Ypg== 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=VWrNMyZoDfL7l68Ms6pfloMPkzoINCdhTAU0j0iWLHk=; b=F2El6fLpy8jPpQ1e1rIl5BUZyaQgUBzt9mTPA2P+vBxMcBuBUJe4QOmHR/3CyMaD8/6zucl8IQfUUr4h/oY1pybK9tav0T0HX4eQf/C0oufufJL1rEi8AjVFUc/ny3uF+f1DhwgqwJPqKl7ccJU+oosnQrt1giJ30/fRZ+/OyN4= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu , Jan Beulich Subject: [PATCH 02/21] libs/guest: rename xc_get_cpu_policy_size to xc_cpu_policy_get_size Date: Tue, 23 Mar 2021 10:58:30 +0100 Message-ID: <20210323095849.37858-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MRXP264CA0036.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:14::24) 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: 7c01cc99-ae16-43d2-eaf1-08d8ede25dff X-MS-TrafficTypeDiagnostic: DM5PR03MB2633: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:626; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SuSm21468e2b8FGwOzyziLa7rDWRJ5tMoY8dmwYT6F7xEizIo2HDcvv/cmsor8WwZlwQIjudiww1bZ671BwWncziaB1gxVpEMXizJFsmZAdqWmsyDMG9dk9PE3gJrOZFBT9UN3u5rz57F0s7G/dFcbE1TQGA5fy4wn0scOh+d3GjJmmwUYzu+VStIW3zv6nXAH4sbuO1kqCIOses0xEcsy+558PMaEmQzjBR3q7DKZoazeq56Sq5C2d5NGZyFPWoRLD61RxoRCzU65nTtyhhxwhtxsF9TniUcc4JE7oSgcvOt+Zxdj1K+17x1ITrGMbokCkpByYz2TXmCNBQzOTPSfgWTsJFWXESspaSbqelHmjOVYXtMVRnxq6js38SnbVCbej949Zm7my5KL8KpTaLzS4XxhK4zay3bhqLKf8OCMCbh8VDIemh9uaeQBz+vYTfawDK8uIKztkLtfUxhLR861+W/CweBIA+CqVOf/x/n3LjxKfdwDBFVqdiuNXI7UKUUYVKXd6Hz63IVHGVkQTFXoJWNPpskE7l1e2Ve5zA8t+aTUfMAORWlp5qtxcDs2TqcUQXYzXJMKbPG7LOWTnMaR7NLdpp2WyKR9N3r0Dh++gPwsyBIIc87XyFh4+33+wDoovXHh0QuqrBBd8FQ9uwFxaPOA35AQoErXbDO3GEzbI= 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)(39860400002)(366004)(376002)(346002)(6486002)(6916009)(36756003)(6496006)(2906002)(8676002)(66476007)(5660300002)(186003)(66556008)(66946007)(8936002)(86362001)(4326008)(54906003)(83380400001)(1076003)(16526019)(316002)(2616005)(38100700001)(956004)(6666004)(478600001)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?iobLmfzQpyAMH2EjcObymdquUqVNv7?= =?utf-8?q?aeE4Jx9NhCTdLZlD4XBxf/sE3iT4QqYmirWL45g74bFDf1mDhO6QH/HfwKqxvPfh+?= =?utf-8?q?MR5Pl3ljIKu6TLTDsIPR1L1nmQjT5xOhTcPCYF3PcBY1jZN2lUCf3JAaAvrRctaX2?= =?utf-8?q?JyMXKWy8ahUXQPETVO7dzlevadeNGjyUpN07OuimOgd2NGoyOZQFDK61Q6hYIe06U?= =?utf-8?q?mdB7/JVrF6MLpeNYnCfWlFlGvoEVvQDSxQY74JNvAnPEPZKEa3emB1GmtY6WZDjUJ?= =?utf-8?q?wXtDSgaiCKOCbgt8mdIKlxl7qjt/i4TxBfBppXuxqGudu+HYHlRKZHqRNThXsZWu2?= =?utf-8?q?W/4nprqHKLvO/PfTPO3IiwzF9hM2Uw964/KuUAVtxmXIbymWuW7x4/aYz+pcHDHoT?= =?utf-8?q?F14rHnIM6dkUOt1U1Dg8jP5cCJvGJKORTx5fd2SzjtylskEs1P0ttm4uLP63JQdAW?= =?utf-8?q?LQI/f5DXWf3AT9hQRWA5BJd/M0+DQRl5QEY5Ug46EIYEhPScm6/ee5b3C2XElsAhs?= =?utf-8?q?0VHAi9v4RobhhLx5WLGNmvJw3fvNeCpDYFODnywKXWwarc7QFdfDNZJWjKxxh/EFy?= =?utf-8?q?09lQTJIvHpeN8a57QyA3kVlo7LyEEQsApZIFuTBbMihkoEiHlYxJy05uhKKLk8qxT?= =?utf-8?q?kRIf87zy81O+0qWXB30fS8PYMCSKADRUjaajXFs5jd326y4wLCuRv5Z6WjwpA2tqN?= =?utf-8?q?XhtF+yZS6JA3mMeHARlBeqESiXRqH3hq6GYQyj9axQZJyQkK+uZjJrQWmkkV0nAwj?= =?utf-8?q?Iey3IAiNqX5NzJnkokS+ib/muwHNe7oDK4mq5fM1PFCxadVeE2SPkcuCV/E3FvgnJ?= =?utf-8?q?ifTaqCjzXGErUfzHibODaTvCFsBwT23WGGvQQRT84dmQ2JU6sd7Ip5eyY+VRvKFdz?= =?utf-8?q?T58xMNbPkbQuKR/XMJdL1sHODKWhdhfTziux9bcM5/vZzrQ+m+vBt6wBRaWvwV7xE?= =?utf-8?q?QfxjOTiHK8VqEyfvbZ4QdLSJp4dBu3jXraxcUcmJMywu4pAuBuUfeORmzY3GUDz7N?= =?utf-8?q?sCkSoDLqyulc84zf8SFs7r+8Fh3d8HM0vQPYysMYwObGjoA3KF7xxjnZwV8Eyb9LS?= =?utf-8?q?bVEOft1S/OV0NbNI7bt9LtGalxdCkroE9FlcszVd7mvtNIplWA6u4awQ6Tqj++Am/?= =?utf-8?q?HuK3FQoHvCe0Q1+cV65/KBH7ig2IuIYRisLBtnfIlfFgkTi3mxCkUHUwtPGmNGiUB?= =?utf-8?q?8didZFPwivvbYI6c3VmMpwuy55WP6zjOs670AsimdPlHcIAZc7DrUT2eV/OTo93B/?= =?utf-8?q?yncqPkIz/y/K6i?= X-MS-Exchange-CrossTenant-Network-Message-Id: 7c01cc99-ae16-43d2-eaf1-08d8ede25dff X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 09:59:37.0391 (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: vgl8PCupPskFSKcEjFaWNRmUte4VK18jpetpjDr5rwt+9ky7SDkA8R8WXreH1yiBmOp0+j8aeulzbuPA8G7j6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2633 X-OriginatorOrg: citrix.com Preparatory change to introduce a new set of xc_cpu_policy_* functions that will replace the current CPUID/MSR helpers. No functional change intended. Signed-off-by: Roger Pau Monné Acked-by: Andrew Cooper --- tools/include/xenctrl.h | 2 +- tools/libs/guest/xg_cpuid_x86.c | 6 +++--- tools/libs/guest/xg_sr_common_x86.c | 2 +- tools/misc/xen-cpuid.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 318920166c5..e91ff92b9b1 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2594,7 +2594,7 @@ 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); -int xc_get_cpu_policy_size(xc_interface *xch, uint32_t *nr_leaves, +int xc_cpu_policy_get_size(xc_interface *xch, uint32_t *nr_leaves, uint32_t *nr_msrs); int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index, uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves, diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c index aae6931a114..9846f81e1f1 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -109,7 +109,7 @@ const uint32_t *xc_get_static_cpu_featuremask( return masks[mask]; } -int xc_get_cpu_policy_size(xc_interface *xch, uint32_t *nr_leaves, +int xc_cpu_policy_get_size(xc_interface *xch, uint32_t *nr_leaves, uint32_t *nr_msrs) { struct xen_sysctl sysctl = {}; @@ -302,7 +302,7 @@ static int xc_cpuid_xend_policy( goto fail; } - rc = xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs); + rc = xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); if ( rc ) { PERROR("Failed to obtain policy info size"); @@ -447,7 +447,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, goto out; } - rc = xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs); + rc = xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); if ( rc ) { PERROR("Failed to obtain policy info size"); diff --git a/tools/libs/guest/xg_sr_common_x86.c b/tools/libs/guest/xg_sr_common_x86.c index 3168c5485fd..4982519e055 100644 --- a/tools/libs/guest/xg_sr_common_x86.c +++ b/tools/libs/guest/xg_sr_common_x86.c @@ -50,7 +50,7 @@ int write_x86_cpu_policy_records(struct xc_sr_context *ctx) uint32_t nr_leaves = 0, nr_msrs = 0; int rc; - if ( xc_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs) < 0 ) + if ( xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs) < 0 ) { PERROR("Unable to get CPU Policy size"); return -1; diff --git a/tools/misc/xen-cpuid.c b/tools/misc/xen-cpuid.c index 2d04162d8d8..52596c08c90 100644 --- a/tools/misc/xen-cpuid.c +++ b/tools/misc/xen-cpuid.c @@ -462,7 +462,7 @@ int main(int argc, char **argv) if ( !xch ) err(1, "xc_interface_open"); - if ( xc_get_cpu_policy_size(xch, &max_leaves, &max_msrs) ) + if ( xc_cpu_policy_get_size(xch, &max_leaves, &max_msrs) ) err(1, "xc_get_cpu_policy_size(...)"); if ( domid == -1 ) printf("Xen reports there are maximum %u leaves and %u MSRs\n", From patchwork Tue Mar 23 09:58:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157329 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 7EB5FC433E0 for ; Tue, 23 Mar 2021 10:00:17 +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 26895619AB for ; Tue, 23 Mar 2021 10:00:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 26895619AB 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.100549.191626 (Exim 4.92) (envelope-from ) id 1lOdpE-0006cj-TQ; Tue, 23 Mar 2021 09:59:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100549.191626; Tue, 23 Mar 2021 09:59:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdpE-0006cc-QA; Tue, 23 Mar 2021 09:59:48 +0000 Received: by outflank-mailman (input) for mailman id 100549; Tue, 23 Mar 2021 09:59:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdpD-0006c2-2x for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 09:59:47 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 2ed01982-7002-44c2-a005-1d398e41eba3; Tue, 23 Mar 2021 09:59:45 +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: 2ed01982-7002-44c2-a005-1d398e41eba3 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493585; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=zcfmbEe4UCyttYXsnFBGL6aT4m16gCdnmGNRMv3yYUY=; b=QSR3AvSA+N+nfREPB4cgLKiYeGBIbRN/dMJU5jyPZfra4L9x/+aZgaPs zcdZ7fWaftWrKrwHjcIXa33pnr2kyzXZPgnnTVhJoZVXb+hRIUvD787gh ZsjyHQ8jXzLVU2R50WvymkGBzkbtZWgMjaWLY3YS/MMTnyvqdSNl2dNsi 4=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: g1PO2tYsGB+bltiKrfzuycs9uxjztNWl4I4fPHHlZKtof4HRwmfoZEjUQRbFuzQ3v86PEz87J9 pWWODA/SpKVTXgBCfPznSJ0npzyjDYV7uXKYAPIYQs5SsKud3PSpcGeK31nsufrvG+yNclEJ7R AyIbB+qtMOYfvfHR/NCgQNhhylGWNqr5KMpqXLS/XTseeWkPen7GO3gW6LDEHjNY96lYJ/L1D8 zQHLLQOfR7a0a5he9ZZIXTKsZR/ATkdLB7R2HFkri1pnOKoz6pUMZBcVR846et9YgE3XDWP95V 4cE= X-SBRS: 5.2 X-MesageID: 40055392 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:i7m16Kt+oYjsieunWxZsjk2L7skCCYcji2hD6mlwRA09T+WxrO rrtOgH1BPylTYaUGwhn9fFA6WbXXbA7/dOjbU5FYyJGC3ronGhIo0n14vtxDX8Bzbzn9Qx6Y 5JSII7Mt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axkAWYgiqGCG9O/ORTAsXYFrQ7RbTa0X+pMuSz5Nw7Nu4R85B/ON/0tOgXFe qZZg+ONTv9T/gkwgqPux8eSWBJgWhhlfPjwxv+6mekmHY5HPrJOVxjLotrVO20/izhR/yS1o 9+gs9wteysMn/pYtrDza3MdTZMJlfSpmGxJttY36x8rOY3tLFpGYPcXiaN3HZb3A8mJMOxjV gAWs1AkcL8E54qe9ZXdzNS/1IvmtjKJEw3shbuCut7eV02lXfUM96A/rKgk8tmPmSR4A/rfV WP+SxU+PnIGzGO0rMXEKo8K2VbYkpU0gUXwMqSM4nLTAm6feBK+1S3dmKneLhGUa6fBPEeqA 1579zgpZ7lSwPonATL+T11LaJF/zz5HYe8AAeQFfVJ9NL/M1KWmaeu6NOyijCySTbTUTVoua RVMUgLKsJEgX0+iYdy1C64QKn+uFgknFtT+isPrC+Z5qG2pGPAWVhbOgjYiIhMVTZdMnKUnd 3ImNLoqkjV8XxAw93fD09ecdFFBsgIQoX2JyloL9IMvLTAxdtevg1TJBE0D2A9jzjh3+Rpmb ehsc+iJNHfNQ== X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="40055392" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Egt3gICVYG9PWWnrHbDpz0D7bT5zGRqJPSXh0xKHax+f4Al0618ZZVqEySH8/R5MLgvEds1E8slTZczaSmghfeFBliL7F/ymqLY3dv40LTJyQHIZPraa6XYH3bss6uob0j7oAY3j/1weVlw00Bk3/C3ka5puwtQPNMEzp6K13Qy//upHtuKB4zb/qoKn3U0kvJ3k/3FFamEEZKa+q9RBvv96Cme80zKrhxwSbjc+jBVcO1VW7LzawMYUb6VWf/7MwqRfRpRpoTmSQMz58SJreYtq9z24a2qRpl4DsxRFwjwXpGa/+tk9awBny1Dn7eOgoJ83ewMP6CuFlazfj0I5gQ== 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=gTCmGbFvBsxXZnJ6Z7hVKQ43JE3lWvZovCCAb8H7ohw=; b=HvnkHgbWMoHT5Og3I292wIFJ+Y+o51+ee8DxkDpkQzLmtMPfWxGbz7CZtBw8cP/+rfWukAqZXn/MbW6yFZmZCKvo8TtgMMz5G56YAWhaBxDOgi4OAwn+ywrxPmyJO949fSAg9lQTZDF/xvut1j9QI68PwK18jWBsVdd20TZMP9UqpjOOy0oW9kFm/vOIRuUgMr3qx39K/8pMC9VNGPLml0V+YMnxOPoA3L4Du6S2sHEHxAD+2MpJF3yR/nsCmBCnzNyXA8mBMMVDoldY8Wu03uCai5932QA4+TOWXkemxpA2uI3ACgmIiFgFOwIzwVxO5ZC/HOZbXx/C0zclomj4Sw== 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=gTCmGbFvBsxXZnJ6Z7hVKQ43JE3lWvZovCCAb8H7ohw=; b=Bv+5c8nstfmbVERiV7hSs3ny3Gy0lTZq86i1I/DVyC7C/8gSYnRi88fElOH06x4xwnJF/TBNxQ3T7oLeP/8NShZ4+Of+Lgji+d/I1OBiwahjUo8gqX8yfTN+jQgK+ta63rDSqbglHY7xDm67irseTCuvdBpLW+TvnMEvVZX5xho= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 03/21] libs/guest: introduce xc_cpu_policy_t Date: Tue, 23 Mar 2021 10:58:31 +0100 Message-ID: <20210323095849.37858-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0135.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:30::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: 945ca441-a6b2-46e2-17aa-08d8ede26131 X-MS-TrafficTypeDiagnostic: DM5PR03MB2633: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1265; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uPLwdr2Q/t4o7xvjoUVEXe8kBWVcW7phbeKhwr2p//nljg6VkdDumuRE9YqELGsyJ4YLCzNMCw8HSLZjdCGBtAMabFpnBfYjcJUSPNXdoPQ7hNf5BQyX3yaGwLT46lc8w4wCAz1zRx1OqYvSK3yeIIZvhBjhikadQUUxvgxbT6yBfvpj3rS6tpqFeCWm4G2EUzgIFg4bkkJSN6xgfz+7vC24wFJZbRv0Rw0tNO8m4MzYZ6tdcNg4pl9U1MPV/eWUgCAw2sdPa/5o4/HRirX7koK/mlNl8kRECMFzRooU243icgcJUDNWAQqfChYauKz2daIBzMeQn4Tqv1gZHBNszWr90o1bNEumXbBcO8o+cBOs9roa4Qf5XgV2x10dBbQrBQpsuJAKI70SDZr17aj+hzCSEvg3V2sXhY9BUpICZTSJ+78V/pmSF9h6UmKQUB3Ya+PUWjUV2DXFn/+7JopIbw/gC1E/eIwZImF6aqiCYSleYJH9Gz6p2N6AG2N0qHgtRQSExOv2Ajv9Kp1a6Zo8XDTF7+30EdXCvwJ2gt0zEHqUBxZhzrznNlxqPATAJAb6GH3Fv+/+XbEwbE3Ef7QYVhRCV6CaO7OMAWB8boMOCFsXaubtuonZR4AxVa1+a1e6DnpSUhfzh48I5PasDFEwdcTG7/IpV1uTzCRTgQqfBc4= 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)(39860400002)(366004)(376002)(346002)(6486002)(6916009)(36756003)(6496006)(2906002)(8676002)(66476007)(5660300002)(186003)(66556008)(66946007)(8936002)(86362001)(4326008)(54906003)(1076003)(16526019)(316002)(2616005)(38100700001)(956004)(6666004)(478600001)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?j03nujw7CRTKla2FN1JQ7I+Nzt8o00?= =?utf-8?q?+h1QIwOhn83PDAl6+504QXWngFIEYUIR+BzExXXQiBthtP2dNDIBa9gRuE7axrMLF?= =?utf-8?q?PF2s/50ccQyNzhkU9MqU6PlJTTybgHrM1w/NDEPGAKRqtuaR3XnKUr67GiHqh1pb9?= =?utf-8?q?0H+V1Y1SkqAy5yOH/e2UX7ZvTr0uYp/A/+Ksn2Llf3Zow87/v74YF5Mw6OJO3IJc7?= =?utf-8?q?rK/r5kvDgdNt5UF6w2BiUNrbRzFhflWPqockUlUnCC3/TWx9i1jafDLPznTG8gv3C?= =?utf-8?q?13QvfxH4nDIirinHkbzmfj574nTV/befhtpknnu6cJh5Q3u2BmuZGrP0F43uSzPk/?= =?utf-8?q?4bvlJbzXuh38BCSHmH7svgBXu5Lo6d0kK1Z8wM/lkve0XepQYlshP5YyyxQQzM81e?= =?utf-8?q?enBF48xuBPmnpIF/Y80HlrSdQjHfF6uFzbH0Kbgu4N/Jcky7OSIaG9OyFV321bf3g?= =?utf-8?q?v/UTSwciBbtjJys/X5f96mMDU2uB7FylvppLaO20sx+fsuo5AIPbhKqchb1KAEHbJ?= =?utf-8?q?Jm0WAs4Uqdg5HI8e+mVBG+LFjj4N3QWJ5XZp/+r0JndqPqM8/OoDa461YgWAi0XKH?= =?utf-8?q?FTmUL4YOyDbrSkNH74ZfOtdRO8Wrv9kJsYMQj1vt5+6KDzEqkyyfuUOOfAHgqSRlg?= =?utf-8?q?BtJ0hO8TjfR7YPztC/eINW9t46OiGxWmR2N5LZNHKfdL1PT7RY7EhPFtBK3vyY+il?= =?utf-8?q?eLaiaRkaedBlXnBNjVf+dwX6Lz9JjUsYuEjLdpPQkZcHb0rFkkQUf1v0zo9jtA9pZ?= =?utf-8?q?bplrXFnfhKPgawocrdKXbV2XLHOuYCr4SariC4Wa+KuG329akrmIxuR8mwT5S/8Pc?= =?utf-8?q?JDq+GO4s5brVY2aXd35snOAUtnp7jBusW4Quq/vH8NcR5R9pA0y2QyWHBjQLe05Mz?= =?utf-8?q?x/oF13xRVmUrJs9lTt4qYeJscMJCE5BUFdwB6LqMWtdXtL/gbQhG0UEbK+z7827V6?= =?utf-8?q?Hn8/Wnc0m1Q75C1NYDAad8WYvUCypkLsAyZCdQxAJjDLYlrhUlks2/0iUpNY7Jng/?= =?utf-8?q?+zRKxuhsRMNcZKO/hivIBunNHcyORQ0drmEzzdZAdxkYIdS/IEsbWk7GSNI0oc2dN?= =?utf-8?q?ZjziSYaxHg4JikdtmKemip6dkaCTL/poNguOtaAa1WQu/JIasiAORam30Em7M09c+?= =?utf-8?q?N5HrkzsK+n4U1fKo8qdzwq+uaub8IoFgmF6OI9c38eF40kSibq3RaD88CydVhcV7E?= =?utf-8?q?FUNmdAhvRzh72sp0bbD0lJ4rB78t5GaY7ZWKThjL7bpOO8ESpIsOP1twIUA46CD1j?= =?utf-8?q?9ighW+rqCNgV/e?= X-MS-Exchange-CrossTenant-Network-Message-Id: 945ca441-a6b2-46e2-17aa-08d8ede26131 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 09:59:42.3915 (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: AObCEWCVcAe0wKnJ1V30eRI7bt4rx9vgytfYHSzTIwNgZDp1cvtAewbyZQFPPhvbrLu83kv4yL7cquYowOmdPA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2633 X-OriginatorOrg: citrix.com Introduce an opaque type that is used to store the CPUID and MSRs policies of a domain. Such type uses the existing cpu_policy structure to store the data, but doesn't expose the type to the users of the xenguest library. Introduce an allocation (init) and freeing function (destroy) to manage the type. Note the type is not yet used anywhere. Signed-off-by: Roger Pau Monné --- tools/include/xenctrl.h | 6 ++++++ tools/libs/guest/xg_cpuid_x86.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index e91ff92b9b1..ffb3024bfeb 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2590,6 +2590,12 @@ int xc_psr_get_domain_data(xc_interface *xch, uint32_t domid, int xc_psr_get_hw_info(xc_interface *xch, uint32_t socket, xc_psr_feat_type type, xc_psr_hw_info *hw_info); +typedef struct cpu_policy *xc_cpu_policy_t; + +/* Create and free a xc_cpu_policy object. */ +xc_cpu_policy_t xc_cpu_policy_init(void); +void xc_cpu_policy_destroy(xc_cpu_policy_t policy); + 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 9846f81e1f1..ade5281c178 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -659,3 +659,31 @@ out: return rc; } + +xc_cpu_policy_t xc_cpu_policy_init(void) +{ + xc_cpu_policy_t policy = calloc(1, sizeof(*policy)); + + if ( !policy ) + return NULL; + + policy->cpuid = calloc(1, sizeof(*policy->cpuid)); + policy->msr = calloc(1, sizeof(*policy->msr)); + if ( !policy->cpuid || !policy->msr ) + { + xc_cpu_policy_destroy(policy); + return NULL; + } + + return policy; +} + +void xc_cpu_policy_destroy(xc_cpu_policy_t policy) +{ + if ( !policy ) + return; + + free(policy->cpuid); + free(policy->msr); + free(policy); +} From patchwork Tue Mar 23 09:58:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157333 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 3977BC433C1 for ; Tue, 23 Mar 2021 10:00: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 BA53E619B9 for ; Tue, 23 Mar 2021 10:00:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA53E619B9 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.100551.191638 (Exim 4.92) (envelope-from ) id 1lOdpP-0006hO-7m; Tue, 23 Mar 2021 09:59:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100551.191638; Tue, 23 Mar 2021 09:59:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdpP-0006hF-4D; Tue, 23 Mar 2021 09:59:59 +0000 Received: by outflank-mailman (input) for mailman id 100551; Tue, 23 Mar 2021 09:59:57 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdpM-0006c2-U1 for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 09:59:56 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7f4fea88-8a60-46fc-ac7d-1b6ba6b0cbd6; Tue, 23 Mar 2021 09:59: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: 7f4fea88-8a60-46fc-ac7d-1b6ba6b0cbd6 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493591; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=4ldnVDCZNMkxZxjsBX20L+XDZ7xhEL53HLTGBDuMf1k=; b=f5jEFTNI+SXMXovAZBuNbmLf/YsS5UcGeKb/jKshBjihlzy8VX7/+T83 GNQxY+xBmqOcQ1WPryn+b/pbNdePHyh8xm5TFPiE8QBY6jD0Qil4PedXZ uVY1PZf7KhghYOlYz2mnvc6+VTVg/xuoYY22zhbadSqDFrx1cjlsUOEye Y=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: aAoWUNYFj3lvfJBt0RGzZMLlCo+oHqM3AZczFG+Rp+nxn9QmGqugJFNoHO5bD9OvG/nQXNml8/ JN2UKRDxFeNv3KJpF880fqjrhn6XlSbV6sjiSFXIdcxXpyXE3q612ChQAdtGkMe1me6t2zuS0R uCtN+sU0KREphmk9xB14NUbePi7NU5ORGLNw3biR1Mve87jSTd4KDhaEvRhK77TB9Bpmwtd902 rSEE+RbiD5lKmXoLonAHgxTBqGrfAckwHG3bhqgzXS+UvKcO2Onj+3fPis6mb8hUaewNTyI/e6 hYI= X-SBRS: 5.2 X-MesageID: 40055398 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:P0QzEKmU6dbYfqmFYbTcnQg+ZHjpDfP+imdD5ilNYBxZY6Wkvu izgfUW0gL1gj4NWHcm3euNIrWEXGm0z/NIyKMaVI3DYCDNvmy0IIZ+qbbz2jGIIVybysdx94 dFN5J/Btr5EERgga/BijWQPt48zLC8n5yAqvzZyx5WIz1CT4FFw0NHBh2AEktwLTM2YKYRMJ aH/MJIq36BVB0sH6eGL0IIVeTCuNHH/aiOCXI7LiUq9RWUineQ4KP6eiLy4j4lTzhNzb0+mF K18TDR26PLiZCG4y6Z7UD/xdB8mNztytxMbfb89/Q9G3HXpSuDIKhkU72GljgprO+o80ZCqq ixnz4Qe/5dxlmUUmapoQb8+wSI6kdQ11bSjWW2rFGmgcvlSCk0A8BM7LgpDCfx2g4bk/xXlI dotljp0KZ/PFf7swnWo+XsbVVMkHG5pHIz+NRj9EB3YM8lR5J66bAE8Fg9KuZnIAvKrLoJPc NJF8/m6PNfYTqhHgrkl1gq+tCqU3gpdy32O3Qqi4iQ2zhSqnhz01EV8swZhmsB75IwUfB/lp z5Dpg= X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="40055398" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f3xj0QHynsjm1a4qlzCCGJSuBXIu8dxHZb2Nn4Py0kT1ecZnS5lHBDPJjn5fn8ZNkFiZfWUX1fEe3ngDypsituZ19gkc+j/e3W0BRyZbXmEqf3/jdhua74qYpR0gzooKpQqkUrZCRaHrOd1sl2AbYXp3+avYSr85w5MBXRboTUwITTnOcEkbail+Y0cYGYoedTcIH74eAtBteeDF8V5gg1c6Pr1jb/Y2G+xLIsqHurxzaX6aq4OsAhBKkx8Geb3aNGSbrLQtuudFeoApKlkvUb4mrNAH87SN1aKmmyGrDnR+cuMRkbGnKKNjYb6hRz4vGYZhgDv2cSVTVFbueFGccA== 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=GrIo5m2fuMUp8p1rJaMPBWTn479oDj4kTjXRWS9pdDA=; b=K4+Dd7MGjGQqKVXDjY99ipJfqA7nBTFbnFG07wptaqW4I2heKdB+OaWMA5MITdO/lX+OM5HtoKdeeL/s4ohyc25ETmolbsJpZHi+MS13sv34p1WLhr0fnFdORf+hFDEtsU2rBUNin/5FIVexIYbyz94tP5MGtpB2BRcGJzfewYEBckO6oLgyaGsMqebWffkBnshQiEeRktr+0SyhfzgNoHWloClGHFvRxcNCz4xEp1fzllxI29kTt7ForvsHeL3NN7eoc21JigDOyV4lW3etGoG0GQ6zfUiQA1n5DlzV2oBHueLdAM+o4sk60uVgo/R8cL5vHmGeuBVpUdWW+uvCPg== 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=GrIo5m2fuMUp8p1rJaMPBWTn479oDj4kTjXRWS9pdDA=; b=lPY0yt0Q+xkCpGOh2o4TRrbTLclcdnnyKjVc7tHuBpGUoYmEhYdpqW0IrFP4ORuTslVq+tpdSaY3J/f9gxhzt+f8JGlCAbn48k/7Z2WhyH7RAycfq7BCt81GfVKkh/TTIisBsu6aAOAG630ypCjvMgvOFtbJerdXfcvWDs9AYzM= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 04/21] libs/guest: introduce helper to fetch a system cpu policy Date: Tue, 23 Mar 2021 10:58:32 +0100 Message-ID: <20210323095849.37858-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0142.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:30::34) 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: 9271642f-2c8d-49cd-cf0c-08d8ede26566 X-MS-TrafficTypeDiagnostic: DM5PR03MB2633: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:127; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Wpun/9Czamem8RV4146BZzJCpvOWa5XqCrnXdW580T+QrK0Aw0aAcsen4SDIBIFluO6q5WnfDoqXyFDiJ9GoZZh0hlM33CD0+Cd+olV+C80KUeU+Jc+nBgDX8OUumAKP++oosgc0K6N3KcF2E9PEh6Z3liHnBOwDydmY1mKOwjfgbwtP4AoOTwR4vYevzmjWSnmRKlbGKO3+/y4xpOEIU2Iml8krY2Xs3PvUwNiCJ05ShuTfut8PAv0TrjhnVWrEJF92R+Jm5BWrOl4ZIid6VISlKLApEGWHI+8uMwA4TAyvGLn0tJToVJmleJsXEYh4Yy4YE6t4KBcJyIRidx+f4VxXgagLQx/el4YNoi69RtlpXufUDP2aUC7Cp0BYLeHa4U75hz3VO+nHrrH1qFQPWLs5mxK6uRt0I5rf6BaMshQYbCf9CjIJ3Cc9F2Vq9oqIXRxrH+vC+yWyGajY0XuixkpctTaOCE7HFCVKoKE2GWeWTCHDkFDecBxT0PiIzhiVAuWN8mLIiWHzxX795zOaDnoFgoROR2JGJ3V9RsQhhEJoEJkSDJyms6ShT/W/5A/Qs2DJPRkg1GF387ZcuVP9jgAhTiayAQOVY2ynU9bLaYDuRJ15UWN7EfMR1Jk+3+PNx3FlS1nfNCLT1VCTjqUrT6s8X2Zkrev3BT6cadmQgf8= 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)(39860400002)(366004)(376002)(346002)(6486002)(6916009)(36756003)(6496006)(2906002)(8676002)(66476007)(5660300002)(186003)(66556008)(66946007)(8936002)(86362001)(4326008)(54906003)(1076003)(16526019)(316002)(2616005)(38100700001)(956004)(6666004)(478600001)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?GFm+kBUpMwfzgVAfdAjAfoDLYBNXmj?= =?utf-8?q?diXoXYYd3X97dKIvRXMrxv3Pv+nz8CyDhL2ffJmDuAgtlaOy8UY4yxC4FDQH6+2Qg?= =?utf-8?q?ZaWgSbokhezv/aDfMJdAPDEdEaJ3gH8Qf1zLJWDGbR6iNxN6pHijYtlRXt4zgfG8X?= =?utf-8?q?aGv2H8pCl3rtOPY8DIFMJj2M4vBHgIaJ+kv51OOhnb/oGJioFh63b/VOgJ9AhSK8u?= =?utf-8?q?RJi0FU34WYyjdmYUUx9upqxgY1rOieIkEX+rH8j3SPJykhCT6076t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?= =?utf-8?q?c5U6nWe5l+7rh+YCrNFQCiJNWqzCEtbGpooC0mJU9oN0fb+xyfYQt5fi75AawDx09?= =?utf-8?q?wlb3AjKjPJQpT71qXZlcvJ69viO8YCeIhoXmE7FTv4I6MsGWfSoySxQSznH87YOLq?= =?utf-8?q?RlclJTieBis9v+?= X-MS-Exchange-CrossTenant-Network-Message-Id: 9271642f-2c8d-49cd-cf0c-08d8ede26566 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 09:59:49.3569 (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: g7h13i4YLjc0tvNUR5Nd1PVCJ5TFWX1RGMfxC1bl7mN9BwktRXPwtXSIy2TkhmVNm/hvAXg7QkEGwe/gvC9boA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2633 X-OriginatorOrg: citrix.com Such helper is based on the existing functions to fetch a CPUID and MSR policies, but uses the xc_cpu_policy_t type to return the data to the caller. Note some helper functions are introduced, those are split from xc_cpu_policy_get_system because they will be used by other functions also. No user of the interface introduced on the patch. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- tools/include/xenctrl.h | 4 ++ tools/libs/guest/xg_cpuid_x86.c | 90 +++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index ffb3024bfeb..fc8e4b28781 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2596,6 +2596,10 @@ typedef struct cpu_policy *xc_cpu_policy_t; xc_cpu_policy_t xc_cpu_policy_init(void); void xc_cpu_policy_destroy(xc_cpu_policy_t policy); +/* Retrieve a system policy, or get/set a domains policy. */ +int xc_cpu_policy_get_system(xc_interface *xch, unsigned int idx, + xc_cpu_policy_t policy); + 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 ade5281c178..3710fb63839 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -687,3 +687,93 @@ void xc_cpu_policy_destroy(xc_cpu_policy_t policy) free(policy->msr); free(policy); } + +static int allocate_buffers(xc_interface *xch, + unsigned int *nr_leaves, xen_cpuid_leaf_t **leaves, + unsigned int *nr_msrs, xen_msr_entry_t **msrs) +{ + int rc; + + *leaves = NULL; + *msrs = NULL; + + rc = xc_cpu_policy_get_size(xch, nr_leaves, nr_msrs); + if ( rc ) + { + PERROR("Failed to obtain policy info size"); + return -errno; + } + + *leaves = calloc(*nr_leaves, sizeof(**leaves)); + *msrs = calloc(*nr_msrs, sizeof(**msrs)); + if ( !*leaves || !*msrs ) + { + PERROR("Failed to allocate resources"); + free(*leaves); + free(*msrs); + return -ENOMEM; + } + + return 0; +} + +static int deserialize_policy(xc_interface *xch, xc_cpu_policy_t policy, + unsigned int nr_leaves, + const xen_cpuid_leaf_t *leaves, + unsigned int nr_msrs, const xen_msr_entry_t *msrs) +{ + uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1; + int rc; + + rc = x86_cpuid_copy_from_buffer(policy->cpuid, leaves, nr_leaves, + &err_leaf, &err_subleaf); + if ( rc ) + { + ERROR("Failed to deserialise CPUID (err leaf %#x, subleaf %#x) (%d = %s)", + err_leaf, err_subleaf, -rc, strerror(-rc)); + return rc; + } + + rc = x86_msr_copy_from_buffer(policy->msr, msrs, nr_msrs, &err_msr); + if ( rc ) + { + ERROR("Failed to deserialise MSR (err MSR %#x) (%d = %s)", + err_msr, -rc, strerror(-rc)); + return rc; + } + + return 0; +} + +int xc_cpu_policy_get_system(xc_interface *xch, unsigned int idx, + xc_cpu_policy_t policy) +{ + unsigned int nr_leaves, nr_msrs; + xen_cpuid_leaf_t *leaves = NULL; + xen_msr_entry_t *msrs = NULL; + int rc; + + rc = allocate_buffers(xch, &nr_leaves, &leaves, &nr_msrs, &msrs); + if ( rc ) + { + errno = -rc; + return -1; + } + + rc = xc_get_system_cpu_policy(xch, idx, &nr_leaves, leaves, &nr_msrs, msrs); + if ( rc ) + { + PERROR("Failed to obtain %u policy", idx); + rc = -1; + goto out; + } + + rc = deserialize_policy(xch, policy, nr_leaves, leaves, nr_msrs, msrs); + if ( rc ) + errno = -rc; + + out: + free(leaves); + free(msrs); + return rc; +} From patchwork Tue Mar 23 09:58:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157331 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 E401CC433DB for ; Tue, 23 Mar 2021 10:00:19 +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 9D6FC619AB for ; Tue, 23 Mar 2021 10:00:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D6FC619AB 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.100552.191650 (Exim 4.92) (envelope-from ) id 1lOdpR-0006ta-Nb; Tue, 23 Mar 2021 10:00:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100552.191650; Tue, 23 Mar 2021 10:00:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdpR-0006s8-Im; Tue, 23 Mar 2021 10:00:01 +0000 Received: by outflank-mailman (input) for mailman id 100552; Tue, 23 Mar 2021 10:00:00 +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 1lOdpQ-0006iw-10 for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:00:00 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5283454a-2c91-43a8-b4f5-40d42cda4fee; Tue, 23 Mar 2021 09:59:59 +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: 5283454a-2c91-43a8-b4f5-40d42cda4fee DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493599; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=sKTDxYJ3rj7iDKcoGoTCGrSKTjWKjCAlgiHohEHoEzI=; b=C7/phOo+BQQc99HiH15nG6eILjbcUvmWtgaV4PLtZ5KN4Uk0Yjjo9olg 7oNlvtC1pwY+uo6scR+ZbQConk6Pr+1+B6eEXEyFTp1TYIwhYazz0jY9p ROATDUSxr9c9Bck0FdRvfxRW7gkHOp/gyP7pe014DIKHsjUUf51uXzisp g=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: 05RJMFpPOZsEkpnGZ4UWBWfrkNvB7rlXZK1avQKDnL2LNL8pcGWvqp33TA0n0La6yYR3KoWAaR FXmCZ4XShXC2KxuTLZOm7tqVVeQkoYAWz3tOep4RcCACLwFSD8yD+7F5pZLHQyQQffOrMEH1B8 9NN+zWkRCbjsq9mVLs/qVMUvLlyXZ6V0atOK3Xm9Ieb0BOJmB6XdXxrucsUBGuJI5znnUBAK05 zFcBS+Fc28lcpgFdxHHCDYaf7G9DUTAdq5TH81Oatd1p3bTPCbNem5Rf7+Tc17m6SCH4BMHndZ HKw= X-SBRS: 5.2 X-MesageID: 40261142 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:8NXDdaxVIRa8umfn2WASKrPxqe4kLtp033Aq2lEZdDV8Sebdv9 yynfgdyB//gCsQXnZlotybJKycWxrnmqJdybI6eZOvRhPvtmftFoFt6oP+3ybtcheTysd07o 0lSaR3DbTLYGRSpdrm4QW+DtYryMSG9qftvuvF03JxV2hRCp1IxS0RMHf+LmRdQg5aCZ0lUK eG7s1cqDa6PVgRZMK3Bn4KNtKz2+HjvpTgfBIAGlob+BCD5AnYlYLSPjq5+lMlUz1Jyao/6m StqWLEz4iqrv3T8G6760b99JJT8eGRqOdrJMvJscQNLyWptwDAXvUbZ5SnnBQY5N6i80wrlt 6kmWZRA+1W52nKdm+45TvBsjOQqQoG0HPpxV+GjXaLm6WQL1hbeqkx975xSRfX51Etu9txys twrhiknqFaEA/am2DF78XIPisa53acm2YokuIYkhVkIOwjQYJWxL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8VC9kG9KHmzbft0T7WEA6wZql Jf78uTl+GaMwr+1wa4h0o3Hot+t0KmS9i1GgSCBKph9MG7I02Fhu+S2/GI5Q2HAAeTWgA/no 1KdUsZc8RFhH0DteQMo1ePY52yhFkknVtY6SxgjXj31OGdkT7mIX0= X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="40261142" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ikA4WW9FVNw8sQq9FVBmUh2iYFw9X8pd5utQylRER89bmHB7IM1Q73QOfIgqgOrueBwlcy9rzxVuD0GiL+stTP01zHWwzTF2jNK3aPabZQ0wteb+TtTEYT5OabZa8gZ6v1wNuaRJvLxsLUKZL8cDBB5EbDeKulc5EmIiREUfUzbCGt+lul3LnlNaZALQr1SNMCsWPbL0RDEZZmbPhtLp/bhVo4dadAplTCuVomw6Ad45ORump55z7kpFiXWnVcCLtj6tYGXuoIw8kVmnhM0Q2+4RwmJHSHh9ff6Z+l6cmDBuNsrqF3lad9d+8c55W44KXivR6hDs8LiE8Hm4x5W+Gg== 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=XiniRgb9Usi7cOKyAntrG74P2w6ZoVZ1eSYmJ4efxZU=; b=PdEDnW8tL8CSRxxAukw/wrUPNe7sjHUYj8wARYpMVvtWW+fbfYvG6UkFcGlaHkXqTJ/4ymSusy1va8xxRrBTDjB49GYP1vPZrTPiKR9ldSjKF2nKvtczaDOtNdlBVb2ZGvtIl8K9PcFXSLQwyYCYheNjjNnfP/h3Unlil+JpSDJV1UxjYxfYF0WrZb4nCLzpZilyyoLv++YsMCeiKDzGFSPO27wIgORZ8vBACikK13WQxag7Q0AaPZNajo3RwBkbcs9XqEDRXNaucHvybVz55lj0Yqw/2FWd6C/QMP8c08FZkqsLiPKNg5ARoCORgIcpPf3f95EhZcvBlrW4E3wnKQ== 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=XiniRgb9Usi7cOKyAntrG74P2w6ZoVZ1eSYmJ4efxZU=; b=RBOajU+Tjs0IsUqY2oJPzIPeEOy8aOQqNpcQXvkBUyrHpeO2jWy2zJdNTB4PSP64At1fJgyXMaqV+AcH6elYkXUvyF5kayK3vBe8XzqbtQWSThe3ctK+iQN3vulb0j8hEq9QWu+uKdHIy//VGyipWaOWpCM3BKQ39QPpu5ttsXw= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 05/21] libs/guest: introduce helper to fetch a domain cpu policy Date: Tue, 23 Mar 2021 10:58:33 +0100 Message-ID: <20210323095849.37858-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0124.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:30::16) 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: 31fd0c1b-e2e9-4a97-4847-08d8ede26874 X-MS-TrafficTypeDiagnostic: DM5PR03MB2633: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:529; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K8GrBI1odyLIpbb0bCGG8EdkjagxIrpA1WBzJiz7XN3Y9RIFGI6HhdgnuLFtCwtvZbXzGdyvcMhvWIK1J0AdZot3HVidqqsCG5ME0sek4NAVVEibR2Sxx8KKZV619TIhr68uG7yxRhCT1DN7GnXgxWr5Tau3cxY+ZeTLWI3HsvPi6BeuL8HpcOXo+xPfskJAFfycoSyV0tQXbCjyO0GRJlT3N3YUoFs7OsjH+cWJFBBDbXDN+VdY675tiwLgAgIw8Q7ZIRLU50Tjd0EGgYUH7XaoVW+Z/wNH5bN6CjX8+gTNN88ALyxCmBFwfp9e5q6OnZue9GzVgzNKyiXMkdKaoaywv1TqkQvt/r8Yuu5xcrNXmNzkZcXl+vrR43ych4baXTD4afXsdaN4X1zunFTi4qNIkaMnyK7+0nGS/siWAeZO9goo8MFkWkJcNXo+4HR8iYCUfdtTexl8DL7DjQRH8vZ2s039m3nICcI15P93fQRyHYOWjYCVhJhah+BNcNE+058+/lD/l9jNZSw1nVphDfQx80QJ85MDIfG9SkQl+2f3M4Xcu4YZQvHeAlQMV8P/s6Ulie2lJlzFwUGyUfiBg0EjCqZ+Lsqb8mDVmpwhfNClRoykxZORAUg7vVGNPq+9wu8ercLsys/nYK1fx4Z6y0RSYdvo2jJ4bzsxfmZImv4= 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)(39860400002)(366004)(376002)(346002)(6486002)(6916009)(36756003)(6496006)(2906002)(8676002)(66476007)(5660300002)(186003)(66556008)(66946007)(8936002)(86362001)(4326008)(54906003)(1076003)(16526019)(316002)(2616005)(38100700001)(956004)(6666004)(478600001)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?zl1vtnp4DXEJauVvYjiOv950O23VfY?= =?utf-8?q?K0mcT1BJycsdySfnCuX/CVcdJMWwo9R4xcA89Cnii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NNNQqOLpCqb8VtpDNJlAV4/SX2I2kINHXlW7iCIph6d3?= =?utf-8?q?hOyccRuKp9uBzmTUzSqAGxVhs61FeCJIeSdr20nej0TlEYjQSREzuLoM2koKLdM9r?= =?utf-8?q?isuWcot8U66/hRkWui/XC2vXLGF67Hppc8d9sBgC25OxdsGwQAf7OwX7yoTW10ncc?= =?utf-8?q?XpCtHuLr0+WMvWz1ORujc1Ladiv2LVfWIMlK6uB7M0u8mVxWjJXIVSHQvYD3YQ0EV?= =?utf-8?q?k6Fpa40kF/cicg/QjIR+7WtPSvRisRAeMM5lnDGzsInoR80OyBhppy7KD82vwPkzf?= =?utf-8?q?Dnxjh8ZrP3R+AEiW2EII0RARUe+LVwY3Yes1nf4RjEb5oJ1WqahHoNHmjGVq+j5kV?= =?utf-8?q?7CWC+6tWqTqMSr?= X-MS-Exchange-CrossTenant-Network-Message-Id: 31fd0c1b-e2e9-4a97-4847-08d8ede26874 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 09:59:54.5848 (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: o3flLIZS9a+/qHR8u2FBopZvPkjJX6OnSDjyqkq9bjb7eU3e5ND+EhFilGQkNXBbcCutF68/ItZ/Er5X4aWPTw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2633 X-OriginatorOrg: citrix.com Such helper is based on the existing functions to fetch a CPUID and MSR policies, but uses the xc_cpu_policy_t type to return the data to the caller. No user of the interface introduced on the patch. Signed-off-by: Roger Pau Monné Reviewed-by: Jan Beulich --- tools/include/xenctrl.h | 2 ++ tools/libs/guest/xg_cpuid_x86.c | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index fc8e4b28781..8b8b30a2764 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2599,6 +2599,8 @@ void xc_cpu_policy_destroy(xc_cpu_policy_t policy); /* Retrieve a system policy, or get/set a domains policy. */ int xc_cpu_policy_get_system(xc_interface *xch, unsigned int idx, xc_cpu_policy_t policy); +int xc_cpu_policy_get_domain(xc_interface *xch, uint32_t domid, + xc_cpu_policy_t policy); 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 3710fb63839..75ac70996ac 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -777,3 +777,37 @@ int xc_cpu_policy_get_system(xc_interface *xch, unsigned int idx, free(msrs); return rc; } + +int xc_cpu_policy_get_domain(xc_interface *xch, uint32_t domid, + xc_cpu_policy_t policy) +{ + unsigned int nr_leaves, nr_msrs; + xen_cpuid_leaf_t *leaves = NULL; + xen_msr_entry_t *msrs = NULL; + int rc; + + rc = allocate_buffers(xch, &nr_leaves, &leaves, &nr_msrs, &msrs); + if ( rc ) + { + errno = -rc; + return -1; + } + + rc = xc_get_domain_cpu_policy(xch, domid, &nr_leaves, leaves, &nr_msrs, + msrs); + if ( rc ) + { + PERROR("Failed to obtain domain %u policy", domid); + rc = -1; + goto out; + } + + rc = deserialize_policy(xch, policy, nr_leaves, leaves, nr_msrs, msrs); + if ( rc ) + errno = -rc; + + out: + free(leaves); + free(msrs); + return rc; +} From patchwork Tue Mar 23 09:58:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157337 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 A07DFC433DB for ; Tue, 23 Mar 2021 10:00:42 +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 51BEF619B9 for ; Tue, 23 Mar 2021 10:00:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 51BEF619B9 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.100558.191674 (Exim 4.92) (envelope-from ) id 1lOdpn-0007nF-D8; Tue, 23 Mar 2021 10:00:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100558.191674; Tue, 23 Mar 2021 10:00:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdpn-0007n7-8w; Tue, 23 Mar 2021 10:00:23 +0000 Received: by outflank-mailman (input) for mailman id 100558; Tue, 23 Mar 2021 10:00:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdpl-0006c2-Ue for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:00:21 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 32db4eeb-74d3-4558-b643-b0ec1e9c8a9f; Tue, 23 Mar 2021 10:00:06 +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: 32db4eeb-74d3-4558-b643-b0ec1e9c8a9f DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493606; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=US6kAIf+2labk2oCST9gZ6uChRGzP0iC69NC7ePJygg=; b=BJErWs9/beJOB+kvaEcC/6x8Dq+z+Dk1KS5f7KilDEOsZtzYkyOw838Y EXfLA3b9efDoUdTJXxN5YoB+7aXrPKjT0+d0iQYEMwlskIVzMHpcXNRGz ukK40NVaOS3WDp+jGsrF1z/YDJgKz46cwNwF2R/Yjgsx67v2u/9r1oVg2 E=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: GVSMCNCdokr7gSpcFW22ITltZD8ODexzTt+VH+cZHrxf4xTk98NRvEB5x25qrcf/nKuvJg0+r3 DWi+bbARwa00W0oIY9khdGpDycK7xOyrPEOnS9gTeChH3NwDxSu0QiIothywpu6vz7AHuPCGGF dEuaj5zkNV0K2VBBI5IfKYlDGLLwZzc1rfBzZ2Qg/qdkpAk0XJlgsX8AxGKnjzwjg4Xde4jjjG K/Jf1OFZtdbAy8Otb5xIpMEDlSRuY7sIUtXPSTNFMwms2Hhr8AEfcelDbnYtNkPraSHou5HS5K 3Ig= X-SBRS: 5.2 X-MesageID: 39900265 X-Ironport-Server: esa2.hc3370-68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0DPuaX8RgiA2rSPQk0k73hAG5n4UTYVc1GxSpStWahA4yQSE8vC wKz4YvxICvt3KDC0saxN45PlpNb2r/OsMeMC21IL97tPTOV2hLPCG3rA3fsT8cPlHHzXk2uw XaXGqpUMCOOHRy/kx9+oLR0H4cTBTYQ2tALk1f9aVGUUrtnFFduNX7Ppab23eNa1cE3+EWOC zEZzxXOQ9129Wrzneu6Uq/PHE9xowZO+TXALE4Goujp0+FOcmGk7oLEORT+4sgPNfysvUTWe baYAONKijkYtlZkjC9tzIgOCNurmMjnu6t0Br57HKg1HpXO4ukHH12A7UaKcqb9W7qWrKB14 h4l8s8ua+1Pn/qYtCLjaHRYDgrEGKknUemC+Upo4tTp6Q8qf96GITaSyLB0DVfxwolRf2E5n 82UeB++vTMK4Vvd8sdd2ZQ+Ucojs2GKA8uvhbtCuEzcFkxhxbgTpu0yquNraBqDlyKpQP2N1 Xa6SFb8vvfVyaI1LIRCcsLUBBrQVl57G4n8PKJdoXWBgnvavpK+0CiNGShNLBaU6qIFNwr32 VHysDNm/XScSX22Ard52QmZq1P9nuqWsO0DkaHH/VS/9mzJFSLhe+r7aeI/UbKYCr+b15dg4 tPMVEUZIBEjDIpiYUsyCi8SqDtuCse4i5jyCAikkSow5Ss5WfQAFpPPgLYiIhHRDU7CAn3se 3VteyDkGnn6DdL2ZPfBF5dc9FHFd8XVJX2JU5VWLgtla/t+bEujCRFaAovCGB5iCmV5ZIY4Y uE X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="39900265" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gXJ1iYuw4/bok+tKQ7fDpj75KpBnWo4cbSXSA/uzhFay4Clfuk6Yy+Xaga1sfOfENCEcLJm1fCuSMwXNf9RzMWr+6zlgesRerDbRR7AlWJ0dosMdKX6xJwLfvvxSGDbIx5FbsobMiOfkFSOpVE5+Ggd/Y+IwOK2Pf8rQhwtKW25nP7YDfwu4f9L89rYd7u8bChBwjwRryxZTlZlvKboUV+G/Vmwix/h5zlugyOHLvWJkEFhyyATFFD3lO53FqahAeCBsEhIeygeb0hVckq/uxH1HfYSoSOYI5Zn3PCNlLGrX2n7E5F5rp8gNuYA2EYiy9p5jR2iP4DCS7KvdfKe0nA== 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=x96POU3Rped/M3iZclAcVyiA8U+JKnNokSoJ4Bo8H4w=; b=QxxxS9mldxbpf9U1yhZOnwLE6bEk3bWXn9cIUhc8mvrYLFrT+ZrOJzK9HX8twmgpLPPa2/moPgsPrnQBAuzmWHFJ2iqSkwqrvAf/X2Wg2y9XC++4DAl2bMDK/2vwpXNc9UekJMPDsFasX2mvNqilVRWxf48Lgoed2CdAlgM3KkrHChhQ9QVMCMSxNnw9f6NQQD/cL8jl4j347Im5IeE0oHZtGL8s/YaF41sAJ9qOf3cLSHqsZ2DQ5+QVgNefTwbANlswGdOx4w4Fweny/pYgUwedZ8USyEQe3XNmusygdOM5Cj0eUYKK60r04cS9njej5hbM2Amy7P1jkdUlU0vq2g== 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=x96POU3Rped/M3iZclAcVyiA8U+JKnNokSoJ4Bo8H4w=; b=Gjt71eSLm2Rh1h7PKyIkj3J3bWVSc+qJcvBFSa4wkS7cPVWzSkDjt5eWNAbV4ImxEsAwG7kFoOTFqCYBIf2B9qpSQBqgVmZiw4iimiYn6EWfv4Mqow9+gklK8U/jRNIcRhfT2WnGOPz+6gULCswHaGX1RSacjj+jN8oXMsg3ZZo= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 06/21] libs/guest: introduce helper to serialize a cpu policy Date: Tue, 23 Mar 2021 10:58:34 +0100 Message-ID: <20210323095849.37858-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0151.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:1::14) 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: 5d183e04-e412-4789-dd82-08d8ede26cd2 X-MS-TrafficTypeDiagnostic: DM5PR03MB2633: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9ElZibxGi0gY3rzpH2bdPuQKaMOd+JXXqyFRdbKV7brYJ/SP4ra9BnmIvvUHdrF61HfMvXJFFuieeqF4rOd+QAvzZkjPczBQrz1iwYdhTAW7RYsS08MjsYx0sHh9PfdEDJwF0R+0FRBruWhtKZTeLG38BAvApYKpVGwSWSbFU93VRYJYhyQocu5uFLI1/N91VU6CnRWJozdAaVCEazP+7PBZYuRKNFI5G0gCzsaH74ykwuRwd+QKrbJ5e/gU6dG7jT7cja7Et6vnpdmGp4bh1/pSpL0FNUeJoMqqs16P7/NsD5nEO63xjG7L31VMj54dEHucaxacq9UGQ5suhpm+ORCVqrU8JnczpGPYon+kQBaK2Y0VIWPDFaOQd6/k45sSc/yVl0hEuCIvJtwasKE9n0p2qEzTp4E5iA2O9qhAkCp9YXchFdmzEXN5dE7K1HPxG+SZSJjxL+lEVOzyPSduzxZWKBUEwAxvDNTSQUmuFgXPPjsGsBuvKasU/V2nsDyI0hx3CIQonHuoFiK0Se+ZdEB8cLXgMlRmTifGv4gE9n7ncwHC4ubCCH6Duvz3yAt2G4bvyKefM8KBl8zfKo2t0fWCG3HaOwYBe0UVIebdnGAUOKkzhv+yuNir8YAKeFNoS2yUQCogIZE29bFHVmZldR7da2TjuoCI/qWUwxa1PHQ= 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)(39860400002)(366004)(376002)(346002)(6486002)(6916009)(36756003)(6496006)(2906002)(8676002)(66476007)(5660300002)(186003)(66556008)(66946007)(8936002)(86362001)(4326008)(54906003)(83380400001)(1076003)(16526019)(316002)(2616005)(38100700001)(956004)(6666004)(478600001)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?VgJa7aujtqNwgKxz6oomgNCAXnJRk7?= =?utf-8?q?nEWtL5gWF5tSzc7d37YI7ySxB2vmBp3lSdfLdNs2iaUdpaH0OaDqcGbBsu6gnZ3Wm?= =?utf-8?q?1EexyEGqltP0tRT/dd7AlK04uHBLmxK+0JIf7XIHC/uTk9owm3QSqcy5APJnxCI30?= =?utf-8?q?NwDnlCqqRasK8Rl/1ysSyP55QCo4prCw7CJxOgMwEJ7JcgC5ZYPKxAX4Rt9EVxZFW?= =?utf-8?q?1p3xB4pyiegdPAqXn85G0AXsfIkHWvjm4QtQ/1Z0Dnm/kyHwjFWeOKysZI6K68B0Z?= =?utf-8?q?AMfAs2hTcC4b5c2BUcFjBrBEbgnntaK3mHKvfOeWF21QM9unYV3wRmWfd+l7xLhpW?= =?utf-8?q?NN7YFDOCZxwCPg2QNKX4Ex7OjXuuPL/ljxCCJFEd72FnLbPXet76Uov2i/Kv4Mnri?= =?utf-8?q?t8+xrqY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utf-8?q?hPSI/btMhD/h6t?= X-MS-Exchange-CrossTenant-Network-Message-Id: 5d183e04-e412-4789-dd82-08d8ede26cd2 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:00:01.9076 (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: lN9TRHtbaV08ZQ+u5C0zWpFawoQxB9E4CeaGr5Xfe66nK8L5KK7/2FySigun1/LIdJ8AU7aq/qvEhP2d87nL9Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2633 X-OriginatorOrg: citrix.com Such helper allow converting a cpu policy into an array of xen_cpuid_leaf_t and xen_msr_entry_t elements, which matches the current interface of the CPUID/MSR functions. This is required in order for the user to be able to parse the CPUID/MSR data. No user of the interface introduced in this patch. Signed-off-by: Roger Pau Monné --- tools/include/xenctrl.h | 5 +++++ tools/libs/guest/xg_cpuid_x86.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 8b8b30a2764..983bb027a04 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2602,6 +2602,11 @@ int xc_cpu_policy_get_system(xc_interface *xch, unsigned int idx, int xc_cpu_policy_get_domain(xc_interface *xch, uint32_t domid, xc_cpu_policy_t policy); +/* Manipulate a policy via architectural representations. */ +int xc_cpu_policy_serialise(xc_interface *xch, const xc_cpu_policy_t policy, + xen_cpuid_leaf_t *leaves, uint32_t *nr_leaves, + xen_msr_entry_t *msrs, uint32_t *nr_msrs); + 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 75ac70996ac..812ef14fbcd 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -811,3 +811,35 @@ int xc_cpu_policy_get_domain(xc_interface *xch, uint32_t domid, free(msrs); return rc; } + +int xc_cpu_policy_serialise(xc_interface *xch, const xc_cpu_policy_t p, + xen_cpuid_leaf_t *leaves, uint32_t *nr_leaves, + xen_msr_entry_t *msrs, uint32_t *nr_msrs) +{ + int rc; + + if ( leaves ) + { + rc = x86_cpuid_copy_to_buffer(p->cpuid, leaves, nr_leaves); + if ( rc ) + { + ERROR("Failed to serialize CPUID policy"); + errno = -rc; + return -1; + } + } + + if ( msrs ) + { + rc = x86_msr_copy_to_buffer(p->msr, msrs, nr_msrs); + if ( rc ) + { + ERROR("Failed to serialize MSR policy"); + errno = -rc; + return -1; + } + } + + errno = 0; + return 0; +} From patchwork Tue Mar 23 09:58:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157369 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 2D563C433E0 for ; Tue, 23 Mar 2021 10:08:12 +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 D42E7619BB for ; Tue, 23 Mar 2021 10:08:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D42E7619BB 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.100603.191850 (Exim 4.92) (envelope-from ) id 1lOdxB-00019I-6j; Tue, 23 Mar 2021 10:08:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100603.191850; Tue, 23 Mar 2021 10:08:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdxA-00018z-SY; Tue, 23 Mar 2021 10:08:00 +0000 Received: by outflank-mailman (input) for mailman id 100603; Tue, 23 Mar 2021 10:07:59 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdqA-0006c2-VI for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:00:47 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 78e0421b-df95-4e63-96f9-dcac87299447; Tue, 23 Mar 2021 10:00:22 +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: 78e0421b-df95-4e63-96f9-dcac87299447 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493621; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=/SoEDPLw6OxZ/qntLzfu2J9mHJByb6j4475FehVwXTs=; b=FO68J3vGdBIIWHC8k+PPS44Z4N5yi3HDicoPWA+SZr/P03afMmWf29En gX3yD3qUvtO0ujU/Qtc5mK4oZhkDqoC0tntEosg0TnSr5vFdqMaLnwu/L EMLNxKU8V5qI9/mC8b5ZaEG49zx22KMFFPFcMugLeCh7yQgoEMAIpzC81 w=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: znpTRrcwkN3GyJeu2IbTnAlnmzqQVx91BMnditoywYrMNVxTgHxjf/stJf0SzxMA83BzJa6GFl MrSolfFM7bPnfT89b16p3MN4VND/bo2OF0VYWttYjsg3Wh6D7HMc1VpfxTR/tEZJVP4qW0TKqi RQaNWew3hv+gIk6F36QaBtvsIvaC1OaYMPn02IXSQfPbJqu0zPZU0Rf+hHYhExwCY4S3zxc1MY RX1q8xk7IxwR7JMvdldSqbctdsCzGYuG0oey4l3PLH/x9XRYh/WlSs85XhGL37GEAFUta60Ijo 85Y= X-SBRS: 5.2 X-MesageID: 39779569 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:gdbciqlGkYzyQci6dTuz8InH9L/pDfPKj2dD5ilNYBxZY6Wkvu iUtrAyyQL0hDENWHsphNCHP+26TWnB8INuiLN+AZ6LZyOjnGezNolt4c/ZwzPmEzDj7eI178 hdWoBEIpnLAVB+5PyX3CCRD8sgzN6b8KqhmOfZyDNXQRt3brx7hj0YNi+wOCRNNW57LLA+E4 eR4dcCmiGpfm4ZYt/+Kn4OWeXCoNOjruOaXTctARk75A6SyQ658bKSKWnj4j4ycRNqhY0j/2 /MjhDj6syY0s2T5xfA2wbonu1rsfT7zN8rPr3otuEwChHBzjmlf55gXbrqhkFFnMiK5EwxmN fB5zcMVv4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MoFpedYOeygxxCtcqP2/aG8isgn7GYYFDCoQpk6eG9OC+LzTr7UzRmWHuQvrIF GamhcttMvtbm+m1bQADbg3LnkTQE8g6G569OfHU4HLEg2le6Vi+1W9W0XNOoN1eeygGb8KqA x97MzNt+iLdzDg0ASVhABFGMt1ghCaaPL3JhmNF+5O+8G7PlrJopLC2r/OsB7HDR2ha0oZgo VZc1c3dcorsEhlsLEK X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="39779569" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GnEIJv55ftMJjvHDkYirmUykjyBXVTIy83GbsXW3ADDA4QElKrqoD1/BO0Ln2xPpvuRndC39HoE4LxgOVKBy6scus4Wxp88yAtX6p04NVi9Mf1HcdP6OKkCZOiPQSt2uqJrbKgnXML3HBnmFpcLP/dEpC/Eq/sX3LJuJ0wz6c0qmF3wAKGJMTY235UolnA7FLR9MWCmTz2flyPwTw52ypL8ITmWl+zLyF5LQp0MXeWPdBOLRj1cOf1S+YGvJax0aDpqLQJKBiZjiez0jwfAAWd11TEzUp9PQw4lES7yhCza6VJk3Nra5lUxHUFm/0cmEbVXbFyyh+30HIfhjuNo8WQ== 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=hPrkBWw3F27B97CCbixdNkftOso/WmqluwfllC0ExZQ=; b=bDNf/fvkqETQgCgdpR2CpVdx0lTt4TRnkoWb+rVre02MEpfkSwV7u0ApeA0Wqcz0O9MRs3nSLfYLP3d9oSwGC9j3ZInmqGVrLG3mO4eZM+TLkDEm5Ncx/Gz6Ka58u3f4Ftt9sYfHNid9rPS0Lvr205zvnQX12W1oyr/xzrXPxmoGDBJl2bGH4UGhhtcX3Oa8JIx48QEj3e+mjGWPb17++a7TA4EInnSLRHcJ6Eay/vZvMtHp1TCuSwbUp/qikIyJB6/JtsuPj/Y5m5q9iXRfFFeRYE3N8p8NiOvGiwVKMdY4LK3owmpNzes5xbf9Pcvupc1Xxnj8g451uTHweSYFfw== 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=hPrkBWw3F27B97CCbixdNkftOso/WmqluwfllC0ExZQ=; b=AE3jEwtbQ9LymVeSmG6gOHVVQC1bkBWyM+LdjlbAopi4wpPTbqieWv4gU5BrRxU51/dRAIpGFWgxMrcugzv0frPgiv31L6W7fpSUTpNNDUsVoCziW3fTkT7VQ/RAHQt9sYoFmulOpBaeP3OzmwfU+HoyUzhnPpu/LJBYd62+QAQ= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu , Jan Beulich Subject: [PATCH 07/21] tools: switch existing users of xc_get_{system,domain}_cpu_policy Date: Tue, 23 Mar 2021 10:58:35 +0100 Message-ID: <20210323095849.37858-8-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0155.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:1::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: 261d4e70-d194-4247-a751-08d8ede27719 X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:76; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C/W/Imvlo7O+hFU6uoGyjd+K5zuMSmYHenMQQW0YUr887rcVjFYnvEy12oNYbmp5N7uwdJkamIBsRc0j9Q9/083gE8uIS48paHJxGDPcY6Weuz0/o5EkAiaDlpVRLuvT5uDrjd1xnYy9P21XaznFoou4p+WlrkjI/WuHVFSoYgQziY5wk4skXAQZ0lDM2fBQsMi/ajs4E0b2cyKq2uJc8eU9JolKJBM2pdGYyz2ZzL3xQ7quJqUGrdFbjQT9lHDyeaxxRpbU8JrAtKaianREkNN42a8XJyq12mh5PqB+iOPq1PTiZBbqsqa9ZHIcje/UurVSLGwWIZQp59hpDw5AWfFzojOGYo6v5Um6I17ES0CQVjPIZul2uhnoaKzXrpbu8dQKTx5v0mrUWTmLgUJQmarCMc3Ji82k4yoWbYNvKWhDNbTFbA4gRI52X4KS5TBuuB9tN3jHNVGW38RGvgg3mCW0hjDHmpGj3+PnC90R3p1Z0iJlLAl/aFDYj3Nyovy4DQEOgytUqg9hEdFMGUuICl/skysS+qb+xyInz9FDgj5M6Pw13BLxM49KBrK0f9Q0Iz28IWIkt9XXyaI4BaZLw7rwhqqshyJ2rW+RaS/PPZhhN/23NtkVbwhzfGJ4IurJLJ8FZG4wbvGpM7xBnaiSDkH/HfGlOL7mhmQ9IwQuSpc= 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(83380400001)(6666004)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-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d36nFjDRb98+gvGsB2X3EIi5bOQGoezjJ?= =?utf-8?q?7Ye4RdJrqI1vjSsCfoP9T6jQg6OjfseL48K3RH4296PjR/lSzc2YdaLICbGtHSSZG?= =?utf-8?q?eGXthtUGwzOWtlkGl2eNZ1cQ7SMm9063diCHbVCZ/YYyNitOMt9cOUAQQ1BeChWYI?= =?utf-8?q?QpGrqV53S0UKoNEagOFDML4RHTv3XZEqrhACRznaKTVWczLR6yL2bS3Ouyo8oPled?= =?utf-8?q?lGHHNlTCzydqh7Muw2BM/MIfFfYCsu5VYrvJypkzm9xIbdv6m5d2YuuKyZWy724c7?= =?utf-8?q?ocd6elivKm/pbtxS+uuwKMfswwJ8N/4Dsi8fa6x77REOQTwOD+rtA+cxATCqF4bNI?= =?utf-8?q?PQlFuI/vCIzIR9q2k2XhL65rSyGY/f787fc6iq0NfT+RwddS4f7CCT+Tubt0YAUPs?= =?utf-8?q?uYMzgf3/+ktgCr?= X-MS-Exchange-CrossTenant-Network-Message-Id: 261d4e70-d194-4247-a751-08d8ede27719 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:00:19.0711 (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: SyOdeCe2URk9KUb2+1G5lIpo1UITYeKOiLysyekLfFHjxA6lFrsnTMn9nLss6hO8szI8s+ah3mRaIFcIZAih0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 X-OriginatorOrg: citrix.com With the introduction of xc_cpu_policy_get_{system,domain} and xc_cpu_policy_serialise the current users of xc_get_{system,domain}_cpu_policy can be switched to the new interface. Note that xc_get_{system,domain}_cpu_policy is removed from the public interface and the functions are made static, since there are still internal consumers in xg_cpuid_x86.c Signed-off-by: Roger Pau Monné --- tools/include/xenctrl.h | 6 ----- tools/libs/guest/xg_cpuid_x86.c | 36 ++++++++++++++--------------- tools/libs/guest/xg_sr_common_x86.c | 15 +++++++++--- tools/misc/xen-cpuid.c | 21 +++++++++++------ 4 files changed, 44 insertions(+), 34 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 983bb027a04..161dafd234b 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2613,12 +2613,6 @@ int xc_get_cpu_featureset(xc_interface *xch, uint32_t index, int xc_cpu_policy_get_size(xc_interface *xch, uint32_t *nr_leaves, uint32_t *nr_msrs); -int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index, - uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves, - uint32_t *nr_msrs, xen_msr_entry_t *msrs); -int xc_get_domain_cpu_policy(xc_interface *xch, uint32_t domid, - uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves, - uint32_t *nr_msrs, xen_msr_entry_t *msrs); int xc_set_domain_cpu_policy(xc_interface *xch, uint32_t domid, uint32_t nr_leaves, xen_cpuid_leaf_t *leaves, uint32_t nr_msrs, xen_msr_entry_t *msrs, diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c index 812ef14fbcd..a8133d5cd3f 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -128,9 +128,9 @@ int xc_cpu_policy_get_size(xc_interface *xch, uint32_t *nr_leaves, return ret; } -int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index, - uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves, - uint32_t *nr_msrs, xen_msr_entry_t *msrs) +static int get_system_cpu_policy(xc_interface *xch, uint32_t index, + uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves, + uint32_t *nr_msrs, xen_msr_entry_t *msrs) { struct xen_sysctl sysctl = {}; DECLARE_HYPERCALL_BOUNCE(leaves, @@ -166,9 +166,9 @@ int xc_get_system_cpu_policy(xc_interface *xch, uint32_t index, return ret; } -int xc_get_domain_cpu_policy(xc_interface *xch, uint32_t domid, - uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves, - uint32_t *nr_msrs, xen_msr_entry_t *msrs) +static int get_domain_cpu_policy(xc_interface *xch, uint32_t domid, + uint32_t *nr_leaves, xen_cpuid_leaf_t *leaves, + uint32_t *nr_msrs, xen_msr_entry_t *msrs) { DECLARE_DOMCTL; DECLARE_HYPERCALL_BOUNCE(leaves, @@ -322,7 +322,7 @@ static int xc_cpuid_xend_policy( /* Get the domain's current policy. */ nr_msrs = 0; nr_cur = nr_leaves; - rc = xc_get_domain_cpu_policy(xch, domid, &nr_cur, cur, &nr_msrs, NULL); + rc = get_domain_cpu_policy(xch, domid, &nr_cur, cur, &nr_msrs, NULL); if ( rc ) { PERROR("Failed to obtain d%d current policy", domid); @@ -333,9 +333,9 @@ static int xc_cpuid_xend_policy( /* Get the domain's max policy. */ nr_msrs = 0; nr_max = nr_leaves; - rc = xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_max - : XEN_SYSCTL_cpu_policy_pv_max, - &nr_max, max, &nr_msrs, NULL); + rc = get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_max + : XEN_SYSCTL_cpu_policy_pv_max, + &nr_max, max, &nr_msrs, NULL); if ( rc ) { PERROR("Failed to obtain %s max policy", di.hvm ? "hvm" : "pv"); @@ -346,8 +346,8 @@ static int xc_cpuid_xend_policy( /* Get the host policy. */ nr_msrs = 0; nr_host = nr_leaves; - rc = xc_get_system_cpu_policy(xch, XEN_SYSCTL_cpu_policy_host, - &nr_host, host, &nr_msrs, NULL); + rc = get_system_cpu_policy(xch, XEN_SYSCTL_cpu_policy_host, + &nr_host, host, &nr_msrs, NULL); if ( rc ) { PERROR("Failed to obtain host policy"); @@ -478,9 +478,9 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, /* Get the domain's default policy. */ nr_msrs = 0; - rc = xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_default - : XEN_SYSCTL_cpu_policy_pv_default, - &nr_leaves, leaves, &nr_msrs, NULL); + rc = get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_default + : XEN_SYSCTL_cpu_policy_pv_default, + &nr_leaves, leaves, &nr_msrs, NULL); if ( rc ) { PERROR("Failed to obtain %s default policy", di.hvm ? "hvm" : "pv"); @@ -760,7 +760,7 @@ int xc_cpu_policy_get_system(xc_interface *xch, unsigned int idx, return -1; } - rc = xc_get_system_cpu_policy(xch, idx, &nr_leaves, leaves, &nr_msrs, msrs); + rc = get_system_cpu_policy(xch, idx, &nr_leaves, leaves, &nr_msrs, msrs); if ( rc ) { PERROR("Failed to obtain %u policy", idx); @@ -793,8 +793,8 @@ int xc_cpu_policy_get_domain(xc_interface *xch, uint32_t domid, return -1; } - rc = xc_get_domain_cpu_policy(xch, domid, &nr_leaves, leaves, &nr_msrs, - msrs); + rc = get_domain_cpu_policy(xch, domid, &nr_leaves, leaves, &nr_msrs, + msrs); if ( rc ) { PERROR("Failed to obtain domain %u policy", domid); diff --git a/tools/libs/guest/xg_sr_common_x86.c b/tools/libs/guest/xg_sr_common_x86.c index 4982519e055..15265e7a331 100644 --- a/tools/libs/guest/xg_sr_common_x86.c +++ b/tools/libs/guest/xg_sr_common_x86.c @@ -48,6 +48,7 @@ int write_x86_cpu_policy_records(struct xc_sr_context *ctx) struct xc_sr_record cpuid = { .type = REC_TYPE_X86_CPUID_POLICY, }; struct xc_sr_record msrs = { .type = REC_TYPE_X86_MSR_POLICY, }; uint32_t nr_leaves = 0, nr_msrs = 0; + xc_cpu_policy_t policy = NULL; int rc; if ( xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs) < 0 ) @@ -58,20 +59,27 @@ int write_x86_cpu_policy_records(struct xc_sr_context *ctx) cpuid.data = malloc(nr_leaves * sizeof(xen_cpuid_leaf_t)); msrs.data = malloc(nr_msrs * sizeof(xen_msr_entry_t)); - if ( !cpuid.data || !msrs.data ) + policy = xc_cpu_policy_init(); + if ( !cpuid.data || !msrs.data || !policy ) { ERROR("Cannot allocate memory for CPU Policy"); rc = -1; goto out; } - if ( xc_get_domain_cpu_policy(xch, ctx->domid, &nr_leaves, cpuid.data, - &nr_msrs, msrs.data) ) + if ( xc_cpu_policy_get_domain(xch, ctx->domid, policy) ) { PERROR("Unable to get d%d CPU Policy", ctx->domid); rc = -1; goto out; } + if ( xc_cpu_policy_serialise(xch, policy, cpuid.data, &nr_leaves, + msrs.data, &nr_msrs) ) + { + PERROR("Unable to serialize d%d CPU Policy", ctx->domid); + rc = -1; + goto out; + } cpuid.length = nr_leaves * sizeof(xen_cpuid_leaf_t); if ( cpuid.length ) @@ -94,6 +102,7 @@ int write_x86_cpu_policy_records(struct xc_sr_context *ctx) out: free(cpuid.data); free(msrs.data); + xc_cpu_policy_destroy(policy); return rc; } diff --git a/tools/misc/xen-cpuid.c b/tools/misc/xen-cpuid.c index 52596c08c90..8ac25581d68 100644 --- a/tools/misc/xen-cpuid.c +++ b/tools/misc/xen-cpuid.c @@ -458,9 +458,12 @@ int main(int argc, char **argv) uint32_t i, max_leaves, max_msrs; xc_interface *xch = xc_interface_open(0, 0, 0); + xc_cpu_policy_t policy = xc_cpu_policy_init(); if ( !xch ) err(1, "xc_interface_open"); + if ( !policy ) + err(1, "xc_cpu_policy_init"); if ( xc_cpu_policy_get_size(xch, &max_leaves, &max_msrs) ) err(1, "xc_get_cpu_policy_size(...)"); @@ -481,10 +484,11 @@ int main(int argc, char **argv) uint32_t nr_leaves = max_leaves; uint32_t nr_msrs = max_msrs; - if ( xc_get_domain_cpu_policy(xch, domid, &nr_leaves, leaves, - &nr_msrs, msrs) ) - err(1, "xc_get_domain_cpu_policy(, %d, %d,, %d,)", - domid, nr_leaves, nr_msrs); + if ( xc_cpu_policy_get_domain(xch, domid, policy) ) + err(1, "xc_cpu_policy_get_domain(, %d, )", domid); + if ( xc_cpu_policy_serialise(xch, policy, leaves, &nr_leaves, + msrs, &nr_msrs) ) + err(1, "xc_cpu_policy_serialise"); snprintf(name, sizeof(name), "Domain %d", domid); print_policy(name, leaves, nr_leaves, msrs, nr_msrs); @@ -497,8 +501,7 @@ int main(int argc, char **argv) uint32_t nr_leaves = max_leaves; uint32_t nr_msrs = max_msrs; - if ( xc_get_system_cpu_policy(xch, i, &nr_leaves, leaves, - &nr_msrs, msrs) ) + if ( xc_cpu_policy_get_system(xch, i, policy) ) { if ( errno == EOPNOTSUPP ) { @@ -507,14 +510,18 @@ int main(int argc, char **argv) continue; } - err(1, "xc_get_system_cpu_policy(, %s,,)", sys_policies[i]); + err(1, "xc_cpu_policy_get_system(, %s, )", sys_policies[i]); } + if ( xc_cpu_policy_serialise(xch, policy, leaves, &nr_leaves, + msrs, &nr_msrs) ) + err(1, "xc_cpu_policy_serialise"); print_policy(sys_policies[i], leaves, nr_leaves, msrs, nr_msrs); } } + xc_cpu_policy_destroy(policy); free(leaves); free(msrs); xc_interface_close(xch); From patchwork Tue Mar 23 09:58:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157339 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 74DB6C433DB for ; Tue, 23 Mar 2021 10:00:50 +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 3B462619AB for ; Tue, 23 Mar 2021 10:00:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B462619AB 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.100561.191686 (Exim 4.92) (envelope-from ) id 1lOdpt-0007sU-QH; Tue, 23 Mar 2021 10:00:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100561.191686; Tue, 23 Mar 2021 10:00:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdpt-0007sM-NG; Tue, 23 Mar 2021 10:00:29 +0000 Received: by outflank-mailman (input) for mailman id 100561; Tue, 23 Mar 2021 10:00:28 +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 1lOdps-0007re-Gl for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:00:28 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 6745d016-9091-4c94-b3d1-66cb4e09a1ff; Tue, 23 Mar 2021 10:00:27 +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: 6745d016-9091-4c94-b3d1-66cb4e09a1ff DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493627; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=wE73k71VkuOoBtJxmEIA4ELSt2NnSaaWq1/7synJqCI=; b=IHHDMoOogwJzBD91G1NySrTYVphVRFFxb0dPpghypB8tZe/yoN0zfyCk TijySJjSWwwsGQCB57C1gwAW29UMsP+nsoSrK6nLr1R5KEHFHHNCgsW8j AFYwyBTX6fFDFzKlllIoalXkSPHB/wZcwliI647em4GrOkQzHXA+JZv9x k=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: 5zM7xB52ycpn/+BdvG7uKilxZJv/2rULgdVN5jfhFnfZV4pGZMOOzVWOuWvkqu/guyt1+SDkfG 9nIeVRp26t8kPTHHtQosCcsKzSOl5IRjMRivDZKe3NZHTvlrogLu6AQboAZ67EkxVtp988VlEy jaEMgZOQr95dR2wfjy2U9dUUjEmyurVZYEDjIrQ6dJev6SrGii9A/iKWjJgrkK+cxcvnjQbXCK LLoyZxHM3HfsPtZIqj6s6mlwxbWkTY1hf09pzXPB/G6XTfo4Emw+hBr8EXrWvsYDJAPNmeIQz3 En0= X-SBRS: 5.2 X-MesageID: 39882229 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:6zQUxqiQHw/8sDbCbn5JdLCaIXBQXwh13DAbvn1ZSRFFG/Gwv9 yynfgdyB//gCsQXnZlotybJKycWxrnmKJdy4N5B9efdSPhv3alK5wn0Jv6z1TbaknD38N+9Y MlSahxD9XsEUN35PyR3CCUG8stqePpzImGnuHbpk0CcShPS4VNqzh0ERyaFEoefngiObMcGI CH7sRK4xqMEE5nDfiTPXUOU+jdq9CjrvuPDSIuPBI79BKIyQqh9b+SKXOl9y0DWDBCy6pKyx mmryXF4MyY0s2T+1vn+EL4q79Xn9bgzdUrPr3wtuElbg/CpyztSIBoW7iptC04rue1+D8R4a XxiiZlBetfwTf8eXy0vAvM1mDboUkTwk6n83C0qz/CptH0Xz0zAcYpv/MmTjLpr3AOkfs59Y Aj5RP/i7NnSSnusQ642v3zEzZtrUawqWpKq59ps1VvFbEwRZUUkZYS5ypuYfE9NRO/0q8LOs 90AvrR4f5HGGnqFUzxjy1UzNugUm9bJGb+fmEy/sic0z1hlHtk1UcvxMsGgnca9J4mIqM0n9 j5Dg== X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="39882229" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PcQrS0vFC0W4ZAmvHdzZzXIOVteHOXlVoZOl+SvqxKPIZIzkDV+/sZWAFvMCF27mCFUDiuyz2qU8iZvoZ7ER3lcMaAq+McEW98AzxjNeIjyDTcPmhVXD+Ox4oWhNEQcCvt260yMPAbG9UJcDmS03E19v3bMpE1JeNFCjxsv2Yv2aUFdhmU+RV1cth99MQ+NxZFW2ICEBQQc+cMJuvZAXtyzJGzLJyP7UDIJwl3milkk+qrAfV4DS/uie1uQPkelq2ARbBa8d9xRjbATR1X/NqB71oDwJAvFhSfcG2WuwlbKMtMZNbljVhajtc+1AkuBPgK6/O2ZuJM1ijVeZTVTwzQ== 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=9t+NT91cGmv6RL2vL9wP6BGEOhhn8NymEq9ul10dNCI=; b=P10VeUCDlGPFnepMfre1po7EieR04WFVt4gLeh8X6aHnVwt6D8VFOZrGG3y5hZn+54HJfT7gSUMlb9pSyLbkjett+eM3Je+ZeIW89H/issEbXkTcEbJ21myhXewkRr74CEHYhEOcXX1gQkksagevcQFfY9czzqvbV1Ir2EdRVApVXs8MOCvy3qqAf6R0eyGWpAgohb9PnNBUt1tMby6TO4qQWOR5Zl0IG+kp9nuWOnbTG5OZ2GG15zucdrngYfSnNQOENImoTpDkQZrKR3bHcEk8b4D8FDKnUYrHsTFUuwyDGunpeS0rAfWtdwIbKm1OvtI3b6SrTeQ3Bh/C05BohQ== 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=9t+NT91cGmv6RL2vL9wP6BGEOhhn8NymEq9ul10dNCI=; b=xA3sfsLfXdVNp+SE896a72G8BTfH8mZ50Ce+0cwn2pIr1BBnnkMOxQiCfABvy/rnk3u8mAxIMlfZ6qzozqVKsvBnLOEad++88kJccjy1OOa94fimSfHgGnQSAyaQ+1gttOm6vvia2AtIl9ZhZCAdmsyOPOYv5n3yeO7va654+Yo= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 08/21] libs/guest: introduce a helper to apply a cpu policy to a domain Date: Tue, 23 Mar 2021 10:58:36 +0100 Message-ID: <20210323095849.37858-9-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR1P264CA0011.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:2e::16) 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: 8eb982bf-8782-49a5-982a-08d8ede27a20 X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2eII0boAvoI9hURjapK8ngY7ozlzy15cv9UIhroSmvCnJziaEZs3YIByCeDX/9GbUpAf2X1665EDO1+fUUMLqQ6o77LlvrntXFPKjNTQmYWQCTxhm6mRvZ0IMmrZbqE7AjM7Nx7pLoZZ0QUtu1XFBLOaLEkrJtaZpDc8YYs0hlwB9kwIsbymvGAUPItmPhnXl95zySCXwLfw7f91tLqrUTm0gGZWUtZMAjwe5vMU3DElYznUuX7CFhNjRr1C25KZ1fOdtOYJz+ZiceEHGRoOQNqFV7AfAjsv9jxlnlos1jnzZFO8z12vVjhDJK1f3zSpuo+KxKYCekafQYsCGojzDX4UKPTHThbvFfk3617gqFsSl3O9WtEVi+gWIP9tMdjZz9rVCW2NtCfmJvy5QpRM57RIvL2lcU7ve14OoVXj4+KsxbYeupSdcz8grW/9LJKxD/okqY5YuVacpgr48rN/hTcyunj+2r5O5ayp9wbfavH87LXErfnke7acqW7oiEEZuf5tk3V/9qZtZauK0svYEbLXoAIDUhUiDgdN65qRbH7jpBi3rOGUBTWwbA9il/YIhG6Yi+vOQnDbCZFdg0+iolHa2YfKuLcoWsDtmpYMptLUJ1BPb6IGi7NVg+YCWCM3DIxmrnpb76dUOY32NkebNhXC0y3qqA//H7qN/g9CElw= 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(6666004)(66476007)(8676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fHQfbexUr8Abpd7NydhrI1?= =?utf-8?q?SjFcvifkHjVoN6Z8nB4H3LYusnok1e+JyCvaf/5fxszlfLEziCM/cSOAF9n/busVj?= =?utf-8?q?VeZMZIFY+NIoQ7G4xNtoYvEGE5X3Q4R3rnhvS+2QBDGyqr9dzDEiL7oFl2ocuktBl?= =?utf-8?q?fEqPbaVLs6wLKciEUW9PDIaI8kA+eKameBNb8OiqJYv2750JtyJBoNekCxik8CCj3?= =?utf-8?q?v96IZQfBb2x+SocQC38DzWV/afB8iHye7g5OhOOJ3zzufgjwKQyxaDG3MtHVrmlCH?= =?utf-8?q?fTpg4B1zIHIdtBcOOHl3TcNTZYRH+ZII6oAsrfeKR9V46F/Ntnu/qk/lZ9dOdOfoM?= =?utf-8?q?qHLAz9iwEqpy7KMv9kAKfPYHLfbbh96oyhcYIqdt20u+17E3Bg4UWvqR2dGw/gb3b?= =?utf-8?q?C133dwyuCXSX5hAX3TdRaITNa79PJ4sgOHgL/Y2kjfdctgLdQJalQn5VB+EhVzH6N?= =?utf-8?q?mSyJGTsHDFtExE?= X-MS-Exchange-CrossTenant-Network-Message-Id: 8eb982bf-8782-49a5-982a-08d8ede27a20 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:00:24.2284 (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: KG+mWYvp6GaE8EkarFpvGXNzq6lSNJG1cVhVZ47yzQ+ut10B43MqcIE7xcZvkiZt8cs5/3M0i/lmnUdDg9LlNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 X-OriginatorOrg: citrix.com Such helper is very similar to the existing xc_set_domain_cpu_policy interface, but takes an opaque xc_cpu_policy_t instead of arrays of CPUID leaves and MSRs. No callers of the interface introduced in this patch. Signed-off-by: Roger Pau Monné --- tools/include/xenctrl.h | 2 ++ tools/libs/guest/xg_cpuid_x86.c | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 161dafd234b..d82c99b2f0d 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2601,6 +2601,8 @@ int xc_cpu_policy_get_system(xc_interface *xch, unsigned int idx, xc_cpu_policy_t policy); int xc_cpu_policy_get_domain(xc_interface *xch, uint32_t domid, xc_cpu_policy_t policy); +int xc_cpu_policy_set_domain(xc_interface *xch, uint32_t domid, + const xc_cpu_policy_t policy); /* Manipulate a policy via architectural representations. */ int xc_cpu_policy_serialise(xc_interface *xch, const xc_cpu_policy_t policy, diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c index a8133d5cd3f..48351f1c4c6 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -812,6 +812,46 @@ int xc_cpu_policy_get_domain(xc_interface *xch, uint32_t domid, return rc; } +int xc_cpu_policy_set_domain(xc_interface *xch, uint32_t domid, + const xc_cpu_policy_t policy) +{ + uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1; + unsigned int nr_leaves, nr_msrs; + xen_cpuid_leaf_t *leaves = NULL; + xen_msr_entry_t *msrs = NULL; + int rc; + + rc = allocate_buffers(xch, &nr_leaves, &leaves, &nr_msrs, &msrs); + if ( rc ) + { + errno = -rc; + return -1; + } + + rc = xc_cpu_policy_serialise(xch, policy, leaves, &nr_leaves, + msrs, &nr_msrs); + if ( rc ) + goto out; + + rc = xc_set_domain_cpu_policy(xch, domid, nr_leaves, leaves, nr_msrs, msrs, + &err_leaf, &err_subleaf, &err_msr); + if ( rc ) + { + ERROR("Failed to set domain %u policy (%d = %s)", domid, -rc, + strerror(-rc)); + if ( err_leaf != -1 ) + ERROR("CPUID leaf %u subleaf %u", err_leaf, err_subleaf); + if ( err_msr != -1 ) + ERROR("MSR index %#x\n", err_msr); + goto out; + } + + out: + free(leaves); + free(msrs); + return rc; +} + int xc_cpu_policy_serialise(xc_interface *xch, const xc_cpu_policy_t p, xen_cpuid_leaf_t *leaves, uint32_t *nr_leaves, xen_msr_entry_t *msrs, uint32_t *nr_msrs) From patchwork Tue Mar 23 09:58:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157341 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 40FD8C433DB for ; Tue, 23 Mar 2021 10:00:55 +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 F1C91619B9 for ; Tue, 23 Mar 2021 10:00:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1C91619B9 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.100563.191698 (Exim 4.92) (envelope-from ) id 1lOdq0-0007xV-3u; Tue, 23 Mar 2021 10:00:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100563.191698; Tue, 23 Mar 2021 10:00:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdq0-0007xL-0P; Tue, 23 Mar 2021 10:00:36 +0000 Received: by outflank-mailman (input) for mailman id 100563; Tue, 23 Mar 2021 10:00:34 +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 1lOdpy-0007wL-A9 for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:00:34 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2bdd0198-a958-4140-a55c-e50105debb1b; Tue, 23 Mar 2021 10:00:33 +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: 2bdd0198-a958-4140-a55c-e50105debb1b DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493633; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=vpl6upBzDqDR+RHogUqp/zpQiubhyzHN4/b5D/chUUc=; b=Fcss3hUDcfiBAnLv4UZdbsd650ayINOhhvCJ1QMQwxzM0awVkkhzdH2D gyORReG+24ajaGxJ71tqWU3Re8j1eO2bk8fwDLrXNhFOxynG7bBb6Sb4K EPEehMbwPBW40c0KzG1/WgVfxQ6t1nvKX7ZZHlcox4LvcVQyLE/6xX/pR Q=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: IDoYHbPfk+3NUUXbcC+DDb5wuu2Qc3Zqf3OApX89jAq2oXaNjYmUe4eUXjw1ikCJ1FIpGUeaLG bCuh/w94tkTesinyQxCL6DUNuA/ul10ZL3x7Ew4ve/EWKUzz1yoWM67dmTj9+bHhpAYqxgR9UU OraKGcy173SVJckCZGdurYsy4rpz6K/jvcb5hRMbO6vUhPonlOI/ewxhO/AbsosSXpSbi8HYuD Fg+56QqJuWh9PrWCoG3sQSOWHFGuxYoov9mnIOUph0gTwBYHtmZbUEszfp5tj2XuTo3d2i2HGb kGg= X-SBRS: 5.2 X-MesageID: 40261192 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:SWP1k6GqYzC/EiTxpLqFbZTXdLJzesId70hD6mlYcjYQWtCEls yogfQQ3QL1jjFUY307hdWcIsC7Lk/03aVepa0cJ62rUgWjgmunK4l+8ZDvqgeNJwTXzcQY76 tpdsFFZeHYJURmjMr8/QmzG8shxt7Cy6yzmeLC1R5WLD1CQYsI1XYcNi+wFEpqSA5aQacjHJ 2H6cZd4xamc3IbbsO0b0N1I9TrjdvNiZ7gfFo6FwcqgTP+8A+AxZzbN1yj3hkYWy5S2rtKyw b4uiHw+6nLiYDc9jbyzGnWhq4m+ufJ6twGP8CUj9hQFzOEsHfSWK1Ee5mv+A84u/uu7lFCqq i9nz4FM95o433cOkGZyCGdojXI6zol53/8xVLwuxKKyqaYNVFKefZpvo5XfgDU7EAtprhHod h29lmUqoZNClf4lDn9juK4Ji1CrFa+onYpjIco/htieLYZAYUhyLA3zQd+FZcNGz/C84Y3EO ViJ9G03ocpTXqqK1/epWVh29qqQzAaGQqHWFELvoiv3yFRh20R9TpV+OUv2lM7sL4tQZhN4O rJdoxuibF1V8cTKYZwHv0IT8ebAnHEKCi8f166EBDCLuUqKnjNo5n47PEe/+exYqEFy5M0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=Sophos;i="5.81,271,1610427600"; d="scan'208";a="40261192" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E7zdB4NqA8L41RGdLAD4B+PNrGJADxzZh/zsFBJXZKr8E44oTQhdlHvKmnLQr9adPid3Zw/IxlzJZ82zk/Oo4XYj4dE9oqpeZjAFMAhySGEukXRgtA7g8VitHGZc+usKMOi8ydju4Tnh2x8nbiEBjINMCZbIMgH80bhzHbLl9gt38SbLFmayGnrYSgKcX8NgkWOGsElyEkiOxZeGsse1rx3CVQPLm/Om29JvfFhVBPk/6lxLOqwukKMJF9OFI68UYOWFgXIFfTw7llmpMi+33kcYMECD18IPnX2pVjDOTBxEryx7fKi9cFkUOk5wmroyalinwJUSUKWcNQF882HKMA== 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=lFZSf71R5KScaIgtNwyj78uSfTAzOxhx/KlkN+/VBBc=; b=gZJCjz8wbO7uktIuvMdl5R/XfiCkl50JtJBm2YSWJFsApu4rMwgWdpmx08JY5vVmsH0BGJFMIi6Ky2T+VWFose22DZpUcteYva572apSq8Jk4no7+AXeezlCCEF7eincXvJuMaTrBdzZeUFHPOBpzx4ddy/KX9IGYfLWpfujGCUjAs1eaXs2RCTO54uIWJZ4i/baq8KGzfD6KvZ7SrY4jBPqH3n30ORsqWxCDm542uXkMihoCiVvsTtQ5HwqevaVeeNP2NxyDPow3bpbFZW/DzHdFj7pJJ5zWiC+x7BDc8ftcXZ8BQ+mjrfWIp39YLcEMSx3uxzmocdFzk5LVci22A== 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=lFZSf71R5KScaIgtNwyj78uSfTAzOxhx/KlkN+/VBBc=; b=HU6a4GO0B4imaIJfFK54+j9ewp1POdeU5Ve6MvvEWCaDXO+yjSK142ViJcGWQ/amekhLK7ampCRienl84Cjrrv4d+HMwTnFjzY+lls3cc/ZGAMWoF8l35Kh+yiuUhpAcvBHyg5NKlijtyNekKeuvHeTQaLExwstvrjkNIiybvmE= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 09/21] libs/guest: allow fetching a specific CPUID leaf from a cpu policy Date: Tue, 23 Mar 2021 10:58:37 +0100 Message-ID: <20210323095849.37858-10-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR1P264CA0017.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:2e::22) 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: 3b29899e-8ca4-477c-bc45-08d8ede27d72 X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2uHAtSnK0L/ffs6sgBLd288LfeYR5YpQ/OjUzq5Obw5JqYVgYB1MsAnryox2pSXKEA7T+fZ2AH1+Qxgtmv3kfCXUOE9jLPqAHBz1vtlitqxftPmsTP85YtzoG2ESoAXuDsIX2qPFat5yET5qkiNCZGPmnFR5eWbsomsWI2bHIvdQD7UFAGNliBa3y60Wzy49f9hrkJh6Et9iuhJGv4PrGdo4QUWH4knxDScIm8W/s7BV1kVhafRAb4/pjtteGoZ/yty63COX4S/GfZJg9RL9r8/Uu6cH3mHI2Nblp3Xik7Ikcpb/BPRhvb/fiaszbks3rMDxKQ1ZzIK1j6iDeA4CtU3MlbPE6eQHZlk+tBqbxN1LCpLxVGL3MZjkAD9RZc8T+ym6rq4RzJ/h/RiEk29I2evjmHFC526oNN/PIxksHL5rsm8mPDxiq0/MognCyuL4dnTM7GO4qqmciQsJhTjENRicwIW5HZE3YGOom5czGq0g2R/R1aLYEFST63UTKK29OnUduIDBslIh4bk0zCfIF5RcU4G5DqvYKZ+8SHo+7POAZauec61lmp4ONBmvgbNw4QXrxkhXqzee23X0yKBO6rYvGUcyDiE3UsesYL+8w5v3b40beW2nivencj2CPoh4IhTFibEF9S5JF2j9RUOrp195wUintmy7RWCZyZKanEw= 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(6666004)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?TnO+I7i2niOughb8N1XsKwSgLTZ8VO?= =?utf-8?q?lLDfNY0FXO1tJfb6f0//D7ydXEmRgFoTS9sKYQjXPYr7KW2duXcmx5c3YRy9OT79r?= =?utf-8?q?jDy5bWZO5sInh+c7bvUEFvf9wTSdsk5NHyrznGCQ9cCkvisSETO4Cak4ZGPwBobXM?= =?utf-8?q?Ifk5wuab4Wcbxp0TfH7ix7UywlvQwavGMmYYedTDdjlhaVJPn8AYJls6oSmTKNjW/?= =?utf-8?q?D1y3S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ViU4n3EyTAdLuT7QEVfC1i35v0KlCvLFtxXEMBQq+r8kA6fuSJLXQJ8?= =?utf-8?q?vObs4gP6ciZm4mjnH6srtWrh5Y8EsqUXJhxYpdC0OcQlEkeRLdl5Ihr07zO4JNNK3?= =?utf-8?q?f3+4qM9dOw7pJKfDLkeuBNL++0E/IFn8AEzybXk/vQ2ELLR2aNWUuAf2kwIvED/0m?= =?utf-8?q?KJPF2npn0ZOdgg?= X-MS-Exchange-CrossTenant-Network-Message-Id: 3b29899e-8ca4-477c-bc45-08d8ede27d72 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:00:29.8009 (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: bZwluCNIJrDE/Cc4KWa/NXWw6F5YRx73wGxQqaKzX1dQA5k0gSX6iDTHlVA06vhk2RChSJYzJz3aIxAVwg4CMQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 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. Signed-off-by: Roger Pau Monné --- tools/include/xenctrl.h | 3 +++ tools/libs/guest/xg_cpuid_x86.c | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index d82c99b2f0d..983e4c11d93 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2608,6 +2608,9 @@ int xc_cpu_policy_set_domain(xc_interface *xch, uint32_t domid, int xc_cpu_policy_serialise(xc_interface *xch, const xc_cpu_policy_t policy, xen_cpuid_leaf_t *leaves, uint32_t *nr_leaves, xen_msr_entry_t *msrs, uint32_t *nr_msrs); +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_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 48351f1c4c6..a1e1bf10d5c 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -883,3 +883,45 @@ int xc_cpu_policy_serialise(xc_interface *xch, const xc_cpu_policy_t p, errno = 0; return 0; } + +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) +{ + unsigned int nr_leaves, nr_msrs, i; + xen_cpuid_leaf_t *leaves; + int rc = xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); + + if ( rc ) + { + PERROR("Failed to obtain policy info size"); + return -1; + } + + leaves = calloc(nr_leaves, sizeof(*leaves)); + if ( !leaves ) + { + PERROR("Failed to allocate resources"); + errno = ENOMEM; + return -1; + } + + rc = xc_cpu_policy_serialise(xch, policy, leaves, &nr_leaves, NULL, 0); + if ( rc ) + goto out; + + for ( i = 0; i < nr_leaves; i++ ) + if ( leaves[i].leaf == leaf && leaves[i].subleaf == subleaf ) + { + *out = leaves[i]; + goto out; + } + + /* Unable to find a matching leaf. */ + errno = ENOENT; + rc = -1; + + out: + free(leaves); + return rc; +} From patchwork Tue Mar 23 09:58:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157343 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 9919AC433C1 for ; Tue, 23 Mar 2021 10:01:09 +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 3CB86619BA for ; Tue, 23 Mar 2021 10:01:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3CB86619BA 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.100567.191710 (Exim 4.92) (envelope-from ) id 1lOdqE-00086z-Ej; Tue, 23 Mar 2021 10:00:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100567.191710; Tue, 23 Mar 2021 10:00: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 1lOdqE-00086p-Ah; Tue, 23 Mar 2021 10:00:50 +0000 Received: by outflank-mailman (input) for mailman id 100567; Tue, 23 Mar 2021 10:00: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 1lOdqC-0007wL-Fk for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:00:48 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8ebd2044-365a-40d0-a972-5e54513d72ef; Tue, 23 Mar 2021 10:00:39 +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: 8ebd2044-365a-40d0-a972-5e54513d72ef DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493639; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=h3ITOhX7tv2nwa7YAoQOgR1WKEOc5xT9SsXwsOaKEa0=; b=O5E6RJPaLqg72uneRLpxahDg5tXw5YI8BHZfuQheRYwabR3Ug1+VScA5 veLw3BalNHyE/AFN++llu2Lyej/MROVoKaFA7lpsBQCI31J5jbqtR3Som PRxzOh84AuU6/4uZ3N+1we6tMbQhW8KovCZZeqn0Ep3jnwCnso467ehvm Y=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: DoQAdXkY97gRg0xOI82IKO2YpwLHJeSaoo5SLrVHhfW2tVadrVJsD81WdeNze+YHrTCUEAHnZV s5Ln591fNZGgaa6JQfzRVDFl2lE+1FvWF+o4Ni2pvOMVU9c96C0m1DblSxlOcQ3wZpTjwjcY4W Kq4/rBXW3cRRdRcAkMjxqA9vAf7KxMn1d6FeT/xW9e9ZHNmZZ0sc9/zVL7fOqicIZ+/BVBFB7D 4lgpUu3oCdLo6LuZLkSLeoY8U6S6xFLQVNXLIKz5gSYat7z1tiN8VehX5yc9or+trGEtqCpIHg eEE= X-SBRS: 5.2 X-MesageID: 39900342 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:gNsv8KoOWVYjYSLLCSg654EaV5v5L9V00zAX/kB9WHVpW+SFis Gjm+ka3xfoiDAXHEotg8yEJbPoex7h3LR+iLNwAZ6JWg76tGy0aLxz9IeK+UyFJwTS1M54kZ 1hfa93FcHqATFB5/rSzQGkH78br+Wv37uvgY7loUtFaSFPR+Ve4xxiCgCde3cGITVuIZYiDp KT6o5milObCBcqR/+2DHUEQOTPzuej/P7bSCULGgI97022hS6ogYSQLzGjwhwcXzlTqI1Sk1 TtrgqR3MSemsD+8DDw/Sv575NamNzuo+EzefCku4wuBRjHziqtbIRlcbWesD4yu/HH0idXrP D85y0OEu42x3TNfnykgRaF4Xie7B8er0XM5HXdoXz/rdf3TDg3YvAx+75xQ1/ixGcL+PRfuZ g7uF6xht5sIj7r2BnZ3ZzuUSpnk0KlyEBS6tI7vjhkfqY1LINKoZd3xjIyLL4wWBjUxaoAC+ dUAMTV9J9tACmnRkGchGVpzdC2N05DZyuucwwHssyR5TBcgGp0+Use3NAehXcN7vsGOuF529 g= X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="39900342" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e4T+UxrA1vFb2VU7u6rOYvVMqWlLUTSndwSRVvhrNalwAhg0502GGSU7r68hLc0fOSGjnp4k9TCVuRLaRFVw0C36IGX/5HR5X7kzhWF8xtIMlrxaLF1x863dDRWanhxxfSL76hmCDHAwBPojm0hunYTCAo08vQY0DKfTe9xSaWZFbleygycvAEJRkDFx5C3meu0EGr+c2UbQ90BoEE0Py/aHwOPePDoXfcQ/tXiHTHtjUA9FcC2tdE8cmNUMiOJvpvj8wZPb0UHaNqgBBLYC7tfWC9NAQkRpsDJ1IYrY7G93tYmWHlAW5zNqEfwQvNhs/2DVxpEn69V9QlwQ6EQJOA== 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=tLD0gqExlSO+XE2AhvF0loGaIpssKAiJtCEzPFIxt+I=; b=mM4qGr6DrUO1XCpWDLopRqflOsOmaZt++8DtePWEfDyuZZqKQI0uo0KkIYhwLgbxkSHrH6CJElH7/Z/lmJO+wdCoJqjUj0F3EMm/Afbwq1efiAPH9IbjT6wYlTTIVcwLe/1573TexNrSMiC49iFMPGoSvdIFNyVGMeo7Cg+v5xzmD3QI46/I5eroTaZ54R+duP/fE9mUc6H2o6Iy/Gl8U0oebybHkVGyM9SP9akPxKc1A0dJBCygnRIDo09LdLKjWWj6j8RkK9jxFilO07tz6FibqiTp9bMW9lQx8FbhoirXfuKFLYFcSXJNUCpFksA09uGBphkCkn82SdR4Rl5iyw== 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=tLD0gqExlSO+XE2AhvF0loGaIpssKAiJtCEzPFIxt+I=; b=K+1pIRti4OggngmJ+ZzjtYTRmuFgJCK9wVwDLB84kxre/vPJuSMhxvUNiRK+dJEK/YU4B8jBUOBvnUiHAnsq9iBcoNdFpNBeWNopVLjuTuHgx1jnqTpF+wivCcXEVTDj8LRvV1sBK2842CSbnX6ZKz2/u18GIr6wYuoszat/8Sk= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 10/21] libs/guest: allow fetching a specific MSR entry from a cpu policy Date: Tue, 23 Mar 2021 10:58:38 +0100 Message-ID: <20210323095849.37858-11-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: PR3P191CA0041.EURP191.PROD.OUTLOOK.COM (2603:10a6:102:55::16) 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: c29a07e9-d2a4-4b80-6ad7-08d8ede280ac X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a2xPCDEFULyMxzkcoZ4/YVb/APADbiHa1/YPHvfUYgYmvq4XE6+qG5L9W3NFaiAdE11e0nzaVZSKgewg0bWhSo8p+o8Vox0nr9XHYw63zqtGaDGDVevaKKyoGyqvhq9as8Jw/rdeIkiU870Sx6W44fVYILoot1yhDACe5M2xNh/FvYIG0eSFuoGsLHYtUvI9c0EVQz2fncYOV05nYRYwZDNVWAGwGgmNRYZJD0mEGYc5/YyVkaSRJkWaWm9/PUHpAg4fWGnGUtVkF9cKHYRQMdX26OFf+Twvb7MUPVPiq+seqcjyhaai6y0JDwHqPGxV90y7MPaQmUVzuHi2tCHHCJLzU7pFzoVWv4RwpGS9mUc8Eb+SxitWPiECzd0Vcyt1j4ZudTWMsgt/SAjzE8PfKs5cnlXPJ8VYxJOWO0n0gR7Bi1okg3PXY52YXqJnQiSIdIHmPE60+mfybQ/PEMuAxxZJgLpqxl5Wn+h6xA4G5d/o1dpMQH9DZH1EGYAQ3j98Sbw9wA/uKSy+ScEDyZrGjL1IBR8YX0IjYttEPiQ6QyfpBxmUZyf7M9rrC14szzF5jVpk17h5nX1SlP/ZXTbPJlj2zL47+sah26lwwDLiZahZ8lo5+Ink9sLVE4iDPdmi/SGKkCySh9hlcsFL3s9AQfdJHqNkszzg6ayyZV/LG5I= 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?Fe76RJ85wAb9Dscn9jtLbOoIeQa3kj?= =?utf-8?q?4av6yciw3ukCGq1L8S40Ju+Eh/m06l+f/uInXOdyJZtHolNTawzyWX7l+WegXbkd6?= =?utf-8?q?qRwpA0V67HL9ghw0wCbKwdlPhxmWWwS/2gFRoO2IhkyJUNz8I83+kp8NsAMohx3xD?= =?utf-8?q?NQtS/vr3fFjnL2Ax5BUm6/snKbrc0r5+vlxGTmJGBj9CEYVSRFADiAaKAY5OsvWvq?= =?utf-8?q?8cZB52cMAXRLbjIJA0E8pvr58SQW2i6w690MQHlUSeyhNJI4YU0J0f7iqI/BYiHKX?= =?utf-8?q?M4Afc4/GJ8yFNVmxOiZpgPdz3dQRx4+KvLw11GQuDobHR57vXqLCcXwHjCon/Q5CB?= =?utf-8?q?uw2oH5+AyrQ022b33XthaGCbKB+leOLnbV1ytaReAEeKku6/X61Vebau6QSIx06mv?= =?utf-8?q?hhN8CyePuGMmANzotvFtyci6pzvMrNTnBARQh1eWq14zekHllr0lQLsFT3vMi2T/h?= =?utf-8?q?j3kA2TKt9fz6XqaL5x4QBQpyXrGsStsVonj40+VFUr+60/EABqL3IAB8wnNQEs7ym?= =?utf-8?q?XBFZlUzZB4+mzGbh3MTv4PKY8yO9LxUGOz56iBOAwaXvSi9l92ds7QyLSZo67rW7v?= =?utf-8?q?919FhWgeZcYeLeB6uFAaY0f1m8gfh5LEX1vzxk+Yesr9PW858bEy/hSer/SsldGDK?= =?utf-8?q?9fZKr91MXWXQQi6s8Z3/EKjwOK+gGERxaKO39QxyQdvuEnmdGXCS6isIa2NyV8Q1n?= =?utf-8?q?NizOP1S8hoYYMrPYoYGAVdeXEwfe5K6Fc7OacLmGUnAqU9930sjTRczfG7HQdljBF?= =?utf-8?q?/q3FKfNPVs4zvA4LyK+FHQez0T68SSw3MVY1XLEFotZZujoR10Zp18H6FDx+L4G5Z?= =?utf-8?q?SN1jNY/bUpSxtnAbSCTrhw5N/NiMLA2bheVujUwDv89mQOWmQ6RJVIKOgUE/nLGeu?= =?utf-8?q?KeLWuBwwnsk7+GTxJrZ2xECzBDl5xvO2MmRbpVJaTTaSq0mn/dgGu0zBYGmAu95e3?= =?utf-8?q?OAQ83qIo15HZpAO6ba8Vrw2LIYR2sszLei5os6pcQeqGHuVWljvKq6+v38HTBxaW8?= =?utf-8?q?gqVIrwCxr46I0l6EYgROwCWkwQZU8JIaXrvhqv5lfouWQV9YUyicyBYSH3wXCTdOx?= =?utf-8?q?++GRZ3EuBoF6l/K1cdFMr0+/i3Dd04yS8odgUlX7iZMXTTbjckDfUgx/enZRdqzMp?= =?utf-8?q?deCdb8y8wjCLklq5eJQBWm8wD2G44DO6GAeYtkEaSe8BmeVxiM0oSa9WWOSSh56RF?= =?utf-8?q?neqqShBhzDuizwzFcrFGCgx9cxxig+kG7K4uTJd1lCzoZy39D8U+RjYwgjlFqKR7j?= =?utf-8?q?2UiBuCeqP1EAFf?= X-MS-Exchange-CrossTenant-Network-Message-Id: c29a07e9-d2a4-4b80-6ad7-08d8ede280ac X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:00:35.1981 (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: xUx9M0aKZRAAr2pRVow6mwnk40rczOD/MifLldya1E1OvFPpucrxQp5lYEyL8tJQn7jmMaBx+RrXEVC/3SIRKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 X-OriginatorOrg: 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é --- tools/include/xenctrl.h | 2 ++ tools/libs/guest/xg_cpuid_x86.c | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 983e4c11d93..ab34df1dc98 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 a1e1bf10d5c..091aeb70c9c 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -925,3 +925,44 @@ int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t policy, free(leaves); return rc; } + +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_leaves, nr_msrs, i; + xen_msr_entry_t *msrs; + int rc = xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); + + if ( rc ) + { + PERROR("Failed to obtain policy info size"); + return -1; + } + + msrs = calloc(nr_msrs, sizeof(*msrs)); + if ( !msrs ) + { + PERROR("Failed to allocate resources"); + errno = ENOMEM; + return -1; + } + + rc = xc_cpu_policy_serialise(xch, policy, NULL, 0, msrs, &nr_msrs); + if ( rc ) + goto out; + + for ( i = 0; i < nr_msrs; i++ ) + if ( msrs[i].idx == msr ) + { + *out = msrs[i]; + goto out; + } + + /* Unable to find a matching MSR. */ + errno = ENOENT; + rc = -1; + + out: + free(msrs); + return rc; +} From patchwork Tue Mar 23 09:58:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157365 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 A3BF1C433DB for ; Tue, 23 Mar 2021 10:08:09 +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 511B4619BB for ; Tue, 23 Mar 2021 10:08:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 511B4619BB 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.100599.191833 (Exim 4.92) (envelope-from ) id 1lOdx9-00015Q-OU; Tue, 23 Mar 2021 10:07:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100599.191833; Tue, 23 Mar 2021 10:07:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdx9-00015I-HW; Tue, 23 Mar 2021 10:07:59 +0000 Received: by outflank-mailman (input) for mailman id 100599; Tue, 23 Mar 2021 10:07:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdqU-0006c2-Vx for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:01:07 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0a5c9fe9-1791-4d4f-85cc-967c23b49b1e; Tue, 23 Mar 2021 10:00:45 +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: 0a5c9fe9-1791-4d4f-85cc-967c23b49b1e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493644; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=qezkb5E4ymN+jRIlFBx+OAG/L1HX+dmHCgIuqcfRKoQ=; b=MXz+aJImKURbM9QBL+DAaaTQDgqjNN5Rfb3Wkrh9dkSD1gzfXqHmISPA 2e96Tr2rL37warFiuAKze3wiayqIgqwZ/Ehfrp6PGWv8IeEvLwHVGxDB+ 9BhfgLwvp7AavaaAydYK2ZUULXkd9CbkpSToeS7ACnmmPG+vKF/qiM449 4=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: LRHjG6HXWKVYDE9/hwVYn0xynz6x2T+jpUbtQFhyFRt+iSK5o6PJZ7S58iQEVQDCrJTTA1BDYj 7KE4NoXI/oqrilMuhHKqneXeeLXzRruCgWWUG4WV63q0uCqdCMUdstcjQOjEkT3RfiKKKOCKu0 Xixx6GdxvYNJyAnNG18PoFOae2OGTrpBmrHJD5hPiPSlplJg4tMS3CiwCv1dH0XT4fmANW4ylg 92gMtR+2Zf9dBrMMznmIYNyHdhJrSmMYDaok57u3QtXukM0RyieJl2OAfSX+XkX3cwMYz6EgXW eyI= X-SBRS: 5.2 X-MesageID: 40055568 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:j8F96K59ymp6XOSSWgPXwbeFI+orLtY04lQ7vn1ZYSd+NuSFis Gjm+ka3xfoiDAXHEotg8yEJbPoex/h3LZPy800Ma25VAfr/FGpIoZr8Jf4z1TbdhHW3tV2kZ 1te60WMrfNJHBxh8ri/U2cG9Ev3NGI/MmT9J7j5l1GJDsKV4hL6QBlBgGHVmh/QwdbDZQ0fa DsnvZvjTymZHgRc4CHFmAINtKz7OHjubDHRVo9BxAh4BSTlj/A0tXHOjWRwxt2aUIr/Z4M6m 7A+jaX2oyCtLWBxgbYxyvv6f1t6b3c4/9iIODJtcQPMDXrjW+TFc5ccpmPpio8ru3qyHtCqq ipnz4aM85+62zccwiOyHPQ8jLt3zo053jpxUXwuwqFneXCWDk4B8Bd7Lg4TjLl6lEttNw58K VH03Pxjes0MTr8nT/w79WNahdylkDcmwtArccviRVkP7c2Wft0l8gy7UlVGJAPEGbR84Y8Ct RjC8na+bJ/bU6aR2qx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O2gjquSbW7/1w/Rtzcgff4L/GajXM+oAAWDXeRP6Me3PFyQgq2spM6/5Q2HOAeTegAdn8 lCc0dVc8FIzj8lh4cz2jKpSqP2rlk++mEulA1PhxrowMy+/GzfHUtaKgXXjZVdQClLPhGz/L r42Pnd0G64/SNM1pbCHlpBZ91CG9AfSY7sMidlQPJgzIKA7u4omSRMYBAnEm46hnT8xopdrM iE5Mk= X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="40055568" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZivyjKQBEOwHlLooMKDAqf6CUffsvfee104m6wGtNCfkSaHOBnXm7NvueKuDLRHoHqMo6KO2nEHUMkQYt/2Y/57s08y+ng65fsgiCsFqt2PV31l6xUL387kf6PPyFexF9xunIbmFFKAL9yAo8T3DTmsw191O0bVPf9SkUB2BaIbMCavnanFnzWxZS8Iah4fIwpDBCQiKSxFuYMRI8g+PzqEn9WuY5+vGOCeJwFMt2ZXRhJM81sBA9RV+gVfaQs0JOoShT6LF8WqD6z9+2yllMhj3GV0zu0tCobVbNxEv45o6mK2N/PuV2PjCrWWL9/doUDCiS5ldO5rszj784G6k1Q== 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=VUfWBdInOKZs5Um38UoLo/Lo9GJ2byqnYqx1gF9ZJ6M=; b=cGabuRCSEPAl9Cb7vL/2OQNC264wpsjMAIhDowdVM0jHXuNGO152K7Gw3w8GKNmaV0tcPk9qJHovMXgn/5G6oSma3aE7t7eYFNLrU/uJ8K2q12G3rj/YDTHCfSjFjlXm+fheAk0GvcHI15daiQzdSQr4uCPUq7k9n9TDg7vPI8drk+KL84vStfn9HTbmAEocwtdA+/iZdfr7svNXmOBAJCIpcqhbpZkKa406m2dMvIyp2jz7F7FB82jdEYDx87mMoQDZf9/W4Yw2+igZNR/j17cTdkzh5OJ1IfOaaVYUinTfD9bTUr/3m8m+UGzz57jSFyVZHDjT51NE5vlvM7cl6Q== 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=VUfWBdInOKZs5Um38UoLo/Lo9GJ2byqnYqx1gF9ZJ6M=; b=IclS5tlY5MpOhs7CuC4Mu/MZ2Hjx3guV62AzITTHaZzK2brBtQhv59RKfjcIuaRmw0Ln/vccd9BgHcQyBaB8eOFAFVa0myvBPnY13OKpe/rsdgmW1HfeGQUHM7wyxiIxATp9mINhykYmE4/2+X592w8XqNRpT/oiAatTKaQMSsc= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 11/21] libs/guest: allow updating a cpu policy CPUID data Date: Tue, 23 Mar 2021 10:58:39 +0100 Message-ID: <20210323095849.37858-12-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0110.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:33::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: 6cd1d566-7a4d-44f8-6435-08d8ede283ed X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kabRokzitRcDEOrGYV4IS+JvR4i+ZKC6/p/H00wwp9o7GVXn25jax+YYMSQ+E1ZqJ+6s5fEgOyez6VGR/iQ1BSUm3qHNCqhRPEJ7K5lqjB7LITGC/CHV9vwIxp8IXdppMvRIGH0wc0L6YbGy7bM2nn4ipb4rOz34Cyk5Iy00D2uG+f5kcGPX4GVM/s+pz0xdOXhkqP6LB4mD782PPlao8oojwtEWKsK9aW81f/qvXrBLlTMSCBIgC0nZ+6Nv2Ag03feNIv/62XibjgetPSLqNUygi2cpkpMKKdt2L+AMTd6NMx7psI5pRUijn7eVjUTH8C8cU9sKIAair7qsfli2utMAo7jFUmjdwFaGOHERmSL8FifyhBFmeHgS/8ZXXMyYZRhougn1Q7/bi0RJXOApULoLqBSFGHHBMEZUEiWuGi1n0VnWfuTokCHzdv0XlOcTPJLdujCRGi6MwHg5zJLXvbCXcrwPeb9NzlkCoYXcYds+2OzPr2hawv0yqwQSGLb8MXrbtjnTaCN8JhIk1y3zbFx9bbtgVsqh3CUAutxZ77xN1kH/h0GYTjAW1PNFcG8s1Mmq4uy92GZf65bt1fftbD9V9yIXBhyNO62gWMHRMHUlKwNe5J/iziawt1MpLAuW9NFhTpig+GdTwPbrXSojhEEjFOFzzRBN+OtNrWwTKkY= 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(83380400001)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?THAYXSPeSCFU/iKUROhHe2vbBtQ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f-8?q?G6h1es6HzP4zT2hemKFpPWMQ7WTQ3k0oAMR8mditpG34B3HjRYfEGzsxC+9o1vmHR?= =?utf-8?q?6pc00iKOL2r8HXuhOjzc9vkoCF3VVvqHAPFTrffTYs0gs/fiiR8Q/Vylkjg7TSWgg?= =?utf-8?q?Uuu8JHAuxrivrxBftN8Ya60CD9k48XrCx8OJAbw/zJYLm2iXOE5PWCEx6ruNwLAgQ?= =?utf-8?q?Nxo/ZMcCgwCOrjS90dlgt/ai7WUXmcBEyhqE5OaocrmC2iY9RBBz91O1W7mzlv1vg?= =?utf-8?q?Q+VLcVUT5tuzowB+LFz0lLWW+syA7PnlR7TnQkvlujVk9HjNIVboLDZVzib5kKbqn?= =?utf-8?q?oAIVjVRb77OTEKknmyDpfgBlu1FBVT2l9F/j53m8Jzo7DxEt6hrXK2KuQmlwNhrOx?= =?utf-8?q?v3ty9WC0/BgmAk?= X-MS-Exchange-CrossTenant-Network-Message-Id: 6cd1d566-7a4d-44f8-6435-08d8ede283ed X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:00:40.6730 (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: 1Qhdy+rh58rr0VhubPn6TkOtICHB+XeOV1dHgdlYYOnDDgLXj9l9VQ31lXazB/B0OtiC/muxL1Vr/97+Mh7j3A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 X-OriginatorOrg: citrix.com Introduce a helper to update the CPUID policy using an array of xen_cpuid_leaf_t entries. Note the leaves present in the input xen_cpuid_leaf_t array will replace any existing leaves on the policy. No user of the interface introduced on this patch. Signed-off-by: Roger Pau Monné --- tools/include/xenctrl.h | 3 ++ tools/libs/guest/xg_cpuid_x86.c | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index ab34df1dc98..2143478fe4b 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2613,6 +2613,9 @@ int xc_cpu_policy_get_cpuid(xc_interface *xch, const xc_cpu_policy_t policy, 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_cpu_policy_update_cpuid(xc_interface *xch, xc_cpu_policy_t policy, + const xen_cpuid_leaf_t *leaves, + uint32_t nr); 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 091aeb70c9c..13c2972ccd3 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -966,3 +966,70 @@ int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t policy, free(msrs); return rc; } + +int xc_cpu_policy_update_cpuid(xc_interface *xch, xc_cpu_policy_t policy, + const xen_cpuid_leaf_t *leaves, + uint32_t nr) +{ + unsigned int err_leaf = -1, err_subleaf = -1; + unsigned int nr_leaves, nr_msrs, i, j; + xen_cpuid_leaf_t *current; + int rc = xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); + + if ( rc ) + { + PERROR("Failed to obtain policy info size"); + return -1; + } + + current = calloc(nr_leaves, sizeof(*current)); + if ( !current ) + { + PERROR("Failed to allocate resources"); + errno = ENOMEM; + return -1; + } + + rc = xc_cpu_policy_serialise(xch, policy, current, &nr_leaves, NULL, 0); + if ( rc ) + goto out; + + for ( i = 0; i < nr; i++ ) + { + const xen_cpuid_leaf_t *update = &leaves[i]; + + for ( j = 0; j < nr_leaves; j++ ) + if ( current[j].leaf == update->leaf && + current[j].subleaf == update->subleaf ) + { + /* + * NB: cannot use an assignation because of the const vs + * non-const difference. + */ + memcpy(¤t[j], update, sizeof(*update)); + break; + } + + if ( j == nr_leaves ) + { + /* Failed to find a matching leaf, append to the end. */ + current = realloc(current, (nr_leaves + 1) * sizeof(*current)); + memcpy(¤t[nr_leaves], update, sizeof(*update)); + nr_leaves++; + } + } + + rc = x86_cpuid_copy_from_buffer(policy->cpuid, current, nr_leaves, + &err_leaf, &err_subleaf); + if ( rc ) + { + ERROR("Failed to deserialise CPUID (err leaf %#x, subleaf %#x) (%d = %s)", + err_leaf, err_subleaf, -rc, strerror(-rc)); + errno = -rc; + rc = -1; + } + + out: + free(current); + return rc; +} From patchwork Tue Mar 23 09:58:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157361 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 F2B3FC433E0 for ; Tue, 23 Mar 2021 10:08:00 +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 8F540619BB for ; Tue, 23 Mar 2021 10:08:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F540619BB 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.100590.191800 (Exim 4.92) (envelope-from ) id 1lOdx1-0000o6-0o; Tue, 23 Mar 2021 10:07:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100590.191800; Tue, 23 Mar 2021 10: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 1lOdx0-0000nc-QF; Tue, 23 Mar 2021 10:07:50 +0000 Received: by outflank-mailman (input) for mailman id 100590; Tue, 23 Mar 2021 10:07:48 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdqZ-0006c2-W1 for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:01:12 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 361e98fd-7e1a-4343-8257-b18ed40b1f10; Tue, 23 Mar 2021 10:00:47 +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: 361e98fd-7e1a-4343-8257-b18ed40b1f10 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493647; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=DR+QXS/ul67exuNBj6emUyOCRNTyaDn6XpX3sgTsimc=; b=EvJXfkXbGgPLyBOG30ah7Wdt1To9Fd+qquf5jvHOgXC0uucmptaHGy1N qIQrngbk8eHieEya9oF6WPiXim5rLkxjik6rIM/pejtRo32UlS4MSruwB J3eGiOVefIOzs57cGDs3nFXEBZoa+ExeW7rYhsmWKT5ab6kKxJJgfiG+0 o=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: +9D8T9GfCxt2Zw2O9jwG/CyqTUuuKHuMWNZ908N7eLj90uPzlfEe0RW0AWNmjxKKXhbN2wO7cc luk2MLgJ054Eo7MFKfPW55bftPxJNfDgc22zgkFF1f4bNWXy9Cy71tAWJws1XBWHTGF2tpBmRS jeLERQjWuvvghdcBw5BCt+NLJTrxrce6SKkkjRDj//jAp0JaNqLGNJSxFLL//EJVYwcMcBDsEa Asuj0Pr3291OjZPSPxDWjP/QrtaTwyRMXPrwmZFuXki3a1W9MjnCwzt+EXYZMK6t2m+K5KOkES NPA= X-SBRS: 5.2 X-MesageID: 39779652 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:Sh0DAqtK4HkPV5dJOzZPj0B97skCCYcji2hD6mlwRA09T+WxrO rrtOgH1BPylTYaUGwhn9fFA6WbXXbA7/dOjbU5FYyJGC3ronGhIo0n14vtxDX8Bzbzn9Qx6Y 5JSII7MtH5CDFB5/rSyAOzH888hPyO9661jenTpk0dND1CQYsI1WZEIyycFVB7QxQDIJI/Go aV6MYvnUvZRV08aMOnCn4ZG9XSvtGjruOsXTcqJT4CrDOPgzSh9aLgH3GjtSs2fjtTzd4ZgA 34uiPj4KHLiZ6G4z/ak1Te9pFH3Obmo+EzYvCkrugwBnHShh2zZIJnMofy9gwdhO208l4lnJ 3tjn4bTqBOwkjcdG20vhfhsjOIuAoG0HPsxUSVhnHuu6XCNVUHIvBcjoFUeAax0Sodlex8y6 5C0ia4sJdaHHr77UbAzuXITB1jmw6Ip2Mjm4co/h9ieLYZAYU+kaUvuGduVLsQFiPz744qVM N0C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Z7lSwPonATL+T11LaJF/zz5HYe8AAeQFfVJ9NL/M1KWmaeu6NOyijCySTbTUTVoua RVMUgLKsJEgX0+iYdy1C64QKn+uFgknFtT+isPrC+Z5qG2pGPAWVhbOgjYiIhMVTZdMnKUnd 3ImNLoqkjV8XxAw93fD09ecdFFBsgIQoX2JyloL9IMvLTAxdtevg1TJBE0D2A9jzjh3+Rpmb ehsc+iJNHfNQ== X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="39779652" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WKgRxfXU5qXLkh+zQxN10xz5TtDTH7tVQTa/Qrk6bNTZmvmSyNMUF9SGkr+66nFO25CKms52sgMG0RmBoS6LzMEV7QwIfZ2VvYPx1mMr8ofUVrncT4vWR32Y9PXTWjFRL6PJzAoJj+CTjuGF/VDaWLZLnlr4puiTuPkjhLR+nz6xGXDfT7F8zhSHNxVmGpqv9lKi0+H8wIjNA5IQ238YKEaJXEp6En34B4fXFpKUBSTpp09XxLwRMF9Jc463sRKq0Uoo3HMATjpeMlJz8ji0Isaa4MGKvSdusqfNvYT60HShE5bXvOixvGxSfO61Hf34CvLLhC9RqsANXnMmUmRsMQ== 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=/3WiOg86VPd8L28F4qhC0/C6RZk1orVvsRJ5t1bdvfc=; b=nqAC3p/WoP+h5dthD9zobly7JWmH7SJYYPGzR7tjpc6dR6/YVessvhhwB3h38zHJLftDn6pgYGQm1VLStJBfZ8dpwEdUdb61vtPxPnjjv5Ugeoh/xEIf5N8prRJtT4dJ91wLaOcmnaeSoUd7t0k4EuJ7wuG0sMHFhtX7GvHx5wSPLvM3B8I7AvAiFoJmfFoKa23xAbxJM1QY028Mwmr/ycRGMoBZOVMcuqTG0yCHnuppxHdH5mzsI/Xm/TNNQhGWF30M1MVgmbDqwT/H4QklgKutqYxNJCmYwqPt84sPYlBMkvu4RfKvEI6qlcet20nTexWqrqbIi+xTsAqIEwr0wg== 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=/3WiOg86VPd8L28F4qhC0/C6RZk1orVvsRJ5t1bdvfc=; b=R/ftgb2rOGdXxIjNJZIgXA9FNI1FVF6I7mMHYnDrw2WnKfRXsg/NcYXwq4i3rNml3A0LY9FPjsLkS7FnrzniayxXFsXqOEnEJ+sSwgXUbILM8oYD9NXax13nn1sDX4wX3gcNhF08WIE+Zvd5T3hA+q5W3fr2qdriGsr6z00Iq6E= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 12/21] libs/guest: allow updating a cpu policy MSR data Date: Tue, 23 Mar 2021 10:58:40 +0100 Message-ID: <20210323095849.37858-13-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: PR0P264CA0122.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1a::14) 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: 62396a62-fd03-4077-3964-08d8ede286c0 X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gJ+0e3/yEvCf3OD/VV18k5lEBHDIb+D0htT6R24DSCgVTzRmfTmXtHRIhXl85JqGzlEkA/1sROUssgi4RXWDhaJ6cuR8bek8LnGGXrzPMEMg7UL5oYklXCl5WPBlXTMqXQ2mhVDGFuTb7e1s+32DCqNdvFBSEnr7/x05f8QDrTUyV8kEZ5Ic8V774c7b2ORfqk/zBt9hY5C2DScjKeGJw5wJewizxx1R+uxzS04CdZKaxyqumI2DsmSnE+kBTIVEYf8xU30yQO7+0bA47X2uqYml5059fABxlaslF1ZsaZOmnfj05r2bJB2BsUrtALngNKfZA178/2B39W4CxmOo4Mkh7lP8fxRu3YJokPG+vlqdpffORDifvOEwVZDuojwtNfHPN06zGsYaAPKY67yFWLkOtRlJgHZtDbRu2I7o7nsEQwkmtPR73Lcf12bdiwwgTIrZoqLklNK5/ub31fTmMqaTW3QvwPQFkEBERFlSYDTbBlYhH3ePZ+a2IIAOlxdFzm9HErl5FUgiE0/AyY1lboMI8697lEDupirJ5/e7/4LT3jVcg1zec3aj0as05CH5sEA769NzK4SaLFFaJmaI+s5mueLSy3FoihHtYJDZD/stXmcCOIhfo4mNcwT4KllBED/eXq+W2Mvoksj/H4K7TPFcjJ57TZ7WHAzu4HoCxaU= 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(83380400001)(6666004)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?nWTE1ZrZVhu+U1wfdi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tkIbMsewYwHDUsDnDXjs+tC7H8yfUFeHtQ6xpYpLEromwgUS+2ltwp4tyoT5/yj6z?= =?utf-8?q?DaU8pGsozZ3gnr95R31soQ3yTkdI7vwKSDaJAGdVMD8nLYq7Ll7qRtuhnd7bdQT3d?= =?utf-8?q?lucwu2R4eH82AIVx7zeqbi/DXzy1sXiL97oZhSHaAH8knk6/IlKSaWx3YlMiRvobV?= =?utf-8?q?bv9cGXRiYsHYIho/vz5j3ENf2gvn8iVuaYDsC+o5WZUF1OaLZI0ohTNv2dh5zAf5L?= =?utf-8?q?MWmOxJWys2/D+xAlg4f0LcYd6E3lQDjjuULugbLtmDvCyk4SnEjOTDaMg5aI1DZye?= =?utf-8?q?SFE8b4btWkLZKjDsX6t2zyOJ/wr2yEw7sEH4+CwV+z9hYBEyNKcbO2utk/gwbtIc2?= =?utf-8?q?BA8bGaDnPZK6xK?= X-MS-Exchange-CrossTenant-Network-Message-Id: 62396a62-fd03-4077-3964-08d8ede286c0 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:00:45.3983 (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: /vrQ9KfsTgcxLzCHRgoOq6tIsf1pxZDIXJTppdHgFKQI7JDZ3+BqwwaMbMC753NFfAoELZxuCYoBT+4/Lr63Bg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 X-OriginatorOrg: citrix.com Introduce a helper to update the MSR policy using an array of xen_msr_entry_t entries. Note the MSRs present in the input xen_msr_entry_t array will replace any existing entries on the policy. No user of the interface introduced on this patch. Signed-off-by: Roger Pau Monné --- tools/include/xenctrl.h | 2 + tools/libs/guest/xg_cpuid_x86.c | 65 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 2143478fe4b..46f5026081c 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2616,6 +2616,8 @@ int xc_cpu_policy_get_msr(xc_interface *xch, const xc_cpu_policy_t policy, int xc_cpu_policy_update_cpuid(xc_interface *xch, xc_cpu_policy_t policy, const xen_cpuid_leaf_t *leaves, 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_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 13c2972ccd3..07756743e76 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -1033,3 +1033,68 @@ int xc_cpu_policy_update_cpuid(xc_interface *xch, xc_cpu_policy_t policy, free(current); return rc; } + +int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t policy, + const xen_msr_entry_t *msrs, uint32_t nr) +{ + unsigned int err_msr = -1; + unsigned int nr_leaves, nr_msrs, i, j; + xen_msr_entry_t *current; + int rc = xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); + + if ( rc ) + { + PERROR("Failed to obtain policy info size"); + return -1; + } + + current = calloc(nr_msrs, sizeof(*current)); + if ( !current ) + { + PERROR("Failed to allocate resources"); + errno = ENOMEM; + return -1; + } + + rc = xc_cpu_policy_serialise(xch, policy, NULL, 0, current, &nr_msrs); + if ( rc ) + goto out; + + for ( i = 0; i < nr; i++ ) + { + const xen_msr_entry_t *update = &msrs[i]; + + for ( j = 0; j < nr_msrs; j++ ) + if ( current[j].idx == update->idx ) + { + /* + * NB: cannot use an assignation because of the const vs + * non-const difference. + */ + memcpy(¤t[j], update, sizeof(*update)); + break; + } + + if ( j == nr_msrs ) + { + /* Failed to find a matching MSR, append to the end. */ + current = realloc(current, (nr_msrs + 1) * sizeof(*current)); + memcpy(¤t[nr_msrs], update, sizeof(*update)); + nr_msrs++; + } + } + + rc = x86_msr_copy_from_buffer(policy->msr, current, nr_msrs, &err_msr); + if ( rc ) + { + ERROR("Failed to deserialise MSRS (err index %#x) (%d = %s)", + err_msr, -rc, strerror(-rc)); + errno = -rc; + rc = -1; + } + + out: + free(current); + return rc; + +} From patchwork Tue Mar 23 09:58:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157357 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 4C156C433C1 for ; Tue, 23 Mar 2021 10:08:00 +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 E9C20619BB for ; Tue, 23 Mar 2021 10:07:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E9C20619BB 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.100588.191785 (Exim 4.92) (envelope-from ) id 1lOdx0-0000lZ-4S; Tue, 23 Mar 2021 10:07:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100588.191785; Tue, 23 Mar 2021 10: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 1lOdx0-0000lG-02; Tue, 23 Mar 2021 10:07:50 +0000 Received: by outflank-mailman (input) for mailman id 100588; Tue, 23 Mar 2021 10:07:48 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdqe-0006c2-W7 for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:01:17 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f8ba6ac2-16b6-45de-b559-d8438a60d5da; Tue, 23 Mar 2021 10:00:55 +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: f8ba6ac2-16b6-45de-b559-d8438a60d5da DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493655; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=cqD+tWGVB4nOXoM5SIKNJg9ABIWM9BwXG5qj4qpnV7o=; b=VlTr1cehDfTXoZ+8f9lzTvecd8+Ol10yjahXRLKxQjYkKwDNZC3Cdz9D uy/88zSGDI9EVPN804pqCMI9IQqnKe21Q1t1+9Hc0P8by3155LOk0PQYF JXyJmZaHoavMg7k+3c6csTFBvAeH5bRTvDAY0cROJyNGo88wGab1lbrs2 c=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: tFVhLBjgM5gWqO4sNFSwKp5Q7HZE1NaaoTm2tbjSxVMDFdERRAA3k93Eavxly1OMcUi6Plsmw9 4EyAgVuQ/M9mPS7av4kvM8LFpOuDMCQ5Tz3sB2xWfvN+mwigvIjTAaPRbnyJNX0CPEdX738l8E qS0Npd/Zb/YkoNIsVgdW9/BJ98yGLhf2hJWjufbgpaA1COyhsKVdwqmVobZss2Y19fXBHU2WJ8 Cj14H8caTNKmGMAQac8o/INumoOiMri9BB9XIdUqhkZePiJdrLZV41xAS8l7/cOxUISuGfp5je bgM= X-SBRS: 5.2 X-MesageID: 40055664 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:WKVnSq+UZ5A3TXsdg1Ruk+Gncb1zdoIgy1knxilNYDRvWIixi9 2ukPMH1RX9lTYWXzUalcqdPbSbKEmxybdc2qNUGbu5RgHptC+TLI9k5Zb/2DGIIUDD38Zn/+ Nbf6B6YeebMXFTh8z3+RT9Nt4mzsWO/qzAv5am815GZ2hRCp1IxQF/FwqdDwlSTA5JGZI2GP Onl7J6jhCnfmkaadn+O2kdU4H41pb2vb/FQTpDPR4o7wGSkSilgYSQLzG01goTOgk/pIsK3n PCl2XCiZmLk/b+8RPE0n+W0pI+oqqG9vJmJOihzvcYMS/tjAHAXvUqZ5SnsCouqO+irHYG+e O8xysIBMh453PPcmzdm3KE5yDa3Dkj8HPkw1OD6EGTxvDRfi4wCMZKmOtiEifx1ks6sNlwlI JN0m6J3qAnby/ooSXn69DEEyxtj0q/yEBS8tI7sno3a+UjQY4UibZa0FJeEZ8GEi6/wpsgCv NSAMbV4+sTWU+GbljC11MfjeCEbzAWJFOrU0ICssua33x9h3Zi1XYVw8QZgzMp6I89cZ9Z/O 7JW54Y2I1mf4szV+ZQFe0BScy4BijmWhTXKl+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0+o3pLj+XvRGEFNLBbQjZpXVyRCK3Tgt7 W6zcGIkHDmpCVf0ZbNFE1MbshDFtgZQI/wNTpvI6Erzc6V1rtqhD9CbhcoB3M9jz643/oO58 bH5Mnv X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="40055664" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hSN2XjNK30WKoKDpaOaZ4ktG/uQLzwTvI7jCXmZbjIuYSogteQtby63ZrGztfSyUjRZQd448eUVCdyCH0Q1Y7tZRenitqKnllJH2+n2CU93wGIYJ3S6GyLUDJkFnjGR/941JR7FsP6k1CeNIHXkA+zTgyHQSCy9VjLsGkhzsWXBVpqCCh/Po20xC1SebLT9R3NSIOEzX8f/G/ghHy5cAjUjyvMuQMwJW715Azmq4fUZT84PnCBn01CkROZCWR2IY2oXYDp2a0KGdawTdnUcd4pryfDer6uFGhtLI1hV8sRAgL51wfV6KW+BuHxCUDkez3gbALXQv96zDpHncnB+DgQ== 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=hY3Kjsh0dxbfkIPBdEUM6WIbCGm2IEEAQFQ7pR2GimY=; b=YA8mMe2Zy+0BtGxjhPMCSr3QU8o3EzRaHD2Or8eF1RwQqtj1eZq1BoBzMk21UMmNEErTH2gYHyGO0jSqjr+R0143vfbyRZoLiAaJOHlDTqy0lJc8nbaCW0DQPu5T2/oK12FNQiSfczJVpwK0XhDIQ/8ApsP9D12N6z/Se0EHp0TDMhgqc5S/b6bgDJSXYbBoq2WUf9Qn1G7oReiBokF1uXkPbNcz22bGQgwgq1Hg+BGFhShkuOwgfVhKp7j1FNhAEmO1+sFFW3eH8lcH8/fivfzJiShMtxNpQ9V7jB6a11PTVpTBP61cVXZUw6aix4tpfDNQJs/2M9x0fC4Yepyiew== 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=hY3Kjsh0dxbfkIPBdEUM6WIbCGm2IEEAQFQ7pR2GimY=; b=JhGzIIbD4S7GRBu0C5YRTn9UXMfw/Bd+4D1p02LPK2ab9181AzkqWCdrvCIdWO5PIwfdR/b71+V9pA0Mlxr3zKIqmusmkaXftJ/TjVGRz4ADQRhAN18CH570j1vkcxPUmvEXHvsOJMp/jS1CB0je0kID7dVgG5kuNWx+JZOS0Fo= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 13/21] libs/guest: switch users of xc_set_domain_cpu_policy Date: Tue, 23 Mar 2021 10:58:41 +0100 Message-ID: <20210323095849.37858-14-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0173.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501::12) 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: 0c34239e-bbc1-4e7e-605c-08d8ede28a66 X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:361; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WXIkZ34+UgPAT83aLO2rXjwWKANlatQh1mO93kMP9s38l7/QNmrAgSx7+rIdcwYG/d8dFy3dsm9SQdHcWTjM5B7iwgDmI0imGJWrN7YkcOtitiIN925K7KE0Ue4odX86QLzXfXIhAOXAJwVLRn3cnwjRsBANat/JGVKzFuwURVdVidwqNmqk6WSjTZ9okF/+lG/HYzepavx2B+Oln8xv71HFrDmn8lwvgEJVVQgU5Jm8j67sC98W8Gqbreic6YpPHj+VQyYApVBaWvj/arGHPrvcZJLbhF0kIKdYNHvrctJgUPmUZbzvQj7jEdGMdKRBzCPCxB/WQ4/6+1VK95+d5kRFK8BU8J+ugiYJM/R067Mo/kJM0s0cqysg4HwRyQuUgmDf0iXrFZyeuWokR60tWSXiSzRVEGvKPn+2Wu9bSb8wtJHfn5x65yyhMs8SXlQhYXh99LCFU0fPhL6Dm1lhu/vM/9whxeNsR3e5yn+6ZaSr0SgYvnf0i4ufZ1qP5YAO9UERZYD0KDQV8rDZrSV1mJ5LqTifnAoF18+Wpyyffe/NAx2nyLTXkTNYoMmxD/dRpeKRUTZPxThfYBw/l0R0WJEopoPsFPAgDpjQvQHFqQge9ow3GEBKWXKY8Ei8GVBdmtnsDB46p1F4bO5dYlABZQ== 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(83380400001)(6666004)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?CH/1ZwPhN6ChdqqIzJPLFGoKPKVd85?= =?utf-8?q?SBxAZtKCsfsTHp30SJmNhViom8UW6tuYBhgPSCszw9qd4rVikH1nfHIob80kcTkCY?= =?utf-8?q?iuY/q7o9UXY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SV7i7wK5godIh0gpUECgOYLwyRjm/3SB5L6Pzy8rly?= =?utf-8?q?ykSMPQ5+S0PlztfQZk5T0g46s8KM/Zk4gL9lf4OCHZ0m9CtoqcWRgFVV6U/Wj2Wai?= =?utf-8?q?iJf7zAyk02foMqB2J8h7Tq9dzRfdQp9PqhohR13rRo990pC/vqZiu1HysZzV5uzET?= =?utf-8?q?0kW6Uj6yEehHNfoD6nFBiTWBeByxwarcKuwPnGRo/ZmuUZNGqwh8GX4stEEhx3GjE?= =?utf-8?q?L8yVyi6uw0SPUksqk/6Tc986Li8ggz3nKAdm5h3DyKbcj30yU+96oaan6LO3eg6ud?= =?utf-8?q?16ky1mUBuzbU0c?= X-MS-Exchange-CrossTenant-Network-Message-Id: 0c34239e-bbc1-4e7e-605c-08d8ede28a66 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:00:51.4327 (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: Eceh7IR/BLgBDKMpPgEw8YBp2pBZsHg47vBirqMeeaViKR/Kf7Wxk8R+Z1k9xbugLj5edwng0Lm61l+3fdFGhg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 X-OriginatorOrg: citrix.com To use the new cpu policy interface xc_cpu_policy_set_domain. Note that xc_set_domain_cpu_policy is removed from the interface and the function is made static to xg_cpuid_x86.c for it's internal callers. Signed-off-by: Roger Pau Monné --- tools/include/xenctrl.h | 5 ----- tools/libs/guest/xg_cpuid_x86.c | 22 +++++++++++----------- tools/libs/guest/xg_sr_common_x86.c | 28 +++++++++++++++++++++------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 46f5026081c..164a287b367 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2625,11 +2625,6 @@ int xc_get_cpu_featureset(xc_interface *xch, uint32_t index, int xc_cpu_policy_get_size(xc_interface *xch, uint32_t *nr_leaves, uint32_t *nr_msrs); -int xc_set_domain_cpu_policy(xc_interface *xch, uint32_t domid, - uint32_t nr_leaves, xen_cpuid_leaf_t *leaves, - uint32_t nr_msrs, xen_msr_entry_t *msrs, - uint32_t *err_leaf_p, uint32_t *err_subleaf_p, - uint32_t *err_msr_p); uint32_t xc_get_cpu_featureset_size(void); diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c index 07756743e76..f7b662f31aa 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -204,11 +204,11 @@ static int get_domain_cpu_policy(xc_interface *xch, uint32_t domid, return ret; } -int xc_set_domain_cpu_policy(xc_interface *xch, uint32_t domid, - uint32_t nr_leaves, xen_cpuid_leaf_t *leaves, - uint32_t nr_msrs, xen_msr_entry_t *msrs, - uint32_t *err_leaf_p, uint32_t *err_subleaf_p, - uint32_t *err_msr_p) +static int set_domain_cpu_policy(xc_interface *xch, uint32_t domid, + uint32_t nr_leaves, xen_cpuid_leaf_t *leaves, + uint32_t nr_msrs, xen_msr_entry_t *msrs, + uint32_t *err_leaf_p, uint32_t *err_subleaf_p, + uint32_t *err_msr_p) { DECLARE_DOMCTL; DECLARE_HYPERCALL_BOUNCE(leaves, @@ -405,8 +405,8 @@ static int xc_cpuid_xend_policy( } /* Feed the transformed currrent policy back up to Xen. */ - rc = xc_set_domain_cpu_policy(xch, domid, nr_cur, cur, 0, NULL, - &err_leaf, &err_subleaf, &err_msr); + rc = 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)", @@ -638,8 +638,8 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, goto out; } - rc = xc_set_domain_cpu_policy(xch, domid, nr_leaves, leaves, 0, NULL, - &err_leaf, &err_subleaf, &err_msr); + rc = 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)", @@ -833,8 +833,8 @@ int xc_cpu_policy_set_domain(xc_interface *xch, uint32_t domid, if ( rc ) goto out; - rc = xc_set_domain_cpu_policy(xch, domid, nr_leaves, leaves, nr_msrs, msrs, - &err_leaf, &err_subleaf, &err_msr); + rc = set_domain_cpu_policy(xch, domid, nr_leaves, leaves, nr_msrs, msrs, + &err_leaf, &err_subleaf, &err_msr); if ( rc ) { ERROR("Failed to set domain %u policy (%d = %s)", domid, -rc, diff --git a/tools/libs/guest/xg_sr_common_x86.c b/tools/libs/guest/xg_sr_common_x86.c index 15265e7a331..02f0c3ae9ed 100644 --- a/tools/libs/guest/xg_sr_common_x86.c +++ b/tools/libs/guest/xg_sr_common_x86.c @@ -151,7 +151,10 @@ int x86_static_data_complete(struct xc_sr_context *ctx, unsigned int *missing) { xc_interface *xch = ctx->xch; uint32_t nr_leaves = 0, nr_msrs = 0; - uint32_t err_l = ~0, err_s = ~0, err_m = ~0; + xc_cpu_policy_t policy = xc_cpu_policy_init(); + + if ( !policy ) + return -1; if ( ctx->x86.restore.cpuid.ptr ) nr_leaves = ctx->x86.restore.cpuid.size / sizeof(xen_cpuid_leaf_t); @@ -163,14 +166,25 @@ int x86_static_data_complete(struct xc_sr_context *ctx, unsigned int *missing) else *missing |= XGR_SDD_MISSING_MSR; + if ( nr_leaves && + xc_cpu_policy_update_cpuid(xch, policy, + ctx->x86.restore.cpuid.ptr, nr_leaves) ) + { + PERROR("Failed to update CPUID policy"); + return -1; + } + if ( nr_msrs && + xc_cpu_policy_update_msrs(xch, policy, + ctx->x86.restore.msr.ptr, nr_msrs) ) + { + PERROR("Failed to update MSR policy"); + return -1; + } + if ( (nr_leaves || nr_msrs) && - xc_set_domain_cpu_policy(xch, ctx->domid, - nr_leaves, ctx->x86.restore.cpuid.ptr, - nr_msrs, ctx->x86.restore.msr.ptr, - &err_l, &err_s, &err_m) ) + xc_cpu_policy_set_domain(xch, ctx->domid, policy) ) { - PERROR("Failed to set CPUID policy: leaf %08x, subleaf %08x, msr %08x", - err_l, err_s, err_m); + PERROR("Failed to set CPUID policy"); return -1; } From patchwork Tue Mar 23 09:58:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157345 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 EBE61C433E0 for ; Tue, 23 Mar 2021 10:01:28 +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 905B1619BD for ; Tue, 23 Mar 2021 10:01:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 905B1619BD 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.100569.191721 (Exim 4.92) (envelope-from ) id 1lOdqR-0008FW-Tb; Tue, 23 Mar 2021 10:01:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100569.191721; Tue, 23 Mar 2021 10:01:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdqR-0008FN-QO; Tue, 23 Mar 2021 10:01:03 +0000 Received: by outflank-mailman (input) for mailman id 100569; Tue, 23 Mar 2021 10:01: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 1lOdqQ-0008Eu-VT for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:01:03 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8fdba55b-bf6a-4b6c-b003-c71aaa53e824; Tue, 23 Mar 2021 10:01:01 +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: 8fdba55b-bf6a-4b6c-b003-c71aaa53e824 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493661; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=7KO7gTVsvFjrD8UnwpRq3qnvKwX9RIxUIWr7RkzivD8=; b=A62HGMb2GRBWkBvEyv/2MRk1qpB4YGPbKFwCqau7WG+ru2pBlVVvJeXS 4j3JFHsx2TG3FVBbX4qBL8xUvSW2S9+0B6qXVZW9zZHF5k45V5DBYdi6c AUDrI+JfS7QsAybxfgQPeRjv2v+5Evz24VgmY6KhSYWPwki54FNT5MUC6 s=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: v8Ha3slj7l1Z9rADSGg3Cw482nNlTGw+xfgmtp2iIoRGwqqG3OKJavETxjgxQTn4JX1I8fEDo+ YpuBBBs7MmBfYu7khPStmOa4G9yFSKHHoytEgYTnZ7INKBAu5M/MwzMSAQ4hNPn+fzMQbr4biZ sVFGpGK0DmnJhwVlX7adOnBM63ndHN4eu6ch2BbgYxqLAwkUypyqrBRhLTXA/9zyRMXLvxpLLq TbLveF989wPst8h+TUEqyYgsRRslEt968TGKC7vSs9stwGsbTHeZ0xvTfzjhkjpQ3gGAMTJstu xlk= X-SBRS: 5.2 X-MesageID: 40261280 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:PfEHMqGCEqtD0lZupLqFDpTXdLJzesId70hD6mlYcjYQWtCEls yogfQQ3QL1jjFUY307hdWcIsC7L0/03aVepa0cJ62rUgWjgmunK4l+8ZDvqgeOJwTXzcQY76 tpdsFFZOHYJURmjMr8/QmzG8shxt7Cy6yzmeLC1R5WLT1CQYsI1XYfNi+wFEpqSA5aQacjHJ 2H6cZd4xamc3IbbsO0b0N1ItTrjdvNiZ7gfFo6FwcqgTP+9w+AxZzbN1yj3hkYWy5S2rtKyw n4uiHw+6nLiYDD9jbyzGnWhq4m/efJ7vtmKIiyhtMOKjPq4zzYFbhJf7GZpjg6rKWOxT8R4a HxiiwtNchy9H/dF1vdyXCGtniCoVRemEPK8lOEnWDl5fXwWTNSMbs+uatibhDb50A81esMtp 5j4mTxjesyMTrw2A7559TOSihwkFu1rXcIgYco/gNieLpbR7lLoYMF+kRJVL8GASLh8YgiVN JjFcfG+Z9tAB6nRkGcmlMq7M2nX3w1EBvDak8euvaN2zwTuHxi1UMXyOEWg39ozuNwd7B0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Wiks++N+868jDD+VD2hTV8X7L c1M3AtUg== X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="40261280" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ksIQ7JeM1Hfh/GKl3D4Wu7VUEA48MYckKlPo6DM/ERI8BUhrHIPI0nHQOLOYdB6H7oigssEcA9AbKlkbzw2pTFemFHDPdglYGdR+U2+rLJm76HcokgJQLXq2m0sIIVLfB7aMLBofWvba4vV33CX0XhO9hx6g0Krji9K6aHimZbuVtB4AR8+nFz1v5WBxqA7L+y7jHR2gOonpv7igJwaMTzPcIK9IJWdb7u1r13TcEy5uRor1AOBGGAS7qgYC4Vy6HH8vt6El5jKxuVoyRnfW7pQUrngJrGliBtT3BmcV2uWDnfmacguGzFqVBJ98XBCTAAlXFwDv5pNiNDbHKyWltw== 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=aI7Y7A0OHymM1N3AAaa+CIA8yVMw6gOJwUG3C50vFTg=; b=ho+xaKbrYGwgFkICAp6aMq4ole1Y53uMJgaxSn6R6/ahLZviov6o1Ey3wZ4gO7vQmnfjJX3JHIKqTNu20K+u1lFXRKmzG6ska0lWRlhqScsWdrCByTF05Inelc9Slp7U0sSnnwq8S4dHtIADqTu4360imm2WWa2F/AxMWrFr0rSii/JF+ONVAS79s4MT/mGl0GnDCxWgmv/7w2AKEOR0cJ+L5qKvE0kRb2K1gjKmHzXW6zX7nsm8mP9ipnxCGs7lR3ghIiTHexVUTIHUIiS3iC3xqgahS2K8ZalOJoJDFX7wrgNTXPhkfzr5rkxTxLWlfTxcHzY6R6kxJ1p1PIw9Fw== 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=aI7Y7A0OHymM1N3AAaa+CIA8yVMw6gOJwUG3C50vFTg=; b=A0LRBjVX3ybEyWYylLw+NFrGBGLQrIaitPigxBh1AWyQdjKvWkJOXlz47+B6iNQ5g6+gX50Xt+rMILbHu5q4TMd90csnMocC0aIXUHSzwIPKgmBO2QGizjQchbr4Z9KyxfvaKjV1IdG5ODh52aPdaWKHWl0son55/bnkrU1qMB8= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 14/21] libs/guest: introduce helper to check cpu policy compatibility Date: Tue, 23 Mar 2021 10:58:42 +0100 Message-ID: <20210323095849.37858-15-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0094.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:32::34) 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: 445ddd65-bf74-4793-de8b-08d8ede28e03 X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2958; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IEryU2nKESj207JzbEOhiqGz23Gfct2ZWjBPAD0Fu4nJC/DAOw0ebr5RhvfoVYFGJl3IDOiloSNQMbtVxdFYbZCRHx5ys11YR4PmTXLXYe+2Ai25tgGrRpDypn4GSqxEx20ohYuSIOqqsbLoowW/VBQ1jXXHSkMEoS+U7/HZISra3QWT4GE7g+NOIPFPySCOotYoLYJfeCwBxmnk+UnyA76gsxs7hKb0J5vLb936CXMoaSTYPswrI+ylAL9hLErxXmFQ+wqDLGke0pPoMgLdKJFwV9r6P5up+hpLARh8LWOfkXCwHMbQ474Rv++5v3x6I50GJZFaoBHsNqWBzw3/1rftlsMwFKe1h8vAn5NIMPP5LXiMSNObNIhXGkPNo8hDFS3sfmy2fvRLBY7+8vRAxtWSZAURDQDKZJMwGjlichcWrPw4Ph7pncQOix6Vx4YIOj7Vd8MbVUSOelT6huhVwHpYMoPStPeJU7CdFWakDGPDYupCGvVi7ypC9NteYYvpaAKurJIDluq2U4OIZyAXu6dIe4sgIVDEWVQWXAOoXRZLNIvRHa3j8aVEphD00a0FemEIvnwUiFypORB1iZ3Vo18I3OotNErORnlbc8ZOnYulaTETK40ZPCvtJyKplwcG8ZOKQbS4MjpqvtNOBb31JA== 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(83380400001)(6666004)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?A2RFtuoJNW7S/MbEP/kAOoTw+T5lcg?= =?utf-8?q?xawdNl2RG1bSK1QLQy1u8BejcsN9Udq56pvDNeHjFtk5f9F6mHkMLMzOXze3CtRqS?= =?utf-8?q?HbJwV/WusMyODH8ODSOn1ZJXA/rINhNIEDPM5MjTPI+CHv9pzQTIW9vfMxzOJZ4WZ?= =?utf-8?q?ivKExoXQu9yiHce564j5mglo/t74oDt3UQ9+b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GU25iOTRjrB2DznomMVF?= =?utf-8?q?/yXHrp5Ph+onf8tQhX2tkWA34j5KFx3eCMzyZJWXTMzLQtOYUc0RQKOHceQSFzBso?= =?utf-8?q?yOxEnjaOTExouxRjCPrgqLg4jlGBYiD0Gn121m06IPpAQmWjxEvfbzMi0FbWIcoFB?= =?utf-8?q?feztbMQ0vre+G0uCH/6HO+wOTd3TriDRZSwya9lbJixO7cI7QuTRS4PKEc9W/ErPx?= =?utf-8?q?LsUKEJRXQhg5Ko?= X-MS-Exchange-CrossTenant-Network-Message-Id: 445ddd65-bf74-4793-de8b-08d8ede28e03 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:00:57.5149 (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: MkCLT83fMmUG3tUHZ8eJG42fY6MbZPwGUsVsRi/rX2iiq7xtq5G2E0dJ9oEWZVzSIsGLNhjusTYg5wMw2envNA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 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é --- tools/include/xenctrl.h | 4 ++++ tools/libs/guest/Makefile | 2 +- tools/libs/guest/xg_cpuid_x86.c | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 164a287b367..165beff330f 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 p1, + const xc_cpu_policy_t p2); + 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 f7b662f31aa..30ea02a0f31 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -1098,3 +1098,20 @@ 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 p1, + const xc_cpu_policy_t p2) +{ + struct cpu_policy_errors err; + int rc = x86_cpu_policies_are_compatible(p1, p2, &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; +} From patchwork Tue Mar 23 09:58:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157347 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 44E42C433C1 for ; Tue, 23 Mar 2021 10:01:34 +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 EEC2A619B9 for ; Tue, 23 Mar 2021 10:01:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEC2A619B9 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.100573.191733 (Exim 4.92) (envelope-from ) id 1lOdqd-0008Lm-6N; Tue, 23 Mar 2021 10:01:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100573.191733; Tue, 23 Mar 2021 10:01: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 1lOdqd-0008Le-2d; Tue, 23 Mar 2021 10:01:15 +0000 Received: by outflank-mailman (input) for mailman id 100573; Tue, 23 Mar 2021 10:01:13 +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 1lOdqb-0008Eu-GH for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:01:13 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id ba0ad827-ca82-4208-8b2f-546188866a20; Tue, 23 Mar 2021 10:01:06 +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: ba0ad827-ca82-4208-8b2f-546188866a20 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493666; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=4lHE2jerg+jbItJ/+12Vb+5du8PMBfuwXfXIwSVEhTU=; b=Ms7dQoMLj4gSnW+pX6RZZfbzsK5c3WbHTvE03+dvu4B4XZ0FtPVNKxyu QcI68rIqByFL2sMWtJ41+8AxvEJlaQwo3Cj8omOELRhbQcuOa3D9kSLcz jnHAHXKq3vCVLMEx4E6WI2VXfLVKzvR7xlOrU+pe2pH5DCMPuqtfKSq0b Y=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: g7DxBHYwtYpWsEK6qiAP6OXHSwV0FtbUHsNBYw9n2kIZlqi8GS6hpKwlcTAhC5J1VrRRVB1i0G pCXKUGpkKJ1LxQVufXNH/2aug9GpnpFptmhWkh5DswzwhjxcmDP5Ls801+EMckIgaAVjg/6Irx T37oLgcVTNcQtd0cFw5VF7QMVuNXZ1992p4mxEBlZfWmidhgcNgHxuR+yKjXm5R5zZRFnbI5Fs yr5J5u3kPIfyn8uA31Tw7g6Gj9Sfjr+AH2OyH4sGI4Ci5X3wOlnHq2QZR8yZQR8U9Kc6VMNldV PT4= X-SBRS: 5.2 X-MesageID: 39779677 X-Iron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VQ8BSibkZ3DToJTgqKZRKPDUdtF6jgvuC9VTs2jjuUKVotxqemEWRAe0UcmcgR8nQh1dgl EZyd5ZvJOw3RKUbUcviuUxN1NBLECaGqhPAgi+aIJIobzzYw1rQWCWhTuVtgErdgPRhjYvr1 2kCRfRVeDAA1JbtHwd6Krs/V9uXki2fk57aBlBwMZAPFWDnkw2/f6AZ6K13WfUV0ALxfsFNi rZJREIJBl1+tyx3BmJuTqLGHk83K8yNujFALlLScCU5lqdbKmz0Y0WFf5d+5hocO30uugQSO SFZku7Kij7B+5B4X3iml8VfA1P7F8qnvPj1Ee7sCyW3HsjDeHTJ1ojbbcBON2Y53XlQfHN8J gRt6NAgcKAdkHKLviBwuXrShQGDDX5i2u/VfspppBZprhajso6I7DrFR/zkEha1xA/JvrunE wQQK5H8KnMU7UfCvA6SmZ8xB4Vj9yBI0sgjxzuDsI/dV8riWXHP9nh2cu+lZMfRmmIpA79Ij CkglVg1saAeyuIzrgBDa0sZUxQdUgn8XxnldnyPbH4OUGPd+tZ+kC9PWL4WLhBSLKdEbFVih ph+dmHk6u2cCX/sTqg8AdTE+Zr82y9R9m1Dx/JMelU88aiMVDJu5CU2qeI/X7KYAr+TV8Zi4 1DfVERacoGqgBKtvxJ7gGCDortokwklFNC5ypAjVCF4Pn+3Fvm X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="39779677" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ETCXfI8+ug8o2r3jD159Dfvxjq9eQ5HaZhNM224zFkq1yEmJhZF/asZzlR9JekKmCW8vxJTQszxiCDgzSDHVYqooEHEuTiKEYE3sZq2oww6knc3d8mq8Gq/jYkv/NoCjNpbuuZVDuAZuXEn7jhwHiVc46aXGPZQQDiKKH841FlcWwvQRlJJsh58RrUL9OgF5iEeAXlJHLzACl0ffgvLuQI/UJ/AmVoySa0yn1dklPhiV71ib9E1znyOx3wnGzyjKcNatQRBDstxrAS4LpfGHYOOTBeMwhnzNNoMlOF4YQ730n6uM8FEiE2VFQiT6RhCfRCpIlCmjHTevytX0Lhcgmg== 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=Blm/0Bd7WSGIeDuYXRMAPB5HSkKSVJuxKVDttIrYYCg=; b=klrFH4V3jYsh5HZM3rZXQQHfJovV8oh/QsSy7bXXZ2LxJx2RQlPkXJBfhsz1SRAXYHO6dKSHHn6SE2Z7qvZQ4dyP8gJGvOhPyuNob8d89/dyJZLZjsjZTXLdf0K0RDwJYRl9VbQOUsRSkxCqVvzvzKV6eUI9Uqnpy+217Sj3sKFBObAfBxpmhhNSv5x1xpFXEQUSAQBCSE9zS5nB0nPWR9zo9otqYwuyeVpdCZ/HSqjU0HXhKml9bkzrf7mxK3KxbZ29Dzrie9wEYrAIklcIm3mIkI7z5t7/x8vE4idYpTucFfTs3VIxdV3YJvVCvAPjxSL51SA8+b8ykgOvdBEmhA== 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=Blm/0Bd7WSGIeDuYXRMAPB5HSkKSVJuxKVDttIrYYCg=; b=ck3d6o4ZCj7tLxrgbrYwNUpew2URpTntyP9ahfroDKOb/DQnjSLnTv+sjy3s4f4i8WoS52JIWygoPpd987crw4Wy9qm0KrzAtGa1oQLS3lWEae1S8vWZDUXWti6pgOSualiSmDScpTu8kD24IZ1/vGsh7UpLAZBIL1svJPkmG0g= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 15/21] libs/guest: obtain a compatible cpu policy from two input ones Date: Tue, 23 Mar 2021 10:58:43 +0100 Message-ID: <20210323095849.37858-16-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0109.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:33::25) 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: 9c6c3518-4f3d-4d3f-f189-08d8ede2913c X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7DVBL7yOKHSTGw8bYEX6EyAgcb5SMH6bb6HORNjz7trlRfw0L/RN1ZrhXD+Z/+WqyMryYLBVFT+EkVm0+dwilsjaVgAGjhadNAfD9A0a9Fld5PwhrwaYGQFcz5uhzhlitrgPbw5JROpIF3RLSq9Kl4C5EZs17HsChN4+y60v5q0i44f2g5u6RYjJNkYobi6P8ow1U0i+5DOoR2Celn6jRRmi/ppyAFjO0cGoOIbZr5B1I9Z263kqwvlvkzBmsBCYNYjS21xpJpefn8KtlRWbawo1GySO6BBb2VrgXx2dzC9mBv6PBrOirbdKB2Z3kJo2r17p5nd0KQNI7zyALv4BwZ/z43WmxmqVehnZXGQP6VVOWtSN0vgZN1YYasly5v/IbA8aRgjg1dcjXf5tUDZp2cvJNmxEVsdI07byxs0KQfyRrO1pRNfwuBXIh1nCNAi1GLZNEbHL4T47WFnQVp/lMoqAxpcQdBTJ2OGPo8pdfb2JsIBIwqmnkuC3fvVk56l3c/YQqRBI2x7MuLg5KB0mKZqwqI+IFDEIXulM7IJ9R1lRhIB/N++kh83shNuvcKoIuc6VMi2YqHzKHhqPSdgF0M/NGiqehOws5VIDptz125bNnu7lMvK5XTL/uN+y1r+i07yrHROww5IFHQ3jbXLkZQ== 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(107886003)(8936002)(6496006)(38100700001)(83380400001)(6666004)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?LKwC1iCJ8uYSQYO3wtw846QHXGs5o7?= =?utf-8?q?tZSrN1U/5kYJxbEim2PoLt5rXuvQ2dNUDAxBzIVfBLLlMvh5cG3d/fLXhwYaWKNlY?= =?utf-8?q?HzTrfJBHDU5e4TsEqz9OY8ncBt6gpjVlMZbp6zJV1Q+o3EFoBaf8Mv2uTSP7sZDOh?= =?utf-8?q?SG0Iui7D2H2LpZTHd42o0ZyF0MZwYGUKS1Vm8IE0vn2ohtRl5ua5x79179/scju6z?= =?utf-8?q?cgZRXzjqyJw4uZa85Q+2M/ihgeRPmU1KrDIPb8/dVYztJaWg7IvzJ/rYvgC4m9Pyo?= =?utf-8?q?XZ0aw9fJx9AXD5QUYL22hCi1UNDESip0uOqjWzv28n3jopOoSKzJ9p6uUWHCJKKBt?= =?utf-8?q?DvNRQIaziIZQjl+UMfN1JQULzEfz6nlDQF6mlQW2RwJr1jgtdUexgC1B3us9RmQpK?= =?utf-8?q?GfDwKES17RB6KN9OP6YlsauKj+x/aQcepPO29swbpy2mEoUPkd8UyzHqFCFwuOben?= =?utf-8?q?9L+IsIOtknFQU9GsjG8jLsVDADa6nSauwly4fDUldcU7tWj0KKN7cfPME+407RAUY?= =?utf-8?q?K0vXNbBpjJbcsQ1lVu80zZrp7eDQNLG9RnUmBh9e5Xe0mdUJLPtuiQrPv1s85E4ry?= =?utf-8?q?+bsVPhO3z7hUefl92qQmvWTIXcvQvS6LtkK1tKtLMv+ELJOPizumqPgvTjlxsCY4f?= =?utf-8?q?0S2mdmim1s1PqEFyXcPpjWbzFezIfNz2IHKew9/CvTu9PGuaFCELu5EcE+3P2nYeD?= =?utf-8?q?W6U2OKGu6fKZ5UnIXHx5/PQ7mAO1BPXtjlU25F7+mKSQZ7amsYFUDx1en+HnZ3Jqv?= =?utf-8?q?Qu6cfzwkKmqrYCqHz5jDsomJcrEGIxbIChSXEh73Py1Dcs+GSWmmxqls+sIbihu1N?= =?utf-8?q?vLgVJSPCpHhEH4dHX0biXLxq5OCkoWuasn1r9hkkmgh5A6qOqVJ+dDz1B894eHAO+?= =?utf-8?q?TW4HK0qIHY4e665UPBLmXTFdJ4B6quxh2qyc0ihenxrWLR861TWHiC2aJ68GNTlQf?= =?utf-8?q?GzUKarDeFlihZHSwUxXlkph9k51qylsVtnrl3I8MO+058EbHXmSLna4uxfNDfp4fE?= =?utf-8?q?bFs1tCHcO3KALXTiB1yzf2rRKafTmTjmLuN1DZEhVEYT/adYSsu23XMwiMu1+14h3?= =?utf-8?q?tYQ9VkAZHVArvFdtreTgqyLPBH93IbzAER6+ZC4HCDamJxs5b9HptqJbAAaot2e6m?= =?utf-8?q?tF7/HpatezKEtI/mVC6wm+rHSvRwNqIssL3AKEfKH4W0RKZidnyU8dyWcLN4+SVp2?= =?utf-8?q?/fI2LmHs5fS3Ep/E0LfyWbrpxx2ogkNnM5QJOhKQ2Zof/etTs/ixJliBRQqr+jHCF?= =?utf-8?q?bv47wJny3rq5XW?= X-MS-Exchange-CrossTenant-Network-Message-Id: 9c6c3518-4f3d-4d3f-f189-08d8ede2913c X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:01:02.9122 (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: AmBkQTDaZgYjvGrZzSZcRLwEcJRHNbMFH99lfS0ltQcX9GYSgV6GcICqwk8W0nZyu5IYAZGAHKIYnAHXV+jKww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 X-OriginatorOrg: citrix.com Introduce a helper to obtain a compatible cpu policy based on two input cpu policies. Currently this is done by and'ing all CPUID leaves and MSR entries, except for MSR_ARCH_CAPABILITIES which has the RSBA bit or'ed. The _AC macro is pulled from libxl_internal.h into xen-tools/libs.h since it's required in order to use the msr-index.h header. Note there's no need to place this helper in libx86, since the calculation of a compatible policy shouldn't be done from the hypervisor. No callers of the interface introduced. Signed-off-by: Roger Pau Monné --- tools/include/xen-tools/libs.h | 5 ++ tools/include/xenctrl.h | 4 ++ tools/libs/guest/xg_cpuid_x86.c | 115 ++++++++++++++++++++++++++++++ tools/libs/light/libxl_internal.h | 2 - 4 files changed, 124 insertions(+), 2 deletions(-) diff --git a/tools/include/xen-tools/libs.h b/tools/include/xen-tools/libs.h index a16e0c38070..b9e89f9a711 100644 --- a/tools/include/xen-tools/libs.h +++ b/tools/include/xen-tools/libs.h @@ -63,4 +63,9 @@ #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1)) #endif +#ifndef _AC +#define __AC(X,Y) (X##Y) +#define _AC(X,Y) __AC(X,Y) +#endif + #endif /* __XEN_TOOLS_LIBS__ */ diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 165beff330f..5f3e5e17e9d 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2622,6 +2622,10 @@ int xc_cpu_policy_update_msrs(xc_interface *xch, xc_cpu_policy_t policy, /* Compatibility calculations. */ bool xc_cpu_policy_is_compatible(xc_interface *xch, const xc_cpu_policy_t p1, const xc_cpu_policy_t p2); +int xc_cpu_policy_calc_compatible(xc_interface *xch, + const xc_cpu_policy_t p1, + const xc_cpu_policy_t p2, + xc_cpu_policy_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 30ea02a0f31..4afca3249ba 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -32,6 +32,7 @@ enum { #include }; +#include #include #include @@ -1115,3 +1116,117 @@ bool xc_cpu_policy_is_compatible(xc_interface *xch, const xc_cpu_policy_t p1, return false; } + +static uint64_t level_msr(unsigned int index, uint64_t val1, uint64_t val2) +{ + uint64_t val; + + switch( index ) + { + case MSR_ARCH_CAPABILITIES: + val = val1 & val2; + /* + * Set RSBA if present on any of the input values to notice the guest + * might run on vulnerable hardware at some point. + */ + val |= (val1 | val2) & ARCH_CAPS_RSBA; + break; + + default: + val = val1 & val2; + break; + } + + return val; +} + +int xc_cpu_policy_calc_compatible(xc_interface *xch, + const xc_cpu_policy_t p1, + const xc_cpu_policy_t p2, + xc_cpu_policy_t out) +{ + xen_cpuid_leaf_t *leaves = NULL, *p1_leaves = NULL, *p2_leaves = NULL; + xen_msr_entry_t *msrs = NULL, *p1_msrs = NULL, *p2_msrs = NULL; + unsigned int nr_leaves, nr_msrs, i, j, index; + unsigned int p1_nr_leaves, p1_nr_msrs, p2_nr_leaves, p2_nr_msrs; + int rc; + + if ( xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs) ) + { + PERROR("Failed to obtain policy info size"); + return -1; + } + + leaves = calloc(nr_leaves, sizeof(*leaves)); + p1_leaves = calloc(nr_leaves, sizeof(*p1_leaves)); + p2_leaves = calloc(nr_leaves, sizeof(*p2_leaves)); + msrs = calloc(nr_msrs, sizeof(*msrs)); + p1_msrs = calloc(nr_msrs, sizeof(*p1_msrs)); + p2_msrs = calloc(nr_msrs, sizeof(*p2_msrs)); + + p1_nr_leaves = p2_nr_leaves = nr_leaves; + p1_nr_msrs = p2_nr_msrs = nr_msrs; + + if ( !leaves || !p1_leaves || !p2_leaves || + !msrs || !p1_msrs || !p2_msrs ) + { + ERROR("Failed to allocate resources"); + errno = ENOMEM; + rc = -1; + goto out; + } + + rc = xc_cpu_policy_serialise(xch, p1, p1_leaves, &p1_nr_leaves, + p1_msrs, &p1_nr_msrs); + if ( rc ) + goto out; + rc = xc_cpu_policy_serialise(xch, p2, p2_leaves, &p2_nr_leaves, + p2_msrs, &p2_nr_msrs); + if ( rc ) + goto out; + + index = 0; + for ( i = 0; i < p1_nr_leaves; i++ ) + for ( j = 0; j < p2_nr_leaves; j++ ) + if ( p1_leaves[i].leaf == p2_leaves[j].leaf && + p1_leaves[i].subleaf == p2_leaves[j].subleaf ) + { + leaves[index].leaf = p1_leaves[i].leaf; + leaves[index].subleaf = p1_leaves[i].subleaf; + leaves[index].a = p1_leaves[i].a & p2_leaves[j].a; + leaves[index].b = p1_leaves[i].b & p2_leaves[j].b; + leaves[index].c = p1_leaves[i].c & p2_leaves[j].c; + leaves[index].d = p1_leaves[i].d & p2_leaves[j].d; + index++; + } + nr_leaves = index; + + index = 0; + for ( i = 0; i < p1_nr_msrs; i++ ) + for ( j = 0; j < p2_nr_msrs; j++ ) + if ( p1_msrs[i].idx == p2_msrs[j].idx ) + { + msrs[index].idx = p1_msrs[i].idx; + msrs[index].val = level_msr(p1_msrs[i].idx, + p1_msrs[i].val, p2_msrs[j].val); + index++; + } + nr_msrs = index; + + rc = deserialize_policy(xch, out, nr_leaves, leaves, nr_msrs, msrs); + if ( rc ) + { + errno = -rc; + rc = -1; + } + + out: + free(leaves); + free(p1_leaves); + free(p2_leaves); + free(msrs); + free(p1_msrs); + free(p2_msrs); + + return rc; +} diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_internal.h index 22b1775b752..53b8939fb5a 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -126,8 +126,6 @@ #define PVSHIM_CMDLINE "pv-shim console=xen,pv" /* Size macros. */ -#define __AC(X,Y) (X##Y) -#define _AC(X,Y) __AC(X,Y) #define MB(_mb) (_AC(_mb, ULL) << 20) #define GB(_gb) (_AC(_gb, ULL) << 30) From patchwork Tue Mar 23 09:58:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157351 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 9FA00C433C1 for ; Tue, 23 Mar 2021 10:01:46 +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 5DDB1619A5 for ; Tue, 23 Mar 2021 10:01:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5DDB1619A5 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.100574.191746 (Exim 4.92) (envelope-from ) id 1lOdqi-0008Pm-LG; Tue, 23 Mar 2021 10:01:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100574.191746; Tue, 23 Mar 2021 10:01:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdqi-0008Pe-Hb; Tue, 23 Mar 2021 10:01:20 +0000 Received: by outflank-mailman (input) for mailman id 100574; Tue, 23 Mar 2021 10:01: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 1lOdqg-0008Eu-GT for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:01:18 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 546e2cf3-4ca8-40b6-8fd8-271706176efc; Tue, 23 Mar 2021 10:01:12 +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: 546e2cf3-4ca8-40b6-8fd8-271706176efc DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493672; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=/Woeth1Qo4qC19JO5EGPKMCsmplx3e3Bv1+R+5k6GM8=; b=JTDGJGWfUZRsIFHsoHBpaLZDtK2n35t1w44/bcr7aZFXAEnXU1HKrfzc yh2iMwNDtl2ouS5Z9lOEvLbVTjxtU02yw7ycZ+MiTZKv2TXMj/6eDUyi8 lGUwdb7CtiDqckKKEeN9j97r8A5tBnGIR/SvRuKwk+kOOMRtd5NkyWrbm g=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: A4PPknK72bCwVwF9v6geA7W2A7lMdgdjTAMz15nEfD9Kj1Gr6XGnJSfhtLEbNdHZdNLKeNy1n2 8Wk3a+dIhabJ8yjtw04s1FsZ4G4n20cB8xdSUjmt51ZBEdaCyl3ONnKtx9JN9MEuognNF60QE9 gOKI95DXJy2UU4lO66JVhYGd3Rwlg0PXjjtNt3sTXlRtezTkixazO/ulZBO4hz9x6bhIHIy8lu 8BYAGVoWZdcexSRa2FtUSVPGBIFTAi4A4s+9es3p2fKdbtQCE6dNtbfDFhV+yOuoygvvOD8Qz5 hTk= X-SBRS: 5.2 X-MesageID: 40261295 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:qPcfFq8VxUJWanqOmeZuk+EKdb1zdoIgy1knxilNYDRIb82VkN 2vlvwH1RnyzA0cQm0khMroAsS9aFnXnKQU3aA6O7C+UA76/Fa5NY0K1/qH/xTMOQ3bstRc26 BpbrRkBLTLZ2RSoM7m7GCDfOoI78KA9MmT69v261dIYUVUZ7p77wF/Yzzrd3FeYAVdH5I2GN 69y6N81lmdUE8aZMi6GXUJNtKrz7H2vanrfAIcAFof4BSO5AnC1JfBDxOa0h0COgk/o4sKzG 6tqW3Ez5Tmid6X4Fv212jf75NZ8eGRt+drNYi3peU+bhnpggasTox9V7OFpyBdmpDS1H8a1O Pijj1lE8Nv627AXmzdm2qT5yDQlAwAxlWn6ViEjWDtqcb0LQhKdfZptMZiXTbyr28D1esMt5 5j7iaimLd8SS7kpmDb4ePFUhl7/3DE2kYKoKoooFF0FbcFZKQ5l/14wGplVK0uMQjd844dHO xnHKjnlYxrWGLfVXzfs2V1qebcJ0gbL1ODSkgGjMSfzyJbqnB/11cZ38wShB47heoAd6U= X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="40261295" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DxSIYiAohgbBF0klDtKHYdqWnvupqP8/NIagBMTq/1K3i5VSj4ev5jxYli4LWqRrivluWM8r/bqeExtddt+SLCRYkVX+lLePKkFbZFNem/qV7btpHUvt0SWCkUoK0h1I7RWR6EBTkxAsu3zySFySKLA3SRvVnoWNC0i1VRUprBAVgN51/gGZnSMPkX4J6SEL59hQhNgtVNCpslf8lFwRK8kHhIyUCJWnwhi0cVoEydHWuoBBDMcwrNE7y232aaxGH3nt1ton7E1ox+9vn5jeP3GUhDMRPL+mqaAPFgqV4wCggGu9hFEMLiWWEpGdyAR1ZbhO2ToP+YpPVmzg09pXew== 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=RlUBOnVeSatdTasqz2pA02ppHxyAvCsUzYnjh93s6fw=; b=cDwW2TkyvklVbV/GUeHZ5rSFJBVkXYCCLmuBNrySCGsIzgX6EFrhEQlExMVDfZg6Kef3MJ1837WC+/E6s34s6d3XRHvDfBH3SiV+KDxWwvjOcRNWhV0xlvxJW6k/Ez5Kjx9TRiM/Ao/J4MfF8Hyq2TM0M00JJ4CFyS55DmJQvmKO8DeDrAMUN09X/cymIVeYmQEaLAuTSL8FKvZ9dcnimm026j03IAK/IoJxvccVtc1GE1hQE+FFAm5jiMyTbjq1+JJFOaCWP2VP7qs8eq00T47MyHkgb4pQz7uWbHezMH5ouhLGyhuNilHtRb6c3P+0xmprfBOE2LptmjZ1Rs+4ww== 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=RlUBOnVeSatdTasqz2pA02ppHxyAvCsUzYnjh93s6fw=; b=JUow7egOyee9RYbfQ/3h7JvTbajg7tkFlWfNKwjJQdGXHf+jrEfnRD/eQPU7ECmnpQFzd1IpAQWXeUDjhY8TII0tC6/Pa2m9m5Ormxb/Lw0QkzJUO4gxsUkeF0yL3HOCWRKnxqIT+gzHDI4kobIDjtIkQ6E+1wFo0vgzEdLTVpU= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 16/21] libs/guest: make a cpu policy compatible with older Xen versions Date: Tue, 23 Mar 2021 10:58:44 +0100 Message-ID: <20210323095849.37858-17-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0121.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:30::13) 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: 3351dc00-b919-4c09-fab6-08d8ede29472 X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:843; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SZn8WarrbgJ2JOZZDmVG9Htb4IGDptJa+sGghFce0AKgoVqaDG/p1PODu42BFjHwaknI7cOmYg1+tqZFkMxYWtdIct1RKf4IKyorcXRtA5cyqReJjScsUHjNZM6c5ga9oWLgpr8GT49SkRsMMT8YO8g9gl/jQM7C+AjIHToe0WHSi6F9+w43BDRk35RvMq4p37HYPYCBQ/OX47zHSnXeL3F5viV07kYiWOr0taWbQmHXgNhDXXP+cbWxMEx6FTPqWR1F81oJCI3dR4erz2zeJsbZL/aGbK6hHvvoo/EPKMTL0DEFbVeKGWQ2lTXHvnSYjoxUB1+E/mkcKn7x2EIx8NQc2fRZBTS2BodtJ4ltUmULjaLu/6Ui+1x4NeiwfidDnODCcNUwW0TLNQsI0l3OLUVJotgEVZ5I2464PxSiXhrCflLtISt0Vv31TJgobkqSB5TApmO0J+PbFCp9NZ9gfzmAru/rqyjCc4xq/18aGypVJMzStrNJjcgWmmJZeQ0kRi/mOTGn5wZLfujIoe2saa7B1aliuuApyda/FrBqC8AwDZCvo19r65SJdorJBTeJxLE/0wePYulhnA+Ydrb6vrMKZ7ylrfC3VtkiCnQ1HRu2MnYiKUKt+Wp82Kb1nP3tSEUZReYbus3OYjVbcfwbCA== 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(83380400001)(6666004)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?CzTxCwg/6m5dGHnikiAEFE52Q7ERhF?= =?utf-8?q?AytGzJT09Fxi1M2xmxEnjvFi9Ah9gh6b9wkfqGtOOOf/jeW52B4bzQPw8RWl0euH1?= =?utf-8?q?KH4tPV/1B1Nj5kDdqsseoS7uhkkgIQizN4tMzF2jX0z71Ul6Tfsh9rvlP66dUs8de?= =?utf-8?q?rqRRPWCJO0tIjKtLphk8sR5x6ITiI81qLfY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//Ys5ZnevWH2D1pe43Kod+H9R0nxzCDnb/?= =?utf-8?q?+uG3kuIhTg9XVQDoA/q6RkANX7eEZaz5eoPpUuBcXUm5EbLWLHUojUA1PsrOcDX7A?= =?utf-8?q?oSU+FefDS0PZe5eAdwX2UQ9jtil3Rxv/Ed9+/O4NHGc+I8+FaFdiBfe+/QzphQLXE?= =?utf-8?q?qTCJVHe4sMKMcNRc3/26f8CWKrJV9240pBnVreWCxo0JA8U+oPyRWXNupM4s24ssd?= =?utf-8?q?Xvbv7MeIn1yK9Z?= X-MS-Exchange-CrossTenant-Network-Message-Id: 3351dc00-b919-4c09-fab6-08d8ede29472 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:01:08.3811 (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: twU6gfn5Hvho/KdLgZ8bWKV3Yw1WtuR3KSkJrnBjiHz8SKr/USrMa599tCnDlhWY4U0ywECJCZ6jB60gGVN9lA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 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é --- tools/include/xenctrl.h | 4 ++++ tools/libs/guest/xg_cpuid_x86.c | 39 ++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 5f3e5e17e9d..6f7158156fa 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2627,6 +2627,10 @@ int xc_cpu_policy_calc_compatible(xc_interface *xch, const xc_cpu_policy_t p2, xc_cpu_policy_t out); +/* Make a policy compatible with previous Xen versions. */ +int xc_cpu_policy_make_compatible(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 4afca3249ba..2abaf400a2b 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -436,6 +436,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 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); @@ -504,12 +505,8 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, */ if ( restore ) { - p->basic.rdrand = test_bit(X86_FEATURE_RDRAND, host_featureset); - - if ( di.hvm ) - { - p->feat.mpx = test_bit(X86_FEATURE_MPX, host_featureset); - } + policy.cpuid = p; + xc_cpu_policy_make_compatible(xch, &policy, di.hvm); } if ( featureset ) @@ -1230,3 +1227,33 @@ int xc_cpu_policy_calc_compatible(xc_interface *xch, return rc; } + +int xc_cpu_policy_make_compatible(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; + } + + policy->cpuid->basic.rdrand = host->cpuid->basic.rdrand; + + if ( hvm ) + policy->cpuid->feat.mpx = host->cpuid->feat.mpx; + + out: + xc_cpu_policy_destroy(host); + return rc; +} From patchwork Tue Mar 23 09:58:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157363 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 E5C1DC433E2 for ; Tue, 23 Mar 2021 10:08: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 69151619AB for ; Tue, 23 Mar 2021 10:08:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 69151619AB 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.100594.191818 (Exim 4.92) (envelope-from ) id 1lOdx2-0000r2-AA; Tue, 23 Mar 2021 10:07:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100594.191818; Tue, 23 Mar 2021 10:07:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdx1-0000qf-S7; Tue, 23 Mar 2021 10:07:51 +0000 Received: by outflank-mailman (input) for mailman id 100594; Tue, 23 Mar 2021 10: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 1lOdqu-0006c2-0R for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:01:32 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f16194ae-ec35-4ed3-b1a4-6f099349c7ba; Tue, 23 Mar 2021 10:01:15 +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: f16194ae-ec35-4ed3-b1a4-6f099349c7ba DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493675; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=1EygkQFfjIgzk70hWDFj486ZCtXSbCWYNcvm9mmxDMs=; b=Ozf1uIghngk8r8/WQZzbn5RV8psjuMy/Pl1KGGqBZ3yWSIxtd45EDBPo 2wZPcOpozEnsXs/+QR/df0Py6tj/Ln/eLgTwmbwTSrtYsq2J65XSPysIP wJ7rnLgkvrRzG1bt/XrH/8GM2neRigGXjOTuRaAW7ZQlKFLh18EIVKZFe A=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: NQY0My0O2GTCI50doOMF5gq8KBDD3yXc98SAgRgzFcAACwc6URUBy/b9tDkemfQ5W2d+Ca+UIo 4g08jRE+YorRqj3rsgkYbw7anf9T2qXm2LqQhgRaEhK14eF5s+wWvtLDC1c0XhENjYwdzCW+eY 0hsVRlT07bLd09UmCyuBi73CIKDudwdmN6OlbnSYj3Hlflj1cwChhvrRky8Z4c6WyYP9UVmdRA YYQ8Z0ePN72+k4NByzRgCQ8Q3qf66p4Dpw1iSARIfwBJedFty5yMDRt79FcZ82vGU0cxa4KE00 PRU= X-SBRS: 5.2 X-MesageID: 41330479 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:4LTdkah422CH3SSo7lssrytgqnBQXzxw3DAbvn1ZSRFFG/Gwv/ uF2NwGyB75jysQUnk8mdaGfJKNW2/Y6IQd2+csFJ+Ydk3DtHGzJI9vqbHjzTrpBjHk+odmup tIW5NVTOf9BV0St6rHySGlDtctx8SG+qi0heHYi0xgVx1udrsI1WdEIyywe3cGIzVuL5w/CZ aa+457vDKmY3sadYCWAXMCUujFqbTw5e/bSDQBAAMq7xTLsCOw5NfBYmKl9zo9cxcK+7ct9m DZjxf0j5/Dj9iXwgLRvlWjlqh+t8DmzrJ4damxo+w0DhmptQqyfoRmXNS5zUEIicWi8kwjnt WJgzpIBbUK11rrcmu4oQTg1mDbuV5EgRKSqi778AjeiPf0WS4gDI55jZ9ZGyGplXYIhs1206 5AwguixvxqJC7H9R6Ng+TgZlVBk0q5pmcaiugDj3BTept2Us4vkaUvuGxSC5sOByT89cQOF/ RvFtjV4LJsfUqddG2xhBgj/PWcGlAIWjuWSEkLvcKYlxBQgXBC1kMdgOgShG0J+p4RQ4RNjt 60fphApfVrdIs7fKh9DOAOTY+cEWrWWy/BN2qUPBDOCLwHE2ilke+33JwFoMWRPLAYxpo7n5 rMFHlCs3QpRk7oAcqSmLVW7xH2RnmnVziF8LAR27FJ/pnHAJb7OyyKT14j1+G6pe8EP8HdU/ GvfL1MBfvOKnbvBJZp0wXyV4I6EwhcbOQl/vIAH36eqMPCLYPn8sbBduzIGbbrGTE4HkPza0 FzHgTbFYFl1ASGS3X4iB/eVzfGYUrk5699F6Dc4qw2wIgJPYtcjxgNhT2Cl4S2AAwHlpZzUF p1IbvhnK/+j3Kx53z042JgPQcYKUpJ/rP6UTdvqRURO035NZYP0u/vNlx67T+iHFtSXsnWGA lQqxBc4qSsNaGdwigkFpaAKWKVj3waoVqQVJcCkqi/5cPoE6lITqoOaehUL0HmBhZ1kQFlpC NocwkfXHLSETvolOGYlpAOPfrecNN9mQ+vBsZRpRvkxAGhjPBqYkFecy+lUMaRjwprYzZPnF V+/5USh6e6lS+1JXEyh/k5N1NweH2aaYg2fDitVcFxoPTGaQtwRWCFiXihhxY/dnHD2m8Sim biRBfkMc3jMx54gDR1w6zq+FR7eiGhZEp2cGl9qpA4P3/BoGxP3eiCYbeT32OdZkAZ+PwUNC jIbFIpU0RT7uHy8CTQtCeJFH0gyJlrA/fUC647darPnlyqM4+FmMg9bohp1acgEOqrlOAFUe iSIVDIaBz5Dv4kwAyTqDIOPjJupHwtjPPv31nE4QGDrQsCKMuXBG4jYbcRZ+y4xSzDYd2j1Z 1il9I7veeqKAzKG5e74JCSSwQGEw/ZpG69cvohpp9Vt58jrbcbJeiobRL4kFV8mCgkJMj6lE kiUL12zbDINIhoZdETcUtijy4UveXKCEMqtwDsa9VOBm0Fvjv+P9mT5aDPpqdqKkqdpBHoMV 33yVwXw971Gw+C36UdEaQ+PCB/b1U98m1r+Kene5fLAAunM8FF81zSCA72TJZtDIyEE64XtB B0/pWhmPKWbTPx3ETohgRAS5g+hVqPcIeVGwKDGelB7ty8NxCtu8KRkbKOpQaybyC6ZUQejZ BCbmoKYK14+38fsLE= X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="41330479" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dCuQPHeg6JqoE6NklkPVLu3VK6h41XTdKg4McfqMVdrErhRctf/D0kc1b+GewHJC21Dk6hOYiYQOL+79DGncRQ3HJ8RqZSrpSrQgFONVB8rs0T00QbE534Y0ioUDGyNtrb6LRGp1gc16Z+ypxFoUaWwaDlIZYyH4frd+UWYBt9ieuVabIwCe290qLwX6JxfwxAfjnKWoN51lfcGpO+XAoNV4hxBofioHG030kXQngI9jBkShmMhNvPVIkShAr7lpAbEAuCr6lwBwe/H/TKifI+ioatiQ1Ib/Uuh/hm2ZCHgGXVmvmvS7DFa8jgg8cPZxfPBsyLaWFuPfqhuQx+MT6g== 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=3MzCUu7d0phi773fHzIkL/rm9IU1nSr6FRF/o5rScJg=; b=TVKbzCYhenaWvFpc6PdNjtAnucSibiYuNFjy7C0cwUyXeBotZFY46LguerAXPD0NUMBVgOKl88EHaJ8qtTfJQ0dWEW9mlU41wW0QuMgm4Kr+eE38zQKdRUGwR9dG+fEwn1b9ncHohKkvSLbuSEFVBl1Ksmy/e+KmuaiGXJMkfwyWg1n2ho/7pHeHQxIDhBeIySMgD5aWohywOuluRc/gCq6cODICaweG5Q6YHpGq6m4iZaUPZZ18UMtnYmQVHsvDrhFE4QOR9dPz9x58724LD/k8RPpNJ1+i24iguuySzYVhzCYLCbdl1C2RmGcae7QVa/QDRqdLFAlfSr5wFs2m6w== 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=3MzCUu7d0phi773fHzIkL/rm9IU1nSr6FRF/o5rScJg=; b=Xa9npiAV6uK6jTWtRpIqa1aONDIoaGhr4Tmap86YOfTz2m9g+SCbMzuhsQJh+idR4xkcZfZmzP/9Bm9T5snqqciDtdcLn6GWHlxlOI6KZFd7sZ5QD7S5e7ZUsuFgySHTQ77/Ahrt+SDBSM62a2smG3/Je2MBwA854zCdp3f7O7I= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 17/21] libs/guest: introduce helper set cpu topology in cpu policy Date: Tue, 23 Mar 2021 10:58:45 +0100 Message-ID: <20210323095849.37858-18-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0124.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:30::16) 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: bcdc9994-d0a8-4d2e-bed0-08d8ede296d1 X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: 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: OjpgtelieldLbBdROZTbEjfus8q7GciP81K5nh+0tGIUI2iyvhtqM67RkthUbUgxX0PG8+wiBwE4+mig5iGhdlCc3KQvH6f4X901XQhtdsPgciCOuHm6jMl059Ee5325cd6707Ci9OsAL+myvIefOQjgzrZqfeV6FCfbv4SLjOMD1rWxOYuwFXBoRExJOf1Csp02xSiUyiI7LjzSuDed4V74WUB0DVhU+5AUAi5YEefpjLz9l18RDEv+EE7lKpxeKc5mUZxOHHcYBcptr7nAoRnyDxMYsQ9dLIel/9p06qJ4JrIt+K/iup6TBmFIKmfS+C73Kn1mkYtDo7q1E4FY0jq1kS5/PUcFzlxTMJbIP6HgCkYHA3uzg9eme8ouqS8IES9ERekwkYvqqiDeG1CmRh++o681a8foKeXrljyIbS19gaMyDOTfBEEGD7siHESGT3QEdLncjgW17UNRgFjiNMPsz7wZYA4/bVSV/BmCjOcZCBdKIDkPmFsrz38P/flCGmyfP68+sN774xBtPtG+TPByTRILOLpm7cEC39KeuNqev031acuKTFFN/oF4CK57jtIoSZ3MpwTBcfV88DEDSsK++DZuw+X9oilM4v0MfAYGmd866WUCObvNZVfy9yoNZsWeufT3lEYKf75KgX9qZg== 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(83380400001)(6666004)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?DwXPVV6lwlDMUEhIYzaE8B1fUMYuqV?= =?utf-8?q?jdxYwaus7/PK3qxuoEYvaPf85zJCPNtmlu8BAvTnBJGJGp61yz2Ju26mfl+HEyd2Y?= =?utf-8?q?gpD5OfBSrrhDvM/XHEpH1va9oHSvntJeRvweG6L1cVcnAOL1r4z3c0uwP/u/dYf4d?= =?utf-8?q?mufhuOr7gVYnTGsEWpy3Y6ydM/S5rTha9CzNHJWsfndCI9U8SZ+q+rJSRHaYNYGmu?= =?utf-8?q?sty0ZK0GMa9VNSm0CTFEfWllnOHfQuW1nGHBl7kyRKAA4gLDTaUqHXIT6Yfq5nE9n?= =?utf-8?q?5Y7dyTJ0Kwr5e3u4YF09T4NZ8acK/GBXEGvmP5smIojgYN3ocfGqRl2C8a+dLJ94n?= =?utf-8?q?4/slvPXpp5NCC0pg3PAtsFKTbXL++ARnEygCBLbUTlQobWd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nnlORYc+uV?= =?utf-8?q?JUg7E3eaMFqOTV?= X-MS-Exchange-CrossTenant-Network-Message-Id: bcdc9994-d0a8-4d2e-bed0-08d8ede296d1 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:01:12.2650 (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: qr+n25OsKlMfAzUVif74wCKJoREMdwoeesqWrY+glNBwqpb+t02D+zE6kdo6mrL197HOyxSCmUj01XgzZ1DWbg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 X-OriginatorOrg: citrix.com This logic is pulled out from xc_cpuid_apply_policy and placed into a separate helper. No functional change intended. Signed-off-by: Roger Pau Monné --- tools/include/xenctrl.h | 4 + tools/libs/guest/xg_cpuid_x86.c | 181 +++++++++++++++++--------------- 2 files changed, 102 insertions(+), 83 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 6f7158156fa..9f94e61523e 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2631,6 +2631,10 @@ int xc_cpu_policy_calc_compatible(xc_interface *xch, int xc_cpu_policy_make_compatible(xc_interface *xch, xc_cpu_policy_t policy, bool hvm); +/* Setup the policy topology. */ +int xc_cpu_policy_topology(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 2abaf400a2b..d50822c0abb 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -433,13 +433,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 = NULL; struct cpuid_policy *p = NULL; struct 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); if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 || di.domid != domid ) @@ -462,22 +460,6 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, (p = calloc(1, sizeof(*p))) == NULL ) goto out; - /* Get the host policy. */ - rc = 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 == ENOBUFS ) - rc = 0; - else - { - PERROR("Failed to obtain host featureset"); - rc = -errno; - goto out; - } - } - /* Get the domain's default policy. */ nr_msrs = 0; rc = get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_default @@ -564,70 +546,10 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, } } - 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 = test_bit(X86_FEATURE_HTT, host_featureset); - p->extd.cmp_legacy = test_bit(X86_FEATURE_CMP_LEGACY, host_featureset); - } - else - { - /* - * Topology for HVM guests is entirely controlled by Xen. For now, we - * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT. - */ - p->basic.htt = true; - p->extd.cmp_legacy = false; - - /* - * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package. - * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid - * overflow. - */ - if ( !(p->basic.lppp & 0x80) ) - p->basic.lppp *= 2; - - switch ( p->x86_vendor ) - { - case X86_VENDOR_INTEL: - for ( i = 0; (p->cache.subleaf[i].type && - i < ARRAY_SIZE(p->cache.raw)); ++i ) - { - p->cache.subleaf[i].cores_per_package = - (p->cache.subleaf[i].cores_per_package << 1) | 1; - p->cache.subleaf[i].threads_per_cache = 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 = 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 != 0 && p->extd.apic_id_size < 0x7 ) - p->extd.apic_id_size++; - - p->extd.nc = (p->extd.nc << 1) | 1; - } - break; - } - } + policy.cpuid = p; + rc = xc_cpu_policy_topology(xch, &policy, di.hvm); + if ( rc ) + goto out; rc = x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves); if ( rc ) @@ -1257,3 +1179,96 @@ int xc_cpu_policy_make_compatible(xc_interface *xch, xc_cpu_policy_t policy, xc_cpu_policy_destroy(host); return rc; } + +int xc_cpu_policy_topology(xc_interface *xch, xc_cpu_policy_t policy, + bool hvm) +{ + if ( !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"); + 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 = host->cpuid->basic.htt; + policy->cpuid->extd.cmp_legacy = host->cpuid->extd.cmp_legacy; + } + else + { + unsigned int i; + + /* + * Topology for HVM guests is entirely controlled by Xen. For now, we + * hardcode APIC_ID = vcpu_id * 2 to give the illusion of no SMT. + */ + policy->cpuid->basic.htt = true; + policy->cpuid->extd.cmp_legacy = false; + + /* + * Leaf 1 EBX[23:16] is Maximum Logical Processors Per Package. + * Update to reflect vLAPIC_ID = vCPU_ID * 2, but make sure to avoid + * overflow. + */ + if ( !(policy->cpuid->basic.lppp & 0x80) ) + policy->cpuid->basic.lppp *= 2; + + switch ( policy->cpuid->x86_vendor ) + { + case X86_VENDOR_INTEL: + for ( i = 0; (policy->cpuid->cache.subleaf[i].type && + i < ARRAY_SIZE(policy->cpuid->cache.raw)); ++i ) + { + policy->cpuid->cache.subleaf[i].cores_per_package = + (policy->cpuid->cache.subleaf[i].cores_per_package << 1) | 1; + policy->cpuid->cache.subleaf[i].threads_per_cache = 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 = 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 != 0 && + policy->cpuid->extd.apic_id_size < 0x7 ) + policy->cpuid->extd.apic_id_size++; + + policy->cpuid->extd.nc = (policy->cpuid->extd.nc << 1) | 1; + } + break; + } + } + + return 0; +} From patchwork Tue Mar 23 09:58:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157349 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 CF004C433DB for ; Tue, 23 Mar 2021 10:01:43 +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 86A5E619A5 for ; Tue, 23 Mar 2021 10:01:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 86A5E619A5 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.100576.191761 (Exim 4.92) (envelope-from ) id 1lOdqm-0008UF-Vm; Tue, 23 Mar 2021 10:01:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100576.191761; Tue, 23 Mar 2021 10:01:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdqm-0008U6-RQ; Tue, 23 Mar 2021 10:01:24 +0000 Received: by outflank-mailman (input) for mailman id 100576; Tue, 23 Mar 2021 10:01:23 +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 1lOdql-0008Eu-Gb for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:01:23 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 873b4118-5e5b-48cb-b00d-f294f73c1ab0; Tue, 23 Mar 2021 10:01:21 +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: 873b4118-5e5b-48cb-b00d-f294f73c1ab0 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493681; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=JEqqKhCzXBW6qHbrKAeTor+WoqPsh+w4N7npvMDHYaI=; b=WBhVzkLvYIs4e6tV5pO1T6TYjgcWwTFwoIy7MttHoCr7PHWHHYD2HIx9 LRSAoN64cwujgd84Y8tNeBmet+j/oUSO5Q/IOYpqodWACwKZn31kYtcCn NiGM8SjicWUfeX4gIC6A5ku/S9lcQVQAzEevHWy4yliKfTi/m5xizMeqy 4=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: eu3bNrFhAMzJJjkq8gmzcFblaLfGCJMJg+infIysrEEoo28BuKZzRilD1DS3JTR84AReX5cXE8 XddaAdzKt3hVz0McTECm2ZWAt5T86bQqlNSEhJyXxxX7yGcPoEmyhiWLK2QjBmznJ+2V3/N0x1 WUYy2cVxhJ0O5XVfTIxDOss15MEQTi5gRSzwQ2C/yhoyYR9n9eZ7RU+v6W2kGsUMwoZhQIgeuP BYRpxGIAvut35IbbknRVnyT/OSFShGBBMvm6fZ7yegqXzvAhMp0RQLAEdLrGo6qNQMIb2yYJOX zyU= X-SBRS: 5.2 X-MesageID: 40055712 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:Bfu7766UnB44deoPnwPXwS6EI+orLtY04lQ7vn1ZYSd+NuSFis Gjm+ka3xfoiDAXHEotg8yEJbPoex3h3LZPy800Ma25VAfr/FGpIoZr8Jf4z1TbdBHW3tV2kZ 1te60WMrHNJHBnkMf35xS5Gd48wN+BtJuln/va0m0Fd2FXQotLhj0JbTqzOEtwWQVAGN4FD5 Ka/MVKvH6Nfn4QY8S9CBA+LpX+jvfMk4/rZgNDOg4/5GC1/EmVwZPZMzzd5BcRVDtT3awvmF KlryXV7riu2svLsyP0+HTU6/1t6b7c4/9iIODJtcQPMDXrjW+TFfVccpmPpio8ru3qyHtCqq i1nz4aM85+62zccwiOyHOHsWSQs0dNmgzf4GSVnGf5pojBTC86YvAx+75xSAfT6EYrobhHoc R29l+e3qAnaS/orWDW4tjFUAxSjUykoXYuuv57tQ0hbaIuLJBWtoAR50VTDdMpGz/78pkuFK 1UANjb/+s+SyLWU1np+k1UhPC8VHU6GRmLBmAEp8yuyjBT2FR01VERysAzlmoJnahNB6Vs1q DhCOBFhbtORsgZYeZWH+EaW/a6DWTLXFblLH+SCU6PLtBHB1v977rMpJkl7uCjf5IFiLEono 7abV9evWkuP2rzFMy12oFR+BylehTyYR3djuVlo7RpsLz1Q7TmdQeZTko1rsemq/IDRuLBXf KeP49XHu/DIWPiFZ0h5Xy8Z7BibV0lFOEFsNcyXFyD5ujRLJfxi+DdePHPYJrheAxUGF/XMz 8mZnzeNc9A5kekVjvTmx7KQU7gfUT54NZVGKje9O4D9ZgVOuR3w00ooGX8wvvOBSxJs6Qwck c7CqjgiLmHqW6/+nuNyGl1JBxHDAJw7K/7W31H4S8GWnmEPooripG6QyR/zXGHLhhwQ4f9Cw hEvWl6/qqxMti33iAtC9WuN0qAlHsNrHe2T5MR85fzpfvNS9cdNNILSaZxHQLEG1heggBxsl pObwcCWwviDD/0sL6ki5YVHenbUNF5jG6QUIppgEOakX/ZidAkR3MdUTLrdcKMmw4hSwBZgU BL/7YFjKCNniuuLmUDkP01WWc8GFi/MfZjNkCodY9UkrfkdEVLQWCGiSezpjszdmDpnn9izl DJHGmxQ7XmE1BdsndX3uLW61tybHyaZF81QGt9q5dBGWPPvWtT3eeHarGo6XaYbkIPz4gmQX b4SApXBjkr68G81RaTljrHKG4vwY82OPfBSJskaLPe1xqWWfq1vJBDO8UR2plrNNrj6LBWFc 2efhKYNzP+BacC3RePqnMsJSlzrz0FnJrTqWjYxVn9+ER6J/zYZGlCbfU8Bfq36mD/XfaG0J ljl7sOzKKNG1S0TuTD8L3daj5IFwjarmG3Rdw5sJw8h9NBiJJDW73gFQbS3H5J3B8CPN75uU MXTqN8+q3AMOZUDrgvUhMc2lIokdiVRXFbyTDeM6sbfVs3iWXcMM7My73UqaA3Cknpnnq6BX Cvtwlc9ezCRS2NyPozDL8xO31fbAwZ5G559O2PM63WBwPCTZAIwHOKdlu8eqRaUq6LBPE5qQ t7+ciBm6uvTBXDsTqgywdTE+Zp6GaoQcS7HQKKF6ppyrWBSCixq5rvxtWygjfxQSa8cGICi+ R+BAotUvg= X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="40055712" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k3b7VeRfzxsoTUrd7vG+Q17Zx9YfiV9BpQ7pPbXCP4vDt8XnEsOElHohp7yEzd3fuEj7W7DRzMGV/V1cXUsXTUR7hJb7WwowBTb/XsD5+tdx+E/oDdav9hfzM/9jISpHURvregdy7G6tJDYzuypi3GOG+kZxpVUCaDgqSxm4LI6Ha1/Pt8dlODlRlQnEDkDcJ6cnIzBRBWwBVreYrHimLGJMUCD1dBFGb1EtKAeqpfk8HerLuzmT2AeoeV4dvjpMAgMrqLuq38c7gnS+aXyrkQATVe3F6PuoFfrFS3TbTb5gEiIlh1MUarVdQKmYwjavUkUL+fMiHg96rVnernYihQ== 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=mdRb+QnYrgGEQMcTps13tpcI68Xa9umSiWj/KPzruTk=; b=brRQTwPON1m8Ujab8hR8nUPJFI2C8FyGsLEw+6y203/3iRen+tx4jRApEoqjwp2Zrz9gqFcupmndqE1m2CyBTgLPOwGygL8Tjq88tCmkl27MS6YH6qNOhSxt4Fk4Q0cwtapjFuBP0UqXMsfo1CetOef9a22fZN1Wlq9OnHzLOeNjbcMwZGO5vVrLfXWijWrA46m9d/BgRvheVVUea/MUYAnlWbbn7oQp/HDCKEpIDcRcW8Lx5V+PjiCLjttIX/CeeRagJdKsDw6VhWjwcSGOSW4Fi5d4BxdS+h5zIqqk2QToZZSJaafuenq8uyk6psr9OHSQ8w8sJkcJl+RXyVgS4w== 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=mdRb+QnYrgGEQMcTps13tpcI68Xa9umSiWj/KPzruTk=; b=TEamV24AxFsN6mVgb7Ilv25t/118jfiXh7qsyQFue39tdsCatpy+BbjQ9ED5JgmNbNlly8JXYdeFKkTUvI7d2Y46u6xcsVeY6U6ARvh6NzBEyXp143kpolxe4ryobCqqp3hOITH3vQ4kaAwgVoj+AhMxhy5Y2LSkWhqCto5T4Wo= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 18/21] libs/guest: rework xc_cpuid_xend_policy Date: Tue, 23 Mar 2021 10:58:46 +0100 Message-ID: <20210323095849.37858-19-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0132.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:30::24) 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: add2c9df-e090-4a3a-1405-08d8ede29a33 X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:64; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AR3kC9/MOD/EPz9y/NVMDmkgwehbXsWhbdGVVLSpxBILgRanA88HcA8m6p9RyuKS/1BhVYFai5HZciz6py+lVUB/n1y8b62VRcwZgFYE1EX9nU1CZdPZP70d01NRsuSTNMLtdfScyqJQNHv8dSgsH0piu/z/gZiVMN4rx0lGc5lYmbSsbLb/l9ZQ+xEtoSbsESXIZ5rrW856Pa29eAdY4M2AhxGPU91WbPOLU9C8iS0vSiIoyyfInMlfr+5FxrzLS6b6iOHCwUb+AJ55XGpwNYDIgOkIJRaPcPuzyp7I/dzo+uh6OaUpyYW4keq8va/memRRPvxdUlEDDWhLNB65PpcFyIMmCdn+G52yHvGn8k6A+eF1AbH4LzjYe7zMKXtYOy6TIBjj7z1L7y8K6ze4L9B65JG40OVF+SHcIjxza9J2nP4z5PrlNPXhkl3ww2VnD58AR8RRQrYLU37K7RZKlBxv3se14ByUXG+gg5Ij2bupOqGUNjmNYbcGrcgipeAxeyZFdArXTBNB31OxdYz1rsreNQY1ayU8kLVFZHiI6m1EVvoD98JA3p5CYXJQ6OgATyOOj1RVoT2JX0J21uXX+PBjuXscooeyqu8tb1Ph6YPChBvDRd2ruADmbzTq3iskKBIcgVGAbu9lZyAYRn42eg== 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(83380400001)(6666004)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?mr/4aWPHAWdHHfSBqIKBOv94Qh6OOA?= =?utf-8?q?ozWNzLVlN3nsBW98s3Oe02JAGCFeCtZ5TcUymc68BtDXUrb75M8IBWDwvB8KviHtR?= =?utf-8?q?hvhLsIkmItssleKPv8l03eWnp9fv+7gSv9PXkIImbn3odq/65PFMOJ1bMyEe4oC5g?= =?utf-8?q?GgJrQXBT8Z5QiUu6FpfeR+UmfETwSg4Zs79Yk20VfxPHw6zQtwGEpi8wWi4UPwsDQ?= =?utf-8?q?cR0jkEisPr8pTv83RqeDhu+ovlUoYIOEY1LSfR5u6wfNtMqkKBNE1bC1pxevd1I84?= =?utf-8?q?xhCQ4B6WoYC6in1v/IWlyWMENu9p4Gad4del6x0CHSdp7gLrmARCi9DwTvUVDqDgt?= =?utf-8?q?c49XVXU0kWlVl227xig6ToLhA9foE63SNum8ouuKwlmSSiph0DDjlQJCTJqAmHOK6?= =?utf-8?q?bFd6Zp4rrjVpJ6KeAGVUZo2hIOdKy1RN2AJmTDpcCawegzVGWWPbLxi4VxooRL343?= =?utf-8?q?mzLtnpPyy5n5LJT/PBCJGCEENN4KifGS12CwUwybOdPJsB/zsiBjpdREafXXjCIt3?= =?utf-8?q?n9P9Kchjkexm/DcNKAG0R1kBWALjSIGI12zHj8xaNsS8FNwWHBA/cIzNe2H0f+k2D?= =?utf-8?q?SdLkWQLq5Ud3fw5+f+S/mCun2CxiWUCQpnJ5m+d0p4Dxe3FBnmRY0PViCdy9Q1Pab?= =?utf-8?q?8yyxIs/POUxx20UQKQsNfVjroYLQ2U9ouaillv5vKT1TUk+clAHET8X8BAZmqVVqO?= =?utf-8?q?ffPmJpuEbYkAiIQx3B2PO+RNGtvxWHCw0mLZmcs0o7SwLjVLbE17Bqbwt+7tDwi+G?= =?utf-8?q?ZiuuORScCCey1LxwpAnR8nv5ZqFYtPnabRIu+SHjMlcj8qwbKHbJpaQXMRVeeGKa3?= =?utf-8?q?FRzEW6fRSxTiIKRc0vwumQYvCtGCXfi8XepomHzctBPn2ZFSPHwkvG4DAfH5sVw/C?= =?utf-8?q?WzlWVInOeFPigKDQaNBcv6i6NRmR+VYL/xfowD1YrcslTykbKj4H5F7TMqey1GF0H?= =?utf-8?q?ZTJZIr9iRBBFSoJFr4K8/bfT0Wz8NS8SPP8tXXaP9YDIqbRDmX1kuGoHKMas8PfmM?= =?utf-8?q?gCb54ai074azNIv++4ovhIT64JzetEKtqTgvPTIiibyMTCbvudxwOBtCcd7Doxdj5?= =?utf-8?q?aXAYzmhu0+Selb3n1SubRG1P5gy9rqn7y/IYauyyMn05Q1nFHZ3TIacPVhcUbBQO/?= =?utf-8?q?FUqCt6x9pmYlVOlnWgsVE/+k0IRNAAH38jfdkMOt7rbFG+6cIKDgSlVCYKWo4dYNw?= =?utf-8?q?XJ4BDlPSUN+gLRT0wOfqqPa/D9+t+cHH4OQlmlXdpT0yAbi+hiJqXyTAgqYHWIxrv?= =?utf-8?q?h3+OzOhDJTpp3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: add2c9df-e090-4a3a-1405-08d8ede29a33 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:01:17.9331 (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: jdOA5dJOU6dijJhJu44CdG1YZI4IqWwIKBg8CFvvLnZJtFOnSvbVkVDLdiZEuouprC6gSonI2w7gxqaZ+RBoMw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 X-OriginatorOrg: 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, since the parsing of a cpu policy in xend format is a layering violation, now the callers should have the necessary helpers to modify an xc_cpu_policy_t themselves. No functional change intended. Signed-off-by: Roger Pau Monné --- tools/include/xenctrl.h | 4 + tools/libs/guest/xg_cpuid_x86.c | 200 +++++++++++++------------------- 2 files changed, 83 insertions(+), 121 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 9f94e61523e..07b8bfc08aa 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2635,6 +2635,10 @@ int xc_cpu_policy_make_compatible(xc_interface *xch, xc_cpu_policy_t policy, int xc_cpu_policy_topology(xc_interface *xch, xc_cpu_policy_t policy, bool hvm); +/* 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_x86.c index d50822c0abb..ce4a4a1a436 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -258,144 +258,107 @@ static int set_domain_cpu_policy(xc_interface *xch, uint32_t domid, return ret; } -static int compare_leaves(const void *l, const void *r) -{ - const xen_cpuid_leaf_t *lhs = l; - const xen_cpuid_leaf_t *rhs = r; - - if ( lhs->leaf != rhs->leaf ) - return lhs->leaf < rhs->leaf ? -1 : 1; - - if ( lhs->subleaf != 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 = { xend->leaf, xend->subleaf }; - - return bsearch(&key, leaves, nr_leaves, sizeof(*leaves), compare_leaves); -} - -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 = -1, err_subleaf = -1, err_msr = -1; - /* - * Three full policies. The host, domain max, and domain current for the - * domain type. - */ - xen_cpuid_leaf_t *host = NULL, *max = NULL, *cur = NULL; - unsigned int nr_host, nr_max, nr_cur; + xc_cpu_policy_t host = NULL, max = NULL; - if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 || - di.domid != domid ) - { - ERROR("Failed to obtain d%d info", domid); - rc = -ESRCH; - goto fail; - } - - rc = xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); - if ( rc ) - { - PERROR("Failed to obtain policy info size"); - rc = -errno; - goto fail; - } - - rc = -ENOMEM; - if ( (host = calloc(nr_leaves, sizeof(*host))) == NULL || - (max = calloc(nr_leaves, sizeof(*max))) == NULL || - (cur = calloc(nr_leaves, sizeof(*cur))) == NULL ) - { - ERROR("Unable to allocate memory for %u CPUID leaves", nr_leaves); - goto fail; - } - - /* Get the domain's current policy. */ - nr_msrs = 0; - nr_cur = nr_leaves; - rc = get_domain_cpu_policy(xch, domid, &nr_cur, cur, &nr_msrs, NULL); - if ( rc ) + host = xc_cpu_policy_init(); + max = xc_cpu_policy_init(); + if ( !host || !max ) { - PERROR("Failed to obtain d%d current policy", domid); - rc = -errno; - goto fail; + PERROR("Failed to init policies"); + rc = -ENOMEM; + goto out; } /* Get the domain's max policy. */ - nr_msrs = 0; - nr_max = nr_leaves; - rc = get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_max + rc = xc_cpu_policy_get_system(xch, hvm ? XEN_SYSCTL_cpu_policy_hvm_max : XEN_SYSCTL_cpu_policy_pv_max, - &nr_max, max, &nr_msrs, NULL); + max); if ( rc ) { - PERROR("Failed to obtain %s max policy", di.hvm ? "hvm" : "pv"); - rc = -errno; - goto fail; + PERROR("Failed to obtain %s max policy", hvm ? "hvm" : "pv"); + goto out; } /* Get the host policy. */ - nr_msrs = 0; - nr_host = nr_leaves; - rc = get_system_cpu_policy(xch, XEN_SYSCTL_cpu_policy_host, - &nr_host, host, &nr_msrs, NULL); + rc = xc_cpu_policy_get_system(xch, XEN_SYSCTL_cpu_policy_host, host); if ( rc ) { PERROR("Failed to obtain host policy"); - rc = -errno; - goto fail; + goto out; } rc = -EINVAL; - for ( ; xend->leaf != XEN_CPUID_INPUT_UNUSED; ++xend ) + for ( ; cpuid->leaf != XEN_CPUID_INPUT_UNUSED; ++cpuid ) { - xen_cpuid_leaf_t *cur_leaf = find_leaf(cur, nr_cur, xend); - const xen_cpuid_leaf_t *max_leaf = find_leaf(max, nr_max, xend); - const xen_cpuid_leaf_t *host_leaf = find_leaf(host, nr_host, xend); + xen_cpuid_leaf_t cur_leaf; + xen_cpuid_leaf_t max_leaf; + xen_cpuid_leaf_t host_leaf; - if ( cur_leaf == NULL || max_leaf == NULL || host_leaf == NULL ) + rc = xc_cpu_policy_get_cpuid(xch, policy, cpuid->leaf, cpuid->subleaf, + &cur_leaf); + if ( rc ) + { + ERROR("Failed to get current policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + goto out; + } + rc = xc_cpu_policy_get_cpuid(xch, max, cpuid->leaf, cpuid->subleaf, + &max_leaf); + if ( rc ) { - ERROR("Missing leaf %#x, subleaf %#x", xend->leaf, xend->subleaf); - goto fail; + ERROR("Failed to get max policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + goto out; + } + rc = xc_cpu_policy_get_cpuid(xch, host, cpuid->leaf, cpuid->subleaf, + &host_leaf); + if ( rc ) + { + ERROR("Failed to get host policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + goto out; } - for ( unsigned int i = 0; i < ARRAY_SIZE(xend->policy); i++ ) + for ( unsigned int i = 0; i < ARRAY_SIZE(cpuid->policy); i++ ) { - uint32_t *cur_reg = &cur_leaf->a + i; - const uint32_t *max_reg = &max_leaf->a + i; - const uint32_t *host_reg = &host_leaf->a + i; + uint32_t *cur_reg = &cur_leaf.a + i; + const uint32_t *max_reg = &max_leaf.a + i; + const uint32_t *host_reg = &host_leaf.a + i; - if ( xend->policy[i] == NULL ) + if ( cpuid->policy[i] == NULL ) continue; for ( unsigned int j = 0; j < 32; j++ ) { bool val; - if ( xend->policy[i][j] == '1' ) + switch ( cpuid->policy[i][j] ) + { + case '1': val = true; - else if ( xend->policy[i][j] == '0' ) + break; + + case '0': val = false; - else if ( xend->policy[i][j] == 'x' ) + break; + + case 'x': val = test_bit(31 - j, max_reg); - else if ( xend->policy[i][j] == 'k' || - xend->policy[i][j] == 's' ) + break; + + case 'k': + case 's': val = 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; } clear_bit(31 - j, cur_reg); @@ -403,25 +366,19 @@ static int xc_cpuid_xend_policy( set_bit(31 - j, cur_reg); } } - } - /* Feed the transformed currrent policy back up to Xen. */ - rc = 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 = -errno; - goto fail; + rc = 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; + } } - /* Success! */ - - fail: - free(cur); - free(max); - free(host); + out: + xc_cpu_policy_destroy(max); + xc_cpu_policy_destroy(host); return rc; } @@ -429,7 +386,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_features, 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; @@ -551,6 +508,10 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, if ( rc ) goto out; + rc = xc_cpu_policy_apply_cpuid(xch, &policy, cpuid, di.hvm); + if ( rc ) + goto out; + rc = x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves); if ( rc ) { @@ -568,9 +529,6 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, goto out; } - if ( xend && (rc = xc_cpuid_xend_policy(xch, domid, xend)) ) - goto out; - rc = 0; out: From patchwork Tue Mar 23 09:58:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157355 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 3C71AC433C1 for ; Tue, 23 Mar 2021 10:07:53 +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 DF20D619AB for ; Tue, 23 Mar 2021 10:07:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF20D619AB 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.100582.191773 (Exim 4.92) (envelope-from ) id 1lOdwo-0000db-QO; Tue, 23 Mar 2021 10:07:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100582.191773; Tue, 23 Mar 2021 10:07:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdwo-0000dU-NP; Tue, 23 Mar 2021 10:07:38 +0000 Received: by outflank-mailman (input) for mailman id 100582; Tue, 23 Mar 2021 10:07:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdr9-0006c2-1B for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:01:47 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cce34c28-814a-474a-b18c-56b37af096c9; Tue, 23 Mar 2021 10:01:37 +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: cce34c28-814a-474a-b18c-56b37af096c9 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493697; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=elgicdoLLjyAPG6mTxXmUlhWyWbTk4KjmQet+vnO69Q=; b=DZkitnqXKuZBiIC1A9HeW2mmWTxmekPiKQcU0Ii+3ainK8Rf2ygpK0Dh bqPLZaFZpnb6i8ltZagZGa/B5yxzQ5f6QuY4B+tGbjcelmW3fZje9HoDl Ck92fAWWsbMUyArW7W/hAEnMnYyn0yA7zm4mXm8nYpOlcZvJaS29ha7Hv A=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: DK49BHw+0b9sC4ZyTccq2A1VcLd2uJ38RZw+M7GYiGZWsQJZrYU9+IQlTPLx93pQg4SHNHvmYi ZhSrtiQTEnTAaPluhln1G1WFLXrChiT9uKmInCdIsgQW2FP84COtMeVuQBE2hwPz35GlfueSfQ KHrcem9qGl83v0RKMmjKMMH8pT5RBiNY+1uWBC2j/TkeP2RALVafPd1C0x32ljqJVeet9f4GIN mZDLQz4n1rZ+G/5RWYriaBG+ubMhziy3HU4PlWoDzpHVFFuMrVYxZ0/GRh65b42DXnyIh/zh5v e34= X-SBRS: 5.2 X-MesageID: 39900444 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:oW3gKaFSjQIIj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GrpJAD6IY5hulqnxdBt9SnqLgjKmmwg+E1CahHk6ty jEF2m5aPvLCl1StjRj3qHm/EhdW0+dc0hzA0oK+rFVJCDjgDJewOWLbq283y+tcVME2PgaKy yASyAVOBlSy9e+0wO1lD6OGW49/IgnOvXQAd0YAvfu80LoDLfNubANHvdS8pogCcvntfUTV/ mDPyCSNzH1BooSqnqoj0dgHBMxjnYqkfnlgkK4qEe52WMyGvrULhBNQaoBL9SV8mjjQLKp3f xC/KYIlNr1Fl+0TNiMjZzzRXpkDDj4pGatVeEmqZxOp8sJxfNONqiedQGN7W1N2RU1Edz9m0 wfSplq+bypAP4bQ+UiPwZiumcznNuBLEEXohX7L+83c1YqlWLaNbqyks31gItqJkWAoQfqUG PvixF1zrPgXyGZ06QdBL91CWNKaFIk4HAKxpLJS6TgTCGrffpE5ly0LzuUd6JcUrGMHfE1og xh69+F28+ReCyQ4nGcgRJLZoZP+X2gW8W8HUalHvNJ6cWzPRC0uZSRifTDxQvfeH+ccEQXhY pMaEwWYIBis1AZ/fIK+xn3bLf2rEIjm0ZZ+hd9mDfWq9Gb3Fs= X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="39900444" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AOKtNw58QdCQiPzStDBaWTYixloQZO3WhTzwSha0l2L+yqOqK7eLXwMClH/Sc8yoJrGlyOTL8skRLJlEswRFCVsX2cc+UkpHJNzGH7q+bMDspwMUCDrzkDLOHB1uoVdTPJxUPc3R7Z11D7bAaRJTzZ3ltCbmXsaVLWz/EF2WLOlu/YXLHYju71SF2LYfAsASq/6Tcdsj9uoEVspyX4HNxy0COdZeuKteDEuLN3XSO8oLLZzFgQniRPpnmFX4XYUX2CnlVtLHnE9YXZqhqxqA2DFmvudPO/kqroggalKwczInL7sffFEmNH4gHjyNP4ubfWTbekqm/IhhXBVLk16MkQ== 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=/sAstwZ3FZzzgYovYIPvWV/JpZRMk/Un8JhdEN4a52A=; b=I+LsnmI+QZuBTFfTCX1N51EhE8BeG0Ap/QAf/GtoYaY3g8XKKGbJZNCccGcpvhe0I1GU1EsVYZfLMD5AOpCZOT6nAkcfQ2DZ/doWubd5bGKU/CuJJJgAfh9JIrMEaK5eWPNEOUEVUNGjnEhkHKMvRBlu3d3QP2qrRdJGvM8JMC1SE/bEVk634mag7Y8QcY+hc7ee//pTz26/I4jDmlpG/PVOed388hsBi81dTGJ1Zq4q9dHNE68aQojhB0FXT9wTGRcthDZg7k0iaL9O7VfAh0Qpbhv1aXzDQz+cVtDngWZjMNpI1oHd0P7lN+WxkKxqs8RbZ7e4xQK1s/b8xz+ffg== 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=/sAstwZ3FZzzgYovYIPvWV/JpZRMk/Un8JhdEN4a52A=; b=Ajs2cmCZbeBkD9V2vWhH4FMyo1DhToX0513zehcMUlAFgQrhqn3Ot5UUs/BD06FbwQ7VHH4WoRdiM3OGp9QaHhv6DVmkbcX8C0qMPOieZzdWZARkzga+TrHWd+oFKQQZrt5TM4QOsCCuLuwpLXSiMQxPMORYxcH81WZctuhaMzU= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH 19/21] libs/guest: apply a featureset into a cpu policy Date: Tue, 23 Mar 2021 10:58:47 +0100 Message-ID: <20210323095849.37858-20-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: MR2P264CA0126.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:30::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: d14b9d14-0391-40b2-09f2-08d8ede29d6f X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: 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: RTkijCKJ1KFTtE8o9PKnBhvssfJyfO7/cpwRLa5J8yvfBPQ8YkqZ+o/2AxWZuFoIGu3KajxME3ooQj7kAcbgEXS2hxjMl3PtghpU4ExZgYYSWTauTjdYTxF5rwwgoS16pSv9Wvu9qvU6N1ltDVNnXIbspBV5AiEfWwTrVI6tWF1xq9khhK7mtUZVXwTRiCl0ObmzxS5wnxc8pmRbO7KZuG/GhHUqsV5dmxEVNCy27rBukBNA44nDJSc3B3dcJSrG2sLr/Zv5awdKZL+Zr3mMWDF+rRXWZkTHDR6Amky2FjKZP6eSoOkAfTxFNGVBqenYxuUWFdy9QNqkAIOSY4L2OUv6Xl97EIg1+cx/PPE+qaM+nKOGM6MSmEx43TuunzBmyAFVw+a9uKGD8sZjBDCe9iw9h08RBI6AoO6eGw2kxgArm1FjWJRh8WmtVES/B8pCChEOIEmnqRAOrLgpN2naIKtJYBgmV84qJwo35a8mAnT3DQySZBqyHPsNBw+6g112DO7cwrZb3ATLF757aSm5K2ZtqV5EgVtTf4OLOmif3J+IX0s296Ie7ja4w1TFf6faEwRE5bq3FHREUKToVRSFUQSZdS3c+HByjSTNJO8GDPX5EWrird9jrasJh2ocSVUVTsSqi3EgrNh7SjzXJpRtmw== 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(8936002)(6496006)(38100700001)(83380400001)(6666004)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?lKM3+Zaf4mGKmu+QfsFN+AqsySFpqX?= =?utf-8?q?pKrapMIv4SzPZe91gK9wpHHcPWEnAqNyTv1ErSevhUYJUI+ZEwmvd5V3nF5fTCRrP?= =?utf-8?q?QRnY8Xm9FEZY3ezNHZGqoKihqjucdYSBEtnpyEmML4UCWKlY2WJ+5VpNdflp3S/MK?= =?utf-8?q?qlIXWoeeUutbSBhKx8FKOFYRHBS9agN2K2NF5g3ECnBGi2z4YQK2LMiZE2s6rN8xC?= =?utf-8?q?PuJGOFk/f8gYC1zxBBv1ntqP8TvLyWcSXM8M9V06T3v2s5DqEZVXapWcUyP7j1qdr?= =?utf-8?q?Vg9OLeOKmS5eqmJF5p/nTFhxUxJIarXIITzbs6N4Sw7kuc4XN4JGzoaYO4GyTIm9p?= =?utf-8?q?VGQj7T4d/cfRRly1BxgKW8hs9/dZMZws8Xye25bPH0WXJZvJvsN75WMlC45EN37ou?= =?utf-8?q?dxanBTJ5mRAVJR113PuQmofjZipHGo2yj8Eu7CBh3Enp8r0ydhoXZ6FuzWm2Cyere?= =?utf-8?q?CxwyfXlJ6B2AvY6M09ayTCezkmr9QoXgkrKT0bIMDW3JTgPX98UKiiulIY5hnBzw8?= =?utf-8?q?bvJzRth5J7J6a0bLU14IQnD25j1Dg4HmlXNqw2cvcxnTyScV3kn0WvzHSBnoJVqv8?= =?utf-8?q?ex1khmlRz+9+WTKedVpb5YleD1VZbbKKDOQFVMHnxuiHIG72AsfQY2fR3/S1uP6Fb?= =?utf-8?q?/8Ww6aSzqrR6YIouxDMt5WEqELM10V+tNG0ICvWg8zXBpowuJtZ4PDlsItRxznd+y?= =?utf-8?q?LiURLv+Jhxknk0zCTf+sUshTqUSr41ctdNKUN7nieBmMGp+hcKzRNuEOJg9s7pg1F?= =?utf-8?q?xDDp6Gdm1WkUrd18Eb6Uu1ZnmmK7ZsGZ1+cRrMbXOlsygWmNgAnvqnoqrumHOyHym?= =?utf-8?q?1vXh0EjCUzUZr7Ewlt422FBq5C1Mu4YedoPYvYecy/hOnJlCRv9TMQ7vdOQUNGGRO?= =?utf-8?q?AeTfNVAm22tIt06O0aBEtzCnqaL9T3f1rxfCgnlUu/qpsJUSQDK19xh6wjY2xYliG?= =?utf-8?q?DVU0UQaJPFJJyIFkOsO3mVriVkH3PElwdH9/H+CZNr+9EJCUZ8xInsQ9G8aywxCQs?= =?utf-8?q?Om1pmc05HMy5WbrkoY/TLsYh5vxJGPYWjXx71lU/OHcroLsM892RI16WXORqo4wLp?= =?utf-8?q?aH16bB+/IT2GZW8a9AaGfgPBiFCFYZ8N4D0pjNML2pZ9HwccCW/6nooxLv1sGkayv?= =?utf-8?q?nctaodBj05Fe8O93uNCXhssmmh3QAoakv+KR15qkQfl0njzBdVK4/szmnpvvd3Ilq?= =?utf-8?q?L8SHOLtxgKFDREfAVFYaGnvh4wyyqUqtjQic18ZVOlXTAiIgLZczEw4//k6vho3dM?= =?utf-8?q?JGsCKRmd+TnB6q?= X-MS-Exchange-CrossTenant-Network-Message-Id: d14b9d14-0391-40b2-09f2-08d8ede29d6f X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:01:23.3851 (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: yeDoZ/E7oFk2udtTDTughx7lpIwXtbR5DlwlcXptKtz3yBpdFrW39UgbLZt2mnjUStF1ySzMQNZVxnbgBenWGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 X-OriginatorOrg: 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é --- tools/include/xenctrl.h | 5 ++ tools/libs/guest/xg_cpuid_x86.c | 94 ++++++++++++++++++++------------- 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 07b8bfc08aa..a830fac1d12 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2639,6 +2639,11 @@ int xc_cpu_policy_topology(xc_interface *xch, xc_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); +/* Apply a featureset to the policy. */ +int xc_cpu_policy_apply_featureset(xc_interface *xch, xc_cpu_policy_t policy, + 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_x86.c index ce4a4a1a436..96b969342fa 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -450,46 +450,14 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, if ( featureset ) { - uint32_t disabled_features[FEATURESET_NR_ENTRIES], - feat[FEATURESET_NR_ENTRIES] = {}; - static const uint32_t deep_features[] = 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 = min(FEATURESET_NR_ENTRIES + 0u, nr_features); - - /* Check for truncated set bits. */ - rc = -EOPNOTSUPP; - for ( i = user_len; i < nr_features; ++i ) - if ( featureset[i] != 0 ) - goto out; - - memcpy(feat, featureset, sizeof(*featureset) * user_len); - - /* Disable deep dependencies of disabled features. */ - for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i ) - disabled_features[i] = ~feat[i] & deep_features[i]; - - for ( b = 0; b < sizeof(disabled_features) * CHAR_BIT; ++b ) + policy.cpuid = p; + rc = xc_cpu_policy_apply_featureset(xch, &policy, featureset, + nr_features); + if ( rc ) { - const uint32_t *dfs; - - if ( !test_bit(b, disabled_features) || - !(dfs = x86_cpuid_lookup_deep_deps(b)) ) - continue; - - for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i ) - { - feat[i] &= ~dfs[i]; - disabled_features[i] &= ~dfs[i]; - } + ERROR("Failed to apply featureset to policy"); + goto out; } - - cpuid_featureset_to_policy(feat, p); } else { @@ -1230,3 +1198,53 @@ int xc_cpu_policy_topology(xc_interface *xch, xc_cpu_policy_t policy, return 0; } + +int xc_cpu_policy_apply_featureset(xc_interface *xch, xc_cpu_policy_t policy, + const uint32_t *featureset, + unsigned int nr_features) +{ + uint32_t disabled_features[FEATURESET_NR_ENTRIES], + feat[FEATURESET_NR_ENTRIES] = {}; + static const uint32_t deep_features[] = 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 = min(FEATURESET_NR_ENTRIES + 0u, nr_features); + + /* Check for truncated set bits. */ + for ( i = user_len; i < nr_features; ++i ) + if ( featureset[i] != 0 ) + { + errno = EOPNOTSUPP; + return -1; + } + + memcpy(feat, featureset, sizeof(*featureset) * user_len); + + /* Disable deep dependencies of disabled features. */ + for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i ) + disabled_features[i] = ~feat[i] & deep_features[i]; + + for ( b = 0; b < sizeof(disabled_features) * CHAR_BIT; ++b ) + { + const uint32_t *dfs; + + if ( !test_bit(b, disabled_features) || + !(dfs = x86_cpuid_lookup_deep_deps(b)) ) + continue; + + for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i ) + { + feat[i] &= ~dfs[i]; + disabled_features[i] &= ~dfs[i]; + } + } + + cpuid_featureset_to_policy(feat, policy->cpuid); + + return 0; +} From patchwork Tue Mar 23 09:58:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157359 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 F0709C433DB for ; Tue, 23 Mar 2021 10:07:59 +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 A757F619AB for ; Tue, 23 Mar 2021 10:07:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A757F619AB 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.100589.191794 (Exim 4.92) (envelope-from ) id 1lOdx0-0000me-LH; Tue, 23 Mar 2021 10:07:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100589.191794; Tue, 23 Mar 2021 10: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 1lOdx0-0000mV-AW; Tue, 23 Mar 2021 10:07:50 +0000 Received: by outflank-mailman (input) for mailman id 100589; Tue, 23 Mar 2021 10:07:48 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdrY-0006c2-1p for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:02:12 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 62d07dfd-584d-4ade-ba26-d97a9f62589c; Tue, 23 Mar 2021 10:01:48 +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: 62d07dfd-584d-4ade-ba26-d97a9f62589c DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493707; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=nS2izB/wMYNzEri//vlEUg8wYiGwzGHZuOBvg6gJjNY=; b=BI23oKd9eV1jPdgoWfeblsJDN9wrpp6kiMtcvl0C7SGAGvCVv8hXEdrQ DVtBofD0nhwEBvBUfiShjbQRivoUUZn3bwvMVl1RT9amIJKHkkxN5mZ/P fy2btkjidmuKyuMOLBD7QnWieuIlA44Vw3WPa6DK611Q6KKq+ctQibzV6 8=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: y2Nkz9I8NkfXTlEo3pOotCr2R230RJXgRk78uP/XeJASRT9gk8K3HfyOLoPVJZxokpMe1U0nEX ekp/mOfkcHEeOrPT5xDgQjpTnOaAJx38LTTtMNippTv+4/vxPyyLjqqXv4r7wdMnR4Jq8XY5pO P5Z2sboKv/CZJCsjhYAoNddN9/O/Jhe8KO9pF9fkoAi7ePP9H0BwKh7ZoBhQClMOaFdvdxhKsg 9FoAD7G3O7Cag899sFl1AErKaIz/GaDJI9tqqXCqvasJGMX5uoB+cQJjT0ZCNaOomkFzZOMgLA fIw= X-SBRS: 5.2 X-MesageID: 40055730 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:EAyTXakB+4i8y9HlFXsw1yB9Z1/pDfOpj2dD5ilNYBxZY6Wkvu iUtrAyyQL0hDENWHsphNCHP+26TWnB8INuiLN/AZ6LZyOjnGezNolt4c/ZwzPmEzDj7eI178 tdWoBEIpnLAVB+5PyW3CCRD8sgzN6b8KqhmOfZyDNXQRt3brx7hj0ZNi+wOCRNNW17LLA+E4 eR4dcCmiGpfm4ZYt/+Kn4OWeXCoNOjruObXTctARk75A6SyQ658bKSKWnk4j4ycRNqhY0j/2 /MjhDj6syY3c2T5xfA2wbonvJrsfT7zN8rPr3vtuE0LXHWhh+sdMBdXdS5zUsIicWOzHpvr9 XWuRcnOK1ImgPsV0W4uwHk1QWl8BtG0Q6a9XaijXHuodP0SVsBYqIr7+IpEWqq12MasN5xy6 5N1W6C3qAndy/opyjh+8POEyhji0vcmwtSrccok3ddXYECAYUhyrA3wUU9KuZkIAvKrKojEO VoEfjG4udXfV6wfxnizxdS6e3pcXIpEhicRE8e/uSTzj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1giuaaPL3JAKHAuhT9dOmfXyKn6ux+ca2yA7NdgHTUTVQua R1MWoKbspCjTE+jIo4lgiKI5aH3X4Noh95+jFollnkx468xnzUdHs2aDHkvg== X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="40055730" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ede7H1yc7gXevCIdFx3ZqT32NSvBjcHYd9c0T+FcOpa6+saO76p2yvbmsy6v4tr2/3MCIExiO6dZkse30qPUmXHqahh32Cykyy9Op0Km79ALGARnOaEbTdDBqgaUWcvxHgpzjJkFKR7+EhbkGGMRWOPi/B8euYP4q0iQ6Lqt7EAnQ32aGddc9H9CHr2VZxok8g4QPBM/4ems2zORYCVNLOE6FNUXWu1/51TCLlIbRbXQE44OCaKijJecajAZ3MGMv9IJNtUYPme5TC7Blwt7ClTsW0KSEfmUnPx0prBPf35lA5+7OJCvoXVS9dzGImqGH6BK1uGdS2TmZFw71JZ8UA== 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=0q/89uigaDgolgby8oRhEV72/0m8hoezhu+aa5CjkiI=; b=a3ZZc0sK+Y77KfJTe6OCEw3mIi8fY6fdWCgIZx3WpuN06dgaoWU6MZt72oDApRNgbVuVn9Bk/09tYWOX/pN2yKKBDJr/U0oAYE6gIBQlrvOO24DefsDD5ZRTJAHKaJblfUwCKyI3E9s2ETnp35V7hdeyo6T3z69dVUo6T7a5QuHEOOlxrscJql1jG2dn5ffajwxCrXOEiv21IXtJXU4xoAT3L31iiJhm+82jmdF8jjf1iWppgdzcpB8dbtClOXJIDUcVISG5tnhMJTVBKN5kQ4+1IVTUQ/IjCbeFNiMHBQQ2sR6X/V0xmAlkTft5uAhhmwEw5f3OH1VH3KQKTCKwTQ== 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=0q/89uigaDgolgby8oRhEV72/0m8hoezhu+aa5CjkiI=; b=B0sGhjU0dy0yK5rTJbvQUWtUPuF8T62Ts8kEYK5sIM6wU9p7l9Ww6fDpurN7vMiWU/A5sdEwN3qSdg6LSk9p9l7JHbCmfAXEHJH1r2S+EzasC6l3V7It+HyiDQV+cfhW49XOnnK23Q8vrNcWg1FLR1LkiRJjOJeteTYvAUn3PwA= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 20/21] libs/{light,guest}: implement xc_cpuid_apply_policy in libxl Date: Tue, 23 Mar 2021 10:58:48 +0100 Message-ID: <20210323095849.37858-21-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: PR0P264CA0191.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1c::35) 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: 690eef40-92ab-4d05-0636-08d8ede2a104 X-MS-TrafficTypeDiagnostic: DM6PR03MB4969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:267; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +kQJVZLBh4jKzhRwMdk67ZsVyijt2xghim6PT/BS9GEmWaj6tTe2oZx5D286ga/BUhMf5X0I+/z7wkznY7IeIUCmQZ1wAJcyJHQ0sLyNOTNCq7lnA3lnEm5eNJCQW80c3zdQLxoTwhScSFEpyftmffu74Khk+aNOWywwFhAJy/s7utiUfMPlPm8eaJlTNmfwGnXwOrLHV1NBo5JSj/pmAg+KzAympW1ZIvHfLZLUe5coY7EJDtEQC7mEXtQ2/aNBF1q/S/7PbruXZvUqHyvyfl7UVOJnQWJhtgqPLl3tI/RgsYMD5GUO1W11UJY/FFJ5UkTjEipJKfEu6XVfGaD+5iWMBkxrSz0I7bhM+aeEI+3BNe7SrNlPvEXw6KYzmwUY9m3UrwWrMLk6FWIs0NgTrvNb0Vg3FwapvMD7QRlnj5nbhXB0LpmHAc8hB7PU7ax7Xx/98N9SBYd8X3f5Sq6c8sQ4SysZAlYqBTCnCCiWu4VGYRU0CZYIj+rSXtlc/XN6t+JyUODFUhtxfjLSujcDs2gdL52h8lkYDbOHbw8O0nA1rPGpkFfbcgiD99BzBkC/394eJxRc1RfPr0QuIwsGoGl/d6oiINMURtYQb8+rrM1RItv1CBykMRkyTPPgQ3g0/O2yfwNdJM/cePA8uYYjeQ== 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)(136003)(376002)(396003)(346002)(39860400002)(54906003)(36756003)(2616005)(316002)(26005)(6486002)(956004)(16526019)(186003)(2906002)(86362001)(66556008)(6916009)(478600001)(5660300002)(107886003)(8936002)(6496006)(38100700001)(83380400001)(6666004)(66476007)(8676002)(66946007)(1076003)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?SK+v5X5s8+jJPnqSqcWuN+851YJ6Et?= =?utf-8?q?EDSWWvNwqDDf8y9py2FisX4puZtIMmh24MJx3WDxJuN5ND7IvaHL9tb9fv+eIL2+p?= =?utf-8?q?TrD2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vGlkxaO5vivXWhRkpBdTMh30tCkysx7soxIjZMuhaCRI+efPqPz94gJLAE5h5?= =?utf-8?q?hSzhliFbnQThDUsAcbRiZ6HtLigIMlcwuD8yOMyEHueOEin1McVxuL1bqWnphxTww?= =?utf-8?q?0fYXJIRxeWwicSNYvIue2uAQ3eL7bfX1yYvDlTIZWtDOQtQpwvoA9QtpyYvGibWlt?= =?utf-8?q?Iu5tDuigDKlGBYZKuvaUL4FH1gpfZJCDmVb+MALcXyIWMxyaYm8c2XlhSsF7q4/92?= =?utf-8?q?lYHXqYAsK4mK69OkZqGF5T0b/NZJCpCRiKInjZA7He5BHv7BErj/FfzrvVmgj0v68?= =?utf-8?q?Sk9obfPYKFzgcQ?= X-MS-Exchange-CrossTenant-Network-Message-Id: 690eef40-92ab-4d05-0636-08d8ede2a104 X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:01:29.3887 (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: 1iX3tVQlntxM3xh0OTc4ljD4asklIUZCEeo4c94FhstTtqE4joX7cyPLWjIc+mFIKy3wQA0EGxJnk0SXxIn9kw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB4969 X-OriginatorOrg: 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é --- I'm unsure why this is called libxl__cpuid_legacy, mostly because I don't seem to be able to spot a libxl__cpuid (ie: non-legacy version). Should this be renamed to libxl__cpuid? 1b3cec69bf300e012a mentions the process of switching to a new cpuid interface, but I'm not sure we need to keep libxl__cpuid_legacy, since that's an internal interface that's not exposed to libxl clients anyway. --- tools/include/xenctrl.h | 18 ----- tools/libs/guest/xg_cpuid_x86.c | 123 -------------------------------- tools/libs/light/libxl_cpuid.c | 87 ++++++++++++++++++++-- 3 files changed, 83 insertions(+), 145 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index a830fac1d12..5a576f72b4d 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1890,24 +1890,6 @@ struct xc_xend_cpuid { char *policy[4]; }; -/* - * 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 individual - * 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 *xend); 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_x86.c index 96b969342fa..dffb9923b33 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -383,129 +383,6 @@ int xc_cpu_policy_apply_cpuid(xc_interface *xch, xc_cpu_policy_t policy, return rc; } -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 *cpuid) -{ - int rc; - xc_dominfo_t di; - unsigned int nr_leaves, nr_msrs; - xen_cpuid_leaf_t *leaves = NULL; - struct cpuid_policy *p = NULL; - struct cpu_policy policy = { }; - uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1; - - if ( xc_domain_getinfo(xch, domid, 1, &di) != 1 || - di.domid != domid ) - { - ERROR("Failed to obtain d%d info", domid); - rc = -ESRCH; - goto out; - } - - rc = xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); - if ( rc ) - { - PERROR("Failed to obtain policy info size"); - rc = -errno; - goto out; - } - - rc = -ENOMEM; - if ( (leaves = calloc(nr_leaves, sizeof(*leaves))) == NULL || - (p = calloc(1, sizeof(*p))) == NULL ) - goto out; - - /* Get the domain's default policy. */ - nr_msrs = 0; - rc = get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_default - : XEN_SYSCTL_cpu_policy_pv_default, - &nr_leaves, leaves, &nr_msrs, NULL); - if ( rc ) - { - PERROR("Failed to obtain %s default policy", di.hvm ? "hvm" : "pv"); - rc = -errno; - goto out; - } - - rc = 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 = %s)", - err_leaf, err_subleaf, -rc, strerror(-rc)); - goto out; - } - - /* - * Account for feature which have been disabled by default since Xen 4.13, - * so migrated-in VM's don't risk seeing features disappearing. - */ - if ( restore ) - { - policy.cpuid = p; - xc_cpu_policy_make_compatible(xch, &policy, di.hvm); - } - - if ( featureset ) - { - policy.cpuid = p; - rc = xc_cpu_policy_apply_featureset(xch, &policy, featureset, - nr_features); - if ( rc ) - { - ERROR("Failed to apply featureset to policy"); - goto out; - } - } - else - { - p->extd.itsc = itsc; - - if ( di.hvm ) - { - p->basic.pae = pae; - p->basic.vmx = nested_virt; - p->extd.svm = nested_virt; - } - } - - policy.cpuid = p; - rc = xc_cpu_policy_topology(xch, &policy, di.hvm); - if ( rc ) - goto out; - - rc = xc_cpu_policy_apply_cpuid(xch, &policy, cpuid, di.hvm); - if ( rc ) - goto out; - - rc = x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves); - if ( rc ) - { - ERROR("Failed to serialise CPUID (%d = %s)", -rc, strerror(-rc)); - goto out; - } - - rc = 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 = -errno; - goto out; - } - - rc = 0; - -out: - free(p); - free(leaves); - - return rc; -} - xc_cpu_policy_t xc_cpu_policy_init(void) { xc_cpu_policy_t policy = calloc(1, sizeof(*policy)); diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index a7b33bbcd06..f1418382b62 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -423,6 +423,8 @@ 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 = NULL; + bool hvm = info->type == LIBXL_DOMAIN_TYPE_HVM; bool pae = true; bool itsc; int rc; @@ -436,6 +438,42 @@ int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, */ bool nested_virt = info->nested_hvm.val > 0; + policy = xc_cpu_policy_init(); + if (!policy) { + LOGE(ERROR, "Failed to init CPU policy"); + rc = ERROR_FAIL; + goto out; + } + + rc = xc_cpu_policy_get_domain(ctx->xch, domid, policy); + if (rc) { + LOGE(ERROR, "Failed to fetch domain %u CPU policy", domid); + rc = ERROR_FAIL; + goto out; + } + + /* + * Account for feature which have been disabled by default since Xen 4.13, + * so migrated-in VM's don't risk seeing features disappearing. + */ + if (restore) { + rc = xc_cpu_policy_make_compatible(ctx->xch, policy, hvm); + if (rc) { + LOGE(ERROR, "Failed to setup compatible CPU policy for domain %u", + domid); + rc = ERROR_FAIL; + goto out; + } + } + + rc = xc_cpu_policy_topology(ctx->xch, policy, hvm); + if (rc) { + LOGE(ERROR, "Failed to setup CPU policy topology for domain %u", + domid); + rc = ERROR_FAIL; + goto out; + } + /* * For PV guests, PAE is Xen-controlled (it is the 'p' that differentiates * the xen-3.0-x86_32 and xen-3.0-x86_32p ABIs). It is mandatory as Xen @@ -446,8 +484,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 == LIBXL_DOMAIN_TYPE_HVM) + if (hvm) pae = libxl_defbool_val(info->u.hvm.pae); + rc = libxl_cpuid_parse_config(&info->cpuid, GCSPRINTF("pae=%d", pae)); + if (rc) { + LOG(ERROR, "Unable to set PAE CPUID flag: %d", rc); + rc = ERROR_FAIL; + goto out; + } + /* * Advertising Invariant TSC to a guest means that the TSC frequency won't @@ -463,12 +508,46 @@ int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, */ itsc = (libxl_defbool_val(info->disable_migrate) || info->tsc_mode == LIBXL_TSC_MODE_ALWAYS_EMULATE); + rc = libxl_cpuid_parse_config(&info->cpuid, GCSPRINTF("invtsc=%d", itsc)); + if (rc) { + LOG(ERROR, "Unable to set Invariant TSC CPUID flag: %d", rc); + rc = ERROR_FAIL; + goto out; + } + + /* Set Nested virt CPUID bits for HVM. */ + if (hvm) { + rc = libxl_cpuid_parse_config(&info->cpuid, GCSPRINTF("vmx=%d", + nested_virt)); + if (rc) { + LOG(ERROR, "Unable to set VMX CPUID flag: %d", rc); + rc = ERROR_FAIL; + goto out; + } + + rc = libxl_cpuid_parse_config(&info->cpuid, GCSPRINTF("svm=%d", + nested_virt)); + if (rc) { + LOG(ERROR, "Unable to set SVM CPUID flag: %d", rc); + rc = ERROR_FAIL; + goto out; + } + } + + /* Apply the bits from info->cpuid if any. */ + rc = xc_cpu_policy_apply_cpuid(ctx->xch, policy, info->cpuid, hvm); + if (rc) { + LOGE(ERROR, "Failed to apply CPUID changes"); + rc = ERROR_FAIL; + goto out; + } - rc = xc_cpuid_apply_policy(ctx->xch, domid, restore, NULL, 0, - pae, itsc, nested_virt, info->cpuid); + rc = xc_cpu_policy_set_domain(ctx->xch, domid, policy); if (rc) - LOGE(ERROR, "Failed to apply CPUID policy"); + LOGE(ERROR, "Failed to set domain %u CPUID policy", domid); + out: + xc_cpu_policy_destroy(policy); GC_FREE; return rc; } From patchwork Tue Mar 23 09:58:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roger Pau Monne X-Patchwork-Id: 12157367 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 E1D74C433C1 for ; Tue, 23 Mar 2021 10:08:09 +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 96959619AB for ; Tue, 23 Mar 2021 10:08:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96959619AB 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.100602.191842 (Exim 4.92) (envelope-from ) id 1lOdxA-00017o-Fp; Tue, 23 Mar 2021 10:08:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 100602.191842; Tue, 23 Mar 2021 10:08:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdxA-00017E-8M; Tue, 23 Mar 2021 10:08:00 +0000 Received: by outflank-mailman (input) for mailman id 100602; Tue, 23 Mar 2021 10:07:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lOdrE-0006c2-1O for xen-devel@lists.xenproject.org; Tue, 23 Mar 2021 10:01:52 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ac161ce9-013a-41c1-aa72-bd6248067ef8; Tue, 23 Mar 2021 10:01:39 +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: ac161ce9-013a-41c1-aa72-bd6248067ef8 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616493698; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=wR4wJPP74Nzgw96212p/UH6sUU/kQSlKJKqNRW2EsfA=; b=U1+QFrKBLEbOVXKND0i75v+Vw9dFdrUh1skhEfRscpLUKlqZedC7g+/8 891jFCZwsm1o/i1Cyunb6UkevkIoREiE0MNh1/ZauVZnY8myll4IWAcAn QUIWMUQSik8fyG5hWxPaHh1IxYQ6lyXEuntQSSF2q8zOs5SnUebjct2/J Q=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: flG4LL9BeCjzwH/PAnsOdAiH+zsEwC/NcqNe+MxUUtS7PT+MS76klZjdd3RabZSn+9XQvRFL/t beatTChezfKdh6lFBRKf+y9yxggifzNM7V6DOFAbRgTnyj1xTttspxrVKb54XkeYq2j/3vcW93 hCExNio+GaOI63+BDkIA2LaC4U8cy9uVkYa0gam3B0r97on3WFK7u9PNk+jxFGe0COGoEcoNMs PSwLh5z+Ud0+fbwj2w1lf0Izex3ORnCXZjQFUeQeD13zUoeo50a0bgC8mU189clk697YcRgLjA 8Pc= X-SBRS: 5.2 X-MesageID: 39900462 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:Dvnxf6M223Wq0cBcT0bw55DYdL4zR+YMi2QD/3taDTRIb82VkN 2vlvwH1RnyzA0cQm0khMroAse9aFvm39pQ7ZMKNbmvGDPntmyhMZ144eLZrAHIMxbVstRQ3a IIScRDIfXtEFl3itv76gGkE9AmhOKK6rysmP229RdQZCtBApsQiDtRIACdD0FwWU16HpI/Dp WR/Y5qoDCndHQRYK2AdwY4dsLEoMDGk4+jXA4eC3ccmXWzpB6LyJq/KRiX2R8CTyhCqI1CzU HpmxH0j5/Tys2T5QTb0wbonvFrsfvnjuBOHcmdzvUSQw+c8DqAQKREd/m8sCsuoOepgWxa4+ Xkhxs7Jcx85zfwUwiO0GPQ8jLt2jov9HPuoGXw6RCIzL2bNVBKfvZpvo5XfgDU7EAtprhHod 929lmUqoZNClf4lDn9juK4Jy1CrFa+onYpjIco/hpieLYZAYUhybA3zQd+FZcNGz/C84Y3EO ViJ9G03ocmTXqqK1/epWVh29qqQzAaGQqHWFELvoiv3yFRh20R9TpW+OUv2lM7sL4tQZhN4O rJdoxuibF1V8cTKYZwHv0IT8ebAnHEKCi8fl66EBDCLuUqKnjNo5n47PEe/+exYqEFy5M0hd DoTE5YnXRaQTOsNeS+mLlwtjzdSmS0WjrgjutE4YJih7H6TL33dQWeVVEVlde6qfl3OLyaZ9 +DfLZtR9PzJ2rnHohEmyfkXYNJFHUYWMoJ/vkhXVajpd/KN53KuuTXfO27HsupLR8UHkfERl cTVjn6I8tNqmqxXGXjvRTXU3TxPmzzlKgAVJTyzqw28swgJ4dMug8ahRCS/ceQMwBPtaQwYQ 9bKLPjmaWrmHmu8Q/zniJUEysYKnwQzKTrUntMqwNPGVjza6w/t9KWfn0X+3ebOBllTYfzHB REr1p6vYK7RqbghBwKOpaCCCa3nnETrHWFQ9M3gauY//rofZs+E9IBQ6x+FQLCEjRvggZ0oG J/aAsJL3WvVA/GuOGAttg5Fevff95zjEOAOshPs0/Ssk2auIUSXHcBZiWvVsSWmA4qYDJRij RKgukiqYvFvQzqBXo0gew+PlEJTGiMGrpJAD6IY5hulqnxdBt9SnqLgjKmmwg+E1CahXk6ty jEF2m5aPvLCl1StjRj3qHm/EhdW0+dc0hzA0oK+7FVJCDjgDJewOWLbq283y+tcVME2PgaKy yASyAVOBlSy9e+0wO1lD6OGW49/IgnOvXQAd0YAuju80LoDLfNubANHvdS8pogCcvntfUTV/ mDPyCSNzH1BooSqkWoj0dgHBMxjnYqkfnlgkK4qEe52WMyGvrULhBNQaoBL9SV8mjjQLKp3f xC/KUIlNr1Fl+0TNiMjZzzRXpkDDj4pGatVeEmqZxOp8sJxfBONqiedQGN7W1N2RU1Edz9m0 wfSplq+bypAP4aQ+UiPwZiumcznNuBLEEXohX7L+83c1YqlWLaNbqyksz1gItqJkWAoQfqUG PviBF1zrPgXyGZ06QdBL91CWNKaFIk4HAKxpLOS6TgTCGrffpE5ly0LzuUd6JcUrGMHfE1og xh69+F28+ReCyQ4nGdgRJLZoZP+X2gW8W8HUalHvNJ6cWzPRC0uZSRifTDxAvfeH+ccEQXhY pMaEwWYIBis1AZ/fMK+xn3bLf2rEIjm0ZZ+hd9mDfWq9Cb3Fs= X-IronPort-AV: E=Sophos;i="5.81,271,1610427600"; d="scan'208";a="39900462" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T7p1ZmqHS78xIz6czIRY9SBPPGFS9Yx3AscabrmCKpeMk9dTVHxFDhLnYsCbLo8iBbE+XBIWpBb7zyTmHMcLXJ7cY++EwPdr9nnTkkixRzMV6jOvKaAoNu82IA9gZMV7QPdjmaimChxAfhtt5GkHxlFQ20Rv7lPJ86sp4ASqlQpugkPKt90ajWymtQnO0K2oC9RYbcMJDtqN4hhjqh1xGoGi/kU+7xNHUHL6jDdi8niNze6VdB/YusEDf3Plkmd0mboX2Odud/1xNO3wvQoAMi3wOXgZcgGIPRBVzX22w1sAHfT9kbpjl7eggSJi9JyGCMfBLW1MpmD+kHrHp5iiNg== 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=Xte694DoXFSNebcQH5zfL8xkf7VzNnQAtPG37OEuSHQ=; b=CikGVkaqhUhgWc1kJVkeDpZG9wH33JihnVz7nLNDCzNWLmcZ22ViA/SvEpZcjm3elEIA/6HPOAHMjBg8KV982VNiw1mOGraXHYk83D3GOwExWy1XbjrP3NNhXoypqUROw9HeDEtZ9s9rIQsSzlYFe8davp+LCAX3Rybx5pVDBNUa6IZ1aQ7M2Nh2+5UAx0zymWfvW36gIxKlAw4JAo7QyvH2NMa0hqqxjv8PP3VWejrYBT6jCOqSEnY9actZMfHwnT4ISF3TGPhz1yM2oUYKaCvMiVlI9R5Lp4CtxTSg52Ryaj0BXeOb8UklHoAjm2qhL5VSwk1Qu1GNgl60UIvZcw== 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=Xte694DoXFSNebcQH5zfL8xkf7VzNnQAtPG37OEuSHQ=; b=aCWKWomeUv14BmOPRXoOP7KAzSH88QnDbkeU//BSlteFMo1BUo77I9uD56NHRwO9grwAwEjZS8H6rFtFT3WYC2UQ6I5Asj8+6aQvyVqH7caAQKhNgK35pEmQH/aJ7RTXM9Va84+aBo3SG6NVJ6FKqf4oBXUNgE2r5L/WF/Ez/cI= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 21/21] libs/guest: (re)move xc_cpu_policy_apply_cpuid Date: Tue, 23 Mar 2021 10:58:49 +0100 Message-ID: <20210323095849.37858-22-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210323095849.37858-1-roger.pau@citrix.com> References: <20210323095849.37858-1-roger.pau@citrix.com> X-ClientProxiedBy: PR3P193CA0057.EURP193.PROD.OUTLOOK.COM (2603:10a6:102:51::32) 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: a9f13b24-f9fb-4d80-5a90-08d8ede2a44d X-MS-TrafficTypeDiagnostic: DM4PR03MB5997: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:312; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gx4Bfir4r/CCh3boBxIoDIBfw/9ro/qVNfbTfqEuGbaxxtOtI+WZu7uKQxHCzBAD7FOouWgCXIEOxFy2Ie1wX0ZE0j5qCqxgBLO2h58YVIsoVl+e2I/n3NwpuobPVjQamKAMrJFXY8cbRGydz/2rQEpzNpBwz8gLHA1AYrSvfzxaUWZ+OUj4J4mB5jszmpTwNYfKaQSxFtdAUxzfTj19c1OLqeHVg48U6E7n2CNtZAqk8I4jlHV+JtyEt6L+fvLfEq+kztTgIQ+f/fd5KSjbqLCYG+5IdUT8ry0oqPjD2nUyK8/iXZ+F+1wT39XP2nkdWKPx574qrZbZiJkEWWj9KIXhumTSyuPX94divZ7pk7/U8hmqpW9kAsipLoaq/vbOF0adyuOh0tmevPimkcaKqiuLAlPRPK/pIlLqOFRU8cs3lZRNeLae3kJ6STbwyDZq4npzFQo+E7BSDDe9H4x6an+7QWvP2S/VDpAVB6zgYpQsoEmVMc4yjrczl8R5+6L3PMy6KNQTVnIyU2KqYBPxPLyY6VtIFsZPrcJk9KeC5PBPdyRopc0cDftW8b+dLwuCkpAs/vBcWMfozNv7AQB+MfQS8b/1QNr7dFNGPBifJKcmteoBYWhsVED9nZBn09T3+wn8m1d+Q0dV9PZ+lf5McA== 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)(346002)(136003)(396003)(376002)(39860400002)(366004)(8676002)(6916009)(83380400001)(86362001)(36756003)(6496006)(5660300002)(6486002)(2906002)(66476007)(66556008)(30864003)(8936002)(66946007)(316002)(2616005)(107886003)(54906003)(186003)(4326008)(6666004)(478600001)(16526019)(1076003)(38100700001)(26005)(956004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?WIT89rtU21rlFy+7JT/TDaTNdaNqEs?= =?utf-8?q?lnKFlnm75cp+1W0TzC7SCUdupdTPveu2kpajVFdEmBw4xKbZxL5n/jUUVfTm+8h1+?= =?utf-8?q?WQekfxGobI+5doUp1/PrXNJBpJWo4IaYEZzmJMiPVypJR04yvihhHLS5cjDsgZ73z?= =?utf-8?q?z8UyEvFQQ1oZYkOgOXl3wGoj0Nh5HqJJQfp97ZKWxcxDfLVhBIbPvmVTaACHJIAkM?= =?utf-8?q?3HDcQPuCpk6ErIlnIpX3DVDFFRz0RPq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ECsB/8I9BaGLIukrdiQtl+BZcvpGvLG?= =?utf-8?q?1/UFxW9/HUDuBc905JMpsQJ8vXqAAkTMp4ykVwZpWKANzVv1mqDnt/7ohKLJ37y5j?= =?utf-8?q?ylx/iHdVI+SKJxkqSqXyYZevGqoP+k1FjKHWuMre/oauW8polBHHy5YWsz/FBG0Ad?= =?utf-8?q?XiTvjPv9KlhTAR?= X-MS-Exchange-CrossTenant-Network-Message-Id: a9f13b24-f9fb-4d80-5a90-08d8ede2a44d X-MS-Exchange-CrossTenant-AuthSource: DS7PR03MB5608.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2021 10:01:35.0936 (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: QwiYEJgQ0NIVWSFlNJEaaIUkZDctOeywqAu+Lls5gJub/YxzbD/WiuBRci3M5ww+aMOov30w9tS0f/+yD5IdcQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR03MB5997 X-OriginatorOrg: 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. Having xenguest parsing CPUID data in xend format was a layering violation, and 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é --- tools/include/libxl.h | 4 +- tools/include/xenctrl.h | 30 ------- tools/libs/guest/xg_cpuid_x86.c | 125 --------------------------- tools/libs/light/libxl_cpuid.c | 135 +++++++++++++++++++++++++++++- tools/libs/light/libxl_internal.h | 26 ++++++ 5 files changed, 160 insertions(+), 160 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index ae7fe27c1f2..923a931fa67 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -1376,9 +1376,9 @@ void libxl_bitmap_dispose(libxl_bitmap *map); /* * libxl_cpuid_policy is opaque in the libxl ABI. Users of both libxl and - * libxc may not make assumptions about xc_xend_cpuid. + * libxc may not make 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 5a576f72b4d..a57e32513d4 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1864,32 +1864,6 @@ int xc_domain_debug_control(xc_interface *xch, #if defined(__i386__) || defined(__x86_64__) -/* - * CPUID policy data, expressed in the legacy XEND format. - * - * Policy is an array of strings, 32 chars long: - * policy[0] = eax - * policy[1] = ebx - * policy[2] = ecx - * policy[3] = 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); @@ -2617,10 +2591,6 @@ int xc_cpu_policy_make_compatible(xc_interface *xch, xc_cpu_policy_t policy, int xc_cpu_policy_topology(xc_interface *xch, xc_cpu_policy_t policy, bool hvm); -/* 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 policy, const uint32_t *featureset, diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c index dffb9923b33..51b0ab66a80 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -258,131 +258,6 @@ static int set_domain_cpu_policy(xc_interface *xch, uint32_t domid, return ret; } -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 = NULL, max = NULL; - - host = xc_cpu_policy_init(); - max = xc_cpu_policy_init(); - if ( !host || !max ) - { - PERROR("Failed to init policies"); - rc = -ENOMEM; - goto out; - } - - /* Get the domain's max policy. */ - rc = xc_cpu_policy_get_system(xch, hvm ? XEN_SYSCTL_cpu_policy_hvm_max - : XEN_SYSCTL_cpu_policy_pv_max, - max); - if ( rc ) - { - PERROR("Failed to obtain %s max policy", hvm ? "hvm" : "pv"); - goto out; - } - - /* Get the host policy. */ - rc = xc_cpu_policy_get_system(xch, XEN_SYSCTL_cpu_policy_host, host); - if ( rc ) - { - PERROR("Failed to obtain host policy"); - goto out; - } - - rc = -EINVAL; - for ( ; cpuid->leaf != XEN_CPUID_INPUT_UNUSED; ++cpuid ) - { - xen_cpuid_leaf_t cur_leaf; - xen_cpuid_leaf_t max_leaf; - xen_cpuid_leaf_t host_leaf; - - rc = xc_cpu_policy_get_cpuid(xch, policy, cpuid->leaf, cpuid->subleaf, - &cur_leaf); - if ( rc ) - { - ERROR("Failed to get current policy leaf %#x subleaf %#x", - cpuid->leaf, cpuid->subleaf); - goto out; - } - rc = xc_cpu_policy_get_cpuid(xch, max, cpuid->leaf, cpuid->subleaf, - &max_leaf); - if ( rc ) - { - ERROR("Failed to get max policy leaf %#x subleaf %#x", - cpuid->leaf, cpuid->subleaf); - goto out; - } - rc = xc_cpu_policy_get_cpuid(xch, host, cpuid->leaf, cpuid->subleaf, - &host_leaf); - if ( rc ) - { - ERROR("Failed to get host policy leaf %#x subleaf %#x", - cpuid->leaf, cpuid->subleaf); - goto out; - } - - for ( unsigned int i = 0; i < ARRAY_SIZE(cpuid->policy); i++ ) - { - uint32_t *cur_reg = &cur_leaf.a + i; - const uint32_t *max_reg = &max_leaf.a + i; - const uint32_t *host_reg = &host_leaf.a + i; - - if ( cpuid->policy[i] == NULL ) - continue; - - for ( unsigned int j = 0; j < 32; j++ ) - { - bool val; - - switch ( cpuid->policy[i][j] ) - { - case '1': - val = true; - break; - - case '0': - val = false; - break; - - case 'x': - val = test_bit(31 - j, max_reg); - break; - - case 'k': - case 's': - val = 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 = 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(max); - xc_cpu_policy_destroy(host); - - return rc; -} - xc_cpu_policy_t xc_cpu_policy_init(void) { xc_cpu_policy_t policy = calloc(1, sizeof(*policy)); diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index f1418382b62..ffa256b62e2 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -291,7 +291,7 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, 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; @@ -369,7 +369,7 @@ int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid, char *endptr; unsigned long value; uint32_t leaf, subleaf = XEN_CPUID_INPUT_UNUSED; - struct xc_xend_cpuid *entry; + struct libxl__cpuid_policy *entry; /* parse the leaf number */ value = strtoul(str, &endptr, 0); @@ -419,6 +419,135 @@ int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid, return 0; } +static int apply_cpuid(libxl_ctx *ctx, xc_cpu_policy_t policy, + libxl_cpuid_policy_list cpuid, bool hvm) +{ + GC_INIT(ctx); + int rc; + xc_cpu_policy_t host = NULL, max = NULL; + + host = xc_cpu_policy_init(); + max = xc_cpu_policy_init(); + if (!host || !max) { + LOG(ERROR, "Failed to init policies"); + rc = ERROR_FAIL; + goto out; + } + + /* Get the domain's max policy. */ + rc = xc_cpu_policy_get_system(ctx->xch, hvm ? XEN_SYSCTL_cpu_policy_hvm_max + : XEN_SYSCTL_cpu_policy_pv_max, + max); + if (rc) { + LOGE(ERROR, "Failed to obtain %s max policy", hvm ? "hvm" : "pv"); + rc = ERROR_FAIL; + goto out; + } + + /* Get the host policy. */ + rc = xc_cpu_policy_get_system(ctx->xch, XEN_SYSCTL_cpu_policy_host, host); + if (rc) { + LOGE(ERROR, "Failed to obtain host policy"); + rc = ERROR_FAIL; + goto out; + } + + for (; cpuid->leaf != XEN_CPUID_INPUT_UNUSED; ++cpuid) { + xen_cpuid_leaf_t cur_leaf; + xen_cpuid_leaf_t max_leaf; + xen_cpuid_leaf_t host_leaf; + + rc = xc_cpu_policy_get_cpuid(ctx->xch, policy, cpuid->leaf, + cpuid->subleaf, &cur_leaf); + if (rc) { + LOGE(ERROR, "Failed to get current policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + rc = ERROR_FAIL; + goto out; + } + rc = xc_cpu_policy_get_cpuid(ctx->xch, max, cpuid->leaf, cpuid->subleaf, + &max_leaf); + if (rc) { + LOGE(ERROR, "Failed to get max policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + rc = ERROR_FAIL; + goto out; + } + rc = xc_cpu_policy_get_cpuid(ctx->xch, host, cpuid->leaf, + cpuid->subleaf, &host_leaf); + if (rc) { + LOGE(ERROR,"Failed to get host policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + rc = ERROR_FAIL; + goto out; + } + + for (unsigned int i = 0; i < ARRAY_SIZE(cpuid->policy); i++) + { + uint32_t *cur_reg = &cur_leaf.a + i; + const uint32_t *max_reg = &max_leaf.a + i; + const uint32_t *host_reg = &host_leaf.a + i; + + if (cpuid->policy[i] == NULL) + continue; + +#define test_bit(i, r) !!(*(r) & (1u << (i))) +#define set_bit(i, r) (*(r) |= (1u << (i))) +#define clear_bit(i, r) (*(r) &= ~(1u << (i))) + for (unsigned int j = 0; j < 32; j++) { + bool val; + + switch (cpuid->policy[i][j]) { + case '1': + val = true; + break; + + case '0': + val = false; + break; + + case 'x': + val = test_bit(31 - j, max_reg); + break; + + case 'k': + case 's': + val = test_bit(31 - j, host_reg); + break; + + default: + LOG(ERROR,"Bad character '%c' in policy[%d] string '%s'", + cpuid->policy[i][j], i, cpuid->policy[i]); + rc = 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 + } + + rc = xc_cpu_policy_update_cpuid(ctx->xch, policy, &cur_leaf, 1); + if ( rc ) + { + LOGE(ERROR,"Failed to set policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + rc = ERROR_FAIL; + goto out; + } + } + + out: + xc_cpu_policy_destroy(max); + xc_cpu_policy_destroy(host); + GC_FREE; + return rc; +} + int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, libxl_domain_build_info *info) { @@ -535,7 +664,7 @@ int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, } /* Apply the bits from info->cpuid if any. */ - rc = xc_cpu_policy_apply_cpuid(ctx->xch, policy, info->cpuid, hvm); + rc = apply_cpuid(ctx, policy, info->cpuid, hvm); if (rc) { LOGE(ERROR, "Failed to apply CPUID changes"); rc = ERROR_FAIL; diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_internal.h index 53b8939fb5a..5b9a220004a 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -2050,6 +2050,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); +/* + * CPUID policy data, expressed in the internal libxl format. + * + * Policy is an array of strings, 32 chars long: + * policy[0] = eax + * policy[1] = ebx + * policy[2] = ecx + * policy[3] = 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 retore, libxl_domain_build_info *info);