From nobody Thu Dec 18 07:20:24 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A575C197A0 for ; Mon, 20 Nov 2023 14:26:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233264AbjKTO0y (ORCPT ); Mon, 20 Nov 2023 09:26:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233204AbjKTO0u (ORCPT ); Mon, 20 Nov 2023 09:26:50 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFE0B11A for ; Mon, 20 Nov 2023 06:26:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700490406; x=1732026406; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=mfeyDKRxFMHuZ0AE0xc+ySqphdof3bC/Ooi7RFDXZW4=; b=N5tPuzk6zfXDPKS2UTP672HktTJXl6Kc8Eb1jeSVkWLBhJUnCN6sCi0C 8Mh7+eFOANAlip4XT4IpfPAkGCGjjvqgxABgZ7VkzJFsJl0o0q7ZgXFpD 2pJsObGj53tGPGAeXWCVgMa00nG0f60Yv6Jq4js7cdNc77lLkFfI47SOd SLJEhoJoME6TbRwLJ8AK8xC+2jLPsCNkfYDUPwnVLa40PPNKgh1rBN2ex D79LH6J4dm1eFNQZEYq184/pl26G/Bwuj5mne2IfxT9NS4YXidMWDN7j8 MMIQW1L3ItKsJgH3jUWN2OhL0RYl6q7Zwn+jEiJklypvhq3qV9I9+ow67 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="370971046" X-IronPort-AV: E=Sophos;i="6.04,214,1695711600"; d="scan'208";a="370971046" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 06:26:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,214,1695711600"; d="scan'208";a="7734299" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.Hitronhub.home) ([10.213.12.244]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 06:26:44 -0800 From: "Fabio M. De Francesco" To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: "Fabio M. De Francesco" , Ira Weiny Subject: [PATCH] mm/mempool: Replace kmap_atomic() with kmap_local_page() Date: Mon, 20 Nov 2023 15:26:31 +0100 Message-ID: <20231120142640.7077-1-fabio.maria.de.francesco@linux.intel.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" kmap_atomic() has been deprecated in favor of kmap_local_page(). Therefore, replace kmap_atomic() with kmap_local_page(). kmap_atomic() is implemented like a kmap_local_page() which also disables page-faults and preemption (the latter only in !PREEMPT_RT kernels). The kernel virtual addresses returned by these two API are only valid in the context of the callers (i.e., they cannot be handed to other threads). With kmap_local_page() the mappings are per thread and CPU local like in kmap_atomic(); however, they can handle page-faults and can be called from any context (including interrupts). The tasks that call kmap_local_page() can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and are still valid. The code blocks between the mappings and un-mappings don't rely on the above-mentioned side effects of kmap_atomic(), so that mere replacements of the old API with the new one is all that they require (i.e., there is no need to explicitly call pagefault_disable() and/or preempt_disable()). Cc: Ira Weiny Signed-off-by: Fabio M. De Francesco --- mm/mempool.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/mempool.c b/mm/mempool.c index 734bcf5afbb7..b3d2084fd989 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -64,10 +64,10 @@ static void check_element(mempool_t *pool, void *elemen= t) } else if (pool->free =3D=3D mempool_free_pages) { /* Mempools backed by page allocator */ int order =3D (int)(long)pool->pool_data; - void *addr =3D kmap_atomic((struct page *)element); + void *addr =3D kmap_local_page((struct page *)element); =20 __check_element(pool, addr, 1UL << (PAGE_SHIFT + order)); - kunmap_atomic(addr); + kunmap_local(addr); } } =20 @@ -89,10 +89,10 @@ static void poison_element(mempool_t *pool, void *eleme= nt) } else if (pool->alloc =3D=3D mempool_alloc_pages) { /* Mempools backed by page allocator */ int order =3D (int)(long)pool->pool_data; - void *addr =3D kmap_atomic((struct page *)element); + void *addr =3D kmap_local_page((struct page *)element); =20 __poison_element(addr, 1UL << (PAGE_SHIFT + order)); - kunmap_atomic(addr); + kunmap_local(addr); } } #else /* CONFIG_DEBUG_SLAB || CONFIG_SLUB_DEBUG_ON */ --=20 2.42.0