Re: [PATCH 5/6] kexec: add helper __crash_shrink_memory()

From: Baoquan He
Date: Wed May 31 2023 - 03:52:09 EST


On 05/27/23 at 08:34pm, Zhen Lei wrote:
> No functional change, in preparation for the next patch so that it is
> easier to review.
>
> Signed-off-by: Zhen Lei <thunder.leizhen@xxxxxxxxxx>
> ---
> kernel/kexec_core.c | 50 +++++++++++++++++++++++++--------------------
> 1 file changed, 28 insertions(+), 22 deletions(-)
>
> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> index 69fe92141b0b62d..e82bc6d6634136a 100644
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -1105,11 +1105,37 @@ ssize_t crash_get_memory_size(void)
> return size;
> }
>
> +int __crash_shrink_memory(struct resource *old_res, unsigned long new_size)

Other than the missing static, looks good,

Acked-by: Baoquan He <bhe@xxxxxxxxxx>

> +{
> + struct resource *ram_res;
> +
> + ram_res = kzalloc(sizeof(*ram_res), GFP_KERNEL);
> + if (!ram_res)
> + return -ENOMEM;
> +
> + ram_res->start = old_res->start + new_size;
> + ram_res->end = old_res->end;
> + ram_res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM;
> + ram_res->name = "System RAM";
> +
> + if (!new_size) {
> + release_resource(old_res);
> + old_res->start = 0;
> + old_res->end = 0;
> + } else {
> + crashk_res.end = ram_res->start - 1;
> + }
> +
> + crash_free_reserved_phys_range(ram_res->start, ram_res->end);
> + insert_resource(&iomem_resource, ram_res);
> +
> + return 0;
> +}
> +
> int crash_shrink_memory(unsigned long new_size)
> {
> int ret = 0;
> unsigned long old_size;
> - struct resource *ram_res;
>
> if (!kexec_trylock())
> return -EBUSY;
> @@ -1125,27 +1151,7 @@ int crash_shrink_memory(unsigned long new_size)
> goto unlock;
> }
>
> - ram_res = kzalloc(sizeof(*ram_res), GFP_KERNEL);
> - if (!ram_res) {
> - ret = -ENOMEM;
> - goto unlock;
> - }
> -
> - ram_res->start = crashk_res.start + new_size;
> - ram_res->end = crashk_res.end;
> - ram_res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM;
> - ram_res->name = "System RAM";
> -
> - if (!new_size) {
> - release_resource(&crashk_res);
> - crashk_res.start = 0;
> - crashk_res.end = 0;
> - } else {
> - crashk_res.end = ram_res->start - 1;
> - }
> -
> - crash_free_reserved_phys_range(ram_res->start, ram_res->end);
> - insert_resource(&iomem_resource, ram_res);
> + ret = __crash_shrink_memory(&crashk_res, new_size);
>
> unlock:
> kexec_unlock();
> --
> 2.25.1
>