Re: [PATCH 1/7] kexec_file: add kexec_file flag to control debug printing
On 11/14/23 at 08:03am, Joe Perches wrote: > On Tue, 2023-11-14 at 23:32 +0800, Baoquan He wrote: > > When specifying 'kexec -c -d', kexec_load interface will print loading > > information, e.g the regions where kernel/initrd/purgatory/cmdline > > are put, the memmap passed to 2nd kernel taken as system RAM ranges, > > and printing all contents of struct kexec_segment, etc. These are > > very helpful for analyzing or positioning what's happening when > > kexec/kdump itself failed. The debugging printing for kexec_load > > interface is made in user space utility kexec-tools. > > > > Whereas, with kexec_file_load interface, 'kexec -s -d' print nothing. > > Because kexec_file code is mostly implemented in kernel space, and the > > debugging printing functionality is missed. It's not convenient when > > debugging kexec/kdump loading and jumping with kexec_file_load > > interface. > > > > Now add KEXEC_FILE_DEBUG to kexec_file flag to control the debugging > > message printing. And add global variable kexec_file_dbg_print and > > macro kexec_dprintk() to facilitate the printing. > > > > This is a preparation, later kexec_dprintk() will be used to replace the > > existing pr_debug(). Once 'kexec -s -d' is specified, it will print out > > kexec/kdump loading information. If '-d' is not specified, it regresses > > to pr_debug(). > > Not quite as pr_debug is completely eliminated with > zero object size when DEBUG is not #defined. > > Now the object size will be larger and contain the > formats in .text. Ah, I didn't realize that. Thanks for telling. I didn't take pr_info() and pr_debug because I want to avoid printing the pr_fmt() string in each file. > > [] > > diff --git a/include/linux/kexec.h b/include/linux/kexec.h > [] > > @@ -264,6 +264,18 @@ arch_kexec_apply_relocations(struct purgatory_info > > *pi, Elf_Shdr *section, > > return -ENOEXEC; > > } > > #endif > > + > > +extern bool kexec_file_dbg_print; > > + > > +#define kexec_dprintk(fmt, args...)\ > > + do {\ > > + if (kexec_file_dbg_print) \ > > + printk(KERN_INFO fmt, ##args); \ > > + else\ > > + printk(KERN_DEBUG fmt, ##args); \ > > + } while (0) > > + > > + > > I don't know how many of these printks exist and if > overall object size matters but using Not too much because they are spread in different arch. > > #define kexec_dprintkfmt, ...)\ > printk("%s" fmt,\ > kexec_file_dbg_print ? KERN_INFO : KERN_DEBUG, \ > ##__VA_ARGS__) > > should reduce overall object size by eliminating the > mostly duplicated format in .text which differs only > by the KERN_ Sure, the new one looks great to me, I will update code to take it. Thanks a lot for your great suggestion. Thanks Baoquan ___ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/7] kexec_file: add kexec_file flag to control debug printing
On Tue, 2023-11-14 at 23:32 +0800, Baoquan He wrote: > When specifying 'kexec -c -d', kexec_load interface will print loading > information, e.g the regions where kernel/initrd/purgatory/cmdline > are put, the memmap passed to 2nd kernel taken as system RAM ranges, > and printing all contents of struct kexec_segment, etc. These are > very helpful for analyzing or positioning what's happening when > kexec/kdump itself failed. The debugging printing for kexec_load > interface is made in user space utility kexec-tools. > > Whereas, with kexec_file_load interface, 'kexec -s -d' print nothing. > Because kexec_file code is mostly implemented in kernel space, and the > debugging printing functionality is missed. It's not convenient when > debugging kexec/kdump loading and jumping with kexec_file_load > interface. > > Now add KEXEC_FILE_DEBUG to kexec_file flag to control the debugging > message printing. And add global variable kexec_file_dbg_print and > macro kexec_dprintk() to facilitate the printing. > > This is a preparation, later kexec_dprintk() will be used to replace the > existing pr_debug(). Once 'kexec -s -d' is specified, it will print out > kexec/kdump loading information. If '-d' is not specified, it regresses > to pr_debug(). Not quite as pr_debug is completely eliminated with zero object size when DEBUG is not #defined. Now the object size will be larger and contain the formats in .text. [] > diff --git a/include/linux/kexec.h b/include/linux/kexec.h [] > @@ -264,6 +264,18 @@ arch_kexec_apply_relocations(struct purgatory_info *pi, > Elf_Shdr *section, > return -ENOEXEC; > } > #endif > + > +extern bool kexec_file_dbg_print; > + > +#define kexec_dprintk(fmt, args...) \ > + do {\ > + if (kexec_file_dbg_print) \ > + printk(KERN_INFO fmt, ##args); \ > + else\ > + printk(KERN_DEBUG fmt, ##args); \ > + } while (0) > + > + I don't know how many of these printks exist and if overall object size matters but using #define kexec_dprintkfmt, ...) \ printk("%s" fmt,\ kexec_file_dbg_print ? KERN_INFO : KERN_DEBUG, \ ##__VA_ARGS__) should reduce overall object size by eliminating the mostly duplicated format in .text which differs only by the KERN_ ___ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec
[PATCH 1/7] kexec_file: add kexec_file flag to control debug printing
When specifying 'kexec -c -d', kexec_load interface will print loading information, e.g the regions where kernel/initrd/purgatory/cmdline are put, the memmap passed to 2nd kernel taken as system RAM ranges, and printing all contents of struct kexec_segment, etc. These are very helpful for analyzing or positioning what's happening when kexec/kdump itself failed. The debugging printing for kexec_load interface is made in user space utility kexec-tools. Whereas, with kexec_file_load interface, 'kexec -s -d' print nothing. Because kexec_file code is mostly implemented in kernel space, and the debugging printing functionality is missed. It's not convenient when debugging kexec/kdump loading and jumping with kexec_file_load interface. Now add KEXEC_FILE_DEBUG to kexec_file flag to control the debugging message printing. And add global variable kexec_file_dbg_print and macro kexec_dprintk() to facilitate the printing. This is a preparation, later kexec_dprintk() will be used to replace the existing pr_debug(). Once 'kexec -s -d' is specified, it will print out kexec/kdump loading information. If '-d' is not specified, it regresses to pr_debug(). Signed-off-by: Baoquan He --- include/linux/kexec.h | 14 +- include/uapi/linux/kexec.h | 1 + kernel/kexec_file.c| 5 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 8227455192b7..189a6c5bec84 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -264,6 +264,18 @@ arch_kexec_apply_relocations(struct purgatory_info *pi, Elf_Shdr *section, return -ENOEXEC; } #endif + +extern bool kexec_file_dbg_print; + +#define kexec_dprintk(fmt, args...)\ + do {\ + if (kexec_file_dbg_print) \ + printk(KERN_INFO fmt, ##args); \ + else\ + printk(KERN_DEBUG fmt, ##args); \ + } while (0) + + #endif /* CONFIG_KEXEC_FILE */ #ifdef CONFIG_KEXEC_ELF @@ -403,7 +415,7 @@ bool kexec_load_permitted(int kexec_image_type); /* List of defined/legal kexec file flags */ #define KEXEC_FILE_FLAGS (KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \ -KEXEC_FILE_NO_INITRAMFS) +KEXEC_FILE_NO_INITRAMFS | KEXEC_FILE_DEBUG) /* flag to track if kexec reboot is in progress */ extern bool kexec_in_progress; diff --git a/include/uapi/linux/kexec.h b/include/uapi/linux/kexec.h index 01766dd839b0..c17bb096ea68 100644 --- a/include/uapi/linux/kexec.h +++ b/include/uapi/linux/kexec.h @@ -25,6 +25,7 @@ #define KEXEC_FILE_UNLOAD 0x0001 #define KEXEC_FILE_ON_CRASH0x0002 #define KEXEC_FILE_NO_INITRAMFS0x0004 +#define KEXEC_FILE_DEBUG 0x0008 /* These values match the ELF architecture values. * Unless there is a good reason that should continue to be the case. diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index f9a419cd22d4..4c35500ae40a 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -38,6 +38,8 @@ void set_kexec_sig_enforced(void) } #endif +bool kexec_file_dbg_print; + static int kexec_calculate_store_digests(struct kimage *image); /* Maximum size in bytes for kernel/initrd files. */ @@ -123,6 +125,8 @@ void kimage_file_post_load_cleanup(struct kimage *image) */ kfree(image->image_loader_data); image->image_loader_data = NULL; + + kexec_file_dbg_print = false; } #ifdef CONFIG_KEXEC_SIG @@ -278,6 +282,7 @@ kimage_file_alloc_init(struct kimage **rimage, int kernel_fd, if (!image) return -ENOMEM; + kexec_file_dbg_print = !!(flags & KEXEC_FILE_DEBUG); image->file_mode = 1; if (kexec_on_panic) { -- 2.41.0 ___ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec