Skip to content

Commit 4fa9161

Browse files
jdreaverliu-song-6
authored andcommitted
md: Replace deprecated kmap_atomic() with kmap_local_page()
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 is safe as long as the code between kmap_atomic() and kunmap_atomic() does not implicitly depend on disabling page faults or preemption. It appears to me that none of the call sites in this patch depend on disabling page faults or preemption; they are all mapping a page to simply extract some information from it or print some debug info. [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> Link: https://lore.kernel.org/r/20250108192131.46843-1-me@davidreaver.com Signed-off-by: Song Liu <song@kernel.org>
1 parent 127186c commit 4fa9161

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

drivers/md/md-bitmap.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ static void bitmap_update_sb(void *data)
682682
return;
683683
if (!bitmap->storage.sb_page) /* no superblock */
684684
return;
685-
sb = kmap_atomic(bitmap->storage.sb_page);
685+
sb = kmap_local_page(bitmap->storage.sb_page);
686686
sb->events = cpu_to_le64(bitmap->mddev->events);
687687
if (bitmap->mddev->events < bitmap->events_cleared)
688688
/* rocking back to read-only */
@@ -702,7 +702,7 @@ static void bitmap_update_sb(void *data)
702702
sb->nodes = cpu_to_le32(bitmap->mddev->bitmap_info.nodes);
703703
sb->sectors_reserved = cpu_to_le32(bitmap->mddev->
704704
bitmap_info.space);
705-
kunmap_atomic(sb);
705+
kunmap_local(sb);
706706

707707
if (bitmap->storage.file)
708708
write_file_page(bitmap, bitmap->storage.sb_page, 1);
@@ -717,7 +717,7 @@ static void bitmap_print_sb(struct bitmap *bitmap)
717717

718718
if (!bitmap || !bitmap->storage.sb_page)
719719
return;
720-
sb = kmap_atomic(bitmap->storage.sb_page);
720+
sb = kmap_local_page(bitmap->storage.sb_page);
721721
pr_debug("%s: bitmap file superblock:\n", bmname(bitmap));
722722
pr_debug(" magic: %08x\n", le32_to_cpu(sb->magic));
723723
pr_debug(" version: %u\n", le32_to_cpu(sb->version));
@@ -736,7 +736,7 @@ static void bitmap_print_sb(struct bitmap *bitmap)
736736
pr_debug(" sync size: %llu KB\n",
737737
(unsigned long long)le64_to_cpu(sb->sync_size)/2);
738738
pr_debug("max write behind: %u\n", le32_to_cpu(sb->write_behind));
739-
kunmap_atomic(sb);
739+
kunmap_local(sb);
740740
}
741741

742742
/*
@@ -760,15 +760,15 @@ static int md_bitmap_new_disk_sb(struct bitmap *bitmap)
760760
return -ENOMEM;
761761
bitmap->storage.sb_index = 0;
762762

763-
sb = kmap_atomic(bitmap->storage.sb_page);
763+
sb = kmap_local_page(bitmap->storage.sb_page);
764764

765765
sb->magic = cpu_to_le32(BITMAP_MAGIC);
766766
sb->version = cpu_to_le32(BITMAP_MAJOR_HI);
767767

768768
chunksize = bitmap->mddev->bitmap_info.chunksize;
769769
BUG_ON(!chunksize);
770770
if (!is_power_of_2(chunksize)) {
771-
kunmap_atomic(sb);
771+
kunmap_local(sb);
772772
pr_warn("bitmap chunksize not a power of 2\n");
773773
return -EINVAL;
774774
}
@@ -803,7 +803,7 @@ static int md_bitmap_new_disk_sb(struct bitmap *bitmap)
803803
sb->events_cleared = cpu_to_le64(bitmap->mddev->events);
804804
bitmap->mddev->bitmap_info.nodes = 0;
805805

806-
kunmap_atomic(sb);
806+
kunmap_local(sb);
807807

808808
return 0;
809809
}
@@ -865,7 +865,7 @@ static int md_bitmap_read_sb(struct bitmap *bitmap)
865865
return err;
866866

867867
err = -EINVAL;
868-
sb = kmap_atomic(sb_page);
868+
sb = kmap_local_page(sb_page);
869869

870870
chunksize = le32_to_cpu(sb->chunksize);
871871
daemon_sleep = le32_to_cpu(sb->daemon_sleep) * HZ;
@@ -932,7 +932,7 @@ static int md_bitmap_read_sb(struct bitmap *bitmap)
932932
err = 0;
933933

934934
out:
935-
kunmap_atomic(sb);
935+
kunmap_local(sb);
936936
if (err == 0 && nodes && (bitmap->cluster_slot < 0)) {
937937
/* Assigning chunksize is required for "re_read" */
938938
bitmap->mddev->bitmap_info.chunksize = chunksize;
@@ -1161,12 +1161,12 @@ static void md_bitmap_file_set_bit(struct bitmap *bitmap, sector_t block)
11611161
bit = file_page_offset(&bitmap->storage, chunk);
11621162

11631163
/* set the bit */
1164-
kaddr = kmap_atomic(page);
1164+
kaddr = kmap_local_page(page);
11651165
if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags))
11661166
set_bit(bit, kaddr);
11671167
else
11681168
set_bit_le(bit, kaddr);
1169-
kunmap_atomic(kaddr);
1169+
kunmap_local(kaddr);
11701170
pr_debug("set file bit %lu page %lu\n", bit, index);
11711171
/* record page number so it gets flushed to disk when unplug occurs */
11721172
set_page_attr(bitmap, index - node_offset, BITMAP_PAGE_DIRTY);
@@ -1190,12 +1190,12 @@ static void md_bitmap_file_clear_bit(struct bitmap *bitmap, sector_t block)
11901190
if (!page)
11911191
return;
11921192
bit = file_page_offset(&bitmap->storage, chunk);
1193-
paddr = kmap_atomic(page);
1193+
paddr = kmap_local_page(page);
11941194
if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags))
11951195
clear_bit(bit, paddr);
11961196
else
11971197
clear_bit_le(bit, paddr);
1198-
kunmap_atomic(paddr);
1198+
kunmap_local(paddr);
11991199
if (!test_page_attr(bitmap, index - node_offset, BITMAP_PAGE_NEEDWRITE)) {
12001200
set_page_attr(bitmap, index - node_offset, BITMAP_PAGE_PENDING);
12011201
bitmap->allclean = 0;
@@ -1214,12 +1214,12 @@ static int md_bitmap_file_test_bit(struct bitmap *bitmap, sector_t block)
12141214
if (!page)
12151215
return -EINVAL;
12161216
bit = file_page_offset(&bitmap->storage, chunk);
1217-
paddr = kmap_atomic(page);
1217+
paddr = kmap_local_page(page);
12181218
if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags))
12191219
set = test_bit(bit, paddr);
12201220
else
12211221
set = test_bit_le(bit, paddr);
1222-
kunmap_atomic(paddr);
1222+
kunmap_local(paddr);
12231223
return set;
12241224
}
12251225

@@ -1388,9 +1388,9 @@ static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
13881388
* If the bitmap is out of date, dirty the whole page
13891389
* and write it out
13901390
*/
1391-
paddr = kmap_atomic(page);
1391+
paddr = kmap_local_page(page);
13921392
memset(paddr + offset, 0xff, PAGE_SIZE - offset);
1393-
kunmap_atomic(paddr);
1393+
kunmap_local(paddr);
13941394

13951395
filemap_write_page(bitmap, i, true);
13961396
if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) {
@@ -1406,12 +1406,12 @@ static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
14061406
void *paddr;
14071407
bool was_set;
14081408

1409-
paddr = kmap_atomic(page);
1409+
paddr = kmap_local_page(page);
14101410
if (test_bit(BITMAP_HOSTENDIAN, &bitmap->flags))
14111411
was_set = test_bit(bit, paddr);
14121412
else
14131413
was_set = test_bit_le(bit, paddr);
1414-
kunmap_atomic(paddr);
1414+
kunmap_local(paddr);
14151415

14161416
if (was_set) {
14171417
/* if the disk bit is set, set the memory bit */
@@ -1546,10 +1546,10 @@ static void bitmap_daemon_work(struct mddev *mddev)
15461546
bitmap_super_t *sb;
15471547
bitmap->need_sync = 0;
15481548
if (bitmap->storage.filemap) {
1549-
sb = kmap_atomic(bitmap->storage.sb_page);
1549+
sb = kmap_local_page(bitmap->storage.sb_page);
15501550
sb->events_cleared =
15511551
cpu_to_le64(bitmap->events_cleared);
1552-
kunmap_atomic(sb);
1552+
kunmap_local(sb);
15531553
set_page_attr(bitmap, 0,
15541554
BITMAP_PAGE_NEEDWRITE);
15551555
}

drivers/md/raid5-cache.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,10 +1023,10 @@ int r5l_write_stripe(struct r5l_log *log, struct stripe_head *sh)
10231023
/* checksum is already calculated in last run */
10241024
if (test_bit(STRIPE_LOG_TRAPPED, &sh->state))
10251025
continue;
1026-
addr = kmap_atomic(sh->dev[i].page);
1026+
addr = kmap_local_page(sh->dev[i].page);
10271027
sh->dev[i].log_checksum = crc32c_le(log->uuid_checksum,
10281028
addr, PAGE_SIZE);
1029-
kunmap_atomic(addr);
1029+
kunmap_local(addr);
10301030
}
10311031
parity_pages = 1 + !!(sh->qd_idx >= 0);
10321032
data_pages = write_disks - parity_pages;
@@ -1979,9 +1979,9 @@ r5l_recovery_verify_data_checksum(struct r5l_log *log,
19791979
u32 checksum;
19801980

19811981
r5l_recovery_read_page(log, ctx, page, log_offset);
1982-
addr = kmap_atomic(page);
1982+
addr = kmap_local_page(page);
19831983
checksum = crc32c_le(log->uuid_checksum, addr, PAGE_SIZE);
1984-
kunmap_atomic(addr);
1984+
kunmap_local(addr);
19851985
return (le32_to_cpu(log_checksum) == checksum) ? 0 : -EINVAL;
19861986
}
19871987

@@ -2381,11 +2381,11 @@ r5c_recovery_rewrite_data_only_stripes(struct r5l_log *log,
23812381
payload->size = cpu_to_le32(BLOCK_SECTORS);
23822382
payload->location = cpu_to_le64(
23832383
raid5_compute_blocknr(sh, i, 0));
2384-
addr = kmap_atomic(dev->page);
2384+
addr = kmap_local_page(dev->page);
23852385
payload->checksum[0] = cpu_to_le32(
23862386
crc32c_le(log->uuid_checksum, addr,
23872387
PAGE_SIZE));
2388-
kunmap_atomic(addr);
2388+
kunmap_local(addr);
23892389
sync_page_io(log->rdev, write_pos, PAGE_SIZE,
23902390
dev->page, REQ_OP_WRITE, false);
23912391
write_pos = r5l_ring_add(log, write_pos,
@@ -2888,10 +2888,10 @@ int r5c_cache_data(struct r5l_log *log, struct stripe_head *sh)
28882888

28892889
if (!test_bit(R5_Wantwrite, &sh->dev[i].flags))
28902890
continue;
2891-
addr = kmap_atomic(sh->dev[i].page);
2891+
addr = kmap_local_page(sh->dev[i].page);
28922892
sh->dev[i].log_checksum = crc32c_le(log->uuid_checksum,
28932893
addr, PAGE_SIZE);
2894-
kunmap_atomic(addr);
2894+
kunmap_local(addr);
28952895
pages++;
28962896
}
28972897
WARN_ON(pages == 0);

0 commit comments

Comments
 (0)