From nobody Sat Nov 30 03:50:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=2; a=rsa-sha256; t=1618322640; cv=pass; d=zohomail.com; s=zohoarc; b=UeEMq3R2uXpaTBfXkLsH9gBdPXdmJti2Pojzb/DvNjiC4++1KWuA+g4AjJ73LGESV+CEqzekmyHOqo6uYY7HCYZTYPd6DCjUG8yq6zdRfD5w8w+J2wgQEMgIa1GCtZbMbbaVNubRS5PgJmOv3jUukpoWrYbGkeYlS3okkovvQDU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618322640; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dhDbUZkOllUWicuxg47GICno5ICsaetEMRtEl5iO2+0=; b=Ppn4hrDkp0qkO5wo9+5vUJaj95Qy7y1sjcfAa4ObSbJ3jgToSGW6Mcy4+wgQpPF5mdqk/SIFHN2SzcfFBQ8PAaTwovotDi1nyX9ad5I358QqwAtSJyxoqvs1cpoeAHEUsDsWY13NpNWHYAj0neR/wjTEGtmo7Thk4EkZbyxgPO0= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1dmarc=pass fromdomain=citrix.com); dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161832264002828.329490455708992; Tue, 13 Apr 2021 07:04:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.109829.209709 (Exim 4.92) (envelope-from ) id 1lWJdm-0006Rv-60; Tue, 13 Apr 2021 14:03:42 +0000 Received: by outflank-mailman (output) from mailman id 109829.209709; Tue, 13 Apr 2021 14:03:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lWJdm-0006Rm-29; Tue, 13 Apr 2021 14:03:42 +0000 Received: by outflank-mailman (input) for mailman id 109829; Tue, 13 Apr 2021 14:03:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lWJdl-0006KX-5I for xen-devel@lists.xenproject.org; Tue, 13 Apr 2021 14:03:41 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 02147ad1-c3de-48ca-8106-a6755cb7693f; Tue, 13 Apr 2021 14:03:39 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 02147ad1-c3de-48ca-8106-a6755cb7693f DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1618322619; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=y5+wq5v92xJaRWVBJA3GfnjlX1XmtbKxgDkEMUjd/7g=; b=ZBzbBoLw7qUwCwwxaYsH/pxKvPxjI6LrwoMrf7O3IS0cqh2qRI9dp7Cy 6vQ8R5XA9qYvmDz6lmWGbyu97nDP3/G0z43+uy+pk9DgaHqhOMs8M1jkM 0Cfrdu1v+HkZIfPP5waf1tKMXkoQAPoC+L1mLqqz2VuoIGZ3Y+H0lg9wt 0=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com IronPort-SDR: CxjGfYuM1jq6+8dncgah+SBVUc8hssM40RcThgFGL8K0u1z9MCHjKpvKpa8gS8XtKdklvjEkwm /F9PQY4IDbmaglIRpMR3eg7Uw0ByVs1iS92vLl+o3tX8rbXfLaoSN7PZPd2pB63i5LSORav+bu KPuMMGPMeNTtk4uH4TIRCOXQDWimWqg+8SwSoHvYWpX+fhK7k7jI3lKgFkB7snrASnWG2piv01 ON+wAId+VKAr28GKI32dgw2D6oo/zzZnNuWRv0e6VgI0n5Xbzqkqut9xnl/TJrhlNSAFZIZFbB Z8w= X-SBRS: 5.2 X-MesageID: 41322412 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:elh6cqj7ZxQ6f4HiewMU9HpWmHBQX19w3DAbvn1ZSRFFG/Gwv/ uF2NwGyB75jysQUnk8mdaGfJKNW2/Y6IQd2+YsFJ+Ydk3DtHGzJI9vqbHjzTrpBjHk+odmuZ tIW5NVTOf9BV0St6vHySGlDtctx8SG+qi0heHYi0xgVx1udrsI1WZEIyywe3cGIDVuL5w/CZ aa+457vDKmY3sadYCWAXMCUujFqbTw5e7bSDQBAAMq7xTLsCOw5NfBYmWl9zo9cxcK+7ct9m DZjxf0j5/Mj9iXwgLRvlWjiah+t8DmzrJ4da6xo+gTbg7hkwO5ILlmMofyxwwdhMGKxBIUnM LXoxEmVv4Dm0/5Wm2uuxPi103B/V8Vmgbf4GSVi3fivsD1LQhSY6Eq5fM7A2nkwnEts91m3K VA03jxjessMTr6kDng/N+Nbhl2lyOP0AsfuNQOhH9SW5Z2Us43kaUj+ipuYfI9NRO/woUm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MbIMrg xi69XNu+OMbSL31ETxujR8S5g+vlqPcIeXAAiWH/RP/MH/EVOQgrGy6Mr2tQzJc1KAGg0lrL wAU1cRYMRFgiQji4Ny8hHacN2JnmsV131E4T9mkVbx3JOB+2mzJzAeDTHk X-IronPort-AV: E=Sophos;i="5.82,219,1613451600"; d="scan'208";a="41322412" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D2JvE0+ooWjkoP4e95ADW87M15OBVrGy6sw408MBCeoy3tNmm7tKOjfqw3pS356UDXjpB9PMPmTytxZ5TonYzgO4A/TlXdqWQlGXue9hz6nLFrngPFg55Vr7D+Qk4o/e1CDThaoUhF18iGyD3Qt82tFlnM+5oUPT5aC5d73u/ePscoZKEXFFeBP/bFfQ1PwYp6RQiLkq4jmZ7fVHjR+tRRh3h5cFw3hwjB8LVAV6yhM53L1oW/uoFHU5dQ/eQMXDMI8pAteGyzkSz8iaedZ2g71cJeFabVAI42c8kf9FPPkvTDR3pLgwUYx8bWPsMwvbKnQuzFrl8x719TFGk61N3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dhDbUZkOllUWicuxg47GICno5ICsaetEMRtEl5iO2+0=; b=BKgnFeQa8/RVaVfkH6gEuL7rPWsNxtvv9MI2UlNgwQZRF6ofbv7SVAYNdc20vHlAjT71OhhGb4fLcTlRk3OjyJRSN65LNGkYNZbKNarhq9YsrroE/X51K+GVsIHT+YklYFrwU1h0HTcG6Y9xWLtiNvaTh7AjCxYZ+0h2kOPyMIeEYzMrZNT4vAZGGX28GEuxESlcFFijlxneiKQLIq48OkAOshxzhunmc0tBc7LdC91DDJNMZi7zbK2b3pluxDOLQhXN3h/VZboYHOuFF5DFow56jo+bltexGDLPzJeAT5Ez1AMBa+KxvUxQiO6yli5aV+aDbcIjY060DqY8BNrAAw== 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=dhDbUZkOllUWicuxg47GICno5ICsaetEMRtEl5iO2+0=; b=IFTJdP5kdWdvX1DO/Yw2nJIuP9le24n1HeV/+CaxNUp8Wxrea9N6DvUJsYTprC4xJC/DBXb9LC0kGsCbz3pIJxlG6TQICybF9/joiEKK8GZf+9hGYSQ+VRn0vh+FfKm6FM5sWW4bWLyMLyCi5J8VWmhk5O/MaAoAsX0+LgT1rEo= From: Roger Pau Monne To: CC: Andrew Cooper , Roger Pau Monne , Ian Jackson , Wei Liu Subject: [PATCH v2 18/21] libs/guest: rework xc_cpuid_xend_policy Date: Tue, 13 Apr 2021 16:01:36 +0200 Message-ID: <20210413140140.73690-19-roger.pau@citrix.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210413140140.73690-1-roger.pau@citrix.com> References: <20210413140140.73690-1-roger.pau@citrix.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MR2P264CA0163.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:1::26) To DS7PR03MB5608.namprd03.prod.outlook.com (2603:10b6:5:2c9::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ebbfea3f-dcd6-4205-08a4-08d8fe84eef3 X-MS-TrafficTypeDiagnostic: DM5PR03MB2969: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:65; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BNb3tyYF9AEA2J87W+GYK1OEjjC7FUwqNAjYvUC66HxgD76ltkDWvU53LETwA0G0JQTpfHykJaMZjsFR9OUawuSs9cC6bV5A5UliuRcZoYOAx68z/LMif2p1tIonFfU3goXmPLmLUEJy0q0SIPKFEAZafmVtIJ90/z6PJGx2v0MlJJxDFEvtekkYi2aoJSgrFE0kFBRSXsoD6Z1vm9DTOzPTgcj0A334sQKC1nGGfxpSlbkDV9/5FiN8VXlZUyCrz15OaXe0CAM2gls2XxqoYKTR8gEbTUVYiselUu0uXedYzsyq2r6jXutv3JQKUnrEwuMJgvkIoUMhR5nbGdmiLw3/2hs5Fux4DdfMkZdwFXa4cEp+NqxsntuDfNJ1s/L94nRvn6hIBAWyocwpSVhCMRHfE3yyPtCbhjA+0ctdgAs5vPcyZ98KZb0Yfts0Wt7LsOuZr9u6rXX7oV/ivvZvVMjUIFa8Rh/pGP3CVcazfXkqBeL343q3DdyVTP+0/FgIPdeh4+6e7Q5R8XBPCHgk1+Z+pRlXZIiIr4oYC2H3D3BeJHV1xyqKZs3e2c01qGZqtWMO6B6xawJPTlIP/GY2+YBFPRVN3gmP/fmqRgZ82dM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS7PR03MB5608.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(376002)(346002)(136003)(39850400004)(366004)(83380400001)(186003)(6496006)(316002)(2906002)(4326008)(36756003)(54906003)(6916009)(2616005)(16526019)(26005)(478600001)(6486002)(1076003)(8676002)(8936002)(5660300002)(66556008)(66946007)(86362001)(66476007)(38100700002)(956004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?c0Q3REtUajhLWUtoYWlJZ3NJNW5UejVZWUthTzE1U2kyeW9BdnhMU1pIeWRM?= =?utf-8?B?c2VMNG1qS3RjYWNvdlRxcXM3djhpZzh2TTM5U1N0akRRQzJvL0FS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look.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 14:03:37.2237 (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: vdQI8/0ShcO5vCUU8yRqMfMDVCB3C5aTDBNgAFguYRDA+o331dnaqHZgS6i1LUPfPHU8/nqZfhgN4a+ZBLXy5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2969 X-OriginatorOrg: citrix.com X-ZohoMail-DKIM: pass (identity @citrix.com) Rename xc_cpuid_xend_policy to xc_cpu_policy_apply_cpuid and make it public. Modify the function internally to use the new xc_cpu_policy_* set of functions. Also don't apply the passed policy to a domain directly, and instead modify the provided xc_cpu_policy_t. The caller will be responsible of applying the modified cpu policy to the domain. Note that further patches will end up removing this function, as the callers should have the necessary helpers to modify an xc_cpu_policy_t themselves. No functional change intended. Signed-off-by: Roger Pau Monn=C3=A9 --- tools/include/xenctrl.h | 4 + tools/libs/guest/xg_cpuid_x86.c | 182 ++++++++++++++------------------ 2 files changed, 84 insertions(+), 102 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index ec184bccd3f..ce0785f7654 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2635,6 +2635,10 @@ int xc_cpu_policy_make_compatible(xc_interface *xch,= xc_cpu_policy_t policy, int xc_cpu_policy_legacy_topology(xc_interface *xch, xc_cpu_policy_t polic= y, bool hvm); =20 +/* Apply an xc_xend_cpuid object to the policy. */ +int xc_cpu_policy_apply_cpuid(xc_interface *xch, xc_cpu_policy_t policy, + const struct xc_xend_cpuid *cpuid, bool hvm); + int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps); int xc_get_cpu_featureset(xc_interface *xch, uint32_t index, uint32_t *nr_features, uint32_t *featureset); diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x8= 6.c index 83cd71148f7..06e3e8131d7 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -288,124 +288,107 @@ static xen_cpuid_leaf_t *find_leaf( return bsearch(&key, leaves, nr_leaves, sizeof(*leaves), compare_leave= s); } =20 -static int xc_cpuid_xend_policy( - xc_interface *xch, uint32_t domid, const struct xc_xend_cpuid *xend) +int xc_cpu_policy_apply_cpuid(xc_interface *xch, xc_cpu_policy_t policy, + const struct xc_xend_cpuid *cpuid, bool hvm) { int rc; - xc_dominfo_t di; - unsigned int nr_leaves, nr_msrs; - uint32_t err_leaf =3D -1, err_subleaf =3D -1, err_msr =3D -1; - /* - * Three full policies. The host, default for the domain type, - * and domain current. - */ - xen_cpuid_leaf_t *host =3D NULL, *def =3D NULL, *cur =3D NULL; - unsigned int nr_host, nr_def, nr_cur; - - if ( xc_domain_getinfo(xch, domid, 1, &di) !=3D 1 || - di.domid !=3D domid ) - { - ERROR("Failed to obtain d%d info", domid); - rc =3D -ESRCH; - goto fail; - } - - rc =3D xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); - if ( rc ) - { - PERROR("Failed to obtain policy info size"); - rc =3D -errno; - goto fail; - } + xc_cpu_policy_t host =3D NULL, def =3D NULL; =20 - rc =3D -ENOMEM; - if ( (host =3D calloc(nr_leaves, sizeof(*host))) =3D=3D NULL || - (def =3D calloc(nr_leaves, sizeof(*def))) =3D=3D NULL || - (cur =3D calloc(nr_leaves, sizeof(*cur))) =3D=3D NULL ) - { - ERROR("Unable to allocate memory for %u CPUID leaves", nr_leaves); - goto fail; - } - - /* Get the domain's current policy. */ - nr_msrs =3D 0; - nr_cur =3D nr_leaves; - rc =3D get_domain_cpu_policy(xch, domid, &nr_cur, cur, &nr_msrs, NULL); - if ( rc ) + host =3D xc_cpu_policy_init(); + def =3D xc_cpu_policy_init(); + if ( !host || !def ) { - PERROR("Failed to obtain d%d current policy", domid); - rc =3D -errno; - goto fail; + PERROR("Failed to init policies"); + rc =3D -ENOMEM; + goto out; } =20 /* Get the domain type's default policy. */ - nr_msrs =3D 0; - nr_def =3D nr_leaves; - rc =3D get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_d= efault + rc =3D xc_cpu_policy_get_system(xch, hvm ? XEN_SYSCTL_cpu_policy_hvm_d= efault : XEN_SYSCTL_cpu_policy_pv_defa= ult, - &nr_def, def, &nr_msrs, NULL); + def); if ( rc ) { - PERROR("Failed to obtain %s def policy", di.hvm ? "hvm" : "pv"); - rc =3D -errno; - goto fail; + PERROR("Failed to obtain %s def policy", hvm ? "hvm" : "pv"); + goto out; } =20 /* Get the host policy. */ - nr_msrs =3D 0; - nr_host =3D nr_leaves; - rc =3D get_system_cpu_policy(xch, XEN_SYSCTL_cpu_policy_host, - &nr_host, host, &nr_msrs, NULL); + rc =3D xc_cpu_policy_get_system(xch, XEN_SYSCTL_cpu_policy_host, host); if ( rc ) { PERROR("Failed to obtain host policy"); - rc =3D -errno; - goto fail; + goto out; } =20 rc =3D -EINVAL; - for ( ; xend->leaf !=3D XEN_CPUID_INPUT_UNUSED; ++xend ) + for ( ; cpuid->leaf !=3D XEN_CPUID_INPUT_UNUSED; ++cpuid ) { - xen_cpuid_leaf_t *cur_leaf =3D find_leaf(cur, nr_cur, - xend->leaf, xend->subleaf); - const xen_cpuid_leaf_t *def_leaf =3D find_leaf(def, nr_def, - xend->leaf, xend->sub= leaf); - const xen_cpuid_leaf_t *host_leaf =3D find_leaf(host, nr_host, xen= d->leaf, - xend->subleaf); - - if ( cur_leaf =3D=3D NULL || def_leaf =3D=3D NULL || host_leaf =3D= =3D NULL ) + xen_cpuid_leaf_t cur_leaf; + xen_cpuid_leaf_t def_leaf; + xen_cpuid_leaf_t host_leaf; + + rc =3D xc_cpu_policy_get_cpuid(xch, policy, cpuid->leaf, cpuid->su= bleaf, + &cur_leaf); + if ( rc ) { - ERROR("Missing leaf %#x, subleaf %#x", xend->leaf, xend->suble= af); - goto fail; + ERROR("Failed to get current policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + goto out; + } + rc =3D xc_cpu_policy_get_cpuid(xch, def, cpuid->leaf, cpuid->suble= af, + &def_leaf); + if ( rc ) + { + ERROR("Failed to get def policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + goto out; + } + rc =3D xc_cpu_policy_get_cpuid(xch, host, cpuid->leaf, cpuid->subl= eaf, + &host_leaf); + if ( rc ) + { + ERROR("Failed to get host policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + goto out; } =20 - for ( unsigned int i =3D 0; i < ARRAY_SIZE(xend->policy); i++ ) + for ( unsigned int i =3D 0; i < ARRAY_SIZE(cpuid->policy); i++ ) { - uint32_t *cur_reg =3D &cur_leaf->a + i; - const uint32_t *def_reg =3D &def_leaf->a + i; - const uint32_t *host_reg =3D &host_leaf->a + i; + uint32_t *cur_reg =3D &cur_leaf.a + i; + const uint32_t *def_reg =3D &def_leaf.a + i; + const uint32_t *host_reg =3D &host_leaf.a + i; =20 - if ( xend->policy[i] =3D=3D NULL ) + if ( cpuid->policy[i] =3D=3D NULL ) continue; =20 for ( unsigned int j =3D 0; j < 32; j++ ) { bool val; =20 - if ( xend->policy[i][j] =3D=3D '1' ) + switch ( cpuid->policy[i][j] ) + { + case '1': val =3D true; - else if ( xend->policy[i][j] =3D=3D '0' ) + break; + + case '0': val =3D false; - else if ( xend->policy[i][j] =3D=3D 'x' ) + break; + + case 'x': val =3D test_bit(31 - j, def_reg); - else if ( xend->policy[i][j] =3D=3D 'k' || - xend->policy[i][j] =3D=3D 's' ) + break; + + case 'k': + case 's': val =3D test_bit(31 - j, host_reg); - else - { + break; + + default: ERROR("Bad character '%c' in policy[%d] string '%s'", - xend->policy[i][j], i, xend->policy[i]); - goto fail; + cpuid->policy[i][j], i, cpuid->policy[i]); + goto out; } =20 clear_bit(31 - j, cur_reg); @@ -413,25 +396,19 @@ static int xc_cpuid_xend_policy( set_bit(31 - j, cur_reg); } } - } =20 - /* Feed the transformed currrent policy back up to Xen. */ - rc =3D xc_set_domain_cpu_policy(xch, domid, nr_cur, cur, 0, NULL, - &err_leaf, &err_subleaf, &err_msr); - if ( rc ) - { - PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr= %#x)", - domid, err_leaf, err_subleaf, err_msr); - rc =3D -errno; - goto fail; + rc =3D xc_cpu_policy_update_cpuid(xch, policy, &cur_leaf, 1); + if ( rc ) + { + PERROR("Failed to set policy leaf %#x subleaf %#x", + cpuid->leaf, cpuid->subleaf); + goto out; + } } =20 - /* Success! */ - - fail: - free(cur); - free(def); - free(host); + out: + xc_cpu_policy_destroy(def); + xc_cpu_policy_destroy(host); =20 return rc; } @@ -439,7 +416,7 @@ static int xc_cpuid_xend_policy( int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore, const uint32_t *featureset, unsigned int nr_feat= ures, bool pae, bool itsc, bool nested_virt, - const struct xc_xend_cpuid *xend) + const struct xc_xend_cpuid *cpuid) { int rc; xc_dominfo_t di; @@ -563,6 +540,10 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t = domid, bool restore, goto out; *p =3D policy.cpuid; =20 + rc =3D xc_cpu_policy_apply_cpuid(xch, &policy, cpuid, di.hvm); + if ( rc ) + goto out; + rc =3D x86_cpuid_copy_to_buffer(p, leaves, &nr_leaves); if ( rc ) { @@ -580,9 +561,6 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t d= omid, bool restore, goto out; } =20 - if ( xend && (rc =3D xc_cpuid_xend_policy(xch, domid, xend)) ) - goto out; - rc =3D 0; =20 out: --=20 2.30.1