From: Baoquan He <bhe@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, kexec@lists.infradead.org,
x86@kernel.org, linux-parisc@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org,
linux-s390@vger.kernel.org, ebiederm@xmission.com,
takahiro.akashi@linaro.org
Subject: Re: [PATCH 1/2] resource: add walk_system_ram_res_rev()
Date: Wed, 15 Nov 2023 08:40:50 +0800 [thread overview]
Message-ID: <ZVQTkqSa4FA6b6iH@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20231114151745.e77ed504b3fce325f54ec08e@linux-foundation.org>
On 11/14/23 at 03:17pm, Andrew Morton wrote:
> On Tue, 14 Nov 2023 17:16:57 +0800 Baoquan He <bhe@redhat.com> wrote:
>
> > 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 to load kernel, initrd etc when
> > preparing kexec reboot.
> >
> > ...
> >
> > +/*
> > + * 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;
> > + unsigned long flags;
> > + int ret = -1;
> > +
> > + /* create a list */
> > + rams = kvcalloc(rams_size, sizeof(struct resource), GFP_KERNEL);
> > + if (!rams)
> > + return ret;
> > +
> > + flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
> > + i = 0;
> > + while ((start < end) &&
> > + (!find_next_iomem_res(start, end, flags, IORES_DESC_NONE, &res))) {
> > + if (i >= rams_size) {
> > + /* re-alloc */
> > + struct resource *rams_new;
> > + int rams_new_size;
> > +
> > + rams_new_size = rams_size + 16;
> > + rams_new = kvcalloc(rams_new_size, sizeof(struct resource),
> > + GFP_KERNEL);
>
> kvrealloc()?
Exactly. Will udpate. Thanks for the great suggestion.
>
> > + if (!rams_new)
> > + goto out;
> > +
> > + memcpy(rams_new, rams,
> > + sizeof(struct resource) * rams_size);
> > + kvfree(rams);
> > + rams = rams_new;
> > + rams_size = rams_new_size;
> > + }
> > +
> > + rams[i].start = res.start;
> > + rams[i++].end = res.end;
> > +
> > + start = res.end + 1;
> > + }
> > +
> > + /* go reverse */
> > + for (i--; i >= 0; i--) {
> > + ret = (*func)(&rams[i], arg);
> > + if (ret)
> > + break;
> > + }
> > +
> > +out:
> > + kvfree(rams);
> > + return ret;
> > +}
> > +
> > /*
> > * This function calls the @func callback against all memory ranges, which
> > * are ranges marked as IORESOURCE_MEM and IORESOUCE_BUSY.
> > --
> > 2.41.0
>
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
WARNING: multiple messages have this Message-ID (diff)
From: Baoquan He <bhe@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, kexec@lists.infradead.org,
x86@kernel.org, linux-parisc@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org,
linux-s390@vger.kernel.org, ebiederm@xmission.com,
takahiro.akashi@linaro.org
Subject: Re: [PATCH 1/2] resource: add walk_system_ram_res_rev()
Date: Wed, 15 Nov 2023 08:40:50 +0800 [thread overview]
Message-ID: <ZVQTkqSa4FA6b6iH@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20231114151745.e77ed504b3fce325f54ec08e@linux-foundation.org>
On 11/14/23 at 03:17pm, Andrew Morton wrote:
> On Tue, 14 Nov 2023 17:16:57 +0800 Baoquan He <bhe@redhat.com> wrote:
>
> > 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 to load kernel, initrd etc when
> > preparing kexec reboot.
> >
> > ...
> >
> > +/*
> > + * 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;
> > + unsigned long flags;
> > + int ret = -1;
> > +
> > + /* create a list */
> > + rams = kvcalloc(rams_size, sizeof(struct resource), GFP_KERNEL);
> > + if (!rams)
> > + return ret;
> > +
> > + flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
> > + i = 0;
> > + while ((start < end) &&
> > + (!find_next_iomem_res(start, end, flags, IORES_DESC_NONE, &res))) {
> > + if (i >= rams_size) {
> > + /* re-alloc */
> > + struct resource *rams_new;
> > + int rams_new_size;
> > +
> > + rams_new_size = rams_size + 16;
> > + rams_new = kvcalloc(rams_new_size, sizeof(struct resource),
> > + GFP_KERNEL);
>
> kvrealloc()?
Exactly. Will udpate. Thanks for the great suggestion.
>
> > + if (!rams_new)
> > + goto out;
> > +
> > + memcpy(rams_new, rams,
> > + sizeof(struct resource) * rams_size);
> > + kvfree(rams);
> > + rams = rams_new;
> > + rams_size = rams_new_size;
> > + }
> > +
> > + rams[i].start = res.start;
> > + rams[i++].end = res.end;
> > +
> > + start = res.end + 1;
> > + }
> > +
> > + /* go reverse */
> > + for (i--; i >= 0; i--) {
> > + ret = (*func)(&rams[i], arg);
> > + if (ret)
> > + break;
> > + }
> > +
> > +out:
> > + kvfree(rams);
> > + return ret;
> > +}
> > +
> > /*
> > * This function calls the @func callback against all memory ranges, which
> > * are ranges marked as IORESOURCE_MEM and IORESOUCE_BUSY.
> > --
> > 2.41.0
>
WARNING: multiple messages have this Message-ID (diff)
From: Baoquan He <bhe@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, kexec@lists.infradead.org,
x86@kernel.org, linux-parisc@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org,
linux-s390@vger.kernel.org, ebiederm@xmission.com,
takahiro.akashi@linaro.org
Subject: Re: [PATCH 1/2] resource: add walk_system_ram_res_rev()
Date: Wed, 15 Nov 2023 08:40:50 +0800 [thread overview]
Message-ID: <ZVQTkqSa4FA6b6iH@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20231114151745.e77ed504b3fce325f54ec08e@linux-foundation.org>
On 11/14/23 at 03:17pm, Andrew Morton wrote:
> On Tue, 14 Nov 2023 17:16:57 +0800 Baoquan He <bhe@redhat.com> wrote:
>
> > 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 to load kernel, initrd etc when
> > preparing kexec reboot.
> >
> > ...
> >
> > +/*
> > + * 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;
> > + unsigned long flags;
> > + int ret = -1;
> > +
> > + /* create a list */
> > + rams = kvcalloc(rams_size, sizeof(struct resource), GFP_KERNEL);
> > + if (!rams)
> > + return ret;
> > +
> > + flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
> > + i = 0;
> > + while ((start < end) &&
> > + (!find_next_iomem_res(start, end, flags, IORES_DESC_NONE, &res))) {
> > + if (i >= rams_size) {
> > + /* re-alloc */
> > + struct resource *rams_new;
> > + int rams_new_size;
> > +
> > + rams_new_size = rams_size + 16;
> > + rams_new = kvcalloc(rams_new_size, sizeof(struct resource),
> > + GFP_KERNEL);
>
> kvrealloc()?
Exactly. Will udpate. Thanks for the great suggestion.
>
> > + if (!rams_new)
> > + goto out;
> > +
> > + memcpy(rams_new, rams,
> > + sizeof(struct resource) * rams_size);
> > + kvfree(rams);
> > + rams = rams_new;
> > + rams_size = rams_new_size;
> > + }
> > +
> > + rams[i].start = res.start;
> > + rams[i++].end = res.end;
> > +
> > + start = res.end + 1;
> > + }
> > +
> > + /* go reverse */
> > + for (i--; i >= 0; i--) {
> > + ret = (*func)(&rams[i], arg);
> > + if (ret)
> > + break;
> > + }
> > +
> > +out:
> > + kvfree(rams);
> > + return ret;
> > +}
> > +
> > /*
> > * This function calls the @func callback against all memory ranges, which
> > * are ranges marked as IORESOURCE_MEM and IORESOUCE_BUSY.
> > --
> > 2.41.0
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Baoquan He <bhe@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-s390@vger.kernel.org, linux-parisc@vger.kernel.org,
x86@kernel.org, kexec@lists.infradead.org,
linux-kernel@vger.kernel.org, takahiro.akashi@linaro.org,
ebiederm@xmission.com, linux-riscv@lists.infradead.org,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 1/2] resource: add walk_system_ram_res_rev()
Date: Wed, 15 Nov 2023 08:40:50 +0800 [thread overview]
Message-ID: <ZVQTkqSa4FA6b6iH@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20231114151745.e77ed504b3fce325f54ec08e@linux-foundation.org>
On 11/14/23 at 03:17pm, Andrew Morton wrote:
> On Tue, 14 Nov 2023 17:16:57 +0800 Baoquan He <bhe@redhat.com> wrote:
>
> > 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 to load kernel, initrd etc when
> > preparing kexec reboot.
> >
> > ...
> >
> > +/*
> > + * 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;
> > + unsigned long flags;
> > + int ret = -1;
> > +
> > + /* create a list */
> > + rams = kvcalloc(rams_size, sizeof(struct resource), GFP_KERNEL);
> > + if (!rams)
> > + return ret;
> > +
> > + flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
> > + i = 0;
> > + while ((start < end) &&
> > + (!find_next_iomem_res(start, end, flags, IORES_DESC_NONE, &res))) {
> > + if (i >= rams_size) {
> > + /* re-alloc */
> > + struct resource *rams_new;
> > + int rams_new_size;
> > +
> > + rams_new_size = rams_size + 16;
> > + rams_new = kvcalloc(rams_new_size, sizeof(struct resource),
> > + GFP_KERNEL);
>
> kvrealloc()?
Exactly. Will udpate. Thanks for the great suggestion.
>
> > + if (!rams_new)
> > + goto out;
> > +
> > + memcpy(rams_new, rams,
> > + sizeof(struct resource) * rams_size);
> > + kvfree(rams);
> > + rams = rams_new;
> > + rams_size = rams_new_size;
> > + }
> > +
> > + rams[i].start = res.start;
> > + rams[i++].end = res.end;
> > +
> > + start = res.end + 1;
> > + }
> > +
> > + /* go reverse */
> > + for (i--; i >= 0; i--) {
> > + ret = (*func)(&rams[i], arg);
> > + if (ret)
> > + break;
> > + }
> > +
> > +out:
> > + kvfree(rams);
> > + return ret;
> > +}
> > +
> > /*
> > * This function calls the @func callback against all memory ranges, which
> > * are ranges marked as IORESOURCE_MEM and IORESOUCE_BUSY.
> > --
> > 2.41.0
>
next prev parent reply other threads:[~2023-11-15 0:41 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Baoquan He
2023-11-14 9:16 ` Baoquan He
2023-11-14 9:16 ` Baoquan He
2023-11-14 9:16 ` [PATCH 1/2] resource: add walk_system_ram_res_rev() Baoquan He
2023-11-14 9:16 ` Baoquan He
2023-11-14 9:16 ` Baoquan He
2023-11-14 9:16 ` Baoquan He
2023-11-14 23:17 ` Andrew Morton
2023-11-14 23:17 ` Andrew Morton
2023-11-14 23:17 ` Andrew Morton
2023-11-14 23:17 ` Andrew Morton
2023-11-15 0:40 ` Baoquan He [this message]
2023-11-15 0:40 ` Baoquan He
2023-11-15 0:40 ` Baoquan He
2023-11-15 0:40 ` Baoquan He
2023-11-15 13:00 ` [PATCH v2 " Baoquan He
2023-11-15 13:00 ` Baoquan He
2023-11-15 13:00 ` Baoquan He
2023-11-15 13:00 ` Baoquan He
2023-11-23 13:27 ` Baoquan He
2023-11-23 13:27 ` Baoquan He
2023-11-23 13:27 ` Baoquan He
2023-11-23 13:27 ` Baoquan He
2024-01-20 21:09 ` patchwork-bot+linux-riscv
2024-01-20 21:09 ` patchwork-bot+linux-riscv
2024-01-20 21:09 ` patchwork-bot+linux-riscv
2024-01-20 21:09 ` patchwork-bot+linux-riscv
2023-11-14 9:16 ` [PATCH 2/2] kexec_file: Load kernel at top of system RAM if required Baoquan He
2023-11-14 9:16 ` Baoquan He
2023-11-14 9:16 ` Baoquan He
2023-11-14 9:16 ` Baoquan He
2024-01-20 21:09 ` [PATCH 0/2] " patchwork-bot+linux-riscv
2024-01-20 21:09 ` patchwork-bot+linux-riscv
2024-01-20 21:09 ` patchwork-bot+linux-riscv
2024-01-20 21:09 ` patchwork-bot+linux-riscv
-- strict thread matches above, loose matches on Subject: below --
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 3:37 ` Baoquan He
2018-03-22 22:29 ` Andrew Morton
2018-03-22 22:29 ` Andrew Morton
2018-03-23 0:58 ` Baoquan He
2018-03-23 0:58 ` Baoquan He
2018-03-23 2:06 ` Andrew Morton
2018-03-23 2:06 ` Andrew Morton
2018-03-23 3:10 ` Baoquan He
2018-03-23 3:10 ` Baoquan He
2018-03-23 20:06 ` Andrew Morton
2018-03-23 20:06 ` Andrew Morton
2018-03-24 13:33 ` Baoquan He
2018-03-24 13:33 ` Baoquan He
2018-03-24 16:13 ` Wei Yang
2018-03-24 16:13 ` Wei Yang
2018-03-26 14:30 ` Baoquan He
2018-03-26 14:30 ` Baoquan He
2018-03-26 15:04 ` Wei Yang
2018-03-26 15:04 ` Wei Yang
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=ZVQTkqSa4FA6b6iH@MiWiFi-R3L-srv \
--to=bhe@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=ebiederm@xmission.com \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=takahiro.akashi@linaro.org \
--cc=x86@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.