kernel/power/snapshot.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
kmap_atomic() is deprecated and should be replaced with kmap_local_page()
[1][2]. kmap_local_page() is faster in kernels with HIGHMEM enabled, can
take page faults, and allows preemption.
According to [2], this replacement is safe as long as the code between
kmap_atomic() and kunmap_atomic() does not implicitly depend on disabling
page faults or preemption. In all of the call sites in this patch, the only
thing happening between mapping and unmapping pages is copy_page() calls,
and I don't suspect they depend on disabling page faults or preemption.
[1] https://lwn.net/Articles/836144/
[2] https://docs.kernel.org/mm/highmem.html#temporary-virtual-mappings
Signed-off-by: David Reaver <me@davidreaver.com>
---
kernel/power/snapshot.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index c9fb559a6399..87f4dde4a49d 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -2270,9 +2270,9 @@ int snapshot_read_next(struct snapshot_handle *handle)
*/
void *kaddr;
- kaddr = kmap_atomic(page);
+ kaddr = kmap_local_page(page);
copy_page(buffer, kaddr);
- kunmap_atomic(kaddr);
+ kunmap_local(kaddr);
handle->buffer = buffer;
} else {
handle->buffer = page_address(page);
@@ -2561,9 +2561,9 @@ static void copy_last_highmem_page(void)
if (last_highmem_page) {
void *dst;
- dst = kmap_atomic(last_highmem_page);
+ dst = kmap_page_local(last_highmem_page);
copy_page(dst, buffer);
- kunmap_atomic(dst);
+ kunmap_local(dst);
last_highmem_page = NULL;
}
}
@@ -2881,13 +2881,13 @@ static inline void swap_two_pages_data(struct page *p1, struct page *p2,
{
void *kaddr1, *kaddr2;
- kaddr1 = kmap_atomic(p1);
- kaddr2 = kmap_atomic(p2);
+ kaddr1 = kmap_local_page(p1);
+ kaddr2 = kmap_local_page(p2);
copy_page(buf, kaddr1);
copy_page(kaddr1, kaddr2);
copy_page(kaddr2, buf);
- kunmap_atomic(kaddr2);
- kunmap_atomic(kaddr1);
+ kunmap_local(kaddr2);
+ kunmap_local(kaddr1);
}
/**
Hi David,
kernel test robot noticed the following build warnings:
[auto build test WARNING on amd-pstate/linux-next]
[also build test WARNING on amd-pstate/bleeding-edge linus/master v6.13-rc6 next-20250110]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/David-Reaver/pm-Replace-deprecated-kmap_atomic-with-kmap_local_page/20250112-100253
base: https://git.kernel.org/pub/scm/linux/kernel/git/superm1/linux.git linux-next
patch link: https://lore.kernel.org/r/20250112015535.191527-1-me%40davidreaver.com
patch subject: [PATCH] pm: Replace deprecated kmap_atomic() with kmap_local_page()
config: i386-buildonly-randconfig-005-20250112 (https://download.01.org/0day-ci/archive/20250112/202501122002.vD4o8M9T-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250112/202501122002.vD4o8M9T-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202501122002.vD4o8M9T-lkp@intel.com/
All warnings (new ones prefixed by >>):
kernel/power/snapshot.c: In function 'copy_last_highmem_page':
kernel/power/snapshot.c:2567:23: error: implicit declaration of function 'kmap_page_local' [-Werror=implicit-function-declaration]
2567 | dst = kmap_page_local(last_highmem_page);
| ^~~~~~~~~~~~~~~
>> kernel/power/snapshot.c:2567:21: warning: assignment to 'void *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
2567 | dst = kmap_page_local(last_highmem_page);
| ^
cc1: some warnings being treated as errors
vim +2567 kernel/power/snapshot.c
2554
2555 /**
2556 * copy_last_highmem_page - Copy most the most recent highmem image page.
2557 *
2558 * Copy the contents of a highmem image from @buffer, where the caller of
2559 * snapshot_write_next() has stored them, to the right location represented by
2560 * @last_highmem_page .
2561 */
2562 static void copy_last_highmem_page(void)
2563 {
2564 if (last_highmem_page) {
2565 void *dst;
2566
> 2567 dst = kmap_page_local(last_highmem_page);
2568 copy_page(dst, buffer);
2569 kunmap_local(dst);
2570 last_highmem_page = NULL;
2571 }
2572 }
2573
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2026 Red Hat, Inc.