* [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined
@ 2023-02-24 9:51 Youling Tang
2023-02-24 9:51 ` [PATCH 2/2] LoongArch: kdump: Set up kernel image segment Youling Tang
2023-02-27 15:19 ` [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined Philipp Rudo
0 siblings, 2 replies; 7+ messages in thread
From: Youling Tang @ 2023-02-24 9:51 UTC (permalink / raw)
To: Simon Horman; +Cc: kexec
The initial reason is that after the merger of 29fe5067ed07
("kexec: make -a the default"), kexec cannot be used on LoongArch,
MIPS .etc architectures. We need to add "-c" for normal use. The
current kexec_file_load system call is not implemented in
architectures such as LoongArch, so it needs to pass kexec_load.
So we need to set __NR_kexec_file_load to undefined in unsupported
architectures. This will return EFALLBACK via is_kexec_file_load_implemented,
and then via kexec_load.
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
---
kexec/kexec-syscall.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/kexec/kexec-syscall.h b/kexec/kexec-syscall.h
index be6ccd5..ea77936 100644
--- a/kexec/kexec-syscall.h
+++ b/kexec/kexec-syscall.h
@@ -59,9 +59,7 @@
#endif
#endif /*ifndef __NR_kexec_load*/
-#ifdef __arm__
#undef __NR_kexec_file_load
-#endif
#ifndef __NR_kexec_file_load
--
2.37.1
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 2/2] LoongArch: kdump: Set up kernel image segment 2023-02-24 9:51 [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined Youling Tang @ 2023-02-24 9:51 ` Youling Tang 2023-02-27 15:19 ` [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined Philipp Rudo 1 sibling, 0 replies; 7+ messages in thread From: Youling Tang @ 2023-02-24 9:51 UTC (permalink / raw) To: Simon Horman; +Cc: kexec On LoongArch, we can use the same kernel image as 1st kernel when [1] is merged, but we have to modify the entry point as well as segments' addresses in the kernel's elf header (or pei format vmlinux.efi) in order to load them into correct places. [1]: https://lore.kernel.org/loongarch/1677150391-12838-1-git-send-email-tangyouling@loongson.cn/T/#t Signed-off-by: Youling Tang <tangyouling@loongson.cn> --- kexec/arch/loongarch/crashdump-loongarch.c | 22 ++++++++++++++++++++++ kexec/arch/loongarch/crashdump-loongarch.h | 1 + kexec/arch/loongarch/kexec-elf-loongarch.c | 8 ++++++++ kexec/arch/loongarch/kexec-loongarch.c | 3 ++- kexec/arch/loongarch/kexec-pei-loongarch.c | 7 +++++++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/kexec/arch/loongarch/crashdump-loongarch.c b/kexec/arch/loongarch/crashdump-loongarch.c index aaf6cf3..81250e4 100644 --- a/kexec/arch/loongarch/crashdump-loongarch.c +++ b/kexec/arch/loongarch/crashdump-loongarch.c @@ -183,6 +183,28 @@ int load_crashdump_segments(struct kexec_info *info) return 0; } +/* + * e_entry and p_paddr are actually in virtual address space. + * Those values will be translated to physcal addresses by using + * virt_to_phys() in add_segment(). + * So let's fix up those values for later use so the memory base will be + * correctly replaced with crash_reserved_mem[usablemem_rgns.size - 1].start. + */ +void fixup_elf_addrs(struct mem_ehdr *ehdr) +{ + struct mem_phdr *phdr; + int i; + + ehdr->e_entry += crash_reserved_mem[usablemem_rgns.size - 1].start; + + for (i = 0; i < ehdr->e_phnum; i++) { + phdr = &ehdr->e_phdr[i]; + if (phdr->p_type != PT_LOAD) + continue; + phdr->p_paddr += crash_reserved_mem[usablemem_rgns.size - 1].start; + } +} + int get_crash_kernel_load_range(uint64_t *start, uint64_t *end) { if (!usablemem_rgns.size) diff --git a/kexec/arch/loongarch/crashdump-loongarch.h b/kexec/arch/loongarch/crashdump-loongarch.h index 3eb4e0a..25ff24b 100644 --- a/kexec/arch/loongarch/crashdump-loongarch.h +++ b/kexec/arch/loongarch/crashdump-loongarch.h @@ -8,6 +8,7 @@ extern struct memory_range elfcorehdr_mem; int load_crashdump_segments(struct kexec_info *info); int is_crashkernel_mem_reserved(void); +void fixup_elf_addrs(struct mem_ehdr *ehdr); int get_crash_kernel_load_range(uint64_t *start, uint64_t *end); #define PAGE_OFFSET 0x9000000000000000ULL diff --git a/kexec/arch/loongarch/kexec-elf-loongarch.c b/kexec/arch/loongarch/kexec-elf-loongarch.c index 2bf128f..45387ca 100644 --- a/kexec/arch/loongarch/kexec-elf-loongarch.c +++ b/kexec/arch/loongarch/kexec-elf-loongarch.c @@ -90,6 +90,14 @@ int elf_loongarch_load(int argc, char **argv, const char *kernel_buf, } } + /* load the kernel */ + if (info->kexec_flags & KEXEC_ON_CRASH) + /* + * offset addresses in elf header in order to load + * vmlinux (elf_exec) into crash kernel's memory. + */ + fixup_elf_addrs(&ehdr); + info->entry = (void *)virt_to_phys(ehdr.e_entry); result = elf_exec_load(&ehdr, info); diff --git a/kexec/arch/loongarch/kexec-loongarch.c b/kexec/arch/loongarch/kexec-loongarch.c index 4c7361c..f47c998 100644 --- a/kexec/arch/loongarch/kexec-loongarch.c +++ b/kexec/arch/loongarch/kexec-loongarch.c @@ -253,7 +253,8 @@ unsigned long loongarch_locate_kernel_segment(struct kexec_info *info) unsigned long hole_end; hole = (crash_reserved_mem[usablemem_rgns.size - 1].start < mem_min ? - mem_min : crash_reserved_mem[usablemem_rgns.size - 1].start); + mem_min : crash_reserved_mem[usablemem_rgns.size - 1].start) + + loongarch_mem.text_offset; hole = _ALIGN_UP(hole, MiB(1)); hole_end = hole + loongarch_mem.text_offset + loongarch_mem.image_size; diff --git a/kexec/arch/loongarch/kexec-pei-loongarch.c b/kexec/arch/loongarch/kexec-pei-loongarch.c index f86ac61..1a11103 100644 --- a/kexec/arch/loongarch/kexec-pei-loongarch.c +++ b/kexec/arch/loongarch/kexec-pei-loongarch.c @@ -66,6 +66,13 @@ int pei_loongarch_load(int argc, char **argv, const char *buf, kernel_entry = virt_to_phys(loongarch_header_kernel_entry(header)); + if (info->kexec_flags & KEXEC_ON_CRASH) + /* + * offset addresses in order to load vmlinux.efi into + * crash kernel's memory. + */ + kernel_entry += crash_reserved_mem[usablemem_rgns.size - 1].start; + dbgprintf("%s: kernel_segment: %016lx\n", __func__, kernel_segment); dbgprintf("%s: kernel_entry: %016lx\n", __func__, kernel_entry); dbgprintf("%s: image_size: %016lx\n", __func__, -- 2.37.1 _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined 2023-02-24 9:51 [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined Youling Tang 2023-02-24 9:51 ` [PATCH 2/2] LoongArch: kdump: Set up kernel image segment Youling Tang @ 2023-02-27 15:19 ` Philipp Rudo 2023-02-28 13:32 ` Baoquan He [not found] ` <eb34b2b5-3965-27f1-2fe5-bb4fda4ef16b@loongson.cn> 1 sibling, 2 replies; 7+ messages in thread From: Philipp Rudo @ 2023-02-27 15:19 UTC (permalink / raw) To: Youling Tang; +Cc: Simon Horman, kexec Hi Youling, On Fri, 24 Feb 2023 17:51:07 +0800 Youling Tang <tangyouling@loongson.cn> wrote: > The initial reason is that after the merger of 29fe5067ed07 > ("kexec: make -a the default"), kexec cannot be used on LoongArch, > MIPS .etc architectures. We need to add "-c" for normal use. The > current kexec_file_load system call is not implemented in > architectures such as LoongArch, so it needs to pass kexec_load. > So we need to set __NR_kexec_file_load to undefined in unsupported > architectures. This will return EFALLBACK via is_kexec_file_load_implemented, > and then via kexec_load. > > Signed-off-by: Youling Tang <tangyouling@loongson.cn> > --- > kexec/kexec-syscall.h | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/kexec/kexec-syscall.h b/kexec/kexec-syscall.h > index be6ccd5..ea77936 100644 > --- a/kexec/kexec-syscall.h > +++ b/kexec/kexec-syscall.h > @@ -59,9 +59,7 @@ > #endif > #endif /*ifndef __NR_kexec_load*/ > > -#ifdef __arm__ > #undef __NR_kexec_file_load > -#endif > > #ifndef __NR_kexec_file_load I don't think this will work as intended. On the top of the file sys/syscall.h gets included. In there architectures that support kexec_file_load define __NR_kexec_file_load. This also means that if an architecture doesn't support kexec_file_load __NR_kexec_file_load shouldn't be defined in the first place. Thus I suggest that you find out why sys/syscall.h defines __NR_kexec_file_load for LoongArch even when the system call is not supported and fix it there. Thanks Philipp _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined 2023-02-27 15:19 ` [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined Philipp Rudo @ 2023-02-28 13:32 ` Baoquan He 2023-03-03 11:03 ` Philipp Rudo [not found] ` <eb34b2b5-3965-27f1-2fe5-bb4fda4ef16b@loongson.cn> 1 sibling, 1 reply; 7+ messages in thread From: Baoquan He @ 2023-02-28 13:32 UTC (permalink / raw) To: Philipp Rudo; +Cc: Youling Tang, Simon Horman, kexec Hi Philipp, On 02/27/23 at 04:19pm, Philipp Rudo wrote: ...... > > diff --git a/kexec/kexec-syscall.h b/kexec/kexec-syscall.h > > index be6ccd5..ea77936 100644 > > --- a/kexec/kexec-syscall.h > > +++ b/kexec/kexec-syscall.h > > @@ -59,9 +59,7 @@ > > #endif > > #endif /*ifndef __NR_kexec_load*/ > > > > -#ifdef __arm__ > > #undef __NR_kexec_file_load > > -#endif > > > > #ifndef __NR_kexec_file_load > > I don't think this will work as intended. > > On the top of the file sys/syscall.h gets included. In there > architectures that support kexec_file_load define __NR_kexec_file_load. > This also means that if an architecture doesn't support kexec_file_load > __NR_kexec_file_load shouldn't be defined in the first place. Thus I > suggest that you find out why sys/syscall.h defines > __NR_kexec_file_load for LoongArch even when the system call is not > supported and fix it there. Checking whether LoongArch has defined __NR_kexec_file_load sounds a good suggestion. Wondering why we still need add __NR_kexec_file_load definition in kexec-tools. E.g below s390 kexec_file support you added. <sys/syscall.h> sometime won't be found or __NR_kexec_file_load could be not defined yet? commit d4a948c268272cf37c71be820fb02bf40e56292b Author: Philipp Rudo <prudo@linux.ibm.com> Date: Wed May 16 14:27:18 2018 +0200 kexec/s390: Add support for kexec_file_load _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined 2023-02-28 13:32 ` Baoquan He @ 2023-03-03 11:03 ` Philipp Rudo 2023-03-07 3:28 ` Baoquan He 0 siblings, 1 reply; 7+ messages in thread From: Philipp Rudo @ 2023-03-03 11:03 UTC (permalink / raw) To: Baoquan He; +Cc: Youling Tang, Simon Horman, kexec Hi Baoquan, On Tue, 28 Feb 2023 21:32:26 +0800 Baoquan He <bhe@redhat.com> wrote: > Hi Philipp, > > On 02/27/23 at 04:19pm, Philipp Rudo wrote: > ...... > > > diff --git a/kexec/kexec-syscall.h b/kexec/kexec-syscall.h > > > index be6ccd5..ea77936 100644 > > > --- a/kexec/kexec-syscall.h > > > +++ b/kexec/kexec-syscall.h > > > @@ -59,9 +59,7 @@ > > > #endif > > > #endif /*ifndef __NR_kexec_load*/ > > > > > > -#ifdef __arm__ > > > #undef __NR_kexec_file_load > > > -#endif > > > > > > #ifndef __NR_kexec_file_load > > > > I don't think this will work as intended. > > > > On the top of the file sys/syscall.h gets included. In there > > architectures that support kexec_file_load define __NR_kexec_file_load. > > This also means that if an architecture doesn't support kexec_file_load > > __NR_kexec_file_load shouldn't be defined in the first place. Thus I > > suggest that you find out why sys/syscall.h defines > > __NR_kexec_file_load for LoongArch even when the system call is not > > supported and fix it there. > > Checking whether LoongArch has defined __NR_kexec_file_load sounds a > good suggestion. Wondering why we still need add __NR_kexec_file_load > definition in kexec-tools. E.g below s390 kexec_file support you added. > <sys/syscall.h> sometime won't be found or __NR_kexec_file_load could be > not defined yet? > > commit d4a948c268272cf37c71be820fb02bf40e56292b > Author: Philipp Rudo <prudo@linux.ibm.com> > Date: Wed May 16 14:27:18 2018 +0200 > > kexec/s390: Add support for kexec_file_load > To be honest I don't remember why I have added it back then. Most likely I simply copied what others have done before. The benefit in having the extra definition I see is that you don't need to rebuild glibc when you implement the syscall and don't use the generic unistd.h. But that is something only few people should ever encounter. Thanks Philipp _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined 2023-03-03 11:03 ` Philipp Rudo @ 2023-03-07 3:28 ` Baoquan He 0 siblings, 0 replies; 7+ messages in thread From: Baoquan He @ 2023-03-07 3:28 UTC (permalink / raw) To: Philipp Rudo; +Cc: Youling Tang, Simon Horman, kexec On 03/03/23 at 12:03pm, Philipp Rudo wrote: > Hi Baoquan, > > On Tue, 28 Feb 2023 21:32:26 +0800 > Baoquan He <bhe@redhat.com> wrote: > > > Hi Philipp, > > > > On 02/27/23 at 04:19pm, Philipp Rudo wrote: > > ...... > > > > diff --git a/kexec/kexec-syscall.h b/kexec/kexec-syscall.h > > > > index be6ccd5..ea77936 100644 > > > > --- a/kexec/kexec-syscall.h > > > > +++ b/kexec/kexec-syscall.h > > > > @@ -59,9 +59,7 @@ > > > > #endif > > > > #endif /*ifndef __NR_kexec_load*/ > > > > > > > > -#ifdef __arm__ > > > > #undef __NR_kexec_file_load > > > > -#endif > > > > > > > > #ifndef __NR_kexec_file_load > > > > > > I don't think this will work as intended. > > > > > > On the top of the file sys/syscall.h gets included. In there > > > architectures that support kexec_file_load define __NR_kexec_file_load. > > > This also means that if an architecture doesn't support kexec_file_load > > > __NR_kexec_file_load shouldn't be defined in the first place. Thus I > > > suggest that you find out why sys/syscall.h defines > > > __NR_kexec_file_load for LoongArch even when the system call is not > > > supported and fix it there. > > > > Checking whether LoongArch has defined __NR_kexec_file_load sounds a > > good suggestion. Wondering why we still need add __NR_kexec_file_load > > definition in kexec-tools. E.g below s390 kexec_file support you added. > > <sys/syscall.h> sometime won't be found or __NR_kexec_file_load could be > > not defined yet? > > > > commit d4a948c268272cf37c71be820fb02bf40e56292b > > Author: Philipp Rudo <prudo@linux.ibm.com> > > Date: Wed May 16 14:27:18 2018 +0200 > > > > kexec/s390: Add support for kexec_file_load > > > > To be honest I don't remember why I have added it back then. Most > likely I simply copied what others have done before. > > The benefit in having the extra definition I see is that you don't need > to rebuild glibc when you implement the syscall and don't use the > generic unistd.h. But that is something only few people should ever > encounter. OK, got it. From the code, the adding won't cuase issue, but a double insurance, not sure if it's redundant. Someone interested can investigate and clean up if needed. Thanks for the information. _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <eb34b2b5-3965-27f1-2fe5-bb4fda4ef16b@loongson.cn>]
* Re: [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined [not found] ` <eb34b2b5-3965-27f1-2fe5-bb4fda4ef16b@loongson.cn> @ 2023-03-03 10:54 ` Philipp Rudo 0 siblings, 0 replies; 7+ messages in thread From: Philipp Rudo @ 2023-03-03 10:54 UTC (permalink / raw) To: Youling Tang; +Cc: Simon Horman, kexec Hi Youling, On Tue, 28 Feb 2023 10:02:16 +0800 Youling Tang <tangyouling@loongson.cn> wrote: > Hi, Philipp > > On 02/27/2023 11:19 PM, Philipp Rudo wrote: > > Hi Youling, > > > > On Fri, 24 Feb 2023 17:51:07 +0800 > > Youling Tang <tangyouling@loongson.cn> wrote: > > > >> The initial reason is that after the merger of 29fe5067ed07 > >> ("kexec: make -a the default"), kexec cannot be used on LoongArch, > >> MIPS .etc architectures. We need to add "-c" for normal use. The > >> current kexec_file_load system call is not implemented in > >> architectures such as LoongArch, so it needs to pass kexec_load. > >> So we need to set __NR_kexec_file_load to undefined in unsupported > >> architectures. This will return EFALLBACK via is_kexec_file_load_implemented, > >> and then via kexec_load. > >> > >> Signed-off-by: Youling Tang <tangyouling@loongson.cn> > >> --- > >> kexec/kexec-syscall.h | 2 -- > >> 1 file changed, 2 deletions(-) > >> > >> diff --git a/kexec/kexec-syscall.h b/kexec/kexec-syscall.h > >> index be6ccd5..ea77936 100644 > >> --- a/kexec/kexec-syscall.h > >> +++ b/kexec/kexec-syscall.h > >> @@ -59,9 +59,7 @@ > >> #endif > >> #endif /*ifndef __NR_kexec_load*/ > >> > >> -#ifdef __arm__ > >> #undef __NR_kexec_file_load > >> -#endif > >> > >> #ifndef __NR_kexec_file_load > > > > I don't think this will work as intended. > > Works fine in LoongArch after applying this patch. I believe you. The problem is that it changes the behavior on other architectures. > > > > On the top of the file sys/syscall.h gets included. In there > > architectures that support kexec_file_load define __NR_kexec_file_load. > > This also means that if an architecture doesn't support kexec_file_load > > __NR_kexec_file_load shouldn't be defined in the first place. Thus I > > suggest that you find out why sys/syscall.h defines > > __NR_kexec_file_load for LoongArch even when the system call is not > > supported and fix it there. > Yes, in the kernel, LoongArch uses the generic syscall number (in > include/uapi/asm-generic/unistd.h), so __NR_kexec_file_load is > defined as 294. Ok, I see. I have expected that it is wrapped in some ifdef CONFIG_KEXEC_FILE. But apparently that is not the case. Thanks for the clarification. > I think the simpler way is to modify it in kexec-tools as follows, > #ifdef __loongarch__ > #undef __NR_kexec_file_load > #endif Yeah, looks like this is the best solution. Only thing you could do is to merge it with the arm special handling. I.e. so it reads #if defined(__arm__) || defined(__longarch__) #undef __NR_kexec_file_load #endif But that is more a matter of taste. So you and Simon need to agree what you like more. Thanks Philipp _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-03-07 3:28 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-24 9:51 [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined Youling Tang
2023-02-24 9:51 ` [PATCH 2/2] LoongArch: kdump: Set up kernel image segment Youling Tang
2023-02-27 15:19 ` [PATCH 1/2] kexec: Default __NR_kexec_file_load is set to undefined Philipp Rudo
2023-02-28 13:32 ` Baoquan He
2023-03-03 11:03 ` Philipp Rudo
2023-03-07 3:28 ` Baoquan He
[not found] ` <eb34b2b5-3965-27f1-2fe5-bb4fda4ef16b@loongson.cn>
2023-03-03 10:54 ` Philipp Rudo
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox