s390x/ipl: support extended kernel command line size
PATCH 1/1 s390x/ipl: support extended kernel command line size
In the past s390 used a fixed command line length of 896 bytes. This has changed with the Linux commit 5ecb2da660ab ("s390: support command lines longer than 896 bytes"). There is now a parm area indicating the maximum command line size. This parm area has always been initialized to zero, so with older kernels this field would read zero and we must then assume that only 896 bytes are available.
--- hw/s390x/ipl.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
hw/s390x/ipl.c +20 -3
@@ -37,8 +37,9 @@#define KERN_IMAGE_START 0x010000UL#define LINUX_MAGIC_ADDR 0x010008UL +#define KERN_PARM_AREA_SIZE_ADDR 0x010430UL#define KERN_PARM_AREA 0x010480UL -#define KERN_PARM_AREA_SIZE 0x000380UL +#define LEGACY_KERN_PARM_AREA_SIZE 0x000380UL#define INITRD_START 0x800000UL#define INITRD_PARM_START 0x010408UL#define PARMFILE_START 0x001000UL
@@ -110,6 +111,21 @@ static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr)return srcaddr + dstaddr; } +static uint64_t get_max_kernel_cmdline_size (void ) +{ +uint64_t *size_ptr =rom_ptr (KERN_PARM_AREA_SIZE_ADDR ,sizeof (*size_ptr)); + +if (size_ptr) { +uint64_t size; + + size =be64_to_cpu (*size_ptr); +if (size !=0 ) { +return size; + } + } +return LEGACY_KERN_PARM_AREA_SIZE ; +} +static void s390_ipl_realize (DeviceState *dev,Error **errp) {MachineState *ms =MACHINE (qdev_get_machine ());
@@ -197,10 +213,11 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp) ipl->start_addr =KERN_IMAGE_START ;/* Overwrite parameters in the kernel image, which are "rom" */ if (parm_area) { -if (cmdline_size >KERN_PARM_AREA_SIZE ) { +uint64_t max_cmdline_size =get_max_kernel_cmdline_size (); +if (cmdline_size > max_cmdline_size) {error_setg (errp,"kernel command line exceeds maximum size: %zu > %lu" , - cmdline_size,KERN_PARM_AREA_SIZE ); + cmdline_size, max_cmdline_size);return ; }
Signature · 1 line
2.31.1
Quoted 30 lines · Marc Hartmayer
In the past s390 used a fixed command line length of 896 bytes. This has changed with the Linux commit
5ecb2da660ab("s390: support command lines longer than 896 bytes"). There is now a parm area indicating the maximum command line size. This parm area has always been initialized to zero, so with older kernels this field would read zero and we must then assume that only 896 bytes are available.Signed-off-by Marc Hartmayer <[email protected]>--- hw/s390x/ipl.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)hw/s390x/ipl.c +2
-1@@ -37,8 +37,9 @@#define KERN_IMAGE_START 0x010000UL#define LINUX_MAGIC_ADDR 0x010008UL +#define KERN_PARM_AREA_SIZE_ADDR 0x010430UL#define KERN_PARM_AREA 0x010480UL -#define KERN_PARM_AREA_SIZE 0x000380UL +#define LEGACY_KERN_PARM_AREA_SIZE 0x000380UL#define INITRD_START 0x800000UL#define INITRD_PARM_START 0x010408UL#define PARMFILE_START 0x001000UL@@ -110,6 +111,21 @@ static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr)return srcaddr + dstaddr; }
hw/s390x/ipl.c static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr) · line 122
Quoted 10 lines
hw/s390x/ipl.c +9
-0+static uint64_t get_max_kernel_cmdline_size (void ) +{ +uint64_t *size_ptr =rom_ptr (KERN_PARM_AREA_SIZE_ADDR ,sizeof (*size_ptr)); + +if (size_ptr) { +uint64_t size; + + size =be64_to_cpu (*size_ptr); +if (size !=0 ) {
Could do "if (size) {"
Quoted 10 lines
hw/s390x/ipl.c +6
-0+return size; + } + } +return LEGACY_KERN_PARM_AREA_SIZE ; +} +static void s390_ipl_realize (DeviceState *dev,Error **errp) {MachineState *ms =MACHINE (qdev_get_machine ());
hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 216
Quoted 5 lines
hw/s390x/ipl.c +1
-1@@ -197,10 +213,11 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp) ipl->start_addr =KERN_IMAGE_START ;/* Overwrite parameters in the kernel image, which are "rom" */ if (parm_area) { -if (cmdline_size >KERN_PARM_AREA_SIZE ) { +uint64_t max_cmdline_size =get_max_kernel_cmdline_size ();
We might want an empty line here.
hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 223
Quoted 9 lines
hw/s390x/ipl.c +2
-1+if (cmdline_size > max_cmdline_size) {error_setg (errp,"kernel command line exceeds maximum size: %zu > %lu" , - cmdline_size,KERN_PARM_AREA_SIZE ); + cmdline_size, max_cmdline_size);return ; }
Signature · 3 lines
Thanks, David / dhildenb
Quoted 32 lines · David Hildenbrand
Quoted 31 lines · Marc Hartmayer
In the past s390 used a fixed command line length of 896 bytes. This has changed with the Linux commit
5ecb2da660ab("s390: support command lines longer than 896 bytes"). There is now a parm area indicating the maximum command line size. This parm area has always been initialized to zero, so with older kernels this field would read zero and we must then assume that only 896 bytes are available.Signed-off-by Marc Hartmayer <[email protected]>--- hw/s390x/ipl.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)hw/s390x/ipl.c +2
-1@@ -37,8 +37,9 @@#define KERN_IMAGE_START 0x010000UL#define LINUX_MAGIC_ADDR 0x010008UL +#define KERN_PARM_AREA_SIZE_ADDR 0x010430UL#define KERN_PARM_AREA 0x010480UL -#define KERN_PARM_AREA_SIZE 0x000380UL +#define LEGACY_KERN_PARM_AREA_SIZE 0x000380UL#define INITRD_START 0x800000UL#define INITRD_PARM_START 0x010408UL#define PARMFILE_START 0x001000UL@@ -110,6 +111,21 @@ static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr)return srcaddr + dstaddr; }
Quoted 11 lines
hw/s390x/ipl.c static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr) · line 122
Quoted 9 lines
hw/s390x/ipl.c +9
-0+static uint64_t get_max_kernel_cmdline_size (void ) +{ +uint64_t *size_ptr =rom_ptr (KERN_PARM_AREA_SIZE_ADDR ,sizeof (*size_ptr)); + +if (size_ptr) { +uint64_t size; + + size =be64_to_cpu (*size_ptr); +if (size !=0 ) {Could do "if (size) {"
Ok.
Quoted 10 lines
Quoted 10 lines
hw/s390x/ipl.c +6
-0+return size; + } + } +return LEGACY_KERN_PARM_AREA_SIZE ; +} +static void s390_ipl_realize (DeviceState *dev,Error **errp) {MachineState *ms =MACHINE (qdev_get_machine ());
Quoted 8 lines
hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 216
Quoted 6 lines
hw/s390x/ipl.c +1
-1@@ -197,10 +213,11 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp) ipl->start_addr =KERN_IMAGE_START ;/* Overwrite parameters in the kernel image, which are "rom" */ if (parm_area) { -if (cmdline_size >KERN_PARM_AREA_SIZE ) { +uint64_t max_cmdline_size =get_max_kernel_cmdline_size ();We might want an empty line here.
Yep.
Quoted 11 lines
hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 223
Quoted 10 lines
hw/s390x/ipl.c +2
-1+if (cmdline_size > max_cmdline_size) {error_setg (errp,"kernel command line exceeds maximum size: %zu > %lu" , - cmdline_size,KERN_PARM_AREA_SIZE ); + cmdline_size, max_cmdline_size);return ; }
Quoted 1 line
Reviewed-by David Hildenbrand <[email protected]>
Thanks for the review!
Quoted 6 lines
Signature · 4 lines
-- Thanks, David / dhildenb
Signature · 8 lines
Kind regards / Beste Grüße Marc Hartmayer IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Gregor Pillen Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
Am 22.11.21 um 12:29 schrieb Marc Hartmayer:
Quoted 8 lines
In the past s390 used a fixed command line length of 896 bytes. This has changed with the Linux commit
5ecb2da660ab("s390: support command lines longer than 896 bytes"). There is now a parm area indicating the maximum command line size. This parm area has always been initialized to zero, so with older kernels this field would read zero and we must then assume that only 896 bytes are available.Signed-off-by Marc Hartmayer <[email protected]>
Quoted 56 lines
--- hw/s390x/ipl.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)hw/s390x/ipl.c +20
-3@@ -37,8 +37,9 @@#define KERN_IMAGE_START 0x010000UL#define LINUX_MAGIC_ADDR 0x010008UL +#define KERN_PARM_AREA_SIZE_ADDR 0x010430UL#define KERN_PARM_AREA 0x010480UL -#define KERN_PARM_AREA_SIZE 0x000380UL +#define LEGACY_KERN_PARM_AREA_SIZE 0x000380UL#define INITRD_START 0x800000UL#define INITRD_PARM_START 0x010408UL#define PARMFILE_START 0x001000UL@@ -110,6 +111,21 @@ static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr)return srcaddr + dstaddr; } +static uint64_t get_max_kernel_cmdline_size (void ) +{ +uint64_t *size_ptr =rom_ptr (KERN_PARM_AREA_SIZE_ADDR ,sizeof (*size_ptr)); + +if (size_ptr) { +uint64_t size; + + size =be64_to_cpu (*size_ptr); +if (size !=0 ) { +return size; + } + } +return LEGACY_KERN_PARM_AREA_SIZE ; +} +static void s390_ipl_realize (DeviceState *dev,Error **errp) {MachineState *ms =MACHINE (qdev_get_machine ());@@ -197,10 +213,11 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp) ipl->start_addr =KERN_IMAGE_START ;/* Overwrite parameters in the kernel image, which are "rom" */ if (parm_area) { -if (cmdline_size >KERN_PARM_AREA_SIZE ) { +uint64_t max_cmdline_size =get_max_kernel_cmdline_size (); +if (cmdline_size > max_cmdline_size) {error_setg (errp,"kernel command line exceeds maximum size: %zu > %lu" , - cmdline_size,KERN_PARM_AREA_SIZE ); + cmdline_size, max_cmdline_size);return ; }
Quoted 50 lines · Marc Hartmayer
In the past s390 used a fixed command line length of 896 bytes. This has changed with the Linux commit
5ecb2da660ab("s390: support command lines longer than 896 bytes"). There is now a parm area indicating the maximum command line size. This parm area has always been initialized to zero, so with older kernels this field would read zero and we must then assume that only 896 bytes are available.Signed-off-by Marc Hartmayer <[email protected]>--- hw/s390x/ipl.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)hw/s390x/ipl.c +17
-1@@ -37,8 +37,9 @@#define KERN_IMAGE_START 0x010000UL#define LINUX_MAGIC_ADDR 0x010008UL +#define KERN_PARM_AREA_SIZE_ADDR 0x010430UL#define KERN_PARM_AREA 0x010480UL -#define KERN_PARM_AREA_SIZE 0x000380UL +#define LEGACY_KERN_PARM_AREA_SIZE 0x000380UL#define INITRD_START 0x800000UL#define INITRD_PARM_START 0x010408UL#define PARMFILE_START 0x001000UL@@ -110,6 +111,21 @@ static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr)return srcaddr + dstaddr; } +static uint64_t get_max_kernel_cmdline_size (void ) +{ +uint64_t *size_ptr =rom_ptr (KERN_PARM_AREA_SIZE_ADDR ,sizeof (*size_ptr)); + +if (size_ptr) { +uint64_t size; + + size =be64_to_cpu (*size_ptr); +if (size !=0 ) { +return size; + } + } +return LEGACY_KERN_PARM_AREA_SIZE ; +} +static void s390_ipl_realize (DeviceState *dev,Error **errp) {MachineState *ms =MACHINE (qdev_get_machine ());
hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 219
Quoted 8 lines
hw/s390x/ipl.c +2
-1@@ -197,10 +213,11 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp) ipl->start_addr =KERN_IMAGE_START ;/* Overwrite parameters in the kernel image, which are "rom" */ if (parm_area) { -if (cmdline_size >KERN_PARM_AREA_SIZE ) { +uint64_t max_cmdline_size =get_max_kernel_cmdline_size (); +if (cmdline_size > max_cmdline_size) { error_setg(errp, "kernel command line exceeds maximum size: %zu > %lu",
I think the %lu likely needs to be turned into a PRIu64 now ... could you please try compiling on a 32-bit host env (e.g. via gitlab-ci), fix the patch accordingly (also with the cosmetics mentioned by David) and send a v2? Thanks!
Thomas
Quoted 4 lines
hw/s390x/ipl.c +1
-1- cmdline_size, KERN_PARM_AREA_SIZE); + cmdline_size, max_cmdline_size);return ; }