Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3532853rwi; Wed, 12 Oct 2022 03:31:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5jBEDRNB9JKse1c05bX9A4nYprbhqqiZ9G3UNLN8ypnAmhHhjxj9Y6e4KKJjGzvnaXEkHL X-Received: by 2002:a17:90b:1d0d:b0:20d:5c1c:5fbb with SMTP id on13-20020a17090b1d0d00b0020d5c1c5fbbmr4378458pjb.196.1665570682174; Wed, 12 Oct 2022 03:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665570682; cv=none; d=google.com; s=arc-20160816; b=qLZ1Geti7Jx6VTlNbJUtMlBeef95mxUeP35LRkd3fljlzk8gUaomrJDIdXbf1+T/bK vV7fpxxeNX40gTPq9ZSv3O1JyjvdOMjjB5AIck+hpeGQmLeBV+CFbTUef6+AhfS6k4+I 1Bi+IOHPxllXPGaYawOw3A7blJhE2NTfrLGVilFlsHDX+opOBFT5O81oI11etbKIdVGQ WI697tIL1cZIC3fdurmi2yhNEHQv8uObb7uKCL91sIHsh04BhB8OFQakq3bZkJ15GjcM 9PUyReG2dd2nFYWY7cqWlyyN8bFadKbMaQH5Lje40N2NHC+8oEE4Nmw0xYNnwQzj2kGk Jgyw== 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=2kW5MauxS98pwWXxx4M/kTdbKrwsWsdXlDypkIhrENA=; b=f+uOOnq8PGH26wrdeBJtusn8SBLvx/O2B5RMwdhOGXx6aYbB9CwRI7rZw0PGdUcAdq ynMh+ds3Up5GUjqZX4We8Mcsp2NNdb3E4biCCupHsyylSoqAlvT88K8ZDqxE5OK1F2tE XCG+ezW6nciD4ybGvbZBtRGXBRFRqBdJXtli7x1Gz1xluvK4d0bEIFz28bLSU+OjNp+y vVMZrjfPoZf8VGxashIPRWB72ye6Hb1VgiB9B6W9xdzVTvn/6hkdc7frBnhZ9ZrrN+h2 yXqzePFoHnpceSOgIox1pzS92VeZrrU0q3fPqr1LDu7lnWLN25JWMQ3jSemsSkWedai8 kVqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HC3zbbp+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b13-20020a6541cd000000b00463fc72dae9si6070385pgq.144.2022.10.12.03.31.11; Wed, 12 Oct 2022 03:31:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HC3zbbp+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbiJLJOI (ORCPT + 99 others); Wed, 12 Oct 2022 05:14:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229907AbiJLJN7 (ORCPT ); Wed, 12 Oct 2022 05:13:59 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88370BC46D; Wed, 12 Oct 2022 02:13:53 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id a13so23641413edj.0; Wed, 12 Oct 2022 02:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2kW5MauxS98pwWXxx4M/kTdbKrwsWsdXlDypkIhrENA=; b=HC3zbbp+P9LikbMl5NHcR5Xlp2Jr32+oOCPK5NKcvSaEv+Hc8CB6hJ2v3zbeXI9HoE 8hBRhgAHifaM9NDHaglA+LqT8c+gm24cFgKF6iyb6LHqlspso3/U1TyhZF1G4GtX4o71 lbY/wC2Ko+RQa9krVsVe3qjv6eLyrstVkH/v1HXGIyqCQhmqXQvVy0qQA1GkjCzS/DfG WMP3ahZIxZqSGbgz5Iu6dAcWScOkT+mfYpLN78AcRfuvKFyp1WwaFCuhZnrRq1zUHmJN gddhem/P1u29YWHQaC+Cu1qDl8cYReIRaPET2HFgKQw+gHJYSM3pPlhamJTTT14PKh/l Y6Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2kW5MauxS98pwWXxx4M/kTdbKrwsWsdXlDypkIhrENA=; b=oRqw+Wv9iOjSQvk2HFn1hk05Lrf/Hg9PWnFobLfz50P0yDkdS770QoU2xnbBLniZLv O1VYq/c9bXFzBuziwdSU8WrMUupmTMFouxvDyIjwmwx5O9pesZrb/EpMTyzQEluEnOr6 GSbipmJQRC8VaMdu5s4F1QXIj7T/d10wU1ZhUj0TQmFdvxy52WBaSnAp0XZet4v0C3QI X8XhSsyjofpsBeDSts04Nty7anEOyQtMl/R2dvxGMbjD2FaKFw+en9jRtjqHYAIKtobT pKs2yVX1dqXiSRTFkOy18L9wpd6gDmkQoqIjIEa5EbuvTm5xaamVXjmwXEWwIUUyFh7F arxw== X-Gm-Message-State: ACrzQf2mfa4agCGOo18h/uEgLYLBBYXy7YbtkmzrjXYjGNycamQFV97S 8Tp1OoRIZfbEBzVTycjANVQ= X-Received: by 2002:a05:6402:1bc6:b0:45c:7611:d86e with SMTP id ch6-20020a0564021bc600b0045c7611d86emr7030281edb.194.1665566031975; Wed, 12 Oct 2022 02:13:51 -0700 (PDT) Received: from localhost.localdomain (host-87-17-81-193.retail.telecomitalia.it. [87.17.81.193]) by smtp.gmail.com with ESMTPSA id lt2-20020a170906fa8200b00779cde476e4sm929649ejb.62.2022.10.12.02.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 02:13:51 -0700 (PDT) From: "Fabio M. De Francesco" To: Nicolas Pitre , Christian Brauner , linux-kernel@vger.kernel.org, bpf@vger.kernel.org Cc: "Fabio M. De Francesco" , "Venkataramanan, Anirudh" , Ira Weiny Subject: [PATCH] fs/cramfs: Convert kmap() to kmap_local_data() Date: Wed, 12 Oct 2022 11:13:56 +0200 Message-Id: <20221012091356.16632-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 The use of kmap() is being deprecated in favor of kmap_local_page(). 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. Furthermore, the tasks can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and still valid. Since its use in fs/cramfs is safe everywhere, it should be preferred. Therefore, replace kmap() with kmap_local_page() in fs/cramfs. Instead of open-coding kmap_local_page() + memcpy(), use memcpy_from_page(). Cc: "Venkataramanan, Anirudh" Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- fs/cramfs/inode.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c index 61ccf7722fc3..c17cbba5d45e 100644 --- a/fs/cramfs/inode.c +++ b/fs/cramfs/inode.c @@ -238,8 +238,7 @@ static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset, struct page *page = pages[i]; if (page) { - memcpy(data, kmap(page), PAGE_SIZE); - kunmap(page); + memcpy_from_page(data, page, 0, PAGE_SIZE); put_page(page); } else memset(data, 0, PAGE_SIZE); @@ -815,7 +814,7 @@ static int cramfs_read_folio(struct file *file, struct folio *folio) maxblock = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT; bytes_filled = 0; - pgdata = kmap(page); + pgdata = kmap_local_page(page); if (page->index < maxblock) { struct super_block *sb = inode->i_sb; @@ -903,13 +902,13 @@ static int cramfs_read_folio(struct file *file, struct folio *folio) memset(pgdata + bytes_filled, 0, PAGE_SIZE - bytes_filled); flush_dcache_page(page); - kunmap(page); + kunmap_local(pgdata); SetPageUptodate(page); unlock_page(page); return 0; err: - kunmap(page); + kunmap_local(pgdata); ClearPageUptodate(page); SetPageError(page); unlock_page(page); -- 2.37.3