From: Jan Kiszka <jan.kis...@siemens.com>

These are essential in order to use the larger root kernel also for the
non-root cell.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>
---
 ...linux-Use-minimal-decompression-space-for.patch | 58 +++++++++++++
 ...linux-Make-kernel-decompression-factor-co.patch | 82 ++++++++++++++++++
 ...linux-Tune-x86-decompression-factor-based.patch | 99 ++++++++++++++++++++++
 recipes-jailhouse/jailhouse/jailhouse_0.8.bb       |  5 ++
 4 files changed, 244 insertions(+)
 create mode 100644 
recipes-jailhouse/jailhouse/files/0001-tools-cell-linux-Use-minimal-decompression-space-for.patch
 create mode 100644 
recipes-jailhouse/jailhouse/files/0002-tools-cell-linux-Make-kernel-decompression-factor-co.patch
 create mode 100644 
recipes-jailhouse/jailhouse/files/0003-tools-cell-linux-Tune-x86-decompression-factor-based.patch

diff --git 
a/recipes-jailhouse/jailhouse/files/0001-tools-cell-linux-Use-minimal-decompression-space-for.patch
 
b/recipes-jailhouse/jailhouse/files/0001-tools-cell-linux-Use-minimal-decompression-space-for.patch
new file mode 100644
index 0000000..4c6ccf8
--- /dev/null
+++ 
b/recipes-jailhouse/jailhouse/files/0001-tools-cell-linux-Use-minimal-decompression-space-for.patch
@@ -0,0 +1,58 @@
+From 0d69f78fb52b66df49c24935d4218c7c8c1f6e7b Mon Sep 17 00:00:00 2001
+From: Jan Kiszka <jan.kis...@siemens.com>
+Date: Sun, 7 Jan 2018 08:43:22 +0100
+Subject: [PATCH 1/4] tools: cell-linux: Use minimal decompression space for
+ ARM64
+
+Factor out a default decompression factor for ARM because ARM64 does not
+perform any compression so far, thus has a factor of 1 only. This allows
+for more compact non-root Linux cell layout during load.
+
+Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>
+Reviewed-by: Lokesh Vutla <lokeshvu...@ti.com>
+---
+ tools/jailhouse-cell-linux | 14 ++++++++++++--
+ 1 file changed, 12 insertions(+), 2 deletions(-)
+
+diff --git a/tools/jailhouse-cell-linux b/tools/jailhouse-cell-linux
+index 086d5982..d27951b7 100755
+--- a/tools/jailhouse-cell-linux
++++ b/tools/jailhouse-cell-linux
+@@ -310,8 +310,10 @@ class ARMCommon:
+         if args.initrd:
+             ramdisk_size = page_align(os.fstat(args.initrd.fileno()).st_size)
+             # leave sufficient space between the kernel and the initrd
+-            image_size += kernel_size * 4
+-            kernel_size *= 5
++            decompression_factor = self.default_decompression_factor()
++            decompression_space = decompression_factor * kernel_size
++            kernel_size += decompression_space
++            image_size += decompression_space
+ 
+         if not args.dtb:
+             print('No device tree specified', file=sys.stderr)
+@@ -425,6 +427,10 @@ class ARM(ARMCommon):
+     def get_kernel_offset(kernel):
+         return 0
+ 
++    @staticmethod
++    def default_decompression_factor():
++        return 4
++
+ 
+ class ARM64(ARMCommon):
+     name = 'arm64'
+@@ -442,6 +448,10 @@ class ARM64(ARMCommon):
+         (text_offset,) = struct.unpack_from('<Q', kernel.read(8))
+         return text_offset
+ 
++    @staticmethod
++    def default_decompression_factor():
++        return 1
++
+ 
+ def resolve_arch(defined_arch=None):
+     arch_classes = {'x86': X86, 'arm': ARM, 'arm64': ARM64, None: None}
+-- 
+2.13.6
+
diff --git 
a/recipes-jailhouse/jailhouse/files/0002-tools-cell-linux-Make-kernel-decompression-factor-co.patch
 
b/recipes-jailhouse/jailhouse/files/0002-tools-cell-linux-Make-kernel-decompression-factor-co.patch
new file mode 100644
index 0000000..9f62062
--- /dev/null
+++ 
b/recipes-jailhouse/jailhouse/files/0002-tools-cell-linux-Make-kernel-decompression-factor-co.patch
@@ -0,0 +1,82 @@
+From 858aa5c6a6c02cc63318e20282011bccc7e9a352 Mon Sep 17 00:00:00 2001
+From: Jan Kiszka <jan.kis...@siemens.com>
+Date: Sun, 7 Jan 2018 08:45:22 +0100
+Subject: [PATCH 2/4] tools: cell-linux: Make kernel decompression factor
+ configurable
+
+The required factor depends on the chosen compression method, and that
+may vary. Have a large factor to account for aggressive compressions
+(and increased memory needs during decompression) will work - as long as
+there is enough memory assigned to the cell. Using a smaller default
+will address this but break if the user chooses a better compression
+method.
+
+Let's make this factor configurable in order to give the user some
+control in case our default should not work.
+
+Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>
+Reviewed-by: Lokesh Vutla <lokeshvu...@ti.com>
+---
+ tools/jailhouse-cell-linux | 17 ++++++++++++++---
+ 1 file changed, 14 insertions(+), 3 deletions(-)
+
+diff --git a/tools/jailhouse-cell-linux b/tools/jailhouse-cell-linux
+index d27951b7..cf9225b2 100755
+--- a/tools/jailhouse-cell-linux
++++ b/tools/jailhouse-cell-linux
+@@ -248,7 +248,8 @@ class X86:
+     def setup(self, args, config):
+         self._cpu_reset_address = config.cpu_reset_address
+ 
+-        self._zero_page = X86ZeroPage(args.kernel, args.initrd, config)
++        self._zero_page = X86ZeroPage(args.kernel, args.initrd,
++                                      args.kernel_decomp_factor, config)
+ 
+         setup_data = x86_gen_setup_data(config)
+ 
+@@ -311,6 +312,8 @@ class ARMCommon:
+             ramdisk_size = page_align(os.fstat(args.initrd.fileno()).st_size)
+             # leave sufficient space between the kernel and the initrd
+             decompression_factor = self.default_decompression_factor()
++            if args.kernel_decomp_factor:
++                decompression_factor = args.kernel_decomp_factor
+             decompression_space = decompression_factor * kernel_size
+             kernel_size += decompression_space
+             image_size += decompression_space
+@@ -649,7 +652,7 @@ class X86SetupHeader:
+ 
+ # see linux/Documentation/x86/zero-page.txt
+ class X86ZeroPage:
+-    def __init__(self, kernel, initrd, config):
++    def __init__(self, kernel, initrd, kernel_decomp_factor, config):
+         self.setup_header = X86SetupHeader(kernel)
+ 
+         prot_image_offs = (self.setup_header.setup_sects + 1) * 512
+@@ -667,8 +670,12 @@ class X86ZeroPage:
+             kernel_size = os.fstat(kernel.fileno()).st_size
+             ramdisk_size = os.fstat(initrd.fileno()).st_size
+             # same as arm, magic factor 10 works generally fine
++            decompression_factor = 10
++            if kernel_decomp_factor:
++                decompression_factor = kernel_decomp_factor
++            decompression_space = decompression_factor * kernel_size
+             ramdisk_load_addr = page_align(self.kernel_load_addr +
+-                                           10 * kernel_size)
++                                           decompression_space)
+ 
+         self.setup_header.set_ramdisk_image(ramdisk_load_addr)
+         self.setup_header.set_ramdisk_size(ramdisk_size)
+@@ -765,6 +772,10 @@ parser.add_argument('--write-params', '-w', 
metavar='FILE',
+                          'to the console')
+ parser.add_argument('--arch', '-a', metavar='ARCH',
+                     help='target architecture')
++parser.add_argument('--kernel-decomp-factor', '-k', metavar='N',
++                    type=int,
++                    help='decompression factor of the kernel image, used to '
++                         'reserve space between the kernel and the initramfs')
+ 
+ try:
+     args = parser.parse_args()
+-- 
+2.13.6
+
diff --git 
a/recipes-jailhouse/jailhouse/files/0003-tools-cell-linux-Tune-x86-decompression-factor-based.patch
 
b/recipes-jailhouse/jailhouse/files/0003-tools-cell-linux-Tune-x86-decompression-factor-based.patch
new file mode 100644
index 0000000..a44d51f
--- /dev/null
+++ 
b/recipes-jailhouse/jailhouse/files/0003-tools-cell-linux-Tune-x86-decompression-factor-based.patch
@@ -0,0 +1,99 @@
+From d0257b07736ebd41df368d9d19fef9b70586218f Mon Sep 17 00:00:00 2001
+From: Jan Kiszka <jan.kis...@siemens.com>
+Date: Sun, 7 Jan 2018 11:30:35 +0100
+Subject: [PATCH 3/4] tools: cell-linux: Tune x86 decompression factor based on
+ compression method
+
+On x86, we can find out which compression method was used. So we are
+able to tune the decompression factor automatically according to this.
+
+Unfortunately, the ARM 32-bit kernel does not expose the payload address
+and, thus, does not allow to apply the same approach.
+
+Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>
+---
+ tools/jailhouse-cell-linux | 44 +++++++++++++++++++++++++++++++++++++++++---
+ 1 file changed, 41 insertions(+), 3 deletions(-)
+
+diff --git a/tools/jailhouse-cell-linux b/tools/jailhouse-cell-linux
+index cf9225b2..6ec18bfc 100755
+--- a/tools/jailhouse-cell-linux
++++ b/tools/jailhouse-cell-linux
+@@ -592,7 +592,7 @@ class Config:
+ # see linux/Documentation/x86/boot.txt
+ class X86SetupHeader:
+     BASE_OFFSET = 0x1f0
+-    _HEADER_FORMAT = 'xB2xI8xH14xB7xII8xI4xI28xQQ'
++    _HEADER_FORMAT = 'xB2xI8xH14xB7xII8xI4xI20xI4xQQ'
+ 
+     def __init__(self, kernel):
+         kernel.seek(X86SetupHeader.BASE_OFFSET)
+@@ -605,6 +605,7 @@ class X86SetupHeader:
+          self.ramdisk_size,
+          self.cmd_line_ptr,
+          self.kernel_alignment,
++         self.payload_offset,
+          self.setup_data,
+          self.pref_address) = \
+             struct.unpack(X86SetupHeader._HEADER_FORMAT,
+@@ -650,6 +651,26 @@ class X86SetupHeader:
+         return self.data
+ 
+ 
++def get_kernel_compression_method(payload_magic):
++    if payload_magic[0] == 0x1f and payload_magic[1] in (0x8b, 0x9e):
++        return 'gzip'
++    elif payload_magic[0] == 0x42 and payload_magic[1] == 0x5a:
++        return 'bzip2'
++    elif payload_magic[0] == 0x5d and payload_magic[1] == 0x0:
++        return 'lzma'
++    elif payload_magic[0] == 0xfd and payload_magic[1] == 0x37:
++        return 'xz'
++    elif payload_magic[0] == 0x02 and payload_magic[1] == 0x21:
++        return 'lz4'
++    elif payload_magic[0] == 0x89 and payload_magic[1] == 0x4c:
++        return 'lzo'
++    elif payload_magic[0] == 0x7f and payload_magic[1] == 0x45 and \
++            payload_magic[2] == 0x4c and payload_magic[3] == 0x46:
++        return 'uncompressed'
++    else:
++        return 'unknown'
++
++
+ # see linux/Documentation/x86/zero-page.txt
+ class X86ZeroPage:
+     def __init__(self, kernel, initrd, kernel_decomp_factor, config):
+@@ -669,11 +690,28 @@ class X86ZeroPage:
+         if initrd:
+             kernel_size = os.fstat(kernel.fileno()).st_size
+             ramdisk_size = os.fstat(initrd.fileno()).st_size
+-            # same as arm, magic factor 10 works generally fine
+-            decompression_factor = 10
++
++            kernel.seek(prot_image_offs + self.setup_header.payload_offset)
++            payload_magic = bytearray(kernel.read(4))
++            compression_method = get_kernel_compression_method(payload_magic)
++
++            # Unless specified, derive decompression factor from method
+             if kernel_decomp_factor:
+                 decompression_factor = kernel_decomp_factor
++            elif compression_method in ('bzip2'):
++                # "Bzip2 uses a large amount of memory."
++                # And that causes a larger binary, thus a smaller factor.
++                decompression_factor = 4
++            elif compression_method in ('lz4', 'lzo'):
++                decompression_factor = 6
++            elif compression_method in ('gzip'):
++                decompression_factor = 7
++            elif compression_method in ('lzma'):
++                decompression_factor = 8
++            else:  # xz or unknown
++                decompression_factor = 9
+             decompression_space = decompression_factor * kernel_size
++
+             ramdisk_load_addr = page_align(self.kernel_load_addr +
+                                            decompression_space)
+ 
+-- 
+2.13.6
+
diff --git a/recipes-jailhouse/jailhouse/jailhouse_0.8.bb 
b/recipes-jailhouse/jailhouse/jailhouse_0.8.bb
index 2b91288..652f034 100644
--- a/recipes-jailhouse/jailhouse/jailhouse_0.8.bb
+++ b/recipes-jailhouse/jailhouse/jailhouse_0.8.bb
@@ -11,4 +11,9 @@
 
 require jailhouse.inc
 
+SRC_URI += " \
+    file://0001-tools-cell-linux-Use-minimal-decompression-space-for.patch \
+    file://0002-tools-cell-linux-Make-kernel-decompression-factor-co.patch \
+    file://0003-tools-cell-linux-Tune-x86-decompression-factor-based.patch"
+
 SRCREV = "07341fa315a7fabb38f07cd3c0b3fe880cffaa65"
-- 
2.13.6

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jailhouse-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to