Skip to content

Commit

Permalink
arch/kunmap_atomic: consolidate duplicate code
Browse files Browse the repository at this point in the history
Every single architecture (including !CONFIG_HIGHMEM) calls...

	pagefault_enable();
	preempt_enable();

... before returning from __kunmap_atomic().  Lift this code into the
kunmap_atomic() macro.

While we are at it rename __kunmap_atomic() to kunmap_atomic_high() to
be consistent.

Link: http://lkml.kernel.org/r/20200507150004.1423069-8-ira.weiny@intel.com
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Christian König <christian.koenig@amd.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Helge Deller <deller@gmx.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
  • Loading branch information
weiny2 authored and sfrothwell committed May 11, 2020
1 parent ac3be52 commit 5ab3e8e
Show file tree
Hide file tree
Showing 23 changed files with 31 additions and 67 deletions.
2 changes: 0 additions & 2 deletions arch/arc/include/asm/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

#include <asm/cacheflush.h>

extern void __kunmap_atomic(void *kvaddr);

extern void kmap_init(void);

static inline void flush_cache_kmaps(void)
Expand Down
7 changes: 2 additions & 5 deletions arch/arc/mm/highmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void *kmap_atomic_high(struct page *page)
}
EXPORT_SYMBOL(kmap_atomic_high);

void __kunmap_atomic(void *kv)
void kunmap_atomic_high(void *kv)
{
unsigned long kvaddr = (unsigned long)kv;

Expand All @@ -87,11 +87,8 @@ void __kunmap_atomic(void *kv)

kmap_atomic_idx_pop();
}

pagefault_enable();
preempt_enable();
}
EXPORT_SYMBOL(__kunmap_atomic);
EXPORT_SYMBOL(kunmap_atomic_high);

static noinline pte_t * __init alloc_kmap_pgtable(unsigned long kvaddr)
{
Expand Down
1 change: 0 additions & 1 deletion arch/arm/include/asm/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ static inline void *kmap_high_get(struct page *page)
* when CONFIG_HIGHMEM is not set.
*/
#ifdef CONFIG_HIGHMEM
extern void __kunmap_atomic(void *kvaddr);
extern void *kmap_atomic_pfn(unsigned long pfn);
#endif

Expand Down
6 changes: 2 additions & 4 deletions arch/arm/mm/highmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void *kmap_atomic_high(struct page *page)
}
EXPORT_SYMBOL(kmap_atomic_high);

void __kunmap_atomic(void *kvaddr)
void kunmap_atomic_high(void *kvaddr)
{
unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
int idx, type;
Expand All @@ -95,10 +95,8 @@ void __kunmap_atomic(void *kvaddr)
/* this address was obtained through kmap_high_get() */
kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)]));
}
pagefault_enable();
preempt_enable();
}
EXPORT_SYMBOL(__kunmap_atomic);
EXPORT_SYMBOL(kunmap_atomic_high);

void *kmap_atomic_pfn(unsigned long pfn)
{
Expand Down
1 change: 0 additions & 1 deletion arch/csky/include/asm/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ extern pte_t *pkmap_page_table;

#define ARCH_HAS_KMAP_FLUSH_TLB
extern void kmap_flush_tlb(unsigned long addr);
extern void __kunmap_atomic(void *kvaddr);
extern void *kmap_atomic_pfn(unsigned long pfn);
extern struct page *kmap_atomic_to_page(void *ptr);

Expand Down
9 changes: 3 additions & 6 deletions arch/csky/mm/highmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ void *kmap_atomic_high(struct page *page)
}
EXPORT_SYMBOL(kmap_atomic_high);

void __kunmap_atomic(void *kvaddr)
void kunmap_atomic_high(void *kvaddr)
{
unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
int idx;

if (vaddr < FIXADDR_START)
goto out;
return;

#ifdef CONFIG_DEBUG_HIGHMEM
idx = KM_TYPE_NR*smp_processor_id() + kmap_atomic_idx();
Expand All @@ -58,11 +58,8 @@ void __kunmap_atomic(void *kvaddr)
(void) idx; /* to kill a warning */
#endif
kmap_atomic_idx_pop();
out:
pagefault_enable();
preempt_enable();
}
EXPORT_SYMBOL(__kunmap_atomic);
EXPORT_SYMBOL(kunmap_atomic_high);

/*
* This is the same as kmap_atomic() but can map memory that doesn't
Expand Down
1 change: 0 additions & 1 deletion arch/microblaze/include/asm/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ static inline void *kmap_atomic_prot(struct page *page, pgprot_t prot)

return kmap_atomic_high_prot(page, prot);
}
extern void __kunmap_atomic(void *kvaddr);

static inline void *kmap_atomic_high(struct page *page)
{
Expand Down
6 changes: 2 additions & 4 deletions arch/microblaze/mm/highmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
}
EXPORT_SYMBOL(kmap_atomic_high_prot);

void __kunmap_atomic(void *kvaddr)
void kunmap_atomic_high(void *kvaddr)
{
unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
int type;
Expand All @@ -77,7 +77,5 @@ void __kunmap_atomic(void *kvaddr)
local_flush_tlb_page(NULL, vaddr);

kmap_atomic_idx_pop();
pagefault_enable();
preempt_enable();
}
EXPORT_SYMBOL(__kunmap_atomic);
EXPORT_SYMBOL(kunmap_atomic_high);
1 change: 0 additions & 1 deletion arch/mips/include/asm/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ extern pte_t *pkmap_page_table;

#define ARCH_HAS_KMAP_FLUSH_TLB
extern void kmap_flush_tlb(unsigned long addr);
extern void __kunmap_atomic(void *kvaddr);
extern void *kmap_atomic_pfn(unsigned long pfn);

#define flush_cache_kmaps() BUG_ON(cpu_has_dc_aliases)
Expand Down
4 changes: 2 additions & 2 deletions arch/mips/mm/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void __flush_dcache_page(struct page *page)
flush_data_cache_page(addr);

if (PageHighMem(page))
__kunmap_atomic((void *)addr);
kunmap_atomic((void *)addr);
}

EXPORT_SYMBOL(__flush_dcache_page);
Expand Down Expand Up @@ -147,7 +147,7 @@ void __update_cache(unsigned long address, pte_t pte)
flush_data_cache_page(addr);

if (PageHighMem(page))
__kunmap_atomic((void *)addr);
kunmap_atomic((void *)addr);

ClearPageDcacheDirty(page);
}
Expand Down
6 changes: 2 additions & 4 deletions arch/mips/mm/highmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void *kmap_atomic_high(struct page *page)
}
EXPORT_SYMBOL(kmap_atomic_high);

void __kunmap_atomic(void *kvaddr)
void kunmap_atomic_high(void *kvaddr)
{
unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
int type __maybe_unused;
Expand All @@ -63,10 +63,8 @@ void __kunmap_atomic(void *kvaddr)
}
#endif
kmap_atomic_idx_pop();
pagefault_enable();
preempt_enable();
}
EXPORT_SYMBOL(__kunmap_atomic);
EXPORT_SYMBOL(kunmap_atomic_high);

/*
* This is the same as kmap_atomic() but can map memory that doesn't
Expand Down
1 change: 0 additions & 1 deletion arch/nds32/include/asm/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ extern void kmap_init(void);
* when CONFIG_HIGHMEM is not set.
*/
#ifdef CONFIG_HIGHMEM
extern void __kunmap_atomic(void *kvaddr);
extern void *kmap_atomic_pfn(unsigned long pfn);
extern struct page *kmap_atomic_to_page(void *ptr);
#endif
Expand Down
6 changes: 2 additions & 4 deletions arch/nds32/mm/highmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void *kmap_atomic_high(struct page *page)
}
EXPORT_SYMBOL(kmap_atomic_high);

void __kunmap_atomic(void *kvaddr)
void kunmap_atomic_high(void *kvaddr)
{
if (kvaddr >= (void *)FIXADDR_START) {
unsigned long vaddr = (unsigned long)kvaddr;
Expand All @@ -44,7 +44,5 @@ void __kunmap_atomic(void *kvaddr)
ptep = pte_offset_kernel(pmd_off_k(vaddr), vaddr);
set_pte(ptep, 0);
}
pagefault_enable();
preempt_enable();
}
EXPORT_SYMBOL(__kunmap_atomic);
EXPORT_SYMBOL(kunmap_atomic_high);
4 changes: 1 addition & 3 deletions arch/parisc/include/asm/cacheflush.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,9 @@ static inline void *kmap_atomic(struct page *page)
return page_address(page);
}

static inline void __kunmap_atomic(void *addr)
static inline void kunmap_atomic_high(void *addr)
{
flush_kernel_dcache_page_addr(addr);
pagefault_enable();
preempt_enable();
}

#define kmap_atomic_prot(page, prot) kmap_atomic(page)
Expand Down
1 change: 0 additions & 1 deletion arch/powerpc/include/asm/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ static inline void *kmap_atomic_prot(struct page *page, pgprot_t prot)

return kmap_atomic_high_prot(page, prot);
}
extern void __kunmap_atomic(void *kvaddr);

static inline void *kmap_atomic_high(struct page *page)
{
Expand Down
6 changes: 2 additions & 4 deletions arch/powerpc/mm/highmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
}
EXPORT_SYMBOL(kmap_atomic_high_prot);

void __kunmap_atomic(void *kvaddr)
void kunmap_atomic_high(void *kvaddr)
{
unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;

Expand All @@ -66,7 +66,5 @@ void __kunmap_atomic(void *kvaddr)
}

kmap_atomic_idx_pop();
pagefault_enable();
preempt_enable();
}
EXPORT_SYMBOL(__kunmap_atomic);
EXPORT_SYMBOL(kunmap_atomic_high);
2 changes: 0 additions & 2 deletions arch/sparc/include/asm/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ void kmap_init(void) __init;

#define PKMAP_END (PKMAP_ADDR(LAST_PKMAP))

void __kunmap_atomic(void *kvaddr);

#define flush_cache_kmaps() flush_cache_all()

#endif /* __KERNEL__ */
Expand Down
6 changes: 2 additions & 4 deletions arch/sparc/mm/highmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void *kmap_atomic_high(struct page *page)
}
EXPORT_SYMBOL(kmap_atomic_high);

void __kunmap_atomic(void *kvaddr)
void kunmap_atomic_high(void *kvaddr)
{
unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
int type;
Expand Down Expand Up @@ -126,7 +126,5 @@ void __kunmap_atomic(void *kvaddr)
#endif

kmap_atomic_idx_pop();
pagefault_enable();
preempt_enable();
}
EXPORT_SYMBOL(__kunmap_atomic);
EXPORT_SYMBOL(kunmap_atomic_high);
1 change: 0 additions & 1 deletion arch/x86/include/asm/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ static inline void *kmap_atomic_high(struct page *page)
{
return kmap_atomic_high_prot(page, kmap_prot);
}
void __kunmap_atomic(void *kvaddr);
void *kmap_atomic_pfn(unsigned long pfn);
void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot);

Expand Down
7 changes: 2 additions & 5 deletions arch/x86/mm/highmem_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void *kmap_atomic_pfn(unsigned long pfn)
}
EXPORT_SYMBOL_GPL(kmap_atomic_pfn);

void __kunmap_atomic(void *kvaddr)
void kunmap_atomic_high(void *kvaddr)
{
unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;

Expand Down Expand Up @@ -60,11 +60,8 @@ void __kunmap_atomic(void *kvaddr)
BUG_ON(vaddr >= (unsigned long)high_memory);
}
#endif

pagefault_enable();
preempt_enable();
}
EXPORT_SYMBOL(__kunmap_atomic);
EXPORT_SYMBOL(kunmap_atomic_high);

void __init set_highmem_pages_init(void)
{
Expand Down
2 changes: 0 additions & 2 deletions arch/xtensa/include/asm/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ static inline void flush_cache_kmaps(void)
flush_cache_all();
}

void __kunmap_atomic(void *kvaddr);

void kmap_init(void);

#endif
7 changes: 2 additions & 5 deletions arch/xtensa/mm/highmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void *kmap_atomic_high(struct page *page)
}
EXPORT_SYMBOL(kmap_atomic_high);

void __kunmap_atomic(void *kvaddr)
void kunmap_atomic_high(void *kvaddr)
{
if (kvaddr >= (void *)FIXADDR_START &&
kvaddr < (void *)FIXADDR_TOP) {
Expand All @@ -73,11 +73,8 @@ void __kunmap_atomic(void *kvaddr)

kmap_atomic_idx_pop();
}

pagefault_enable();
preempt_enable();
}
EXPORT_SYMBOL(__kunmap_atomic);
EXPORT_SYMBOL(kunmap_atomic_high);

void __init kmap_init(void)
{
Expand Down
11 changes: 7 additions & 4 deletions include/linux/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static inline void invalidate_kernel_vmap_range(void *vaddr, int size)

#ifdef CONFIG_HIGHMEM
extern void *kmap_atomic_high(struct page *page);
extern void kunmap_atomic_high(void *kvaddr);
#include <asm/highmem.h>

#ifndef ARCH_HAS_KMAP_FLUSH_TLB
Expand Down Expand Up @@ -151,10 +152,10 @@ static inline void *kmap_atomic(struct page *page)
}
#define kmap_atomic_prot(page, prot) kmap_atomic(page)

static inline void __kunmap_atomic(void *addr)
static inline void kunmap_atomic_high(void *addr)
{
pagefault_enable();
preempt_enable();
/* Nothing to do in the CONFIG_HIGHMEM=n case as kunmap_atomic()
* handles re-enabling faults + preemption */
}

#define kmap_atomic_pfn(pfn) kmap_atomic(pfn_to_page(pfn))
Expand Down Expand Up @@ -204,7 +205,9 @@ static inline void kmap_atomic_idx_pop(void)
#define kunmap_atomic(addr) \
do { \
BUILD_BUG_ON(__same_type((addr), struct page *)); \
__kunmap_atomic(addr); \
kunmap_atomic_high(addr); \
pagefault_enable(); \
preempt_enable(); \
} while (0)


Expand Down

0 comments on commit 5ab3e8e

Please sign in to comment.