arm: Correct virt_addr_valid
Subsystems (2)
PATCH v2 1/2 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.
--- arch/arm/include/asm/memory.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
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) (pfn_valid(__pa(kaddr) >> PAGE_SHIFT) && \ + ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory))#endif
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 2/2 arm64: 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.
--- arch/arm64/include/asm/memory.h | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
arch/arm64/include/asm/memory.h +3 -2
@@ -146,8 +146,9 @@ static inline void *phys_to_virt(phys_addr_t 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) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \ - ((void *)(kaddr) < (void *)high_memory)) +#define virt_addr_valid (kaddr) (pfn_valid(__pa(kaddr) >> PAGE_SHIFT) && \ + ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)) +#endif
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Catalin Marinas
maintainerPATCH v2 2/2 arm64: Correct virt_addr_valid
arch/arm64/include/asm/memory.h static inline void *phys_to_virt(phys_addr_t x) · line 151
Quoted 13 lines · Laura Abbott
arch/arm64/include/asm/memory.h +3
-2@@ -146,8 +146,9 @@ static inline void *phys_to_virt(phys_addr_t 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) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \ - ((void *)(kaddr) < (void *)high_memory)) +#define virt_addr_valid (kaddr) (pfn_valid(__pa(kaddr) >> PAGE_SHIFT) && \ + ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)) +
I still think the original patch was fine for arm64, no need for additional checks since we don't have highmem and __pa() is always linear.
Signature · 1 line
Catalin
PATCH v2 1/2 arm: Correct virt_addr_valid
In reply to Laura AbbottQuoted 24 lines · Laura Abbott
The definition of
virt_addr_validis thatvirt_addr_validshould return true if and only ifvirt_to_pagereturns a valid pointer. The current definition ofvirt_addr_validonly checks against the virtual address range. There's no guarantee that just because a virtual address falls bewteenPAGE_OFFSETandhigh_memorythe associated physical memory has a valid backing struct page. Follow the example of other architectures and convert topfn_validto verify that the virtual address is actually valid. The check for an address betweenPAGE_OFFSETandhigh_memoryis still necessary as vmalloc/highmem addresses are not valid withvirt_to_page.Cc Russell King <[email protected]>Cc Will Deacon <[email protected]>Cc Nicolas Pitre <[email protected]>Signed-off-by Laura Abbott <[email protected]>--- arch/arm/include/asm/memory.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)arch/arm/include/asm/memory.h +0
-0
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) (pfn_valid(__pa(kaddr) >> PAGE_SHIFT) && \ + ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory))
Can you change the order of the check please, so that we do the quicker lowmem range checks before the pfn_valid check? I know I backed down on the latter being slow, but it's still slower than what we had before and changing the order of the conjunction is easy to do.
Cheers,
Will
PATCH v2 2/2 arm64: Correct virt_addr_valid
In reply to Catalin MarinasQuoted 8 lines · Catalin Marinas
Quoted 7 lines · Laura Abbott
arch/arm64/include/asm/memory.h +0
-0@@ -146,8 +146,9 @@ static inline void *phys_to_virt(phys_addr_t x)#define ARCH_PFN_OFFSET PHYS_PFN_OFFSET
Quoted 11 lines
arch/arm64/include/asm/memory.h static inline void *phys_to_virt(phys_addr_t x) · line 151
Quoted 6 lines
arch/arm64/include/asm/memory.h +3
-2#define virt_to_page (kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) -#define virt_addr_valid (kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \ - ((void *)(kaddr) < (void *)high_memory)) +#define virt_addr_valid (kaddr) (pfn_valid(__pa(kaddr) >> PAGE_SHIFT) && \ + ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)) +I still think the original patch was fine for arm64, no need for additional checks since we don't have highmem and
__pa()is always linear.
Okay, do you want to go ahead and just take the previous version then?
Laura
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Catalin Marinas
maintainerPATCH v2 2/2 arm64: Correct virt_addr_valid
Quoted 20 lines · Laura Abbott
Quoted 8 lines · Catalin Marinas
Quoted 7 lines · Laura Abbott
arch/arm64/include/asm/memory.h +0
-0@@ -146,8 +146,9 @@ static inline void *phys_to_virt(phys_addr_t x)#define ARCH_PFN_OFFSET PHYS_PFN_OFFSETQuoted 10 lines
arch/arm64/include/asm/memory.h static inline void *phys_to_virt(phys_addr_t x) · line 151
Quoted 6 lines
arch/arm64/include/asm/memory.h +3
-2#define virt_to_page (kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) -#define virt_addr_valid (kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \ - ((void *)(kaddr) < (void *)high_memory)) +#define virt_addr_valid (kaddr) (pfn_valid(__pa(kaddr) >> PAGE_SHIFT) && \ + ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)) +I still think the original patch was fine for arm64, no need for additional checks since we don't have highmem and
__pa()is always linear.
Quoted 1 line
Okay, do you want to go ahead and just take the previous version then?
I already did (while Will is away ;)). Thanks.
Signature · 1 line
Catalin