From nobody Mon Feb 9 11:05:57 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=1568403036; cv=none; d=zoho.com; s=zohoarc; b=RqwvMtXB6nUkNIdxNS+/Ta7lZcbpneJYrIkSlviqpEaQ1Rv9F9xJaswNJkMMZxSygiFbm2cIcWEYy2wfEyC98xysbnF4SRgVijoVD8rNq/CRJVBg5y8Yl3CMWTFDNoTp1tTnThoqiz6SHCH8+QbXzvoFrp4SVemXtnl3nbqVdSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568403036; 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=EQWIaXNI4xWqHWRvfMhM0Tl5+ZZNKn73U6uvrZ+17Yc=; b=bYSo0cDXZscsV0PkFhBp7l/craShYJW0oVu26I9PgrOmKLkfiSOkWV8/cSD0cWFequLc9sKuTphctoDG8ARHOnbMVxTvaJ+E/3FXebr2jhLtZ5VdE4XUXYY7Cs9yAQCZM7F6q0XrbRYu+pIMs1KDGfmCTp9IOqayuygpXF6WRSk= 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 1568403036066547.6302785970032; Fri, 13 Sep 2019 12:30:36 -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 1i8rEr-0006nL-VU; Fri, 13 Sep 2019 19:28:13 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8rEq-0006n8-Ck for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 19:28:12 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9ccc2f6c-d65c-11e9-a337-bc764e2007e4; Fri, 13 Sep 2019 19:28:07 +0000 (UTC) X-Inumbo-ID: 9ccc2f6c-d65c-11e9-a337-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568402888; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KxL0uF2fdDQlL0Z8KL8i80DFo81YGc/cGCmm6s1ebNU=; b=dOktXEOmTXmBv5tS/DWE+6o/VqerM7tWbGBXZlA+8Y6Qtey4PjACGIus C4MQRVRNw/a298xlNjdr7BgCbKGFr1Z4FtqTbk/U3nj7i088faS+4U/LI QqxfIbLdIaqql5zaNqrhQwG9Z/7Fra41GInh1pxzxqAOA4swRqK4jvc2p Y=; 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: kONV0tIMmPtfzNhFdtJRIP8t8gpPESNuhXx3RYJ+BcSileBkqC+fI9yURoJJpvHkalyjHnXcPT oE2ONdPXpV5Qyk/IIkObJQv3zqE3kBW4dJBdmz7tGMBYc9XLQI60yNlaVjNKHY/gYdl2xgF2a3 acdcQ8EcBl8mKZeLsigHDO13MYf5S57R8RQQVRdwlmLGSVqW8FfgSQO2bgB/cllu/HvC+ET+fh zuA9VbWxuHKKCltrw3XWZ8p545TDA7GaHkHSEEcOw1JM9AGkgsSi1h6wpYa7KYVIM0A/7WaoWk W1s= X-SBRS: 2.7 X-MesageID: 5553060 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,501,1559534400"; d="scan'208";a="5553060" From: Andrew Cooper To: Xen-devel Date: Fri, 13 Sep 2019 20:27:56 +0100 Message-ID: <20190913192759.10795-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190913192759.10795-1-andrew.cooper3@citrix.com> References: <20190913192759.10795-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 07/10] 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. No semantics changes to xc_cpuid_set(). There are conceptual problems with how the function works, which will be addressed in future toolstack work. 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 8785cae329..77f96a4ea6 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -902,20 +902,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++ ) { @@ -966,9 +1026,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++ ) @@ -978,6 +1050,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