mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
kexec: add helper __crash_shrink_memory()
No functional change, in preparation for the next patch so that it is easier to review. [akpm@linux-foundation.org: make __crash_shrink_memory() static] Link: https://lore.kernel.org/oe-kbuild-all/202305280717.Pw06aLkz-lkp@intel.com/ Link: https://lkml.kernel.org/r/20230527123439.772-6-thunder.leizhen@huawei.com Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> Acked-by: Baoquan He <bhe@redhat.com> Cc: Cong Wang <amwang@redhat.com> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
@@ -1105,11 +1105,38 @@ ssize_t crash_get_memory_size(void)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int __crash_shrink_memory(struct resource *old_res,
|
||||||
|
unsigned long new_size)
|
||||||
|
{
|
||||||
|
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 crash_shrink_memory(unsigned long new_size)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
unsigned long old_size;
|
unsigned long old_size;
|
||||||
struct resource *ram_res;
|
|
||||||
|
|
||||||
if (!kexec_trylock())
|
if (!kexec_trylock())
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
@@ -1125,27 +1152,7 @@ int crash_shrink_memory(unsigned long new_size)
|
|||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
ram_res = kzalloc(sizeof(*ram_res), GFP_KERNEL);
|
ret = __crash_shrink_memory(&crashk_res, new_size);
|
||||||
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);
|
|
||||||
|
|
||||||
unlock:
|
unlock:
|
||||||
kexec_unlock();
|
kexec_unlock();
|
||||||
|
Reference in New Issue
Block a user