From patchwork Wed Nov 23 20:57:33 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: 13054287 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 2864BC43219 for ; Wed, 23 Nov 2022 20:58:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234913AbiKWU6W (ORCPT ); Wed, 23 Nov 2022 15:58:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239240AbiKWU6K (ORCPT ); Wed, 23 Nov 2022 15:58:10 -0500 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A54DF580; Wed, 23 Nov 2022 12:58:05 -0800 (PST) Received: by mail-pg1-f169.google.com with SMTP id b62so17811610pgc.0; Wed, 23 Nov 2022 12:58:05 -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=vi68gSKm8AaGgHkr2eCWaAuUOEyq7Y6kAABVSvzrER4=; b=dlHHuPftvHvYf1A1TR5rqch7oJFiiYX9pm/L2A9L0aOW+Q99uM0lXP4JdUi6rWfIVy 8SE4tpvEYuisCFPf4jksaSvu7T646miXnKvXOurq7C0+g3sjL2u6p4gbYoLuRDuwCNlg PUBLk1WhEDc+qjw2mFnqGdSXWpHLe0G+AK3Vyewd6LCK46mVWgGZnGl3/+Ydu0sjm4H3 LnITe6IxfZo2OVZqysODVqgM6lOIZevr+borFwidfZZ2YqARfWcqYYmkwfOIYRjfEqTD +1Luueu2BHNsMZ6nhm+I2vTnDeNbAsdBQJujQ6VIPS4Mp17rqWpGHi7SBcF2V1R01Ara sOVw== X-Gm-Message-State: ANoB5plQe0WFmJP1BWinFDrj773x2UhL3OwCuYTMLlv5Nvz9qb9LV9TB KZmK+Eg4qiMnaSO1brgpjAA= X-Google-Smtp-Source: AA0mqf44ID5su45eYuFdJ9rAu/qDePvGNIr2FBHHKC3nwX8kURz1QBzbfoHhoV3VqB2VZYwWAFYsYg== X-Received: by 2002:a62:5f46:0:b0:56b:cc74:4bd5 with SMTP id t67-20020a625f46000000b0056bcc744bd5mr12240835pfb.79.1669237084446; Wed, 23 Nov 2022 12:58:04 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 12:58:03 -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 1/8] block: Introduce CONFIG_BLK_SUB_PAGE_SEGMENTS and QUEUE_FLAG_SUB_PAGE_SEGMENTS Date: Wed, 23 Nov 2022 12:57:33 -0800 Message-Id: <20221123205740.463185-2-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-block@vger.kernel.org Prepare for introducing support for segments smaller than the page size by introducing the request queue flag QUEUE_FLAG_SUB_PAGE_SEGMENTS. Introduce CONFIG_BLK_SUB_PAGE_SEGMENTS to prevent that performance of block drivers that support segments >= PAGE_SIZE would be affected. Cc: Christoph Hellwig Cc: Ming Lei Cc: Keith Busch Signed-off-by: Bart Van Assche --- block/Kconfig | 9 +++++++++ include/linux/blkdev.h | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/block/Kconfig b/block/Kconfig index 444c5ab3b67e..c3857795fc0d 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -36,6 +36,15 @@ config BLOCK_LEGACY_AUTOLOAD created on demand, but scripts that manually create device nodes and then call losetup might rely on this behavior. +config BLK_SUB_PAGE_SEGMENTS + bool "Support segments smaller than the page size" + default n + help + Most storage controllers support DMA segments larger than the typical + size of a virtual memory page. Some embedded controllers only support + DMA segments smaller than the page size. Enable this option to support + such controllers. + config BLK_RQ_ALLOC_TIME bool diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 3dbd45725b9f..a2362cf07366 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -548,6 +548,7 @@ struct request_queue { /* Keep blk_queue_flag_name[] in sync with the definitions below */ #define QUEUE_FLAG_STOPPED 0 /* queue is stopped */ #define QUEUE_FLAG_DYING 1 /* queue being torn down */ +#define QUEUE_FLAG_SUB_PAGE_SEGMENTS 2 /* segments smaller than one page */ #define QUEUE_FLAG_NOMERGES 3 /* disable merge attempts */ #define QUEUE_FLAG_SAME_COMP 4 /* complete on same CPU-group */ #define QUEUE_FLAG_FAIL_IO 5 /* fake timeout */ @@ -614,6 +615,12 @@ bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q); #define blk_queue_sq_sched(q) test_bit(QUEUE_FLAG_SQ_SCHED, &(q)->queue_flags) #define blk_queue_skip_tagset_quiesce(q) \ test_bit(QUEUE_FLAG_SKIP_TAGSET_QUIESCE, &(q)->queue_flags) +#ifdef CONFIG_BLK_SUB_PAGE_SEGMENTS +#define blk_queue_sub_page_segments(q) \ + test_bit(QUEUE_FLAG_SUB_PAGE_SEGMENTS, &(q)->queue_flags) +#else +#define blk_queue_sub_page_segments(q) false +#endif extern void blk_set_pm_only(struct request_queue *q); extern void blk_clear_pm_only(struct request_queue *q); From patchwork Wed Nov 23 20:57:34 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: 13054288 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 87C95C3A59F for ; Wed, 23 Nov 2022 20:58:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233560AbiKWU6V (ORCPT ); Wed, 23 Nov 2022 15:58:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239236AbiKWU6K (ORCPT ); Wed, 23 Nov 2022 15:58:10 -0500 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A4AAF03D; Wed, 23 Nov 2022 12:58:07 -0800 (PST) Received: by mail-pl1-f175.google.com with SMTP id k7so17702722pll.6; Wed, 23 Nov 2022 12:58:07 -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=jowSlLiL6KGV55IcMYZWeqN5/FXu2HkeW31efA29JJQ=; b=LXXQh3Gbn8XLGJNm7OWvlADu0zl9mkxUOQqkTd4u4nJ8oLnHiK7wNvdN2xBT0QOU5p GvWmZsfzzoNjEw0B9Ex0fkY7Wb/H6GyGgMvN8nkODtbgIA+TeH4mESG1W8JM4MpOyuRh Ya0jrfzPaqGc+ydx5r63NZ4kXTAvkbh9pJevZQuduFDqm5w5gLnDAIgg+F/4W+k0KXbf vHh4G/y2CcK7K0cP9noycyPqfjVKBjTzs2jMVOEtp2Pd9oHaUy/VAyZ0Ha3bekoEARiq YCwI7uaip9ggrC4hGtgpC2Fx5JPLp/WPRikM6w+BnfHe8O3wQzEMeProQTGDV0OtXDBd qzRg== X-Gm-Message-State: ANoB5pkD3/CcMpEcDNsplpawe5cXc4XJHMQBxEsY7RbGPfR98qwSzwEa tZJHKlyxbGo36FJ2GVXup7o= X-Google-Smtp-Source: AA0mqf4CgXq1JETjQQHzqHw5wv3EFngdoURmA4ZaHIijk5irbPmboc3q7nHo1/0eQkOKhGEv7lR78Q== X-Received: by 2002:a17:902:f391:b0:188:537d:78d9 with SMTP id f17-20020a170902f39100b00188537d78d9mr19512555ple.48.1669237086424; Wed, 23 Nov 2022 12:58:06 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 12:58:05 -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 2/8] block: Support configuring limits below the page size Date: Wed, 23 Nov 2022 12:57:34 -0800 Message-Id: <20221123205740.463185-3-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-block@vger.kernel.org Allow block drivers to configure the following if CONFIG_BLK_SUB_PAGE_SEGMENTS=y: * Maximum number of hardware sectors values smaller than PAGE_SIZE >> SECTOR_SHIFT. With PAGE_SIZE = 4096 this means that values below 8 become supported. * A maximum segment size smaller than the page size. This is most useful for page sizes above 4096 bytes. The behavior of the block layer is not modified if CONFIG_BLK_SUB_PAGE_SEGMENTS=n. Cc: Christoph Hellwig Cc: Ming Lei Cc: Keith Busch Signed-off-by: Bart Van Assche --- block/blk-settings.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/block/blk-settings.c b/block/blk-settings.c index 0477c4d527fe..f9d78dea0291 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -122,12 +122,14 @@ EXPORT_SYMBOL(blk_queue_bounce_limit); void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_sectors) { struct queue_limits *limits = &q->limits; + unsigned int min_max_hw_sectors = blk_queue_sub_page_segments(q) ? 1 : + PAGE_SIZE >> SECTOR_SHIFT; unsigned int max_sectors; - if ((max_hw_sectors << 9) < PAGE_SIZE) { - max_hw_sectors = 1 << (PAGE_SHIFT - 9); - printk(KERN_INFO "%s: set to minimum %d\n", - __func__, max_hw_sectors); + if (max_hw_sectors < min_max_hw_sectors) { + max_hw_sectors = min_max_hw_sectors; + printk(KERN_INFO "%s: set to minimum %u\n", __func__, + max_hw_sectors); } max_hw_sectors = round_down(max_hw_sectors, @@ -277,10 +279,12 @@ EXPORT_SYMBOL_GPL(blk_queue_max_discard_segments); **/ void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size) { - if (max_size < PAGE_SIZE) { - max_size = PAGE_SIZE; - printk(KERN_INFO "%s: set to minimum %d\n", - __func__, max_size); + unsigned int min_max_segment_size = blk_queue_sub_page_segments(q) ? + SECTOR_SIZE : PAGE_SIZE; + + if (max_size < min_max_segment_size) { + max_size = min_max_segment_size; + printk(KERN_INFO "%s: set to minimum %u\n", __func__, max_size); } /* see blk_queue_virt_boundary() for the explanation */ From patchwork Wed Nov 23 20:57:35 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: 13054289 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 3F22CC46467 for ; Wed, 23 Nov 2022 20:58:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234984AbiKWU6W (ORCPT ); Wed, 23 Nov 2022 15:58:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239253AbiKWU6K (ORCPT ); Wed, 23 Nov 2022 15:58:10 -0500 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48BF9F02D; Wed, 23 Nov 2022 12:58:09 -0800 (PST) Received: by mail-pg1-f182.google.com with SMTP id q71so17748137pgq.8; Wed, 23 Nov 2022 12:58:09 -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=u/TsybekEubKHyQUK6eV+iAAL5xeGQVyeA/isuI9nLY=; b=ZRZKWSimsv5E2sYWVuUZN4D72PHIe/e/qHesajpFfxBy7kQCkrMKVswlk9n1g8Tl2k fPjS1L+BwUf6hnsfwfiXWmmk6XVz/KNx+yWdtv301m4Xxuy2yX378ZW2S/ACTHgN4o3f BEpGUNCOz7iIhc6gdiYrmR2jqU5i77U22+E3T1jU+BW4EE4eCMrDJByYoJcIkTUp9Vja q7DxsdOm9ndLA6CvBVWOxLcYMU75mPVmLNRh+374XuhJ8aKlvxQeC8giNpCc29lWUi5n i8dPbo4tizcTLkSXizWqG6C7684OgTIC53uYz09JlVZylF1hzmMrWSass/Wq+DlL45Bc rDLg== X-Gm-Message-State: ANoB5png55PXzce7bauq2c79kS2pnOld+aFl5RoKR1QWnT+/QpEXJJI3 tLg++03rdxjQXn6ZQkS9gYE= X-Google-Smtp-Source: AA0mqf7APCgI6nlqyOOHzYLhP4ztkxEwCdOPlgdjAeFusBIRXA2M/Bh3idKagRwBuc0kgMu5j1+AVg== X-Received: by 2002:a63:dd43:0:b0:45c:5a74:9a92 with SMTP id g3-20020a63dd43000000b0045c5a749a92mr9452347pgj.473.1669237088627; Wed, 23 Nov 2022 12:58:08 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 12:58:07 -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 3/8] block: Support submitting passthrough requests with small segments Date: Wed, 23 Nov 2022 12:57:35 -0800 Message-Id: <20221123205740.463185-4-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-block@vger.kernel.org If the segment size is smaller than the page size there may be multiple segments per bvec even if a bvec only contains a single page. Hence this patch. Cc: Christoph Hellwig Cc: Ming Lei Cc: Keith Busch Signed-off-by: Bart Van Assche --- block/blk-map.c | 16 +++++++++++++++- block/blk.h | 11 +++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/block/blk-map.c b/block/blk-map.c index 19940c978c73..d2d6ee098514 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -524,6 +524,20 @@ static struct bio *bio_copy_kern(struct request_queue *q, void *data, return ERR_PTR(-ENOMEM); } +#ifdef CONFIG_BLK_SUB_PAGE_SEGMENTS +/* Number of DMA segments required to transfer @bytes data. */ +unsigned int blk_segments(const struct queue_limits *limits, unsigned int bytes) +{ + const unsigned int mss = limits->max_segment_size; + + if (bytes <= mss) + return 1; + if (is_power_of_2(mss)) + return round_up(bytes, mss) >> ilog2(mss); + return (bytes + mss - 1) / mss; +} +#endif + /* * Append a bio to a passthrough request. Only works if the bio can be merged * into the request based on the driver constraints. @@ -535,7 +549,7 @@ int blk_rq_append_bio(struct request *rq, struct bio *bio) unsigned int nr_segs = 0; bio_for_each_bvec(bv, bio, iter) - nr_segs++; + nr_segs += blk_segments(&rq->q->limits, bv.bv_len); if (!rq->bio) { blk_rq_bio_prep(rq, bio, nr_segs); diff --git a/block/blk.h b/block/blk.h index 5929559acd71..fb486eff3eef 100644 --- a/block/blk.h +++ b/block/blk.h @@ -80,6 +80,17 @@ struct bio_vec *bvec_alloc(mempool_t *pool, unsigned short *nr_vecs, gfp_t gfp_mask); void bvec_free(mempool_t *pool, struct bio_vec *bv, unsigned short nr_vecs); +#ifdef CONFIG_BLK_SUB_PAGE_SEGMENTS +unsigned int blk_segments(const struct queue_limits *limits, + unsigned int bytes); +#else +static inline unsigned int blk_segments(const struct queue_limits *limits, + unsigned int bytes) +{ + return 1; +} +#endif + static inline bool biovec_phys_mergeable(struct request_queue *q, struct bio_vec *vec1, struct bio_vec *vec2) { 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: 13054290 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 78336C47088 for ; Wed, 23 Nov 2022 20:58:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235147AbiKWU6X (ORCPT ); Wed, 23 Nov 2022 15:58:23 -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-block@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: 13054291 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 2AA54C43219 for ; Wed, 23 Nov 2022 20:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235297AbiKWU6Y (ORCPT ); Wed, 23 Nov 2022 15:58:24 -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-block@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: 13054292 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 36A8CC4332F for ; Wed, 23 Nov 2022 20:58:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235426AbiKWU6Z (ORCPT ); Wed, 23 Nov 2022 15:58:25 -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-block@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: 13054293 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 B3591C43219 for ; Wed, 23 Nov 2022 20:58:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235768AbiKWU61 (ORCPT ); Wed, 23 Nov 2022 15:58:27 -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-block@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: 13054294 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 35BB4C4332F for ; Wed, 23 Nov 2022 20:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235369AbiKWU62 (ORCPT ); Wed, 23 Nov 2022 15:58:28 -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-block@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 */