History

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. [akpm@linux-foundation.org: coding style fixes] Signed-off-by: Ira Weiny <ira.weiny@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> 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> Link: http://lkml.kernel.org/r/20200507150004.1423069-7-ira.weiny@intel.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Ira Weiny committed 6 years ago

Commit 78b6d911 parent ee9bc5f21 files · +46 −93Browse files

Unified · Split

21 files
  1. arch/arc/include/asm/highmem.h +0 −1
  2. arch/arc/mm/highmem.c +2 −7
  3. arch/arm/include/asm/highmem.h +0 −1
  4. arch/arm/mm/highmem.c +2 −7
  5. arch/csky/include/asm/highmem.h +0 −1
  6. arch/csky/mm/highmem.c +2 −7
  7. arch/microblaze/include/asm/highmem.h +2 −2
  8. arch/mips/include/asm/highmem.h +0 −1
  9. arch/mips/mm/cache.c +1 −1
  10. arch/mips/mm/highmem.c +2 −16
  11. arch/nds32/include/asm/highmem.h +0 −1
  12. arch/nds32/mm/highmem.c +2 −9
  13. arch/powerpc/include/asm/highmem.h +2 −2
  14. arch/powerpc/mm/highmem.c +0 −6
  15. arch/sparc/include/asm/highmem.h +0 −1
  16. arch/sparc/mm/highmem.c +2 −7
  17. arch/x86/include/asm/highmem.h +4 −1
  18. arch/x86/mm/highmem_32.c +0 −14
  19. arch/xtensa/include/asm/highmem.h +0 −1
  20. arch/xtensa/mm/highmem.c +2 −7
  21. include/linux/highmem.h +23 −0
arch/arc/include/asm/highmem.h+0−1
@@ -30,7 +30,6 @@ · 29 unmodified lines
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+2−7
@@ -49,16 +49,11 @@ · 48 unmodified lines
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) · 3 unmodified lines
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+0−1
@@ -60,7 +60,6 @@ static inline void *kmap_high_get(struct page *page) · 59 unmodified lines
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+2−7
@@ -31,18 +31,13 @@ static inline pte_t get_fixmap_pte(unsigned long vaddr) · 30 unmodified lines
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) · 27 unmodified lines
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+0−1
@@ -32,7 +32,6 @@ extern pte_t *pkmap_page_table; · 31 unmodified lines
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+2−7
@@ -21,16 +21,11 @@ EXPORT_SYMBOL(kmap_flush_tlb); · 20 unmodified lines
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) · 5 unmodified lines
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+2−2
@@ -63,9 +63,9 @@ static inline void *kmap_atomic_prot(struct page *page, pgprot_t prot) · 62 unmodified lines
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+0−1
@@ -48,7 +48,6 @@ extern pte_t *pkmap_page_table; · 47 unmodified lines
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+1−1
@@ -14,9 +14,9 @@ · 13 unmodified lines
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+2−16
@@ -18,25 +18,11 @@ void kmap_flush_tlb(unsigned long addr) · 17 unmodified lines
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) · 5 unmodified lines
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 {
arch/nds32/include/asm/highmem.h+0−1
@@ -51,7 +51,6 @@ extern void kmap_init(void); · 50 unmodified lines
5151 * when CONFIG_HIGHMEM is not set.
5252 */
5353 #ifdef CONFIG_HIGHMEM
54−extern void *kmap_atomic(struct page *page);
5554 extern void __kunmap_atomic(void *kvaddr);
5655 extern void *kmap_atomic_pfn(unsigned long pfn);
5756 extern struct page *kmap_atomic_to_page(void *ptr);
arch/nds32/mm/highmem.c+2−9
@@ -10,18 +10,13 @@ · 9 unmodified lines
1010 #include <asm/fixmap.h>
1111 #include <asm/tlbflush.h>
1212
13−void *kmap_atomic(struct page *page)
13+void *kmap_atomic_high(struct page *page)
1414 {
1515 unsigned int idx;
1616 unsigned long vaddr, pte;
1717 int type;
1818 pte_t *ptep;
1919
20− preempt_disable();
21− pagefault_disable();
22− if (!PageHighMem(page))
23− return page_address(page);
24−
2520 type = kmap_atomic_idx_push();
2621
2722 idx = type + KM_TYPE_NR * smp_processor_id();
@@ -36,8 +31,7 @@ void *kmap_atomic(struct page *page) · 8 unmodified lines
3631 __nds32__isb();
3732 return (void *)vaddr;
3833 }
39−
40−EXPORT_SYMBOL(kmap_atomic);
34+EXPORT_SYMBOL(kmap_atomic_high);
4135
4236 void __kunmap_atomic(void *kvaddr)
4337 {
@@ -53,5 +47,4 @@ void __kunmap_atomic(void *kvaddr) · 9 unmodified lines
5347 pagefault_enable();
5448 preempt_enable();
5549 }
56−
5750 EXPORT_SYMBOL(__kunmap_atomic);
arch/powerpc/include/asm/highmem.h+2−2
@@ -71,9 +71,9 @@ static inline void *kmap_atomic_prot(struct page *page, pgprot_t prot) · 70 unmodified lines
7171 }
7272 extern void __kunmap_atomic(void *kvaddr);
7373
74−static inline void *kmap_atomic(struct page *page)
74+static inline void *kmap_atomic_high(struct page *page)
7575 {
76− return kmap_atomic_prot(page, kmap_prot);
76+ return kmap_atomic_high_prot(page, kmap_prot);
7777 }
7878
7979
arch/powerpc/mm/highmem.c+0−6
@@ -24,12 +24,6 @@ · 23 unmodified lines
2424 #include <linux/highmem.h>
2525 #include <linux/module.h>
2626
27−/*
28− * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
29− * gives a more generic (and caching) interface. But kmap_atomic can
30− * be used in IRQ contexts, so in some (very limited) cases we need
31− * it.
32− */
3327 void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
3428 {
3529 unsigned long vaddr;
arch/sparc/include/asm/highmem.h+0−1
@@ -50,7 +50,6 @@ void kmap_init(void) __init; · 49 unmodified lines
5050
5151 #define PKMAP_END (PKMAP_ADDR(LAST_PKMAP))
5252
53−void *kmap_atomic(struct page *page);
5453 void __kunmap_atomic(void *kvaddr);
5554
5655 #define flush_cache_kmaps() flush_cache_all()
arch/sparc/mm/highmem.c+2−7
@@ -53,16 +53,11 @@ void __init kmap_init(void) · 52 unmodified lines
5353 kmap_prot = __pgprot(SRMMU_ET_PTE | SRMMU_PRIV | SRMMU_CACHE);
5454 }
5555
56−void *kmap_atomic(struct page *page)
56+void *kmap_atomic_high(struct page *page)
5757 {
5858 unsigned long vaddr;
5959 long idx, type;
6060
61− preempt_disable();
62− pagefault_disable();
63− if (!PageHighMem(page))
64− return page_address(page);
65−
6661 type = kmap_atomic_idx_push();
6762 idx = type + KM_TYPE_NR*smp_processor_id();
6863 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
@@ -87,7 +82,7 @@ void *kmap_atomic(struct page *page) · 18 unmodified lines
8782
8883 return (void*) vaddr;
8984 }
90−EXPORT_SYMBOL(kmap_atomic);
85+EXPORT_SYMBOL(kmap_atomic_high);
9186
9287 void __kunmap_atomic(void *kvaddr)
9388 {
arch/x86/include/asm/highmem.h+4−1
@@ -68,7 +68,10 @@ static inline void *kmap_atomic_prot(struct page *page, pgprot_t prot) · 67 unmodified lines
6868
6969 return kmap_atomic_high_prot(page, prot);
7070 }
71−void *kmap_atomic(struct page *page);
71+static inline void *kmap_atomic_high(struct page *page)
72+{
73+ return kmap_atomic_high_prot(page, kmap_prot);
74+}
7275 void __kunmap_atomic(void *kvaddr);
7376 void *kmap_atomic_pfn(unsigned long pfn);
7477 void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot);
arch/x86/mm/highmem_32.c+0−14
@@ -4,14 +4,6 @@ · 3 unmodified lines
44 #include <linux/swap.h> /* for totalram_pages */
55 #include <linux/memblock.h>
66
7−/*
8− * kmap_atomic/kunmap_atomic is significantly faster than kmap/kunmap because
9− * no global lock is needed and because the kmap code must perform a global TLB
10− * invalidation when the kmap pool wraps.
11− *
12− * However when holding an atomic kmap it is not legal to sleep, so atomic
13− * kmaps are appropriate for short, tight code paths only.
14− */
157 void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
168 {
179 unsigned long vaddr;
@@ -28,12 +20,6 @@ void *kmap_atomic_high_prot(struct page *page, pgprot_t prot) · 10 unmodified lines
2820 }
2921 EXPORT_SYMBOL(kmap_atomic_high_prot);
3022
31−void *kmap_atomic(struct page *page)
32−{
33− return kmap_atomic_prot(page, kmap_prot);
34−}
35−EXPORT_SYMBOL(kmap_atomic);
36−
3723 /*
3824 * This is the same as kmap_atomic() but can map memory that doesn't
3925 * have a struct page associated with it.
arch/xtensa/include/asm/highmem.h+0−1
@@ -68,7 +68,6 @@ static inline void flush_cache_kmaps(void) · 67 unmodified lines
6868 flush_cache_all();
6969 }
7070
71−void *kmap_atomic(struct page *page);
7271 void __kunmap_atomic(void *kvaddr);
7372
7473 void kmap_init(void);
arch/xtensa/mm/highmem.c+2−7
@@ -37,16 +37,11 @@ static inline enum fixed_addresses kmap_idx(int type, unsigned long color) · 36 unmodified lines
3737 color;
3838 }
3939
40−void *kmap_atomic(struct page *page)
40+void *kmap_atomic_high(struct page *page)
4141 {
4242 enum fixed_addresses idx;
4343 unsigned long vaddr;
4444
45− preempt_disable();
46− pagefault_disable();
47− if (!PageHighMem(page))
48− return page_address(page);
49−
5045 idx = kmap_idx(kmap_atomic_idx_push(),
5146 DCACHE_ALIAS(page_to_phys(page)));
5247 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
@@ -57,7 +52,7 @@ void *kmap_atomic(struct page *page) · 4 unmodified lines
5752
5853 return (void *)vaddr;
5954 }
60−EXPORT_SYMBOL(kmap_atomic);
55+EXPORT_SYMBOL(kmap_atomic_high);
6156
6257 void __kunmap_atomic(void *kvaddr)
6358 {
include/linux/highmem.h+23−0
@@ -32,6 +32,7 @@ static inline void invalidate_kernel_vmap_range(void *vaddr, int size) · 31 unmodified lines
3232 #include <asm/kmap_types.h>
3333
3434 #ifdef CONFIG_HIGHMEM
35+extern void *kmap_atomic_high(struct page *page);
3536 #include <asm/highmem.h>
3637
3738 #ifndef ARCH_HAS_KMAP_FLUSH_TLB
@@ -62,6 +63,28 @@ static inline void kunmap(struct page *page) · 24 unmodified lines
6263 kunmap_high(page);
6364 }
6465
66+/*
67+ * kmap_atomic/kunmap_atomic is significantly faster than kmap/kunmap because
68+ * no global lock is needed and because the kmap code must perform a global TLB
69+ * invalidation when the kmap pool wraps.
70+ *
71+ * However when holding an atomic kmap is is not legal to sleep, so atomic
72+ * kmaps are appropriate for short, tight code paths only.
73+ *
74+ * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
75+ * gives a more generic (and caching) interface. But kmap_atomic can
76+ * be used in IRQ contexts, so in some (very limited) cases we need
77+ * it.
78+ */
79+static inline void *kmap_atomic(struct page *page)
80+{
81+ preempt_disable();
82+ pagefault_disable();
83+ if (!PageHighMem(page))
84+ return page_address(page);
85+ return kmap_atomic_high(page);
86+}
87+
6588 /* declarations for linux/mm/highmem.c */
6689 unsigned int nr_free_highpages(void);
6790 extern atomic_long_t _totalhigh_pages;