Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3164800rdh; Mon, 27 Nov 2023 07:46:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9+J/3ly710XZwI0HOX8fLamyLvvbmFWYoXSybYnxI69h4iC2Q8lOKMQIQdiz1xf8GxcUP X-Received: by 2002:a05:6a21:1a9:b0:18c:6c2:5369 with SMTP id le41-20020a056a2101a900b0018c06c25369mr11769615pzb.30.1701099986002; Mon, 27 Nov 2023 07:46:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701099985; cv=none; d=google.com; s=arc-20160816; b=nOFblcZ45bTXHq21FQcpI7VpzGQKge7qrL9d4cvkuz1zkmx1IAPQMNELVlFHHgwwQv O7G0teaR7s+Wm0ZSe+ezvhE7+shCdbHnsWm+y8+aJ+GsMYTX36Bz23P4pvo9zAfp45q2 O3UHQO55lvzep1rDLzzZUxgFSdNIMhfHHQR35UMoqtlAOPXl6N+BJnFRwXxzyI6eOzk9 rCKcknmo0d1iy/No7qIr6NaENeO4WeX+BAI1IjR3fkiORxHqRuzQI6Z+JU4hm2kec89A g6eD8KvhScaE75x2QmhA0rH1YaNvU/WJMQz4LQvgG4XDUyWV1sIdJfWJau0JSDYg3XzO ZN0A== 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=MNX6xUcIjUPKGafvzW/5P1W0B44Y68q7BIIbZI1dg5M=; fh=XH3pxpKr7AUB4GM0Y3GdAQEzWmNMu4SdIEH1hms+9D0=; b=mQHy40h8Ega2Pw8Wqj/lekqdpLLwEbqPgNLF1rUVW/L8rADheJyWli89R6OX3ll5G6 /etcZJimdbWeHPTqqCBQMdCJgbZ28zSIDDBe4NqwFWIgD8BvoxmKtp2SQqkLybKj51rN +OUJFwuzZHMYAmgbhurVQnXn4tRkElGWmvQ5ipztawNRYJBkxEZoiPRmX1B8iTHCb8+M VHqHQ8EBC2q14JnjFoPffwWSymMnqk0vo8/ji4qKUeMNnR6IarDGTK5ZqeigCQNt4GgF EBLECr43SVN2KNe5KVZ79q4d0VDWu9ZmLcXPzaWXrR3T4x/U0sQVyNCsw1Flt1W1VCVs Yjag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="GwyD/hFM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id bg3-20020a056a02010300b005bdf596188asi10247734pgb.667.2023.11.27.07.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 07:46:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="GwyD/hFM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id EB21D8068206; Mon, 27 Nov 2023 07:46:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233793AbjK0PqE (ORCPT + 99 others); Mon, 27 Nov 2023 10:46:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233565AbjK0PqD (ORCPT ); Mon, 27 Nov 2023 10:46:03 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DD3E194 for ; Mon, 27 Nov 2023 07:46:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701099969; x=1732635969; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=RjG/hMs9OyhxSl+EFc3Kn1xp7ecsjibFgqdSxnjn0+Q=; b=GwyD/hFMPqJGuhkUIvQqkjWw3tz/+u+xmgL3FOnxXUACfg3LspOPzYEu /4bfkBM+td39MuSjW7lfbZwQ7CIv+4odalaZWcLLh5Zle1ROCWEN1O3em 0922tazxhkfHl4GdbSt1m//JR+GXzrf8e2qkNHamP2hw5QdIb4kVtwJvC oKDvff7B8AdrAo/Fd844WdHfR1ejmSx/1ShYpaucBr7Xwd82dppqdSpAK 9jkBq5GrKNY8bYpabrjHOYKZVeLwHEY55erbMVOxQK6ezDFwcvnKVqQ3z qHnDb4KwwEZkHyjHEryQnCy8tBNJCUpMnKTUeAJi/Rc8O3aQxRaOq43u2 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="383114500" X-IronPort-AV: E=Sophos;i="6.04,231,1695711600"; d="scan'208";a="383114500" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 07:46:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="768202052" X-IronPort-AV: E=Sophos;i="6.04,231,1695711600"; d="scan'208";a="768202052" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.Hitronhub.home) ([10.213.15.40]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 07:46:06 -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 1006/1007] mm/swapfile: Replace kmap_atomic() with kmap_local_page() Date: Mon, 27 Nov 2023 16:45:53 +0100 Message-ID: <20231127154601.585849-1-fabio.maria.de.francesco@linux.intel.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 27 Nov 2023 07:46:22 -0800 (PST) kmap_atomic() has been deprecated in favor of kmap_local_page(). Therefore, replace kmap_atomic() with kmap_local_page() in swapfile.c. 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. In mm/swapfile.c, the blocks of code between the mappings and un-mappings do not depend on the above-mentioned side effects of kmap_aatomic(), so that the mere replacements of the old API with the new one is all that is required (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/swapfile.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 4bc70f459164..8be70912e298 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1495,9 +1495,9 @@ int swp_swapcount(swp_entry_t entry) do { page = list_next_entry(page, lru); - map = kmap_atomic(page); + map = kmap_local_page(page); tmp_count = map[offset]; - kunmap_atomic(map); + kunmap_local(map); count += (tmp_count & ~COUNT_CONTINUED) * n; n *= (SWAP_CONT_MAX + 1); @@ -3477,9 +3477,9 @@ int add_swap_count_continuation(swp_entry_t entry, gfp_t gfp_mask) if (!(count & COUNT_CONTINUED)) goto out_unlock_cont; - map = kmap_atomic(list_page) + offset; + map = kmap_local_page(list_page) + offset; count = *map; - kunmap_atomic(map); + kunmap_local(map); /* * If this continuation count now has some space in it, @@ -3529,7 +3529,7 @@ static bool swap_count_continued(struct swap_info_struct *si, spin_lock(&si->cont_lock); offset &= ~PAGE_MASK; page = list_next_entry(head, lru); - map = kmap_atomic(page) + offset; + map = kmap_local_page(page) + offset; if (count == SWAP_MAP_MAX) /* initial increment from swap_map */ goto init_map; /* jump over SWAP_CONT_MAX checks */ @@ -3539,27 +3539,27 @@ static bool swap_count_continued(struct swap_info_struct *si, * Think of how you add 1 to 999 */ while (*map == (SWAP_CONT_MAX | COUNT_CONTINUED)) { - kunmap_atomic(map); + kunmap_local(map); page = list_next_entry(page, lru); BUG_ON(page == head); - map = kmap_atomic(page) + offset; + map = kmap_local_page(page) + offset; } if (*map == SWAP_CONT_MAX) { - kunmap_atomic(map); + kunmap_local(map); page = list_next_entry(page, lru); if (page == head) { ret = false; /* add count continuation */ goto out; } - map = kmap_atomic(page) + offset; + map = kmap_local_page(page) + offset; init_map: *map = 0; /* we didn't zero the page */ } *map += 1; - kunmap_atomic(map); + kunmap_local(map); while ((page = list_prev_entry(page, lru)) != head) { - map = kmap_atomic(page) + offset; + map = kmap_local_page(page) + offset; *map = COUNT_CONTINUED; - kunmap_atomic(map); + kunmap_local(map); } ret = true; /* incremented */ @@ -3569,21 +3569,21 @@ init_map: *map = 0; /* we didn't zero the page */ */ BUG_ON(count != COUNT_CONTINUED); while (*map == COUNT_CONTINUED) { - kunmap_atomic(map); + kunmap_local(map); page = list_next_entry(page, lru); BUG_ON(page == head); - map = kmap_atomic(page) + offset; + map = kmap_local_page(page) + offset; } BUG_ON(*map == 0); *map -= 1; if (*map == 0) count = 0; - kunmap_atomic(map); + kunmap_local(map); while ((page = list_prev_entry(page, lru)) != head) { - map = kmap_atomic(page) + offset; + map = kmap_local_page(page) + offset; *map = SWAP_CONT_MAX | count; count = COUNT_CONTINUED; - kunmap_atomic(map); + kunmap_local(map); } ret = count == COUNT_CONTINUED; } -- 2.42.0