From patchwork Mon Jun 12 20:33:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13277282 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 A2E10C88CB2 for ; Mon, 12 Jun 2023 20:33:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229604AbjFLUdX (ORCPT ); Mon, 12 Jun 2023 16:33:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235128AbjFLUdW (ORCPT ); Mon, 12 Jun 2023 16:33:22 -0400 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC62BE56 for ; Mon, 12 Jun 2023 13:33:20 -0700 (PDT) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1b3c5389fa2so11486525ad.0 for ; Mon, 12 Jun 2023 13:33:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686602000; x=1689194000; 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=4lGvwSDI7LLN74ZAuyT/VMv3HlxsqUq48elrI1Vl7fQ=; b=kVc/BLFZ8jzruqtT4OI0oTRkVy/esyoCEeK6RIkqwF5UpJp3w3WTlfvURwhhmcESTg KSfUN7ByBWVFO8wffS5bXUdhS4yZVgLgHrfUyayLJ4DU4Oszj8Sx1SDPqjhSCf38uVVj cZj1OBN1PW1GvZIzLNPDm4zKKvmu38ld+XTOfO4o72ns2S5KZBFyD8adpn2ADVLBLVwt /O+3avUku8DKySY//CWBczJRrD2q2BWzcmySfNOj/03Us0tFxWnZ+LEjZuOpeFoIq4sb 4tbcvmzT32xkSisYUlTLo7dgjcql4Mi8/69dPgwp3omoSoxJUNHYzEagfFiSK4rLPe+C imxA== X-Gm-Message-State: AC+VfDyJMF2db2tbjrGggtSw2mzWgA3Jxp9j3gFnQKqWkYkJRKQCh0rN tWR/jchMNXjwrG4a+galA0Q= X-Google-Smtp-Source: ACHHUZ5h2SezzJYr202WZSuEJZKjzMjwqZpE01jUZI77FaEJLxcrDWtN6vXu0eBDrQDSSF002FtMwQ== X-Received: by 2002:a17:902:f68a:b0:1ac:8062:4f31 with SMTP id l10-20020a170902f68a00b001ac80624f31mr9136199plg.37.1686602000334; Mon, 12 Jun 2023 13:33:20 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id ji1-20020a170903324100b001b016313b1dsm3324767plb.86.2023.06.12.13.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 13:33:19 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Luis Chamberlain , Sandeep Dhavale , Juan Yescas , Bart Van Assche , Ming Lei , Keith Busch Subject: [PATCH v6 1/8] block: Use pr_info() instead of printk(KERN_INFO ...) Date: Mon, 12 Jun 2023 13:33:07 -0700 Message-Id: <20230612203314.17820-2-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612203314.17820-1-bvanassche@acm.org> References: <20230612203314.17820-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Switch to the modern style of printing kernel messages. Use %u instead of %d to print unsigned integers. Reviewed-by: Luis Chamberlain Tested-by: Sandeep Dhavale Cc: Christoph Hellwig Cc: Ming Lei Cc: Keith Busch Signed-off-by: Bart Van Assche --- block/blk-settings.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/block/blk-settings.c b/block/blk-settings.c index 896b4654ab00..1d8d2ae7bdf4 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -127,8 +127,7 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto 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); + pr_info("%s: set to minimum %u\n", __func__, max_hw_sectors); } max_hw_sectors = round_down(max_hw_sectors, @@ -248,8 +247,7 @@ void blk_queue_max_segments(struct request_queue *q, unsigned short max_segments { if (!max_segments) { max_segments = 1; - printk(KERN_INFO "%s: set to minimum %d\n", - __func__, max_segments); + pr_info("%s: set to minimum %u\n", __func__, max_segments); } q->limits.max_segments = max_segments; @@ -285,8 +283,7 @@ 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); + pr_info("%s: set to minimum %u\n", __func__, max_size); } /* see blk_queue_virt_boundary() for the explanation */ @@ -740,8 +737,7 @@ void blk_queue_segment_boundary(struct request_queue *q, unsigned long mask) { if (mask < PAGE_SIZE - 1) { mask = PAGE_SIZE - 1; - printk(KERN_INFO "%s: set to minimum %lx\n", - __func__, mask); + pr_info("%s: set to minimum %lx\n", __func__, mask); } q->limits.seg_boundary_mask = mask; From patchwork Mon Jun 12 20:33:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13277283 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 63326C7EE43 for ; Mon, 12 Jun 2023 20:33:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235128AbjFLUdY (ORCPT ); Mon, 12 Jun 2023 16:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236274AbjFLUdX (ORCPT ); Mon, 12 Jun 2023 16:33:23 -0400 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35F2C10F5 for ; Mon, 12 Jun 2023 13:33:22 -0700 (PDT) Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-5445ef3ef1eso3349186a12.2 for ; Mon, 12 Jun 2023 13:33:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686602001; x=1689194001; 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=5x+hvU6mLO5SBhoAWule2OzZmYU1RVF158u1Z2pevWA=; b=OpVxNRt827PzzT6lWyRsqNnOzfKhRQgth1PrgQQVhsCPWsSatV4JWuRqp5Zlbl27Vc ArHACutME4tB1Ybfjhf9QGUqj0ve2dBgewXSwZs3oga3wmkao343YH0R9dVJ6DPK1UP4 y1sHS9KZXE6xgM1Mm8eCDCZTw6w9Qe0sXjw/YkqqQUiou/V1JDgU1pokhjkedgZ4XRLM 7kEb6zmqCerwrUKc+Hz5g+SX2B1sk4Honb9dnQAbRRmg4sl1JSUCcVsrkVa9PRt0Iw9i 9vEFFmnxp6aKY7ZmA190n1x/UDpAnTxH7xN9W0ZlVpxm28sqNoOHxsFwNf+xsoae4G3R wcbg== X-Gm-Message-State: AC+VfDyx0nRX4RtaHPe0yJsbD28y0EziySt/PqTrqIbtmLNDI9Tmv9Q4 mCPBfeWp0r2RI48UmcVVte0ATfcuzdzTRQ== X-Google-Smtp-Source: ACHHUZ5yKVE35qfo3jbunEfHX9ENPHVajo+aUhl/Ehz+Scb4cjhfTpljq90c55IwRq/x07wvTKq6EQ== X-Received: by 2002:a17:90b:e12:b0:25b:f113:19b5 with SMTP id ge18-20020a17090b0e1200b0025bf11319b5mr2694829pjb.40.1686602001552; Mon, 12 Jun 2023 13:33:21 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id ji1-20020a170903324100b001b016313b1dsm3324767plb.86.2023.06.12.13.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 13:33:20 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Luis Chamberlain , Sandeep Dhavale , Juan Yescas , Bart Van Assche , Ming Lei , Keith Busch Subject: [PATCH v6 2/8] block: Prepare for supporting sub-page limits Date: Mon, 12 Jun 2023 13:33:08 -0700 Message-Id: <20230612203314.17820-3-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612203314.17820-1-bvanassche@acm.org> References: <20230612203314.17820-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Introduce variables that represent the lower configuration bounds. This patch does not change any functionality. Reviewed-by: Luis Chamberlain Tested-by: Sandeep Dhavale Cc: Christoph Hellwig Cc: Ming Lei Cc: Keith Busch Signed-off-by: Bart Van Assche --- block/blk-settings.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/block/blk-settings.c b/block/blk-settings.c index 1d8d2ae7bdf4..95d6e836c4a7 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -123,10 +123,11 @@ 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 = PAGE_SIZE >> SECTOR_SHIFT; unsigned int max_sectors; - if ((max_hw_sectors << 9) < PAGE_SIZE) { - max_hw_sectors = 1 << (PAGE_SHIFT - 9); + if (max_hw_sectors < min_max_hw_sectors) { + max_hw_sectors = min_max_hw_sectors; pr_info("%s: set to minimum %u\n", __func__, max_hw_sectors); } @@ -281,8 +282,10 @@ 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; + unsigned int min_max_segment_size = PAGE_SIZE; + + if (max_size < min_max_segment_size) { + max_size = min_max_segment_size; pr_info("%s: set to minimum %u\n", __func__, max_size); } From patchwork Mon Jun 12 20:33:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13277284 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 9E6F3C88CB5 for ; Mon, 12 Jun 2023 20:33:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236492AbjFLUd0 (ORCPT ); Mon, 12 Jun 2023 16:33:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234857AbjFLUdZ (ORCPT ); Mon, 12 Jun 2023 16:33:25 -0400 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CA13E57 for ; Mon, 12 Jun 2023 13:33:23 -0700 (PDT) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1b3c0c476d1so16104945ad.1 for ; Mon, 12 Jun 2023 13:33:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686602003; x=1689194003; 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=xGT3esQWRf5e91YtXev0us55UEaQ38pPW1j92RLY91M=; b=PL3u5X5x0ZQn8T3QDDDLKOvUh04lnwrA/3ipW++yp6GZVLyy0xl56xcHX/34WOtYxr 7MsgRysOcOLl+UBrKKuGDOMXbb1CxgCEbmQVeNkny1ZaAmf3lE+fR4Xgz9nhzyaJGXi9 zKCadjZ30mB1Wwbo2WFS9BqJFYL5qBRrVaF4FT9IkfILixxfzmEXTIB5j3MTvK5axz5k y9sqlUIWGcXJ4xuhA/trsBUh0AD5e7jzB7VBFMqIFlwjiIji2ObBWMV44QifOewcc60d itKmkey+bo+JHG1BSxhpCC0mvu+MwJH7DALdQycO6Ze8kC++2nYGnlOHoNBtK7SDJ2hc +1Nw== X-Gm-Message-State: AC+VfDzae6ELJT4FJAub0PZyYps/wYuzSgk7bBzav01YGFUSaznzpgc0 N32V3RMtHfKh1SeRICxZvZsZxpZ8QyUSvw== X-Google-Smtp-Source: ACHHUZ6jKyVfUYKfCXTbRR2Jfp22c+n2AG8q0eVobbZ2L7T37kiJZLtlog36nunXHBxTsE46hKXhdA== X-Received: by 2002:a17:902:8642:b0:1b0:348:2498 with SMTP id y2-20020a170902864200b001b003482498mr7000659plt.2.1686602002990; Mon, 12 Jun 2023 13:33:22 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id ji1-20020a170903324100b001b016313b1dsm3324767plb.86.2023.06.12.13.33.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 13:33:22 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Luis Chamberlain , Sandeep Dhavale , Juan Yescas , Bart Van Assche , Ming Lei , Keith Busch Subject: [PATCH v6 3/8] block: Support configuring limits below the page size Date: Mon, 12 Jun 2023 13:33:09 -0700 Message-Id: <20230612203314.17820-4-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612203314.17820-1-bvanassche@acm.org> References: <20230612203314.17820-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: * Maximum number of hardware sectors values smaller than PAGE_SIZE >> SECTOR_SHIFT. For PAGE_SIZE = 4096 this means that values below 8 become supported. * A maximum segment size below the page size. This is most useful for page sizes above 4096 bytes. The blk_sub_page_segments static branch will be used in later patches to prevent that performance of block drivers that support segments >= PAGE_SIZE and max_hw_sectors >= PAGE_SIZE >> SECTOR_SHIFT would be affected. This patch may change the behavior of existing block drivers from not working into working. If a block driver calls blk_queue_max_hw_sectors() or blk_queue_max_segment_size(), this is usually done to configure the maximum supported limits. An attempt to configure a limit below what is supported by the block layer causes the block layer to select a larger value. If that value is not supported by the block driver, this may cause other data to be transferred than requested, a kernel crash or other undesirable behavior. Tested-by: Sandeep Dhavale Cc: Christoph Hellwig Cc: Ming Lei Cc: Keith Busch Cc: Luis Chamberlain Signed-off-by: Bart Van Assche --- block/blk-core.c | 2 ++ block/blk-settings.c | 60 ++++++++++++++++++++++++++++++++++++++++++ block/blk.h | 9 +++++++ include/linux/blkdev.h | 2 ++ 4 files changed, 73 insertions(+) diff --git a/block/blk-core.c b/block/blk-core.c index 2ae22bebeb3e..73b8b547ecb9 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -264,6 +264,8 @@ static void blk_free_queue_rcu(struct rcu_head *rcu_head) static void blk_free_queue(struct request_queue *q) { blk_free_queue_stats(q->stats); + blk_disable_sub_page_limits(&q->limits); + if (queue_is_mq(q)) blk_mq_release(q); diff --git a/block/blk-settings.c b/block/blk-settings.c index 95d6e836c4a7..607f21b99f3c 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -19,6 +19,11 @@ #include "blk-rq-qos.h" #include "blk-wbt.h" +/* Protects blk_nr_sub_page_limit_queues and blk_sub_page_limits changes. */ +static DEFINE_MUTEX(blk_sub_page_limit_lock); +static uint32_t blk_nr_sub_page_limit_queues; +DEFINE_STATIC_KEY_FALSE(blk_sub_page_limits); + void blk_queue_rq_timeout(struct request_queue *q, unsigned int timeout) { q->rq_timeout = timeout; @@ -59,6 +64,7 @@ void blk_set_default_limits(struct queue_limits *lim) lim->zoned = BLK_ZONED_NONE; lim->zone_write_granularity = 0; lim->dma_alignment = 511; + lim->sub_page_limits = false; } /** @@ -101,6 +107,50 @@ void blk_queue_bounce_limit(struct request_queue *q, enum blk_bounce bounce) } EXPORT_SYMBOL(blk_queue_bounce_limit); +/** + * blk_enable_sub_page_limits - enable support for limits below the page size + * @lim: request queue limits for which to enable support of these features. + * + * Enable support for max_segment_size values smaller than PAGE_SIZE and for + * max_hw_sectors values below PAGE_SIZE >> SECTOR_SHIFT. Support for these + * features is not enabled all the time because of the runtime overhead of these + * features. + */ +static void blk_enable_sub_page_limits(struct queue_limits *lim) +{ + if (lim->sub_page_limits) + return; + + lim->sub_page_limits = true; + + mutex_lock(&blk_sub_page_limit_lock); + if (++blk_nr_sub_page_limit_queues == 1) + static_branch_enable(&blk_sub_page_limits); + mutex_unlock(&blk_sub_page_limit_lock); +} + +/** + * blk_disable_sub_page_limits - disable support for limits below the page size + * @lim: request queue limits for which to enable support of these features. + * + * max_segment_size values smaller than PAGE_SIZE and for max_hw_sectors values + * below PAGE_SIZE >> SECTOR_SHIFT. Support for these features is not enabled + * all the time because of the runtime overhead of these features. + */ +void blk_disable_sub_page_limits(struct queue_limits *lim) +{ + if (!lim->sub_page_limits) + return; + + lim->sub_page_limits = false; + + mutex_lock(&blk_sub_page_limit_lock); + WARN_ON_ONCE(blk_nr_sub_page_limit_queues <= 0); + if (--blk_nr_sub_page_limit_queues == 0) + static_branch_disable(&blk_sub_page_limits); + mutex_unlock(&blk_sub_page_limit_lock); +} + /** * blk_queue_max_hw_sectors - set max sectors for a request for this queue * @q: the request queue for the device @@ -126,6 +176,11 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto unsigned int min_max_hw_sectors = PAGE_SIZE >> SECTOR_SHIFT; unsigned int max_sectors; + if (max_hw_sectors < min_max_hw_sectors) { + blk_enable_sub_page_limits(limits); + min_max_hw_sectors = 1; + } + if (max_hw_sectors < min_max_hw_sectors) { max_hw_sectors = min_max_hw_sectors; pr_info("%s: set to minimum %u\n", __func__, max_hw_sectors); @@ -284,6 +339,11 @@ void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size) { unsigned int min_max_segment_size = PAGE_SIZE; + if (max_size < min_max_segment_size) { + blk_enable_sub_page_limits(&q->limits); + min_max_segment_size = SECTOR_SIZE; + } + if (max_size < min_max_segment_size) { max_size = min_max_segment_size; pr_info("%s: set to minimum %u\n", __func__, max_size); diff --git a/block/blk.h b/block/blk.h index 768852a84fef..d37ec737e05e 100644 --- a/block/blk.h +++ b/block/blk.h @@ -13,6 +13,7 @@ struct elevator_type; #define BLK_MAX_TIMEOUT (5 * HZ) extern struct dentry *blk_debugfs_root; +DECLARE_STATIC_KEY_FALSE(blk_sub_page_limits); struct blk_flush_queue { unsigned int flush_pending_idx:1; @@ -32,6 +33,14 @@ struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size, gfp_t flags); void blk_free_flush_queue(struct blk_flush_queue *q); +static inline bool blk_queue_sub_page_limits(const struct queue_limits *lim) +{ + return static_branch_unlikely(&blk_sub_page_limits) && + lim->sub_page_limits; +} + +void blk_disable_sub_page_limits(struct queue_limits *q); + void blk_freeze_queue(struct request_queue *q); void __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic); void blk_queue_start_drain(struct request_queue *q); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index ed44a997f629..54360ef85109 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -324,6 +324,8 @@ struct queue_limits { * due to possible offsets. */ unsigned int dma_alignment; + + bool sub_page_limits; }; typedef int (*report_zones_cb)(struct blk_zone *zone, unsigned int idx, From patchwork Mon Jun 12 20:33:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13277285 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 2FE28C88CB2 for ; Mon, 12 Jun 2023 20:33:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234857AbjFLUd1 (ORCPT ); Mon, 12 Jun 2023 16:33:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236274AbjFLUd0 (ORCPT ); Mon, 12 Jun 2023 16:33:26 -0400 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB36010CE for ; Mon, 12 Jun 2023 13:33:24 -0700 (PDT) Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-256766a1c43so2425550a91.1 for ; Mon, 12 Jun 2023 13:33:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686602004; x=1689194004; 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=x31Gz5puzFT8R232eHlZC5XC6VRgSkQxD0Tkic2sb8Q=; b=XMKv2ql7ofyVTV+8mpOpI/I2UyrBb/z9rZGr1/214IH4sm8NnAHbCfT+VUhxx67Z6u XGG0Nv1vVSRXFBwYNWweuJkscqt6QEpfmy/FTbbWucwo4zx8a/rq1nZkHuicERIeaPWR WlOW4uTkyq8Y9aim8a7lnezbOm90o0bEfVzxNvwy6zHxuQgfzCpxJwhoFbg06H4NLVh+ Ivs6U2/hGeP+BbA12/PXFi5x95izpI6PJS9d/7BrTOa9/QTf9WfaxniqqBrOFuJAeXr3 mdcftL531IHjnE0tprgTzAXGhxXVDbbt3d91HYOUWTPVk1c9Mzg5qzNOWUM1HLpNZDyX OsDQ== X-Gm-Message-State: AC+VfDwUJXeDRojGsHKAh9TKS/Jp7Kj7ZtOq2LVDSIi1+0q10djv35tU XN1PfrR5LjfwugnJupsBpWI= X-Google-Smtp-Source: ACHHUZ4RQAplvPEhC6w29FH35KVFdNQ03BRnc8sVUMlfsZ+w4lr9VlDcClVQU2RNhdpONVEBUfSwdQ== X-Received: by 2002:a17:90a:d98e:b0:25b:e4da:c73a with SMTP id d14-20020a17090ad98e00b0025be4dac73amr3324055pjv.13.1686602004185; Mon, 12 Jun 2023 13:33:24 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id ji1-20020a170903324100b001b016313b1dsm3324767plb.86.2023.06.12.13.33.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 13:33:23 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Luis Chamberlain , Sandeep Dhavale , Juan Yescas , Bart Van Assche , Ming Lei , Keith Busch Subject: [PATCH v6 4/8] block: Make sub_page_limit_queues available in debugfs Date: Mon, 12 Jun 2023 13:33:10 -0700 Message-Id: <20230612203314.17820-5-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612203314.17820-1-bvanassche@acm.org> References: <20230612203314.17820-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This new debugfs attribute makes it easier to verify the code that tracks how many queues require limits below the page size. Reviewed-by: Luis Chamberlain Cc: Christoph Hellwig Cc: Ming Lei Cc: Keith Busch Signed-off-by: Bart Van Assche --- block/blk-core.c | 2 ++ block/blk-mq-debugfs.c | 9 +++++++++ block/blk-mq-debugfs.h | 6 ++++++ block/blk-settings.c | 8 ++++++++ block/blk.h | 1 + 5 files changed, 26 insertions(+) diff --git a/block/blk-core.c b/block/blk-core.c index 73b8b547ecb9..ef6173ad4731 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -45,6 +45,7 @@ #include #include "blk.h" +#include "blk-mq-debugfs.h" #include "blk-mq-sched.h" #include "blk-pm.h" #include "blk-cgroup.h" @@ -1204,6 +1205,7 @@ int __init blk_dev_init(void) sizeof(struct request_queue), 0, SLAB_PANIC, NULL); blk_debugfs_root = debugfs_create_dir("block", NULL); + blk_mq_debugfs_init(); return 0; } diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index c3b5930106b2..5649c9e3719d 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -846,3 +846,12 @@ void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx) debugfs_remove_recursive(hctx->sched_debugfs_dir); hctx->sched_debugfs_dir = NULL; } + +DEFINE_DEBUGFS_ATTRIBUTE(blk_sub_page_limit_queues_fops, + blk_sub_page_limit_queues_get, NULL, "%llu\n"); + +void blk_mq_debugfs_init(void) +{ + debugfs_create_file("sub_page_limit_queues", 0400, blk_debugfs_root, + NULL, &blk_sub_page_limit_queues_fops); +} diff --git a/block/blk-mq-debugfs.h b/block/blk-mq-debugfs.h index 9c7d4b6117d4..7942119051f5 100644 --- a/block/blk-mq-debugfs.h +++ b/block/blk-mq-debugfs.h @@ -17,6 +17,8 @@ struct blk_mq_debugfs_attr { const struct seq_operations *seq_ops; }; +void blk_mq_debugfs_init(void); + int __blk_mq_debugfs_rq_show(struct seq_file *m, struct request *rq); int blk_mq_debugfs_rq_show(struct seq_file *m, void *v); @@ -36,6 +38,10 @@ void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx); void blk_mq_debugfs_register_rqos(struct rq_qos *rqos); void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos); #else +static inline void blk_mq_debugfs_init(void) +{ +} + static inline void blk_mq_debugfs_register(struct request_queue *q) { } diff --git a/block/blk-settings.c b/block/blk-settings.c index 607f21b99f3c..c1c4988cc575 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -107,6 +107,14 @@ void blk_queue_bounce_limit(struct request_queue *q, enum blk_bounce bounce) } EXPORT_SYMBOL(blk_queue_bounce_limit); +/* For debugfs. */ +int blk_sub_page_limit_queues_get(void *data, u64 *val) +{ + *val = READ_ONCE(blk_nr_sub_page_limit_queues); + + return 0; +} + /** * blk_enable_sub_page_limits - enable support for limits below the page size * @lim: request queue limits for which to enable support of these features. diff --git a/block/blk.h b/block/blk.h index d37ec737e05e..065449e7d0bd 100644 --- a/block/blk.h +++ b/block/blk.h @@ -39,6 +39,7 @@ static inline bool blk_queue_sub_page_limits(const struct queue_limits *lim) lim->sub_page_limits; } +int blk_sub_page_limit_queues_get(void *data, u64 *val); void blk_disable_sub_page_limits(struct queue_limits *q); void blk_freeze_queue(struct request_queue *q); From patchwork Mon Jun 12 20:33:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13277286 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 B2DC1C7EE2E for ; Mon, 12 Jun 2023 20:33:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236274AbjFLUd1 (ORCPT ); Mon, 12 Jun 2023 16:33:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236307AbjFLUd0 (ORCPT ); Mon, 12 Jun 2023 16:33:26 -0400 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB32710C9 for ; Mon, 12 Jun 2023 13:33:25 -0700 (PDT) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1b3d29cfb17so11909635ad.3 for ; Mon, 12 Jun 2023 13:33:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686602005; x=1689194005; 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=qo39VGVNKAqYQuhvjR9+/XSsIZeV792czsUdbh6Q7Qk=; b=j/iTwHf2pXI3vhU0slyNvW0z5X7qbfZ/BfTCQAaco2FalLE89OsTDrjZRufXNGxWlz 2eWULbrhbsgzlItO3rPfb9uDnG63jE72l+VUnGQVchcVqyqDEvHJae6nlSq4C+2ntOMV /CLx+TFm8HruhLqnMS/xf0qeXyjKeLJTyYAGclAfQGA24D+cp7QEmj827v3AepBahxnb tPpH5oAsAg6NJPZ0PYw2mPb4Rs02n0vRnf3hU+zGRahE0Z+P744eXOEcdpMUGs0RWgnp QrRMRaKqdiQPPb3NEOjVz7+DKw68iCPF70jb6Ex5rpAn650aAuqfAIH6ponw/nbocmt5 c9NA== X-Gm-Message-State: AC+VfDzCMOJEj43md+yz3av9ssWSTZysSePmvhwIz/pqgYngyPGy6KfV rDuxwUawTD/ZoTLOosJGfYE= X-Google-Smtp-Source: ACHHUZ5wFhJjb9g/E2490NF5L48uzJhLdUJt7YLw7hmbdFJDs89hn7CpzfCM7PGdmFyNHLRXx+s/NQ== X-Received: by 2002:a17:902:c407:b0:1ac:5717:fd5 with SMTP id k7-20020a170902c40700b001ac57170fd5mr10519253plk.60.1686602005320; Mon, 12 Jun 2023 13:33:25 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id ji1-20020a170903324100b001b016313b1dsm3324767plb.86.2023.06.12.13.33.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 13:33:24 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Luis Chamberlain , Sandeep Dhavale , Juan Yescas , Bart Van Assche , Ming Lei , Keith Busch Subject: [PATCH v6 5/8] block: Support submitting passthrough requests with small segments Date: Mon, 12 Jun 2023 13:33:11 -0700 Message-Id: <20230612203314.17820-6-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612203314.17820-1-bvanassche@acm.org> References: <20230612203314.17820-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. Reviewed-by: Luis Chamberlain Cc: Christoph Hellwig Cc: Ming Lei Cc: Keith Busch Signed-off-by: Bart Van Assche --- block/blk-map.c | 2 +- block/blk.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/block/blk-map.c b/block/blk-map.c index 3551c3ff17cf..c1d92b0dcc5d 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -535,7 +535,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 065449e7d0bd..18b898a38c72 100644 --- a/block/blk.h +++ b/block/blk.h @@ -86,6 +86,24 @@ 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); +/* Number of DMA segments required to transfer @bytes data. */ +static inline unsigned int blk_segments(const struct queue_limits *limits, + unsigned int bytes) +{ + if (!blk_queue_sub_page_limits(limits)) + return 1; + + { + 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; + } +} + static inline bool biovec_phys_mergeable(struct request_queue *q, struct bio_vec *vec1, struct bio_vec *vec2) { From patchwork Mon Jun 12 20:33:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13277287 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 BF689C7EE43 for ; Mon, 12 Jun 2023 20:33:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236160AbjFLUda (ORCPT ); Mon, 12 Jun 2023 16:33:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236594AbjFLUd2 (ORCPT ); Mon, 12 Jun 2023 16:33:28 -0400 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FA7C10CE for ; Mon, 12 Jun 2023 13:33:27 -0700 (PDT) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1b3a9eae57cso15992885ad.1 for ; Mon, 12 Jun 2023 13:33:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686602007; x=1689194007; 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=D76EF1PRUG4k1Tw0AWeqUDGcfk53v67F7APUOd5gLok=; b=D1eDFKnJvuKEhCmvLysekJuRq4ReyBb52w6apBOtRbBEopofhO5/PKLZZnkCFEzM1m 7E+YAFMTHMjLqdHLIvAY0mdTkllcCUT8X8n6JlDLVJ5LamZkow4jBymxguBXkaMv3oRu SSit/fN9Otxz2vxdrttcdOfHGC2l3KnwViaNIUqV/r3iU9WIBTC728l19QwW0leUePkS xzOcW8ssdIAm+8XXYJT3JtkEyed2TAZuf70QFb4y2naGNDXnfgE82EgpB8db1KRFkAFV uWj8bRk+0+QXKbChAjZVudkPfeViRBHi/4upxmBnC85zUwPXe/s/OMZimd0K5gpJ0n3B COPg== X-Gm-Message-State: AC+VfDwDIcZyQlaEDCF3Wo4c9zenOQBJUGEUFSKuGAdF+ZPQTW3LOGy8 KyD54O9T1ocBEGfj+GCu+bk= X-Google-Smtp-Source: ACHHUZ6+ywaGcwwhW/1e0+gJeV6PNofySNqKstbEfzqwcpLZqBmm/9miafUPnKio/eEZhl7jtElv7w== X-Received: by 2002:a17:902:d487:b0:1b2:22cd:9827 with SMTP id c7-20020a170902d48700b001b222cd9827mr9630245plg.1.1686602006638; Mon, 12 Jun 2023 13:33:26 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id ji1-20020a170903324100b001b016313b1dsm3324767plb.86.2023.06.12.13.33.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 13:33:25 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Luis Chamberlain , Sandeep Dhavale , Juan Yescas , Bart Van Assche , Ming Lei , Keith Busch Subject: [PATCH v6 6/8] block: Add support for filesystem requests and small segments Date: Mon, 12 Jun 2023 13:33:12 -0700 Message-Id: <20230612203314.17820-7-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612203314.17820-1-bvanassche@acm.org> References: <20230612203314.17820-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. Reviewed-by: Luis Chamberlain Tested-by: Sandeep Dhavale Cc: Christoph Hellwig Cc: Ming Lei Cc: Keith Busch Signed-off-by: Bart Van Assche --- block/blk-merge.c | 8 ++++++-- block/blk-mq.c | 2 ++ block/blk.h | 11 +++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 65e75efa9bd3..0b28f6df07bc 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -294,7 +294,8 @@ 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, @@ -544,7 +545,10 @@ 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 && + (!blk_queue_sub_page_limits(&q->limits) || + bvec.bv_len <= q->limits.max_segment_size)) + /* single-segment bvec optimization */ 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 1749f5890606..ad787c14ea09 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2936,6 +2936,8 @@ void blk_mq_submit_bio(struct bio *bio) bio = __bio_split_to_limits(bio, &q->limits, &nr_segs); if (!bio) return; + } else if (bio->bi_vcnt == 1) { + nr_segs = blk_segments(&q->limits, bio->bi_io_vec[0].bv_len); } if (!bio_integrity_prep(bio)) diff --git a/block/blk.h b/block/blk.h index 18b898a38c72..e905cc6364fa 100644 --- a/block/blk.h +++ b/block/blk.h @@ -332,13 +332,12 @@ static inline bool bio_may_exceed_limits(struct bio *bio, } /* - * All drivers must accept single-segments bios that are <= PAGE_SIZE. - * 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 - * to the performance impact of cloned bios themselves the loop below - * doesn't matter anyway. + * Check whether bio splitting should be performed. This check may + * trigger the bio splitting code even if splitting is not necessary. */ + if (blk_queue_sub_page_limits(lim) && bio->bi_io_vec && + bio->bi_io_vec->bv_len > lim->max_segment_size) + return true; return lim->chunk_sectors || bio->bi_vcnt != 1 || bio->bi_io_vec->bv_len + bio->bi_io_vec->bv_offset > PAGE_SIZE; } From patchwork Mon Jun 12 20:33:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13277288 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 B52EFC7EE2E for ; Mon, 12 Jun 2023 20:33:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236594AbjFLUdb (ORCPT ); Mon, 12 Jun 2023 16:33:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236681AbjFLUd3 (ORCPT ); Mon, 12 Jun 2023 16:33:29 -0400 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A84BE10FC for ; Mon, 12 Jun 2023 13:33:28 -0700 (PDT) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1b3a6fc8067so15779605ad.3 for ; Mon, 12 Jun 2023 13:33:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686602008; x=1689194008; 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=h+3rH1/I9JYUC9AV7hb8Nbme0XVHrq65BO+O7WSem7o=; b=DIX81hQI59dj3BtOdYT/ldIw7UFTVpMbSdZtek4VIiLeTZpw4bjW/XdtNfeTzNPq3F 05lfxhSIEPSRlz/8UkNUnp8sXRL5Kp8eUsuFgacjFuN3d07Vtgg5KSKaexB7/uIWPnb/ kykW/ga3x4rspZ4RDSKz+fMuGUDEwCa8BTmvhAU8zzN9lFXIjf2j4DCiSuDk8xza+91Q ZGCrXxwoEjWvJEb6FN0BFCtEboc0sinLw10BWdvKEtMgoGCGe96zScM6vYM8fLK/C09M 1cj25Pmu22jkQodbhJaayUpgy++Pmb3TwoY28J2H889hRVTNbjZO2nDFyykAYNpVK5Kk R1sw== X-Gm-Message-State: AC+VfDySJNtMUx16ackx8ciwstVux7QlyyGTFq6ai61TIlw3VffJ7R// m44ItfxpAi5ym38yuc8j/Mo= X-Google-Smtp-Source: ACHHUZ58dz+iv/BsbrZlS7DI2Y3W8VhQ8/RxK2kfezpujyVSFBZCL6KBaRh+Bm9oLMANo1mIE7LX3g== X-Received: by 2002:a17:903:248:b0:1b2:4e00:a3a9 with SMTP id j8-20020a170903024800b001b24e00a3a9mr7158565plh.41.1686602007995; Mon, 12 Jun 2023 13:33:27 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id ji1-20020a170903324100b001b016313b1dsm3324767plb.86.2023.06.12.13.33.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 13:33:27 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Luis Chamberlain , Sandeep Dhavale , Juan Yescas , Bart Van Assche , Douglas Gilbert , "Martin K . Petersen" Subject: [PATCH v6 7/8] scsi_debug: Support configuring the maximum segment size Date: Mon, 12 Jun 2023 13:33:13 -0700 Message-Id: <20230612203314.17820-8-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612203314.17820-1-bvanassche@acm.org> References: <20230612203314.17820-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. Acked-by: Douglas Gilbert Reviewed-by: Luis Chamberlain Cc: Martin K. Petersen Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 8c58128ad32a..e951c622bf64 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -752,6 +752,7 @@ static int sdebug_host_max_queue; /* per host */ static int sdebug_lowest_aligned = DEF_LOWEST_ALIGNED; static int sdebug_max_luns = DEF_MAX_LUNS; static int sdebug_max_queue = SDEBUG_CANQUEUE; /* per submit queue */ +static unsigned int sdebug_max_segment_size = BLK_MAX_SEGMENT_SIZE; static unsigned int sdebug_medium_error_start = OPT_MEDIUM_ERR_ADDR; static int sdebug_medium_error_count = OPT_MEDIUM_ERR_NUM; static int sdebug_ndelay = DEF_NDELAY; /* if > 0 then unit is nanoseconds */ @@ -5735,6 +5736,7 @@ module_param_named(lowest_aligned, sdebug_lowest_aligned, int, S_IRUGO); module_param_named(lun_format, sdebug_lun_am_i, int, S_IRUGO | S_IWUSR); module_param_named(max_luns, sdebug_max_luns, int, S_IRUGO | S_IWUSR); module_param_named(max_queue, sdebug_max_queue, int, S_IRUGO | S_IWUSR); +module_param_named(max_segment_size, sdebug_max_segment_size, uint, S_IRUGO); module_param_named(medium_error_count, sdebug_medium_error_count, int, S_IRUGO | S_IWUSR); module_param_named(medium_error_start, sdebug_medium_error_start, int, @@ -5811,6 +5813,7 @@ MODULE_PARM_DESC(lowest_aligned, "lowest aligned lba (def=0)"); MODULE_PARM_DESC(lun_format, "LUN format: 0->peripheral (def); 1 --> flat address method"); MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)"); MODULE_PARM_DESC(max_queue, "max number of queued commands (1 to max(def))"); +MODULE_PARM_DESC(max_segment_size, "max bytes in a single segment"); MODULE_PARM_DESC(medium_error_count, "count of sectors to return follow on MEDIUM error"); MODULE_PARM_DESC(medium_error_start, "starting sector number to return MEDIUM error"); MODULE_PARM_DESC(ndelay, "response delay in nanoseconds (def=0 -> ignore)"); @@ -7723,6 +7726,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 Mon Jun 12 20:33:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13277289 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 0D24CC7EE43 for ; Mon, 12 Jun 2023 20:33:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236307AbjFLUdd (ORCPT ); Mon, 12 Jun 2023 16:33:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236681AbjFLUdc (ORCPT ); Mon, 12 Jun 2023 16:33:32 -0400 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C289B1709 for ; Mon, 12 Jun 2023 13:33:29 -0700 (PDT) Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-654f8b56807so4965759b3a.1 for ; Mon, 12 Jun 2023 13:33:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686602009; x=1689194009; 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=lpUcy7oYahIvhr78o+dNH1Dduzl5FT2Qd4Zw/NLc3wg=; b=ByEsXcCORi8LTsLanBhIA/iXA2MZh6PT12DVY/5NJ5CjWfTMGdHKrmI8MAKyaQA/cR CNQz7vzfKOcmJXwpHiQpbHuDcvrLV6xGVpUE0HFXoxJdxhdBOQJns+16XczK/q4XzDzb yBRtnMfK8/I4tRI4efDTc59Wa4eQpNRNQwb1VUVrkko1GmHjjkxdQqLTAW0dAOBbepsE ywEknqzDiHRa6ahTxDIZM2nx+tUMGID2W/DLpMHLuuRianpWPnmbtoWlxVKCwJGdPzaJ c0ABrniJJZB6gf/kZ5JhIYxPfGZXV5gHkpvUriiyHEI6E1Bx7GHwB1QbbPmlkEkwce/U C2fg== X-Gm-Message-State: AC+VfDx80s0i41WCjqPzI9SstAeKavfYgwIsybjPogFtNd3x/To/bcBO IQRNkhF0InxH4LnCZuoziGebR37WZANPMg== X-Google-Smtp-Source: ACHHUZ4BVbKU4FvUfyz4et5GgOsgFDpVPtG7mWv3REFZ+nKtm4vkJtFTb07iV0siiu1SgxMirm/JLw== X-Received: by 2002:a17:903:1209:b0:1b0:3224:e53a with SMTP id l9-20020a170903120900b001b03224e53amr9781355plh.20.1686602009167; Mon, 12 Jun 2023 13:33:29 -0700 (PDT) Received: from asus.hsd1.ca.comcast.net ([98.51.102.78]) by smtp.gmail.com with ESMTPSA id ji1-20020a170903324100b001b016313b1dsm3324767plb.86.2023.06.12.13.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 13:33:28 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Luis Chamberlain , Sandeep Dhavale , Juan Yescas , Bart Van Assche , Chaitanya Kulkarni , Ming Lei , Damien Le Moal Subject: [PATCH v6 8/8] null_blk: Support configuring the maximum segment size Date: Mon, 12 Jun 2023 13:33:14 -0700 Message-Id: <20230612203314.17820-9-bvanassche@acm.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612203314.17820-1-bvanassche@acm.org> References: <20230612203314.17820-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(). Reviewed-by: Chaitanya Kulkarni Reviewed-by: Luis Chamberlain Cc: Christoph Hellwig Cc: Ming Lei Cc: Damien Le Moal Signed-off-by: Bart Van Assche --- drivers/block/null_blk/main.c | 19 ++++++++++++++++--- drivers/block/null_blk/null_blk.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index b3fedafe301e..9c9098f1bd52 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 = BLK_MAX_SEGMENT_SIZE; +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); @@ -550,6 +555,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, @@ -652,7 +658,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," @@ -722,6 +729,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; @@ -1248,6 +1256,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, @@ -1283,7 +1293,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); @@ -1310,7 +1321,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); @@ -2161,6 +2173,7 @@ static int null_add_dev(struct nullb_device *dev) dev->max_sectors = queue_max_hw_sectors(nullb->q); dev->max_sectors = min(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 929f659dd255..7bf80b0035f5 100644 --- a/drivers/block/null_blk/null_blk.h +++ b/drivers/block/null_blk/null_blk.h @@ -107,6 +107,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 */