kexec, x86/boot: map systab region in identity mapping before accessing it
Subsystems (3)
Borislav Petkov
maintainerBreaking thread because this one got too big.
Quoted 2 lines · Kairui Song
There are two approach to fix it, detect if the systab is mapped, and avoid reading it if not.
Ok, so tglx and I discussed this situation which is slowly getting out of hand with all the tinkering.
So, here's what we should do - scream loudly now if some of this doesn't make any sense.
1. Junichi's patch should get the systab check above added and sent to 5.1 so that at least some EFI kexecing can work with 5.1
2. Then, the fact whether the kernel has been kexec'ed and which addresses it should use early, should all be passed through boot_params which is either setup by kexec(1) or by the first kernel itself, in the kexec_file_load() case.
Quoted 2 lines
the systab region is not mapped by the identity mapping provided by kexec.
3. Then that needs to be fixed in the first kernel as it is a shortcoming of us starting to parse systab very early. It is the kexec setup code's problem not the early compressed stage's problem that the EFI systab is not mapped.
Anything else I've forgotten? Anything I've misrepresented?
Thx.
Signature · 9 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexecQuoted 6 lines · Borislav Petkov
Breaking thread because this one got too big.
Quoted 2 lines · Kairui Song
There are two approach to fix it, detect if the systab is mapped, and avoid reading it if not.
Quoted 8 lines
Ok, so tglx and I discussed this situation which is slowly getting out of hand with all the tinkering.
So, here's what we should do - scream loudly now if some of this doesn't make any sense.
1. Junichi's patch should get the systab check above added and sent to 5.1 so that at least some EFI kexecing can work with 5.1
Talked with Kairui privately just now. Seems Junichi's patch need add this systab mapping. Since the systab region is not mapped on some machines. Those machine don't have this issue because they got systab region luckily coverred by 1 GB page mapping in 1st kernel before kexec jumping.
This issue should happen whether it is KASLR kernel or not KASLR kernel.
Quoted 5 lines
2. Then, the fact whether the kernel has been kexec'ed and which addresses it should use early, should all be passed through
boot_paramswhich is either setup by kexec(1) or by the first kernel itself, in thekexec_file_load()case.
Seems no better way to check if it's kexec-ed kernel, except of the setup data checking of kexec-ed kernel.
It may happen in both kexec_load or kexec_file_load, since we build ident mapping of kexec for RAM in 1st kernel.
Quoted 8 lines
Quoted 3 lines
the systab region is not mapped by the identity mapping provided by kexec.
3. Then that needs to be fixed in the first kernel as it is a shortcoming of us starting to parse systab very early. It is the kexec setup code's problem not the early compressed stage's problem that the EFI systab is not mapped.
Yeah, adding the systab mapping looks good. Kairui put it in decompressing stage just because he wants to cover the case in which the old kernel kexec jumping to 2nd kernel. Now it seems not very reasonable, we also have the new kernel kexec jumping to old 2nd kernel.
Thanks
Baoquan
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 40 lines · Baoquan He
Quoted 6 lines · Borislav Petkov
Breaking thread because this one got too big.
Quoted 2 lines · Kairui Song
There are two approach to fix it, detect if the systab is mapped, and avoid reading it if not.
Quoted 8 lines
Ok, so tglx and I discussed this situation which is slowly getting out of hand with all the tinkering.
So, here's what we should do - scream loudly now if some of this doesn't make any sense.
1. Junichi's patch should get the systab check above added and sent to 5.1 so that at least some EFI kexecing can work with 5.1
Talked with Kairui privately just now. Seems Junichi's patch need add this systab mapping. Since the systab region is not mapped on some machines. Those machine don't have this issue because they got systab region luckily coverred by 1 GB page mapping in 1st kernel before kexec jumping.
This issue should happen whether it is KASLR kernel or not KASLR kernel.
Quoted 5 lines
2. Then, the fact whether the kernel has been kexec'ed and which addresses it should use early, should all be passed through
boot_paramswhich is either setup by kexec(1) or by the first kernel itself, in thekexec_file_load()case.Seems no better way to check if it's kexec-ed kernel, except of the setup data checking of kexec-ed kernel.
It may happen in both
kexec_loadorkexec_file_load, since we build ident mapping of kexec for RAM in 1st kernel.Quoted 4 lines
Quoted 3 lines
the systab region is not mapped by the identity mapping provided by kexec.
Quoted 6 lines
Quoted 4 lines
3. Then that needs to be fixed in the first kernel as it is a shortcoming of us starting to parse systab very early. It is the kexec setup code's problem not the early compressed stage's problem that the EFI systab is not mapped.
Yeah, adding the systab mapping looks good. Kairui put it in
^ in 1st kernel
Quoted 6 lines
decompressing stage just because he wants to cover the case in which the old kernel kexec jumping to 2nd kernel. Now it seems not very reasonable, we also have the new kernel kexec jumping to old 2nd kernel.
Thanks
Baoquan
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 17 lines · Baoquan He
Quoted 6 lines · Borislav Petkov
Breaking thread because this one got too big.
Quoted 2 lines · Kairui Song
There are two approach to fix it, detect if the systab is mapped, and avoid reading it if not.
Quoted 8 lines
Ok, so tglx and I discussed this situation which is slowly getting out of hand with all the tinkering.
So, here's what we should do - scream loudly now if some of this doesn't make any sense.
1. Junichi's patch should get the systab check above added and sent to 5.1 so that at least some EFI kexecing can work with 5.1
Quoted 7 lines
Talked with Kairui privately just now. Seems Junichi's patch need add this systab mapping. Since the systab region is not mapped on some machines. Those machine don't have this issue because they got systab region luckily coverred by 1 GB page mapping in 1st kernel before kexec jumping.
This issue should happen whether it is KASLR kernel or not KASLR kernel.
Thanks for the declaration Bao, I can verify on the machine I have, the issue still exist without kaslr. Currently, we read rsdp in early code and fill in boot_params unconditional, so it will read from the systab anyway.
Quoted 7 lines
Quoted 6 lines
2. Then, the fact whether the kernel has been kexec'ed and which addresses it should use early, should all be passed through
boot_paramswhich is either setup by kexec(1) or by the first kernel itself, in thekexec_file_load()case.
Quoted 5 lines
Seems no better way to check if it's kexec-ed kernel, except of the setup data checking of kexec-ed kernel.
It may happen in both
kexec_loadorkexec_file_load, since we build ident mapping of kexec for RAM in 1st kernel.
For kexec_file_load newer kernel will fill in the acpi_rsdp in boot_params so it bypassed the kexec_get_rsdp_addr (which will read from systab). The problem is not fixed, systab mapping still missing, but not likely to happen with kexec_file_load on newer kernel.
Quoted 10 lines
Quoted 9 lines
Quoted 4 lines
the systab region is not mapped by the identity mapping provided by kexec.
3. Then that needs to be fixed in the first kernel as it is a shortcoming of us starting to parse systab very early. It is the kexec setup code's problem not the early compressed stage's problem that the EFI systab is not mapped.
Quoted 4 lines
Yeah, adding the systab mapping looks good. Kairui put it in decompressing stage just because he wants to cover the case in which the old kernel kexec jumping to 2nd kernel. Now it seems not very reasonable, we also have the new kernel kexec jumping to old 1nd kernel.
Yes, kexec only cover RAM in the ident map it prepared for second kernel, but the systab could be in reserved region, so if it didn't fall into the 1G padding by accident it will fail when reading from it. Fix in early code could make sure 2nd kernel always work. Or should we treat it specially in kexec mapping prepare code?
Quoted 3 lines
Thanks
Baoquan
--
Best Regards,
Kairui Song
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Borislav Petkov
maintainerQuoted 4 lines · Kairui Song
Thanks for the declaration Bao, I can verify on the machine I have, the issue still exist without kaslr. Currently, we read rsdp in early code and fill in
boot_paramsunconditional, so it will read from the systab anyway.
Yes, and in the future, info required by the kexec'ed kernel - like the EFI systab address or even whether the kernel has been kexec'ed or comes from cold boot - should be passed in boot_params. So that we don't have to do all that ugly dancing in early code.
Quoted 5 lines
Yes, kexec only cover RAM in the ident map it prepared for second kernel, but the systab could be in reserved region, so if it didn't fall into the 1G padding by accident it will fail when reading from it. Fix in early code could make sure 2nd kernel always work. Or should we treat it specially in kexec mapping prepare code?
Yes, we should. As I said, this is not early boot code's problem but the kexec setup code's problem.
If the new kernel cannot get RSDP that early, then it should fail the same way it failed before. That early RDSP parsing was added for the movable regions thing working with KASLR.
If it can't get a RDSP for whatever reason, then if KASLR selects a region overlapping with the movable regions, then it is the old behavior.
Ok?
Signature · 9 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexecQuoted 25 lines · Borislav Petkov
Quoted 4 lines · Kairui Song
Thanks for the declaration Bao, I can verify on the machine I have, the issue still exist without kaslr. Currently, we read rsdp in early code and fill in
boot_paramsunconditional, so it will read from the systab anyway.Yes, and in the future, info required by the kexec'ed kernel - like the EFI systab address or even whether the kernel has been kexec'ed or comes from cold boot - should be passed in
boot_params. So that we don't have to do all that ugly dancing in early code.Quoted 5 lines
Yes, kexec only cover RAM in the ident map it prepared for second kernel, but the systab could be in reserved region, so if it didn't fall into the 1G padding by accident it will fail when reading from it. Fix in early code could make sure 2nd kernel always work. Or should we treat it specially in kexec mapping prepare code?
Yes, we should. As I said, this is not early boot code's problem but the kexec setup code's problem.
If the new kernel cannot get RSDP that early, then it should fail the same way it failed before. That early RDSP parsing was added for the movable regions thing working with KASLR.
Quoted 6 lines
If it can't get a RDSP for whatever reason, then if KASLR selects a region overlapping with the movable regions, then it is the old behavior.
Ok?
OK. And then fix the mapping issue in 1st kernel is the right way, I'll skip the update for the early code mapping thing.
--
Best Regards,
Kairui Song
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Borislav Petkov
maintainerPATCH 1/1 x86/boot: Disable RSDP parsing temporarily
Ok,
thinking about this more, we believe it is too late in the release cycle to keep experimenting so the only thing left to do is the below.
This should bring the situation back to what it was before, at 5.0 times, and we'll have plenty of time now to address and properly fix all the outstanding issues.
---
From: Borislav Petkov <[email protected]>
The original intention to move RDSP parsing very early, before KASLR does its ranges selection, was to accommodate movable memory regions machines (CONFIG_MEMORY_HOTREMOVE) to still be able to do memory hotplug.
However, that broke kexec'ing a kernel on EFI machines because depending on where the EFI systab was mapped, on at least one machine it isn't present in the kexec mapping of the second kernel, leading to a triple fault in the early code.
Fixing this properly requires significantly involved surgery and we cannot allow ourselves to do that, that close to the merge window.
So disable the RSDP parsing code temporarily until it is fixed properly in the next release cycle.
--- arch/x86/boot/compressed/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/compressed/misc.c +1 -1
@@ -352,7 +352,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, boot_params->hdr.loadflags &= ~KASLR_FLAG ;/* Save RSDP address for later use. */ - boot_params->acpi_rsdp_addr =get_rsdp_addr (); +/* boot_params->acpi_rsdp_addr = get_rsdp_addr(); */ sanitize_boot_params (boot_params);
Signature · 13 lines
2.21.0
--
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexectip-bot for Borislav Petkov
merge bot[tip:x86/urgent] x86/boot: Disable RSDP parsing temporarily
x86/boot: Disable RSDP parsing temporarily
Commit-ID: 36f0c423552dacaca152324b8e9bda42a6d88865 Gitweb: https://git.kernel.org/tip/36f0c423552dacaca152324b8e9bda42a6d88865 Author: Borislav Petkov <[email protected]> AuthorDate: Fri, 19 Apr 2019 15:40:14 +0200 Committer: Borislav Petkov <[email protected]> CommitDate: Mon, 22 Apr 2019 11:36:43 +0200
x86/boot: Disable RSDP parsing temporarily
The original intention to move RDSP parsing very early, before KASLR does its ranges selection, was to accommodate movable memory regions machines (CONFIG_MEMORY_HOTREMOVE) to still be able to do memory hotplug.
However, that broke kexec'ing a kernel on EFI machines because depending on where the EFI systab was mapped, on at least one machine it isn't present in the kexec mapping of the second kernel, leading to a triple fault in the early code.
Fixing this properly requires significantly involved surgery and we cannot allow ourselves to do that, that close to the merge window.
So disable the RSDP parsing code temporarily until it is fixed properly in the next release cycle.
--- arch/x86/boot/compressed/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/boot/compressed/misc.c +1 -1
@@ -352,7 +352,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, boot_params->hdr.loadflags &= ~KASLR_FLAG ;/* Save RSDP address for later use. */ - boot_params->acpi_rsdp_addr =get_rsdp_addr (); +/* boot_params->acpi_rsdp_addr = get_rsdp_addr(); */ sanitize_boot_params (boot_params);
Borislav Petkov
maintainerQuoted 5 lines · Baoquan He
Talked with Kairui privately just now. Seems Junichi's patch need add this systab mapping. Since the systab region is not mapped on some machines. Those machine don't have this issue because they got systab region luckily coverred by 1 GB page mapping in 1st kernel before kexec jumping.
You don't have to repeat all I that - I know what the problem is. Read what I said again: it is too late for 5.1 to do any involved surgery.
Quoted 7 lines
Quoted 4 lines
2. Then, the fact whether the kernel has been kexec'ed and which addresses it should use early, should all be passed through
boot_paramswhich is either setup by kexec(1) or by the first kernel itself, in thekexec_file_load()case.Seems no better way to check if it's kexec-ed kernel, except of the setup data checking of kexec-ed kernel.
Why does that "seem" so?
Read again what I said: "should all be passed through boot_params". Which means, boot_params should be extended with a field of a flag to
say: "this is a kexec'ed kernel".
If it "seems" then it should be made to not "seem" but to work properly.
Quoted 4 lines
Yeah, adding the systab mapping looks good. Kairui put it in decompressing stage just because he wants to cover the case in which the old kernel kexec jumping to 2nd kernel. Now it seems not very reasonable, we also have the new kernel kexec jumping to old 2nd kernel.
I don't think we can guarantee kexec between old<->new kernel to always work. Otherwise, we can forget all development and improvements of new kernel.
Signature · 9 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexecBorislav Petkov
maintainerQuoted 3 lines · Borislav Petkov
Read again what I said: "should all be passed through
boot_params". Which means,boot_paramsshould be extended with a field of a flag to
say: "this is a kexec'ed kernel".
And by that I mean similar to the XLF_EFI_KEXEC mechanism. The first kernel or kexec(1) should prepare the info needed by the kexec'ed kernel.
Signature · 9 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexecQuoted 8 lines · Borislav Petkov
Quoted 3 lines · Borislav Petkov
Read again what I said: "should all be passed through
boot_params". Which means,boot_paramsshould be extended with a field of a flag to
say: "this is a kexec'ed kernel".And by that I mean similar to the
XLF_EFI_KEXECmechanism. The first kernel or kexec(1) should prepare the info needed by the kexec'ed kernel.
We have set the loader type to '0x0D << 4' for kexec specifically, in both kexec_load and kexec_file_load. We can check this to identify if it's kexec-ed kernel or not.
Update patch with it?
static void *bzImage64_load(struct kimage *image, char *kernel,
unsigned long kernel_len, char *initrd, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len)
{
...
/* bootloader info. Do we need a separate ID for kexec kernel loader? */
params->hdr.type_of_loader = 0x0D << 4;
...}
Borislav Petkov
maintainer+ hpa
Quoted 22 lines · Baoquan He
Quoted 8 lines · Borislav Petkov
Quoted 3 lines · Borislav Petkov
Read again what I said: "should all be passed through
boot_params". Which means,boot_paramsshould be extended with a field of a flag to
say: "this is a kexec'ed kernel".And by that I mean similar to the
XLF_EFI_KEXECmechanism. The first kernel or kexec(1) should prepare the info needed by the kexec'ed kernel.We have set the loader type to '
0x0D<< 4' for kexec specifically, in bothkexec_loadandkexec_file_load. We can check this to identify if it's kexec-ed kernel or not.Update patch with it?
static void *bzImage64_load(struct kimage *image, char *kernel,
unsigned longkernel_len, char *initrd, unsigned longinitrd_len, char *cmdline, unsigned longcmdline_len)
{
Quoted 3 lines
...
/* bootloader info. Do we need a separate ID for kexec kernel loader? */
params->hdr.type_of_loader = 0x0D << 4;That's already documented in Documentation/x86/boot.txt
Field name: type_of_loader Type: write (obligatory) Offset/size: 0x210/1 Protocol: 2.00+
...
D kexec-toolsAnd yes, the question in the code is still valid: do we need a separate ID.
I'd say no and we'll simply call 0xD all kernels loaded using a kexec-type syscall.
IMO.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Quoted 36 lines · Borislav Petkov
+ hpa
Quoted 22 lines · Baoquan He
Quoted 8 lines · Borislav Petkov
Quoted 3 lines · Borislav Petkov
Read again what I said: "should all be passed through
boot_params". Which means,boot_paramsshould be extended with a field of a flag to
say: "this is a kexec'ed kernel".And by that I mean similar to the
XLF_EFI_KEXECmechanism. The first kernel or kexec(1) should prepare the info needed by the kexec'ed kernel.We have set the loader type to '
0x0D<< 4' for kexec specifically, in bothkexec_loadandkexec_file_load. We can check this to identify if it's kexec-ed kernel or not.Update patch with it?
static void *bzImage64_load(struct kimage *image, char *kernel,
unsigned longkernel_len, char *initrd, unsigned longinitrd_len, char *cmdline, unsigned longcmdline_len)
{Quoted 3 lines
... /* bootloader info. Do we need a separate ID for kexec kernel loader? */ params->hdr.type_of_loader = 0x0D << 4;That's already documented in
Documentation/x86/boot.txtField name: type_of_loader Type: write (obligatory) Offset/size: 0x210/1 Protocol: 2.00+
Quoted 8 lines
... D kexec-toolsAnd yes, the question in the code is still valid: do we need a separate ID.
I'd say no and we'll simply call
0xDall kernels loaded using a kexec-type syscall.
Yes, agree. Time has proved we don't need a separate ID, just 0x0D is fine for both kexec/kdump. We can clear it away now.
I can make a patch to add a bit into xloadflags, to indicate that this is kexec-ed kernel. It can help to differentiate kexec-ed kernel from kdump kernel. As we know, kdump kernel is recognized with /proc/vmcore existence. While during kernel initialization stage, or /proc/vmcore is not validated in some cases, the adding bit may help.
Thoughts?
Thanks
Baoquan
Borislav Petkov
maintainerQuoted 3 lines · Baoquan He
I can make a patch to add a bit into xloadflags, to indicate that this is kexec-ed kernel. It can help to differentiate kexec-ed kernel from kdump kernel.
From the recent snafu, the only thing we needed is to differentiate between the *first* kernel and the following kernel(s) which has been started/loaded using a kexec syscall.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Quoted 8 lines · Borislav Petkov
Quoted 3 lines · Baoquan He
I can make a patch to add a bit into xloadflags, to indicate that this is kexec-ed kernel. It can help to differentiate kexec-ed kernel from kdump kernel.
From the recent snafu, the only thing we needed is to differentiate between the *first* kernel and the following kernel(s) which has been started/loaded using a kexec syscall.
OK. To make sure I got it, the loader type 0xD is enough for this, right?
It's fine to me, we can add it later if needed. I remember there's an issue in intel/amd iommu, in which we need differentiate between kexec/kdump kernel, but not very sure. I will check it when I have time to work on that.
Thanks
Baoquan
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 7 lines · Borislav Petkov
Why does that "seem" so?
Read again what I said: "should all be passed through
boot_params". Which means,boot_paramsshould be extended with a field of a flag to
say: "this is a kexec'ed kernel".If it "seems" then it should be made to not "seem" but to work properly.
No objection to extending with fields of a flag to mark kexec'ed kernel. Or kdump kernel either. We now check kdump kernel by /proc/vmcore.
Quoted 9 lines
Quoted 5 lines
Yeah, adding the systab mapping looks good. Kairui put it in decompressing stage just because he wants to cover the case in which the old kernel kexec jumping to 2nd kernel. Now it seems not very reasonable, we also have the new kernel kexec jumping to old 2nd kernel.
I don't think we can guarantee kexec between old<->new kernel to always work. Otherwise, we can forget all development and improvements of new kernel.
I personally agree with this. Very earlier, we tried to remove the 896 MB limitation of crashkernel=xM, to extend it to 4G or the whole RAM, but rejcted by linus since he worried it could break the old kernel kdumping. I may not remember well.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec