[RH8] ploop: Zero tail of tail page

Submitted by Kirill Tkhai on Dec. 10, 2020, 11:52 a.m.

Details

Message ID 160760109410.111441.12360268753961624039.stgit@localhost.localdomain
State New
Series "ploop: Zero tail of tail page"
Headers show

Commit Message

Kirill Tkhai Dec. 10, 2020, 11:52 a.m.
In case of BAT ends in middle of page, zero its tail.
Otherwise, garbage is there.

https://jira.sw.ru/browse/PSBM-123639
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/md/dm-ploop-bat.c |    5 +++++
 drivers/md/dm-ploop.h     |    1 +
 2 files changed, 6 insertions(+)

Patch hide | download patch | download mbox

diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index d6b687806118..da18dd2e4638 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -168,6 +168,11 @@  static int ploop_read_bat(struct ploop *ploop, struct bio *bio)
 			from = kmap(bio->bi_io_vec[page].bv_page);
 			memcpy(to, from, nr_copy * sizeof(map_index_t));
 			kunmap(bio->bi_io_vec[page].bv_page);
+			if (unlikely(nr_copy < BAT_ENTRIES_PER_PAGE)) {
+				memset(from + nr_copy, 0, sizeof(map_index_t) *
+				       (BAT_ENTRIES_PER_PAGE - nr_copy));
+			}
+
 			ret = parse_bat_entries(ploop, to, md->bat_levels,
 						nr_copy, id);
 			kunmap(md->page);
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index dc5362f01e21..a025df4bf328 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -6,6 +6,7 @@ 
 
 #define PLOOP_MAP_OFFSET 16
 typedef u32 map_index_t;
+#define BAT_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(map_index_t))
 
 #define SIGNATURE_DISK_IN_USE           0x746F6E59