[Devel] [PATCH RHEL7 COMMIT] ploop: Check that nobody writes to ZERO_PAGE()

Konstantin Khorenko khorenko at virtuozzo.com
Tue Aug 6 13:25:13 MSK 2019


The commit is pushed to "branch-rh7-3.10.0-957.21.3.vz7.106.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.21.3.vz7.106.7
------>
commit 3a44b99ce15ef953953e898b3cbab3e204fae3d3
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Tue Aug 6 13:25:11 2019 +0300

    ploop: Check that nobody writes to ZERO_PAGE()
    
    ploop juggles this aux_bio, reuses it from time to time,
    so it's easy to make a mistake and to reuse a zero page.
    Say, we use zero page in ploop_entry_nullify_req() after
    fill_zero_bio(), and later PLOOP_E_RELOC_NULLIFY state
    may become PLOOP_E_ENTRY, which is just generic state
    of all requests.
    
    For beter debug and detection of such the cases, add
    the debug check to be safe against the above mistakes.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/block/ploop/dev.c       | 5 ++++-
 drivers/block/ploop/io_direct.c | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index 64d205e691ba..6fb95f0fadb6 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -1583,6 +1583,7 @@ static void bio_bcopy(struct bio *dst, struct bio *src, struct ploop_device *plo
 		if (copy > PAGE_SIZE - poff)
 			copy = PAGE_SIZE - poff;
 
+		WARN_ON_ONCE(bv->bv_page == ZERO_PAGE(0));
 		ksrc = kmap_atomic(bv->bv_page);
 		memcpy(page_address(dst->bi_io_vec[didx].bv_page) + poff,
 		       ksrc + bv->bv_offset + bv_off,
@@ -2768,9 +2769,11 @@ static void ploop_req_state_process(struct ploop_request * preq)
 				break;
 			}
 
-			for (i = 0; i < preq->aux_bio->bi_vcnt; i++)
+			for (i = 0; i < preq->aux_bio->bi_vcnt; i++) {
+				WARN_ON_ONCE(preq->aux_bio->bi_io_vec[i].bv_page == ZERO_PAGE(0));
 				memset(page_address(preq->aux_bio->bi_io_vec[i].bv_page),
 				       0, PAGE_SIZE);
+			}
 
 			bio_list_for_each(b, &preq->bl) {
 				bio_bcopy(preq->aux_bio, b, plo);
diff --git a/drivers/block/ploop/io_direct.c b/drivers/block/ploop/io_direct.c
index abee1b2ae15c..6b4fd667ff71 100644
--- a/drivers/block/ploop/io_direct.c
+++ b/drivers/block/ploop/io_direct.c
@@ -348,6 +348,7 @@ static void bcopy_from_blist(struct page *page, int dst_off, /* dst */
 		u8 *ksrc;
 		int copy = MIN(copy_len, biter->bv->bv_len - biter->off);
 
+		WARN_ON_ONCE(biter->bv->bv_page == ZERO_PAGE(0));
 		ksrc = kmap_atomic(biter->bv->bv_page);
 		memcpy(kdst + dst_off,
 		       ksrc + biter->bv->bv_offset + biter->off,



More information about the Devel mailing list