From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
Anthony PERARD <anthony.perard@vates.tech>,
Juergen Gross <jgross@suse.com>,
Oleksii Kurochko <oleksii.kurochko@gmail.com>
Subject: Re: [PATCH 2/2] tools/libs/guest: Use the system liblz4 in the bzimage loader
Date: Mon, 8 Jun 2026 12:46:55 +0200 [thread overview]
Message-ID: <aiadn_Gaf9IfkrUu@macbook.local> (raw)
In-Reply-To: <20260603085331.2704108-3-andrew.cooper3@citrix.com>
On Wed, Jun 03, 2026 at 09:53:31AM +0100, Andrew Cooper wrote:
> Right now lz4, unlike every other compression scheme, unconditionally uses
> Xen's unsafe decompressor. Make it consistent with all other compression
> schemes by using liblz4.
>
> The unsafe decompression is still required for the MiniOS build, so rename
> xg_dom_decompress_lz4.c to xg_dom_decompress_unsafe_lz4.c and drop the
> non-MiniOS content.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
> ---
> CC: Anthony PERARD <anthony.perard@vates.tech>
> CC: Juergen Gross <jgross@suse.com>
> CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
> ---
> tools/libs/guest/Makefile.common | 2 +-
> tools/libs/guest/xg_dom_bzimageloader.c | 128 +++++++++++++++-
> tools/libs/guest/xg_dom_decompress.h | 6 -
> tools/libs/guest/xg_dom_decompress_lz4.c | 143 ------------------
> tools/libs/guest/xg_dom_decompress_unsafe.h | 2 +
> .../libs/guest/xg_dom_decompress_unsafe_lz4.c | 39 +++++
> 6 files changed, 169 insertions(+), 151 deletions(-)
> delete mode 100644 tools/libs/guest/xg_dom_decompress.h
> delete mode 100644 tools/libs/guest/xg_dom_decompress_lz4.c
> create mode 100644 tools/libs/guest/xg_dom_decompress_unsafe_lz4.c
>
> diff --git a/tools/libs/guest/Makefile.common b/tools/libs/guest/Makefile.common
> index b928a4a246a9..86b1f160e536 100644
> --- a/tools/libs/guest/Makefile.common
> +++ b/tools/libs/guest/Makefile.common
> @@ -46,7 +46,6 @@ OBJS-y += xg_dom_core.o
> OBJS-y += xg_dom_boot.o
> OBJS-y += xg_dom_elfloader.o
> OBJS-$(CONFIG_X86) += xg_dom_bzimageloader.o
> -OBJS-$(CONFIG_X86) += xg_dom_decompress_lz4.o
> OBJS-$(CONFIG_X86) += xg_dom_hvmloader.o
> OBJS-$(CONFIG_ARM) += xg_dom_armzimageloader.o
> OBJS-y += xg_dom_binloader.o
> @@ -59,6 +58,7 @@ OBJS-$(CONFIG_ARM) += xg_dom_arm.o
> ifeq ($(CONFIG_LIBXC_MINIOS),y)
> OBJS-y += xg_dom_decompress_unsafe.o
> OBJS-y += xg_dom_decompress_unsafe_bzip2.o
> +OBJS-y += xg_dom_decompress_unsafe_lz4.o
> OBJS-y += xg_dom_decompress_unsafe_lzma.o
> OBJS-y += xg_dom_decompress_unsafe_lzo1x.o
> OBJS-y += xg_dom_decompress_unsafe_xz.o
> diff --git a/tools/libs/guest/xg_dom_bzimageloader.c b/tools/libs/guest/xg_dom_bzimageloader.c
> index 1fb4e5a1f728..32b3c682a447 100644
> --- a/tools/libs/guest/xg_dom_bzimageloader.c
> +++ b/tools/libs/guest/xg_dom_bzimageloader.c
> @@ -32,7 +32,6 @@
> #include <inttypes.h>
>
> #include "xg_private.h"
> -#include "xg_dom_decompress.h"
>
> #include <xen-tools/common-macros.h>
>
> @@ -623,6 +622,133 @@ static int xc_try_zstd_decode(
>
> #endif
>
> +#if defined(HAVE_LZ4)
> +
> +#include <lz4.h>
> +
> +#define ARCHIVE_MAGICNUMBER 0x184C2102
> +
> +static int xc_try_lz4_decode(struct xc_dom_image *dom, void **blob, size_t *size)
> +{
> + size_t outsize, insize;
> + unsigned char *outbuf = NULL, *inp = *blob, *outp;
> + uint32_t chunksize;
> +
> + /* Magic, descriptor byte, and trailing size field. */
> + if ( *size <= 8 )
> + {
> + DOMPRINTF("LZ4: insufficient input data");
> + goto err;
> + }
> +
> + insize = *size - 4;
> + outsize = get_unaligned_le32(*blob + insize);
> +
> + if ( xc_dom_kernel_check_size(dom, outsize) )
> + {
> + DOMPRINTF("LZ4: output too large");
> + goto err;
> + }
> +
> + outbuf = malloc(outsize);
I would use calloc() or memset() the buffer, just in case part of it
is (wrongly) left uninitialized, as this is copied into guest memory.
I see this is code moment, so possibly better to adjust afterwards if
anything.
Thanks, Roger.
next prev parent reply other threads:[~2026-06-08 10:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 8:53 [PATCH for-4.22(?) 0/2] tools: Use the system liblz4 package Andrew Cooper
2026-06-03 8:53 ` [PATCH 1/2] tools/configure: Detect the presence of liblz4 Andrew Cooper
2026-06-08 10:15 ` Roger Pau Monné
2026-06-03 8:53 ` [PATCH 2/2] tools/libs/guest: Use the system liblz4 in the bzimage loader Andrew Cooper
2026-06-08 10:46 ` Roger Pau Monné [this message]
2026-06-08 10:51 ` Andrew Cooper
2026-06-03 9:16 ` [PATCH for-4.22(?) 0/2] tools: Use the system liblz4 package Jan Beulich
2026-06-03 9:21 ` Andrew Cooper
2026-06-03 9:24 ` Jan Beulich
2026-06-03 13:01 ` Oleksii Kurochko
2026-06-08 10:51 ` Oleksii Kurochko
2026-06-08 10:57 ` Andrew Cooper
2026-06-08 11:30 ` Oleksii Kurochko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aiadn_Gaf9IfkrUu@macbook.local \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=jgross@suse.com \
--cc=oleksii.kurochko@gmail.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.