add reserved e820 ranges to the kdump kernel e820 table
Subsystems (3)
v3 cover add reserved e820 ranges to the kdump kernel e820 table
E820 reserved ranges is useful in kdump kernel, we have added this in kexec-tools code.
One reason is PCI mmconf (extended mode) requires reserved region otherwise it falls back to legacy mode.
Furthermore, when AMD SME kdump support, it needs to map dmi table area as unencrypted. For normal boot, these ranges sit in e820 reserved ranges, thus the early ioremap code naturally map them as unencrypted. If we also have same e820 reserve setup in kdump kernel then it will just work like normal kernel.
Kdump uses walk_iomem_res_desc to iterate resources, then adds matched desc to e820 table for the kdump kernel.
But IORES_DESC_NONE resource type includes several different e820 types, we need add exact e820 type to the kdump kernel e820 table, thus it also needs an extra checking in memmap_entry_callback() to match the e820 type and resource name.
By the way, we also fix an error which walks through iomem resources, the values of the function parameter may be modified in the while loop of __walk_iomem_res_desc(), which will cause us to not get the desired result in some cases.
Changes since v2:
1. Modified the value of flags to "0", when walking through the whole tree for e820 reserved ranges.
2. Modified the invalid SOB chain issue.
Lianbo Jiang (3):
resource: fix an error which walks through iomem resources x86/kexec_file: add e820 entry in case e820 type string matches to io
resource name
x86/kexec_file: add reserved e820 ranges to kdump kernel e820 table
arch/x86/include/asm/e820/api.h | 2 ++ arch/x86/kernel/crash.c | 11 ++++++++++- arch/x86/kernel/e820.c | 2 +- kernel/resource.c | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/3 resource: fix an error which walks through iomem resources
When we walk through iomem resources by calling walk_iomem_res_desc(), the values of the function parameter may be modified in the while loop of __walk_iomem_res_desc(), which will cause us to not get the desired result in some cases.
At present, it only restores the original value of res->end, but it doesn't restore the original value of res->flags in the while loop of __walk_iomem _res_desc(). Whenever the find_next_iomem_res() finds a resource and returns the result, the original values of this resource will be modified, which might lead to an error in the next loop. For example:
The original value of resource flags is:
res->flags=0x80000200(initial value)
p->flags _ 0x81000200 _ _ 0x80000200 _
/ \ / \ |________|_______A________|____|_....._|______B_________|..........___| 0 0xffffffff
(memory address ranges)
Note: if ((p->flags & res->flags) != res->flags) continue;
When the resource A is found, the original value of this resource flags will be changed to 0x81000200(res->flags=0x81000200), and continue to look for the next resource, when the loop reaches resource B, it can not get the resource B any more(you can refer to the for loop of find_next _iomem_res()), because the value of conditional expression will become true and will also jump the resource B.
In fact, we should get the resource A and B when we walk through the whole tree, but it only gets the resource A, the resource B is missed.
--- kernel/resource.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/resource.c +2 -0
@@ -375,6 +375,7 @@ static int __walk_iomem_res_desc(struct resource *res, unsigned long desc, int (*func)(struct resource *, void *)) {u64 orig_end = res->end; +u64 orig_flags = res->flags;int ret =-1 ; while ((res->start < res->end) &&
@@ -385,6 +386,7 @@ static int __walk_iomem_res_desc(struct resource *res, unsigned long desc, res->start = res->end +1 ; res->end = orig_end; + res->flags = orig_flags; }return ret;
Signature · 1 line
2.17.1
Re: [PATCH 1/3 v3] resource: fix an error which walks through iomem resources
Quoted 4 lines · Lianbo Jiang
When we walk through iomem resources by calling
walk_iomem_res_desc(), the values of the function parameter may be modified in the while loop of__walk_iomem_res_desc(), which will cause us to not get the desired result in some cases.
If I understand correctly, the issue is caused by the interaction between __walk_iomem_res_desc() and find_next_iomem_res() in this path:
__walk_iomem_res_desc
find_next_iomem_res
res->flags = p->flags; # <-- problemThis path is used by the following interfaces, and I think your patch would fix the issue for them:
walk_iomem_res_desc()
walk_system_ram_res()
walk_mem_res()
However, find_next_iomem_res() is also used directly by walk_system_ram_range(). I think that path has the same problem, and your patch does not fix that path.
I have a few more comments related to the existing code that I'll post soon.
Quoted 53 lines
At present, it only restores the original value of
res->end, but it doesn't restore the original value ofres->flagsin the while loop of__walk_iomem_res_desc(). Whenever thefind_next_iomem_res()finds a resource and returns the result, the original values of this resource will be modified, which might lead to an error in the next loop. For example:The original value of resource flags is:
res->flags=0x80000200(initial value)
p->flags_0x81000200_ _0x80000200_/ \ / \ |________|_______A________|____|_....._|______B_________|..........___| 0 0xffffffff(memory address ranges)
Note: if ((
p->flags&res->flags) !=res->flags) continue;When the resource A is found, the original value of this resource flags will be changed to 0x81000200(res->flags=0x81000200), and continue to look for the next resource, when the loop reaches resource B, it can not get the resource B any
more(you can refer to the for loop of find_next _iomem_res()), because the value of conditional expression will become true and will also jump the resource B.In fact, we should get the resource A and B when we walk through the whole tree, but it only gets the resource A, the resource B is missed.
Signed-off-by Lianbo Jiang <[email protected]>--- kernel/resource.c | 2 ++ 1 file changed, 2 insertions(+)kernel/resource.c +2
-0@@ -375,6 +375,7 @@ static int __walk_iomem_res_desc(struct resource *res, unsigned long desc, int (*func)(struct resource *, void *)) {u64 orig_end = res->end; +u64 orig_flags = res->flags;int ret =-1 ; while ((res->start < res->end) &&@@ -385,6 +386,7 @@ static int __walk_iomem_res_desc(struct resource *res, unsigned long desc, res->start = res->end +1 ; res->end = orig_end; + res->flags = orig_flags; }return ret;
Re: [PATCH 1/3 v3] resource: fix an error which walks through iomem resources
Quoted 17 lines · Bjorn Helgaas
Quoted 4 lines · Lianbo Jiang
When we walk through iomem resources by calling
walk_iomem_res_desc(), the values of the function parameter may be modified in the while loop of__walk_iomem_res_desc(), which will cause us to not get the desired result in some cases.If I understand correctly, the issue is caused by the interaction between
__walk_iomem_res_desc()andfind_next_iomem_res()in this path:
__walk_iomem_res_descfind_next_iomem_res res->flags = p->flags; # <-- problemThis path is used by the following interfaces, and I think your patch would fix the issue for them:
Quoted 8 lines
walk_iomem_res_desc()
walk_system_ram_res()
walk_mem_res()However,
find_next_iomem_res()is also used directly bywalk_system_ram_range(). I think that path has the same problem, and your patch does not fix that path.
Thanks for your comment.
Originally, my patch 1 only fixed this issue in kdump path, of course, i can also improve this patch and fix the same issue in walk_system_ram_range(). If you have fixed this issue, it's good to me.
Quoted 56 lines
I have a few more comments related to the existing code that I'll post soon.
Quoted 53 lines
At present, it only restores the original value of
res->end, but it doesn't restore the original value ofres->flagsin the while loop of__walk_iomem_res_desc(). Whenever thefind_next_iomem_res()finds a resource and returns the result, the original values of this resource will be modified, which might lead to an error in the next loop. For example:The original value of resource flags is:
res->flags=0x80000200(initial value)
p->flags_0x81000200_ _0x80000200_/ \ / \ |________|_______A________|____|_....._|______B_________|..........___| 0 0xffffffff(memory address ranges)
Note: if ((
p->flags&res->flags) !=res->flags) continue;When the resource A is found, the original value of this resource flags will be changed to 0x81000200(res->flags=0x81000200), and continue to look for the next resource, when the loop reaches resource B, it can not get the resource B any
more(you can refer to the for loop of find_next _iomem_res()), because the value of conditional expression will become true and will also jump the resource B.In fact, we should get the resource A and B when we walk through the whole tree, but it only gets the resource A, the resource B is missed.
Signed-off-by Lianbo Jiang <[email protected]>--- kernel/resource.c | 2 ++ 1 file changed, 2 insertions(+)kernel/resource.c +2
-0@@ -375,6 +375,7 @@ static int __walk_iomem_res_desc(struct resource *res, unsigned long desc, int (*func)(struct resource *, void *)) {u64 orig_end = res->end; +u64 orig_flags = res->flags;int ret =-1 ; while ((res->start < res->end) &&@@ -385,6 +386,7 @@ static int __walk_iomem_res_desc(struct resource *res, unsigned long desc, res->start = res->end +1 ; res->end = orig_end; + res->flags = orig_flags; }return ret;
cover find_next_iomem_res() fixes
In reply to Lianbo JiangHi Lianbo,
These three patches are a possible replacement for your first patch ("[PATCH 1/3 v3] resource: fix an error which walks through iomem resources").
I think the interface of find_next_iomem_res() can be improved to make the code easier to read and also avoid the errors you're fixing.
I can't test these, so they've only been compiled. If you can test them and if you like them, feel free to incorporate them into your series. If not, just drop them (but please at least fix the same error in walk_system_ram_range()).
---
Bjorn Helgaas (3):
x86/kexec: Correct KEXEC_BACKUP_SRC_END off-by-one error
resource: Include resource end in walk_*() interfaces
resource: Fix find_next_iomem_res() iteration issue
arch/x86/include/asm/kexec.h | 2 - kernel/resource.c | 96 ++++++++++++++++++------------------------ 2 files changed, 43 insertions(+), 55 deletions(-)
PATCH 1/3 x86/kexec: Correct KEXEC_BACKUP_SRC_END off-by-one error
From: Bjorn Helgaas <[email protected]>
The only use of KEXEC_BACKUP_SRC_END is as an argument to walk_system_ram_res():
int crash_load_segments(struct kimage *image)
{
...
walk_system_ram_res(KEXEC_BACKUP_SRC_START, KEXEC_BACKUP_SRC_END,
image, determine_backup_region);walk_system_ram_res() expects "start, end" arguments that are inclusive, i.e., the range to be walked includes both the start and end addresses.
KEXEC_BACKUP_SRC_END was previously defined as (640 * 1024UL), which is the first address *past* the desired 0-64KB range.
Define KEXEC_BACKUP_SRC_END as (640 * 1024UL - 1) so the KEXEC_BACKUP_SRC region is [0-0xffff], not [0-0x10000].
--- arch/x86/include/asm/kexec.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/kexec.h +1 -1
@@ -67,7 +67,7 @@ struct kimage;/* Memory to backup during crash kdump */ #define KEXEC_BACKUP_SRC_START (0UL) -#define KEXEC_BACKUP_SRC_END (640 * 1024UL)/* 640K */ +#define KEXEC_BACKUP_SRC_END (640 * 1024UL - 1)/* 640K */ /* * CPU does not save ss and sp on stack if execution is already
PATCH 2/3 resource: Include resource end in walk_*() interfaces
In reply to Bjorn HelgaasFrom: Bjorn Helgaas <[email protected]>
find_next_iomem_res() finds an iomem resource that covers part of a range described by "start, end". All callers expect that range to be inclusive, i.e., both start and end are included, but find_next_iomem_res() doesn't handle the end address correctly.
If it finds an iomem resource that contains exactly the end address, it skips it, e.g., if "start, end" is [0x0-0x10000] and there happens to be an iomem resource [mem 0x10000-0x10000] (the single byte at 0x10000), we skip it:
find_next_iomem_res(...)
{
start = 0x0;
end = 0x10000;
for (p = next_resource(...)) {
# p->start = 0x10000;
# p->end = 0x10000;
# we *should* return this resource, but this condition is false:
if ((p->end >= start) && (p->start < end))
break;Adjust find_next_iomem_res() so it allows a resource that includes the single byte at the end of the range. This is a corner case that we probably don't see in practice.
--- kernel/resource.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/resource.c +2 -2
@@ -319,7 +319,7 @@ int release_resource(struct resource *old)EXPORT_SYMBOL (release_resource);/* -* Finds the lowest iomem resource existing within [res->start.res->end). +* Finds the lowest iomem resource existing within [res->start..res->end]. * The caller must specify res->start, res->end, res->flags, and optionally * desc. If found, returns 0, res is overwritten, if not found, returns -1. * This function walks the whole tree and not just first level children until
@@ -352,7 +352,7 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc, p =NULL ;break ; } -if ((p->end >= start) && (p->start < end)) +if ((p->end >= start) && (p->start <= end))break ; }
PATCH 3/3 resource: Fix find_next_iomem_res() iteration issue
In reply to Bjorn HelgaasFrom: Bjorn Helgaas <[email protected]>
Previously find_next_iomem_res() used "*res" as both an input parameter for the range to search and the type of resource to search for, and an output parameter for the resource we found, which makes the interface confusing and hard to use correctly.
All callers allocate a single struct resource and use it for repeated calls to find_next_iomem_res(). When find_next_iomem_res() returns a resource, it overwrites the start, end, flags, and desc members of the struct. If we call find_next_iomem_res() again, we must update or restore these fields.
The callers (__walk_iomem_res_desc() and walk_system_ram_range()) do not restore res->flags, so if the caller is searching for flags of IORESOURCE_MEM | IORESOURCE_BUSY and finds a resource with flags of IORESOURCE_MEM | IORESOURCE_BUSY | IORESOURCE_SYSRAM, the next search will find only resources marked as IORESOURCE_SYSRAM.
Fix this by restructuring the interface so it takes explicit "start, end, flags" parameters and uses "*res" only as an output parameter.
Original-patch: http://lore.kernel.org/lkml/[email protected]
--- kernel/resource.c | 94 +++++++++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 53 deletions(-)
kernel/resource.c +41 -53
@@ -319,23 +319,26 @@ int release_resource(struct resource *old)EXPORT_SYMBOL (release_resource);/* -* Finds the lowest iomem resource existing within [res->start..res->end]. -* The caller must specify res->start, res->end, res->flags, and optionally -* desc. If found, returns 0, res is overwritten, if not found, returns -1. -* This function walks the whole tree and not just first level children until -* and unless first_level_children_only is true. +* Finds the lowest iomem resource that covers part of [start..end]. The +* caller must specify start, end, flags, and desc (which may be +* IORES_DESC_NONE). +* +* If a resource is found, returns 0 and *res is overwritten with the part +* of the resource that's within [start..end]; if none is found, returns +* -1. +* +* This function walks the whole tree and not just first level children +* unless first_level_children_only is true. */ -static int find_next_iomem_res (struct resource *res,unsigned long desc, -bool first_level_children_only) +static int find_next_iomem_res (resource_size_t start,resource_size_t end, +unsigned long flags,unsigned long desc, +bool first_level_children_only, +struct resource *res) { -resource_size_t start, end;struct resource *p;bool sibling_only = false;BUG_ON (!res); - - start = res->start; - end = res->end;BUG_ON (start >= end);if (first_level_children_only)
@@ -344,7 +347,7 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc,read_lock (&resource_lock);for (p = iomem_resource.child; p; p =next_resource (p, sibling_only)) { -if ((p->flags & res->flags) != res->flags) +if ((p->flags & flags) != flags)continue ;if ((desc !=IORES_DESC_NONE ) && (desc != p->desc))continue ;
@@ -359,32 +362,31 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc,read_unlock (&resource_lock);if (!p)return -1 ; +/* copy data */ -if (res->start < p->start) - res->start = p->start; -if (res->end > p->end) - res->end = p->end; + res->start =max (start, p->start); + res->end =min (end, p->end); res->flags = p->flags; res->desc = p->desc;return 0 ; } -static int __walk_iomem_res_desc (struct resource *res,unsigned long desc, -bool first_level_children_only, -void *arg, +static int __walk_iomem_res_desc (resource_size_t start,resource_size_t end, +unsigned long flags,unsigned long desc, +bool first_level_children_only,void *arg,int (*func)(struct resource *,void *)) { -u64 orig_end = res->end; +struct resource res;int ret =-1 ; -while ((res->start < res->end) && - !find_next_iomem_res (res, desc, first_level_children_only)) { - ret = (*func)(res, arg); +while (start < end && + !find_next_iomem_res (start, end, flags, desc, + first_level_children_only, &res)) { + ret = (*func)(&res, arg);if (ret)break ; - res->start = res->end +1 ; - res->end = orig_end; + start = res.end +1 ; }return ret;
@@ -407,13 +409,7 @@ static int __walk_iomem_res_desc(struct resource *res, unsigned long desc,int walk_iomem_res_desc (unsigned long desc,unsigned long flags,u64 start,u64 end,void *arg,int (*func)(struct resource *,void *)) { -struct resource res; - - res.start = start; - res.end = end; - res.flags = flags; - -return __walk_iomem_res_desc (&res, desc, false, arg, func); +return __walk_iomem_res_desc (start, end, flags, desc, false, arg, func); }EXPORT_SYMBOL_GPL (walk_iomem_res_desc);
@@ -427,13 +423,9 @@ EXPORT_SYMBOL_GPL(walk_iomem_res_desc);int walk_system_ram_res (u64 start,u64 end,void *arg,int (*func)(struct resource *,void *)) { -struct resource res; - - res.start = start; - res.end = end; - res.flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; +unsigned long flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; -return __walk_iomem_res_desc (&res,IORES_DESC_NONE , true, +return __walk_iomem_res_desc (start, end, flags,IORES_DESC_NONE , true, arg, func); }
@@ -444,13 +436,9 @@ int walk_system_ram_res(u64 start, u64 end, void *arg,int walk_mem_res (u64 start,u64 end,void *arg,int (*func)(struct resource *,void *)) { -struct resource res; - - res.start = start; - res.end = end; - res.flags =IORESOURCE_MEM |IORESOURCE_BUSY ; +unsigned long flags =IORESOURCE_MEM |IORESOURCE_BUSY ; -return __walk_iomem_res_desc (&res,IORES_DESC_NONE , true, +return __walk_iomem_res_desc (start, end, flags,IORES_DESC_NONE , true, arg, func); }
@@ -464,25 +452,25 @@ int walk_mem_res(u64 start, u64 end, void *arg,int walk_system_ram_range (unsigned long start_pfn,unsigned long nr_pages,void *arg,int (*func)(unsigned long ,unsigned long ,void *)) { +resource_size_t start, end; +unsigned long flags;struct resource res;unsigned long pfn, end_pfn; -u64 orig_end;int ret =-1 ; - res.start = (u64 ) start_pfn <<PAGE_SHIFT ; - res.end = ((u64)(start_pfn + nr_pages) <<PAGE_SHIFT ) -1 ; - res.flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; - orig_end = res.end; -while ((res.start < res.end) && - (find_next_iomem_res (&res,IORES_DESC_NONE , true) >=0 )) { + start = (u64 ) start_pfn <<PAGE_SHIFT ; + end = ((u64)(start_pfn + nr_pages) <<PAGE_SHIFT ) -1 ; + flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; +while (start < end && + !find_next_iomem_res (start, end, flags,IORES_DESC_NONE , + true, &res)) { pfn = (res.start +PAGE_SIZE -1 ) >>PAGE_SHIFT ; end_pfn = (res.end +1 ) >>PAGE_SHIFT ;if (end_pfn > pfn) ret = (*func)(pfn, end_pfn - pfn, arg);if (ret)break ; - res.start = res.end +1 ; - res.end = orig_end; + start = res.end +1 ; }return ret; }
Re: [PATCH 3/3] resource: Fix find_next_iomem_res() iteration issue
Hi Bjorn,
kernel/resource.c static int find_next_iomem_res(struct resource *res, unsigned long desc, · line 369
Quoted 13 lines · Bjorn Helgaas
kernel/resource.c +3
-4@@ -359,32 +362,31 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc,read_unlock (&resource_lock);if (!p)return -1 ; +/* copy data */ -if (res->start < p->start) - res->start = p->start; -if (res->end > p->end) - res->end = p->end; + res->start =max (start, p->start); + res->end =min (end, p->end); res->flags = p->flags;
I think this fix is good. However, is it OK to keep res->flags always, never touch it in find_next_iomem_res()? We just iterate and update region, its start and end. So just removing that "res->flags = p->flags;" line might involve much less code changes.
Thanks
Baoquan
Re: [PATCH 3/3] resource: Fix find_next_iomem_res() iteration issue
Quoted 13 lines · Baoquan He
Hi Bjorn,
Quoted 10 lines · Bjorn Helgaas
kernel/resource.c +1
-4@@ -359,32 +362,31 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc,read_unlock (&resource_lock);if (!p)return -1 ; +/* copy data */ -if (res->start < p->start) - res->start = p->start; -if (res->end > p->end) - res->end = p->end;
Quoted 8 lines
kernel/resource.c static int find_next_iomem_res(struct resource *res, unsigned long desc, · line 369
Quoted 3 lines
kernel/resource.c +2
-0+ res->start =max (start, p->start); + res->end =min (end, p->end); res->flags = p->flags;I think this fix is good. However, is it OK to keep
res->flagsalways, never touch it infind_next_iomem_res()? We just iterate and update region, its start and end. So just removing that "res->flags=p->flags;" line might involve much less code changes.
Rethink about it, I was wrong. Please ignore my comment.
Re: [PATCH 3/3] resource: Fix find_next_iomem_res() iteration issue
In reply to Bjorn HelgaasQuoted 12 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Previously
find_next_iomem_res()used "*res" as both an input parameter for the range to search and the type of resource to search for, and an output parameter for the resource we found, which makes the interface confusing and hard to use correctly.All callers allocate a single struct resource and use it for repeated calls to
find_next_iomem_res(). Whenfind_next_iomem_res()returns a resource, it overwrites the start, end, flags, and desc members of the struct. If we callfind_next_iomem_res()again, we must update or restore these fields.
Quoted 9 lines
The callers (
__walk_iomem_res_desc()andwalk_system_ram_range()) do not restoreres->flags, so if the caller is searching for flags ofIORESOURCE_MEM|IORESOURCE_BUSYand finds a resource with flags ofIORESOURCE_MEM|IORESOURCE_BUSY|IORESOURCE_SYSRAM, the next search will find only resources marked asIORESOURCE_SYSRAM.Fix this by restructuring the interface so it takes explicit "start, end, flags" parameters and uses "*res" only as an output parameter.
Hi, Bjorn
I personally suggest that some comments might be added in the code, make it clear and easy to understand, then which could avoid the old confusion and more code changes.
Thanks
Lianbo
Quoted 192 lines
Original-patch: http://lore.kernel.org/lkml/[email protected]
Based-on-patch-by Lianbo Jiang <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>--- kernel/resource.c | 94 +++++++++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 53 deletions(-)kernel/resource.c +41
-53@@ -319,23 +319,26 @@ int release_resource(struct resource *old)EXPORT_SYMBOL (release_resource);/* -* Finds the lowest iomem resource existing within [res->start..res->end]. -* The caller must specify res->start, res->end, res->flags, and optionally -* desc. If found, returns 0, res is overwritten, if not found, returns -1. -* This function walks the whole tree and not just first level children until -* and unless first_level_children_only is true. +* Finds the lowest iomem resource that covers part of [start..end]. The +* caller must specify start, end, flags, and desc (which may be +* IORES_DESC_NONE). +* +* If a resource is found, returns 0 and *res is overwritten with the part +* of the resource that's within [start..end]; if none is found, returns +* -1. +* +* This function walks the whole tree and not just first level children +* unless first_level_children_only is true. */ -static int find_next_iomem_res (struct resource *res,unsigned long desc, -bool first_level_children_only) +static int find_next_iomem_res (resource_size_t start,resource_size_t end, +unsigned long flags,unsigned long desc, +bool first_level_children_only, +struct resource *res) { -resource_size_t start, end;struct resource *p;bool sibling_only = false;BUG_ON (!res); - - start = res->start; - end = res->end;BUG_ON (start >= end);if (first_level_children_only)@@ -344,7 +347,7 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc,read_lock (&resource_lock);for (p = iomem_resource.child; p; p =next_resource (p, sibling_only)) { -if ((p->flags & res->flags) != res->flags) +if ((p->flags & flags) != flags)continue ;if ((desc !=IORES_DESC_NONE ) && (desc != p->desc))continue ;@@ -359,32 +362,31 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc,read_unlock (&resource_lock);if (!p)return -1 ; +/* copy data */ -if (res->start < p->start) - res->start = p->start; -if (res->end > p->end) - res->end = p->end; + res->start =max (start, p->start); + res->end =min (end, p->end); res->flags = p->flags; res->desc = p->desc;return 0 ; } -static int __walk_iomem_res_desc (struct resource *res,unsigned long desc, -bool first_level_children_only, -void *arg, +static int __walk_iomem_res_desc (resource_size_t start,resource_size_t end, +unsigned long flags,unsigned long desc, +bool first_level_children_only,void *arg,int (*func)(struct resource *,void *)) { -u64 orig_end = res->end; +struct resource res;int ret =-1 ; -while ((res->start < res->end) && - !find_next_iomem_res (res, desc, first_level_children_only)) { - ret = (*func)(res, arg); +while (start < end && + !find_next_iomem_res (start, end, flags, desc, + first_level_children_only, &res)) { + ret = (*func)(&res, arg);if (ret)break ; - res->start = res->end +1 ; - res->end = orig_end; + start = res.end +1 ; }return ret;@@ -407,13 +409,7 @@ static int __walk_iomem_res_desc(struct resource *res, unsigned long desc,int walk_iomem_res_desc (unsigned long desc,unsigned long flags,u64 start,u64 end,void *arg,int (*func)(struct resource *,void *)) { -struct resource res; - - res.start = start; - res.end = end; - res.flags = flags; - -return __walk_iomem_res_desc (&res, desc, false, arg, func); +return __walk_iomem_res_desc (start, end, flags, desc, false, arg, func); }EXPORT_SYMBOL_GPL (walk_iomem_res_desc);@@ -427,13 +423,9 @@ EXPORT_SYMBOL_GPL(walk_iomem_res_desc);int walk_system_ram_res (u64 start,u64 end,void *arg,int (*func)(struct resource *,void *)) { -struct resource res; - - res.start = start; - res.end = end; - res.flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; +unsigned long flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; -return __walk_iomem_res_desc (&res,IORES_DESC_NONE , true, +return __walk_iomem_res_desc (start, end, flags,IORES_DESC_NONE , true, arg, func); }@@ -444,13 +436,9 @@ int walk_system_ram_res(u64 start, u64 end, void *arg,int walk_mem_res (u64 start,u64 end,void *arg,int (*func)(struct resource *,void *)) { -struct resource res; - - res.start = start; - res.end = end; - res.flags =IORESOURCE_MEM |IORESOURCE_BUSY ; +unsigned long flags =IORESOURCE_MEM |IORESOURCE_BUSY ; -return __walk_iomem_res_desc (&res,IORES_DESC_NONE , true, +return __walk_iomem_res_desc (start, end, flags,IORES_DESC_NONE , true, arg, func); }@@ -464,25 +452,25 @@ int walk_mem_res(u64 start, u64 end, void *arg,int walk_system_ram_range (unsigned long start_pfn,unsigned long nr_pages,void *arg,int (*func)(unsigned long ,unsigned long ,void *)) { +resource_size_t start, end; +unsigned long flags;struct resource res;unsigned long pfn, end_pfn; -u64 orig_end;int ret =-1 ; - res.start = (u64 ) start_pfn <<PAGE_SHIFT ; - res.end = ((u64)(start_pfn + nr_pages) <<PAGE_SHIFT ) -1 ; - res.flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; - orig_end = res.end; -while ((res.start < res.end) && - (find_next_iomem_res (&res,IORES_DESC_NONE , true) >=0 )) { + start = (u64 ) start_pfn <<PAGE_SHIFT ; + end = ((u64)(start_pfn + nr_pages) <<PAGE_SHIFT ) -1 ; + flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; +while (start < end && + !find_next_iomem_res (start, end, flags,IORES_DESC_NONE , + true, &res)) { pfn = (res.start +PAGE_SIZE -1 ) >>PAGE_SHIFT ; end_pfn = (res.end +1 ) >>PAGE_SHIFT ;if (end_pfn > pfn) ret = (*func)(pfn, end_pfn - pfn, arg);if (ret)break ; - res.start = res.end +1 ; - res.end = orig_end; + start = res.end +1 ; }return ret; }_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 3/3] resource: Fix find_next_iomem_res() iteration issue
Quoted 19 lines · lijiang
Quoted 18 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Previously
find_next_iomem_res()used "*res" as both an input parameter for the range to search and the type of resource to search for, and an output parameter for the resource we found, which makes the interface confusing and hard to use correctly.All callers allocate a single struct resource and use it for repeated calls to
find_next_iomem_res(). Whenfind_next_iomem_res()returns a resource, it overwrites the start, end, flags, and desc members of the struct. If we callfind_next_iomem_res()again, we must update or restore these fields.The callers (
__walk_iomem_res_desc()andwalk_system_ram_range()) do not restoreres->flags, so if the caller is searching for flags ofIORESOURCE_MEM|IORESOURCE_BUSYand finds a resource with flags ofIORESOURCE_MEM|IORESOURCE_BUSY|IORESOURCE_SYSRAM, the next search will find only resources marked asIORESOURCE_SYSRAM.
Quoted 6 lines
Quoted 2 lines
Fix this by restructuring the interface so it takes explicit "start, end, flags" parameters and uses "*res" only as an output parameter.
Hi, Bjorn
I personally suggest that some comments might be added in the code, make it clear and easy to understand, then which could avoid the old confusion and more code changes.
Since I think the current interface (using *res as both input and output parameters that have very different meanings) is confusing, it's hard for *me* to write comments that make it less confusing, but of course, you're welcome to propose something.
My opinion (probably not universally shared) is that my proposal would make the code more readable, and it's worth doing even though the diff is larger.
Anyway, I'll post these patches independently and see if anybody else has an opinion.
Bjorn
Quoted 192 lines
Quoted 192 lines
Original-patch: http://lore.kernel.org/lkml/[email protected]
Based-on-patch-by Lianbo Jiang <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>--- kernel/resource.c | 94 +++++++++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 53 deletions(-)kernel/resource.c +41
-53@@ -319,23 +319,26 @@ int release_resource(struct resource *old)EXPORT_SYMBOL (release_resource);/* -* Finds the lowest iomem resource existing within [res->start..res->end]. -* The caller must specify res->start, res->end, res->flags, and optionally -* desc. If found, returns 0, res is overwritten, if not found, returns -1. -* This function walks the whole tree and not just first level children until -* and unless first_level_children_only is true. +* Finds the lowest iomem resource that covers part of [start..end]. The +* caller must specify start, end, flags, and desc (which may be +* IORES_DESC_NONE). +* +* If a resource is found, returns 0 and *res is overwritten with the part +* of the resource that's within [start..end]; if none is found, returns +* -1. +* +* This function walks the whole tree and not just first level children +* unless first_level_children_only is true. */ -static int find_next_iomem_res (struct resource *res,unsigned long desc, -bool first_level_children_only) +static int find_next_iomem_res (resource_size_t start,resource_size_t end, +unsigned long flags,unsigned long desc, +bool first_level_children_only, +struct resource *res) { -resource_size_t start, end;struct resource *p;bool sibling_only = false;BUG_ON (!res); - - start = res->start; - end = res->end;BUG_ON (start >= end);if (first_level_children_only)@@ -344,7 +347,7 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc,read_lock (&resource_lock);for (p = iomem_resource.child; p; p =next_resource (p, sibling_only)) { -if ((p->flags & res->flags) != res->flags) +if ((p->flags & flags) != flags)continue ;if ((desc !=IORES_DESC_NONE ) && (desc != p->desc))continue ;@@ -359,32 +362,31 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc,read_unlock (&resource_lock);if (!p)return -1 ; +/* copy data */ -if (res->start < p->start) - res->start = p->start; -if (res->end > p->end) - res->end = p->end; + res->start =max (start, p->start); + res->end =min (end, p->end); res->flags = p->flags; res->desc = p->desc;return 0 ; } -static int __walk_iomem_res_desc (struct resource *res,unsigned long desc, -bool first_level_children_only, -void *arg, +static int __walk_iomem_res_desc (resource_size_t start,resource_size_t end, +unsigned long flags,unsigned long desc, +bool first_level_children_only,void *arg,int (*func)(struct resource *,void *)) { -u64 orig_end = res->end; +struct resource res;int ret =-1 ; -while ((res->start < res->end) && - !find_next_iomem_res (res, desc, first_level_children_only)) { - ret = (*func)(res, arg); +while (start < end && + !find_next_iomem_res (start, end, flags, desc, + first_level_children_only, &res)) { + ret = (*func)(&res, arg);if (ret)break ; - res->start = res->end +1 ; - res->end = orig_end; + start = res.end +1 ; }return ret;@@ -407,13 +409,7 @@ static int __walk_iomem_res_desc(struct resource *res, unsigned long desc,int walk_iomem_res_desc (unsigned long desc,unsigned long flags,u64 start,u64 end,void *arg,int (*func)(struct resource *,void *)) { -struct resource res; - - res.start = start; - res.end = end; - res.flags = flags; - -return __walk_iomem_res_desc (&res, desc, false, arg, func); +return __walk_iomem_res_desc (start, end, flags, desc, false, arg, func); }EXPORT_SYMBOL_GPL (walk_iomem_res_desc);@@ -427,13 +423,9 @@ EXPORT_SYMBOL_GPL(walk_iomem_res_desc);int walk_system_ram_res (u64 start,u64 end,void *arg,int (*func)(struct resource *,void *)) { -struct resource res; - - res.start = start; - res.end = end; - res.flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; +unsigned long flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; -return __walk_iomem_res_desc (&res,IORES_DESC_NONE , true, +return __walk_iomem_res_desc (start, end, flags,IORES_DESC_NONE , true, arg, func); }@@ -444,13 +436,9 @@ int walk_system_ram_res(u64 start, u64 end, void *arg,int walk_mem_res (u64 start,u64 end,void *arg,int (*func)(struct resource *,void *)) { -struct resource res; - - res.start = start; - res.end = end; - res.flags =IORESOURCE_MEM |IORESOURCE_BUSY ; +unsigned long flags =IORESOURCE_MEM |IORESOURCE_BUSY ; -return __walk_iomem_res_desc (&res,IORES_DESC_NONE , true, +return __walk_iomem_res_desc (start, end, flags,IORES_DESC_NONE , true, arg, func); }@@ -464,25 +452,25 @@ int walk_mem_res(u64 start, u64 end, void *arg,int walk_system_ram_range (unsigned long start_pfn,unsigned long nr_pages,void *arg,int (*func)(unsigned long ,unsigned long ,void *)) { +resource_size_t start, end; +unsigned long flags;struct resource res;unsigned long pfn, end_pfn; -u64 orig_end;int ret =-1 ; - res.start = (u64 ) start_pfn <<PAGE_SHIFT ; - res.end = ((u64)(start_pfn + nr_pages) <<PAGE_SHIFT ) -1 ; - res.flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; - orig_end = res.end; -while ((res.start < res.end) && - (find_next_iomem_res (&res,IORES_DESC_NONE , true) >=0 )) { + start = (u64 ) start_pfn <<PAGE_SHIFT ; + end = ((u64)(start_pfn + nr_pages) <<PAGE_SHIFT ) -1 ; + flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; +while (start < end && + !find_next_iomem_res (start, end, flags,IORES_DESC_NONE , + true, &res)) { pfn = (res.start +PAGE_SIZE -1 ) >>PAGE_SHIFT ; end_pfn = (res.end +1 ) >>PAGE_SHIFT ;if (end_pfn > pfn) ret = (*func)(pfn, end_pfn - pfn, arg);if (ret)break ; - res.start = res.end +1 ; - res.end = orig_end; + start = res.end +1 ; }return ret; }_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 3/3] resource: Fix find_next_iomem_res() iteration issue
Quoted 32 lines · Bjorn Helgaas
Quoted 19 lines · lijiang
Quoted 18 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
Previously
find_next_iomem_res()used "*res" as both an input parameter for the range to search and the type of resource to search for, and an output parameter for the resource we found, which makes the interface confusing and hard to use correctly.All callers allocate a single struct resource and use it for repeated calls to
find_next_iomem_res(). Whenfind_next_iomem_res()returns a resource, it overwrites the start, end, flags, and desc members of the struct. If we callfind_next_iomem_res()again, we must update or restore these fields.The callers (
__walk_iomem_res_desc()andwalk_system_ram_range()) do not restoreres->flags, so if the caller is searching for flags ofIORESOURCE_MEM|IORESOURCE_BUSYand finds a resource with flags ofIORESOURCE_MEM|IORESOURCE_BUSY|IORESOURCE_SYSRAM, the next search will find only resources marked asIORESOURCE_SYSRAM.Quoted 6 lines
Quoted 2 lines
Fix this by restructuring the interface so it takes explicit "start, end, flags" parameters and uses "*res" only as an output parameter.
Hi, Bjorn
I personally suggest that some comments might be added in the code, make it clear and easy to understand, then which could avoid the old confusion and more code changes.Since I think the current interface (using *res as both input and output parameters that have very different meanings) is confusing, it's hard for *me* to write comments that make it less confusing, but of course, you're welcome to propose something.
Quoted 7 lines
My opinion (probably not universally shared) is that my proposal would make the code more readable, and it's worth doing even though the diff is larger.
Anyway, I'll post these patches independently and see if anybody else has an opinion.
I don't mind at all, because that is just my own opinion about more code changes.
Anyway, thank you to improve this patch.
Regards,
Lianbo
Quoted 194 lines
Bjorn
Quoted 192 lines
Quoted 192 lines
Original-patch: http://lore.kernel.org/lkml/[email protected]
Based-on-patch-by Lianbo Jiang <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>--- kernel/resource.c | 94 +++++++++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 53 deletions(-)kernel/resource.c +41
-53@@ -319,23 +319,26 @@ int release_resource(struct resource *old)EXPORT_SYMBOL (release_resource);/* -* Finds the lowest iomem resource existing within [res->start..res->end]. -* The caller must specify res->start, res->end, res->flags, and optionally -* desc. If found, returns 0, res is overwritten, if not found, returns -1. -* This function walks the whole tree and not just first level children until -* and unless first_level_children_only is true. +* Finds the lowest iomem resource that covers part of [start..end]. The +* caller must specify start, end, flags, and desc (which may be +* IORES_DESC_NONE). +* +* If a resource is found, returns 0 and *res is overwritten with the part +* of the resource that's within [start..end]; if none is found, returns +* -1. +* +* This function walks the whole tree and not just first level children +* unless first_level_children_only is true. */ -static int find_next_iomem_res (struct resource *res,unsigned long desc, -bool first_level_children_only) +static int find_next_iomem_res (resource_size_t start,resource_size_t end, +unsigned long flags,unsigned long desc, +bool first_level_children_only, +struct resource *res) { -resource_size_t start, end;struct resource *p;bool sibling_only = false;BUG_ON (!res); - - start = res->start; - end = res->end;BUG_ON (start >= end);if (first_level_children_only)@@ -344,7 +347,7 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc,read_lock (&resource_lock);for (p = iomem_resource.child; p; p =next_resource (p, sibling_only)) { -if ((p->flags & res->flags) != res->flags) +if ((p->flags & flags) != flags)continue ;if ((desc !=IORES_DESC_NONE ) && (desc != p->desc))continue ;@@ -359,32 +362,31 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc,read_unlock (&resource_lock);if (!p)return -1 ; +/* copy data */ -if (res->start < p->start) - res->start = p->start; -if (res->end > p->end) - res->end = p->end; + res->start =max (start, p->start); + res->end =min (end, p->end); res->flags = p->flags; res->desc = p->desc;return 0 ; } -static int __walk_iomem_res_desc (struct resource *res,unsigned long desc, -bool first_level_children_only, -void *arg, +static int __walk_iomem_res_desc (resource_size_t start,resource_size_t end, +unsigned long flags,unsigned long desc, +bool first_level_children_only,void *arg,int (*func)(struct resource *,void *)) { -u64 orig_end = res->end; +struct resource res;int ret =-1 ; -while ((res->start < res->end) && - !find_next_iomem_res (res, desc, first_level_children_only)) { - ret = (*func)(res, arg); +while (start < end && + !find_next_iomem_res (start, end, flags, desc, + first_level_children_only, &res)) { + ret = (*func)(&res, arg);if (ret)break ; - res->start = res->end +1 ; - res->end = orig_end; + start = res.end +1 ; }return ret;@@ -407,13 +409,7 @@ static int __walk_iomem_res_desc(struct resource *res, unsigned long desc,int walk_iomem_res_desc (unsigned long desc,unsigned long flags,u64 start,u64 end,void *arg,int (*func)(struct resource *,void *)) { -struct resource res; - - res.start = start; - res.end = end; - res.flags = flags; - -return __walk_iomem_res_desc (&res, desc, false, arg, func); +return __walk_iomem_res_desc (start, end, flags, desc, false, arg, func); }EXPORT_SYMBOL_GPL (walk_iomem_res_desc);@@ -427,13 +423,9 @@ EXPORT_SYMBOL_GPL(walk_iomem_res_desc);int walk_system_ram_res (u64 start,u64 end,void *arg,int (*func)(struct resource *,void *)) { -struct resource res; - - res.start = start; - res.end = end; - res.flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; +unsigned long flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; -return __walk_iomem_res_desc (&res,IORES_DESC_NONE , true, +return __walk_iomem_res_desc (start, end, flags,IORES_DESC_NONE , true, arg, func); }@@ -444,13 +436,9 @@ int walk_system_ram_res(u64 start, u64 end, void *arg,int walk_mem_res (u64 start,u64 end,void *arg,int (*func)(struct resource *,void *)) { -struct resource res; - - res.start = start; - res.end = end; - res.flags =IORESOURCE_MEM |IORESOURCE_BUSY ; +unsigned long flags =IORESOURCE_MEM |IORESOURCE_BUSY ; -return __walk_iomem_res_desc (&res,IORES_DESC_NONE , true, +return __walk_iomem_res_desc (start, end, flags,IORES_DESC_NONE , true, arg, func); }@@ -464,25 +452,25 @@ int walk_mem_res(u64 start, u64 end, void *arg,int walk_system_ram_range (unsigned long start_pfn,unsigned long nr_pages,void *arg,int (*func)(unsigned long ,unsigned long ,void *)) { +resource_size_t start, end; +unsigned long flags;struct resource res;unsigned long pfn, end_pfn; -u64 orig_end;int ret =-1 ; - res.start = (u64 ) start_pfn <<PAGE_SHIFT ; - res.end = ((u64)(start_pfn + nr_pages) <<PAGE_SHIFT ) -1 ; - res.flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; - orig_end = res.end; -while ((res.start < res.end) && - (find_next_iomem_res (&res,IORES_DESC_NONE , true) >=0 )) { + start = (u64 ) start_pfn <<PAGE_SHIFT ; + end = ((u64)(start_pfn + nr_pages) <<PAGE_SHIFT ) -1 ; + flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; +while (start < end && + !find_next_iomem_res (start, end, flags,IORES_DESC_NONE , + true, &res)) { pfn = (res.start +PAGE_SIZE -1 ) >>PAGE_SHIFT ; end_pfn = (res.end +1 ) >>PAGE_SHIFT ;if (end_pfn > pfn) ret = (*func)(pfn, end_pfn - pfn, arg);if (ret)break ; - res.start = res.end +1 ; - res.end = orig_end; + start = res.end +1 ; }return ret; }_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 3/3] resource: Fix find_next_iomem_res() iteration issue
In reply to Bjorn HelgaasQuoted 2 lines · Bjorn Helgaas
Since I think the current interface (using *res as both input and output parameters that have very different meanings) is confusing,
FTR, I too, think that this whole machinery in resource.c with passing in a function and a struct resource pointer and is clumsy and could use a rewrite. When there's time... ;-\
Signature · 4 lines
Regards/Gruss,
Boris.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)Re: [PATCH 0/3] find_next_iomem_res() fixes
In reply to Bjorn HelgaasQuoted 6 lines · Bjorn Helgaas
Hi Lianbo,
These three patches are a possible replacement for your first patch ("[PATCH 1/3 v3] resource: fix an error which walks through iomem resources").
Quoted 8 lines
I think the interface of
find_next_iomem_res()can be improved to make the code easier to read and also avoid the errors you're fixing.I can't test these, so they've only been compiled. If you can test them and if you like them, feel free to incorporate them into your series. If not, just drop them (but please at least fix the same error in
walk_system_ram_range()).
Hi, Bjorn
Sorry for my late reply about this. No need to incorporate them into my patch series, you might freely submit them to upstream.
I will test your patches whether it can also work well for my case, and you will get feedback about my test later.
Thanks.
Lianbo
Quoted 17 lines
---
Bjorn Helgaas (3):
x86/kexec: CorrectKEXEC_BACKUP_SRC_ENDoff-by-one error
resource: Include resource end in walk_*() interfaces
resource: Fixfind_next_iomem_res()iteration issuearch/x86/include/asm/kexec.h | 2 - kernel/resource.c | 96 ++++++++++++++++++------------------------ 2 files changed, 43 insertions(+), 55 deletions(-)_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 0/3] find_next_iomem_res() fixes
Quoted 17 lines · lijiang
Quoted 6 lines · Bjorn Helgaas
Hi Lianbo,
These three patches are a possible replacement for your first patch ("[PATCH 1/3 v3] resource: fix an error which walks through iomem resources").
Quoted 8 lines
I think the interface of
find_next_iomem_res()can be improved to make the code easier to read and also avoid the errors you're fixing.I can't test these, so they've only been compiled. If you can test them and if you like them, feel free to incorporate them into your series. If not, just drop them (but please at least fix the same error in
walk_system_ram_range()).
Quoted 7 lines
Hi, Bjorn
Sorry for my late reply about this. No need to incorporate them into my patch series, you might freely submit them to upstream.I will test your patches whether it can also work well for my case, and you will get feedback about my test later.
For my case, your patches can also work well.
Quoted 20 lines
Thanks.
LianboQuoted 17 lines
---
Bjorn Helgaas (3):
x86/kexec: CorrectKEXEC_BACKUP_SRC_ENDoff-by-one error
resource: Include resource end in walk_*() interfaces
resource: Fixfind_next_iomem_res()iteration issuearch/x86/include/asm/kexec.h | 2 - kernel/resource.c | 96 ++++++++++++++++++------------------------ 2 files changed, 43 insertions(+), 55 deletions(-)_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 2/3 x86/kexec_file: add e820 entry in case e820 type string matches to io resource name
In reply to Lianbo Jiangkdump uses walk_iomem_res_desc() to iterate io resources, then adds matched desc to e820 table for kdump kernel.
But IORES_DESC_NONE resource type includes several different e820 types, we need add exact e820 type to kdump kernel e820 table, thus it also needs an extra checking in memmap_entry_callback() to match the e820 type and resource name.
--- arch/x86/include/asm/e820/api.h | 2 ++ arch/x86/kernel/crash.c | 6 +++++- arch/x86/kernel/e820.c | 2 +- kernel/resource.c | 1 + 4 files changed, 9 insertions(+), 2 deletions(-)
arch/x86/include/asm/e820/api.h +2 -0
@@ -42,6 +42,8 @@ extern void e820__register_nosave_regions(unsigned long limit_pfn);extern int e820__get_entry_type (u64 start,u64 end); +extern const char *e820_type_to_string (struct e820_entry *entry); +/* * Returns true iff the specified range [start,end) is completely contained inside * the ISA region.
arch/x86/kernel/crash.c +5 -1
@@ -37,6 +37,7 @@#include <asm/reboot.h> #include <asm/virtext.h> #include <asm/intel_pt.h> +#include <asm/e820/api.h> /* Used while preparing memory map entries for second kernel */ struct crash_memmap_data {
@@ -314,11 +315,14 @@ static int memmap_entry_callback(struct resource *res, void *arg)struct crash_memmap_data *cmd = arg;struct boot_params *params = cmd->params;struct e820_entry ei; +const char *name; ei.addr = res->start; ei.size =resource_size (res); ei.type = cmd->type; -add_e820_entry (params, &ei); + name =e820_type_to_string (&ei); +if (res->name && !strcmp (name, res->name)) +add_e820_entry (params, &ei);return 0 ; }
arch/x86/kernel/e820.c +1 -1
@@ -1012,7 +1012,7 @@ void __init e820__finish_early_params(void) } } -static const char *__init e820_type_to_string (struct e820_entry *entry) +const char *e820_type_to_string (struct e820_entry *entry) {switch (entry->type) {case E820_TYPE_RESERVED_KERN :/* Fall-through: */
kernel/resource.c +1 -0
@@ -366,6 +366,7 @@ static int find_next_iomem_res(struct resource *res, unsigned long desc, res->end = p->end; res->flags = p->flags; res->desc = p->desc; + res->name = p->name;return 0 ; }
Signature · 1 line
2.17.1
PATCH v3 3/3 x86/kexec_file: add reserved e820 ranges to kdump kernel e820 table
In reply to Lianbo JiangE820 reserved ranges is useful in kdump kernel, we have added this in kexec-tools code.
One reason is PCI mmconf (extended mode) requires reserved region otherwise it falls back to legacy mode.
When AMD SME kdump support, it needs to map dmi table area as unencrypted. For normal boot, these ranges sit in e820 reserved ranges, thus the early ioremap code naturally map them as unencrypted. If we also have same e820 reserve setup in kdump kernel then it will just work like normal kernel.
--- arch/x86/kernel/crash.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/kernel/crash.c +5 -0
@@ -384,6 +384,11 @@ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)walk_iomem_res_desc (IORES_DESC_ACPI_NV_STORAGE , flags,0 ,-1 , &cmd, memmap_entry_callback); +/* Add all reserved ranges */ + cmd.type =E820_TYPE_RESERVED ; +walk_iomem_res_desc (IORES_DESC_NONE ,0 ,0 ,-1 , &cmd, + memmap_entry_callback); +/* Add crashk_low_res region */ if (crashk_low_res.end) { ei.addr = crashk_low_res.start;
Signature · 1 line
2.17.1
Quoted 30 lines · Lianbo Jiang
E820 reserved ranges is useful in kdump kernel, we have added this in kexec-tools code.
One reason is PCI mmconf (extended mode) requires reserved region otherwise it falls back to legacy mode.
Furthermore, when AMD SME kdump support, it needs to map dmi table area as unencrypted. For normal boot, these ranges sit in e820 reserved ranges, thus the early ioremap code naturally map them as unencrypted. If we also have same e820 reserve setup in kdump kernel then it will just work like normal kernel.
Kdump uses
walk_iomem_res_descto iterate resources, then adds matched desc to e820 table for the kdump kernel.But
IORES_DESC_NONEresource type includes several different e820 types, we need add exact e820 type to the kdump kernel e820 table, thus it also needs an extra checking inmemmap_entry_callback()to match the e820 type and resource name.By the way, we also fix an error which walks through iomem resources, the values of the function parameter may be modified in the while loop of
__walk_iomem_res_desc(), which will cause us to not get the desired result in some cases.Changes since v2:
1. Modified the value of flags to "0", when walking through the whole tree for e820 reserved ranges.
2. Modified the invalid SOB chain issue.
Quoted 5 lines
Lianbo Jiang (3):
resource: fix an error which walks through iomem resources x86/kexec_file: add e820 entry in case e820 type string matches to io
resource name
x86/kexec_file: add reserved e820 ranges to kdump kernel e820 table
Lianbo, since Bjorn has fixed the resource issue in another patchset, can you rebase your patch 2 and 3 on top of his patches and resend?
Quoted 10 lines
arch/x86/include/asm/e820/api.h | 2 ++ arch/x86/kernel/crash.c | 11 ++++++++++- arch/x86/kernel/e820.c | 2 +- kernel/resource.c | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-)Signature · 1 line
2.17.1
Thanks
Dave
Quoted 31 lines · Dave Young
Quoted 30 lines · Lianbo Jiang
E820 reserved ranges is useful in kdump kernel, we have added this in kexec-tools code.
One reason is PCI mmconf (extended mode) requires reserved region otherwise it falls back to legacy mode.
Furthermore, when AMD SME kdump support, it needs to map dmi table area as unencrypted. For normal boot, these ranges sit in e820 reserved ranges, thus the early ioremap code naturally map them as unencrypted. If we also have same e820 reserve setup in kdump kernel then it will just work like normal kernel.
Kdump uses
walk_iomem_res_descto iterate resources, then adds matched desc to e820 table for the kdump kernel.But
IORES_DESC_NONEresource type includes several different e820 types, we need add exact e820 type to the kdump kernel e820 table, thus it also needs an extra checking inmemmap_entry_callback()to match the e820 type and resource name.By the way, we also fix an error which walks through iomem resources, the values of the function parameter may be modified in the while loop of
__walk_iomem_res_desc(), which will cause us to not get the desired result in some cases.Changes since v2:
1. Modified the value of flags to "0", when walking through the whole tree for e820 reserved ranges.
2. Modified the invalid SOB chain issue.
Quoted 9 lines
Quoted 5 lines
Lianbo Jiang (3):
resource: fix an error which walks through iomem resources x86/kexec_file: add e820 entry in case e820 type string matches to io
resource name
x86/kexec_file: add reserved e820 ranges to kdump kernel e820 tableLianbo, since Bjorn has fixed the resource issue in another patchset, can you rebase your patch 2 and 3 on top of his patches and resend?
Ok, Thanks for your reminder.
I will adjust these patches and post again.
Thanks.
Lianbo
Quoted 14 lines
Quoted 10 lines
arch/x86/include/asm/e820/api.h | 2 ++ arch/x86/kernel/crash.c | 11 ++++++++++- arch/x86/kernel/e820.c | 2 +- kernel/resource.c | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-)Signature · 1 line
2.17.1Thanks
Dave