Skip to content

Commit 1dff808

Browse files
Ard Biesheuvelwildea01
authored andcommitted
mm: replace open coded page to virt conversion with page_to_virt()
The open coded conversion from struct page address to virtual address in lowmem_page_address() involves an intermediate conversion step to pfn number/physical address. Since the placement of the struct page array relative to the linear mapping may be completely independent from the placement of physical RAM (as is that case for arm64 after commit dfd55ad 'arm64: vmemmap: use virtual projection of linear region'), the conversion to physical address and back again should factor out of the equation, but unfortunately, the shifting and pointer arithmetic involved prevent this from happening, and the resulting calculation essentially subtracts the address of the start of physical memory and adds it back again, in a way that prevents the compiler from optimizing it away. Since the start of physical memory is not a build time constant on arm64, the resulting conversion involves an unnecessary memory access, which we would like to get rid of. So replace the open coded conversion with a call to page_to_virt(), and use the open coded conversion as its default definition, to be overriden by the architecture, if desired. The existing arch specific definitions of page_to_virt are all equivalent to this default definition, so by itself this patch is a no-op. Acked-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 86d618c commit 1dff808

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

include/linux/mm.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ extern int mmap_rnd_compat_bits __read_mostly;
7272
#define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
7373
#endif
7474

75+
#ifndef page_to_virt
76+
#define page_to_virt(x) __va(PFN_PHYS(page_to_pfn(x)))
77+
#endif
78+
7579
/*
7680
* To prevent common memory management code establishing
7781
* a zero page mapping on a read fault.
@@ -948,7 +952,7 @@ static inline struct mem_cgroup *page_memcg(struct page *page)
948952

949953
static __always_inline void *lowmem_page_address(const struct page *page)
950954
{
951-
return __va(PFN_PHYS(page_to_pfn(page)));
955+
return page_to_virt(page);
952956
}
953957

954958
#if defined(CONFIG_HIGHMEM) && !defined(WANT_PAGE_VIRTUAL)

0 commit comments

Comments
 (0)