From patchwork Mon Nov 27 15:54:37 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: 170256 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3235373vqx; Mon, 27 Nov 2023 07:55:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFS9syLpZyVfuKoZ7+XarxvC30e1Vu8DI1R/hQEblSWiFp9pcJEM03lBuUzUv62advCFpVO X-Received: by 2002:a05:6a20:3d14:b0:18a:b5c3:55da with SMTP id y20-20020a056a203d1400b0018ab5c355damr15630130pzi.10.1701100509069; Mon, 27 Nov 2023 07:55:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701100509; cv=none; d=google.com; s=arc-20160816; b=OIzDs4dJ1+OdY3s+tCUqSoxtfPcf8pDZjgA+fG4RDSVx70WHwoKcqJzdXp0JiL2hSa F3jZ6yH6/w/DV6FFWUxpLXhOEDQjtnKyq7ChX7C81oPcxq0WO4lY5iseppY28UmyviTZ uZAJaZDpCKqwt3S4DcORzK/glSK9Q95edoGqgnBvY7zvoNWv5vVfmXlE8NkMA1sYWYnH rlA+p9fg6KI+CXFRP07h194uSNYEp6YWema6v55Ti/wiIiAe6qj3Jls3NjSiwmrwMBls X1Tp93XXv0lHmnmvkXaf04L/gdwv6reP8NYeyCk5XeZ6v+7nhuTo8gyTu/kMizbhmTkS /8fw== 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=9BKvUrFOHUP8AxotLNt/EygHkRFXdS8iVwc2Dr9kSB8=; fh=XH3pxpKr7AUB4GM0Y3GdAQEzWmNMu4SdIEH1hms+9D0=; b=y15ZKvgcrgcMlMjOoCYMoEGyMHGR0WCmkrtGIKxaPv55LKUX1kB5YRY9aeXYDLtNQc IbZ++7jMSmF7IU59Cb5gO6U/jt8FT8uD10epoHGuy4u8ApiAY2ylWjsjPK/AtstMMolt PNYhsFiIVLstUVyLW3Seuq4LlpdxHn3gFeksD+g0HR+xKyRX1KGL13ZoYXkh69rQdw5p kNxSUrS8FZUE4XnXVCAMxD2gK7LQxxf/ruIax+Hq4gNE0Ac7WoRe1WSjBiP1Cr+LkFwx errTTtOCEQAIIsdqyoC943TSGljHRHR4lW03PLzWnqxQ1wHMUBQSgtG3cZmqOsAbSiEV NesA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="PT/TYdHN"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id c1-20020a63da01000000b00578db6172fdsi10183198pgh.325.2023.11.27.07.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 07:55:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="PT/TYdHN"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 573708136BC8; Mon, 27 Nov 2023 07:55:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234111AbjK0Pyz (ORCPT + 99 others); Mon, 27 Nov 2023 10:54:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234079AbjK0Pyy (ORCPT ); Mon, 27 Nov 2023 10:54:54 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F160E8E for ; Mon, 27 Nov 2023 07:55:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701100501; x=1732636501; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Jbqrcaws7niX0yRLQXZmoxSJqKNkjetK5HxGGMrB6Bk=; b=PT/TYdHNLSLuxC8p5GHswFYItX2c71bm/DXhe0ybgA+YhwLJ7TcsHWyv obB7z9PwiKBzOfmvNhPTtqLTIXr/Nm/AMMVsz+ph2pLel00OanXCZ9R4F rqzIic/xUqcLpffSgtQL7R2Ue84luIZ6RNSSI3c5aM3g00sD33TjrQTbw fS+YHu3zuDW3J6dRJHbgB3eOIu1LXG164irs5CoJF3DIfu9F6nYx5sWEf q/CV/NhH/9XzIXL3sddzxm3rzoVeK5xZ9TzvxcX5W6tghtYu+uQev3s7r +GRx+lIGNrdHWONKPOuScnd8DcfK/Cj2UkHOXzCG7bGYtwfyn63ycZC/R w==; X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="5922059" X-IronPort-AV: E=Sophos;i="6.04,231,1695711600"; d="scan'208";a="5922059" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 07:55:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="802688045" X-IronPort-AV: E=Sophos;i="6.04,231,1695711600"; d="scan'208";a="802688045" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.Hitronhub.home) ([10.213.15.40]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 07:54:57 -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/swapfile: Replace kmap_atomic() with kmap_local_page() Date: Mon, 27 Nov 2023 16:54:37 +0100 Message-ID: <20231127155452.586387-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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 27 Nov 2023 07:55:04 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783732613862243915 X-GMAIL-MSGID: 1783733167273861828 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_atomic(), 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; }