s390: add support for extended cmdline length
Subsystems (2)
v3 cover s390: add support for extended cmdline length
Hi,
this patchset adds support for extended command line lengths on s390. The former limit of 896 has been too short in a some configurations. The linux kernel now provides an additional field in the parameter area which contains the maximum allowed command line length. In older kernels this field is zero. In that case the old limit of 896 bytes is used. This was introduced with 5ecb2da660ab ("s390: support command lines longer than 896 bytes") in linux.
And while at it, also add the --reuse-cmdline option and use KEXEC_ALL_OPTIONS.
Changes in v3:
- handle short reads and interruptions in slurp_proc_file()
Changes in v2:
- add slurp_proc_file() to read proc files without knowing the size upfront
- move command_line string from global to function scope
Sven Schnelle (5):
s390: add variable command line size
s390: use KEXEC_ALL_OPTIONS
add slurp_proc_file()
use slurp_proc_file() in get_command_line()
s390: add support for --reuse-cmdline
kexec/arch/s390/crashdump-s390.c | 3 +- kexec/arch/s390/include/arch/options.h | 10 +-- kexec/arch/s390/kexec-image.c | 84 ++++++++++++++++---------- kexec/arch/s390/kexec-s390.h | 21 ++++--- kexec/kexec.c | 77 ++++++++++++++++++----- 5 files changed, 133 insertions(+), 62 deletions(-)
Signature · 7 lines
2.32.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 1/5 s390: add variable command line size
Newer s390 kernels support a command line size longer than 896 bytes. Such kernels contain a new member in the parameter area, which might be utilized by tools like kexec. Older kernels have the location initialized to zero, so we check whether there's a non-zero number present and use that. If there isn't, we fallback to the legacy command line size of 896 bytes.
--- kexec/arch/s390/crashdump-s390.c | 3 +- kexec/arch/s390/kexec-image.c | 65 +++++++++++++++++++++----------- kexec/arch/s390/kexec-s390.h | 21 ++++++----- 3 files changed, 55 insertions(+), 34 deletions(-)
kexec/arch/s390/crashdump-s390.c +2 -1
@@ -52,7 +52,8 @@ static int create_elf_header(struct kexec_info *info, unsigned long crash_base, elfcorehdr_size = bufsz;snprintf (str,sizeof (str)," elfcorehdr=%ld@%ldK\n" , elfcorehdr_size, elfcorehdr /1024 ); -command_line_add (str); +if (command_line_add (info, str)) +return -1 ;#endif return 0 ; }
kexec/arch/s390/kexec-image.c +42 -23
139 lines not on this page · raw message
kexec/arch/s390/kexec-s390.h +11 -10
@@ -10,16 +10,17 @@#ifndef KEXEC_S390_H #define KEXEC_S390_H -#define IMAGE_READ_OFFSET 0x10000 +#define IMAGE_READ_OFFSET 0x10000 -#define RAMDISK_ORIGIN_ADDR 0x800000 -#define INITRD_START_OFFS 0x408 -#define INITRD_SIZE_OFFS 0x410 -#define OLDMEM_BASE_OFFS 0x418 -#define OLDMEM_SIZE_OFFS 0x420 -#define COMMAND_LINE_OFFS 0x480 -#define COMMAND_LINESIZE 896 -#define MAX_MEMORY_RANGES 1024 +#define RAMDISK_ORIGIN_ADDR 0x800000 +#define INITRD_START_OFFS 0x408 +#define INITRD_SIZE_OFFS 0x410 +#define OLDMEM_BASE_OFFS 0x418 +#define OLDMEM_SIZE_OFFS 0x420 +#define MAX_COMMAND_LINESIZE_OFFS 0x430 +#define COMMAND_LINE_OFFS 0x480 +#define LEGACY_COMMAND_LINESIZE 896 +#define MAX_MEMORY_RANGES 1024#define MAX (x, y) ((x) > (y) ? (x) : (y))#define MIN (x, y) ((x) < (y) ? (x) : (y))
@@ -32,6 +33,6 @@ extern int load_crashdump_segments(struct kexec_info *info, unsigned long crash_end);extern int get_memory_ranges_s390 (struct memory_range range[],int *ranges,int with_crashk); -extern int command_line_add (const char *str); +extern int command_line_add (struct kexec_info *info,const char *str);#endif /* KEXEC_S390_H */
Signature · 7 lines
2.32.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 2/5 s390: use KEXEC_ALL_OPTIONS
In reply to Sven SchnelleKEXEC_ALL_OPTIONS could be used instead defining the same array several times. This makes code easier to maintain when new options are added.
--- kexec/arch/s390/kexec-image.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
kexec/arch/s390/kexec-image.c +2 -8
@@ -57,10 +57,7 @@ int image_s390_load_file(int argc, char **argv, struct kexec_info *info)static const struct option options[] = { - KEXEC_OPTIONS - {"command-line" ,1 ,0 ,OPT_APPEND }, - {"append" ,1 ,0 ,OPT_APPEND }, - {"initrd" ,1 ,0 ,OPT_RAMDISK }, + KEXEC_ALL_OPTIONS {0 ,0 ,0 ,0 }, };static const char short_options[] =KEXEC_OPT_STR "" ;
@@ -111,10 +108,7 @@ image_s390_load(int argc, char **argv, const char *kernel_buf,static const struct option options[] = { - KEXEC_OPTIONS - {"command-line" ,1 ,0 ,OPT_APPEND }, - {"append" ,1 ,0 ,OPT_APPEND }, - {"initrd" ,1 ,0 ,OPT_RAMDISK }, + KEXEC_ALL_OPTIONS {0 ,0 ,0 ,0 }, };static const char short_options[] =KEXEC_OPT_STR "" ;
Signature · 7 lines
2.32.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 3/5 add slurp_proc_file()
In reply to Sven Schnelleslurp_file() cannot be used to read proc files, as they are returning a size of zero in stat(). Add a function slurp_proc_file() which is similar to slurp_file(), but doesn't require the size of the file to be known.
--- kexec/kexec.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
kexec/kexec.c +51 -0
@@ -1106,6 +1106,57 @@ static void remove_parameter(char *line, const char *param_name) } } +static ssize_t _read (int fd,void *buf,size_t count) +{ +ssize_t ret, offset =0 ; + +do { + ret =read (fd, buf + offset, count - offset); +if (ret <0 ) { +if ((errno ==EINTR ) || (errno ==EAGAIN )) +continue ; +return ret; + } + offset += ret; + }while (ret && offset < count); + +return offset; +} + +static char *slurp_proc_file (const char *filename,size_t *len) +{ +ssize_t ret, startpos =0 ; +unsigned int size =64 ; +char *buf =NULL , *tmp; +int fd; + + fd =open (filename,O_RDONLY ); +if (fd ==-1 ) +return NULL ; + +do { + size *=2 ; + tmp =realloc (buf, size); +if (!tmp) { +free (buf); +return NULL ; + } + buf = tmp; + + ret =_read (fd, buf + startpos, size - startpos); +if (ret <0 ) { +free (buf); +return NULL ; + } + + startpos += ret; + + }while (ret); + + *len = startpos; +return buf; +} +/* * Returns the contents of the current command line to be used with * --reuse-cmdline option. The function gets called from architecture specific
Signature · 7 lines
2.32.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 4/5 use slurp_proc_file() in get_command_line()
In reply to Sven SchnelleThis way the size of the command line that get_command_line() can handle is no longer fixed.
--- kexec/kexec.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
kexec/kexec.c +10 -16
@@ -1172,25 +1172,19 @@ static char *slurp_proc_file(const char *filename, size_t *len)*/ char *get_command_line (void ) { -FILE *fp; -char *line; -const int sizeof_line =2048 ; - - line =malloc (sizeof_line); -if (line ==NULL ) -die ("Could not allocate memory to read /proc/cmdline." ); - - fp =fopen ("/proc/cmdline" ,"r" ); -if (!fp) -die ("Could not open /proc/cmdline." ); - -if (fgets (line, sizeof_line, fp) ==NULL ) -die ("Can't read /proc/cmdline." ); +char *p, *line; +size_t size; -fclose (fp); + line =slurp_proc_file ("/proc/cmdline" , &size); +if (!line || !size) +die ("Failed to read /proc/cmdline\n" );/* strip newline */ - line[strlen (line) -1 ] ='\0' ; + line[size-1 ] ='\0' ; + + p =strpbrk (line,"\r\n" ); +if (p) + *p ='\0' ;remove_parameter (line,"BOOT_IMAGE" );if (kexec_flags &KEXEC_ON_CRASH )
Signature · 7 lines
2.32.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 5/5 s390: add support for --reuse-cmdline
In reply to Sven Schnelle--reuse-cmdline reads the command line of the currently running kernel from /proc/cmdline and uses that for the kernel that should be kexec'd.
--- kexec/arch/s390/include/arch/options.h | 10 ++++++---- kexec/arch/s390/kexec-image.c | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-)
kexec/arch/s390/include/arch/options.h +6 -4
@@ -1,9 +1,10 @@#ifndef KEXEC_ARCH_S390_OPTIONS_H #define KEXEC_ARCH_S390_OPTIONS_H -#define OPT_ARCH_MAX (OPT_MAX+0) -#define OPT_APPEND OPT_MAX+0 -#define OPT_RAMDISK OPT_MAX+1 +#define OPT_ARCH_MAX (OPT_MAX+0) +#define OPT_APPEND (OPT_MAX+0) +#define OPT_RAMDISK (OPT_MAX+1) +#define OPT_REUSE_CMDLINE (OPT_MAX+2)/* Options relevant to the architecture (excluding loader-specific ones), * in this case none:
@@ -31,7 +32,8 @@KEXEC_ARCH_OPTIONS \ {"command-line", 1, 0, OPT_APPEND}, \ {"append", 1, 0, OPT_APPEND}, \ - {"initrd", 1, 0, OPT_RAMDISK}, + {"initrd", 1, 0, OPT_RAMDISK}, \ + {"reuse-cmdline", 0, 0, OPT_REUSE_CMDLINE }, #define KEXEC_ALL_OPT_STR KEXEC_ARCH_OPT_STR
kexec/arch/s390/kexec-image.c +9 -0
@@ -71,6 +71,10 @@ int image_s390_load_file(int argc, char **argv, struct kexec_info *info)case OPT_RAMDISK : ramdisk = optarg;break ; +case OPT_REUSE_CMDLINE : +free (info->command_line); + info->command_line =get_command_line (); +break ; } }
@@ -123,6 +127,10 @@ image_s390_load(int argc, char **argv, const char *kernel_buf,if (command_line_add (info, optarg))return -1 ;break ; +case OPT_REUSE_CMDLINE : +free (info->command_line); + info->command_line =get_command_line (); +break ;case OPT_RAMDISK : ramdisk = optarg;break ;
@@ -223,5 +231,6 @@ image_s390_usage(void)printf ("--command-line=STRING Set the kernel command line to STRING.\n" "--append=STRING Set the kernel command line to STRING.\n" "--initrd=FILENAME Use the file FILENAME as a ramdisk.\n" +"--reuse-cmdline Use kernel command line from running system.\n" ); }
Signature · 7 lines
2.32.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Simon Horman
Appliedv3 cover s390: add support for extended cmdline length
In reply to Sven SchnelleQuoted 13 lines · Sven Schnelle
Hi,
this patchset adds support for extended command line lengths on s390. The former limit of 896 has been too short in a some configurations. The linux kernel now provides an additional field in the parameter area which contains the maximum allowed command line length. In older kernels this field is zero. In that case the old limit of 896 bytes is used. This was introduced with
5ecb2da660ab("s390: support command lines longer than 896 bytes") in linux.And while at it, also add the --reuse-cmdline option and use
KEXEC_ALL_OPTIONS.
Quoted 7 lines
Changes in v3:
- handle short reads and interruptions inslurp_proc_file()Changes in v2:
- add
slurp_proc_file()to read proc files without knowing the size upfront
- movecommand_linestring from global to function scope
Thanks, applied.