From patchwork Wed Sep 11 20:05:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11141849 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6403717E6 for ; Wed, 11 Sep 2019 20:07:28 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3EE8420838 for ; Wed, 11 Sep 2019 20:07:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="ZonA4OKy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EE8420838 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i88rj-00030W-Ri; Wed, 11 Sep 2019 20:05:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i88ri-00030J-KR for xen-devel@lists.xenproject.org; Wed, 11 Sep 2019 20:05:22 +0000 X-Inumbo-ID: 7be61c7e-d4cf-11e9-978d-bc764e2007e4 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7be61c7e-d4cf-11e9-978d-bc764e2007e4; Wed, 11 Sep 2019 20:05:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1568232321; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5mwy1x2NvpEAJcMZSDwwXuBx23b+MiSxgOml7mKLXH8=; b=ZonA4OKyao3OBNU7aqKvlxaKsK+mlY6mwnmYOhG3kQIcKRGPqmfjmYUk dsFzw9irY9wtl311oFW3eowKIfoZQH2ufQVLZGoAzwP7dHxZZ5uTp6pcm 1xli73fbunqh9OiUlniXw2Gj/S5Ahr8tPi0+E5QbDl3mqQwG0QtTmGYjZ c=; Authentication-Results: esa4.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 (esa4.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=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.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=esa4.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 (esa4.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=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 9aRAf2ARsQVOzObqupFfxU3QpYt4Vs/I9oSKXX3xWLakzEzIq1AfhtKQmVi2gdYLMT/E5eos2L 6ebiRzc5rMuWKHDM3k09OXXPDqf0G8wouNIieQ/BF0g8mjHTivNEw1JN1LkUSSB6MySgF+f/yi 9qAudeJ2jE25M/musySF6AZ8rCeoEJkPGHf+56QOn0PlUgUFR9RZ5qiBsLcv8Eh13jQRO5OMBG F6nVfM1/f7cu0/AGYfhvAeOEkq90BAEYUeL7HiJika2RaqgoVBzq1NuYvICS/XrdQNWfXJiklp Upk= X-SBRS: 2.7 X-MesageID: 5742443 X-Ironport-Server: esa4.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="5742443" From: Andrew Cooper To: Xen-devel Date: Wed, 11 Sep 2019 21:05:00 +0100 Message-ID: <20190911200504.5693-5-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 4/8] tools/libxc: Pre-cleanup for xc_cpuid_{set, apply_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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This patch is broken out just to simplify the following two. For xc_cpuid_set(), document how the 'k' works because it is quite subtle. Replace a memset() with weird calculation for a loop of 4 explicit NULL assigments. This mirrors the free()'s in the fail path. For xc_cpuid_apply_policy(), const-ify the featureset pointer. It isn't written to, and was never intended to be mutable. Drop three pieces of trailing whitespace. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Ian Jackson --- tools/libxc/include/xenctrl.h | 2 +- tools/libxc/xc_cpuid_x86.c | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index e47778535d..2419a47f22 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1800,7 +1800,7 @@ int xc_cpuid_set(xc_interface *xch, char **config_transformed); int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, - uint32_t *featureset, + const uint32_t *featureset, unsigned int nr_features); int xc_mca_op(xc_interface *xch, struct xen_mc *mc); int xc_mca_op_inject_v2(xc_interface *xch, unsigned int flags, diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index 33b9e9fc85..a2d29a0fae 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -1,5 +1,5 @@ /****************************************************************************** - * xc_cpuid_x86.c + * xc_cpuid_x86.c * * Compute cpuid of a domain. * @@ -332,7 +332,7 @@ static void cpuid(const unsigned int *input, unsigned int *regs) static int get_cpuid_domain_info(xc_interface *xch, uint32_t domid, struct cpuid_domain_info *info, - uint32_t *featureset, + const uint32_t *featureset, unsigned int nr_features) { struct xen_domctl domctl = {}; @@ -807,8 +807,7 @@ static void sanitise_featureset(struct cpuid_domain_info *info) } int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, - uint32_t *featureset, - unsigned int nr_features) + const uint32_t *featureset, unsigned int nr_features) { struct cpuid_domain_info info = {}; unsigned int input[2] = { 0, 0 }, regs[4]; @@ -898,7 +897,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, * 'k' -> pass through host value * 's' -> pass through the first time and then keep the same value * across save/restore and migration. - * + * * For 's' and 'x' the configuration is overwritten with the value applied. */ int xc_cpuid_set( @@ -909,7 +908,8 @@ int xc_cpuid_set( unsigned int i, j, regs[4], polregs[4]; struct cpuid_domain_info info = {}; - memset(config_transformed, 0, 4 * sizeof(*config_transformed)); + for ( i = 0; i < 4; ++i ) + config_transformed[i] = NULL; rc = get_cpuid_domain_info(xch, domid, &info, NULL, 0); if ( rc ) @@ -927,7 +927,7 @@ int xc_cpuid_set( regs[i] = polregs[i]; continue; } - + config_transformed[i] = calloc(33, 1); /* 32 bits, NUL terminator. */ if ( config_transformed[i] == NULL ) { @@ -935,6 +935,13 @@ int xc_cpuid_set( goto fail; } + /* + * Notes for following this algorithm: + * + * While it will accept any leaf data, it only makes sense to use on + * feature leaves. regs[] initially contains the host values. This, + * with the fall-through chain is how the 'k' option works. + */ for ( j = 0; j < 32; j++ ) { unsigned char val = !!((regs[i] & (1U << (31 - j))));