From patchwork Fri May 21 03:01:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12271773 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A7F6C433B4 for ; Fri, 21 May 2021 03:02:19 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7B5C561353 for ; Fri, 21 May 2021 03:02:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B5C561353 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=dm-devel-bounces@redhat.com Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-440-3Fo76Qj3NPO3GHltQXALuQ-1; Thu, 20 May 2021 23:02:15 -0400 X-MC-Unique: 3Fo76Qj3NPO3GHltQXALuQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01E3D107ACC7; Fri, 21 May 2021 03:02:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D45305D9DC; Fri, 21 May 2021 03:02:11 +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 A3801180B465; Fri, 21 May 2021 03:02:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14L31awl013485 for ; Thu, 20 May 2021 23:01:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9C31510552CE; Fri, 21 May 2021 03:01:36 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 974FB1055241 for ; Fri, 21 May 2021 03:01:36 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7FE0C80122D for ; Fri, 21 May 2021 03:01:36 +0000 (UTC) Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-371-e2WZcYS4PpGLI-0TSVcq1Q-1; Thu, 20 May 2021 23:01:34 -0400 X-MC-Unique: e2WZcYS4PpGLI-0TSVcq1Q-1 IronPort-SDR: WoUEfFO6ppndAEvdJBaJas+ux+Jqc9MXoRTVgwe95fCUZQXblknvZ1XN98v+sMoBL32FQfFFiL 2Wjdn4kEV9McwKl9wDCsaF3oMqniez2WENV6g4H4ZB95nsCWSCQ4nwrdukd4rz+Bx9x9O7VhzG drG6SkwY7AJ9Xv7WrCdl1pje3X1BYj2yUsX3IuUgLBeIJyXeFyCf793DU4uvEQGABP5Jt8uba/ CMdfykRHczIAns3BPEVnyUxrkX2yjsrz2hT1UhuWbD6XZ8IvRLyLdD8uA/CHSgsN13/OCZpz6W SWw= X-IronPort-AV: E=Sophos;i="5.82,313,1613404800"; d="scan'208";a="173591095" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 21 May 2021 11:01:31 +0800 IronPort-SDR: y9dTSQf3avkm3adXAGOMsnq9p5nam42MZj40rRuJX/mYt3iMwORTuZW/OJy9sG31Bz9OMvDIzw zllC4fpAo8JoCNid+nbF9hy0EIBCn6SRTTro+YRR2Wm2fcHZcXOjv/12kAS3ANeLfIx4gGvDEF f1oQSI9P8847N8Yo03CAyDJMTztMEnK3hjIw4flU4/BRglTedUjZb8DyQ9qwzg8IerN5YcngyZ ULwuRX7V+3i9ZGE7wajHtlL3znEYQ10SG3iObxf5MoUwKakJvly88xBtzMYnOCCFrwdj9EkPeY sSPoN77m3a67T/RCBOcQg51P Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2021 19:41:08 -0700 IronPort-SDR: RAD/kYBdYh3LJ64YeVuAYXWHENoCW0YElm3jtEfobVEjhQ9kzBBjCH/iPr+ASuy0nMAsjNe8DS /SaYZ8aeSBDlwWztzeUk0zbcOoX5BI8Jw1GybLeW8ajgbCZjOKJAmQe7SuxMjWZF6hEwIeLKwC t6DC/qW6w+Rtfg932+ugEJ347giEQKNN7+8QbILwY/DWmDxp8c5WuOri9ZBu49bmFbZiAsQl+W k2PuYAqDitp4GT4e3sCfIHxTQ89alh7WQ2O2YQTlFNNgBXdG5mCB8A/X9d2Ze7/cFGDG1psREs 07I= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 20 May 2021 20:01:32 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Date: Fri, 21 May 2021 12:01:16 +0900 Message-Id: <20210521030119.1209035-9-damien.lemoal@wdc.com> In-Reply-To: <20210521030119.1209035-1-damien.lemoal@wdc.com> References: <20210521030119.1209035-1-damien.lemoal@wdc.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH v3 08/11] dm: Forbid requeue of writes to zones 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: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com A target map method requesting the requeue of a bio with DM_MAPIO_REQUEUE or completing it with DM_ENDIO_REQUEUE can cause unaligned write errors if the bio is a write operation targeting a sequential zone. If a zoned target request such a requeue, warn about it and kill the IO. The function dm_is_zone_write() is introduced to detect write operations to zoned targets. This change does not affect the target drivers supporting zoned devices and exposing a zoned device, namely dm-crypt, dm-linear and dm-flakey as none of these targets ever request a requeue. Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Johannes Thumshirn --- drivers/md/dm-zone.c | 17 +++++++++++++++++ drivers/md/dm.c | 18 +++++++++++++++--- drivers/md/dm.h | 5 +++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c index b42474043249..edc3bbb45637 100644 --- a/drivers/md/dm-zone.c +++ b/drivers/md/dm-zone.c @@ -104,6 +104,23 @@ int dm_report_zones(struct block_device *bdev, sector_t start, sector_t sector, } EXPORT_SYMBOL_GPL(dm_report_zones); +bool dm_is_zone_write(struct mapped_device *md, struct bio *bio) +{ + struct request_queue *q = md->queue; + + if (!blk_queue_is_zoned(q)) + return false; + + switch (bio_op(bio)) { + case REQ_OP_WRITE_ZEROES: + case REQ_OP_WRITE_SAME: + case REQ_OP_WRITE: + return !op_is_flush(bio->bi_opf) && bio_sectors(bio); + default: + return false; + } +} + void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q) { if (!blk_queue_is_zoned(q)) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 45d2dc2ee844..4426019a89cc 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -846,11 +846,15 @@ static void dec_pending(struct dm_io *io, blk_status_t error) * Target requested pushing back the I/O. */ spin_lock_irqsave(&md->deferred_lock, flags); - if (__noflush_suspending(md)) + if (__noflush_suspending(md) && + !WARN_ON_ONCE(dm_is_zone_write(md, bio))) /* NOTE early return due to BLK_STS_DM_REQUEUE below */ bio_list_add_head(&md->deferred, io->orig_bio); else - /* noflush suspend was interrupted. */ + /* + * noflush suspend was interrupted or this is + * a write to a zoned target. + */ io->status = BLK_STS_IOERR; spin_unlock_irqrestore(&md->deferred_lock, flags); } @@ -947,7 +951,15 @@ static void clone_endio(struct bio *bio) int r = endio(tio->ti, bio, &error); switch (r) { case DM_ENDIO_REQUEUE: - error = BLK_STS_DM_REQUEUE; + /* + * Requeuing writes to a sequential zone of a zoned + * target will break the sequential write pattern: + * fail such IO. + */ + if (WARN_ON_ONCE(dm_is_zone_write(md, bio))) + error = BLK_STS_IOERR; + else + error = BLK_STS_DM_REQUEUE; fallthrough; case DM_ENDIO_DONE: break; diff --git a/drivers/md/dm.h b/drivers/md/dm.h index fdf1536a4b62..39c243258e24 100644 --- a/drivers/md/dm.h +++ b/drivers/md/dm.h @@ -107,8 +107,13 @@ void dm_set_zones_restrictions(struct dm_table *t, struct request_queue *q); #ifdef CONFIG_BLK_DEV_ZONED int dm_blk_report_zones(struct gendisk *disk, sector_t sector, unsigned int nr_zones, report_zones_cb cb, void *data); +bool dm_is_zone_write(struct mapped_device *md, struct bio *bio); #else #define dm_blk_report_zones NULL +static inline bool dm_is_zone_write(struct mapped_device *md, struct bio *bio) +{ + return false; +} #endif /*-----------------------------------------------------------------