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: 167177 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2238379vqn; Mon, 20 Nov 2023 06:27:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4y8kNXJ3XWWdUB+9Hhk7Edd0JJ/29SObRwSQoVtQd5zpUKVznxb9IAKQmSJ2/pgyiEwVo X-Received: by 2002:a05:6a20:3281:b0:181:ed8b:4823 with SMTP id g1-20020a056a20328100b00181ed8b4823mr4552805pzd.43.1700490460927; Mon, 20 Nov 2023 06:27:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700490460; cv=none; d=google.com; s=arc-20160816; b=C8Ot2k3fz/47JZ1nMf2lmVjetE7cEwHUOMTPA7Z+MDgR9RuYxh9Hq7U9Tfh8YJJBc/ mF9mBOq8xkbaHZvphM3QWQ8sRZsbFu47v4fnFa7KT0hdfiUZOM3u45qbXrTvZNrKZFk/ LANJqUA+MSDS2o6JBPP/Fmh92H7M2fWOaqy8ew8iTwGTFKpyQg/GoDFKD09xuspBZbLn 2NNlj32gwpQHtZ371i1mh4N5hy+tR1WGkgYn2w7deApWIK0t0rNscprQAZhzG4rvRsjY 12AyTTxZo0HDWLy/SlFRNGkLD7WYNSCJr5I1+lAjTY2utKWwHdftGiBXcNLATZfdtCoq 8tIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=UrNUiDQhPRVXPRaqGASTaNUFFHGOEChD1f0OLJ2XEyU=; fh=XH3pxpKr7AUB4GM0Y3GdAQEzWmNMu4SdIEH1hms+9D0=; b=DyOwUrF4WTKqm7QgyjnETu0Y+QEHZrLIAwBoZGdowPvSXD8LdEFsSzPQlgqBmrwfde U2pIAtzpwMfz/197ET8TU83B3izGeE12fBiRA4FzD3tt49S2zr6eZTNGDbakDG0rbYXt THi9wbNLmqzvETSSYY++V+iXTiHdsz8VWdXjhFJpl+yNV7ps3LKpU8yGqEdnYxoimduY laaW8115N9xLKTHVM4EUEHdjovv524PTshImitDFdwpCEhf2WRiURJufoPGgNpX/dJ1G BiFv7kYfM4PSbor/OdocyGmcGRGnjNmbPHzCRoPZfnjW6gUueLRls98YfLasdlN5FwW3 cELA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=N5tPuzk6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id p15-20020a056a000a0f00b00690bd178205si8353628pfh.215.2023.11.20.06.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 06:27:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=N5tPuzk6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0EC3C80A8535; Mon, 20 Nov 2023 06:27:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233209AbjKTO0x (ORCPT + 27 others); Mon, 20 Nov 2023 09:26:53 -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 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 20 Nov 2023 06:27:15 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783093485437156522 X-GMAIL-MSGID: 1783093485437156522 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 */