From patchwork Tue Oct 17 20:47: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: 13426071 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 5E73CC46CA1 for ; Tue, 17 Oct 2023 20:48:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234861AbjJQUsU (ORCPT ); Tue, 17 Oct 2023 16:48:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230056AbjJQUsT (ORCPT ); Tue, 17 Oct 2023 16:48:19 -0400 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70C2CED; Tue, 17 Oct 2023 13:48:18 -0700 (PDT) Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-6b709048f32so3130633b3a.0; Tue, 17 Oct 2023 13:48:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575698; x=1698180498; 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=yoHPYDQbTkwUBMMunMv9kXgtGCryiEzUWGYqg25wuEw=; b=S+3GwpSZI88XIlFDGt7RMfiqSVDPkaZp+yMnkM0kPsx+MZDc6xZIH/2DBmxVwuGSHk n/G4KQIu8vc+LazMn0yBmmRgVhGB2UGdZ4nzJnRqZhuuCodJv5dOANEzVXsczEzSLn0V k5kp9ZV8rlSD9CsmVhMvBW1Pj3aiJK+Y0T+Ng5OTeeiab612tXZ8Sfe+KImPxwERW1mi 2OkiPBfzvSnuIBw28yFTQD7YxE4gmGFI38c1KgrgywSzaKL0Qbx3ClF6Cdzp6bvMH6jw bLXyiodnz/lB5vs71SS8VSzhpF3p1YCZ3E42gf473gqfsZSm4PIRO1zOHayFbaoyj/lD mpWA== X-Gm-Message-State: AOJu0YxRFuZ8bYFhpVw5k5dP7LwU0yxGJgtdEx3doUUr7Hf0lEcNm28M 6CXncvD8Fazp8Ydau268C88= X-Google-Smtp-Source: AGHT+IGGo232JgEpvGCW1xTE/zif4CZSXY7EyIlhzXdDHgWYzLvrFd1xG6e4xQ2gZEvytT8a+UK0wg== X-Received: by 2002:a05:6a00:230b:b0:68b:c562:da65 with SMTP id h11-20020a056a00230b00b0068bc562da65mr3422101pfh.26.1697575697688; Tue, 17 Oct 2023 13:48:17 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:17 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Jan Kara , Christian Brauner , Jaegeuk Kim , Chao Yu , Alexander Viro , Jeff Layton , Chuck Lever Subject: [PATCH v3 01/14] fs: Move enum rw_hint into a new header file Date: Tue, 17 Oct 2023 13:47:09 -0700 Message-ID: <20231017204739.3409052-2-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Move enum rw_hint into a new header file to prepare for using this data type in the block layer. Add the attribute __packed to reduce the space occupied by instances of this data type from four bytes to one byte. Change the data type of i_write_hint from u8 into enum rw_hint. Change the RWH_* constants into literal constants to prevent that would have to be included. Cc: Jan Kara Cc: Christoph Hellwig Cc: Christian Brauner Signed-off-by: Bart Van Assche --- fs/f2fs/f2fs.h | 1 + fs/fcntl.c | 1 + fs/inode.c | 1 + include/linux/fs.h | 16 ++-------------- include/linux/rw_hint.h | 20 ++++++++++++++++++++ 5 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 include/linux/rw_hint.h diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 6d688e42d89c..56ee7fff55c7 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include diff --git a/fs/fcntl.c b/fs/fcntl.c index e871009f6c88..ed923640aecf 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include diff --git a/fs/inode.c b/fs/inode.c index 84bc3c76e5cc..ebcc41ac9682 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "internal.h" diff --git a/include/linux/fs.h b/include/linux/fs.h index b528f063e8ff..971f0bafa782 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -309,19 +310,6 @@ struct address_space; struct writeback_control; struct readahead_control; -/* - * Write life time hint values. - * Stored in struct inode as u8. - */ -enum rw_hint { - WRITE_LIFE_NOT_SET = 0, - WRITE_LIFE_NONE = RWH_WRITE_LIFE_NONE, - WRITE_LIFE_SHORT = RWH_WRITE_LIFE_SHORT, - WRITE_LIFE_MEDIUM = RWH_WRITE_LIFE_MEDIUM, - WRITE_LIFE_LONG = RWH_WRITE_LIFE_LONG, - WRITE_LIFE_EXTREME = RWH_WRITE_LIFE_EXTREME, -}; - /* Match RWF_* bits to IOCB bits */ #define IOCB_HIPRI (__force int) RWF_HIPRI #define IOCB_DSYNC (__force int) RWF_DSYNC @@ -677,7 +665,7 @@ struct inode { spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ unsigned short i_bytes; u8 i_blkbits; - u8 i_write_hint; + enum rw_hint i_write_hint; blkcnt_t i_blocks; #ifdef __NEED_I_SIZE_ORDERED diff --git a/include/linux/rw_hint.h b/include/linux/rw_hint.h new file mode 100644 index 000000000000..4a7d28945973 --- /dev/null +++ b/include/linux/rw_hint.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_RW_HINT_H +#define _LINUX_RW_HINT_H + +#include +#include + +/* Block storage write lifetime hint values. */ +enum rw_hint { + WRITE_LIFE_NOT_SET = 0, /* RWH_WRITE_LIFE_NOT_SET */ + WRITE_LIFE_NONE = 1, /* RWH_WRITE_LIFE_NONE */ + WRITE_LIFE_SHORT = 2, /* RWH_WRITE_LIFE_SHORT */ + WRITE_LIFE_MEDIUM = 3, /* RWH_WRITE_LIFE_MEDIUM */ + WRITE_LIFE_LONG = 4, /* RWH_WRITE_LIFE_LONG */ + WRITE_LIFE_EXTREME = 5, /* RWH_WRITE_LIFE_EXTREME */ +} __packed; + +static_assert(sizeof(enum rw_hint) == 1); + +#endif /* _LINUX_RW_HINT_H */ From patchwork Tue Oct 17 20:47: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: 13426073 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 0CCC2CDB482 for ; Tue, 17 Oct 2023 20:48:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234963AbjJQUsY (ORCPT ); Tue, 17 Oct 2023 16:48:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234920AbjJQUsW (ORCPT ); Tue, 17 Oct 2023 16:48:22 -0400 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28C73F0; Tue, 17 Oct 2023 13:48:20 -0700 (PDT) Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-6bd04558784so4295711a34.3; Tue, 17 Oct 2023 13:48:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575699; x=1698180499; 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=0zKJwlNU37xBJ2eHozPULDjMADCdbgGWOVklVioEvRw=; b=Gxlro9T61b1KesibqkjGemRoap/RNCyK/8Ee2ueiuBbn/a3JD2GtbtESncvg9wEgCP snXF6aOXfo2/cwlBdWmc5qPXRdjDxokeB7+zqkYYJMC3/lGzfRyXaVmM+daR0bqJLnwV uWpBSTZuQ+OYIPnNKgLGcKrv5yaoQ06TI/lO1sSdhZL5aoi1jlW1Z7HyODyWXA5bPiHP vk/PEzDKHaWDMqxdohrtAvUKEMdU5CIIc4dSced8/EuqWcJ2BFIitSwa2H+VO/26ADok C6P31FC24jakwi9xd/Xq+ltKRjzyqGF4dh4VxTEi/23CWsZcCCKKojTJhtabR7q5Go/c jbwg== X-Gm-Message-State: AOJu0Yz8w6FtUUwwxK1cZCwEBPMl0uCBENN5j9wqoEB7QfSMTsQvXJ9a qnJbo+navUeVtw6gI+DUHig= X-Google-Smtp-Source: AGHT+IEE6N0vYqYBGbaDDPav+vLSuM2Vwj8TQAV4LWIeBTn/WK/tEcpCesHGpwI+JsErwXCHOyTl/g== X-Received: by 2002:a9d:4811:0:b0:6c4:fc45:8681 with SMTP id c17-20020a9d4811000000b006c4fc458681mr3499731otf.25.1697575699367; Tue, 17 Oct 2023 13:48:19 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:19 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Damien Le Moal Subject: [PATCH v3 02/14] block: Restore data lifetime support in struct bio and struct request Date: Tue, 17 Oct 2023 13:47:10 -0700 Message-ID: <20231017204739.3409052-3-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Provide a mechanism for filesystems to pass data lifetime information to block drivers. Data lifetime information can be used by block devices with append/erase storage technology (NAND flash) to reduce garbage collection activity. This patch restores a subset of the functionality that was removed by commit c75e707fe1aa ("block: remove the per-bio/request write hint"). Cc: Christoph Hellwig Cc: Damien Le Moal Signed-off-by: Bart Van Assche --- block/bio.c | 2 ++ block/blk-crypto-fallback.c | 1 + block/blk-merge.c | 6 ++++++ block/blk-mq.c | 1 + block/bounce.c | 1 + include/linux/blk-mq.h | 2 ++ include/linux/blk_types.h | 2 ++ 7 files changed, 15 insertions(+) diff --git a/block/bio.c b/block/bio.c index 816d412c06e9..1a3733635079 100644 --- a/block/bio.c +++ b/block/bio.c @@ -251,6 +251,7 @@ void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table, bio->bi_opf = opf; bio->bi_flags = 0; bio->bi_ioprio = 0; + bio->bi_lifetime = 0; bio->bi_status = 0; bio->bi_iter.bi_sector = 0; bio->bi_iter.bi_size = 0; @@ -813,6 +814,7 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp) { bio_set_flag(bio, BIO_CLONED); bio->bi_ioprio = bio_src->bi_ioprio; + bio->bi_lifetime = bio_src->bi_lifetime; bio->bi_iter = bio_src->bi_iter; if (bio->bi_bdev) { diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c index e6468eab2681..e25a6d551594 100644 --- a/block/blk-crypto-fallback.c +++ b/block/blk-crypto-fallback.c @@ -172,6 +172,7 @@ static struct bio *blk_crypto_fallback_clone_bio(struct bio *bio_src) if (bio_flagged(bio_src, BIO_REMAPPED)) bio_set_flag(bio, BIO_REMAPPED); bio->bi_ioprio = bio_src->bi_ioprio; + bio->bi_lifetime = bio_src->bi_lifetime; bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; diff --git a/block/blk-merge.c b/block/blk-merge.c index 65e75efa9bd3..62718cc871bd 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -814,6 +814,9 @@ static struct request *attempt_merge(struct request_queue *q, if (rq_data_dir(req) != rq_data_dir(next)) return NULL; + if (req->lifetime != next->lifetime) + return NULL; + if (req->ioprio != next->ioprio) return NULL; @@ -941,6 +944,9 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) if (!bio_crypt_rq_ctx_compatible(rq, bio)) return false; + if (rq->lifetime != bio->bi_lifetime) + return NULL; + if (rq->ioprio != bio_prio(bio)) return false; diff --git a/block/blk-mq.c b/block/blk-mq.c index a815403f375c..10540a3b3c49 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3148,6 +3148,7 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src, } rq->nr_phys_segments = rq_src->nr_phys_segments; rq->ioprio = rq_src->ioprio; + rq->lifetime = rq_src->lifetime; if (rq->bio && blk_crypto_rq_bio_prep(rq, rq->bio, gfp_mask) < 0) goto free_and_out; diff --git a/block/bounce.c b/block/bounce.c index 7cfcb242f9a1..b03e4944ace8 100644 --- a/block/bounce.c +++ b/block/bounce.c @@ -169,6 +169,7 @@ static struct bio *bounce_clone_bio(struct bio *bio_src) if (bio_flagged(bio_src, BIO_REMAPPED)) bio_set_flag(bio, BIO_REMAPPED); bio->bi_ioprio = bio_src->bi_ioprio; + bio->bi_lifetime = bio_src->bi_lifetime; bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 1ab3081c82ed..1afd731432fe 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -136,6 +136,7 @@ struct request { #endif unsigned short ioprio; + enum rw_hint lifetime; enum mq_rq_state state; atomic_t ref; @@ -957,6 +958,7 @@ static inline void blk_rq_bio_prep(struct request *rq, struct bio *bio, rq->__data_len = bio->bi_iter.bi_size; rq->bio = rq->biotail = bio; rq->ioprio = bio_prio(bio); + rq->lifetime = bio->bi_lifetime; } void blk_mq_hctx_set_fq_lock_class(struct blk_mq_hw_ctx *hctx, diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index d5c5e59ddbd2..5e21f44141fb 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -10,6 +10,7 @@ #include #include #include +#include struct bio_set; struct bio; @@ -269,6 +270,7 @@ struct bio { */ unsigned short bi_flags; /* BIO_* below */ unsigned short bi_ioprio; + enum rw_hint bi_lifetime; /* data lifetime */ blk_status_t bi_status; atomic_t __bi_remaining; From patchwork Tue Oct 17 20:47: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: 13426072 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 D85AEC41513 for ; Tue, 17 Oct 2023 20:48:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343653AbjJQUsY (ORCPT ); Tue, 17 Oct 2023 16:48:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234986AbjJQUsX (ORCPT ); Tue, 17 Oct 2023 16:48:23 -0400 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E887ABA; Tue, 17 Oct 2023 13:48:21 -0700 (PDT) Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-57b8cebf57dso3235119eaf.0; Tue, 17 Oct 2023 13:48:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575701; x=1698180501; 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=oerpJ9CuDBWq3MQr5Gs8nB1eNmQFO47LyUbsIakiSyk=; b=uarBHyufmoRNgv+FCRjM0PD8d5MX0iAS8XV72qePPUaK3JI179fP//MUuIGO8kaYpl 731IlX9ynjYK8QBrnLYca6X0HD10VCnauv73VqgjHp1VXPucE0svq7iQwbUgAUvzx+i1 mpQZKne9IgqLLTlGy/br3u+X7si/rr5yNVeOdjuid4n8Zkg4TEMjxm5H0Le/ytKUFRA3 IS4RFosUrqIIPgYaIZQDVydmgPA2zKzP+VyQSCQgVgig1gyHGRu80UNwYD11/Qr8U3HW viw7HZUFnuoUOWeJHrLCrGbomywtEmUOsfVnp12+fUgBY0/wBOvPgl4ossLqrZFuWkv5 au0Q== X-Gm-Message-State: AOJu0Yy16A0u8WkrqWDrKVYt+3w7qr/MaPz46iRz3c9WwzLVb6F6YEA/ 7Z/PCYbxVDbnu1o1xmpYBSc= X-Google-Smtp-Source: AGHT+IHSHy1lg+QFVKlHSx9HOjVcNCKEh+vRH955EmvGGpVXCsX5+UmwP8rcx8afz6dKZUCiv8ZpXw== X-Received: by 2002:a05:6358:3106:b0:166:e1cc:bc27 with SMTP id c6-20020a056358310600b00166e1ccbc27mr2588671rwe.10.1697575701087; Tue, 17 Oct 2023 13:48:21 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:20 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Jan Kara , Christian Brauner , "Darrick J. Wong" , Alexander Viro Subject: [PATCH v3 03/14] fs: Restore write hint support Date: Tue, 17 Oct 2023 13:47:11 -0700 Message-ID: <20231017204739.3409052-4-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Initialize the bio lifetime to the data lifetime information that is available in struct inode. This patch reverts a small subset of commit c75e707fe1aa ("block: remove the per-bio/request write hint"). Cc: Jan Kara Cc: Christoph Hellwig Cc: Christian Brauner Signed-off-by: Bart Van Assche --- block/fops.c | 3 +++ fs/iomap/buffered-io.c | 2 ++ fs/iomap/direct-io.c | 1 + fs/mpage.c | 1 + 4 files changed, 7 insertions(+) diff --git a/block/fops.c b/block/fops.c index acff3d5d22d4..c9ca9f0fd48f 100644 --- a/block/fops.c +++ b/block/fops.c @@ -74,6 +74,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, } bio.bi_iter.bi_sector = pos >> SECTOR_SHIFT; bio.bi_ioprio = iocb->ki_ioprio; + bio.bi_lifetime = iocb->ki_filp->f_inode->i_write_hint; ret = bio_iov_iter_get_pages(&bio, iter); if (unlikely(ret)) @@ -206,6 +207,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, bio->bi_private = dio; bio->bi_end_io = blkdev_bio_end_io; bio->bi_ioprio = iocb->ki_ioprio; + bio->bi_lifetime = iocb->ki_filp->f_inode->i_write_hint; ret = bio_iov_iter_get_pages(bio, iter); if (unlikely(ret)) { @@ -323,6 +325,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, bio->bi_iter.bi_sector = pos >> SECTOR_SHIFT; bio->bi_end_io = blkdev_bio_end_io_async; bio->bi_ioprio = iocb->ki_ioprio; + bio->bi_lifetime = iocb->ki_filp->f_inode->i_write_hint; if (iov_iter_is_bvec(iter)) { /* diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 644479ccefbd..fe82c8882c62 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1660,6 +1660,7 @@ iomap_alloc_ioend(struct inode *inode, struct iomap_writepage_ctx *wpc, REQ_OP_WRITE | wbc_to_write_flags(wbc), GFP_NOFS, &iomap_ioend_bioset); bio->bi_iter.bi_sector = sector; + bio->bi_lifetime = inode->i_write_hint; wbc_init_bio(wbc, bio); ioend = container_of(bio, struct iomap_ioend, io_inline_bio); @@ -1690,6 +1691,7 @@ iomap_chain_bio(struct bio *prev) new = bio_alloc(prev->bi_bdev, BIO_MAX_VECS, prev->bi_opf, GFP_NOFS); bio_clone_blkg_association(new, prev); new->bi_iter.bi_sector = bio_end_sector(prev); + new->bi_lifetime = prev->bi_lifetime; bio_chain(prev, new); bio_get(prev); /* for iomap_finish_ioend */ diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index bcd3f8cf5ea4..df095b9700a7 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -381,6 +381,7 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, GFP_KERNEL); bio->bi_iter.bi_sector = iomap_sector(iomap, pos); bio->bi_ioprio = dio->iocb->ki_ioprio; + bio->bi_lifetime = dio->iocb->ki_filp->f_inode->i_write_hint; bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; diff --git a/fs/mpage.c b/fs/mpage.c index 242e213ee064..19b7ced1a9aa 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -612,6 +612,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, GFP_NOFS); bio->bi_iter.bi_sector = blocks[0] << (blkbits - 9); wbc_init_bio(wbc, bio); + bio->bi_lifetime = inode->i_write_hint; } /* From patchwork Tue Oct 17 20:47: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: 13426074 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 3CE68CDB474 for ; Tue, 17 Oct 2023 20:48:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344167AbjJQUsb (ORCPT ); Tue, 17 Oct 2023 16:48:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343908AbjJQUsZ (ORCPT ); Tue, 17 Oct 2023 16:48:25 -0400 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A56CC6; Tue, 17 Oct 2023 13:48:23 -0700 (PDT) Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1ca74e77aecso20602815ad.1; Tue, 17 Oct 2023 13:48:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575703; x=1698180503; 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=m+VQXOryPBR0w8OfYGjgYJWwAn5XaqF9GFf/iAaLAsQ=; b=OCZ3j4AOl9qNB9nFhw0cr57K8l8V670gFw9vK+O7jA+mCNn7i6Lt4Ahm4tWvDzm4BQ d0GzEibgsAn4bDlMrEae7IJZi71UjV10aOnSGBUk0IGaxDZKlMCBn1oHnq6SNlY7RbTH tRTVkciDiScRLcSjwymtYEQoq9n6/Wk8gGoupRUIKBmhHDAgWdvNF5TYm4q/uH95kTMj TNLsIx0bSbSOwRLLiW5Ozcn1SOch3UujE7uXpa3GHhJi5oU2xx6+VWq+BLoWAEql/aRq dP+lAbEem4PQCqGYH12CPJGOaodS8CkX/NzQZogn7XyX6IvyLS8G58IsJ4dFWd4fs2/r LnxQ== X-Gm-Message-State: AOJu0YyUH5+xz9rgV5eMBgBZA1Yc3FKiYtxeCUzFLV48TpJiToI2rCRT YUg36dhoePp7mRqE5hFyo5w= X-Google-Smtp-Source: AGHT+IGxj8k+Wf+TuS/3SI/H1kAqB/XVRY2YjyO9eAbl5kLOqsRSOSoUZXbQaHQDwAOj1fGmcP1PLQ== X-Received: by 2002:a17:903:2287:b0:1c9:dac0:fbc2 with SMTP id b7-20020a170903228700b001c9dac0fbc2mr4812720plh.13.1697575702834; Tue, 17 Oct 2023 13:48:22 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:22 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Avri Altman , Bean Huo , Jaegeuk Kim , Chao Yu , Jonathan Corbet Subject: [PATCH v3 04/14] fs/f2fs: Restore data lifetime support Date: Tue, 17 Oct 2023 13:47:12 -0700 Message-ID: <20231017204739.3409052-5-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Restore support for the whint_mode mount option by reverting commit 930e2607638d ("f2fs: remove obsolete whint_mode"). Additionally, restore the bio->bi_lifetime assignment in __bio_alloc() that was removed by commit c75e707fe1aa ("block: remove the per-bio/request write hint"). Cc: Avri Altman Cc: Bean Huo Cc: Daejun Park Cc: Jaegeuk Kim Cc: Chao Yu Signed-off-by: Bart Van Assche --- Documentation/filesystems/f2fs.rst | 70 ++++++++++++++++++++++ fs/f2fs/data.c | 2 + fs/f2fs/f2fs.h | 9 +++ fs/f2fs/segment.c | 95 ++++++++++++++++++++++++++++++ fs/f2fs/super.c | 32 +++++++++- 5 files changed, 207 insertions(+), 1 deletion(-) diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst index d32c6209685d..de412ddebcc8 100644 --- a/Documentation/filesystems/f2fs.rst +++ b/Documentation/filesystems/f2fs.rst @@ -242,6 +242,12 @@ offgrpjquota Turn off group journalled quota. offprjjquota Turn off project journalled quota. quota Enable plain user disk quota accounting. noquota Disable all plain disk quota option. +whint_mode=%s Control which write hints are passed down to block + layer. This supports "off", "user-based", and + "fs-based". In "off" mode (default), f2fs does not pass + down hints. In "user-based" mode, f2fs tries to pass + down hints given by users. And in "fs-based" mode, f2fs + passes down hints with its policy. alloc_mode=%s Adjust block allocation policy, which supports "reuse" and "default". fsync_mode=%s Control the policy of fsync. Currently supports "posix", @@ -776,6 +782,70 @@ In order to identify whether the data in the victim segment are valid or not, F2FS manages a bitmap. Each bit represents the validity of a block, and the bitmap is composed of a bit stream covering whole blocks in main area. +Write-hint Policy +----------------- + +1) whint_mode=off. F2FS only passes down WRITE_LIFE_NOT_SET. + +2) whint_mode=user-based. F2FS tries to pass down hints given by +users. + +===================== ======================== =================== +User F2FS Block +===================== ======================== =================== +N/A META WRITE_LIFE_NOT_SET +N/A HOT_NODE " +N/A WARM_NODE " +N/A COLD_NODE " +ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME +extension list " " + +-- buffered io +WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME +WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT +WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET +WRITE_LIFE_NONE " " +WRITE_LIFE_MEDIUM " " +WRITE_LIFE_LONG " " + +-- direct io +WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME +WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT +WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET +WRITE_LIFE_NONE " WRITE_LIFE_NONE +WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM +WRITE_LIFE_LONG " WRITE_LIFE_LONG +===================== ======================== =================== + +3) whint_mode=fs-based. F2FS passes down hints with its policy. + +===================== ======================== =================== +User F2FS Block +===================== ======================== =================== +N/A META WRITE_LIFE_MEDIUM; +N/A HOT_NODE WRITE_LIFE_NOT_SET +N/A WARM_NODE " +N/A COLD_NODE WRITE_LIFE_NONE +ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME +extension list " " + +-- buffered io +WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME +WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT +WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_LONG +WRITE_LIFE_NONE " " +WRITE_LIFE_MEDIUM " " +WRITE_LIFE_LONG " " + +-- direct io +WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME +WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT +WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET +WRITE_LIFE_NONE " WRITE_LIFE_NONE +WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM +WRITE_LIFE_LONG " WRITE_LIFE_LONG +===================== ======================== =================== + Fallocate(2) Policy ------------------- diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 916e317ac925..4a5edb9a1a1e 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -478,6 +478,8 @@ static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages) } else { bio->bi_end_io = f2fs_write_end_io; bio->bi_private = sbi; + bio->bi_lifetime = f2fs_io_type_to_rw_hint(sbi, fio->type, + fio->temp); } iostat_alloc_and_bind_ctx(sbi, bio, NULL); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 56ee7fff55c7..8d408afb044b 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -158,6 +158,7 @@ struct f2fs_mount_info { int s_jquota_fmt; /* Format of quota to use */ #endif /* For which write hints are passed down to block layer */ + int whint_mode; int alloc_mode; /* segment allocation policy */ int fsync_mode; /* fsync policy */ int fs_mode; /* fs mode: LFS or ADAPTIVE */ @@ -1344,6 +1345,12 @@ enum { FS_MODE_FRAGMENT_BLK, /* block fragmentation mode */ }; +enum { + WHINT_MODE_OFF, /* not pass down write hints */ + WHINT_MODE_USER, /* try to pass down hints given by users */ + WHINT_MODE_FS, /* pass down hints with F2FS policy */ +}; + enum { ALLOC_MODE_DEFAULT, /* stay default */ ALLOC_MODE_REUSE, /* reuse segments as much as possible */ @@ -3728,6 +3735,8 @@ void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi); int __init f2fs_create_segment_manager_caches(void); void f2fs_destroy_segment_manager_caches(void); int f2fs_rw_hint_to_seg_type(enum rw_hint hint); +enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi, + enum page_type type, enum temp_type temp); unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi, unsigned int segno); unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi, diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index d05b41608fc0..38c0cb8d9571 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3290,6 +3290,101 @@ int f2fs_rw_hint_to_seg_type(enum rw_hint hint) } } +/* This returns write hints for each segment type. This hints will be + * passed down to block layer. There are mapping tables which depend on + * the mount option 'whint_mode'. + * + * 1) whint_mode=off. F2FS only passes down WRITE_LIFE_NOT_SET. + * + * 2) whint_mode=user-based. F2FS tries to pass down hints given by users. + * + * User F2FS Block + * ---- ---- ----- + * META WRITE_LIFE_NOT_SET + * HOT_NODE " + * WARM_NODE " + * COLD_NODE " + * ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME + * extension list " " + * + * -- buffered io + * WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME + * WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT + * WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET + * WRITE_LIFE_NONE " " + * WRITE_LIFE_MEDIUM " " + * WRITE_LIFE_LONG " " + * + * -- direct io + * WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME + * WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT + * WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET + * WRITE_LIFE_NONE " WRITE_LIFE_NONE + * WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM + * WRITE_LIFE_LONG " WRITE_LIFE_LONG + * + * 3) whint_mode=fs-based. F2FS passes down hints with its policy. + * + * User F2FS Block + * ---- ---- ----- + * META WRITE_LIFE_MEDIUM; + * HOT_NODE WRITE_LIFE_NOT_SET + * WARM_NODE " + * COLD_NODE WRITE_LIFE_NONE + * ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME + * extension list " " + * + * -- buffered io + * WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME + * WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT + * WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_LONG + * WRITE_LIFE_NONE " " + * WRITE_LIFE_MEDIUM " " + * WRITE_LIFE_LONG " " + * + * -- direct io + * WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME + * WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT + * WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET + * WRITE_LIFE_NONE " WRITE_LIFE_NONE + * WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM + * WRITE_LIFE_LONG " WRITE_LIFE_LONG + */ + +enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi, + enum page_type type, enum temp_type temp) +{ + if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_USER) { + if (type == DATA) { + if (temp == WARM) + return WRITE_LIFE_NOT_SET; + else if (temp == HOT) + return WRITE_LIFE_SHORT; + else if (temp == COLD) + return WRITE_LIFE_EXTREME; + } else { + return WRITE_LIFE_NOT_SET; + } + } else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS) { + if (type == DATA) { + if (temp == WARM) + return WRITE_LIFE_LONG; + else if (temp == HOT) + return WRITE_LIFE_SHORT; + else if (temp == COLD) + return WRITE_LIFE_EXTREME; + } else if (type == NODE) { + if (temp == WARM || temp == HOT) + return WRITE_LIFE_NOT_SET; + else if (temp == COLD) + return WRITE_LIFE_NONE; + } else if (type == META) { + return WRITE_LIFE_MEDIUM; + } + } + return WRITE_LIFE_NOT_SET; +} + static int __get_segment_type_2(struct f2fs_io_info *fio) { if (fio->type == DATA) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index a8c8232852bb..5bb062075acf 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -141,6 +141,7 @@ enum { Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, + Opt_whint, Opt_alloc, Opt_fsync, Opt_test_dummy_encryption, @@ -220,6 +221,7 @@ static match_table_t f2fs_tokens = { {Opt_jqfmt_vfsold, "jqfmt=vfsold"}, {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"}, + {Opt_whint, "whint_mode=%s"}, {Opt_alloc, "alloc_mode=%s"}, {Opt_fsync, "fsync_mode=%s"}, {Opt_test_dummy_encryption, "test_dummy_encryption=%s"}, @@ -988,6 +990,22 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount) f2fs_info(sbi, "quota operations not supported"); break; #endif + case Opt_whint: + name = match_strdup(&args[0]); + if (!name) + return -ENOMEM; + if (!strcmp(name, "user-based")) { + F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER; + } else if (!strcmp(name, "off")) { + F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; + } else if (!strcmp(name, "fs-based")) { + F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS; + } else { + kfree(name); + return -EINVAL; + } + kfree(name); + break; case Opt_alloc: name = match_strdup(&args[0]); if (!name) @@ -1389,6 +1407,12 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount) return -EINVAL; } + /* Not pass down write hints if the number of active logs is lesser + * than NR_CURSEG_PERSIST_TYPE. + */ + if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_PERSIST_TYPE) + F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; + if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) { f2fs_err(sbi, "Allow to mount readonly mode only"); return -EROFS; @@ -2060,6 +2084,10 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root) seq_puts(seq, ",prjquota"); #endif f2fs_show_quota_options(seq, sbi->sb); + if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_USER) + seq_printf(seq, ",whint_mode=%s", "user-based"); + else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS) + seq_printf(seq, ",whint_mode=%s", "fs-based"); fscrypt_show_test_dummy_encryption(seq, ',', sbi->sb); @@ -2129,6 +2157,7 @@ static void default_options(struct f2fs_sb_info *sbi, bool remount) F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE; F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS; + F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; if (le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_main) <= SMALL_VOLUME_SEGMENTS) F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; @@ -2443,7 +2472,8 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) need_stop_gc = true; } - if (*flags & SB_RDONLY) { + if (*flags & SB_RDONLY || + F2FS_OPTION(sbi).whint_mode != org_mount_opt.whint_mode) { sync_inodes_sb(sb); set_sbi_flag(sbi, SBI_IS_DIRTY); From patchwork Tue Oct 17 20:47: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: 13426075 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 6FB96CDB474 for ; Tue, 17 Oct 2023 20:48:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344148AbjJQUsd (ORCPT ); Tue, 17 Oct 2023 16:48:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344172AbjJQUs1 (ORCPT ); Tue, 17 Oct 2023 16:48:27 -0400 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51AE79F; Tue, 17 Oct 2023 13:48:25 -0700 (PDT) Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-581b6b93bd1so1541938eaf.1; Tue, 17 Oct 2023 13:48:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575704; x=1698180504; 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=29C1aI2A2KGCyq9yUe4PdFSu3conZ39y3j9E4Fn9lFo=; b=j9LncJK8KKfvkioT8Q21lW79nOTP87JFPP2ux04k12QwwkUYgQauzAKlrpumiLyrUs 3s3eEnl3zD9gAhXtrDD31CC5g0d6MyMN7ezjBWtPs7rxV0vlsJNDDOQb/igQ+hPp1/zT XZKtA9C5xj0JudsjDPxroeqxeoMFD9DrUL0n0kFNT3Dbz4roBuPqM5UmRAC0oKljTi51 y3A2qKleolR06oY/9+iBLIIC2iLX86p8pOJySbEldtLy4Y3vv7Iz22MbombjFRbsFu2t AotsXJkKXg/tSp4e/Wa29aYNuIw5bubPIUzWFiZJsOQiO/rQXMQrAFHnDYHyeyRc/7iF taZg== X-Gm-Message-State: AOJu0Yzo4wk3eyWUJO625J8RqB9ZVHT63Jf5ych9/YkS3ri9LCuGIlVH Y6fMJWMwDy36FdihykkkTtk= X-Google-Smtp-Source: AGHT+IGsmXt7VpkLw0tEtaclHjsoZRsI/bJIG6ugvFa+zQMCcSze01pj0EjA5AExdkd8s3WJ4VSHUg== X-Received: by 2002:a05:6358:c62a:b0:166:ce95:7122 with SMTP id fd42-20020a056358c62a00b00166ce957122mr3802323rwb.14.1697575704430; Tue, 17 Oct 2023 13:48:24 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:24 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Avri Altman , "James E.J. Bottomley" Subject: [PATCH v3 05/14] scsi: core: Query the Block Limits Extension VPD page Date: Tue, 17 Oct 2023 13:47:13 -0700 Message-ID: <20231017204739.3409052-6-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Parse the Reduced Stream Control Supported (RSCS) bit from the block limits extension VPD page. The RSCS bit is defined in SBC-5 r05 (https://www.t10.org/cgi-bin/ac.pl?t=f&f=sbc5r05.pdf). Reviewed-by: Avri Altman Reviewed-by: Daejun Park Cc: Martin K. Petersen Signed-off-by: Bart Van Assche --- drivers/scsi/scsi.c | 2 ++ drivers/scsi/scsi_sysfs.c | 10 ++++++++++ drivers/scsi/sd.c | 13 +++++++++++++ drivers/scsi/sd.h | 1 + include/scsi/scsi_device.h | 1 + 5 files changed, 27 insertions(+) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index d0911bc28663..5ad291770806 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -499,6 +499,8 @@ void scsi_attach_vpd(struct scsi_device *sdev) scsi_update_vpd_page(sdev, 0xb1, &sdev->vpd_pgb1); if (vpd_buf->data[i] == 0xb2) scsi_update_vpd_page(sdev, 0xb2, &sdev->vpd_pgb2); + if (vpd_buf->data[i] == 0xb7) + scsi_update_vpd_page(sdev, 0xb7, &sdev->vpd_pgb7); } kfree(vpd_buf); } diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 24f6eefb6803..93652a786a46 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -449,6 +449,7 @@ static void scsi_device_dev_release(struct device *dev) struct scsi_vpd *vpd_pg80 = NULL, *vpd_pg83 = NULL; struct scsi_vpd *vpd_pg0 = NULL, *vpd_pg89 = NULL; struct scsi_vpd *vpd_pgb0 = NULL, *vpd_pgb1 = NULL, *vpd_pgb2 = NULL; + struct scsi_vpd *vpd_pgb7 = NULL; unsigned long flags; might_sleep(); @@ -494,6 +495,8 @@ static void scsi_device_dev_release(struct device *dev) lockdep_is_held(&sdev->inquiry_mutex)); vpd_pgb2 = rcu_replace_pointer(sdev->vpd_pgb2, vpd_pgb2, lockdep_is_held(&sdev->inquiry_mutex)); + vpd_pgb7 = rcu_replace_pointer(sdev->vpd_pgb7, vpd_pgb7, + lockdep_is_held(&sdev->inquiry_mutex)); mutex_unlock(&sdev->inquiry_mutex); if (vpd_pg0) @@ -510,6 +513,8 @@ static void scsi_device_dev_release(struct device *dev) kfree_rcu(vpd_pgb1, rcu); if (vpd_pgb2) kfree_rcu(vpd_pgb2, rcu); + if (vpd_pgb7) + kfree_rcu(vpd_pgb7, rcu); kfree(sdev->inquiry); kfree(sdev); @@ -921,6 +926,7 @@ sdev_vpd_pg_attr(pg89); sdev_vpd_pg_attr(pgb0); sdev_vpd_pg_attr(pgb1); sdev_vpd_pg_attr(pgb2); +sdev_vpd_pg_attr(pgb7); sdev_vpd_pg_attr(pg0); static ssize_t show_inquiry(struct file *filep, struct kobject *kobj, @@ -1295,6 +1301,9 @@ static umode_t scsi_sdev_bin_attr_is_visible(struct kobject *kobj, if (attr == &dev_attr_vpd_pgb2 && !sdev->vpd_pgb2) return 0; + if (attr == &dev_attr_vpd_pgb7 && !sdev->vpd_pgb7) + return 0; + return S_IRUGO; } @@ -1347,6 +1356,7 @@ static struct bin_attribute *scsi_sdev_bin_attrs[] = { &dev_attr_vpd_pgb0, &dev_attr_vpd_pgb1, &dev_attr_vpd_pgb2, + &dev_attr_vpd_pgb7, &dev_attr_inquiry, NULL }; diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index c92a317ba547..879edbc1a065 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3019,6 +3019,18 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) rcu_read_unlock(); } +/* Parse the Block Limits Extension VPD page (0xb7) */ +static void sd_read_block_limits_ext(struct scsi_disk *sdkp) +{ + struct scsi_vpd *vpd; + + rcu_read_lock(); + vpd = rcu_dereference(sdkp->device->vpd_pgb7); + if (vpd && vpd->len >= 2) + sdkp->rscs = vpd->data[5] & 1; + rcu_read_unlock(); +} + /** * sd_read_block_characteristics - Query block dev. characteristics * @sdkp: disk to query @@ -3373,6 +3385,7 @@ static int sd_revalidate_disk(struct gendisk *disk) if (scsi_device_supports_vpd(sdp)) { sd_read_block_provisioning(sdkp); sd_read_block_limits(sdkp); + sd_read_block_limits_ext(sdkp); sd_read_block_characteristics(sdkp); sd_zbc_read_zones(sdkp, buffer); sd_read_cpr(sdkp); diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 5eea762f84d1..84685168b6e0 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -150,6 +150,7 @@ struct scsi_disk { unsigned urswrz : 1; unsigned security : 1; unsigned ignore_medium_access_errors : 1; + bool rscs : 1; /* reduced stream control support */ }; #define to_scsi_disk(obj) container_of(obj, struct scsi_disk, disk_dev) diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index b9230b6add04..2dd96ae101e1 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -153,6 +153,7 @@ struct scsi_device { struct scsi_vpd __rcu *vpd_pgb0; struct scsi_vpd __rcu *vpd_pgb1; struct scsi_vpd __rcu *vpd_pgb2; + struct scsi_vpd __rcu *vpd_pgb7; struct scsi_target *sdev_target; From patchwork Tue Oct 17 20:47: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: 13426078 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 E12DDCDB485 for ; Tue, 17 Oct 2023 20:48:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344254AbjJQUsg (ORCPT ); Tue, 17 Oct 2023 16:48:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344190AbjJQUsa (ORCPT ); Tue, 17 Oct 2023 16:48:30 -0400 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97AA6FA; Tue, 17 Oct 2023 13:48:26 -0700 (PDT) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6b2018a11efso4280935b3a.0; Tue, 17 Oct 2023 13:48:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575706; x=1698180506; 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=T4k+JDqEcQkKs3J5VRs0ivCwgTJsm0PTpYm6Nj592ys=; b=RgkIRboai4lX0Xy1ylkKgXRKV77aYnylQsHi7S/6cqY7+KFBFp/Y4/O4leOYn5tEOY 5Sco1MCoVi8H6yw8EYNRMWahoQ7d7eHqTjtQjxI6hiTwBn405uLuMbZpm4dNKbR2DkhZ N6dZDvtO8Es0QLRsE5F41BC79q7dxN5cEF2C4pordmLtEKuFags5A56GlvzoVORWvRCf e1c8K60qUXsjprpxegBoULzGUdF9Bz0ke8pws3eU+9HwLQhOzGeCJwYr/EH2xoDNrtvD 1JCZsmPyQCjEa1MzQiwHK/yieQJmXVD9AVjfWOGx00pH8+PmtlaIhQzD1Sd/MMmuoGPN FC1Q== X-Gm-Message-State: AOJu0Yw/hmceKiDU81ZAMFE8/HQyfSh+rDz0kfUctcDaGZavEM8xhFx6 6/PIn7QU884ZRFPSh6PsRtUTDJXOCJo= X-Google-Smtp-Source: AGHT+IE9JmC7mnpFAERJjbxXj8433DA2LiY59WlVX6Lr+DI/sHn29bu/4VP2IM+dMqjwkD0A6kKnow== X-Received: by 2002:aa7:88ce:0:b0:6b1:c1c4:ae98 with SMTP id k14-20020aa788ce000000b006b1c1c4ae98mr3811496pff.18.1697575705851; Tue, 17 Oct 2023 13:48:25 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:25 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , "James E.J. Bottomley" Subject: [PATCH v3 06/14] scsi_proto: Add structures and constants related to I/O groups and streams Date: Tue, 17 Oct 2023 13:47:14 -0700 Message-ID: <20231017204739.3409052-7-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Prepare for adding code that will query the I/O advice hints group descriptors and for adding code that will retrieve the stream status. Cc: Martin K. Petersen Signed-off-by: Bart Van Assche --- include/scsi/scsi_proto.h | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index 07d65c1f59db..9ee4983c23b4 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -10,6 +10,7 @@ #ifndef _SCSI_PROTO_H_ #define _SCSI_PROTO_H_ +#include #include /* @@ -126,6 +127,7 @@ #define SAI_READ_CAPACITY_16 0x10 #define SAI_GET_LBA_STATUS 0x12 #define SAI_REPORT_REFERRALS 0x13 +#define SAI_GET_STREAM_STATUS 0x16 /* values for maintenance in */ #define MI_REPORT_IDENTIFYING_INFORMATION 0x05 #define MI_REPORT_TARGET_PGS 0x0a @@ -275,6 +277,79 @@ struct scsi_lun { __u8 scsi_lun[8]; }; +/* SBC-5 IO advice hints group descriptor */ +struct scsi_io_group_descriptor { +#if defined(__BIG_ENDIAN) + u8 io_advice_hints_mode: 2; + u8 reserved1: 3; + u8 st_enble: 1; + u8 cs_enble: 1; + u8 ic_enable: 1; +#elif defined(__LITTLE_ENDIAN) + u8 ic_enable: 1; + u8 cs_enble: 1; + u8 st_enble: 1; + u8 reserved1: 3; + u8 io_advice_hints_mode: 2; +#else +#error +#endif + u8 reserved2[3]; + /* Logical block markup descriptor */ +#if defined(__BIG_ENDIAN) + u8 acdlu: 1; + u8 reserved3: 1; + u8 rlbsr: 2; + u8 lbm_descriptor_type: 4; +#elif defined(__LITTLE_ENDIAN) + u8 lbm_descriptor_type: 4; + u8 rlbsr: 2; + u8 reserved3: 1; + u8 acdlu: 1; +#else +#error +#endif + u8 params[2]; + u8 reserved4; + u8 reserved5[8]; +}; + +static_assert(sizeof(struct scsi_io_group_descriptor) == 16); + +struct scsi_stream_status { +#if defined(__BIG_ENDIAN) + u16 perm: 1; + u16 reserved1: 15; +#elif defined(__LITTLE_ENDIAN) + u16 reserved1: 15; + u16 perm: 1; +#else +#error +#endif + __be16 stream_identifier; +#if defined(__BIG_ENDIAN) + u8 reserved2: 2; + u8 rel_lifetime: 6; +#elif defined(__LITTLE_ENDIAN) + u8 rel_lifetime: 6; + u8 reserved2: 2; +#else +#error +#endif + u8 reserved3[3]; +}; + +static_assert(sizeof(struct scsi_stream_status) == 8); + +struct scsi_stream_status_header { + __be32 len; /* length in bytes of stream_status[] array. */ + u16 reserved; + u16 number_of_open_streams; + DECLARE_FLEX_ARRAY(struct scsi_stream_status, stream_status); +}; + +static_assert(sizeof(struct scsi_stream_status_header) == 8); + /* SPC asymmetric access states */ #define SCSI_ACCESS_STATE_OPTIMAL 0x00 #define SCSI_ACCESS_STATE_ACTIVE 0x01 From patchwork Tue Oct 17 20:47: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: 13426076 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 85796C46CA1 for ; Tue, 17 Oct 2023 20:48:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344172AbjJQUsd (ORCPT ); Tue, 17 Oct 2023 16:48:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344205AbjJQUsb (ORCPT ); Tue, 17 Oct 2023 16:48:31 -0400 Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BA90FD; Tue, 17 Oct 2023 13:48:28 -0700 (PDT) Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-57b5ef5b947so4024827eaf.0; Tue, 17 Oct 2023 13:48:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575707; x=1698180507; 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=snz5ro7zX54Yit88zG0S8a/usk7R516A5R+TFp98aDM=; b=v0maQpMcQRPOi40H8irFX6VoOvYw4Z1xHulfjL9te0PxH0qfDQh5eDYe5sW7TsZR/p ZGy0MeO3mbm41AyRSpXZ11XmeVbFJWTrsUDBFxqXeNnaaGk+uLMLVFwkN75XIJUHQSH9 mdhz4K+lX5id7RQXEbi/bZmRinoRb9l7RIeIjBp0pPJW//hzbueJvpzCB1ZhjdMUHbwQ gI2NXsGAW8SrVNOWTnqkM0yLKLQv0SARVpxZqs6YypZ+/dlAs+sv3KT2qYr3moTx4kKj e8LK08x7wV8KVcaTfZg7gdkP5Z+qS/ureicyQDa8IBeftkWvzHVHkxlnYUQJ4Nd68oMz zL0g== X-Gm-Message-State: AOJu0YzAUBhxsUPPGwsC3qpKfmhYeYlYwwCxBOrDVFyc2x7zF24XSon7 ryubZvWBfcpu4LVM5bx3nIikt6LQzSw= X-Google-Smtp-Source: AGHT+IGqMw4FcKIR3vh9qvpNp78dRVEeU+DeJBToSujv3opQZcEfJFFvFq2/3QOn4wmXZwWnNx2csA== X-Received: by 2002:a05:6359:6604:b0:166:a6e3:cba5 with SMTP id sm4-20020a056359660400b00166a6e3cba5mr3168984rwb.2.1697575707302; Tue, 17 Oct 2023 13:48:27 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:26 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Damien Le Moal , "James E.J. Bottomley" Subject: [PATCH v3 07/14] sd: Translate data lifetime information Date: Tue, 17 Oct 2023 13:47:15 -0700 Message-ID: <20231017204739.3409052-8-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Recently T10 standardized SBC constrained streams. This mechanism allows to pass data lifetime information to SCSI devices in the group number field. Add support for translating write hint information into a permanent stream number in the sd driver. Use WRITE(10) instead of WRITE(6) if data lifetime information is present because the WRITE(6) command does not have a GROUP NUMBER field. Cc: Martin K. Petersen Cc: Christoph Hellwig Cc: Damien Le Moal Signed-off-by: Bart Van Assche --- drivers/scsi/sd.c | 98 +++++++++++++++++++++++++++++++++++++++++++++-- drivers/scsi/sd.h | 2 + 2 files changed, 97 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 879edbc1a065..8b6e6e4d0f51 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -1001,12 +1002,38 @@ static blk_status_t sd_setup_flush_cmnd(struct scsi_cmnd *cmd) return BLK_STS_OK; } +/** + * sd_group_number() - Compute the GROUP NUMBER field + * @cmd: SCSI command for which to compute the value of the six-bit GROUP NUMBER + * field. + * + * From SBC-5 r05 (https://www.t10.org/cgi-bin/ac.pl?t=f&f=sbc5r05.pdf): + * 0: no relative lifetime. + * 1: shortest relative lifetime. + * 2: second shortest relative lifetime. + * 3 - 0x3d: intermediate relative lifetimes. + * 0x3e: second longest relative lifetime. + * 0x3f: longest relative lifetime. + */ +static u8 sd_group_number(struct scsi_cmnd *cmd) +{ + const struct request *rq = scsi_cmd_to_rq(cmd); + struct scsi_disk *sdkp = scsi_disk(rq->q->disk); + + if (!sdkp->rscs) + return 0; + + return min3((u32)rq->lifetime, (u32)sdkp->permanent_stream_count, + 0x3fu); +} + static blk_status_t sd_setup_rw32_cmnd(struct scsi_cmnd *cmd, bool write, sector_t lba, unsigned int nr_blocks, unsigned char flags, unsigned int dld) { cmd->cmd_len = SD_EXT_CDB_SIZE; cmd->cmnd[0] = VARIABLE_LENGTH_CMD; + cmd->cmnd[6] = sd_group_number(cmd); cmd->cmnd[7] = 0x18; /* Additional CDB len */ cmd->cmnd[9] = write ? WRITE_32 : READ_32; cmd->cmnd[10] = flags; @@ -1025,7 +1052,7 @@ static blk_status_t sd_setup_rw16_cmnd(struct scsi_cmnd *cmd, bool write, cmd->cmd_len = 16; cmd->cmnd[0] = write ? WRITE_16 : READ_16; cmd->cmnd[1] = flags | ((dld >> 2) & 0x01); - cmd->cmnd[14] = (dld & 0x03) << 6; + cmd->cmnd[14] = ((dld & 0x03) << 6) | sd_group_number(cmd); cmd->cmnd[15] = 0; put_unaligned_be64(lba, &cmd->cmnd[2]); put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); @@ -1040,7 +1067,7 @@ static blk_status_t sd_setup_rw10_cmnd(struct scsi_cmnd *cmd, bool write, cmd->cmd_len = 10; cmd->cmnd[0] = write ? WRITE_10 : READ_10; cmd->cmnd[1] = flags; - cmd->cmnd[6] = 0; + cmd->cmnd[6] = sd_group_number(cmd); cmd->cmnd[9] = 0; put_unaligned_be32(lba, &cmd->cmnd[2]); put_unaligned_be16(nr_blocks, &cmd->cmnd[7]); @@ -1177,7 +1204,7 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) ret = sd_setup_rw16_cmnd(cmd, write, lba, nr_blocks, protect | fua, dld); } else if ((nr_blocks > 0xff) || (lba > 0x1fffff) || - sdp->use_10_for_rw || protect) { + sdp->use_10_for_rw || protect || rq->lifetime) { ret = sd_setup_rw10_cmnd(cmd, write, lba, nr_blocks, protect | fua); } else { @@ -2912,6 +2939,70 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer) sdkp->DPOFUA = 0; } +static bool sd_is_perm_stream(struct scsi_disk *sdkp, unsigned stream_id) +{ + u8 cdb[16] = { SERVICE_ACTION_IN_16, SAI_GET_STREAM_STATUS }; + struct { + struct scsi_stream_status_header h; + struct scsi_stream_status s; + } buf; + struct scsi_device *sdev = sdkp->device; + struct scsi_sense_hdr sshdr; + const struct scsi_exec_args exec_args = { + .sshdr = &sshdr, + }; + int res; + + put_unaligned_be16(stream_id, &cdb[4]); + put_unaligned_be32(sizeof(buf), &cdb[10]); + + res = scsi_execute_cmd(sdev, cdb, REQ_OP_DRV_IN, &buf, sizeof(buf), + SD_TIMEOUT, sdkp->max_retries, &exec_args); + if (res < 0) + return false; + if (scsi_status_is_check_condition(res) && scsi_sense_valid(&sshdr)) + sd_print_sense_hdr(sdkp, &sshdr); + if (res) + return false; + if (get_unaligned_be32(&buf.h.len) < sizeof(struct scsi_stream_status)) + return false; + return buf.h.stream_status[0].perm; +} + +static void sd_read_io_hints(struct scsi_disk *sdkp, unsigned char *buffer) +{ + struct scsi_device *sdp = sdkp->device; + const struct scsi_io_group_descriptor *desc, *start, *end; + struct scsi_sense_hdr sshdr; + struct scsi_mode_data data; + int res; + + res = scsi_mode_sense(sdp, /*dbd=*/0x8, /*modepage=*/0x0a, + /*subpage=*/0x05, buffer, SD_BUF_SIZE, + SD_TIMEOUT, sdkp->max_retries, &data, &sshdr); + if (res < 0) + return; + start = (void *)buffer + data.header_length + 16; + end = (void *)buffer + ALIGN_DOWN(data.header_length + data.length, + sizeof(*end)); + /* + * From "SBC-5 Constrained Streams with Data Lifetimes": Device severs + * should assign the lowest numbered stream identifiers to permanent + * streams. + */ + for (desc = start; desc < end; desc++) + if (!desc->st_enble || !sd_is_perm_stream(sdkp, desc - start)) + break; + sdkp->permanent_stream_count = desc - start; + if (sdkp->rscs && sdkp->permanent_stream_count < 2) + sd_printk(KERN_INFO, sdkp, + "Unexpected: RSCS has been set and the permanent stream count is %u\n", + sdkp->permanent_stream_count); + else if (sdkp->permanent_stream_count) + sd_printk(KERN_INFO, sdkp, "permanent stream count = %d\n", + sdkp->permanent_stream_count); +} + /* * The ATO bit indicates whether the DIF application tag is available * for use by the operating system. @@ -3395,6 +3486,7 @@ static int sd_revalidate_disk(struct gendisk *disk) sd_read_write_protect_flag(sdkp, buffer); sd_read_cache_type(sdkp, buffer); + sd_read_io_hints(sdkp, buffer); sd_read_app_tag_own(sdkp, buffer); sd_read_write_same(sdkp, buffer); sd_read_security(sdkp, buffer); diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 84685168b6e0..570d5a72749a 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -125,6 +125,8 @@ struct scsi_disk { unsigned int physical_block_size; unsigned int max_medium_access_timeouts; unsigned int medium_access_timed_out; + /* number of permanent streams */ + u16 permanent_stream_count; u8 media_present; u8 write_prot; u8 protection_type;/* Data Integrity Field */ From patchwork Tue Oct 17 20:47: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: 13426077 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 D21F3CDB483 for ; Tue, 17 Oct 2023 20:48:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344263AbjJQUse (ORCPT ); Tue, 17 Oct 2023 16:48:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344267AbjJQUsb (ORCPT ); Tue, 17 Oct 2023 16:48:31 -0400 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97FFE10A; Tue, 17 Oct 2023 13:48:29 -0700 (PDT) Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6b87c1edfd5so3073246b3a.1; Tue, 17 Oct 2023 13:48:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575709; x=1698180509; 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=y+MAWTVMOc62bHJcXIWIdTiq/rQINfWWQsJrgwniqu0=; b=W8sYdSXjfsxUKuH2zyBrymOKUZORr6Ec0IOdQTFo/6C+ejec2Eu4NG8LwzNdpaxOh+ aSTmJQPteUCm2iKJCIKYGUxMYv5yNKMAhq7tdJXLjcorXmF8g/BTrfKp7o4KWg5bpBTX uiVv9gpm3X+VLD2q6fxjZTdAkJE4WlllKIMzxcHCMKNoSESURj8u8sUfSP15W9DAxZZM tWT2MPbHNa4MfH2ZavR1wjPaK7OtbfPvOCsc0hAPV99H9Gc/+EsL4FHr4QB6TwQyaKn3 K27lcttLtBT3jkDQgIP5YB4Ip7ZG3d2tYM/GKKyC87zZ3WrFteeUKn/sG8tDAji56pM7 KO8g== X-Gm-Message-State: AOJu0Yyyz8euZcvR7+2c9AerIa3GPjcSuMqJlPKyS2tmbV14azQOw8KO ODLGK/Y2PoPD2G/UxvMGPNI= X-Google-Smtp-Source: AGHT+IE5YudWJEC7u99kPshKCLRdfNd5U9itIKpcJ7NpJ+wtlHFneKhLU/UBFZhljuedidatO7udJQ== X-Received: by 2002:aa7:88cf:0:b0:690:3b59:cc7b with SMTP id k15-20020aa788cf000000b006903b59cc7bmr3445223pff.32.1697575708846; Tue, 17 Oct 2023 13:48:28 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:28 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Avri Altman , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v3 08/14] scsi_debug: Reduce code duplication Date: Tue, 17 Oct 2023 13:47:16 -0700 Message-ID: <20231017204739.3409052-9-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org All VPD pages have the page code in byte one. Reduce code duplication by storing the VPD page code once. Reviewed-by: Avri Altman Cc: Martin K. Petersen Cc: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 9c0af50501f9..46eaa2f9e63b 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -1598,7 +1598,8 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) u32 len; char lu_id_str[6]; int host_no = devip->sdbg_host->shost->host_no; - + + arr[1] = cmd[2]; port_group_id = (((host_no + 1) & 0x7f) << 8) + (devip->channel & 0x7f); if (sdebug_vpd_use_hostno == 0) @@ -1609,7 +1610,6 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) (devip->target * 1000) - 3; len = scnprintf(lu_id_str, 6, "%d", lu_id_num); if (0 == cmd[2]) { /* supported vital product data pages */ - arr[1] = cmd[2]; /*sanity */ n = 4; arr[n++] = 0x0; /* this page */ arr[n++] = 0x80; /* unit serial number */ @@ -1630,23 +1630,18 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } arr[3] = n - 4; /* number of supported VPD pages */ } else if (0x80 == cmd[2]) { /* unit serial number */ - arr[1] = cmd[2]; /*sanity */ arr[3] = len; memcpy(&arr[4], lu_id_str, len); } else if (0x83 == cmd[2]) { /* device identification */ - arr[1] = cmd[2]; /*sanity */ arr[3] = inquiry_vpd_83(&arr[4], port_group_id, target_dev_id, lu_id_num, lu_id_str, len, &devip->lu_name); } else if (0x84 == cmd[2]) { /* Software interface ident. */ - arr[1] = cmd[2]; /*sanity */ arr[3] = inquiry_vpd_84(&arr[4]); } else if (0x85 == cmd[2]) { /* Management network addresses */ - arr[1] = cmd[2]; /*sanity */ arr[3] = inquiry_vpd_85(&arr[4]); } else if (0x86 == cmd[2]) { /* extended inquiry */ - arr[1] = cmd[2]; /*sanity */ arr[3] = 0x3c; /* number of following entries */ if (sdebug_dif == T10_PI_TYPE3_PROTECTION) arr[4] = 0x4; /* SPT: GRD_CHK:1 */ @@ -1656,30 +1651,23 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) arr[4] = 0x0; /* no protection stuff */ arr[5] = 0x7; /* head of q, ordered + simple q's */ } else if (0x87 == cmd[2]) { /* mode page policy */ - arr[1] = cmd[2]; /*sanity */ arr[3] = 0x8; /* number of following entries */ arr[4] = 0x2; /* disconnect-reconnect mp */ arr[6] = 0x80; /* mlus, shared */ arr[8] = 0x18; /* protocol specific lu */ arr[10] = 0x82; /* mlus, per initiator port */ } else if (0x88 == cmd[2]) { /* SCSI Ports */ - arr[1] = cmd[2]; /*sanity */ arr[3] = inquiry_vpd_88(&arr[4], target_dev_id); } else if (is_disk_zbc && 0x89 == cmd[2]) { /* ATA info */ - arr[1] = cmd[2]; /*sanity */ n = inquiry_vpd_89(&arr[4]); put_unaligned_be16(n, arr + 2); } else if (is_disk_zbc && 0xb0 == cmd[2]) { /* Block limits */ - arr[1] = cmd[2]; /*sanity */ arr[3] = inquiry_vpd_b0(&arr[4]); } else if (is_disk_zbc && 0xb1 == cmd[2]) { /* Block char. */ - arr[1] = cmd[2]; /*sanity */ arr[3] = inquiry_vpd_b1(devip, &arr[4]); } else if (is_disk && 0xb2 == cmd[2]) { /* LB Prov. */ - arr[1] = cmd[2]; /*sanity */ arr[3] = inquiry_vpd_b2(&arr[4]); } else if (is_zbc && cmd[2] == 0xb6) { /* ZB dev. charact. */ - arr[1] = cmd[2]; /*sanity */ arr[3] = inquiry_vpd_b6(devip, &arr[4]); } else { mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1); From patchwork Tue Oct 17 20:47: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: 13426079 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 A8B92CDB474 for ; Tue, 17 Oct 2023 20:48:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235073AbjJQUsp (ORCPT ); Tue, 17 Oct 2023 16:48:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344186AbjJQUsd (ORCPT ); Tue, 17 Oct 2023 16:48:33 -0400 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 459A592; Tue, 17 Oct 2023 13:48:31 -0700 (PDT) Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-57b68556d6dso3417587eaf.1; Tue, 17 Oct 2023 13:48:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575710; x=1698180510; 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=105xJtXU3kMI2hh6/g7PSS5FLkiZJWAuMxIKylxsIMA=; b=e1EOyN+kQM8p1yAG3aLBBb6Y5abK6836jHXVGh+QEoc90djBXR6cXqLNMjaxbqlVjq RPOU59K7vyow+dNk7rSbZ5TAzl9HOE/kCZ6Rw6yXbi2I77F5EBkQbyVka37e8Flq84Pf sQZu7zwsOVUkrEKUTM1PJSn6sJVE6y/LiB2PNONB7kKB09hsAXbQ9HW+mn49AADOLMi+ 8EjFvKkHKVwaYps8MbB4YbX6Q6Vac/sNfxVGOsMIrv85i+w25gtP4KQ3hV3phm+oKcva m6pacgglbcB8/CvWDMvk3J9BUezLGl8EA59wlLJGx2EmN7VAmctYhpBN2DUBm4KQNqtF 47hw== X-Gm-Message-State: AOJu0YxEPE3WGCRTbtQMXl6YV061MjOZnKnM5g9X3+OKrtoOOjY4ZRQ6 wRjnQk+U1rSeiOE/lpbwxD0= X-Google-Smtp-Source: AGHT+IGKpwnJVusLdCOnbH4TMWpBVokmUp5EtTJw1dIbjz3QvVxicCOEifeVNO4gmLHRTIznDv/kXw== X-Received: by 2002:a05:6359:29c2:b0:13e:d853:cc22 with SMTP id qf2-20020a05635929c200b0013ed853cc22mr3093749rwb.4.1697575710260; Tue, 17 Oct 2023 13:48:30 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:29 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v3 09/14] scsi_debug: Support the block limits extension VPD page Date: Tue, 17 Oct 2023 13:47:17 -0700 Message-ID: <20231017204739.3409052-10-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From SBC-5 r05: "Reduced stream control: a) reduces the maximum number of streams that the device server supports; and b) increases the number of write commands that are able to specify a stream to be written in any write command that contains the GROUP NUMBER field in its CDB. If the RSCS bit (see 6.6.5) is set to one, then the device server shall: a) support per group stream identifier usage as described in 4.32.2; b) support the IO Advice Hints Grouping mode page (see 6.5.7); and c) set the MAXIMUM NUMBER OF STREAMS field (see 6.6.5) to a value that is less than 64. Device servers that set the RSCS bit to one may support other features (e.g., permanent streams (see 4.32.4)). 4.32.4 Permanent streams A permanent stream is a stream for which the device server does not allow closing or otherwise modifying the configuration of that stream. The PERM bit (see 5.9.2.3) indicates whether a stream is a permanent stream. If a STREAM CONTROL command (see 5.32) specifies the closing of a permanent stream, the device server terminates that command with CHECK CONDITION status instead of closing the specified stream. A permanent stream is always an open stream. Device severs should assign the lowest numbered stream identifiers to permanent streams." Report that reduced stream control is supported. Cc: Martin K. Petersen Cc: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 46eaa2f9e63b..88cba9374166 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -1627,6 +1627,7 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) arr[n++] = 0xb2; /* LB Provisioning */ if (is_zbc) arr[n++] = 0xb6; /* ZB dev. char. */ + arr[n++] = 0xb7; /* Block limits extension */ } arr[3] = n - 4; /* number of supported VPD pages */ } else if (0x80 == cmd[2]) { /* unit serial number */ @@ -1669,6 +1670,9 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) arr[3] = inquiry_vpd_b2(&arr[4]); } else if (is_zbc && cmd[2] == 0xb6) { /* ZB dev. charact. */ arr[3] = inquiry_vpd_b6(devip, &arr[4]); + } else if (cmd[2] == 0xb7) { /* block limits extension page */ + arr[3] = 2; /* page length */ + arr[5] = 1; /* Reduced stream control support (RSCS) */ } else { mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1); kfree(arr); From patchwork Tue Oct 17 20:47: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: 13426080 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 7A3B7CDB482 for ; Tue, 17 Oct 2023 20:48:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232300AbjJQUsq (ORCPT ); Tue, 17 Oct 2023 16:48:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344235AbjJQUse (ORCPT ); Tue, 17 Oct 2023 16:48:34 -0400 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B295F9; Tue, 17 Oct 2023 13:48:32 -0700 (PDT) Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6ba172c5f3dso2822699b3a.0; Tue, 17 Oct 2023 13:48:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575712; x=1698180512; 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=/amIXBh2OmwTU85hCgujumlTfo/mnD8IJjMcbcGdMyM=; b=rivGhzSeZtDCGz+2H4pjclqRkayqC4n7Q3lAH1MuWGXTiwO3oP45FJ0w1ec3RZoEyL 7Vxvb8qkNSJ3XTA0dGaC4d5qWjdDgN83hN/NaPMnQn+zhTW1JHMIwzoJB9FS2qyyac0D koAl5DuGkRIY6Eabhul0QrxCI5Wvzett105B7784zb5iVOyyHvRkdWKCVzdhRhgKQh9l KbA4qsWGYYA56T8xO2WM1Qq6+pWE4pEQ8pVxKu9JoDEMQUBhx7uKLgO9vtM+eS2hR4Rn m7Tlf6mncNR7MIiD0iwt5Q6HBNXhr0mdojYIBk4v2qaja19v23nDjdgozvUkA1SdRQxv 43JA== X-Gm-Message-State: AOJu0YyXu6cQt/5xYs1Vm58i8V3dIKoPMKJlDGJn++T1iEclwMVNI0Ft jAAKXI98rLm0gNo0BXifVGI= X-Google-Smtp-Source: AGHT+IG8H89iYb8bSQyP2l3JUs90G/z/NmytVkTWV1KBTgXA2IhnL3HAGHo39NpzPOiPU/GFHy6KTw== X-Received: by 2002:a05:6a00:22cb:b0:690:c75e:25d7 with SMTP id f11-20020a056a0022cb00b00690c75e25d7mr3804199pfj.18.1697575711687; Tue, 17 Oct 2023 13:48:31 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:31 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v3 10/14] scsi_debug: Rework page code error handling Date: Tue, 17 Oct 2023 13:47:18 -0700 Message-ID: <20231017204739.3409052-11-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Instead of tracking whether or not the page code is valid in a boolean variable, jump to error handling code if an unsupported page code is encountered. Cc: Martin K. Petersen Cc: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 88cba9374166..6b87d267c9c5 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -2327,7 +2327,7 @@ static int resp_mode_sense(struct scsi_cmnd *scp, unsigned char *ap; unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; unsigned char *cmd = scp->cmnd; - bool dbd, llbaa, msense_6, is_disk, is_zbc, bad_pcode; + bool dbd, llbaa, msense_6, is_disk, is_zbc; dbd = !!(cmd[1] & 0x8); /* disable block descriptors */ pcontrol = (cmd[2] & 0xc0) >> 6; @@ -2391,7 +2391,6 @@ static int resp_mode_sense(struct scsi_cmnd *scp, mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); return check_condition_result; } - bad_pcode = false; switch (pcode) { case 0x1: /* Read-Write error recovery page, direct access */ @@ -2406,15 +2405,17 @@ static int resp_mode_sense(struct scsi_cmnd *scp, if (is_disk) { len = resp_format_pg(ap, pcontrol, target); offset += len; - } else - bad_pcode = true; + } else { + goto bad_pcode; + } break; case 0x8: /* Caching page, direct access */ if (is_disk || is_zbc) { len = resp_caching_pg(ap, pcontrol, target); offset += len; - } else - bad_pcode = true; + } else { + goto bad_pcode; + } break; case 0xa: /* Control Mode page, all devices */ len = resp_ctrl_m_pg(ap, pcontrol, target); @@ -2467,18 +2468,17 @@ static int resp_mode_sense(struct scsi_cmnd *scp, } break; default: - bad_pcode = true; - break; - } - if (bad_pcode) { - mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, 5); - return check_condition_result; + goto bad_pcode; } if (msense_6) arr[0] = offset - 1; else put_unaligned_be16((offset - 2), arr + 0); return fill_from_dev_buffer(scp, arr, min_t(u32, alloc_len, offset)); + +bad_pcode: + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, 5); + return check_condition_result; } #define SDEBUG_MAX_MSELECT_SZ 512 From patchwork Tue Oct 17 20:47: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: 13426081 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 A7977CDB484 for ; Tue, 17 Oct 2023 20:48:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235137AbjJQUss (ORCPT ); Tue, 17 Oct 2023 16:48:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235019AbjJQUso (ORCPT ); Tue, 17 Oct 2023 16:48:44 -0400 Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7D9310B; Tue, 17 Oct 2023 13:48:33 -0700 (PDT) Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-6c7ce16ddfaso4246676a34.3; Tue, 17 Oct 2023 13:48:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575713; x=1698180513; 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=WgLtfRupmxASF+XQWKDQIVeDU0ZhEvhZXbulw0ZxJ0s=; b=ATDcgei/f47g2DINDRjORZSFt84TIwqXdGK8GJ1SFWWvGXDFOjm/1pDVFujUH4ELjz 4rJl5B1nwg7hmF66vmqd5VWfvUB/sZ+iQQdcK/dIBQ12Cj8bLTfdUxjJ+HVew7e/ev6N fZbp0KvX0Gk/2N+NrUaKnius4C5BqN+zm7dDdA9foosYrTsGP/Y/xaAtGJ7bjKBAcroN lURWhr/HlNPkiNx8w9bNFtheHTQxILYslDOqW4Y6/hbqtVgkiRSirG+FUPBuCmR06m+y FPrakz2Z1SivD3yQTyeF2BR/+RFWbZ2uUaDCBR+eL5ESK7h2Eu7DpxnxGEz5QtIGGw6M Q7jw== X-Gm-Message-State: AOJu0YyJcvPczeTXt42JHSUb5fGrHHeOEQJQxPCGyekkv0cXxoyNDO/R KGrLi2kV9EdymqXOX4PtVnU= X-Google-Smtp-Source: AGHT+IFRkJ+7tMIkyFke2H6yk/D/xHF/7PGCHIXuKBREezajI9+DgZbxy0a8rHy1aKOMH9mBk5PJMQ== X-Received: by 2002:a05:6830:1007:b0:6c6:42ca:ed52 with SMTP id a7-20020a056830100700b006c642caed52mr3254291otp.30.1697575713103; Tue, 17 Oct 2023 13:48:33 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:32 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v3 11/14] scsi_debug: Rework subpage code error handling Date: Tue, 17 Oct 2023 13:47:19 -0700 Message-ID: <20231017204739.3409052-12-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Move the subpage code checks into the switch statement to make it easier to add support for new page code / subpage code combinations. Cc: Martin K. Petersen Cc: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 70 ++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 6b87d267c9c5..a96eb0d10346 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -2386,22 +2386,22 @@ static int resp_mode_sense(struct scsi_cmnd *scp, ap = arr + offset; } - if ((subpcode > 0x0) && (subpcode < 0xff) && (0x19 != pcode)) { - /* TODO: Control Extension page */ - mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); - return check_condition_result; - } - switch (pcode) { case 0x1: /* Read-Write error recovery page, direct access */ + if (subpcode > 0x0 && subpcode < 0xff) + goto bad_subpcode; len = resp_err_recov_pg(ap, pcontrol, target); offset += len; break; case 0x2: /* Disconnect-Reconnect page, all devices */ + if (subpcode > 0x0 && subpcode < 0xff) + goto bad_subpcode; len = resp_disconnect_pg(ap, pcontrol, target); offset += len; break; case 0x3: /* Format device page, direct access */ + if (subpcode > 0x0 && subpcode < 0xff) + goto bad_subpcode; if (is_disk) { len = resp_format_pg(ap, pcontrol, target); offset += len; @@ -2410,6 +2410,8 @@ static int resp_mode_sense(struct scsi_cmnd *scp, } break; case 0x8: /* Caching page, direct access */ + if (subpcode > 0x0 && subpcode < 0xff) + goto bad_subpcode; if (is_disk || is_zbc) { len = resp_caching_pg(ap, pcontrol, target); offset += len; @@ -2418,14 +2420,14 @@ static int resp_mode_sense(struct scsi_cmnd *scp, } break; case 0xa: /* Control Mode page, all devices */ + if (subpcode > 0x0 && subpcode < 0xff) + goto bad_subpcode; len = resp_ctrl_m_pg(ap, pcontrol, target); offset += len; break; case 0x19: /* if spc==1 then sas phy, control+discover */ - if ((subpcode > 0x2) && (subpcode < 0xff)) { - mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); - return check_condition_result; - } + if (subpcode > 0x2 && subpcode < 0xff) + goto bad_subpcode; len = 0; if ((0x0 == subpcode) || (0xff == subpcode)) len += resp_sas_sf_m_pg(ap + len, pcontrol, target); @@ -2437,35 +2439,31 @@ static int resp_mode_sense(struct scsi_cmnd *scp, offset += len; break; case 0x1c: /* Informational Exceptions Mode page, all devices */ + if (subpcode > 0x0 && subpcode < 0xff) + goto bad_subpcode; len = resp_iec_m_pg(ap, pcontrol, target); offset += len; break; case 0x3f: /* Read all Mode pages */ - if ((0 == subpcode) || (0xff == subpcode)) { - len = resp_err_recov_pg(ap, pcontrol, target); - len += resp_disconnect_pg(ap + len, pcontrol, target); - if (is_disk) { - len += resp_format_pg(ap + len, pcontrol, - target); - len += resp_caching_pg(ap + len, pcontrol, - target); - } else if (is_zbc) { - len += resp_caching_pg(ap + len, pcontrol, - target); - } - len += resp_ctrl_m_pg(ap + len, pcontrol, target); - len += resp_sas_sf_m_pg(ap + len, pcontrol, target); - if (0xff == subpcode) { - len += resp_sas_pcd_m_spg(ap + len, pcontrol, - target, target_dev_id); - len += resp_sas_sha_m_spg(ap + len, pcontrol); - } - len += resp_iec_m_pg(ap + len, pcontrol, target); - offset += len; - } else { - mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); - return check_condition_result; + if (subpcode > 0x0 && subpcode < 0xff) + goto bad_subpcode; + len = resp_err_recov_pg(ap, pcontrol, target); + len += resp_disconnect_pg(ap + len, pcontrol, target); + if (is_disk) { + len += resp_format_pg(ap + len, pcontrol, target); + len += resp_caching_pg(ap + len, pcontrol, target); + } else if (is_zbc) { + len += resp_caching_pg(ap + len, pcontrol, target); + } + len += resp_ctrl_m_pg(ap + len, pcontrol, target); + len += resp_sas_sf_m_pg(ap + len, pcontrol, target); + if (0xff == subpcode) { + len += resp_sas_pcd_m_spg(ap + len, pcontrol, target, + target_dev_id); + len += resp_sas_sha_m_spg(ap + len, pcontrol); } + len += resp_iec_m_pg(ap + len, pcontrol, target); + offset += len; break; default: goto bad_pcode; @@ -2479,6 +2477,10 @@ static int resp_mode_sense(struct scsi_cmnd *scp, bad_pcode: mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, 5); return check_condition_result; + +bad_subpcode: + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1); + return check_condition_result; } #define SDEBUG_MAX_MSELECT_SZ 512 From patchwork Tue Oct 17 20:47: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: 13426082 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 B61DECDB485 for ; Tue, 17 Oct 2023 20:48:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232068AbjJQUst (ORCPT ); Tue, 17 Oct 2023 16:48:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235026AbjJQUso (ORCPT ); Tue, 17 Oct 2023 16:48:44 -0400 Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 598E9113; Tue, 17 Oct 2023 13:48:35 -0700 (PDT) Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-57f0f81b2aeso3404478eaf.3; Tue, 17 Oct 2023 13:48:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575714; x=1698180514; 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=UM8sqysXvoRJ5DMnsmYXvV6LHJ7K767rwmBQQL3CWG0=; b=e2ra+MormH+7kdP6iE6cUxAU/6WB5wz1fKlke1TZEXcDwdff9Xew6YR7U4xN/PNksz Va3T9XioDxvR9eBK0DhXP1OHwwXINyloLfv+Pcmkw1DFnWFhLMyIj7w0dYG60BRLmLcc T4eP38EpWNwwH1jbF84LSUazOufQz+ISr1SntRNezmtESEdxc6IigZbuqIQdFF8rmX+s n/JdTfxaq27MjO9fMDeu7ZFUjvczR+2QI6rGTmu21o0OxUrSuILtPq3FGgVid0JRNarv 3rNZrP0x3YtBFGxXQloj2ep9N7jvl15E9l/3MSuPbVbdcY5hwFR+RnYbK+vfB5NtFd+h 9dLQ== X-Gm-Message-State: AOJu0YzQm29VEHJcDe/bM5FtIItfXRxIRHNnjeo+xuOx0i0c/rovnLOv VZi3quBhx4ge74OE67LSsm0= X-Google-Smtp-Source: AGHT+IF/5L3x/Ab+PAUfdX+hgUIOKfSGbqsErIOon16NHRSS3O63qPnEQlqyvTg+yp+05VhyWXhxhQ== X-Received: by 2002:a05:6358:ce11:b0:166:dcf6:cd82 with SMTP id gt17-20020a056358ce1100b00166dcf6cd82mr3050454rwb.14.1697575714527; Tue, 17 Oct 2023 13:48:34 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:34 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v3 12/14] scsi_debug: Implement the IO Advice Hints Grouping mode page Date: Tue, 17 Oct 2023 13:47:20 -0700 Message-ID: <20231017204739.3409052-13-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Implement an IO Advice Hints Grouping mode page with three permanent streams. A permanent stream is a stream for which the device server does not allow closing or otherwise modifying the configuration of that stream. The stream identifier enable (ST_ENBLE) bit specifies whether the stream identifier may be used in the GROUP NUMBER field of SCSI WRITE commands. Cc: Martin K. Petersen Cc: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 42 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index a96eb0d10346..d56989e94c4a 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -2241,6 +2241,36 @@ static int resp_ctrl_m_pg(unsigned char *p, int pcontrol, int target) return sizeof(ctrl_m_pg); } +enum { MAXIMUM_NUMBER_OF_STREAMS = 4 }; + +/* IO Advice Hints Grouping mode page */ +static int resp_grouping_m_pg(unsigned char *p, int pcontrol, int target) +{ + /* IO Advice Hints Grouping mode page */ + struct grouping_m_pg { + u8 page_code; + u8 subpage_code; + __be16 page_length; + u8 reserved[12]; + struct scsi_io_group_descriptor + descr[MAXIMUM_NUMBER_OF_STREAMS]; + }; + static const struct grouping_m_pg gr_m_pg = { + .page_code = 0xa, + .subpage_code = 5, + .page_length = cpu_to_be16(sizeof(gr_m_pg) - 4), + .descr = { + { .st_enble = 1 }, + { .st_enble = 1 }, + { .st_enble = 1 }, + { .st_enble = 0 }, + } + }; + + BUILD_BUG_ON(sizeof(struct grouping_m_pg) != 16 + 4 * 16); + memcpy(p, &gr_m_pg, sizeof(gr_m_pg)); + return sizeof(gr_m_pg); +} static int resp_iec_m_pg(unsigned char *p, int pcontrol, int target) { /* Informational Exceptions control mode page for mode_sense */ @@ -2420,9 +2450,17 @@ static int resp_mode_sense(struct scsi_cmnd *scp, } break; case 0xa: /* Control Mode page, all devices */ - if (subpcode > 0x0 && subpcode < 0xff) + switch (subpcode) { + case 0: + case 0xff: + len = resp_ctrl_m_pg(ap, pcontrol, target); + break; + case 0x05: + len = resp_grouping_m_pg(ap, pcontrol, target); + break; + default: goto bad_subpcode; - len = resp_ctrl_m_pg(ap, pcontrol, target); + } offset += len; break; case 0x19: /* if spc==1 then sas phy, control+discover */ From patchwork Tue Oct 17 20:47: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: 13426083 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 34759CDB486 for ; Tue, 17 Oct 2023 20:48:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344198AbjJQUsw (ORCPT ); Tue, 17 Oct 2023 16:48:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235052AbjJQUsp (ORCPT ); Tue, 17 Oct 2023 16:48:45 -0400 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF9D911D; Tue, 17 Oct 2023 13:48:36 -0700 (PDT) Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6c0b8f42409so4182047a34.0; Tue, 17 Oct 2023 13:48:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575716; x=1698180516; 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=7d0SXC6UVHzAU0xOIJZHMg0dP00OvMSzg+wOowpDTtA=; b=sR0khXhgs+XqHyPqS3dCWVMOjjNss4LuzpqEhDGJavoywJCk7BqzhwKZ3+ubCTa5hU VtQMTLZCskLz9QA25dFydtppXStrJjRWhhlB2jh7tvccP4ucK75CEVRJ3pPCGNtTGtwj 09DfIcoi+M6MMDpA23rxwFWBMLiJ6dU+YC1cP+Mtswmfrv3lQfEMXc49Jjk/+SuPOdrF 5P+SRQOPUNxj/rqhmLdPA/pQCOCyUchs8HnPqBGilMKcekNup59LoP/TN6RQMCyBlUtV whKRtKc5qr6WxYFQMFeeNAC6wNv03xcfP34AWjmwet2WDUhsXm2VzzYKKpZ4WYpPMCc1 GwPg== X-Gm-Message-State: AOJu0YwFT7k7nOb2XUINEB7T3ZR1eBwGwWkd1264fru0CvqoUhZ1ADXJ 45led5VRyzQ4oVIos6G3sX/M4U0KyW4= X-Google-Smtp-Source: AGHT+IGSXWyx/eFcMYRpo1ZiNRhWiL5aUn/JUd141oVaiXdvlK8l3n7dB/+STLHaUa3pL8qBl4z9Mw== X-Received: by 2002:a05:6830:310a:b0:6aa:ecb5:f186 with SMTP id b10-20020a056830310a00b006aaecb5f186mr4768411ots.7.1697575715918; Tue, 17 Oct 2023 13:48:35 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:35 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v3 13/14] scsi_debug: Implement GET STREAM STATUS Date: Tue, 17 Oct 2023 13:47:21 -0700 Message-ID: <20231017204739.3409052-14-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Implement the GET STREAM STATUS SCSI command. Report that the first three stream indexes correspond to permanent streams. Cc: Martin K. Petersen Cc: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 44 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index d56989e94c4a..801448570960 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -481,6 +481,8 @@ static int resp_write_scat(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_start_stop(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_readcap16(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_get_lba_status(struct scsi_cmnd *, struct sdebug_dev_info *); +static int resp_get_stream_status(struct scsi_cmnd *scp, + struct sdebug_dev_info *devip); static int resp_report_tgtpgs(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_unmap(struct scsi_cmnd *, struct sdebug_dev_info *); static int resp_rsup_opcodes(struct scsi_cmnd *, struct sdebug_dev_info *); @@ -555,6 +557,9 @@ static const struct opcode_info_t sa_in_16_iarr[] = { {0, 0x9e, 0x12, F_SA_LOW | F_D_IN, resp_get_lba_status, NULL, {16, 0x12, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0xc7} }, /* GET LBA STATUS(16) */ + {0, 0x9e, 0x16, F_SA_LOW | F_D_IN, resp_get_stream_status, NULL, + {16, 0x16, 0, 0, 0xff, 0xff, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, + 0, 0} }, /* GET STREAM STATUS */ }; static const struct opcode_info_t vl_iarr[] = { /* VARIABLE LENGTH */ @@ -2241,7 +2246,7 @@ static int resp_ctrl_m_pg(unsigned char *p, int pcontrol, int target) return sizeof(ctrl_m_pg); } -enum { MAXIMUM_NUMBER_OF_STREAMS = 4 }; +enum { MAXIMUM_NUMBER_OF_STREAMS = 4, PERMANENT_STREAM_COUNT = 3 }; /* IO Advice Hints Grouping mode page */ static int resp_grouping_m_pg(unsigned char *p, int pcontrol, int target) @@ -4236,6 +4241,43 @@ static int resp_get_lba_status(struct scsi_cmnd *scp, return fill_from_dev_buffer(scp, arr, SDEBUG_GET_LBA_STATUS_LEN); } +static int resp_get_stream_status(struct scsi_cmnd *scp, + struct sdebug_dev_info *devip) +{ + u16 starting_stream_id, stream_id; + const u8 *cmd = scp->cmnd; + u32 alloc_len, offset; + u8 arr[256]; + + starting_stream_id = get_unaligned_be16(cmd + 4); + alloc_len = get_unaligned_be32(cmd + 10); + + if (alloc_len < 8) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 10, -1); + return check_condition_result; + } + + if (starting_stream_id >= MAXIMUM_NUMBER_OF_STREAMS) { + mk_sense_invalid_fld(scp, SDEB_IN_CDB, 4, -1); + return check_condition_result; + } + + for (offset = 8, stream_id = starting_stream_id; + offset + 8 <= min_t(u32, alloc_len, sizeof(arr)) && + stream_id < MAXIMUM_NUMBER_OF_STREAMS; + offset += 8, stream_id++) { + struct scsi_stream_status *stream_status = (void *)arr + offset; + + stream_status->perm = stream_id < PERMANENT_STREAM_COUNT; + put_unaligned_be16(stream_id, + &stream_status->stream_identifier); + stream_status->rel_lifetime = stream_id + 1; + } + put_unaligned_be32(offset - 8, arr + 0); /* PARAMETER DATA LENGTH */ + + return fill_from_dev_buffer(scp, arr, min(offset, alloc_len)); +} + static int resp_sync_cache(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) { From patchwork Tue Oct 17 20:47: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: 13426084 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 9E34ECDB474 for ; Tue, 17 Oct 2023 20:48:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344235AbjJQUs4 (ORCPT ); Tue, 17 Oct 2023 16:48:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235066AbjJQUsp (ORCPT ); Tue, 17 Oct 2023 16:48:45 -0400 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29829123; Tue, 17 Oct 2023 13:48:38 -0700 (PDT) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6b201a93c9cso3848270b3a.0; Tue, 17 Oct 2023 13:48:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575717; x=1698180517; 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=UCPfzQ6gGXtCtFoEWf6GEkmetjqJd0PL6BZnUtAtOy0=; b=Vt9NNOBlYD9kps5hkBuzIzBzuEX7eTobKnJipO0JmS6b/aGhjPzSXuYwbrSMViPhfw R8jqN/Uy72ZXRMzzHb3viTV3+DLjmdpGnfqejLaage8a/UJ6Ie938Cx2Jp9vRN3RWgrK yNc15P7Me8c6oEWzYul8bKpA5U0L98M88YwsWcF375kAaNCCGpINGpwlOdal1ccGbxhB xX/JB4LLNVva982S7XpzXVkSXdwurwmU9BkEbsw9vDlyefHPpgVHIe8li4KVLCoDopjD k8CiLnUJHquYOuck6/aMf7As1+AMcS81SpxQqaA2nkkMdT7EOcVwLoHPooDi8pGTeDy/ WUGw== X-Gm-Message-State: AOJu0YyL88HeXpOGBXjNUTKNxJ8J+OjUbPuJM8/BRG6saqFAK/rJBjsx mgY0kdzwcmRQDIbCWBAzxkg= X-Google-Smtp-Source: AGHT+IGLtf5JVJbh8jxsrak07fhOzuFs0F8KGhRSffVSrD/2+5/2uK0jdz4gTrgWw4uM63DNmxrcOA== X-Received: by 2002:a05:6a00:218f:b0:693:3783:4a29 with SMTP id h15-20020a056a00218f00b0069337834a29mr3669286pfi.20.1697575717354; Tue, 17 Oct 2023 13:48:37 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:8f02:2919:9600:ac09]) by smtp.gmail.com with ESMTPSA id fa36-20020a056a002d2400b006b2e07a6235sm1874704pfb.136.2023.10.17.13.48.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:48:37 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Martin K . Petersen" , Christoph Hellwig , Niklas Cassel , Avri Altman , Bean Huo , Daejun Park , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v3 14/14] scsi_debug: Maintain write statistics per group number Date: Tue, 17 Oct 2023 13:47:22 -0700 Message-ID: <20231017204739.3409052-15-bvanassche@acm.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231017204739.3409052-1-bvanassche@acm.org> References: <20231017204739.3409052-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Track per GROUP NUMBER how many write commands have been processed. Make this information available in sysfs. Reset these statistics if any data is written into the sysfs attribute. Note: SCSI devices should only interpret the information in the GROUP NUMBER field as a stream identifier if the ST_ENBLE bit has been set to one. This patch follows a simpler approach: count the number of writes per GROUP NUMBER whether or not the group number represents a stream identifier. Cc: Martin K. Petersen Cc: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 51 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 801448570960..c2102c0046ad 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -846,6 +846,8 @@ static int sdeb_zbc_nr_conv = DEF_ZBC_NR_CONV_ZONES; static int submit_queues = DEF_SUBMIT_QUEUES; /* > 1 for multi-queue (mq) */ static int poll_queues; /* iouring iopoll interface.*/ +static atomic_long_t writes_by_group_number[64]; + static char sdebug_proc_name[] = MY_NAME; static const char *my_name = MY_NAME; @@ -3040,7 +3042,8 @@ static inline struct sdeb_store_info *devip2sip(struct sdebug_dev_info *devip, /* Returns number of bytes copied or -1 if error. */ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, - u32 sg_skip, u64 lba, u32 num, bool do_write) + u32 sg_skip, u64 lba, u32 num, bool do_write, + u8 group_number) { int ret; u64 block, rest = 0; @@ -3059,6 +3062,10 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, return 0; if (scp->sc_data_direction != dir) return -1; + + if (do_write && group_number < ARRAY_SIZE(writes_by_group_number)) + atomic_long_inc(&writes_by_group_number[group_number]); + fsp = sip->storep; block = do_div(lba, sdebug_store_sectors); @@ -3432,7 +3439,7 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } } - ret = do_device_access(sip, scp, 0, lba, num, false); + ret = do_device_access(sip, scp, 0, lba, num, false, 0); sdeb_read_unlock(sip); if (unlikely(ret == -1)) return DID_ERROR << 16; @@ -3617,6 +3624,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) { bool check_prot; u32 num; + u8 group = 0; u32 ei_lba; int ret; u64 lba; @@ -3628,11 +3636,13 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ei_lba = 0; lba = get_unaligned_be64(cmd + 2); num = get_unaligned_be32(cmd + 10); + group = cmd[14] & 0x3f; check_prot = true; break; case WRITE_10: ei_lba = 0; lba = get_unaligned_be32(cmd + 2); + group = cmd[6] & 0x3f; num = get_unaligned_be16(cmd + 7); check_prot = true; break; @@ -3647,15 +3657,18 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) ei_lba = 0; lba = get_unaligned_be32(cmd + 2); num = get_unaligned_be32(cmd + 6); + group = cmd[6] & 0x3f; check_prot = true; break; case 0x53: /* XDWRITEREAD(10) */ ei_lba = 0; lba = get_unaligned_be32(cmd + 2); + group = cmd[6] & 0x1f; num = get_unaligned_be16(cmd + 7); check_prot = false; break; default: /* assume WRITE(32) */ + group = cmd[6] & 0x3f; lba = get_unaligned_be64(cmd + 12); ei_lba = get_unaligned_be32(cmd + 20); num = get_unaligned_be32(cmd + 28); @@ -3710,7 +3723,7 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) } } - ret = do_device_access(sip, scp, 0, lba, num, true); + ret = do_device_access(sip, scp, 0, lba, num, true, group); if (unlikely(scsi_debug_lbp())) map_region(sip, lba, num); /* If ZBC zone then bump its write pointer */ @@ -3762,12 +3775,14 @@ static int resp_write_scat(struct scsi_cmnd *scp, u32 lb_size = sdebug_sector_size; u32 ei_lba; u64 lba; + u8 group; int ret, res; bool is_16; static const u32 lrd_size = 32; /* + parameter list header size */ if (cmd[0] == VARIABLE_LENGTH_CMD) { is_16 = false; + group = cmd[6] & 0x3f; wrprotect = (cmd[10] >> 5) & 0x7; lbdof = get_unaligned_be16(cmd + 12); num_lrd = get_unaligned_be16(cmd + 16); @@ -3778,6 +3793,7 @@ static int resp_write_scat(struct scsi_cmnd *scp, lbdof = get_unaligned_be16(cmd + 4); num_lrd = get_unaligned_be16(cmd + 8); bt_len = get_unaligned_be32(cmd + 10); + group = cmd[14] & 0x3f; if (unlikely(have_dif_prot)) { if (sdebug_dif == T10_PI_TYPE2_PROTECTION && wrprotect) { @@ -3866,7 +3882,8 @@ static int resp_write_scat(struct scsi_cmnd *scp, } } - ret = do_device_access(sip, scp, sg_off, lba, num, true); + ret = do_device_access(sip, scp, sg_off, lba, num, true, + group); /* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned(devip)) zbc_inc_wp(devip, lba, num); @@ -6828,6 +6845,31 @@ static ssize_t tur_ms_to_ready_show(struct device_driver *ddp, char *buf) } static DRIVER_ATTR_RO(tur_ms_to_ready); +static ssize_t group_number_stats_show(struct device_driver *ddp, char *buf) +{ + char *p = buf, *end = buf + PAGE_SIZE; + int i; + + for (i = 0; i < ARRAY_SIZE(writes_by_group_number); i++) + p += scnprintf(p, end - p, "%d %ld\n", i, + atomic_long_read(&writes_by_group_number[i])); + + return p - buf; +} + +static ssize_t group_number_stats_store(struct device_driver *ddp, + const char *buf, + size_t count) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(writes_by_group_number); i++) + atomic_long_set(&writes_by_group_number[i], 0); + + return 0; +} +static DRIVER_ATTR_RW(group_number_stats); + /* Note: The following array creates attribute files in the /sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these files (over those found in the /sys/module/scsi_debug/parameters @@ -6874,6 +6916,7 @@ static struct attribute *sdebug_drv_attrs[] = { &driver_attr_cdb_len.attr, &driver_attr_tur_ms_to_ready.attr, &driver_attr_zbc.attr, + &driver_attr_group_number_stats.attr, NULL, }; ATTRIBUTE_GROUPS(sdebug_drv);