From nobody Wed May 8 10:34:42 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; 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; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1591959363; cv=none; d=zohomail.com; s=zohoarc; b=jusnfctMvL4VqsAlJtscItUUZPSxVEhCpJkwpq9VE82/qJQk8rrFvp9Z83sHTvPCTCERuqa6KOd7tipkpz7XI71Y1/cgyHNtLQqYWOl98iqbW4dhS251dEZXVQGCzKf3T/fpr7Ka6LeKdj+H1rSES9Z+AM4A+o3Wtck8/D5lN8M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591959363; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=JLA9rEVPsFujzA4T5tbgp91C7p+JlxOztReJgh0y4Yk=; b=BB3mUyEJLi8/kdUbQOyWBrEQKhK/7TU6lGlsmeB+S5bvqh5680EjVek9CrZCFyxZ3K2GnSihAW6gPAqtry65h0SLPqrwgr3iHQYmzNv14Sbn15bNJr9s9lCons4xZozuj0DA2meM7HdUKByElPYMW0RoISdbFoZau87o3WU24pU= ARC-Authentication-Results: i=1; mx.zohomail.com; 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; dmarc=fail header.from= (p=none 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 1591959363879846.9391159985994; Fri, 12 Jun 2020 03:56:03 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjhLh-0004RF-Ms; Fri, 12 Jun 2020 10:55:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jjhLg-0004R8-Tc for xen-devel@lists.xenproject.org; Fri, 12 Jun 2020 10:55:48 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 44e14b14-ac9b-11ea-8496-bc764e2007e4; Fri, 12 Jun 2020 10:55:46 +0000 (UTC) X-Inumbo-ID: 44e14b14-ac9b-11ea-8496-bc764e2007e4 Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: oyqfG7pWJjfrdc3HHfqcE7uu2ZRzS4OEvBC5OiKvK+DKMxFY8l9GwV3BnR4jtkWkwQAbnGKrdD Vxz+ZLh1eiMCaFV/6m/DjR2MCX9s7aVEVHPOCz9BQOP2+uzO5t161H2eSoUZ7JrDzbSQHWoVH8 FQ/Re/9wsbw40qWLCKITEw0sGC4TSD0ZqfDon0NBS5gA0P9UzRK/mWc10ZhIrMlnK8V2MLHiUU z140UHgUbTAAZOoG7lkI74MLsn755D14X/leGplUymLH9IEhHE5qsi7QyXi88mhCBv+6wWzu7/ aN8= X-SBRS: 2.7 X-MesageID: 20186911 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.73,503,1583211600"; d="scan'208";a="20186911" From: Andrew Cooper To: Xen-devel Subject: [PATCH for-4.14] tools/libxc: Drop config_transformed parameter from xc_cpuid_set() Date: Fri, 12 Jun 2020 11:55:19 +0100 Message-ID: <20200612105519.18728-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Paul Durrant , Wei Liu , Ian Jackson Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" libxl is now the sole caller of xc_cpuid_set(). The config_transformed out= put is ignored, and this patch trivially highlights the resulting memory leak. "transformed" config is now properly forwarded on migrate as part of the general VM state, so delete the transformation logic completely, rather than trying to adjust just libxl to avoid leaking memory. Signed-off-by: Andrew Cooper Reviewed-by: Ian Jackson Reviewed-by: Paul Durrant --- CC: Ian Jackson CC: Wei Liu CC: Paul Durrant For 4.14 for hopefully obvious reasons. Ian: for backport to 4.13 and earlier, there are a number of options. The reasoning we used to delete the other callers of xc_cpuid_set() is still valid, but probably not backport material. OTOH, moding libxl_cpuid_set() (as it was back then) to loop over cpuid_res= [] and free them all should work. --- tools/libxc/include/xenctrl.h | 3 +-- tools/libxc/xc_cpuid_x86.c | 25 +------------------------ tools/libxl/libxl_cpuid.c | 3 +-- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index f9e17ae424..113ddd935d 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1795,8 +1795,7 @@ int xc_domain_debug_control(xc_interface *xch, int xc_cpuid_set(xc_interface *xch, uint32_t domid, const unsigned int *input, - const char **config, - char **config_transformed); + const char **config); =20 /* * Make adjustments to the CPUID settings for a domain. diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c index 89d2ecdad2..b42edd6457 100644 --- a/tools/libxc/xc_cpuid_x86.c +++ b/tools/libxc/xc_cpuid_x86.c @@ -279,7 +279,7 @@ int xc_set_domain_cpu_policy(xc_interface *xch, uint32_= t domid, */ int xc_cpuid_set( xc_interface *xch, uint32_t domid, const unsigned int *input, - const char **config, char **config_transformed) + const char **config) { int rc; unsigned int i, j, regs[4] =3D {}, polregs[4] =3D {}; @@ -288,9 +288,6 @@ int xc_cpuid_set( 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; - if ( xc_domain_getinfo(xch, domid, 1, &di) !=3D 1 || di.domid !=3D domid ) { @@ -365,13 +362,6 @@ int xc_cpuid_set( continue; } =20 - config_transformed[i] =3D calloc(33, 1); /* 32 bits, NUL terminato= r. */ - if ( config_transformed[i] =3D=3D NULL ) - { - rc =3D -ENOMEM; - goto fail; - } - /* * Notes for following this algorithm: * @@ -399,11 +389,6 @@ int xc_cpuid_set( set_feature(31 - j, regs[i]); else clear_feature(31 - j, regs[i]); - - config_transformed[i][j] =3D config[i][j]; - /* All non 0/1 values get overwritten. */ - if ( (config[i][j] & ~1) !=3D '0' ) - config_transformed[i][j] =3D '0' + val; } } =20 @@ -421,16 +406,8 @@ int xc_cpuid_set( } =20 /* Success! */ - goto out; =20 fail: - for ( i =3D 0; i < 4; i++ ) - { - free(config_transformed[i]); - config_transformed[i] =3D NULL; - } - - out: free(leaves); =20 return rc; diff --git a/tools/libxl/libxl_cpuid.c b/tools/libxl/libxl_cpuid.c index 4e4852ddeb..796ec4f2d9 100644 --- a/tools/libxl/libxl_cpuid.c +++ b/tools/libxl/libxl_cpuid.c @@ -421,7 +421,6 @@ void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, { libxl_cpuid_policy_list cpuid =3D info->cpuid; int i; - char *cpuid_res[4]; bool pae =3D true; =20 /* @@ -444,7 +443,7 @@ void libxl__cpuid_legacy(libxl_ctx *ctx, uint32_t domid, =20 for (i =3D 0; cpuid[i].input[0] !=3D XEN_CPUID_INPUT_UNUSED; i++) xc_cpuid_set(ctx->xch, domid, cpuid[i].input, - (const char**)(cpuid[i].policy), cpuid_res); + (const char**)cpuid[i].policy); } =20 static const char *input_names[2] =3D { "leaf", "subleaf" }; --=20 2.11.0