From patchwork Thu Feb 22 21:44:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 775091 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C30E273F35 for ; Thu, 22 Feb 2024 21:45:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638337; cv=none; b=Hw9OTXHR4vO79r7z26IdSo2tmhU61lbi80ZpCY3/CT/0CW4VJWiU88NNHiGV0gRxWXhHudRRdbGw7gbwc/ccGxmEe1+H+ABrvhX91Q8Dmmu9ONM/LO9e0Qp+UMHDWNiX+jOtewj+vAnydUE9DPkiPydg6JPYtCTMHr8FQGR5vIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638337; c=relaxed/simple; bh=IZLFcYg2OIZSLkiQ/W/q/KUUDiPZzSGXAYOJi8me4oI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=msTpLCVb/nwHmV6tIluCHsvdsUfPyuSltSmghgzEAGo69NUGTXuE33hg3Qqi21NgIRYHbnFiC0+13dZ+z4/an+Tvd78kQfZGgCZWNrAI6gab3vSSXh9WmtxzHaSubsw6VpKGProtS1aQdaGemO1EaUnY3XAl1JKklijDkmM0Exk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.167.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3bba50cd318so126573b6e.0 for ; Thu, 22 Feb 2024 13:45:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708638335; x=1709243135; 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=jDsDYeayP8K2ZFZQIHRgga96Fxvejuk3hfJv5kIPTZY=; b=Uza7LtwtPyOeoTCACmlaLtjqL+5bnqtmUvtlhLmTiEfoCnECo8PcvLKjNfdQyjobe0 Wd26APIb1WA1PhNuxlzxLpnNXxfSUaESNaaRfrV4dTpcpM0U5RaTVUCqDvfyK1WOHkzn Vbpa9M3VVulAaGTwN8npPtbALvPCRbcYlYHX1cf5t9jvSqgmgtyTuuiY8pXq2cGogdW3 qrQQWqEyvU88+DaAzTH4xISM+7GdbYn4DpSV4N5pBMABUjnJm/h5YaNH1+XCYW+lH6YP XOlvCu/+IvUUBh8RGZZ14yeG7bC6cWgUxp6ZRVDdvBpu+xrT6XS81I596A8PDgdm7AMN MT3Q== X-Gm-Message-State: AOJu0Yw85hqlijUwVcjwFUlUE9hs0oudVVMIZXo5kM2QxRx46sZ1+aH4 WNA++EirZ0GyONXPOP0iZl4RKngRlkD1BxYxlUFutrmXBZIcItjS X-Google-Smtp-Source: AGHT+IHaMVYC8QyQy3ih8GZtYSEVQOSVIlFYGjDKMPveS8APaGUjP6YcAt/V1rqJGUdtb0uSjotsZw== X-Received: by 2002:a05:6808:1151:b0:3c1:862d:7e2e with SMTP id u17-20020a056808115100b003c1862d7e2emr178771oiu.50.1708638334668; Thu, 22 Feb 2024 13:45:34 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:bcee:4c5d:88b9:5644]) by smtp.gmail.com with ESMTPSA id a1-20020aa78e81000000b006e414faff99sm9598203pfr.180.2024.02.22.13.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:45:34 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Daejun Park , Kanchan Joshi , Bart Van Assche , Avri Altman , "James E.J. Bottomley" Subject: [PATCH v10 01/11] scsi: core: Query the Block Limits Extension VPD page Date: Thu, 22 Feb 2024 13:44:49 -0800 Message-ID: <20240222214508.1630719-2-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240222214508.1630719-1-bvanassche@acm.org> References: <20240222214508.1630719-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 76d369343c7a..74cc3369dd8d 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 0833b3e6aa6e..86b819fa04d9 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3108,6 +3108,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 @@ -3459,6 +3471,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 409dda5350d1..f1120de03d51 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -151,6 +151,7 @@ struct scsi_disk { unsigned urswrz : 1; unsigned security : 1; unsigned ignore_medium_access_errors : 1; + unsigned 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 5ec1e71a09de..f670b55d803a 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 Thu Feb 22 21:44:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 775461 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 127FA6E601 for ; Thu, 22 Feb 2024 21:45:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638343; cv=none; b=JpnYggaAdJX7HAxYvu6Su2Fnuw0vRNxFJP69rhhGshbrCAc+v/iwg8OeSwyJ8Myc2qJnRo98VtDy7oSYi8eusDUo3vLGjhvCi7/LWSRs8Y+M6xNb2orfwy4sH3+14XcIN5EUjnbxlNyP7Peh3phsF9HV0Tl8zu+wZuUbuEDuKpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638343; c=relaxed/simple; bh=vKkLynyPI87nBPlD+YkeLe9enWhazuyF+YIUJ+9jpD8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V4vIuGQH0ZIducGoqZl4rntXensMdUsFKoVxAlhnU6MBijpNAePa6kkOfouZHYpfZ6/TW1AyC/2PVfXzY4ZQ5HRKnj8x4hCQ/hV4FzPKx4ss4A33/0RcZDVkmWQWJuugWFth4+Zi80PkFZQY7524WNmY749YOJfQBaf1gYkkV2M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6da4a923b1bso125026b3a.2 for ; Thu, 22 Feb 2024 13:45:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708638341; x=1709243141; 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=42p6S51yVjjRx4XaJ49dXrO2bR8JV9Iikw1taYqMYk4=; b=FFVUXNS9osOK4GpRkg/vg8jm1A48NdloorrIXJ2oRGf8EU95U/Ryut1+nUKNmWKWg/ dWsfxmwsarZ1bo9IPGCv+c5IXyycu2yY9/DVrpSa511kkjue84+rm4V0qqbpL3rgbr0n nqIXYulV122UIgbI+v0MoVZLaw4gtzbCcZUJ0oa1A66wam9P63GgFWZS0x47XZfjLwl8 S1EgtyAcZJ1IBt6Jna0ZLFm13by97e5SzM1ZzWo9fDc6rnaW2g7G35Cn7jTtBaUdlUhA w059wEIbg2DicQO3Z/JQZb2oXf31ZhKKv/rBQPkpwRtLVsH3mFaaeADGaMnxUwoKAqxV J2lA== X-Gm-Message-State: AOJu0Ywlp6mQTcV0Cku4pOwfkhLaY3+RbCCspFgZAR2jH52mAc2tbXMJ 4o0xPeMSoJ+ZSQw3LBPECzePfFh8ntqiFIOT6MI4z72RM8S6wSHI X-Google-Smtp-Source: AGHT+IETsLQBk2X6xqcvY4T3QHCCEiFif67b0jwxxOLZmx6VmsB+Q5Wt/LLsB5v/eEDHFXPLsM0PXQ== X-Received: by 2002:a05:6a21:3944:b0:1a0:5841:6740 with SMTP id ac4-20020a056a21394400b001a058416740mr168288pzc.14.1708638341264; Thu, 22 Feb 2024 13:45:41 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:bcee:4c5d:88b9:5644]) by smtp.gmail.com with ESMTPSA id a1-20020aa78e81000000b006e414faff99sm9598203pfr.180.2024.02.22.13.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:45:40 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Daejun Park , Kanchan Joshi , Bart Van Assche , "James E.J. Bottomley" Subject: [PATCH v10 02/11] scsi: scsi_proto: Add structures and constants related to I/O groups and streams Date: Thu, 22 Feb 2024 13:44:50 -0800 Message-ID: <20240222214508.1630719-3-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240222214508.1630719-1-bvanassche@acm.org> References: <20240222214508.1630719-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Prepare for 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 --- drivers/scsi/Kconfig | 5 +++ drivers/scsi/Makefile | 2 + drivers/scsi/scsi_proto_test.c | 56 ++++++++++++++++++++++++ include/scsi/scsi_proto.h | 78 ++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 drivers/scsi/scsi_proto_test.c diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index addac7fbe37b..83b542abfc29 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig @@ -232,6 +232,11 @@ config SCSI_SCAN_ASYNC Note that this setting also affects whether resuming from system suspend will be performed asynchronously. +config SCSI_PROTO_TEST + tristate "scsi_proto.h unit tests" if !KUNIT_ALL_TESTS + depends on SCSI && KUNIT + default KUNIT_ALL_TESTS + menu "SCSI Transports" depends on SCSI diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile index f055bfd54a68..1313ddf2fd1a 100644 --- a/drivers/scsi/Makefile +++ b/drivers/scsi/Makefile @@ -24,6 +24,8 @@ obj-$(CONFIG_SCSI_COMMON) += scsi_common.o obj-$(CONFIG_RAID_ATTRS) += raid_class.o +obj-$(CONFIG_SCSI_PROTO_TEST) += scsi_proto_test.o + # --- NOTE ORDERING HERE --- # For kernel non-modular link, transport attributes need to # be initialised before drivers diff --git a/drivers/scsi/scsi_proto_test.c b/drivers/scsi/scsi_proto_test.c new file mode 100644 index 000000000000..7fa0a78a2ad1 --- /dev/null +++ b/drivers/scsi/scsi_proto_test.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2023 Google LLC + */ +#include +#include +#include + +static void test_scsi_proto(struct kunit *test) +{ + static const union { + struct scsi_io_group_descriptor desc; + u8 arr[sizeof(struct scsi_io_group_descriptor)]; + } d = { .arr = { 0x45, 0, 0, 0, 0xb0, 0xe4, 0xe3 } }; + KUNIT_EXPECT_EQ(test, d.desc.io_advice_hints_mode + 0, 1); + KUNIT_EXPECT_EQ(test, d.desc.st_enble + 0, 1); + KUNIT_EXPECT_EQ(test, d.desc.cs_enble + 0, 0); + KUNIT_EXPECT_EQ(test, d.desc.ic_enable + 0, 1); + KUNIT_EXPECT_EQ(test, d.desc.acdlu + 0, 1); + KUNIT_EXPECT_EQ(test, d.desc.rlbsr + 0, 3); + KUNIT_EXPECT_EQ(test, d.desc.lbm_descriptor_type + 0, 0); + KUNIT_EXPECT_EQ(test, d.desc.params[0] + 0, 0xe4); + KUNIT_EXPECT_EQ(test, d.desc.params[1] + 0, 0xe3); + + static const union { + struct scsi_stream_status s; + u8 arr[sizeof(struct scsi_stream_status)]; + } ss = { .arr = { 0x80, 0, 0x12, 0x34, 0x3f } }; + KUNIT_EXPECT_EQ(test, ss.s.perm + 0, 1); + KUNIT_EXPECT_EQ(test, get_unaligned_be16(&ss.s.stream_identifier), + 0x1234); + KUNIT_EXPECT_EQ(test, ss.s.rel_lifetime + 0, 0x3f); + + static const union { + struct scsi_stream_status_header h; + u8 arr[sizeof(struct scsi_stream_status_header)]; + } sh = { .arr = { 1, 2, 3, 4, 0, 0, 5, 6 } }; + KUNIT_EXPECT_EQ(test, get_unaligned_be32(&sh.h.len), 0x1020304); + KUNIT_EXPECT_EQ(test, get_unaligned_be16(&sh.h.number_of_open_streams), + 0x506); +} + +static struct kunit_case scsi_proto_test_cases[] = { + KUNIT_CASE(test_scsi_proto), + {} +}; + +static struct kunit_suite scsi_proto_test_suite = { + .name = "scsi_proto", + .test_cases = scsi_proto_test_cases, +}; +kunit_test_suite(scsi_proto_test_suite); + +MODULE_DESCRIPTION(" unit tests"); +MODULE_AUTHOR("Bart Van Assche"); +MODULE_LICENSE("GPL"); diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index 07d65c1f59db..843106e1109f 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,82 @@ 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); + +/* SCSI stream status descriptor */ +struct scsi_stream_status { +#if defined(__BIG_ENDIAN) + u8 perm: 1; + u8 reserved1: 7; +#elif defined(__LITTLE_ENDIAN) + u8 reserved1: 7; + u8 perm: 1; +#else +#error +#endif + u8 reserved2; + __be16 stream_identifier; +#if defined(__BIG_ENDIAN) + u8 reserved3: 2; + u8 rel_lifetime: 6; +#elif defined(__LITTLE_ENDIAN) + u8 rel_lifetime: 6; + u8 reserved3: 2; +#else +#error +#endif + u8 reserved4[3]; +}; + +static_assert(sizeof(struct scsi_stream_status) == 8); + +/* GET STREAM STATUS parameter data */ +struct scsi_stream_status_header { + __be32 len; /* length in bytes of stream_status[] array. */ + u16 reserved; + __be16 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 Thu Feb 22 21:44:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 775090 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A5F612D1E4 for ; Thu, 22 Feb 2024 21:45:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638344; cv=none; b=fHpdNZGqs54xi/eQEI+ix9YyXGK7JuXvFk1ZPdemZeTUdYYtcgXqWeR1DjGkPamQOoyd3x7ilP1lUJ/AgmHQsSOWbO/Dz15CfLo6rG7leVb9AAUHbh689st0wapBD1z+e28721fkRG9OKWqv2kw8w+x0hgCPAcP3HHCo+gHOeyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638344; c=relaxed/simple; bh=6Es1z9Z021Z+d2BSbfnWdCwEq2J0mG6QTi9n7uOvsr8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L+ovGiCic9cIUacFFRkyhd7XxQ6iVSthz/+rcxOt+4HI8rLYAnTuMLTUPJj93nGohkOIm9P3Pg1KtK13iJx5EzRjO6VqIVtsl2Q63qu0SMroyNz2DEXzTHYI1Yxf9S3IRvZQtGgIknRD2lXVQXe0hI1oMLIfZZn3IsjQAXJYM9A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6e4560664b5so100851b3a.1 for ; Thu, 22 Feb 2024 13:45:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708638342; x=1709243142; 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=omJq96HpIrT4jxUoJlMDOO+77ZTwDn15R2tbbux00I8=; b=FO3tkqvig8PBXWAIgXls5Ufwh6x+Z+i0BHHm+SYSQb6nghoRonPeEbSTSaiXkNMEES Eg5lkX7Q5Uz9in3cFa3W40+wS1br+rJAVv5j6ipuD7ucBjjMgLOYmhCakl/TWJ25uhwa BWjFt/baKFC/voTFHU79V0LjTSKqKyUPW+kK7sCQLIMI+ScA1ns9cMB8tPH3gioAP7do gm30zN2WveSn2RWYlbQ24hjTMZdpsMbnxkusG8tZ3/VjptsmUNvKiliyOw9fDyNjI3Rf GT8qfLCZEKTLlXAVbk61N1t3FZg1XFaqWYFvmW+Ex/Xv41OcJLlrHPO3UJFc+nsU3tOu LmUg== X-Gm-Message-State: AOJu0YxeMwt8c+5wIALfbl7qqbiklEjD4iOaB0uX/L9i53hz0sv7wse6 UQue7Mpi/pg7zOFK+wrrvrvf8gFR53o40fNtOwmZVePvjBSdK7EA X-Google-Smtp-Source: AGHT+IGLRSnDVvaDmNjdhydC2QgIbkwgi7S0tmq3dauPyNwkZTO945wn2mmXRQiT72Urfd3feOIBpA== X-Received: by 2002:a05:6a21:360b:b0:1a0:d5b3:8e1 with SMTP id yg11-20020a056a21360b00b001a0d5b308e1mr101253pzb.30.1708638342516; Thu, 22 Feb 2024 13:45:42 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:bcee:4c5d:88b9:5644]) by smtp.gmail.com with ESMTPSA id a1-20020aa78e81000000b006e414faff99sm9598203pfr.180.2024.02.22.13.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:45:42 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Daejun Park , Kanchan Joshi , Bart Van Assche , Christoph Hellwig , Damien Le Moal , "James E.J. Bottomley" Subject: [PATCH v10 03/11] scsi: sd: Translate data lifetime information Date: Thu, 22 Feb 2024 13:44:51 -0800 Message-ID: <20240222214508.1630719-4-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240222214508.1630719-1-bvanassche@acm.org> References: <20240222214508.1630719-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Cc: Martin K. Petersen Cc: Christoph Hellwig Cc: Damien Le Moal Signed-off-by: Bart Van Assche --- drivers/scsi/sd.c | 104 +++++++++++++++++++++++++++++++++++++++++++++- drivers/scsi/sd.h | 2 + 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 86b819fa04d9..48496e816409 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -1080,12 +1081,35 @@ 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); + + return min3((u32)rq->write_hint, (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; @@ -1104,7 +1128,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]); @@ -1119,7 +1143,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]); @@ -3001,6 +3025,81 @@ 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 int 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; + + if (!sdkp->rscs) + return; + + 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->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); + return; + } + + sd_printk(KERN_INFO, sdkp, "permanent stream count = %d\n", + sdkp->permanent_stream_count); + /* + * 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. + */ + sdp->use_10_for_rw = true; +} + /* * The ATO bit indicates whether the DIF application tag is available * for use by the operating system. @@ -3481,6 +3580,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 f1120de03d51..5c4285a582b2 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 Thu Feb 22 21:44:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 775460 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BF1A73F35 for ; Thu, 22 Feb 2024 21:45:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638345; cv=none; b=TGWFR0uEYjxuD6qiK6cZ9Q9d+uthdMjLMgw4RO/Yif5+LL44CE+rHBAUQlc3rJ36aICci9dvo2KgrmtRJlmJ6bm2GC/EfaUtRC1gJnPNMP1a9FTmHk87uM5RwRHcGHpED175fhytr8DJPyDVsCw15rBJ1+00L1Hn9EnpKTUWQqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638345; c=relaxed/simple; bh=j5NL+pf5dNmehOHSM4AtREv1UpGo9QI/k7CIUEVDncY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bMIm3hE5xknZ3ZdW2i+JSrcnx9vNBygStzXI5tf9HlJ4V5GHZLEarj6lXU/3epCBR5Aiz8G/tVU1ez92OF6oUe433r4rUeguwi6IGJVHOHcghRKgjXADB0xzSmNRL62JsOGmiiRKKd42lkvYjlJ3S343q3CG/qz1UeB5NMayRXU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6da202aa138so79159b3a.2 for ; Thu, 22 Feb 2024 13:45:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708638344; x=1709243144; 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=vZzeF2/oOW/Kgo+XqzYjaeSGsfNBRPeMT9QOp9BrwRU=; b=hOzOfg8nBzQgtCq2Rhs0OpIv5nmG94V4nx5iWW0gn0fIjKGWRM29utL3Zky+1wTzF0 UHj9QKE6ahTJ6WAubsMigr6SeDSPQZfRMEEBYYBxHGKVoqDxCkQqr6QUbwNfH2Wwwp7M 3sPMl+iFGfQMaVg82ZjyeVnFvgk3GZuda7QYHeEc2nRrEL4MX9c5yqDUZTO2gvbTKgkt UugKvOMwlpJKxYZqa+BovimeeHfKcMuvK/vXsl83tqZhSAEK21z7A279YuQN/E+0/x4T Kwzy15FrWce5qxmwBjEMn+YHDO6yoCkNsoob37haw9eWPAYdroRI2dzhifzpIiNmfKrY 3+MA== X-Gm-Message-State: AOJu0YysJucu8qRLz/yY0rcZbfvxa5fYPT8keNE0BFEPBfzpbXGvH01w wdSvpT37p6TQPYzIFcg8qKQ1XUxmaqC46SlfsYz0KpvQg9bonvkJ X-Google-Smtp-Source: AGHT+IFK6P2B3z0M9V1S0WcIzoAeQqs0kUEpWt+6biSFMJDcPa5+IDP6Zrc0ch/RC85fHjXdeq+VUg== X-Received: by 2002:a05:6a00:4f88:b0:6e4:7453:7ed2 with SMTP id ld8-20020a056a004f8800b006e474537ed2mr239999pfb.3.1708638343616; Thu, 22 Feb 2024 13:45:43 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:bcee:4c5d:88b9:5644]) by smtp.gmail.com with ESMTPSA id a1-20020aa78e81000000b006e414faff99sm9598203pfr.180.2024.02.22.13.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:45:43 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Daejun Park , Kanchan Joshi , Bart Van Assche , Avri Altman , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v10 04/11] scsi: scsi_debug: Reduce code duplication Date: Thu, 22 Feb 2024 13:44:52 -0800 Message-ID: <20240222214508.1630719-5-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240222214508.1630719-1-bvanassche@acm.org> References: <20240222214508.1630719-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 All VPD pages have the page code in byte one. Reduce code duplication by combining all page code assignment statements. Reviewed-by: Avri Altman Cc: Martin K. Petersen Cc: Douglas Gilbert Tested-by: 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 d03d66f11493..994a2b829b94 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -1903,7 +1903,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) @@ -1914,7 +1915,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 */ @@ -1935,23 +1935,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 */ @@ -1961,30 +1956,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 Thu Feb 22 21:44:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 775459 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1D8F73F35 for ; Thu, 22 Feb 2024 21:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638348; cv=none; b=AVq28KhKPQ+5keieH/Ni3hnfOaio6JgS4Ls0+JulS3hUFqQ1l3Aiq33cCPrWBDfyS2uJu5Lpzxnb6uztfWDqndljEfSP+i2swH0nEg5K3rBfBpx6Vk2kDVe6ynCS2sIg7uG834hDwrR6bnb6cR0vOfzNrpDq1xIjF03KpdGUVeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638348; c=relaxed/simple; bh=ReoAgyArusvAYBEY1Dxq9pKXMLzy1yk/3CyhJgGq2xw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u456ASRHXhBglXiIejaQkzzh0BacoeeYZTj/D2y8dC7zLezdzIGmak9inZ91APyf0HcecQZfTo+QqSvi0trpRJ4FPqxADjwofggtcXBb3n3VzIOf2lSnZXPtOAmHgdUGu+El0AslsDuwRQBilhViljV+l2A3CaOAzigMRdas/ys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6e46dcd8feaso64447b3a.2 for ; Thu, 22 Feb 2024 13:45:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708638346; x=1709243146; 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=2qSkiYLEpndgk91NEKVImgnQ0iTk/12SnGdfVXY3CVY=; b=nJ0NybmT3/d6+faDBqR0/DCX9BEOZFg6Mao9cR87HE2+5XGNH6BB1YMZ0oYJn+et2F wjMUyr8bUjJ0Fc72R5IDK6idqIT82je0+EpnN40UXATLH6Hx5H7glIMEYT3UELlQPJjS Ig04yLvFHheb8tJo3DTpzAkofIrAJEXBxett85u1AkJ8651iBIh+1IlmIO1EtqcZzkor 7NcN/hg+QNh9ah93AueNBOpu8Kj3VUQRtYTcBX1RAwSlcW3pOyUoxibayDiuvSh0/laQ loiexe1FXYsvmLim3Bv4N6v65aOCbbGyb+Y0g7SlpMbhX78erdQiaiKH217Z9pPt11l6 L8pw== X-Gm-Message-State: AOJu0YxL1XbG8ZACk+bc8qgmTdEkoev9hsPt5p9NBpAwe28Uo+HRpCM4 gMFhNkfRdj/Ra7eBL2s1ca8dNV/yh7Ii686HGAJnN2B637x5i8OByvKWydwo X-Google-Smtp-Source: AGHT+IFW+F91cwA1RPrd8SZWeO410QMkdR8a/Wlg07cuJeoSjMstUsDvQF4Uy2JW+4nE00lMc3Rbww== X-Received: by 2002:aa7:8449:0:b0:6e4:5a0f:b87a with SMTP id r9-20020aa78449000000b006e45a0fb87amr178445pfn.12.1708638345752; Thu, 22 Feb 2024 13:45:45 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:bcee:4c5d:88b9:5644]) by smtp.gmail.com with ESMTPSA id a1-20020aa78e81000000b006e414faff99sm9598203pfr.180.2024.02.22.13.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:45:45 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Daejun Park , Kanchan Joshi , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v10 06/11] scsi: scsi_debug: Rework page code error handling Date: Thu, 22 Feb 2024 13:44:54 -0800 Message-ID: <20240222214508.1630719-7-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240222214508.1630719-1-bvanassche@acm.org> References: <20240222214508.1630719-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Tested-by: 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 8dba838ef983..ba0a29e6a86d 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -2644,7 +2644,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; @@ -2708,7 +2708,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 */ @@ -2723,15 +2722,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); @@ -2784,18 +2785,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 Thu Feb 22 21:44:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 775089 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E2B012D1FD for ; Thu, 22 Feb 2024 21:45:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638349; cv=none; b=NPmWVR3UTa32IinMchUcQ6yEFTC2xkFpajHJ/p+aw8kaLIiiuJfePsRgMJcYuoJvdk+QNH+zydS35aYhdpiJA6pfg2p+gCt92C4pFCOGSkgBvHPiQnN4hVpH6dYuZrDTeVG8X/qgbINm7+Q7E3ID/DH4MZa/1Z8GO6R76DI/Jd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638349; c=relaxed/simple; bh=mW+VEHSEMe5NTiO4ammMUexCtbQO4umn8rI2uNjOxkA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kd0RV57TnYJCeOLQEXh/l8sny4CXJrDRr//fubcfqVyhuu+6Dkad7/Jx+QTCcHc8kUIXlDbegIdsUHBzevnUh0tSgaGvkbu2Yc9Dy/jeITJRy8m2NJP1nRFPiUVVQT8YnJ8bBZw5d6OdSvJxtSKiilO5HzpyjY6UVgmfJLrsvYA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6e34d12404eso86954b3a.2 for ; Thu, 22 Feb 2024 13:45:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708638347; x=1709243147; 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=tbVZNnyK3WhWIR+xZPdP47ThSfpJCvGfnUGz/BJTKu4=; b=FHnZyU/1Znv04y59ivlnyc/Jd89A5qeVrrpehah8lfqEnfFAT1GubW34cHPZAbeEcM wVWYKLrghoD1Pu1+ladWK4t4t5XRPQTMOnzn2diBy+4Yame6wtdAdlluocHMetRn2DcX dMdqb5bW3apyLyoBUfgoxKb16/+lncew3kzW6/q0Zis0o7EzlwpnnQrPWleyJs1m1YeZ dG4AgBAy6VyZl2RNUm8DhJvOm01p7EQ7LnVkeYbjFCvmNvW1H7xEFZhUVSWeEvPApepd +o/FxnGDjL4J2mpUG2Y+ucV/JZTt62tK8Znhtxs58lRqvG2KdC9LeFq5POHB3KWJTI1X xSMQ== X-Gm-Message-State: AOJu0YzVBGvW7FY0u5w5Dv+s4XvyMgJKxPOFpHBx5iNpnfLJzmTK+K4f 1/MzHMKvXlfsFwqL/j7AIrsHoNOWx47KlvNKI7gRetlDcMU1SzyR X-Google-Smtp-Source: AGHT+IH198SnUzC9uexgBweFIPBYov/JuCatyGTYWFWICOwC6qF9ejbHrI9nnHOSHGn+0uSLBmQJcQ== X-Received: by 2002:a05:6a00:70a:b0:6e3:84cb:3d51 with SMTP id 10-20020a056a00070a00b006e384cb3d51mr117322pfl.33.1708638346860; Thu, 22 Feb 2024 13:45:46 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:bcee:4c5d:88b9:5644]) by smtp.gmail.com with ESMTPSA id a1-20020aa78e81000000b006e414faff99sm9598203pfr.180.2024.02.22.13.45.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:45:46 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Daejun Park , Kanchan Joshi , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v10 07/11] scsi: scsi_debug: Rework subpage code error handling Date: Thu, 22 Feb 2024 13:44:55 -0800 Message-ID: <20240222214508.1630719-8-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240222214508.1630719-1-bvanassche@acm.org> References: <20240222214508.1630719-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Tested-by: 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 ba0a29e6a86d..67a8e6243e5e 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -2703,22 +2703,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; @@ -2727,6 +2727,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; @@ -2735,14 +2737,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); @@ -2754,35 +2756,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; @@ -2796,6 +2794,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 Thu Feb 22 21:44:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 775458 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C007012D1ED for ; Thu, 22 Feb 2024 21:45:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638350; cv=none; b=RSsoB2ouV2YXm7Q7scSXyiQyr5GfqJr4+fxkyRJSBTGtTQCCVqFfVXmu20zU6wNDciE1FyQvnlW8Dw5n0Dxc8mfY6PntYVuGNqeEhvZ5f4iq99dzpw6xGInmNrz0hq3oifZ0tfWx2H3QXOcrpPQ+v57UdONvpEjuzPubuyl3jgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638350; c=relaxed/simple; bh=1me+1Iv1gWQ+ySDhaIkrWsKCsTYqu1di4VIRAFR4faQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J39PidbGh+gDEX/XHATqzMlz/EBctNewzgh54SQfzt1Poj/IrvOTwIjdX1qgMeqkfRpjUVfgeD38zBrOyVISF1y5T/DwYB2AKK9dWL9ritKY2/k3ZOjRzJSL2WGvC3MsWRi8UpkciX5m4pxTMHgrAbLuhYjuD8KFx+n7M1KjGb8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6e332bc65b3so91074b3a.3 for ; Thu, 22 Feb 2024 13:45:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708638348; x=1709243148; 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=i3J+SA4hd8ZssMKvGLhLa01/X8dHvroLM2Zuh1UtpU4=; b=hKxPQUkUg3M5BZSkIGbBHuIreZYfvd7uWwkC+g/Iqf4Rr3ZDdkqTiaPVNF1Cbd2st5 prem4bxtMyZKjkisMyVVNBfqqmuZ74b0SMMUkgxxDveFlyfPDBtwlapdQvZWy/YvxotJ W5wOi60ml4aN4U17kXjfrvCcpBMUggiIKtMFoRjReoE2P+idRqf+dToFGXXfMjCpC5Hp cQlMJ2dmc8WFS553ebutffzVy0uUXVVVkydidBS9zetPkyj5MDpSB05u+YElV9z8MfcT fTroer8KlVNgG5sexe+de0eu0BDHSEOsflfhCqVs2vTa4j/oEs7XQlhZHLdbNT2w7S5B gfuQ== X-Gm-Message-State: AOJu0Yw2TG1EuSvF4E1b+KP+2CV7WYClUuByXH34BrsKzpQviVijJ8L9 pB3Mr4L/P5r8LCL8D1Pw0coZlaeTn/BwhxxjR/THjwi+MwwrAY4q X-Google-Smtp-Source: AGHT+IHbobqYv/wVir22xNwsC8GjqciZtOOKVbcKhAEvhSjmsmv7kAsVfBvHbud/s0ACGL67qzxXHA== X-Received: by 2002:a05:6a00:1988:b0:6e1:4085:dd4f with SMTP id d8-20020a056a00198800b006e14085dd4fmr184245pfl.25.1708638347942; Thu, 22 Feb 2024 13:45:47 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:bcee:4c5d:88b9:5644]) by smtp.gmail.com with ESMTPSA id a1-20020aa78e81000000b006e414faff99sm9598203pfr.180.2024.02.22.13.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:45:47 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Daejun Park , Kanchan Joshi , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v10 08/11] scsi: scsi_debug: Allocate the MODE SENSE response from the heap Date: Thu, 22 Feb 2024 13:44:56 -0800 Message-ID: <20240222214508.1630719-9-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240222214508.1630719-1-bvanassche@acm.org> References: <20240222214508.1630719-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make the MODE SENSE response buffer larger and allocate it from the heap. This patch prepares for adding support for the IO Advice Hints Grouping mode page. Suggested-by: Douglas Gilbert Cc: Douglas Gilbert Tested-by: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 67a8e6243e5e..b544498324f6 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -43,6 +43,7 @@ #include #include #include +#include #include @@ -2631,7 +2632,8 @@ static int resp_sas_sha_m_spg(unsigned char *p, int pcontrol) return sizeof(sas_sha_m_pg); } -#define SDEBUG_MAX_MSENSE_SZ 256 +/* PAGE_SIZE is more than necessary but provides room for future expansion. */ +#define SDEBUG_MAX_MSENSE_SZ PAGE_SIZE static int resp_mode_sense(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) @@ -2642,10 +2644,13 @@ static int resp_mode_sense(struct scsi_cmnd *scp, int target_dev_id; int target = scp->device->id; unsigned char *ap; - unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; + unsigned char *arr __free(kfree); unsigned char *cmd = scp->cmnd; bool dbd, llbaa, msense_6, is_disk, is_zbc; + arr = kzalloc(SDEBUG_MAX_MSENSE_SZ, GFP_ATOMIC); + if (!arr) + return -ENOMEM; dbd = !!(cmd[1] & 0x8); /* disable block descriptors */ pcontrol = (cmd[2] & 0xc0) >> 6; pcode = cmd[2] & 0x3f; From patchwork Thu Feb 22 21:44:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 775088 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3A2E12D1E4 for ; Thu, 22 Feb 2024 21:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638351; cv=none; b=DLPbGjA+CQYkv+T82i1ouia4Z5WC0K5+ZtOjd0lE5MTZbOkpIZ7UNhm1nlHkKnwIXMRT1WbvLXJOQQjlb/fqq7yH2hrr4na+izajj1SMqwvf1DRy0sswdiBCz3rkNA7GvbmTiIpeArOhwyUWCNK5kSVxgArMs20n/xvfahwQIW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638351; c=relaxed/simple; bh=Zf0R25Rg1mXeSROfgZKxHfIZKaY0FWVp6rdNT8OKDps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GdbzXY8YZ15Wxu6FncNt4yU3el9lmOMgxG7V1kFlV8do+denFFrVQQHfNQVJHrtaQv1F3yoNK6V177aDtB64swRey6Gvab5tdTLfUdjzQHREOd12lMUxlbSYX8G8nEgvAbOVdGBxMTVGPqjAH6rqJ4XBWgPwi9VR/RmJOCxu/q8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6e43ee3f6fbso98653b3a.3 for ; Thu, 22 Feb 2024 13:45:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708638349; x=1709243149; 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=N+HWSlaiIpcKUI/XYMTeimlVB+yEtY/A7WgNkX4Hy3o=; b=sL9kIB67oTo3NZy8K6/YtVHl7Yeqp2IlQR5e4ZKCvntHxtdKjX4jrloxhKI/CkBAD1 sIISu8QCLwbEhZkAprKZYP4kCtt1UMiOw5x+yC04cYtTQe5Rr4GKYMmLzbFXgmn/Wh9u WsdZ3VfMPEal6rTycMH1WYbWrIPgtGSuE1Hoy+0EwQ1HgI1k8RXCU2W4RIuBh89Ultph 7eOV25KQeO+TeHbxjAiniR4OPLHKUYQhl9KqNOJQtnDC/ozfDMRyRsJZ1xc1NEfrCk31 mS+SQnwwy6koJFk3rKXJu8BnDnGoyZUbebaxBG3JJwzt4mC+e+o1QduxSPbw72HwZde+ nqhw== X-Gm-Message-State: AOJu0YzPoeoPOkTeU90qxmEETmr8ZwVBSmavztslcDeOEcbGuFtv0gVD W+Q/eLsaV2vzkg/rb75WAlQEnXHtUeVP2uzVuvawvQ+MLLC3KPfD X-Google-Smtp-Source: AGHT+IHrQK7kHqtSXfeUUzC4n4a0HuhPySvbJ2sXDBnfLN1hThsLzlWob5cwYVWYyOt4W/EUTgTkGA== X-Received: by 2002:a05:6a00:939f:b0:6e4:c4c3:d4c6 with SMTP id ka31-20020a056a00939f00b006e4c4c3d4c6mr168865pfb.4.1708638349079; Thu, 22 Feb 2024 13:45:49 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:bcee:4c5d:88b9:5644]) by smtp.gmail.com with ESMTPSA id a1-20020aa78e81000000b006e414faff99sm9598203pfr.180.2024.02.22.13.45.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:45:48 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Daejun Park , Kanchan Joshi , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v10 09/11] scsi: scsi_debug: Implement the IO Advice Hints Grouping mode page Date: Thu, 22 Feb 2024 13:44:57 -0800 Message-ID: <20240222214508.1630719-10-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240222214508.1630719-1-bvanassche@acm.org> References: <20240222214508.1630719-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Tested-by: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 61 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index b544498324f6..ccf59b3e7602 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -1969,7 +1969,11 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) arr[4] = 0x5; /* SPT: GRD_CHK:1, REF_CHK:1 */ else arr[4] = 0x0; /* no protection stuff */ - arr[5] = 0x7; /* head of q, ordered + simple q's */ + /* + * GROUP_SUP=1; HEADSUP=1 (HEAD OF QUEUE); ORDSUP=1 + * (ORDERED queuing); SIMPSUP=1 (SIMPLE queuing). + */ + arr[5] = 0x17; } else if (0x87 == cmd[2]) { /* mode page policy */ arr[3] = 0x8; /* number of following entries */ arr[4] = 0x2; /* disconnect-reconnect mp */ @@ -2559,6 +2563,40 @@ static int resp_ctrl_m_pg(unsigned char *p, int pcontrol, int target) return sizeof(ctrl_m_pg); } +/* 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; /* OR 0x40 when subpage_code > 0 */ + 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 | 0x40, + .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 = 1 }, + { .st_enble = 1 }, + { .st_enble = 0 }, + } + }; + + BUILD_BUG_ON(sizeof(struct grouping_m_pg) != + 16 + MAXIMUM_NUMBER_OF_STREAMS * 16); + memcpy(p, &gr_m_pg, sizeof(gr_m_pg)); + if (1 == pcontrol) { + /* There are no changeable values so clear from byte 4 on. */ + memset(p + 4, 0, sizeof(gr_m_pg) - 4); + } + 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 */ @@ -2708,6 +2746,10 @@ static int resp_mode_sense(struct scsi_cmnd *scp, ap = arr + offset; } + /* + * N.B. If len>0 before resp_*_pg() call, then form of that call should be: + * len += resp_*_pg(ap + len, pcontrol, target); + */ switch (pcode) { case 0x1: /* Read-Write error recovery page, direct access */ if (subpcode > 0x0 && subpcode < 0xff) @@ -2742,9 +2784,20 @@ 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: + len = resp_ctrl_m_pg(ap, pcontrol, target); + break; + case 0x05: + len = resp_grouping_m_pg(ap, pcontrol, target); + break; + case 0xff: + len = resp_ctrl_m_pg(ap, pcontrol, target); + len += resp_grouping_m_pg(ap + len, 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 */ @@ -2778,6 +2831,8 @@ static int resp_mode_sense(struct scsi_cmnd *scp, len += resp_caching_pg(ap + len, pcontrol, target); } len += resp_ctrl_m_pg(ap + len, pcontrol, target); + if (0xff == subpcode) + len += resp_grouping_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, From patchwork Thu Feb 22 21:44:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 775457 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4D00131722 for ; Thu, 22 Feb 2024 21:45:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638352; cv=none; b=bOvHER4RUT+ddvi+NCuJ1jyFb5TPyMynQJ6d0aOC4dxjCuqQVPnbjsxwoQ+4om7lgn1Rbf5FsAn/Dolgi92C1MqFydp/cxN+jIKC/8gJ7oOt/7mqNEn2l+Ur1rGCAMfIw9oxa4H1NVDlg5KPIfWEh2QC9CJNOsljrOMDfW8GYUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638352; c=relaxed/simple; bh=pGSlucTX1aa7NSOV1toYrh+mVFV8y0R0cQ5zCPzahHk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m1gOSnWkF3ajIm39DzUn8xx6+Y1RT4DYqeP7ZuW2rZEOE9B7m8kY+gKEPCRFqxsNbqeKS6nmWhmpSISkag+skjZTMVDhgNsyaXtBMkPF1YIm3B5Nbc5HxKPmtVTHCCo8hxVqxGbcaELeu6YXKFFwWRwRF74PY3ZjAAANxWBu9ls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6e47a104c2eso81648b3a.2 for ; Thu, 22 Feb 2024 13:45:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708638350; x=1709243150; 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=e8d++JaxF6VU87K9paur+P9+uK/jbaFQAG39Cl7Itqo=; b=patRSZmzhOHCc3RVpIgi0qejtTHZ8G2YGUTOTogA8E/KW8DnmhV400EIBvTtnV3jZq qm8UatuGefSQYb7mWlbPkPPCIoWIgyuQsJCPb1gW2iPf2A8H1J01yj91DtCwHFJD/q8X N0DMYmvKQqboTJ31OxW09c/HGfezEE7zuFdjnCkoxC/dq4W/92YWrQjXZ587b6hvK3Av UhItgOSMoOyVs/VLnn50f1zE7gn2YYhv8opMVWFNDg7qRM9t7zEAE7j3TUxvkCcr2c7N RGi2PUNp9QG6aWNbaVi5qcm9p5mjr5XSfgZb/VPe24Q7DAw2XMEwtL1WR8Nct9rseGxD w46g== X-Gm-Message-State: AOJu0Ywvx2yfCKCCqdirWWwnjHP/ldr5X3bCHXDorXgo//q9YFfT/RRX VGf/zse9AtuZrnQSAq2dorK6XwXHw2ixHu8RiPQAbw3hKgC0ig4XswiXsmVa X-Google-Smtp-Source: AGHT+IE20CTHM5bY/kL7TZHCZhKRoNQv18BcD8pfPz4+mLKs0IPSntl7QETagxEQlANFrAigkZVRpQ== X-Received: by 2002:a05:6a00:b91:b0:6e4:8c40:3f09 with SMTP id g17-20020a056a000b9100b006e48c403f09mr155086pfj.25.1708638350110; Thu, 22 Feb 2024 13:45:50 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:bcee:4c5d:88b9:5644]) by smtp.gmail.com with ESMTPSA id a1-20020aa78e81000000b006e414faff99sm9598203pfr.180.2024.02.22.13.45.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:45:49 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Daejun Park , Kanchan Joshi , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v10 10/11] scsi: scsi_debug: Implement GET STREAM STATUS Date: Thu, 22 Feb 2024 13:44:58 -0800 Message-ID: <20240222214508.1630719-11-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240222214508.1630719-1-bvanassche@acm.org> References: <20240222214508.1630719-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Implement the GET STREAM STATUS SCSI command. Report that the first five stream indexes correspond to permanent streams. Cc: Martin K. Petersen Cc: Douglas Gilbert Tested-by: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index ccf59b3e7602..497045e54300 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -533,6 +533,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 *); @@ -607,6 +609,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 */ @@ -4573,6 +4578,51 @@ 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] = {}; + struct scsi_stream_status_header *h = (void *)arr; + + 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; + } + + /* + * The GET STREAM STATUS command only reports status information + * about open streams. Treat the non-permanent stream as open. + */ + put_unaligned_be16(MAXIMUM_NUMBER_OF_STREAMS, + &h->number_of_open_streams); + + 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, &h->len); /* 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 Thu Feb 22 21:44:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 775087 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E616673F35 for ; Thu, 22 Feb 2024 21:45:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638353; cv=none; b=UVVmWkM2IJDVlet9LKCouikCBHC+u2V7ETzxZm57LZyajG8xem2jnT4dLg2X+iOlGzigSynLM+TeI3lP9Pkz4pZ/NSOKDY6JEJDpYMsFn1DiKaBzMrEF36kO5l9X2cxenuX9ZJJyINK6QSl4NNnhY1Q0aQ1LJGJzUsbMyCRwCjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708638353; c=relaxed/simple; bh=QM3pj8RymkvttqcCJVdupGcih6w4z7Gl+b93y9il9A8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GSnq8+9RsfZKG7Ijr9AlsBGjIN7bTCUJC5oPG807qdEQ2dT7Wrc089galviRlS/UEpxfFzHm64F3MQDXU1n8+efBlfOX6lJ+C3D6AckHtjJUkj0Lncz/g2iMAtXyswitUb6tdBIsmqwIcd1HKtzA+NbdHgkJGKkgBdMTvqw9/c0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6e34d12404eso87004b3a.2 for ; Thu, 22 Feb 2024 13:45:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708638351; x=1709243151; 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=V0Xmdm/OHLZ7BZpyv4wwjqwC83xCcMmBotSHyQroMK0=; b=qRLEYUDWHoWYTPpn7QJtX6kIHCXfJFNwhK9sK7T/bFcr643OGIvE09X2fTgaAYuvyQ b87WmrE4HL5yNmACxU5AVvpT8dspB7s0o5AJgMDCbqXmh+NnymPgzIafq39hYDiwVl2i zF6d2Ca7iiy7JyoAmnilQkGW/LnM0935XkyUD+JUeNaE1q/r5Vaq+FSJPcab7OBA5mVr 664IvpdgvFbCtvDIUOz1T3yFj4Z60vpHW3qEj1TfBxPQ/8FwB8z/jBKsvKvv49o6Ui0E wjjLByMUwelP99zAMebsbrGblKMR1zaCE9jYOV9CgG8EJXaMYGoB4xdFCdzUPTCSNmYq /nCw== X-Gm-Message-State: AOJu0YxzmE63UNHJ28/5qZc5a/uP1JlJi2goLfJagycQNzbOpn7Pnfnn igu8LzLWpXQ2rLTkMPDYnhZKvWUl2i5UP51V5uA9zePCq7YVs9yd X-Google-Smtp-Source: AGHT+IFsba57CzwzFTSgifwOg5HdZCq+3HWSOx+5/M+g+HsGdle+S3f7EeVottYWvtD52uDh/XCVWA== X-Received: by 2002:a05:6a20:5194:b0:1a0:c3e6:3135 with SMTP id j20-20020a056a20519400b001a0c3e63135mr111602pzf.28.1708638351342; Thu, 22 Feb 2024 13:45:51 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:bcee:4c5d:88b9:5644]) by smtp.gmail.com with ESMTPSA id a1-20020aa78e81000000b006e414faff99sm9598203pfr.180.2024.02.22.13.45.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 13:45:50 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Daejun Park , Kanchan Joshi , Bart Van Assche , Douglas Gilbert , "James E.J. Bottomley" Subject: [PATCH v10 11/11] scsi: scsi_debug: Maintain write statistics per group number Date: Thu, 22 Feb 2024 13:44:59 -0800 Message-ID: <20240222214508.1630719-12-bvanassche@acm.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240222214508.1630719-1-bvanassche@acm.org> References: <20240222214508.1630719-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Tested-by: Douglas Gilbert Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_debug.c | 49 +++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 497045e54300..ce52d580d1aa 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -902,6 +902,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; @@ -3377,7 +3379,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; @@ -3396,6 +3399,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); @@ -3769,7 +3776,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; @@ -3954,6 +3961,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; @@ -3965,11 +3973,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; @@ -3984,15 +3994,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); @@ -4047,7 +4060,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 */ @@ -4099,12 +4112,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); @@ -4115,6 +4130,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) { @@ -4203,7 +4219,7 @@ 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); @@ -7298,6 +7314,30 @@ 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 count; +} +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 @@ -7344,6 +7384,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);