From: Baoquan He <bhe@redhat.com>
To: Zhen Lei <thunder.leizhen@huawei.com>
Cc: Eric Biederman <ebiederm@xmission.com>,
kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
Michael Holzheu <holzheu@linux.vnet.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 6/6] kexec: enable kexec_crash_size to support two crash kernel regions
Date: Wed, 31 May 2023 17:53:34 +0800 [thread overview]
Message-ID: <ZHcY/jsExa8t7hJW@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20230527123439.772-7-thunder.leizhen@huawei.com>
On 05/27/23 at 08:34pm, Zhen Lei wrote:
> The crashk_low_res should be considered by /sys/kernel/kexec_crash_size
> to support two crash kernel regions. Since crashk_res manages the memory
> with high address and crashk_low_res manages the memory with low address,
> crashk_low_res is shrunken only when all crashk_res is shrunken. And
> because when there is only one crash kernel region, crashk_res is always
> used. Therefore, if all crashk_res is shrunken and crashk_low_res still
> exists, swap them.
This looks good, otherwise someone else won't stop attempting to add
support of crashk_low_res shrinking. Not sure if this will bring corner
case issue in testing, let's see. For the patch log, I tried to
rephrase, feel free to refer to.
=====
The crashk_low_res should be considered by /sys/kernel/kexec_crash_size
to support two crash kernel regions shrinking if existing.
While doing it, crashk_low_res will only be shrunk when the entire
crashk_res is empty; and if the crashk_res is empty and crahk_low_res
is not, change crashk_low_res to be crashk_res.
=====
With the log updated, you can add:
Acked-by: Baoquan He <bhe@redhat.com>
>
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
> kernel/kexec_core.c | 43 ++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 38 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> index e82bc6d6634136a..c1d50f6566300d9 100644
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -1091,6 +1091,11 @@ __bpf_kfunc void crash_kexec(struct pt_regs *regs)
> }
> }
>
> +static inline resource_size_t crash_resource_size(const struct resource *res)
> +{
> + return !res->end ? 0 : resource_size(res);
> +}
> +
> ssize_t crash_get_memory_size(void)
> {
> ssize_t size = 0;
> @@ -1098,8 +1103,8 @@ ssize_t crash_get_memory_size(void)
> if (!kexec_trylock())
> return -EBUSY;
>
> - if (crashk_res.end != crashk_res.start)
> - size = resource_size(&crashk_res);
> + size += crash_resource_size(&crashk_res);
> + size += crash_resource_size(&crashk_low_res);
>
> kexec_unlock();
> return size;
> @@ -1135,7 +1140,7 @@ int __crash_shrink_memory(struct resource *old_res, unsigned long new_size)
> int crash_shrink_memory(unsigned long new_size)
> {
> int ret = 0;
> - unsigned long old_size;
> + unsigned long old_size, low_size;
>
> if (!kexec_trylock())
> return -EBUSY;
> @@ -1144,14 +1149,42 @@ int crash_shrink_memory(unsigned long new_size)
> ret = -ENOENT;
> goto unlock;
> }
> - old_size = !crashk_res.end ? 0 : resource_size(&crashk_res);
> +
> + low_size = crash_resource_size(&crashk_low_res);
> + old_size = crash_resource_size(&crashk_res) + low_size;
> new_size = roundup(new_size, KEXEC_CRASH_MEM_ALIGN);
> if (new_size >= old_size) {
> ret = (new_size == old_size) ? 0 : -EINVAL;
> goto unlock;
> }
>
> - ret = __crash_shrink_memory(&crashk_res, new_size);
> + /*
> + * (low_size > new_size) implies that low_size is greater than zero.
> + * This also means that if low_size is zero, the else branch is taken.
> + *
> + * If low_size is greater than 0, (low_size > new_size) indicates that
> + * crashk_low_res also needs to be shrunken. Otherwise, only crashk_res
> + * needs to be shrunken.
> + */
> + if (low_size > new_size) {
> + ret = __crash_shrink_memory(&crashk_res, 0);
> + if (ret)
> + goto unlock;
> +
> + ret = __crash_shrink_memory(&crashk_low_res, new_size);
> + } else {
> + ret = __crash_shrink_memory(&crashk_res, new_size - low_size);
> + }
> +
> + /* Swap crashk_res and crashk_low_res if needed */
> + if (!crashk_res.end && crashk_low_res.end) {
> + crashk_res.start = crashk_low_res.start;
> + crashk_res.end = crashk_low_res.end;
> + release_resource(&crashk_low_res);
> + crashk_low_res.start = 0;
> + crashk_low_res.end = 0;
> + insert_resource(&iomem_resource, &crashk_res);
> + }
>
> unlock:
> kexec_unlock();
> --
> 2.25.1
>
_______________________________________________
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: Zhen Lei <thunder.leizhen@huawei.com>
Cc: Eric Biederman <ebiederm@xmission.com>,
kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
Michael Holzheu <holzheu@linux.vnet.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 6/6] kexec: enable kexec_crash_size to support two crash kernel regions
Date: Wed, 31 May 2023 17:53:34 +0800 [thread overview]
Message-ID: <ZHcY/jsExa8t7hJW@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20230527123439.772-7-thunder.leizhen@huawei.com>
On 05/27/23 at 08:34pm, Zhen Lei wrote:
> The crashk_low_res should be considered by /sys/kernel/kexec_crash_size
> to support two crash kernel regions. Since crashk_res manages the memory
> with high address and crashk_low_res manages the memory with low address,
> crashk_low_res is shrunken only when all crashk_res is shrunken. And
> because when there is only one crash kernel region, crashk_res is always
> used. Therefore, if all crashk_res is shrunken and crashk_low_res still
> exists, swap them.
This looks good, otherwise someone else won't stop attempting to add
support of crashk_low_res shrinking. Not sure if this will bring corner
case issue in testing, let's see. For the patch log, I tried to
rephrase, feel free to refer to.
=====
The crashk_low_res should be considered by /sys/kernel/kexec_crash_size
to support two crash kernel regions shrinking if existing.
While doing it, crashk_low_res will only be shrunk when the entire
crashk_res is empty; and if the crashk_res is empty and crahk_low_res
is not, change crashk_low_res to be crashk_res.
=====
With the log updated, you can add:
Acked-by: Baoquan He <bhe@redhat.com>
>
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
> kernel/kexec_core.c | 43 ++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 38 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> index e82bc6d6634136a..c1d50f6566300d9 100644
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -1091,6 +1091,11 @@ __bpf_kfunc void crash_kexec(struct pt_regs *regs)
> }
> }
>
> +static inline resource_size_t crash_resource_size(const struct resource *res)
> +{
> + return !res->end ? 0 : resource_size(res);
> +}
> +
> ssize_t crash_get_memory_size(void)
> {
> ssize_t size = 0;
> @@ -1098,8 +1103,8 @@ ssize_t crash_get_memory_size(void)
> if (!kexec_trylock())
> return -EBUSY;
>
> - if (crashk_res.end != crashk_res.start)
> - size = resource_size(&crashk_res);
> + size += crash_resource_size(&crashk_res);
> + size += crash_resource_size(&crashk_low_res);
>
> kexec_unlock();
> return size;
> @@ -1135,7 +1140,7 @@ int __crash_shrink_memory(struct resource *old_res, unsigned long new_size)
> int crash_shrink_memory(unsigned long new_size)
> {
> int ret = 0;
> - unsigned long old_size;
> + unsigned long old_size, low_size;
>
> if (!kexec_trylock())
> return -EBUSY;
> @@ -1144,14 +1149,42 @@ int crash_shrink_memory(unsigned long new_size)
> ret = -ENOENT;
> goto unlock;
> }
> - old_size = !crashk_res.end ? 0 : resource_size(&crashk_res);
> +
> + low_size = crash_resource_size(&crashk_low_res);
> + old_size = crash_resource_size(&crashk_res) + low_size;
> new_size = roundup(new_size, KEXEC_CRASH_MEM_ALIGN);
> if (new_size >= old_size) {
> ret = (new_size == old_size) ? 0 : -EINVAL;
> goto unlock;
> }
>
> - ret = __crash_shrink_memory(&crashk_res, new_size);
> + /*
> + * (low_size > new_size) implies that low_size is greater than zero.
> + * This also means that if low_size is zero, the else branch is taken.
> + *
> + * If low_size is greater than 0, (low_size > new_size) indicates that
> + * crashk_low_res also needs to be shrunken. Otherwise, only crashk_res
> + * needs to be shrunken.
> + */
> + if (low_size > new_size) {
> + ret = __crash_shrink_memory(&crashk_res, 0);
> + if (ret)
> + goto unlock;
> +
> + ret = __crash_shrink_memory(&crashk_low_res, new_size);
> + } else {
> + ret = __crash_shrink_memory(&crashk_res, new_size - low_size);
> + }
> +
> + /* Swap crashk_res and crashk_low_res if needed */
> + if (!crashk_res.end && crashk_low_res.end) {
> + crashk_res.start = crashk_low_res.start;
> + crashk_res.end = crashk_low_res.end;
> + release_resource(&crashk_low_res);
> + crashk_low_res.start = 0;
> + crashk_low_res.end = 0;
> + insert_resource(&iomem_resource, &crashk_res);
> + }
>
> unlock:
> kexec_unlock();
> --
> 2.25.1
>
next prev parent reply other threads:[~2023-05-31 9:53 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-27 12:34 [PATCH 0/6] kexec: enable kexec_crash_size to support two crash kernel regions Zhen Lei
2023-05-27 12:34 ` Zhen Lei
2023-05-27 12:34 ` [PATCH 1/6] kexec: fix a memory leak in crash_shrink_memory() Zhen Lei
2023-05-27 12:34 ` Zhen Lei
2023-05-31 0:13 ` Baoquan He
2023-05-31 0:13 ` Baoquan He
2023-05-31 1:16 ` Leizhen (ThunderTown)
2023-05-31 1:16 ` Leizhen (ThunderTown)
2023-05-31 7:31 ` Baoquan He
2023-05-31 7:31 ` Baoquan He
2023-05-27 12:34 ` [PATCH 2/6] kexec: delete a useless check " Zhen Lei
2023-05-27 12:34 ` Zhen Lei
2023-05-31 0:17 ` Baoquan He
2023-05-31 0:17 ` Baoquan He
2023-05-31 2:19 ` Leizhen (ThunderTown)
2023-05-31 2:19 ` Leizhen (ThunderTown)
2023-05-31 7:41 ` Baoquan He
2023-05-31 7:41 ` Baoquan He
2023-05-31 8:26 ` Leizhen (ThunderTown)
2023-05-31 8:26 ` Leizhen (ThunderTown)
2023-05-27 12:34 ` [PATCH 3/6] kexec: clear crashk_res if all its memory has been released Zhen Lei
2023-05-27 12:34 ` Zhen Lei
2023-05-31 0:33 ` Baoquan He
2023-05-31 0:33 ` Baoquan He
2023-05-27 12:34 ` [PATCH 4/6] kexec: improve the readability of crash_shrink_memory() Zhen Lei
2023-05-27 12:34 ` Zhen Lei
2023-05-31 7:48 ` Baoquan He
2023-05-31 7:48 ` Baoquan He
2023-05-27 12:34 ` [PATCH 5/6] kexec: add helper __crash_shrink_memory() Zhen Lei
2023-05-27 12:34 ` Zhen Lei
2023-05-28 0:08 ` kernel test robot
2023-05-28 0:08 ` kernel test robot
2023-05-29 0:37 ` Leizhen (ThunderTown)
2023-05-29 0:37 ` Leizhen (ThunderTown)
2023-05-28 1:44 ` kernel test robot
2023-05-28 1:44 ` kernel test robot
2023-05-28 6:26 ` kernel test robot
2023-05-28 6:26 ` kernel test robot
2023-05-31 7:50 ` Baoquan He
2023-05-31 7:50 ` Baoquan He
2023-05-27 12:34 ` [PATCH 6/6] kexec: enable kexec_crash_size to support two crash kernel regions Zhen Lei
2023-05-27 12:34 ` Zhen Lei
2023-05-31 9:53 ` Baoquan He [this message]
2023-05-31 9:53 ` Baoquan He
2023-05-31 14:25 ` Leizhen (ThunderTown)
2023-05-31 14:25 ` Leizhen (ThunderTown)
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=ZHcY/jsExa8t7hJW@MiWiFi-R3L-srv \
--to=bhe@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=ebiederm@xmission.com \
--cc=holzheu@linux.vnet.ibm.com \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=thunder.leizhen@huawei.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 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.