]> git.baikalelectronics.ru Git - kernel.git/commitdiff
arch/kmap_atomic: consolidate duplicate code
authorIra Weiny <ira.weiny@intel.com>
Thu, 4 Jun 2020 23:47:42 +0000 (16:47 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 5 Jun 2020 02:06:22 +0000 (19:06 -0700)
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>
21 files changed:
arch/arc/include/asm/highmem.h
arch/arc/mm/highmem.c
arch/arm/include/asm/highmem.h
arch/arm/mm/highmem.c
arch/csky/include/asm/highmem.h
arch/csky/mm/highmem.c
arch/microblaze/include/asm/highmem.h
arch/mips/include/asm/highmem.h
arch/mips/mm/cache.c
arch/mips/mm/highmem.c
arch/nds32/include/asm/highmem.h
arch/nds32/mm/highmem.c
arch/powerpc/include/asm/highmem.h
arch/powerpc/mm/highmem.c
arch/sparc/include/asm/highmem.h
arch/sparc/mm/highmem.c
arch/x86/include/asm/highmem.h
arch/x86/mm/highmem_32.c
arch/xtensa/include/asm/highmem.h
arch/xtensa/mm/highmem.c
include/linux/highmem.h

index 8387a5596a919723f9faf69fadeb887b859b958c..db425cd38545de3929d58abee292704cccbbf7a3 100644 (file)
@@ -30,7 +30,6 @@
 
 #include <asm/cacheflush.h>
 
-extern void *kmap_atomic(struct page *page);
 extern void __kunmap_atomic(void *kvaddr);
 
 extern void kmap_init(void);
index 4db13a6b9f3b4883d0c1e5e8149457ecf268aa74..0964b011c29f3b9817a0c9d140fabe8b95b5513e 100644 (file)
 extern pte_t * pkmap_page_table;
 static pte_t * fixmap_page_table;
 
-void *kmap_atomic(struct page *page)
+void *kmap_atomic_high(struct page *page)
 {
        int idx, cpu_idx;
        unsigned long vaddr;
 
-       preempt_disable();
-       pagefault_disable();
-       if (!PageHighMem(page))
-               return page_address(page);
-
        cpu_idx = kmap_atomic_idx_push();
        idx = cpu_idx + KM_TYPE_NR * smp_processor_id();
        vaddr = FIXMAP_ADDR(idx);
@@ -68,7 +63,7 @@ void *kmap_atomic(struct page *page)
 
        return (void *)vaddr;
 }
-EXPORT_SYMBOL(kmap_atomic);
+EXPORT_SYMBOL(kmap_atomic_high);
 
 void __kunmap_atomic(void *kv)
 {
index 736f65283e7b459f281d6a466e22ce4742fb796c..8c80bfe18a34d06a4b10cdd4a8db2659b4931b45 100644 (file)
@@ -60,7 +60,6 @@ static inline void *kmap_high_get(struct page *page)
  * when CONFIG_HIGHMEM is not set.
  */
 #ifdef CONFIG_HIGHMEM
-extern void *kmap_atomic(struct page *page);
 extern void __kunmap_atomic(void *kvaddr);
 extern void *kmap_atomic_pfn(unsigned long pfn);
 #endif
index c700b32350eea0850e0279a510658180a567e8fe..075fdc2350917481c935bc9ee068ed8715fed500 100644 (file)
@@ -31,18 +31,13 @@ static inline pte_t get_fixmap_pte(unsigned long vaddr)
        return *ptep;
 }
 
-void *kmap_atomic(struct page *page)
+void *kmap_atomic_high(struct page *page)
 {
        unsigned int idx;
        unsigned long vaddr;
        void *kmap;
        int type;
 
-       preempt_disable();
-       pagefault_disable();
-       if (!PageHighMem(page))
-               return page_address(page);
-
 #ifdef CONFIG_DEBUG_HIGHMEM
        /*
         * There is no cache coherency issue when non VIVT, so force the
@@ -76,7 +71,7 @@ void *kmap_atomic(struct page *page)
 
        return (void *)vaddr;
 }
-EXPORT_SYMBOL(kmap_atomic);
+EXPORT_SYMBOL(kmap_atomic_high);
 
 void __kunmap_atomic(void *kvaddr)
 {
index be11c5b671228ef37c7a0f99c911112d82aaf248..8ceee12f9bc16926ed5ee861918e3e48ad366998 100644 (file)
@@ -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 *kmap_atomic(struct page *page);
 extern void __kunmap_atomic(void *kvaddr);
 extern void *kmap_atomic_pfn(unsigned long pfn);
 extern struct page *kmap_atomic_to_page(void *ptr);
index e9952211264bb063200b18e4930e166c4c7af152..63d74b47eee6918d84bdcba0e96118c479afa646 100644 (file)
@@ -21,16 +21,11 @@ EXPORT_SYMBOL(kmap_flush_tlb);
 
 EXPORT_SYMBOL(kmap);
 
-void *kmap_atomic(struct page *page)
+void *kmap_atomic_high(struct page *page)
 {
        unsigned long vaddr;
        int idx, type;
 
-       preempt_disable();
-       pagefault_disable();
-       if (!PageHighMem(page))
-               return page_address(page);
-
        type = kmap_atomic_idx_push();
        idx = type + KM_TYPE_NR*smp_processor_id();
        vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
@@ -42,7 +37,7 @@ void *kmap_atomic(struct page *page)
 
        return (void *)vaddr;
 }
-EXPORT_SYMBOL(kmap_atomic);
+EXPORT_SYMBOL(kmap_atomic_high);
 
 void __kunmap_atomic(void *kvaddr)
 {
index c38d920a11718848760dedee522e1f47ddb1c1f9..f7c5467df5add50a1005fd57fa2251ca7680fd25 100644 (file)
@@ -63,9 +63,9 @@ static inline void *kmap_atomic_prot(struct page *page, pgprot_t prot)
 }
 extern void __kunmap_atomic(void *kvaddr);
 
-static inline void *kmap_atomic(struct page *page)
+static inline void *kmap_atomic_high(struct page *page)
 {
-       return kmap_atomic_prot(page, kmap_prot);
+       return kmap_atomic_high_prot(page, kmap_prot);
 }
 
 #define flush_cache_kmaps()    { flush_icache(); flush_dcache(); }
index 24e7e7e5cc7b817a21d9a12f4bc5d1f58d7eca25..8bdbbfc322adccbd2097fec9840ee4839dcf1bba 100644 (file)
@@ -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 *kmap_atomic(struct page *page);
 extern void __kunmap_atomic(void *kvaddr);
 extern void *kmap_atomic_pfn(unsigned long pfn);
 
index ad6df1cea866f5cc92ee572a70e81289bc9756bf..295bfda7da975525c984a1ba9885146dbac590a4 100644 (file)
@@ -14,9 +14,9 @@
 #include <linux/sched.h>
 #include <linux/syscalls.h>
 #include <linux/mm.h>
+#include <linux/highmem.h>
 
 #include <asm/cacheflush.h>
-#include <asm/highmem.h>
 #include <asm/processor.h>
 #include <asm/cpu.h>
 #include <asm/cpu-features.h>
index eb8ec8493f2f778372267b545647cb22b7b2938c..2bda56372995edf8b114e2efe3fdeb3a3dc9e296 100644 (file)
@@ -18,25 +18,11 @@ void kmap_flush_tlb(unsigned long addr)
 }
 EXPORT_SYMBOL(kmap_flush_tlb);
 
-/*
- * kmap_atomic/kunmap_atomic is significantly faster than kmap/kunmap because
- * no global lock is needed and because the kmap code must perform a global TLB
- * invalidation when the kmap pool wraps.
- *
- * However when holding an atomic kmap is is not legal to sleep, so atomic
- * kmaps are appropriate for short, tight code paths only.
- */
-
-void *kmap_atomic(struct page *page)
+void *kmap_atomic_high(struct page *page)
 {
        unsigned long vaddr;
        int idx, type;
 
-       preempt_disable();
-       pagefault_disable();
-       if (!PageHighMem(page))
-               return page_address(page);
-
        type = kmap_atomic_idx_push();
        idx = type + KM_TYPE_NR*smp_processor_id();
        vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
@@ -48,7 +34,7 @@ void *kmap_atomic(struct page *page)
 
        return (void*) vaddr;
 }
-EXPORT_SYMBOL(kmap_atomic);
+EXPORT_SYMBOL(kmap_atomic_high);
 
 void __kunmap_atomic(void *kvaddr)
 {
index c93c7368bb3fbc2738dba11932ca16835f3c6c1f..a3970e566ede12d669cff0ea787ffe5fe1385ea7 100644 (file)
@@ -51,7 +51,6 @@ extern void kmap_init(void);
  * when CONFIG_HIGHMEM is not set.
  */
 #ifdef CONFIG_HIGHMEM
-extern void *kmap_atomic(struct page *page);
 extern void __kunmap_atomic(void *kvaddr);
 extern void *kmap_atomic_pfn(unsigned long pfn);
 extern struct page *kmap_atomic_to_page(void *ptr);
index f9348bec0ecb5ce36371653d223caf266610d2b9..d4387d8358708f9adef7004c3bd65c734b013863 100644 (file)
 #include <asm/fixmap.h>
 #include <asm/tlbflush.h>
 
-void *kmap_atomic(struct page *page)
+void *kmap_atomic_high(struct page *page)
 {
        unsigned int idx;
        unsigned long vaddr, pte;
        int type;
        pte_t *ptep;
 
-       preempt_disable();
-       pagefault_disable();
-       if (!PageHighMem(page))
-               return page_address(page);
-
        type = kmap_atomic_idx_push();
 
        idx = type + KM_TYPE_NR * smp_processor_id();
@@ -36,8 +31,7 @@ void *kmap_atomic(struct page *page)
        __nds32__isb();
        return (void *)vaddr;
 }
-
-EXPORT_SYMBOL(kmap_atomic);
+EXPORT_SYMBOL(kmap_atomic_high);
 
 void __kunmap_atomic(void *kvaddr)
 {
@@ -53,5 +47,4 @@ void __kunmap_atomic(void *kvaddr)
        pagefault_enable();
        preempt_enable();
 }
-
 EXPORT_SYMBOL(__kunmap_atomic);
index d049806a83543364590e9b7b05b0d7cc0511b8db..74fa2c726fdeee6afd2c8f6b0d8ae37e1a6b14e8 100644 (file)
@@ -71,9 +71,9 @@ static inline void *kmap_atomic_prot(struct page *page, pgprot_t prot)
 }
 extern void __kunmap_atomic(void *kvaddr);
 
-static inline void *kmap_atomic(struct page *page)
+static inline void *kmap_atomic_high(struct page *page)
 {
-       return kmap_atomic_prot(page, kmap_prot);
+       return kmap_atomic_high_prot(page, kmap_prot);
 }
 
 
index f075cef6d663882f65341c64d6f0fbfe222c8e5c..67aaa5217f7f7d46d5bd4b28f75acebe78fd2b14 100644 (file)
 #include <linux/highmem.h>
 #include <linux/module.h>
 
-/*
- * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
- * gives a more generic (and caching) interface. But kmap_atomic can
- * be used in IRQ contexts, so in some (very limited) cases we need
- * it.
- */
 void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
 {
        unsigned long vaddr;
index 4bdb79fed02c746ad3302320fa0bcfc6f0772c74..458210c5bc381909c1cdb4a1b9f40e3dee0de136 100644 (file)
@@ -50,7 +50,6 @@ void kmap_init(void) __init;
 
 #define PKMAP_END (PKMAP_ADDR(LAST_PKMAP))
 
-void *kmap_atomic(struct page *page);
 void __kunmap_atomic(void *kvaddr);
 
 #define flush_cache_kmaps()    flush_cache_all()
index d4a80adea7e59b1fb6469ac16d110a3589a4bb53..b53070ab6a31e7a57a533da50da2d5ac5e61bcab 100644 (file)
@@ -53,16 +53,11 @@ void __init kmap_init(void)
         kmap_prot = __pgprot(SRMMU_ET_PTE | SRMMU_PRIV | SRMMU_CACHE);
 }
 
-void *kmap_atomic(struct page *page)
+void *kmap_atomic_high(struct page *page)
 {
        unsigned long vaddr;
        long idx, type;
 
-       preempt_disable();
-       pagefault_disable();
-       if (!PageHighMem(page))
-               return page_address(page);
-
        type = kmap_atomic_idx_push();
        idx = type + KM_TYPE_NR*smp_processor_id();
        vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
@@ -87,7 +82,7 @@ void *kmap_atomic(struct page *page)
 
        return (void*) vaddr;
 }
-EXPORT_SYMBOL(kmap_atomic);
+EXPORT_SYMBOL(kmap_atomic_high);
 
 void __kunmap_atomic(void *kvaddr)
 {
index 61f47fef40e5121959437a1c69c3ee33d5616e5b..9393d55a2adb7f8ebf87cf5fb3c255a47c37f216 100644 (file)
@@ -68,7 +68,10 @@ static inline void *kmap_atomic_prot(struct page *page, pgprot_t prot)
 
        return kmap_atomic_high_prot(page, prot);
 }
-void *kmap_atomic(struct page *page);
+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);
index 48b56b1af902ee6d94e6363aea5fa7ccf2ad22b4..c3e272a759e0289d993a9eb6f35f12ec0154f450 100644 (file)
@@ -4,14 +4,6 @@
 #include <linux/swap.h> /* for totalram_pages */
 #include <linux/memblock.h>
 
-/*
- * kmap_atomic/kunmap_atomic is significantly faster than kmap/kunmap because
- * no global lock is needed and because the kmap code must perform a global TLB
- * invalidation when the kmap pool wraps.
- *
- * However when holding an atomic kmap it is not legal to sleep, so atomic
- * kmaps are appropriate for short, tight code paths only.
- */
 void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
 {
        unsigned long vaddr;
@@ -28,12 +20,6 @@ void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
 }
 EXPORT_SYMBOL(kmap_atomic_high_prot);
 
-void *kmap_atomic(struct page *page)
-{
-       return kmap_atomic_prot(page, kmap_prot);
-}
-EXPORT_SYMBOL(kmap_atomic);
-
 /*
  * This is the same as kmap_atomic() but can map memory that doesn't
  * have a struct page associated with it.
index 5a481f7def0bbb13e8653923310b127d98da1f04..1e6aa15c4bdf342d4167db2b1642ec2507aa3538 100644 (file)
@@ -68,7 +68,6 @@ static inline void flush_cache_kmaps(void)
        flush_cache_all();
 }
 
-void *kmap_atomic(struct page *page);
 void __kunmap_atomic(void *kvaddr);
 
 void kmap_init(void);
index da734a2ed641866863e3e202dc0dbd92f880adbf..90b85a897cb088cc50cdc0c1862bb41ff5da569b 100644 (file)
@@ -37,16 +37,11 @@ static inline enum fixed_addresses kmap_idx(int type, unsigned long color)
                color;
 }
 
-void *kmap_atomic(struct page *page)
+void *kmap_atomic_high(struct page *page)
 {
        enum fixed_addresses idx;
        unsigned long vaddr;
 
-       preempt_disable();
-       pagefault_disable();
-       if (!PageHighMem(page))
-               return page_address(page);
-
        idx = kmap_idx(kmap_atomic_idx_push(),
                       DCACHE_ALIAS(page_to_phys(page)));
        vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
@@ -57,7 +52,7 @@ void *kmap_atomic(struct page *page)
 
        return (void *)vaddr;
 }
-EXPORT_SYMBOL(kmap_atomic);
+EXPORT_SYMBOL(kmap_atomic_high);
 
 void __kunmap_atomic(void *kvaddr)
 {
index 216a647ed7db73d0fbcac9b98ece54353b5211c9..d2209ae8be99b786f95ef64c52151531088186f4 100644 (file)
@@ -32,6 +32,7 @@ static inline void invalidate_kernel_vmap_range(void *vaddr, int size)
 #include <asm/kmap_types.h>
 
 #ifdef CONFIG_HIGHMEM
+extern void *kmap_atomic_high(struct page *page);
 #include <asm/highmem.h>
 
 #ifndef ARCH_HAS_KMAP_FLUSH_TLB
@@ -62,6 +63,28 @@ static inline void kunmap(struct page *page)
        kunmap_high(page);
 }
 
+/*
+ * kmap_atomic/kunmap_atomic is significantly faster than kmap/kunmap because
+ * no global lock is needed and because the kmap code must perform a global TLB
+ * invalidation when the kmap pool wraps.
+ *
+ * However when holding an atomic kmap is is not legal to sleep, so atomic
+ * kmaps are appropriate for short, tight code paths only.
+ *
+ * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
+ * gives a more generic (and caching) interface. But kmap_atomic can
+ * be used in IRQ contexts, so in some (very limited) cases we need
+ * it.
+ */
+static inline void *kmap_atomic(struct page *page)
+{
+       preempt_disable();
+       pagefault_disable();
+       if (!PageHighMem(page))
+               return page_address(page);
+       return kmap_atomic_high(page);
+}
+
 /* declarations for linux/mm/highmem.c */
 unsigned int nr_free_highpages(void);
 extern atomic_long_t _totalhigh_pages;