fs/ecryptfs: Replace kmap() with kmap_local_page()
authorFabio M. De Francesco <fmdefrancesco@gmail.com>
Wed, 26 Apr 2023 17:22:21 +0000 (19:22 +0200)
committerChristian Brauner <brauner@kernel.org>
Mon, 10 Jul 2023 12:36:10 +0000 (14:36 +0200)
commit8b70deb8ca901d45e2342d654c1e8d306f52e6cb
tree535c8dc007fbe0e31f629a591a9eded40d11661b
parent06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
fs/ecryptfs: Replace kmap() with kmap_local_page()

kmap() has been deprecated in favor of kmap_local_page().

Therefore, replace kmap() with kmap_local_page() in fs/ecryptfs.

There are two main problems with kmap(): (1) It comes with an overhead as
the mapping space is restricted and protected by a global lock for
synchronization and (2) it 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.

With kmap_local_page() the mappings are per thread, CPU local, can take
page faults, and can be called from any context (including interrupts).
It is faster than kmap() in kernels with HIGHMEM enabled. The tasks can
be preempted and, when they are scheduled to run again, the kernel
virtual addresses are restored and still valid.

Obviously, thread locality implies that the kernel virtual addresses
returned by kmap_local_page() are only valid in the context of the
callers (i.e., they cannot be handed to other threads).

The use of kmap_local_page() in fs/ecryptfs does not break the
above-mentioned assumption, so it is allowed and preferred.

Tested in a QEMU/KVM x86_32 VM, 6GB RAM, booting a kernel with
HIGHMEM64GB enabled.

Suggested-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
Message-Id: <20230426172223.8896-2-fmdefrancesco@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/ecryptfs/crypto.c
fs/ecryptfs/read_write.c