linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] arch : arm : add a criteria for pfn_valid
@ 2019-08-19  1:36 Zhaoyang Huang
  2019-08-19  1:45 ` Zhaoyang Huang
  2019-08-19  4:55 ` [PATCH v2] " Mike Rapoport
  0 siblings, 2 replies; 5+ messages in thread
From: Zhaoyang Huang @ 2019-08-19  1:36 UTC (permalink / raw)
  To: Andrew Morton, Zhaoyang Huang, Russell King, Mike Rapoport,
	Rob Herring, Florian Fainelli, Geert Uytterhoeven, Doug Berger,
	linux-mm, linux-kernel

From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>

pfn_valid can be wrong when parsing a invalid pfn whose phys address
exceeds BITS_PER_LONG as the MSB will be trimed when shifted.

Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
 arch/arm/mm/init.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index c2daabb..cc769fa 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -177,6 +177,11 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max_low,
 #ifdef CONFIG_HAVE_ARCH_PFN_VALID
 int pfn_valid(unsigned long pfn)
 {
+	phys_addr_t addr = __pfn_to_phys(pfn);
+
+	if (__phys_to_pfn(addr) != pfn)
+		return 0;
+
 	return memblock_is_map_memory(__pfn_to_phys(pfn));
 }
 EXPORT_SYMBOL(pfn_valid);
-- 
1.9.1


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

end of thread, other threads:[~2019-08-20 12:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-19  1:36 [PATCH v2] arch : arm : add a criteria for pfn_valid Zhaoyang Huang
2019-08-19  1:45 ` Zhaoyang Huang
2019-08-19  5:50   ` [PATCH v3] " Zhaoyang Huang
2019-08-20 12:45     ` [Resend PATCH " Zhaoyang Huang
2019-08-19  4:55 ` [PATCH v2] " Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).