From patchwork Mon Jun 16 22:33:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 897500 Received: from 003.mia.mailroute.net (003.mia.mailroute.net [199.89.3.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61DF021882B; Mon, 16 Jun 2025 22:34:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113248; cv=none; b=Hr37puJpZrnAEcdt91sZOXduf6O7aQVgkPMOR01kBhDDpw+t+LmhHDMFqSxbVDy0uIpKo+6Tk+e0rwkqziwG7PYezM1C0S/y6RPVHDdq3gjS9kssF9wkBCu/bKg4YdeXQVT83rNLnasGDU/2k2UIt4nT44lJ5qgXeqPf7bAdtqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113248; c=relaxed/simple; bh=6KWLiaHT2G15XUIgczC5dweZMYdMw2OhuVSwqi1N070=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AK5PvZzsDwCIOQ6ACuED8lgZHZmzK/tHNJ8bhpm2TFheIAlBs47/xhLRBMAO5q5qBTEjqjoEF6F7N1qcBXJF1PXmpUyDqk/kvUMAwdrL/RmXvMVEUNptmrIy4V0xuNY5d1tIsqAUdCb76HE/+JOXNaLUUzmv0akvv7ZIFIimK34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=qvTjFTpY; arc=none smtp.client-ip=199.89.3.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="qvTjFTpY" Received: from localhost (localhost [127.0.0.1]) by 003.mia.mailroute.net (Postfix) with ESMTP id 4bLlCx37jwzlgqxq; Mon, 16 Jun 2025 22:34:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1750113243; x=1752705244; bh=zGhhv pwkmk/v+KzVsp65m2pIBhdvNNox27Y0g4lOBEw=; b=qvTjFTpYJO5nli7I2Q//5 jlkplro1nyPJrzE5LyXs/Id0zkHh3nEv0ZTK1At92lfUrq5t5b6nk7Q6PqoUe8dF kUlTwmDBCJWKbkqAhyls9KKXkIaNLYXrTY7DJ4NQKP18qBdywi+gJBMNi0b/XfeK pc3dZEgBuwjlnCoVoM29w3o7HK8o8tjMmk1AGJn4dc2fNYpKxxS12RVRPNtI9jKl ZtBxXqfezPZk61F5EsqDuk5USXXLWmjJus38dm/mSdlQhkoE5Rb6hH+n8XsvVoe2 e7Etf/69lLpTfaA1Xu4q5lk/rF2CDj63fJS6LShlAn+uwcLNGhXYN2IvDzVveaMk A== X-Virus-Scanned: by MailRoute Received: from 003.mia.mailroute.net ([127.0.0.1]) by localhost (003.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id E0Yb5wTW_FlQ; Mon, 16 Jun 2025 22:34:03 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 003.mia.mailroute.net (Postfix) with ESMTPSA id 4bLlCn3P5XzlgqVy; Mon, 16 Jun 2025 22:33:56 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Bart Van Assche , Hannes Reinecke , Nitesh Shetty , Ming Lei Subject: [PATCH v18 01/12] block: Support block drivers that preserve the order of write requests Date: Mon, 16 Jun 2025 15:33:01 -0700 Message-ID: <20250616223312.1607638-2-bvanassche@acm.org> X-Mailer: git-send-email 2.50.0.rc2.692.g299adb8693-goog In-Reply-To: <20250616223312.1607638-1-bvanassche@acm.org> References: <20250616223312.1607638-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some storage controllers preserve the request order per hardware queue. Introduce the request queue limit member variable 'driver_preserves_write_order' to allow block drivers to indicate that the order of write commands is preserved per hardware queue and hence that serialization of writes per zone is not required if all pending writes are submitted to the same hardware queue. Cc: Damien Le Moal Cc: Hannes Reinecke Cc: Nitesh Shetty Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- block/blk-settings.c | 2 ++ include/linux/blkdev.h | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/block/blk-settings.c b/block/blk-settings.c index a000daafbfb4..bceb9a9cb5ba 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -814,6 +814,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, } t->max_secure_erase_sectors = min_not_zero(t->max_secure_erase_sectors, b->max_secure_erase_sectors); + t->driver_preserves_write_order = t->driver_preserves_write_order && + b->driver_preserves_write_order; t->zone_write_granularity = max(t->zone_write_granularity, b->zone_write_granularity); if (!(t->features & BLK_FEAT_ZONED)) { diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index a59880c809c7..6d01269f9fcf 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -408,6 +408,11 @@ struct queue_limits { unsigned int max_open_zones; unsigned int max_active_zones; + /* + * Whether or not the block driver preserves the order of write + * requests per hardware queue. Set by the block driver. + */ + bool driver_preserves_write_order; /* * Drivers that set dma_alignment to less than 511 must be prepared to From patchwork Mon Jun 16 22:33:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 897274 Received: from 003.mia.mailroute.net (003.mia.mailroute.net [199.89.3.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B554E221F39; Mon, 16 Jun 2025 22:34:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113252; cv=none; b=fdFgDcydsH9E/UBrsRR+uhmalNYUTBRJhoXtFOcQsDL9XOIM8drrN6OvF+T61EzOKN8kuLIZrHUtyw1iNmnsj+luzgeKYhAcVUnem6EKa31DAaPcr1sDwX2pzQ3YyLgnuAwHfzRpE2wvTKcboLPCYQiognrq6HcfuPy9ypULf+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113252; c=relaxed/simple; bh=WkspTtZktCrVVhYMViyuXOzCPzrEE+4QyKqMe0hyo8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pF/tZc8xMOAVCfxh8zd4/iY4qEuoo6OnVTWiuCttjMtQ+orizgJq7HZZgoHXqJC+e+ATYxAWSfrtjSr/prUHmhRjMMd/TpvigavFW3/5AQDpYai7nQ/DfOTc9T31huTBE1C7N23p7Z8OSQ6Yf5DAcC9IvftEDFwb/J3nFGep/tM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=4jPPS6F+; arc=none smtp.client-ip=199.89.3.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="4jPPS6F+" Received: from localhost (localhost [127.0.0.1]) by 003.mia.mailroute.net (Postfix) with ESMTP id 4bLlD15WThzlgqxn; Mon, 16 Jun 2025 22:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1750113248; x=1752705249; bh=NDbe3 yo4MseCqIsSuJwry3J82K0MgPm+dnsCV0z82NI=; b=4jPPS6F+Z/6a03CIobuYC FyF626RXcHp8idwf3Fk+VEBiWOv6ZPX//Lk4CgjPhzD2ULaqWx5qRNAspVqVHgaE 606E84zJR7cE0ae6NnuZIXz2+YL2MytqMBfhzyMzsbTUjKLi/nY9NXjiHh6XV5Hr ZSrJx7hlmc/b+3M0tyVlFJ/MiKLTWcXnojukOSbiZRr+uYP4XWhZGCQU2f24uPub uU61o2oaCFqLuGE/xvYpIeeqeL/sX4/PlB8VScX+uRydRXUUTEbN2O17mphJMkjo 8MxCk04dOt2gevS9z18DtsuxGtW/JBhxM4BIONUEnsa5fKLqBsCk5mxMIba4zOn3 g== X-Virus-Scanned: by MailRoute Received: from 003.mia.mailroute.net ([127.0.0.1]) by localhost (003.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id a5HpaHXybln9; Mon, 16 Jun 2025 22:34:08 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 003.mia.mailroute.net (Postfix) with ESMTPSA id 4bLlCw38khzlgqVx; Mon, 16 Jun 2025 22:34:03 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Bart Van Assche Subject: [PATCH v18 02/12] block: Rework request allocation in blk_mq_submit_bio() Date: Mon, 16 Jun 2025 15:33:02 -0700 Message-ID: <20250616223312.1607638-3-bvanassche@acm.org> X-Mailer: git-send-email 2.50.0.rc2.692.g299adb8693-goog In-Reply-To: <20250616223312.1607638-1-bvanassche@acm.org> References: <20250616223312.1607638-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Prepare for allocating a request from a specific hctx by making blk_mq_submit_bio() allocate a request later. The performance impact of this patch on the hot path is small: if a request is cached, one percpu_ref_get(&q->q_usage_counter) call and one percpu_ref_put(&q->q_usage_counter) call are added to the hot path. Cc: Christoph Hellwig Cc: Damien Le Moal Signed-off-by: Bart Van Assche --- block/blk-mq.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 4806b867e37d..b22b56042e91 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3116,11 +3116,6 @@ void blk_mq_submit_bio(struct bio *bio) struct request *rq; blk_status_t ret; - /* - * If the plug has a cached request for this queue, try to use it. - */ - rq = blk_mq_peek_cached_request(plug, q, bio->bi_opf); - /* * A BIO that was released from a zone write plug has already been * through the preparation in this function, already holds a reference @@ -3129,19 +3124,11 @@ void blk_mq_submit_bio(struct bio *bio) */ if (bio_zone_write_plugging(bio)) { nr_segs = bio->__bi_nr_segments; - if (rq) - blk_queue_exit(q); goto new_request; } - /* - * The cached request already holds a q_usage_counter reference and we - * don't have to acquire a new one if we use it. - */ - if (!rq) { - if (unlikely(bio_queue_enter(bio))) - return; - } + if (unlikely(bio_queue_enter(bio))) + return; /* * Device reconfiguration may change logical block size or reduce the @@ -3173,8 +3160,15 @@ void blk_mq_submit_bio(struct bio *bio) goto queue_exit; new_request: + rq = blk_mq_peek_cached_request(plug, q, bio->bi_opf); if (rq) { blk_mq_use_cached_rq(rq, plug, bio); + /* + * Here we hold two references: one because of the + * bio_queue_enter() call and a second one as the result of + * request allocation. Drop one. + */ + blk_queue_exit(q); } else { rq = blk_mq_get_new_requests(q, plug, bio); if (unlikely(!rq)) { @@ -3220,12 +3214,7 @@ void blk_mq_submit_bio(struct bio *bio) return; queue_exit: - /* - * Don't drop the queue reference if we were trying to use a cached - * request and thus didn't acquire one. - */ - if (!rq) - blk_queue_exit(q); + blk_queue_exit(q); } #ifdef CONFIG_BLK_MQ_STACKING From patchwork Mon Jun 16 22:33:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 897499 Received: from 003.mia.mailroute.net (003.mia.mailroute.net [199.89.3.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 332D4223DD5; Mon, 16 Jun 2025 22:34:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113257; cv=none; b=SyqMyxAgCu9ud1spjXI9SLt/AYYs9vrM3tiOLicf+/a4KlGsRIfL1SBA5JQW9G8z1/mHH0HRLqZOznM/2Ww22/Cz1z55KbxIakdP7LwAcVW/LvqoDQ+A9YeejdcarF7l0+TrgLJ4g71EZWrQdFiECSXaa1ENnSISpKjst+9rmRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113257; c=relaxed/simple; bh=oB+FK6wc34qj/05XQvy9U02kNtN4u4syv+paBEBkuLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tmJFcr83zSolMbG5X31RYZm8f9H8LYRsC2+D6XDGU2oj42SGuucNbPEHwyTRXAKqjz6z7trprJjIrRXof5Fiarv2vOpyjY4wjGiHfJRY8DG4pD/F1tASjgE4m4GoUORu3BMhbFWxUdzaMogXhjjmPqawNTszqaMgxCWbEpyKlRQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=Ydmj6C+h; arc=none smtp.client-ip=199.89.3.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="Ydmj6C+h" Received: from localhost (localhost [127.0.0.1]) by 003.mia.mailroute.net (Postfix) with ESMTP id 4bLlD65BBszlgqxn; Mon, 16 Jun 2025 22:34:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1750113253; x=1752705254; bh=VPQ7Z DSVFj8W8B/TtqF1oUfcWbdyfa+IDng6PBfMreU=; b=Ydmj6C+hOA2Qf/2THz5qk URZyeFTTVQ4gtWa1MPv6tsusezRnDVxruB17cCWVFig7IgHPV0NorCq01/DhZDvp hngTx+qOiaqH0FwQL8pqhLPyLJU69QTtsCumexIFz1Mo2/okG2mwJoRxVMpzdEZB 7RCpmO9FD4YD2XzAVjMwpz/QSD4QpXCDYQuruHQmsvoDLJsp3mIieOShk9cXbo2N JCxOU2DvQ5kFLUHOTTiw2hWSaPkye5kbmhJt52afwaOx3eclkPYjZ1n5Bt0+6wnv xzEp8mxFzKHxeOMrZJzi2Ijo1PId3s/B9m6p1lNT8z1tpOONnj901tkrov8iLM6P g== X-Virus-Scanned: by MailRoute Received: from 003.mia.mailroute.net ([127.0.0.1]) by localhost (003.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 3ivdfYr48WcO; Mon, 16 Jun 2025 22:34:13 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 003.mia.mailroute.net (Postfix) with ESMTPSA id 4bLlD12BbHzlgqVy; Mon, 16 Jun 2025 22:34:08 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Bart Van Assche Subject: [PATCH v18 03/12] block: Support allocating from a specific software queue Date: Mon, 16 Jun 2025 15:33:03 -0700 Message-ID: <20250616223312.1607638-4-bvanassche@acm.org> X-Mailer: git-send-email 2.50.0.rc2.692.g299adb8693-goog In-Reply-To: <20250616223312.1607638-1-bvanassche@acm.org> References: <20250616223312.1607638-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A later patch will preserve the order of pipelined zoned writes by submitting all zoned writes per zone to the same software queue as previously submitted zoned writes. Hence support allocating a request from a specific software queue. Cc: Christoph Hellwig Cc: Damien Le Moal Signed-off-by: Bart Van Assche --- block/blk-mq.c | 18 ++++++++++++++---- block/blk-mq.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index b22b56042e91..9dab1caf750a 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -485,6 +485,7 @@ __blk_mq_alloc_requests_batch(struct blk_mq_alloc_data *data) static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data) { struct request_queue *q = data->q; + int from_cpu = data->from_cpu; u64 alloc_time_ns = 0; struct request *rq; unsigned int tag; @@ -497,7 +498,8 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data) data->flags |= BLK_MQ_REQ_NOWAIT; retry: - data->ctx = blk_mq_get_ctx(q); + data->from_cpu = from_cpu >= 0 ? from_cpu : raw_smp_processor_id(); + data->ctx = __blk_mq_get_ctx(q, data->from_cpu); data->hctx = blk_mq_map_queue(data->cmd_flags, data->ctx); if (q->elevator) { @@ -579,6 +581,7 @@ static struct request *blk_mq_rq_cache_fill(struct request_queue *q, .rq_flags = 0, .nr_tags = plug->nr_ios, .cached_rqs = &plug->cached_rqs, + .from_cpu = -1, .ctx = NULL, .hctx = NULL }; @@ -644,6 +647,7 @@ struct request *blk_mq_alloc_request(struct request_queue *q, blk_opf_t opf, .cmd_flags = opf, .rq_flags = 0, .nr_tags = 1, + .from_cpu = -1, .cached_rqs = NULL, .ctx = NULL, .hctx = NULL @@ -678,6 +682,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, .cmd_flags = opf, .rq_flags = 0, .nr_tags = 1, + .from_cpu = -1, .cached_rqs = NULL, .ctx = NULL, .hctx = NULL @@ -3012,6 +3017,7 @@ static bool blk_mq_attempt_bio_merge(struct request_queue *q, } static struct request *blk_mq_get_new_requests(struct request_queue *q, + int from_cpu, struct blk_plug *plug, struct bio *bio) { @@ -3021,6 +3027,7 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q, .shallow_depth = 0, .cmd_flags = bio->bi_opf, .rq_flags = 0, + .from_cpu = from_cpu, .nr_tags = 1, .cached_rqs = NULL, .ctx = NULL, @@ -3046,7 +3053,7 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q, * Check if there is a suitable cached request and return it. */ static struct request *blk_mq_peek_cached_request(struct blk_plug *plug, - struct request_queue *q, blk_opf_t opf) + struct request_queue *q, int from_cpu, blk_opf_t opf) { enum hctx_type type = blk_mq_get_hctx_type(opf); struct request *rq; @@ -3056,6 +3063,8 @@ static struct request *blk_mq_peek_cached_request(struct blk_plug *plug, rq = rq_list_peek(&plug->cached_rqs); if (!rq || rq->q != q) return NULL; + if (from_cpu >= 0 && rq->mq_ctx->cpu != from_cpu) + return NULL; if (type != rq->mq_hctx->type && (type != HCTX_TYPE_READ || rq->mq_hctx->type != HCTX_TYPE_DEFAULT)) return NULL; @@ -3114,6 +3123,7 @@ void blk_mq_submit_bio(struct bio *bio) struct blk_mq_hw_ctx *hctx; unsigned int nr_segs; struct request *rq; + int from_cpu = -1; blk_status_t ret; /* @@ -3160,7 +3170,7 @@ void blk_mq_submit_bio(struct bio *bio) goto queue_exit; new_request: - rq = blk_mq_peek_cached_request(plug, q, bio->bi_opf); + rq = blk_mq_peek_cached_request(plug, q, from_cpu, bio->bi_opf); if (rq) { blk_mq_use_cached_rq(rq, plug, bio); /* @@ -3170,7 +3180,7 @@ void blk_mq_submit_bio(struct bio *bio) */ blk_queue_exit(q); } else { - rq = blk_mq_get_new_requests(q, plug, bio); + rq = blk_mq_get_new_requests(q, from_cpu, plug, bio); if (unlikely(!rq)) { if (bio->bi_opf & REQ_NOWAIT) bio_wouldblock_error(bio); diff --git a/block/blk-mq.h b/block/blk-mq.h index affb2e14b56e..52e907547b55 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -156,6 +156,7 @@ struct blk_mq_alloc_data { struct rq_list *cached_rqs; /* input & output parameter */ + int from_cpu; struct blk_mq_ctx *ctx; struct blk_mq_hw_ctx *hctx; }; From patchwork Mon Jun 16 22:33:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 897273 Received: from 003.mia.mailroute.net (003.mia.mailroute.net [199.89.3.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DDAC1DB92A; Mon, 16 Jun 2025 22:34:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113263; cv=none; b=aqdCd4yUYoFnbETXmykWaWucKfztD2vakY0DAUqg9aulv6drsYUnSG61MqqXsWtaOjD3IE5rfNHst1Gi1T3CUYu1aPOH0nXnDX30tyrdsmh6D1NscUAd2rL1t7JZWqDLcY7oU2uDNP92SJG67jAyGq2jgNrnfkPdxB7ZEdQ0pFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113263; c=relaxed/simple; bh=ntA8KiqVTDS23AUUqj6SV5pCYkwNF/Gg+KoeULYMKSU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XELx/WT7eP2FkZjHyIHnzg8ipldEyEnn7eQDWkGQXT9Z3fAf5/5aT0BSBrfLRIgTjwiS/vs6TwWcytBYvXou/zAwZLPbyiCB7h124DoOM/aYysE0jm6zlnQyuWq/a0Yu3vID+L3mbee4FWZszV7hpnJdRsjAeLbf32uSiZvCYqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=rS4jMzJd; arc=none smtp.client-ip=199.89.3.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="rS4jMzJd" Received: from localhost (localhost [127.0.0.1]) by 003.mia.mailroute.net (Postfix) with ESMTP id 4bLlDD32Zxzlgqxq; Mon, 16 Jun 2025 22:34:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1750113258; x=1752705259; bh=JFqAP Ri/vIgzyDFpGmlkFYzHBYBdAEH9luUneuwjDwE=; b=rS4jMzJdbfsx5dxtGsB3v CrstKi/cB5FozB45s7H+HOtMHzdiOYSoX0rd6DsZdaEkGHvKvy5vHerdHOi21a07 3j9Rj2CslS0liAHzwMpRQXCDH0OIO9zXcWvXykDF8mfeEdCnk3RyhTk1zESqRS/l tdPz0slEX7+TqU7ljMkNxJ1+NI4Q5ut4pNlHeAncpvPbNLW6WWf5FepmoCP5ACAz W6T7a0/lq6RN7m0qZynohsdn3Mqug7qI3s/iIxEo4vhirBd0cb141HWezIkCy4ro nB4qe1l9+ZuYwQOgNe6ypUM1UjZPn5jXBEPmJn70x6uPk7LdFMFM1c7gEqIsjach Q== X-Virus-Scanned: by MailRoute Received: from 003.mia.mailroute.net ([127.0.0.1]) by localhost (003.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id ewJMwwrOFp2g; Mon, 16 Jun 2025 22:34:18 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 003.mia.mailroute.net (Postfix) with ESMTPSA id 4bLlD6175XzlgqVx; Mon, 16 Jun 2025 22:34:13 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Bart Van Assche , Yu Kuai Subject: [PATCH v18 04/12] blk-mq: Restore the zoned write order when requeuing Date: Mon, 16 Jun 2025 15:33:04 -0700 Message-ID: <20250616223312.1607638-5-bvanassche@acm.org> X-Mailer: git-send-email 2.50.0.rc2.692.g299adb8693-goog In-Reply-To: <20250616223312.1607638-1-bvanassche@acm.org> References: <20250616223312.1607638-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Zoned writes may be requeued. This happens if a block driver returns BLK_STS_RESOURCE, to handle SCSI unit attentions or by the SCSI error handler after error handling has finished. Requests may be requeued in another order than submitted. Restore the request order if requests are requeued. Add RQF_DONTPREP to RQF_NOMERGE_FLAGS because this patch may cause RQF_DONTPREP requests to be sent to the code that checks whether a request can be merged and RQF_DONTPREP requests must not be merged. Cc: Christoph Hellwig Cc: Damien Le Moal Cc: Yu Kuai Signed-off-by: Bart Van Assche --- block/bfq-iosched.c | 2 ++ block/blk-mq.c | 20 +++++++++++++++++++- block/blk-mq.h | 2 ++ block/kyber-iosched.c | 2 ++ block/mq-deadline.c | 7 ++++++- include/linux/blk-mq.h | 13 ++++++++++++- 6 files changed, 43 insertions(+), 3 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 0cb1e9873aab..1bd3afe5d779 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -6276,6 +6276,8 @@ static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq, if (flags & BLK_MQ_INSERT_AT_HEAD) { list_add(&rq->queuelist, &bfqd->dispatch); + } else if (flags & BLK_MQ_INSERT_ORDERED) { + blk_mq_insert_ordered(rq, &bfqd->dispatch); } else if (!bfqq) { list_add_tail(&rq->queuelist, &bfqd->dispatch); } else { diff --git a/block/blk-mq.c b/block/blk-mq.c index 9dab1caf750a..1735b1ac0574 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1562,7 +1562,9 @@ static void blk_mq_requeue_work(struct work_struct *work) * already. Insert it into the hctx dispatch list to avoid * block layer merges for the request. */ - if (rq->rq_flags & RQF_DONTPREP) + if (blk_rq_is_seq_zoned_write(rq)) + blk_mq_insert_request(rq, BLK_MQ_INSERT_ORDERED); + else if (rq->rq_flags & RQF_DONTPREP) blk_mq_request_bypass_insert(rq, 0); else blk_mq_insert_request(rq, BLK_MQ_INSERT_AT_HEAD); @@ -2595,6 +2597,20 @@ static void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, blk_mq_run_hw_queue(hctx, run_queue_async); } +void blk_mq_insert_ordered(struct request *rq, struct list_head *list) +{ + struct request_queue *q = rq->q; + struct request *rq2; + + list_for_each_entry(rq2, list, queuelist) + if (rq2->q == q && blk_rq_pos(rq2) > blk_rq_pos(rq)) + break; + + /* Insert rq before rq2. If rq2 is the list head, append at the end. */ + list_add_tail(&rq->queuelist, &rq2->queuelist); +} +EXPORT_SYMBOL_GPL(blk_mq_insert_ordered); + static void blk_mq_insert_request(struct request *rq, blk_insert_t flags) { struct request_queue *q = rq->q; @@ -2649,6 +2665,8 @@ static void blk_mq_insert_request(struct request *rq, blk_insert_t flags) spin_lock(&ctx->lock); if (flags & BLK_MQ_INSERT_AT_HEAD) list_add(&rq->queuelist, &ctx->rq_lists[hctx->type]); + else if (flags & BLK_MQ_INSERT_ORDERED) + blk_mq_insert_ordered(rq, &ctx->rq_lists[hctx->type]); else list_add_tail(&rq->queuelist, &ctx->rq_lists[hctx->type]); diff --git a/block/blk-mq.h b/block/blk-mq.h index 52e907547b55..75b657554f1f 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -40,8 +40,10 @@ enum { typedef unsigned int __bitwise blk_insert_t; #define BLK_MQ_INSERT_AT_HEAD ((__force blk_insert_t)0x01) +#define BLK_MQ_INSERT_ORDERED ((__force blk_insert_t)0x02) void blk_mq_submit_bio(struct bio *bio); +void blk_mq_insert_ordered(struct request *rq, struct list_head *list); int blk_mq_poll(struct request_queue *q, blk_qc_t cookie, struct io_comp_batch *iob, unsigned int flags); void blk_mq_exit_queue(struct request_queue *q); diff --git a/block/kyber-iosched.c b/block/kyber-iosched.c index 4dba8405bd01..051c05ceafd7 100644 --- a/block/kyber-iosched.c +++ b/block/kyber-iosched.c @@ -603,6 +603,8 @@ static void kyber_insert_requests(struct blk_mq_hw_ctx *hctx, trace_block_rq_insert(rq); if (flags & BLK_MQ_INSERT_AT_HEAD) list_move(&rq->queuelist, head); + else if (flags & BLK_MQ_INSERT_ORDERED) + blk_mq_insert_ordered(rq, head); else list_move_tail(&rq->queuelist, head); sbitmap_set_bit(&khd->kcq_map[sched_domain], diff --git a/block/mq-deadline.c b/block/mq-deadline.c index 2edf1cac06d5..110fef65b829 100644 --- a/block/mq-deadline.c +++ b/block/mq-deadline.c @@ -710,7 +710,12 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq, * set expire time and add to fifo list */ rq->fifo_time = jiffies + dd->fifo_expire[data_dir]; - list_add_tail(&rq->queuelist, &per_prio->fifo_list[data_dir]); + if (flags & BLK_MQ_INSERT_ORDERED) + blk_mq_insert_ordered(rq, + &per_prio->fifo_list[data_dir]); + else + list_add_tail(&rq->queuelist, + &per_prio->fifo_list[data_dir]); } } diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index de8c85a03bb7..6833d5a980ef 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -86,7 +86,7 @@ enum rqf_flags { /* flags that prevent us from merging requests: */ #define RQF_NOMERGE_FLAGS \ - (RQF_STARTED | RQF_FLUSH_SEQ | RQF_SPECIAL_PAYLOAD) + (RQF_STARTED | RQF_FLUSH_SEQ | RQF_DONTPREP | RQF_SPECIAL_PAYLOAD) enum mq_rq_state { MQ_RQ_IDLE = 0, @@ -1189,4 +1189,15 @@ static inline int blk_rq_map_sg(struct request *rq, struct scatterlist *sglist) } void blk_dump_rq_flags(struct request *, char *); +static inline bool blk_rq_is_seq_zoned_write(struct request *rq) +{ + switch (req_op(rq)) { + case REQ_OP_WRITE: + case REQ_OP_WRITE_ZEROES: + return bdev_zone_is_seq(rq->q->disk->part0, blk_rq_pos(rq)); + default: + return false; + } +} + #endif /* BLK_MQ_H */ From patchwork Mon Jun 16 22:33:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 897498 Received: from 003.mia.mailroute.net (003.mia.mailroute.net [199.89.3.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C42C31DB92A; Mon, 16 Jun 2025 22:34:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113267; cv=none; b=lIbSnaT9NNZvDxHx1A2OHRhAPMZA/1TTOoBtDgl73K6vuVV+2PpSNcHMxvKUWhI/9y07ytov9u3+is66y/sy8QCnhf/f7giBgWFZoLi0RkwbpGCNoq8UXMqTDJMRxQGfWIUK217UYZD94jPoxlc58MrMfaTJP6WkaNX+Fvt0m/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113267; c=relaxed/simple; bh=nUu/P956qFKPTLZJ+EE+nbZr5DTSyfgJMzZo3aIryZw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gdaMRGGDYxyuEWz5zEMkmYAvKqU9QP/ms/psyXkmByHwuPgguZtm1mkEhcWVY4nwkttCAqsJSiD4KTSJu0QUnFO9qAt+9rSzSVdB54ri8CIswmw8r4AOshnwpfhYZNCB+t4NCKkC8OftPVD67U5YSxbsWF3q7HlaqgAKASoIZoI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=l/y4fsy5; arc=none smtp.client-ip=199.89.3.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="l/y4fsy5" Received: from localhost (localhost [127.0.0.1]) by 003.mia.mailroute.net (Postfix) with ESMTP id 4bLlDK0xG7zlgqxr; Mon, 16 Jun 2025 22:34:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1750113263; x=1752705264; bh=3TDpt GXYFDjQWPXazFKS9qAdi/nTvRIVWafz+MxYZak=; b=l/y4fsy5fMyfGUeH3W+1S aSNWbhlPLBw+k7cw2TDUz82jBVfXKWR0ioHN54/RhRPucp+uMPTXE20khGugdl8z 6MSbERdj3uUAql2hzY1z/d+tQ1RiTrozlFtr3+s1PqCQ2+5stF/pV/sn031VwrZx atJq998sH+8h1SoRKgeX41jNf4FDbdsSUO3ovRHnu0jzsxwbfHBkpWNRGC14fWNj gJu/A6TLE3YsZkDWAFx7Qiwn5DnASSSqCboHNw/We2Hm3e7K5ZDehTpRK9GjkoWG F87MafmMCBxhm/8TC0r05N5egZaT2LjNjeew/V8JPiAsAyuhud4XJAsyKW1uFNW/ A== X-Virus-Scanned: by MailRoute Received: from 003.mia.mailroute.net ([127.0.0.1]) by localhost (003.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id ngWWGQLvfR0Y; Mon, 16 Jun 2025 22:34:23 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 003.mia.mailroute.net (Postfix) with ESMTPSA id 4bLlDC4mb3zlgqVy; Mon, 16 Jun 2025 22:34:18 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Bart Van Assche Subject: [PATCH v18 05/12] blk-zoned: Add an argument to blk_zone_plug_bio() Date: Mon, 16 Jun 2025 15:33:05 -0700 Message-ID: <20250616223312.1607638-6-bvanassche@acm.org> X-Mailer: git-send-email 2.50.0.rc2.692.g299adb8693-goog In-Reply-To: <20250616223312.1607638-1-bvanassche@acm.org> References: <20250616223312.1607638-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Prepare for preserving the order of pipelined zoned writes per zone. Cc: Christoph Hellwig Cc: Damien Le Moal Signed-off-by: Bart Van Assche --- block/blk-mq.c | 2 +- block/blk-zoned.c | 4 +++- drivers/md/dm.c | 2 +- include/linux/blkdev.h | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 1735b1ac0574..ec04ff556983 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3184,7 +3184,7 @@ void blk_mq_submit_bio(struct bio *bio) if (blk_mq_attempt_bio_merge(q, bio, nr_segs)) goto queue_exit; - if (blk_queue_is_zoned(q) && blk_zone_plug_bio(bio, nr_segs)) + if (blk_queue_is_zoned(q) && blk_zone_plug_bio(bio, nr_segs, &from_cpu)) goto queue_exit; new_request: diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 351d659280e1..a79bb71a83e0 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -1104,6 +1104,8 @@ static void blk_zone_wplug_handle_native_zone_append(struct bio *bio) * blk_zone_plug_bio - Handle a zone write BIO with zone write plugging * @bio: The BIO being submitted * @nr_segs: The number of physical segments of @bio + * @from_cpu: [out] CPU of the software queue to which the bio should be + * queued * * Handle write, write zeroes and zone append operations requiring emulation * using zone write plugging. @@ -1112,7 +1114,7 @@ static void blk_zone_wplug_handle_native_zone_append(struct bio *bio) * write plug. Otherwise, return false to let the submission path process * @bio normally. */ -bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs) +bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs, int *from_cpu) { struct block_device *bdev = bio->bi_bdev; diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 1726f0f828cc..18084277ea27 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1788,7 +1788,7 @@ static inline bool dm_zone_bio_needs_split(struct mapped_device *md, } static inline bool dm_zone_plug_bio(struct mapped_device *md, struct bio *bio) { - return dm_emulate_zone_append(md) && blk_zone_plug_bio(bio, 0); + return dm_emulate_zone_append(md) && blk_zone_plug_bio(bio, 0, NULL); } static blk_status_t __send_zone_reset_all_emulated(struct clone_info *ci, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 6d01269f9fcf..f3471c98c22f 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -842,7 +842,7 @@ static inline unsigned int disk_nr_zones(struct gendisk *disk) { return disk->nr_zones; } -bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs); +bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs, int *from_cpu); /** * disk_zone_capacity - returns the zone capacity of zone containing @sector From patchwork Mon Jun 16 22:33:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 897272 Received: from 003.mia.mailroute.net (003.mia.mailroute.net [199.89.3.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E54024A0C; Mon, 16 Jun 2025 22:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113272; cv=none; b=lFyx8xc0gk4EYfF8Tk5JSt1pPkX+GcbmE4qpCrPJW58YxawcpxfYmuCu0FlPM6pfMG8YF5TTpd3UR/y+EKGXl8eV7/326alflw3Wg8DvlzuxxqMHeEnAYvHpPjH+hOnluIqtOwK99Ww2NZMlKdF/Ch+HAAVO9TjlKFs+52pNcNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113272; c=relaxed/simple; bh=SSsXvsUdfN3Qm8rSKvHvTFQo24rID/Db6IyG1R/WrOs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K7vVlrjIzfcZAiLidRFtNT7h0+8IPw6LDT3OFoV2HopaFXjv540nxP6kha+iYwyefZQSfTtSePxCdtM681ThjJPkbDcnwjqCBqVe2tneL+DDONKLrOjRKS1yTUFj4r6KF8phNCVuYjgRJZmsqj9Fu6pJ+RyH/4VcKu1GC+UhSjc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=ZOvtGfvc; arc=none smtp.client-ip=199.89.3.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="ZOvtGfvc" Received: from localhost (localhost [127.0.0.1]) by 003.mia.mailroute.net (Postfix) with ESMTP id 4bLlDQ1wF0zlgqxs; Mon, 16 Jun 2025 22:34:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1750113268; x=1752705269; bh=OvhHE 5KSCs4+rbYXi5MhgMZPB2AOtH9lh4zoHhAh+YU=; b=ZOvtGfvcUwLRXLdU6WkBh Z3sjvpPewRwuZ6fuxs2AFbjsY1AJYf0iz03MFhEe/3hmfgb6o6TtKIfNP5Hillgy wooi6GVd31lNuwSQ2ioWjjg75X+EPuuzb/mRNREGgAW+QQLP4wOhV7OFl7IFJVno EC8KeUI32wHqNceRE/5hINqutiqkYq+sBpMenskkAsuDZ+DBUj26j8csmeEPE5TF tWaBocl1PKvO6QPdxKVZC7ddM6SX/bsz/SldEUjPaDMHWQfRB0niROKm6jVr4tW8 qIfF39LmuaNMsSqMoe0lweeI6Wdt+8WQnLMm+EhUpMBaXatOi9ENbc3YHSorW14u A== X-Virus-Scanned: by MailRoute Received: from 003.mia.mailroute.net ([127.0.0.1]) by localhost (003.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 75Acpz3Ih7iw; Mon, 16 Jun 2025 22:34:28 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 003.mia.mailroute.net (Postfix) with ESMTPSA id 4bLlDJ4sNnzlgqVx; Mon, 16 Jun 2025 22:34:23 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Bart Van Assche Subject: [PATCH v18 06/12] blk-zoned: Support pipelining of zoned writes Date: Mon, 16 Jun 2025 15:33:06 -0700 Message-ID: <20250616223312.1607638-7-bvanassche@acm.org> X-Mailer: git-send-email 2.50.0.rc2.692.g299adb8693-goog In-Reply-To: <20250616223312.1607638-1-bvanassche@acm.org> References: <20250616223312.1607638-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Support pipelining of zoned writes if the block driver preserves the write order per hardware queue. Track per zone to which software queue writes have been queued. If zoned writes are pipelined, submit new writes to the same software queue as the writes that are already in progress. This prevents reordering by submitting requests for the same zone to different software or hardware queues. Cc: Christoph Hellwig Cc: Damien Le Moal Signed-off-by: Bart Van Assche --- block/blk-mq.c | 4 ++-- block/blk-zoned.c | 30 +++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index ec04ff556983..6954de9f9fe9 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3147,8 +3147,8 @@ void blk_mq_submit_bio(struct bio *bio) /* * A BIO that was released from a zone write plug has already been * through the preparation in this function, already holds a reference - * on the queue usage counter, and is the only write BIO in-flight for - * the target zone. Go straight to preparing a request for it. + * on the queue usage counter. Go straight to preparing a request for + * it. */ if (bio_zone_write_plugging(bio)) { nr_segs = bio->__bi_nr_segments; diff --git a/block/blk-zoned.c b/block/blk-zoned.c index a79bb71a83e0..76f76fd83f73 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -51,6 +51,8 @@ static const char *const zone_cond_name[] = { * @zone_no: The number of the zone the plug is managing. * @wp_offset: The zone write pointer location relative to the start of the zone * as a number of 512B sectors. + * @from_cpu: Software queue to submit writes from for drivers that preserve + * the write order. * @bio_list: The list of BIOs that are currently plugged. * @bio_work: Work struct to handle issuing of plugged BIOs * @rcu_head: RCU head to free zone write plugs with an RCU grace period. @@ -63,6 +65,7 @@ struct blk_zone_wplug { unsigned int flags; unsigned int zone_no; unsigned int wp_offset; + int from_cpu; struct bio_list bio_list; struct work_struct bio_work; struct rcu_head rcu_head; @@ -72,8 +75,7 @@ struct blk_zone_wplug { /* * Zone write plug flags bits: * - BLK_ZONE_WPLUG_PLUGGED: Indicates that the zone write plug is plugged, - * that is, that write BIOs are being throttled due to a write BIO already - * being executed or the zone write plug bio list is not empty. + * that is, that write BIOs are being throttled. * - BLK_ZONE_WPLUG_NEED_WP_UPDATE: Indicates that we lost track of a zone * write pointer offset and need to update it. * - BLK_ZONE_WPLUG_UNHASHED: Indicates that the zone write plug was removed @@ -568,6 +570,7 @@ static struct blk_zone_wplug *disk_get_and_lock_zone_wplug(struct gendisk *disk, zwplug->flags = 0; zwplug->zone_no = zno; zwplug->wp_offset = bdev_offset_from_zone_start(disk->part0, sector); + zwplug->from_cpu = -1; bio_list_init(&zwplug->bio_list); INIT_WORK(&zwplug->bio_work, blk_zone_wplug_bio_work); zwplug->disk = disk; @@ -983,7 +986,8 @@ static bool blk_zone_wplug_prepare_bio(struct blk_zone_wplug *zwplug, return true; } -static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs) +static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs, + int *from_cpu) { struct gendisk *disk = bio->bi_bdev->bd_disk; sector_t sector = bio->bi_iter.bi_sector; @@ -1045,7 +1049,13 @@ static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs) return true; } - zwplug->flags |= BLK_ZONE_WPLUG_PLUGGED; + if (disk->queue->limits.driver_preserves_write_order) { + if (zwplug->from_cpu < 0) + zwplug->from_cpu = raw_smp_processor_id(); + *from_cpu = zwplug->from_cpu; + } else { + zwplug->flags |= BLK_ZONE_WPLUG_PLUGGED; + } spin_unlock_irqrestore(&zwplug->lock, flags); @@ -1165,7 +1175,7 @@ bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs, int *from_cpu) fallthrough; case REQ_OP_WRITE: case REQ_OP_WRITE_ZEROES: - return blk_zone_wplug_handle_write(bio, nr_segs); + return blk_zone_wplug_handle_write(bio, nr_segs, from_cpu); case REQ_OP_ZONE_RESET: return blk_zone_wplug_handle_reset_or_finish(bio, 0); case REQ_OP_ZONE_FINISH: @@ -1197,6 +1207,9 @@ static void disk_zone_wplug_unplug_bio(struct gendisk *disk, zwplug->flags &= ~BLK_ZONE_WPLUG_PLUGGED; + if (refcount_read(&zwplug->ref) == 2) + zwplug->from_cpu = -1; + /* * If the zone is full (it was fully written or finished, or empty * (it was reset), remove its zone write plug from the hash table. @@ -1848,6 +1861,7 @@ static void queue_zone_wplug_show(struct blk_zone_wplug *zwplug, unsigned int zwp_zone_no, zwp_ref; unsigned int zwp_bio_list_size; unsigned long flags; + int from_cpu; spin_lock_irqsave(&zwplug->lock, flags); zwp_zone_no = zwplug->zone_no; @@ -1855,10 +1869,12 @@ static void queue_zone_wplug_show(struct blk_zone_wplug *zwplug, zwp_ref = refcount_read(&zwplug->ref); zwp_wp_offset = zwplug->wp_offset; zwp_bio_list_size = bio_list_size(&zwplug->bio_list); + from_cpu = zwplug->from_cpu; spin_unlock_irqrestore(&zwplug->lock, flags); - seq_printf(m, "%u 0x%x %u %u %u\n", zwp_zone_no, zwp_flags, zwp_ref, - zwp_wp_offset, zwp_bio_list_size); + seq_printf(m, "zone_no %u flags 0x%x ref %u wp_offset %u bio_list_size %u from_cpu %d\n", + zwp_zone_no, zwp_flags, zwp_ref, zwp_wp_offset, + zwp_bio_list_size, from_cpu); } int queue_zone_wplugs_show(void *data, struct seq_file *m) From patchwork Mon Jun 16 22:33:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 897497 Received: from 003.mia.mailroute.net (003.mia.mailroute.net [199.89.3.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25C804A0C; Mon, 16 Jun 2025 22:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113278; cv=none; b=Y5NKE5k7Px9+bRtmz5/AxKNqhE4j4TjS4Nl0JrhixeUnaGvthhOPRuRXjZOUKCfi9aIv1UDmfNHplEamIE5j1CD2l6STXnRxFfiMMcAq7nAaq+mnE1OHozOcJNtCciUIc0J4xVTvty6YBqNPSzhsEYTTiS9iszzs9D4MSNHwwzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113278; c=relaxed/simple; bh=Zu6vSqmxcukieee3JufQ7CZA9MPWG9AOrjYb8HYU918=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c2MI0d76btENL5+GjmtoyXyep3RHMs6oKVRSkhydlkMK8QbkISRGx9vHComonOdWevuAEon/W5la/wApSpnCBLV6ua9GekuM7aiVIHt0YVoSQZdnBAp+mwtr7axY0ppmjja0jypQM99ygSPDqj0nyiLaTn0dAXQIGWTVThI7qjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=ihY/0vQb; arc=none smtp.client-ip=199.89.3.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="ihY/0vQb" Received: from localhost (localhost [127.0.0.1]) by 003.mia.mailroute.net (Postfix) with ESMTP id 4bLlDW07Txzlgqxq; Mon, 16 Jun 2025 22:34:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1750113273; x=1752705274; bh=UZVZc BJ6evy4O6Ie4aey7pelKnBwOFg5FdqzgsjjCj0=; b=ihY/0vQb/rvKL2RpniDyO /W8SBaXVPOdhoDx957l5K+yi+Q3ihF1yBuA+LXs9yVk8X4YJPOHM9lbrtdJt/ywp PCEkLl2M6pdSpXEK4UE/kfizufwRdX/L7yFxc5yboTQaWWI24/5VQiyZvYEfWLEx gZ97X9sY4TdDWLDRzgBZWS+e376n2H5VMi/RPK1T0fOynin4gq6+YuTCc8HFqiNf 7yLewI/NZRi0Rtrt0w29yaEcbKpzyoz6fe4SU9jTPGJIFB9ot3B8FzgIEXbRFkZP a8nuptzM2wommP8y6QmXcjsrqukhrBop4S/diuaUNF6Ejm+sqL4Zp2nevlpoMVQG A== X-Virus-Scanned: by MailRoute Received: from 003.mia.mailroute.net ([127.0.0.1]) by localhost (003.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id ko07yo0UeU4u; Mon, 16 Jun 2025 22:34:33 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 003.mia.mailroute.net (Postfix) with ESMTPSA id 4bLlDP4PXczlgqVt; Mon, 16 Jun 2025 22:34:28 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Bart Van Assche Subject: [PATCH v18 07/12] null_blk: Add the preserves_write_order attribute Date: Mon, 16 Jun 2025 15:33:07 -0700 Message-ID: <20250616223312.1607638-8-bvanassche@acm.org> X-Mailer: git-send-email 2.50.0.rc2.692.g299adb8693-goog In-Reply-To: <20250616223312.1607638-1-bvanassche@acm.org> References: <20250616223312.1607638-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Support configuring the preserves_write_order in the null_blk driver to make it easier to test support for this attribute. Cc: Christoph Hellwig Cc: Damien Le Moal Signed-off-by: Bart Van Assche --- drivers/block/null_blk/main.c | 3 +++ drivers/block/null_blk/null_blk.h | 1 + 2 files changed, 4 insertions(+) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index aa163ae9b2aa..45eaa6f0e983 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -475,6 +475,7 @@ NULLB_DEVICE_ATTR(fua, bool, NULL); NULLB_DEVICE_ATTR(rotational, bool, NULL); NULLB_DEVICE_ATTR(badblocks_once, bool, NULL); NULLB_DEVICE_ATTR(badblocks_partial_io, bool, NULL); +NULLB_DEVICE_ATTR(preserves_write_order, bool, NULL); static ssize_t nullb_device_power_show(struct config_item *item, char *page) { @@ -613,6 +614,7 @@ static struct configfs_attribute *nullb_device_attrs[] = { &nullb_device_attr_no_sched, &nullb_device_attr_poll_queues, &nullb_device_attr_power, + &nullb_device_attr_preserves_write_order, &nullb_device_attr_queue_mode, &nullb_device_attr_rotational, &nullb_device_attr_shared_tag_bitmap, @@ -1979,6 +1981,7 @@ static int null_add_dev(struct nullb_device *dev) if (dev->virt_boundary) lim.virt_boundary_mask = PAGE_SIZE - 1; null_config_discard(nullb, &lim); + lim.driver_preserves_write_order = dev->preserves_write_order; if (dev->zoned) { rv = null_init_zoned_dev(dev, &lim); if (rv) diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h index 7bb6128dbaaf..08b732cf853f 100644 --- a/drivers/block/null_blk/null_blk.h +++ b/drivers/block/null_blk/null_blk.h @@ -110,6 +110,7 @@ struct nullb_device { bool shared_tag_bitmap; /* use hostwide shared tags */ bool fua; /* Support FUA */ bool rotational; /* Fake rotational device */ + bool preserves_write_order; }; struct nullb { From patchwork Mon Jun 16 22:33:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 897271 Received: from 003.mia.mailroute.net (003.mia.mailroute.net [199.89.3.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4865022068D; Mon, 16 Jun 2025 22:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113283; cv=none; b=BfWlxrP6eKnwtUyGLURgCL3E6lqrNRpAPLo8RCYnh65fSq55+XgZKKJE4zgVXAesZ0V3Ii8zb9tGyhZmKRG02FwEa32V7tlOKOsvAnzPv2SP3Cq73KmMOloYKgWdATjamVVSi1qmDvYACfFLUhAIza8oPR6cfwaxtUO50QlJPIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113283; c=relaxed/simple; bh=Kd1dd5huFr95E+OWVN11lbDqGnaXpx93SFNG/EYGvx8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rCayupo40c8obBvbxEI+UVFKicTptUCvU9iZ+EYvBjSufZZWgYVVb78JzS+YhnJB6bTtrs4uYscT0E1vVczKKQPr3DpT7GqmQ3U7DyPRbm1CQSbVE/9bxyTqqOx4sR9JD4azM+0HNiltBPc1mAga2G5eIg8es7WcX1Fnmq2UN5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=nzWi9kRD; arc=none smtp.client-ip=199.89.3.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="nzWi9kRD" Received: from localhost (localhost [127.0.0.1]) by 003.mia.mailroute.net (Postfix) with ESMTP id 4bLlDd4YR8zlgqxt; Mon, 16 Jun 2025 22:34:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1750113279; x=1752705280; bh=Y7Jmq ZnByKSzKcv3V7vqe/DZ+bbEmFGlv+KJiG3EZ2U=; b=nzWi9kRDOR3SUlZWWioW4 2mqjzmh7l/rdr31EEyJJpX6HHtNWrQagoaPa6o6DdAfXvpqm4oMx3kgaW2o6mSF0 Hqdf15HlhlbR5wX40Je5SsJFHQP6Rde1w/KDpvZoTAbPW2dG8f9k6jVmoifqlhSp O4byyviE0Ptd1m0iJsf6hFWMYmZsUvjrAGIOKF6xBS8oONY6xZRBDbQSaLmO0iSB yRva10huaYOHFHMIHVF3adhWhkUbiTYUub3wFw9rG16l/zvR9awmWpKD11gnkn3v k6iShopJtzNv1aseomrO1exeS/+qNnTeaxg+vDhAqWd0RIquY0GJS0orlfCQ/cGa g== X-Virus-Scanned: by MailRoute Received: from 003.mia.mailroute.net ([127.0.0.1]) by localhost (003.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id hnDg4Zfv_mtR; Mon, 16 Jun 2025 22:34:39 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 003.mia.mailroute.net (Postfix) with ESMTPSA id 4bLlDV2cFHzlgqVx; Mon, 16 Jun 2025 22:34:33 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Bart Van Assche , "Martin K. Petersen" , Ming Lei Subject: [PATCH v18 08/12] scsi: core: Retry unaligned zoned writes Date: Mon, 16 Jun 2025 15:33:08 -0700 Message-ID: <20250616223312.1607638-9-bvanassche@acm.org> X-Mailer: git-send-email 2.50.0.rc2.692.g299adb8693-goog In-Reply-To: <20250616223312.1607638-1-bvanassche@acm.org> References: <20250616223312.1607638-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If zoned writes (REQ_OP_WRITE) for a sequential write required zone have a starting LBA that differs from the write pointer, e.g. because a prior write triggered a unit attention condition, then the storage device will respond with an UNALIGNED WRITE COMMAND error. Retry commands that failed with an unaligned write error. Reviewed-by: Damien Le Moal Cc: Martin K. Petersen Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_error.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 376b8897ab90..32f0f7d520df 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -712,6 +712,22 @@ enum scsi_disposition scsi_check_sense(struct scsi_cmnd *scmd) fallthrough; case ILLEGAL_REQUEST: + /* + * Unaligned write command. This may indicate that zoned writes + * have been received by the device in the wrong order. If write + * pipelining is enabled, retry. + */ + if (sshdr.asc == 0x21 && sshdr.ascq == 0x04 && + req->q->limits.driver_preserves_write_order && + blk_rq_is_seq_zoned_write(req) && + scsi_cmd_retry_allowed(scmd)) { + SCSI_LOG_ERROR_RECOVERY(1, + sdev_printk(KERN_WARNING, scmd->device, + "Retrying unaligned write at LBA %#llx.\n", + scsi_get_lba(scmd))); + return NEEDS_RETRY; + } + if (sshdr.asc == 0x20 || /* Invalid command operation code */ sshdr.asc == 0x21 || /* Logical block address out of range */ sshdr.asc == 0x22 || /* Invalid function */ From patchwork Mon Jun 16 22:33:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 897496 Received: from 003.mia.mailroute.net (003.mia.mailroute.net [199.89.3.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDDEE214A6A; Mon, 16 Jun 2025 22:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113290; cv=none; b=WxSw0Th/e4TJGxG/CYMs5zwgUXwhB6e0C85Zc1kXeRrPMKHxNvrbcEa8jbzUkXv9KtY63MnL2/WlIqAnBLM8pN2c+Q666NOGJ4TQFUH0yQ6Ki5vmZ0A6inpNN63W5ZKGPJrnV9mRwVHsu2mM92Sm8wR9Lx2SuyXLM3zodcVkZVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113290; c=relaxed/simple; bh=dFAcw8eDQw0VtPzqgrkRQZ94gUMfcy23v+aQMCyOusw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h9fJgcQhbVJU3Lp4pjbhzs5mAkmJlZXuv3DYCtiHKVNiUCoIZpr03pLLlTyUrt5xHIThvHBSQ0BHnJAaVeW7xn0QXXbiPamkP7FR8UU4dD4bCFSXGN+6vaZHr5lKt2MA/d88XO+mEsxx1lKt03kbADIViRPuvW8PAEz4WCwOj3Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=vvSgtFRv; arc=none smtp.client-ip=199.89.3.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="vvSgtFRv" Received: from localhost (localhost [127.0.0.1]) by 003.mia.mailroute.net (Postfix) with ESMTP id 4bLlDl6Z6gzlgqVy; Mon, 16 Jun 2025 22:34:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1750113286; x=1752705287; bh=Ga5J3 j5MWVZpsDWOGPQ1rbLEtAl56z4ONXUShhBY274=; b=vvSgtFRvoWl/pN1mEQg9H LZfp5tTQqqk6R21KCz9gbTAfg9GE0MJTtp2g8GM7BW93E3XbTvGAPbZWraQ8vhhA cYtTeeYfZ70bj76rOIg23gS60qHUTyYAJqT+EcFv1cPzBKLiF835PLYmPOK5vQyp ugrgBjZnRZ9WDC1LZJzfNTNaw/YPu3s0fzK4PD0k0o97LqT6QVZDVFv+6sH2otWe m0sLljJfMNVCHtoOVZrGq292vOe3Wa8epd1PMguI9jGb5r/LOsSsYeHghph3sx+f s7MlJsEtvGmKgtOtTAyUZsO7U5/J/zBrd/gfHHUx6H9z7mH9PypUfr7Dep/VogKC A== X-Virus-Scanned: by MailRoute Received: from 003.mia.mailroute.net ([127.0.0.1]) by localhost (003.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id OmOXXrzsEVKc; Mon, 16 Jun 2025 22:34:46 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 003.mia.mailroute.net (Postfix) with ESMTPSA id 4bLlDc5fmJzlgqVt; Mon, 16 Jun 2025 22:34:39 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Bart Van Assche , "Martin K. Petersen" , Ming Lei Subject: [PATCH v18 09/12] scsi: sd: Increase retry count for zoned writes Date: Mon, 16 Jun 2025 15:33:09 -0700 Message-ID: <20250616223312.1607638-10-bvanassche@acm.org> X-Mailer: git-send-email 2.50.0.rc2.692.g299adb8693-goog In-Reply-To: <20250616223312.1607638-1-bvanassche@acm.org> References: <20250616223312.1607638-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If the write order is preserved, increase the number of retries for write commands sent to a sequential zone to the maximum number of outstanding commands because in the worst case the number of times reordered zoned writes have to be retried is (number of outstanding writes per sequential zone) - 1. Cc: Damien Le Moal Cc: Martin K. Petersen Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- drivers/scsi/sd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 3f6e87705b62..75ff6af37ecc 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1404,6 +1404,13 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) cmd->transfersize = sdp->sector_size; cmd->underflow = nr_blocks << 9; cmd->allowed = sdkp->max_retries; + /* + * Increase the number of allowed retries for zoned writes if the driver + * preserves the command order. + */ + if (rq->q->limits.driver_preserves_write_order && + blk_rq_is_seq_zoned_write(rq)) + cmd->allowed += rq->q->nr_requests; cmd->sdb.length = nr_blocks * sdp->sector_size; SCSI_LOG_HLQUEUE(1, From patchwork Mon Jun 16 22:33:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 897270 Received: from 003.mia.mailroute.net (003.mia.mailroute.net [199.89.3.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA8D84A0C; Mon, 16 Jun 2025 22:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113297; cv=none; b=ukI9WF0oh6XL7gE3hK83UcfnZ+51k4WZS8VVzSqSCgCaCxvrARvxY9EK8zUcMKNfhLx5PqwsBaVcAENjLHqz9tzavB7PBFmBR6XCNjr/BsaA3mnxvcDcRcXEuE0HFI8l0GpigtZ/eFUQ1eFdgBrPl/YPSvFZvQ86hP9y0Y0p5GM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113297; c=relaxed/simple; bh=yWEPQmP8nFQ9yUmKXi4e2tufhCHjEyr5ZO3WD+Vymtw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KHCYVMAtBLRmr9wR5x8YeWfZ3T0ERL/1zyTQBsun3IYB82LuYQgXDUA7c5BExyzhZa/c3JJCeaU65RhPXBqwselyAnhrlMLU4b5EHxh+o0Ww3E5zhWFjSwZ1M0sB43nYwHAekwEooCr4gKM5oWySzzx/NEsG98CXwGpGpFgwkbM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=W4Togw2s; arc=none smtp.client-ip=199.89.3.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="W4Togw2s" Received: from localhost (localhost [127.0.0.1]) by 003.mia.mailroute.net (Postfix) with ESMTP id 4bLlDv0RVkzlgqxr; Mon, 16 Jun 2025 22:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1750113293; x=1752705294; bh=w1sG3 TOiywRbcIeqeoGch3zZcEOXACvywEVY7r5KDws=; b=W4Togw2sr2YvSw+md5xu9 OTYWakYI9yd/rFPVxC0G9LG30nWsg2e2amcZW4J3aAXKdKxNK0M8OllxoiqbK3Iz OSPMPjpg4mLeXyJBpuhHy7TtAdwggOwlJ59E59AvAQiN9VJ5RX4gdtCy2hT4VzYY tdUlEkkEZTDNkw1KbwU7o1bbExRTt5IHHTtcVir6SAZnxPixDr54jC1ZcGsThkh3 VxWEZZNOTdiPeLndiaZ65kNhvtk4C0L5ONTvy4TPj/FpkRSuFjlux8n7rbzXAM4I qTOLevzSajJfrBjto9un/0PUeMiER61w826Qx3MeXUKfEqJ0C9wd4JDvqc2kC3jC g== X-Virus-Scanned: by MailRoute Received: from 003.mia.mailroute.net ([127.0.0.1]) by localhost (003.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id zN9nXgBYdUtS; Mon, 16 Jun 2025 22:34:53 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 003.mia.mailroute.net (Postfix) with ESMTPSA id 4bLlDl0lYCzlgqVx; Mon, 16 Jun 2025 22:34:46 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Bart Van Assche , Douglas Gilbert , "Martin K. Petersen" , Ming Lei Subject: [PATCH v18 10/12] scsi: scsi_debug: Add the preserves_write_order module parameter Date: Mon, 16 Jun 2025 15:33:10 -0700 Message-ID: <20250616223312.1607638-11-bvanassche@acm.org> X-Mailer: git-send-email 2.50.0.rc2.692.g299adb8693-goog In-Reply-To: <20250616223312.1607638-1-bvanassche@acm.org> References: <20250616223312.1607638-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Zone write locking is not used for zoned devices if the block driver reports that it preserves the order of write commands. Make it easier to test not using zone write locking by adding support for setting the driver_preserves_write_order flag. Acked-by: Douglas Gilbert Reviewed-by: Damien Le Moal Cc: Martin K. Petersen Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index aef33d1e346a..5575bc8a833d 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -1004,6 +1004,7 @@ static int dix_reads; static int dif_errors; /* ZBC global data */ +static bool sdeb_preserves_write_order; static bool sdeb_zbc_in_use; /* true for host-aware and host-managed disks */ static int sdeb_zbc_zone_cap_mb; static int sdeb_zbc_zone_size_mb; @@ -6607,10 +6608,14 @@ static struct sdebug_dev_info *find_build_dev_info(struct scsi_device *sdev) static int scsi_debug_sdev_init(struct scsi_device *sdp) { + struct request_queue *q = sdp->request_queue; + if (sdebug_verbose) pr_info("sdev_init <%u %u %u %llu>\n", sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); + q->limits.driver_preserves_write_order = sdeb_preserves_write_order; + return 0; } @@ -7339,6 +7344,8 @@ module_param_named(statistics, sdebug_statistics, bool, S_IRUGO | S_IWUSR); module_param_named(strict, sdebug_strict, bool, S_IRUGO | S_IWUSR); module_param_named(submit_queues, submit_queues, int, S_IRUGO); module_param_named(poll_queues, poll_queues, int, S_IRUGO); +module_param_named(preserves_write_order, sdeb_preserves_write_order, bool, + S_IRUGO); module_param_named(tur_ms_to_ready, sdeb_tur_ms_to_ready, int, S_IRUGO); module_param_named(unmap_alignment, sdebug_unmap_alignment, int, S_IRUGO); module_param_named(unmap_granularity, sdebug_unmap_granularity, int, S_IRUGO); @@ -7411,6 +7418,8 @@ MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... MODULE_PARM_DESC(per_host_store, "If set, next positive add_host will get new store (def=0)"); MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)"); MODULE_PARM_DESC(poll_queues, "support for iouring iopoll queues (1 to max(submit_queues - 1))"); +MODULE_PARM_DESC(preserves_write_order, + "Whether or not to inform the block layer that this driver preserves the order of WRITE commands (def=0)"); MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])"); MODULE_PARM_DESC(random, "If set, uniformly randomize command duration between 0 and delay_in_ns"); MODULE_PARM_DESC(removable, "claim to have removable media (def=0)"); From patchwork Mon Jun 16 22:33:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 897495 Received: from 003.mia.mailroute.net (003.mia.mailroute.net [199.89.3.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06FFA4A0C; Mon, 16 Jun 2025 22:35:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.3.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113304; cv=none; b=iN4YvyqFutSN2bWKLYe3SnztRsC9AN+5prH3O8uJDGEsVtVyhuMQ0gUZVRUwLMv2OSOIqDsKDX/EcYFgyrQRLLKJgijX7QJrsqcfNJbVV8ERn2iTNtrPP29sTfIAX1q6U9L6SLSVoy3M75zMygvd6cROCAZu7YnRVY+W+cQrgls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750113304; c=relaxed/simple; bh=t2dLqiVV93nIpk4hAhMdRoS/atQvk65z071/Yn98h5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IXj2+thWTgjk8R+m70LF7iRuYffwT2gyazMxfFEsp52lXT7IEbYayfZdNcsgMee2+zFzwjLQ2Ei1/XBntwcbP+OySKvGes3D44+HLnCD3bl+2VcMADCnSDqYjHnWezyCSKbniO3LUvtepQ54ajEpgOHhVJAG6oTrLHJvb9MYkko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=aYghsQca; arc=none smtp.client-ip=199.89.3.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="aYghsQca" Received: from localhost (localhost [127.0.0.1]) by 003.mia.mailroute.net (Postfix) with ESMTP id 4bLlF20Xqyzlgqxn; Mon, 16 Jun 2025 22:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1750113300; x=1752705301; bh=igGoR aDrwEsquUk50FNqWwB9z+w2YY76hv9v+5TDYQU=; b=aYghsQcaQ6hRHj5h8mq0C zFN5T2kY0s0dR0WRtntQtYIWUrddYqk2XLCqp3whh18PF7CgmqKu5DnJjSnmFCMt MXyj/ThdHCnrOPYpuZL6mSDcb7G4iAi8+yGP/BnX+UdOkcBdUx4mJdhgyQJ6HHeh SqtyeJXDAg3DcpY7xg7mu4pred8VZgDnNGg95y8F97z95M0hgMfwQFPLiMxpENgP 44Fv660slpleakQheZ9fKtY4eOzVwYGHfbR1AIY2RPAGW6PlekjPoWE703QCcIGd MGF/Ww0yJu+TeSnpZ7SNij9lbeGMsIUp87KcSReEAnyL2XmJW7ttnBvNSJbU6ZH/ Q== X-Virus-Scanned: by MailRoute Received: from 003.mia.mailroute.net ([127.0.0.1]) by localhost (003.mia [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id 8OQCC1PrZtil; Mon, 16 Jun 2025 22:35:00 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.204.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 003.mia.mailroute.net (Postfix) with ESMTPSA id 4bLlDt0C64zlgqVt; Mon, 16 Jun 2025 22:34:53 +0000 (UTC) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , Damien Le Moal , Bart Van Assche , Douglas Gilbert , "Martin K. Petersen" , Ming Lei Subject: [PATCH v18 11/12] scsi: scsi_debug: Support injecting unaligned write errors Date: Mon, 16 Jun 2025 15:33:11 -0700 Message-ID: <20250616223312.1607638-12-bvanassche@acm.org> X-Mailer: git-send-email 2.50.0.rc2.692.g299adb8693-goog In-Reply-To: <20250616223312.1607638-1-bvanassche@acm.org> References: <20250616223312.1607638-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Allow user space software, e.g. a blktests test, to inject unaligned write errors. Acked-by: Douglas Gilbert Reviewed-by: Damien Le Moal Cc: Martin K. Petersen Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 5575bc8a833d..963246f5894a 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -230,6 +230,7 @@ struct tape_block { #define SDEBUG_OPT_NO_CDB_NOISE 0x4000 #define SDEBUG_OPT_HOST_BUSY 0x8000 #define SDEBUG_OPT_CMD_ABORT 0x10000 +#define SDEBUG_OPT_UNALIGNED_WRITE 0x20000 #define SDEBUG_OPT_ALL_NOISE (SDEBUG_OPT_NOISE | SDEBUG_OPT_Q_NOISE | \ SDEBUG_OPT_RESET_NOISE) #define SDEBUG_OPT_ALL_INJECTING (SDEBUG_OPT_RECOVERED_ERR | \ @@ -237,7 +238,8 @@ struct tape_block { SDEBUG_OPT_DIF_ERR | SDEBUG_OPT_DIX_ERR | \ SDEBUG_OPT_SHORT_TRANSFER | \ SDEBUG_OPT_HOST_BUSY | \ - SDEBUG_OPT_CMD_ABORT) + SDEBUG_OPT_CMD_ABORT | \ + SDEBUG_OPT_UNALIGNED_WRITE) #define SDEBUG_OPT_RECOV_DIF_DIX (SDEBUG_OPT_RECOVERED_ERR | \ SDEBUG_OPT_DIF_ERR | SDEBUG_OPT_DIX_ERR) @@ -4915,6 +4917,14 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) u8 *cmd = scp->cmnd; bool meta_data_locked = false; + if (unlikely(sdebug_opts & SDEBUG_OPT_UNALIGNED_WRITE && + atomic_read(&sdeb_inject_pending))) { + atomic_set(&sdeb_inject_pending, 0); + mk_sense_buffer(scp, ILLEGAL_REQUEST, LBA_OUT_OF_RANGE, + UNALIGNED_WRITE_ASCQ); + return check_condition_result; + } + switch (cmd[0]) { case WRITE_16: ei_lba = 0;