Skip to contentSkip to conversation

arm64: add kc_offset_to_vaddr and kc_vaddr_to_offset macro

PATCH In review yalin wang 2 participants 2 messages Sep 6, 2015 – Sep 7, 2015 arm64

lore
Share & tools
lore

yalin wang

author
#0 lore raw

PATCH v2 1/1 arm64: add kc_offset_to_vaddr and kc_vaddr_to_offset macro

This patch add kc_offset_to_vaddr() and kc_vaddr_to_offset(), the default version doesn't work on arm64, because arm64 kernel address is below the PAGE_OFFSET, like module address and vmemmap address are all below PAGE_OFFSET address.

---
 arch/arm64/include/asm/memory.h  | 1 +
 arch/arm64/include/asm/pgtable.h | 2 ++
 2 files changed, 3 insertions(+)
arch/arm64/include/asm/memory.h +1 -0
index f800d45..2d09fe8 100644
@@ -55,6 +55,7 @@
 #define PCI_IO_START		(PCI_IO_END - PCI_IO_SIZE)
 #define FIXADDR_TOP		(PCI_IO_START - SZ_2M)
 #define TASK_SIZE_64		(UL(1) << VA_BITS)
+#define __VIRTUAL_MASK		((1UL << VA_BITS) - 1)
 
 #ifdef CONFIG_COMPAT
 #define TASK_SIZE_32		UL(0x100000000)
arch/arm64/include/asm/pgtable.h +2 -0
index d374191..9da6681 100644
@@ -660,6 +660,8 @@ 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) & __VIRTUAL_MASK)
+#define	kc_offset_to_vaddr(o) ((o) | ~__VIRTUAL_MASK)
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __ASM_PGTABLE_H */
Signature · 1 line
1.9.1
#1 lore raw

On Sep 6, 2015, at 1:04 PM, yalin wang wrote:

Hello Yalin,

Quoted 16 lines

This patch add kc_offset_to_vaddr() and kc_vaddr_to_offset(), the default version doesn't work on arm64, because arm64 kernel address is below the PAGE_OFFSET, like module address and vmemmap address are all below PAGE_OFFSET address.

---
arch/arm64/include/asm/memory.h | 1 +
arch/arm64/include/asm/pgtable.h | 2 ++

2 files changed, 3 insertions(+)
arch/arm64/include/asm/memory.h +0 -0
index f800d45..2d09fe8 100644

arch/arm64/include/asm/memory.h line 58

Quoted 4 lines
arch/arm64/include/asm/memory.h +1 -0
@@ -55,6 +55,7 @@
 #define PCI_IO_START		(PCI_IO_END - PCI_IO_SIZE)
 #define FIXADDR_TOP		(PCI_IO_START - SZ_2M)
 #define TASK_SIZE_64		(UL(1) << VA_BITS)
+#define __VIRTUAL_MASK		((1UL << VA_BITS) - 1)

According to Catalin's comment, [1], it might need to be rewritten using VA_START in the KASan patches, [2], after this merge window.

[1] https://lkml.org/lkml/2015/9/4/529
[2] git://github.com/aryabinin/linux.git kasan/arm64v5

Best Regards
Jungseok Lee