From patchwork Fri Aug 11 21:35:35 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: 713140 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 71C1DC001B0 for ; Fri, 11 Aug 2023 21:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236942AbjHKVgL (ORCPT ); Fri, 11 Aug 2023 17:36:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236570AbjHKVgK (ORCPT ); Fri, 11 Aug 2023 17:36:10 -0400 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C36A268C; Fri, 11 Aug 2023 14:36:10 -0700 (PDT) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1bc6535027aso21041525ad.2; Fri, 11 Aug 2023 14:36:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691789770; x=1692394570; 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=5q+IWn4ek8qUOXLGwDyPCO3ru0XE1sUcjJbkQBMhNLw=; b=ZaIIDwXeIsbv+IUo5n0beD0WJXpr8yxnJwVv3HAIotlZmVRzDnIL1zkczFBk+itORj 7dYzDhDXuQriNrAlRYnvcfDR8MTnQ5JDwKOBg4GHPwEGo8irdMv6flD3u9fdWTjKVkVF TEJ5p1guy6UDAG3k6AZhxQScdXH0TnXF8QRboKT2c/tcRLXPlf1jEa7SkaKy7gCPvOXm WcZ0tjv/ao1m+SHtDsAd9+yQKiRv0HvEXW6NmWqG55iZkr4xEDQuUo0ezGFUKqbzw76b E6YdQ6quwvcI5PpFh4XACKnWtoh8T+yvDE0If1SfSNIVFPb/S05nPXi9c1E3bwOma+A1 5vfg== X-Gm-Message-State: AOJu0YzV9aJ74nNFiMzu1vhNZlcter5cDumTNFhonUiFbVgEJNmiBJUy Tg7z/lhx6f5vdNXJCrpz6sA= X-Google-Smtp-Source: AGHT+IGnGNkoTePbWqEwM7nJ7yC2s8Nxe0/3+t1aL4MSTt59xW0qm39OplLw8wQpXtVYWfxUnTm20A== X-Received: by 2002:a17:902:f68d:b0:1bc:14f0:b76c with SMTP id l13-20020a170902f68d00b001bc14f0b76cmr3398899plg.65.1691789769789; Fri, 11 Aug 2023 14:36:09 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:cdd8:4c3:2f3c:adea]) by smtp.gmail.com with ESMTPSA id c10-20020a170903234a00b001b89c313185sm4394865plh.205.2023.08.11.14.36.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 14:36:09 -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 Subject: [PATCH v8 1/9] block: Introduce more member variables related to zone write locking Date: Fri, 11 Aug 2023 14:35:35 -0700 Message-ID: <20230811213604.548235-2-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230811213604.548235-1-bvanassche@acm.org> References: <20230811213604.548235-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 a new request queue limit member variable (driver_preserves_write_order) that allows block drivers to indicate that the order of write commands is preserved and hence that serialization of writes per zone is not required. Make disk_set_zoned() set 'use_zone_write_lock' only if the block device has zones and if the block driver does not preserve the order of write requests. Cc: Damien Le Moal Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- block/blk-settings.c | 7 +++++++ include/linux/blkdev.h | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/block/blk-settings.c b/block/blk-settings.c index 0046b447268f..3a7748af1bef 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; @@ -685,6 +687,9 @@ 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); + /* Request-based stacking drivers do not reorder requests. */ + t->driver_preserves_write_order = b->driver_preserves_write_order; + t->use_zone_write_lock = b->use_zone_write_lock; t->zoned = max(t->zoned, b->zoned); return ret; } @@ -949,6 +954,8 @@ void disk_set_zoned(struct gendisk *disk, enum blk_zoned_model model) } q->limits.zoned = model; + 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/include/linux/blkdev.h b/include/linux/blkdev.h index 2f5371b8482c..2c090a28ec78 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 Fri Aug 11 21:35:36 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: 713243 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 CA148C0015E for ; Fri, 11 Aug 2023 21:36:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236962AbjHKVgQ (ORCPT ); Fri, 11 Aug 2023 17:36:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236948AbjHKVgM (ORCPT ); Fri, 11 Aug 2023 17:36:12 -0400 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E592213F; Fri, 11 Aug 2023 14:36:11 -0700 (PDT) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1bdbbede5d4so7499025ad.2; Fri, 11 Aug 2023 14:36:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691789771; x=1692394571; 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=n06oYeoYQM0v3vn2nA9IswRTL3X/Y5HU1qarWU54XEo=; b=TvAW2jrG5Yj2uV6KCM50EeSiuani/rjhPPa8he1XJaisIc20s4NeOjx+mkNSkb11ld vDDUcYv3kiDYeN/lr4d7qsFsKhh1xvJaW+lXvqThXkrKpYJJTHWvhsnN97acsVTbmMhi +L4qGkv0WAbVQa3NQver/45VnNGsX2UrYc7v4AAWeyi6OZs0dceZvcJiozTWN8SF2Byi kVibm3vX1NogzxTQWuLruMIEJ7x2T7w7NgzrqD20SJDV/wcAj6GYz1ep+JLwdiihrjNz NgxY24Ak+TQzQ3LfwALN0WJW6VHcu1yy4qgWYa/kmZfAzS0M/26BuhySmfDvqeZR8yX1 q/jQ== X-Gm-Message-State: AOJu0YzTNDtrnKKA6HdyzLw83lG2TXTlVwo0f+zA/Ikch6TImTdi7epq nJ14+9AfqeHffcsViDnTm8Q= X-Google-Smtp-Source: AGHT+IE53t3cLEXbln8ILW+YTdF+jl3iSJDR/tcOotTM+KJ2FcaMUy2kmC1ywmCI41q6a0YY/SEyUg== X-Received: by 2002:a17:903:444:b0:1b8:53b5:8518 with SMTP id iw4-20020a170903044400b001b853b58518mr2829779plb.63.1691789770961; Fri, 11 Aug 2023 14:36:10 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:cdd8:4c3:2f3c:adea]) by smtp.gmail.com with ESMTPSA id c10-20020a170903234a00b001b89c313185sm4394865plh.205.2023.08.11.14.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 14:36:10 -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 Subject: [PATCH v8 2/9] block/mq-deadline: Only use zone locking if necessary Date: Fri, 11 Aug 2023 14:35:36 -0700 Message-ID: <20230811213604.548235-3-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230811213604.548235-1-bvanassche@acm.org> References: <20230811213604.548235-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. Cc: Damien Le Moal Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- block/mq-deadline.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/block/mq-deadline.c b/block/mq-deadline.c index f958e79277b8..5c2fc4003bc0 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; @@ -552,7 +553,8 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd, /* * If the request needs its target zone locked, do it. */ - blk_req_zone_write_lock(rq); + if (rq->q->limits.use_zone_write_lock) + blk_req_zone_write_lock(rq); rq->rq_flags |= RQF_STARTED; return rq; } @@ -934,7 +936,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 Fri Aug 11 21:35:37 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: 713139 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 1322BC0015E for ; Fri, 11 Aug 2023 21:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236949AbjHKVgU (ORCPT ); Fri, 11 Aug 2023 17:36:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236452AbjHKVgT (ORCPT ); Fri, 11 Aug 2023 17:36:19 -0400 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9065B2684; Fri, 11 Aug 2023 14:36:18 -0700 (PDT) Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1bc8045e09dso18139305ad.0; Fri, 11 Aug 2023 14:36:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691789778; x=1692394578; 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=VejU/kV71hFZ1/4fu0TIDkfHCBIfE8lpTp30B2bYt/c=; b=Wdq+6oNbkeBtBHaJVftwHBs/Aa41Eb5gyITAwt8B3gmbg3upjfBxWz1gZrax0Ci+si TySDfRCeea3Zh9oNIyxbvebLUZsnjUFu2Goc3uwNIxA4kWfdMra5l9Fw7v6FPlI2IhIT YoX5gLBa5ZVzcO35Tw1DC8J1Q3cRGWpC78pa5m98h+D7LXBqmj4x2R7iKV4S/SNb6nEW cb/hgXSy3Upde4P4E8cESG3Y6/PJYfOtu+dcIPdMdjJhb0fsnFHTo3JE5B3yhpZj3Ene HOARnLIIWe5kgkS/fazhxzOnsg6TAaP59PUSRCmr4prnX5GFEX9iQAwzlGx4RpeJMlTg mzsQ== X-Gm-Message-State: AOJu0YyxnbZ3JIzLwGKdjQogUet8yIT1/cGz3WDZG+0/JEsjnSMXOPv+ mvZRhrHPW9x0eWCRBcAhyQc= X-Google-Smtp-Source: AGHT+IHs3Q18FSrv8FFeF9SEcE57+rV8IYmFvxLSxTlFa2KQNn/9UHl/VJTRDyeDtg6e2uIuG2BnOA== X-Received: by 2002:a17:902:f7ce:b0:1bd:b05c:c752 with SMTP id h14-20020a170902f7ce00b001bdb05cc752mr2783107plw.26.1691789777931; Fri, 11 Aug 2023 14:36:17 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:cdd8:4c3:2f3c:adea]) by smtp.gmail.com with ESMTPSA id c10-20020a170903234a00b001b89c313185sm4394865plh.205.2023.08.11.14.36.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 14:36: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 v8 3/9] scsi: core: Call .eh_prepare_resubmit() before resubmitting Date: Fri, 11 Aug 2023 14:35:37 -0700 Message-ID: <20230811213604.548235-4-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230811213604.548235-1-bvanassche@acm.org> References: <20230811213604.548235-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Make the error handler call .eh_prepare_resubmit() before resubmitting commands. A later patch will use this functionality to sort SCSI commands per LBA from inside the SCSI disk driver. 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 | 43 ++++++++++++++++ drivers/scsi/scsi_error_test.c | 92 ++++++++++++++++++++++++++++++++++ drivers/scsi/scsi_priv.h | 1 + include/scsi/scsi_driver.h | 1 + 8 files changed, 146 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 4962ce989113..fc288f8fb800 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..68e3d90d49e9 --- /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_MOD && 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 c67cdcdc3ba8..0d7835bdc8af 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,46 @@ void scsi_eh_ready_devs(struct Scsi_Host *shost, } EXPORT_SYMBOL_GPL(scsi_eh_ready_devs); +/* + * Comparison function that allows to sort 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 list_head *done_q) +{ + struct scsi_cmnd *scmd, *next; + + /* 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 = scsi_cmd_to_driver(scmd); + 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. * @done_q: list_head of processed commands. @@ -2194,6 +2235,8 @@ void scsi_eh_flush_done_q(struct list_head *done_q) { struct scsi_cmnd *scmd, *next; + scsi_call_prepare_resubmit(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_error_test.c b/drivers/scsi/scsi_error_test.c new file mode 100644 index 000000000000..fd616527f726 --- /dev/null +++ b/drivers/scsi/scsi_error_test.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2023 Google LLC + */ +#include +#include +#include +#include "scsi_priv.h" + +static struct kunit *kunit_test; + +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_resubmit(struct kunit *test) +{ + static struct scsi_cmnd cmd1, cmd2, cmd3, cmd4, cmd5, cmd6; + static struct scsi_device dev1, dev2, dev3; + struct scsi_driver *uld; + LIST_HEAD(cmd_list); + + 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]; + dev1.sdev_gendev.driver = &uld1->gendrv; + dev2.sdev_gendev.driver = &uld2->gendrv; + dev3.sdev_gendev.driver = &uld3->gendrv; + cmd1.device = &dev1; + cmd2.device = &dev1; + cmd3.device = &dev2; + cmd4.device = &dev2; + cmd5.device = &dev3; + cmd6.device = &dev3; + list_add_tail(&cmd1.eh_entry, &cmd_list); + list_add_tail(&cmd3.eh_entry, &cmd_list); + list_add_tail(&cmd5.eh_entry, &cmd_list); + list_add_tail(&cmd2.eh_entry, &cmd_list); + list_add_tail(&cmd4.eh_entry, &cmd_list); + list_add_tail(&cmd6.eh_entry, &cmd_list); + + KUNIT_EXPECT_EQ(test, list_count_nodes(&cmd_list), 6); + kunit_test = test; + scsi_call_prepare_resubmit(&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.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next, &cmd2.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next->next, &cmd3.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next->next->next, + &cmd4.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next->next->next->next, + &cmd5.eh_entry); + KUNIT_EXPECT_PTR_EQ(test, cmd_list.next->next->next->next->next->next, + &cmd6.eh_entry); + kfree(uld); +} + +static struct kunit_case prepare_resubmit_test_cases[] = { + KUNIT_CASE(test_prepare_resubmit), + {} +}; + +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_AUTHOR("Bart Van Assche"); +MODULE_LICENSE("GPL"); diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index f42388ecb024..df4af4645430 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -101,6 +101,7 @@ 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 list_head *done_q); /* scsi_lib.c */ extern int scsi_maybe_unblock_host(struct scsi_device *sdev); 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) From patchwork Fri Aug 11 21:35:38 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: 713242 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 E0FB7C04A94 for ; Fri, 11 Aug 2023 21:36:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236047AbjHKVgV (ORCPT ); Fri, 11 Aug 2023 17:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236570AbjHKVgU (ORCPT ); Fri, 11 Aug 2023 17:36:20 -0400 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD81F213F; Fri, 11 Aug 2023 14:36:19 -0700 (PDT) Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-68706b39c4cso1883867b3a.2; Fri, 11 Aug 2023 14:36:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691789779; x=1692394579; 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=0MTRiIPOGKG6b+x9b42B4xdETbTVAE/EoHB9M4Iemm0=; b=EhWWUg+5j6P4IEryBdxDw3/wvtPoMpmDFgeCNUp0bJjKNiQiIcBcPGJFHkG2j+EiNL EkiAU+bQZ1q0N6g5fiTIfVayw6XgOyUh4ayB/t3w6sqckBXey3l/zBaUuQ50/xEZwXED xVl1wrbZSsBKYj9YAri9WqOUWJD/6TPM1QhpqnLV/4Bt13LmEtG46EkEUxrVYoqktZZb TDdl/IF+iyNdX6O2U8MrkwzqwFHbTbC1N6xAF/4hOd4egBnHh1sT3IsH2/AmNU4akioO 0MkS/bFgAZSOSrTPFsM11o2tys2zkwRsXKMNRmhblM6KDRo3mw7TEe0/wPzcGX0TsUsQ ZVcg== X-Gm-Message-State: AOJu0Yy6hAiB3/9SetCcyh3CFTsaqLG7hi4nT22pmauH7j3M1RAyeRl1 dH/I2sDsxZA7+Lzok5y1FiY= X-Google-Smtp-Source: AGHT+IH6thqQ6Vhm5jL5/oI97dSKkYiE6b7IUoHLeuLaf99nXleZcKqX7SRd4ex5zgkMQ6j1qsjyhA== X-Received: by 2002:a17:902:9a06:b0:1bb:673f:36ae with SMTP id v6-20020a1709029a0600b001bb673f36aemr2316144plp.15.1691789779158; Fri, 11 Aug 2023 14:36:19 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:cdd8:4c3:2f3c:adea]) by smtp.gmail.com with ESMTPSA id c10-20020a170903234a00b001b89c313185sm4394865plh.205.2023.08.11.14.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 14:36: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 , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v8 4/9] scsi: sd: Sort commands by LBA before resubmitting Date: Fri, 11 Aug 2023 14:35:38 -0700 Message-ID: <20230811213604.548235-5-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230811213604.548235-1-bvanassche@acm.org> References: <20230811213604.548235-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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 3c668cfb146d..4d9c6ad11cca 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -117,6 +118,7 @@ static void sd_uninit_command(struct scsi_cmnd *SCpnt); static int sd_done(struct scsi_cmnd *); static void sd_eh_reset(struct scsi_cmnd *); static int sd_eh_action(struct scsi_cmnd *, int); +static void sd_prepare_resubmit(struct list_head *cmd_list); static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer); static void scsi_disk_release(struct device *cdev); @@ -617,6 +619,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, }; /* @@ -2018,6 +2021,26 @@ 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); + + /* See also the comment above the list_sort() definition. */ + return blk_rq_pos(scsi_cmd_to_rq(a)) > blk_rq_pos(scsi_cmd_to_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); From patchwork Fri Aug 11 21:35:39 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: 713138 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 555ABC04A6A for ; Fri, 11 Aug 2023 21:36:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236570AbjHKVg1 (ORCPT ); Fri, 11 Aug 2023 17:36:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbjHKVgV (ORCPT ); Fri, 11 Aug 2023 17:36:21 -0400 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F098213B; Fri, 11 Aug 2023 14:36:21 -0700 (PDT) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1bc7b25c699so17823455ad.1; Fri, 11 Aug 2023 14:36:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691789780; x=1692394580; 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=c/fuXfOdSDw5mvrnZplxrJ6YdhO/1ZNBN3hPGAXmYZQ=; b=WMPuFPgH8QBL8zMt1HCXO+BlB2yqTul8Pr3DHAPX3ZqQVHVsatFY0FfYNrcBXYFHlR I7lWJ6+unGHcGjvUh7EN5bgVyc0OaK5W+vXPod8dMUKW3CEAO2J6jKg6BDPtMoXJ0v57 zyLPXKc54JLN168Jh0j5qz3J5Q1NeOELW0CYVa/7DrRNbqDBihBYHGnwD9eJzh3Gy3dF 0t7iBpUE4Qu3qquG1wYvwKv1UdX03qQX2cEm4MYE1P2lEhm/+pn4/KI2LlUorWKTcf7w R/0JGaGon1/7XyhpEVoNY3zIyiitkEpTVhdliRB8Gd51kfvzCzF+pgZcfq1zZl4XGAH6 XetA== X-Gm-Message-State: AOJu0Yx09xbPMznhy38PwxBNqqtLrDlwoEN2SaDbTczWdWN+XLnA4lJn MBx6N6HpI5djudJEgBYlRnz9+gMFa8s= X-Google-Smtp-Source: AGHT+IFfqwsDTejz+GQD4x/v4VHoXmp7UFlBLrGDsmMZXY0arnCcmTnqcF94Umet/p50t9DJz2UC5w== X-Received: by 2002:a17:903:181:b0:1bd:b8c8:98fc with SMTP id z1-20020a170903018100b001bdb8c898fcmr3004721plg.14.1691789780521; Fri, 11 Aug 2023 14:36:20 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:cdd8:4c3:2f3c:adea]) by smtp.gmail.com with ESMTPSA id c10-20020a170903234a00b001b89c313185sm4394865plh.205.2023.08.11.14.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 14:36: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 , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v8 5/9] scsi: core: Retry unaligned zoned writes Date: Fri, 11 Aug 2023 14:35:39 -0700 Message-ID: <20230811213604.548235-6-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230811213604.548235-1-bvanassche@acm.org> References: <20230811213604.548235-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. Let the SCSI error handler 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. Cc: Martin K. Petersen Cc: Damien Le Moal 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 | 2 ++ include/scsi/scsi.h | 1 + 4 files changed, 20 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 0d7835bdc8af..7ae43fac07b7 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)) { + SCSI_LOG_ERROR_RECOVERY(3, + 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 59176946ab56..69da8aee13df 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 4d9c6ad11cca..c8466c6c7387 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1238,6 +1238,8 @@ 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; + 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 Fri Aug 11 21:35:40 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: 713241 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 6AE1CC04A94 for ; Fri, 11 Aug 2023 21:36:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236967AbjHKVg1 (ORCPT ); Fri, 11 Aug 2023 17:36:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236953AbjHKVgW (ORCPT ); Fri, 11 Aug 2023 17:36:22 -0400 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 678BB2684; Fri, 11 Aug 2023 14:36:22 -0700 (PDT) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1bc34b32785so17987205ad.3; Fri, 11 Aug 2023 14:36:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691789782; x=1692394582; 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=f1sJsHjb25Up82wy0+rLFEE09ikEWVEcaOgckYbsEWo=; b=ce7RHME4s/VP9AWSKWT+EUFev5PealTv5akMS69gkdmon1cTTo2FR1bWdXtoUV0zBo GCioN4K+IMeFJHtD50r7YD5b1on6fHV9/8AavcxsyBdmWEMSbjghDWSXp24OCAbjiV43 ALQroklZLiO7g4pq8cyvWrOcZBWe+1169gJKc0MkuAO5O7wEmRmqrxYzTy08PH/SV3mD zvtfoXGe8jX9Swuz/AfUrQLwK06DPhyVOa7+5VXCevAB9HY58tXthhovccmrlXpGOi6j iBLEgUL6x0DMWoW25RSNLWXmNmNewdeySyVGvBAxmYmx30v3A2OD3dPP+iz1COroTf2o zHoA== X-Gm-Message-State: AOJu0Yzcu3p3MfL60IjFY85bmXIxfJ2jg2nd764JFItHu6st+G5CKDPc TuVbTsKylm0RyQ2ViTyGvns2cCwq928= X-Google-Smtp-Source: AGHT+IG8c4wGJtGRdc1Rjch42EG34wEZInEi1sxfwXp9Xv05f/OHlhxQDfJ2e4tcBd6Te7BSleLTmA== X-Received: by 2002:a17:902:9009:b0:1bb:f1d9:432e with SMTP id a9-20020a170902900900b001bbf1d9432emr2637854plp.37.1691789781787; Fri, 11 Aug 2023 14:36:21 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:cdd8:4c3:2f3c:adea]) by smtp.gmail.com with ESMTPSA id c10-20020a170903234a00b001b89c313185sm4394865plh.205.2023.08.11.14.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 14:36:21 -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 v8 6/9] scsi: scsi_debug: Support disabling zone write locking Date: Fri, 11 Aug 2023 14:35:40 -0700 Message-ID: <20230811213604.548235-7-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230811213604.548235-1-bvanassche@acm.org> References: <20230811213604.548235-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 not using zone write locking by supporting disabling zone write locking in the scsi_debug driver. Cc: Martin K. Petersen Cc: Douglas Gilbert Cc: Damien Le Moal Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 9c0af50501f9..c44c523bde2c 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_no_zwrl; 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_no_zwrl) + q->limits.driver_preserves_write_order = true; return 0; } @@ -5738,6 +5743,7 @@ module_param_named(ndelay, sdebug_ndelay, int, S_IRUGO | S_IWUSR); module_param_named(no_lun_0, sdebug_no_lun_0, int, S_IRUGO | S_IWUSR); module_param_named(no_rwlock, sdebug_no_rwlock, bool, S_IRUGO | S_IWUSR); module_param_named(no_uld, sdebug_no_uld, int, S_IRUGO); +module_param_named(no_zone_write_lock, sdeb_no_zwrl, bool, S_IRUGO); module_param_named(num_parts, sdebug_num_parts, int, S_IRUGO); module_param_named(num_tgts, sdebug_num_tgts, int, S_IRUGO | S_IWUSR); module_param_named(opt_blks, sdebug_opt_blks, int, S_IRUGO); @@ -5812,6 +5818,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(no_zone_write_lock, + "Disable serialization of zoned writes (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 Fri Aug 11 21:35:41 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: 713137 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 864F1C04E69 for ; Fri, 11 Aug 2023 21:36:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236959AbjHKVg3 (ORCPT ); Fri, 11 Aug 2023 17:36:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236958AbjHKVgX (ORCPT ); Fri, 11 Aug 2023 17:36:23 -0400 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A29DC271B; Fri, 11 Aug 2023 14:36:23 -0700 (PDT) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1bb84194bf3so16745755ad.3; Fri, 11 Aug 2023 14:36:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691789783; x=1692394583; 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=PniZFVm0KVVX2uS5WNDISfoYsmok7mUzRbqporfC4VQ=; b=MfKEE7oUjfrZZmAFYFwv/5WQFD9rbV1e13Oc6C+nyfY8Ia+/qw7GZKHaK+GUV4GMxO 3/5jjYch4kuRYicwJEBKIIc2icOvkx1XN4ZoxG/eCotuGBUPoIjrrWRDxmstIcU2Pizo x9DbnAvdo2gqgV+Wfd45d42hcIosvcRmourvUMCL3t/9600blJNm4qNy+YTdxWaSuUX0 Qa7Ww+ROblRPAGlt/jHFHJEVkedoD+CtLMBts2DNTwboykF8Pw60D+9WSfjWn6t7QBgX P24REJcMmR/EQ3GHjAdc0u4yK57WdFagtnk7UXC6YV36h4TcphSkVif2HLVNP7r3aP1E 9STw== X-Gm-Message-State: AOJu0Yx6RMYPBmEdEi6OWJ9Sivs9xI2J5vTEon+Fmic2Pqrsm/PKoDG3 S8QQY/EtxtW/vFzSYz3eTXI= X-Google-Smtp-Source: AGHT+IFD4hgcPG8C/LyricdK8OC2TRKTqSwUZLbW+EQX9HYgLUkVvaj4eixpYsDaHwJuJSm7yaOqsQ== X-Received: by 2002:a17:902:d4c6:b0:1b8:936f:c34d with SMTP id o6-20020a170902d4c600b001b8936fc34dmr3270015plg.27.1691789782986; Fri, 11 Aug 2023 14:36:22 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:cdd8:4c3:2f3c:adea]) by smtp.gmail.com with ESMTPSA id c10-20020a170903234a00b001b89c313185sm4394865plh.205.2023.08.11.14.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 14:36:22 -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 v8 7/9] scsi: scsi_debug: Support injecting unaligned write errors Date: Fri, 11 Aug 2023 14:35:41 -0700 Message-ID: <20230811213604.548235-8-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230811213604.548235-1-bvanassche@acm.org> References: <20230811213604.548235-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 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 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index c44c523bde2c..c92bd6d00249 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 Fri Aug 11 21:35:42 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: 713240 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 A403CC0015E for ; Fri, 11 Aug 2023 21:36:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236970AbjHKVgj (ORCPT ); Fri, 11 Aug 2023 17:36:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235778AbjHKVgh (ORCPT ); Fri, 11 Aug 2023 17:36:37 -0400 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38A37273E; Fri, 11 Aug 2023 14:36:31 -0700 (PDT) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1bbf8cb61aeso18058245ad.2; Fri, 11 Aug 2023 14:36:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691789791; x=1692394591; 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=/Ht/S5/IQaEQ/R/sr0BTkozacEwEufdvyDt4t1mhvhY=; b=Qd/DF5uUJENlQAq6JNhPwmHm9A00QvG4vPZabvnNCglqSs8cZiNJCxNnUr9DtJPpbC VL+UNH7qcf8HBAWCzrNKvJy6PwRXiZ5ERVziheICVEN5XCPOMl/G7v7FFyxYgQTLiXsa 3QMrVoe0yGhPguxgWuEPL5gfQha7g/OSaV/A5fS+Y3RbpcqhuTCr9WWG5v7AmuV45KK+ R5ujYbiMgwRQxIwTNB4BxKRMGsims8DEsFrDXyIIoKbBsfDKGKDWjTkg1s/SfyBaceGB DhpFX8wLzeTaQLSrazJXm13bURMqR5TL0o8Ns8j1+hJE64VXF1503LpgpxJutlmbY9bf 86ig== X-Gm-Message-State: AOJu0Yw9SK/BXGeuPBjwU6tWPZMmvuqHOlDAD6yDa7QY7ODo9C8PZwzP CVpoombxcixtsVbcSd1o08M= X-Google-Smtp-Source: AGHT+IGrohq1/jQlzRg4hcWKjYmERF7NLULiKTKhVGJtJ4WF1smTq76OcaO5hx5TK/lb6iXFe6Glsw== X-Received: by 2002:a17:902:ea0c:b0:1b8:b3f9:58e5 with SMTP id s12-20020a170902ea0c00b001b8b3f958e5mr3507061plg.38.1691789790655; Fri, 11 Aug 2023 14:36:30 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:cdd8:4c3:2f3c:adea]) by smtp.gmail.com with ESMTPSA id c10-20020a170903234a00b001b89c313185sm4394865plh.205.2023.08.11.14.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 14:36:30 -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 , Can Guo , Avri Altman , Damien Le Moal , Ming Lei , "James E.J. Bottomley" , Stanley Chu , Bean Huo , Asutosh Das , "Bao D. Nguyen" , Arthur Simchaev Subject: [PATCH v8 8/9] scsi: ufs: Split an if-condition Date: Fri, 11 Aug 2023 14:35:42 -0700 Message-ID: <20230811213604.548235-9-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230811213604.548235-1-bvanassche@acm.org> References: <20230811213604.548235-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Make the next patch in this series easier to read. No functionality is changed. Reviewed-by: Can Guo Cc: Martin K. Petersen Cc: Avri Altman Cc: Christoph Hellwig Cc: Damien Le Moal Cc: Ming Lei Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 129446775796..ae7b868f9c26 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -4352,8 +4352,9 @@ void ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) } spin_unlock_irqrestore(hba->host->host_lock, flags); - if (update && - !pm_runtime_suspended(&hba->ufs_device_wlun->sdev_gendev)) { + if (!update) + return; + if (!pm_runtime_suspended(&hba->ufs_device_wlun->sdev_gendev)) { ufshcd_rpm_get_sync(hba); ufshcd_hold(hba); ufshcd_auto_hibern8_enable(hba);