Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5831868rdb; Thu, 14 Dec 2023 00:11:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTS5WgAMUScaH87tOvFcY1ypYB5dsGbQBiYRn2qwpym53ua4JI44At+mupkrR0qz/xrBhD X-Received: by 2002:a05:6358:3419:b0:170:d757:f369 with SMTP id h25-20020a056358341900b00170d757f369mr8008466rwd.38.1702541497271; Thu, 14 Dec 2023 00:11:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702541497; cv=none; d=google.com; s=arc-20160816; b=k/B7h6XXh403+Ke3iRiLwZ3ABgCc82aiBg6OOPpAcO1EaFqpXIA4yofW5603qiidH6 x0pYPnXyoHMF16r9+XYExQb/UF9xlm24VUfxUpdXbw5F67ENBLf3EiBNp48swce19iGU yQnfvZRKAY9jFNDWKDuc7o4ZvmA9mqHVMOuOk8Xgq4/m8/qijA9w2zAZ2NLe/x8jCi0F BRYxxtTCYhez4aUd3aegLUOG/zixgPVw2qYiTZQernCCGFNKTUjYhnnHtWBg+kn4q5S4 ztXRw2W+4f3YBfxOgyWiibFnF73gOh6pLlGYkV0I7WfQiu+2vurlS2KpcGjkWPkM8gMq Rm6A== 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=CNTI+KMQLvhKnjeNbo+J/agOUmrbDWV8WlyDwZcJPxQ=; fh=qDXlVLl7br5m5Sn+oYnwTx/CBlJrf1pIUlN2uc2ZUlU=; b=ZR6x2GlCY2nbciLjoRPyb/P+03ewBeaM/974oQgei8ptxkYj9gK/ht3hHBTGHAOw0k JbpXo1JVe76xla5/6w7xRTwf+HZPP4zFXcpzmMBVASLtOaFXSheDGjh2TDNCGd+AJQ1x 4R+cZUFlOdX/KgzZyXiVXm+VeGYVxYwcEDk26Vqka35xhbOZrH9Rl84pyo0Xg2f+71VJ jJ4AblMLIOmRCFN61lB1f2zH3ZXiwSokdZHcWfxQExdyu42NEQhLxhTGXjja6rzXF8XP dMQsJ3ZU25t2dT1JDgTid2fJhP14wHtu/IijjE8UKgL6Lyt5t/ezmPSVEO5PBj33zRua MyBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ifgF2mMQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id mh7-20020a17090b4ac700b00286e8838b6fsi12444852pjb.119.2023.12.14.00.11.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 00:11:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ifgF2mMQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 A039780A8525; Thu, 14 Dec 2023 00:11:21 -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 S1443415AbjLNIK5 (ORCPT + 99 others); Thu, 14 Dec 2023 03:10:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234409AbjLNIKv (ORCPT ); Thu, 14 Dec 2023 03:10:51 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF796B9 for ; Thu, 14 Dec 2023 00:10:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702541448; x=1734077448; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=i8XSla6hrQt6zIq4G6Aba+318oa4y1bEQ+Pf+qR2Hcw=; b=ifgF2mMQjm0yl9A2LX2LdpNODtvgS7BZvj7pTxpgP/makPRUeLqwTLkb +PY6uBjZbAhUb2Q441jfPard2lkTLO7HcuzX/u4YZRCBipLadjlqmnZlI QjUCJ07gO1w2aiOMjHzkz4UD0GAF+QaiOSG19dWVUPnzjaIciVNyGv1Ss +jIzFYAimFjidPw5M7DYB8BZojWYVbjgaTDRHpJyv9SsTXph00ygRv+E8 KKj+iDh+ubD7WjTV0Zh/Gt4lhuDJWvCnk05g+3fO88a1RDrwdOJ/IyFC9 TCG94d7uacgaDlsIspaAm66+qPXGzIhl4jP+Ga4PLwZe7mRUP39bo5MYP Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="1903236" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="1903236" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 00:10:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="803191192" X-IronPort-AV: E=Sophos;i="6.04,274,1695711600"; d="scan'208";a="803191192" Received: from mrejmak-mobl.ger.corp.intel.com (HELO fdefranc-mobl3.Hitronhub.home) ([10.213.24.154]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 00:10:45 -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/memory: Replace kmap() with kmap_local_page() Date: Thu, 14 Dec 2023 09:10:04 +0100 Message-ID: <20231214081039.1919328-1-fabio.maria.de.francesco@linux.intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 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]); Thu, 14 Dec 2023 00:11:21 -0800 (PST) From: "Fabio M. De Francesco" kmap() has been deprecated in favor of kmap_local_page(). Therefore, replace kmap() with kmap_local_page() in mm/memory.c. There are two main problems with kmap(): (1) It comes with an overhead as the mapping space is restricted and protected by a global lock for synchronization and (2) it also requires global TLB invalidation when the kmap’s pool wraps and it might block when the mapping space is fully utilized until a slot becomes available. With kmap_local_page() the mappings are per thread, CPU local, can take page-faults, and can be called from any context (including interrupts). It is faster than kmap() in kernels with HIGHMEM enabled. The tasks can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and still valid. Obviously, thread locality implies that the kernel virtual addresses returned by kmap_local_page() are only valid in the context of the callers (i.e., they cannot be handed to other threads). The use of kmap_local_page() in mm/memory.c does not break the above-mentioned assumption, so it is allowed and preferred. Cc: Ira Weiny Signed-off-by: Fabio M. De Francesco --- mm/memory.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 7d9f6b685032..88377a107fbe 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5852,7 +5852,7 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr, if (bytes > PAGE_SIZE-offset) bytes = PAGE_SIZE-offset; - maddr = kmap(page); + maddr = kmap_local_page(page); if (write) { copy_to_user_page(vma, page, addr, maddr + offset, buf, bytes); @@ -5861,8 +5861,7 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr, copy_from_user_page(vma, page, addr, buf, maddr + offset, bytes); } - kunmap(page); - put_page(page); + unmap_and_put_page(page, maddr); } len -= bytes; buf += bytes; -- 2.43.0