Skip to content

Commit 873ba46

Browse files
rppttorvalds
authored andcommitted
arm64: decouple check whether pfn is in linear map from pfn_valid()
The intended semantics of pfn_valid() is to verify whether there is a struct page for the pfn in question and nothing else. Yet, on arm64 it is used to distinguish memory areas that are mapped in the linear map vs those that require ioremap() to access them. Introduce a dedicated pfn_is_map_memory() wrapper for memblock_is_map_memory() to perform such check and use it where appropriate. Using a wrapper allows to avoid cyclic include dependencies. While here also update style of pfn_valid() so that both pfn_valid() and pfn_is_map_memory() declarations will be consistent. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Mike Rapoport <[email protected]> Acked-by: David Hildenbrand <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Reviewed-by: Kefeng Wang <[email protected]> Cc: Anshuman Khandual <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 9092d4f commit 873ba46

File tree

6 files changed

+19
-6
lines changed

6 files changed

+19
-6
lines changed

arch/arm64/include/asm/memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ static inline void *phys_to_virt(phys_addr_t x)
369369

370370
#define virt_addr_valid(addr) ({ \
371371
__typeof__(addr) __addr = __tag_reset(addr); \
372-
__is_lm_address(__addr) && pfn_valid(virt_to_pfn(__addr)); \
372+
__is_lm_address(__addr) && pfn_is_map_memory(virt_to_pfn(__addr)); \
373373
})
374374

375375
void dump_mem_limit(void);

arch/arm64/include/asm/page.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ void copy_highpage(struct page *to, struct page *from);
3737

3838
typedef struct page *pgtable_t;
3939

40-
extern int pfn_valid(unsigned long);
40+
int pfn_valid(unsigned long pfn);
41+
int pfn_is_map_memory(unsigned long pfn);
4142

4243
#include <asm/memory.h>
4344

arch/arm64/kvm/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void kvm_flush_remote_tlbs(struct kvm *kvm)
8585

8686
static bool kvm_is_device_pfn(unsigned long pfn)
8787
{
88-
return !pfn_valid(pfn);
88+
return !pfn_is_map_memory(pfn);
8989
}
9090

9191
static void *stage2_memcache_zalloc_page(void *arg)

arch/arm64/mm/init.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,18 @@ int pfn_valid(unsigned long pfn)
256256
}
257257
EXPORT_SYMBOL(pfn_valid);
258258

259+
int pfn_is_map_memory(unsigned long pfn)
260+
{
261+
phys_addr_t addr = PFN_PHYS(pfn);
262+
263+
/* avoid false positives for bogus PFNs, see comment in pfn_valid() */
264+
if (PHYS_PFN(addr) != pfn)
265+
return 0;
266+
267+
return memblock_is_map_memory(addr);
268+
}
269+
EXPORT_SYMBOL(pfn_is_map_memory);
270+
259271
static phys_addr_t memory_limit = PHYS_ADDR_MAX;
260272

261273
/*

arch/arm64/mm/ioremap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static void __iomem *__ioremap_caller(phys_addr_t phys_addr, size_t size,
4343
/*
4444
* Don't allow RAM to be mapped.
4545
*/
46-
if (WARN_ON(pfn_valid(__phys_to_pfn(phys_addr))))
46+
if (WARN_ON(pfn_is_map_memory(__phys_to_pfn(phys_addr))))
4747
return NULL;
4848

4949
area = get_vm_area_caller(size, VM_IOREMAP, caller);
@@ -84,7 +84,7 @@ EXPORT_SYMBOL(iounmap);
8484
void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size)
8585
{
8686
/* For normal memory we already have a cacheable mapping. */
87-
if (pfn_valid(__phys_to_pfn(phys_addr)))
87+
if (pfn_is_map_memory(__phys_to_pfn(phys_addr)))
8888
return (void __iomem *)__phys_to_virt(phys_addr);
8989

9090
return __ioremap_caller(phys_addr, size, __pgprot(PROT_NORMAL),

arch/arm64/mm/mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void set_swapper_pgd(pgd_t *pgdp, pgd_t pgd)
8282
pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
8383
unsigned long size, pgprot_t vma_prot)
8484
{
85-
if (!pfn_valid(pfn))
85+
if (!pfn_is_map_memory(pfn))
8686
return pgprot_noncached(vma_prot);
8787
else if (file->f_flags & O_SYNC)
8888
return pgprot_writecombine(vma_prot);

0 commit comments

Comments
 (0)