From patchwork Mon Oct 23 21:53:52 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: 737747 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 C8D33C25B49 for ; Mon, 23 Oct 2023 21:56:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231873AbjJWV4v (ORCPT ); Mon, 23 Oct 2023 17:56:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229763AbjJWV4u (ORCPT ); Mon, 23 Oct 2023 17:56:50 -0400 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99FEFDE; Mon, 23 Oct 2023 14:56:48 -0700 (PDT) Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-27d18475ed4so2785549a91.0; Mon, 23 Oct 2023 14:56:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098208; x=1698703008; 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=cTMw0a7/Uh2Lje80+tulC82TkA3w3+NwQr1GUTziZqE=; b=g9nOgpuE6QUZj3EfRGG3NGqbVZWwxKLmyUA/II1uTbBu6v19MBenjzk+QLzKUd7Bj2 Yoqzm/ZvuputGPu4eHSy3yyQ/FfQB2U/8lXx/D0IK8zZrrfFhW4S4Bam4M12I5SaCxtX L/Nb0Ndh4GulGFPQ6LGPHForjCzNUlHx3aSOVXW1yKLXhwbJsbGqQFnPTGivTKRVDXtD YUvMDEzcdrJA9t/8qn7InJM2WiEimAC8Kjge7WFimbg9NaeLrCdtBFHzlwBrUM4cSGan aiaOBVkWzKXu5lNuVmjcD+HWLuniX8lNCZArdIq7R4bAojjD7aOx5s2MG/V71cDvNWHk OipA== X-Gm-Message-State: AOJu0Yx5IV3Tru27R7R6XY0qTS5jCmJ37g3SsFPqtIlMoo9OBo8jNiS3 F00DDjQVy4aLWXtN4EGgx84= X-Google-Smtp-Source: AGHT+IF/kM2h/DfPvHLxlHnJ/jky6/+RCZRPKHEbnln4JlMS+8VZ30sPYvXvW3i7Mnk/FI0XsgD1rQ== X-Received: by 2002:a17:90b:1490:b0:27c:edd5:6137 with SMTP id js16-20020a17090b149000b0027cedd56137mr8088074pjb.25.1698098207924; Mon, 23 Oct 2023 14:56:47 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:56:47 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Hannes Reinecke , Nitesh Shetty , Ming Lei Subject: [PATCH v14 01/19] block: Introduce more member variables related to zone write locking Date: Mon, 23 Oct 2023 14:53:52 -0700 Message-ID: <20231023215638.3405959-2-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Many but not all storage controllers require serialization of zoned writes. Introduce two new request queue limit member variables related to write serialization. 'driver_preserves_write_order' allows block drivers to indicate that the order of write commands is preserved and hence that serialization of writes per zone is not required. 'use_zone_write_lock' is set by disk_set_zoned() if and only if the block device has zones and if the block driver does not preserve the order of write requests. Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Nitesh Shetty Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- block/blk-settings.c | 15 +++++++++++++++ block/blk-zoned.c | 1 + include/linux/blkdev.h | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/block/blk-settings.c b/block/blk-settings.c index 0046b447268f..4c776c08f190 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -56,6 +56,8 @@ void blk_set_default_limits(struct queue_limits *lim) lim->alignment_offset = 0; lim->io_opt = 0; lim->misaligned = 0; + lim->driver_preserves_write_order = false; + lim->use_zone_write_lock = false; lim->zoned = BLK_ZONED_NONE; lim->zone_write_granularity = 0; lim->dma_alignment = 511; @@ -82,6 +84,8 @@ void blk_set_stacking_limits(struct queue_limits *lim) lim->max_dev_sectors = UINT_MAX; lim->max_write_zeroes_sectors = UINT_MAX; lim->max_zone_append_sectors = UINT_MAX; + /* Request-based stacking drivers do not reorder requests. */ + lim->driver_preserves_write_order = true; } EXPORT_SYMBOL(blk_set_stacking_limits); @@ -685,6 +689,10 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, b->max_secure_erase_sectors); t->zone_write_granularity = max(t->zone_write_granularity, b->zone_write_granularity); + t->driver_preserves_write_order = t->driver_preserves_write_order && + b->driver_preserves_write_order; + t->use_zone_write_lock = t->use_zone_write_lock || + b->use_zone_write_lock; t->zoned = max(t->zoned, b->zoned); return ret; } @@ -949,6 +957,13 @@ void disk_set_zoned(struct gendisk *disk, enum blk_zoned_model model) } q->limits.zoned = model; + /* + * Use the zone write lock only for zoned block devices and only if + * the block driver does not preserve the order of write commands. + */ + q->limits.use_zone_write_lock = model != BLK_ZONED_NONE && + !q->limits.driver_preserves_write_order; + if (model != BLK_ZONED_NONE) { /* * Set the zone write granularity to the device logical block diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 619ee41a51cc..112620985bff 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -631,6 +631,7 @@ void disk_clear_zone_settings(struct gendisk *disk) q->limits.chunk_sectors = 0; q->limits.zone_write_granularity = 0; q->limits.max_zone_append_sectors = 0; + q->limits.use_zone_write_lock = false; blk_mq_unfreeze_queue(q); } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index eef450f25982..b67bd8433225 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -316,6 +316,16 @@ struct queue_limits { unsigned char misaligned; unsigned char discard_misaligned; unsigned char raid_partial_stripes_expensive; + /* + * Whether or not the block driver preserves the order of write + * requests. Set by the block driver. + */ + bool driver_preserves_write_order; + /* + * Whether or not zone write locking should be used. Set by + * disk_set_zoned(). + */ + bool use_zone_write_lock; enum blk_zoned_model zoned; /* From patchwork Mon Oct 23 21:53:53 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: 737473 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 BBBB5C25B42 for ; Mon, 23 Oct 2023 21:56:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232475AbjJWV4z (ORCPT ); Mon, 23 Oct 2023 17:56:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbjJWV4v (ORCPT ); Mon, 23 Oct 2023 17:56:51 -0400 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBC21DE; Mon, 23 Oct 2023 14:56:49 -0700 (PDT) Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-27d11401516so2486721a91.2; Mon, 23 Oct 2023 14:56:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098209; x=1698703009; 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=aH5XPQQCiAVF4r+XWGxE/2XmtFY/9NCJod7T1V555TM=; b=WCzt+zLVwOkJlOEztpUcUxglDhBiNFbns/2+XyxuGOtpxT+hhd1fgs/XMnnApjhsT8 QlEH9bTvQMiniroZYy//O1t6yahdGgo7GkRz5sTKDvX+enJuZCOHKtCvsGhDs+ThECfj o8ATVd990nqZ3AubCniAaFurjeDegfHbzIEGecOYsMZmRLdAa8QxpRVDFZYuasoFBUSb M4zN0Wuyg03LoychaWSdFHPPRVBFTm/CvPQx4YLvN6Tal8QNiYE7k740dxL5ay4n5kYs l1YnSp52Ib5T7VgcL8A9W4JfNt1SEfNBti3CQrXLExAkqgjd53IVEqKBLdrpv/nRsolp vbkg== X-Gm-Message-State: AOJu0Yxn9+BxXLvRk/b2zYh6mv9rjicCsP+CK/WuVfm3rvaSVsQS6NWJ 3H5lP9xbf+zNwSI3cKzE0aU= X-Google-Smtp-Source: AGHT+IHR8LGf7uHZXM3UG64COGxd37714NNJ+EnM6yob3YnVnow4RZsDRfXMoIch83ZZkfDGzCIjsA== X-Received: by 2002:a17:90a:d995:b0:27d:4901:b0b7 with SMTP id d21-20020a17090ad99500b0027d4901b0b7mr7092830pjv.30.1698098209274; Mon, 23 Oct 2023 14:56:49 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.56.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:56:48 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Hannes Reinecke , Nitesh Shetty , Damien Le Moal , Ming Lei Subject: [PATCH v14 02/19] block: Only use write locking if necessary Date: Mon, 23 Oct 2023 14:53:53 -0700 Message-ID: <20231023215638.3405959-3-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Make blk_req_needs_zone_write_lock() return false if q->limits.use_zone_write_lock is false. Reviewed-by: Hannes Reinecke Reviewed-by: Nitesh Shetty Cc: Damien Le Moal Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche Reviewed-by: Damien Le Moal --- block/blk-zoned.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 112620985bff..d8a80cce832f 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -53,11 +53,16 @@ const char *blk_zone_cond_str(enum blk_zone_cond zone_cond) EXPORT_SYMBOL_GPL(blk_zone_cond_str); /* - * Return true if a request is a write requests that needs zone write locking. + * Return true if a request is a write request that needs zone write locking. */ bool blk_req_needs_zone_write_lock(struct request *rq) { - if (!rq->q->disk->seq_zones_wlock) + struct request_queue *q = rq->q; + + if (!q->limits.use_zone_write_lock) + return false; + + if (!q->disk->seq_zones_wlock) return false; return blk_rq_is_seq_zoned_write(rq); From patchwork Mon Oct 23 21:53:54 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: 737746 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 E3287C25B46 for ; Mon, 23 Oct 2023 21:56:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232611AbjJWV44 (ORCPT ); Mon, 23 Oct 2023 17:56:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232053AbjJWV4x (ORCPT ); Mon, 23 Oct 2023 17:56:53 -0400 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33E65FD; Mon, 23 Oct 2023 14:56:51 -0700 (PDT) Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-27d1aee5aa1so2762332a91.0; Mon, 23 Oct 2023 14:56:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098210; x=1698703010; 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=/Z4rDL2TyIbEkp8fI7s0C+IPERBnhnxV2g5mRuTAQjE=; b=CRo1BeJNJUTr9H8HwGCM3WXnkNnFXu9/sdtj9YG33vYVDGMzV2moiDSQZ7VDbYS8nb nsa/JlQ6woOunljPbyoM9mlbBiJCzOCA36Mc7JJEuPJFyNSvtgL0Id9XbSGlOCzqfOAB /niIJAk64vXiDusi85R/Tmz79yCqtJ20JxF8WMIH2rxMsrIK5AjDQ1hQXMHOk/4C/hwj 9Px1ORfbMGJfTvwAu1cROClwTMR9RBlWVQcyCR1NR0TWYuZc/KCYKOGpZx+QJI2na+n6 J9pU0pEPNXcDHkAZhjBQjBSUgRZzX31I6FAg1nITaohSgkxOsSva6svyhfciDR7H1eKx KYqQ== X-Gm-Message-State: AOJu0Yy96cqs62JdHmsuGhgpAFXBUFk0PH/+JZC3bW7QkcIizaJJZ0yo uq1DlKJee3J7tvnzxvAHUjo= X-Google-Smtp-Source: AGHT+IHslL8JuKlMJzYNPkDlEGnm1ND7/6d+zbhFyMjawYmHx8z+9bDz1o68UDSfIFC/8983LctCIw== X-Received: by 2002:a17:90a:f184:b0:27d:306d:71cb with SMTP id bv4-20020a17090af18400b0027d306d71cbmr18504509pjb.10.1698098210559; Mon, 23 Oct 2023 14:56:50 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:56:50 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , Hannes Reinecke Subject: [PATCH v14 03/19] block: Preserve the order of requeued zoned writes Date: Mon, 23 Oct 2023 14:53:54 -0700 Message-ID: <20231023215638.3405959-4-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org blk_mq_requeue_work() inserts requeued requests in front of other requests. This is fine for all request types except for sequential zoned writes. Hence this patch. Note: moving this functionality into the mq-deadline I/O scheduler is not an option because we want to be able to use zoned storage without I/O scheduler. Cc: Christoph Hellwig Cc: Damien Le Moal Cc: Ming Lei Cc: Hannes Reinecke Signed-off-by: Bart Van Assche --- block/blk-mq.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index e2d11183f62e..e678edca3fa8 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1484,8 +1484,12 @@ static void blk_mq_requeue_work(struct work_struct *work) list_del_init(&rq->queuelist); blk_mq_request_bypass_insert(rq, 0); } else { + blk_insert_t insert_flags = BLK_MQ_INSERT_AT_HEAD; + list_del_init(&rq->queuelist); - blk_mq_insert_request(rq, BLK_MQ_INSERT_AT_HEAD); + if (blk_rq_is_seq_zoned_write(rq)) + insert_flags = 0; + blk_mq_insert_request(rq, insert_flags); } } From patchwork Mon Oct 23 21:53:55 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: 737472 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 851DFC25B4B for ; Mon, 23 Oct 2023 21:56:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233353AbjJWV46 (ORCPT ); Mon, 23 Oct 2023 17:56:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232165AbjJWV4y (ORCPT ); Mon, 23 Oct 2023 17:56:54 -0400 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FD2610E; Mon, 23 Oct 2023 14:56:52 -0700 (PDT) Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-27d3c886671so3329866a91.3; Mon, 23 Oct 2023 14:56:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098212; x=1698703012; 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=Qt1sHc5t/dL7mhPeX2SDNFeaW6muSPBn8kxtGzd5CRY=; b=TdqNuVLL6VrQ9KOSCYOR+vKXp/S7w5ng/RVNdvF+880d3xYLbUQfUa1OYVK6nbLyo9 5pvsc0ryslU+RliKkEHRmB7aTIMlz0E9ZVWsWN0t/ld4TlCybxlGQBg5hvEOA01ZlC9B 9UjmC9Zvjuo73dQNr2pYAmwpE3iNQ0H+CpOmN/53pd63GRhxByJKadonK7Ai66TPZ5Wq Pos34g3UTVolj8WFEPhEYcB10K9khdQnHJwRGoZLaXIDXIER+5PnDRvQN9wul1yAl6Gs mE5JetuJRP5khcKT3mRJSYMynCKAwXUgPjyET7C+M73Voay3ZCAb/7Y4kEXe4+JebkUA jNHA== X-Gm-Message-State: AOJu0YxhpYshXB6LrvvE4VN9wXkNTMitvjjrlebme4T6z2iGxEcxE9wS 3e8A2Yw7w8WjyDHpAbhC9jw= X-Google-Smtp-Source: AGHT+IH1Rj0B2kHqJCvWhJpX9pUviXCQEmLz6WcrJB5/DFcQVYnfaZIHYJedQuxoiqusWC8dCSl+hw== X-Received: by 2002:a17:90a:8d86:b0:27d:4d0:d79b with SMTP id d6-20020a17090a8d8600b0027d04d0d79bmr11321960pjo.23.1698098211962; Mon, 23 Oct 2023 14:56:51 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:56:51 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Hannes Reinecke , Nitesh Shetty , Ming Lei Subject: [PATCH v14 04/19] block/mq-deadline: Only use zone locking if necessary Date: Mon, 23 Oct 2023 14:53:55 -0700 Message-ID: <20231023215638.3405959-5-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Measurements have shown that limiting the queue depth to one per zone for zoned writes has a significant negative performance impact on zoned UFS devices. Hence this patch that disables zone locking by the mq-deadline scheduler if the storage controller preserves the command order. This patch is based on the following assumptions: - It happens infrequently that zoned write requests are reordered by the block layer. - The I/O priority of all write requests is the same per zone. - Either no I/O scheduler is used or an I/O scheduler is used that serializes write requests per zone. Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Reviewed-by: Nitesh Shetty Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- block/mq-deadline.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/block/mq-deadline.c b/block/mq-deadline.c index f958e79277b8..082ccf3186f4 100644 --- a/block/mq-deadline.c +++ b/block/mq-deadline.c @@ -353,7 +353,7 @@ deadline_fifo_request(struct deadline_data *dd, struct dd_per_prio *per_prio, return NULL; rq = rq_entry_fifo(per_prio->fifo_list[data_dir].next); - if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q)) + if (data_dir == DD_READ || !rq->q->limits.use_zone_write_lock) return rq; /* @@ -398,7 +398,7 @@ deadline_next_request(struct deadline_data *dd, struct dd_per_prio *per_prio, if (!rq) return NULL; - if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q)) + if (data_dir == DD_READ || !rq->q->limits.use_zone_write_lock) return rq; /* @@ -526,8 +526,9 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd, } /* - * For a zoned block device, if we only have writes queued and none of - * them can be dispatched, rq will be NULL. + * For a zoned block device that requires write serialization, if we + * only have writes queued and none of them can be dispatched, rq will + * be NULL. */ if (!rq) return NULL; @@ -934,7 +935,7 @@ static void dd_finish_request(struct request *rq) atomic_inc(&per_prio->stats.completed); - if (blk_queue_is_zoned(q)) { + if (rq->q->limits.use_zone_write_lock) { unsigned long flags; spin_lock_irqsave(&dd->zone_lock, flags); From patchwork Mon Oct 23 21:53:56 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: 737745 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 3B4BBC25B46 for ; Mon, 23 Oct 2023 21:57:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233317AbjJWV5G (ORCPT ); Mon, 23 Oct 2023 17:57:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233456AbjJWV5D (ORCPT ); Mon, 23 Oct 2023 17:57:03 -0400 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF3BA10D3; Mon, 23 Oct 2023 14:56:59 -0700 (PDT) Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-27d104fa285so3271434a91.2; Mon, 23 Oct 2023 14:56:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098219; x=1698703019; 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=IMmTgdt0sRo6a6NvHol68KyIZZ4Zv+cZHY8Wdw0Zpt0=; b=blef7qEipNcN1iCjwn8ezuZharF3kli/NZfpfo8SCK6zVt8/Z+uRWOr6YiISYMmaGY 42EDn0RpzMuFdubRIRkIzcd7oIsgR9op/urrUpxaytTtcfeJDKao/GWUQgBPIeN33DeY ZusDlWx4TdpkUIsSMRaHsinuFf0sDuVmuoWDRxDSqA5/LvIPxowLAwbt3okkP4cCVLC/ kigmUQs29XzLJOZ3mfowlojZRevxEykgzYHfQCxJXBcdZQDNLhDyl/4WptEMeMta/dgT o6etgaaSg1A7Rx+kl/ie9AoIEqUQT4GrE0yAWq98tJZn0KZ/D4J/DjER/KQu44Fl5z4X UZmA== X-Gm-Message-State: AOJu0YwRhj6QlloyfeNabasLz7yvfeXZV5rPiqZyPITuh5bxfKdbsSVp dz2L+2tnUQEVglGFPpj92Nlm7KkyQAs= X-Google-Smtp-Source: AGHT+IFSYWod3gz2NJ0PLxDcdtkNj17oMNzmmwucZAmfxjwUtF3yLPxwD2h2khPvSEeNp141ht/JcA== X-Received: by 2002:a17:90a:d407:b0:27d:7ebe:2e8 with SMTP id r7-20020a17090ad40700b0027d7ebe02e8mr11215883pju.9.1698098218958; Mon, 23 Oct 2023 14:56:58 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.56.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:56:58 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Damien Le Moal , "James E.J. Bottomley" , Jason Yan , John Garry , Wenchao Hao Subject: [PATCH v14 05/19] scsi: Add an argument to scsi_eh_flush_done_q() Date: Mon, 23 Oct 2023 14:53:56 -0700 Message-ID: <20231023215638.3405959-6-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This patch prepares for using the host pointer directly in scsi_eh_flush_done_q() in a later patch. Cc: Martin K. Petersen Cc: Damien Le Moal Signed-off-by: Bart Van Assche --- drivers/ata/libata-eh.c | 2 +- drivers/scsi/libsas/sas_scsi_host.c | 2 +- drivers/scsi/scsi_error.c | 5 +++-- include/scsi/scsi_eh.h | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 4cf4f57e57b8..9a1a06a8e5db 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -738,7 +738,7 @@ void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap) spin_unlock_irqrestore(ap->lock, flags); ata_eh_release(ap); - scsi_eh_flush_done_q(&ap->eh_done_q); + scsi_eh_flush_done_q(host, &ap->eh_done_q); /* clean up */ spin_lock_irqsave(ap->lock, flags); diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c index 9047cfcd1072..dd4fb97fdc4b 100644 --- a/drivers/scsi/libsas/sas_scsi_host.c +++ b/drivers/scsi/libsas/sas_scsi_host.c @@ -730,7 +730,7 @@ void sas_scsi_recover_host(struct Scsi_Host *shost) /* now link into libata eh --- if we have any ata devices */ sas_ata_strategy_handler(shost); - scsi_eh_flush_done_q(&ha->eh_done_q); + scsi_eh_flush_done_q(shost, &ha->eh_done_q); /* check if any new eh work was scheduled during the last run */ spin_lock_irq(&ha->lock); diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index c67cdcdc3ba8..7390131e7f0a 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -2188,9 +2188,10 @@ EXPORT_SYMBOL_GPL(scsi_eh_ready_devs); /** * scsi_eh_flush_done_q - finish processed commands or retry them. + * @shost: SCSI host pointer. * @done_q: list_head of processed commands. */ -void scsi_eh_flush_done_q(struct list_head *done_q) +void scsi_eh_flush_done_q(struct Scsi_Host *shost, struct list_head *done_q) { struct scsi_cmnd *scmd, *next; @@ -2265,7 +2266,7 @@ static void scsi_unjam_host(struct Scsi_Host *shost) if (shost->eh_deadline != -1) shost->last_reset = 0; spin_unlock_irqrestore(shost->host_lock, flags); - scsi_eh_flush_done_q(&eh_done_q); + scsi_eh_flush_done_q(shost, &eh_done_q); } /** diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h index 1ae08e81339f..d2807d799fda 100644 --- a/include/scsi/scsi_eh.h +++ b/include/scsi/scsi_eh.h @@ -11,7 +11,8 @@ struct Scsi_Host; extern void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, struct list_head *done_q); -extern void scsi_eh_flush_done_q(struct list_head *done_q); +extern void scsi_eh_flush_done_q(struct Scsi_Host *shost, + struct list_head *done_q); extern void scsi_report_bus_reset(struct Scsi_Host *, int); extern void scsi_report_device_reset(struct Scsi_Host *, int, int); extern int scsi_block_when_processing_errors(struct scsi_device *); From patchwork Mon Oct 23 21:53:57 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: 737471 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 867E7C25B4A for ; Mon, 23 Oct 2023 21:57:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233443AbjJWV5H (ORCPT ); Mon, 23 Oct 2023 17:57:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232738AbjJWV5D (ORCPT ); Mon, 23 Oct 2023 17:57:03 -0400 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AE6310D8; Mon, 23 Oct 2023 14:57:01 -0700 (PDT) Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-27d45f5658fso3030010a91.3; Mon, 23 Oct 2023 14:57:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098220; x=1698703020; 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=H20lDRhK4GDyaMBBwpn1BdMOXepbGFTFy7qq+KEqdsE=; b=gy6EVAYX6Mx1yFWDVLX4QWY+v7lgzwue12T7u/pfRTA7ZOE6OG55jG7o0x2XE2pox/ t7XoDFQSGxGmBpoAnfRaudywxFS5prjKViptX2sQD2GkWQ699127yUc8UDyejJfZL/K8 jADuYZC3XXoYO4B1zZn/C9wBz8UVMnYRq6uYUUxEPQYupJ3CRtdW5ceRKldddNYwOHJs PUcNG4RoeqOuc2Hk9u1oWhAAtjHlKwSN6I0sp9tFd1GDEnZVaRu87dbLt+qBjAlvmFc3 +NUJSY5BCs43mas7/wkO7NpE5SQrPcJK209M++8ifeLiOdCpJb1qXsVkcDqoKqGwY5zK yYzQ== X-Gm-Message-State: AOJu0YyH3CgJjspj+cS7Gl/Iqc+YCaQCQuJsLenceke87uYQNXp8j9sE yM2L3kynftDwBFx0I85V9Pw= X-Google-Smtp-Source: AGHT+IFj8GUj8LPTAdQXglCzvPWwsAuByUWUeLoVRF/+ro182nUvxiD+SRguSfOtgymzVY6i0GsK9A== X-Received: by 2002:a17:90a:c087:b0:27e:277:3015 with SMTP id o7-20020a17090ac08700b0027e02773015mr10152039pjs.16.1698098220452; Mon, 23 Oct 2023 14:57:00 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.56.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:57:00 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v14 06/19] scsi: core: Introduce a mechanism for reordering requests in the error handler Date: Mon, 23 Oct 2023 14:53:57 -0700 Message-ID: <20231023215638.3405959-7-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Introduce the .eh_needs_prepare_resubmit and the .eh_prepare_resubmit function pointers in struct scsi_driver. Make the error handler call .eh_prepare_resubmit() before resubmitting commands if any of the .eh_needs_prepare_resubmit() invocations return true. A later patch will use this functionality to sort SCSI commands by LBA from inside the SCSI disk driver before these are resubmitted by the error handler. Cc: Martin K. Petersen Cc: Damien Le Moal Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche Reviewed-by: Damien Le Moal --- drivers/scsi/scsi_error.c | 51 ++++++++++++++++++++++++++++++++++++++ drivers/scsi/scsi_priv.h | 2 ++ include/scsi/scsi_driver.h | 1 + include/scsi/scsi_host.h | 6 +++++ 4 files changed, 60 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 7390131e7f0a..a9588188e8a6 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -2186,6 +2187,54 @@ void scsi_eh_ready_devs(struct Scsi_Host *shost, } EXPORT_SYMBOL_GPL(scsi_eh_ready_devs); +/* + * Comparison function for sorting SCSI commands by ULD driver. + */ +static int scsi_cmp_uld(void *priv, const struct list_head *_a, + const struct list_head *_b) +{ + struct scsi_cmnd *a = list_entry(_a, typeof(*a), eh_entry); + struct scsi_cmnd *b = list_entry(_b, typeof(*b), eh_entry); + + /* See also the comment above the list_sort() definition. */ + return scsi_cmd_to_driver(a) > scsi_cmd_to_driver(b); +} + +void scsi_call_prepare_resubmit(struct Scsi_Host *shost, + struct list_head *done_q) +{ + struct scsi_cmnd *scmd, *next; + + if (!shost->hostt->needs_prepare_resubmit) + return; + + if (list_empty(done_q)) + return; + + /* Sort pending SCSI commands by ULD. */ + list_sort(NULL, done_q, scsi_cmp_uld); + + /* + * Call .eh_prepare_resubmit for each range of commands with identical + * ULD driver pointer. + */ + list_for_each_entry_safe(scmd, next, done_q, eh_entry) { + struct scsi_driver *uld = + scmd->device ? scsi_cmd_to_driver(scmd) : NULL; + struct list_head *prev, uld_cmd_list; + + while (&next->eh_entry != done_q && + scsi_cmd_to_driver(next) == uld) + next = list_next_entry(next, eh_entry); + if (!uld->eh_prepare_resubmit) + continue; + prev = scmd->eh_entry.prev; + list_cut_position(&uld_cmd_list, prev, next->eh_entry.prev); + uld->eh_prepare_resubmit(&uld_cmd_list); + list_splice(&uld_cmd_list, prev); + } +} + /** * scsi_eh_flush_done_q - finish processed commands or retry them. * @shost: SCSI host pointer. @@ -2195,6 +2244,8 @@ void scsi_eh_flush_done_q(struct Scsi_Host *shost, struct list_head *done_q) { struct scsi_cmnd *scmd, *next; + scsi_call_prepare_resubmit(shost, done_q); + list_for_each_entry_safe(scmd, next, done_q, eh_entry) { list_del_init(&scmd->eh_entry); if (scsi_device_online(scmd->device) && diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index 3f0dfb97db6b..2caf4bcb072a 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -101,6 +101,8 @@ int scsi_eh_get_sense(struct list_head *work_q, struct list_head *done_q); bool scsi_noretry_cmd(struct scsi_cmnd *scmd); void scsi_eh_done(struct scsi_cmnd *scmd); +void scsi_call_prepare_resubmit(struct Scsi_Host *shost, + struct list_head *done_q); /* scsi_lib.c */ extern void scsi_device_unbusy(struct scsi_device *sdev, struct scsi_cmnd *cmd); diff --git a/include/scsi/scsi_driver.h b/include/scsi/scsi_driver.h index 4ce1988b2ba0..2b11be896eee 100644 --- a/include/scsi/scsi_driver.h +++ b/include/scsi/scsi_driver.h @@ -18,6 +18,7 @@ struct scsi_driver { int (*done)(struct scsi_cmnd *); int (*eh_action)(struct scsi_cmnd *, int); void (*eh_reset)(struct scsi_cmnd *); + void (*eh_prepare_resubmit)(struct list_head *cmd_list); }; #define to_scsi_driver(drv) \ container_of((drv), struct scsi_driver, gendrv) diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 49f768d0ff37..3e07e5b1a70c 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -461,6 +461,12 @@ struct scsi_host_template { /* The queuecommand callback may block. See also BLK_MQ_F_BLOCKING. */ unsigned queuecommand_may_block:1; + /* + * The scsi_driver .eh_prepare_resubmit function must be called by + * the SCSI error handler. + */ + unsigned needs_prepare_resubmit:1; + /* * Countdown for host blocking with no commands outstanding. */ From patchwork Mon Oct 23 21:53:58 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: 737744 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 9566CC25B42 for ; Mon, 23 Oct 2023 21:57:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233548AbjJWV5R (ORCPT ); Mon, 23 Oct 2023 17:57:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbjJWV5L (ORCPT ); Mon, 23 Oct 2023 17:57:11 -0400 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D505910D4; Mon, 23 Oct 2023 14:57:07 -0700 (PDT) Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-27d1aee5aa1so2762582a91.0; Mon, 23 Oct 2023 14:57:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098227; x=1698703027; 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=M4qqSCthtEfa+k90uThG1cM6ynrgRU2Y8NB50k0g/ic=; b=sXrqUNkf2bDd92zsT3v/SuYwOusB7i5NUI+kNwggd14lznFhhGQ9JBajs1LhmNN8px 4E4pX23akal94hpYv86hbazTWFEmU1XVFzXRPUGTagfDRyTpLCOF0wx0KvQlyhFf7btL nmbc0agMrZxjAhcMYhnajr2/THmoswf27NmMRVYCfVQihc7WCznzSuGyI9Q7gghfpF6J QQ6p70L98Tk/+j/Egee1m4o+8eALQzo7e8+R32mpmi6nXCqnc00czohiuLmqq2I0zWKJ PscuGrn9NU/wKsVqi+5AIHlfTrvDBrsIs2zo0ts6NgxvGS3hxE5yj9DmHuw7qHegiJRq TaSA== X-Gm-Message-State: AOJu0Yyb0aVFhz41Fz7P5L9M4Wab/OQy0Imn8nvLKxcffCiNkUukghTx 4iZCqCBGZFRDhYG5x4yBP+4= X-Google-Smtp-Source: AGHT+IG2bc8X7lilwVmwvpTiMyHw/gPAteWrTlhMz3iUhPz4C8LeY9OF1VFO+qHD1CvvmZLNR79FUw== X-Received: by 2002:a17:90a:6fc5:b0:268:808:8e82 with SMTP id e63-20020a17090a6fc500b0026808088e82mr13849848pjk.1.1698098227093; Mon, 23 Oct 2023 14:57:07 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.57.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:57:06 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v14 07/19] scsi: core: Add unit tests for scsi_call_prepare_resubmit() Date: Mon, 23 Oct 2023 14:53:58 -0700 Message-ID: <20231023215638.3405959-8-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Triggering all code paths in scsi_call_prepare_resubmit() via manual testing is difficult. Hence add unit tests for this function. Cc: Martin K. Petersen Cc: Damien Le Moal Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- drivers/scsi/Kconfig | 2 + drivers/scsi/Kconfig.kunit | 4 + drivers/scsi/Makefile | 2 + drivers/scsi/Makefile.kunit | 1 + drivers/scsi/scsi_error.c | 3 + drivers/scsi/scsi_error_test.c | 227 +++++++++++++++++++++++++++++++++ 6 files changed, 239 insertions(+) create mode 100644 drivers/scsi/Kconfig.kunit create mode 100644 drivers/scsi/Makefile.kunit create mode 100644 drivers/scsi/scsi_error_test.c diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index 695a57d894cd..734a5b10e94c 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig @@ -232,6 +232,8 @@ config SCSI_SCAN_ASYNC Note that this setting also affects whether resuming from system suspend will be performed asynchronously. +source "drivers/scsi/Kconfig.kunit" + menu "SCSI Transports" depends on SCSI diff --git a/drivers/scsi/Kconfig.kunit b/drivers/scsi/Kconfig.kunit new file mode 100644 index 000000000000..90984a6ec7cc --- /dev/null +++ b/drivers/scsi/Kconfig.kunit @@ -0,0 +1,4 @@ +config SCSI_ERROR_TEST + tristate "scsi_error.c unit tests" if !KUNIT_ALL_TESTS + depends on SCSI && KUNIT + default KUNIT_ALL_TESTS diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile index f055bfd54a68..1c5c3afb6c6e 100644 --- a/drivers/scsi/Makefile +++ b/drivers/scsi/Makefile @@ -168,6 +168,8 @@ scsi_mod-$(CONFIG_PM) += scsi_pm.o scsi_mod-$(CONFIG_SCSI_DH) += scsi_dh.o scsi_mod-$(CONFIG_BLK_DEV_BSG) += scsi_bsg.o +include $(srctree)/drivers/scsi/Makefile.kunit + hv_storvsc-y := storvsc_drv.o sd_mod-objs := sd.o diff --git a/drivers/scsi/Makefile.kunit b/drivers/scsi/Makefile.kunit new file mode 100644 index 000000000000..3e98053b2709 --- /dev/null +++ b/drivers/scsi/Makefile.kunit @@ -0,0 +1 @@ +obj-$(CONFIG_SCSI_ERROR_TEST) += scsi_error_test.o diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index a9588188e8a6..8b1eb637ffa8 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -2234,6 +2234,9 @@ void scsi_call_prepare_resubmit(struct Scsi_Host *shost, list_splice(&uld_cmd_list, prev); } } +#if IS_MODULE(CONFIG_SCSI_ERROR_TEST) +EXPORT_SYMBOL_GPL(scsi_call_prepare_resubmit); +#endif /** * scsi_eh_flush_done_q - finish processed commands or retry them. diff --git a/drivers/scsi/scsi_error_test.c b/drivers/scsi/scsi_error_test.c new file mode 100644 index 000000000000..b9b0f2045ede --- /dev/null +++ b/drivers/scsi/scsi_error_test.c @@ -0,0 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2023 Google LLC + */ +#include +#include +#include +#include +#include +#include "scsi_priv.h" + +#define ALLOC(type, ...) \ + ({ \ + type *obj; \ + obj = kmalloc(sizeof(*obj), GFP_KERNEL); \ + if (obj) \ + *obj = (type){ __VA_ARGS__ }; \ + obj; \ + }) + +#define ALLOC_Q(...) ALLOC(struct request_queue, __VA_ARGS__) + +#define ALLOC_SDEV(...) ALLOC(struct scsi_device, __VA_ARGS__) + +#define ALLOC_CMD(...) ALLOC(struct rq_and_cmd, __VA_ARGS__) + +static struct kunit *kunit_test; + +static void uld_prepare_resubmit(struct list_head *cmd_list) +{ + /* This function must not be called. */ + KUNIT_EXPECT_TRUE(kunit_test, false); +} + +/* + * Verify that .eh_prepare_resubmit() is not called if needs_prepare_resubmit is + * false. + */ +static void test_prepare_resubmit1(struct kunit *test) +{ + static struct gendisk disk; + static struct request_queue q = { + .disk = &disk, + .limits = { + .driver_preserves_write_order = false, + .use_zone_write_lock = true, + .zoned = BLK_ZONED_HM, + } + }; + static struct scsi_driver uld = { + .eh_prepare_resubmit = uld_prepare_resubmit, + }; + static const struct scsi_host_template host_template; + static struct Scsi_Host host = { + .hostt = &host_template, + }; + static struct scsi_device dev = { + .request_queue = &q, + .sdev_gendev.driver = &uld.gendrv, + .host = &host, + }; + static struct rq_and_cmd { + struct request rq; + struct scsi_cmnd cmd; + } cmd1, cmd2; + LIST_HEAD(cmd_list); + + BUILD_BUG_ON(scsi_cmd_to_rq(&cmd1.cmd) != &cmd1.rq); + + disk.queue = &q; + cmd1 = (struct rq_and_cmd){ + .rq = { + .q = &q, + .cmd_flags = REQ_OP_WRITE, + .__sector = 2, + }, + .cmd.device = &dev, + }; + cmd2 = cmd1; + cmd2.rq.__sector = 1; + list_add_tail(&cmd1.cmd.eh_entry, &cmd_list); + list_add_tail(&cmd2.cmd.eh_entry, &cmd_list); + + KUNIT_EXPECT_EQ(test, list_count_nodes(&cmd_list), 2); + kunit_test = test; + scsi_call_prepare_resubmit(&host, &cmd_list); + kunit_test = NULL; + KUNIT_EXPECT_EQ(test, list_count_nodes(&cmd_list), 2); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next, &cmd1.cmd.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next, &cmd2.cmd.eh_entry); +} + +static struct scsi_driver *uld1, *uld2, *uld3; + +static void uld1_prepare_resubmit(struct list_head *cmd_list) +{ + struct scsi_cmnd *cmd; + + KUNIT_EXPECT_EQ(kunit_test, list_count_nodes(cmd_list), 2); + list_for_each_entry(cmd, cmd_list, eh_entry) + KUNIT_EXPECT_PTR_EQ(kunit_test, scsi_cmd_to_driver(cmd), uld1); +} + +static void uld2_prepare_resubmit(struct list_head *cmd_list) +{ + struct scsi_cmnd *cmd; + + KUNIT_EXPECT_EQ(kunit_test, list_count_nodes(cmd_list), 2); + list_for_each_entry(cmd, cmd_list, eh_entry) + KUNIT_EXPECT_PTR_EQ(kunit_test, scsi_cmd_to_driver(cmd), uld2); +} + +static void test_prepare_resubmit2(struct kunit *test) +{ + static const struct scsi_host_template host_template = { + .needs_prepare_resubmit = true, + }; + static struct Scsi_Host host = { + .hostt = &host_template, + }; + struct gendisk *disk __free(kfree) = NULL; + struct request_queue *q __free(kfree) = + ALLOC_Q(.limits = { + .driver_preserves_write_order = true, + .use_zone_write_lock = false, + .zoned = BLK_ZONED_HM, + }); + struct rq_and_cmd { + struct request rq; + struct scsi_cmnd cmd; + } *cmd1 __free(kfree), *cmd2 __free(kfree), *cmd3 __free(kfree), + *cmd4 __free(kfree), *cmd5 __free(kfree), *cmd6 __free(kfree); + struct scsi_device *dev1 __free(kfree), *dev2 __free(kfree), + *dev3 __free(kfree); + struct scsi_driver *uld __free(kfree); + LIST_HEAD(cmd_list); + + BUILD_BUG_ON(scsi_cmd_to_rq(&cmd1->cmd) != &cmd1->rq); + + uld = kzalloc(3 * sizeof(*uld), GFP_KERNEL); + uld1 = &uld[0]; + uld1->eh_prepare_resubmit = uld1_prepare_resubmit; + uld2 = &uld[1]; + uld2->eh_prepare_resubmit = uld2_prepare_resubmit; + uld3 = &uld[2]; + disk = kzalloc(sizeof(*disk), GFP_KERNEL); + disk->queue = q; + q->disk = disk; + dev1 = ALLOC_SDEV(.sdev_gendev.driver = &uld1->gendrv, + .request_queue = q, .host = &host); + dev2 = ALLOC_SDEV(.sdev_gendev.driver = &uld2->gendrv, + .request_queue = q, .host = &host); + dev3 = ALLOC_SDEV(.sdev_gendev.driver = &uld3->gendrv, + .request_queue = q, .host = &host); + cmd1 = ALLOC_CMD( + .rq = { + .q = q, + .cmd_flags = REQ_OP_WRITE, + .__sector = 3, + }, + .cmd.device = dev1, + ); + cmd2 = ALLOC_CMD(); + *cmd2 = *cmd1; + cmd2->rq.__sector = 4; + cmd3 = ALLOC_CMD( + .rq = { + .q = q, + .cmd_flags = REQ_OP_WRITE, + .__sector = 1, + }, + .cmd.device = dev2, + ); + cmd4 = kmemdup(cmd3, sizeof(*cmd3), GFP_KERNEL); + cmd4->rq.__sector = 2, + cmd5 = ALLOC_CMD( + .rq = { + .q = q, + .cmd_flags = REQ_OP_WRITE, + .__sector = 5, + }, + .cmd.device = dev3, + ); + cmd6 = kmemdup(cmd5, sizeof(*cmd3), GFP_KERNEL); + cmd6->rq.__sector = 6; + list_add_tail(&cmd3->cmd.eh_entry, &cmd_list); + list_add_tail(&cmd1->cmd.eh_entry, &cmd_list); + list_add_tail(&cmd2->cmd.eh_entry, &cmd_list); + list_add_tail(&cmd5->cmd.eh_entry, &cmd_list); + list_add_tail(&cmd6->cmd.eh_entry, &cmd_list); + list_add_tail(&cmd4->cmd.eh_entry, &cmd_list); + + KUNIT_EXPECT_EQ(test, list_count_nodes(&cmd_list), 6); + kunit_test = test; + scsi_call_prepare_resubmit(&host, &cmd_list); + kunit_test = NULL; + KUNIT_EXPECT_EQ(test, list_count_nodes(&cmd_list), 6); + KUNIT_EXPECT_TRUE(test, uld1 < uld2); + KUNIT_EXPECT_TRUE(test, uld2 < uld3); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next, &cmd1->cmd.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next, &cmd2->cmd.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next->next, + &cmd3->cmd.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next->next->next, + &cmd4->cmd.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next->next->next->next, + &cmd5->cmd.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next->next->next->next->next, + &cmd6->cmd.eh_entry); + kfree(uld); +} + +static struct kunit_case prepare_resubmit_test_cases[] = { + KUNIT_CASE(test_prepare_resubmit1), + KUNIT_CASE(test_prepare_resubmit2), + {} +}; + +static struct kunit_suite prepare_resubmit_test_suite = { + .name = "prepare_resubmit", + .test_cases = prepare_resubmit_test_cases, +}; +kunit_test_suite(prepare_resubmit_test_suite); + +MODULE_DESCRIPTION("scsi_call_prepare_resubmit() unit tests"); +MODULE_AUTHOR("Bart Van Assche"); +MODULE_LICENSE("GPL"); From patchwork Mon Oct 23 21:53:59 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: 737470 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 53ABCC25B42 for ; Mon, 23 Oct 2023 21:57:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233605AbjJWV5S (ORCPT ); Mon, 23 Oct 2023 17:57:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233620AbjJWV5M (ORCPT ); Mon, 23 Oct 2023 17:57:12 -0400 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3381B10DC; Mon, 23 Oct 2023 14:57:09 -0700 (PDT) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6b7f0170d7bso3631408b3a.2; Mon, 23 Oct 2023 14:57:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098228; x=1698703028; 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=+MwF9wgkw4wG6rVgsbprmoEZnKhhCCis6ECe24Y7w3U=; b=gUktnSOhq/AFfjSf2ZeRR91f2qGhA8S2iZDxvXxBAiByqVllzCsQd7lRw1zK6XPRRZ PLYBuVTUGJhGm3DHiOZHl598fnut0E1PVsQxlRLQ/oWIHdH5CBlXPeigdwUcH4z86nI6 RxfVGGXJYAHu6EpfUJgNnBv9xX1+XeNnFBe59izulueCMu8WRF7HiENqfCaqDmgD9fD/ G1p7T51NdcBvRTBHrgNhhJy+1neOQzZFDOhgsBMEeZh+YT3CnXzw4hECEDcpwWdGAvas P9NY9+GPd3v9gN3hqyJljOqi3aGOA5HBYtOyDrYKxITEQwiVv21QWeqId8CoLC2eQOV+ /4/g== X-Gm-Message-State: AOJu0YwG3cpTlgYTA3pJTfHJKD0NCGmNwO/UZ2bJai7HnOw6yVDn5k14 ZWwndtQndZTZKg+P4e31E3o= X-Google-Smtp-Source: AGHT+IF+CGI0PJ9I+cIeRDIhpuUgpk/AHdlJCkSOXrzp84qBcNJ/hieDhmmIDRVhv9xaP7xTnx/phA== X-Received: by 2002:a05:6a20:3d1e:b0:14c:f16a:2b78 with SMTP id y30-20020a056a203d1e00b0014cf16a2b78mr947207pzi.45.1698098228461; Mon, 23 Oct 2023 14:57:08 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:57:08 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v14 08/19] scsi: sd: Sort commands by LBA before resubmitting Date: Mon, 23 Oct 2023 14:53:59 -0700 Message-ID: <20231023215638.3405959-9-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Sort SCSI commands by LBA before the SCSI error handler resubmits these commands. This is necessary when resubmitting zoned writes (REQ_OP_WRITE) if multiple writes have been queued for a single zone. Cc: Martin K. Petersen Cc: Damien Le Moal Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- drivers/scsi/sd.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index c92a317ba547..c9de909ad506 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -1979,6 +1980,38 @@ static int sd_eh_action(struct scsi_cmnd *scmd, int eh_disp) return eh_disp; } +static int sd_cmp_sector(void *priv, const struct list_head *_a, + const struct list_head *_b) +{ + struct scsi_cmnd *a = list_entry(_a, typeof(*a), eh_entry); + struct scsi_cmnd *b = list_entry(_b, typeof(*b), eh_entry); + struct request *rq_a = scsi_cmd_to_rq(a); + struct request *rq_b = scsi_cmd_to_rq(b); + bool use_zwl_a = rq_a->q->limits.use_zone_write_lock; + bool use_zwl_b = rq_b->q->limits.use_zone_write_lock; + + /* + * Order the commands that need zone write locking after the commands + * that do not need zone write locking. Order the commands that do not + * need zone write locking by LBA. Do not reorder the commands that + * need zone write locking. See also the comment above the list_sort() + * definition. + */ + if (use_zwl_a || use_zwl_b) + return use_zwl_a > use_zwl_b; + return blk_rq_pos(rq_a) > blk_rq_pos(rq_b); +} + +static void sd_prepare_resubmit(struct list_head *cmd_list) +{ + /* + * Sort pending SCSI commands in starting sector order. This is + * important if one of the SCSI devices associated with @shost is a + * zoned block device for which zone write locking is disabled. + */ + list_sort(NULL, cmd_list, sd_cmp_sector); +} + static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd) { struct request *req = scsi_cmd_to_rq(scmd); @@ -3915,6 +3948,7 @@ static struct scsi_driver sd_template = { .done = sd_done, .eh_action = sd_eh_action, .eh_reset = sd_eh_reset, + .eh_prepare_resubmit = sd_prepare_resubmit, }; /** From patchwork Mon Oct 23 21:54:00 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: 737469 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 E6AB5C25B45 for ; Mon, 23 Oct 2023 21:57:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233572AbjJWV50 (ORCPT ); Mon, 23 Oct 2023 17:57:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233387AbjJWV5S (ORCPT ); Mon, 23 Oct 2023 17:57:18 -0400 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4B7AD79; Mon, 23 Oct 2023 14:57:15 -0700 (PDT) Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-27d0251d305so2477076a91.2; Mon, 23 Oct 2023 14:57:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098235; x=1698703035; 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=eslftmeaUhr6gGr/R7540wMyMB4pipneawlcocLt5qY=; b=ZKYONOk6+nMhxpwcOwD5CIjj6JhSIb4A+qGYbrbD9DmJSN9HlPTXV0eS74AbZTnmlY ztHfZvunRiUZqSdZBjfH+DWuMV90LoOtLhzyp5EzpL205/LPf77NyEvgzs9j2FQ42Ylu ZacfgVXg8xYnn1AVvHTRMUlha+NrabGAniYk5DECbxfc6YY3Q+O37jtQd4buW3Jc3FV8 tfQ1Dr6cVAMaSMN5jrTQBc7yNHVjT9F+qWeai5a4WdLKUI85VmLuyCEyuwIRsJzV0z// rtVztg6bG4T67Il8mxmvAyeUGw7ngPtDNzdQR+gQw7r6s411cT7dzBw2rOGYkm+Okj0k QZ6Q== X-Gm-Message-State: AOJu0YwY6HXm/34sTbHJHsP2dv6PnQbCXBelepowXNDnFpEMY2x+Y9UG IPQl03EndRC6FJ6ZjNZBV9A= X-Google-Smtp-Source: AGHT+IF89FVXIfoPrVM7/ipFwSNPc0oTakHnELADax/9myEN88959OyA9/138kjoBFR1O7P4stiugg== X-Received: by 2002:a17:90b:f98:b0:27d:3e90:9ee1 with SMTP id ft24-20020a17090b0f9800b0027d3e909ee1mr9074086pjb.23.1698098235043; Mon, 23 Oct 2023 14:57:15 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:57:14 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v14 09/19] scsi: sd: Add a unit test for sd_cmp_sector() Date: Mon, 23 Oct 2023 14:54:00 -0700 Message-ID: <20231023215638.3405959-10-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Make it easier to test sd_cmp_sector() by adding a unit test for this function. Cc: Martin K. Petersen Cc: Damien Le Moal Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- drivers/scsi/Kconfig.kunit | 5 +++ drivers/scsi/Makefile.kunit | 1 + drivers/scsi/sd.c | 7 ++- drivers/scsi/sd.h | 2 + drivers/scsi/sd_test.c | 86 +++++++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 drivers/scsi/sd_test.c diff --git a/drivers/scsi/Kconfig.kunit b/drivers/scsi/Kconfig.kunit index 90984a6ec7cc..907798967b6f 100644 --- a/drivers/scsi/Kconfig.kunit +++ b/drivers/scsi/Kconfig.kunit @@ -2,3 +2,8 @@ config SCSI_ERROR_TEST tristate "scsi_error.c unit tests" if !KUNIT_ALL_TESTS depends on SCSI && KUNIT default KUNIT_ALL_TESTS + +config SD_TEST + tristate "sd.c unit tests" if !KUNIT_ALL_TESTS + depends on SCSI && BLK_DEV_SD && KUNIT + default KUNIT_ALL_TESTS diff --git a/drivers/scsi/Makefile.kunit b/drivers/scsi/Makefile.kunit index 3e98053b2709..dc0a21d7749f 100644 --- a/drivers/scsi/Makefile.kunit +++ b/drivers/scsi/Makefile.kunit @@ -1 +1,2 @@ obj-$(CONFIG_SCSI_ERROR_TEST) += scsi_error_test.o +obj-$(CONFIG_SD_TEST) += sd_test.o diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index c9de909ad506..82abc721b543 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1980,8 +1980,8 @@ static int sd_eh_action(struct scsi_cmnd *scmd, int eh_disp) return eh_disp; } -static int sd_cmp_sector(void *priv, const struct list_head *_a, - const struct list_head *_b) +int sd_cmp_sector(void *priv, const struct list_head *_a, + const struct list_head *_b) { struct scsi_cmnd *a = list_entry(_a, typeof(*a), eh_entry); struct scsi_cmnd *b = list_entry(_b, typeof(*b), eh_entry); @@ -2001,6 +2001,9 @@ static int sd_cmp_sector(void *priv, const struct list_head *_a, return use_zwl_a > use_zwl_b; return blk_rq_pos(rq_a) > blk_rq_pos(rq_b); } +#if IS_MODULE(CONFIG_SD_TEST) +EXPORT_SYMBOL_GPL(sd_cmp_sector); +#endif static void sd_prepare_resubmit(struct list_head *cmd_list) { diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 5eea762f84d1..35b7cdb7bf3b 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -292,6 +292,8 @@ static inline blk_status_t sd_zbc_prepare_zone_append(struct scsi_cmnd *cmd, #endif /* CONFIG_BLK_DEV_ZONED */ +int sd_cmp_sector(void *priv, const struct list_head *_a, + const struct list_head *_b); void sd_print_sense_hdr(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr); void sd_print_result(const struct scsi_disk *sdkp, const char *msg, int result); diff --git a/drivers/scsi/sd_test.c b/drivers/scsi/sd_test.c new file mode 100644 index 000000000000..b9c3d2bf311e --- /dev/null +++ b/drivers/scsi/sd_test.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2023 Google LLC + */ +#include +#include +#include +#include +#include +#include +#include "sd.h" + +#define ALLOC(type, ...) \ + ({ \ + type *obj; \ + obj = kmalloc(sizeof(*obj), GFP_KERNEL); \ + if (obj) \ + *obj = (type){ __VA_ARGS__ }; \ + obj; \ + }) + +#define ALLOC_Q(...) ALLOC(struct request_queue, __VA_ARGS__) + +#define ALLOC_CMD(...) ALLOC(struct rq_and_cmd, __VA_ARGS__) + +struct rq_and_cmd { + struct request rq; + struct scsi_cmnd cmd; +}; + +/* + * Verify that sd_cmp_sector() does what it is expected to do. + */ +static void test_sd_cmp_sector(struct kunit *test) +{ + struct request_queue *q1 __free(kfree) = + ALLOC_Q(.limits.use_zone_write_lock = true); + struct request_queue *q2 __free(kfree) = + ALLOC_Q(.limits.use_zone_write_lock = false); + struct rq_and_cmd *cmd1 __free(kfree) = ALLOC_CMD(.rq = { + .q = q1, + .__sector = 7, + }); + struct rq_and_cmd *cmd2 __free(kfree) = ALLOC_CMD(.rq = { + .q = q1, + .__sector = 5, + }); + struct rq_and_cmd *cmd3 __free(kfree) = ALLOC_CMD(.rq = { + .q = q2, + .__sector = 7, + }); + struct rq_and_cmd *cmd4 __free(kfree) = ALLOC_CMD(.rq = { + .q = q2, + .__sector = 5, + }); + LIST_HEAD(cmd_list); + + list_add_tail(&cmd1->cmd.eh_entry, &cmd_list); + list_add_tail(&cmd2->cmd.eh_entry, &cmd_list); + list_add_tail(&cmd3->cmd.eh_entry, &cmd_list); + list_add_tail(&cmd4->cmd.eh_entry, &cmd_list); + KUNIT_EXPECT_EQ(test, list_count_nodes(&cmd_list), 4); + list_sort(NULL, &cmd_list, sd_cmp_sector); + KUNIT_EXPECT_EQ(test, list_count_nodes(&cmd_list), 4); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next, &cmd4->cmd.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next, &cmd3->cmd.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next->next, + &cmd1->cmd.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next->next->next, + &cmd2->cmd.eh_entry); +} + +static struct kunit_case sd_test_cases[] = { + KUNIT_CASE(test_sd_cmp_sector), + {} +}; + +static struct kunit_suite sd_test_suite = { + .name = "sd", + .test_cases = sd_test_cases, +}; +kunit_test_suite(sd_test_suite); + +MODULE_DESCRIPTION("SCSI disk (sd) driver unit tests"); +MODULE_AUTHOR("Bart Van Assche"); +MODULE_LICENSE("GPL"); From patchwork Mon Oct 23 21:54:01 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: 737743 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 723D1C25B46 for ; Mon, 23 Oct 2023 21:57:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233638AbjJWV51 (ORCPT ); Mon, 23 Oct 2023 17:57:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233624AbjJWV5T (ORCPT ); Mon, 23 Oct 2023 17:57:19 -0400 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FD1F10CE; Mon, 23 Oct 2023 14:57:17 -0700 (PDT) Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-27d23f1e3b8so3269265a91.1; Mon, 23 Oct 2023 14:57:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098236; x=1698703036; 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=cx49ComzXIk6YQdiKmeJ7XcBZ6Q2N4Tg8VArGGWadjk=; b=lHaoNOSKp9oVZK8p1I0Jm+WurfzItL4rGUAlx+PEcwPVv92Sr2tQQ1UXZ24JkljOiM rdfk1LgOqL4/1lBDnb0lbisu1V0KxvKKC+87msq50Q/+3tbnwMzeCyebNsD20PD6s0Dr 8Vy1CB9aBkp1zuJbO1W8Kbd0MgsC42Jwis8bAfbuMgfvXEDKcG0IVAwhCQ1Q+axWrRhN TKfpNILIqaxkuvDfHGD1gcysj2sIo0xo6WMrglXH1a4Cam7PrmvsVTezPjJfKJseI6Ke neLbJoh/ACWeSFAmfVFwzedBB/LKNXZnBeZZvB2lnIvIRqnxiZZwJ1vlSPzmQL2fsXxt UTNA== X-Gm-Message-State: AOJu0YyRLGAu5d42J+cyjv90R8wCBQE65dPrcQa8vimHKi3acSxD9MJW 1OelnruYXxV2AegUT+XzIgY= X-Google-Smtp-Source: AGHT+IE21QgfX+sNSY3NPVXYgtSgxbmaU97grVdxp/FacjI6ezhQ2aLiy+bPREGymaqAZ4R9pR0LUg== X-Received: by 2002:a17:90a:1996:b0:27d:2054:9641 with SMTP id 22-20020a17090a199600b0027d20549641mr10300547pji.36.1698098236525; Mon, 23 Oct 2023 14:57:16 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:57:16 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v14 10/19] scsi: core: Retry unaligned zoned writes Date: Mon, 23 Oct 2023 14:54:01 -0700 Message-ID: <20231023215638.3405959-11-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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 zoned writes have been reordered, then the storage device will respond with an UNALIGNED WRITE COMMAND error. Send commands that failed with an unaligned write error to the SCSI error handler if zone write locking is disabled. The SCSI error handler will sort SCSI commands per LBA before resubmitting these. If zone write locking is disabled, 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. 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 ++++++++++++++++ drivers/scsi/scsi_lib.c | 1 + drivers/scsi/sd.c | 6 ++++++ include/scsi/scsi.h | 1 + 4 files changed, 24 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 8b1eb637ffa8..9a54856fa03b 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -699,6 +699,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 zone + * write locking is disabled, retry after all pending commands + * have completed. + */ + if (sshdr.asc == 0x21 && sshdr.ascq == 0x04 && + !req->q->limits.use_zone_write_lock && + blk_rq_is_seq_zoned_write(req) && + scmd->retries <= scmd->allowed) { + sdev_printk(KERN_INFO, scmd->device, + "Retrying unaligned write at LBA %#llx.\n", + scsi_get_lba(scmd)); + return NEEDS_DELAYED_RETRY; + } + if (sshdr.asc == 0x20 || /* Invalid command operation code */ sshdr.asc == 0x21 || /* Logical block address out of range */ sshdr.asc == 0x22 || /* Invalid function */ diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index c2f647a7c1b0..33a34693c8a2 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1443,6 +1443,7 @@ static void scsi_complete(struct request *rq) case ADD_TO_MLQUEUE: scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY); break; + case NEEDS_DELAYED_RETRY: default: scsi_eh_scmd_add(cmd); break; diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 82abc721b543..4e6b77f5854f 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1197,6 +1197,12 @@ 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 zone + * write locking is disabled. + */ + if (!rq->q->limits.use_zone_write_lock && 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, diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h index ec093594ba53..6600db046227 100644 --- a/include/scsi/scsi.h +++ b/include/scsi/scsi.h @@ -93,6 +93,7 @@ static inline int scsi_status_is_check_condition(int status) * Internal return values. */ enum scsi_disposition { + NEEDS_DELAYED_RETRY = 0x2000, NEEDS_RETRY = 0x2001, SUCCESS = 0x2002, FAILED = 0x2003, From patchwork Mon Oct 23 21:54:02 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: 737742 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 152D8C25B49 for ; Mon, 23 Oct 2023 21:57:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233609AbjJWV52 (ORCPT ); Mon, 23 Oct 2023 17:57:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233641AbjJWV5U (ORCPT ); Mon, 23 Oct 2023 17:57:20 -0400 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AA8A10D4; Mon, 23 Oct 2023 14:57:18 -0700 (PDT) Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-27d0251d305so2477117a91.2; Mon, 23 Oct 2023 14:57:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098238; x=1698703038; 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=KzaYxnCqQNUVR3i3khEB0a4wN2TqC5S5bjyD6Ki8qwY=; b=lt4UT+cZArwJUfLCtu78yynM/OV/s875M7KdhWDns+029oirX0ztFP4z8AyBf3O++t v4V5dFH0cNgxjz11RM51qitE6QyEUpldcH0DZIT/EDVbKM8tvJGGE8SSn7ECRvtg2Ix8 u9Dnf5xj8HQGyNzBurLbM9hjMTb/jN9o+qJfBEtD6CCKM5faWePAfpoUVdf86WQEfp5f PyaJriskLxl7Ia04oBJ4kv3BejG6GohEwMnlk1aN6EDmVlcRP0MmOYpzu93WYIcKWPwA h8dqC+1I73pjYCswtSoPOihlnKI74FcA94JtFt2Lm+n83T/qgZL3ikkrU/uFJaek7x25 7EUA== X-Gm-Message-State: AOJu0YxpnVUFEJaNQT/BLATDBMtDj5VzLpFe3LcMBjf7cVEhvG6ttE7J ZJ2fhjch/VRzfSa4c3C6FOg= X-Google-Smtp-Source: AGHT+IEc95mRiWYe19QEf1c6PbttdDZO+usFDQZzlmhFSnlCgbhpscBLmMPz769p1kK7+UrBGFYMBA== X-Received: by 2002:a17:90b:3717:b0:27d:98f3:21a7 with SMTP id mg23-20020a17090b371700b0027d98f321a7mr7706129pjb.8.1698098237793; Mon, 23 Oct 2023 14:57:17 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:57:17 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v14 11/19] scsi: sd_zbc: Only require an I/O scheduler if needed Date: Mon, 23 Oct 2023 14:54:02 -0700 Message-ID: <20231023215638.3405959-12-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org An I/O scheduler that serializes zoned writes is only needed if the SCSI LLD does not preserve the write order. Hence only set ELEVATOR_F_ZBD_SEQ_WRITE if the LLD does not preserve the write order. Reviewed-by: Damien Le Moal Cc: Martin K. Petersen Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- drivers/scsi/sd_zbc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index a25215507668..718b31bed878 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -955,7 +955,9 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, u8 buf[SD_BUF_SIZE]) /* The drive satisfies the kernel restrictions: set it up */ blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); - blk_queue_required_elevator_features(q, ELEVATOR_F_ZBD_SEQ_WRITE); + if (!q->limits.driver_preserves_write_order) + blk_queue_required_elevator_features(q, + ELEVATOR_F_ZBD_SEQ_WRITE); if (sdkp->zones_max_open == U32_MAX) disk_set_max_open_zones(disk, 0); else From patchwork Mon Oct 23 21:54:03 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: 737468 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 C0EB8C25B4D for ; Mon, 23 Oct 2023 21:57:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233665AbjJWV53 (ORCPT ); Mon, 23 Oct 2023 17:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233694AbjJWV5Y (ORCPT ); Mon, 23 Oct 2023 17:57:24 -0400 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9D2110E7; Mon, 23 Oct 2023 14:57:19 -0700 (PDT) Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-564b6276941so3002234a12.3; Mon, 23 Oct 2023 14:57:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098239; x=1698703039; 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=035k58Gc0xjZLYCOymyww+e8cIPTj80YBwmkGqX/6yA=; b=JoV4iq06FWpQHTGfxdHQKwUXENR9d1CAPW01Dr3MvRxLJkXbtkMLKuSe08cHvQ8xWZ z9pNJ2gfrpVX5Otl8tmUqHi6cL/CV/VKOJwKpQSCqkox7xrbFypfD2fyzbQI4DWJ5Sod BKWTgCFrmS9qDqATQW7L0TDJVtZGUZtkN9R2K7P+cXr0ffJu7b8FmXGTXD2vuxzx07X0 phzV2LJxJd1qCGVxiRftaWmoGBKLQEK3EEguGGNAcb3xve7aK0mexwLSNbA2+lqoWHUu 5ybMp6lzXVRUxbChVyNYeYp3wmGjyWGDS4G6GydMyhAybf/oHgUBWHLNuOw4icZeeNPw 5QkQ== X-Gm-Message-State: AOJu0YwK9Kg1Xgc4qp3lRZmA5ajyUxmDXVqT/P0rXwBNCu4Y4iaASYgr wU/RtZnHX7INtbCxC2w5PJA= X-Google-Smtp-Source: AGHT+IHjBlHmvzNZardMAAImwOu4q3MqqnOh0Ig36ujDnZ4x/zlGbGub4rh3A8S1RPaOOEdeheX0tg== X-Received: by 2002:a05:6a21:790a:b0:17a:284:97c4 with SMTP id bg10-20020a056a21790a00b0017a028497c4mr886231pzc.61.1698098239185; Mon, 23 Oct 2023 14:57:19 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:57:18 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Douglas Gilbert , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v14 12/19] scsi: scsi_debug: Add the preserves_write_order module parameter Date: Mon, 23 Oct 2023 14:54:03 -0700 Message-ID: <20231023215638.3405959-13-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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 Cc: Martin K. Petersen Cc: Damien Le Moal 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 9c0af50501f9..1ea4925d2c2f 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -832,6 +832,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; @@ -5138,9 +5139,13 @@ static struct sdebug_dev_info *find_build_dev_info(struct scsi_device *sdev) static int scsi_debug_slave_alloc(struct scsi_device *sdp) { + struct request_queue *q = sdp->request_queue; + if (sdebug_verbose) pr_info("slave_alloc <%u %u %u %llu>\n", sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); + if (sdeb_preserves_write_order) + q->limits.driver_preserves_write_order = true; return 0; } @@ -5755,6 +5760,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); @@ -5812,6 +5819,8 @@ MODULE_PARM_DESC(ndelay, "response delay in nanoseconds (def=0 -> ignore)"); MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)"); MODULE_PARM_DESC(no_rwlock, "don't protect user data reads+writes (def=0)"); MODULE_PARM_DESC(no_uld, "stop ULD (e.g. sd driver) attaching (def=0))"); +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(num_parts, "number of partitions(def=0)"); MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)"); MODULE_PARM_DESC(opt_blks, "optimal transfer length in blocks (def=1024)"); From patchwork Mon Oct 23 21:54:04 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: 737741 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 91979C00A8F for ; Mon, 23 Oct 2023 21:57:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233509AbjJWV5j (ORCPT ); Mon, 23 Oct 2023 17:57:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233705AbjJWV5Y (ORCPT ); Mon, 23 Oct 2023 17:57:24 -0400 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C9F610EC; Mon, 23 Oct 2023 14:57:21 -0700 (PDT) Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-564af0ac494so2268214a12.0; Mon, 23 Oct 2023 14:57:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098240; x=1698703040; 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=mKw3Aw2p8++zyZ3GJZp8ItEvankLwq1zpCMHoyF24eQ=; b=CWA8BPmIohmEGUDYMPyhJq9VH9h2XD7175/bnjMSOdxU75loTf7F1BFclYj+W13AaK +bSI7UP2xr+c4ORJyhAO7bQ0hDJ9d8BBOzoQRu+ZlBVtUVGF3ro/yRviMUGBrMOptNAg pMV5GlrSfKGiWboSi2IvaC3SPROWY1RNr9oldbVfc1G7FijsqTAfkJaY10b53H8BwAJs V4jbIMZ0cIfvtg0lMMb0YXum+AacO4mTbXB0xKsO9cZdmDjPzoShg1xtm6A9bIstb3lW +OkqRb+LqGUr/BfjeippwqaLLDZKDOLsEhFRkaI7Mb2JW/hedZviGvHT5v5WxiSRpc4I kAjQ== X-Gm-Message-State: AOJu0YwR6XKyEM4ma6F1ztwOliGHAkozJfoKcbV+jNHWeZ1JXZqMpaLe HSQgeWFaxda7OMOzIzLMZBs= X-Google-Smtp-Source: AGHT+IEpDxM3YONiZwMFQEk4b2mAmkbWU9ZBBwbCPtXFuZ6mEDcCWgiCMR5XvX3h6ZB7CtZwCM8LYw== X-Received: by 2002:a17:90a:19c5:b0:27d:e73:3077 with SMTP id 5-20020a17090a19c500b0027d0e733077mr8024912pjj.1.1698098240525; Mon, 23 Oct 2023 14:57:20 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.57.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:57:20 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , Douglas Gilbert , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v14 13/19] scsi: scsi_debug: Support injecting unaligned write errors Date: Mon, 23 Oct 2023 14:54:04 -0700 Message-ID: <20231023215638.3405959-14-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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 1ea4925d2c2f..164e82c218ff 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -181,6 +181,7 @@ static const char *sdebug_version_date = "20210520"; #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 | \ @@ -188,7 +189,8 @@ static const char *sdebug_version_date = "20210520"; 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) @@ -3587,6 +3589,14 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) struct sdeb_store_info *sip = devip2sip(devip, true); u8 *cmd = scp->cmnd; + 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; From patchwork Mon Oct 23 21:54:05 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: 737467 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 3C1C4C00A8F for ; Mon, 23 Oct 2023 21:57:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233676AbjJWV5m (ORCPT ); Mon, 23 Oct 2023 17:57:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233684AbjJWV5a (ORCPT ); Mon, 23 Oct 2023 17:57:30 -0400 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2457E10D1; Mon, 23 Oct 2023 14:57:28 -0700 (PDT) Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-27d113508bfso3269233a91.3; Mon, 23 Oct 2023 14:57:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098247; x=1698703047; 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=XeTP9UxMC9xuYvRY29/KP6o+hE37UxPqFnd4pYMhYhI=; b=aztYl985tFqX3IBVkb3PPhcy0t7ZUVT1Z5dy67UHptdp5Qz0hxzrRSR89gqmnWixdD 32Ik7wUcBTBogjtw9EgZexjsGD+l4gX5c69MJ3p69TjSrm7ptJpAoIuZIBT0Dfs7WZQC XaS6mpTnVd27RaNxqR1/5za9PiFkygUMKTjBhUpgtb9EavABZPHDFwB86ENtfswEbpgy /XUncnZm5qi2AoNn5T9Nc0bGSLESEyTFiO264Dlu/L36XEmEZgh9KLQP7oN+uBooVEAB CiE1NXyo3cKo6MZOErKeXnJL3qh+fwBI3a4iI0Qy0/i1PDgUpz0CT3Xp7VxRft1ZbcNM 4IpA== X-Gm-Message-State: AOJu0YycoSwFBtMJBfLb3VLt5WR6alRAU88CWapbjcvBmEx6P8JTlHp9 FK1Sv4d8qYC9nkSdqc2UIec= X-Google-Smtp-Source: AGHT+IFvMjCQL618I1hkh8Ykghqvr+SDilKYxgGyqq/Ja6+VI8YMobiB/rXNeOOGBMIqDTKn8jYTaw== X-Received: by 2002:a17:90a:dd44:b0:27d:916a:23ec with SMTP id u4-20020a17090add4400b0027d916a23ecmr11691856pjv.37.1698098247439; Mon, 23 Oct 2023 14:57:27 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.57.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:57:27 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , "Bao D . Nguyen" , Can Guo , Avri Altman , "James E.J. Bottomley" , Stanley Chu , Adrian Hunter , Keoseong Park , Krzysztof Kozlowski Subject: [PATCH v14 14/19] scsi: ufs: hisi: Rework the code that disables auto-hibernation Date: Mon, 23 Oct 2023 14:54:05 -0700 Message-ID: <20231023215638.3405959-15-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The host driver link startup callback is called indirectly by ufshcd_probe_hba(). That function applies the auto-hibernation settings by writing hba->ahit into the auto-hibernation control register. Simplify the code for disabling auto-hibernation by setting hba->ahit instead of writing into the auto-hibernation control register. This patch is part of an effort to move all auto-hibernation register changes into the UFSHCI driver core. Reviewed-by: Bao D. Nguyen Cc: Martin K. Petersen Cc: Can Guo Cc: Avri Altman Signed-off-by: Bart Van Assche --- drivers/ufs/host/ufs-hisi.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/ufs/host/ufs-hisi.c b/drivers/ufs/host/ufs-hisi.c index 5b3060cd0ab8..f2ec687121bb 100644 --- a/drivers/ufs/host/ufs-hisi.c +++ b/drivers/ufs/host/ufs-hisi.c @@ -142,7 +142,6 @@ static int ufs_hisi_link_startup_pre_change(struct ufs_hba *hba) struct ufs_hisi_host *host = ufshcd_get_variant(hba); int err; uint32_t value; - uint32_t reg; /* Unipro VS_mphy_disable */ ufshcd_dme_set(hba, UIC_ARG_MIB_SEL(0xD0C1, 0x0), 0x1); @@ -232,9 +231,7 @@ static int ufs_hisi_link_startup_pre_change(struct ufs_hba *hba) ufshcd_writel(hba, UFS_HCLKDIV_NORMAL_VALUE, UFS_REG_HCLKDIV); /* disable auto H8 */ - reg = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER); - reg = reg & (~UFS_AHIT_AH8ITV_MASK); - ufshcd_writel(hba, reg, REG_AUTO_HIBERNATE_IDLE_TIMER); + hba->ahit = 0; /* Unipro PA_Local_TX_LCC_Enable */ ufshcd_disable_host_tx_lcc(hba); From patchwork Mon Oct 23 21:54:06 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: 737740 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 D6851C25B42 for ; Mon, 23 Oct 2023 21:57:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233710AbjJWV55 (ORCPT ); Mon, 23 Oct 2023 17:57:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233519AbjJWV5p (ORCPT ); Mon, 23 Oct 2023 17:57:45 -0400 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6600D10C7; Mon, 23 Oct 2023 14:57:41 -0700 (PDT) Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-27d104fa285so3271984a91.2; Mon, 23 Oct 2023 14:57:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098260; x=1698703060; 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=V/rTfHgytuRXp+ZwQl4c9m7yojfusAtRvmfOp3Vdh2A=; b=s/CZi8rJMDqmy7kRxIeydUsGyoc9fBvPwnCOW8BrtPKu3Ufq9urgjNcdvUFhogB84Q s+thmrFlGFNqFrDst1RXg0Bv42OMbTYkk7iAlbwOKWSbVoWrhJBn6kmPhbWhXoAlXlpy u34Uh9alzBCaKvPa+7C0DSaYsF5ryd8GS05QwWm9oRJrCnGRYmNnk/647MmaksvceFSL x8aTFxFWaU/ZZ1vXrlOBfV8gGuJosSmhANXcObQI9czrikXHyEpEiRO7YrhE8ogM01a1 4TO+R9k4N4r50UMWx8wBPnn80qh1z03bfTwJwnfS6ZUXUepMK6dxUb4zGOQQMifS4Ep+ GaXw== X-Gm-Message-State: AOJu0YxHFh3P4tcnYLdpr0gcpTV+z9vWAQLJot0FCdjVmDijCBIiOO71 dGX+lrZN70MuNoKV2EglfsOajVaqG50= X-Google-Smtp-Source: AGHT+IGF0iJVAOVzzctpRgkGvOhgNZ639u9wvySQziNJqVj3qVn+HQLNn9Drfsvv2trpTSO2URte6Q== X-Received: by 2002:a17:90a:355:b0:273:cb91:c74f with SMTP id 21-20020a17090a035500b00273cb91c74fmr9822927pjf.8.1698098260472; Mon, 23 Oct 2023 14:57:40 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:57:40 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , "Bao D . Nguyen" , Can Guo , Avri Altman , "James E.J. Bottomley" , Stanley Chu , Manivannan Sadhasivam , Asutosh Das , Bean Huo , Arthur Simchaev , Po-Wen Kao , Eric Biggers , Keoseong Park Subject: [PATCH v14 15/19] scsi: ufs: Rename ufshcd_auto_hibern8_enable() and make it static Date: Mon, 23 Oct 2023 14:54:06 -0700 Message-ID: <20231023215638.3405959-16-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Rename ufshcd_auto_hibern8_enable() into ufshcd_configure_auto_hibern8() since this function can enable or disable auto-hibernation. Since ufshcd_auto_hibern8_enable() is only used inside the UFSHCI driver core, declare it static. Additionally, move the definition of this function to just before its first caller. Suggested-by: Bao D. Nguyen Reviewed-by: Bao D. Nguyen Reviewed-by: Can Guo Cc: Martin K. Petersen Cc: Avri Altman Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 24 +++++++++++------------- include/ufs/ufshcd.h | 1 - 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index c2df07545f96..38e79ce05545 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -4305,6 +4305,14 @@ int ufshcd_uic_hibern8_exit(struct ufs_hba *hba) } EXPORT_SYMBOL_GPL(ufshcd_uic_hibern8_exit); +static void ufshcd_configure_auto_hibern8(struct ufs_hba *hba) +{ + if (!ufshcd_is_auto_hibern8_supported(hba)) + return; + + ufshcd_writel(hba, hba->ahit, REG_AUTO_HIBERNATE_IDLE_TIMER); +} + void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) { unsigned long flags; @@ -4324,21 +4332,13 @@ void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) !pm_runtime_suspended(&hba->ufs_device_wlun->sdev_gendev)) { ufshcd_rpm_get_sync(hba); ufshcd_hold(hba); - ufshcd_auto_hibern8_enable(hba); + ufshcd_configure_auto_hibern8(hba); ufshcd_release(hba); ufshcd_rpm_put_sync(hba); } } EXPORT_SYMBOL_GPL(ufshcd_auto_hibern8_update); -void ufshcd_auto_hibern8_enable(struct ufs_hba *hba) -{ - if (!ufshcd_is_auto_hibern8_supported(hba)) - return; - - ufshcd_writel(hba, hba->ahit, REG_AUTO_HIBERNATE_IDLE_TIMER); -} - /** * ufshcd_init_pwr_info - setting the POR (power on reset) * values in hba power info @@ -8757,8 +8757,7 @@ static int ufshcd_probe_hba(struct ufs_hba *hba, bool init_dev_params) if (hba->ee_usr_mask) ufshcd_write_ee_control(hba); - /* Enable Auto-Hibernate if configured */ - ufshcd_auto_hibern8_enable(hba); + ufshcd_configure_auto_hibern8(hba); out: spin_lock_irqsave(hba->host->host_lock, flags); @@ -9744,8 +9743,7 @@ static int __ufshcd_wl_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) cancel_delayed_work(&hba->rpm_dev_flush_recheck_work); } - /* Enable Auto-Hibernate if configured */ - ufshcd_auto_hibern8_enable(hba); + ufshcd_configure_auto_hibern8(hba); goto out; diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index 7d07b256e906..fceef91d186e 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1356,7 +1356,6 @@ static inline int ufshcd_disable_host_tx_lcc(struct ufs_hba *hba) return ufshcd_dme_set(hba, UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE), 0); } -void ufshcd_auto_hibern8_enable(struct ufs_hba *hba); void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit); void ufshcd_fixup_dev_quirks(struct ufs_hba *hba, const struct ufs_dev_quirk *fixups); From patchwork Mon Oct 23 21:54: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: 737466 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 11316C25B42 for ; Mon, 23 Oct 2023 21:58:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231419AbjJWV6I (ORCPT ); Mon, 23 Oct 2023 17:58:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231381AbjJWV6H (ORCPT ); Mon, 23 Oct 2023 17:58:07 -0400 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B1DFDE; Mon, 23 Oct 2023 14:58:05 -0700 (PDT) Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-27d3ede72f6so3339068a91.1; Mon, 23 Oct 2023 14:58:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098285; x=1698703085; 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=SlC0BoedbyGdgzOhgrB/N96VnR6DBEr2m3fzKGpr6oQ=; b=ZfjvPcFyIJeBkjjNlBzjUdNBcw9aBH5kH0WXJkTWHlbziNwxvylNvOUQbpUJV3fxwa FM0PXMR6tEdfZ9wzFJB7G8hIwBDWF+hPxsDFvbpy03OkdjLBQYcxNycE+eL5iDVhX1Lb OQwEFgA+/eSNBKrMchmRpx+0bp5fqspJeqva+JXbCeSW75t0FH+NMDbdY39V7DvAm5Cq gbFTXK5DsuRI+lOzhH6w6SSrRQb8HPfol3263+v5Zhkr26rSafE5OPf52Geb/BpqauJB AiS7iZXFST14Y0gkE9e1pGsWsU2ziXptnOb68tqyDeOnQn7OeE8nudM1A5k3kKF2rV6+ nMsA== X-Gm-Message-State: AOJu0Yzv5D25py1vZs1SX1mBHhTaGs/h3k/bH0HHmPZUK3P4x0eV7K9D 3aITTdG4ntby8rN9XNyVwV4= X-Google-Smtp-Source: AGHT+IFeP7+z6b6NCRR7zZBnTFItyvS6sBOpHnYBPFpCOQi0QgK95zM94cfDwRPPfCf7q+E6zFatMQ== X-Received: by 2002:a17:90a:e509:b0:27d:b811:2fe4 with SMTP id t9-20020a17090ae50900b0027db8112fe4mr9674322pjy.26.1698098284773; Mon, 23 Oct 2023 14:58:04 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:58:04 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , "Bao D . Nguyen" , Can Guo , Peter Wang , Avri Altman , "James E.J. Bottomley" , Matthias Brugger , Bean Huo , Arthur Simchaev , Lu Hongfei , Stanley Chu , Manivannan Sadhasivam , Asutosh Das , zhanghui , Po-Wen Kao , Eric Biggers , Keoseong Park Subject: [PATCH v14 16/19] scsi: ufs: Change the return type of ufshcd_auto_hibern8_update() Date: Mon, 23 Oct 2023 14:54:07 -0700 Message-ID: <20231023215638.3405959-17-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org A later patch will introduce an error path in ufshcd_auto_hibern8_update(). Change the return type of that function before introducing calls to that function in the host drivers such that the host drivers only have to be modified once. Reviewed-by: Bao D. Nguyen Reviewed-by: Can Guo Reviewed-by: Peter Wang Cc: Martin K. Petersen Cc: Avri Altman Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufs-sysfs.c | 2 +- drivers/ufs/core/ufshcd-priv.h | 1 - drivers/ufs/core/ufshcd.c | 6 ++++-- include/ufs/ufshcd.h | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c index c95906443d5f..a1554eac9bbc 100644 --- a/drivers/ufs/core/ufs-sysfs.c +++ b/drivers/ufs/core/ufs-sysfs.c @@ -203,7 +203,7 @@ static ssize_t auto_hibern8_store(struct device *dev, goto out; } - ufshcd_auto_hibern8_update(hba, ufshcd_us_to_ahit(timer)); + ret = ufshcd_auto_hibern8_update(hba, ufshcd_us_to_ahit(timer)); out: up(&hba->host_sem); diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h index f42d99ce5bf1..de8e891da36a 100644 --- a/drivers/ufs/core/ufshcd-priv.h +++ b/drivers/ufs/core/ufshcd-priv.h @@ -60,7 +60,6 @@ int ufshcd_query_attr(struct ufs_hba *hba, enum query_opcode opcode, enum attr_idn idn, u8 index, u8 selector, u32 *attr_val); int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, enum flag_idn idn, u8 index, bool *flag_res); -void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit); void ufshcd_compl_one_cqe(struct ufs_hba *hba, int task_tag, struct cq_entry *cqe); int ufshcd_mcq_init(struct ufs_hba *hba); diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 38e79ce05545..d3718fbe51b9 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -4313,13 +4313,13 @@ static void ufshcd_configure_auto_hibern8(struct ufs_hba *hba) ufshcd_writel(hba, hba->ahit, REG_AUTO_HIBERNATE_IDLE_TIMER); } -void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) +int ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) { unsigned long flags; bool update = false; if (!ufshcd_is_auto_hibern8_supported(hba)) - return; + return 0; spin_lock_irqsave(hba->host->host_lock, flags); if (hba->ahit != ahit) { @@ -4336,6 +4336,8 @@ void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) ufshcd_release(hba); ufshcd_rpm_put_sync(hba); } + + return 0; } EXPORT_SYMBOL_GPL(ufshcd_auto_hibern8_update); diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index fceef91d186e..8fd95a5d5538 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1356,7 +1356,7 @@ static inline int ufshcd_disable_host_tx_lcc(struct ufs_hba *hba) return ufshcd_dme_set(hba, UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE), 0); } -void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit); +int ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit); void ufshcd_fixup_dev_quirks(struct ufs_hba *hba, const struct ufs_dev_quirk *fixups); #define SD_ASCII_STD true From patchwork Mon Oct 23 21:54: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: 737739 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 8E914C25B49 for ; Mon, 23 Oct 2023 21:58:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233641AbjJWV6P (ORCPT ); Mon, 23 Oct 2023 17:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233546AbjJWV6O (ORCPT ); Mon, 23 Oct 2023 17:58:14 -0400 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E6E810C; Mon, 23 Oct 2023 14:58:13 -0700 (PDT) Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-27d0e3d823fso2475309a91.1; Mon, 23 Oct 2023 14:58:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098292; x=1698703092; 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=BSMTtopnpnoVFRhHmUt+zlCmNcQ7/eLzIQS1hLfLLj0=; b=EKU8qibpePZhCEjMnIwJqpIDysuOJhuowpR2GuY9RVopt60XEpUKA+vdQS/x3dUa1X HFaVHEcASJQfL/4dwtnOhfYDNeqJSPlYJN237Cmxy6gTwnECXLu6alR5yXIws2DPTiDG UQpKoAL46uElTtumjfFSYXi01lQe5egE3tVhCSd9/lv3tC68z+qwDbQbbLwiAbOP3KF/ +t+ZrzjRqd2Ee2sGTCbP/RlW3Z/u6TV1K7Nu/gSZg9a8FXhBnuBzrOohX8CtcPppIJuV iIOV/ly37S0BV28RC3c6J7NEgaHN2dStcfnOX0f8slxuVUJQsLuFYh0DlrnppHuMx6tk gyCQ== X-Gm-Message-State: AOJu0YyeJtYedYIZgD8jRSYWBn6Z8K6pvB53BURnnPNJyZkGaREHYnOZ 3t8SLCE3quEd91v0P0G+AAY= X-Google-Smtp-Source: AGHT+IEwAJvhCcCxXwyfbALfHfqywFwwS4Tx58BIVtxt9V7KlwNwZY2Os1PvmqoQ5Au7rtdq2w5A/A== X-Received: by 2002:a17:90a:e008:b0:27d:58a8:fa7f with SMTP id u8-20020a17090ae00800b0027d58a8fa7fmr9161361pjy.37.1698098292431; Mon, 23 Oct 2023 14:58:12 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:58:12 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , "Bao D . Nguyen" , Can Guo , Avri Altman , "James E.J. Bottomley" , Stanley Chu , Manivannan Sadhasivam , Asutosh Das , Bean Huo , Arthur Simchaev Subject: [PATCH v14 17/19] scsi: ufs: Simplify ufshcd_auto_hibern8_update() Date: Mon, 23 Oct 2023 14:54:08 -0700 Message-ID: <20231023215638.3405959-18-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Calls to ufshcd_auto_hibern8_update() are already serialized: this function is either called if user space software is not running (preparing to suspend) or from a single sysfs store callback function. Kernfs serializes sysfs .store() callbacks. No functionality is changed. This patch makes the next patch in this series easier to read. Reviewed-by: Bao D. Nguyen Reviewed-by: Can Guo Cc: Martin K. Petersen Cc: Avri Altman Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index d3718fbe51b9..3fc33794ce1f 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -4315,21 +4315,13 @@ static void ufshcd_configure_auto_hibern8(struct ufs_hba *hba) int ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) { - unsigned long flags; - bool update = false; + const u32 cur_ahit = READ_ONCE(hba->ahit); - if (!ufshcd_is_auto_hibern8_supported(hba)) + if (!ufshcd_is_auto_hibern8_supported(hba) || cur_ahit == ahit) return 0; - spin_lock_irqsave(hba->host->host_lock, flags); - if (hba->ahit != ahit) { - hba->ahit = ahit; - update = true; - } - spin_unlock_irqrestore(hba->host->host_lock, flags); - - if (update && - !pm_runtime_suspended(&hba->ufs_device_wlun->sdev_gendev)) { + WRITE_ONCE(hba->ahit, ahit); + if (!pm_runtime_suspended(&hba->ufs_device_wlun->sdev_gendev)) { ufshcd_rpm_get_sync(hba); ufshcd_hold(hba); ufshcd_configure_auto_hibern8(hba); From patchwork Mon Oct 23 21:54: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: 737465 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 65374C00A8F for ; Mon, 23 Oct 2023 21:58:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233707AbjJWV60 (ORCPT ); Mon, 23 Oct 2023 17:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233678AbjJWV6X (ORCPT ); Mon, 23 Oct 2023 17:58:23 -0400 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF5B310D8; Mon, 23 Oct 2023 14:58:20 -0700 (PDT) Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-5aa7fdd1420so2133760a12.3; Mon, 23 Oct 2023 14:58:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698098300; x=1698703100; 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=MaWb7DT0DEjxXHAAOV/ImKft4gO+Lr1J7bQB17+rCQ0=; b=V+SzVXWyTh4cnKlvgrf8c9y/kaq3ANXZ9lclhfEHQ67HbGqiLLuR62FSyQWp7SRM/G qz0jE+ZqzEqy3bCaxQrS7NDGaSHVP76pdatlPcUNAtPwAXZraleBoBDniv82dCmtc93o P7+Pzfhvt+QHUqAGTnSnNicJ776ipF5zo6Ln3rrxQLLdlatLqLBgIyEToutgvX/oURhu 1rz3n0jOiBVp6bNfyi2fiWurIimXVQQQdSX6bbGJ5twaS1DJ5a2KBg7bk2HHHhO3rWtL xkjL0sVhLD8df/GuZA9Bn5LCXldwIU5+JPnudU6SKtzzUF5F4LS5A2cUuEyaoEQ+KgtL undg== X-Gm-Message-State: AOJu0YwlogkqdXvTgfdJNpd+ONJ+UAcZLKB3Ddk17XnolO+cbgOa08Lt 1Ex38umBruViTShFA5b3xAI= X-Google-Smtp-Source: AGHT+IE6esnJMDrUyM3z+ybJewbiE++YW5zP7Yud7ZMukUM2bxcXuoRBeKlrhliMt8CpIUCcL2IVyA== X-Received: by 2002:a05:6a20:e123:b0:13d:2f80:cf1c with SMTP id kr35-20020a056a20e12300b0013d2f80cf1cmr1074461pzb.17.1698098300070; Mon, 23 Oct 2023 14:58:20 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:14f9:170e:9304:1c4e]) by smtp.gmail.com with ESMTPSA id b12-20020a17090acc0c00b0027d12b1e29dsm7851029pju.25.2023.10.23.14.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:58:19 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Bart Van Assche , "Bao D . Nguyen" , Can Guo , Avri Altman , "James E.J. Bottomley" , Stanley Chu , Manivannan Sadhasivam , Asutosh Das , Bean Huo , Arthur Simchaev Subject: [PATCH v14 18/19] scsi: ufs: Forbid auto-hibernation without I/O scheduler Date: Mon, 23 Oct 2023 14:54:09 -0700 Message-ID: <20231023215638.3405959-19-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231023215638.3405959-1-bvanassche@acm.org> References: <20231023215638.3405959-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org UFSHCI controllers in legacy mode do not preserve the write order if auto-hibernation is enabled. If the write order is not preserved, an I/O scheduler is required to serialize zoned writes. Hence do not allow auto-hibernation to be enabled without I/O scheduler if a zoned logical unit is present and if the controller is operating in legacy mode. This patch has been tested with the following shell script: show_ah8() { echo -n "auto_hibern8: " adb shell "cat /sys/devices/platform/13200000.ufs/auto_hibern8" } set_ah8() { local rc adb shell "echo $1 > /sys/devices/platform/13200000.ufs/auto_hibern8" rc=$? show_ah8 return $rc } set_iosched() { adb shell "echo $1 >/sys/class/block/$zoned_bdev/queue/scheduler && echo -n 'I/O scheduler: ' && cat /sys/class/block/sde/queue/scheduler" } adb root zoned_bdev=$(adb shell grep -lvw 0 /sys/class/block/sd*/queue/chunk_sectors |& sed 's|/sys/class/block/||g;s|/queue/chunk_sectors||g') [ -n "$zoned_bdev" ] show_ah8 set_ah8 0 set_iosched none if set_ah8 150000; then echo "Error: enabled AH8 without I/O scheduler" fi set_iosched mq-deadline set_ah8 150000 Reviewed-by: Bao D. Nguyen Reviewed-by: Can Guo Cc: Martin K. Petersen Cc: Avri Altman Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 3fc33794ce1f..0a21ea9d7576 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -4305,6 +4305,30 @@ int ufshcd_uic_hibern8_exit(struct ufs_hba *hba) } EXPORT_SYMBOL_GPL(ufshcd_uic_hibern8_exit); +static int ufshcd_update_preserves_write_order(struct ufs_hba *hba, + bool preserves_write_order) +{ + struct scsi_device *sdev; + + if (!preserves_write_order) { + shost_for_each_device(sdev, hba->host) { + struct request_queue *q = sdev->request_queue; + + /* + * Refuse to enable auto-hibernation if no I/O scheduler + * is present. This code does not check whether the + * attached I/O scheduler serializes zoned writes + * (ELEVATOR_F_ZBD_SEQ_WRITE) because this cannot be + * checked from outside the block layer core. + */ + if (blk_queue_is_zoned(q) && !q->elevator) + return -EPERM; + } + } + + return 0; +} + static void ufshcd_configure_auto_hibern8(struct ufs_hba *hba) { if (!ufshcd_is_auto_hibern8_supported(hba)) @@ -4313,13 +4337,42 @@ static void ufshcd_configure_auto_hibern8(struct ufs_hba *hba) ufshcd_writel(hba, hba->ahit, REG_AUTO_HIBERNATE_IDLE_TIMER); } +/** + * ufshcd_auto_hibern8_update() - Modify the auto-hibernation control register + * @hba: per-adapter instance + * @ahit: New auto-hibernate settings. Includes the scale and the value of the + * auto-hibernation timer. See also the UFSHCI_AHIBERN8_TIMER_MASK and + * UFSHCI_AHIBERN8_SCALE_MASK constants. + * + * Notes: + * - UFSHCI controllers do not preserve the command order in legacy mode + * if auto-hibernation is enabled. If the command order is not preserved, an + * I/O scheduler that serializes zoned writes (mq-deadline) is required if a + * zoned logical unit is present. Enabling auto-hibernation without attaching + * the mq-deadline scheduler first may cause unaligned write errors for the + * zoned logical unit if a zoned logical unit is present. + * - Calls of this function must be serialized. + */ int ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) { const u32 cur_ahit = READ_ONCE(hba->ahit); + bool prev_state, new_state; + int ret; if (!ufshcd_is_auto_hibern8_supported(hba) || cur_ahit == ahit) return 0; + prev_state = FIELD_GET(UFSHCI_AHIBERN8_TIMER_MASK, cur_ahit); + new_state = FIELD_GET(UFSHCI_AHIBERN8_TIMER_MASK, ahit); + + if (!is_mcq_enabled(hba) && !prev_state && new_state) { + /* + * Auto-hibernation will be enabled for legacy UFSHCI mode. + */ + ret = ufshcd_update_preserves_write_order(hba, false); + if (ret) + return ret; + } WRITE_ONCE(hba->ahit, ahit); if (!pm_runtime_suspended(&hba->ufs_device_wlun->sdev_gendev)) { ufshcd_rpm_get_sync(hba); @@ -4328,6 +4381,13 @@ int ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) ufshcd_release(hba); ufshcd_rpm_put_sync(hba); } + if (!is_mcq_enabled(hba) && prev_state && !new_state) { + /* + * Auto-hibernation has been disabled. + */ + ret = ufshcd_update_preserves_write_order(hba, true); + WARN_ON_ONCE(ret); + } return 0; }