From patchwork Tue Jul 25 13:05:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13326427 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 75659C001DF for ; Tue, 25 Jul 2023 13:06:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.569668.890560 (Exim 4.92) (envelope-from ) id 1qOHkB-0003v3-Us; Tue, 25 Jul 2023 13:06:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 569668.890560; Tue, 25 Jul 2023 13:06:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHkB-0003uw-S9; Tue, 25 Jul 2023 13:06:27 +0000 Received: by outflank-mailman (input) for mailman id 569668; Tue, 25 Jul 2023 13:06:27 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHkA-0003uq-PM for xen-devel@lists.xenproject.org; Tue, 25 Jul 2023 13:06:27 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0dc09ab2-2aec-11ee-b23f-6b7b168915f2; Tue, 25 Jul 2023 15:06:24 +0200 (CEST) Received: from mail-dm6nam10lp2106.outbound.protection.outlook.com (HELO NAM10-DM6-obe.outbound.protection.outlook.com) ([104.47.58.106]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jul 2023 09:06:21 -0400 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) by SA1PR03MB6516.namprd03.prod.outlook.com (2603:10b6:806:1c7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 13:06:19 +0000 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767]) by SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767%3]) with mapi id 15.20.6609.031; Tue, 25 Jul 2023 13:06:18 +0000 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: 0dc09ab2-2aec-11ee-b23f-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1690290384; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=/jv+CyPM3neLkaA4oQq4tIsXoYzSYlUOZobTjS+1d6o=; b=ZbeF5W5raUvGtH3RBcFU3i+yrOeoSMp6FLLCCB2hEJMrwaXhtkKn+y6B XNf5f+XGn3fRH1ROHs2Azdn6vRecZ+o9t/+cBBAv2jzyXEcPWY0jZjTFk nNz3Eo3r9nRe67R3HQIVTsO0VVLQ6Xo8ATDB+8Qmmw/BL77gQmu0FISN1 o=; X-IronPort-RemoteIP: 104.47.58.106 X-IronPort-MID: 117380966 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:7UDWfKyDpIWQKTopfx16t+cTxyrEfRIJ4+MujC+fZmUNrF6WrkUC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UID: 9a23:cUDXfgzeDvCapxKQvsVDLgruqWOaqPyjDXwPqpIHgOOBDDwtGB64vRu2Q4Byfw== X-IronPort-AV: E=Sophos;i="6.01,230,1684814400"; d="scan'208";a="117380966" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jJhS924O7TznFdejo4+eYlT8tedekz0WgmozmcLsmMf5BRrBdHQ89DqyMU77dl2tWcH+QLbBMfFQ737QEIpqmo6qzb4izUA1+vFoMDf7GHv+BzqrsaNxrCcJpsl5rFlgS7mJfnaQT0vO7roYyhdXmb0pOZwZAamAHUEuH74GZu3RXnjxFz3jclk3rXfsjLusNrGJ5hjckmo9RbRLDFTovmYkX53LZbI0Dn1PRiCf2IQyaBT3UnUJ3t7vBNSmX50rHDCfCcLYKtax1AP9p6n6U4PsPN1ZKhQ8twuyH1daaWtHWQJ3rOn60o8cBUm0r9kMQ3UPqF+KgvJpqXb/dz30oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wf40HwzFigWxi5/seuFzBWojNz9BnyuqK0PdkFX/FF4=; b=E2rJQLdtPmYzXguFadCGEP34V7PRqEvvHJsnMXA9bLx6DjQAG1SzR4EbcidwPcZHbSSsApaPLphmp5UzyQpH3w2ZyWEn/Tx0XeCrGPAAhk0HpBGkfg98IQSShVxeN61x0RqfbOrnKfABkf5W4DXL3OksimQIsv75rn76YCZcsm7tk6J87MyeXse/C+ThnVXbOtzpcaKW9vMIViXqB7gAblbh7GX1FK2Fj92bihphbWFuKr/q4UFv2yUsuajFmCmDeQs7Td/OYHNCIR40WwC+sqanRJf6Og89mChqS1qUYkqrnTORU5fu8Y03PNpLa4/0Q1GAfAq0Yi6QFXG24eoOsw== 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=wf40HwzFigWxi5/seuFzBWojNz9BnyuqK0PdkFX/FF4=; b=uZprRpw5WEAc1yT8Z7OyMEQEiEz9w0pQ1rvG/zwG6/tNiyKBea0vhRTTQNcVCLa2OnV4D5j1WdJW1mCQv0mt/qbmGlllHW5T005zyjJSzisVq9YrwpvflT6+eNt7bq+y3wzORn8o0+NZoPHNutRk0FfzKSXUfjcce2UbNqF1NUY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v4 1/6] libs/guest: introduce support for setting guest MSRs Date: Tue, 25 Jul 2023 15:05:53 +0200 Message-ID: <20230725130558.58094-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725130558.58094-1-roger.pau@citrix.com> References: <20230725130558.58094-1-roger.pau@citrix.com> X-ClientProxiedBy: LO4P265CA0094.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2bc::9) To SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6423:EE_|SA1PR03MB6516:EE_ X-MS-Office365-Filtering-Correlation-Id: 0edbc6cc-9e8e-49f5-a3b0-08db8d0fef8d X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FaW1Z1yUCozNZhWPhHqLirx6wDlOnkgtJ8b9ouy6CaUKavGX2p0dafFoPS9GY+vsTICbrNegQvosUEYYmJVENUsFGGC52++GAxWbrCSETz7+FYTRSy78xGKLnnTZgslmn9KrCpR480Tv6CsGIikYckttahDrZSC2HioNQbNNG9gFqMO+j12o019A6SU84LmEAWpA4PqXZwqzXzZtIsvVuHXbcUuqzl/MHIOBg/Di6vTeg9tGRG4EEASgsndU1GWyHtB/bXsBcodbqQlOtdkjVsA8xuJcv8jiEdgb6lEQ8+RCq+lHEreCDpKeWh/GID/da9h7vXZsamRYW8xFuxNuEc4iMe6BXJx2NNCLEwTCeCmiQoJSy/6NjjCzxU0vfgwjesocUklLR3n2Xvo4iv9eFXIX9TY0gEFSraJ4DTGgLHK5PnifGX9wL2nHy3+63GcDOaVOB0VYlRgW6zhL4xQkfgAkdA0Vo4kX0WeyZf9OOAN0vbVcDbv7WwSh5+Da+3wTs0fkTjNJNOcjS3U0XvtG8T36sTXzE5k01wc8SrK6gxgPXn6OFSyEEOjtFalGP6p+ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6423.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(366004)(136003)(346002)(396003)(39860400002)(451199021)(6486002)(6666004)(82960400001)(478600001)(83380400001)(8936002)(1076003)(26005)(6512007)(6506007)(66946007)(38100700002)(66556008)(54906003)(6916009)(4326008)(66476007)(186003)(2616005)(5660300002)(8676002)(2906002)(316002)(41300700001)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?vZnIGcNJEG5zaFO5Use59fx2AFRX?= =?utf-8?q?IhS9gNZPKeLhgkh+6YsPRyKvUzoI8CN9/Ciz4XdJratqOxJgrrVy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jWkTjJcPw/m9S7i1LryXu0eGW6oAyvOxU1Mjdx/5dv6uepE1lCTs2m6MsqSoxfzZQ8VYG8jy36GcHliuznEJD3nGTjL+o6rJynw0xnjSYpdvPUQtAFpnEOiOYYsJLs8udIyE8T+WHpKFLruowpyGlfEL9mE5YbCVSrxnN53nYCEhbe2m3Qw6jR04fcYL20ob6Tp+rrLpzr5M1Jwn9ZM2dp6BykVDthZ/O3/cEJiA2n2pX8VJ/A2xke9vkiyF4fJtYtAQUbqlejU4zWgEyPt9ijofEzyBtgeWBXlcrUPJ3iptKkCMW9daWcDyCDnVJnkc7//6QitiLx579ZZoM9kjNW5ycGwPtcJV3sxBjlRtQND63Uo0C9CCPMf5HLv/7yUbbwTmf9E3HJq8gY7Rk9ZmrCxtxx4UUJifcfWDQXDrffakSLQ+Zv2RoptS6c3jaFgb+jglQ9SstiuVQIXmwRRPnku/bxeAGqU59TdPYgMENM2koSXvRw5xwfkChuiEKutTgeu0bYpl3AOFKYKrljzcwArEvZrP0fNQw4Bb9PYt0pTBOrsb6dv1jjg83ulBSVb35dq4PHpUHZI5VJIbJhbhc5 X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0edbc6cc-9e8e-49f5-a3b0-08db8d0fef8d X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6423.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 13:06:18.8670 (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: GxwbBhlDpizBh02WU05k3YvB3FDidmY2Yb6JB0ZumNL09ZYHvj9uvSshU6I+lG+88n36OGuCNgj8KEM7xK8/iw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR03MB6516 Like it's done with CPUID, introduce support for passing MSR values to xc_cpuid_apply_policy(). The chosen format for expressing MSR policy data matches the current one used for CPUID. Note that existing callers of xc_cpuid_apply_policy() can pass NULL as the value for the newly introduced 'msr' parameter in order to preserve the same functionality, and in fact that's done in libxl on this patch. Signed-off-by: Roger Pau Monné Acked-by: Anthony PERARD --- Changes since v2: - Some code adjustment, no functional change. --- tools/include/xenctrl.h | 21 +++- tools/libs/guest/xg_cpuid_x86.c | 169 +++++++++++++++++++++++++++++++- tools/libs/light/libxl_cpuid.c | 2 +- 3 files changed, 188 insertions(+), 4 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index dba33d5d0f39..faec1dd82453 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1822,6 +1822,21 @@ struct xc_xend_cpuid { char *policy[4]; }; +/* + * MSR policy data. + * + * The format of the policy string is the following: + * '1' -> force to 1 + * '0' -> force to 0 + * 'x' -> we don't care (use default) + * 'k' -> pass through host value + */ +struct xc_msr { + uint32_t index; + char policy[65]; +}; +#define XC_MSR_INPUT_UNUSED 0xffffffffu + /* * Make adjustments to the CPUID settings for a domain. * @@ -1833,13 +1848,15 @@ struct xc_xend_cpuid { * 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. + * Then (optionally) apply legacy XEND CPUID overrides (@xend) or MSR (@msr) + * 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); + bool nested_virt, const struct xc_xend_cpuid *xend, + const struct xc_msr *msr); 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 5b035223f4f5..f2b1e809011d 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -423,10 +423,170 @@ static int xc_cpuid_xend_policy( return rc; } +static int compare_msr(const void *l, const void *r) +{ + const xen_msr_entry_t *lhs = l; + const xen_msr_entry_t *rhs = r; + + if ( lhs->idx == rhs->idx ) + return 0; + + return lhs->idx < rhs->idx ? -1 : 1; +} + +static xen_msr_entry_t *find_msr( + xen_msr_entry_t *msrs, unsigned int nr_msrs, + uint32_t index) +{ + const xen_msr_entry_t key = { .idx = index }; + + return bsearch(&key, msrs, nr_msrs, sizeof(*msrs), compare_msr); +} + + +static int xc_msr_policy(xc_interface *xch, domid_t domid, + const struct xc_msr *msr) +{ + int rc; + bool hvm; + xc_domaininfo_t di; + unsigned int nr_leaves, nr_msrs; + uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1; + /* + * Three full policies. The host, default for the domain type, + * and domain current. + */ + xen_msr_entry_t *host = NULL, *def = NULL, *cur = NULL; + unsigned int nr_host, nr_def, nr_cur; + + if ( (rc = xc_domain_getinfo_single(xch, domid, &di)) < 0 ) + { + PERROR("Failed to obtain d%d info", domid); + rc = -errno; + goto out; + } + hvm = di.flags & XEN_DOMINF_hvm_guest; + + rc = xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); + if ( rc ) + { + PERROR("Failed to obtain policy info size"); + rc = -errno; + goto out; + } + + if ( (host = calloc(nr_msrs, sizeof(*host))) == NULL || + (def = calloc(nr_msrs, sizeof(*def))) == NULL || + (cur = calloc(nr_msrs, sizeof(*cur))) == NULL ) + { + ERROR("Unable to allocate memory for %u CPUID leaves", nr_leaves); + rc = -ENOMEM; + goto out; + } + + /* Get the domain's current policy. */ + nr_leaves = 0; + nr_cur = nr_msrs; + rc = get_domain_cpu_policy(xch, domid, &nr_leaves, NULL, &nr_cur, cur); + if ( rc ) + { + PERROR("Failed to obtain d%d current policy", domid); + rc = -errno; + goto out; + } + + /* Get the domain type's default policy. */ + nr_leaves = 0; + nr_def = nr_msrs; + rc = get_system_cpu_policy(xch, hvm ? XEN_SYSCTL_cpu_policy_hvm_default + : XEN_SYSCTL_cpu_policy_pv_default, + &nr_leaves, NULL, &nr_def, def); + if ( rc ) + { + PERROR("Failed to obtain %s def policy", hvm ? "hvm" : "pv"); + rc = -errno; + goto out; + } + + /* Get the host policy. */ + nr_leaves = 0; + nr_host = nr_msrs; + rc = get_system_cpu_policy(xch, XEN_SYSCTL_cpu_policy_host, + &nr_leaves, NULL, &nr_host, host); + if ( rc ) + { + PERROR("Failed to obtain host policy"); + rc = -errno; + goto out; + } + + for ( ; msr->index != XC_MSR_INPUT_UNUSED; ++msr ) + { + xen_msr_entry_t *cur_msr = find_msr(cur, nr_cur, msr->index); + const xen_msr_entry_t *def_msr = find_msr(def, nr_def, msr->index); + const xen_msr_entry_t *host_msr = find_msr(host, nr_host, msr->index); + unsigned int i; + + if ( cur_msr == NULL || def_msr == NULL || host_msr == NULL ) + { + ERROR("Missing MSR %#x", msr->index); + rc = -ENOENT; + goto out; + } + + for ( i = 0; i < ARRAY_SIZE(msr->policy) - 1; i++ ) + { + bool val; + + if ( msr->policy[i] == '1' ) + val = true; + else if ( msr->policy[i] == '0' ) + val = false; + else if ( msr->policy[i] == 'x' ) + val = test_bit(63 - i, &def_msr->val); + else if ( msr->policy[i] == 'k' ) + val = test_bit(63 - i, &host_msr->val); + else + { + ERROR("MSR index %#x: bad character '%c' in policy string '%s'", + msr->index, msr->policy[i], msr->policy); + rc = -EINVAL; + goto out; + } + + if ( val ) + set_bit(63 - i, &cur_msr->val); + else + clear_bit(63 - i, &cur_msr->val); + } + } + + /* Feed the transformed policy back up to Xen. */ + rc = xc_set_domain_cpu_policy(xch, domid, 0, NULL, nr_cur, cur, + &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; + } + + /* Success! */ + + out: + free(cur); + free(def); + free(host); + + 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 *xend) + const struct xc_xend_cpuid *xend, + const struct xc_msr *msr) { int rc; bool hvm; @@ -663,6 +823,13 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, if ( xend && (rc = xc_cpuid_xend_policy(xch, domid, xend)) ) goto out; + if ( msr ) + { + rc = xc_msr_policy(xch, domid, msr); + if ( rc ) + goto out; + } + rc = 0; out: diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index f5ce9f97959c..c96aeb3bce46 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -502,7 +502,7 @@ int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, info->tsc_mode == LIBXL_TSC_MODE_ALWAYS_EMULATE); r = xc_cpuid_apply_policy(ctx->xch, domid, restore, NULL, 0, - pae, itsc, nested_virt, info->cpuid); + pae, itsc, nested_virt, info->cpuid, NULL); if (r) LOGEVD(ERROR, -r, domid, "Failed to apply CPUID policy"); From patchwork Tue Jul 25 13:05:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13326426 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4D75C001DE for ; Tue, 25 Jul 2023 13:06:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.569671.890591 (Exim 4.92) (envelope-from ) id 1qOHkO-0004iH-0e; Tue, 25 Jul 2023 13:06:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 569671.890591; Tue, 25 Jul 2023 13:06:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHkN-0004i1-S8; Tue, 25 Jul 2023 13:06:39 +0000 Received: by outflank-mailman (input) for mailman id 569671; Tue, 25 Jul 2023 13:06:38 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHkM-0004BN-9V for xen-devel@lists.xenproject.org; Tue, 25 Jul 2023 13:06:38 +0000 Received: from esa4.hc3370-68.iphmx.com (esa4.hc3370-68.iphmx.com [216.71.155.144]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f852f70f-2aeb-11ee-8613-37d641c3527e; Tue, 25 Jul 2023 15:05:46 +0200 (CEST) Received: from mail-co1nam11lp2169.outbound.protection.outlook.com (HELO NAM11-CO1-obe.outbound.protection.outlook.com) ([104.47.56.169]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jul 2023 09:06:27 -0400 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) by SA1PR03MB6516.namprd03.prod.outlook.com (2603:10b6:806:1c7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 13:06:25 +0000 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767]) by SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767%3]) with mapi id 15.20.6609.031; Tue, 25 Jul 2023 13:06:25 +0000 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: f852f70f-2aeb-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1690290396; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=/DjRmCpyR41ndqdeo2ztSdCTQNy5XAVA3JYpNnatIeo=; b=NS3wq0BIDjGu6pXsjcrYtHbpSH3HbFmmLSvtLn3QFuDbZm0CtwdvhzZv 0eFkZn9UJstnwPhSM2hsGUKOo+REOZJWt7Xd3n7ndmmHt3IaugS/SEHfG sRuieQfkWwfg786XlPrYbUjYuI0AxTR/YnpOiqYmdj+TVAlYSES4SuoLn E=; X-IronPort-RemoteIP: 104.47.56.169 X-IronPort-MID: 119981299 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:vuFeb6MxV0vrVlDvrR2BlsFynXyQoLVcMsEvi/4bfWQNrUog0zxUy GFNCGqDaPjeajH3etwlYNmwpxkE7cfXmtJiQQto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQAOKnUoYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGjxSs/vrRC9H5qyo42tH5AFmPJingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0vcrL1hr9 7tCFD4cVSu8lcW76pCQZvY506zPLOGzVG8ekldJ6GiASN0BGNXESaiM4sJE1jAtgMwIBezZe 8cSdTtoalLHfgFLPVAUTpk5mY9EhFGmK2Ee9A3T+PRxujaCpOBy+OGF3N79YNuFSN8Thk+Fj mnH4374ElcRM9n3JT+tqyv917+Wx3KqMG4UPIeI+uNl2gS3/GkCJzYQFma0u9C2qkHrDrqzL GRRoELCt5Ma5EGtC9XwQRC8iHqFpQIHHcpdFfUg7wOAwbaS5ByWbkAbShZRZdpgs9U5LRQo2 UWOhMjBHiF0vfueTnf1y1uPhTa7OCxQJmhbYyYBFFIB+4O6/tB1iQ/TRNF+FqLzlsfyBTz73 zGNqm45mqkXiskIka68+Dgrng6Rm3QAdSZtji2/Y45vxloRiFKND2Bw1WXm0A== IronPort-HdrOrdr: A9a23:oNak46GK+Z9bE1jipLqEzceALOsnbusQ8zAXPiFKKSC9F/byqy nAppomPHPP+VMssRIb9uxoWpPgfZq0z/cci+R8AV7FZniehILBFvAE0WLM+UyDJ8SUzJ846U 4PSdkFNPTASXR8kMbm8E2ZPr8bsaS6GOvBv5a5854Xd3AIV0i41XYANu9MKDwMeDV7 X-Talos-CUID: 9a23:XflY6WC8e0YtksX6Ezg72ncxGId/TnPM90zvMWi1I0RCZKLAHA== X-Talos-MUID: 9a23:0+U6YQ35CaWZ0zLgcyEgUrP9tDUj2ZSiFU9XyLE8vtirHiozBjiHpTuXTdpy X-IronPort-AV: E=Sophos;i="6.01,230,1684814400"; d="scan'208";a="119981299" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QZXMP0bomo0LK1ts5N3E3/F2ffI6CDEPtUe7CmQNJKg7hTng1w6nlnZtyeQrChqa5g/9i5Jaf0f8YqVHcOpi5q+eqeqzsYvtc26Xb4nVaAc3THpQoUiO7G6CCrANIZJHvxGKEaXgUMMQ5QneuuZZ9xc70MhRK8T6ZhFj/CvZhs5Cxs03wrV5gFzRxv342F5GNXXW5YeONpeXeOKE+VV+QXG5C8hXpyHYBMsYn1wF41C3SM4SJ/vOtZnQbjbUmt8NjH+nI/1AXn4cy35L9zs5kgDNkEAxbrzI8DzLIbgEBMAiTEUfD0Wp0rJd7oSGzLLnTog7l4SrnLzqrc7cuXn3jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OvAgEnMZzKsiO5gFVAUArv65sWJ/koiL8PS5eQmSiJs=; b=YrfJ5Ht7lWa/RmjXNc/nYgWNDwVQR5G1/YJNndcJ6qmq4enZU/5sFYH/B1RG5wn5D27M6YiZBizO5d9+2b/78ymNwJVpO9AK7wEDDaxASX4wnfDkSziY0scskGJ55BP05OFKXvAHBRgvvJRsZ9Wb50J2i/nV6HLQ9gxVZuohFMXhIsUAnO9Sc5MlUDJbwAkRXXPjWvSY7oQqmA+a+LKpS1BL7wR4EGetylFmrvO7pq2c5/7Xjo7na21za5FQJj7FuBAUYRJjcX9nQnxicWy0zsadx+ieiM2lSLSE0tD6/kOGpkIyMqgAjuXMxONHhfteZIhsUd0f0zERhBRTJzLefw== 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=OvAgEnMZzKsiO5gFVAUArv65sWJ/koiL8PS5eQmSiJs=; b=TXemCq/e5A9HSugl/SdInMqG3e/h/2x854TDUcigBR82MeDdSYdN9RI2Ek5tek9o9P4pa4SfQ2ezq9kzqETltTvmZoF9/w7+sIw4JSlPLmwmENECGF57sXQjLo+HiM7i/+EK/6iT/pVpJhJ5EWD3a/4lYtNVUhiUO0J5vOAla+s= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v4 2/6] libxl: change the type of libxl_cpuid_policy_list Date: Tue, 25 Jul 2023 15:05:54 +0200 Message-ID: <20230725130558.58094-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725130558.58094-1-roger.pau@citrix.com> References: <20230725130558.58094-1-roger.pau@citrix.com> X-ClientProxiedBy: LO4P123CA0552.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:319::14) To SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6423:EE_|SA1PR03MB6516:EE_ X-MS-Office365-Filtering-Correlation-Id: c810b45d-b3b5-4240-5c76-08db8d0ff361 X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CNEA1qaeQ11vMnyI0IzvN0e12CeU8T8koj5/bq5+wFMmD9mlZrPmrq7juTKmP3n+XQZw7o9Y7vD+eNh/udBogv8n22qbKE9E3OKViZTmMY3CyETkatMYTeru/crWTNIq8xEOFYBsa0cUOAS7swGzlPS/h8MCmjbmrOe6X0RZoLVaHQ0HJ73DM1l+8GD8R7c/U2jyXfGdb2Ix2VC+Wj/fUBVq4bwSi2z24kYEah+B4uoGxaZv9giW842SUZksumd/8BeRZubcD3vxZy8ofNB0S5XBq2keG5C1V0cGKCFFvXuxJUr2OPRScksG4ec134tYWB33YMuvEPl1/bz1Y49B0BIT2yP3lYfjsXQbiRrxfJTm+pUnTvhiUk/xh3/8XdZwjrd+tz9DqUoSHBtyaEjfY1G66j9wLzfk+cG9MfbWIL/a9z883pXqlJKyO75oCmD9B2owwIoGHOzVVtOYP5OkYfW1jnnbwBjMvRjAiRXZ6FA9VQY3gHur8lZwRzhyIKa3N4R6cNd2iTvH4ms9SA1vKv7gvFICfVIzOyAEJL0+DkCB1UjJtJ5JgNNgwZHl+I0b X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6423.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(366004)(136003)(346002)(396003)(39860400002)(451199021)(6486002)(6666004)(82960400001)(478600001)(83380400001)(8936002)(1076003)(26005)(6512007)(6506007)(66946007)(38100700002)(66556008)(54906003)(6916009)(4326008)(66476007)(186003)(2616005)(5660300002)(8676002)(2906002)(316002)(41300700001)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?vsjr7jsZHk7udB6GlpjiqD4UIf3u?= =?utf-8?q?nAWB+GSgPrjg4ViI3N7qpfkXVnQ5eXathtQkZgqvRCMwH0QGZ4J1FCZljeQChhoAD?= =?utf-8?q?VQ1nIugGnbn0Ux8ZqZDQqbQmSgM5EhVqn8Gkuql1xBMaapj9zL4Efgg93DgHmkbdb?= =?utf-8?q?ljECFNU8hxXm/btu+wyTy6Ytd+vvXyR1EqYCiIPDgCntY3lnZMkE3PVhE8qd5czGi?= =?utf-8?q?SSZezcriasBdR++tvK5KDnFqCI7Wy+iU1fP6v8PQ218ovX27R73ZtDUeAAgmajSqD?= =?utf-8?q?CbKHKwlCZ50T50hcpPWcQ+rj/DcmcuF5e24wX+9NbN6qk/txhSyvv6FHP93FgcWcY?= =?utf-8?q?jZoxUCPDzm6J3exG4Slq7xyyKfx/y1G403ozhz1PF2sV7cw1QgMjd03L4ra6+/hCo?= =?utf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Mvstun0LF4m62yJE10imOXoh/lFbcU3T1s6skR5QxbGk3wAf9VWUPlo5tmc4VPHqAOLJ0ih3GAM2oPLTq6b3+cqUZPrVBrRWnmoaLvZmC7u95chmAidCZyUN2ryx4wmRz3kXckjdhAO93FFl0doMMr3uXvAn0XRMpDUGadMVS6iW1pOhelOVih8QtPTd7Cq8Rm X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: c810b45d-b3b5-4240-5c76-08db8d0ff361 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6423.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 13:06:25.2836 (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: gklcuy1WpFY+prOgUOoBkRJmEiza7S6Tl4/gNhM1ckOVjmihXETUp5RqHnbZdeXkQ/HnKjb+qbvh/zSdnJUzcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR03MB6516 Currently libxl_cpuid_policy_list is an opaque type to the users of libxl, and internally it's an array of xc_xend_cpuid objects. Change the type to instead be a structure that contains one array for CPUID policies, in preparation for it also holding another array for MSR policies. Signed-off-by: Roger Pau Monné Reviewed-by: Anthony PERARD --- Changes since v2: - Add braces in the inner loop. - Do not set the policy to NULL. --- tools/include/libxl.h | 8 +-- tools/libs/light/libxl_cpuid.c | 87 ++++++++++++++++++++----------- tools/libs/light/libxl_internal.h | 4 ++ 3 files changed, 63 insertions(+), 36 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index cac641a7eba2..f3975ecc021f 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -1455,12 +1455,8 @@ typedef struct { void libxl_bitmap_init(libxl_bitmap *map); 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. - */ -typedef struct xc_xend_cpuid libxl_cpuid_policy; -typedef libxl_cpuid_policy * libxl_cpuid_policy_list; +struct libxl__cpu_policy; +typedef struct libxl__cpu_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); void libxl_cpuid_policy_list_copy(libxl_ctx *ctx, diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index c96aeb3bce46..3c8b2a72c0b8 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -19,22 +19,29 @@ int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl) return !libxl_cpuid_policy_list_length(pl); } -void libxl_cpuid_dispose(libxl_cpuid_policy_list *p_cpuid_list) +void libxl_cpuid_dispose(libxl_cpuid_policy_list *pl) { - int i, j; - libxl_cpuid_policy_list cpuid_list = *p_cpuid_list; + libxl_cpuid_policy_list policy = *pl; - if (cpuid_list == NULL) + if (policy == NULL) return; - for (i = 0; cpuid_list[i].input[0] != XEN_CPUID_INPUT_UNUSED; i++) { - for (j = 0; j < 4; j++) - if (cpuid_list[i].policy[j] != NULL) { - free(cpuid_list[i].policy[j]); - cpuid_list[i].policy[j] = NULL; + + if (policy->cpuid) { + unsigned int i, j; + struct xc_xend_cpuid *cpuid_list = policy->cpuid; + + for (i = 0; cpuid_list[i].input[0] != XEN_CPUID_INPUT_UNUSED; i++) { + for (j = 0; j < 4; j++) { + if (cpuid_list[i].policy[j] != NULL) { + free(cpuid_list[i].policy[j]); + } } + } + free(policy->cpuid); } - free(cpuid_list); - *p_cpuid_list = NULL; + + free(policy); + *pl = NULL; return; } @@ -62,11 +69,17 @@ struct cpuid_flags { /* go through the dynamic array finding the entry for a specified leaf. * if no entry exists, allocate one and return that. */ -static libxl_cpuid_policy_list cpuid_find_match(libxl_cpuid_policy_list *list, - uint32_t leaf, uint32_t subleaf) +static struct xc_xend_cpuid *cpuid_find_match(libxl_cpuid_policy_list *pl, + uint32_t leaf, uint32_t subleaf) { + libxl_cpuid_policy_list policy = *pl; + struct xc_xend_cpuid **list; int i = 0; + if (policy == NULL) + policy = *pl = calloc(1, sizeof(*policy)); + + list = &policy->cpuid; if (*list != NULL) { for (i = 0; (*list)[i].input[0] != XEN_CPUID_INPUT_UNUSED; i++) { if ((*list)[i].input[0] == leaf && (*list)[i].input[1] == subleaf) @@ -86,7 +99,7 @@ static libxl_cpuid_policy_list cpuid_find_match(libxl_cpuid_policy_list *list, * Will overwrite earlier entries and thus can be called multiple * times. */ -int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str) +int libxl_cpuid_parse_config(libxl_cpuid_policy_list *policy, const char* str) { #define NA XEN_CPUID_INPUT_UNUSED static const struct cpuid_flags cpuid_flags[] = { @@ -345,7 +358,7 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str) if (flag->name == NULL) { return 2; } - entry = cpuid_find_match(cpuid, flag->leaf, flag->subleaf); + entry = cpuid_find_match(policy, flag->leaf, flag->subleaf); resstr = entry->policy[flag->reg - 1]; num = strtoull(val, &endptr, 0); flags[flag->length] = 0; @@ -400,7 +413,7 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str) * the strings for each register were directly exposed to the user. * Used for maintaining compatibility with older config files */ -int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid, +int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *policy, const char* str) { char *endptr; @@ -427,7 +440,7 @@ int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid, return 3; } str = endptr + 1; - entry = cpuid_find_match(cpuid, leaf, subleaf); + entry = cpuid_find_match(policy, leaf, subleaf); for (str = endptr + 1; *str != 0;) { if (str[0] != 'e' || str[2] != 'x') { return 4; @@ -502,7 +515,8 @@ int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, info->tsc_mode == LIBXL_TSC_MODE_ALWAYS_EMULATE); r = xc_cpuid_apply_policy(ctx->xch, domid, restore, NULL, 0, - pae, itsc, nested_virt, info->cpuid, NULL); + pae, itsc, nested_virt, + info->cpuid ? info->cpuid->cpuid : NULL, NULL); if (r) LOGEVD(ERROR, -r, domid, "Failed to apply CPUID policy"); @@ -527,16 +541,18 @@ static const char *policy_names[4] = { "eax", "ebx", "ecx", "edx" }; */ yajl_gen_status libxl_cpuid_policy_list_gen_json(yajl_gen hand, - libxl_cpuid_policy_list *pcpuid) + libxl_cpuid_policy_list *pl) { - libxl_cpuid_policy_list cpuid = *pcpuid; + libxl_cpuid_policy_list policy = *pl; + struct xc_xend_cpuid *cpuid; yajl_gen_status s; int i, j; s = yajl_gen_array_open(hand); if (s != yajl_gen_status_ok) goto out; - if (cpuid == NULL) goto empty; + if (policy == NULL || policy->cpuid == NULL) goto empty; + cpuid = policy->cpuid; for (i = 0; cpuid[i].input[0] != XEN_CPUID_INPUT_UNUSED; i++) { s = yajl_gen_map_open(hand); @@ -575,7 +591,7 @@ int libxl__cpuid_policy_list_parse_json(libxl__gc *gc, libxl_cpuid_policy_list *p) { int i, size; - libxl_cpuid_policy_list l; + struct xc_xend_cpuid *l; flexarray_t *array; if (!libxl__json_object_is_array(o)) @@ -586,8 +602,10 @@ int libxl__cpuid_policy_list_parse_json(libxl__gc *gc, return 0; size = array->count; + *p = libxl__calloc(NOGC, 1, sizeof(**p)); /* need one extra slot as sentinel */ - l = *p = libxl__calloc(NOGC, size + 1, sizeof(libxl_cpuid_policy)); + l = (*p)->cpuid = libxl__calloc(NOGC, size + 1, + sizeof(struct xc_xend_cpuid)); l[size].input[0] = XEN_CPUID_INPUT_UNUSED; l[size].input[1] = XEN_CPUID_INPUT_UNUSED; @@ -630,8 +648,12 @@ int libxl__cpuid_policy_list_parse_json(libxl__gc *gc, int libxl_cpuid_policy_list_length(const libxl_cpuid_policy_list *pl) { int i = 0; - libxl_cpuid_policy_list l = *pl; + const struct xc_xend_cpuid *l; + + if (*pl == NULL) + return 0; + l = (*pl)->cpuid; if (l) { while (l[i].input[0] != XEN_CPUID_INPUT_UNUSED) i++; @@ -641,20 +663,25 @@ int libxl_cpuid_policy_list_length(const libxl_cpuid_policy_list *pl) } void libxl_cpuid_policy_list_copy(libxl_ctx *ctx, - libxl_cpuid_policy_list *dst, - const libxl_cpuid_policy_list *src) + libxl_cpuid_policy_list *pdst, + const libxl_cpuid_policy_list *psrc) { + struct xc_xend_cpuid **dst; + struct xc_xend_cpuid *const *src; GC_INIT(ctx); int i, j, len; - if (*src == NULL) { - *dst = NULL; + if (*psrc == NULL) { + *pdst = NULL; goto out; } - len = libxl_cpuid_policy_list_length(src); + *pdst = libxl__calloc(NOGC, 1, sizeof(**pdst)); + dst = &(*pdst)->cpuid; + src = &(*psrc)->cpuid; + len = libxl_cpuid_policy_list_length(psrc); /* one extra slot for sentinel */ - *dst = libxl__calloc(NOGC, len + 1, sizeof(libxl_cpuid_policy)); + *dst = libxl__calloc(NOGC, len + 1, sizeof(struct xc_xend_cpuid)); (*dst)[len].input[0] = XEN_CPUID_INPUT_UNUSED; (*dst)[len].input[1] = XEN_CPUID_INPUT_UNUSED; diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_internal.h index 1cf3d400bfce..ef882cff3912 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -4869,6 +4869,10 @@ int libxl__setresuid(uid_t ruid, uid_t euid, uid_t suid); _hidden int libxl__domain_set_paging_mempool_size( libxl__gc *gc, libxl_domain_config *d_config, uint32_t domid); +struct libxl__cpu_policy { + struct xc_xend_cpuid *cpuid; +}; + #endif /* From patchwork Tue Jul 25 13:05:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13326428 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C7F6C001DE for ; Tue, 25 Jul 2023 13:06:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.569670.890581 (Exim 4.92) (envelope-from ) id 1qOHkM-0004Rj-FW; Tue, 25 Jul 2023 13:06:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 569670.890581; Tue, 25 Jul 2023 13:06: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 1qOHkM-0004RZ-Cc; Tue, 25 Jul 2023 13:06:38 +0000 Received: by outflank-mailman (input) for mailman id 569670; Tue, 25 Jul 2023 13:06:37 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHkL-0003uq-DN for xen-devel@lists.xenproject.org; Tue, 25 Jul 2023 13:06:37 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 14d87be6-2aec-11ee-b23f-6b7b168915f2; Tue, 25 Jul 2023 15:06:36 +0200 (CEST) Received: from mail-co1nam11lp2176.outbound.protection.outlook.com (HELO NAM11-CO1-obe.outbound.protection.outlook.com) ([104.47.56.176]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jul 2023 09:06:33 -0400 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) by SA1PR03MB6516.namprd03.prod.outlook.com (2603:10b6:806:1c7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 13:06:31 +0000 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767]) by SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767%3]) with mapi id 15.20.6609.031; Tue, 25 Jul 2023 13:06:31 +0000 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: 14d87be6-2aec-11ee-b23f-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1690290395; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=JIumuHTKjeGUw+xjOuW7QgTbX2kySrmgaixI+f/zzfA=; b=DFgX/0HgS/T2QiaHb4SMOlJtyxJH8L2GgV540GOq+eYW3QtfvVhzS8Xh yKwaJuZGta+F7fq0dLloiL2P9qHRKBAGFX4HTiiRnCKSeYBwoTaxWFHys KkcbZf2C5i+3PTt8hLrnKhGWb0gMMlwTe5ky3ISRq+Dilac8o5G9KUnNI A=; X-IronPort-RemoteIP: 104.47.56.176 X-IronPort-MID: 117238716 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:6sNhbKl5rLf/Z6X8afdDSbno5gylJ0RdPkR7XQ2eYbSJt1+Wr1Gzt xIaDW2HM/rbMWb0fotzOY/l8h5QvpDQnIVnTwRl/n08QSMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+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684814400"; d="scan'208";a="117238716" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kW/KYh8RNZ2GYvwGTTj0rcIpXQ4L+zCC2+QY90QTeIPAiOvzul1OOOy/zjDLaVTK4PUXuxwMNd/S73dvddsqF5P43+TJ5HolNJ9JpPrsPwXVXObWiu+ZhEXa2nzM2LR56pNzR3YzMsXeoHC01GrhrnG64Dm9c0C1C/4HkoPm6Ga+xXyZgxWduoXN9zkQh1vQNk4+zsJKvNi5XFZ+zScJ0FUVRP/fFqITPkjK6nEm+3dOO552BWAkg5OAA51rDwizfU94lxEyi2L359OBhjjJ/B7BPMU++vR4wtP2a70aAFMqkgBlRYCHY5e4xodwOHuMVQni1ZZ1+8+IinhbNhtvVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=T7eRUdhf8n5WuI46Z6Zzvuxd+0+61lrZHp1tvM3LQ/4=; b=NoLe/QZvRWqstynHzS3Cp1HiTrEaeQ+wopI/xJzYgBGErrvWhG+9N9XRwRR1Ot8IH5HZv+Y1NVkEeYpgOGSRoJiFHvTx4tHt1ipGtgjBjaY3U3xVJDroyJ7X6bD4sEmJGYb4p7M5slcE6O3/Eo/Qim+5PKTA7z22RMZmiX0342ZQH95OjdBT+jFP/LLzoZ/hwoTS4Ez1nhng1cUd9sda3iyI0h+Gliswttz9pshuT391egFSwkH7ZHjdVLTYv4N3E8otNCEr+UE3kGmQWNZMS5y47Wj0lfhJx6oe+ZZW77/TghOQ6DNgOUSf3Yc8aNfLHOjUNkhgmHmTJfSjxGFknQ== 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=T7eRUdhf8n5WuI46Z6Zzvuxd+0+61lrZHp1tvM3LQ/4=; b=ElRG6uALVEPV0/HYMSz9jT7/G3ZfjqeUOJXNfgWkb4FSncpsdmyUXPLbJAvzaIVsTj2Rdl9mzZ5dijphObnFFpyc6AoVaqyCbh1BD32sXfM/ft+ZWdvoKhmiN2ziALZkWtF/1QdSyjO8b2dJvjr8R8roHE6MvhinmaXbqy3ZsrU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v4 3/6] libxl: introduce MSR data in libxl_cpuid_policy Date: Tue, 25 Jul 2023 15:05:55 +0200 Message-ID: <20230725130558.58094-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725130558.58094-1-roger.pau@citrix.com> References: <20230725130558.58094-1-roger.pau@citrix.com> X-ClientProxiedBy: LO4P123CA0238.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a7::9) To SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6423:EE_|SA1PR03MB6516:EE_ X-MS-Office365-Filtering-Correlation-Id: c8afc498-b61d-4d10-1afe-08db8d0ff6f7 X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: paeRlOQLrWbUX1W/YAGz+3GS5bvWjnMCSX5SS6B6ZkJ84LKJWT1AQz+0N34yxenXKNMFgbrXOjY+2Z9dE/G3JYPxIqsvjbWTITClOui2Yw61hi6plnGSyK0o30Dr1oEAoSAoMZFOkmddteaAKB3OScUP5Dpr+RJRW4LACGCgDm515g3ZiyqxGOX3ZuJ0OSYJKmXVJoSXlxm6eUsonUdoCD7qbjeY5J1TnSuExCTYfzK+ZDn5KLNcECvo4Jm0C798l92tV2nO7UN241O8ZmomrEyDffbwO97pgjrMtf4MCcf74gDl/4m6heKlOoStWTQZ3id4ReUzlXOIEHIBfJwNoPuvtXn6dmMrIRSDEdDJrDO9Og1Dly0g4Gadp85wrMM5deGtt98sVKaS/H3rn6QdkJt4BrNvJGzaVKOzq24V5vwxBDfGIeGS1aXK2sJc7uA/Ba5ekP3Hsc9isdbgwUnC/v4zSfexdAzzYkXzvlVO2Ew4fDKug3FcbvBU7keQrracopGmSvLADzwkHUKlrEpYg+cxD29o+ik39bIsSiAAtSvnpuZReAxwzIWiBFnClIYW X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6423.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(366004)(136003)(346002)(396003)(39860400002)(451199021)(6486002)(6666004)(82960400001)(478600001)(83380400001)(8936002)(1076003)(26005)(6512007)(6506007)(66946007)(38100700002)(66556008)(54906003)(6916009)(4326008)(66476007)(186003)(2616005)(5660300002)(8676002)(2906002)(316002)(41300700001)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?in1085drohRYEih+0ESq6wITkpCA?= =?utf-8?q?TkuBlHl6m30yCT4lMWnTqexf32Ni4g9ztuq2OZvOkLSzfcHdF/7M7Z65mqwsv1ZER?= =?utf-8?q?1gKb+9B4HNTCDz5SqUr4uxusMW+fbAIPsLk49yFkwSZXj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g53ARjqADXsnX+ux2iEY3GYMiFTk4M43JiFnxpNsrW+iLtBzZL5DZx6wkd8vAs4yijY1ESXrgq+psC5kfRxvB//0xIu4puRPsiDCtJwT5mlz/tI9fHYkNXcRChaiFBwen2Dszq2+XtnYE8t4f+JVbx/y527nbRh59uhXQb4dt97J5M3AqiYj0s4Yd8wUnmC6LXiO29Mtoi3oOzT8SOJ4h4DJID6HL8IDP8gBPncR+N6lVQPHgOggdmJWTR1h2JLBKVK97Q5ddhtewAeolRF3rznceU0l/zGfRptuxsHk/u0ujeMtAPfKyhi63j3zS9s2zbH9VXc6YLnP3/BM++fEpamSSWlC837IEVwVNcrgZqxGHZYgKcN84TBzB3EW8koJhmgV1Iz7FOt/9gE/xc2JZSDheY6BtZq/rTa/yNfyY9WUe7B+tj2GWc9jX9tFEbwizfFjJTsqCaL/iSHjnpvSVa71JPNbS+6eJN9ASU0p4+UQK4L25kSps1PENlfLvJEZirI6sHqaGBkiF7Ai6e X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8afc498-b61d-4d10-1afe-08db8d0ff6f7 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6423.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 13:06:31.3225 (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: Ko7ipICwXvrHNhoLkkoNeKrSzrW2j6juq9m5ztZcRUM8b/SK+rLpbFtXRd/3Sh992EX0GsKQqxIwWVjxSZ/PYg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR03MB6516 Add a new array field to libxl_cpuid_policy in order to store the MSR policies. Adding the MSR data in the libxl_cpuid_policy_list type is done so that existing users can seamlessly pass MSR features as part of the CPUID data, without requiring the introduction of a separate domain_build_info field, and a new set of handlers functions. Note that support for parsing the old JSON format is kept, as that's required in order to restore domains or received migrations from previous tool versions. Differentiation between the old and the new formats is done based on whether the contents of the 'cpuid' field is an array or a map JSON object. Signed-off-by: Roger Pau Monné Reviewed-by: Anthony PERARD --- Changes since v3: - Keep support for the old json format in the parse function. Changes since v2: - Unconditionally call free(). - Implement the JSON marshaling functions. --- tools/libs/light/libxl_cpuid.c | 152 ++++++++++++++++++++++++++---- tools/libs/light/libxl_internal.h | 1 + tools/libs/light/libxl_types.idl | 2 +- 3 files changed, 138 insertions(+), 17 deletions(-) diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index 3c8b2a72c0b8..dd97699bbde7 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -16,7 +16,7 @@ int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl) { - return !libxl_cpuid_policy_list_length(pl); + return !*pl || (!libxl_cpuid_policy_list_length(pl) && !(*pl)->msr); } void libxl_cpuid_dispose(libxl_cpuid_policy_list *pl) @@ -40,6 +40,8 @@ void libxl_cpuid_dispose(libxl_cpuid_policy_list *pl) free(policy->cpuid); } + free(policy->msr); + free(policy); *pl = NULL; return; @@ -516,7 +518,8 @@ int libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, bool restore, r = xc_cpuid_apply_policy(ctx->xch, domid, restore, NULL, 0, pae, itsc, nested_virt, - info->cpuid ? info->cpuid->cpuid : NULL, NULL); + info->cpuid ? info->cpuid->cpuid : NULL, + info->cpuid ? info->cpuid->msr : NULL); if (r) LOGEVD(ERROR, -r, domid, "Failed to apply CPUID policy"); @@ -528,16 +531,22 @@ static const char *input_names[2] = { "leaf", "subleaf" }; static const char *policy_names[4] = { "eax", "ebx", "ecx", "edx" }; /* * Aiming for: - * [ - * { 'leaf': 'val-eax', - * 'subleaf': 'val-ecx', - * 'eax': 'filter', - * 'ebx': 'filter', - * 'ecx': 'filter', - * 'edx': 'filter' }, - * { 'leaf': 'val-eax', ..., 'eax': 'filter', ... }, - * ... etc ... - * ] + * { 'cpuid': [ + * { 'leaf': 'val-eax', + * 'subleaf': 'val-ecx', + * 'eax': 'filter', + * 'ebx': 'filter', + * 'ecx': 'filter', + * 'edx': 'filter' }, + * { 'leaf': 'val-eax', ..., 'eax': 'filter', ... }, + * ... etc ... + * ], + * 'msr': [ + * { 'index': 'val-index', + * 'policy': 'filter', }, + * ... etc ... + * ], + * } */ yajl_gen_status libxl_cpuid_policy_list_gen_json(yajl_gen hand, @@ -545,9 +554,16 @@ yajl_gen_status libxl_cpuid_policy_list_gen_json(yajl_gen hand, { libxl_cpuid_policy_list policy = *pl; struct xc_xend_cpuid *cpuid; + const struct xc_msr *msr; yajl_gen_status s; int i, j; + s = yajl_gen_map_open(hand); + if (s != yajl_gen_status_ok) goto out; + + s = libxl__yajl_gen_asciiz(hand, "cpuid"); + if (s != yajl_gen_status_ok) goto out; + s = yajl_gen_array_open(hand); if (s != yajl_gen_status_ok) goto out; @@ -582,6 +598,39 @@ yajl_gen_status libxl_cpuid_policy_list_gen_json(yajl_gen hand, empty: s = yajl_gen_array_close(hand); + if (s != yajl_gen_status_ok) goto out; + + s = libxl__yajl_gen_asciiz(hand, "msr"); + if (s != yajl_gen_status_ok) goto out; + + s = yajl_gen_array_open(hand); + if (s != yajl_gen_status_ok) goto out; + + if (!policy || !policy->msr) goto done; + msr = policy->msr; + + for (i = 0; msr[i].index != XC_MSR_INPUT_UNUSED; i++) { + s = yajl_gen_map_open(hand); + if (s != yajl_gen_status_ok) goto out; + + s = libxl__yajl_gen_asciiz(hand, "index"); + if (s != yajl_gen_status_ok) goto out; + s = yajl_gen_integer(hand, msr[i].index); + if (s != yajl_gen_status_ok) goto out; + s = libxl__yajl_gen_asciiz(hand, "policy"); + if (s != yajl_gen_status_ok) goto out; + s = yajl_gen_string(hand, + (const unsigned char *)msr[i].policy, 64); + if (s != yajl_gen_status_ok) goto out; + + s = yajl_gen_map_close(hand); + if (s != yajl_gen_status_ok) goto out; + } + +done: + s = yajl_gen_array_close(hand); + if (s != yajl_gen_status_ok) goto out; + s = yajl_gen_map_close(hand); out: return s; } @@ -592,17 +641,32 @@ int libxl__cpuid_policy_list_parse_json(libxl__gc *gc, { int i, size; struct xc_xend_cpuid *l; + struct xc_msr *msr; + const libxl__json_object *co; flexarray_t *array; + bool cpuid_only = false; + + if (libxl__json_object_is_array(o)) { + co = o; + cpuid_only = true; + goto parse_cpuid; + } + + if (!libxl__json_object_is_map(o)) + return ERROR_FAIL; - if (!libxl__json_object_is_array(o)) + co = libxl__json_map_get("cpuid", o, JSON_ARRAY); + if (!libxl__json_object_is_array(co)) return ERROR_FAIL; - array = libxl__json_object_get_array(o); +parse_cpuid: + *p = libxl__calloc(NOGC, 1, sizeof(**p)); + + array = libxl__json_object_get_array(co); if (!array->count) - return 0; + goto cpuid_empty; size = array->count; - *p = libxl__calloc(NOGC, 1, sizeof(**p)); /* need one extra slot as sentinel */ l = (*p)->cpuid = libxl__calloc(NOGC, size + 1, sizeof(struct xc_xend_cpuid)); @@ -641,6 +705,42 @@ int libxl__cpuid_policy_list_parse_json(libxl__gc *gc, libxl__strdup(NOGC, libxl__json_object_get_string(r)); } } + if (cpuid_only) + return 0; + +cpuid_empty: + co = libxl__json_map_get("msr", o, JSON_ARRAY); + if (!libxl__json_object_is_array(co)) + return ERROR_FAIL; + + array = libxl__json_object_get_array(co); + if (!array->count) + return 0; + size = array->count; + /* need one extra slot as sentinel */ + msr = (*p)->msr = libxl__calloc(NOGC, size + 1, sizeof(struct xc_msr)); + + msr[size].index = XC_MSR_INPUT_UNUSED; + + for (i = 0; i < size; i++) { + const libxl__json_object *t, *r; + + if (flexarray_get(array, i, (void**)&t) != 0) + return ERROR_FAIL; + + if (!libxl__json_object_is_map(t)) + return ERROR_FAIL; + + r = libxl__json_map_get("index", t, JSON_INTEGER); + if (!r) return ERROR_FAIL; + msr[i].index = libxl__json_object_get_integer(r); + r = libxl__json_map_get("policy", t, JSON_STRING); + if (!r) return ERROR_FAIL; + if (strlen(libxl__json_object_get_string(r)) != + ARRAY_SIZE(msr[i].policy) - 1) + return ERROR_FAIL; + strcpy(msr[i].policy, libxl__json_object_get_string(r)); + } return 0; } @@ -677,6 +777,10 @@ void libxl_cpuid_policy_list_copy(libxl_ctx *ctx, } *pdst = libxl__calloc(NOGC, 1, sizeof(**pdst)); + + if (!(*psrc)->cpuid) + goto copy_msr; + dst = &(*pdst)->cpuid; src = &(*psrc)->cpuid; len = libxl_cpuid_policy_list_length(psrc); @@ -696,6 +800,22 @@ void libxl_cpuid_policy_list_copy(libxl_ctx *ctx, (*dst)[i].policy[j] = NULL; } +copy_msr: + if ((*psrc)->msr) { + const struct xc_msr *msr = (*psrc)->msr; + + for (i = 0; msr[i].index != XC_MSR_INPUT_UNUSED; i++) + ; + len = i; + (*pdst)->msr = libxl__calloc(NOGC, len + 1, sizeof(struct xc_msr)); + (*pdst)->msr[len].index = XC_MSR_INPUT_UNUSED; + + for (i = 0; i < len; i++) { + (*pdst)->msr[i].index = msr[i].index; + strcpy((*pdst)->msr[i].policy, msr[i].policy); + } + } + out: GC_FREE; } diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_internal.h index ef882cff3912..b1a7cd9f615b 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -4871,6 +4871,7 @@ _hidden int libxl__domain_set_paging_mempool_size( struct libxl__cpu_policy { struct xc_xend_cpuid *cpuid; + struct xc_msr *msr; }; #endif diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.idl index 9e48bb772646..fd2f3f6e485f 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -19,7 +19,7 @@ libxl_mac = Builtin("mac", json_parse_type="JSON_STRING", passby=PASS_BY_REFEREN libxl_bitmap = Builtin("bitmap", json_parse_type="JSON_ARRAY", dispose_fn="libxl_bitmap_dispose", passby=PASS_BY_REFERENCE, check_default_fn="libxl_bitmap_is_empty", copy_fn="libxl_bitmap_copy_alloc") libxl_cpuid_policy_list = Builtin("cpuid_policy_list", dispose_fn="libxl_cpuid_dispose", passby=PASS_BY_REFERENCE, - json_parse_type="JSON_ARRAY", check_default_fn="libxl__cpuid_policy_is_empty", + json_parse_type="JSON_ANY", check_default_fn="libxl__cpuid_policy_is_empty", copy_fn="libxl_cpuid_policy_list_copy") libxl_string_list = Builtin("string_list", dispose_fn="libxl_string_list_dispose", passby=PASS_BY_REFERENCE, From patchwork Tue Jul 25 13:05:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13326429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5BF07C001DE for ; Tue, 25 Jul 2023 13:07:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.569672.890601 (Exim 4.92) (envelope-from ) id 1qOHkT-000534-8W; Tue, 25 Jul 2023 13:06:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 569672.890601; Tue, 25 Jul 2023 13:06:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHkT-00052v-5C; Tue, 25 Jul 2023 13:06:45 +0000 Received: by outflank-mailman (input) for mailman id 569672; Tue, 25 Jul 2023 13:06:44 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHkR-0004BN-Ry for xen-devel@lists.xenproject.org; Tue, 25 Jul 2023 13:06:43 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fabb7852-2aeb-11ee-8613-37d641c3527e; Tue, 25 Jul 2023 15:05:52 +0200 (CEST) Received: from mail-co1nam11lp2175.outbound.protection.outlook.com (HELO NAM11-CO1-obe.outbound.protection.outlook.com) ([104.47.56.175]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jul 2023 09:06:39 -0400 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) by SA1PR03MB6516.namprd03.prod.outlook.com (2603:10b6:806:1c7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 13:06:36 +0000 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767]) by SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767%3]) with mapi id 15.20.6609.031; Tue, 25 Jul 2023 13:06:36 +0000 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: fabb7852-2aeb-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1690290401; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=3YW2uWrH0cDvz/qKgkm2RdMtfdnR+LKEqygNTbfvJjA=; b=dQBSZwaLQj5QMfayv8gWbneKNrWBspYvRwlWncrCsMjexZFTuHl/T+Dg nNsQJipwFM5rZkZ7ciHzUGjtgOz/U5SAafRdRnznzrdn4I5M98uykXgkC 5/TTNcRiF7QNFOWQ+5gjAN+Rxw/JO4Huom+nrsCJYN8TRubEc4WDIWhMX A=; X-IronPort-RemoteIP: 104.47.56.175 X-IronPort-MID: 117795529 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:l7pT2anBQev/1El6WeMxiSro5gylJ0RdPkR7XQ2eYbSJt1+Wr1Gzt xIWDGyEaf7Ya2KmKNB1Po7joEgH6JHXmoU3HQA5ri03QyMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+39B55C49SEUOZmgH+a6U6icfHgqH2eIcQ954Tp7gek1n4V0ttawBgKJq LvartbWfVSowFaYCEpNg064gE0p5K2aVA8w5ARkPqgU5gKGzhH5MbpETU2PByqgKmVrNrbSq 9brlNmR4m7f9hExPdKp+p6TnpoiG+O60aCm0xK6aoD66vRwjnVaPpUTbZLwXXx/mTSR9+2d/ f0W3XCGpaXFCYWX8AgVe0Ew/yiTpsSq8pefSZS0mZT7I0Er7xIAahihZa07FdRwxwp5PY1B3 dU8FWAITQiSvaGv0bi8FrlwhcslcNa+aevzulk4pd3YJdAPZMmaBo7tvJpf1jp2gd1SF/HDY cZfcSBocBnLfxxIPBEQFY46m+CrwHL4dlW0qnrM/fZxvzeVkVI3ieewWDbWUoXiqcF9hEGXq 3iA523kKhobKMae2XyO9XfEaurnxHqkB9NPSefpnhJsqFqQ51cQMhkaaRyE+OCgqxSYB+ptE VNBr0LCqoB3riRHVOLVTxC+5XKJoBMYc95RCPEhrhGAzLLO5ASUDXRCSSROAPQ5sOcmSDps0 UWG9/vrCiZoq6a9Um+G+/GfqjbaBMQOBWoLZCtBRgxc5dDm+dg3lkiWEYslF7OphNroHz222 yqNsCU1m7QUi4gMyrm/+lfExTmro/AlUzII2+keZUr9hisRWWJvT9XABYTzhRqYELukcw== IronPort-HdrOrdr: A9a23:+GvE36FnwL6TdsTHpLqE7MeALOsnbusQ8zAXPiFKJSC9F/byqy nAppsmPHPP5gr5IUtQ/uxoWpPhfZqsz/9ICOAqVN/JMTUO01HYT72Kg7GSpgHIKmnT8fNcyL clU4UWMqyVMbGit7eZ3DWF X-Talos-CUID: 9a23:U3I9Dm9HBBJ/JP5JgxiVv2cwJ5AgUWXM9jTJMkW/VTZ1S7KTFUDFrQ== X-Talos-MUID: 9a23:/e139g9kVmO+sRO2Skgx+DGQf8Brwp+tMkQBrdI54tCdFHZWZw+vtiviFw== X-IronPort-AV: E=Sophos;i="6.01,230,1684814400"; d="scan'208";a="117795529" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LCtSwQLq1Gls2hTnfurr/Xz9Nz3Ia09KzLde1qICbHmLAWQAsZFGdCl6vmCS+jiCwcyjNIfYF/rjoqKboBHU/bUKpGeu3kvRetgYsY2GQGY4+HK8gi07G7rU5+ZQjxBcK3nlCXrFI5lTeJ0EOuIu7QU/s9VcBlIGmp8WIcHj23gJ8QxeJX8ha4wIy7m7E6LSaMMfwM1rxAW8/3+4vYJSn4V7yt7mpd4YPyhsmqunW/C8iHobu/xMNiMohP2Z56ozdBXhqeeULvz6tb1J+8MA2Hg3sR3O809JNsTe7c7PEkoxSWONyEkH1WypVhl7l9pGx2RadCSMMvukN1zJUb67jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0VuaruMFBkjm32zvsZJXEPKcdb4HJwG3XWzAhS0qQtk=; b=egSXSQeMHCwIeJN2dpvvH62kIUQ1tlFbUSBL8g48Sji+HJbUnlQfK6b668NfY6Uhfc8kol5fIzOBTKVxwBja6AXg/o6pqznI0I4y/LrHXJDyMXo3Hg1Nk3Oy3czFIsYIaOGCxPy0YQK/rPuP5zIKdP4oUvhrgZ7YwNUkTAWLD9joXnT99jcpk/3V/DTI4Uy+jHeGhp+Fv7xT3awil1lsiOOPOYdLvL3yqOpGoDR6uGdBczv1zOj0ke+AJO9vWU1/wA9oeIscJrSMzsbiGF++N3+M4YOE2FOKVKk1pxCPn2Nzg2iMeKnrQZ0wcgSqEQOcErIQv9gRaKa7Qbd3+DPyMQ== 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=0VuaruMFBkjm32zvsZJXEPKcdb4HJwG3XWzAhS0qQtk=; b=D7JVqtUg2/4SIQauCDh2Bv90795Fq6HQJSezaVChS7maYb14ZxdPyN0/mSzfQ8hxsSpz+9FngzrD3NgSIqw3Dw1AS3+crFzMh2HNkvHVOi3/pUkkWUtPCcgvcd1KRm5WSpsUW2RDWnxL9/vlEugG3mh8UIF47WxrReNB24CjQt8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v4 4/6] libxl: split logic to parse user provided CPUID features Date: Tue, 25 Jul 2023 15:05:56 +0200 Message-ID: <20230725130558.58094-5-roger.pau@citrix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725130558.58094-1-roger.pau@citrix.com> References: <20230725130558.58094-1-roger.pau@citrix.com> X-ClientProxiedBy: LO2P265CA0494.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13a::19) To SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6423:EE_|SA1PR03MB6516:EE_ X-MS-Office365-Filtering-Correlation-Id: b3b60524-1da8-45ff-2fab-08db8d0ffa3e X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NNw0DSUyAqQaAVVCQd2pMffUYw5wdLUDH7Uj0y4oQo9G7THSjfsJzdsf49TFEKDqh9QHTfiidU36G8krmeEXEYi/7J2h8Wo/xiS4rd2av+PNp+rzvGc1+H4C1XK2F4j8bxRZWLx+cKpd1qiqPVrwU4oB4dqkkJRL4TgCGA5/Ojof0PXQuyF/tFwOJpocT1Ux5zByccbvLaxYSDoTS4yUiG8Sla54TNB3/iTS+xR9sbVOmkW4thMtFBcS00ZDVSIHPOYgB64l5KRuQsHVIOvur/lfZJMgr5rCkqpUEyiMgKPXsTIRAQ2BBP6gPMBTBCyzMsIT/mGzhi8LxvJpVSuqgSwXWn28e6bSLVRV3grUZbGRScYCIweE1k3WdpjceeUGBATxAP+V2YtFFCY+kE12Ja1SN0D2AIBxxhg01f5ff0yT7jNwpTXzt7MHoR+4Gl1HTDCJHxcFRxq2lW2RBWuSHwrIMtxHqYjvdP+5TZWoOo+AbFnQ+rMV8dcX0Aj23SjT1b+uuIjAYU8Brw/x/3DpQZrEhNBbn11Fte19iQyATB2vumH23vAnjwAi1G77OPCd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6423.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(366004)(136003)(346002)(396003)(39860400002)(451199021)(6486002)(6666004)(82960400001)(478600001)(83380400001)(8936002)(1076003)(26005)(6512007)(6506007)(66946007)(38100700002)(66556008)(54906003)(6916009)(4326008)(66476007)(186003)(2616005)(5660300002)(8676002)(2906002)(316002)(41300700001)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?bWJgHgycBeiwNFNQENWMSNIAMrHI?= =?utf-8?q?2jem09N5WJ/WoHjKQwDeEfd9NFFm3+BF49I+us7czijpd+kuOo1K7sHwyfeLNZ1Xa?= =?utf-8?q?SnueFGSyOIJzfxeoBsYP0cx8MbhaZcEOD3STKnudLsxtGlM44Rqu9+lrrLn9jekpq?= =?utf-8?q?ZCFzN2f0K7nfwRdGle85pL/0D6D4NA6kyz1146OQ8SU5ZgBhZK/VYXdrISLRt4mur?= =?utf-8?q?rBgtJxr5nWoAm1/AcV30husJnbivP9a65TF0dZY6Z29aTNb6IV4CaQLWTZQHERY7Q?= =?utf-8?q?boRImt8y/V6AcTkmNy6cHzer7ibDoG1I2Hf5s9LXZPtq5R4/q40kmCfXV6t/QzsNF?= =?utf-8?q?XuNSEHjHEQbU1RDidb+dmcyxYiZF/qEdiQNU9QJvCfZT8AEtNdOxvXhKBXZPD//Kw?= =?utf-8?q?O5mb9rdzRJIyAYlobC2TuYiMGNZyLgpVRWetnY09tcjcDGxdjHAQ6/OCa//EGJHCd?= =?utf-8?q?yvJvL8nipI0fpw7CZTLeDt7yv1lLowkQtEBQ9aT/6YHAtfJSvQxsp5qb1shUrzOxw?= =?utf-8?q?jbFOZWFNMM5JOrXXAhrRdliAOimF5ANM+gBnNbUIIAlHnw5Z4AwsMad8qJK6Az2Dv?= =?utf-8?q?Pa3T+LsYuvFbpxK+BEY9GzyHEMTS7PWefHVvPlNbGnw5O1hJC6umtd0MnpCmH30w5?= =?utf-8?q?J5wtqHx6xkgwkJKveL3TzGQuR+mS5JtLhYY5IazNxsfozG2+AXbavNJPxmV8Ing+k?= =?utf-8?q?CkRWi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ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: sV1F5z5smsqDnqQ38HRij+UF7jxC/aXQOTTzJBROlpSO21S65of7N51Ouc7/OpefhgjckT1ka3sAWd+EYhCj78FX00hzw1r39ByM/qznFHUH3kcelRXnE/9uXg2Bve5qHjgfaZOnX5KahiPj7u8LHJyVju8Qkcp/yNwB9RjJTOu+YGXD5UGgwzfHXdPhUw4CxTadGwWrMDMq4QIY0rqYNBXAuEctGxyaLduteaZ7pAN3/83XQgPa0DxGTtT3aWvKcJEdxoGF8GlHPsVo3zicmL+6lOcqyXZew/tGVuQAodQKwHj5H6RZbfMSfKcJoBaQitXS3E2wGTc1FhdVSnnrX+C8ukt1ykz/AoebNZ8AatZPlvP2iIJCSTFTOjld736BoDyNWQto0NrZ0o41p6KFSvT0oTuFyz60s5oFMwGR8E5Rr2+1E45Znt8GK8lumCUBVptjjRWOPbX9qs1/Fc+ilzz1gptKhcBj1afsPyLpq/T9Lc+byEY/6OFltb8IuGTyvosZlc1MdnBRe64Y4c9EsaKL29OPw9oa95ZfFN2d/YZqqQLhoeVn/6N+f0lsZOtyjirxaUZeuIqmVd0QmyQO/Mouia2eZi0iyo9GpJ2EoFh+RmRLx0fznwbXugtdpp26hOd8tjSNipGtLi9djQecX275p92IRQ/zLgET1Iexkj4PziD9cfa9WoSINw7A++QCEmH1EE3bOXUHAM6EMDZkeJf/jd/B+KAlE3fWv6m6IxUgqr2QrpeIKW8Oa56Q1E1k0IEMT2Nruty+mDwx4Abkgo321u1VmjvVA/o6Izg1ziQIpa+AapzCb25OwZye+LcC X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: b3b60524-1da8-45ff-2fab-08db8d0ffa3e X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6423.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 13:06:36.6710 (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: 3XYaVcH2aXV3HgNi1QraV9fTnZT6qnMFZP3HuUMVrL9brfqM84iy5NybVjjcKfzo9gmkGsrrAi5zpmY5iLUUqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR03MB6516 Move the CPUID value parsers out of libxl_cpuid_parse_config() into a newly created cpuid_add() local helper. This is in preparation for also adding MSR feature parsing support. No functional change intended. Signed-off-by: Roger Pau Monné Reviewed-by: Anthony PERARD --- Changes since v3: - Fix UB and use strtoul. --- tools/libs/light/libxl_cpuid.c | 120 +++++++++++++++++---------------- 1 file changed, 63 insertions(+), 57 deletions(-) diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index dd97699bbde7..f04b192c0e44 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -96,6 +96,66 @@ static struct xc_xend_cpuid *cpuid_find_match(libxl_cpuid_policy_list *pl, return *list + i; } +static int cpuid_add(libxl_cpuid_policy_list *policy, + const struct cpuid_flags *flag, const char *val) +{ + struct xc_xend_cpuid *entry = cpuid_find_match(policy, flag->leaf, + flag->subleaf); + unsigned long num; + char flags[33], *resstr, *endptr; + unsigned int i; + + resstr = entry->policy[flag->reg - 1]; + num = strtoul(val, &endptr, 0); + flags[flag->length] = 0; + if (endptr != val) { + /* if this was a valid number, write the binary form into the string */ + for (i = 0; i < flag->length; i++) { + flags[flag->length - 1 - i] = "01"[(num >> i) & 1]; + } + } else { + switch(val[0]) { + case 'x': case 'k': case 's': + memset(flags, val[0], flag->length); + break; + default: + return 3; + } + } + + if (resstr == NULL) { + resstr = strdup("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + } + + /* the family and model entry is potentially split up across + * two fields in Fn0000_0001_EAX, so handle them here separately. + */ + if (!strcmp(flag->name, "family")) { + if (num < 16) { + memcpy(resstr + (32 - 4) - flag->bit, flags + 4, 4); + memcpy(resstr + (32 - 8) - 20, "00000000", 8); + } else { + num -= 15; + memcpy(resstr + (32 - 4) - flag->bit, "1111", 4); + for (i = 0; i < 7; i++) { + flags[7 - i] = "01"[num & 1]; + num >>= 1; + } + memcpy(resstr + (32 - 8) - 20, flags, 8); + } + } else if (!strcmp(flag->name, "model")) { + memcpy(resstr + (32 - 4) - 16, flags, 4); + memcpy(resstr + (32 - 4) - flag->bit, flags + 4, 4); + } else { + memcpy(resstr + (32 - flag->length) - flag->bit, flags, + flag->length); + } + entry->policy[flag->reg - 1] = resstr; + + return 0; + +} + /* parse a single key=value pair and translate it into the libxc * used interface using 32-characters strings for each register. * Will overwrite earlier entries and thus can be called multiple @@ -340,12 +400,8 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *policy, const char* str) {NULL, 0, NA, CPUID_REG_INV, 0, 0} }; #undef NA - char *sep, *val, *endptr; - int i; + const char *sep, *val; const struct cpuid_flags *flag; - struct xc_xend_cpuid *entry; - unsigned long num; - char flags[33], *resstr; sep = strchr(str, '='); if (sep == NULL) { @@ -355,60 +411,10 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *policy, const char* str) } for (flag = cpuid_flags; flag->name != NULL; flag++) { if(!strncmp(str, flag->name, sep - str) && flag->name[sep - str] == 0) - break; - } - if (flag->name == NULL) { - return 2; - } - entry = cpuid_find_match(policy, flag->leaf, flag->subleaf); - resstr = entry->policy[flag->reg - 1]; - num = strtoull(val, &endptr, 0); - flags[flag->length] = 0; - if (endptr != val) { - /* if this was a valid number, write the binary form into the string */ - for (i = 0; i < flag->length; i++) { - flags[flag->length - 1 - i] = "01"[!!(num & (1 << i))]; - } - } else { - switch(val[0]) { - case 'x': case 'k': case 's': - memset(flags, val[0], flag->length); - break; - default: - return 3; - } - } - - if (resstr == NULL) { - resstr = strdup("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + return cpuid_add(policy, flag, val); } - /* the family and model entry is potentially split up across - * two fields in Fn0000_0001_EAX, so handle them here separately. - */ - if (!strncmp(str, "family", sep - str)) { - if (num < 16) { - memcpy(resstr + (32 - 4) - flag->bit, flags + 4, 4); - memcpy(resstr + (32 - 8) - 20, "00000000", 8); - } else { - num -= 15; - memcpy(resstr + (32 - 4) - flag->bit, "1111", 4); - for (i = 0; i < 7; i++) { - flags[7 - i] = "01"[num & 1]; - num >>= 1; - } - memcpy(resstr + (32 - 8) - 20, flags, 8); - } - } else if (!strncmp(str, "model", sep - str)) { - memcpy(resstr + (32 - 4) - 16, flags, 4); - memcpy(resstr + (32 - 4) - flag->bit, flags + 4, 4); - } else { - memcpy(resstr + (32 - flag->length) - flag->bit, flags, - flag->length); - } - entry->policy[flag->reg - 1] = resstr; - - return 0; + return 2; } /* parse a single list item from the legacy Python xend syntax, where From patchwork Tue Jul 25 13:05:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13326431 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DF2E0C001DE for ; Tue, 25 Jul 2023 13:07:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.569676.890621 (Exim 4.92) (envelope-from ) id 1qOHkf-0005ww-14; Tue, 25 Jul 2023 13:06:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 569676.890621; Tue, 25 Jul 2023 13:06:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHke-0005wH-TM; Tue, 25 Jul 2023 13:06:56 +0000 Received: by outflank-mailman (input) for mailman id 569676; Tue, 25 Jul 2023 13:06:55 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHkc-0004BN-UW for xen-devel@lists.xenproject.org; Tue, 25 Jul 2023 13:06:55 +0000 Received: from esa6.hc3370-68.iphmx.com (esa6.hc3370-68.iphmx.com [216.71.155.175]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0108943b-2aec-11ee-8613-37d641c3527e; Tue, 25 Jul 2023 15:06:02 +0200 (CEST) Received: from mail-co1nam11lp2171.outbound.protection.outlook.com (HELO NAM11-CO1-obe.outbound.protection.outlook.com) ([104.47.56.171]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jul 2023 09:06:46 -0400 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) by SA1PR03MB6516.namprd03.prod.outlook.com (2603:10b6:806:1c7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 13:06:42 +0000 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767]) by SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767%3]) with mapi id 15.20.6609.031; Tue, 25 Jul 2023 13:06:42 +0000 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: 0108943b-2aec-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1690290411; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=yn7kJQzbf6RnPHIK78W4GQCjFinnOtP7h79IJBxxEjo=; b=BRScAGoX2jPfpcWA8oqDJr9/P+bVw8i/pqQow86QYepy4XJ/ezlOHSlc mi0nYZEpeConzmhXqB11JRqIgmytglrBVng1BFCSFpXG7gIRud4/JV+SE hjVZl8AT/NsNu9j90jmnsNXd/gmu2PrSN2oV2xMpw5p7aBKp/PsktuXWH s=; X-IronPort-RemoteIP: 104.47.56.171 X-IronPort-MID: 116652320 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:OnJ3oaw018E45dFDgV16t+cTxyrEfRIJ4+MujC+fZmUNrF6WrkUGm mAbUW/QbvrZYzPxKtlwPdznp08Pv8LSydUyHAI/qCAxQypGp/SeCIXCJC8cHc8wwu7rFxs7s ppEOrEsCOhuExcwcz/0auCJQUFUjP3OHfykTrafYEidfCc8IA85kxVvhuUltYBhhNm9Emult Mj75sbSIzdJ4RYtWo4vw/zF8EoHUMja4mtC5QRhP60T5TcyqlFOZH4hDfDpR5fHatE88t6SH 47r0Ly/92XFyBYhYvvNfmHTKxBirhb6ZGBiu1IOM0SQqkEqSh8ai87XAME0e0ZP4whlqvgqo Dl7WT5cfi9yVkHEsLx1vxC1iEiSN4UekFPMCSDXXcB+UyQq2pYjqhljJBheAGEWxgp4KVBC3 8U+IQkKVD+kttyVn4CyTdtslO12eaEHPKtH0p1h5RfwKK9/BLvkGuDN79Ie2yosjMdTG/qYf 9AedTdkcBXHZVtIJ0sTD5U92uyvgxETcRUB8A7T+fVxvjaVlVMouFTuGIO9ltiiX8Jak1zev mvb12/4HgsbJJqUzj/tHneE37aRw36hA9hKfFG+3qc6gk+Sn3YCMycXElj4ufC2kEW8ROsKf iT4/QJr98De7neDXtT7GhG1vnOAlhodQMZLVf037hmXzajZ6BrfAXILJhZebPQ2uclwQiYlv neLkMnuHidHq6CORDSW8bL8kN+pES0cLGtHbihdSwIAuoDnuNtq0UuJSct/GqmoiNGzASv33 z2BsCk5gfMUkNIP0KK4u1vAhlpAu6T0c+L83S2PNkrN0++zTNTNi1CAgbQD0ct9EQ== IronPort-HdrOrdr: A9a23:Rny0fK+laMDsnPC1KHpuk+AHI+orL9Y04lQ7vn2ZKCYlDvBw8v rEoB11737JYUkqKRcdcLy7VJVoAkmsjKKdmLNhR4tKBTOWxVdAT7sSkrcKoQeBJ8SkzJ8k6U 4IScEXYuEYa2IUsS+Q2mSF+rgbruVujciT9JzjJqNWPGNXg90J1XYfNu/iKDwUeOCwP+tcKH M03Lsjmwad X-Talos-CUID: 9a23:OxJKwmATZiXsGLr6Exhr3ncyE/kiSFL6/UnzfH2xDlRpWpTAHA== X-Talos-MUID: 9a23:kPv/oATO5mrp4qq4RXS11DNwNZ5y8p+UCQcO0o0PtNOPNzNJbmI= X-IronPort-AV: E=Sophos;i="6.01,230,1684814400"; d="scan'208";a="116652320" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GTB7lcehk+MqNCPoFh8M1abVRhfReF+lJkobeuVvoi9bwdkO+7C5HOI+F4yTZxXNQGkpUQaHHyBVzoDYbhAmsbblhZYb2gOs0yxul7XG+zFOVohyf27m0YEBeC9PMKovcZCEKngXUQDrPTldtwrPMRabXoy3+CTQnj3WLURT1os1s5cvmYo+yPDH/MJIjFPGt9bom9lmb/mT6lsUwzrwwr55iZluutXz48QPNYBThIZuCqi9g1F29Y734IRBNUr512EBm+UtMcs+lfPU+F7uKEaImPm3g3In3dIzCkaqE83sS30n5/GnCdVuZDwyT22OzOABaj0evDZuEzGyQv2GnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HmAWMVJN7ymqGfurpuYWddbt8PjeHmT9mj43QmC7/1I=; b=Hd4wiL5YmPDuwghU1CaFs4UvKYuWRQw2+aBds0JU4TO1sg1vNRthte2GZgzCUruY3/kBVhqb1RNS4b2ijK0EvBzExiZifje7jenbJtQkMUxOObKK4LQEO7/e1LWan/z05tPkqYRBCunZzZojlTpiuAYyc9tQh9KqVMHhaIqhusd5T3x4Njeptbntaf1NOZaqpYbGbIf5zG4J9tS3gT9oofiYT7KbOSofLRdmDJBex8cQiM2gUNcgk/IflFcj7C7XLdxGdJqDDnz3lFXKRyssgLQN+Wvc8BG21khjznuWVOSXziCyKdBfp806hcZHkT8dxdeQNiTMRp4T5+K6+qpYNQ== 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=HmAWMVJN7ymqGfurpuYWddbt8PjeHmT9mj43QmC7/1I=; b=meZAiXrkZtugv3/8TbIPHmIY8l06PxrVT7D1h+05EK44Dp2a0BcK3ZrJaZXvRrs8Gw9eXXTYD2Oj6fgM0UChkT1e654j6HAkdhgM10mTBz8Fxqa6yyycubJ8oxLhrUWRl1sq4ywpyw/JGyPCY6JXi/K9fHjE1r6rUZZ9VaJ2G+I= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v4 5/6] libxl: use the cpuid feature names from cpufeatureset.h Date: Tue, 25 Jul 2023 15:05:57 +0200 Message-ID: <20230725130558.58094-6-roger.pau@citrix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725130558.58094-1-roger.pau@citrix.com> References: <20230725130558.58094-1-roger.pau@citrix.com> X-ClientProxiedBy: LO4P123CA0394.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18f::21) To SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6423:EE_|SA1PR03MB6516:EE_ X-MS-Office365-Filtering-Correlation-Id: 36bb92bb-1d37-484e-030e-08db8d0ffdc8 X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VpOfEXRP3uIJfQYGjivgL72zpAYa/9zu8Ix8eDe55aQNlaOuRet2Bqi1GIX9YGIkgIP41EIltcT0a2UHGxVmDZlMxBuhTPP/cOLDLlE5PHew38cuzorRujxpr5QyLiiW9HYZWPmT7/oqMF4fE0bWwg/kt+0fhObzL3gGXbret9LkQHPIeUXJUyeqMJ3G8sWVKlfqwwLYkkiDT1sFRRZmR8VphIXeaHQyBjG00Xe68xegSjN3W/mNpLPBi1VXxW9Si8oURwt6ECFdFq+GDM4KgJAjMnzW93/yqX4Agg3b1oeHi78meDu3od8qprCGRsfOFLZgMEwOl9aCjQIVmGAWzDsGAi6U+FyozKdn/lH6+64+s1upNjX8LPPll80Hut6clnTJyEkckZ32MlLsN9g3QAURJzUbRuKAPlFYjPmS5UZfZc9rQMvRjBxtBb+RjxezXl+l+l2VEhsM4b1AQfxbDlBBKTmPOm5FgVhepUECc6E6R83krq+4FvNpxGdIqeAEqnjzGIrpUPZS2HxDhEWNtumFEcriOFOdrKrblaMPe4Dtb+z2XhKFJIpYuQrXjZCrQ/xRDHFQN42X/JylOhjdAkwykdZzox9z+NLMmu2BCj8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6423.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(366004)(136003)(346002)(396003)(39860400002)(451199021)(6486002)(6666004)(82960400001)(478600001)(83380400001)(8936002)(1076003)(26005)(6512007)(6506007)(66946007)(38100700002)(66556008)(54906003)(6916009)(4326008)(66476007)(186003)(66574015)(2616005)(5660300002)(8676002)(2906002)(30864003)(316002)(41300700001)(86362001)(36756003)(473944003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?45Pjdpqm7Z6gGvHp7v8fqKTei9Er?= =?utf-8?q?Ew/nCnqB147kstTg2L4GWSQNAmrgIAx2BY47Hc91ADgrBoFmYCTayKgCCnXUQHpE4?= =?utf-8?q?33NmfkTj87eY+JrlCS6Y6CEK8+5riZpOPLETuUvBogfQNSE+VqeotBk1DNzrnQSnf?= =?utf-8?q?58EhcjpZ9UgGit1dRh1qWlUacV5bBnj/wL1No9+cWNx/1cKdTyyKrK4dmabkgCvl7?= =?utf-8?q?I3NOayMxGPC6uE7Q/fKPyIL6SwlhrpbI42TMrF9CkrfLn2hUSVo3K0U3Z9p3K2CDd?= =?utf-8?q?pj2n/RU22Lj9M+yr+xuotCJsXZX5SaWrs1uoKaq8SUluyM8qF2Vz1wpJU6/QBMhfK?= =?utf-8?q?IVoK4IOqpxdG1QvoHQAwbXyNcf1iVsU6fwDr9Bh/kMIeq371EnpAR+Oo1EYYJsz7I?= =?utf-8?q?nfIRc3qkHoI+G4GbQMp9hT+tkIJlSW6DiskRBkivJPKET5ryKQ4+EplaAd6JYBKtC?= =?utf-8?q?6gAsRO2rjRGxR8nR3Two8nxkp6sq26BKVMfFbB0szPVjciVnhV7HupSdUq1b+BVex?= =?utf-8?q?ems8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8?q?MbzCL8egyN/7R5kNgX7xHZTcAy0ZRzUdm2npTGchUXMndcj79WNZB3POWuGuJRijD?= =?utf-8?q?CACbRG3XFaYzBvvUV5djhsSKXp+D4QD0/ppOkaAA08PThc/RHc3ji33/fckU3kwjm?= =?utf-8?q?V9nYcCo+/5xvRc4+w4Kqz4rzuFBi3iqcFQ=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: RuAEejb1AwvZ6Ebo/BZLnQTc0UA5ubBqQRMFpvIy3vSPFmcWLru6wvz5VBth9FkNGwcV7/AbZl4a26w/9NnW1/EnwvYFmU89ufU9BjrGrj/gDT/eSeSHCRgm9hzes88ffl8eKLl7grZuxtgG/clEsQNFMxuK3FdLTGpuD2TLpHFCqxkLH1GFohpypnX2yGNkV0GekjWFREFQ8sIansb/gyL7Zpv4R+0d+lpIXeDDdRsM0noPFJCQutW4GNUWHKnFrAcCkwygzv/0MT6M4EDKzE0pRTjmFDmY6Yd8MHZcXf05Yq206u5fVTXtgqQRzf3XsXT8wPmj7pvP/jLlubJcEon4XCA89IgX7BuU2DQrkIufzGoVJOZuWd4GVn08rszT194FYNGvPJbzGNRoe+6andYdNJH3jxWta+zf+m/2jYqJHPhci9RWCXdVmRBZjN+YWryYmXC/WYQquEj1ePFZ+j1vO1IJnS9BBHj6LYPHQXdiYqq04EI19g/437RQqjR1ado6gIC6696OjR0f9Nq37inwNywVHR32mDyg/VwYhmOr3P/ZRMc5qr4NegISiRwshjxGi4ZQgskjLXG613teaa7k9wd33ipqtkBqtykUFMqiVuOAcBl/2cihy9A01RnedM9bJ+WVmvdFVDax+MAPiCec+RS4UGNkXSOhKby05fLUl407x6S0LwAdYDTOanDbWb/Gp+6PTnmYsvpkG8Cc1WG7covhVeV9vHNKN/cwvHojQPwFCrcOqmho/JMKQqhkTlAsebI3CCyRJvKU9u54J9Ihb/+q6kR/4cMyW6FO64QoHnNZ5ZLS6cG/VfEE0ITt X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36bb92bb-1d37-484e-030e-08db8d0ffdc8 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6423.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 13:06:42.7554 (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: F6KJyBpWpuNKzUQxbf6Y4xBe7sKmfSK5UTOB/mno8v6QihY0m0KPu7qcmb/0In0yI8V8DFLaofpTFeA+bPCp2Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR03MB6516 The current implementation in libxl_cpuid_parse_config() requires keeping a list of cpuid feature bits that should be mostly in sync with the contents of cpufeatureset.h. Avoid such duplication by using the automatically generated list of cpuid features in INIT_FEATURE_NAMES in order to map feature names to featureset bits, and then translate from featureset bits into cpuid leaf, subleaf, register tuple. Note that the full contents of the previous cpuid translation table can't be removed. That's because some feature names allowed by libxl are not described in the featuresets, or because naming has diverged and the previous nomenclature is preserved for compatibility reasons. Should result in no functional change observed by callers, albeit some new cpuid features will be available as a result of the change. While there constify cpuid_flags name field. Signed-off-by: Roger Pau Monné Reviewed-by: Anthony PERARD --- Changes since v1: - const unnamed structure cast. - Declare struct feature_name outside the function. - Use strcmp. - Fix indentation. - Add back missing feature name options. - Return ERROR_NOMEM if allocation fails. - Improve xl.cfg documentation about how to reference the features described in the public header. --- docs/man/xl.cfg.5.pod.in | 24 +-- tools/libs/light/libxl_cpuid.c | 267 ++++++++++++--------------------- tools/xl/xl_parse.c | 3 + 3 files changed, 107 insertions(+), 187 deletions(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 3979be2a590a..55161856f4c7 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -2010,24 +2010,16 @@ proccount procpkg stepping =back -List of keys taking a character: +List of keys taking a character can be found in the public header file +L -=over 4 - -3dnow 3dnowext 3dnowprefetch abm acpi adx aes altmovcr8 apic arat avx avx2 -avx512-4fmaps avx512-4vnniw avx512bw avx512cd avx512dq avx512er avx512f -avx512ifma avx512pf avx512vbmi avx512vl bmi1 bmi2 clflushopt clfsh clwb cmov -cmplegacy cmpxchg16 cmpxchg8 cmt cntxid dca de ds dscpl dtes64 erms est extapic -f16c ffxsr fma fma4 fpu fsgsbase fxsr hle htt hypervisor ia64 ibs invpcid -invtsc lahfsahf lm lwp mca mce misalignsse mmx mmxext monitor movbe mpx msr -mtrr nodeid nx ospke osvw osxsave pae page1gb pat pbe pcid pclmulqdq pdcm -perfctr_core perfctr_nb pge pku popcnt pse pse36 psn rdrand rdseed rdtscp rtm -sha skinit smap smep smx ss sse sse2 sse3 sse4.1 sse4.2 sse4_1 sse4_2 sse4a -ssse3 svm svm_decode svm_lbrv svm_npt svm_nrips svm_pausefilt svm_tscrate -svm_vmcbclean syscall sysenter tbm tm tm2 topoext tsc tsc-deadline tsc_adjust -umip vme vmx wdt x2apic xop xsave xtpr +The feature names described in C should be specified in all +lowercase letters, and with underscores converted to hyphens. For example in +order to reference feature C the string C should be used. -=back +Note that C is described as an option that takes a value, and that +takes precedence over the C flag in C. The feature +flag must be referenced as C. =back diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index f04b192c0e44..0daa564abb81 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -14,6 +14,8 @@ #include "libxl_internal.h" +#include + int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl) { return !*pl || (!libxl_cpuid_policy_list_length(pl) && !(*pl)->msr); @@ -60,7 +62,7 @@ void libxl_cpuid_dispose(libxl_cpuid_policy_list *pl) * Used for the static structure describing all features. */ struct cpuid_flags { - char* name; + const char *name; uint32_t leaf; uint32_t subleaf; int reg; @@ -153,7 +155,19 @@ static int cpuid_add(libxl_cpuid_policy_list *policy, entry->policy[flag->reg - 1] = resstr; return 0; +} + +struct feature_name { + const char *name; + unsigned int bit; +}; + +static int search_feature(const void *a, const void *b) +{ + const char *key = a; + const char *feat = ((const struct feature_name *)b)->name; + return strcmp(key, feat); } /* parse a single key=value pair and translate it into the libxc @@ -176,208 +190,42 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *policy, const char* str) {"proccount", 0x00000001, NA, CPUID_REG_EBX, 16, 8}, {"localapicid", 0x00000001, NA, CPUID_REG_EBX, 24, 8}, - {"sse3", 0x00000001, NA, CPUID_REG_ECX, 0, 1}, - {"pclmulqdq", 0x00000001, NA, CPUID_REG_ECX, 1, 1}, - {"dtes64", 0x00000001, NA, CPUID_REG_ECX, 2, 1}, - {"monitor", 0x00000001, NA, CPUID_REG_ECX, 3, 1}, - {"dscpl", 0x00000001, NA, CPUID_REG_ECX, 4, 1}, - {"vmx", 0x00000001, NA, CPUID_REG_ECX, 5, 1}, - {"smx", 0x00000001, NA, CPUID_REG_ECX, 6, 1}, {"est", 0x00000001, NA, CPUID_REG_ECX, 7, 1}, - {"tm2", 0x00000001, NA, CPUID_REG_ECX, 8, 1}, - {"ssse3", 0x00000001, NA, CPUID_REG_ECX, 9, 1}, {"cntxid", 0x00000001, NA, CPUID_REG_ECX, 10, 1}, - {"fma", 0x00000001, NA, CPUID_REG_ECX, 12, 1}, {"cmpxchg16", 0x00000001, NA, CPUID_REG_ECX, 13, 1}, - {"xtpr", 0x00000001, NA, CPUID_REG_ECX, 14, 1}, - {"pdcm", 0x00000001, NA, CPUID_REG_ECX, 15, 1}, - {"pcid", 0x00000001, NA, CPUID_REG_ECX, 17, 1}, - {"dca", 0x00000001, NA, CPUID_REG_ECX, 18, 1}, /* Linux uses sse4_{1,2}. Keep sse4.{1,2} for compatibility */ {"sse4_1", 0x00000001, NA, CPUID_REG_ECX, 19, 1}, {"sse4.1", 0x00000001, NA, CPUID_REG_ECX, 19, 1}, {"sse4_2", 0x00000001, NA, CPUID_REG_ECX, 20, 1}, {"sse4.2", 0x00000001, NA, CPUID_REG_ECX, 20, 1}, - {"x2apic", 0x00000001, NA, CPUID_REG_ECX, 21, 1}, - {"movbe", 0x00000001, NA, CPUID_REG_ECX, 22, 1}, - {"popcnt", 0x00000001, NA, CPUID_REG_ECX, 23, 1}, - {"tsc-deadline", 0x00000001, NA, CPUID_REG_ECX, 24, 1}, {"aes", 0x00000001, NA, CPUID_REG_ECX, 25, 1}, - {"xsave", 0x00000001, NA, CPUID_REG_ECX, 26, 1}, - {"osxsave", 0x00000001, NA, CPUID_REG_ECX, 27, 1}, - {"avx", 0x00000001, NA, CPUID_REG_ECX, 28, 1}, - {"f16c", 0x00000001, NA, CPUID_REG_ECX, 29, 1}, - {"rdrand", 0x00000001, NA, CPUID_REG_ECX, 30, 1}, - {"hypervisor", 0x00000001, NA, CPUID_REG_ECX, 31, 1}, - - {"fpu", 0x00000001, NA, CPUID_REG_EDX, 0, 1}, - {"vme", 0x00000001, NA, CPUID_REG_EDX, 1, 1}, - {"de", 0x00000001, NA, CPUID_REG_EDX, 2, 1}, - {"pse", 0x00000001, NA, CPUID_REG_EDX, 3, 1}, - {"tsc", 0x00000001, NA, CPUID_REG_EDX, 4, 1}, - {"msr", 0x00000001, NA, CPUID_REG_EDX, 5, 1}, - {"pae", 0x00000001, NA, CPUID_REG_EDX, 6, 1}, - {"mce", 0x00000001, NA, CPUID_REG_EDX, 7, 1}, + {"cmpxchg8", 0x00000001, NA, CPUID_REG_EDX, 8, 1}, - {"apic", 0x00000001, NA, CPUID_REG_EDX, 9, 1}, {"sysenter", 0x00000001, NA, CPUID_REG_EDX, 11, 1}, - {"mtrr", 0x00000001, NA, CPUID_REG_EDX, 12, 1}, - {"pge", 0x00000001, NA, CPUID_REG_EDX, 13, 1}, - {"mca", 0x00000001, NA, CPUID_REG_EDX, 14, 1}, - {"cmov", 0x00000001, NA, CPUID_REG_EDX, 15, 1}, - {"pat", 0x00000001, NA, CPUID_REG_EDX, 16, 1}, - {"pse36", 0x00000001, NA, CPUID_REG_EDX, 17, 1}, {"psn", 0x00000001, NA, CPUID_REG_EDX, 18, 1}, {"clfsh", 0x00000001, NA, CPUID_REG_EDX, 19, 1}, - {"ds", 0x00000001, NA, CPUID_REG_EDX, 21, 1}, - {"acpi", 0x00000001, NA, CPUID_REG_EDX, 22, 1}, - {"mmx", 0x00000001, NA, CPUID_REG_EDX, 23, 1}, - {"fxsr", 0x00000001, NA, CPUID_REG_EDX, 24, 1}, - {"sse", 0x00000001, NA, CPUID_REG_EDX, 25, 1}, - {"sse2", 0x00000001, NA, CPUID_REG_EDX, 26, 1}, - {"ss", 0x00000001, NA, CPUID_REG_EDX, 27, 1}, - {"htt", 0x00000001, NA, CPUID_REG_EDX, 28, 1}, {"tm", 0x00000001, NA, CPUID_REG_EDX, 29, 1}, {"ia64", 0x00000001, NA, CPUID_REG_EDX, 30, 1}, {"pbe", 0x00000001, NA, CPUID_REG_EDX, 31, 1}, {"arat", 0x00000006, NA, CPUID_REG_EAX, 2, 1}, - {"fsgsbase", 0x00000007, 0, CPUID_REG_EBX, 0, 1}, {"tsc_adjust", 0x00000007, 0, CPUID_REG_EBX, 1, 1}, - {"bmi1", 0x00000007, 0, CPUID_REG_EBX, 3, 1}, - {"hle", 0x00000007, 0, CPUID_REG_EBX, 4, 1}, - {"avx2", 0x00000007, 0, CPUID_REG_EBX, 5, 1}, - {"smep", 0x00000007, 0, CPUID_REG_EBX, 7, 1}, - {"bmi2", 0x00000007, 0, CPUID_REG_EBX, 8, 1}, - {"erms", 0x00000007, 0, CPUID_REG_EBX, 9, 1}, - {"invpcid", 0x00000007, 0, CPUID_REG_EBX, 10, 1}, - {"rtm", 0x00000007, 0, CPUID_REG_EBX, 11, 1}, {"cmt", 0x00000007, 0, CPUID_REG_EBX, 12, 1}, - {"mpx", 0x00000007, 0, CPUID_REG_EBX, 14, 1}, - {"avx512f", 0x00000007, 0, CPUID_REG_EBX, 16, 1}, - {"avx512dq", 0x00000007, 0, CPUID_REG_EBX, 17, 1}, - {"rdseed", 0x00000007, 0, CPUID_REG_EBX, 18, 1}, - {"adx", 0x00000007, 0, CPUID_REG_EBX, 19, 1}, - {"smap", 0x00000007, 0, CPUID_REG_EBX, 20, 1}, - {"avx512-ifma", 0x00000007, 0, CPUID_REG_EBX, 21, 1}, - {"clflushopt", 0x00000007, 0, CPUID_REG_EBX, 23, 1}, - {"clwb", 0x00000007, 0, CPUID_REG_EBX, 24, 1}, - {"proc-trace", 0x00000007, 0, CPUID_REG_EBX, 25, 1}, - {"avx512pf", 0x00000007, 0, CPUID_REG_EBX, 26, 1}, - {"avx512er", 0x00000007, 0, CPUID_REG_EBX, 27, 1}, - {"avx512cd", 0x00000007, 0, CPUID_REG_EBX, 28, 1}, - {"sha", 0x00000007, 0, CPUID_REG_EBX, 29, 1}, - {"avx512bw", 0x00000007, 0, CPUID_REG_EBX, 30, 1}, - {"avx512vl", 0x00000007, 0, CPUID_REG_EBX, 31, 1}, - - {"prefetchwt1", 0x00000007, 0, CPUID_REG_ECX, 0, 1}, - {"avx512-vbmi", 0x00000007, 0, CPUID_REG_ECX, 1, 1}, - {"umip", 0x00000007, 0, CPUID_REG_ECX, 2, 1}, - {"pku", 0x00000007, 0, CPUID_REG_ECX, 3, 1}, - {"ospke", 0x00000007, 0, CPUID_REG_ECX, 4, 1}, - {"avx512-vbmi2", 0x00000007, 0, CPUID_REG_ECX, 6, 1}, - {"cet-ss", 0x00000007, 0, CPUID_REG_ECX, 7, 1}, - {"gfni", 0x00000007, 0, CPUID_REG_ECX, 8, 1}, - {"vaes", 0x00000007, 0, CPUID_REG_ECX, 9, 1}, - {"vpclmulqdq", 0x00000007, 0, CPUID_REG_ECX, 10, 1}, - {"avx512-vnni", 0x00000007, 0, CPUID_REG_ECX, 11, 1}, - {"avx512-bitalg",0x00000007, 0, CPUID_REG_ECX, 12, 1}, - {"avx512-vpopcntdq",0x00000007,0,CPUID_REG_ECX, 14, 1}, - {"rdpid", 0x00000007, 0, CPUID_REG_ECX, 22, 1}, - {"cldemote", 0x00000007, 0, CPUID_REG_ECX, 25, 1}, - {"pks", 0x00000007, 0, CPUID_REG_ECX, 31, 1}, - - {"avx512-4vnniw",0x00000007, 0, CPUID_REG_EDX, 2, 1}, - {"avx512-4fmaps",0x00000007, 0, CPUID_REG_EDX, 3, 1}, - {"fsrm", 0x00000007, 0, CPUID_REG_EDX, 4, 1}, - {"avx512-vp2intersect",0x00000007,0,CPUID_REG_EDX,8, 1}, - {"srbds-ctrl", 0x00000007, 0, CPUID_REG_EDX, 9, 1}, - {"md-clear", 0x00000007, 0, CPUID_REG_EDX, 10, 1}, - {"serialize", 0x00000007, 0, CPUID_REG_EDX, 14, 1}, - {"tsxldtrk", 0x00000007, 0, CPUID_REG_EDX, 16, 1}, - {"cet-ibt", 0x00000007, 0, CPUID_REG_EDX, 20, 1}, - {"avx512-fp16", 0x00000007, 0, CPUID_REG_EDX, 23, 1}, - {"ibrsb", 0x00000007, 0, CPUID_REG_EDX, 26, 1}, - {"stibp", 0x00000007, 0, CPUID_REG_EDX, 27, 1}, - {"l1d-flush", 0x00000007, 0, CPUID_REG_EDX, 28, 1}, - {"arch-caps", 0x00000007, 0, CPUID_REG_EDX, 29, 1}, - {"core-caps", 0x00000007, 0, CPUID_REG_EDX, 30, 1}, - {"ssbd", 0x00000007, 0, CPUID_REG_EDX, 31, 1}, - - {"avx-vnni", 0x00000007, 1, CPUID_REG_EAX, 4, 1}, - {"avx512-bf16", 0x00000007, 1, CPUID_REG_EAX, 5, 1}, - {"fzrm", 0x00000007, 1, CPUID_REG_EAX, 10, 1}, - {"fsrs", 0x00000007, 1, CPUID_REG_EAX, 11, 1}, - {"fsrcs", 0x00000007, 1, CPUID_REG_EAX, 12, 1}, - {"wrmsrns", 0x00000007, 1, CPUID_REG_EAX, 19, 1}, - {"avx-ifma", 0x00000007, 1, CPUID_REG_EAX, 23, 1}, - - {"avx-vnni-int8",0x00000007, 1, CPUID_REG_EDX, 4, 1}, - {"avx-ne-convert",0x00000007, 1, CPUID_REG_EDX, 5, 1}, - {"cet-sss", 0x00000007, 1, CPUID_REG_EDX, 18, 1}, - - {"intel-psfd", 0x00000007, 2, CPUID_REG_EDX, 0, 1}, - {"ipred-ctrl", 0x00000007, 2, CPUID_REG_EDX, 1, 1}, - {"rrsba-ctrl", 0x00000007, 2, CPUID_REG_EDX, 2, 1}, - {"ddp-ctrl", 0x00000007, 2, CPUID_REG_EDX, 3, 1}, - {"bhi-ctrl", 0x00000007, 2, CPUID_REG_EDX, 4, 1}, - {"mcdt-no", 0x00000007, 2, CPUID_REG_EDX, 5, 1}, {"lahfsahf", 0x80000001, NA, CPUID_REG_ECX, 0, 1}, {"cmplegacy", 0x80000001, NA, CPUID_REG_ECX, 1, 1}, - {"svm", 0x80000001, NA, CPUID_REG_ECX, 2, 1}, - {"extapic", 0x80000001, NA, CPUID_REG_ECX, 3, 1}, {"altmovcr8", 0x80000001, NA, CPUID_REG_ECX, 4, 1}, - {"abm", 0x80000001, NA, CPUID_REG_ECX, 5, 1}, - {"sse4a", 0x80000001, NA, CPUID_REG_ECX, 6, 1}, - {"misalignsse", 0x80000001, NA, CPUID_REG_ECX, 7, 1}, - {"3dnowprefetch",0x80000001, NA, CPUID_REG_ECX, 8, 1}, - {"osvw", 0x80000001, NA, CPUID_REG_ECX, 9, 1}, - {"ibs", 0x80000001, NA, CPUID_REG_ECX, 10, 1}, - {"xop", 0x80000001, NA, CPUID_REG_ECX, 11, 1}, - {"skinit", 0x80000001, NA, CPUID_REG_ECX, 12, 1}, - {"wdt", 0x80000001, NA, CPUID_REG_ECX, 13, 1}, - {"lwp", 0x80000001, NA, CPUID_REG_ECX, 15, 1}, - {"fma4", 0x80000001, NA, CPUID_REG_ECX, 16, 1}, {"nodeid", 0x80000001, NA, CPUID_REG_ECX, 19, 1}, - {"tbm", 0x80000001, NA, CPUID_REG_ECX, 21, 1}, - {"topoext", 0x80000001, NA, CPUID_REG_ECX, 22, 1}, {"perfctr_core", 0x80000001, NA, CPUID_REG_ECX, 23, 1}, {"perfctr_nb", 0x80000001, NA, CPUID_REG_ECX, 24, 1}, - {"syscall", 0x80000001, NA, CPUID_REG_EDX, 11, 1}, - {"nx", 0x80000001, NA, CPUID_REG_EDX, 20, 1}, - {"mmxext", 0x80000001, NA, CPUID_REG_EDX, 22, 1}, - {"ffxsr", 0x80000001, NA, CPUID_REG_EDX, 25, 1}, - {"page1gb", 0x80000001, NA, CPUID_REG_EDX, 26, 1}, - {"rdtscp", 0x80000001, NA, CPUID_REG_EDX, 27, 1}, - {"lm", 0x80000001, NA, CPUID_REG_EDX, 29, 1}, - {"3dnowext", 0x80000001, NA, CPUID_REG_EDX, 30, 1}, - {"3dnow", 0x80000001, NA, CPUID_REG_EDX, 31, 1}, - {"procpkg", 0x00000004, 0, CPUID_REG_EAX, 26, 6}, {"invtsc", 0x80000007, NA, CPUID_REG_EDX, 8, 1}, - {"clzero", 0x80000008, NA, CPUID_REG_EBX, 0, 1}, - {"rstr-fp-err-ptrs", 0x80000008, NA, CPUID_REG_EBX, 2, 1}, - {"wbnoinvd", 0x80000008, NA, CPUID_REG_EBX, 9, 1}, - {"ibpb", 0x80000008, NA, CPUID_REG_EBX, 12, 1}, - {"ibrs", 0x80000008, NA, CPUID_REG_EBX, 14, 1}, - {"amd-stibp", 0x80000008, NA, CPUID_REG_EBX, 15, 1}, - {"ibrs-always", 0x80000008, NA, CPUID_REG_EBX, 16, 1}, - {"stibp-always", 0x80000008, NA, CPUID_REG_EBX, 17, 1}, - {"ibrs-fast", 0x80000008, NA, CPUID_REG_EBX, 18, 1}, - {"ibrs-same-mode", 0x80000008, NA, CPUID_REG_EBX, 19, 1}, - {"no-lmsl", 0x80000008, NA, CPUID_REG_EBX, 20, 1}, {"ppin", 0x80000008, NA, CPUID_REG_EBX, 23, 1}, - {"amd-ssbd", 0x80000008, NA, CPUID_REG_EBX, 24, 1}, - {"virt-ssbd", 0x80000008, NA, CPUID_REG_EBX, 25, 1}, - {"ssb-no", 0x80000008, NA, CPUID_REG_EBX, 26, 1}, - {"psfd", 0x80000008, NA, CPUID_REG_EBX, 28, 1}, {"btc-no", 0x80000008, NA, CPUID_REG_EBX, 29, 1}, - {"ibpb-ret", 0x80000008, NA, CPUID_REG_EBX, 30, 1}, {"nc", 0x80000008, NA, CPUID_REG_ECX, 0, 8}, {"apicidsize", 0x80000008, NA, CPUID_REG_ECX, 12, 4}, @@ -391,17 +239,63 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *policy, const char* str) {"svm_pausefilt",0x8000000a, NA, CPUID_REG_EDX, 10, 1}, {"lfence+", 0x80000021, NA, CPUID_REG_EAX, 2, 1}, - {"nscb", 0x80000021, NA, CPUID_REG_EAX, 6, 1}, - {"auto-ibrs", 0x80000021, NA, CPUID_REG_EAX, 8, 1}, - {"cpuid-user-dis", 0x80000021, NA, CPUID_REG_EAX, 17, 1}, {"maxhvleaf", 0x40000000, NA, CPUID_REG_EAX, 0, 8}, {NULL, 0, NA, CPUID_REG_INV, 0, 0} }; + static const struct feature_name features[] = INIT_FEATURE_NAMES; + /* + * NB: if we switch to using a cpu_policy derived object instead of a + * libxl_cpuid_policy_list we could get rid of the featureset -> cpuid leaf + * conversion table and use a featureset directly as we have conversions + * to/from featureset and cpu_policy. + */ + static const struct { + enum { FEAT_CPUID, FEAT_MSR } type; + union { + struct { + uint32_t leaf, subleaf; + unsigned int reg; + } cpuid; + struct { + uint32_t index; + unsigned int reg; + } msr; + }; + } feature_to_policy[] = { +#define CPUID_ENTRY(l, s, r) \ + { .type = FEAT_CPUID, .cpuid.leaf = l, .cpuid.subleaf = s, .cpuid.reg = r } +#define MSR_ENTRY(i, r) \ + { .type = FEAT_MSR, .msr.index = i, .msr.reg = r } + CPUID_ENTRY(0x00000001, NA, CPUID_REG_EDX), + CPUID_ENTRY(0x00000001, NA, CPUID_REG_ECX), + CPUID_ENTRY(0x80000001, NA, CPUID_REG_EDX), + CPUID_ENTRY(0x80000001, NA, CPUID_REG_ECX), + CPUID_ENTRY(0x0000000D, 1, CPUID_REG_EAX), + CPUID_ENTRY(0x00000007, 0, CPUID_REG_EBX), + CPUID_ENTRY(0x00000007, 0, CPUID_REG_ECX), + CPUID_ENTRY(0x80000007, NA, CPUID_REG_EDX), + CPUID_ENTRY(0x80000008, NA, CPUID_REG_EBX), + CPUID_ENTRY(0x00000007, 0, CPUID_REG_EDX), + CPUID_ENTRY(0x00000007, 1, CPUID_REG_EAX), + CPUID_ENTRY(0x80000021, NA, CPUID_REG_EAX), + CPUID_ENTRY(0x00000007, 1, CPUID_REG_EBX), + CPUID_ENTRY(0x00000007, 2, CPUID_REG_EDX), + CPUID_ENTRY(0x00000007, 1, CPUID_REG_ECX), + CPUID_ENTRY(0x00000007, 1, CPUID_REG_EDX), + MSR_ENTRY(0x10a, CPUID_REG_EAX), + MSR_ENTRY(0x10a, CPUID_REG_EDX), +#undef MSR_ENTRY +#undef CPUID_ENTRY + }; #undef NA const char *sep, *val; + char *name; const struct cpuid_flags *flag; + const struct feature_name *feat; + + BUILD_BUG_ON(ARRAY_SIZE(feature_to_policy) != FEATURESET_NR_ENTRIES); sep = strchr(str, '='); if (sep == NULL) { @@ -414,6 +308,37 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *policy, const char* str) return cpuid_add(policy, flag, val); } + /* Provide a NUL terminated feature name to the search helper. */ + name = strndup(str, sep - str); + if (name == NULL) + return ERROR_NOMEM; + + feat = bsearch(name, features, ARRAY_SIZE(features), sizeof(features[0]), + search_feature); + free(name); + + if (feat == NULL) + return 2; + + switch (feature_to_policy[feat->bit / 32].type) { + case FEAT_CPUID: + { + struct cpuid_flags f; + + f.name = feat->name; + f.leaf = feature_to_policy[feat->bit / 32].cpuid.leaf; + f.subleaf = feature_to_policy[feat->bit / 32].cpuid.subleaf; + f.reg = feature_to_policy[feat->bit / 32].cpuid.reg; + f.bit = feat->bit % 32; + f.length = 1; + + return cpuid_add(policy, &f, val); + } + + case FEAT_MSR: + return 2; + } + return 2; } diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index f036e56fc239..7bf587455d08 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -2620,6 +2620,9 @@ skip_usbdev: case 3: errstr = "illegal CPUID value (must be: [0|1|x|k|s])"; break; + case ERROR_NOMEM: + errstr = "out of memory"; + break; default: errstr = "unknown error"; break; From patchwork Tue Jul 25 13:05:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13326430 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16581C001E0 for ; Tue, 25 Jul 2023 13:07:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.569675.890611 (Exim 4.92) (envelope-from ) id 1qOHkd-0005f8-Md; Tue, 25 Jul 2023 13:06:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 569675.890611; Tue, 25 Jul 2023 13:06:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHkd-0005ez-Ja; Tue, 25 Jul 2023 13:06:55 +0000 Received: by outflank-mailman (input) for mailman id 569675; Tue, 25 Jul 2023 13:06:54 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOHkc-0003uq-9c for xen-devel@lists.xenproject.org; Tue, 25 Jul 2023 13:06:54 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1f372882-2aec-11ee-b23f-6b7b168915f2; Tue, 25 Jul 2023 15:06:53 +0200 (CEST) Received: from mail-co1nam11lp2175.outbound.protection.outlook.com (HELO NAM11-CO1-obe.outbound.protection.outlook.com) ([104.47.56.175]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jul 2023 09:06:51 -0400 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) by SA1PR03MB6516.namprd03.prod.outlook.com (2603:10b6:806:1c7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 13:06:49 +0000 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767]) by SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::2e0e:5665:96a7:5767%3]) with mapi id 15.20.6609.031; Tue, 25 Jul 2023 13:06:49 +0000 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: 1f372882-2aec-11ee-b23f-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1690290413; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=8h94lYnckg0tD+pN5EVmt3fI//N3Vydy/cqPpyKBrQo=; b=hLZFRLreukjkjmYEWIMxHGqfiAgCPjLQ7+9NvCyrMQHU5Zs91OQhq8yG S/ytbkDO6LohsErBh1E3F/RHnPli+kmHL6RuGH2jbZmLE3JDAuLA00uzN FzoOB/1o71ZJnMb6sb/mL5BzEbfdQSHHWSdtXJ8kgZuHVUvEVH6Ttjn9O s=; X-IronPort-RemoteIP: 104.47.56.175 X-IronPort-MID: 117381056 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:cGTcoK3T0sBB2+9Io/bD5fdwkn2cJEfYwER7XKvMYLTBsI5bpzUBz WJKCz/XO/iONGKmeIx2Otvj8EpTuJbRmoVlGgA/pC1hF35El5HIVI+TRqvS04F+DeWYFR46s J9OAjXkBJppJpMJjk71atANlVEliefTAOK6ULWeUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tq3qMDEULOf82cc3lk8teTb8XuDgNyo4GlD5gNkOKgS1LPjvyJ94Kw3dPnZw0TQGuG4LsbiL 87fwbew+H/u/htFIrtJRZ6iLyXm6paLVeS/oiI+t5qK23CulQRrukoPD9IOaF8/ttm8t4sZJ OOhF3CHYVxB0qXkwIzxWvTDes10FfUuFLTveRBTvSEPpqFvnrSFL/hGVSkL0YMkFulfOj9Nq tpHJw00bwm8wMWv/em7S7FPmZF2RCXrFNt3VnBI6xj8VK9jareaBqLA6JlfwSs6gd1IEbDGf c0FZDFzbRPGJRpSJlMQD5F4l+Ct7pX9W2QA9BTJ+uxqvS6Kk1EZPLvFabI5fvSQQspYhACAr 3/u9GXlGBAKcteYzFJp91r137CUzXqjBdx6+LuQ/aJPglye520pVyYdFlqlp6iBh2WGYocKQ 6AT0m90xUQoz2S7Q9+4UxCmrXqsuh8HR8EWA+A88BuKyKff/0CeHGdsZiFFQMwrsokxXzNC/ l2GhdTyHhR0raaYD3ma89+pQSiaPCEUKSoJYnYCRA5cut37+ths01TIU8ppF7OzgpvtAzbsz juWrS84wbIOkcoM0Kb99lfC696xmqX0oscOzl2/dgqYAslRP+ZJu6TABYDn0Mt9 IronPort-HdrOrdr: A9a23:JI4szKwbv3O7ecj5K3+3KrPxaeskLtp133Aq2lEZdPU1SL3sqy nKpp906faaslYssQ4b6Ky90cW7IE80lqQFkrX5Q43SPjUO0VHAROtfBODZsl7d8kPFh4tgPa wJSdkANDWZZ2IXsS6QijPWLz7uquPrzImYwd77i1NRZUVSbadkhj0JeDpy0CdNNXd77V5SLu vt2iKDzQDQCEj/Ff7LYkUtbqz4vtjWk5CjSQcebiRXkTWmvHeT8bvnFBrd9QsfVj4n+8ZezU H11zbh47mlsbWdwhvRvlWjiKh+qZ/a095eA87JrNYTJi6EsHfPWK1RH4eauSwzoqWUyHtCqq i1nz4Qe/5r7m/XfCWOrQDz1xLG2DIjgkWSsmOwsD/YuMnkQzB/NMZbn4JedXLimjAdgO0= X-Talos-CUID: 9a23:fiZWLGNCS0LeUO5DY3dkq2hLFf0cc2Tii1DJHhS4CD5KV+jA X-Talos-MUID: 9a23:go6S4AQaWtZ4cXdfRXTn2BRgNcpJ4p7xM0tOkIsA6vGJHhRJbmI= X-IronPort-AV: E=Sophos;i="6.01,230,1684814400"; d="scan'208";a="117381056" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XdFIcAWrIrreNII2IBy/vsOV4e6ygiJo3meTf5PdODv2bAD9bvZaoBlGhCbThEx/f9T1AxTqv8M7lU4pCLza/3+WDlNCpHzvbUsqmDD+eckqjFT801+2D4/tyRh2NKRVPOhcZqpH8OZbnAsntdtlCoq5S9X+tzOFMBMhG6Ijcn9jQcjPMsfPEWtcXHVMeE8SFrMGCALHVr+EspJsf0/ku6wr/GaL3lkvyOo2q5HK2YnsuIGcTrp/gqI5GPt5Ps/CfZNf5Eq98HP1SZzQEGcpbvr7Ejo6jBcpoFOeq5gEnrYVckiBbB00AhWw3XhFsRsqMTqzN1IlE7Hhotz/arAnvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IkXSjb3Rn7PBge9Ur09P08ZeEBi8VRA2CbzLrLn2KAg=; b=fTlP60mScZM/FOJl/eSxo1k09CrSYsRjth07E5GXFpsGa2p2TX7vQoD623rBU87uOzgDxo2QssSY/CwXyF0vqVeHUH1NnLycwLtiIWUuMIcJBoHnyuDMCjFXivIUcFACS2+1Gi4nO90JMR/AqeHrDczE0NsGilIX4c+V8WfXHVFTpbuJyZZTZ9fuLjR6ebldNSMyQEbayWyNUVmOOI4AZk8nJv/cyhhLNOeB1/sNyuAGAV3umGi6OhscpB/PsL/YmmjJsABx19V8dluqGc9xmPjrMUzXWQkdcQPhJQgwM7WwWOej89ggEs3nKSBeFPlOmh3Oh2u1lg1ZIsynRKkR0Q== 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=IkXSjb3Rn7PBge9Ur09P08ZeEBi8VRA2CbzLrLn2KAg=; b=XZ/7p1Pi6PXpxBFCIZKyNukTXmN6X4gKWIgmNWEF8c308GpdmWfZYAmmxamLyATl3DkNxqj4eGURk0XCIPARPZave06Kei2SJ5eeZVuG1JbPps2Nhw/OOrQ8TtlDZm2FlmpLU360lWfIqZqxhv+S070UEmsz47MDm1MOvdsD7/U= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH v4 6/6] libxl: add support for parsing MSR features Date: Tue, 25 Jul 2023 15:05:58 +0200 Message-ID: <20230725130558.58094-7-roger.pau@citrix.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725130558.58094-1-roger.pau@citrix.com> References: <20230725130558.58094-1-roger.pau@citrix.com> X-ClientProxiedBy: LO2P265CA0468.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a2::24) To SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6423:EE_|SA1PR03MB6516:EE_ X-MS-Office365-Filtering-Correlation-Id: d2b71db7-93f5-46de-11ec-08db8d10014d X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pdC8HJ24MckIsjVkpCU3dR8pauJH4DDum1JnCrj24clURoVopgExhMe65UNFFnQGVlk6sbCcXUnlUN9gvnq+UWn3t/MYCpp3d6qPoINcMpfiU9stj8cfEWelckzDZD/nigZTAsDAMoFRj1LJ5FyS9c8g5+JjfJDpCzbx9Z+dy1GTIoiFRGKhKLp65XTdy1fBOx1E4VQ6c1x4f+Qmel8325VHzpHzKRbtkC0RqAEFLttf9Hwu6VkAXHtZTHpIX0rSetwkZmUJ1gr3YcmiXN9YPOOgE/1xqa6f2nI0cFfKxqTMVAtZk7qUjrBgOH5Y4919zQpNRZv0FkXMNa7d3/U5XJzsQ0q+QqenV1AzUsZ0lsoZXQOf1O4Npd/LXkbTG+VcAkPAL9xFC3TFZWY/Cg95woy9frBfEF1ADU7qQgK+js0/OEY20maThBHMsW1q3cs0noQARZl1n2aGwXlbThnJWmjYQ1Oswgrsn5cnKr1Mll3RjfoluLo99vcQUs8JVg03rqCsiZ35ujzqU2OgLtqEddg9UhZ02OArFfybOHw/CMcibCMzvyy1DQyMFR7UWnIQ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6423.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(366004)(136003)(346002)(396003)(39860400002)(451199021)(6486002)(6666004)(82960400001)(478600001)(83380400001)(8936002)(1076003)(26005)(6512007)(6506007)(66946007)(38100700002)(66556008)(54906003)(6916009)(4326008)(66476007)(186003)(2616005)(5660300002)(8676002)(2906002)(316002)(41300700001)(86362001)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?7+nFpzqHDd+A86AkERGeNSwQpoJH?= =?utf-8?q?RAAFWRwgVhuzPGSyDaP9HfXLNmLTBvrmZPJ1hSvyWdJpVYKSwT4tykxHD1jVlFeRo?= =?utf-8?q?oc9HCPzVgyb9zP1+k/ewx+z7DSKVZRyk+RzrIb+EebAoArWPWLGaHJo+eKsOi0tvz?= =?utf-8?q?USsKaKLvujss/h4nJcalKvyYpHd5bPLmmtIlrV9+OFJxB13zWmJ5TKm7zvL9DanGm?= =?utf-8?q?6Or/cnl9CU5gkFI/FI/bB0ew0YFh2uAjvYRG7F9vK6oB2qvUhEAK0mIuT5WsfVn5h?= =?utf-8?q?n18ndU0H2Eb6rFD4tmswRBKs+55IACdkPRnIl15wgoefSIvJWkDA+LS2Mh3elYor9?= =?utf-8?q?7ZQi2c5CaLGNexio2fd/6GBV2efrNhE7gDH8CDgQV4/5FMmHQ888492WumOgsvduc?= =?utf-8?q?1LhNBLv/fm2RKtLQQLxbAyoV+fJG8Kf9IutDx+AS3F5QQEnuLof//kE1YR8iFXjjI?= =?utf-8?q?NZAgXflSvwuS7MYl0rU526OTEPK8O9G6EB0EBqgIsgaoLFBjML6Y0Gqu8BVgi8Egk?= =?utf-8?q?mkiGHSwEuuY3oC6jSO1xqX56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+MK10o5absS66aGenoGePxdkP?= =?utf-8?q?IthmS15SfyGnekueOUyL/8KppNVmPWCRjddCcCMtl0CzXzy8/yBprDLKujxiLdbju?= =?utf-8?q?itl5WsvztEZykAL2FSupAI9txSlqIpha+A=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: gNUl+olermFwWatXLxRTLCtbQC9SFNi043oOCQKtnuw5QtlLYq7WTNleBPMKRRoUXJzdi1ZuHaH0bd8/oS4FK2BuuAOwDJkDlXDohIsOu4wZGCK+sE8LUDCf8sTezQcSqwYF8yFBpdHO0vQZ7n7xDqI0u/3upmk9EDsb5TgSETctuOkGjILRLN7SteYoxX0KkMpZydUMNJF1GhzAfzpCHsIrx3H4anHCKw8KVPZNyzkTdGpcjvAsxNuz4qGj2KPCoQAD75yYVJ0GFavfs2gGmq9ZLMoSEtHMyGPvLxE59QcGi3JlqgzXGNM/3uGKMgHYuS8lvX7FN6QqufjN/ru9GVTnpBKxz3OH4TzKe6Adz20t2PILWeYZEt9gEHXJSJXSldG2Kcij4Ad1ImIEg7IjjqP+makoN3ii9YY+nCjQYMxZUhBKP8ISz66k1XoYcOzJB6ZISd/5lMsOMuXXWttjflIhPOxrsFcGSTGxl3szx7CIhoO4OKoQXcHxibEaKwPWn67GPRNdvSAnBliejRxIl8HT/fFr8cTpF2cal1krgxiCMz8fusr8je5ZXwd6gMC8J+U0Tipqs/8WpzSWCw3yq3KUXxUOlPUQZWtJmIbkQPwmlvgQdq2+CQVFye7zMoinMuugq+l9zRBZmkwijpjmRr3mXyfVTnlkCNRWJVT5xIfkvC2eViwxeMdRU1CgzH9xwOLpIIhOC/wAq0phnzfzEfFTXioxt9t/iOgUq5Chjyd5kEExvYYdtPcwgoObDN5WbzkV/80886tE+27Yb5gng0i0qoQgOvZcAPssZK3pmAKu2rySttK2kWQ+Rhvkwrvv X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2b71db7-93f5-46de-11ec-08db8d10014d X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6423.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 13:06:48.6637 (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: xamPO9QI13iSAP66uF7DBsx8p2If9I1fdT1qK/gTq60bJF9d89n5J5P/CclpymQBpYDtl9gJez0AOxzbLGZTrg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR03MB6516 Introduce support for handling MSR features in libxl_cpuid_parse_config(). The MSR policies are added to the libxl_cpuid_policy like the CPUID one, which gets passed to xc_cpuid_apply_policy(). This allows existing users of libxl to provide MSR related features as key=value pairs to libxl_cpuid_parse_config() without requiring the usage of a different API. Signed-off-by: Roger Pau Monné Acked-by: Anthony PERARD --- Changes since v2: - Add some braces. --- tools/libs/light/libxl_cpuid.c | 64 +++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/tools/libs/light/libxl_cpuid.c b/tools/libs/light/libxl_cpuid.c index 0daa564abb81..46dd2ce5f9e3 100644 --- a/tools/libs/light/libxl_cpuid.c +++ b/tools/libs/light/libxl_cpuid.c @@ -157,6 +157,60 @@ static int cpuid_add(libxl_cpuid_policy_list *policy, return 0; } +static struct xc_msr *msr_find_match(libxl_cpuid_policy_list *pl, uint32_t index) +{ + unsigned int i = 0; + libxl_cpuid_policy_list policy = *pl; + + if (policy == NULL) + policy = *pl = calloc(1, sizeof(*policy)); + + if (policy->msr != NULL) { + for (i = 0; policy->msr[i].index != XC_MSR_INPUT_UNUSED; i++) { + if (policy->msr[i].index == index) { + return &policy->msr[i]; + } + } + } + + policy->msr = realloc(policy->msr, sizeof(struct xc_msr) * (i + 2)); + policy->msr[i].index = index; + memset(policy->msr[i].policy, 'x', ARRAY_SIZE(policy->msr[0].policy) - 1); + policy->msr[i].policy[ARRAY_SIZE(policy->msr[0].policy) - 1] = '\0'; + policy->msr[i + 1].index = XC_MSR_INPUT_UNUSED; + + return &policy->msr[i]; +} + +static int msr_add(libxl_cpuid_policy_list *policy, uint32_t index, unsigned int bit, + const char *val) +{ + struct xc_msr *entry = msr_find_match(policy, index); + + /* Only allow options taking a character for MSRs, no values allowed. */ + if (strlen(val) != 1) + return 3; + + switch (val[0]) { + case '0': + case '1': + case 'x': + case 'k': + entry->policy[63 - bit] = val[0]; + break; + + case 's': + /* Translate s -> k as xc_msr doesn't support the deprecated 's'. */ + entry->policy[63 - bit] = 'k'; + break; + + default: + return 3; + } + + return 0; +} + struct feature_name { const char *name; unsigned int bit; @@ -336,7 +390,15 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *policy, const char* str) } case FEAT_MSR: - return 2; + { + unsigned int bit = feat->bit % 32; + + if (feature_to_policy[feat->bit / 32].msr.reg == CPUID_REG_EDX) + bit += 32; + + return msr_add(policy, feature_to_policy[feat->bit / 32].msr.index, + bit, val); + } } return 2;