From nobody Mon Jun 15 18:32:32 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE880C433F5 for ; Mon, 25 Apr 2022 16:24:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243378AbiDYQ1T (ORCPT ); Mon, 25 Apr 2022 12:27:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238361AbiDYQ1N (ORCPT ); Mon, 25 Apr 2022 12:27:13 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B53E211F95E; Mon, 25 Apr 2022 09:24:08 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id g23so12065308edy.13; Mon, 25 Apr 2022 09:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uCI5XJJQhEl0Rvu0MUBKvOSHqWoc72nC9Ng5croQe20=; b=GWM426VVKttgpvPwF1MZmSeP7wVjoc6F9U6TxK5zuzh3hInFVLrofTmC7gs/A7wkDz akCLKZ9mSDwVs/qqYEpiliNdmn5eLZ24eIB+ePTBkhb/b4t+eqt//hHwAM3WHbJTKS9G QLrx2eqH/x9j3iK4IqURkQcuDYamABjO78otOx6tH45RFL55Q1WSHNdDMviZxxXfTDC4 5haJedFtVLO9df98juFNJ3wkeNw6QjLBevlU4Y9OiyjMs/8xCuVJCC9banu7y21ZKaFx TBCC7MTlEAN3EMTsnHKcH9DUin/wRfYJsZNagW3S1E7bW78/z8R1bOYHRr9xxuNMsH1c L07w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uCI5XJJQhEl0Rvu0MUBKvOSHqWoc72nC9Ng5croQe20=; b=m00EWAoJjvtxQsjMqRImKRjMvOHhARI2f03W33j6MVnnfpAm4CU2wA7DatmJA9u8U7 tNb0cJWlMF9vLesEoMAlMU4KWa2sqtjodzFHbWKD7tHdDavCdssJpU3P/Nnc4yFH8+K0 msOI+XCQDZ3ogTcm25U7GyiysHEO3vOL4qp1wHFHtUFfKhRUgLPU41SLYNb8lLg9nId9 OZpG5keOLvx/CGOnYmxOFqZKrqeClRxWNbn3+DlPi2yVGPFF4sLSRX/sPNLiYaeJRooD EVZajOvZOM6SV1I9v8ZpNOBa5CIYTokRPbWZPliI9UmxpWyT4yDpI5Mlv95CTeFXClkd OqoQ== X-Gm-Message-State: AOAM532EQ6ltscF84g5vc8240+02iVLWi16DDkGnxgtfaVnSxazJM8TS egERtj4f1JPgsltMETFKpao= X-Google-Smtp-Source: ABdhPJwQbgy60NHrcrLBuAejcY/4n0Ir6e8Pjhj1ueo4kxtfr5zsTKcRDPd8DUgRRQwPwMqZpgP9oQ== X-Received: by 2002:aa7:d5c5:0:b0:425:b144:ab84 with SMTP id d5-20020aa7d5c5000000b00425b144ab84mr19906210eds.200.1650903847284; Mon, 25 Apr 2022 09:24:07 -0700 (PDT) Received: from localhost.localdomain (host-79-50-86-254.retail.telecomitalia.it. [79.50.86.254]) by smtp.gmail.com with ESMTPSA id s12-20020a1709062ecc00b006e8558c9a5csm3784122eji.94.2022.04.25.09.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 09:24:05 -0700 (PDT) From: "Fabio M. De Francesco" To: Ira Weiny , Andrew Morton , Catalin Marinas , "Matthew Wilcox (Oracle)" , Will Deacon , Peter Collingbourne , Vlastimil Babka , Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, Jonathan Corbet , linux-doc@vger.kernel.org, outreachy@lists.linux.dev Cc: "Fabio M. De Francesco" , "Acked-by : Mike Rapoport" Subject: [PATCH v2 1/4] mm/highmem: Fix kernel-doc warnings in highmem*.h Date: Mon, 25 Apr 2022 18:23:57 +0200 Message-Id: <20220425162400.11334-2-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220425162400.11334-1-fmdefrancesco@gmail.com> References: <20220425162400.11334-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" `scripts/kernel-doc -v -none include/linux/highmem*` reports the following warnings: include/linux/highmem.h:160: warning: expecting prototype for kunmap_atomic= (). Prototype was for nr_free_highpages() instead include/linux/highmem.h:204: warning: No description found for return value= of 'alloc_zeroed_user_highpage_movable' include/linux/highmem-internal.h:256: warning: Function parameter or member= '__addr' not described in 'kunmap_atomic' include/linux/highmem-internal.h:256: warning: Excess function parameter 'a= ddr' description in 'kunmap_atomic' Fix these warnings by (1) moving the kernel-doc comments from highmem.h to highmem-internal.h (which is the file were the kunmap_atomic() macro is actually defined), (2) extending and merging it with the comment which was already in highmem-internal.h, and (3) using correct parameter names. Cc: Matthew Wilcox Cc: Acked-by: Mike Rapoport Cc: Reviewed-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- include/linux/highmem-internal.h | 14 +++++++++++--- include/linux/highmem.h | 15 +++------------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/include/linux/highmem-internal.h b/include/linux/highmem-inter= nal.h index a77be5630209..aa22daeed617 100644 --- a/include/linux/highmem-internal.h +++ b/include/linux/highmem-internal.h @@ -236,9 +236,17 @@ static inline unsigned long totalhigh_pages(void) { re= turn 0UL; } =20 #endif /* CONFIG_HIGHMEM */ =20 -/* - * Prevent people trying to call kunmap_atomic() as if it were kunmap() - * kunmap_atomic() should get the return value of kmap_atomic, not the pag= e. +/** + * kunmap_atomic - Unmap the virtual address mapped by kmap_atomic() + * @__addr: Virtual address to be unmapped + * + * Unmaps an address previously mapped by kmap_atomic() and re-enables + * pagefaults and preemption. Mappings should be unmapped in the reverse + * order that they were mapped. See kmap_local_page() for details. + * @__addr can be any address within the mapped page, so there is no need + * to subtract any offset that has been added. In contrast to kunmap(), + * this function takes the address returned from kmap_atomic(), not the + * page passed to it. The compiler will warn you if you pass the page. */ #define kunmap_atomic(__addr) \ do { \ diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 39bb9b47fa9c..3456dc1d38db 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -37,7 +37,7 @@ static inline void *kmap(struct page *page); =20 /** * kunmap - Unmap the virtual address mapped by kmap() - * @addr: Virtual address to be unmapped + * @page: Pointer to the page which was mapped by kmap() * * Counterpart to kmap(). A NOOP for CONFIG_HIGHMEM=3Dn and for mappings of * pages in the low memory area. @@ -145,17 +145,6 @@ static inline void *kmap_local_folio(struct folio *fol= io, size_t offset); */ static inline void *kmap_atomic(struct page *page); =20 -/** - * kunmap_atomic - Unmap the virtual address mapped by kmap_atomic() - * @addr: Virtual address to be unmapped - * - * Counterpart to kmap_atomic(). - * - * Effectively a wrapper around kunmap_local() which additionally undoes - * the side effects of kmap_atomic(), i.e. reenabling pagefaults and - * preemption. - */ - /* Highmem related interfaces for management code */ static inline unsigned int nr_free_highpages(void); static inline unsigned long totalhigh_pages(void); @@ -191,6 +180,8 @@ static inline void clear_user_highpage(struct page *pag= e, unsigned long vaddr) * @vma: The VMA the page is to be allocated for * @vaddr: The virtual address the page will be inserted into * + * Returns: The allocated and zeroed HIGHMEM page + * * This function will allocate a page for a VMA that the caller knows will * be able to migrate in the future using move_pages() or reclaimed * --=20 2.34.1 From nobody Mon Jun 15 18:32:32 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADCF1C433EF for ; Mon, 25 Apr 2022 16:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243391AbiDYQ1V (ORCPT ); Mon, 25 Apr 2022 12:27:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243362AbiDYQ1P (ORCPT ); Mon, 25 Apr 2022 12:27:15 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26F6911F953; Mon, 25 Apr 2022 09:24:11 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id p4so3465183edx.0; Mon, 25 Apr 2022 09:24:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k75/spXS+k5a5+DVquVFeCXg9KobdD3U49dRA56k3UQ=; b=o9+2pBqWUis4C6ZmgeEt5DTfRXP576snfeynxz9Ldb7ffqC3x9eTcQ2TP0dl8TEupW rHiAmS/ZLdlYuA5KVEiPg0INBIPqtvD1zRVFVfoiBi8Yb9j2bfAyuOmjLUkibHyuCBm1 phhllpn38RK6N48Gkijl4o0vHsbMNoCyjkA/QXisVu5//F6HOp4ZgIhacDVrvGujNZOr yvC/TM2VAJbPILhgMsgI4RwNe+wKp/PDZKY1NLf0s2V3L1FWYjKDCR2SkXJess0xTFku uqEsrCEj/nUBe/X4yx0wun5/MqGdMA+dvlxgy/j5cgQv0p62t6UnSe/xMd4pi58THbLs 6iMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k75/spXS+k5a5+DVquVFeCXg9KobdD3U49dRA56k3UQ=; b=vJSEKhfmaGYbU4kU0EcIdJoJhL3XvfjC+wVtJBHjheD9BP8UhqFy0zLr8+yvYxMb0v 8Gm7MpkFxx+tP9LWaVDihKkPLfxKwE1YI/UxfoSTe/5LPUTSXEtssnCFIZ+Fgr+RNqjC PaohhGSCmzyp2nq5Y94DC7gsviq8qewbf3W9Y2P7bF3/PZciveuQGZoHzs6R0Rg5+Wk0 RqexyrSlBGjwgk7xo7zqrJXS1tUpykI9+LFQ8tytZUQieiMqv1rj8cMgtupULnHafDr1 og9r755Qc1gL3cA/oYvBh/W4dOfrQxjFyKjGNs7Xsndp6+fJThVPRzJlP4bBmmuy9qpW bdFw== X-Gm-Message-State: AOAM53150d6Sd2l0aewKhynOt8gpcFoRZ676HOAX7W02iN9JPQpKudUe nRvimtAuCUV1G5cEUyPZkao= X-Google-Smtp-Source: ABdhPJxsVB07TMND4r1/D1MiuXyvmgzMTJcIRZOlK5oN4b3CUelM/Sd2DPPsgUpZiXdLG0i/3CyNnw== X-Received: by 2002:a05:6402:51d2:b0:424:536:94dd with SMTP id r18-20020a05640251d200b00424053694ddmr20029040edd.191.1650903849582; Mon, 25 Apr 2022 09:24:09 -0700 (PDT) Received: from localhost.localdomain (host-79-50-86-254.retail.telecomitalia.it. [79.50.86.254]) by smtp.gmail.com with ESMTPSA id s12-20020a1709062ecc00b006e8558c9a5csm3784122eji.94.2022.04.25.09.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 09:24:08 -0700 (PDT) From: "Fabio M. De Francesco" To: Ira Weiny , Andrew Morton , Catalin Marinas , "Matthew Wilcox (Oracle)" , Will Deacon , Peter Collingbourne , Vlastimil Babka , Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, Jonathan Corbet , linux-doc@vger.kernel.org, outreachy@lists.linux.dev Cc: "Fabio M. De Francesco" , Thomas Gleixner , Peter Zijlstra , Mike Rapoport Subject: [PATCH v2 2/4] Documentation/vm: Include kdocs into highmem.rst Date: Mon, 25 Apr 2022 18:23:58 +0200 Message-Id: <20220425162400.11334-3-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220425162400.11334-1-fmdefrancesco@gmail.com> References: <20220425162400.11334-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" kernel-docs that are in include/linux/highmem.h and in include/linux/highmem-internal.h should be included in highmem.rst. Use kdocs directives to include the above-mentioned comments into highmem.rst. Cc: Jonathan Corbet Cc: Thomas Gleixner Cc: Matthew Wilcox Cc: Peter Zijlstra Suggested-by: Ira Weiny Acked-by: Mike Rapoport Reviewed-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- Documentation/vm/highmem.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/vm/highmem.rst b/Documentation/vm/highmem.rst index 0f69a9fec34d..ccff08a8211d 100644 --- a/Documentation/vm/highmem.rst +++ b/Documentation/vm/highmem.rst @@ -145,3 +145,10 @@ The general recommendation is that you don't use more = than 8GiB on a 32-bit machine - although more might work for you and your workload, you're pretty much on your own - don't expect kernel developers to really care much if t= hings come apart. + + +Functions +=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. kernel-doc:: include/linux/highmem.h +.. kernel-doc:: include/linux/highmem-internal.h --=20 2.34.1 From nobody Mon Jun 15 18:32:32 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 164A3C433EF for ; Mon, 25 Apr 2022 16:25:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243550AbiDYQ2F (ORCPT ); Mon, 25 Apr 2022 12:28:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243380AbiDYQ1S (ORCPT ); Mon, 25 Apr 2022 12:27:18 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E54711F961; Mon, 25 Apr 2022 09:24:13 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id y21so12184591edo.2; Mon, 25 Apr 2022 09:24:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+Zl4c5jLaRcNs7un+USLcaMW4MzMPWj/KhoSlyRdffo=; b=DM1uNsyJDZ+YgMjVkHr9YjLJab0jghTM741FuQr/9hLhPA6kee/3ke59nLooPT2INj 0loV0sdVLbwcaGE7MLXtL64v/l5Kxem/2ahz2vGfyBbmDg0i2FYBfRltqm69yVv0qhro 98UZqEWGfQDVfdREl1TQT9ly6FZ0um5jkzcuI8oflWfmc1aYQt8RGhDLuzre8a4Lmibh Ytr6M1z2WQYLWG3Bum+WGjcHeG3XBNAmLVcnvJDo9VyTLghHo0U/wU61dxkqDAPkhqEG 2TEi0WF2J5pcD2TFal2xICG7VKHp5LwoVcTa7BaZB12sYIMcWvnDJ7sMm+wYrVzOYJsz KqSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+Zl4c5jLaRcNs7un+USLcaMW4MzMPWj/KhoSlyRdffo=; b=5rjfUGivumFkBn5UX+s8zhpL6wSO53ISC+8x8D+s8cpIs74HkHpSn0Hvx7lkddb4hG +ZpoZJd3yyR4PA7T0HsLzkl8XtyD7v7C/9beDAbxChnq55ajLaxMml1lHu889/8M3ehO nkT784VMSbjCllKXSBBKT4XoiY2J0quV3rB6a+EBjq9eL5X4ZEkPdTTgLiPWWnwqbULf WdomEtzoz5AurRwpr2kuGBmMj+wV3PVnp6irAUTvNvNhLJsLk6v14zJp34+hRLWJy/d9 QamCtkqQvTZY/qYFBxfFUw68m1Yj7DkKGPBvT7rRTDjJJgbT10Hsp/6KBMlhFDvKG/Hr qi9A== X-Gm-Message-State: AOAM532Q/I8vyAtScXOgvWBjuzsSKFdKzBuyNxRKBZcaMdYTVgFlJJrV oaEtiPx3+RkngPdCVCjbkCE= X-Google-Smtp-Source: ABdhPJw0kQrnedcs+J68OcUUWPs+98m3RHnEnwndKP9hsiRpV/ZQk/hECQHKL1DmrKownzsXBQ1Ssg== X-Received: by 2002:a05:6402:3486:b0:425:f2c6:9695 with SMTP id v6-20020a056402348600b00425f2c69695mr2903431edc.2.1650903852053; Mon, 25 Apr 2022 09:24:12 -0700 (PDT) Received: from localhost.localdomain (host-79-50-86-254.retail.telecomitalia.it. [79.50.86.254]) by smtp.gmail.com with ESMTPSA id s12-20020a1709062ecc00b006e8558c9a5csm3784122eji.94.2022.04.25.09.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 09:24:10 -0700 (PDT) From: "Fabio M. De Francesco" To: Ira Weiny , Andrew Morton , Catalin Marinas , "Matthew Wilcox (Oracle)" , Will Deacon , Peter Collingbourne , Vlastimil Babka , Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, Jonathan Corbet , linux-doc@vger.kernel.org, outreachy@lists.linux.dev Cc: "Fabio M. De Francesco" , Thomas Gleixner , Peter Zijlstra Subject: [PATCH v2 3/4] Documentation/vm: Move section from highmem.rst to highmem.h Date: Mon, 25 Apr 2022 18:23:59 +0200 Message-Id: <20220425162400.11334-4-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220425162400.11334-1-fmdefrancesco@gmail.com> References: <20220425162400.11334-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The use of kmap_atomic() is new code is being deprecated in favor of kmap_local_page(). For this reason the "Using kmap_atomic" section in highmem.rst is obsolete and unnecessary, but it can still help developers if it were moved to kdocs in highmem.h. Therefore, move the relevant parts of this section from highmem.rst and merge them with the kdocs in highmem.h. Cc: Jonathan Corbet Cc: Thomas Gleixner Cc: Matthew Wilcox Cc: Peter Zijlstra Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- Documentation/vm/highmem.rst | 35 ----------------------------------- include/linux/highmem.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/Documentation/vm/highmem.rst b/Documentation/vm/highmem.rst index ccff08a8211d..e05bf5524174 100644 --- a/Documentation/vm/highmem.rst +++ b/Documentation/vm/highmem.rst @@ -72,41 +72,6 @@ The kernel contains several ways of creating temporary m= appings: It may be assumed that k[un]map_atomic() won't fail. =20 =20 -Using kmap_atomic -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - -When and where to use kmap_atomic() is straightforward. It is used when c= ode -wants to access the contents of a page that might be allocated from high m= emory -(see __GFP_HIGHMEM), for example a page in the pagecache. The API has two -functions, and they can be used in a manner similar to the following:: - - /* Find the page of interest. */ - struct page *page =3D find_get_page(mapping, offset); - - /* Gain access to the contents of that page. */ - void *vaddr =3D kmap_atomic(page); - - /* Do something to the contents of that page. */ - memset(vaddr, 0, PAGE_SIZE); - - /* Unmap that page. */ - kunmap_atomic(vaddr); - -Note that the kunmap_atomic() call takes the result of the kmap_atomic() c= all -not the argument. - -If you need to map two pages because you want to copy from one page to -another you need to keep the kmap_atomic calls strictly nested, like:: - - vaddr1 =3D kmap_atomic(page1); - vaddr2 =3D kmap_atomic(page2); - - memcpy(vaddr1, vaddr2, PAGE_SIZE); - - kunmap_atomic(vaddr2); - kunmap_atomic(vaddr1); - - Cost of Temporary Mappings =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =20 diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 3456dc1d38db..6b2d59e025c5 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -142,6 +142,37 @@ static inline void *kmap_local_folio(struct folio *fol= io, size_t offset); * and preemption. * * Do not use in new code. Use kmap_local_page() instead. + * + * It is used in atomic context when code wants to access the contents of a + * page that might be allocated from high memory (see __GFP_HIGHMEM), for + * example a page in the pagecache. The API has two functions, and they + * can be used in a manner similar to the following: + * + * -- Find the page of interest. -- + * struct page *page =3D find_get_page(mapping, offset); + * + * -- Gain access to the contents of that page. -- + * void *vaddr =3D kmap_atomic(page); + * + * -- Do something to the contents of that page. -- + * memset(vaddr, 0, PAGE_SIZE); + * + * -- Unmap that page. -- + * kunmap_atomic(vaddr); + * + * Note that the kunmap_atomic() call takes the result of the kmap_atomic() + * call, not the argument. + * + * If you need to map two pages because you want to copy from one page to + * another you need to keep the kmap_atomic calls strictly nested, like: + * + * vaddr1 =3D kmap_atomic(page1); + * vaddr2 =3D kmap_atomic(page2); + * + * memcpy(vaddr1, vaddr2, PAGE_SIZE); + * + * kunmap_atomic(vaddr2); + * kunmap_atomic(vaddr1); */ static inline void *kmap_atomic(struct page *page); =20 --=20 2.34.1 From nobody Mon Jun 15 18:32:32 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55598C433F5 for ; Mon, 25 Apr 2022 16:25:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243461AbiDYQ2L (ORCPT ); Mon, 25 Apr 2022 12:28:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243387AbiDYQ1V (ORCPT ); Mon, 25 Apr 2022 12:27:21 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3112E11F95D; Mon, 25 Apr 2022 09:24:16 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id be20so10736408edb.12; Mon, 25 Apr 2022 09:24:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OJGoiJNwFDmzE6NZyaviRL0fEUXeK4n13JnNeBVTnoY=; b=QrnfVKZSrkyH0G9YYMJPjxqtJnZgqF/lOhQXKE7zaCAFKC6qv5NSrjPyHaXqTJAZcW knqvwYiRlh98S5V0plazvm/ZeOB8qzt7fl7aiNx6KCjPlp2XxVaWAkp1IowiMcIcM5aS 7F6SQn2iFoTugdkx7DA8fRRhxVwoKFs33mZcfYcwx1L+OYTkDovymxDUJTrjBC24RUOI uPdArrtUPZb5Y9CNHGTsZe79B/yBWRFv6LX8v/2x4F9XaGd9in2xLIqW9F0CNcJHTb+I BVCEb2Cqq5TZhFrggaTPl03M3QlJHonYVLLz1IQ45gvxBN6aFPG7maFIRlPRpgObn/VF yw4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OJGoiJNwFDmzE6NZyaviRL0fEUXeK4n13JnNeBVTnoY=; b=i1FDUusplzhp124H/gI1HZWMYambhuxyrZgMLrLXDyUsd9DWaKTTxCMQx2unGvA/cw 8+Y11ShuNlQbaQm3uez22c7UaFs2qDr/rn8F2YbpX4PcO1Kg/aMLP9fYcFbCalXlvSIS 8FMOWQw2Ut/k5sl8vffowytDLTPLSMm0e+NQJXJgbHsWzy+abhHnWvtrcmbrH+urII/P 65+pevDZ+xb5w+Vvnz4epUOax/C1AfDSAr8sbSt4NTIidbgHRpoBmeXwOp0HW7px6Vom LzpRqpd8GxzjePosh3QyZi77XgqH9k964Aa39W3tqymD9GmSLwetYxW5iHp+nH8cBNaa VAFQ== X-Gm-Message-State: AOAM533eREbX2pJsJNklk0Asar6r/vexUk9IlXSo8WDtOBg7lzQHzeOv HQ9kZ53HT8dNMGyD3wEFJl8= X-Google-Smtp-Source: ABdhPJw9+DlfQBDaEvdFlPBGZF1PZTZcAcH6T54OGUFmHhZAoP3YHxD8OhDfKdcHl4Ub53GqIh/5nA== X-Received: by 2002:aa7:d916:0:b0:425:d75f:ae68 with SMTP id a22-20020aa7d916000000b00425d75fae68mr10832913edr.270.1650903854728; Mon, 25 Apr 2022 09:24:14 -0700 (PDT) Received: from localhost.localdomain (host-79-50-86-254.retail.telecomitalia.it. [79.50.86.254]) by smtp.gmail.com with ESMTPSA id s12-20020a1709062ecc00b006e8558c9a5csm3784122eji.94.2022.04.25.09.24.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 09:24:13 -0700 (PDT) From: "Fabio M. De Francesco" To: Ira Weiny , Andrew Morton , Catalin Marinas , "Matthew Wilcox (Oracle)" , Will Deacon , Peter Collingbourne , Vlastimil Babka , Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, Jonathan Corbet , linux-doc@vger.kernel.org, outreachy@lists.linux.dev Cc: "Fabio M. De Francesco" , Thomas Gleixner , Peter Zijlstra Subject: [PATCH v2 4/4] Documentation/vm: Rework "Temporary Virtual Mappings" section Date: Mon, 25 Apr 2022 18:24:00 +0200 Message-Id: <20220425162400.11334-5-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220425162400.11334-1-fmdefrancesco@gmail.com> References: <20220425162400.11334-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Extend and rework the "Temporary Virtual Mappings" section of the highmem.r= st documentation. Despite the local kmaps were introduced by Thomas Gleixner in October 2020, documentation was still missing information about them. These additions rely largely on Gleixner's patches, Jonathan Corbet's LWN articles, comments by Ira Weiny and Matthew Wilcox, and in-code comments from ./include/linux/highmem.h. 1) Add a paragraph to document kmap_local_page(). 2) Reorder the list of functions by decreasing order of preference of use. 3) Rework part of the kmap() entry in list. Cc: Jonathan Corbet Cc: Thomas Gleixner Cc: Matthew Wilcox Cc: Peter Zijlstra Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- Documentation/vm/highmem.rst | 73 ++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/Documentation/vm/highmem.rst b/Documentation/vm/highmem.rst index e05bf5524174..b09f1f9a81f2 100644 --- a/Documentation/vm/highmem.rst +++ b/Documentation/vm/highmem.rst @@ -50,26 +50,77 @@ space when they use mm context tags. Temporary Virtual Mappings =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =20 -The kernel contains several ways of creating temporary mappings: +The kernel contains several ways of creating temporary mappings. The follo= wing +list shows them in order of preference of use. =20 -* vmap(). This can be used to make a long duration mapping of multiple - physical pages into a contiguous virtual space. It needs global - synchronization to unmap. +* kmap_local_page(). This function is used to require short term mappings. + It can be invoked from any context (including interrupts) but the mappin= gs + can only be used in the context which acquired them. + + This function should be preferred, where feasible, over all the others. =20 -* kmap(). This permits a short duration mapping of a single page. It nee= ds - global synchronization, but is amortized somewhat. It is also prone to - deadlocks when using in a nested fashion, and so it is not recommended f= or - new code. + These mappings are per thread, CPU local (i.e., migration from one CPU to + another is disabled - this is why they are called "local"), but they don= 't + disable preemption. It's valid to take pagefaults in a local kmap region, + unless the context in which the local mapping is acquired does not allow + it for other reasons. + + kmap_local_page() always returns a valid virtual address and it is assum= ed + that kunmap_local() will never fail. + + If a task holding local kmaps is preempted, the maps are removed on cont= ext + switch and restored when the task comes back on the CPU. As the maps are + strictly CPU local, it is guaranteed that the task stays on the CPU and + that the CPU cannot be unplugged until the local kmaps are released. + + Nesting kmap_local_page() and kmap_atomic() mappings is allowed to a cer= tain + extent (up to KMAP_TYPE_NR) but their invocations have to be strictly or= dered + because the map implementation is stack based. See kmap_local_page () kd= ocs + (included in the "Functions" section) for details on how to manage nested + mappings. =20 * kmap_atomic(). This permits a very short duration mapping of a single page. Since the mapping is restricted to the CPU that issued it, it performs well, but the issuing task is therefore required to stay on that CPU until it has finished, lest some other task displace its mappings. =20 - kmap_atomic() may also be used by interrupt contexts, since it is does n= ot - sleep and the caller may not sleep until after kunmap_atomic() is called. + kmap_atomic() may also be used by interrupt contexts, since it does not + sleep and the callers too may not sleep until after kunmap_atomic() is + called. + + Each call of kmap_atomic() in the kernel creates a non-preemptible secti= on + and disable pagefaults. This could be a source of unwanted latency, so it + should be only used if it is absolutely required, otherwise kmap_local_p= age() + should be used where it is feasible. =20 - It may be assumed that k[un]map_atomic() won't fail. + It is assumed that k[un]map_atomic() won't fail. + +* kmap(). This should be used to make short duration mapping of a single + page with no restrictions on preemption or migration. It comes with an + overhead as mapping space is restricted and protected by a global lock + for synchronization. When mapping is no longer needed, the address that + the page was mapped to must be released with kunmap(). + + Mapping changes must be propagated across all the CPUs. kmap() 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. Therefore, kmap() is only callable from preemptible context. + + All the above work is necessary if a mapping must last for a relatively + long time but the bulk of high-memory mappings in the kernel are + short-lived and only used in one place. This means that the cost of + kmap() is mostly wasted in such cases. kmap() was not intended for long + term mappings but it has morphed in that direction and its use is + strongly discouraged in newer code and the set of the preceding functions + should be preferred. + + On 64-bit systems, calls to kmap_local_page(), kmap_atomic() and kmap() = have + no real work to do because a 64-bit address space is more than sufficien= t to + address all the physical memory whose pages are permanently mapped. + +* vmap(). This can be used to make a long duration mapping of multiple + physical pages into a contiguous virtual space. It needs global + synchronization to unmap. =20 =20 Cost of Temporary Mappings --=20 2.34.1