The patch titled Subject: kernel/kexec_file.c: add walk_system_ram_res_rev() has been added to the -mm tree. Its filename is resource-add-walk_system_ram_res_rev.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/resource-add-walk_system_ram_res_rev.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/resource-add-walk_system_ram_res_rev.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: AKASHI Takahiro <takahiro.akashi@xxxxxxxxxx> Subject: kernel/kexec_file.c: add walk_system_ram_res_rev() This function, being a variant of walk_system_ram_res() introduced in commit 8c86e70acead ("resource: provide new functions to walk through resources"), walks through a list of all the resources of System RAM in reversed order, i.e., from higher to lower. It will be used in kexec_file code. Link: http://lkml.kernel.org/r/20180322033722.9279-2-bhe@xxxxxxxxxx Signed-off-by: AKASHI Takahiro <takahiro.akashi@xxxxxxxxxx> Signed-off-by: Baoquan He <bhe@xxxxxxxxxx> Cc: Eric W. Biederman <ebiederm@xxxxxxxxxxxx> Cc: Vivek Goyal <vgoyal@xxxxxxxxxx> Cc: Dave Young <dyoung@xxxxxxxxxx> Cc: Philipp Rudo <prudo@xxxxxxxxxxxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/ioport.h | 3 + kernel/resource.c | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff -puN include/linux/ioport.h~resource-add-walk_system_ram_res_rev include/linux/ioport.h --- a/include/linux/ioport.h~resource-add-walk_system_ram_res_rev +++ a/include/linux/ioport.h @@ -277,6 +277,9 @@ extern int walk_system_ram_res(u64 start, u64 end, void *arg, int (*func)(struct resource *, void *)); extern int +walk_system_ram_res_rev(u64 start, u64 end, void *arg, + int (*func)(struct resource *, void *)); +extern int walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end, void *arg, int (*func)(struct resource *, void *)); diff -puN kernel/resource.c~resource-add-walk_system_ram_res_rev kernel/resource.c --- a/kernel/resource.c~resource-add-walk_system_ram_res_rev +++ a/kernel/resource.c @@ -23,6 +23,8 @@ #include <linux/pfn.h> #include <linux/mm.h> #include <linux/resource_ext.h> +#include <linux/string.h> +#include <linux/vmalloc.h> #include <asm/io.h> @@ -470,6 +472,67 @@ int walk_system_ram_res(u64 start, u64 e } /* + * This function, being a variant of walk_system_ram_res(), calls the @func + * callback against all memory ranges of type System RAM which are marked as + * IORESOURCE_SYSTEM_RAM and IORESOUCE_BUSY in reversed order, i.e., from + * higher to lower. + */ +int walk_system_ram_res_rev(u64 start, u64 end, void *arg, + int (*func)(struct resource *, void *)) +{ + struct resource res, *rams; + int rams_size = 16, i; + int ret = -1; + + /* create a list */ + rams = vmalloc(sizeof(struct resource) * rams_size); + if (!rams) + return ret; + + res.start = start; + res.end = end; + res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; + i = 0; + while ((res.start < res.end) && + (!find_next_iomem_res(&res, IORES_DESC_NONE, true))) { + if (i >= rams_size) { + /* re-alloc */ + struct resource *rams_new; + int rams_new_size; + + rams_new_size = rams_size + 16; + rams_new = vmalloc(sizeof(struct resource) + * rams_new_size); + if (!rams_new) + goto out; + + memcpy(rams_new, rams, + sizeof(struct resource) * rams_size); + vfree(rams); + rams = rams_new; + rams_size = rams_new_size; + } + + rams[i].start = res.start; + rams[i++].end = res.end; + + res.start = res.end + 1; + res.end = end; + } + + /* go reverse */ + for (i--; i >= 0; i--) { + ret = (*func)(&rams[i], arg); + if (ret) + break; + } + +out: + vfree(rams); + return ret; +} + +/* * This function calls the @func callback against all memory ranges, which * are ranges marked as IORESOURCE_MEM and IORESOUCE_BUSY. */ _ Patches currently in -mm which might be from takahiro.akashi@xxxxxxxxxx are kexec_file-make-an-use-of-purgatory-optional.patch kexec_file-make-an-use-of-purgatory-optional-fix.patch kexec_filex86powerpc-factor-out-kexec_file_ops-functions.patch x86-kexec_file-purge-system-ram-walking-from-prepare_elf64_headers.patch x86-kexec_file-remove-x86_64-dependency-from-prepare_elf64_headers.patch x86-kexec_file-lift-crash_max_ranges-limit-on-crash_mem-buffer.patch x86-kexec_file-clean-up-prepare_elf64_headers.patch kexec_file-x86-move-re-factored-code-to-generic-side.patch resource-add-walk_system_ram_res_rev.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html