From patchwork Tue Jun 26 00:10:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10487603 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 062A860230 for ; Tue, 26 Jun 2018 00:10:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E94ED28668 for ; Tue, 26 Jun 2018 00:10:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB0142870C; Tue, 26 Jun 2018 00:10:16 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 E69B028668 for ; Tue, 26 Jun 2018 00:10:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755797AbeFZAKM (ORCPT ); Mon, 25 Jun 2018 20:10:12 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:6902 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934154AbeFZAKL (ORCPT ); Mon, 25 Jun 2018 20:10:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1529971812; x=1561507812; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=pNSpEJjcd7gCX/Sx7KsIU7dNrLWyJx7fZzTxUC4p6fY=; b=m77JsgTBU6FrFvA3fyIQaegY4PEIxtxECu3hs3hj47XPjPl0kNSW7Auu nnoKTS0hJvQ+ntWViM+s4HgN8x3a5G2c7qG1o5fw39YWVfX+J+SJ6jJn6 /fSxFCpRloN1I7HemXlTNTnuH3/9vkfR2gse7CukCiPYLoskfjJb9A1jA p0hSMrY59xUu3DqPamdanichQGHCZemchCYM1u5tQfgI7EDKa6Th3sbBf nFMD42vLZ9j/oDWGB8ALJKIx9Nt38YROGXII6Djpu/ysS2KpIUxne0RxY V0SE05tAWpDR0AgKOah0i9xH5rZuj01N7ly+8gccEatsSEemajVtCKQ9e g==; X-IronPort-AV: E=Sophos;i="5.51,272,1526313600"; d="scan'208";a="81809623" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 26 Jun 2018 08:10:11 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 25 Jun 2018 16:59:30 -0700 Received: from thinkpad-bart.sdcorp.global.sandisk.com ([10.111.67.248]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2018 17:10:10 -0700 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Ming Lei Subject: [PATCH 1/3] block: Fix blk_rq_payload_bytes() Date: Mon, 25 Jun 2018 17:10:07 -0700 Message-Id: <20180626001009.16557-2-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180626001009.16557-1-bart.vanassche@wdc.com> References: <20180626001009.16557-1-bart.vanassche@wdc.com> 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 SCSI sd driver converts a block layer request into a SCSI WRITE SAME command in the following cases: 1. REQ_OP_DISCARD if the sd driver has been configured to translate this request type into WRITE SAME. 2. REQ_OP_WRITE_SAME. The SCSI sd driver sets RQF_SPECIAL_PAYLOAD in case (1) but not in case (2). Make sure that blk_rq_payload_bytes() handles both cases correctly. Fixes: 2e3258ecfaeb ("block: add blk_rq_payload_bytes") Signed-off-by: Bart Van Assche Cc: Christoph Hellwig Cc: Ming Lei --- include/linux/blkdev.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index dcf5e0990bfa..b7519a5c1002 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1091,15 +1091,19 @@ static inline unsigned int blk_rq_zone_is_seq(struct request *rq) #endif /* CONFIG_BLK_DEV_ZONED */ /* - * Some commands like WRITE SAME have a payload or data transfer size which - * is different from the size of the request. Any driver that supports such - * commands using the RQF_SPECIAL_PAYLOAD flag needs to use this helper to - * calculate the data transfer size. + * Some commands like DISCARD and WRITE SAME have a payload size which is + * different from the number of bytes affected on the storage medium. Any + * driver that supports such commands needs to use this helper to calculate + * the data buffer size. */ -static inline unsigned int blk_rq_payload_bytes(struct request *rq) +static inline unsigned int blk_rq_payload_bytes(const struct request *rq) { if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) return rq->special_vec.bv_len; + if (req_op(rq) == REQ_OP_WRITE_SAME) { + WARN_ON_ONCE(rq->bio->bi_vcnt != 1); + return rq->bio->bi_io_vec->bv_len; + } return blk_rq_bytes(rq); }