From patchwork Mon Nov 20 14:18:44 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: 13461409 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 9FB2CC2BB3F for ; Mon, 20 Nov 2023 14:19:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B5006B044A; Mon, 20 Nov 2023 09:19:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 33C206B0451; Mon, 20 Nov 2023 09:19:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DDB16B0453; Mon, 20 Nov 2023 09:19:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 07C7F6B044A for ; Mon, 20 Nov 2023 09:19:06 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DB8FCA023E for ; Mon, 20 Nov 2023 14:19:05 +0000 (UTC) X-FDA: 81478539450.08.9504FFA Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf07.hostedemail.com (Postfix) with ESMTP id 0F54E4001A for ; Mon, 20 Nov 2023 14:19:03 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; spf=softfail (imf07.hostedemail.com: 134.134.136.100 is neither permitted nor denied by domain of fmdefrancesco@gmail.com) smtp.mailfrom=fmdefrancesco@gmail.com; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700489944; 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; bh=NLQEP6kXTo6ts2tnk0a++rjXWR+UaxTnOS6ZAUn3QUE=; b=5D5+kjGW1pcd+FViyMKWZ3eNfoPDdNFgzopD1Dz1O2a3MvqzN5d5mUf45lHQiTtUrpxns/ scsQzGQ5zxDF3Ksfasq68wWyo3woyZaejl13g9NfmoezvTt+2FwXMRy1F+u7N5ihf78IPf ELQt4uj0EV9r4CjKAm6xw7vmWfM4yao= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=softfail (imf07.hostedemail.com: 134.134.136.100 is neither permitted nor denied by domain of fmdefrancesco@gmail.com) smtp.mailfrom=fmdefrancesco@gmail.com; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700489944; a=rsa-sha256; cv=none; b=WTELQZO/2I3o5oqW1jxejK7/AaPfKXJ8Eo9EUQOohETncxWKkPwwM/Wunp6S6kAt1vvcDX dNbESJDOs9jzQISGEqZn0pEhz/jDgW8YHz7GyqUbfHdNDJMi+Wze/t2kWVAWgeulqXj2fw 4oxXgLsIv3wBK/nIbKDlF++uZfFlKcE= X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="458123494" X-IronPort-AV: E=Sophos;i="6.04,214,1695711600"; d="scan'208";a="458123494" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 06:19:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="759795920" X-IronPort-AV: E=Sophos;i="6.04,214,1695711600"; d="scan'208";a="759795920" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.Hitronhub.home) ([10.213.12.244]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 06:19:00 -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 , "Fabio M . De Francesco" Subject: [PATCH] mm/ksm: Use kmap_local_page() in calc_checksum() Date: Mon, 20 Nov 2023 15:18:44 +0100 Message-ID: <20231120141855.6761-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 0F54E4001A X-Rspam-User: X-Stat-Signature: tuoqximysre1ogwg4u887yyx444w9xzx X-Rspamd-Server: rspam01 X-HE-Tag: 1700489943-9094 X-HE-Meta: U2FsdGVkX1/Cyq59Yc9WQsV4ghNWCuBz8ecpmraz1pF9iiSpVr3HsXkPRzujqgcSNf+pmbgjPFm9NsUrW8ma6P5hfCPb7nNM4Hgu5qHExVrwXWAMHjtyq++tVqkifVYSGR2e0i8afGbFOJLgVqpbPojCJnjAhl2UbBjDKrwTvg2UGSwzkThyKw1NI0oNPRfKiEwghevM07IJBEld8Bw9U5KCFSkMvWi1C8evrg5IeMyiBJ8WwlAVjVjqZwSeyK50hmrl5sXQ6Dg2jrpqyMl/J9u6Cl/IIt/eLIZtSSAGXfmLgZappN0M8mwm/YSlaJXdFhQgP/9t2lhSNMXnwuoQr3CxWdTTtdxg8NH7Dmq2IlCri+6oTXs7W6XLVgABf71QbvsObOsqaGjKx5VCXW01sO2B4fGAzBnMAZdCERoNyXFqye4n8gEO4s+HDPxpO/1YDFYWriLhtvnerWVTBPPSxAcftFHbAYVjE3p0LO+RDlFwV3BrXV4IMiehCy7LzWzrp82mfQccZKkoIzI4s5O25b3GPLOv/NudUQUqe5Cffn8tpK0ANr4cL42LoGZ+U7IKXDXtOZvWLsPrl0rshQ9GNXpSFFlgt2G24z/Ck8Gp0WwSxG0Bp6fKYtv3kRC4JO5OLeByErLqWocXna5Yv0ZTgwKK5qlWFx36Iu96aZa/K70Q3yyszTixrJInJZvp4XyYA2U+Tf8XDxPSVpt7Qnaofa/g0buEibpbSQ4UjBS0QOTY2dDfqL0ZgzCTXf63HX1boVGrI6Ii/7k41AhPjyMjhF4xvXEHE5iMSxn31knZ/ZBeFdtANp34vSTKy9WrfY5hrtSVhxzy9YZxWoA0fJuDtixNj7SaLRY6fqTRhKqwqmWAMxETkL6yNuB8JGjdQeYYwH8eNzErxUo0PeXsK0UnUwrxLsTAzx0EZ9RbRlLlRVTPWr9c8Omdis0IBLalPaJOuqcIURs2bXtd26F44lT jniFFKF5 jORhneP/JXw0CPVEll9VjrmvoBTlZAlm6JV6eVXqVNn/v72ft/DNxPK/o3IJhOT7lHbeJo2FwckE0HRfLUg4pixz3YLNDpOsj1ZyG2agDa0FIee27L4f8/SVvIrz8jdXz+4pMa65+RGwQVdy/nCqWC3at0KvDEDsU8wfPE/JeAS+71GZUzPxr7hMlGI9fYTd6TynBxAPAXXoZ10JiZcrgjOZkErU/oh0lsO0VVRgHh4pv79ncJuBCU3ttBUfjNBFqRVQOTVv3RcRToEjw0BG+1ygiYpCifxPzf9DwoVvZ7/0rF9FhvfHu/7IDfBkvjHxs1d0h X-Bogosity: Ham, tests=bogofilter, spamicity=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: From: "Fabio M. De Francesco" kmap_atomic() has been deprecated in favor of kmap_local_page(). Therefore, replace kmap_atomic() with kmap_local_page() in calc_checksum(). 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 calc_checksum(), the block of code between the mapping and un-mapping does not depend on the above-mentioned side effects of kmap_aatomic(), so that a 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/ksm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 6a831009b4cb..5d60d5385de6 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1099,9 +1099,9 @@ static int unmerge_and_remove_all_rmap_items(void) static u32 calc_checksum(struct page *page) { u32 checksum; - void *addr = kmap_atomic(page); + void *addr = kmap_local_page(page); checksum = xxhash(addr, PAGE_SIZE, 0); - kunmap_atomic(addr); + kunmap_local(addr); return checksum; }