Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp23833137rwd; Sat, 1 Jul 2023 08:01:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6AY3ZZmcL9+u68zdqBqrslraRFKucFxoz8aD3rC/dERh25bfErDhmcbpiqsnps24KlCpDY X-Received: by 2002:a05:6a20:1018:b0:123:2c2a:ee62 with SMTP id gs24-20020a056a20101800b001232c2aee62mr5877167pzc.14.1688223710701; Sat, 01 Jul 2023 08:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688223710; cv=none; d=google.com; s=arc-20160816; b=cITXhIijvlWsMP7rjEQzaT7lH1jPwaexYUFXT4zzY4NOxwRSFHMFNnKEkUAjOdpfAd qzFKYH8oP5TxeOmljO1peQAg9hI491V1Us4uhguTxDUFQcFuhYnz6NrXMdTdAsXejSI7 UAIo99wuV2WAWzminyT1h3QEhhZCsHLqN0fjWQOw94AE215n/acmbmGo5JYKCaWQOr+O d3u2budHo0WxkOhuPvcTYNsJzAn/5D3imFSUVegWgYYDGShZq9T0J7Cc5mdLl/uvyyUX pOLp2iKPMV5148ZdEmxMwrg0tVuW68rPoLOkyFuNgdsxgZ3HLvAgE2Yz7MwQCUpgxRzO pMDg== 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=4xzwfPjRQFT6QKTWY2W7B8J20zCNe8ZcBZy6OXaEZiE=; fh=/mWQIBZP4D1eJ6+cy83OycKk/gh+bsvkgcCq5V5nZSg=; b=QRVteZgH66N84ghxmfSP9wQDeOqvtGUvYYr6hkH6Njwh2YD77MSRU6dWDIcwDv4H9O 9jCjRxImWahG7r05JkqUOnF7+NWhREKObc56SOQNj/l4V1OHMAPVNZp4hvrTiLHwg4uw KkVBOFIw+p2AW9kw50oINoESYGyqnH8GyYE73v8i/B9VD5FsfP3fjjdvA+hWh3Spy7h+ 7BZbyDJWZQMoanODX89Cmsb0n/7VNtqJ1KcZhWCdbYX7BlA82T+vvp53F764iLXkCXhw Nd4HFCElYQHw9drGfI5E2SO7WDa03yn2XYK69mTHjlyHQ5TSfNFSkPqAOXlHpWwLHYJ6 hObQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=VMDWbuxc; 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 s7-20020a170902988700b001b5afcfa180si14750312plp.213.2023.07.01.08.01.37; Sat, 01 Jul 2023 08:01:50 -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=20221208 header.b=VMDWbuxc; 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 S230297AbjGAOUu (ORCPT + 99 others); Sat, 1 Jul 2023 10:20:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229641AbjGAOUt (ORCPT ); Sat, 1 Jul 2023 10:20:49 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF31630D0; Sat, 1 Jul 2023 07:20:47 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-314172bb818so3263179f8f.1; Sat, 01 Jul 2023 07:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688221246; x=1690813246; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4xzwfPjRQFT6QKTWY2W7B8J20zCNe8ZcBZy6OXaEZiE=; b=VMDWbuxc1Y6vsnHVtQXRkXyvapLiLnw6gcnHcjZLt2lDpg8vDqciqBzOkHDZgGgCJJ +QwCuRAk8LsSSfXQOXg7wO1/dG+fYDAmMT/+mEf/uMJ/DDIr29gwEKvPARdlvxRnUplI u3brKHyBqYEOAby5GHwvguXFV5okajoyD/gpdVUy2qgMAT/EOBRO9OVzk4uOIShNc0DM 65CMYHkesyGwMuesK+Aqzo6cnCKO7q1glqj6an3sIU+GtW1GKwkW3M4jLVYQCnVT3Nr5 qn4j820pxQOdVxkMyUFSePMrzKu1DdtNubgwbhuUuMwF4HhiiZ7Oi9Vn1xgGKHJtsQJw k/zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688221246; x=1690813246; 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=4xzwfPjRQFT6QKTWY2W7B8J20zCNe8ZcBZy6OXaEZiE=; b=bQnejJCtCN2ZvUvkV0Vol3464wDn1dFfxfI/hxcFIXqzGXBO2Gc55kZ5m8/mLRYEWy QS5T3kfoyTuUau7oD11A17WKo24l0kFgYdEFfdjTVQ5bIMBX+zjrx+nWi51TbMX6F8xj MDTflJhDl4EoXg6GzmqqXK5ucuR1rF17xgzkJplxYSGaBsMexnSttCwVQ3axo/bTXR4o Rpuh0cZF2pXnYinNj9yLp0AIjRBhSXBXOdVSHzHJQKB4TbObFowCiIxiG+RZquwsyKAO LnzuenxqVQGgHiUMA0522GcH4Tr0OiGmQ7Z7LM5+NakgpOXv7DnoXRVxrCDGElc84Skd IRFQ== X-Gm-Message-State: ABy/qLbo9Za+1vpUKew8TM6o54FWo+FDOgYPHO8nmR643E6JfuqHayqw EC0uzPT5IdG1qb3aXmDW8SE= X-Received: by 2002:a5d:49d1:0:b0:314:15b7:1fb5 with SMTP id t17-20020a5d49d1000000b0031415b71fb5mr4238962wrs.34.1688221246067; Sat, 01 Jul 2023 07:20:46 -0700 (PDT) Received: from localhost.localdomain (host-82-49-237-33.retail.telecomitalia.it. [82.49.237.33]) by smtp.gmail.com with ESMTPSA id t5-20020a05600001c500b00313f7b077fesm14307741wrx.59.2023.07.01.07.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 07:20:45 -0700 (PDT) From: "Fabio M. De Francesco" To: Jonathan Corbet , Andrew Morton , "Fabio M. De Francesco" , "Mike Rapoport (IBM)" , Deming Wang , Ira Weiny , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Catalin Marinas , Matthew Wilcox , Mike Rapoport , Peter Collingbourne , Peter Zijlstra , Sebastian Andrzej Siewior , Thomas Gleixner , Vlastimil Babka , Will Deacon Subject: [PATCH v2] Documentation/mm: Add information about kmap_local_folio() Date: Sat, 1 Jul 2023 16:19:31 +0200 Message-ID: <20230701142041.9992-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 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,T_SCC_BODY_TEXT_LINE 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 differences between kmap_local_page() and kmap_local_folio() consist only in the first taking a pointer to a page and the second taking two arguments, a pointer to a folio and the byte offset within the folio which identifies the page. The two API's can be explained at the same time in the "Temporary Virtual Mappings" section of the Highmem's documentation. Add information about kmap_local_folio() in the same subsection that explains kmap_local_page(). Cc: Andrew Morton Cc: Catalin Marinas Cc: Ira Weiny Cc: Jonathan Corbet Cc: Matthew Wilcox (Oracle) Cc: Mike Rapoport Cc: Peter Collingbourne Cc: Peter Zijlstra Cc: Sebastian Andrzej Siewior Cc: Thomas Gleixner Cc: Vlastimil Babka Cc: Will Deacon Reviewed-by: Ira Weiny Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Fabio M. De Francesco --- v1->v2: I thought to Cc everybody but Andrew :-( Sorry, fixed. Andrew, can you please take this patch through your tree? Documentation/mm/highmem.rst | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Documentation/mm/highmem.rst b/Documentation/mm/highmem.rst index c964e0848702..bb9584f167a6 100644 --- a/Documentation/mm/highmem.rst +++ b/Documentation/mm/highmem.rst @@ -51,11 +51,14 @@ Temporary Virtual Mappings The kernel contains several ways of creating temporary mappings. The following list shows them in order of preference of use. -* kmap_local_page(). This function is used to require short term mappings. - It can be invoked from any context (including interrupts) but the mappings - can only be used in the context which acquired them. - - This function should always be used, whereas kmap_atomic() and kmap() have +* kmap_local_page(), kmap_local_folio() - These functions are used to require + short term mappings. They can be invoked from any context (including + interrupts) but the mappings can only be used in the context which acquired + them. The only differences between them consist in the first taking a pointer + to a struct page and the second taking a pointer to struct folio and the byte + offset within the folio which identifies the page. + + These functions should always be used, whereas kmap_atomic() and kmap() have been deprecated. These mappings are thread-local and CPU-local, meaning that the mapping @@ -72,17 +75,17 @@ list shows them in order of preference of use. maps of the outgoing task are saved and those of the incoming one are restored. - kmap_local_page() always returns a valid virtual address and it is assumed - that kunmap_local() will never fail. + kmap_local_page(), as well as kmap_local_folio() always returns valid virtual + kernel addresses and it is assumed that kunmap_local() will never fail. - On CONFIG_HIGHMEM=n kernels and for low memory pages this returns the + On CONFIG_HIGHMEM=n kernels and for low memory pages they return the virtual address of the direct mapping. Only real highmem pages are temporarily mapped. Therefore, users may call a plain page_address() for pages which are known to not come from ZONE_HIGHMEM. However, it is - always safe to use kmap_local_page() / kunmap_local(). + always safe to use kmap_local_{page,folio}() / kunmap_local(). - While it is significantly faster than kmap(), for the highmem case it - comes with restrictions about the pointers validity. Contrary to kmap() + While they are significantly faster than kmap(), for the highmem case they + come with restrictions about the pointers validity. Contrary to kmap() mappings, the local mappings are only valid in the context of the caller and cannot be handed to other contexts. This implies that users must be absolutely sure to keep the use of the return address local to the @@ -91,7 +94,7 @@ list shows them in order of preference of use. Most code can be designed to use thread local mappings. User should therefore try to design their code to avoid the use of kmap() by mapping pages in the same thread the address will be used and prefer - kmap_local_page(). + kmap_local_page() or kmap_local_folio(). Nesting kmap_local_page() and kmap_atomic() mappings is allowed to a certain extent (up to KMAP_TYPE_NR) but their invocations have to be strictly ordered -- 2.41.0