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/[email protected] Signed-off-by: Fabio M. De Francesco <[email protected]> Suggested-by: Ira Weiny <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Peter Collingbourne <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
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)