From: Andrew Morton <akpm@linux-foundation.org>
To: Baoquan He <bhe@redhat.com>
Cc: linux-kernel@vger.kernel.org, kexec@lists.infradead.org,
takahiro.akashi@linaro.org, ebiederm@xmission.com,
vgoyal@redhat.com, dyoung@redhat.com, prudo@linux.vnet.ibm.com
Subject: Re: [PATCH 1/2] resource: add walk_system_ram_res_rev()
Date: Thu, 22 Mar 2018 15:29:29 -0700 [thread overview]
Message-ID: <20180322152929.9b421af2f66cc819ad691207@linux-foundation.org> (raw)
In-Reply-To: <20180322033722.9279-2-bhe@redhat.com>
On Thu, 22 Mar 2018 11:37:21 +0800 Baoquan He <bhe@redhat.com> wrote:
> From: AKASHI Takahiro <takahiro.akashi@linaro.org>
>
> 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.
>
> ...
>
> --- a/kernel/resource.c
> +++ b/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 end, void *arg,
> }
>
> /*
> + * 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.
> + */
This should document the return value, as should walk_system_ram_res().
Why does it return -1 on error rather than an errno (ENOMEM)?
> +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;
> + }
erk, this is pretty nasty. Isn't there a better way :(
> +out:
> + vfree(rams);
> + return ret;
> +}
next prev parent reply other threads:[~2018-03-22 22:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-22 3:37 [PATCH 0/2] Kexec_file: Load kernel at top of system ram Baoquan He
2018-03-22 3:37 ` [PATCH 1/2] resource: add walk_system_ram_res_rev() Baoquan He
2018-03-22 22:29 ` Andrew Morton [this message]
2018-03-23 0:58 ` Baoquan He
2018-03-23 2:06 ` Andrew Morton
2018-03-23 3:10 ` Baoquan He
2018-03-23 20:06 ` Andrew Morton
2018-03-24 13:33 ` Baoquan He
2018-03-24 16:13 ` Wei Yang
2018-03-26 14:30 ` Baoquan He
2018-03-26 15:04 ` Wei Yang
2018-03-22 3:37 ` [PATCH 2/2] kexec_file: Load kernel at top of system RAM if required Baoquan He
2018-03-22 22:38 ` [PATCH 0/2] Kexec_file: Load kernel at top of system ram Andrew Morton
2018-03-23 8:38 ` Baoquan He
2023-11-14 9:16 [PATCH 0/2] kexec_file: Load kernel at top of system RAM if required Baoquan He
2023-11-14 9:16 ` [PATCH 1/2] resource: add walk_system_ram_res_rev() Baoquan He
2023-11-14 23:17 ` Andrew Morton
2023-11-15 0:40 ` Baoquan He
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180322152929.9b421af2f66cc819ad691207@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=dyoung@redhat.com \
--cc=ebiederm@xmission.com \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=prudo@linux.vnet.ibm.com \
--cc=takahiro.akashi@linaro.org \
--cc=vgoyal@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®