Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Arnd Bergmann <arnd@kernel.org>
Cc: linux-mm@kvack.org, Arnd Bergmann <arnd@arndb.de>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Andreas Larsson <andreas@gaisler.com>,
	 "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	 "David Hildenbrand (Arm)" <david@kernel.org>,
	Jason Gunthorpe <jgg@nvidia.com>,
	 Linus Walleij <linus.walleij@linaro.org>,
	Matthew Wilcox <willy@infradead.org>,
	 Malin Jonsson <malin.jonsson@est.tech>,
	Richard Weinberger <richard@nod.at>,
	 Russell King <linux@armlinux.org.uk>,
	linux-arm-kernel@lists.infradead.org,
	 linux-fsdevel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	x86@kernel.org
Subject: Re: [PATCH v2 2/6] mm: remove ARCH_NEEDS_KMAP_HIGH_GET
Date: Fri, 13 Nov 2026 18:39:34 +0000	[thread overview]
Message-ID: <avdXERQgqgJ3P_Sd@gremlin> (raw)
In-Reply-To: <20261112112528.1116405-3-arnd@kernel.org>

On Thu, Nov 12, 2026 at 12:25:24PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> Arm has stopped setting ARCH_NEEDS_KMAP_HIGH_GET, so this
> is handled using the same wrappers across all architectures
> now, which leaves room for simplification.
>
> Replace lock_kmap()/unlock_kmap() with open-coded spinlocks
> and drop the now empty arch_kmap_local_high_get() and
> kmap_high_unmap_local() helpers.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Lovely :)

Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>

> ---
>  mm/highmem.c | 100 ++++++---------------------------------------------
>  1 file changed, 10 insertions(+), 90 deletions(-)
>
> diff --git a/mm/highmem.c b/mm/highmem.c
> index a33e41183951..214164f9172b 100644
> --- a/mm/highmem.c
> +++ b/mm/highmem.c
> @@ -143,25 +143,6 @@ static  __cacheline_aligned_in_smp DEFINE_SPINLOCK(kmap_lock);
>
>  pte_t *pkmap_page_table;
>
> -/*
> - * Most architectures have no use for kmap_high_get(), so let's abstract
> - * the disabling of IRQ out of the locking in that case to save on a
> - * potential useless overhead.
> - */
> -#ifdef ARCH_NEEDS_KMAP_HIGH_GET
> -#define lock_kmap()             spin_lock_irq(&kmap_lock)
> -#define unlock_kmap()           spin_unlock_irq(&kmap_lock)
> -#define lock_kmap_any(flags)    spin_lock_irqsave(&kmap_lock, flags)
> -#define unlock_kmap_any(flags)  spin_unlock_irqrestore(&kmap_lock, flags)
> -#else
> -#define lock_kmap()             spin_lock(&kmap_lock)
> -#define unlock_kmap()           spin_unlock(&kmap_lock)
> -#define lock_kmap_any(flags)    \
> -		do { spin_lock(&kmap_lock); (void)(flags); } while (0)
> -#define unlock_kmap_any(flags)  \
> -		do { spin_unlock(&kmap_lock); (void)(flags); } while (0)
> -#endif
> -
>  struct page *__kmap_to_page(void *vaddr)
>  {
>  	unsigned long base = (unsigned long) vaddr & PAGE_MASK;
> @@ -238,9 +219,9 @@ static void flush_all_zero_pkmaps(void)
>
>  void __kmap_flush_unused(void)
>  {
> -	lock_kmap();
> +	spin_lock(&kmap_lock);
>  	flush_all_zero_pkmaps();
> -	unlock_kmap();
> +	spin_unlock(&kmap_lock);
>  }
>
>  static inline unsigned long map_new_virtual(struct page *page)
> @@ -274,10 +255,10 @@ static inline unsigned long map_new_virtual(struct page *page)
>
>  			__set_current_state(TASK_UNINTERRUPTIBLE);
>  			add_wait_queue(pkmap_map_wait, &wait);
> -			unlock_kmap();
> +			spin_unlock(&kmap_lock);
>  			schedule();
>  			remove_wait_queue(pkmap_map_wait, &wait);
> -			lock_kmap();
> +			spin_lock(&kmap_lock);
>
>  			/* Somebody else might have mapped it while we slept */
>  			if (page_address(page))
> @@ -313,60 +294,32 @@ void *kmap_high(struct page *page)
>  	 * For highmem pages, we can't trust "virtual" until
>  	 * after we have the lock.
>  	 */
> -	lock_kmap();
> +	spin_lock(&kmap_lock);
>  	vaddr = (unsigned long)page_address(page);
>  	if (!vaddr)
>  		vaddr = map_new_virtual(page);
>  	pkmap_count[PKMAP_NR(vaddr)]++;
>  	BUG_ON(pkmap_count[PKMAP_NR(vaddr)] < 2);
> -	unlock_kmap();
> +	spin_unlock(&kmap_lock);
>  	return (void *) vaddr;
>  }
>  EXPORT_SYMBOL(kmap_high);
>
> -#ifdef ARCH_NEEDS_KMAP_HIGH_GET
> -/**
> - * kmap_high_get - pin a highmem page into memory
> - * @page: &struct page to pin
> - *
> - * Returns the page's current virtual memory address, or NULL if no mapping
> - * exists.  If and only if a non null address is returned then a
> - * matching call to kunmap_high() is necessary.
> - *
> - * This can be called from any context.
> - */
> -void *kmap_high_get(const struct page *page)
> -{
> -	unsigned long vaddr, flags;
> -
> -	lock_kmap_any(flags);
> -	vaddr = (unsigned long)page_address(page);
> -	if (vaddr) {
> -		BUG_ON(pkmap_count[PKMAP_NR(vaddr)] < 1);
> -		pkmap_count[PKMAP_NR(vaddr)]++;
> -	}
> -	unlock_kmap_any(flags);
> -	return (void *) vaddr;
> -}
> -#endif
> -
>  /**
>   * kunmap_high - unmap a highmem page into memory
>   * @page: &struct page to unmap
>   *
> - * If ARCH_NEEDS_KMAP_HIGH_GET is not defined then this may be called
> - * only from user context.
> + * This may be called only from user context.
>   */
>  void kunmap_high(const struct page *page)
>  {
>  	unsigned long vaddr;
>  	unsigned long nr;
> -	unsigned long flags;
>  	int need_wakeup;
>  	unsigned int color = get_pkmap_color(page);
>  	wait_queue_head_t *pkmap_map_wait;
>
> -	lock_kmap_any(flags);
> +	spin_lock(&kmap_lock);
>  	vaddr = (unsigned long)page_address(page);
>  	BUG_ON(!vaddr);
>  	nr = PKMAP_NR(vaddr);
> @@ -393,7 +346,7 @@ void kunmap_high(const struct page *page)
>  		pkmap_map_wait = get_pkmap_wait_queue_head(color);
>  		need_wakeup = waitqueue_active(pkmap_map_wait);
>  	}
> -	unlock_kmap_any(flags);
> +	spin_unlock(&kmap_lock);
>
>  	/* do wake-up, if needed, race-free outside of the spin lock */
>  	if (need_wakeup)
> @@ -508,30 +461,11 @@ static inline void kmap_local_idx_pop(void)
>  #define arch_kmap_local_unmap_idx(idx, vaddr)	kmap_local_calc_idx(idx)
>  #endif
>
> -#ifndef arch_kmap_local_high_get
> -static inline void *arch_kmap_local_high_get(const struct page *page)
> -{
> -	return NULL;
> -}
> -#endif
> -
>  #ifndef arch_kmap_local_set_pte
>  #define arch_kmap_local_set_pte(mm, vaddr, ptep, ptev)	\
>  	set_pte_at(mm, vaddr, ptep, ptev)
>  #endif
>
> -/* Unmap a local mapping which was obtained by kmap_high_get() */
> -static inline bool kmap_high_unmap_local(unsigned long vaddr)
> -{
> -#ifdef ARCH_NEEDS_KMAP_HIGH_GET
> -	if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) {
> -		kunmap_high(pte_page(ptep_get(&pkmap_page_table[PKMAP_NR(vaddr)])));
> -		return true;
> -	}
> -#endif
> -	return false;
> -}
> -
>  static pte_t *__kmap_pte;
>
>  static pte_t *kmap_get_pte(unsigned long vaddr, int idx)
> @@ -575,8 +509,6 @@ EXPORT_SYMBOL_GPL(__kmap_local_pfn_prot);
>
>  void *__kmap_local_page_prot(const struct page *page, pgprot_t prot)
>  {
> -	void *kmap;
> -
>  	/*
>  	 * To broaden the usage of the actual kmap_local() machinery always map
>  	 * pages when debugging is enabled and the architecture has no problems
> @@ -585,11 +517,6 @@ void *__kmap_local_page_prot(const struct page *page, pgprot_t prot)
>  	if (!IS_ENABLED(CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP) && !PageHighMem(page))
>  		return page_address(page);
>
> -	/* Try kmap_high_get() if architecture has it enabled */
> -	kmap = arch_kmap_local_high_get(page);
> -	if (kmap)
> -		return kmap;
> -
>  	return __kmap_local_pfn_prot(page_to_pfn(page), prot);
>  }
>  EXPORT_SYMBOL(__kmap_local_page_prot);
> @@ -607,14 +534,7 @@ void kunmap_local_indexed(const void *vaddr)
>  			WARN_ON_ONCE(1);
>  			return;
>  		}
> -		/*
> -		 * Handle mappings which were obtained by kmap_high_get()
> -		 * first as the virtual address of such mappings is below
> -		 * PAGE_OFFSET. Warn for all other addresses which are in
> -		 * the user space part of the virtual address space.
> -		 */
> -		if (!kmap_high_unmap_local(addr))
> -			WARN_ON_ONCE(addr < PAGE_OFFSET);
> +		WARN_ON_ONCE(addr < PAGE_OFFSET);
>  		return;
>  	}
>
> --
> 2.53.0
>

--
Cheers, Lorenzo


  parent reply	other threads:[~2026-11-13 18:39 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 11:25 [PATCH v2 0/6] mm: highmem cleanups Arnd Bergmann
2026-11-12 11:25 ` [PATCH v2 1/6] ARM: remove support for highmem on VIVT Arnd Bergmann
2026-11-12 13:47   ` Arnd Bergmann
2026-11-13 11:26   ` sashiko-bot
2026-11-13 11:36     ` Arnd Bergmann
2026-11-13 18:28   ` Lorenzo Stoakes (ARM)
2026-11-12 11:25 ` [PATCH v2 2/6] mm: remove ARCH_NEEDS_KMAP_HIGH_GET Arnd Bergmann
2026-11-12 11:48   ` Mike Rapoport
2026-11-13 18:39   ` Lorenzo Stoakes (ARM) [this message]
2026-11-12 11:25 ` [PATCH v2 3/6] ARM: drop CONFIG_HIGHPTE support Arnd Bergmann
2026-11-12 11:47   ` Mike Rapoport
2026-11-12 12:22     ` Arnd Bergmann
2026-11-13 18:41   ` Lorenzo Stoakes (ARM)
2026-11-12 11:25 ` [PATCH v2 4/6] mm: drop HIGHPTE support altogether Arnd Bergmann
2026-11-12 11:54   ` Mike Rapoport
2026-11-12 12:33     ` David Hildenbrand (Arm)
2026-11-12 13:26     ` Arnd Bergmann
2026-11-13 10:50       ` David Hildenbrand (Arm)
2026-11-13 18:53   ` Lorenzo Stoakes (ARM)
2026-11-12 11:25 ` [PATCH v2 5/6] arch/*: increase lowmem size to avoid highmem use Arnd Bergmann
2026-11-12 12:00   ` Mike Rapoport
2026-11-13 11:26   ` sashiko-bot
2026-11-13 17:54     ` Arnd Bergmann
2026-11-13 18:35   ` H. Peter Anvin
2026-11-13 18:58   ` Lorenzo Stoakes (ARM)
2026-11-12 11:25 ` [PATCH v2 6/6] ARM: add CONFIG_VMSPLIT_2G_OPT option Arnd Bergmann
2026-11-13 11:26   ` sashiko-bot
2026-11-13 14:18     ` Arnd Bergmann
2026-11-13 19:20   ` Lorenzo Stoakes (ARM)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=avdXERQgqgJ3P_Sd@gremlin \
    --to=ljs@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andreas@gaisler.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=chleroy@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@kernel.org \
    --cc=jgg@nvidia.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@armlinux.org.uk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=malin.jonsson@est.tech \
    --cc=richard@nod.at \
    --cc=willy@infradead.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox