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>
Showing the changes to include/linux (1 of 21 files). Show all
Unified · Split
| @@ -32,6 +32,7 @@ static inline void invalidate_kernel_vmap_range(void *vaddr, int size) · 31 unmodified lines | |||
| 32 | #include <asm/kmap_types.h> | 32 | #include <asm/kmap_types.h> |
| 33 | 33 | ||
| 34 | #ifdef CONFIG_HIGHMEM | 34 | #ifdef CONFIG_HIGHMEM |
| 35 | extern void *kmap_atomic_high(struct page *page); | ||
| 35 | #include <asm/highmem.h> | 36 | #include <asm/highmem.h> |
| 36 | 37 | ||
| 37 | #ifndef ARCH_HAS_KMAP_FLUSH_TLB | 38 | #ifndef ARCH_HAS_KMAP_FLUSH_TLB |
| @@ -62,6 +63,28 @@ static inline void kunmap(struct page *page) · 24 unmodified lines | |||
| 62 | kunmap_high(page); | 63 | kunmap_high(page); |
| 63 | } | 64 | } |
| 64 | 65 | ||
| 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 | |||
| 65 | /* declarations for linux/mm/highmem.c */ | 88 | /* declarations for linux/mm/highmem.c */ |
| 66 | unsigned int nr_free_highpages(void); | 89 | unsigned int nr_free_highpages(void); |
| 67 | extern atomic_long_t _totalhigh_pages; | 90 | extern atomic_long_t _totalhigh_pages; |