From patchwork Sat Jul 8 12:16:18 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: 13305665 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 156F7EB64DC for ; Sat, 8 Jul 2023 12:17:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2ACBA6B0071; Sat, 8 Jul 2023 08:17:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 234828D0002; Sat, 8 Jul 2023 08:17:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AE2A8D0001; Sat, 8 Jul 2023 08:17:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EA9946B0071 for ; Sat, 8 Jul 2023 08:17:30 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B8A131C7876 for ; Sat, 8 Jul 2023 12:17:30 +0000 (UTC) X-FDA: 80988345060.10.38A6BAD Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by imf03.hostedemail.com (Postfix) with ESMTP id E9B812000B for ; Sat, 8 Jul 2023 12:17:27 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=Zb3fPI84; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.128.50 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688818648; 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:dkim-signature; bh=qrwJasY3cJuEA4+eZCnOTkC6/C/i+F1wG15vTJoUGTg=; b=6BRKo2EVjyNChC89DNBdse/KmCZW7b+0+koYi64NgZkbZGF7ChJqLIQbu3mATl5ItQGtz8 4y1uPhcJu3pC0a1YkwjAa2/3xT6cSYlN80Dky1duk9Q9qh3mY2wyI5YrEmuYGhxISHVk7h ibtN6DU+MGIl3paCh0VR0znpEZLOjj0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=Zb3fPI84; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.128.50 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688818648; a=rsa-sha256; cv=none; b=aUICFVLN1X5sFFYhkkBPrJSyZV68gIzKcWQW9n2wFL585Vlnw4E4ujPoSyGgR/8osKz+Vg 3FsYpfDgq/9zaw3kG3f7bHekgMcy4HYDH4dHyRKsGXfoCQVRzvDhuxCpXiYBsMstIOaCAC SQh3bXLAEtJXtg2lLUJyliHISlRyTfQ= Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-3fb4146e8fcso23542215e9.0 for ; Sat, 08 Jul 2023 05:17:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688818646; x=1691410646; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qrwJasY3cJuEA4+eZCnOTkC6/C/i+F1wG15vTJoUGTg=; b=Zb3fPI842NYI9Pnn1VdSQGtfjPgEH/6Se9Fn99r25H8BipyXFJ1sjvge760Hx8bDgH bMNogKxczovu24ZofN0c7P7tyZQwgopxFiuzwc0AQXTW7uGPHKgOhQL3y4UTw6b5UH6Q wnsPK2B4soVXZ8RWHRbtz1NPeM25rNFfZKHE5zX6rtz/w1EdgDC9hPcqujvBuz+xPDYJ OQQl3NLZdyBELb3N6rzjWceuuGSfPJpSDNPFB6sj9SIIvV8nz5UB2QLvdiKQ9gAN4Ttq dxI8pQGDcKtjhaWQS7K2v+s6W9cYDjE9eU1er2hPOx46nnsaegwCJaWbaks+FhYEdb+i T+Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688818646; x=1691410646; 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=qrwJasY3cJuEA4+eZCnOTkC6/C/i+F1wG15vTJoUGTg=; b=CykNUCvd72tC9+164+UQfkTSUMm0CaIYwAO1B2mo2Y5yJ+38UMyHdXyVHug1VZlsg9 vsvbr5847XM1H35j4o0Ry5SDBimqez/VO66NKz5vsdDyYmOiA1hkNpIIz7eS92/FUsCj zucnAo7Cc5RxvpcAx65TrclRenc39OspuFUksblsvzEPtNHRwga6PupwWQCLNu6quCUT U6764ewPL1z8C+3HS89hHfZ9MrOlltmay5VtkJ0tmDMoaLfmwRqnrt4+AtTH14TnYAlh YSJ58GBmF9GuagQkXfJqCBuhLO9ME1G9FzfRn0Prc1Rave38gnwGF7fMUdDp9z4517RT +VlA== X-Gm-Message-State: ABy/qLYgWQMVuCXCcY7d5kOUk2udbiUidhEO2OMASL3n0PfPebYyo8Fv oXYws36wfmVwt9CJL/EXKdY= X-Google-Smtp-Source: APBJJlF5S37/61IOUN4boRGyQ+eZbxbUsGSs3iPJnY2sKXBk7rqPV2h3cJxGNUS1K7AOv/xHI7PW6Q== X-Received: by 2002:a1c:770b:0:b0:3f7:c92:57a0 with SMTP id t11-20020a1c770b000000b003f70c9257a0mr7445101wmi.14.1688818645993; Sat, 08 Jul 2023 05:17:25 -0700 (PDT) Received: from localhost.localdomain (host-95-247-100-31.retail.telecomitalia.it. [95.247.100.31]) by smtp.gmail.com with ESMTPSA id f17-20020adfe911000000b0031416362e23sm6889003wrm.3.2023.07.08.05.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jul 2023 05:17:25 -0700 (PDT) From: "Fabio M. De Francesco" To: Jonathan Corbet , Andrew Morton , "Fabio M. De Francesco" , "Mike Rapoport (IBM)" , Ira Weiny , Deming Wang , linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Catalin Marinas , Matthew Wilcox , Mike Rapoport , Peter Collingbourne , Peter Zijlstra , Randy Dunlap , Sebastian Andrzej Siewior , Thomas Gleixner , Vlastimil Babka , Will Deacon Subject: [PATCH v3] Documentation/highmem: Add information about kmap_local_folio() Date: Sat, 8 Jul 2023 14:16:18 +0200 Message-ID: <20230708121719.8270-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: E9B812000B X-Stat-Signature: s81d17d7ibifdh8cfdphjnjpd3xcbjza X-Rspam-User: X-HE-Tag: 1688818647-208546 X-HE-Meta: U2FsdGVkX19fGrYrb5YNDSDystFx9oUIi9KhZCccr5XzyfU6q2kCMbja/LVDoXgONMFnl/w2Gv1SV/slf+MCbMDiEM+mh4qZ3fPPs8FbYWxGOJ5J6QtAyXrFCDss6W4DmPYHbBuvD+8Es1PtKGxlFv46O2ELWlVTw/SOzAQF953O1iXIOqiA3Z7VADraELAu6/u9JtUB1OZRem+BODa/TB99faB8odqW2GVRspoNB2sScKlQrgeSsxqTEzGt5jARdNE64jhwZ7r7WowuS3gNVj2IYcvxNeD5+SDl9tDFk1fRLKJ1azJSJrGwA1wULlYmRIUzFOyY8+Ltqh1hjpRXzrb28HvzKykxG++/Rs9GYwPLOveuRtc/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h6lNBYN4aH4S6wndlEV6NBrgm2GsXRoO1b4Zcrvtu1dw6UlpwZdSlHuiZgm5BQP8YQRz+mzA+kf4141hlwl4LVksyKdHz6Ic7dUFaFRbKZ3POulHf8dRbxIIsdi/hNLxEj5wYt3QyZKldYNdkyqqNjOm9K5L33PlJcwskb6+llXr3yn5U3rqHqqo9NmaCagQQGRY1o928pn5ztujka/3s4gScTcBOqC6zDmD+r02YZi9H+1xjn0p5xQCdwVHNXgarSAUE9yua8X/CFqVBGnBfSd+lRwSM5qOajgW6az58kqUdmtIvPzEWeQTdga4XBUCQe0uviyni5nYn29iqrOaND3AQs4pLKH36p+FqIcrv9bDcPFDAp9iCYTTUSEQpDuJF5jglPjk68IeLhkwqX0NlouA= 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: 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: Randy Dunlap 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 --- v2->v3: Replaced "request" with "create". Noticed by Randy (thanks), fixed by Matthew (again thanks). https://lore.kernel.org/lkml/970a881a-cdaf-2568-657a-3b93b0273338@infradead.org/ v1-v2: I had Cc'ed everybody but Andrew :-( Sorry, it's now fixed. In the meantime, I collected the review tags by Ira and Mike (thanks to both of you). All entries are listed using a simple ascending lexycographycal order based on first names. 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..fe68e02fc8ff 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 create + 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