From nobody Mon Feb 9 04:14:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1568232406; cv=none; d=zoho.com; s=zohoarc; b=lKplh8yMiDGBBlZIZuXO3Udz3j1j+hqEYaC2t6R4LTFM/9EeA1sJqOOe61VnRCs2qUL6NYUDbnTsmBKPK7jFBAgyjrHEfqd7uY2rtz+IOS+29Z32nSGlkGw2I48dxbYoBnWA2Q6p3f8sHsGv48Fjq5OcpvXnruru3Xq3r+RoMw4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568232406; 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:ARC-Authentication-Results; bh=3kOsVS40V1M19EDgyP0KY2yEFq7SkdJUKq8GCDMAwHg=; b=hMRsKqFEuq8vnqsFWS9GfQJy6nv5hrxwv7GAb8awPBOtBxhZCzjG0q1tuKjMNIa5uqn9unnBO4fPnLRV8RxUdCyNnUroizOSRbHqSJumv+8Yrv50kyMLkvoe1kMQa/MLQpc9T2jPIoIc6Mc+go/85uQqZ26dr7ZquhQWZB8dtuw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1568232406009162.9809909178565; Wed, 11 Sep 2019 13:06:46 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i88rf-000301-GT; Wed, 11 Sep 2019 20:05:19 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i88re-0002zv-4q for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 20:05:18 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 76dcce3b-d4cf-11e9-83dd-12813bfff9fa; Wed, 11 Sep 2019 20:05:13 +0000 (UTC) X-Inumbo-ID: 76dcce3b-d4cf-11e9-83dd-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568232314; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Vf1AG29drMqw2LT/Z66r4aJJqf5+EsSaB0/oRaGhy1U=; b=Fb6x6l7GhTtLYwIetbfFRQlzkbgUyg6bqmtagtEDAUifZ/XM6EbUURgv UiLUDy5iGMPw1rvtvLxPukM15ApHR3IXdeIJyelWrGwdFF6mtvKF7k9WP Ka5Q7Q89WRiCS2PIfZUebHb41Yn1omUlRID0Su2LvPpJvynrG2fhYSrmD M=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: +nKyXPXKqy3lx81FteDEfZSU9DIo1LYIMo+nWZao9CWra4UpLmTBCdgMMtCiWqVUE0P0VfMQ9P Fwr7JQz2ywdM8lDwSJIs/4YM6nh8Cex8eJ8wv+1wZT1xEAMoEQeBM6TKQ9hoRadptEJYGeZtHU exFt891zTg7MDwErmVyJNoiJHeVhCtTOyBM8qZLOsObF+GLaWrN93Y9146dqCQX9sZEwCVU5Ti pzZ/83z1EkFCk1jCJSa1PCGIHrLObPrv9XqCjKtwfGl+a9/baIvSOOFfI+UhMhohuqdy7j19OU 1q4= X-SBRS: 2.7 X-MesageID: 5451849 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,494,1559534400"; d="scan'208";a="5451849" From: Andrew Cooper To: Xen-devel Date: Wed, 11 Sep 2019 21:05:01 +0100 Message-ID: <20190911200504.5693-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190911200504.5693-1-andrew.cooper3@citrix.com> References: <20190911200504.5693-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 5/8] tools/libxc: Rework xc_cpuid_set() to use {get, set}_cpu_policy() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Ian Jackson , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The purpose of this change is to stop using xc_cpuid_do_domctl(), and to st= op basing decisions on a local CPUID instruction. This is not an appropriate = way to construct policy information for other domains. Obtain the host and domain-max policies from Xen, and mix the results as before. Provide rather more error logging than before. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Ian Jackson --- tools/libxc/xc_cpuid_x86.c | 95 ++++++++++++++++++++++++++++++++++++++++--= ---- 1 file changed, 84 insertions(+), 11 deletions(-) diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index a2d29a0fae..d1a2b61214 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -905,20 +905,80 @@ int xc_cpuid_set( const char **config, char **config_transformed) { int rc; - unsigned int i, j, regs[4], polregs[4]; - struct cpuid_domain_info info =3D {}; + unsigned int i, j, regs[4] =3D {}, polregs[4] =3D {}; + xc_dominfo_t di; + xen_cpuid_leaf_t *leaves =3D NULL; + unsigned int nr_leaves, policy_leaves, nr_msrs; + uint32_t err_leaf =3D -1, err_subleaf =3D -1, err_msr =3D -1; =20 for ( i =3D 0; i < 4; ++i ) config_transformed[i] =3D NULL; =20 - rc =3D get_cpuid_domain_info(xch, domid, &info, NULL, 0); + 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_get_cpu_policy_size(xch, &nr_leaves, &nr_msrs); if ( rc ) - goto out; + { + PERROR("Failed to obtain policy info size"); + rc =3D -errno; + goto fail; + } =20 - cpuid(input, regs); + rc =3D -ENOMEM; + if ( (leaves =3D calloc(nr_leaves, sizeof(*leaves))) =3D=3D NULL ) + { + ERROR("Unable to allocate memory for %u CPUID leaves", nr_leaves); + goto fail; + } =20 - memcpy(polregs, regs, sizeof(regs)); - xc_cpuid_policy(&info, input, polregs); + /* Get the domain's max policy. */ + nr_msrs =3D 0; + policy_leaves =3D nr_leaves; + rc =3D xc_get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hv= m_max + : XEN_SYSCTL_cpu_policy_pv_m= ax, + &policy_leaves, leaves, &nr_msrs, NULL); + if ( rc ) + { + PERROR("Failed to obtain %s max policy", di.hvm ? "hvm" : "pv"); + rc =3D -errno; + goto fail; + } + for ( i =3D 0; i < policy_leaves; ++i ) + if ( leaves[i].leaf =3D=3D input[0] && leaves[i].subleaf =3D=3D in= put[1] ) + { + polregs[0] =3D leaves[i].a; + polregs[1] =3D leaves[i].b; + polregs[2] =3D leaves[i].c; + polregs[3] =3D leaves[i].d; + break; + } + + /* Get the host policy. */ + nr_msrs =3D 0; + policy_leaves =3D nr_leaves; + rc =3D xc_get_system_cpu_policy(xch, XEN_SYSCTL_cpu_policy_host, + &policy_leaves, leaves, &nr_msrs, NULL); + if ( rc ) + { + PERROR("Failed to obtain host policy"); + rc =3D -errno; + goto fail; + } + for ( i =3D 0; i < policy_leaves; ++i ) + if ( leaves[i].leaf =3D=3D input[0] && leaves[i].subleaf =3D=3D in= put[1] ) + { + regs[0] =3D leaves[i].a; + regs[1] =3D leaves[i].b; + regs[2] =3D leaves[i].c; + regs[3] =3D leaves[i].d; + break; + } =20 for ( i =3D 0; i < 4; i++ ) { @@ -969,9 +1029,21 @@ int xc_cpuid_set( } } =20 - rc =3D xc_cpuid_do_domctl(xch, domid, input, regs); - if ( rc =3D=3D 0 ) - goto out; + /* Feed the transformed leaf back up to Xen. */ + leaves[0] =3D (xen_cpuid_leaf_t){ input[0], input[1], + regs[0], regs[1], regs[2], regs[3] }; + rc =3D xc_set_domain_cpu_policy(xch, domid, 1, leaves, 0, NULL, + &err_leaf, &err_subleaf, &err_msr); + if ( rc ) + { + PERROR("Failed to set d%d's policy (err leaf %#x, subleaf %#x, msr= %#x)", + domid, err_leaf, err_subleaf, err_msr); + rc =3D -errno; + goto fail; + } + + /* Success! */ + goto out; =20 fail: for ( i =3D 0; i < 4; i++ ) @@ -981,6 +1053,7 @@ int xc_cpuid_set( } =20 out: - free_cpuid_domain_info(&info); + free(leaves); + return rc; } --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel