Skip to content

Commit 307fed0

Browse files
weiny2sfrothwell
authored andcommitted
arch/kmap_atomic: consolidate duplicate code
Every arch has the same code to ensure atomic operations and a check for !HIGHMEM page. Remove the duplicate code by defining a core kmap_atomic() which only calls the arch specific kmap_atomic_high() when the page is high memory. Link: http://lkml.kernel.org/r/20200507150004.1423069-7-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>
1 parent 0afb944 commit 307fed0

File tree

21 files changed

+46
-91
lines changed

21 files changed

+46
-91
lines changed

arch/arc/include/asm/highmem.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include <asm/cacheflush.h>
3232

33-
extern void *kmap_atomic(struct page *page);
3433
extern void __kunmap_atomic(void *kvaddr);
3534

3635
extern void kmap_init(void);

arch/arc/mm/highmem.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,11 @@
4949
extern pte_t * pkmap_page_table;
5050
static pte_t * fixmap_page_table;
5151

52-
void *kmap_atomic(struct page *page)
52+
void *kmap_atomic_high(struct page *page)
5353
{
5454
int idx, cpu_idx;
5555
unsigned long vaddr;
5656

57-
preempt_disable();
58-
pagefault_disable();
59-
if (!PageHighMem(page))
60-
return page_address(page);
61-
6257
cpu_idx = kmap_atomic_idx_push();
6358
idx = cpu_idx + KM_TYPE_NR * smp_processor_id();
6459
vaddr = FIXMAP_ADDR(idx);
@@ -68,7 +63,7 @@ void *kmap_atomic(struct page *page)
6863

6964
return (void *)vaddr;
7065
}
71-
EXPORT_SYMBOL(kmap_atomic);
66+
EXPORT_SYMBOL(kmap_atomic_high);
7267

7368
void __kunmap_atomic(void *kv)
7469
{

arch/arm/include/asm/highmem.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ static inline void *kmap_high_get(struct page *page)
6060
* when CONFIG_HIGHMEM is not set.
6161
*/
6262
#ifdef CONFIG_HIGHMEM
63-
extern void *kmap_atomic(struct page *page);
6463
extern void __kunmap_atomic(void *kvaddr);
6564
extern void *kmap_atomic_pfn(unsigned long pfn);
6665
#endif

arch/arm/mm/highmem.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,13 @@ static inline pte_t get_fixmap_pte(unsigned long vaddr)
3131
return *ptep;
3232
}
3333

34-
void *kmap_atomic(struct page *page)
34+
void *kmap_atomic_high(struct page *page)
3535
{
3636
unsigned int idx;
3737
unsigned long vaddr;
3838
void *kmap;
3939
int type;
4040

41-
preempt_disable();
42-
pagefault_disable();
43-
if (!PageHighMem(page))
44-
return page_address(page);
45-
4641
#ifdef CONFIG_DEBUG_HIGHMEM
4742
/*
4843
* There is no cache coherency issue when non VIVT, so force the
@@ -76,7 +71,7 @@ void *kmap_atomic(struct page *page)
7671

7772
return (void *)vaddr;
7873
}
79-
EXPORT_SYMBOL(kmap_atomic);
74+
EXPORT_SYMBOL(kmap_atomic_high);
8075

8176
void __kunmap_atomic(void *kvaddr)
8277
{

arch/csky/include/asm/highmem.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ extern pte_t *pkmap_page_table;
3232

3333
#define ARCH_HAS_KMAP_FLUSH_TLB
3434
extern void kmap_flush_tlb(unsigned long addr);
35-
extern void *kmap_atomic(struct page *page);
3635
extern void __kunmap_atomic(void *kvaddr);
3736
extern void *kmap_atomic_pfn(unsigned long pfn);
3837
extern struct page *kmap_atomic_to_page(void *ptr);

arch/csky/mm/highmem.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,11 @@ EXPORT_SYMBOL(kmap_flush_tlb);
2121

2222
EXPORT_SYMBOL(kmap);
2323

24-
void *kmap_atomic(struct page *page)
24+
void *kmap_atomic_high(struct page *page)
2525
{
2626
unsigned long vaddr;
2727
int idx, type;
2828

29-
preempt_disable();
30-
pagefault_disable();
31-
if (!PageHighMem(page))
32-
return page_address(page);
33-
3429
type = kmap_atomic_idx_push();
3530
idx = type + KM_TYPE_NR*smp_processor_id();
3631
vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
@@ -42,7 +37,7 @@ void *kmap_atomic(struct page *page)
4237

4338
return (void *)vaddr;
4439
}
45-
EXPORT_SYMBOL(kmap_atomic);
40+
EXPORT_SYMBOL(kmap_atomic_high);
4641

4742
void __kunmap_atomic(void *kvaddr)
4843
{

arch/microblaze/include/asm/highmem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ static inline void *kmap_atomic_prot(struct page *page, pgprot_t prot)
6363
}
6464
extern void __kunmap_atomic(void *kvaddr);
6565

66-
static inline void *kmap_atomic(struct page *page)
66+
static inline void *kmap_atomic_high(struct page *page)
6767
{
68-
return kmap_atomic_prot(page, kmap_prot);
68+
return kmap_atomic_high_prot(page, kmap_prot);
6969
}
7070

7171
#define flush_cache_kmaps() { flush_icache(); flush_dcache(); }

arch/mips/include/asm/highmem.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ extern pte_t *pkmap_page_table;
4848

4949
#define ARCH_HAS_KMAP_FLUSH_TLB
5050
extern void kmap_flush_tlb(unsigned long addr);
51-
extern void *kmap_atomic(struct page *page);
5251
extern void __kunmap_atomic(void *kvaddr);
5352
extern void *kmap_atomic_pfn(unsigned long pfn);
5453

arch/mips/mm/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#include <linux/sched.h>
1515
#include <linux/syscalls.h>
1616
#include <linux/mm.h>
17+
#include <linux/highmem.h>
1718

1819
#include <asm/cacheflush.h>
19-
#include <asm/highmem.h>
2020
#include <asm/processor.h>
2121
#include <asm/cpu.h>
2222
#include <asm/cpu-features.h>

arch/mips/mm/highmem.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,11 @@ void kmap_flush_tlb(unsigned long addr)
1818
}
1919
EXPORT_SYMBOL(kmap_flush_tlb);
2020

21-
/*
22-
* kmap_atomic/kunmap_atomic is significantly faster than kmap/kunmap because
23-
* no global lock is needed and because the kmap code must perform a global TLB
24-
* invalidation when the kmap pool wraps.
25-
*
26-
* However when holding an atomic kmap is is not legal to sleep, so atomic
27-
* kmaps are appropriate for short, tight code paths only.
28-
*/
29-
30-
void *kmap_atomic(struct page *page)
21+
void *kmap_atomic_high(struct page *page)
3122
{
3223
unsigned long vaddr;
3324
int idx, type;
3425

35-
preempt_disable();
36-
pagefault_disable();
37-
if (!PageHighMem(page))
38-
return page_address(page);
39-
4026
type = kmap_atomic_idx_push();
4127
idx = type + KM_TYPE_NR*smp_processor_id();
4228
vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
@@ -48,7 +34,7 @@ void *kmap_atomic(struct page *page)
4834

4935
return (void*) vaddr;
5036
}
51-
EXPORT_SYMBOL(kmap_atomic);
37+
EXPORT_SYMBOL(kmap_atomic_high);
5238

5339
void __kunmap_atomic(void *kvaddr)
5440
{

0 commit comments

Comments
 (0)