From: "Jan Beulich" Subject: [PATCH] libxl: fix "xl mem-set" regression from 0c029c4da2 Date: Wed, 22 Apr 2015 13:02:16 +0100 Message-ID: <5537A9E80200007800074B19@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part5F6B30D8.2__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YktMC-0006ro-7U for xen-devel@lists.xenproject.org; Wed, 22 Apr 2015 12:02:20 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Ian Campbell , Ian Jackson , Wei Liu , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part5F6B30D8.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Said commit ("libxl_set_memory_target: retain the same maxmem offset on top of the current target") caused a regression for "xl mem-set" against Dom0: While prior to creation of the first domain this works, the first domain creation involving ballooning breaks. Due to "enforce" not being set in the domain creation case, and due to Dom0's initial ->max_pages (in the hypervisor) being UINT_MAX, the calculation of "memorykb" in the first "xl mem-set" adusting the target upwards subsequent to domain creation and termination may cause an overflow, resulting in Dom0's maximum getting to a very small value. This small maximum will the make the subsequent setting of the PoD target fail. Signed-off-by: Jan Beulich --- Note that this only fixes the immediate problem - there appear to be further issues lurking here: - libxl_set_memory_target()'s *_memkb variables all being 32-bit, - libxl_domain_setmaxmem()'s max_memkb parameter being 32-bit, - other similar code living elsewhere? Note also that this requires http://lists.xenproject.org/archives/html/xen-devel/2015-04/msg02485.html= =20 (or some other change avoiding truncation) to also be in place in order to address the observed problem. Note further that xc_domain_setmaxmem() is being used by upstream qemu and hence the libxc interface change here may represent a compatibility issue. Finally the setting of a PoD target for non-HVM domains seems bogus too (even if it's expected to just be a no-op in that case). --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1256,7 +1256,7 @@ int xc_getcpuinfo(xc_interface *xch, int =20 int xc_domain_setmaxmem(xc_interface *xch, uint32_t domid, - unsigned int max_memkb); + uint64_t max_memkb); =20 int xc_domain_set_memmap_limit(xc_interface *xch, uint32_t domid, --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -634,7 +634,7 @@ int xc_shadow_control(xc_interface *xch, =20 int xc_domain_setmaxmem(xc_interface *xch, uint32_t domid, - unsigned int max_memkb) + uint64_t max_memkb) { DECLARE_DOMCTL; domctl.cmd =3D XEN_DOMCTL_max_mem; --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -4726,7 +4726,8 @@ int libxl_set_memory_target(libxl_ctx *c { GC_INIT(ctx); int rc =3D 1, abort_transaction =3D 0; - uint32_t memorykb =3D 0, videoram =3D 0; + uint64_t memorykb; + uint32_t videoram =3D 0; uint32_t current_target_memkb =3D 0, new_target_memkb =3D 0; uint32_t current_max_memkb =3D 0; char *memmax, *endptr, *videoram_s =3D NULL, *target =3D NULL; @@ -4820,7 +4821,7 @@ retry_transaction: rc =3D xc_domain_setmaxmem(ctx->xch, domid, memorykb); if (rc !=3D 0) { LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "xc_domain_setmaxmem domid=3D%d memkb=3D%d failed " + "xc_domain_setmaxmem domid=3D%u memkb=3D%"PRIu64" = failed " "rc=3D%d\n", domid, memorykb, rc); abort_transaction =3D 1; goto out; --=__Part5F6B30D8.2__= Content-Type: text/plain; name="libxl-mem-set-regression.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="libxl-mem-set-regression.patch" libxl: fix "xl mem-set" regression from 0c029c4da2=0A=0ASaid commit = ("libxl_set_memory_target: retain the same maxmem offset on=0Atop of the = current target") caused a regression for "xl mem-set"=0Aagainst Dom0: = While prior to creation of the first domain this works,=0Athe first domain = creation involving ballooning breaks. Due to "enforce"=0Anot being set in = the domain creation case, and due to Dom0's initial=0A->max_pages (in the = hypervisor) being UINT_MAX, the calculation of=0A"memorykb" in the first = "xl mem-set" adusting the target upwards=0Asubsequent to domain creation = and termination may cause an overflow,=0Aresulting in Dom0's maximum = getting to a very small value. This small=0Amaximum will the make the = subsequent setting of the PoD target fail.=0A=0ASigned-off-by: Jan Beulich = =0A---=0ANote that this only fixes the immediate = problem - there appear to be=0Afurther issues lurking here:=0A- libxl_set_m= emory_target()'s *_memkb variables all being 32-bit,=0A- libxl_domain_setma= xmem()'s max_memkb parameter being 32-bit,=0A- other similar code living = elsewhere?=0ANote also that this requires=0Ahttp://lists.xenproject.org/arc= hives/html/xen-devel/2015-04/msg02485.html=0A(or some other change = avoiding truncation) to also be in place in order=0Ato address the = observed problem.=0ANote further that xc_domain_setmaxmem() is being used = by upstream qemu=0Aand hence the libxc interface change here may represent = a compatibility=0Aissue.=0AFinally the setting of a PoD target for non-HVM = domains seems bogus too=0A(even if it's expected to just be a no-op in = that case).=0A=0A--- a/tools/libxc/include/xenctrl.h=0A+++ b/tools/libxc/in= clude/xenctrl.h=0A@@ -1256,7 +1256,7 @@ int xc_getcpuinfo(xc_interface = *xch, int=0A =0A int xc_domain_setmaxmem(xc_interface *xch,=0A = uint32_t domid,=0A- unsigned int = max_memkb);=0A+ uint64_t max_memkb);=0A =0A int = xc_domain_set_memmap_limit(xc_interface *xch,=0A = uint32_t domid,=0A--- a/tools/libxc/xc_domain.c=0A+++ b/tools/libxc/xc= _domain.c=0A@@ -634,7 +634,7 @@ int xc_shadow_control(xc_interface = *xch,=0A =0A int xc_domain_setmaxmem(xc_interface *xch,=0A = uint32_t domid,=0A- unsigned int max_memkb)= =0A+ uint64_t max_memkb)=0A {=0A DECLARE_DOMCTL;= =0A domctl.cmd =3D XEN_DOMCTL_max_mem;=0A--- a/tools/libxl/libxl.c=0A++= + b/tools/libxl/libxl.c=0A@@ -4726,7 +4726,8 @@ int libxl_set_memory_target= (libxl_ctx *c=0A {=0A GC_INIT(ctx);=0A int rc =3D 1, abort_transact= ion =3D 0;=0A- uint32_t memorykb =3D 0, videoram =3D 0;=0A+ uint64_t = memorykb;=0A+ uint32_t videoram =3D 0;=0A uint32_t current_target_me= mkb =3D 0, new_target_memkb =3D 0;=0A uint32_t current_max_memkb =3D = 0;=0A char *memmax, *endptr, *videoram_s =3D NULL, *target =3D = NULL;=0A@@ -4820,7 +4821,7 @@ retry_transaction:=0A rc =3D = xc_domain_setmaxmem(ctx->xch, domid, memorykb);=0A if (rc !=3D 0) = {=0A LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,=0A- = "xc_domain_setmaxmem domid=3D%d memkb=3D%d failed "=0A+ = "xc_domain_setmaxmem domid=3D%u memkb=3D%"PRIu64" failed "=0A = "rc=3D%d\n", domid, memorykb, rc);=0A abort_transac= tion =3D 1;=0A goto out;=0A --=__Part5F6B30D8.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part5F6B30D8.2__=--