From: Marc Zyngier <maz@kernel.org> Date: 2021-05-26 19:05:47
This series is a complete departure from the approach I initially sent
almost a month ago[1]. Instead of trying to teach EFI, ACPI and other
subsystem to use memblock, I've decided to stick with the iomem
resource tree and use that exclusively for arm64.
This means that my current approach is (despite what I initially
replied to both Dave and Catalin) to provide an arm64-specific
implementation of arch_kexec_locate_mem_hole() which walks the
resource tree and excludes ranges of RAM that have been registered for
any odd purpose. This is exactly what the userspace implementation
does, and I don't really see a good reason to diverge from it.
Again, this allows my Synquacer board to reliably use kexec_file_load
with as little as 256M, something that would always fail before as it
would overwrite most of the reserved tables.
Obviously, this is now at least 5.14 material. Given how broken
kexec_file_load is for non-crash kernels on arm64 at the moment,
should we at least disable it in 5.13 and all previous stable kernels?
Thanks,
M.
[1] https://lore.kernel.org/r/20210429133533.1750721-1-maz@kernel.org
Marc Zyngier (4):
kexec_file: Make locate_mem_hole_callback global
kernel/resource: Populate child pointer in find_next_iomem_res()
kernel/resource: Add walk_excluding_child_res() helper
arm64: kexec_image: Implement arch_kexec_locate_mem_hole()
arch/arm64/kernel/kexec_image.c | 45 ++++++++++++++++++
include/linux/ioport.h | 4 ++
include/linux/kexec.h | 1 +
kernel/kexec_file.c | 6 +--
kernel/resource.c | 81 +++++++++++++++++++++++++++++++++
5 files changed, 134 insertions(+), 3 deletions(-)
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Marc Zyngier <maz@kernel.org> Date: 2021-05-26 19:05:52
In order for architectures to make use of locate_mem_hole_callback()
and avoid reinventing a square wheel, make this function global
and rename it to kexec_locate_mem_hole_callback() to match the
other global kexec symbols.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
include/linux/kexec.h | 1 +
kernel/kexec_file.c | 6 +++---
2 files changed, 4 insertions(+), 3 deletions(-)
@@ -517,7 +517,7 @@ static int locate_mem_hole_bottom_up(unsigned long start, unsigned long end,return1;}-staticintlocate_mem_hole_callback(structresource*res,void*arg)+intkexec_locate_mem_hole_callback(structresource*res,void*arg){structkexec_buf*kbuf=(structkexec_buf*)arg;u64start=res->start,end=res->end;
@@ -634,9 +634,9 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf)return0;if(!IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK))-ret=kexec_walk_resources(kbuf,locate_mem_hole_callback);+ret=kexec_walk_resources(kbuf,kexec_locate_mem_hole_callback);else-ret=kexec_walk_memblock(kbuf,locate_mem_hole_callback);+ret=kexec_walk_memblock(kbuf,kexec_locate_mem_hole_callback);returnret==1?0:-EADDRNOTAVAIL;}
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Marc Zyngier <maz@kernel.org> Date: 2021-05-26 19:05:58
When find_next_iomem_res() returns a resource, it doesn't
populate the child pointer (but does so with the parent).
As we are about to need to arse child resources, populate
this pointer as well.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
kernel/resource.c | 1 +
1 file changed, 1 insertion(+)
From: Marc Zyngier <maz@kernel.org> Date: 2021-05-26 19:06:01
Once we have obtained a resource of a certain type from
find_next_iomem_res(), it doesn't necessarily mean that the whole
resource is usable, and we have cases where a child resource
denotes an exclusion in the initial resource.
Provide a new walker that deals with this exact case, and calls
a callback on each resource fragment that doesn't have a child.
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
include/linux/ioport.h | 4 +++
kernel/resource.c | 80 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+)
@@ -318,6 +318,86 @@ int release_resource(struct resource *old)EXPORT_SYMBOL(release_resource);+/**+*walk_excluding_child_res-callacallbackfunctiononeachfragmentof+*aresourcethatdonothaveachildresource+*+*@res:therootresourcecontainingtheinitialrange+*@arg:functionargumentforthecallback@func+*@func:callbackfunctionthatiscalledforeachqualifyingresourcearea+*+*Foragivenresource,removeallthechildresourcesandfeedthe+*resultingfragmentstokexec_locate_mem_hole_callback().+*/+intwalk_excluding_child_res(structresource*res,void*arg,+int(*func)(structresource*,void*))+{+structresource*tmp,cursor;+intret=0;++cursor=*res;++/* Use .child for the head of the list, .sibling for the tail */+cursor.child=cursor.sibling=NULL;++read_lock(&resource_lock);++for(tmp=res->child;tmp;tmp=tmp->sibling){+structresource*new;++if(cursor.start<tmp->start){+new=kmalloc(sizeof(*new),GFP_KERNEL);+if(!new)+gotocleanup;++*new=(structresource){+.start=cursor.start,+.end=tmp->start-1,+.flags=res->flags,+.desc=res->desc,+.parent=res->parent,+};++if(!cursor.child)+cursor.child=new;+if(cursor.sibling)+cursor.sibling->sibling=new;+cursor.sibling=new;+}++/*+*Thismayresultinaresourcewithanegativesize+*attheveryendoftheloop.+*/+cursor.start=tmp->end+1;+}++read_unlock(&resource_lock);++/*+*Atthisstage,thelistpointedtobycursor.childcontains+*everynon-reservedblocks,completedby'cursor'which+*containsthepotentiallastblock(maybeempty).+*/+for(tmp=cursor.child;tmp;tmp=tmp->sibling){+ret=func(tmp,arg);+if(ret)+break;+}++if(!ret&&cursor.start<=cursor.end)+ret=func(&cursor,tmp);++cleanup:+while(cursor.child){+tmp=cursor.child;+cursor.child=cursor.child->sibling;+kfree(tmp);+}++returnret;+}+/***find_next_iomem_res-Findsthelowestiomemresourcethatcoverspartof*[@start..@end].
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Marc Zyngier <maz@kernel.org> Date: 2021-05-26 19:06:03
Provide an arm64-specific implementation for arch_kexec_locate_mem_hole(),
using the resource tree instead of memblock, and respecting
the reservations added by EFI.
This ensures that kexec_file is finally reliable.
Reported-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/kernel/kexec_image.c | 45 +++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
On Wed, May 26, 2021 at 08:05:29PM +0100, Marc Zyngier wrote:
When find_next_iomem_res() returns a resource, it doesn't
populate the child pointer (but does so with the parent).
As we are about to need to arse child resources, populate
this pointer as well.
On Wed, May 26, 2021 at 08:05:31PM +0100, Marc Zyngier wrote:
Provide an arm64-specific implementation for arch_kexec_locate_mem_hole(),
using the resource tree instead of memblock, and respecting
the reservations added by EFI.
This ensures that kexec_file is finally reliable.
Reported-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
It would have been clearer if __walk_iomem_res_desc() was able to do
such child res excluding callback (if asked via a new flag/arg) directly
but it's too late in the day to figure out if it's possible. It would
save us from another callback in the arch code. But if it's not possible
or you want to stick to this approach, fine by me:
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
--
Catalin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Wed, May 26, 2021 at 08:05:27PM +0100, Marc Zyngier wrote:
This series is a complete departure from the approach I initially sent
almost a month ago[1]. Instead of trying to teach EFI, ACPI and other
subsystem to use memblock, I've decided to stick with the iomem
resource tree and use that exclusively for arm64.
This means that my current approach is (despite what I initially
replied to both Dave and Catalin) to provide an arm64-specific
implementation of arch_kexec_locate_mem_hole() which walks the
resource tree and excludes ranges of RAM that have been registered for
any odd purpose. This is exactly what the userspace implementation
does, and I don't really see a good reason to diverge from it.
Again, this allows my Synquacer board to reliably use kexec_file_load
with as little as 256M, something that would always fail before as it
would overwrite most of the reserved tables.
Obviously, this is now at least 5.14 material. Given how broken
kexec_file_load is for non-crash kernels on arm64 at the moment,
should we at least disable it in 5.13 and all previous stable kernels?
I think it makes sense to disable it in the current and earlier kernels.
For this series:
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Marc Zyngier <maz@kernel.org> Date: 2021-05-28 08:06:55
On Thu, 27 May 2021 17:53:56 +0100,
Catalin Marinas [off-list ref] wrote:
On Wed, May 26, 2021 at 08:05:29PM +0100, Marc Zyngier wrote:
quoted
When find_next_iomem_res() returns a resource, it doesn't
populate the child pointer (but does so with the parent).
As we are about to need to arse child resources, populate
this pointer as well.
Did you mean "parse"? ;)
This is so embarrassing... :-/ Let me fix that right now.
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Marc Zyngier <maz@kernel.org> Date: 2021-05-28 09:06:13
On Thu, 27 May 2021 18:37:37 +0100,
Catalin Marinas [off-list ref] wrote:
On Wed, May 26, 2021 at 08:05:31PM +0100, Marc Zyngier wrote:
quoted
Provide an arm64-specific implementation for arch_kexec_locate_mem_hole(),
using the resource tree instead of memblock, and respecting
the reservations added by EFI.
This ensures that kexec_file is finally reliable.
Reported-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
It would have been clearer if __walk_iomem_res_desc() was able to do
such child res excluding callback (if asked via a new flag/arg) directly
but it's too late in the day to figure out if it's possible. It would
save us from another callback in the arch code.
Yeah, that should be possible with some minor refactoring of the
generic and x86 code, allowing us to get rid of the double arch
callback circus.
It would also make the locking a bit saner, but also change it for all
the callers... I'll have a play with it.
But if it's not possible or you want to stick to this approach, fine
by me:
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Thu, 27 May 2021 at 19:39, Catalin Marinas [off-list ref] wrote:
On Wed, May 26, 2021 at 08:05:27PM +0100, Marc Zyngier wrote:
quoted
This series is a complete departure from the approach I initially sent
almost a month ago[1]. Instead of trying to teach EFI, ACPI and other
subsystem to use memblock, I've decided to stick with the iomem
resource tree and use that exclusively for arm64.
This means that my current approach is (despite what I initially
replied to both Dave and Catalin) to provide an arm64-specific
implementation of arch_kexec_locate_mem_hole() which walks the
resource tree and excludes ranges of RAM that have been registered for
any odd purpose. This is exactly what the userspace implementation
does, and I don't really see a good reason to diverge from it.
Again, this allows my Synquacer board to reliably use kexec_file_load
with as little as 256M, something that would always fail before as it
would overwrite most of the reserved tables.
Obviously, this is now at least 5.14 material. Given how broken
kexec_file_load is for non-crash kernels on arm64 at the moment,
should we at least disable it in 5.13 and all previous stable kernels?
I think it makes sense to disable it in the current and earlier kernels.
Ack to that
For this series:
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
and likewise for the series
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel