mbox series

[v3,0/5] RISC-V: Add kexec/kdump support

Message ID 20210405085712.1953848-1-mick@ics.forth.gr (mailing list archive)
Headers show
Series RISC-V: Add kexec/kdump support | expand

Message

Nick Kossifidis April 5, 2021, 8:57 a.m. UTC
This patch series adds kexec/kdump and crash kernel
support on RISC-V. For testing the patches a patched
version of kexec-tools is needed (still a work in
progress) which can be found at:

https://riscv.ics.forth.gr/kexec-tools-patched.tar.xz

v3:
 * Rebase on newer kernel tree
 * Minor cleanups
 * Split UAPI changes to a separate patch
 * Improve / cleanup init_resources
 * Resolve Palmer's comments

v2:
 * Rebase on newer kernel tree
 * Minor cleanups
 * Properly populate the ioresources tre, so that it
   can be used later on for implementing strict /dev/mem
 * Use linux,usable-memory on /memory instead of a new binding
 * USe a reserved-memory node for ELF core header

Nick Kossifidis (5):
  RISC-V: Add EM_RISCV to kexec UAPI header
  RISC-V: Add kexec support
  RISC-V: Improve init_resources
  RISC-V: Add kdump support
  RISC-V: Add crash kernel support

 arch/riscv/Kconfig                  |  25 ++++
 arch/riscv/include/asm/elf.h        |   6 +
 arch/riscv/include/asm/kexec.h      |  54 +++++++
 arch/riscv/kernel/Makefile          |   6 +
 arch/riscv/kernel/crash_dump.c      |  46 ++++++
 arch/riscv/kernel/crash_save_regs.S |  56 +++++++
 arch/riscv/kernel/kexec_relocate.S  | 222 ++++++++++++++++++++++++++++
 arch/riscv/kernel/machine_kexec.c   | 193 ++++++++++++++++++++++++
 arch/riscv/kernel/setup.c           | 113 ++++++++------
 arch/riscv/mm/init.c                | 110 ++++++++++++++
 include/uapi/linux/kexec.h          |   1 +
 11 files changed, 787 insertions(+), 45 deletions(-)
 create mode 100644 arch/riscv/include/asm/kexec.h
 create mode 100644 arch/riscv/kernel/crash_dump.c
 create mode 100644 arch/riscv/kernel/crash_save_regs.S
 create mode 100644 arch/riscv/kernel/kexec_relocate.S
 create mode 100644 arch/riscv/kernel/machine_kexec.c

Comments

Yixun Lan April 7, 2021, 7:45 a.m. UTC | #1
Hi Nick

On 4/5/21 8:57 AM, Nick Kossifidis wrote:
> This patch series adds kexec/kdump and crash kernel
> support on RISC-V. For testing the patches a patched
> version of kexec-tools is needed (still a work in
> progress) which can be found at:
>
> https://riscv.ics.forth.gr/kexec-tools-patched.tar.xz
>
> v3:
>   * Rebase on newer kernel tree
>   * Minor cleanups
>   * Split UAPI changes to a separate patch
>   * Improve / cleanup init_resources
>   * Resolve Palmer's comments
>
> v2:
>   * Rebase on newer kernel tree
>   * Minor cleanups
>   * Properly populate the ioresources tre, so that it
>     can be used later on for implementing strict /dev/mem
>   * Use linux,usable-memory on /memory instead of a new binding
>   * USe a reserved-memory node for ELF core header
>
> Nick Kossifidis (5):
>    RISC-V: Add EM_RISCV to kexec UAPI header
>    RISC-V: Add kexec support
>    RISC-V: Improve init_resources
>    RISC-V: Add kdump support
>    RISC-V: Add crash kernel support
>
>   arch/riscv/Kconfig                  |  25 ++++
>   arch/riscv/include/asm/elf.h        |   6 +
>   arch/riscv/include/asm/kexec.h      |  54 +++++++
>   arch/riscv/kernel/Makefile          |   6 +
>   arch/riscv/kernel/crash_dump.c      |  46 ++++++
>   arch/riscv/kernel/crash_save_regs.S |  56 +++++++
>   arch/riscv/kernel/kexec_relocate.S  | 222 ++++++++++++++++++++++++++++
>   arch/riscv/kernel/machine_kexec.c   | 193 ++++++++++++++++++++++++
>   arch/riscv/kernel/setup.c           | 113 ++++++++------
>   arch/riscv/mm/init.c                | 110 ++++++++++++++
>   include/uapi/linux/kexec.h          |   1 +
>   11 files changed, 787 insertions(+), 45 deletions(-)
>   create mode 100644 arch/riscv/include/asm/kexec.h
>   create mode 100644 arch/riscv/kernel/crash_dump.c
>   create mode 100644 arch/riscv/kernel/crash_save_regs.S
>   create mode 100644 arch/riscv/kernel/kexec_relocate.S
>   create mode 100644 arch/riscv/kernel/machine_kexec.c
>

Just ask out of curiosity (maybe out of topic)..
Is crash analysis [1] capable of parsing RISC-V kdump image? No?

Or, any plan working on it?

[1] https://github.com/crash-utility/crash

Yxun Lan
Rob Herring April 7, 2021, 4:29 p.m. UTC | #2
On Mon, Apr 05, 2021 at 11:57:07AM +0300, Nick Kossifidis wrote:
> This patch series adds kexec/kdump and crash kernel
> support on RISC-V. For testing the patches a patched
> version of kexec-tools is needed (still a work in
> progress) which can be found at:
> 
> https://riscv.ics.forth.gr/kexec-tools-patched.tar.xz
> 
> v3:
>  * Rebase on newer kernel tree
>  * Minor cleanups
>  * Split UAPI changes to a separate patch
>  * Improve / cleanup init_resources
>  * Resolve Palmer's comments
> 
> v2:
>  * Rebase on newer kernel tree
>  * Minor cleanups
>  * Properly populate the ioresources tre, so that it
>    can be used later on for implementing strict /dev/mem
>  * Use linux,usable-memory on /memory instead of a new binding

Where? In any case, that's not going to work well with EFI support 
assuming like arm64, 'memory' is passed in UEFI structures instead of 
DT. That's why there's now a /chosen linux,usable-memory-ranges 
property. 

Isn't the preferred kexec interface the file based interface? I'd 
expect a new arch to only support that. And there's common kexec DT 
handling for that pending for 5.13.

Rob
Nick Kossifidis April 9, 2021, 10:02 a.m. UTC | #3
Στις 2021-04-07 19:29, Rob Herring έγραψε:
> On Mon, Apr 05, 2021 at 11:57:07AM +0300, Nick Kossifidis wrote:
>> This patch series adds kexec/kdump and crash kernel
>> support on RISC-V. For testing the patches a patched
>> version of kexec-tools is needed (still a work in
>> progress) which can be found at:
>> 
>> https://riscv.ics.forth.gr/kexec-tools-patched.tar.xz
>> 
>> v3:
>>  * Rebase on newer kernel tree
>>  * Minor cleanups
>>  * Split UAPI changes to a separate patch
>>  * Improve / cleanup init_resources
>>  * Resolve Palmer's comments
>> 
>> v2:
>>  * Rebase on newer kernel tree
>>  * Minor cleanups
>>  * Properly populate the ioresources tre, so that it
>>    can be used later on for implementing strict /dev/mem
>>  * Use linux,usable-memory on /memory instead of a new binding
> 
> Where? In any case, that's not going to work well with EFI support
> assuming like arm64, 'memory' is passed in UEFI structures instead of
> DT. That's why there's now a /chosen linux,usable-memory-ranges
> property.
> 

Here:
https://elixir.bootlin.com/linux/v5.12-rc5/source/drivers/of/fdt.c#L1001

The "linux,usable-memory" binding is already defined and is part of
early_init_dt_scan_memory() which we call on mm/init.c to determine
system's memory layout. It's simple, clean and I don't see a reason
to use another binding on /chosen and add extra code for this, when
we already handle it on early_init_dt_scan_memory() anyway. As for
EFI, even when enabled, we still use DT to determine system memory
layout, not EFI structures, plus I don't see how EFI is relevant
here, the bootloader in kexec's case is Linux, not EFI. BTW the /memory
node is mandatory in any case, it should exist on DT regardless of EFI,
/chosen node on the other hand is -in general- optional, and we can 
still
boot a riscv system without /chosen node present (we only require it for
the built-in cmdline to work).

Also a simple grep for "linux,usable-memory-ranges" on the latest kernel
sources didn't return anything, there is also nothing on chosen.txt, 
where
is that binding documented/implemented ?

> Isn't the preferred kexec interface the file based interface? I'd
> expect a new arch to only support that. And there's common kexec DT
> handling for that pending for 5.13.
> 

Both approaches have their pros an cons, that's why both are available, 
in no
way CONFIG_KEXEC is deprecated in favor of CONFIG_KEXEC_FILE, at least 
not as
far as I know. The main point for the file-based syscall is to support 
secure
boot, since the image is loaded by the kernel directly without any 
processing
by the userspace tools, so it can be pre-signed by the kernel's 
"vendor". On
the other hand, the kernel part is more complicated and you can't pass a 
new
device tree, the kernel needs to re-use the existing one (or modify it
in-kernel), you can only override the cmdline.

This doesn't work for our use cases in FORTH, where we use kexec not 
only to
re-boot our systems, but also to boot to a system with different hw 
layout
(e.g. FPGA prototypes or systems with FPGAs on the side), device tree 
overlays
also don't cover our use cases. To give you an idea we can 
add/remove/modify
devices, move them to another region etc and still use kexec to avoid 
going
through the full boot cycle. We just unload their drivers, perform a 
full or
partial re-programming of the FPGA from within Linux, and kexec to the 
new
system with the new device tree. The file-based syscall can't cover this
scenario, in general it's less flexible and it's only there for secure 
boot,
not for using custom-built kernels, nor custom device tree images.

Security-wise the file load syscall provides guarantees for integrity 
and
authenticity, but depending on the kernel "vendor"'s infrastructure and
signing process this may allow e.g. to load an older/vulnerable kernel 
through
kexec and get away with it, there is no check as far as I know  to make 
sure
the loaded kernel is at least as old as the running kernel, the 
assumption is
that the "vendor" will use a different signing key/cert for each kernel 
and
that you'll kexec to a kernel/crash kernel that's the same version as 
the
running one. Until we have clear guidelines on how this is meant to be 
used
and have a discussion on secure boot within RISC-V (we have something on
the TEE TG but we'll probably switch to a SIG committee for this), I 
don't
see how this feature is a priority compared to the more generic 
CONFIG_KEXEC.

Regards,
Nick
Palmer Dabbelt April 23, 2021, 3:30 a.m. UTC | #4
On Mon, 05 Apr 2021 01:57:07 PDT (-0700), mick@ics.forth.gr wrote:
> This patch series adds kexec/kdump and crash kernel
> support on RISC-V. For testing the patches a patched
> version of kexec-tools is needed (still a work in
> progress) which can be found at:
>
> https://riscv.ics.forth.gr/kexec-tools-patched.tar.xz
>
> v3:
>  * Rebase on newer kernel tree
>  * Minor cleanups
>  * Split UAPI changes to a separate patch
>  * Improve / cleanup init_resources
>  * Resolve Palmer's comments
>
> v2:
>  * Rebase on newer kernel tree
>  * Minor cleanups
>  * Properly populate the ioresources tre, so that it
>    can be used later on for implementing strict /dev/mem
>  * Use linux,usable-memory on /memory instead of a new binding
>  * USe a reserved-memory node for ELF core header
>
> Nick Kossifidis (5):
>   RISC-V: Add EM_RISCV to kexec UAPI header
>   RISC-V: Add kexec support
>   RISC-V: Improve init_resources
>   RISC-V: Add kdump support
>   RISC-V: Add crash kernel support
>
>  arch/riscv/Kconfig                  |  25 ++++
>  arch/riscv/include/asm/elf.h        |   6 +
>  arch/riscv/include/asm/kexec.h      |  54 +++++++
>  arch/riscv/kernel/Makefile          |   6 +
>  arch/riscv/kernel/crash_dump.c      |  46 ++++++
>  arch/riscv/kernel/crash_save_regs.S |  56 +++++++
>  arch/riscv/kernel/kexec_relocate.S  | 222 ++++++++++++++++++++++++++++
>  arch/riscv/kernel/machine_kexec.c   | 193 ++++++++++++++++++++++++
>  arch/riscv/kernel/setup.c           | 113 ++++++++------
>  arch/riscv/mm/init.c                | 110 ++++++++++++++
>  include/uapi/linux/kexec.h          |   1 +
>  11 files changed, 787 insertions(+), 45 deletions(-)
>  create mode 100644 arch/riscv/include/asm/kexec.h
>  create mode 100644 arch/riscv/kernel/crash_dump.c
>  create mode 100644 arch/riscv/kernel/crash_save_regs.S
>  create mode 100644 arch/riscv/kernel/kexec_relocate.S
>  create mode 100644 arch/riscv/kernel/machine_kexec.c

Thanks.  There were some minor issues and some merge conflicts, I put 
this on for-next with some fixups.
Nick Kossifidis April 23, 2021, 3:36 a.m. UTC | #5
Στις 2021-04-23 06:30, Palmer Dabbelt έγραψε:
> On Mon, 05 Apr 2021 01:57:07 PDT (-0700), mick@ics.forth.gr wrote:
>> This patch series adds kexec/kdump and crash kernel
>> support on RISC-V. For testing the patches a patched
>> version of kexec-tools is needed (still a work in
>> progress) which can be found at:
>> 
>> https://riscv.ics.forth.gr/kexec-tools-patched.tar.xz
>> 
>> v3:
>>  * Rebase on newer kernel tree
>>  * Minor cleanups
>>  * Split UAPI changes to a separate patch
>>  * Improve / cleanup init_resources
>>  * Resolve Palmer's comments
>> 
>> v2:
>>  * Rebase on newer kernel tree
>>  * Minor cleanups
>>  * Properly populate the ioresources tre, so that it
>>    can be used later on for implementing strict /dev/mem
>>  * Use linux,usable-memory on /memory instead of a new binding
>>  * USe a reserved-memory node for ELF core header
>> 
>> Nick Kossifidis (5):
>>   RISC-V: Add EM_RISCV to kexec UAPI header
>>   RISC-V: Add kexec support
>>   RISC-V: Improve init_resources
>>   RISC-V: Add kdump support
>>   RISC-V: Add crash kernel support
>> 
>>  arch/riscv/Kconfig                  |  25 ++++
>>  arch/riscv/include/asm/elf.h        |   6 +
>>  arch/riscv/include/asm/kexec.h      |  54 +++++++
>>  arch/riscv/kernel/Makefile          |   6 +
>>  arch/riscv/kernel/crash_dump.c      |  46 ++++++
>>  arch/riscv/kernel/crash_save_regs.S |  56 +++++++
>>  arch/riscv/kernel/kexec_relocate.S  | 222 
>> ++++++++++++++++++++++++++++
>>  arch/riscv/kernel/machine_kexec.c   | 193 ++++++++++++++++++++++++
>>  arch/riscv/kernel/setup.c           | 113 ++++++++------
>>  arch/riscv/mm/init.c                | 110 ++++++++++++++
>>  include/uapi/linux/kexec.h          |   1 +
>>  11 files changed, 787 insertions(+), 45 deletions(-)
>>  create mode 100644 arch/riscv/include/asm/kexec.h
>>  create mode 100644 arch/riscv/kernel/crash_dump.c
>>  create mode 100644 arch/riscv/kernel/crash_save_regs.S
>>  create mode 100644 arch/riscv/kernel/kexec_relocate.S
>>  create mode 100644 arch/riscv/kernel/machine_kexec.c
> 
> Thanks.  There were some minor issues and some merge conflicts, I put
> this on for-next with some fixups.

I've sent a v4 that shouldn't have merge conflicts, addressing some 
comments from Alex as well, could you use that instead or is it too late 
?
Palmer Dabbelt April 23, 2021, 3:48 a.m. UTC | #6
On Thu, 22 Apr 2021 20:36:56 PDT (-0700), mick@ics.forth.gr wrote:
> Στις 2021-04-23 06:30, Palmer Dabbelt έγραψε:
>> On Mon, 05 Apr 2021 01:57:07 PDT (-0700), mick@ics.forth.gr wrote:
>>> This patch series adds kexec/kdump and crash kernel
>>> support on RISC-V. For testing the patches a patched
>>> version of kexec-tools is needed (still a work in
>>> progress) which can be found at:
>>>
>>> https://riscv.ics.forth.gr/kexec-tools-patched.tar.xz
>>>
>>> v3:
>>>  * Rebase on newer kernel tree
>>>  * Minor cleanups
>>>  * Split UAPI changes to a separate patch
>>>  * Improve / cleanup init_resources
>>>  * Resolve Palmer's comments
>>>
>>> v2:
>>>  * Rebase on newer kernel tree
>>>  * Minor cleanups
>>>  * Properly populate the ioresources tre, so that it
>>>    can be used later on for implementing strict /dev/mem
>>>  * Use linux,usable-memory on /memory instead of a new binding
>>>  * USe a reserved-memory node for ELF core header
>>>
>>> Nick Kossifidis (5):
>>>   RISC-V: Add EM_RISCV to kexec UAPI header
>>>   RISC-V: Add kexec support
>>>   RISC-V: Improve init_resources
>>>   RISC-V: Add kdump support
>>>   RISC-V: Add crash kernel support
>>>
>>>  arch/riscv/Kconfig                  |  25 ++++
>>>  arch/riscv/include/asm/elf.h        |   6 +
>>>  arch/riscv/include/asm/kexec.h      |  54 +++++++
>>>  arch/riscv/kernel/Makefile          |   6 +
>>>  arch/riscv/kernel/crash_dump.c      |  46 ++++++
>>>  arch/riscv/kernel/crash_save_regs.S |  56 +++++++
>>>  arch/riscv/kernel/kexec_relocate.S  | 222
>>> ++++++++++++++++++++++++++++
>>>  arch/riscv/kernel/machine_kexec.c   | 193 ++++++++++++++++++++++++
>>>  arch/riscv/kernel/setup.c           | 113 ++++++++------
>>>  arch/riscv/mm/init.c                | 110 ++++++++++++++
>>>  include/uapi/linux/kexec.h          |   1 +
>>>  11 files changed, 787 insertions(+), 45 deletions(-)
>>>  create mode 100644 arch/riscv/include/asm/kexec.h
>>>  create mode 100644 arch/riscv/kernel/crash_dump.c
>>>  create mode 100644 arch/riscv/kernel/crash_save_regs.S
>>>  create mode 100644 arch/riscv/kernel/kexec_relocate.S
>>>  create mode 100644 arch/riscv/kernel/machine_kexec.c
>>
>> Thanks.  There were some minor issues and some merge conflicts, I put
>> this on for-next with some fixups.
>
> I've sent a v4 that shouldn't have merge conflicts, addressing some
> comments from Alex as well, could you use that instead or is it too late
> ?

Thanks, for some reason I didn't see it when poking around.  There was 
still that one init_resources() merge conflict and I fixed up some of 
the commit texts, it's now on for-next as

b94394119804 (HEAD -> for-next, riscv/for-next) RISC-V: Add crash kernel support
6e8451782c90 RISC-V: Add kdump support
0a0652429bdb RISC-V: Improve init_resources()
d9a8897d6b5d RISC-V: Add kexec support
f59938095b94 RISC-V: Add EM_RISCV to kexec UAPI header
Nick Kossifidis April 23, 2021, 3:53 a.m. UTC | #7
Στις 2021-04-23 06:48, Palmer Dabbelt έγραψε:
> On Thu, 22 Apr 2021 20:36:56 PDT (-0700), mick@ics.forth.gr wrote:
>> Στις 2021-04-23 06:30, Palmer Dabbelt έγραψε:
>>> On Mon, 05 Apr 2021 01:57:07 PDT (-0700), mick@ics.forth.gr wrote:
>>>> This patch series adds kexec/kdump and crash kernel
>>>> support on RISC-V. For testing the patches a patched
>>>> version of kexec-tools is needed (still a work in
>>>> progress) which can be found at:
>>>> 
>>>> https://riscv.ics.forth.gr/kexec-tools-patched.tar.xz
>>>> 
>>>> v3:
>>>>  * Rebase on newer kernel tree
>>>>  * Minor cleanups
>>>>  * Split UAPI changes to a separate patch
>>>>  * Improve / cleanup init_resources
>>>>  * Resolve Palmer's comments
>>>> 
>>>> v2:
>>>>  * Rebase on newer kernel tree
>>>>  * Minor cleanups
>>>>  * Properly populate the ioresources tre, so that it
>>>>    can be used later on for implementing strict /dev/mem
>>>>  * Use linux,usable-memory on /memory instead of a new binding
>>>>  * USe a reserved-memory node for ELF core header
>>>> 
>>>> Nick Kossifidis (5):
>>>>   RISC-V: Add EM_RISCV to kexec UAPI header
>>>>   RISC-V: Add kexec support
>>>>   RISC-V: Improve init_resources
>>>>   RISC-V: Add kdump support
>>>>   RISC-V: Add crash kernel support
>>>> 
>>>>  arch/riscv/Kconfig                  |  25 ++++
>>>>  arch/riscv/include/asm/elf.h        |   6 +
>>>>  arch/riscv/include/asm/kexec.h      |  54 +++++++
>>>>  arch/riscv/kernel/Makefile          |   6 +
>>>>  arch/riscv/kernel/crash_dump.c      |  46 ++++++
>>>>  arch/riscv/kernel/crash_save_regs.S |  56 +++++++
>>>>  arch/riscv/kernel/kexec_relocate.S  | 222
>>>> ++++++++++++++++++++++++++++
>>>>  arch/riscv/kernel/machine_kexec.c   | 193 ++++++++++++++++++++++++
>>>>  arch/riscv/kernel/setup.c           | 113 ++++++++------
>>>>  arch/riscv/mm/init.c                | 110 ++++++++++++++
>>>>  include/uapi/linux/kexec.h          |   1 +
>>>>  11 files changed, 787 insertions(+), 45 deletions(-)
>>>>  create mode 100644 arch/riscv/include/asm/kexec.h
>>>>  create mode 100644 arch/riscv/kernel/crash_dump.c
>>>>  create mode 100644 arch/riscv/kernel/crash_save_regs.S
>>>>  create mode 100644 arch/riscv/kernel/kexec_relocate.S
>>>>  create mode 100644 arch/riscv/kernel/machine_kexec.c
>>> 
>>> Thanks.  There were some minor issues and some merge conflicts, I put
>>> this on for-next with some fixups.
>> 
>> I've sent a v4 that shouldn't have merge conflicts, addressing some
>> comments from Alex as well, could you use that instead or is it too 
>> late
>> ?
> 
> Thanks, for some reason I didn't see it when poking around.  There was
> still that one init_resources() merge conflict and I fixed up some of
> the commit texts, it's now on for-next as
> 
> b94394119804 (HEAD -> for-next, riscv/for-next) RISC-V: Add crash 
> kernel support
> 6e8451782c90 RISC-V: Add kdump support
> 0a0652429bdb RISC-V: Improve init_resources()
> d9a8897d6b5d RISC-V: Add kexec support
> f59938095b94 RISC-V: Add EM_RISCV to kexec UAPI header

Thanks a lot ! I'll keep on working on the user-space part and submit it 
on kexec-tools later on.