Skip to contentSkip to conversation

arm: Correct virt_addr_valid

PATCH New Laura Abbott 2 participants 2 messages Dec 19, 2013 – Dec 20, 2013 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 arm: Correct virt_addr_valid

The definition of virt_addr_valid is that virt_addr_valid should return true if and only if virt_to_page returns a valid pointer. The current definition of virt_addr_valid only checks against the virtual address range. There's no guarantee that just because a virtual address falls bewteen PAGE_OFFSET and high_memory the associated physical memory has a valid backing struct page. Follow the example of other architectures and convert to pfn_valid to verify that the virtual address is actually valid. The check for an address between PAGE_OFFSET and high_memory is still necessary as vmalloc/highmem addresses are not valid with virt_to_page.

Cc Russell King <[email protected]>
Cc Will Deacon <[email protected]>
Cc Nicolas Pitre <[email protected]>
---
 arch/arm/include/asm/memory.h |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/arm/include/asm/memory.h +2 -1
index 9ecccc8..35a8511 100644
@@ -350,7 +350,8 @@ static inline __deprecated void *bus_to_virt(unsigned long x)
 #define ARCH_PFN_OFFSET		PHYS_PFN_OFFSET
 
 #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
-#define virt_addr_valid(kaddr)	((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
+#define virt_addr_valid(kaddr)	(((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory) \
+					&& pfn_valid(__pa(kaddr) >> PAGE_SHIFT) )
 
 #endif
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#1 lore raw

PATCH v3 1/1 arm: Correct virt_addr_valid

Quoted 24 lines · Laura Abbott

The definition of virt_addr_valid is that virt_addr_valid should return true if and only if virt_to_page returns a valid pointer. The current definition of virt_addr_valid only checks against the virtual address range. There's no guarantee that just because a virtual address falls bewteen PAGE_OFFSET and high_memory the associated physical memory has a valid backing struct page. Follow the example of other architectures and convert to pfn_valid to verify that the virtual address is actually valid. The check for an address between PAGE_OFFSET and high_memory is still necessary as vmalloc/highmem addresses are not valid with virt_to_page.

Cc Russell King <[email protected]>
Cc Will Deacon <[email protected]>
Cc Nicolas Pitre <[email protected]>
---
 arch/arm/include/asm/memory.h |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/arm/include/asm/memory.h +0 -0
index 9ecccc8..35a8511 100644

arch/arm/include/asm/memory.h static inline __deprecated void *bus_to_virt(unsigned long x) · line 354

Quoted 6 lines
arch/arm/include/asm/memory.h +2 -1
@@ -350,7 +350,8 @@ static inline __deprecated void *bus_to_virt(unsigned long x)
 #define ARCH_PFN_OFFSET		PHYS_PFN_OFFSET
 
 #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
-#define virt_addr_valid(kaddr)	((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
+#define virt_addr_valid(kaddr)	(((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory) \
+					&& pfn_valid(__pa(kaddr) >> PAGE_SHIFT) )

Will