From patchwork Wed May 10 08:56:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinyoung Choi X-Patchwork-Id: 13236661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2ACCFC77B7C for ; Wed, 10 May 2023 08:56:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236872AbjEJI4U (ORCPT ); Wed, 10 May 2023 04:56:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236846AbjEJI4P (ORCPT ); Wed, 10 May 2023 04:56:15 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 781897EC5 for ; Wed, 10 May 2023 01:56:11 -0700 (PDT) Received: from epcas2p2.samsung.com (unknown [182.195.41.54]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20230510085609epoutp01fea915d187e9da96a17471a6ca0a515e~dvGMxclEK1575915759epoutp01W for ; Wed, 10 May 2023 08:56:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20230510085609epoutp01fea915d187e9da96a17471a6ca0a515e~dvGMxclEK1575915759epoutp01W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1683708969; bh=v5aifcuvT4v06m1yAYerf8h0h01yE8oqVL3cCIFGtC8=; h=Subject:Reply-To:From:To:In-Reply-To:Date:References:From; b=QeisWYDH+pcUIb/jjZqmWj9kjOeqOborClEn2r1kgCkny2ZD12tzuTCUrkOFPgoFR vWVed2KbkcSKLifspcau6Oq85O4v+e+sA9oB9ZqWFohzOm2snELr9l/unXmCbBzrRU dZCwaCFHMwgNC6j0FrAH7YNO3zQ2I51EjoThIh40= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas2p1.samsung.com (KnoxPortal) with ESMTP id 20230510085608epcas2p1febf27b02dec1003268c5c8056bb5682~dvGL35aQq1806718067epcas2p15; Wed, 10 May 2023 08:56:08 +0000 (GMT) Received: from epsmges2p3.samsung.com (unknown [182.195.36.92]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4QGTQc2M0Rz4x9QB; Wed, 10 May 2023 08:56:08 +0000 (GMT) X-AuditID: b6c32a47-e99fd70000002007-9c-645b5c28f5cc Received: from epcas2p4.samsung.com ( [182.195.41.56]) by epsmges2p3.samsung.com (Symantec Messaging Gateway) with SMTP id 79.09.08199.82C5B546; Wed, 10 May 2023 17:56:08 +0900 (KST) Mime-Version: 1.0 Subject: [PATCH v2 08/14] scsi: add scsi_alloc_integrity_sgtables() for integrity process Reply-To: j-young.choi@samsung.com Sender: Jinyoung CHOI From: Jinyoung CHOI To: Jinyoung CHOI , "axboe@kernel.dk" , "kbusch@kernel.org" , "hch@lst.de" , "sagi@grimberg.me" , "jejb@linux.ibm.com" , "martin.petersen@oracle.com" , "johannes.thumshirn@wdc.com" , "kch@nvidia.com" , "willy@infradead.org" , "linux-block@vger.kernel.org" , "linux-kernel@vger.kernel.org" X-Priority: 3 X-Content-Kind-Code: NORMAL In-Reply-To: <20230510084407epcms2p123f17696d3c30c749897eeaf2c4de684@epcms2p1> X-CPGS-Detection: blocking_info_exchange X-Drm-Type: N,general X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Message-ID: <20230510085607epcms2p3d2b2dfc5db42f77c41f570c361a41c6a@epcms2p3> Date: Wed, 10 May 2023 17:56:07 +0900 X-CMS-MailID: 20230510085607epcms2p3d2b2dfc5db42f77c41f570c361a41c6a X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P X-CPGSPASS: Y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+N4Vn6yf/kJxd8z40PrUPfxkg9Ox9f1Tn JrVlXYY9hjub0pY1iysFbPv8VCGWPaUn/Hvkg5aYDRGF+pomSbvYxBczP/abv23Xb07+NYI8 CXwKMz7ZOoY6pPfkLAh8IhsueeO6UC6XwtNjx+yunVcQmJDpVfhk693ZVc3yz1+0KnK807ve eUZfccm2qEtXvs0Jmug1O5d3a1rYGe5v34QvnzNYs2tzwKTtVSaO2RxP4uTWG9rXSYQ3Rs35 /lmJpTgj0VCLuag4EQD4eukiTQQAAA== DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230510084407epcms2p123f17696d3c30c749897eeaf2c4de684 References: <20230510084407epcms2p123f17696d3c30c749897eeaf2c4de684@epcms2p1> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Separate the integrity mapping process of scsi_alloc_sgtables() into a new function for readability. Cc: Christoph Hellwig Cc: Martin K. Petersen Signed-off-by: Jinyoung Choi --- drivers/scsi/scsi_lib.c | 71 ++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index b7c569a42aa4..89cf21345e1a 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1003,6 +1003,40 @@ static inline bool scsi_cmd_needs_dma_drain(struct scsi_device *sdev, sdev->host->hostt->dma_need_drain(rq); } +static blk_status_t scsi_alloc_integrity_sgtables(struct scsi_cmnd *cmd) +{ + struct request *rq = scsi_cmd_to_rq(cmd); + struct scsi_data_buffer *prot_sdb = cmd->prot_sdb; + int count, ivecs; + + if (WARN_ON_ONCE(!prot_sdb)) { + /* + * This can happen if someone (e.g. multipath) + * queues a command to a device on an adapter + * that does not support DIX. + */ + return BLK_STS_IOERR; + } + + ivecs = blk_rq_count_integrity_sg(rq->q, rq->bio); + + if (sg_alloc_table_chained(&prot_sdb->table, ivecs, + prot_sdb->table.sgl, + SCSI_INLINE_PROT_SG_CNT)) { + return BLK_STS_RESOURCE; + } + + count = blk_rq_map_integrity_sg(rq->q, rq->bio, prot_sdb->table.sgl); + + BUG_ON(count > ivecs); + BUG_ON(count > queue_max_integrity_segments(rq->q)); + + cmd->prot_sdb = prot_sdb; + cmd->prot_sdb->table.nents = count; + + return BLK_STS_OK; +} + /** * scsi_alloc_sgtables - Allocate and initialize data and integrity scatterlists * @cmd: SCSI command data structure to initialize. @@ -1021,7 +1055,7 @@ blk_status_t scsi_alloc_sgtables(struct scsi_cmnd *cmd) struct request *rq = scsi_cmd_to_rq(cmd); unsigned short nr_segs = blk_rq_nr_phys_segments(rq); struct scatterlist *last_sg = NULL; - blk_status_t ret; + blk_status_t ret = BLK_STS_OK; bool need_drain = scsi_cmd_needs_dma_drain(sdev, rq); int count; @@ -1071,40 +1105,11 @@ blk_status_t scsi_alloc_sgtables(struct scsi_cmnd *cmd) cmd->sdb.length = blk_rq_payload_bytes(rq); if (blk_integrity_rq(rq)) { - struct scsi_data_buffer *prot_sdb = cmd->prot_sdb; - int ivecs; - - if (WARN_ON_ONCE(!prot_sdb)) { - /* - * This can happen if someone (e.g. multipath) - * queues a command to a device on an adapter - * that does not support DIX. - */ - ret = BLK_STS_IOERR; - goto out_free_sgtables; - } - - ivecs = blk_rq_count_integrity_sg(rq->q, rq->bio); - - if (sg_alloc_table_chained(&prot_sdb->table, ivecs, - prot_sdb->table.sgl, - SCSI_INLINE_PROT_SG_CNT)) { - ret = BLK_STS_RESOURCE; - goto out_free_sgtables; - } - - count = blk_rq_map_integrity_sg(rq->q, rq->bio, - prot_sdb->table.sgl); - BUG_ON(count > ivecs); - BUG_ON(count > queue_max_integrity_segments(rq->q)); - - cmd->prot_sdb = prot_sdb; - cmd->prot_sdb->table.nents = count; + ret = scsi_alloc_integrity_sgtables(cmd); + if (ret != BLK_STS_OK) + scsi_free_sgtables(cmd); } - return BLK_STS_OK; -out_free_sgtables: - scsi_free_sgtables(cmd); return ret; } EXPORT_SYMBOL(scsi_alloc_sgtables);