From patchwork Mon Nov 20 14:28:23 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: 167178 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2239237vqn; Mon, 20 Nov 2023 06:28:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/DkLlXIb1xvycR6MgaM4KtuCJOkEL9kEmsuO8+/+mvY0B0hWqNmfYrfQ/pV0xooI35YWc X-Received: by 2002:a05:6808:11c2:b0:3b0:daf8:954 with SMTP id p2-20020a05680811c200b003b0daf80954mr10603710oiv.49.1700490539229; Mon, 20 Nov 2023 06:28:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700490539; cv=none; d=google.com; s=arc-20160816; b=b4gK9ruZnwKzLah9tD8fdyP1ACsMCk2CKRJ9R5VLUkGoNcpDghAYFaF9Q+qYtyt4DN wz9ES+Ya5GT6X3B0Q/Y5EFPZxDJJp+yg0y4mZalCfiC/m5Hbe/EnykhDjbOnL5Z3MiBF SqOI4qZ4kuygRSu4Y9L5AaGzODuuZTsEP9SqvzMfRw8XpQrRN3lY9Mz3TfrHCHzywDsS wAuq0sJFNF6WoDeSu0mD7M6YrMySMabE2Aj8spEzwe7HIOByeCWqxTvPbIkHldNiu8HU PpMSfDrui/BZ3k9L4X3+avbdYGJ6B8MWcCYbhnHcC7U0OdErKteCMdxHq2xFjad5yjen P6Gg== 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=g8SfughDL+yX2k7623D64oHQ3Oew/7Ftmso+UKuqnjA=; fh=XH3pxpKr7AUB4GM0Y3GdAQEzWmNMu4SdIEH1hms+9D0=; b=JJKThTLBMnVs10BaGZh4GpFef6sRw8IhP52U4cNsAaR1bOPxJXAV8InhxneZkEAVR2 Uvb1b+6DFRkzylJ1X6x0AyA1EF1mQ/QK9O6aQaWD0OmwvK31Pk4xT+B8wva6mhrgukHH liiuezfhgkNx+M4R+8cAu6XuY176lZXzfk4rsy3x0QkF3+Xtd8dgx01lmS/MOVr4wKZq xHA4w06k4c+SeLddt8G/BOA5AYpBltNwv96UDBG5z60bNPALUebD7bI9DnRchQxMqEay U5MEaV8J+ktMdHU7vqIw7vjjbXqmvPE0dQrcEPQ1s2bpxuufczQXHsKUgF/aLYDhsq4E eWJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NpEmC0Bp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b4-20020a655cc4000000b005c2122eb968si6844985pgt.140.2023.11.20.06.28.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 06:28:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NpEmC0Bp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 0EC0F806666F; Mon, 20 Nov 2023 06:28:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233528AbjKTO2s (ORCPT + 27 others); Mon, 20 Nov 2023 09:28:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233487AbjKTO2r (ORCPT ); Mon, 20 Nov 2023 09:28:47 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C95EAA0 for ; Mon, 20 Nov 2023 06:28:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700490523; x=1732026523; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=wXfYH9PEJHi5SE6jMxUu9uOPBnqBdEjEY0c0DJLAYZY=; b=NpEmC0BpHwAGvVNTwP2NVDIotU9nTHdQUxMUZ+QEaV73LOVL8OYomuHS DTJXKiaMR12Rk9JjevjZYtQo+eqtjObHGpnThnIh5HAA6AOiw8Om7KVo3 3cFhe2fbxLTO3L0/lM35ZmmEjLydY052gkNfPo7i2JtkQSKMpkPKtjkw8 AOO+KFQSwxTiC99pEeSg9C5Ygyyoh3nkBS3HMjgT3YKtUu3yfY+dtvEnx ncm5VXE9xGU1ORi1qNZxHDSPiXMGRKRHRPwEOqGctC6EuT3KssCwASEmf oFocns88ZPxJvnN5dHpUejInjXso7fRwkIsxoBzKP9MStsbnhOd0CI7Q2 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="390485710" X-IronPort-AV: E=Sophos;i="6.04,214,1695711600"; d="scan'208";a="390485710" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 06:28:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="1097758447" X-IronPort-AV: E=Sophos;i="6.04,214,1695711600"; d="scan'208";a="1097758447" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.Hitronhub.home) ([10.213.12.244]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 06:28:41 -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/page_poison: Replace kmap_atomic() with kmap_local_page() Date: Mon, 20 Nov 2023 15:28:23 +0100 Message-ID: <20231120142836.7219-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=-1.8 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 06:28:58 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783093567805072788 X-GMAIL-MSGID: 1783093567805072788 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 do not 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/page_poison.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/page_poison.c b/mm/page_poison.c index b4f456437b7e..3e9037363cf9 100644 --- a/mm/page_poison.c +++ b/mm/page_poison.c @@ -21,13 +21,13 @@ early_param("page_poison", early_page_poison_param); static void poison_page(struct page *page) { - void *addr = kmap_atomic(page); + void *addr = kmap_local_page(page); /* KASAN still think the page is in-use, so skip it. */ kasan_disable_current(); memset(kasan_reset_tag(addr), PAGE_POISON, PAGE_SIZE); kasan_enable_current(); - kunmap_atomic(addr); + kunmap_local(addr); } void __kernel_poison_pages(struct page *page, int n) @@ -77,7 +77,7 @@ static void unpoison_page(struct page *page) { void *addr; - addr = kmap_atomic(page); + addr = kmap_local_page(page); kasan_disable_current(); /* * Page poisoning when enabled poisons each and every page @@ -86,7 +86,7 @@ static void unpoison_page(struct page *page) */ check_poison_mem(page, kasan_reset_tag(addr), PAGE_SIZE); kasan_enable_current(); - kunmap_atomic(addr); + kunmap_local(addr); } void __kernel_unpoison_pages(struct page *page, int n)