[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Xenctrl.domain_setmaxmem: fix 32-bit truncation bug


  • To: Edwin Török <edwin.torok@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Thu, 5 Feb 2026 16:10:12 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CIFNsboLgTT8NUSFp1lc6J0wLhVurW6307dOo7PAn9c=; b=kPRaCcRneJYK19tjngSlviB0H4e0v+x+ivsqWXX9ZqV0j3dcmnI3OYD2lDaQwQ00IGC87/o+m6V34zpXUknHZWICwJm7P0Kk4s+p9jmNCLSrU78nJbr/IZi28ACplCYf6LOe28ngR+YypwIXmiP8yjFxVR/OjnorBLbpvvwBCCX5NEAfIca6CrEaepFASCZKaXDqEp1W+pCzyviSc+LzV1PfO2KEaDsd/I3XItMdrsUxCgT1cM1lISgn6ulakG9YstOOcbK7N15kpSRWXcn6V97MoBZLTg5xsd2tb4i5k805RrvnTHG8FKlo8q/yVGfNGFrLq4RSeLiOnPzQGdUI6g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MoD7BpQmz6GK24hN28r4IHa/Dn7JwLgP2Q5HgdYUani75Im9FhI+5lhw6pGy70nzmLa3W1o50cwNyhuTu52r8iG9qcS4tyRzPSxkaI3tlr6Kq5YsRMEs3+76okI7eFwu6K+3G7yx+37p3jtZghFmmv0vLhMKfcbA9yiJidz/2usfY4TddfTh14EnbYNePb3QXnwZiK7XPL0IFxJlrOowF5Wy7DZpo+inF/nveNCkCgJeGOj89hXqqowy/i+flW9VerTiwLMQXMt7YgpyGGaX0ZqeSJ6Kc7H5SMs/2MJB2mAGKhSXZFFTA+wBN10mLZYzjQwBGhLWYhW2n4PaV13BJg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Christian Lindig <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Delivery-date: Thu, 05 Feb 2026 16:10:23 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 05/02/2026 1:56 pm, Edwin Török wrote:
> Observed when attempting to boot a >4TiB VM:
>
> After a call to domain_setmaxmem with 6370254848 (KiB),
> the domain's maxmem got set to 2075287552,
> which is exactly 2^32 smaller.
>
> xc_domain_setmaxmem takes an uint64_t as a parameter,
> and the OCaml value is 64-bit already, so fix the C variable
> to match the type and avoid the truncation.

Fixes: f5b43e95facd ("libxl: fix "xl mem-set" regression from 0c029c4da2")

> Signed-off-by: Edwin Török <edwin.torok@xxxxxxxxxx>

Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>

> ---
>  tools/ocaml/libs/xc/xenctrl_stubs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c 
> b/tools/ocaml/libs/xc/xenctrl_stubs.c
> index ac2a7537d6..c55f73b265 100644
> --- a/tools/ocaml/libs/xc/xenctrl_stubs.c
> +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
> @@ -947,7 +947,7 @@ CAMLprim value stub_xc_domain_setmaxmem(value xch_val, 
> value domid,
>       int retval;
>  
>       uint32_t c_domid = Int_val(domid);
> -     unsigned int c_max_memkb = Int64_val(max_memkb);
> +     uint64_t c_max_memkb = Int64_val(max_memkb);
>       caml_enter_blocking_section();
>       retval = xc_domain_setmaxmem(xch, c_domid, c_max_memkb);
>       caml_leave_blocking_section();

Interestingly, in 8b7ce06a2d341c1f when the Ocaml bindings where
introduced, it was always an Int64 downcast into an unsigned int, so the
binding was correct.  Later, xc_domain_setmaxmem() was upgraded from an
unsigned int to a uint64_t.

~Andrew



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.