Skip to contentSkip to conversation

grub-install: Include all decompressor modules in pvxen core image.

PATCH In review Ian Campbell 3 participants 11 messages Nov 28, 2014 – Feb 12, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 grub-install: Include all decompressor modules in pvxen core image.

From: Ian Campbell <[email protected]>

This avoids needing to update all the native update-grub stanzas to also probe for and arrange to load the relevant decompressor, which would be wasteful on native boots.

---
 util/grub-install.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
util/grub-install.c +25 -0
index 7a7734e..6ad5afb 100644
@@ -422,6 +422,14 @@ push_cryptodisk_module (const char *mod, void *data __attribute__ ((unused)))
 }
 
 static void
+push_all_decompressor_modules(void)
+{
+  grub_install_push_module ("gzio");
+  grub_install_push_module ("xzio");
+  grub_install_push_module ("lzopio");
+}
+
+static void
 probe_mods (grub_disk_t disk)
 {
   grub_partition_t part;
@@ -1228,6 +1236,23 @@ main (int argc, char *argv[])
 	}
     }
 
+
+  switch (platform)
+    {
+    case GRUB_INSTALL_PLATFORM_I386_XEN:
+    case GRUB_INSTALL_PLATFORM_X86_64_XEN:
+      /* When booting a Xen PV kernel grub may need to decompress the
+       * kernel which may use a variety of algorithmns. Since we try
+       * to reuse the native grub.cfg files rather than trying to
+       * insmod the relevant decompressors on the fly we build them
+       * into the core image. This means we avoid needlessly loading
+       * modules on native. */
+      push_all_decompressor_modules();
+      break;
+    default:
+      break;
+    }
+
   grub_install_copy_files (grub_install_source_directory,
 			   grubdir, platform);
 
Signature · 1 line
2.1.3
#1 lore raw

В Fri, 28 Nov 2014 08:33:34 +0000
Ian Campbell <[email protected]> пишет:

Quoted 6 lines

From: Ian Campbell <[email protected]>

This avoids needing to update all the native update-grub stanzas to also probe for and arrange to load the relevant decompressor, which would be wasteful on native boots.

Could you give some more details why you need it?

Quoted 10 lines
---
 util/grub-install.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
util/grub-install.c +0 -0
index 7a7734e..6ad5afb 100644

util/grub-install.c push_cryptodisk_module (const char *mod, void *data __attribute__ ((unused))) · line 431

Quoted 10 lines
util/grub-install.c +7 -0
@@ -422,6 +422,14 @@ push_cryptodisk_module (const char *mod, void *data __attribute__ ((unused)))
 }
 
 static void
+push_all_decompressor_modules(void)
+{
+  grub_install_push_module ("gzio");
+  grub_install_push_module ("xzio");
+  grub_install_push_module ("lzopio");
+}
+

It is not enough. Some of them need another modules that are autoloaded by normal.

Quoted 28 lines
util/grub-install.c +18 -0
+static void
 probe_mods (grub_disk_t disk)
 {
   grub_partition_t part;
@@ -1228,6 +1236,23 @@ main (int argc, char *argv[])
 	}
     }
 
+
+  switch (platform)
+    {
+    case GRUB_INSTALL_PLATFORM_I386_XEN:
+    case GRUB_INSTALL_PLATFORM_X86_64_XEN:
+      /* When booting a Xen PV kernel grub may need to decompress the
+       * kernel which may use a variety of algorithmns. Since we try
+       * to reuse the native grub.cfg files rather than trying to
+       * insmod the relevant decompressors on the fly we build them
+       * into the core image. This means we avoid needlessly loading
+       * modules on native. */
+      push_all_decompressor_modules();
+      break;
+    default:
+      break;
+    }
+
   grub_install_copy_files (grub_install_source_directory,
 			   grubdir, platform);
 
#2 lore raw
Quoted 11 lines · Andrei Borzenkov

В Fri, 28 Nov 2014 08:33:34 +0000
Ian Campbell <[email protected]> пишет:

Quoted 6 lines

From: Ian Campbell <[email protected]>

This avoids needing to update all the native update-grub stanzas to also probe for and arrange to load the relevant decompressor, which would be wasteful on native boots.

Could you give some more details why you need it?

In order to boot a Linux kernel under Xen grub needs to extract the ELF file from the bzImage payload, which is compressed.

The compression algo is a kernel compile time option, gz and xz are the most probably ones today.

Quoted 10 lines

util/grub-install.c push_cryptodisk_module (const char *mod, void *data __attribute__ ((unused))) · line 431

Quoted 7 lines
util/grub-install.c +7 -0
+push_all_decompressor_modules(void)
+{
+  grub_install_push_module ("gzio");
+  grub_install_push_module ("xzio");
+  grub_install_push_module ("lzopio");
+}
+

It is not enough. Some of them need another modules that are autoloaded by normal.

autoloading should work, I think.

But if not -- how can one determine which modules are required and/or arrange for them to be added automatically?

Quoted 31 lines
Quoted 29 lines
util/grub-install.c +18 -0
+static void
 probe_mods (grub_disk_t disk)
 {
   grub_partition_t part;
@@ -1228,6 +1236,23 @@ main (int argc, char *argv[])
 	}
     }
 
+
+  switch (platform)
+    {
+    case GRUB_INSTALL_PLATFORM_I386_XEN:
+    case GRUB_INSTALL_PLATFORM_X86_64_XEN:
+      /* When booting a Xen PV kernel grub may need to decompress the
+       * kernel which may use a variety of algorithmns. Since we try
+       * to reuse the native grub.cfg files rather than trying to
+       * insmod the relevant decompressors on the fly we build them
+       * into the core image. This means we avoid needlessly loading
+       * modules on native. */
+      push_all_decompressor_modules();
+      break;
+    default:
+      break;
+    }
+
   grub_install_copy_files (grub_install_source_directory,
 			   grubdir, platform);
 
#3 lore raw

В Fri, 28 Nov 2014 17:25:55 +0000
Ian Campbell <[email protected]> пишет:

Quoted 11 lines · Andrei Borzenkov
Quoted 10 lines

В Fri, 28 Nov 2014 08:33:34 +0000
Ian Campbell <[email protected]> пишет:

Quoted 6 lines

From: Ian Campbell <[email protected]>

This avoids needing to update all the native update-grub stanzas to also probe for and arrange to load the relevant decompressor, which would be wasteful on native boots.

Quoted 8 lines
Quoted 1 line

Could you give some more details why you need it?

In order to boot a Linux kernel under Xen grub needs to extract the ELF file from the bzImage payload, which is compressed.

The compression algo is a kernel compile time option, gz and xz are the most probably ones today.

Not directly related but I this comment in Makefile draw my attention:

# Note that the bytes added by size_append will make the xz tool think that

# the file is corrupt. This is expected.

We probably never read vmlinuz to the end anyway, but I wonder if it could be an issue.

Quoted 11 lines
Quoted 10 lines

util/grub-install.c push_cryptodisk_module (const char *mod, void *data __attribute__ ((unused))) · line 431

Quoted 7 lines
util/grub-install.c +7 -0
+push_all_decompressor_modules(void)
+{
+  grub_install_push_module ("gzio");
+  grub_install_push_module ("xzio");
+  grub_install_push_module ("lzopio");
+}
+

It is not enough. Some of them need another modules that are autoloaded by normal.

Quoted 2 lines

autoloading should work, I think.

OK, so you need it post-normal. core.img is really about getting access to /boot/grub; anything else can be done from within grub.cfg. If you do not want to load other filters unconditionally, just use

if [ x$grub_platform = xxen ]; then
insmod xzio
fi

But as far as I understand, CONFIG_KERNEL_XZ is not really dependent on Xen; so we may want to either load them for real hardware as well or - better - extend grub-file to check for compression method.

Quoted 36 lines

But if not -- how can one determine which modules are required and/or arrange for them to be added automatically?

Quoted 31 lines
Quoted 29 lines
util/grub-install.c +18 -0
+static void
 probe_mods (grub_disk_t disk)
 {
   grub_partition_t part;
@@ -1228,6 +1236,23 @@ main (int argc, char *argv[])
 	}
     }
 
+
+  switch (platform)
+    {
+    case GRUB_INSTALL_PLATFORM_I386_XEN:
+    case GRUB_INSTALL_PLATFORM_X86_64_XEN:
+      /* When booting a Xen PV kernel grub may need to decompress the
+       * kernel which may use a variety of algorithmns. Since we try
+       * to reuse the native grub.cfg files rather than trying to
+       * insmod the relevant decompressors on the fly we build them
+       * into the core image. This means we avoid needlessly loading
+       * modules on native. */
+      push_all_decompressor_modules();
+      break;
+    default:
+      break;
+    }
+
   grub_install_copy_files (grub_install_source_directory,
 			   grubdir, platform);
 
#4 lore raw
Quoted 23 lines · Andrei Borzenkov

В Fri, 28 Nov 2014 17:25:55 +0000
Ian Campbell <[email protected]> пишет:

Quoted 11 lines · Andrei Borzenkov
Quoted 10 lines

В Fri, 28 Nov 2014 08:33:34 +0000
Ian Campbell <[email protected]> пишет:

Quoted 6 lines

From: Ian Campbell <[email protected]>

This avoids needing to update all the native update-grub stanzas to also probe for and arrange to load the relevant decompressor, which would be wasteful on native boots.

Quoted 8 lines
Quoted 1 line

Could you give some more details why you need it?

In order to boot a Linux kernel under Xen grub needs to extract the ELF file from the bzImage payload, which is compressed.

The compression algo is a kernel compile time option, gz and xz are the most probably ones today.

Quoted 7 lines

Not directly related but I this comment in Makefile draw my attention:

# Note that the bytes added by size_append will make the xz tool think that

# the file is corrupt. This is expected.

We probably never read vmlinuz to the end anyway, but I wonder if it could be an issue.

I've no idea. I don't see that comment anywhere in either Linux nor Grub codebase though. I do know that insmod xzio makes grub capable of booting the Debian kernel.

Quoted 14 lines
Quoted 11 lines
Quoted 10 lines

util/grub-install.c push_cryptodisk_module (const char *mod, void *data __attribute__ ((unused))) · line 431

Quoted 7 lines
util/grub-install.c +7 -0
+push_all_decompressor_modules(void)
+{
+  grub_install_push_module ("gzio");
+  grub_install_push_module ("xzio");
+  grub_install_push_module ("lzopio");
+}
+

It is not enough. Some of them need another modules that are autoloaded by normal.

Quoted 2 lines

autoloading should work, I think.

Quoted 7 lines

OK, so you need it post-normal. core.img is really about getting access to /boot/grub; anything else can be done from within grub.cfg. If you do not want to load other filters unconditionally, just use

if [ x$grub_platform = xxen ]; then
insmod xzio
fi

I think that could work. Is adding Xen specific stuff to grub.cfg the preferred way to do this sort of thing then?

Quoted 3 lines

But as far as I understand, CONFIG_KERNEL_XZ is not really dependent on Xen; so we may want to either load them for real hardware as well or - better - extend grub-file to check for compression method.

On native the bootloader has no reason to decompress the Linux bzImage payload, the kernel itself can do so. AFAIK decompression is only need for Xen (and for certain userspace tools like crash and other debuggers, but they aren't relevant here).

Quoted 2 lines
Quoted 2 lines

But if not -- how can one determine which modules are required and/or arrange for them to be added automatically?

You'd have to peer into the kernel image, use the bzImage header fields to locate the payload and then do magic number probing to figure out which compression algorithm is used.

Ian.

#5 lore raw
Quoted 1 line · Ian Campbell

On Sun, 2014-11-30 at 14:31 +0300, Andrei Borzenkov wrote:

[...]

Quoted 5 lines
Quoted 2 lines

We probably never read vmlinuz to the end anyway, but I wonder if it could be an issue.

I've no idea. I don't see that comment anywhere in either Linux nor Grub codebase though.

NM, I found it in scripts/Makefile.lib...

Doesn't seem to matter in practice though.

Ian.

#6 lore raw
In reply to Ian Campbell
Quoted 6 lines · Ian Campbell
Quoted 3 lines · Andrei Borzenkov

if [ x$grub_platform = xxen ]; then
insmod xzio
fi

I think that could work.

Indeed it does, so how about this instead of the patch at the start of the thread?

From f4199776eca80dfad4e9378a01ddb5866face3d7 Mon Sep 17 00:00:00 2001
From: Ian Campbell <[email protected]>
Date: Sun, 30 Nov 2014 12:12:52 +0000
Subject: [PATCH] Arrange to insmod xzio when booting a kernel as a Xen guest

This is needed in case the Linux kernel is compiled with CONFIG_KERNEL_XZ rather than CONFIG_KERNEL_GZ (gzio is already loaded by grub.cfg).

Patch-Name: insmod-xzio-on-xen.patch

---
 util/grub.d/10_linux.in | 1 +
 1 file changed, 1 insertion(+)
util/grub.d/10_linux.in +1 -0
index 79fa03a..86e35f2 100644
@@ -150,6 +150,7 @@ linux_entry ()
   fi
 
   echo "	insmod gzio" | sed "s/^/$submenu_indentation/"
+  echo "	if [ x\$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi" | sed "s/^/$submenu_indentation/"
 
   if [ x$dirname = x/ ]; then
     if [ -z "${prepare_root_cache}" ]; then
Signature · 1 line
2.1.3
#7 lore raw
Quoted 11 lines · Ian Campbell
Quoted 6 lines · Ian Campbell
Quoted 3 lines · Andrei Borzenkov

if [ x$grub_platform = xxen ]; then
insmod xzio
fi

I think that could work.

Indeed it does, so how about this instead of the patch at the start of the thread?

This should probably have been autoloaded. Can you send me privately a kernel you use, so I can reproduce your tests?

Quoted 28 lines
Quoted 1 line

From f4199776eca80dfad4e9378a01ddb5866face3d7 Mon Sep 17 00:00:00 2001

From: Ian Campbell <[email protected]>
Date: Sun, 30 Nov 2014 12:12:52 +0000
Subject: [PATCH] Arrange to insmod xzio when booting a kernel as a Xen guest

This is needed in case the Linux kernel is compiled with CONFIG_KERNEL_XZ rather than CONFIG_KERNEL_GZ (gzio is already loaded by grub.cfg).

Patch-Name: insmod-xzio-on-xen.patch

---
 util/grub.d/10_linux.in | 1 +
 1 file changed, 1 insertion(+)
util/grub.d/10_linux.in +1 -0
index 79fa03a..86e35f2 100644
@@ -150,6 +150,7 @@ linux_entry ()
   fi
 
   echo "	insmod gzio" | sed "s/^/$submenu_indentation/"
+  echo "	if [ x\$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi" | sed "s/^/$submenu_indentation/"
 
   if [ x$dirname = x/ ]; then
     if [ -z "${prepare_root_cache}" ]; then
#8 lore raw

В Sun, 07 Dec 2014 18:18:47 +0100
Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]> пишет:

Quoted 7 lines · Ian Campbell
Quoted 6 lines · Ian Campbell
Quoted 5 lines · Andrei Borzenkov
Quoted 3 lines

if [ x$grub_platform = xxen ]; then
insmod xzio
fi

Quoted 6 lines
Quoted 5 lines
Quoted 1 line

I think that could work.

Indeed it does, so how about this instead of the patch at the start of the thread?

This should probably have been autoloaded.

File filters are not autoloaded and I do not see how it can really be done. OTOH unconditionally loading them may have unwanted side effect where we assumed files were not decompressed.

In this specific case extending grub-file to detect compression type used by kernel is probably OK.

Quoted 32 lines

Can you send me privately a
kernel you use, so I can reproduce your tests?

Quoted 28 lines
Quoted 1 line

From f4199776eca80dfad4e9378a01ddb5866face3d7 Mon Sep 17 00:00:00 2001

From: Ian Campbell <[email protected]>
Date: Sun, 30 Nov 2014 12:12:52 +0000
Subject: [PATCH] Arrange to insmod xzio when booting a kernel as a Xen guest

This is needed in case the Linux kernel is compiled with CONFIG_KERNEL_XZ rather than CONFIG_KERNEL_GZ (gzio is already loaded by grub.cfg).

Patch-Name: insmod-xzio-on-xen.patch

---
 util/grub.d/10_linux.in | 1 +
 1 file changed, 1 insertion(+)
util/grub.d/10_linux.in +1 -0
index 79fa03a..86e35f2 100644
@@ -150,6 +150,7 @@ linux_entry ()
   fi
 
   echo "	insmod gzio" | sed "s/^/$submenu_indentation/"
+  echo "	if [ x\$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi" | sed "s/^/$submenu_indentation/"
 
   if [ x$dirname = x/ ]; then
     if [ -z "${prepare_root_cache}" ]; then
#9 lore raw
Quoted 12 lines · Andrei Borzenkov

В Sun, 07 Dec 2014 18:18:47 +0100
Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]> пишет:

Quoted 9 lines · Ian Campbell
Quoted 8 lines · Ian Campbell
Quoted 6 lines · Andrei Borzenkov
Quoted 3 lines

if [ x$grub_platform = xxen ]; then
insmod xzio
fi

I think that could work.

Quoted 9 lines
Quoted 4 lines
Quoted 3 lines

Indeed it does, so how about this instead of the patch at the start of the thread?

This should probably have been autoloaded.

File filters are not autoloaded and I do not see how it can really be done. OTOH unconditionally loading them may have unwanted side effect where we assumed files were not decompressed.

In this particular case we could autoload based on signature to module map. Probably it's a fair game since compressor can be uniquely determined from magic.
Autoload could be restricted to xen linux loader.

Quoted 43 lines

In this specific case extending grub-file to detect compression type used by kernel is probably OK.

Quoted 24 lines

Can you send me privately a
kernel you use, so I can reproduce your tests?

Quoted 22 lines
Quoted 1 line

From f4199776eca80dfad4e9378a01ddb5866face3d7 Mon Sep 17 00:00:00 2001

From: Ian Campbell <[email protected]>
Date: Sun, 30 Nov 2014 12:12:52 +0000
Subject: [PATCH] Arrange to insmod xzio when booting a kernel as a Xen guest

This is needed in case the Linux kernel is compiled with CONFIG_KERNEL_XZ rather than CONFIG_KERNEL_GZ (gzio is already loaded by grub.cfg).

Patch-Name: insmod-xzio-on-xen.patch

---
 util/grub.d/10_linux.in | 1 +
 1 file changed, 1 insertion(+)
util/grub.d/10_linux.in +0 -0
index 79fa03a..86e35f2 100644
@@ -150,6 +150,7 @@ linux_entry ()
   fi
 
Quoted 8 lines

util/grub.d/10_linux.in linux_entry () · line 156

Quoted 6 lines
util/grub.d/10_linux.in +1 -0
   echo "	insmod gzio" | sed "s/^/$submenu_indentation/"
+  echo "	if [ x\$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi" | sed "s/^/$submenu_indentation/"
 
   if [ x$dirname = x/ ]; then
     if [ -z "${prepare_root_cache}" ]; then

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#10 lore raw
In reply to Andrei Borzenkov
Quoted 15 lines · Andrei Borzenkov

В Sun, 07 Dec 2014 18:18:47 +0100
Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]> пишет:

Quoted 12 lines · Ian Campbell
Quoted 11 lines · Ian Campbell
Quoted 6 lines · Andrei Borzenkov
Quoted 3 lines

if [ x$grub_platform = xxen ]; then
insmod xzio
fi

I think that could work.

Indeed it does, so how about this instead of the patch at the start of the thread?

Quoted 8 lines
Quoted 1 line

This should probably have been autoloaded.

File filters are not autoloaded and I do not see how it can really be done. OTOH unconditionally loading them may have unwanted side effect where we assumed files were not decompressed.

In this specific case extending grub-file to detect compression type used by kernel is probably OK.

Please test attached file.

Quoted 36 lines
Quoted 25 lines

Can you send me privately a
kernel you use, so I can reproduce your tests?

Quoted 22 lines
Quoted 1 line

From f4199776eca80dfad4e9378a01ddb5866face3d7 Mon Sep 17 00:00:00 2001

From: Ian Campbell <[email protected]>
Date: Sun, 30 Nov 2014 12:12:52 +0000
Subject: [PATCH] Arrange to insmod xzio when booting a kernel as a Xen guest

This is needed in case the Linux kernel is compiled with CONFIG_KERNEL_XZ rather than CONFIG_KERNEL_GZ (gzio is already loaded by grub.cfg).

Patch-Name: insmod-xzio-on-xen.patch

---
 util/grub.d/10_linux.in | 1 +
 1 file changed, 1 insertion(+)
util/grub.d/10_linux.in +0 -0
index 79fa03a..86e35f2 100644
@@ -150,6 +150,7 @@ linux_entry ()
   fi
 
Quoted 8 lines

util/grub.d/10_linux.in linux_entry () · line 156

Quoted 6 lines
util/grub.d/10_linux.in +1 -0
   echo "	insmod gzio" | sed "s/^/$submenu_indentation/"
+  echo "	if [ x\$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi" | sed "s/^/$submenu_indentation/"
 
   if [ x$dirname = x/ ]; then
     if [ -z "${prepare_root_cache}" ]; then
Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

grub-core/loader/i386/xen_file.c +95 -3
index 5836218..90e0a6e 100644
@@ -20,12 +20,99 @@
 #include <grub/i386/linux.h>
 #include <grub/misc.h>
 
+#define LZOP_MAGIC "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a"
+#define LZOP_MAGIC_SIZE 9
+#define XZ_MAGIC "\3757zXZ\0"
+#define XZ_MAGIC_SIZE 6
+#define ELF_MAGIC "\177ELF"
+#define ELF_MAGIC_SIZE 4
+#define GZ_MAGIC "\x1F\x8B"
+#define GZ_MAGIC_SIZE 2
+#define GZ_OLD_MAGIC "\x1F\x9E"
+#define GZ_OLD_MAGIC_SIZE 2
+
+#ifndef GRUB_UTIL
+
+#include <grub/dl.h>
+
+static grub_uint8_t
+mod_31 (grub_uint16_t v)
+{
+  /* At most 2 iterations for any number that
+     we can get here.
+     In any case faster than real division.  */
+  while (v > 0x1f)
+    v = (v & 0x1f) + (v >> 5);
+  if (v == 0x1f)
+    return 0;
+  return v;
+}
+
+static int
+is_zlib (grub_uint8_t *head)
+{
+  grub_uint8_t cmf, flg;
+ 
+  cmf = head[0];
+  flg = head[1];
+
+  if ((cmf & 0xf) != 8)
+    return 0;
+
+  if (mod_31 (cmf + flg * 4) != 0)
+    return 0;
+
+  if (flg & 0x20)
+    return 0;
+  
+  return 1;
+}
+
+static void
+autoload_filters (grub_file_t file, grub_uint32_t payload_offset)
+{
+  grub_uint8_t payload_header[LZOP_MAGIC_SIZE];
+
+  grub_file_seek (file, payload_offset);
+
+  if (grub_file_read (file, &payload_header, sizeof (payload_header)) != sizeof (payload_header))
+    {
+      grub_print_error ();
+      return;
+    }
+
+  if (grub_memcmp (payload_header, ELF_MAGIC, ELF_MAGIC_SIZE) == 0)
+    {
+      /* Uncompressed.  */
+    }
+  else if (grub_memcmp (payload_header, XZ_MAGIC, XZ_MAGIC_SIZE) == 0)
+    {
+      grub_dl_load("xzio");
+      grub_print_error ();
+    }
+  else if (grub_memcmp (payload_header, LZOP_MAGIC, LZOP_MAGIC_SIZE) == 0)
+    {
+      grub_dl_load("lzopio");
+      grub_print_error ();
+    }
+  else if (grub_memcmp (payload_header, GZ_MAGIC, GZ_MAGIC_SIZE) == 0
+	   || grub_memcmp (payload_header, GZ_OLD_MAGIC, GZ_OLD_MAGIC_SIZE) == 0
+	   || is_zlib (payload_header))
+    {
+      grub_dl_load("gzio");
+      grub_print_error ();
+    }
+}
+
+#endif
+
 grub_elf_t
 grub_xen_file (grub_file_t file)
 {
   grub_elf_t elf;
   struct linux_kernel_header lh;
   grub_file_t off_file;
+  grub_uint32_t payload_offset;
 
   elf = grub_elf_file (file, file->name);
   if (elf)
@@ -46,19 +133,24 @@ grub_xen_file (grub_file_t file)
       return NULL;
     }
 
-  if (lh.payload_length < 4)
+  if (lh.payload_length < LZOP_MAGIC_SIZE)
     {
       grub_error (GRUB_ERR_BAD_OS, "payload too short");
       return NULL;
     }
 
+  payload_offset = (lh.setup_sects + 1) * 512 + lh.payload_offset;
+
+#ifndef GRUB_UTIL
+  autoload_filters (file, payload_offset);
+#endif
+
   grub_dprintf ("xen", "found bzimage payload 0x%llx-0x%llx\n",
 		(unsigned long long) (lh.setup_sects + 1) * 512
 		+ lh.payload_offset,
 		(unsigned long long) lh.payload_length - 4);
 
-  off_file = grub_file_offset_open (file, (lh.setup_sects + 1) * 512
-				    + lh.payload_offset,
+  off_file = grub_file_offset_open (file, payload_offset,
 				    lh.payload_length - 4);
   if (!off_file)
     goto fail;