From patchwork Tue Nov 14 21:16: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: 13455979 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 9DFC6C41535 for ; Tue, 14 Nov 2023 21:18:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231617AbjKNVSR (ORCPT ); Tue, 14 Nov 2023 16:18:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbjKNVSQ (ORCPT ); Tue, 14 Nov 2023 16:18:16 -0500 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6E169D; Tue, 14 Nov 2023 13:18:13 -0800 (PST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1cc4f777ab9so47031725ad.0; Tue, 14 Nov 2023 13:18:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996693; x=1700601493; 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=0iDgtijbfSr5IQPF1PJVs/YOTy8FP7gUZQnGFONo3vA=; b=LHgN7hvwDdY4f66Vl7LAfUK6etOj7kRpmzREYoETp2L6X7Gltai6HDoRtHyEg2FeC7 I4cl94Z2FPzWlQSjS/Pxy0bdDfaRsP+XDqgROGcyhB3LeTOubH61bSoaNtJcGtYlmeqY tWmHboXJEINA6XMsGc7u/RVbhBgC5VYBA8TEvG0bjm80n1x09fJssG4xgjS64mmxIY4a HyYjqMmNQFeB09z/ccu8ORa25puecQ7GgetQTUerQPPRbvpxepqeSC4N8tjzk84WjdbI eTF3wnPrdN9OBi/7psTjs1rn/G3uzh2opuAa7hIhjv5B6Xgsx8Rd1MpQzvyfcR+e/odL 9BzA== X-Gm-Message-State: AOJu0YxbGSaqXXv4lXERgSlpdbi+7NScbw9Z/9v06RzF6w2gLZasiY8/ 6VHy0jri3SchbSRfoczNJ5U= X-Google-Smtp-Source: AGHT+IE7kkAMSflj5vy7ZLuFnrflrpiNamM6Gh7Lvi/UwSi/Ydp/VgaE+M6hmurKlkWCE3oz8JtenA== X-Received: by 2002:a17:902:c411:b0:1cc:59a1:79ae with SMTP id k17-20020a170902c41100b001cc59a179aemr366922plk.39.1699996693078; Tue, 14 Nov 2023 13:18:13 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:12 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Hannes Reinecke , Nitesh Shetty , Ming Lei Subject: [PATCH v15 01/19] block: Introduce more member variables related to zone write locking Date: Tue, 14 Nov 2023 13:16:09 -0800 Message-ID: <20231114211804.1449162-2-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 51fa7ffdee83..2d452f5a36c8 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 Tue Nov 14 21:16:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13455980 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 9EC7DC4332F for ; Tue, 14 Nov 2023 21:18:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232570AbjKNVSX (ORCPT ); Tue, 14 Nov 2023 16:18:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbjKNVSS (ORCPT ); Tue, 14 Nov 2023 16:18:18 -0500 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15558C4; Tue, 14 Nov 2023 13:18:15 -0800 (PST) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1ccbb7f79cdso46798365ad.3; Tue, 14 Nov 2023 13:18:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996694; x=1700601494; 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=oel4Kf7Y7WF07iqdKA85OqM7IXICtU2wzVvg+2gGSoc=; b=AtbLysGGoT8WbWUqkVBo3t1nYlef3cWrDRQx9m1SA8LdGVnCXBcNqn0zYtOkCH7LZr aCdCfTyiJsUWpEJCB11RMbbz4OShr43oieo/IKkdDxsPfeU3e7NL5E5Ty18T1CsZQ2o/ UmhpHHZ8oJUpb/IBxy9mfrk3zmCMatN0CTQZmKa/upSH0lbPtMBvJBuYInxUPD6xPrtB SQG+gv3oSUimQtJZuG2H0RJDgjL+S+NVflIB5KqFLAoIU4V4GPWQJVELEfxkItbIJm3M kaHyQfxKyAIjcQhLKAf/cqT1sI2XtqSHgLYSrvNpg94cxO/E/dAGkt0sZw0ONP4Zm9Ny H53Q== X-Gm-Message-State: AOJu0YwAtyitZh3Tq2KBa9skMmJYMpZ4+Lg6vgpz1TR5q9KvsfhuG8tH Rv6fUAslEES/CHLSbnZgw7s= X-Google-Smtp-Source: AGHT+IFa1bH/vGYxgfH/S0jrHh8ritrazrtDwJ1JAyog6EHCLtrlbM7nZ5eUjMSq5lzZbcdhy8RT3w== X-Received: by 2002:a17:902:6acb:b0:1cc:6acc:8fa0 with SMTP id i11-20020a1709026acb00b001cc6acc8fa0mr3483797plt.34.1699996694399; Tue, 14 Nov 2023 13:18:14 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:14 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Hannes Reinecke , Nitesh Shetty , Damien Le Moal , Ming Lei Subject: [PATCH v15 02/19] block: Only use write locking if necessary Date: Tue, 14 Nov 2023 13:16:10 -0800 Message-ID: <20231114211804.1449162-3-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 Reviewed-by: Damien Le Moal Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- 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 Tue Nov 14 21:16:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13455981 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 3556EC4167D for ; Tue, 14 Nov 2023 21:18:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233986AbjKNVSY (ORCPT ); Tue, 14 Nov 2023 16:18:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232492AbjKNVST (ORCPT ); Tue, 14 Nov 2023 16:18:19 -0500 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CE18C3; Tue, 14 Nov 2023 13:18:16 -0800 (PST) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1cc3bb4c307so47997685ad.0; Tue, 14 Nov 2023 13:18:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996696; x=1700601496; 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=ZXxdMX6CRen+F1nt9soo8zhbGYJ2EAO/La69VGLccjY=; b=bKyqjHZKpre4rgvpuiP1XrhZSxt07mjzkfqAolgozYxmrFNNL9536bQsdOpBYfpaNJ POmXQQEiPb9Xv/w/X/+gCwS0JNkr5HwYWj+dqTJz+jwJROpFjc+4DMCI6O6bjcBCrU08 4wR0cHL2Vwxnpo6GEbvHzCquHIN/cfwQ2z5ITNoIlvt0mQLzsrTt5MN7BHmASbUVjQuY V4Kh4nBHWpgoQYHTzlaHtbtxruAy5/yzxFOgOrxOL22LMoUfTZt1R9naSrwUbXUOieAx 7sJq/GenLoZT2y8YMJbd3eoiSBP3qAr+59JoZ4Qag5jiM9pPQ4LVMd5qc/qUXTKceaYP BPuw== X-Gm-Message-State: AOJu0Yz9I+ysPu0jd2IOI2ZJfJP/8BBXxfqTcRo/+gB4jR98i7hXv+3l Q6jM84Np7gijFBslSn+zsdmrsRy+PPs= X-Google-Smtp-Source: AGHT+IEsWJ3GrKRckqCklmb9GC86ZArKHc4WpMAY3SEJcmmubp6LGwVbslDiFCFoDQ/eE9dM6s+BmQ== X-Received: by 2002:a17:902:ec92:b0:1cc:bfb4:2dd1 with SMTP id x18-20020a170902ec9200b001ccbfb42dd1mr3736233plg.53.1699996695726; Tue, 14 Nov 2023 13:18:15 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:15 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , Hannes Reinecke Subject: [PATCH v15 03/19] block: Preserve the order of requeued zoned writes Date: Tue, 14 Nov 2023 13:16:11 -0800 Message-ID: <20231114211804.1449162-4-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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. Reviewed-by: Damien Le Moal Cc: Christoph Hellwig 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 Tue Nov 14 21:16:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13455982 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 D2877C41535 for ; Tue, 14 Nov 2023 21:18:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234045AbjKNVSZ (ORCPT ); Tue, 14 Nov 2023 16:18:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233654AbjKNVSU (ORCPT ); Tue, 14 Nov 2023 16:18:20 -0500 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB25DC8; Tue, 14 Nov 2023 13:18:17 -0800 (PST) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1cc4f777ab9so47032175ad.0; Tue, 14 Nov 2023 13:18:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996697; x=1700601497; 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=W1thpV5OlILolOgxvwdjg5s7xMMPBztR5MCTbqin1/PwJhDw65H4sHd2tENg8o4ThR KoaYLZp8cYztlUQoBzqGOB/QJj0M491Mcr5ZEAPptR1qU2xGa1Ebw1DiumtjcURoIgLk 2khJV06fp2TzaJDBFy5wzTBnZHF45QA2OT2dyWPcXvsMzX0TVXWvTxpJebvYrZ8yUle9 xWFKlfYejK1ZyQfJauQl425nRxJvV51XnHOAAXlP8cqmfkq6WD7iVPikpVs5mfrzbNW0 k2gwBDaxfaxbYB4fDivTKkF8EzcfNANbLIWOfzsVgmp5WzWlvBd5FQFxqKr11FQVQMyB WC8Q== X-Gm-Message-State: AOJu0YxcLLRJ+6sUVlDKzj5VnyMudxVzWrFI8J3XmjuC0ZU8g9pn5YKE oTTVFOZqhXZqul4jv9FgNnU= X-Google-Smtp-Source: AGHT+IES1fYe74T5BSKRfTRW4DAsH1QeHddnUcXD8eJk/oW6LbQYivvwA9bIeraiR6QHYvUSIdSJXA== X-Received: by 2002:a17:903:244d:b0:1cc:50ad:58 with SMTP id l13-20020a170903244d00b001cc50ad0058mr3528705pls.42.1699996697077; Tue, 14 Nov 2023 13:18:17 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:16 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Hannes Reinecke , Nitesh Shetty , Ming Lei Subject: [PATCH v15 04/19] block/mq-deadline: Only use zone locking if necessary Date: Tue, 14 Nov 2023 13:16:12 -0800 Message-ID: <20231114211804.1449162-5-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 Tue Nov 14 21:16:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13455983 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 8857BC4332F for ; Tue, 14 Nov 2023 21:18:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233654AbjKNVSa (ORCPT ); Tue, 14 Nov 2023 16:18:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234044AbjKNVS3 (ORCPT ); Tue, 14 Nov 2023 16:18:29 -0500 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12218D5; Tue, 14 Nov 2023 13:18:26 -0800 (PST) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1cc1ee2d8dfso54695405ad.3; Tue, 14 Nov 2023 13:18:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996705; x=1700601505; 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=hEB5AQTRUTdOnsPOaGK+HSfWWF2oI6RKvZDS0NG1d3w=; b=CxWUYpQgciS7DTf0yx6ccrFZ0OEx4Rcwd2NU5I2KR8jWQIw/lgzhWOD6zREQHclt79 MPbNh+CmkTTGrIB6uQRkw3l2de0ySYkoBpOvKzD96iE3PdxUIzBCdKgx8d9Hz0+kN/Ch 41FM5184CckJQffLLm6n55gfaidtmyGLPw7t2Tq+pYO+j7YfXIPknJyZzHiZdye0AO/G KcToyFVj2ew6+GppC0692QYfzqXrRhS4OBleagXlCht9mKbv4+QMaWaSGJ+hAOD5dvXY Wdd6arBYW1pLU05bZG+BSnwSC48uHG7watBYCi2UMy5t5OO7vhd+SY6mi/FXWyzwR1Dk DGzw== X-Gm-Message-State: AOJu0YyR+QgCZdrYXOcvaCWfTgpUo9vcQsndl3Ng81/ylCFdsIpp46fM 3aJE8YgDd0NyHwch+H9WGcc= X-Google-Smtp-Source: AGHT+IHhcjnOxAPLwOhAVYvIsTZ0lsfBJJswaQZJeMhWVew//IeJiHQw1atrNDCRu/cJhtU5ZxPdSQ== X-Received: by 2002:a17:902:8c96:b0:1ce:16e7:f4f8 with SMTP id t22-20020a1709028c9600b001ce16e7f4f8mr3037620plo.11.1699996705438; Tue, 14 Nov 2023 13:18:25 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:25 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Damien Le Moal , "James E.J. Bottomley" , Jason Yan , John Garry , Wenchao Hao Subject: [PATCH v15 05/19] scsi: Pass SCSI host pointer to scsi_eh_flush_done_q() Date: Tue, 14 Nov 2023 13:16:13 -0800 Message-ID: <20231114211804.1449162-6-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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. Acked-by: Damien Le Moal Cc: Martin K. Petersen 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 b0d6e69c4a5b..ff03c4a6bad9 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -768,7 +768,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 Tue Nov 14 21:16:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13455984 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 6233EC4167D for ; Tue, 14 Nov 2023 21:18:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234058AbjKNVSc (ORCPT ); Tue, 14 Nov 2023 16:18:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234052AbjKNVSa (ORCPT ); Tue, 14 Nov 2023 16:18:30 -0500 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E1DFC3; Tue, 14 Nov 2023 13:18:27 -0800 (PST) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1cc30bf9e22so1757245ad.1; Tue, 14 Nov 2023 13:18:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996707; x=1700601507; 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=S4050Df3wVHg7KTGgS7dsrp4UQxEW02D6+iCI7Hka50=; b=f767J7XoN3AbLztMIm3l9a6cKPFzFsB31FImQOeVHq3XSGh8S3fbkop9fp5/C9jxia 92k4kQw9uoJxA2wRZ0FfjS2nhoo8PvroAnt7Osvhj89vCH3sidkO49W39+tUj1Y6uYCB SvtG8WWoIRa8phQ3lF1286l9zVORRgVn09WYSbAFkPjDz8OKuIY6Q1V3aFwpVVsXiiV0 sqe+xzgjEVOUwvrHLdSyNmmXZ270F2H9a0ZsNOLXnvu4bf/nxu0DonEDkiPQWEItweKH X6FRZxGbQJ28E35GKeo90VEsfeQy+K+p6ZZ4ze55Vt9FELaSlSPqHQNYeLFZUk7m6kSm c+xQ== X-Gm-Message-State: AOJu0Yyd49OEGk/N1S7w6aFLILwEWsQ/sFGlEIscBaSCJq3G5Rl5OTje 1tVbFBHZAx+3G/OafBurexw= X-Google-Smtp-Source: AGHT+IFUEGs3c9fwcpw04I5xr9zni4VLuz/t0KQFPwlMkw82wMsPfhCbYmM+D4qGppL4TGN40sh2KQ== X-Received: by 2002:a17:902:8216:b0:1ce:1b7b:8396 with SMTP id x22-20020a170902821600b001ce1b7b8396mr4018537pln.29.1699996706899; Tue, 14 Nov 2023 13:18:26 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:26 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v15 06/19] scsi: core: Introduce a mechanism for reordering requests in the error handler Date: Tue, 14 Nov 2023 13:16:14 -0800 Message-ID: <20231114211804.1449162-7-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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. 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 | 51 ++++++++++++++++++++++++++++++++++++++ include/scsi/scsi_driver.h | 1 + include/scsi/scsi_host.h | 6 +++++ 3 files changed, 58 insertions(+) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 7390131e7f0a..4214d7b79b06 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); +} + +static 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/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 3b907fc2ef08..150ae619c4d2 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -464,6 +464,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 Tue Nov 14 21:16:15 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: 13455985 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 830CAC4332F for ; Tue, 14 Nov 2023 21:18:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234079AbjKNVSo (ORCPT ); Tue, 14 Nov 2023 16:18:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234078AbjKNVSk (ORCPT ); Tue, 14 Nov 2023 16:18:40 -0500 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64996D3; Tue, 14 Nov 2023 13:18:35 -0800 (PST) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1cc5916d578so54649025ad.2; Tue, 14 Nov 2023 13:18:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996715; x=1700601515; 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=zO/ChiiZm3CqAyVOLnE1irAFBX4OB6MDooFslSh0zhI=; b=ENsPewi+m603dtLn0cteJ62op7wcWo67r7gXL1cgopZblbVsri9/5k7yvrOACo4ud8 Q2M6GInC28mN8iQ/K/oF0G9F3XmlMsV4iR7ZM4TYc4MNKggLNn2oBd4VNRZMzj44zAP0 P7V8Y+NRAvJOPWNsoXjdJ7WnzPiGTso6mISXfwOl8nLrDC4p9xfVXr7rhVetMIadPs+e pRJnYvVVULLyKKOIoZ8svEh4cCa5skM6FzcKXz4t0Glg/GYQEch9dOxQ8FmcvllL/OVH mBZPTxRo1yIDrnKGgPXB2QkGOjC1esHfgnhlbIm3opFX2Eqk/S9NAsCr7NX1wVNZQ8PT 8/Qg== X-Gm-Message-State: AOJu0YydI6mAAzqP1wwC1IDp6GDS1kwlznHaedq+MQtr379I9PAA6opS jCQra1pNKJxWtW5t4E645+k= X-Google-Smtp-Source: AGHT+IHD3X3stfLSj9IM+KAmQ+R21ZGjPqGzkswaha4DeQrZsb20e/40TRMyJkgTs/wNleJwW40e5w== X-Received: by 2002:a17:903:32c5:b0:1ca:72f9:253a with SMTP id i5-20020a17090332c500b001ca72f9253amr3703563plr.23.1699996714729; Tue, 14 Nov 2023 13:18:34 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:34 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v15 07/19] scsi: core: Add unit tests for scsi_call_prepare_resubmit() Date: Tue, 14 Nov 2023 13:16:15 -0800 Message-ID: <20231114211804.1449162-8-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 | 5 + drivers/scsi/scsi_error.c | 4 + drivers/scsi/scsi_error_test.c | 233 +++++++++++++++++++++++++++++++++ 3 files changed, 242 insertions(+) create mode 100644 drivers/scsi/scsi_error_test.c diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index addac7fbe37b..2e57afdbbc4d 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig @@ -232,6 +232,11 @@ config SCSI_SCAN_ASYNC Note that this setting also affects whether resuming from system suspend will be performed asynchronously. +config SCSI_ERROR_TEST + tristate "scsi_error.c unit tests" if !KUNIT_ALL_TESTS + depends on SCSI && KUNIT + default KUNIT_ALL_TESTS + menu "SCSI Transports" depends on SCSI diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 4214d7b79b06..3a2643293abf 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -2621,3 +2621,7 @@ bool scsi_get_sense_info_fld(const u8 *sense_buffer, int sb_len, } } EXPORT_SYMBOL(scsi_get_sense_info_fld); + +#ifdef CONFIG_SCSI_ERROR_TEST +#include "scsi_error_test.c" +#endif diff --git a/drivers/scsi/scsi_error_test.c b/drivers/scsi/scsi_error_test.c new file mode 100644 index 000000000000..46362766ad48 --- /dev/null +++ b/drivers/scsi/scsi_error_test.c @@ -0,0 +1,233 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2023 Google LLC + */ +#include +#include +#include +#include +#include + +#define ALLOC(type, ...) \ + ({ \ + type *obj; \ + obj = kmalloc(sizeof(*obj), GFP_KERNEL); \ + if (obj) \ + *obj = (type){ __VA_ARGS__ }; \ + obj; \ + }) + +#define ALLOC_DISK(...) ALLOC(struct gendisk, __VA_ARGS__) + +#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) +{ + struct gendisk *disk __free(kfree) = ALLOC_DISK(); + struct request_queue *q __free(kfree) = ALLOC_Q( + .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, + }; + struct scsi_device *dev __free(kfree) = ALLOC_SDEV( + .request_queue = q, + .sdev_gendev.driver = &uld.gendrv, + .host = &host, + ); + struct rq_and_cmd { + struct request rq; + struct scsi_cmnd cmd; + } *cmd1 __free(kfree) = NULL, *cmd2 __free(kfree); + LIST_HEAD(cmd_list); + + BUILD_BUG_ON(scsi_cmd_to_rq(&cmd1->cmd) != &cmd1->rq); + + q->disk = disk; + disk->queue = q; + cmd1 = ALLOC_CMD( + .rq = { + .q = q, + .cmd_flags = REQ_OP_WRITE, + .__sector = 2, + }, + .cmd.device = dev, + ); + cmd2 = ALLOC_CMD( + .rq = { + .q = q, + .cmd_flags = REQ_OP_WRITE, + .__sector = 1, + }, + .cmd.device = dev, + ); + 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); + 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 = ALLOC_DISK(); + 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); +} + +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 Tue Nov 14 21:16:16 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: 13455986 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 D3733C4167D for ; Tue, 14 Nov 2023 21:18:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234081AbjKNVSo (ORCPT ); Tue, 14 Nov 2023 16:18:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234082AbjKNVSl (ORCPT ); Tue, 14 Nov 2023 16:18:41 -0500 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9612AF0; Tue, 14 Nov 2023 13:18:36 -0800 (PST) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1cc2fc281cdso47167325ad.0; Tue, 14 Nov 2023 13:18:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996716; x=1700601516; 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=YVWi2Q1sV9spaxry37mpQP98JceOEq6IkdRxW6ewZhs=; b=QoQYuBFEoHVC4QE0z09vVrjHq9ybM9jAINOBhrDotJG1xijnOUUBkIPW3OvMSXmcN9 p3w6LJPQO5YhHOFJ3tuTQ2qyKLLrBz8h2pkyqh3/SlTDefjSC+p4PsV2Nnh5wG/y2DUL mSqrsZDlRhl83RRIk4OmsyScgtj4eJdesgmZut1ofuyFGTjvjw02f2tve+3wXnjUTHlE ay2yHoa2rSnXKGuxHiqtUm0/O0G2WOG+ztSnovsYR+WEftTCQxhSxCvSDcPNQZfNgg8g rSbXBeoXvyV8jFwZ9honwNI2dLRgF92GKubVweimaOejoaCipKyajYUuy0G6/6JDHuiG Fo5Q== X-Gm-Message-State: AOJu0YyQUo+7m89s8TQElkOcG0I7MS54Xgvg+f5SHjSLpHldaFWcMrib 3ICzb4rIgEprljmc0hOeD1M= X-Google-Smtp-Source: AGHT+IEp9+kqkeTpv4Xkg1juZDhsct2JPEvKd7Xw3fYoiyHC5+VwP3N5Q+HgdM1Q86Mj/INBMQF9vA== X-Received: by 2002:a17:902:8542:b0:1cc:ef37:664a with SMTP id d2-20020a170902854200b001ccef37664amr3088361plo.31.1699996716016; Tue, 14 Nov 2023 13:18:36 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:35 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v15 08/19] scsi: sd: Support sorting commands by LBA before resubmitting Date: Tue, 14 Nov 2023 13:16:16 -0800 Message-ID: <20231114211804.1449162-9-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Support sorting 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. Reviewed-by: Damien Le Moal Cc: Martin K. Petersen 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 530918cbfce2..63bb01ddadde 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -2058,6 +2059,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); @@ -4014,6 +4047,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 Tue Nov 14 21:16:17 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: 13455987 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 6E56AC4332F for ; Tue, 14 Nov 2023 21:18:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234085AbjKNVS4 (ORCPT ); Tue, 14 Nov 2023 16:18:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234095AbjKNVSr (ORCPT ); Tue, 14 Nov 2023 16:18:47 -0500 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EF1BFB; Tue, 14 Nov 2023 13:18:44 -0800 (PST) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1cc34c3420bso47872865ad.3; Tue, 14 Nov 2023 13:18:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996724; x=1700601524; 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=u5C8QTqGh/a0Jki+l9qVpbMBnpDJv7ICCSUZf0jmocU=; b=EOB8NZFyVNa6urdrdea1Aibe7UenZylCH3z6bKCdSs6Nzv5PhMVGWhWk4kIZBuzQ4j tsnnzb2ak3Y+8innvquEQGi4mvlCzendDPV6pLWoo/NmqU46CQlpek7esBMwj8vrkf/Q cBuvcKl4QXYUjiLqnM+R1p/hHicTGc5S1KCwwLM4KODdWilIiwwu5xn6mIQCvQnUt+ac 0dEhOIujR8tUrd5DOTgUfKWowm9klhIRoYxiKUS1YhOjjojRLQPTlenSZUCJAh2WEjyu ppmmxKz4Qnz/VHFaGlqpTdQJeiEQkRYr6Msje4FsXru7lGfRM6Zfad8q/9Y0vyYsWklD zUZA== X-Gm-Message-State: AOJu0Yz2Cdf0yV8rwY+/L2wSEQ6MjSUiHd+x2+tv79o/CLl03D/FiBSb hg+hO4LW4sDfHwnFFIer5nMmwZyUIO8= X-Google-Smtp-Source: AGHT+IGuLpK5c0LU1HnWPaHYPG5YSuXxZ0RuTZFXErMNKVuIgISMT1OPYL1QI22cdBlFo57goyPK3w== X-Received: by 2002:a17:902:db03:b0:1cc:32ae:4afd with SMTP id m3-20020a170902db0300b001cc32ae4afdmr4367405plx.46.1699996723778; Tue, 14 Nov 2023 13:18:43 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:43 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v15 09/19] scsi: sd: Add a unit test for sd_cmp_sector() Date: Tue, 14 Nov 2023 13:16:17 -0800 Message-ID: <20231114211804.1449162-10-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 | 5 +++ drivers/scsi/sd.c | 4 ++ drivers/scsi/sd_test.c | 86 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 drivers/scsi/sd_test.c diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index 2e57afdbbc4d..ba2b81ddd7f8 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig @@ -237,6 +237,11 @@ config SCSI_ERROR_TEST 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 + menu "SCSI Transports" depends on SCSI diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 63bb01ddadde..d52ea605ada8 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -4141,3 +4141,7 @@ void sd_print_result(const struct scsi_disk *sdkp, const char *msg, int result) "%s: Result: hostbyte=0x%02x driverbyte=%s\n", msg, host_byte(result), "DRIVER_OK"); } + +#ifdef CONFIG_SD_TEST +#include "sd_test.c" +#endif 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 Tue Nov 14 21:16:18 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: 13455989 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 6FBA5C41535 for ; Tue, 14 Nov 2023 21:18:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234086AbjKNVS5 (ORCPT ); Tue, 14 Nov 2023 16:18:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234070AbjKNVSt (ORCPT ); Tue, 14 Nov 2023 16:18:49 -0500 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 126F310C; Tue, 14 Nov 2023 13:18:46 -0800 (PST) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1cc2f17ab26so45872395ad.0; Tue, 14 Nov 2023 13:18:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996725; x=1700601525; 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=ga3scwKkF9qdx4A7qJSd8RHB1gIKlvpQqaon9XQUKgo=; b=UhSpvO8Z59/YVN2Ib4iF9oTuaL3bVh5zr2P5MSDYlqdZcCT4wXYTTTR7rpVNVKEyCa zEOPJRjwLhkyR8922XdQZJol4SCnDBK9BbgLTxl/nDO4jT1m80kp/1ORVPcHPXbESZpj FxIXB74f1KM37kR0qmPbOQaeMw4HCsYDYJ6WtWC7y4lTzOp4du1A7JmjHPjyelPr37TR sAoYp7SP9Nk2MtelKFREE5mT1xwP/974X4LXSavyFybkYQR2W1P9Nlbf3N8AIrDdkkdh 4mC3WRuKAO1GACIyynFDGDE2SLXRxj27VCr0uV1LDqIp800VR0fO2yKmijIvs2xkZy+/ Z0Gw== X-Gm-Message-State: AOJu0Yy4hZmwYQdI6qGPF+AkNf9wE9K8vjjaZTdUbIiNk6Ft1ArGLpT0 4xPedAfsfEuXNprAk+VgmG4= X-Google-Smtp-Source: AGHT+IGpVL8qlxt+SMe76aCZCYpbUMzJ4XdAOgyg+UBWsG9lfmZB1jdRk9YL/pZskk/OU92qXqg9Xg== X-Received: by 2002:a17:902:9343:b0:1cc:6d2c:fb59 with SMTP id g3-20020a170902934300b001cc6d2cfb59mr3550760plp.28.1699996725353; Tue, 14 Nov 2023 13:18:45 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:44 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v15 10/19] scsi: core: Retry unaligned zoned writes Date: Tue, 14 Nov 2023 13:16:18 -0800 Message-ID: <20231114211804.1449162-11-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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/constants.c | 1 + drivers/scsi/scsi_error.c | 17 +++++++++++++++++ drivers/scsi/scsi_lib.c | 1 + drivers/scsi/sd.c | 6 ++++++ include/scsi/scsi.h | 1 + 5 files changed, 26 insertions(+) diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c index 340785536998..8ddb30741999 100644 --- a/drivers/scsi/constants.c +++ b/drivers/scsi/constants.c @@ -419,6 +419,7 @@ EXPORT_SYMBOL(scsi_hostbyte_string); #define scsi_mlreturn_name(result) { result, #result } static const struct value_name_pair scsi_mlreturn_arr[] = { + scsi_mlreturn_name(NEEDS_DELAYED_RETRY), scsi_mlreturn_name(NEEDS_RETRY), scsi_mlreturn_name(SUCCESS), scsi_mlreturn_name(FAILED), diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 3a2643293abf..4e9a35866a0d 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -699,6 +699,23 @@ 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_cmd_retry_allowed(scmd)) { + SCSI_LOG_ERROR_RECOVERY(1, + sdev_printk(KERN_WARNING, scmd->device, + "Retrying unaligned write at LBA %#llx.\n", + scsi_get_lba(scmd))); + return NEEDS_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 cf3864f72093..2e28a1aeedd0 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1442,6 +1442,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 d52ea605ada8..7e71f9f42036 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1276,6 +1276,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 4498f845b112..5eb8b6e3f85a 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 Tue Nov 14 21:16:19 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: 13455988 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 79846C4167B for ; Tue, 14 Nov 2023 21:18:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234074AbjKNVS6 (ORCPT ); Tue, 14 Nov 2023 16:18:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234060AbjKNVSw (ORCPT ); Tue, 14 Nov 2023 16:18:52 -0500 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3F66CE; Tue, 14 Nov 2023 13:18:48 -0800 (PST) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1cc316ccc38so47915365ad.1; Tue, 14 Nov 2023 13:18:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996728; x=1700601528; 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=wtwomS/B6NAHkI0aQd5LGv/6avBX99ZZNowgwo7RKOz4W55M0ypq58HoGbaKODGNWM y7BPsw74/p4xk550BygWcKCNQq9z+6asuyt2OmtIgeYxM8QMAKDkeMz96J0ugoIk4XnD 5XckP+XlcBQ1jzwthxJrxv8FtMsn+a0Q8KoVGHuTE/5ZVn6j/bdBIoOcUaObaIvMNjiT e3v05rxFJlt9TzHZUJe4QCwEA+NtkBoPu2SKjw1oQaEh7LQZVMkwmGHCpH360AbPnGVM NuOwd4gWTkFZBD+3OSZS5dkLtE7RkVi6MU1Tr1p99VLXYTTpugeMe1/peRzLrUtPP4gB pWfQ== X-Gm-Message-State: AOJu0YxkjIALFGpyzFhW5X6jz6QhlEDon53ATH0/jYXT7TtIaPLPgbdq uA7l+moHqpnDpPXTGNQU0O0= X-Google-Smtp-Source: AGHT+IG85bUY2TGtdUU0k7nmDZaddRK4qcnB44Hr/BLvuCFyQe0iwL4X2hrB4t7fuBEqPgsTiHr7jQ== X-Received: by 2002:a17:902:ac8f:b0:1cc:b460:e6cc with SMTP id h15-20020a170902ac8f00b001ccb460e6ccmr3717355plr.12.1699996728371; Tue, 14 Nov 2023 13:18:48 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:46 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v15 11/19] scsi: sd_zbc: Only require an I/O scheduler if needed Date: Tue, 14 Nov 2023 13:16:19 -0800 Message-ID: <20231114211804.1449162-12-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 Tue Nov 14 21:16:20 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: 13455990 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 83E05C4332F for ; Tue, 14 Nov 2023 21:19:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234078AbjKNVTH (ORCPT ); Tue, 14 Nov 2023 16:19:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234083AbjKNVSx (ORCPT ); Tue, 14 Nov 2023 16:18:53 -0500 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43B1D10F; Tue, 14 Nov 2023 13:18:50 -0800 (PST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1cc58219376so55106085ad.1; Tue, 14 Nov 2023 13:18:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996730; x=1700601530; 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=qs4UkxFl7+VzoezS1ZO67kX/44OBoCmLVQ8zvswAPf4=; b=qELkzFCCvGxCvkiv6tVpMZWzWtyhADv+Wa/D9cesdSioQEWspNrVwyE/9JwkWQEUC5 f+xNSPC2Zdc2QhFlGFG7/paRwxFU+fK1Sw+8RR0w8nHgSz2UQOS8EqiEJmjR9+h5ndTA MplXZh+al55apkdYbcwbuTNsWEqWEehfaFrVrPQyHJI3o15NQUwp2Q90e+y89RFXXVNN ysRRM/Gmd2vE2JGWwi/tCv+25Bu6a1I+KdAhvga4OltTmGvPrmXzhG7skS8lB/Ana5pN +/FehLhyZqw9D+u+9mS72vuz5skVVCkXCLgehsmN6LiFAsMO724po9+PSoihV4Sd7zxn H2dw== X-Gm-Message-State: AOJu0YxETqeCyUk/w2qEQ5iCvjMVahJutmPhSk8tPuDEdoOEMiGnRo7w QRhN/Hx6NanYGCQCPOWa56s= X-Google-Smtp-Source: AGHT+IEFt5ab0tBuX7ZvV0PKCNZDHa1SAF9XUNrXWvy6cUDHK+c0MnF3M9V+g9wxQK9whYNg9m09FQ== X-Received: by 2002:a17:902:f651:b0:1cc:6b55:fd3 with SMTP id m17-20020a170902f65100b001cc6b550fd3mr3797184plg.42.1699996729649; Tue, 14 Nov 2023 13:18:49 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:49 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Douglas Gilbert , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v15 12/19] scsi: scsi_debug: Add the preserves_write_order module parameter Date: Tue, 14 Nov 2023 13:16:20 -0800 Message-ID: <20231114211804.1449162-13-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 Reviewed-by: Damien Le Moal Cc: Martin K. Petersen Cc: Christoph Hellwig Cc: Ming Lei Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 67922e2c4c19..6f0c78e727ec 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -884,6 +884,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; @@ -5451,10 +5452,14 @@ 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); + q->limits.driver_preserves_write_order = sdeb_preserves_write_order; + return 0; } @@ -6189,6 +6194,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); @@ -6255,6 +6262,8 @@ MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... MODULE_PARM_DESC(per_host_store, "If set, next positive add_host will get new store (def=0)"); MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)"); MODULE_PARM_DESC(poll_queues, "support for iouring iopoll queues (1 to max(submit_queues - 1))"); +MODULE_PARM_DESC(preserves_write_order, + "Whether or not to inform the block layer that this driver preserves the order of WRITE commands (def=0)"); MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])"); MODULE_PARM_DESC(random, "If set, uniformly randomize command duration between 0 and delay_in_ns"); MODULE_PARM_DESC(removable, "claim to have removable media (def=0)"); From patchwork Tue Nov 14 21:16:21 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: 13455991 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 C07E9C4167D for ; Tue, 14 Nov 2023 21:19:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234049AbjKNVTI (ORCPT ); Tue, 14 Nov 2023 16:19:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234064AbjKNVSy (ORCPT ); Tue, 14 Nov 2023 16:18:54 -0500 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0C39121; Tue, 14 Nov 2023 13:18:51 -0800 (PST) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1cc4f777ab9so47036455ad.0; Tue, 14 Nov 2023 13:18:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996731; x=1700601531; 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=MNaII3DND/2IYpwh5Jy74a0kz8WOg4MBJJED5/gaHxY=; b=wZ7eBYb5cz4qEa7hUGnYfpE4eSO3h7cZHTfdEWD+bGAnNBNrO/Dd2Zdpu/wg/oVGvr KDSnFiVlV+N+5UfvEu7OIxAV7xTLY2/OE89kWQLnCzlw+3wOTO3DQbis3hfXRO558vXd 1604vz3OX7+49i55/kpBq2uwfSMj0c92EStz2B/avgp67raZRrJ84qArUqG0Km8/zOBz TtfWwIRslS/Od+O3vnWmIUGTc4wK3JNDpEfHEcq3853zBypugaawC0NI2Z2Gi17zDYY6 twlXIZjvjCn35231CvJvIRvvaBVSA4ucj6XDtneaPpXBsOz53d7dr2A4qYPBBVwTJKNJ LnRA== X-Gm-Message-State: AOJu0YxJllsdN2hAHH70DVtwr0rx2h3xbTgIC5Ga7LZ3Gsy2QeCYm2gB k6slX23w5puB9sukabQvwvM= X-Google-Smtp-Source: AGHT+IFltOELmXW1lWl4h45zu2rS7AGfH6Qm3CcVnB/raF3IwylxbNF/pxTiv8+54MPB4qT06N5FcQ== X-Received: by 2002:a17:902:db85:b0:1cc:476c:896c with SMTP id m5-20020a170902db8500b001cc476c896cmr3298348pld.60.1699996730970; Tue, 14 Nov 2023 13:18:50 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:50 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , Douglas Gilbert , Damien Le Moal , Ming Lei , "James E.J. Bottomley" Subject: [PATCH v15 13/19] scsi: scsi_debug: Support injecting unaligned write errors Date: Tue, 14 Nov 2023 13:16:21 -0800 Message-ID: <20231114211804.1449162-14-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 6f0c78e727ec..23ea090698df 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -183,6 +183,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 | \ @@ -190,7 +191,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) @@ -3898,6 +3900,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 Tue Nov 14 21:16:22 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: 13455992 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 65900C4332F for ; Tue, 14 Nov 2023 21:19:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234094AbjKNVTP (ORCPT ); Tue, 14 Nov 2023 16:19:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234111AbjKNVTC (ORCPT ); Tue, 14 Nov 2023 16:19:02 -0500 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97816F3; Tue, 14 Nov 2023 13:18:59 -0800 (PST) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1cc1ee2d8dfso54699435ad.3; Tue, 14 Nov 2023 13:18:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996739; x=1700601539; 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=a/jFKmYA4b/I5NdwoRTgPurns61Kr2vxDZ6EVCw0jDk=; b=nxR3Owm/C5fKiKxIFueC6spGafX9/yPdXrG1K/n7vIspel6cQoBglyvXGWgdslWW7E 02LPOvDc+k8j8oPP0flDynrYaN3hI8k2Ztam8Pp48/yPBJNYo8JreJZhHqkeaJzCxR5m RmEsjRCoDfq5NQyY6gJ4f29zGTNb9X5RbmhKS+L+00SqyhZXt+Ac+xHehDytRz4BA/MU jIklwFBmMAf4TespQ7FUV8ejc7BlDavr4xUgemihKRj0ZOnkNz5166e7Bs4XDTRX6lkF cAsyPOxEi2QNL3QDhiQyX2/G8r81sFu+Cj6r9dlFHHS9vn4owpi0GPnfayPrvY2nq2RK wdNw== X-Gm-Message-State: AOJu0YyKE0jVOTUfTgEKEVNLk18dKWpman++rEBYbMGiSVr16Jj/MH0K 7sAccKDKcbyEINy9+UHi5z4= X-Google-Smtp-Source: AGHT+IELUfic68TNf5ipjG5vfFrum1HgG4FKPn2VNX9AD8GYZCLWSHXfxiqeEAMv3UiEnYUNzF70PA== X-Received: by 2002:a17:903:40cd:b0:1cc:4071:fa44 with SMTP id t13-20020a17090340cd00b001cc4071fa44mr4328683pld.8.1699996738949; Tue, 14 Nov 2023 13:18:58 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:18:58 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , "Bao D . Nguyen" , Can Guo , Avri Altman , "James E.J. Bottomley" , Bean Huo , Keoseong Park , Adrian Hunter , Krzysztof Kozlowski , =?utf-8?q?Uwe_Kleine-?= =?utf-8?q?K=C3=B6nig?= Subject: [PATCH v15 14/19] scsi: ufs: hisi: Rework the code that disables auto-hibernation Date: Tue, 14 Nov 2023 13:16:22 -0800 Message-ID: <20231114211804.1449162-15-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 0229ac0a8dbe..2e032eaf9e93 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 Tue Nov 14 21:16:23 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: 13455993 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 EDE6BC4332F for ; Tue, 14 Nov 2023 21:19:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234053AbjKNVTV (ORCPT ); Tue, 14 Nov 2023 16:19:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234052AbjKNVTR (ORCPT ); Tue, 14 Nov 2023 16:19:17 -0500 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D456F9D; Tue, 14 Nov 2023 13:19:14 -0800 (PST) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1cc329ce84cso54690865ad.2; Tue, 14 Nov 2023 13:19:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996754; x=1700601554; 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=LVqfYcvdgpr14aJfDAk0DLCnWHZd5hJ9BIYRPuekypM=; b=kib4vt19aDKzsa0+KANCEqVnS1yxjSk6IsWEdFIrPYcOPnmR/XIbIjh06iR7MY3MIU a0PZ6v1SSVQ5gqtbbHqETIJq1WR5PhXXXYeGOQDGult7aTx1NRV95F6cUG1U5oMMnSIF KbM3JfBpQZg9Ohiiq6LvPpd6OZgfEYtlFQ+rv/YCDag3kxEoXForfyJvczwDSdquaIZX 8Q88TJo4AAibmMnG73DCYYYwyy2DgJ7m6IvTHMIPKh+CnNqCTTBYYH4NcJCOYt5e14Vm +dKU+w3yXnLghErBbnztndxPgkvv/OjS1T9RqlcXWbus6qSVWWrY2Q2pOkqKVim7ULwL SPpg== X-Gm-Message-State: AOJu0YydQe+Vswd3zf67F8C9gvhmjqsj4khyF2BrTjUyC89L2SiVOGKM Mz7SVSsBwpQIQd6USZJvsuVeD5hO0ZE= X-Google-Smtp-Source: AGHT+IFWNIpMHYIm0btFZHTOJ9/LbXu82quF73+bVhO7wz2AsL9zFKlc98HkiDa+3GPVKGAfTFPMNw== X-Received: by 2002:a17:902:bc84:b0:1cc:431f:55e6 with SMTP id bb4-20020a170902bc8400b001cc431f55e6mr3336699plb.63.1699996754154; Tue, 14 Nov 2023 13:19:14 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:19:13 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , "Bao D . Nguyen" , Can Guo , Avri Altman , "James E.J. Bottomley" , Stanley Chu , Manivannan Sadhasivam , Asutosh Das , Peter Wang , Bean Huo , Arthur Simchaev , Po-Wen Kao , Eric Biggers Subject: [PATCH v15 15/19] scsi: ufs: Rename ufshcd_auto_hibern8_enable() and make it static Date: Tue, 14 Nov 2023 13:16:23 -0800 Message-ID: <20231114211804.1449162-16-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 8b1031fb0a44..e80878a5d4e6 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -4401,6 +4401,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; @@ -4420,21 +4428,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 @@ -8864,8 +8864,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); @@ -9862,8 +9861,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 7f0b2c5599cd..4156dc2b389b 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1360,7 +1360,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 Tue Nov 14 21:16:24 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: 13455994 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 18CFFC4332F for ; Tue, 14 Nov 2023 21:19:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234051AbjKNVTq (ORCPT ); Tue, 14 Nov 2023 16:19:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbjKNVTp (ORCPT ); Tue, 14 Nov 2023 16:19:45 -0500 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1C7FC3; Tue, 14 Nov 2023 13:19:42 -0800 (PST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1cc3388621cso1624275ad.1; Tue, 14 Nov 2023 13:19:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996782; x=1700601582; 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=/fOK1xMggPhxX79YRNUZ2PbNiBQeCgJB2yiQ208LOJo=; b=BLYPFOecb9xaJXXtXLqkyCgaIEV2B/Q5G4xuxDOPUuucyPSGbp37GEKymGfpAlEZbX JECK2Gej1tPKOztXspj8v4RTT8WtQyvgcsVzvoTYBkQxKJvyplS/V6cwCXlAU3xu/PX6 jez9lB4DOQpChwq7Vvs5BqpHdgipJD+KWpBODvjrKmBH31k7Kre7ZsDZXAggqht1aeRZ r3BOXOeZlSERuhLhT8wgMm45FdM2vNnDva6jPVjnwS3fH/6L3/yN9qo3U/9aDL7fLEKG 3BV+Q3Bbjkxkc/nxq+dg29vAdIngyvqoERlxh9DUyX/bdbu6KCamZKU3ws8MPKhZCyZ5 7J6A== X-Gm-Message-State: AOJu0YxeZVVpTeKX/UXr5b7XeyUj8buOmoLNrdBAb/u69/xVToLFi+RS /ya3GXdDww9AY+caW3F/BQc= X-Google-Smtp-Source: AGHT+IHcYY9WW5ODiC5atmmJWq68nbwF+KYhWpcBmeO/Y9IWZVp6t9xOoXUSQj8TI8YjFHSLcPPgEQ== X-Received: by 2002:a17:902:cecb:b0:1c0:afda:7707 with SMTP id d11-20020a170902cecb00b001c0afda7707mr4247354plg.34.1699996782064; Tue, 14 Nov 2023 13:19:42 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.19.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:19:41 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , "Bao D . Nguyen" , Can Guo , Peter Wang , Avri Altman , "James E.J. Bottomley" , Matthias Brugger , AngeloGioacchino Del Regno , Bean Huo , Lu Hongfei , Stanley Chu , Manivannan Sadhasivam , Asutosh Das , Arthur Simchaev , zhanghui , Keoseong Park , Po-Wen Kao , Eric Biggers Subject: [PATCH v15 16/19] scsi: ufs: Change the return type of ufshcd_auto_hibern8_update() Date: Tue, 14 Nov 2023 13:16:24 -0800 Message-ID: <20231114211804.1449162-17-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 e80878a5d4e6..a4f25131a78c 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -4409,13 +4409,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) { @@ -4432,6 +4432,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 4156dc2b389b..513ecd485bb0 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1360,7 +1360,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 Tue Nov 14 21:16:25 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: 13455995 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 71625C4167D for ; Tue, 14 Nov 2023 21:19:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234052AbjKNVTz (ORCPT ); Tue, 14 Nov 2023 16:19:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234054AbjKNVTy (ORCPT ); Tue, 14 Nov 2023 16:19:54 -0500 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E415CB; Tue, 14 Nov 2023 13:19:51 -0800 (PST) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1cc0d0a0355so46992055ad.3; Tue, 14 Nov 2023 13:19:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996791; x=1700601591; 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=5hCFLPJyNlTWaTqcc9sUMaTozBjdPIt45oPYglqkq3o=; b=RW4CqW7F4Xt5rA+bjzJCokFQ8aujIxw3PNtFCXewDSt4dvivI+xtvY1l+f/um08/QV LzABUrYkCtf1zyGFWDwMTHiprEG7ZWydP7jjDeEw8CtWxGibYDtm3lY6tx/OEVrIMl5q xMacO6FNydUxyd4g5xrCEVXA6lYNSuPDD6uG5Nsa5gY2QDuvzRdrR48K3zww0qgJ+Vuw 8zBGPuHMdnion/SLTFEb8Z48XDRwZpknFKZtM9WpCfJ6Qf4yHoWjopMv6nzjkj8b8XTk eZIYOt5hxUYnzhhqWNsaHc2RKq1uulHO9m5WJXx09RTG+EAvIaCADkeYGRipEcE8NiA4 JiEg== X-Gm-Message-State: AOJu0YwATh9Vrvpx50CHTijXSUTRBxnJL6CmxPHFkozobFj9rib8yolz nXNeNUQYf2wGGon3zw5HcNs= X-Google-Smtp-Source: AGHT+IGjEFlMza2Psi0NVqhMLIkOTPPm++q44fMEJoZwAmywnvytORTc1xG5dWNYMm2lBUTrXmOGiw== X-Received: by 2002:a17:903:234b:b0:1cc:9781:4782 with SMTP id c11-20020a170903234b00b001cc97814782mr4427268plh.62.1699996790717; Tue, 14 Nov 2023 13:19:50 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:19:50 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , "Bao D . Nguyen" , Can Guo , Avri Altman , "James E.J. Bottomley" , Stanley Chu , Manivannan Sadhasivam , Asutosh Das , Peter Wang , Bean Huo , Arthur Simchaev Subject: [PATCH v15 17/19] scsi: ufs: Simplify ufshcd_auto_hibern8_update() Date: Tue, 14 Nov 2023 13:16:25 -0800 Message-ID: <20231114211804.1449162-18-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 a4f25131a78c..73cdf9917e02 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -4411,21 +4411,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 Tue Nov 14 21:16:26 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: 13455996 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 CD587C4332F for ; Tue, 14 Nov 2023 21:20:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234060AbjKNVUG (ORCPT ); Tue, 14 Nov 2023 16:20:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234054AbjKNVUF (ORCPT ); Tue, 14 Nov 2023 16:20:05 -0500 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF051C4; Tue, 14 Nov 2023 13:19:59 -0800 (PST) Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-280109daaaaso4684259a91.3; Tue, 14 Nov 2023 13:19:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996799; x=1700601599; 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=CHfCUfy3YZ4/cZAo2CvvXHiRDCpV7olj515/DJuvegE=; b=rRlT/MvxlezjqGIb3d1/efNBY6eYI2dNm5kjrHSAFBuEHaiZH+yixQRCauomLk3aIi Kqfyp/NeneyjOs8hpsCNSYCPSS2XkXMZXs3vHGAHXXT9dfrF+38VKllddSX96LKlOfa2 eXQUUYXGYMNiOvb6YJqehYbGK5PB/kgx/NMQJuxnCmgz0uo62W3sRIIfMG8jWxIff/Uq ExEZiD31g78HUD11CXM6IQG7SoxWhKRDWc0K/xrJj+bx4LZqgEAWCskgbBvLvVMVESXR xIElbWuW5vKICvhT5hJzsIgaWV1iL2/fMjp/QJlMmg8pecv097EkjpJXJZ4VlbPClubg nNsQ== X-Gm-Message-State: AOJu0YwJs/TDVxk0daRRGk65LEUgrizVNDMs6EMNuENMRx89cmml1O7Z jivu2EDnetBW3F4NoCtww3U= X-Google-Smtp-Source: AGHT+IEJBomTrjeTK+QrNA7hMvMr2TseY8i5KPDUt0E9uVm0VByT8BNeUtGQZAmGYdoT84j4yd/2Vw== X-Received: by 2002:a17:90b:4b82:b0:271:7cd6:165d with SMTP id lr2-20020a17090b4b8200b002717cd6165dmr9367182pjb.26.1699996799288; Tue, 14 Nov 2023 13:19:59 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:19:58 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , "Bao D . Nguyen" , Can Guo , Avri Altman , "James E.J. Bottomley" , Stanley Chu , Manivannan Sadhasivam , Asutosh Das , Peter Wang , Bean Huo , Arthur Simchaev Subject: [PATCH v15 18/19] scsi: ufs: Forbid auto-hibernation without I/O scheduler Date: Tue, 14 Nov 2023 13:16:26 -0800 Message-ID: <20231114211804.1449162-19-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-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 73cdf9917e02..732509289165 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -4401,6 +4401,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)) @@ -4409,13 +4433,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); @@ -4424,6 +4477,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; } From patchwork Tue Nov 14 21:16:27 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: 13455997 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 80B4CC4332F for ; Tue, 14 Nov 2023 21:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234064AbjKNVUM (ORCPT ); Tue, 14 Nov 2023 16:20:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbjKNVUL (ORCPT ); Tue, 14 Nov 2023 16:20:11 -0500 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34F909D; Tue, 14 Nov 2023 13:20:08 -0800 (PST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1cc5916d578so54661325ad.2; Tue, 14 Nov 2023 13:20:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699996807; x=1700601607; 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=q5+QxzV8SEnrspkTplBx7X3m9ppb+56nGOToDTc83Nw=; b=PGIIVRz7KDltcDI449tLOSbaMaBPAnLSzcp9PWhWWrfgyXaZ1QBZUAZCTAUXPK2Vhu R9bmmEWDcXbEci4LN7FnUG+gofOGJX+eA8Xvk1hn2n8lYBf03LUwdgqdYBxB0Jd4ngg4 SPb8SJoBIXg4YzZ5X39LnhRh0v5IUzXQinJvEKDH0IOrNGoR+a7cfePD17A6uHbKcAPF hWHDGrlinkHnqQwhN5GmBvy8isQcYQjqU9G0BT/FUfGu6gD5HqZ23tmiIFj4JzWt6FZd R+t4dTlnjrpgFnK5c47XmLZIGWqkmQOfK4ukNd9BvwkufOphWpfD0AG/KYfucWJI+q32 Vm5w== X-Gm-Message-State: AOJu0YwGyT/TpPUClbWR3gcHnkaBO4dK9uVafz7jyNi4JKO7QtMQlyJT XP34si5wXUWSRhNkvpub+0o= X-Google-Smtp-Source: AGHT+IFReN0liBceDtxwgA5scU2N9cZo0WgKLj2FWzWIjJvMPyLc1N+99GQMmlSiZXsbWjKffdybMA== X-Received: by 2002:a17:903:1108:b0:1c3:c687:478c with SMTP id n8-20020a170903110800b001c3c687478cmr4691366plh.8.1699996807528; Tue, 14 Nov 2023 13:20:07 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:2278:ad72:cefb:4d49]) by smtp.gmail.com with ESMTPSA id ix7-20020a170902f80700b001c71ec1866fsm6169288plb.258.2023.11.14.13.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 13:20:07 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Bart Van Assche , "Bao D . Nguyen" , Can Guo , Avri Altman , "James E.J. Bottomley" , Stanley Chu , Manivannan Sadhasivam , Asutosh Das , Peter Wang , Bean Huo , Arthur Simchaev Subject: [PATCH v15 19/19] scsi: ufs: Inform the block layer about write ordering Date: Tue, 14 Nov 2023 13:16:27 -0800 Message-ID: <20231114211804.1449162-20-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231114211804.1449162-1-bvanassche@acm.org> References: <20231114211804.1449162-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From the UFSHCI 4.0 specification, about the legacy (single queue) mode: "The host controller always process transfer requests in-order according to the order submitted to the list. In case of multiple commands with single doorbell register ringing (batch mode), The dispatch order for these transfer requests by host controller will base on their index in the List. A transfer request with lower index value will be executed before a transfer request with higher index value." From the UFSHCI 4.0 specification, about the MCQ mode: "Command Submission 1. Host SW writes an Entry to SQ 2. Host SW updates SQ doorbell tail pointer Command Processing 3. After fetching the Entry, Host Controller updates SQ doorbell head pointer 4. Host controller sends COMMAND UPIU to UFS device" In other words, for both legacy and MCQ mode, UFS controllers are required to forward commands to the UFS device in the order these commands have been received from the host. Notes: - For legacy mode this is only correct if the host submits one command at a time. The UFS driver does this. - Also in legacy mode, the command order is not preserved if auto-hibernation is enabled in the UFS controller. Hence, enable zone write locking if auto-hibernation is enabled. This patch improves performance as follows on my test setup: - With the mq-deadline scheduler: 2.5x more IOPS for small writes. - When not using an I/O scheduler compared to using mq-deadline with zone locking: 4x more IOPS for small writes. 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 | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 732509289165..e78954cda3ae 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -4421,6 +4421,20 @@ static int ufshcd_update_preserves_write_order(struct ufs_hba *hba, return -EPERM; } } + shost_for_each_device(sdev, hba->host) + blk_freeze_queue_start(sdev->request_queue); + shost_for_each_device(sdev, hba->host) { + struct request_queue *q = sdev->request_queue; + + blk_mq_freeze_queue_wait(q); + q->limits.driver_preserves_write_order = preserves_write_order; + blk_queue_required_elevator_features(q, + !preserves_write_order && blk_queue_is_zoned(q) ? + ELEVATOR_F_ZBD_SEQ_WRITE : 0); + if (q->disk) + disk_set_zoned(q->disk, q->limits.zoned); + blk_mq_unfreeze_queue(q); + } return 0; } @@ -4463,7 +4477,8 @@ int ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) if (!is_mcq_enabled(hba) && !prev_state && new_state) { /* - * Auto-hibernation will be enabled for legacy UFSHCI mode. + * Auto-hibernation will be enabled for legacy UFSHCI mode. Tell + * the block layer that write requests may be reordered. */ ret = ufshcd_update_preserves_write_order(hba, false); if (ret) @@ -4479,7 +4494,8 @@ int ufshcd_auto_hibern8_update(struct ufs_hba *hba, u32 ahit) } if (!is_mcq_enabled(hba) && prev_state && !new_state) { /* - * Auto-hibernation has been disabled. + * Auto-hibernation has been disabled. Tell the block layer that + * the order of write requests is preserved. */ ret = ufshcd_update_preserves_write_order(hba, true); WARN_ON_ONCE(ret); @@ -5247,6 +5263,10 @@ static int ufshcd_slave_configure(struct scsi_device *sdev) struct ufs_hba *hba = shost_priv(sdev->host); struct request_queue *q = sdev->request_queue; + q->limits.driver_preserves_write_order = + !ufshcd_is_auto_hibern8_supported(hba) || + FIELD_GET(UFSHCI_AHIBERN8_TIMER_MASK, hba->ahit) == 0; + blk_queue_update_dma_pad(q, PRDT_DATA_BYTE_COUNT_PAD - 1); /* @@ -9026,6 +9046,7 @@ static const struct scsi_host_template ufshcd_driver_template = { .max_host_blocked = 1, .track_queue_depth = 1, .skip_settle_delay = 1, + .needs_prepare_resubmit = 1, .sdev_groups = ufshcd_driver_groups, .rpm_autosuspend_delay = RPM_AUTOSUSPEND_DELAY_MS, };