From patchwork Sun Apr 26 05:54:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 11510173 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 559911864 for ; Sun, 26 Apr 2020 05:54:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48D462098B for ; Sun, 26 Apr 2020 05:54:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726234AbgDZFyX (ORCPT ); Sun, 26 Apr 2020 01:54:23 -0400 Received: from mga12.intel.com ([192.55.52.136]:61093 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbgDZFyW (ORCPT ); Sun, 26 Apr 2020 01:54:22 -0400 IronPort-SDR: 8JM4+t1gtS5CauTdvh737TsizdImx9w9xW5PdDi5kzMuNn5db252RyRuQcAN4yk4RCtrM2Xhtb soMqIYPX2Xnw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2020 22:54:22 -0700 IronPort-SDR: 5vI0aC2WJoqaA1rHDNfx4RDyW1Iy/jFdcIF6pYkCY1G8ZX2vahQBBRAQFahQ7DWdPPgIrwO58B 3sdyElhYKHjQ== X-IronPort-AV: E=Sophos;i="5.73,319,1583222400"; d="scan'208";a="260317587" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2020 22:54:21 -0700 From: ira.weiny@intel.com To: linux-kernel@vger.kernel.org, Andrew Morton Cc: Ira Weiny , Dan Williams , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Benjamin Herrenschmidt , Paul Mackerras , "David S. Miller" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Chris Zankel , Max Filippov , linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH 1/5] arch/kmap: Remove BUG_ON() Date: Sat, 25 Apr 2020 22:54:02 -0700 Message-Id: <20200426055406.134198-2-ira.weiny@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200426055406.134198-1-ira.weiny@intel.com> References: <20200426055406.134198-1-ira.weiny@intel.com> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Ira Weiny Replace the use of BUG_ON(in_interrupt()) in the kmap() and kunmap() in favor of might_sleep(). Besides the benefits of might_sleep(), this normalizes the implementations such that they can be made generic in subsequent patches. Reviewed-by: Dan Williams Signed-off-by: Ira Weiny --- arch/arc/include/asm/highmem.h | 2 +- arch/arc/mm/highmem.c | 2 +- arch/arm/mm/highmem.c | 2 +- arch/csky/mm/highmem.c | 2 +- arch/microblaze/include/asm/highmem.h | 2 +- arch/mips/mm/highmem.c | 2 +- arch/nds32/mm/highmem.c | 2 +- arch/powerpc/include/asm/highmem.h | 2 +- arch/sparc/include/asm/highmem.h | 4 ++-- arch/x86/mm/highmem_32.c | 3 +-- arch/xtensa/include/asm/highmem.h | 4 ++-- 11 files changed, 13 insertions(+), 14 deletions(-) diff --git a/arch/arc/include/asm/highmem.h b/arch/arc/include/asm/highmem.h index 1af00accb37f..042e92921c4c 100644 --- a/arch/arc/include/asm/highmem.h +++ b/arch/arc/include/asm/highmem.h @@ -45,7 +45,7 @@ static inline void flush_cache_kmaps(void) static inline void kunmap(struct page *page) { - BUG_ON(in_interrupt()); + might_sleep(); if (!PageHighMem(page)) return; kunmap_high(page); diff --git a/arch/arc/mm/highmem.c b/arch/arc/mm/highmem.c index fc8849e4f72e..39ef7b9a3aa9 100644 --- a/arch/arc/mm/highmem.c +++ b/arch/arc/mm/highmem.c @@ -51,7 +51,7 @@ static pte_t * fixmap_page_table; void *kmap(struct page *page) { - BUG_ON(in_interrupt()); + might_sleep(); if (!PageHighMem(page)) return page_address(page); diff --git a/arch/arm/mm/highmem.c b/arch/arm/mm/highmem.c index a76f8ace9ce6..cc6eb79ef20c 100644 --- a/arch/arm/mm/highmem.c +++ b/arch/arm/mm/highmem.c @@ -42,7 +42,7 @@ EXPORT_SYMBOL(kmap); void kunmap(struct page *page) { - BUG_ON(in_interrupt()); + might_sleep(); if (!PageHighMem(page)) return; kunmap_high(page); diff --git a/arch/csky/mm/highmem.c b/arch/csky/mm/highmem.c index 813129145f3d..690d678649d1 100644 --- a/arch/csky/mm/highmem.c +++ b/arch/csky/mm/highmem.c @@ -29,7 +29,7 @@ EXPORT_SYMBOL(kmap); void kunmap(struct page *page) { - BUG_ON(in_interrupt()); + might_sleep(); if (!PageHighMem(page)) return; kunmap_high(page); diff --git a/arch/microblaze/include/asm/highmem.h b/arch/microblaze/include/asm/highmem.h index 332c78e15198..99ced7278b5c 100644 --- a/arch/microblaze/include/asm/highmem.h +++ b/arch/microblaze/include/asm/highmem.h @@ -66,7 +66,7 @@ static inline void *kmap(struct page *page) static inline void kunmap(struct page *page) { - BUG_ON(in_interrupt()); + might_sleep(); if (!PageHighMem(page)) return; kunmap_high(page); diff --git a/arch/mips/mm/highmem.c b/arch/mips/mm/highmem.c index d08e6d7d533b..edd889f6cede 100644 --- a/arch/mips/mm/highmem.c +++ b/arch/mips/mm/highmem.c @@ -28,7 +28,7 @@ EXPORT_SYMBOL(kmap); void kunmap(struct page *page) { - BUG_ON(in_interrupt()); + might_sleep(); if (!PageHighMem(page)) return; kunmap_high(page); diff --git a/arch/nds32/mm/highmem.c b/arch/nds32/mm/highmem.c index 022779af6148..4c7c28e994ea 100644 --- a/arch/nds32/mm/highmem.c +++ b/arch/nds32/mm/highmem.c @@ -24,7 +24,7 @@ EXPORT_SYMBOL(kmap); void kunmap(struct page *page) { - BUG_ON(in_interrupt()); + might_sleep(); if (!PageHighMem(page)) return; kunmap_high(page); diff --git a/arch/powerpc/include/asm/highmem.h b/arch/powerpc/include/asm/highmem.h index a4b65b186ec6..529512f6d65a 100644 --- a/arch/powerpc/include/asm/highmem.h +++ b/arch/powerpc/include/asm/highmem.h @@ -74,7 +74,7 @@ static inline void *kmap(struct page *page) static inline void kunmap(struct page *page) { - BUG_ON(in_interrupt()); + might_sleep(); if (!PageHighMem(page)) return; kunmap_high(page); diff --git a/arch/sparc/include/asm/highmem.h b/arch/sparc/include/asm/highmem.h index 18d776925c45..7dd2d4b3f980 100644 --- a/arch/sparc/include/asm/highmem.h +++ b/arch/sparc/include/asm/highmem.h @@ -55,7 +55,7 @@ void kunmap_high(struct page *page); static inline void *kmap(struct page *page) { - BUG_ON(in_interrupt()); + might_sleep(); if (!PageHighMem(page)) return page_address(page); return kmap_high(page); @@ -63,7 +63,7 @@ static inline void *kmap(struct page *page) static inline void kunmap(struct page *page) { - BUG_ON(in_interrupt()); + might_sleep(); if (!PageHighMem(page)) return; kunmap_high(page); diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c index 0a1898b8552e..8af66382672b 100644 --- a/arch/x86/mm/highmem_32.c +++ b/arch/x86/mm/highmem_32.c @@ -15,8 +15,7 @@ EXPORT_SYMBOL(kmap); void kunmap(struct page *page) { - if (in_interrupt()) - BUG(); + might_sleep(); if (!PageHighMem(page)) return; kunmap_high(page); diff --git a/arch/xtensa/include/asm/highmem.h b/arch/xtensa/include/asm/highmem.h index 04e9340eac4b..413848cc1e56 100644 --- a/arch/xtensa/include/asm/highmem.h +++ b/arch/xtensa/include/asm/highmem.h @@ -73,7 +73,7 @@ static inline void *kmap(struct page *page) */ BUILD_BUG_ON(PKMAP_BASE < TLBTEMP_BASE_1 + TLBTEMP_SIZE); - BUG_ON(in_interrupt()); + might_sleep(); if (!PageHighMem(page)) return page_address(page); return kmap_high(page); @@ -81,7 +81,7 @@ static inline void *kmap(struct page *page) static inline void kunmap(struct page *page) { - BUG_ON(in_interrupt()); + might_sleep(); if (!PageHighMem(page)) return; kunmap_high(page); From patchwork Sun Apr 26 05:54:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 11510161 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 386DB1667 for ; Sun, 26 Apr 2020 05:54:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 238F22098B for ; Sun, 26 Apr 2020 05:54:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726271AbgDZFyZ (ORCPT ); Sun, 26 Apr 2020 01:54:25 -0400 Received: from mga14.intel.com ([192.55.52.115]:2358 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726227AbgDZFyY (ORCPT ); Sun, 26 Apr 2020 01:54:24 -0400 IronPort-SDR: jA+I94UWz/vSnVxE7tVsvo5YwWYU0fezfyoE0ZliCqvkOWQMs+pCdg2I97ly+mDbCG3ZTsSgEo ERVPJfKELerQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2020 22:54:23 -0700 IronPort-SDR: cx88cSBlRxSL+ntfH3sL2yK1eLs9LSednmue8odGKUh2mrKFYgcR/pzIaZYWqIi2OxqYOInn8s 94VzyyLw2D4A== X-IronPort-AV: E=Sophos;i="5.73,319,1583222400"; d="scan'208";a="256859643" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2020 22:54:22 -0700 From: ira.weiny@intel.com To: linux-kernel@vger.kernel.org, Andrew Morton Cc: Ira Weiny , Dan Williams , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Benjamin Herrenschmidt , Paul Mackerras , "David S. Miller" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Chris Zankel , Max Filippov , linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH 2/5] arch/kmap: Remove redundant arch specific kmaps Date: Sat, 25 Apr 2020 22:54:03 -0700 Message-Id: <20200426055406.134198-3-ira.weiny@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200426055406.134198-1-ira.weiny@intel.com> References: <20200426055406.134198-1-ira.weiny@intel.com> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Ira Weiny The kmap code for all the architectures is almost 100% identical. Lift the common code to the core. Use ARCH_HAS_KMAP to indicate if an arch needs a special kmap. This also has the benefit of changing kmap() on a number of architectures to be an inline call rather than an actual function. Reviewed-by: Dan Williams Signed-off-by: Ira Weiny --- arch/arc/include/asm/highmem.h | 2 -- arch/arc/mm/highmem.c | 10 ---------- arch/arm/include/asm/highmem.h | 2 -- arch/arm/mm/highmem.c | 9 --------- arch/csky/include/asm/highmem.h | 2 +- arch/csky/mm/highmem.c | 7 +------ arch/microblaze/include/asm/highmem.h | 9 --------- arch/mips/include/asm/highmem.h | 2 +- arch/mips/mm/highmem.c | 7 +------ arch/nds32/include/asm/highmem.h | 2 -- arch/nds32/mm/highmem.c | 12 ------------ arch/powerpc/include/asm/highmem.h | 9 --------- arch/sparc/include/asm/highmem.h | 9 --------- arch/x86/include/asm/highmem.h | 2 -- arch/x86/mm/highmem_32.c | 9 --------- arch/xtensa/include/asm/highmem.h | 6 +----- include/linux/highmem.h | 18 ++++++++++++++++++ 17 files changed, 23 insertions(+), 94 deletions(-) diff --git a/arch/arc/include/asm/highmem.h b/arch/arc/include/asm/highmem.h index 042e92921c4c..96eb67c86961 100644 --- a/arch/arc/include/asm/highmem.h +++ b/arch/arc/include/asm/highmem.h @@ -30,8 +30,6 @@ #include -extern void *kmap(struct page *page); -extern void *kmap_high(struct page *page); extern void *kmap_atomic(struct page *page); extern void __kunmap_atomic(void *kvaddr); extern void kunmap_high(struct page *page); diff --git a/arch/arc/mm/highmem.c b/arch/arc/mm/highmem.c index 39ef7b9a3aa9..4db13a6b9f3b 100644 --- a/arch/arc/mm/highmem.c +++ b/arch/arc/mm/highmem.c @@ -49,16 +49,6 @@ extern pte_t * pkmap_page_table; static pte_t * fixmap_page_table; -void *kmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return page_address(page); - - return kmap_high(page); -} -EXPORT_SYMBOL(kmap); - void *kmap_atomic(struct page *page) { int idx, cpu_idx; diff --git a/arch/arm/include/asm/highmem.h b/arch/arm/include/asm/highmem.h index eb4e4207cd3c..c917522541de 100644 --- a/arch/arm/include/asm/highmem.h +++ b/arch/arm/include/asm/highmem.h @@ -20,7 +20,6 @@ extern pte_t *pkmap_page_table; -extern void *kmap_high(struct page *page); extern void kunmap_high(struct page *page); /* @@ -63,7 +62,6 @@ static inline void *kmap_high_get(struct page *page) * when CONFIG_HIGHMEM is not set. */ #ifdef CONFIG_HIGHMEM -extern void *kmap(struct page *page); extern void kunmap(struct page *page); extern void *kmap_atomic(struct page *page); extern void __kunmap_atomic(void *kvaddr); diff --git a/arch/arm/mm/highmem.c b/arch/arm/mm/highmem.c index cc6eb79ef20c..e8ba37c36590 100644 --- a/arch/arm/mm/highmem.c +++ b/arch/arm/mm/highmem.c @@ -31,15 +31,6 @@ static inline pte_t get_fixmap_pte(unsigned long vaddr) return *ptep; } -void *kmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return page_address(page); - return kmap_high(page); -} -EXPORT_SYMBOL(kmap); - void kunmap(struct page *page) { might_sleep(); diff --git a/arch/csky/include/asm/highmem.h b/arch/csky/include/asm/highmem.h index a345a2f2c22e..4caeff143748 100644 --- a/arch/csky/include/asm/highmem.h +++ b/arch/csky/include/asm/highmem.h @@ -30,9 +30,9 @@ extern pte_t *pkmap_page_table; #define PKMAP_NR(virt) ((virt-PKMAP_BASE) >> PAGE_SHIFT) #define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT)) -extern void *kmap_high(struct page *page); extern void kunmap_high(struct page *page); +#define ARCH_HAS_KMAP extern void *kmap(struct page *page); extern void kunmap(struct page *page); extern void *kmap_atomic(struct page *page); diff --git a/arch/csky/mm/highmem.c b/arch/csky/mm/highmem.c index 690d678649d1..5fb0bd855444 100644 --- a/arch/csky/mm/highmem.c +++ b/arch/csky/mm/highmem.c @@ -15,14 +15,9 @@ unsigned long highstart_pfn, highend_pfn; void *kmap(struct page *page) { - void *addr; + void *addr = kmap_generic(page); - might_sleep(); - if (!PageHighMem(page)) - return page_address(page); - addr = kmap_high(page); flush_tlb_one((unsigned long)addr); - return addr; } EXPORT_SYMBOL(kmap); diff --git a/arch/microblaze/include/asm/highmem.h b/arch/microblaze/include/asm/highmem.h index 99ced7278b5c..8c5bfd228bd8 100644 --- a/arch/microblaze/include/asm/highmem.h +++ b/arch/microblaze/include/asm/highmem.h @@ -51,19 +51,10 @@ extern pte_t *pkmap_page_table; #define PKMAP_NR(virt) ((virt - PKMAP_BASE) >> PAGE_SHIFT) #define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT)) -extern void *kmap_high(struct page *page); extern void kunmap_high(struct page *page); extern void *kmap_atomic_prot(struct page *page, pgprot_t prot); extern void __kunmap_atomic(void *kvaddr); -static inline void *kmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return page_address(page); - return kmap_high(page); -} - static inline void kunmap(struct page *page) { might_sleep(); diff --git a/arch/mips/include/asm/highmem.h b/arch/mips/include/asm/highmem.h index 9d84aafc33d0..c30bbb88fcfe 100644 --- a/arch/mips/include/asm/highmem.h +++ b/arch/mips/include/asm/highmem.h @@ -46,9 +46,9 @@ extern pte_t *pkmap_page_table; #define PKMAP_NR(virt) ((virt-PKMAP_BASE) >> PAGE_SHIFT) #define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT)) -extern void * kmap_high(struct page *page); extern void kunmap_high(struct page *page); +#define ARCH_HAS_KMAP extern void *kmap(struct page *page); extern void kunmap(struct page *page); extern void *kmap_atomic(struct page *page); diff --git a/arch/mips/mm/highmem.c b/arch/mips/mm/highmem.c index edd889f6cede..3867dbe9ef32 100644 --- a/arch/mips/mm/highmem.c +++ b/arch/mips/mm/highmem.c @@ -14,14 +14,9 @@ unsigned long highstart_pfn, highend_pfn; void *kmap(struct page *page) { - void *addr; + void *addr = kmap_generic(page); - might_sleep(); - if (!PageHighMem(page)) - return page_address(page); - addr = kmap_high(page); flush_tlb_one((unsigned long)addr); - return addr; } EXPORT_SYMBOL(kmap); diff --git a/arch/nds32/include/asm/highmem.h b/arch/nds32/include/asm/highmem.h index b3a82c97ded3..b13654a79069 100644 --- a/arch/nds32/include/asm/highmem.h +++ b/arch/nds32/include/asm/highmem.h @@ -44,7 +44,6 @@ extern unsigned long highstart_pfn, highend_pfn; extern pte_t *pkmap_page_table; -extern void *kmap_high(struct page *page); extern void kunmap_high(struct page *page); extern void kmap_init(void); @@ -54,7 +53,6 @@ extern void kmap_init(void); * when CONFIG_HIGHMEM is not set. */ #ifdef CONFIG_HIGHMEM -extern void *kmap(struct page *page); extern void kunmap(struct page *page); extern void *kmap_atomic(struct page *page); extern void __kunmap_atomic(void *kvaddr); diff --git a/arch/nds32/mm/highmem.c b/arch/nds32/mm/highmem.c index 4c7c28e994ea..d0cde53b84ae 100644 --- a/arch/nds32/mm/highmem.c +++ b/arch/nds32/mm/highmem.c @@ -10,18 +10,6 @@ #include #include -void *kmap(struct page *page) -{ - unsigned long vaddr; - might_sleep(); - if (!PageHighMem(page)) - return page_address(page); - vaddr = (unsigned long)kmap_high(page); - return (void *)vaddr; -} - -EXPORT_SYMBOL(kmap); - void kunmap(struct page *page) { might_sleep(); diff --git a/arch/powerpc/include/asm/highmem.h b/arch/powerpc/include/asm/highmem.h index 529512f6d65a..f14e4feef6d5 100644 --- a/arch/powerpc/include/asm/highmem.h +++ b/arch/powerpc/include/asm/highmem.h @@ -59,19 +59,10 @@ extern pte_t *pkmap_page_table; #define PKMAP_NR(virt) ((virt-PKMAP_BASE) >> PAGE_SHIFT) #define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT)) -extern void *kmap_high(struct page *page); extern void kunmap_high(struct page *page); extern void *kmap_atomic_prot(struct page *page, pgprot_t prot); extern void __kunmap_atomic(void *kvaddr); -static inline void *kmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return page_address(page); - return kmap_high(page); -} - static inline void kunmap(struct page *page) { might_sleep(); diff --git a/arch/sparc/include/asm/highmem.h b/arch/sparc/include/asm/highmem.h index 7dd2d4b3f980..2ff1192047f7 100644 --- a/arch/sparc/include/asm/highmem.h +++ b/arch/sparc/include/asm/highmem.h @@ -50,17 +50,8 @@ void kmap_init(void) __init; #define PKMAP_END (PKMAP_ADDR(LAST_PKMAP)) -void *kmap_high(struct page *page); void kunmap_high(struct page *page); -static inline void *kmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return page_address(page); - return kmap_high(page); -} - static inline void kunmap(struct page *page) { might_sleep(); diff --git a/arch/x86/include/asm/highmem.h b/arch/x86/include/asm/highmem.h index a8059930056d..c916a28a9738 100644 --- a/arch/x86/include/asm/highmem.h +++ b/arch/x86/include/asm/highmem.h @@ -58,10 +58,8 @@ extern unsigned long highstart_pfn, highend_pfn; #define PKMAP_NR(virt) ((virt-PKMAP_BASE) >> PAGE_SHIFT) #define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT)) -extern void *kmap_high(struct page *page); extern void kunmap_high(struct page *page); -void *kmap(struct page *page); void kunmap(struct page *page); void *kmap_atomic_prot(struct page *page, pgprot_t prot); diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c index 8af66382672b..12591a81b85c 100644 --- a/arch/x86/mm/highmem_32.c +++ b/arch/x86/mm/highmem_32.c @@ -4,15 +4,6 @@ #include /* for totalram_pages */ #include -void *kmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return page_address(page); - return kmap_high(page); -} -EXPORT_SYMBOL(kmap); - void kunmap(struct page *page) { might_sleep(); diff --git a/arch/xtensa/include/asm/highmem.h b/arch/xtensa/include/asm/highmem.h index 413848cc1e56..fac4f48bde6c 100644 --- a/arch/xtensa/include/asm/highmem.h +++ b/arch/xtensa/include/asm/highmem.h @@ -63,7 +63,6 @@ static inline wait_queue_head_t *get_pkmap_wait_queue_head(unsigned int color) extern pte_t *pkmap_page_table; -void *kmap_high(struct page *page); void kunmap_high(struct page *page); static inline void *kmap(struct page *page) @@ -73,10 +72,7 @@ static inline void *kmap(struct page *page) */ BUILD_BUG_ON(PKMAP_BASE < TLBTEMP_BASE_1 + TLBTEMP_SIZE); - might_sleep(); - if (!PageHighMem(page)) - return page_address(page); - return kmap_high(page); + return kmap_generic(page); } static inline void kunmap(struct page *page) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index ea5cdbd8c2c3..2f7f710b7e7d 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -32,8 +32,26 @@ static inline void invalidate_kernel_vmap_range(void *vaddr, int size) #include #ifdef CONFIG_HIGHMEM +extern void *kmap_high(struct page *page); + +/* kmap_generic: architecture independent portion of kmap calls */ +static inline void *kmap_generic(struct page *page) +{ + might_sleep(); + if (!PageHighMem(page)) + return page_address(page); + return kmap_high(page); +} + #include +#ifndef ARCH_HAS_KMAP +static inline void *kmap(struct page *page) +{ + return kmap_generic(page); +} +#endif + /* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages(void); extern atomic_long_t _totalhigh_pages; From patchwork Sun Apr 26 05:54:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 11510171 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4420392A for ; Sun, 26 Apr 2020 05:54:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34D7D2098B for ; Sun, 26 Apr 2020 05:54:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726349AbgDZFyh (ORCPT ); Sun, 26 Apr 2020 01:54:37 -0400 Received: from mga06.intel.com ([134.134.136.31]:57441 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726249AbgDZFyY (ORCPT ); Sun, 26 Apr 2020 01:54:24 -0400 IronPort-SDR: VzlFhdTEuODkHES7tfpAmc32rgPV+BZoxxhmEoRh4UDEESOCIqyPZo5lnA3C7j5WNjjPtmYdzz 8fGjRrMxHLXA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2020 22:54:23 -0700 IronPort-SDR: OkT3JFTLADkNjn3UowLHjtWAG/8+lfmHPe7Y3tdnmzHkWlptAPlMqa7rHtAf79YOBGXzoBP6cc KBC96wVpnPDQ== X-IronPort-AV: E=Sophos;i="5.73,319,1583222400"; d="scan'208";a="458418423" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2020 22:54:22 -0700 From: ira.weiny@intel.com To: linux-kernel@vger.kernel.org, Andrew Morton Cc: Ira Weiny , Dan Williams , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Benjamin Herrenschmidt , Paul Mackerras , "David S. Miller" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Chris Zankel , Max Filippov , linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH 3/5] arch/kunmap: Remove duplicate kunmap implementations Date: Sat, 25 Apr 2020 22:54:04 -0700 Message-Id: <20200426055406.134198-4-ira.weiny@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200426055406.134198-1-ira.weiny@intel.com> References: <20200426055406.134198-1-ira.weiny@intel.com> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Ira Weiny All architectures do exactly the same thing for kunmap(); remove all the duplicate definitions and lift the call to the core. Reviewed-by: Dan Williams Signed-off-by: Ira Weiny --- arch/arc/include/asm/highmem.h | 9 --------- arch/arm/include/asm/highmem.h | 1 - arch/arm/mm/highmem.c | 9 --------- arch/csky/include/asm/highmem.h | 1 - arch/csky/mm/highmem.c | 9 --------- arch/microblaze/include/asm/highmem.h | 8 -------- arch/mips/include/asm/highmem.h | 1 - arch/mips/mm/highmem.c | 9 --------- arch/nds32/include/asm/highmem.h | 1 - arch/nds32/mm/highmem.c | 10 ---------- arch/powerpc/include/asm/highmem.h | 8 -------- arch/sparc/include/asm/highmem.h | 8 -------- arch/x86/include/asm/highmem.h | 2 -- arch/x86/mm/highmem_32.c | 9 --------- arch/xtensa/include/asm/highmem.h | 8 -------- include/linux/highmem.h | 8 ++++++++ 16 files changed, 8 insertions(+), 93 deletions(-) diff --git a/arch/arc/include/asm/highmem.h b/arch/arc/include/asm/highmem.h index 96eb67c86961..c03a911c9f21 100644 --- a/arch/arc/include/asm/highmem.h +++ b/arch/arc/include/asm/highmem.h @@ -41,15 +41,6 @@ static inline void flush_cache_kmaps(void) flush_cache_all(); } -static inline void kunmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return; - kunmap_high(page); -} - - #endif #endif diff --git a/arch/arm/include/asm/highmem.h b/arch/arm/include/asm/highmem.h index c917522541de..829e3b969819 100644 --- a/arch/arm/include/asm/highmem.h +++ b/arch/arm/include/asm/highmem.h @@ -62,7 +62,6 @@ static inline void *kmap_high_get(struct page *page) * when CONFIG_HIGHMEM is not set. */ #ifdef CONFIG_HIGHMEM -extern void kunmap(struct page *page); extern void *kmap_atomic(struct page *page); extern void __kunmap_atomic(void *kvaddr); extern void *kmap_atomic_pfn(unsigned long pfn); diff --git a/arch/arm/mm/highmem.c b/arch/arm/mm/highmem.c index e8ba37c36590..c700b32350ee 100644 --- a/arch/arm/mm/highmem.c +++ b/arch/arm/mm/highmem.c @@ -31,15 +31,6 @@ static inline pte_t get_fixmap_pte(unsigned long vaddr) return *ptep; } -void kunmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return; - kunmap_high(page); -} -EXPORT_SYMBOL(kunmap); - void *kmap_atomic(struct page *page) { unsigned int idx; diff --git a/arch/csky/include/asm/highmem.h b/arch/csky/include/asm/highmem.h index 4caeff143748..a0e7c43731a0 100644 --- a/arch/csky/include/asm/highmem.h +++ b/arch/csky/include/asm/highmem.h @@ -34,7 +34,6 @@ extern void kunmap_high(struct page *page); #define ARCH_HAS_KMAP extern void *kmap(struct page *page); -extern void kunmap(struct page *page); extern void *kmap_atomic(struct page *page); extern void __kunmap_atomic(void *kvaddr); extern void *kmap_atomic_pfn(unsigned long pfn); diff --git a/arch/csky/mm/highmem.c b/arch/csky/mm/highmem.c index 5fb0bd855444..69b1931986ae 100644 --- a/arch/csky/mm/highmem.c +++ b/arch/csky/mm/highmem.c @@ -22,15 +22,6 @@ void *kmap(struct page *page) } EXPORT_SYMBOL(kmap); -void kunmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return; - kunmap_high(page); -} -EXPORT_SYMBOL(kunmap); - void *kmap_atomic(struct page *page) { unsigned long vaddr; diff --git a/arch/microblaze/include/asm/highmem.h b/arch/microblaze/include/asm/highmem.h index 8c5bfd228bd8..1cbd52a0e39b 100644 --- a/arch/microblaze/include/asm/highmem.h +++ b/arch/microblaze/include/asm/highmem.h @@ -55,14 +55,6 @@ extern void kunmap_high(struct page *page); extern void *kmap_atomic_prot(struct page *page, pgprot_t prot); extern void __kunmap_atomic(void *kvaddr); -static inline void kunmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return; - kunmap_high(page); -} - static inline void *kmap_atomic(struct page *page) { return kmap_atomic_prot(page, kmap_prot); diff --git a/arch/mips/include/asm/highmem.h b/arch/mips/include/asm/highmem.h index c30bbb88fcfe..af9a66300628 100644 --- a/arch/mips/include/asm/highmem.h +++ b/arch/mips/include/asm/highmem.h @@ -50,7 +50,6 @@ extern void kunmap_high(struct page *page); #define ARCH_HAS_KMAP extern void *kmap(struct page *page); -extern void kunmap(struct page *page); extern void *kmap_atomic(struct page *page); extern void __kunmap_atomic(void *kvaddr); extern void *kmap_atomic_pfn(unsigned long pfn); diff --git a/arch/mips/mm/highmem.c b/arch/mips/mm/highmem.c index 3867dbe9ef32..c3c9fe962f0f 100644 --- a/arch/mips/mm/highmem.c +++ b/arch/mips/mm/highmem.c @@ -21,15 +21,6 @@ void *kmap(struct page *page) } EXPORT_SYMBOL(kmap); -void kunmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return; - kunmap_high(page); -} -EXPORT_SYMBOL(kunmap); - /* * 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 diff --git a/arch/nds32/include/asm/highmem.h b/arch/nds32/include/asm/highmem.h index b13654a79069..e455e2624247 100644 --- a/arch/nds32/include/asm/highmem.h +++ b/arch/nds32/include/asm/highmem.h @@ -53,7 +53,6 @@ extern void kmap_init(void); * when CONFIG_HIGHMEM is not set. */ #ifdef CONFIG_HIGHMEM -extern void kunmap(struct page *page); extern void *kmap_atomic(struct page *page); extern void __kunmap_atomic(void *kvaddr); extern void *kmap_atomic_pfn(unsigned long pfn); diff --git a/arch/nds32/mm/highmem.c b/arch/nds32/mm/highmem.c index d0cde53b84ae..f9348bec0ecb 100644 --- a/arch/nds32/mm/highmem.c +++ b/arch/nds32/mm/highmem.c @@ -10,16 +10,6 @@ #include #include -void kunmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return; - kunmap_high(page); -} - -EXPORT_SYMBOL(kunmap); - void *kmap_atomic(struct page *page) { unsigned int idx; diff --git a/arch/powerpc/include/asm/highmem.h b/arch/powerpc/include/asm/highmem.h index f14e4feef6d5..08e02a4f3a8f 100644 --- a/arch/powerpc/include/asm/highmem.h +++ b/arch/powerpc/include/asm/highmem.h @@ -63,14 +63,6 @@ extern void kunmap_high(struct page *page); extern void *kmap_atomic_prot(struct page *page, pgprot_t prot); extern void __kunmap_atomic(void *kvaddr); -static inline void kunmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return; - kunmap_high(page); -} - static inline void *kmap_atomic(struct page *page) { return kmap_atomic_prot(page, kmap_prot); diff --git a/arch/sparc/include/asm/highmem.h b/arch/sparc/include/asm/highmem.h index 2ff1192047f7..b3ee234b2a8f 100644 --- a/arch/sparc/include/asm/highmem.h +++ b/arch/sparc/include/asm/highmem.h @@ -52,14 +52,6 @@ void kmap_init(void) __init; void kunmap_high(struct page *page); -static inline void kunmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return; - kunmap_high(page); -} - void *kmap_atomic(struct page *page); void __kunmap_atomic(void *kvaddr); diff --git a/arch/x86/include/asm/highmem.h b/arch/x86/include/asm/highmem.h index c916a28a9738..102cdcde74cb 100644 --- a/arch/x86/include/asm/highmem.h +++ b/arch/x86/include/asm/highmem.h @@ -60,8 +60,6 @@ extern unsigned long highstart_pfn, highend_pfn; extern void kunmap_high(struct page *page); -void kunmap(struct page *page); - void *kmap_atomic_prot(struct page *page, pgprot_t prot); void *kmap_atomic(struct page *page); void __kunmap_atomic(void *kvaddr); diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c index 12591a81b85c..c4ebfd0ae401 100644 --- a/arch/x86/mm/highmem_32.c +++ b/arch/x86/mm/highmem_32.c @@ -4,15 +4,6 @@ #include /* for totalram_pages */ #include -void kunmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return; - kunmap_high(page); -} -EXPORT_SYMBOL(kunmap); - /* * 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 diff --git a/arch/xtensa/include/asm/highmem.h b/arch/xtensa/include/asm/highmem.h index fac4f48bde6c..ae9e0ffbdb80 100644 --- a/arch/xtensa/include/asm/highmem.h +++ b/arch/xtensa/include/asm/highmem.h @@ -75,14 +75,6 @@ static inline void *kmap(struct page *page) return kmap_generic(page); } -static inline void kunmap(struct page *page) -{ - might_sleep(); - if (!PageHighMem(page)) - return; - kunmap_high(page); -} - static inline void flush_cache_kmaps(void) { flush_cache_all(); diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 2f7f710b7e7d..1a3b7690c78c 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -52,6 +52,14 @@ static inline void *kmap(struct page *page) } #endif +static inline void kunmap(struct page *page) +{ + might_sleep(); + if (!PageHighMem(page)) + return; + kunmap_high(page); +} + /* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages(void); extern atomic_long_t _totalhigh_pages; From patchwork Sun Apr 26 05:54:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 11510159 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 744421667 for ; Sun, 26 Apr 2020 05:54:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 616A721D7B for ; Sun, 26 Apr 2020 05:54:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726295AbgDZFy0 (ORCPT ); Sun, 26 Apr 2020 01:54:26 -0400 Received: from mga05.intel.com ([192.55.52.43]:34948 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726228AbgDZFyY (ORCPT ); Sun, 26 Apr 2020 01:54:24 -0400 IronPort-SDR: yik+lW6jLFww72iGqqtV+gwEW5b2Cqu5v2V0GfswzYKOLd/cbabjIXUiUpwElsrf0zdAY3TKG9 4Adxy+Os6HYA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2020 22:54:23 -0700 IronPort-SDR: JbrFxZQOg4mMIuwtoATzRdij1dRliQGnUgWcjgmHA5TRHF3mzGglJEjgI5nDw5LX1Vgmb6bj/B U1DQQme6oOjQ== X-IronPort-AV: E=Sophos;i="5.73,319,1583222400"; d="scan'208";a="302014809" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2020 22:54:23 -0700 From: ira.weiny@intel.com To: linux-kernel@vger.kernel.org, Andrew Morton Cc: Ira Weiny , Dan Williams , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Benjamin Herrenschmidt , Paul Mackerras , "David S. Miller" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Chris Zankel , Max Filippov , linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH 4/5] arch/kmap_atomic: Consolidate duplicate code Date: Sat, 25 Apr 2020 22:54:05 -0700 Message-Id: <20200426055406.134198-5-ira.weiny@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200426055406.134198-1-ira.weiny@intel.com> References: <20200426055406.134198-1-ira.weiny@intel.com> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Ira Weiny Every arch has the same check for a not HIGHMEM page. Define kmap_atomic_fast() to quickly return already mapped pages and reduce the code duplication by lifting this check to the core. Reviewed-by: Dan Williams Signed-off-by: Ira Weiny --- arch/arc/mm/highmem.c | 7 +++---- arch/arm/mm/highmem.c | 8 +++----- arch/csky/mm/highmem.c | 7 +++---- arch/microblaze/mm/highmem.c | 8 +++----- arch/mips/mm/highmem.c | 7 +++---- arch/nds32/mm/highmem.c | 7 +++---- arch/powerpc/mm/highmem.c | 7 +++---- arch/sparc/mm/highmem.c | 7 +++---- arch/x86/mm/highmem_32.c | 8 +++----- arch/xtensa/mm/highmem.c | 7 +++---- include/linux/highmem.h | 9 +++++++++ 11 files changed, 39 insertions(+), 43 deletions(-) diff --git a/arch/arc/mm/highmem.c b/arch/arc/mm/highmem.c index 4db13a6b9f3b..1cae4b911a33 100644 --- a/arch/arc/mm/highmem.c +++ b/arch/arc/mm/highmem.c @@ -53,11 +53,10 @@ void *kmap_atomic(struct page *page) { int idx, cpu_idx; unsigned long vaddr; + void *addr = kmap_atomic_fast(page); - preempt_disable(); - pagefault_disable(); - if (!PageHighMem(page)) - return page_address(page); + if (addr) + return addr; cpu_idx = kmap_atomic_idx_push(); idx = cpu_idx + KM_TYPE_NR * smp_processor_id(); diff --git a/arch/arm/mm/highmem.c b/arch/arm/mm/highmem.c index c700b32350ee..4a629f616a6a 100644 --- a/arch/arm/mm/highmem.c +++ b/arch/arm/mm/highmem.c @@ -35,13 +35,11 @@ void *kmap_atomic(struct page *page) { unsigned int idx; unsigned long vaddr; - void *kmap; + void *kmap = kmap_atomic_fast(page); int type; - preempt_disable(); - pagefault_disable(); - if (!PageHighMem(page)) - return page_address(page); + if (kmap) + return kmap; #ifdef CONFIG_DEBUG_HIGHMEM /* diff --git a/arch/csky/mm/highmem.c b/arch/csky/mm/highmem.c index 69b1931986ae..1191f57f53ae 100644 --- a/arch/csky/mm/highmem.c +++ b/arch/csky/mm/highmem.c @@ -25,12 +25,11 @@ EXPORT_SYMBOL(kmap); void *kmap_atomic(struct page *page) { unsigned long vaddr; + void *addr = kmap_atomic_fast(page); int idx, type; - preempt_disable(); - pagefault_disable(); - if (!PageHighMem(page)) - return page_address(page); + if (addr) + return addr; type = kmap_atomic_idx_push(); idx = type + KM_TYPE_NR*smp_processor_id(); diff --git a/arch/microblaze/mm/highmem.c b/arch/microblaze/mm/highmem.c index d7569f77fa15..99fdf826edc2 100644 --- a/arch/microblaze/mm/highmem.c +++ b/arch/microblaze/mm/highmem.c @@ -36,13 +36,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot) { unsigned long vaddr; + void *addr = kmap_atomic_fast(page); int idx, type; - preempt_disable(); - pagefault_disable(); - if (!PageHighMem(page)) - return page_address(page); - + if (addr) + return addr; type = kmap_atomic_idx_push(); idx = type + KM_TYPE_NR*smp_processor_id(); diff --git a/arch/mips/mm/highmem.c b/arch/mips/mm/highmem.c index c3c9fe962f0f..ba03ca75d4a1 100644 --- a/arch/mips/mm/highmem.c +++ b/arch/mips/mm/highmem.c @@ -33,12 +33,11 @@ EXPORT_SYMBOL(kmap); void *kmap_atomic(struct page *page) { unsigned long vaddr; + void *addr = kmap_atomic_fast(page); int idx, type; - preempt_disable(); - pagefault_disable(); - if (!PageHighMem(page)) - return page_address(page); + if (addr) + return addr; type = kmap_atomic_idx_push(); idx = type + KM_TYPE_NR*smp_processor_id(); diff --git a/arch/nds32/mm/highmem.c b/arch/nds32/mm/highmem.c index f9348bec0ecb..4aabde586489 100644 --- a/arch/nds32/mm/highmem.c +++ b/arch/nds32/mm/highmem.c @@ -14,13 +14,12 @@ void *kmap_atomic(struct page *page) { unsigned int idx; unsigned long vaddr, pte; + void *addr = kmap_atomic_fast(page); int type; pte_t *ptep; - preempt_disable(); - pagefault_disable(); - if (!PageHighMem(page)) - return page_address(page); + if (addr) + return addr; type = kmap_atomic_idx_push(); diff --git a/arch/powerpc/mm/highmem.c b/arch/powerpc/mm/highmem.c index 320c1672b2ae..cdf5b716801a 100644 --- a/arch/powerpc/mm/highmem.c +++ b/arch/powerpc/mm/highmem.c @@ -33,12 +33,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot) { unsigned long vaddr; + void *addr = kmap_atomic_fast(page); int idx, type; - preempt_disable(); - pagefault_disable(); - if (!PageHighMem(page)) - return page_address(page); + if (addr) + return addr; type = kmap_atomic_idx_push(); idx = type + KM_TYPE_NR*smp_processor_id(); diff --git a/arch/sparc/mm/highmem.c b/arch/sparc/mm/highmem.c index d4a80adea7e5..178641805567 100644 --- a/arch/sparc/mm/highmem.c +++ b/arch/sparc/mm/highmem.c @@ -56,12 +56,11 @@ void __init kmap_init(void) void *kmap_atomic(struct page *page) { unsigned long vaddr; + void *addr = kmap_atomic_fast(page); long idx, type; - preempt_disable(); - pagefault_disable(); - if (!PageHighMem(page)) - return page_address(page); + if (addr) + return addr; type = kmap_atomic_idx_push(); idx = type + KM_TYPE_NR*smp_processor_id(); diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c index c4ebfd0ae401..34770499b0ff 100644 --- a/arch/x86/mm/highmem_32.c +++ b/arch/x86/mm/highmem_32.c @@ -15,13 +15,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot) { unsigned long vaddr; + void *addr = kmap_atomic_fast(page); int idx, type; - preempt_disable(); - pagefault_disable(); - - if (!PageHighMem(page)) - return page_address(page); + if (addr) + return addr; type = kmap_atomic_idx_push(); idx = type + KM_TYPE_NR*smp_processor_id(); diff --git a/arch/xtensa/mm/highmem.c b/arch/xtensa/mm/highmem.c index 184ceadccc1a..38c14e0b578c 100644 --- a/arch/xtensa/mm/highmem.c +++ b/arch/xtensa/mm/highmem.c @@ -41,11 +41,10 @@ void *kmap_atomic(struct page *page) { enum fixed_addresses idx; unsigned long vaddr; + void *addr = kmap_atomic_fast(page); - preempt_disable(); - pagefault_disable(); - if (!PageHighMem(page)) - return page_address(page); + if (addr) + return addr; idx = kmap_idx(kmap_atomic_idx_push(), DCACHE_ALIAS(page_to_phys(page))); diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 1a3b7690c78c..eee53e151900 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -60,6 +60,15 @@ static inline void kunmap(struct page *page) kunmap_high(page); } +static inline void *kmap_atomic_fast(struct page *page) +{ + preempt_disable(); + pagefault_disable(); + if (!PageHighMem(page)) + return page_address(page); + return NULL; +} + /* declarations for linux/mm/highmem.c */ unsigned int nr_free_highpages(void); extern atomic_long_t _totalhigh_pages; From patchwork Sun Apr 26 05:54:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 11510165 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEF181805 for ; Sun, 26 Apr 2020 05:54:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA6112173E for ; Sun, 26 Apr 2020 05:54:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726264AbgDZFyZ (ORCPT ); Sun, 26 Apr 2020 01:54:25 -0400 Received: from mga06.intel.com ([134.134.136.31]:57441 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbgDZFyY (ORCPT ); Sun, 26 Apr 2020 01:54:24 -0400 IronPort-SDR: pSRn4sTKqs+CzzvOCrSeldPsYyrnw/f/yZJk71/3AP69VNp9IP3UAqqgfPbGoLW6arIDB3VCbL 6MgTgoNg5qQA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2020 22:54:24 -0700 IronPort-SDR: ULIPpftXlRuZVncLUHSwuauSzU7AMt8SQ3FSLW4e25oH6OANV+RbXbJFufO4yzakpq0D15kNUU 6n3sFI9wk+2w== X-IronPort-AV: E=Sophos;i="5.73,319,1583222400"; d="scan'208";a="245732999" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2020 22:54:23 -0700 From: ira.weiny@intel.com To: linux-kernel@vger.kernel.org, Andrew Morton Cc: Ira Weiny , Dan Williams , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Benjamin Herrenschmidt , Paul Mackerras , "David S. Miller" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Chris Zankel , Max Filippov , linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH 5/5] arch/kunmap_atomic: Consolidate duplicate code Date: Sat, 25 Apr 2020 22:54:06 -0700 Message-Id: <20200426055406.134198-6-ira.weiny@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200426055406.134198-1-ira.weiny@intel.com> References: <20200426055406.134198-1-ira.weiny@intel.com> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Ira Weiny Every single architecture (including !CONFIG_HIGHMEM) calls... pagefault_enable(); preempt_enable(); ... before returning from __kunmap_atomic(). Lift this code into the kunmap_atomic() macro. Reviewed-by: Dan Williams Signed-off-by: Ira Weiny --- arch/arc/mm/highmem.c | 3 --- arch/arm/mm/highmem.c | 2 -- arch/csky/mm/highmem.c | 5 +---- arch/microblaze/mm/highmem.c | 2 -- arch/mips/mm/highmem.c | 2 -- arch/nds32/mm/highmem.c | 2 -- arch/parisc/include/asm/cacheflush.h | 2 -- arch/powerpc/mm/highmem.c | 2 -- arch/sparc/mm/highmem.c | 2 -- arch/x86/mm/highmem_32.c | 3 --- arch/xtensa/mm/highmem.c | 3 --- include/linux/highmem.h | 6 ++++-- 12 files changed, 5 insertions(+), 29 deletions(-) diff --git a/arch/arc/mm/highmem.c b/arch/arc/mm/highmem.c index 1cae4b911a33..0725fc56b016 100644 --- a/arch/arc/mm/highmem.c +++ b/arch/arc/mm/highmem.c @@ -91,9 +91,6 @@ void __kunmap_atomic(void *kv) kmap_atomic_idx_pop(); } - - pagefault_enable(); - preempt_enable(); } EXPORT_SYMBOL(__kunmap_atomic); diff --git a/arch/arm/mm/highmem.c b/arch/arm/mm/highmem.c index 4a629f616a6a..4983bf18ec32 100644 --- a/arch/arm/mm/highmem.c +++ b/arch/arm/mm/highmem.c @@ -98,8 +98,6 @@ 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); diff --git a/arch/csky/mm/highmem.c b/arch/csky/mm/highmem.c index 1191f57f53ae..106fa6773084 100644 --- a/arch/csky/mm/highmem.c +++ b/arch/csky/mm/highmem.c @@ -50,7 +50,7 @@ void __kunmap_atomic(void *kvaddr) int idx; if (vaddr < FIXADDR_START) - goto out; + return; #ifdef CONFIG_DEBUG_HIGHMEM idx = KM_TYPE_NR*smp_processor_id() + kmap_atomic_idx(); @@ -63,9 +63,6 @@ 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); diff --git a/arch/microblaze/mm/highmem.c b/arch/microblaze/mm/highmem.c index 99fdf826edc2..d382c6821747 100644 --- a/arch/microblaze/mm/highmem.c +++ b/arch/microblaze/mm/highmem.c @@ -81,7 +81,5 @@ void __kunmap_atomic(void *kvaddr) local_flush_tlb_page(NULL, vaddr); kmap_atomic_idx_pop(); - pagefault_enable(); - preempt_enable(); } EXPORT_SYMBOL(__kunmap_atomic); diff --git a/arch/mips/mm/highmem.c b/arch/mips/mm/highmem.c index ba03ca75d4a1..5a3fc7e84e66 100644 --- a/arch/mips/mm/highmem.c +++ b/arch/mips/mm/highmem.c @@ -79,8 +79,6 @@ void __kunmap_atomic(void *kvaddr) } #endif kmap_atomic_idx_pop(); - pagefault_enable(); - preempt_enable(); } EXPORT_SYMBOL(__kunmap_atomic); diff --git a/arch/nds32/mm/highmem.c b/arch/nds32/mm/highmem.c index 4aabde586489..b8862aafa189 100644 --- a/arch/nds32/mm/highmem.c +++ b/arch/nds32/mm/highmem.c @@ -49,8 +49,6 @@ 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); diff --git a/arch/parisc/include/asm/cacheflush.h b/arch/parisc/include/asm/cacheflush.h index 0c83644bfa5c..c8458491b9af 100644 --- a/arch/parisc/include/asm/cacheflush.h +++ b/arch/parisc/include/asm/cacheflush.h @@ -125,8 +125,6 @@ static inline void *kmap_atomic(struct page *page) static inline void __kunmap_atomic(void *addr) { flush_kernel_dcache_page_addr(addr); - pagefault_enable(); - preempt_enable(); } #define kmap_atomic_prot(page, prot) kmap_atomic(page) diff --git a/arch/powerpc/mm/highmem.c b/arch/powerpc/mm/highmem.c index cdf5b716801a..7dfccf519621 100644 --- a/arch/powerpc/mm/highmem.c +++ b/arch/powerpc/mm/highmem.c @@ -76,7 +76,5 @@ void __kunmap_atomic(void *kvaddr) } kmap_atomic_idx_pop(); - pagefault_enable(); - preempt_enable(); } EXPORT_SYMBOL(__kunmap_atomic); diff --git a/arch/sparc/mm/highmem.c b/arch/sparc/mm/highmem.c index 178641805567..7a99a1097f67 100644 --- a/arch/sparc/mm/highmem.c +++ b/arch/sparc/mm/highmem.c @@ -130,7 +130,5 @@ void __kunmap_atomic(void *kvaddr) #endif kmap_atomic_idx_pop(); - pagefault_enable(); - preempt_enable(); } EXPORT_SYMBOL(__kunmap_atomic); diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c index 34770499b0ff..b20e81b2b833 100644 --- a/arch/x86/mm/highmem_32.c +++ b/arch/x86/mm/highmem_32.c @@ -78,9 +78,6 @@ void __kunmap_atomic(void *kvaddr) BUG_ON(vaddr >= (unsigned long)high_memory); } #endif - - pagefault_enable(); - preempt_enable(); } EXPORT_SYMBOL(__kunmap_atomic); diff --git a/arch/xtensa/mm/highmem.c b/arch/xtensa/mm/highmem.c index 38c14e0b578c..9a49263e4cd6 100644 --- a/arch/xtensa/mm/highmem.c +++ b/arch/xtensa/mm/highmem.c @@ -77,9 +77,6 @@ void __kunmap_atomic(void *kvaddr) kmap_atomic_idx_pop(); } - - pagefault_enable(); - preempt_enable(); } EXPORT_SYMBOL(__kunmap_atomic); diff --git a/include/linux/highmem.h b/include/linux/highmem.h index eee53e151900..94145d4200ab 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -133,8 +133,8 @@ static inline void *kmap_atomic(struct page *page) static inline void __kunmap_atomic(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)) @@ -185,6 +185,8 @@ static inline void kmap_atomic_idx_pop(void) do { \ BUILD_BUG_ON(__same_type((addr), struct page *)); \ __kunmap_atomic(addr); \ + pagefault_enable(); \ + preempt_enable(); \ } while (0)