main/s390-tools: fix creating merged image post linux-lts update to 6.6

Linux kernels post 6.1 go beyond the 8MB offset which has been hardcoded
in many alternative implementations of IBM's s390-tools's mk-s390image.

This is a known issue from over at Fedora: https://bugzilla.redhat.com/show_bug.cgi?id=1891778

I tried switching over to the official script, and amend it to set
the correct LPSW, but that image caused the following kernel panic:

```
KASLR disabled: CPU has no PRNG
KASLR disabled: CPU has no PRNG
[    1.863539] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(1,0)
[    1.864887] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.6.43-0-lts #1-Alpine
[    1.865167] Hardware name: QEMU 8561 QEMU (KVM/Linux)
[    1.865346] Call Trace:
[    1.865437]  [<0000000000b46892>] dump_stack_lvl+0x62/0x88
[    1.865944]  [<000000000018d6c8>] panic+0x320/0x338
[    1.866000]  [<00000000014401d6>] mount_root_generic+0x20e/0x4a0
[    1.866045]  [<000000000144090c>] prepare_namespace+0xc4/0x3f8
[    1.866084]  [<000000000143f23a>] kernel_init_freeable+0x5ba/0x698
[    1.866142]  [<0000000000b73026>] kernel_init+0x2e/0x1f0
[    1.866191]  [<00000000001034a4>] __ret_from_fork+0x3c/0x50
[    1.866232]  [<0000000000b885da>] ret_from_fork+0xa/0x30
```

The approach taken here is to just preserve the fixed offset if the
compressed kernel image is < 8MB, and adjust it otherwise. A future
FIXME would be to migrate to the official script altogether and
investigate why the image it produces is invalid.

Fixes #16310
This commit is contained in:
L. E. Segovia 2024-08-04 01:20:45 +00:00 committed by Natanael Copa
parent 8d0d8b86ef
commit 391cc3a191
3 changed files with 97 additions and 3 deletions

View file

@ -0,0 +1,85 @@
From 45007a0525eb10a15003550a91cacc2f6e878765 Mon Sep 17 00:00:00 2001
From: "L. E. Segovia" <amy@amyspark.me>
Date: Sun, 4 Aug 2024 14:04:23 -0300
Subject: [PATCH] tools: Fix compilation with musl and gcc 14
lscss.c: In function 'is_sch_vfio':
lscss.c:392:20: error: implicit declaration of function 'basename' [-Wimplicit-function-declaration]
392 | if (strcmp(basename(driver_path), "vfio_ccw") == 0)
device.c: In function 'device_read_active_attrib':
device.c:426:45: error: implicit declaration of function 'basename'; did you mean 'rename'? [-Wimplicit-function-declaration]
426 | value = misc_strdup(basename(link));
| ^~~~~~~~
| rename
---
zconf/css/lscss.c | 1 +
zdev/src/ccw.c | 1 +
zdev/src/ccwgroup.c | 1 +
zdev/src/device.c | 1 +
zdev/src/generic_ccw.c | 1 +
5 files changed, 5 insertions(+)
diff --git a/zconf/css/lscss.c b/zconf/css/lscss.c
index fd58bb3..e75b2b2 100644
--- a/zconf/css/lscss.c
+++ b/zconf/css/lscss.c
@@ -9,6 +9,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <libgen.h>
#include "lib/ccw.h"
#include "lib/util_base.h"
diff --git a/zdev/src/ccw.c b/zdev/src/ccw.c
index e8c40f9..3507049 100644
--- a/zdev/src/ccw.c
+++ b/zdev/src/ccw.c
@@ -8,6 +8,7 @@
*/
#include <inttypes.h>
+#include <libgen.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/zdev/src/ccwgroup.c b/zdev/src/ccwgroup.c
index 61e12cc..6a35d6c 100644
--- a/zdev/src/ccwgroup.c
+++ b/zdev/src/ccwgroup.c
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <libgen.h>
#include "lib/util_base.h"
#include "lib/util_path.h"
diff --git a/zdev/src/device.c b/zdev/src/device.c
index 61647df..63767b6 100644
--- a/zdev/src/device.c
+++ b/zdev/src/device.c
@@ -11,6 +11,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <libgen.h>
#include "lib/util_path.h"
diff --git a/zdev/src/generic_ccw.c b/zdev/src/generic_ccw.c
index c7f144a..637ccfc 100644
--- a/zdev/src/generic_ccw.c
+++ b/zdev/src/generic_ccw.c
@@ -8,6 +8,7 @@
*/
#include <string.h>
+#include <libgen.h>
#include "lib/util_path.h"
--
2.45.2

View file

@ -2,7 +2,7 @@
# Maintainer: Tuan Hoang <tmhoang@linux.ibm.com>
pkgname=s390-tools
pkgver=2.23.0
pkgrel=2
pkgrel=3
pkgdesc="Tools for use with the s390 Linux kernel and device drivers"
url="https://github.com/ibm-s390-tools/s390-tools"
arch="s390x"
@ -20,6 +20,7 @@ source="$pkgname-$pkgver.tar.gz::https://github.com/ibm-s390-tools/s390-tools/ar
0007-tunedasd-no-need-error-h.patch
0008-iucvterm-no-nls.patch
0010-musl-s390x-signal-def.patch
0011-tools-Fix-compilation-with-musl-and-gcc-14.patch
0200-dasdinfo-gnu-ext-hack.patch
0300-disable-program-using-gnu-ext.patch
@ -71,6 +72,7 @@ e41548d83d53e4371afcee3601505520506d05b932aeb91f1ca86e589c010fa5d22777d4617c1e25
ecfbba213d2a705e2a5a2697090f659670ca1a12e4568c1de87f17d11d72a1a6c524b23b4db25c0558b4e8239c27afddb94d8887d93170b359d77985018f9b9c 0007-tunedasd-no-need-error-h.patch
bdbeb6f3873ede82487c7e4fcac84aa2bf8a922991ec32d029a64cd7142625f5a99920db0f1b6935805d7371ae5a7640c5ea577969937dd96c4f4f996b909ac3 0008-iucvterm-no-nls.patch
f785a899583de8592422e5e46c4e4893196e3c7885e4a0bb4c717c3587db8c1a4c264c80337b1d0c31b39150f3c3b71b876fe156086ace3a542c12678ae7c85e 0010-musl-s390x-signal-def.patch
f9cbf044e3a69bd170e1cd12c13414f7c8ded76fee24459a3a2b3a74c8e8703eeff6449789698e0e17f40f437e12b30e495c31fa1ad8a42129fadb98b7509c71 0011-tools-Fix-compilation-with-musl-and-gcc-14.patch
f5e06e28f77c44f591d74f383ce308a6bfb129b00b291601f2be8866dd1382c597348794be2109c9dc0fa8fdbbee509d036fa6c215e73c4c99f476d3c1cb5a83 0200-dasdinfo-gnu-ext-hack.patch
89ca081aabb5d0f8868ce171cf27265f127585dc57f9950b3ee24d31c1a9a0c25026da77724dc96be8d579768625fee9b2b1214647355dffb49e338dfce18092 0300-disable-program-using-gnu-ext.patch
6d07d0c1f380da42f092038a1434dc1934dead821d6f7c3f8a9e2e85c38e477cf2e34a98d33ac515b67bb0202ca5a469c059d59678c19d9e9bd01456518608e1 0400-busybox-compat.patch
@ -85,5 +87,5 @@ ab1bc0273fdd529fe4dcf20d3d8760d30702d670bbef1f173951d12fe2a62344c8b81209296c103c
2e573314d4c4ed90b61da28de22ae8e2f68ced5489f7e5e0b30f51b776efaf40c1f781d3b485418572d8f33a169fa6946b7358cbd4a7de5a3724b20ed622262b argz.c
50bd5c0f555963dadbfaa72df5bf0801a48743d6d0feddb6ebfa4ffa410196216c1860d3a577361e035169fea4217aef3f04d69394c59db65b60c5ea29eba8cb argz.h
5e19ccfce59a2a79863db676b0ea4280cb9016cda1a30dc233526f52425c305410dd148453b75c2613acac37e364305ee25f8e545d57c5059cca19a13bac2a5e Makefile.argz
349eb06895016d16194819c4a04f604720f1373ea61a9bc4c58467281c9a2ed3539bd4e8b6984f4e5177630dbe8b928aa95912c9a3e3b0e1fe275d59f9fe573d mk-s390-cdboot.c
41b581d2b9cc061964aa2d5ff022de89399b7e377afef2d2fd46414a63a338fd4897e8bb1e06ca4f5fe33c9addedc8934f07980899bcd5291823de093e1b8af9 mk-s390-cdboot.c
"

View file

@ -145,8 +145,15 @@ int main (int argc, char **argv) {
}
}
const off_t real_initrd_start = ftello(fd1);
printf("writing initrd...\n");
fseek(fd1, initrd_start, SEEK_SET);
if (real_initrd_start < initrd_start) {
fseek(fd1, initrd_start, SEEK_SET);
} else {
initrd_start = real_initrd_start;
}
while (1) {
rc = fread(buffer, 1, 1, fd3);