From patchwork Wed Dec 7 22:53:08 2022 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: 13067733 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 E7BD4C4708D for ; Wed, 7 Dec 2022 22:53:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BCA38E0005; Wed, 7 Dec 2022 17:53:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 46CC68E0001; Wed, 7 Dec 2022 17:53:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 336028E0005; Wed, 7 Dec 2022 17:53:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2150D8E0001 for ; Wed, 7 Dec 2022 17:53:20 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D5141C08AE for ; Wed, 7 Dec 2022 22:53:19 +0000 (UTC) X-FDA: 80217012918.19.DA732BF Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by imf18.hostedemail.com (Postfix) with ESMTP id 442211C0002 for ; Wed, 7 Dec 2022 22:53:17 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KXjL2cfI; spf=pass (imf18.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670453597; a=rsa-sha256; cv=none; b=f5Gnjms951r1NB02fVaCNn954Wmdhx3nad3mVo68Qd9xWW40Nhj3u4cGle4kaIlifSj+yZ Sv1CWJpqSlymn79uh0XbtRAjQynYQ9wnmLro3sl+yXkW13rxRb+7snvcGVcG+0/abeDe3R kiwOT5yDBBkKb5zmfMAnzAnfClLsS1A= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KXjL2cfI; spf=pass (imf18.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670453597; 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=HpiEQsJqjPxsOEBWR03lhLs9G9Tun7tgT+BbU2JVnqM=; b=s5c2/KjnQCSGqB7lc2XYl7C0zGQ4GOEhhKJsXhMqw9VWe8cRCOwmj4LVQC2CmeWNIi+iHQ HsvOMwedUth7hiE3bLXvTt0uE7csrLx/HlkdQgrPrWk6scR5CHZ6myZ8KZ5XW2R3dL9Vas +IX74ZbweClhvVHquTZ/Yg1RlN4CNEU= Received: by mail-wm1-f42.google.com with SMTP id c65-20020a1c3544000000b003cfffd00fc0so2218085wma.1 for ; Wed, 07 Dec 2022 14:53:16 -0800 (PST) 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=HpiEQsJqjPxsOEBWR03lhLs9G9Tun7tgT+BbU2JVnqM=; b=KXjL2cfIKBIgvx/ytT7JhyrRXAqi7DV7bxrCXM+sOdrDcD2GOwOv5ycP1DizwVgXBF qBNeH7o27ARFQQi31x9qziF33+wuYXEow8qjNuuGvdx6s+QvV6EDRIsAx1R/ZZK+9+6E f+eZAcPASZaFH7pT4EDUl+ya4wAhQS2jikI9LnKZuUSEFC/waE2+pkNAYGbuUIaH80AT z2dRCPE1x6RNvrXRDcQACbEHKuUALwlLegyQToyDuWef1ZXYdVh5l/eVoV4csoMK7+RF TlGuDixcoqD3EDJNTUTRzF0LhSyRKKhhcDj6O9g9J8U381q/zt5TO9kTW//oByM7OmyV R1vw== 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=HpiEQsJqjPxsOEBWR03lhLs9G9Tun7tgT+BbU2JVnqM=; b=j1MRB+CnfPUCI4Sx+3p+5fb2NRjTgdyndJny4229RzWER6i0AJOGJmK5zZOaZNDw7v yDvvbQ8lDPyBBr5dkWHYrckgu/RsNJ6QO1rlsCSf7FAhfKtbyolH2LZcWJR8B/d9P2KN UqciRlI2kLSMBlqvcu7gBks59lM9Al5wwGf0SRhrX9L3ZYXS1jR4OEVE6T2DcM2MbwrL kbIIq59eDp8pl9GMInEXmlCK1jXz5tXsnVWiIlFpyqILoMmRChPMOnisgP2g2ATv+Box 7a7NC3pmsdKMZEwHTa1B21Gly0d6EF6e5UqVEPeIBaiALuiRbOMiT9bois9tC+atVj5c 2eaw== X-Gm-Message-State: ANoB5pne9GpxuYJtareW5ee3+Nlmq8ecTmGWWXRaUJtmU5nCej/vtGlm Zxg0zwO/UkvvS2o3Z1c0QAc= X-Google-Smtp-Source: AA0mqf4tnmjf1HliNyoRRGtVseloKTRhEfEpPkT57aJot8dbKjBP3UEhygy7Vvu6dtPjkOj5W4521A== X-Received: by 2002:a05:600c:3647:b0:3cf:5014:c773 with SMTP id y7-20020a05600c364700b003cf5014c773mr1041611wmq.40.1670453595741; Wed, 07 Dec 2022 14:53:15 -0800 (PST) Received: from localhost.localdomain (host-79-26-108-238.retail.telecomitalia.it. [79.26.108.238]) by smtp.gmail.com with ESMTPSA id l39-20020a05600c1d2700b003c6c4639ac6sm3338273wms.34.2022.12.07.14.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 14:53:14 -0800 (PST) From: "Fabio M. De Francesco" To: Jonathan Corbet , "Fabio M. De Francesco" , Andrew Morton , Sebastian Andrzej Siewior , Ira Weiny , Mike Rapoport , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Rapoport , Peter Zijlstra , Thomas Gleixner Subject: [PATCH v2] mm/highmem: Add notes about conversions from kmap{,_atomic}() Date: Wed, 7 Dec 2022 23:53:08 +0100 Message-Id: <20221207225308.8290-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 442211C0002 X-Rspamd-Server: rspam01 X-Stat-Signature: 5j8mhsy9zon76g1eyp96gxux1a5ajc97 X-HE-Tag: 1670453597-980412 X-HE-Meta: U2FsdGVkX1/5YG35xwyoNM7U5f5FPjEyUxYZGr7AiQNWpRFGYsVRl6i0hT8v6Xj1Fpjsi1BHGcLpFKpg8AyVyfDw0BKjBYEyPpaASzs+3Hbulw9qJ06S7fGqYZsruE0l3Ey0VznWMNqpyQkk5ZnKX2xnypqZcZn48tQBpvuure+mwswseNikAOv+sy0WTSP0WV1Xd9NGgK5fg2yOZN+4zyGDqYJbf1bEYprzeKHxCFG6DzDbm3D8M4LXBc8ARvIPofvYL7TC1AOz1jerRbHzv7CeVLOthVM/H2sTDBqDYgPcvohREuy8wQqxCJ+uQxc7A6riFciwg/ek0p+3fLjAceaIw2UmacifsI349YPUufFRnfyKL2XgObDuf+SbDjTnqPQ9mIV1UqxTEEJYmp4EXM6yWQjKACYdrtPIwzAsLw08/hxbufOCghaJ4egRQVtajQRRa7O6cl0F0yehAipkg4hwpP/tmdTRJROzER7+8XokvZRkBDt3qu1WKjuBKwSIUIR5tGHevohjLR5jDCEURzttUnUhLuPrnSP4xz26jHyREUAAybOMmkab5cMZ9D8aso2GbZHab8PRXW8+5I9wM6ZWdOKAv9BCbCDSR6+355RfJ1ho6+g5UxdFUSL0dcuISaYIvZzGkh7FUS+CoYXbxp5BE2d4+4u4U13d7anxhCYXwvR+vF6bc+wsybP2dPYyu/bloI+Z3acDBxq+HDgAtzQCZ0IWr7v7GXxTiCSUrPQHDYjZGQwANVfygiN3bqqItI9r/4Me6Uxvvu2CkK4wc2TYr8EyZekkscm6lC6d5Ip7so2xHAcK7w3kQ/bxtnAloaRgrssxpQ8YJc0tgIFKhkBRo3AWjM1PYcvPGkBSBZFv1ZVBSgL2bIQyv/8zp9KxrJsfaQCbGYNchBAf+eNTelUkuqNvxEx/b2iq5j9GMY1/bBrcOhwCjXgRN1jXv3iCT08wxsT4vX9F3R+nsGA ZI2kyRKv T3Fy4kA1ubAOtEREiLq76RHVBIAz/HZtxqZF2MyunYK5fMwdem68ubdqWvYDOMXjkHTtrRORNAaSYTK5QpBLPVxmqvW9Fv35hYyA8ad9Tk5JIi+Ml3KZgutjBwUZEfCGv3EeqdadtBx/Uh2GHGWXyXerrNF07I9p/RMBkyHUdL9iJ8aL1WyBR1Jw04g== 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: kmap() and kmap_atomic() have been deprecated. kmap_local_page() should always be used in new code and the call sites of the two deprecated functions should be converted. This latter task can lead to errors if it is not carried out with the necessary attention to the context around and between the maps and unmaps. Therefore, add further information to the Highmem's documentation for the purpose to make it clearer that (1) kmap() and kmap_atomic() must not any longer be called in new code and (2) developers doing conversions from kmap() amd kmap_atomic() are expected to take care of the context around and between the maps and unmaps, in order to not break the code. Relevant parts of this patch have been taken from messages exchanged privately with Ira Weiny (thanks!). Cc: Andrew Morton Cc: Ira Weiny Cc: Jonathan Corbet Cc: Mike Rapoport Cc: Peter Zijlstra Cc: Sebastian Andrzej Siewior Cc: Thomas Gleixner Signed-off-by: Fabio M. De Francesco --- v1->v2: Reworked part of the "Notes" paragraph in the kmap_atomic() section in order to leave less room for misinterpretation. I've made these changes by merging some suggestions from Sebastian (thanks!), although I'm not yet entirely sure I've achieved crystal clear exposition. Documentation/mm/highmem.rst | 41 +++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/Documentation/mm/highmem.rst b/Documentation/mm/highmem.rst index 0f731d9196b0..59d1078f53df 100644 --- a/Documentation/mm/highmem.rst +++ b/Documentation/mm/highmem.rst @@ -57,7 +57,8 @@ list shows them in order of preference of use. 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 be preferred, where feasible, over all the others. + This function should always be used. kmap_atomic() and kmap() have been + deprecated. These mappings are thread-local and CPU-local, meaning that the mapping can only be accessed from within this thread and the thread is bound to the @@ -100,10 +101,21 @@ list shows them in order of preference of use. (included in the "Functions" section) for details on how to manage nested mappings. -* 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. +* kmap_atomic(). This function has been deprecated; use kmap_local_page(). + + NOTE: Conversions to kmap_local_page() must take care to follow the mapping + restrictions imposed on kmap_local_page(). Furthermore, the code between + calls to kmap_atomic() and kunmap_atomic() may implicitly depend on the side + effects of atomic mappings, i.e. disabling page faults or preemption, or both. + In that case, explicit calls to pagefault_disable() or preempt_disable() or + both must be made in conjunction with the use of kmap_local_page(). + + [Legacy documentation] + + 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. 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 @@ -115,11 +127,20 @@ list shows them in order of preference of use. 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(). +* kmap(). This function has been deprecated; use kmap_local_page(). + + NOTE: Conversions to kmap_local_page() must take care to follow the mapping + restrictions imposed on kmap_local_page(). In particular, it is necessary to + make sure that the kernel virtual memory pointer is only valid in the thread + that obtained it. + + [Legacy documentation] + + 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