From patchwork Tue May 25 02:25:39 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: 12277617 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 B2EB5C2B9F7 for ; Tue, 25 May 2021 02:26:18 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.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 3FFFE613EC for ; Tue, 25 May 2021 02:26:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3FFFE613EC 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-199-Uh6a53P8MlunxS2EkeH7aw-1; Mon, 24 May 2021 22:26:15 -0400 X-MC-Unique: Uh6a53P8MlunxS2EkeH7aw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F342180FD62; Tue, 25 May 2021 02:26:10 +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 77DDB687E6; Tue, 25 May 2021 02:26:10 +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 4C35E59CD2; Tue, 25 May 2021 02:26:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14P2PvRl027738 for ; Mon, 24 May 2021 22:25:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5DCD09C051; Tue, 25 May 2021 02:25:57 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 581F39C05B for ; Tue, 25 May 2021 02:25:56 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.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 4166E80D0E6 for ; Tue, 25 May 2021 02:25:56 +0000 (UTC) Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-354-OSywuF-PMRiRs1T3c3gYGQ-4; Mon, 24 May 2021 22:25:54 -0400 X-MC-Unique: OSywuF-PMRiRs1T3c3gYGQ-4 IronPort-SDR: H1DlRJ5HyocMOKL1EkTu0xJtfXguvBGbtILMXnhk8kut7IMwM8ZbsdW0G1CQUdvba8/fIyiu0B Uv15b6xHH7q11yzOVuEKPIz0QsxvCK3xt+ljeCjbl+p79B1dwS1cE+OJw0qKDozNLsmfJOSrqX mnYySfhx72Y4IIM+ua9PauLQ0M6fbFFSvrk0u/iKYbDYzREvEvQutAQ8ktZtCtGKTZ7KUJmLeI 638sqz/KfonCWpOFKhnZzRZSnpY8pAiMbmwJ7swUW9UozfR63UQ3PwziTFYqGa6wA5SGi28CAm zYc= X-IronPort-AV: E=Sophos;i="5.82,327,1613404800"; d="scan'208";a="273213797" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 25 May 2021 10:26:56 +0800 IronPort-SDR: GnuSrRckQrhdxYe34YFeA7VUF3znCrMAnPcO4QFLpT3Nuri8mMOpqYi+106hIg10jD3NL7uqqF QCqD88sk/47FwbervpOT3JDMqi38LmWJz8aamNb4JZ7otaNJPXCcrmWt47F2OiYSKpu/pQ7Lxq lZwuaVO2adydBDtkjwPwlXCpuBI29k6rBdsubub2pm3Lp9vX5/4OV2THTOZv2RuDzgya7Iuwo2 d98AXvK6d/JXD2nAecMXNqOvtNhLa9/DUqw5DQoTy3nNpc036jluKupD6gbLtcVNndOAFshJaV HLVqHmmP7kYufx6nI1DFsSpT Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2021 19:04:08 -0700 IronPort-SDR: oEOKXEdbvYxZSVW+jMMzY8LIseyUt/eSLLs0v9t0+4YtGgwansZMcF2C8yc6LQ48pQlwNRUk3v RuLluZ6B8r+AIJ1JZqgIF/zXj0cdQkwDWme2/rKhtFhOVyDOWb1quU3/C/DjrNAxxLkJWgaJsL 2qFwWwCXJLXv4gYW8RNo84gQufmCV0KqvB3Fu9XYfodwp/joTtnZ2zVaxix3Ih0g+34yYMqNOL OrrNKHVzBit8oPIu2OyJ8kJkwijlNwPtqrnMi8Ks/fSbrXaHcV1ZoGnJTFI/d0lFBOG/lPOYUf eMc= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 24 May 2021 19:25:52 -0700 From: Damien Le Moal To: dm-devel@redhat.com, Mike Snitzer , linux-block@vger.kernel.org, Jens Axboe Date: Tue, 25 May 2021 11:25:39 +0900 Message-Id: <20210525022539.119661-12-damien.lemoal@wdc.com> In-Reply-To: <20210525022539.119661-1-damien.lemoal@wdc.com> References: <20210525022539.119661-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.79 on 10.11.54.5 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH v4 11/11] dm crypt: Fix zoned block device support 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.13 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 Zone append BIOs (REQ_OP_ZONE_APPEND) always specify the start sector of the zone to be written instead of the actual sector location to write. The write location is determined by the device and returned to the host upon completion of the operation. This interface, while simple and efficient for writing into sequential zones of a zoned block device, is incompatible with the use of sector values to calculate a cypher block IV. All data written in a zone end up using the same IV values corresponding to the first sectors of the zone, but read operation will specify any sector within the zone resulting in an IV mismatch between encryption and decryption. To solve this problem, report to DM core that zone append operations are not supported. This result in the zone append operations being emulated using regular write operations. Reported-by: Shin'ichiro Kawasaki Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Himanshu Madhani --- drivers/md/dm-crypt.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index f410ceee51d7..50f4cbd600d5 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -3280,14 +3280,28 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv) } cc->start = tmpll; - /* - * For zoned block devices, we need to preserve the issuer write - * ordering. To do so, disable write workqueues and force inline - * encryption completion. - */ if (bdev_is_zoned(cc->dev->bdev)) { + /* + * For zoned block devices, we need to preserve the issuer write + * ordering. To do so, disable write workqueues and force inline + * encryption completion. + */ set_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags); set_bit(DM_CRYPT_WRITE_INLINE, &cc->flags); + + /* + * All zone append writes to a zone of a zoned block device will + * have the same BIO sector, the start of the zone. When the + * cypher IV mode uses sector values, all data targeting a + * zone will be encrypted using the first sector numbers of the + * zone. This will not result in write errors but will + * cause most reads to fail as reads will use the sector values + * for the actual data locations, resulting in IV mismatch. + * To avoid this problem, ask DM core to emulate zone append + * operations with regular writes. + */ + DMDEBUG("Zone append operations will be emulated"); + ti->emulate_zone_append = true; } if (crypt_integrity_aead(cc) || cc->integrity_iv_size) {