From nobody Thu Nov 14 07:18:30 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; dkim=pass; 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=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1675200598; cv=none; d=zohomail.com; s=zohoarc; b=ayaif7PsjhBCt5DY4Jfu4Ing3ajm84yKBag0QCGZvebTRkkzErqLCn+ZiL/yBEEHgTfBhFsfde9hojMLUd5/JmBd0QOQMvaxrOND9sUf/8prrDpdsX9bTsRYUp6yadYuEYZ8tg1CHNCZPTUjJ7UP/0yBlV/ZzJKzWAV4J0dkGOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675200598; 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; bh=QUeB6tNZE7IPjyugDVSD0+aF2N6eaF/lZ2cncven+CI=; b=Nkq8lF1jA8ObldhR8g6WvZrPMjCA4B7VQPZ39A9WHlF3u4BAGpwVAE3OUtUARXtU9u6atTZMXHSZZZ055T8paaiE1wmMZY3P6rFxPagm/jIRbSyw6m0259WiJ7eODvowDH25B+1spcMg1fhn2Ozgod270iqNQqLarFep7rrA0D8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1675200597993890.4645723203801; Tue, 31 Jan 2023 13:29:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.487847.755590 (Exim 4.92) (envelope-from ) id 1pMyC6-00015d-35; Tue, 31 Jan 2023 21:29:34 +0000 Received: by outflank-mailman (output) from mailman id 487847.755590; Tue, 31 Jan 2023 21:29:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC5-000159-Ty; Tue, 31 Jan 2023 21:29:33 +0000 Received: by outflank-mailman (input) for mailman id 487847; Tue, 31 Jan 2023 21:29:32 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pMyC4-0000Nb-Kh for xen-devel@lists.xenproject.org; Tue, 31 Jan 2023 21:29:32 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 58eef30c-a1ae-11ed-933c-83870f6b2ba8; Tue, 31 Jan 2023 22:29:31 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 58eef30c-a1ae-11ed-933c-83870f6b2ba8 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1675200570; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h6tenPYxyZVuTbfcgU9nfxQU9sqSsuEBVjFHdCiT8ok=; b=ZqQqvOdX5KKbbBc3TH9V8JrKxTvwFWztDm1k7EmLlFMal2Qc2wD+TqMZ MZj+V/IaN4scW7KbBhxfC/5ayssWolx4KVrtyEtccb5tDt0lvvDBvtvEV N8h6tAFJtwyY9c0q7TKebPETQ/bQV7g9QRc9QqhlA2PoLcfTTsmXI2xWG U=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 95499179 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:dbqxyaKz/vJ8W1YuFE+R0JUlxSXFcZb7ZxGr2PjKsXjdYENShDMOz 2QcXGCPaPuNajDyKNkiPYmy8E1S6JTWm4MyQVBlqX01Q3x08seUXt7xwmUcnc+xBpaaEB84t ZV2hv3odp1coqr0/0/1WlTZhSAgk/rOHv+kUrWs1hlZHWdMUD0mhQ9oh9k3i4tphcnRKw6Ws Jb5rta31GWNglaYCUpJrfPcwP9TlK6q4mhA5wdnPasjUGL2zBH5MrpOfcldEFOgKmVkNrbSb /rOyri/4lTY838FYj9yuu+mGqGiaue60Tmm0hK6aYD76vRxjnVaPpIAHOgdcS9qZwChxLid/ jnvWauYEm/FNoWU8AgUvoIx/ytWZcWq85efSZSzXFD6I+QrvBIAzt03ZHzaM7H09c5eGUQWx 7s6NgkUZx2Po7nq6YCJW9BF05FLwMnDZOvzu1llxDDdS/0nXYrCU+PB4towMDUY354UW6yEP oxANGQpNU6bC/FMEg5/5JYWteGknHTgNRZfr0qYv/Ef6GnP1g1hlrPqNbI5f/TbGJkEzx/H9 woq+UziPB9CZYSR+AaI91ypgM70xDrZcYE7QejQGvlC3wTImz175ActfUu2p7y1h1CzX/pbK lcI4Ww+oK4q7kupQ9LhGRqirxasshcCVvJKHuY96QXLzbDbizt1HUBdEGQHMoZ/8pZrG3pzj AThc87V6SJHmaWwEUDa1KmttDq/NQxOcUYwVz49ZF5QizX8m70bghXKR9dlNae6iNzpBD39q wy3QDgCa6Y71pBSifjilbzTq3f1/8WSEFZpjunCdjj9hj6VcrJJcGBBBbLzyf9bZLiUQVCa1 JTvs5jPtbteZX1hecHkf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rQw0qnwYA6GvPH4YQKSRnDC X-IronPort-AV: E=Sophos;i="5.97,261,1669093200"; d="scan'208";a="95499179" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Christian Lindig , David Scott , =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Rob Hoes Subject: [PATCH 2/7] tools/ocaml/libs: Allocate the correct amount of memory for Abstract_tag Date: Tue, 31 Jan 2023 21:29:08 +0000 Message-ID: <20230131212913.6199-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20230131212913.6199-1-andrew.cooper3@citrix.com> References: <20230131212913.6199-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1675200599494100001 caml_alloc() takes units of Wsize (word size), not bytes. As a consequence, we're allocating 4 or 8 times too much memory. Ocaml has a helper, Wsize_bsize(), but it truncates cases which aren't an exact multiple. Use a BUILD_BUG_ON() to cover the potential for truncation, as there's no rounding-up form of the helper. Fixes: 8b7ce06a2d34 ("ocaml: Add XC bindings.") Fixes: d3e649277a13 ("ocaml: add mmap bindings implementation.") Signed-off-by: Andrew Cooper --- CC: Christian Lindig CC: David Scott CC: Edwin T=C3=B6r=C3=B6k CC: Rob Hoes --- tools/ocaml/libs/mmap/Makefile | 2 ++ tools/ocaml/libs/mmap/xenmmap_stubs.c | 6 +++++- tools/ocaml/libs/xc/xenctrl_stubs.c | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/ocaml/libs/mmap/Makefile b/tools/ocaml/libs/mmap/Makefile index a62153713571..855b8b2c9877 100644 --- a/tools/ocaml/libs/mmap/Makefile +++ b/tools/ocaml/libs/mmap/Makefile @@ -2,6 +2,8 @@ OCAML_TOPLEVEL=3D$(CURDIR)/../.. XEN_ROOT=3D$(OCAML_TOPLEVEL)/../.. include $(OCAML_TOPLEVEL)/common.make =20 +CFLAGS +=3D $(CFLAGS_xeninclude) + OBJS =3D xenmmap INTF =3D $(foreach obj, $(OBJS),$(obj).cmi) LIBS =3D xenmmap.cma xenmmap.cmxa diff --git a/tools/ocaml/libs/mmap/xenmmap_stubs.c b/tools/ocaml/libs/mmap/= xenmmap_stubs.c index e03951d781bb..d623ad390e40 100644 --- a/tools/ocaml/libs/mmap/xenmmap_stubs.c +++ b/tools/ocaml/libs/mmap/xenmmap_stubs.c @@ -21,6 +21,8 @@ #include #include "mmap_stubs.h" =20 +#include + #include #include #include @@ -59,7 +61,9 @@ CAMLprim value stub_mmap_init(value fd, value pflag, valu= e mflag, default: caml_invalid_argument("maptype"); } =20 - result =3D caml_alloc(sizeof(struct mmap_interface), Abstract_tag); + BUILD_BUG_ON((sizeof(struct mmap_interface) % sizeof(value)) !=3D 0); + result =3D caml_alloc(Wsize_bsize(sizeof(struct mmap_interface)), + Abstract_tag); =20 if (mmap_interface_init(Intf_val(result), Int_val(fd), c_pflag, c_mflag, diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenc= trl_stubs.c index 728818445975..fd1f306f0202 100644 --- a/tools/ocaml/libs/xc/xenctrl_stubs.c +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c @@ -1031,7 +1031,10 @@ CAMLprim value stub_map_foreign_range(value xch, val= ue dom, uint32_t c_dom; unsigned long c_mfn; =20 - result =3D caml_alloc(sizeof(struct mmap_interface), Abstract_tag); + BUILD_BUG_ON((sizeof(struct mmap_interface) % sizeof(value)) !=3D 0); + result =3D caml_alloc(Wsize_bsize(sizeof(struct mmap_interface)), + Abstract_tag); + intf =3D (struct mmap_interface *) result; =20 intf->len =3D Int_val(size); --=20 2.11.0