From patchwork Tue Nov 13 13:04:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 10680589 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 723811709 for ; Tue, 13 Nov 2018 13:05:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F9C42855C for ; Tue, 13 Nov 2018 13:05:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 519662A889; Tue, 13 Nov 2018 13:05:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BCB772855C for ; Tue, 13 Nov 2018 13:05:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D1123084293; Tue, 13 Nov 2018 13:05:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0C9D5C1A1; Tue, 13 Nov 2018 13:05:33 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C93FD3D385; Tue, 13 Nov 2018 13:05:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wADD4jT2007891 for ; Tue, 13 Nov 2018 08:04:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9F3AC1A7E9; Tue, 13 Nov 2018 13:04:45 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 98C9B1A7E6 for ; Tue, 13 Nov 2018 13:04:43 +0000 (UTC) Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 26C56307DABD for ; Tue, 13 Nov 2018 13:04:43 +0000 (UTC) Received: by mail-pg1-f199.google.com with SMTP id h10so5582819pgv.20 for ; Tue, 13 Nov 2018 05:04:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xU3lmeQBsM2EaR0vPYmgJoZeTqlXhZ4LJ3hJiKLmxIw=; b=ZuBFfF+BG+c7vfo1QFbnH/+p4A/GD2tJc/Q/uG0r8Wgq53JM0MovUcXGFA0RN069bq 80GniGXBErM/fLr90fvRNWhAbBqhhtoJK6Ubd0SJSFK7rIXYghuLcat4wSp9DOvZYUuM gFUk2XXGrNJP2KgNKzPLGrJk0ZEt8FO0G8PBSgedTkGwdKdtsdfs0fvc2pjbooSeINph 171yGUeucog6W40RDQ8Io30kE6N22m/Mo7H5HY8MO23znxysMsD5vdlYGA8fagSO8Ocm wQigEk3LnpOg0nA5F53DSFvI6SiU8lHgEMqMyzV21mIg8QvJMNjr/tcLkyn6QUg7kMgS eA/g== X-Gm-Message-State: AGRZ1gInfAeWA/7OpGZ0tUIZf/YyHSxn0SGrywB5UysAdrvKMgshQvUs Lh4pxDL6gwto5ORXQE2fUGBH7/YhztMQSH24/kYdhSxHC/yLpoFMjy+4vGXezD8RI/Kyr17UdC5 UJfHyHJ8UUEx1DvM= X-Received: by 2002:a17:902:3283:: with SMTP id z3-v6mr5079449plb.308.1542114282637; Tue, 13 Nov 2018 05:04:42 -0800 (PST) X-Google-Smtp-Source: AJdET5d1DFpyNWcZcS76/sOlnql5scjDuyPRyvaaA31on9upeJRx0b3/aLIiUFQyEy43D7W8w5WBpQ== X-Received: by 2002:a17:902:3283:: with SMTP id z3-v6mr5079427plb.308.1542114282400; Tue, 13 Nov 2018 05:04:42 -0800 (PST) Received: from pbitcolo-build-14.permabit.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id z127-v6sm15000538pfz.135.2018.11.13.05.04.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Nov 2018 05:04:41 -0800 (PST) From: Sweet Tea X-Google-Original-From: "Sweet Tea" Received: by pbitcolo-build-14.permabit.com (sSMTP sendmail emulation); Tue, 13 Nov 2018 08:04:33 -0500 To: Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com Date: Tue, 13 Nov 2018 08:04:24 -0500 Message-Id: <1542114264-13420-1-git-send-email-jdorminy@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: John Dorminy Subject: [dm-devel] [PATCH] dm flakey: Properly corrupt multi-page bios. X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 13 Nov 2018 13:05:37 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP The flakey target is documented to be able to corrupt the Nth byte in a bio, but does not corrupt byte indices after the first biovec in the bio. Change the corrupting function to actually corrupt the Nth byte no matter in which biovec that index falls. A test device generating two-page bios, atop a flakey device configured to corrupt a byte index on the second page, verified both the failure to corrupt before this patch and the expected corruption after this change. Signed-off-by: John Dorminy --- drivers/md/dm-flakey.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm-flakey.c b/drivers/md/dm-flakey.c index 3cb97fa..75a206c 100644 --- a/drivers/md/dm-flakey.c +++ b/drivers/md/dm-flakey.c @@ -287,20 +287,31 @@ static void flakey_map_bio(struct dm_target *ti, struct bio *bio) static void corrupt_bio_data(struct bio *bio, struct flakey_c *fc) { - unsigned bio_bytes = bio_cur_bytes(bio); - char *data = bio_data(bio); + unsigned int corrupt_bio_byte = fc->corrupt_bio_byte - 1; + + struct bvec_iter iter; + struct bio_vec bvec; + + if (!bio_has_data(bio)) + return; /* - * Overwrite the Nth byte of the data returned. + * Overwrite the Nth byte of the bio's data, on whichever page + * it falls. */ - if (data && bio_bytes >= fc->corrupt_bio_byte) { - data[fc->corrupt_bio_byte - 1] = fc->corrupt_bio_value; - - DMDEBUG("Corrupting data bio=%p by writing %u to byte %u " - "(rw=%c bi_opf=%u bi_sector=%llu cur_bytes=%u)\n", - bio, fc->corrupt_bio_value, fc->corrupt_bio_byte, - (bio_data_dir(bio) == WRITE) ? 'w' : 'r', bio->bi_opf, - (unsigned long long)bio->bi_iter.bi_sector, bio_bytes); + bio_for_each_segment(bvec, bio, iter) { + if (bio_iter_len(bio, iter) > corrupt_bio_byte) { + char *segment = (page_address(bio_iter_page(bio, iter)) + + bio_iter_offset(bio, iter)); + segment[corrupt_bio_byte] = fc->corrupt_bio_value; + DMDEBUG("Corrupting data bio=%p by writing %u to byte %u " + "(rw=%c bi_opf=%u bi_sector=%llu size=%u)\n", + bio, fc->corrupt_bio_value, fc->corrupt_bio_byte, + (bio_data_dir(bio) == WRITE) ? 'w' : 'r', bio->bi_opf, + (unsigned long long)bio->bi_iter.bi_sector, bio->bi_iter.bi_size); + break; + } + corrupt_bio_byte -= bio_iter_len(bio, iter); } }