Skip to contentSkip to conversation

use bio kmap helpers in device mapper

dm-devel New Christoph Hellwig 1 participant 5 messages Oct 19, 2021 Device mapper

lore
Share & tools
lore
#1 lore raw

PATCH 1/4 dm-integrity: use bvec_kmap_local in integrity_metadata

Using local kmaps slightly reduces the chances to stray writes, and the bvec interface cleans up the code a little bit.

---
 drivers/md/dm-integrity.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/dm-integrity.c +2 -2
index dc03b70f6e65c..77c1f645f8438 100644
@@ -1765,7 +1765,7 @@ static void integrity_metadata(struct work_struct *w)
 			char *mem, *checksums_ptr;
 
 again:
-			mem = (char *)kmap_atomic(bv.bv_page) + bv.bv_offset;
+			mem = bvec_kmap_local(&bv);
 			pos = 0;
 			checksums_ptr = checksums;
 			do {
@@ -1775,7 +1775,7 @@ static void integrity_metadata(struct work_struct *w)
 				pos += ic->sectors_per_block << SECTOR_SHIFT;
 				sector += ic->sectors_per_block;
 			} while (pos < bv.bv_len && sectors_to_process && checksums != checksums_onstack);
-			kunmap_atomic(mem);
+			kunmap_local(mem);
 
 			r = dm_integrity_rw_tag(ic, checksums, &dio->metadata_block, &dio->metadata_offset,
 						checksums_ptr - checksums, dio->op == REQ_OP_READ ? TAG_CMP : TAG_WRITE);
Signature · 6 lines
2.30.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#2 lore raw

PATCH 2/4 dm-integrity: use bvec_kmap_local in __journal_read_write

In reply to Christoph Hellwig

Using local kmaps slightly reduces the chances to stray writes, and the bvec interface cleans up the code a little bit.

---
 drivers/md/dm-integrity.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/dm-integrity.c +3 -3
index 77c1f645f8438..86350d7c1175f 100644
@@ -1953,7 +1953,7 @@ static bool __journal_read_write(struct dm_integrity_io *dio, struct bio *bio,
 		n_sectors -= bv.bv_len >> SECTOR_SHIFT;
 		bio_advance_iter(bio, &bio->bi_iter, bv.bv_len);
 retry_kmap:
-		mem = kmap_atomic(bv.bv_page);
+		mem = bvec_kmap_local(&bv);
 		if (likely(dio->op == REQ_OP_WRITE))
 			flush_dcache_page(bv.bv_page);
 
@@ -1967,7 +1967,7 @@ static bool __journal_read_write(struct dm_integrity_io *dio, struct bio *bio,
 
 				if (unlikely(journal_entry_is_inprogress(je))) {
 					flush_dcache_page(bv.bv_page);
-					kunmap_atomic(mem);
+					kunmap_local(mem);
 
 					__io_wait_event(ic->copy_to_journal_wait, !journal_entry_is_inprogress(je));
 					goto retry_kmap;
@@ -2058,7 +2058,7 @@ static bool __journal_read_write(struct dm_integrity_io *dio, struct bio *bio,
 
 		if (unlikely(dio->op == REQ_OP_READ))
 			flush_dcache_page(bv.bv_page);
-		kunmap_atomic(mem);
+		kunmap_local(mem);
 	} while (n_sectors);
 
 	if (likely(dio->op == REQ_OP_WRITE)) {
Signature · 6 lines
2.30.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#3 lore raw

PATCH 3/4 dm-log-writes: use memcpy_from_bvec in log_writes_map

In reply to Christoph Hellwig

Use memcpy_from_bvec instead of open coding the logic.

---
 drivers/md/dm-log-writes.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/md/dm-log-writes.c +2 -4
index d93a4db235124..eeaf729287f06 100644
@@ -753,7 +753,7 @@ static int log_writes_map(struct dm_target *ti, struct bio *bio)
 	 */
 	bio_for_each_segment(bv, bio, iter) {
 		struct page *page;
-		void *src, *dst;
+		void *dst;
 
 		page = alloc_page(GFP_NOIO);
 		if (!page) {
@@ -765,11 +765,9 @@ static int log_writes_map(struct dm_target *ti, struct bio *bio)
 			return DM_MAPIO_KILL;
 		}
 
-		src = kmap_atomic(bv.bv_page);
 		dst = kmap_atomic(page);
-		memcpy(dst, src + bv.bv_offset, bv.bv_len);
+		memcpy_from_bvec(dst, &bv);
 		kunmap_atomic(dst);
-		kunmap_atomic(src);
 		block->vecs[i].bv_page = page;
 		block->vecs[i].bv_len = bv.bv_len;
 		block->vec_cnt++;
Signature · 6 lines
2.30.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#4 lore raw

PATCH 4/4 dm-verity: use bvec_kmap_local in verity_for_bv_block

In reply to Christoph Hellwig

Using local kmaps slightly reduces the chances to stray writes, and the bvec interface cleans up the code a little bit.

---
 drivers/md/dm-verity-target.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/dm-verity-target.c +3 -3
index aae48a8b1a048..c1403d3e9d1ea 100644
@@ -428,14 +428,14 @@ int verity_for_bv_block(struct dm_verity *v, struct dm_verity_io *io,
 		unsigned len;
 		struct bio_vec bv = bio_iter_iovec(bio, *iter);
 
-		page = kmap_atomic(bv.bv_page);
+		page = bvec_kmap_local(&bv);
 		len = bv.bv_len;
 
 		if (likely(len >= todo))
 			len = todo;
 
-		r = process(v, io, page + bv.bv_offset, len);
-		kunmap_atomic(page);
+		r = process(v, io, page, len);
+		kunmap_local(page);
 
 		if (r < 0)
 			return r;
Signature · 6 lines
2.30.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel