Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7019256rwb; Mon, 5 Dec 2022 23:14:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ljzbtKf9Kb05GD8+/kQeZadu5AzfoDkMl5orxZ7dcglnaOsUxFrvCiL/w+D3jGndcVXPy X-Received: by 2002:a17:902:b40b:b0:188:ca57:ce0c with SMTP id x11-20020a170902b40b00b00188ca57ce0cmr74149367plr.57.1670310888260; Mon, 05 Dec 2022 23:14:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670310888; cv=none; d=google.com; s=arc-20160816; b=O8X1MgQI9G5GkJ4S0B9MdxD9zLulyLM4qnFrQK6XI1NPJ4mEPsAjex5zdeizB5AlE2 JEIR3IpS47oQiqGwQeWu+8gWr380k4gt5bdmZje1lISNQJ3HpdTNBW7XlQkwUhFwPegD u5Jndk6j+tMatfmILgFeODATeg/ZHrf42WK0PZiA1R7D1ITBcrtbYlQ8Tz4UXr01RQr9 mxBJToku6ZPoIkBYFqVJSbz3WQjZ8Nm7FetRabIP9yfXgNb7i/A23hThed9TBy3zMfcy rx+4Rcw9rI515Se+/m8FsRJZzBNQEbn9M7eDY9kcG8GM2g3yoWUt4hgWF/ADf+dsVUsc fdWg== 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=P97r2c1GXauiwyVZKp573X9iPgDxxANKiNnZxGB6wLk=; b=LYcYqCxfrLBFU6rrCKAzstTcmPnAoxuHaFQGJM2+YMc6HDR9Op0LnMJxR38q3IgpKL jh74+N933VWhNo86SuKTfdJk2d1GmG9C6eVNQEHN/wH0nlXmBG7K1gLdxmIA9yf2bDQN DN22/jevKnxxsynObaOFQDQ4a/EpXP5NhIi+x8MqxzkK+mMCCGQ/v+EKosODVlIQhyrL w19ErZ7o+vl/PIhJnjBvBK22Bw1TWgrIT3vqObHRvbejqORCYzKfJwaX3veFXvCiRvua 1sL1Ia590ht7A2hE+RmBVp8kd6LECsKsVeU035/41vElZ+Esids9ZIFYORRH17A/Y95w bF+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Nids9vLD; 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 k7-20020a056a00134700b00554e240fa1bsi17963827pfu.95.2022.12.05.23.14.37; Mon, 05 Dec 2022 23:14:48 -0800 (PST) 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=Nids9vLD; 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 S234092AbiLFHAj (ORCPT + 80 others); Tue, 6 Dec 2022 02:00:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbiLFHAh (ORCPT ); Tue, 6 Dec 2022 02:00:37 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6947D23173; Mon, 5 Dec 2022 23:00:36 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id v7so10496005wmn.0; Mon, 05 Dec 2022 23:00:36 -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=P97r2c1GXauiwyVZKp573X9iPgDxxANKiNnZxGB6wLk=; b=Nids9vLDVijoiPSTlFco9YxkZu3SKe7mqXwVtqGmQ8yHv+WTeIiNOV+wET1qQApI8I KMDEHMlGUdXHc/qzwVkulOzz/nKXtIrxaY8uWArAGbtknTkrzfngG+JlMrOe5h7xlUwd 9My9CIHJ0G/eEpBCVUKIBCapnTkjItqqpLpkUPqo1w9auNEjqUSbbL8tSGCyYl57SQHg LNkB+fdh5agzZbTB9Xf82SxNbCQkjV8HjRGXC3meh9x+7CWCK9fziWd8/mRsSsfD0W6X fRQfnufqmVjgT43KHc/I9EU4hTmj/FMwcdRP3GZzbQDTAzwFJpJ7ZosnlsRq6XUXkTnV 1ntg== 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=P97r2c1GXauiwyVZKp573X9iPgDxxANKiNnZxGB6wLk=; b=oND0+BNrard5NdSI3nlKbw4H5sd7CM6YhDQah1lnc+0HLSGt6r4qdZCl+vAjgskl+V EohlGy/jk4qBteo7jYpZdVtdIVTBZ0wYh3sY4HAHYXuUhco4p84bByTDP6xr2ZCD5JoP S12+maC/saowkEryOBEMSTW988pufnTaKOlk9in/Mmps49aXtPNXf8g9tZ6hcNxcHXYa Uj1s2zoDae2QKwDSLMvGsc73GKb6+M8QIk9qgm20pRzVeRUc9dXYjZIEZuZnAR0jIHTk hGVbk8Nnu6hM20FLdeilm1DStYYiqygtpZzJdQf8j+z0srk7rOBpon4q0NrH8UfGT5BT hGSw== X-Gm-Message-State: ANoB5pkzmNb6Gan/32Gvd9FraeCwtk3WuRWSndYBJAl9gPjkbfkFwysB wnwAgxhxXkV0uLdytqT8+jQ= X-Received: by 2002:a05:600c:4f51:b0:3b4:a6c4:70fb with SMTP id m17-20020a05600c4f5100b003b4a6c470fbmr49115209wmq.79.1670310034579; Mon, 05 Dec 2022 23:00:34 -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 t16-20020a5d6910000000b0024217e7aaa7sm15652605wru.50.2022.12.05.23.00.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 23:00:33 -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] mm/highmem: Add notes about conversions from kmap{,_atomic}() Date: Tue, 6 Dec 2022 08:00:29 +0100 Message-Id: <20221206070029.7342-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.38.1 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 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 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 --- 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..9523e92299f6 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, code between the + map/unmap operations may implicitly depended on the side effects of + kmap_atomic(), such as disabling pagefaults, migration, and/or preemption. + Such conversions should be changed to make explicit calls for those + requirements. + + [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 -- 2.38.1