From patchwork Wed Nov 23 20:57:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 628163 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 495BFC433FE for ; Wed, 23 Nov 2022 20:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235823AbiKWU63 (ORCPT ); Wed, 23 Nov 2022 15:58:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239268AbiKWU6M (ORCPT ); Wed, 23 Nov 2022 15:58:12 -0500 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89AACF02D; Wed, 23 Nov 2022 12:58:11 -0800 (PST) Received: by mail-pj1-f47.google.com with SMTP id x13-20020a17090a46cd00b00218f611b6e9so1276941pjg.1; Wed, 23 Nov 2022 12:58:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pLbbN/1qbe+HxyJXe7G2OJd9lUGhOuHPJTNebNcpj5I=; b=0Ew7oUNov/C4LPwoR9i4zEM32v5rTM+Kb3ZOMqune2amhErCLPYrRunEBFQpD/qJA2 91cEprlK1FvCzPRWihL65fLWvzuBWr/CpmtDOpDbPWf4WSfUpq/GST+7FhB4OT7LTUdS mhhv2ikBmzN4KBei14EjjyAQrDDGjhmwh1/9NhAKPjYuptYgo+elRGQcjd1HB3cvx8X7 t+MDc5De5WIihrk4Ylf3u+EC+AeohBau3fv5HX4mra43l/zcuiXeWtTEX4wEjc2TwKoA 900jtQ8E+cH/Zz/TT7D7qrqmcFznADIQgy0yPdTBmXzddPHqi7ZDUCknOVolMMDUF7+/ nVog== X-Gm-Message-State: ANoB5pkwd/y3b6W2jybUvhfCvtWjDSI+9daB1NZ1ogOg/jhnrgJEVERq +OejhYBWKNI9mEwSGMW5MVg= X-Google-Smtp-Source: AA0mqf6Jl8uOa4Rz1+yh5/7zZycqw7TPxBJCyJ7DCDV8obZokSAlOtp2ltoe5u1/pUfxbhCMra5Pqw== X-Received: by 2002:a17:902:ea91:b0:186:880c:1680 with SMTP id x17-20020a170902ea9100b00186880c1680mr12576845plb.164.1669237090934; Wed, 23 Nov 2022 12:58:10 -0800 (PST) Received: from bvanassche-glaptop2.roam.corp.google.com ([2601:642:4c02:686d:4311:4764:eee7:ac6d]) by smtp.gmail.com with ESMTPSA id i89-20020a17090a3de200b0020b2082e0acsm1858809pjc.0.2022.11.23.12.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 12:58:10 -0800 (PST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Adrian Hunter , Avri Altman , Bart Van Assche , Ming Lei , Keith Busch Subject: [PATCH v2 4/8] block: Add support for filesystem requests and small segments Date: Wed, 23 Nov 2022 12:57:36 -0800 Message-Id: <20221123205740.463185-5-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221123205740.463185-1-bvanassche@acm.org> References: <20221123205740.463185-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add support in the bio splitting code and also in the bio submission code for bios with segments smaller than the page size. Cc: Christoph Hellwig Cc: Ming Lei Cc: Keith Busch Signed-off-by: Bart Van Assche --- block/blk-merge.c | 6 ++++-- block/blk-mq.c | 2 ++ block/blk.h | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 35a8f75cc45d..7badfbed09fc 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -294,7 +294,8 @@ static struct bio *bio_split_rw(struct bio *bio, const struct queue_limits *lim, if (nsegs < lim->max_segments && bytes + bv.bv_len <= max_bytes && bv.bv_offset + bv.bv_len <= PAGE_SIZE) { - nsegs++; + /* single-page bvec optimization */ + nsegs += blk_segments(lim, bv.bv_len); bytes += bv.bv_len; } else { if (bvec_split_segs(lim, &bv, &nsegs, &bytes, @@ -531,7 +532,8 @@ static int __blk_bios_map_sg(struct request_queue *q, struct bio *bio, __blk_segment_map_sg_merge(q, &bvec, &bvprv, sg)) goto next_bvec; - if (bvec.bv_offset + bvec.bv_len <= PAGE_SIZE) + if (bvec.bv_offset + bvec.bv_len <= PAGE_SIZE && + bvec.bv_len <= q->limits.max_segment_size) nsegs += __blk_bvec_map_sg(bvec, sglist, sg); else nsegs += blk_bvec_map_sg(q, &bvec, sglist, sg); diff --git a/block/blk-mq.c b/block/blk-mq.c index f72164429446..1560e4f76f2d 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2953,6 +2953,8 @@ void blk_mq_submit_bio(struct bio *bio) bio = blk_queue_bounce(bio, q); if (bio_may_exceed_limits(bio, &q->limits)) bio = __bio_split_to_limits(bio, &q->limits, &nr_segs); + else if (bio->bi_vcnt == 1) + nr_segs = blk_segments(&q->limits, bio->bi_io_vec[0].bv_len); if (!bio_integrity_prep(bio)) return; diff --git a/block/blk.h b/block/blk.h index fb486eff3eef..c45f86b74b1d 100644 --- a/block/blk.h +++ b/block/blk.h @@ -320,7 +320,7 @@ static inline bool bio_may_exceed_limits(struct bio *bio, } /* - * All drivers must accept single-segments bios that are <= PAGE_SIZE. + * Check whether bio splitting should be performed. * This is a quick and dirty check that relies on the fact that * bi_io_vec[0] is always valid if a bio has data. The check might * lead to occasional false negatives when bios are cloned, but compared @@ -328,6 +328,7 @@ static inline bool bio_may_exceed_limits(struct bio *bio, * doesn't matter anyway. */ return lim->chunk_sectors || bio->bi_vcnt != 1 || + bio->bi_io_vec->bv_len > lim->max_segment_size || bio->bi_io_vec->bv_len + bio->bi_io_vec->bv_offset > PAGE_SIZE; } From patchwork Wed Nov 23 20:57:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 628162 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 51A3DC433FE for ; Wed, 23 Nov 2022 20:58:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236332AbiKWU6d (ORCPT ); Wed, 23 Nov 2022 15:58:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239286AbiKWU6N (ORCPT ); Wed, 23 Nov 2022 15:58:13 -0500 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C88A140C0; Wed, 23 Nov 2022 12:58:13 -0800 (PST) Received: by mail-pj1-f49.google.com with SMTP id k5so16838660pjo.5; Wed, 23 Nov 2022 12:58:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Wi2GoAyFUTgrX+Rf06IdeXck2r4WJc+cBT1lfqDw3xY=; b=7KPdZBcRl5RL7CrSyKMqzzyRnqgBH5TwreJ7FaUVAI//sjzPB87lhz5nP7zNqbCHZK oTBejhcCEEeqSoZSI+eotpHOSpNWkHLRGNYz9nzP/ul6TRxrlxo26PcpERlL+oiQbKBS Nx5AuVxvJ3t/WpLMxelQe/FW05Jr+/z/RxxULulzcNyMtsPmV36I8kde0vRkC36jwBt0 6UL6k1/5Eq/B6EmEMCq5NAT7rcPJNuEzmfB37GziNyrUcRe16c4LE1KLHDJBOhHs/HDS Yl/7NvXpQBZwWX8g9iie+Rv5G+pY/dWhf4oe8h/FTSG98/CBXXzoXL/Td90wnTOAefPY iDDQ== X-Gm-Message-State: ANoB5pnyDaQCx7UPxJgD+2nIKe1alHCp/h83VZK/T3NR1M5E4HX8XE8r eVC5tE3BM5nIAxJFK+h/bdg= X-Google-Smtp-Source: AA0mqf7JLxx2EB1MmUPgcoW8eaI7dcQjvOeS5t4YGMA4EzQEoDZFVU7fffM1286cjbbLsUKB7y5xTw== X-Received: by 2002:a17:90a:7b8f:b0:218:b477:98e0 with SMTP id z15-20020a17090a7b8f00b00218b47798e0mr16210151pjc.173.1669237092704; Wed, 23 Nov 2022 12:58:12 -0800 (PST) Received: from bvanassche-glaptop2.roam.corp.google.com ([2601:642:4c02:686d:4311:4764:eee7:ac6d]) by smtp.gmail.com with ESMTPSA id i89-20020a17090a3de200b0020b2082e0acsm1858809pjc.0.2022.11.23.12.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 12:58:11 -0800 (PST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Adrian Hunter , Avri Altman , Bart Van Assche , Ming Lei , Keith Busch Subject: [PATCH v2 5/8] block: Add support for small segments in blk_rq_map_user_iov() Date: Wed, 23 Nov 2022 12:57:37 -0800 Message-Id: <20221123205740.463185-6-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221123205740.463185-1-bvanassche@acm.org> References: <20221123205740.463185-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Before changing the return value of bio_add_hw_page() into a value in the range [0, len], make blk_rq_map_user_iov() fall back to copying data if mapping the data is not possible due to the segment limit. Cc: Christoph Hellwig Cc: Ming Lei Cc: Keith Busch Signed-off-by: Bart Van Assche --- block/blk-map.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index d2d6ee098514..f3f2ed9c6183 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -308,17 +308,26 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, else { for (j = 0; j < npages; j++) { struct page *page = pages[j]; - unsigned int n = PAGE_SIZE - offs; + unsigned int n = PAGE_SIZE - offs, added; bool same_page = false; if (n > bytes) n = bytes; - if (!bio_add_hw_page(rq->q, bio, page, n, offs, - max_sectors, &same_page)) { + added = bio_add_hw_page(rq->q, bio, page, n, + offs, max_sectors, &same_page); + if (added == 0) { if (same_page) put_page(page); break; + } else if (added != n) { + /* + * The segment size is smaller than the + * page size and an iov exceeds the + * segment size. Give up. + */ + ret = -EREMOTEIO; + goto out_unmap; } bytes -= n; @@ -672,10 +681,18 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq, i = *iter; do { - if (copy) + if (copy) { ret = bio_copy_user_iov(rq, map_data, &i, gfp_mask); - else + } else { ret = bio_map_user_iov(rq, &i, gfp_mask); + /* + * Fall back to copying the data if bio_map_user_iov() + * returns -EREMOTEIO. + */ + if (ret == -EREMOTEIO) + ret = bio_copy_user_iov(rq, map_data, &i, + gfp_mask); + } if (ret) goto unmap_rq; if (!bio) From patchwork Wed Nov 23 20:57:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 628165 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 779C6C433FE for ; Wed, 23 Nov 2022 20:58:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234403AbiKWU6V (ORCPT ); Wed, 23 Nov 2022 15:58:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239330AbiKWU6Q (ORCPT ); Wed, 23 Nov 2022 15:58:16 -0500 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4304A140C0; Wed, 23 Nov 2022 12:58:15 -0800 (PST) Received: by mail-pl1-f181.google.com with SMTP id y4so17725962plb.2; Wed, 23 Nov 2022 12:58:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mp24Nu2I7gSCQlK5n4D23tYVc00qzhoCs3YPv13NVLc=; b=aDbAKX4/HrS6PYGlupBLqoc55qAtmVeMTr0ECmEBsyPZnak6ogYo3L6fb+I7P0x7zU ueEV4XyHTmft7e9CezGDKkMtsUcvnjORAUL/bHJ4f5jFmWLJ1CMb8OXVH3lEVp5P34cv wbShJmzXDidDdq2iucIU7fuyfkvbmPaDUsd+0m1j325esrUz6+QJimH5Cja4TXBg9eLm Vi7EG+2recswylP1zD43Y1SfA/xieVBuh76hoYE8dKFFSTHtkSjXfdXXWhz38dVNXRIN TsyKU4a7ruYut2KUQElAnqqTex9PnmNPhoy11GIVmG4K9h52eQVkizdiRxu03xvdS7dY Fq7Q== X-Gm-Message-State: ANoB5pm+IYHyT/9Nn1lReRQd4a8bnsGf7rQaM4I7dD7dPh33b0VTnVGx +/rsAhdA2cRtG6kGtpqoOII= X-Google-Smtp-Source: AA0mqf7B1E2KDzXA+R+qCuwUzpTvPmhl0nhIS+bgHL2i1hi5Cg3+xqJwzMUZrRsONSajQyZrwPNj6w== X-Received: by 2002:a17:90b:2684:b0:218:907c:da24 with SMTP id pl4-20020a17090b268400b00218907cda24mr25001836pjb.18.1669237094703; Wed, 23 Nov 2022 12:58:14 -0800 (PST) Received: from bvanassche-glaptop2.roam.corp.google.com ([2601:642:4c02:686d:4311:4764:eee7:ac6d]) by smtp.gmail.com with ESMTPSA id i89-20020a17090a3de200b0020b2082e0acsm1858809pjc.0.2022.11.23.12.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 12:58:13 -0800 (PST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Adrian Hunter , Avri Altman , Bart Van Assche , "Martin K . Petersen" Subject: [PATCH v2 6/8] scsi: core: Set the SUB_PAGE_SEGMENTS request queue flag Date: Wed, 23 Nov 2022 12:57:38 -0800 Message-Id: <20221123205740.463185-7-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221123205740.463185-1-bvanassche@acm.org> References: <20221123205740.463185-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch enables support for segments smaller than the page size. No changes other than setting the SUB_PAGE_SEGMENTS flag are required since the SCSI code uses blk_rq_map_sg(). Cc: Martin K. Petersen Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 249757ddd8fe..d91aefdfb8d4 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1877,6 +1877,8 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q) { struct device *dev = shost->dma_dev; + blk_queue_flag_set(QUEUE_FLAG_SUB_PAGE_SEGMENTS, q); + /* * this limit is imposed by hardware restrictions */ From patchwork Wed Nov 23 20:57:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 628164 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 6428AC433FE for ; Wed, 23 Nov 2022 20:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235362AbiKWU6Z (ORCPT ); Wed, 23 Nov 2022 15:58:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239354AbiKWU6S (ORCPT ); Wed, 23 Nov 2022 15:58:18 -0500 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B7EB140DC; Wed, 23 Nov 2022 12:58:17 -0800 (PST) Received: by mail-pl1-f181.google.com with SMTP id 4so17747258pli.0; Wed, 23 Nov 2022 12:58:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RFVPNR8S50CoEUmmic/+TdXIVTdXYTFAywePSuWS/vg=; b=uggAH6eiYpVqABs5toRVcVUFtTu5sejgLcGLGSOPOvrd7C3jPoiGdKTx/vMN0tV4d+ /AvArV8h0V9pM2YOYOsNS8AqDVo1ausneXo+s/LedLg4mvnz3zDUMU+oR1bDFccgavs8 5d8GIZUULX+1QLnrc6e6cQWEVdnaY7l1j8NMWP5ITRrhXzIJtNFL9oNv8lS7qBqnatZO HQFYk+2R9FZKCDJRwbLF3vkr06gP/Pck5lT5PUyoTtfYksh4sdOtGowWUyqKynhQiYF4 3g9QaftxiJhxLzZKGpe65DaA+Wn+f3gwioH3H2XbJC6L1fDTL/z0awHF1MBMZSQdrt8L eC2g== X-Gm-Message-State: ANoB5pnei9wxPWqHaj7Efihin7QLeehVBjes/IF+zhI64ppZ52ke7MOF SkKxt9kQce99hHgqLmZwDndGjs7v1Lc= X-Google-Smtp-Source: AA0mqf5yS+Nq0J4bdlyuZeBTsZ9+CAHVtHH1wpeSDUq/JdzeDl/ju/41d+RC1SbhEDycEC1J6Tyt+w== X-Received: by 2002:a17:902:b101:b0:188:abb9:288 with SMTP id q1-20020a170902b10100b00188abb90288mr12659090plr.123.1669237096711; Wed, 23 Nov 2022 12:58:16 -0800 (PST) Received: from bvanassche-glaptop2.roam.corp.google.com ([2601:642:4c02:686d:4311:4764:eee7:ac6d]) by smtp.gmail.com with ESMTPSA id i89-20020a17090a3de200b0020b2082e0acsm1858809pjc.0.2022.11.23.12.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 12:58:15 -0800 (PST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Adrian Hunter , Avri Altman , Bart Van Assche , Doug Gilbert , "Martin K . Petersen" Subject: [PATCH v2 7/8] scsi_debug: Support configuring the maximum segment size Date: Wed, 23 Nov 2022 12:57:39 -0800 Message-Id: <20221123205740.463185-8-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221123205740.463185-1-bvanassche@acm.org> References: <20221123205740.463185-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a kernel module parameter for configuring the maximum segment size. This patch enables testing SCSI support for segments smaller than the page size. Cc: Doug Gilbert Cc: Martin K. Petersen Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index bebda917b138..ea8f762c55c3 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -770,6 +770,7 @@ static int sdebug_sector_size = DEF_SECTOR_SIZE; static int sdeb_tur_ms_to_ready = DEF_TUR_MS_TO_READY; static int sdebug_virtual_gb = DEF_VIRTUAL_GB; static int sdebug_vpd_use_hostno = DEF_VPD_USE_HOSTNO; +static unsigned int sdebug_max_segment_size = -1U; static unsigned int sdebug_lbpu = DEF_LBPU; static unsigned int sdebug_lbpws = DEF_LBPWS; static unsigned int sdebug_lbpws10 = DEF_LBPWS10; @@ -5851,6 +5852,7 @@ module_param_named(ndelay, sdebug_ndelay, int, S_IRUGO | S_IWUSR); module_param_named(no_lun_0, sdebug_no_lun_0, int, S_IRUGO | S_IWUSR); module_param_named(no_rwlock, sdebug_no_rwlock, bool, S_IRUGO | S_IWUSR); module_param_named(no_uld, sdebug_no_uld, int, S_IRUGO); +module_param_named(max_segment_size, sdebug_max_segment_size, uint, S_IRUGO); module_param_named(num_parts, sdebug_num_parts, int, S_IRUGO); module_param_named(num_tgts, sdebug_num_tgts, int, S_IRUGO | S_IWUSR); module_param_named(opt_blks, sdebug_opt_blks, int, S_IRUGO); @@ -7815,6 +7817,7 @@ static int sdebug_driver_probe(struct device *dev) sdebug_driver_template.can_queue = sdebug_max_queue; sdebug_driver_template.cmd_per_lun = sdebug_max_queue; + sdebug_driver_template.max_segment_size = sdebug_max_segment_size; if (!sdebug_clustering) sdebug_driver_template.dma_boundary = PAGE_SIZE - 1; From patchwork Wed Nov 23 20:57:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 628161 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 D9892C433FE for ; Wed, 23 Nov 2022 20:58:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236489AbiKWU6l (ORCPT ); Wed, 23 Nov 2022 15:58:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239377AbiKWU6U (ORCPT ); Wed, 23 Nov 2022 15:58:20 -0500 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ECBF140C0; Wed, 23 Nov 2022 12:58:19 -0800 (PST) Received: by mail-pj1-f41.google.com with SMTP id o5-20020a17090a678500b00218cd5a21c9so2893760pjj.4; Wed, 23 Nov 2022 12:58:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Uwxzy/vnTYe7j1cxWFfbVCkjxj/b84aaZ2OIZYuk8gk=; b=sD9y76MSQIX1wTHjOcMQ4FyQ8sZ9OgGV6/YHI8USAh4VO5SEtO8jB4OimLO4TqC1MD bu1G/iuXhykUALMJABbIGm0zCljHLRMrFyd/nA8zIC5bCw2TD4FjZi1oJLR8x2L/CI7m trZGb8PJgTS69Z7OpXfdxeZOZU9IITmqBr71c4SymhK9txL/wCVRH+ldS4INQgDZ5uzi x14T0Nqu2+lOW9OPAeeb5eRoR1VvbsE0ER7j4jTDKYTniEe6v7viypuIDoQReMCul5Wt GZAp/b0W0HEhZECdyuk2CrRrqef8nLGb9tJGNcnb/eCr+Saf9TsRl/Bjg5y9AB3uCOUv yYuw== X-Gm-Message-State: ANoB5pljrOxe4+9qZ1GxcXn+AYgNvkZ11CEKsU03OnX7Lf+lEyaDiJGO loJT13OjC8jrjVMqNnRT/og= X-Google-Smtp-Source: AA0mqf7+JBIOhe1o2hSWrTCx70L2510aOko13WwChQmaUEZoX2xuID2S5wpJM/1KoZirQRwNAMRG+A== X-Received: by 2002:a17:903:300a:b0:186:5de3:8f10 with SMTP id o10-20020a170903300a00b001865de38f10mr22929446pla.92.1669237098563; Wed, 23 Nov 2022 12:58:18 -0800 (PST) Received: from bvanassche-glaptop2.roam.corp.google.com ([2601:642:4c02:686d:4311:4764:eee7:ac6d]) by smtp.gmail.com with ESMTPSA id i89-20020a17090a3de200b0020b2082e0acsm1858809pjc.0.2022.11.23.12.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 12:58:17 -0800 (PST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Adrian Hunter , Avri Altman , Bart Van Assche , Ming Lei , Damien Le Moal , Chaitanya Kulkarni Subject: [PATCH v2 8/8] null_blk: Support configuring the maximum segment size Date: Wed, 23 Nov 2022 12:57:40 -0800 Message-Id: <20221123205740.463185-9-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221123205740.463185-1-bvanassche@acm.org> References: <20221123205740.463185-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add support for configuring the maximum segment size. Add support for segments smaller than the page size. This patch enables testing segments smaller than the page size with a driver that does not call blk_rq_map_sg(). Cc: Christoph Hellwig Cc: Ming Lei Cc: Damien Le Moal Cc: Chaitanya Kulkarni Signed-off-by: Bart Van Assche --- drivers/block/null_blk/main.c | 20 +++++++++++++++++--- drivers/block/null_blk/null_blk.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 1f154f92f4c2..bc811ab52c4a 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -157,6 +157,10 @@ static int g_max_sectors; module_param_named(max_sectors, g_max_sectors, int, 0444); MODULE_PARM_DESC(max_sectors, "Maximum size of a command (in 512B sectors)"); +static unsigned int g_max_segment_size = 1UL << 31; +module_param_named(max_segment_size, g_max_segment_size, int, 0444); +MODULE_PARM_DESC(max_segment_size, "Maximum size of a segment in bytes"); + static unsigned int nr_devices = 1; module_param(nr_devices, uint, 0444); MODULE_PARM_DESC(nr_devices, "Number of devices to register"); @@ -409,6 +413,7 @@ NULLB_DEVICE_ATTR(home_node, uint, NULL); NULLB_DEVICE_ATTR(queue_mode, uint, NULL); NULLB_DEVICE_ATTR(blocksize, uint, NULL); NULLB_DEVICE_ATTR(max_sectors, uint, NULL); +NULLB_DEVICE_ATTR(max_segment_size, uint, NULL); NULLB_DEVICE_ATTR(irqmode, uint, NULL); NULLB_DEVICE_ATTR(hw_queue_depth, uint, NULL); NULLB_DEVICE_ATTR(index, uint, NULL); @@ -532,6 +537,7 @@ static struct configfs_attribute *nullb_device_attrs[] = { &nullb_device_attr_queue_mode, &nullb_device_attr_blocksize, &nullb_device_attr_max_sectors, + &nullb_device_attr_max_segment_size, &nullb_device_attr_irqmode, &nullb_device_attr_hw_queue_depth, &nullb_device_attr_index, @@ -610,7 +616,8 @@ static ssize_t memb_group_features_show(struct config_item *item, char *page) return snprintf(page, PAGE_SIZE, "badblocks,blocking,blocksize,cache_size," "completion_nsec,discard,home_node,hw_queue_depth," - "irqmode,max_sectors,mbps,memory_backed,no_sched," + "irqmode,max_sectors,max_segment_size,mbps," + "memory_backed,no_sched," "poll_queues,power,queue_mode,shared_tag_bitmap,size," "submit_queues,use_per_node_hctx,virt_boundary,zoned," "zone_capacity,zone_max_active,zone_max_open," @@ -673,6 +680,7 @@ static struct nullb_device *null_alloc_dev(void) dev->queue_mode = g_queue_mode; dev->blocksize = g_bs; dev->max_sectors = g_max_sectors; + dev->max_segment_size = g_max_segment_size; dev->irqmode = g_irqmode; dev->hw_queue_depth = g_hw_queue_depth; dev->blocking = g_blocking; @@ -1214,6 +1222,8 @@ static int null_transfer(struct nullb *nullb, struct page *page, unsigned int valid_len = len; int err = 0; + WARN_ONCE(len > dev->max_segment_size, "%u > %u\n", len, + dev->max_segment_size); if (!is_write) { if (dev->zoned) valid_len = null_zone_valid_read_len(nullb, @@ -1249,7 +1259,8 @@ static int null_handle_rq(struct nullb_cmd *cmd) spin_lock_irq(&nullb->lock); rq_for_each_segment(bvec, rq, iter) { - len = bvec.bv_len; + len = min(bvec.bv_len, nullb->dev->max_segment_size); + bvec.bv_len = len; err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset, op_is_write(req_op(rq)), sector, rq->cmd_flags & REQ_FUA); @@ -1276,7 +1287,8 @@ static int null_handle_bio(struct nullb_cmd *cmd) spin_lock_irq(&nullb->lock); bio_for_each_segment(bvec, bio, iter) { - len = bvec.bv_len; + len = min(bvec.bv_len, nullb->dev->max_segment_size); + bvec.bv_len = len; err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset, op_is_write(bio_op(bio)), sector, bio->bi_opf & REQ_FUA); @@ -2088,6 +2100,7 @@ static int null_add_dev(struct nullb_device *dev) nullb->q->queuedata = nullb; blk_queue_flag_set(QUEUE_FLAG_NONROT, nullb->q); blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, nullb->q); + blk_queue_flag_set(QUEUE_FLAG_SUB_PAGE_SEGMENTS, nullb->q); mutex_lock(&lock); rv = ida_simple_get(&nullb_indexes, 0, 0, GFP_KERNEL); @@ -2106,6 +2119,7 @@ static int null_add_dev(struct nullb_device *dev) dev->max_sectors = min_t(unsigned int, dev->max_sectors, BLK_DEF_MAX_SECTORS); blk_queue_max_hw_sectors(nullb->q, dev->max_sectors); + blk_queue_max_segment_size(nullb->q, dev->max_segment_size); if (dev->virt_boundary) blk_queue_virt_boundary(nullb->q, PAGE_SIZE - 1); diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h index 94ff68052b1e..6784ee9f5fda 100644 --- a/drivers/block/null_blk/null_blk.h +++ b/drivers/block/null_blk/null_blk.h @@ -102,6 +102,7 @@ struct nullb_device { unsigned int queue_mode; /* block interface */ unsigned int blocksize; /* block size */ unsigned int max_sectors; /* Max sectors per command */ + unsigned int max_segment_size; /* Max size of a single DMA segment. */ unsigned int irqmode; /* IRQ completion handler */ unsigned int hw_queue_depth; /* queue depth */ unsigned int index; /* index of the disk, only valid with a disk */