From patchwork Wed Jul 25 14:22:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Edwards X-Patchwork-Id: 10544125 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 C626A112B for ; Wed, 25 Jul 2018 14:38:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5C152A1C1 for ; Wed, 25 Jul 2018 14:38:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A93332A1CC; Wed, 25 Jul 2018 14:38:53 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BAC22A1C1 for ; Wed, 25 Jul 2018 14:38:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728631AbeGYPuv (ORCPT ); Wed, 25 Jul 2018 11:50:51 -0400 Received: from legacy.ddn.com ([64.47.133.206]:21860 "EHLO legacy.ddn.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727881AbeGYPuv (ORCPT ); Wed, 25 Jul 2018 11:50:51 -0400 Received: from LAX-EX-CAHT3.datadirect.datadirectnet.com (10.8.103.85) by LAX-EX-CAHT3.datadirect.datadirectnet.com (10.8.103.85) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 25 Jul 2018 07:23:47 -0700 Received: from LAX-EX-CAHT1.datadirect.datadirectnet.com (10.8.103.81) by LAX-EX-CAHT3.datadirect.datadirectnet.com (10.8.103.85) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Wed, 25 Jul 2018 07:23:47 -0700 Received: from soma.datadirect.datadirectnet.com (10.48.114.40) by LAX-EX-CAHT1.datadirect.datadirectnet.com (10.8.103.81) with Microsoft SMTP Server (TLS) id 14.3.389.1; Wed, 25 Jul 2018 07:23:46 -0700 From: Greg Edwards To: , CC: Jens Axboe , "Martin K. Petersen" , Greg Edwards Subject: [PATCH 1/2] block: move bio_integrity_{intervals,bytes} into blkdev.h Date: Wed, 25 Jul 2018 10:22:58 -0400 Message-ID: <20180725142259.20562-2-gedwards@ddn.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180725142259.20562-1-gedwards@ddn.com> References: <20180725142259.20562-1-gedwards@ddn.com> MIME-Version: 1.0 X-Originating-IP: [10.48.114.40] Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This allows bio_integrity_bytes() to be called from drivers instead of open coding it. Signed-off-by: Greg Edwards Acked-by: Martin K. Petersen --- block/bio-integrity.c | 22 ---------------------- include/linux/blkdev.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index add7c7c85335..67b5fb861a51 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -159,28 +159,6 @@ int bio_integrity_add_page(struct bio *bio, struct page *page, } EXPORT_SYMBOL(bio_integrity_add_page); -/** - * bio_integrity_intervals - Return number of integrity intervals for a bio - * @bi: blk_integrity profile for device - * @sectors: Size of the bio in 512-byte sectors - * - * Description: The block layer calculates everything in 512 byte - * sectors but integrity metadata is done in terms of the data integrity - * interval size of the storage device. Convert the block layer sectors - * to the appropriate number of integrity intervals. - */ -static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, - unsigned int sectors) -{ - return sectors >> (bi->interval_exp - 9); -} - -static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, - unsigned int sectors) -{ - return bio_integrity_intervals(bi, sectors) * bi->tuple_size; -} - /** * bio_integrity_process - Process integrity metadata for a bio * @bio: bio to generate/verify integrity metadata for diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 79226ca8f80f..553cc97900f6 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1877,6 +1877,28 @@ static inline bool integrity_req_gap_front_merge(struct request *req, bip_next->bip_vec[0].bv_offset); } +/** + * bio_integrity_intervals - Return number of integrity intervals for a bio + * @bi: blk_integrity profile for device + * @sectors: Size of the bio in 512-byte sectors + * + * Description: The block layer calculates everything in 512 byte + * sectors but integrity metadata is done in terms of the data integrity + * interval size of the storage device. Convert the block layer sectors + * to the appropriate number of integrity intervals. + */ +static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, + unsigned int sectors) +{ + return sectors >> (bi->interval_exp - 9); +} + +static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, + unsigned int sectors) +{ + return bio_integrity_intervals(bi, sectors) * bi->tuple_size; +} + #else /* CONFIG_BLK_DEV_INTEGRITY */ struct bio; @@ -1950,6 +1972,18 @@ static inline bool integrity_req_gap_front_merge(struct request *req, return false; } +static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, + unsigned int sectors) +{ + return 0; +} + +static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, + unsigned int sectors) +{ + return 0; +} + #endif /* CONFIG_BLK_DEV_INTEGRITY */ struct block_device_operations { From patchwork Wed Jul 25 14:22:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Edwards X-Patchwork-Id: 10544093 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 3ACD2112B for ; Wed, 25 Jul 2018 14:29:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A08A2A100 for ; Wed, 25 Jul 2018 14:29:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E53F2A14B; Wed, 25 Jul 2018 14:29:35 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA8AF2A100 for ; Wed, 25 Jul 2018 14:29:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728490AbeGYPl3 (ORCPT ); Wed, 25 Jul 2018 11:41:29 -0400 Received: from legacy.ddn.com ([64.47.133.206]:5294 "EHLO legacy.ddn.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728051AbeGYPl2 (ORCPT ); Wed, 25 Jul 2018 11:41:28 -0400 Received: from LAX-EX-CAHT1.datadirect.datadirectnet.com (10.8.103.81) by LAX-EX-CAHT2.datadirect.datadirectnet.com (10.8.103.82) with Microsoft SMTP Server (TLS) id 14.3.389.1; Wed, 25 Jul 2018 07:24:07 -0700 Received: from soma.datadirect.datadirectnet.com (10.48.114.40) by LAX-EX-CAHT1.datadirect.datadirectnet.com (10.8.103.81) with Microsoft SMTP Server (TLS) id 14.3.389.1; Wed, 25 Jul 2018 07:24:06 -0700 From: Greg Edwards To: , CC: Jens Axboe , "Martin K. Petersen" , Greg Edwards Subject: [PATCH 2/2] scsi: virtio_scsi: fix pi_bytes{out,in} on 4 KiB block size devices Date: Wed, 25 Jul 2018 10:22:59 -0400 Message-ID: <20180725142259.20562-3-gedwards@ddn.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180725142259.20562-1-gedwards@ddn.com> References: <20180725142259.20562-1-gedwards@ddn.com> MIME-Version: 1.0 X-Originating-IP: [10.48.114.40] Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The current calculation for pi_bytes{out,in} assumes a 512 byte logical block size and a protection interval exponent of 0, i.e. 512 bytes data + 8 bytes PI. When run on a 4 KiB logical block size device with a protection interval exponent of 0, i.e. 4096 bytes data + 8 bytes PI, the driver miscalculates the pi_bytes{out,in} by a factor of 8x (64 bytes). This leads to errors on all reads and writes on 4 KiB logical block size devices when CONFIG_BLK_DEV_INTEGRITY is enabled and the VIRTIO_SCSI_F_T10_PI feature bit has been negotiated. Fixes: e6dc783a38ec0 ("virtio-scsi: Enable DIF/DIX modes in SCSI host LLD") Signed-off-by: Greg Edwards Acked-by: Martin K. Petersen --- drivers/scsi/virtio_scsi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index 6dc8891ccb74..a1e85ab76f74 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c @@ -513,12 +513,12 @@ static void virtio_scsi_init_hdr_pi(struct virtio_device *vdev, if (sc->sc_data_direction == DMA_TO_DEVICE) cmd_pi->pi_bytesout = cpu_to_virtio32(vdev, - blk_rq_sectors(rq) * - bi->tuple_size); + bio_integrity_bytes(bi, + blk_rq_sectors(rq))); else if (sc->sc_data_direction == DMA_FROM_DEVICE) cmd_pi->pi_bytesin = cpu_to_virtio32(vdev, - blk_rq_sectors(rq) * - bi->tuple_size); + bio_integrity_bytes(bi, + blk_rq_sectors(rq))); } #endif