From patchwork Mon Nov 20 14:26:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 13461411 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40A1DC2BB3F for ; Mon, 20 Nov 2023 14:26:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5B4F6B045B; Mon, 20 Nov 2023 09:26:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0ADD6B045C; Mon, 20 Nov 2023 09:26:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D2366B045D; Mon, 20 Nov 2023 09:26:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8DF3E6B045B for ; Mon, 20 Nov 2023 09:26:50 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 606011408BA for ; Mon, 20 Nov 2023 14:26:50 +0000 (UTC) X-FDA: 81478558980.22.B12F6A5 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by imf28.hostedemail.com (Postfix) with ESMTP id EDBFDC002C for ; Mon, 20 Nov 2023 14:26:47 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=aNDTuUh7; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf28.hostedemail.com: domain of fabio.maria.de.francesco@linux.intel.com has no SPF policy when checking 192.55.52.136) smtp.mailfrom=fabio.maria.de.francesco@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700490408; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=UrNUiDQhPRVXPRaqGASTaNUFFHGOEChD1f0OLJ2XEyU=; b=SdaIC/fo/ZA7vaaEQsFLjix8RIp9rZeKMtfua1tnZv1n3MXC1NI++IEGNMAejFRnRcmk8e 38ICucTgY+iwHQ4baoTRkabP/5SrkTZnLktJPnzQCyY1xG4EY4CEKh4R4HSjkxQGnjuCx5 jR2p6+lt6j6JIod9k0KvnKMSOSTmksA= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=aNDTuUh7; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf28.hostedemail.com: domain of fabio.maria.de.francesco@linux.intel.com has no SPF policy when checking 192.55.52.136) smtp.mailfrom=fabio.maria.de.francesco@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700490408; a=rsa-sha256; cv=none; b=QhD5nOqa2dUaFahYILO/+XALYr1HglwgZxz2bVXUXcDCwcjGQ4Oic3gye2Sg9t6RhKQwsE cBDYWMROlD7Kh1Q6P3gteMozUP9QDbOrP/Q9RIrtQcCuqZ9JHN/GOoqs1tJCWPCaUiKRqE 8ie0Se4wU+OJHXbjBxNbh7vXnyiVieg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700490408; x=1732026408; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=mfeyDKRxFMHuZ0AE0xc+ySqphdof3bC/Ooi7RFDXZW4=; b=aNDTuUh7vidiJXEE6J+VqgjzyULMqkIUkg39LawA/c7jFrNQ2iGHjwCZ cBBkY5GpAWel2DNa1TDnS8Iraz5afzFlGHh8wbmAyOi/jVHDsXB4hNoSN elCpC/yEwrGkDzx0bqHf5tcEGs9h/5NiB5NZEAsj4W3qS65Y5IHhvlftJ 6Yyi+nNxLbhYmNX0GfPHZZSJSasUqh94HODUD6qfaBUhg0OP61dlqsp7Q A0bu5BKP/q01U4MAJv+vJNivw0WM2vAY1eI6nmSAjxzLNAPkvt2lcdA/G Qybs2sgHeyOfdFeRu2o/tT8heljkBRpi+4Ka1pIYuNuCtzZAOm6eHgH3h w==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="370971048" X-IronPort-AV: E=Sophos;i="6.04,214,1695711600"; d="scan'208";a="370971048" 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 X-Rspamd-Queue-Id: EDBFDC002C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: r6xqgsidm4enk3cpso9oytfryp9ccfff X-HE-Tag: 1700490407-198704 X-HE-Meta: U2FsdGVkX1/xOK9Hz/KFxMUwpiugr/cR2kvRDrBGKXMCcUuEi6sGFtWH1/VX7hYUY2EbzsbB2Ats/PIKkRolmZrSGL54Zc/3AaxBALdTM98DtTj6/lGwfQjksMw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0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 *element) } else if (pool->free == mempool_free_pages) { /* Mempools backed by page allocator */ int order = (int)(long)pool->pool_data; - void *addr = kmap_atomic((struct page *)element); + void *addr = kmap_local_page((struct page *)element); __check_element(pool, addr, 1UL << (PAGE_SHIFT + order)); - kunmap_atomic(addr); + kunmap_local(addr); } } @@ -89,10 +89,10 @@ static void poison_element(mempool_t *pool, void *element) } else if (pool->alloc == mempool_alloc_pages) { /* Mempools backed by page allocator */ int order = (int)(long)pool->pool_data; - void *addr = kmap_atomic((struct page *)element); + void *addr = kmap_local_page((struct page *)element); __poison_element(addr, 1UL << (PAGE_SHIFT + order)); - kunmap_atomic(addr); + kunmap_local(addr); } } #else /* CONFIG_DEBUG_SLAB || CONFIG_SLUB_DEBUG_ON */