The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] kexec: use phys_addr_t in generic crash_free_reserved_phys_range()
@ 2026-11-28  8:19 Jingyi Sun
  2026-11-29  9:59 ` Mike Rapoport
  0 siblings, 1 reply; 3+ messages in thread
From: Jingyi Sun @ 2026-11-28  8:19 UTC (permalink / raw)
  To: Andrew Morton, Baoquan He, Mike Rapoport, Pasha Tatashin,
	Pratyush Yadav, Shradha Gupta, Thomas Huth, Sourabh Jain,
	Pingfan Liu, Jingyi Sun, Benjamin Herrenschmidt, Anton Blanchard
  Cc: kexec, linux-kernel, Russell King, linux-arm-kernel

The generic crash_free_reserved_phys_range() takes the range as
unsigned long, but its only caller, __crash_shrink_memory(), passes
resource_size_t values from crashk_res / crashk_low_res. On 32-bit
architectures with a 64-bit phys_addr_t that do not provide their own
helper (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. x86_64 with the same layout
behaves correctly.

Use phys_addr_t for the range and the loop variable, and PHYS_PFN() to
derive the PFN.

Fixes: c0bb9e45f3a7 ("kdump: Allow shrinking of kdump region to be overridden")
Signed-off-by: Jingyi Sun <1045704958@qq.com>
---
 include/linux/kexec.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index bac11e940e74..e21dcc316bf9 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -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
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] kexec: use phys_addr_t in generic crash_free_reserved_phys_range()
  2026-11-28  8:19 [PATCH] kexec: use phys_addr_t in generic crash_free_reserved_phys_range() Jingyi Sun
@ 2026-11-29  9:59 ` Mike Rapoport
  2026-11-29 10:28   ` Jingyi Sun
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Rapoport @ 2026-11-29  9:59 UTC (permalink / raw)
  To: Jingyi Sun
  Cc: Andrew Morton, Baoquan He, Pasha Tatashin, Pratyush Yadav,
	Shradha Gupta, Thomas Huth, Sourabh Jain, Pingfan Liu,
	Benjamin Herrenschmidt, Anton Blanchard, kexec, linux-kernel,
	Russell King, linux-arm-kernel

Hi,

On Sat, Nov 28, 2026 at 04:19:03PM +0800, Jingyi Sun wrote:
> The generic crash_free_reserved_phys_range() takes the range as
> unsigned long, but its only caller, __crash_shrink_memory(), passes
> resource_size_t values from crashk_res / crashk_low_res. On 32-bit
> architectures with a 64-bit phys_addr_t that do not provide their own
> helper (e.g. ARM with LPAE), a crash kernel region above 4GiB is then

Which helper that would be?

> 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. x86_64 with the same layout
> behaves correctly.

How is x86_64 related?
 
> Use phys_addr_t for the range and the loop variable, and PHYS_PFN() to
> derive the PFN.
> 
> Fixes: c0bb9e45f3a7 ("kdump: Allow shrinking of kdump region to be overridden")
> Signed-off-by: Jingyi Sun <1045704958@qq.com>

Other than nits in the changelong the patch looks good, thanks!

> ---
>  include/linux/kexec.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/kexec.h b/include/linux/kexec.h
> index bac11e940e74..e21dcc316bf9 100644
> --- a/include/linux/kexec.h
> +++ b/include/linux/kexec.h
> @@ -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
> -- 
> 2.43.0
> 

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kexec: use phys_addr_t in generic crash_free_reserved_phys_range()
  2026-11-29  9:59 ` Mike Rapoport
@ 2026-11-29 10:28   ` Jingyi Sun
  0 siblings, 0 replies; 3+ messages in thread
From: Jingyi Sun @ 2026-11-29 10:28 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Andrew Morton, Baoquan He, Pasha Tatashin, Pratyush Yadav,
	Shradha Gupta, Thomas Huth, Sourabh Jain, Pingfan Liu,
	Benjamin Herrenschmidt, Anton Blanchard, Russell King, kexec,
	linux-kernel, linux-arm-kernel

Hi Mike,

On Sun, Nov 29, 2026 at 11:59:21AM +0200, Mike Rapoport wrote:
> Which helper that would be?

An architecture-specific crash_free_reserved_phys_range(). arm64,
powerpc and s390 define their own; all other architectures, including
32-bit ARM, use the generic one in <linux/kexec.h>. I'll spell that out.

> How is x86_64 related?

It isn't, really. I only used it as a control run where unsigned long
is 64 bits wide and nothing gets truncated. I'll drop that sentence.

Thanks for the review, v2 with the updated changelog follows.

Jingyi


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-29 10:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28  8:19 [PATCH] kexec: use phys_addr_t in generic crash_free_reserved_phys_range() Jingyi Sun
2026-11-29  9:59 ` Mike Rapoport
2026-11-29 10:28   ` Jingyi Sun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox