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 1/6] kexec: fix a memory leak in crash_shrink_memory()
Date: Wed, 31 May 2023 08:13:00 +0800 [thread overview]
Message-ID: <ZHaQ7qRYWX9FETu6@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20230527123439.772-2-thunder.leizhen@huawei.com>
On 05/27/23 at 08:34pm, Zhen Lei wrote:
> If the value of parameter 'new_size' is in the semi-open and semi-closed
> interval (crashk_res.end - KEXEC_CRASH_MEM_ALIGN + 1, crashk_res.end], the
> calculation result of ram_res is:
> ram_res->start = crashk_res.end + 1
> ram_res->end = crashk_res.end
If the new_size is smaller than KEXEC_CRASH_MEM_ALIGN, does it make
any sense except of testing purpose? Do we need to fail this kind of
shrinking, or just shrink all the left crash memory?
> The operation of function insert_resource() fails, and ram_res is not
> added to iomem_resource. As a result, the memory of the control block
> ram_res is leaked.
>
> In fact, on all architectures, the start address and size of crashk_res
> are already aligned by KEXEC_CRASH_MEM_ALIGN. Therefore, we do not need to
> round up crashk_res.start again. Instead, we should round up 'new_size'
> in advance.
>
> Fixes: 6480e5a09237 ("kdump: add missing RAM resource in crash_shrink_memory()")
> Fixes: 06a7f711246b ("kexec: premit reduction of the reserved memory size")
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> ---
> kernel/kexec_core.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> index 3d578c6fefee385..22acee18195a591 100644
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -1122,6 +1122,7 @@ int crash_shrink_memory(unsigned long new_size)
> start = crashk_res.start;
> end = crashk_res.end;
> old_size = (end == 0) ? 0 : end - start + 1;
> + new_size = roundup(new_size, KEXEC_CRASH_MEM_ALIGN);
> if (new_size >= old_size) {
> ret = (new_size == old_size) ? 0 : -EINVAL;
> goto unlock;
> @@ -1133,9 +1134,7 @@ int crash_shrink_memory(unsigned long new_size)
> goto unlock;
> }
>
> - start = roundup(start, KEXEC_CRASH_MEM_ALIGN);
> - end = roundup(start + new_size, KEXEC_CRASH_MEM_ALIGN);
> -
> + end = start + new_size;
> crash_free_reserved_phys_range(end, crashk_res.end);
>
> if ((start == end) && (crashk_res.parent != NULL))
> --
> 2.25.1
>
next prev parent reply other threads:[~2023-05-31 0:14 UTC|newest]
Thread overview: 23+ 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 ` [PATCH 1/6] kexec: fix a memory leak in crash_shrink_memory() Zhen Lei
2023-05-31 0:13 ` Baoquan He [this message]
2023-05-31 1:16 ` Leizhen (ThunderTown)
2023-05-31 7:31 ` Baoquan He
2023-05-27 12:34 ` [PATCH 2/6] kexec: delete a useless check " Zhen Lei
2023-05-31 0:17 ` Baoquan He
2023-05-31 2:19 ` Leizhen (ThunderTown)
2023-05-31 7:41 ` Baoquan He
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-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-31 7:48 ` Baoquan He
2023-05-27 12:34 ` [PATCH 5/6] kexec: add helper __crash_shrink_memory() Zhen Lei
2023-05-28 0:08 ` kernel test robot
2023-05-29 0:37 ` Leizhen (ThunderTown)
2023-05-28 1:44 ` kernel test robot
2023-05-28 6:26 ` kernel test robot
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-31 9:53 ` Baoquan He
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=ZHaQ7qRYWX9FETu6@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox