Skip to content

Commit 6b3afe2

Browse files
xp4ns3akpm00
authored andcommitted
Documentation/mm: avoid invalid use of addresses from kmap_local_page()
Users of kmap_local_page() must be absolutely sure to not hand kernel virtual address obtained calling kmap_local_page() on highmem pages to other contexts because those pointers are thread local, therefore, they are no longer valid across different contexts. Extend the documentation of kmap_local_page() to warn users about the above-mentioned potential invalid use of pointers returned by kmap_local_page(). Link: https://lkml.kernel.org/r/20220728154844.10874-5-fmdefrancesco@gmail.com Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Suggested-by: Ira Weiny <ira.weiny@intel.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Mike Rapoport <rppt@linux.ibm.com> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Peter Collingbourne <pcc@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 516ea04 commit 6b3afe2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Documentation/mm/highmem.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ list shows them in order of preference of use.
7777
for pages which are known to not come from ZONE_HIGHMEM. However, it is
7878
always safe to use kmap_local_page() / kunmap_local().
7979

80+
While it is significantly faster than kmap(), for the higmem case it
81+
comes with restrictions about the pointers validity. Contrary to kmap()
82+
mappings, the local mappings are only valid in the context of the caller
83+
and cannot be handed to other contexts. This implies that users must
84+
be absolutely sure to keep the use of the return address local to the
85+
thread which mapped it.
86+
8087
Nesting kmap_local_page() and kmap_atomic() mappings is allowed to a certain
8188
extent (up to KMAP_TYPE_NR) but their invocations have to be strictly ordered
8289
because the map implementation is stack based. See kmap_local_page() kdocs

0 commit comments

Comments
 (0)