kexec: use phys_addr_t in generic crash_free_reserved_phys_range()
Subsystems (3)
PATCH v2 1/1 kexec: use phys_addr_t in generic crash_free_reserved_phys_range()
The generic crash_free_reserved_phys_range() in <linux/kexec.h> takes the range as unsigned long, but its only caller, __crash_shrink_memory(), passes resource_size_t values from crashk_res / crashk_low_res.
arm64, powerpc and s390 provide their own crash_free_reserved_phys_range(); all other architectures use the generic one. On 32-bit architectures with a 64-bit phys_addr_t among them (e.g. ARM with LPAE), a crash kernel region above 4GiB is then truncated to its low 32 bits when /sys/kernel/kexec_crash_size is shrunk: free_reserved_page() is called on unrelated low-memory pages, while the pages that were actually released from the reservation stay reserved forever.
This was observed on QEMU (virt, cortex-a15, ARM_LPAE, 6G) with "mem=1G@0x40000000 mem=512M@0x140000000 crashkernel=64M@0x150000000":
after "echo 0 > /sys/kernel/kexec_crash_size" the HighMem zone's managed page count stayed unchanged, while the low-memory zone grew by 16384 pages (64MiB), i.e. the pages at 0x50000000-0x53ffffff were "freed" instead of 0x150000000-0x153ffffff.
Use phys_addr_t for the range and the loop variable, and PHYS_PFN() to derive the PFN.
---
Changes in v2:
- Say which architectures provide their own helper (Mike Rapoport)
- Drop the unrelated x86_64 remark (Mike Rapoport)
- No code changes
v1: https://lore.kernel.org/all/[email protected]/
include/linux/kexec.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/kexec.h +3 -3
@@ -484,12 +484,12 @@ static inline phys_addr_t boot_phys_to_phys(unsigned long boot_phys)#endif #ifndef crash_free_reserved_phys_range -static inline void crash_free_reserved_phys_range (unsigned long begin,unsigned long end) +static inline void crash_free_reserved_phys_range (phys_addr_t begin,phys_addr_t end) { -unsigned long addr; +phys_addr_t addr;for (addr = begin; addr < end; addr +=PAGE_SIZE ) -free_reserved_page (boot_pfn_to_page (addr >>PAGE_SHIFT )); +free_reserved_page (boot_pfn_to_page (PHYS_PFN (addr))); }#endif
base-commit: 7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 19 lines
The generic
crash_free_reserved_phys_range()in <linux/kexec.h> takes the range as unsigned long, but its only caller,__crash_shrink_memory(), passesresource_size_tvalues fromcrashk_res/crashk_low_res.arm64, powerpc and s390 provide their own
crash_free_reserved_phys_range(); all other architectures use the generic one. On 32-bit architectures with a 64-bitphys_addr_tamong them (e.g. ARM with LPAE), a crash kernel region above 4GiB is then truncated to its low 32 bits when/sys/kernel/kexec_crash_sizeis shrunk:free_reserved_page()is called on unrelated low-memory pages, while the pages that were actually released from the reservation stay reserved forever.This was observed on QEMU (virt, cortex-a15,
ARM_LPAE, 6G) with "mem=1G@0x40000000 mem=512M@0x140000000 crashkernel=64M@0x150000000":
after "echo 0 >/sys/kernel/kexec_crash_size" the HighMem zone's managed page count stayed unchanged, while the low-memory zone grew by 16384 pages (64MiB), i.e. the pages at 0x50000000-0x53ffffff were "freed" instead of 0x150000000-0x153ffffff.
Quoted 5 lines
Use
phys_addr_tfor the range and the loop variable, andPHYS_PFN()to derive the PFN.Fixes c0bb9e45f3a7 ("kdump: Allow shrinking of kdump region to be overridden")Signed-off-by Jingyi Sun <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 8 lines · Jingyi Sun
The generic
crash_free_reserved_phys_range()in <linux/kexec.h> takes the range as unsigned long, but its only caller,__crash_shrink_memory(), passesresource_size_tvalues fromcrashk_res/crashk_low_res.arm64, powerpc and s390 provide their own
crash_free_reserved_phys_range(); all other architectures use the generic one. On 32-bit architectures with a 64-bitphys_addr_tamong them (e.g. ARM with LPAE), a crash kernel region above 4GiB is then truncated to its low 32 bits when
Right, arm32 with LPAE will select PHYS_ADDR_T_64BIT, resource_size_t will be u64.
169 #ifdef CONFIG_PHYS_ADDR_T_64BIT
170 typedef u64 phys_addr_t;
171 #else
172 typedef u32 phys_addr_t;
173 #endif
.....
180 typedef phys_addr_t resource_size_t;
680 config ARM_LPAE
681 >-------bool "Support for the Large Physical Address Extension" 682 >-------depends on MMU && CPU_32v7 && !CPU_32v6 && !CPU_32v5 && \
683 >------->-------!CPU_32v4 && !CPU_32v3
684 >-------select PHYS_ADDR_T_64BIT
Quoted 11 lines
/sys/kernel/kexec_crash_sizeis shrunk:free_reserved_page()is called on unrelated low-memory pages, while the pages that were actually released from the reservation stay reserved forever.This was observed on QEMU (virt, cortex-a15,
ARM_LPAE, 6G) with "mem=1G@0x40000000 mem=512M@0x140000000 crashkernel=64M@0x150000000":
after "echo 0 >/sys/kernel/kexec_crash_size" the HighMem zone's managed page count stayed unchanged, while the low-memory zone grew by 16384 pages (64MiB), i.e. the pages at 0x50000000-0x53ffffff were "freed" instead of 0x150000000-0x153ffffff.
Quoted 2 lines
Use
phys_addr_tfor the range and the loop variable, andPHYS_PFN()to derive the PFN.
LGTM
Quoted 36 lines
Fixes c0bb9e45f3a7 ("kdump: Allow shrinking of kdump region to be overridden")Signed-off-by Jingyi Sun <[email protected]>---
Changes in v2:
- Say which architectures provide their own helper (Mike Rapoport)
- Drop the unrelatedx86_64remark (Mike Rapoport)
- No code changesv1: https://lore.kernel.org/all/[email protected]/
include/linux/kexec.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)include/linux/kexec.h +3
-3@@ -484,12 +484,12 @@ static inline phys_addr_t boot_phys_to_phys(unsigned long boot_phys)#endif #ifndef crash_free_reserved_phys_range -static inline void crash_free_reserved_phys_range (unsigned long begin,unsigned long end) +static inline void crash_free_reserved_phys_range (phys_addr_t begin,phys_addr_t end) { -unsigned long addr; +phys_addr_t addr;for (addr = begin; addr < end; addr +=PAGE_SIZE ) -free_reserved_page (boot_pfn_to_page (addr >>PAGE_SHIFT )); +free_reserved_page (boot_pfn_to_page (PHYS_PFN (addr))); }#endif base-commit:
7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046
From: Mike Rapoport (Microsoft) <[email protected]>
Quoted 12 lines · Jingyi Sun
The generic
crash_free_reserved_phys_range()in <linux/kexec.h> takes the range as unsigned long, but its only caller,__crash_shrink_memory(), passesresource_size_tvalues fromcrashk_res/crashk_low_res.arm64, powerpc and s390 provide their own
crash_free_reserved_phys_range(); all other architectures use the generic one. On 32-bit architectures with a 64-bitphys_addr_tamong them (e.g. ARM with LPAE), a crash kernel region above 4GiB is then truncated to its low 32 bits when/sys/kernel/kexec_crash_sizeis shrunk:free_reserved_page()is called on unrelated low-memory pages, while the pages that were actually released from the reservation stay reserved forever.
Quoted 1 line
[...]
Applied to kexec-7.5 branch of liveupdate/linux.git tree, thanks!
[1/1] kexec: use phys_addr_t in generic crash_free_reserved_phys_range()
commit: 1d33d7e3c7866646436cb493311b5ddfd6477121
tree: https://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux
branch: kexec-7.5
--
Sincerely yours,
Mike.