diff mbox series

[v2] arm64: fix kcore macros 52-bit va fallout

Message ID 20191010172247.19033-1-crecklin@redhat.com (mailing list archive)
State Mainlined
Commit 86109a691a454e08cbe0356400268cb2a81f1997
Headers show
Series [v2] arm64: fix kcore macros 52-bit va fallout | expand

Commit Message

Chris von Recklinghausen Oct. 10, 2019, 5:22 p.m. UTC
We export the entire kernel address space (i.e. the whole of the TTBR1
address range) via /proc/kcore. The kc_vaddr_to_offset() and
kc_offset_to_vaddr() macros are intended to convert between a kernel
virtual address and its offset relative to the start of the TTBR1
address space.

Prior to commit:

  14c127c957c1c607 ("arm64: mm: Flip kernel VA space")

... the offset was calculated relative to VA_START, which at the time
was the start of the TTBR1 address space. At this time, PAGE_OFFSET
pointed to the high half of the TTBR1 address space where arm64's
linear map lived.

That commit swapped the position of VA_START and PAGE_OFFSET, but
failed to update kc_vaddr_to_offset() or kc_offset_to_vaddr(), so
since then the two macros behave incorrectly.

Note that VA_START was subsequently renamed to PAGE_END in commit:

  77ad4ce69321abbe ("arm64: memory: rename VA_START to PAGE_END")

As the generic implementations of the two macros calculate the offset
relative to PAGE_OFFSET (which is now the start of the TTBR1 address
space), we can delete the arm64 implementation and use those.

Fixes: 14c127c957c1c607 ("arm64: mm: Flip kernel VA space")

Signed-off-by: Chris von Recklinghausen <crecklin@redhat.com>
---
v1 -> v2
   reword commit comment to to what Mark Rutland suggested
   add Signed-off-by
   no code changes

 arch/arm64/include/asm/pgtable.h | 3 ---
 1 file changed, 3 deletions(-)

Comments

James Morse Oct. 11, 2019, 3:37 p.m. UTC | #1
Hi Chris,

On 10/10/2019 18:22, Chris von Recklinghausen wrote:
> We export the entire kernel address space (i.e. the whole of the TTBR1
> address range) via /proc/kcore. The kc_vaddr_to_offset() and
> kc_offset_to_vaddr() macros are intended to convert between a kernel
> virtual address and its offset relative to the start of the TTBR1
> address space.
> 
> Prior to commit:
> 
>   14c127c957c1c607 ("arm64: mm: Flip kernel VA space")
> 
> ... the offset was calculated relative to VA_START, which at the time
> was the start of the TTBR1 address space. At this time, PAGE_OFFSET
> pointed to the high half of the TTBR1 address space where arm64's
> linear map lived.
> 
> That commit swapped the position of VA_START and PAGE_OFFSET, but
> failed to update kc_vaddr_to_offset() or kc_offset_to_vaddr(), so
> since then the two macros behave incorrectly.
> 
> Note that VA_START was subsequently renamed to PAGE_END in commit:
> 
>   77ad4ce69321abbe ("arm64: memory: rename VA_START to PAGE_END")
> 
> As the generic implementations of the two macros calculate the offset
> relative to PAGE_OFFSET (which is now the start of the TTBR1 address
> space), we can delete the arm64 implementation and use those.

Reviewed-by: James Morse <james.morse@arm.com>

I think you can pick up Mark's R-B tag too:
https://lore.kernel.org/r/20191010165537.GA27584@lakrids.cambridge.arm.com


Thanks,

James
Will Deacon Oct. 11, 2019, 4:38 p.m. UTC | #2
On Thu, Oct 10, 2019 at 01:22:47PM -0400, Chris von Recklinghausen wrote:
> We export the entire kernel address space (i.e. the whole of the TTBR1
> address range) via /proc/kcore. The kc_vaddr_to_offset() and
> kc_offset_to_vaddr() macros are intended to convert between a kernel
> virtual address and its offset relative to the start of the TTBR1
> address space.
> 
> Prior to commit:
> 
>   14c127c957c1c607 ("arm64: mm: Flip kernel VA space")
> 
> ... the offset was calculated relative to VA_START, which at the time
> was the start of the TTBR1 address space. At this time, PAGE_OFFSET
> pointed to the high half of the TTBR1 address space where arm64's
> linear map lived.
> 
> That commit swapped the position of VA_START and PAGE_OFFSET, but
> failed to update kc_vaddr_to_offset() or kc_offset_to_vaddr(), so
> since then the two macros behave incorrectly.
> 
> Note that VA_START was subsequently renamed to PAGE_END in commit:
> 
>   77ad4ce69321abbe ("arm64: memory: rename VA_START to PAGE_END")
> 
> As the generic implementations of the two macros calculate the offset
> relative to PAGE_OFFSET (which is now the start of the TTBR1 address
> space), we can delete the arm64 implementation and use those.
> 
> Fixes: 14c127c957c1c607 ("arm64: mm: Flip kernel VA space")
> 
> Signed-off-by: Chris von Recklinghausen <crecklin@redhat.com>
> ---
> v1 -> v2
>    reword commit comment to to what Mark Rutland suggested
>    add Signed-off-by
>    no code changes
> 
>  arch/arm64/include/asm/pgtable.h | 3 ---
>  1 file changed, 3 deletions(-)

Thanks. Queued as a fix with James and Mark's reviewed-by tags.

Will
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 7576df00eb50..8330810f699e 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -876,9 +876,6 @@  static inline void update_mmu_cache(struct vm_area_struct *vma,
 
 #define update_mmu_cache_pmd(vma, address, pmd) do { } while (0)
 
-#define kc_vaddr_to_offset(v)	((v) & ~PAGE_END)
-#define kc_offset_to_vaddr(o)	((o) | PAGE_END)
-
 #ifdef CONFIG_ARM64_PA_BITS_52
 #define phys_to_ttbr(addr)	(((addr) | ((addr) >> 46)) & TTBR_BADDR_MASK_52)
 #else