From patchwork Wed Jul 13 07:20:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 590249 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 30A51C433EF for ; Wed, 13 Jul 2022 07:21:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234372AbiGMHVt (ORCPT ); Wed, 13 Jul 2022 03:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234708AbiGMHVm (ORCPT ); Wed, 13 Jul 2022 03:21:42 -0400 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2066.outbound.protection.outlook.com [40.107.96.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F51BC444D; Wed, 13 Jul 2022 00:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ces1hp0VphY/+rM5L3o9xzMQHPwM5zeCkdEj+vYtHnXQFvJg88kHs2BZMXAQjqGHE4PVrzEp12KPWIwCKz6+UFFJRyS7vFF2ZeFHFUYfTSu5FLMxmpU7bDRv6hLcBMe+eqx/GqUihUqXSJnnobI8AuRdTspXNZtc+Nq/2AtmJEYf/0A0r84VCyJ7dDqxES0Dl2gP+mg2w/1aV2kssm6ro/AsBS9gwZJDuPdwYfqY/gUDCL6ckC94nWfLpn3vCYmB+2UxykPxiRe6RIpxsW1mG8E5x35+RGyu19+S/2aeZQ/QEayUh43NDsO6wUcUFUoICdU+GTz20CsdT3ux84IoAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VE7jo1aPoWeVsjqVruNOXX2q9+W6F6XYr+aNXAjKYvI=; b=A5Ea6hXgd/1m4tCRVDpDjJtYq7qlKW7XvZA0Ud2xjmCRgQyu8JApSJxJtOzDq/obcNWPxN3Aw/43zNT6aSJxc1k/UKMYG7BGwGR/38+pep9CaAUdIcg67ghYCPThN+2yCnwV4yc2nTYVe8WeH9j6Uwh/dYQqlS42lZqwOhZZRWXnup5a7G36AQfoa0HidpKc3qYt1WPUgbiWKe/hFF9vnUzGTJbeu5ZJ3Z/3zXANpFe9+XQQmZmH7Spn+AO1pMNjolr9k1CzbPfvzZxaplwC1tBY16KO5wMzq1FUi7dpJ2mA0VhbNoVNamus29peAvtazg7NxRh8ZRhJgiANDsD9tw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=kernel.dk smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VE7jo1aPoWeVsjqVruNOXX2q9+W6F6XYr+aNXAjKYvI=; b=tJ3gk24kFle6zQ9g776L5FFyCv3+3hfXI3Gr8QPB+FbcTSZaEGFUarg02ZyGPZHwN612xsDQ6WVnKDPC7yc7r33gW9kM9Mgi/PLk0TUa/bXEaZE2M+NEdWotxwrwepLPKd27hCzE2XvBjnwAT4OZXBlaSBsr2M+DEaCBhByfrVQK6qzkYKObRG/VVwh28s+ABNxUdSSlnGTSWav08vWlikHmKg2Rn7kWQUF6n4qDyVzVqhqac3Jh038uPzUCX+xyeLe5UKM1Ty8gitE98/LoLE7n+7HX1Oka0AYpPnAzFLmAewUL6j9PvwVgJKLm5+LCSpt6T2GRIxWbb8tOgZLnCw== Received: from MW4PR03CA0212.namprd03.prod.outlook.com (2603:10b6:303:b9::7) by PH0PR12MB5500.namprd12.prod.outlook.com (2603:10b6:510:ef::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.16; Wed, 13 Jul 2022 07:21:28 +0000 Received: from CO1NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::3f) by MW4PR03CA0212.outlook.office365.com (2603:10b6:303:b9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5438.12 via Frontend Transport; Wed, 13 Jul 2022 07:21:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by CO1NAM11FT054.mail.protection.outlook.com (10.13.174.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5438.12 via Frontend Transport; Wed, 13 Jul 2022 07:21:28 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 13 Jul 2022 07:21:26 +0000 Received: from dev.nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 13 Jul 2022 00:21:23 -0700 From: Chaitanya Kulkarni To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Chaitanya Kulkarni Subject: [PATCH V2 1/6] block: add support for REQ_OP_VERIFY Date: Wed, 13 Jul 2022 00:20:14 -0700 Message-ID: <20220713072019.5885-2-kch@nvidia.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220713072019.5885-1-kch@nvidia.com> References: <20220713072019.5885-1-kch@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d2c2658e-557d-43dc-2b7b-08da64a04d5d X-MS-TrafficTypeDiagnostic: PH0PR12MB5500:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IxDilZGDEvnPvZXc+IvRv0MQzex8wMun98eqtA7kdd+SFvAcPr0Ol7gjZJYuhserY00wuGDzTmtO71GoEPB9L7FyBtqan5NEOw5jzOOvALmBM19shQGvBygUr5FZiGS1lSPud+8VWg1hQvXh7EUoFCQt6zgjeUPbxoXekNiubGQKAe4CNG9qZrDBR5fw0B2QHCl0VJZmkOo39C1DDl2leMATnWJFERZG9uO5MHZLqyKdp4oDT8tR7o7VmyYTMwFdShs4F0qRzY7dA8geM3y9wgWg4BLhxhZU9/DxYt9agr9u2Ylp6R4/CgN/XPZ2m4VufCcU5BNDFvnCqLygZwYVHXkWIIGAtRbBwxmalYi6QMRpp+yeJawgwKgKzktYWMH44BBHCVycSDrN1WFMKlZNIR7cMLbThoWq2msHuotbf7MBE0mPliKQkm7tFl4IXfcVZT19YIGhXIWCA5xRO/2B/nU86dokMLqPLiCYiXVuQwdQmEPsJ39SAbyd0LsYSl4/Ap8xBF1PBxnKO5XykiShfX4cjC/RQzaMLSiMbHhukkJqbUG8ftT6rftVFJjz0BjRzXhD2GNMs0rtNaSZGpNx2S2KyHXOzFTVpJYx3hwZqXkCD9vygY0qedocKhOODoqIHXxn8V/7L3qWoC18tLLqQMRQpdz0wAQnzgzDpQr6rNL61aTeg9nncy2HuDRRhH1oARCWKjxhND76TkwEs3y+d4PA/CnU+JYPHqAAEcRsP91OyyUnyv+4OmrNlFBuLs62BvxLlKyHGj8d0YuN0Yip1Jts2X8eUijhekzr0xSQ+9GmAw4yhiZHxOZJD2KRAbLdPoSK60HhFq0UyyDL8TX5wiFsQMVtbUjBGRSLhefKRZqO8k2WvzYaUIDWSuzMZEMq X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(136003)(39860400002)(376002)(346002)(396003)(36840700001)(40470700004)(46966006)(1076003)(70586007)(186003)(8676002)(2616005)(16526019)(7416002)(316002)(107886003)(426003)(336012)(70206006)(4326008)(81166007)(6666004)(82310400005)(7696005)(47076005)(40480700001)(36756003)(41300700001)(478600001)(82740400003)(40460700003)(110136005)(54906003)(8936002)(356005)(2906002)(7406005)(30864003)(36860700001)(83380400001)(26005)(5660300002)(2101003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2022 07:21:28.0593 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d2c2658e-557d-43dc-2b7b-08da64a04d5d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5500 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This adds a new block layer operation to offload verifying a range of LBAs. This support is needed in order to provide file systems and fabrics, kernel components to offload LBA verification when it is supported by the hardware controller. In case hardware offloading is not supported then we provide API to emulate the same. The prominent example of that is SCSI and NVMe Verify command. Block layer API also provide an emulation of the same operation that can be used in case H/W does not support verify. This is still useful when block device is remotely attached e.g. using NVMeOF. Signed-off-by: Chaitanya Kulkarni --- Documentation/ABI/stable/sysfs-block | 12 +++ block/blk-core.c | 5 + block/blk-lib.c | 155 +++++++++++++++++++++++++++ block/blk-merge.c | 18 ++++ block/blk-settings.c | 17 +++ block/blk-sysfs.c | 8 ++ block/blk.h | 7 ++ block/ioctl.c | 35 ++++++ include/linux/bio.h | 9 +- include/linux/blk_types.h | 2 + include/linux/blkdev.h | 19 ++++ include/uapi/linux/fs.h | 1 + 12 files changed, 285 insertions(+), 3 deletions(-) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index cd14ecb3c9a5..e3a10ed1f955 100644 --- a/Documentation/ABI/stable/sysfs-block +++ b/Documentation/ABI/stable/sysfs-block @@ -666,6 +666,18 @@ Description: in a single write zeroes command. If write_zeroes_max_bytes is 0, write zeroes is not supported by the device. +What: /sys/block//queue/verify_max_bytes +Date: July 2022 +Contact: Chaitanya Kulkarni +Description: + Devices that support verify operation in which a single + request can be issued to verify the range of the contiguous + blocks on the storage without any payload in the request. + This can be used to optimize verifying LBAs on the device + without reading by offloading functionality. verify_max_bytes + indicates how many bytes can be written in a single verify + command. If verify_max_bytes is 0, verify operation is not + supported by the device. What: /sys/block//queue/zone_append_max_bytes Date: May 2020 diff --git a/block/blk-core.c b/block/blk-core.c index b530ce7b370c..a77975b8ae60 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -123,6 +123,7 @@ static const char *const blk_op_name[] = { REQ_OP_NAME(ZONE_FINISH), REQ_OP_NAME(ZONE_APPEND), REQ_OP_NAME(WRITE_ZEROES), + REQ_OP_NAME(VERIFY), REQ_OP_NAME(DRV_IN), REQ_OP_NAME(DRV_OUT), }; @@ -785,6 +786,10 @@ void submit_bio_noacct(struct bio *bio) if (!q->limits.max_write_zeroes_sectors) goto not_supported; break; + case REQ_OP_VERIFY: + if (!q->limits.max_verify_sectors) + goto not_supported; + break; default: break; } diff --git a/block/blk-lib.c b/block/blk-lib.c index 09b7e1200c0f..df2e2bc092b3 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -340,3 +340,158 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector, return ret; } EXPORT_SYMBOL(blkdev_issue_secure_erase); + +/** + * __blkdev_emulate_verify - emulate number of verify operations + * asynchronously + * @bdev: blockdev to issue + * @sector: start sector + * @nr_sects: number of sectors to verify + * @gfp_mask: memory allocation flags (for bio_alloc) + * @biop: pointer to anchor bio + * @buf: data buffer to mapped on bio + * + * Description: + * Verify a block range by emulating REQ_OP_VERIFY into REQ_OP_READ, + * use this when H/W offloading is not supported asynchronously. + * Caller is responsible to handle anchored bio. + */ +static int __blkdev_emulate_verify(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, char *buf) +{ + struct bio *bio = *biop; + unsigned int sz; + int bi_size; + + while (nr_sects != 0) { + bio = blk_next_bio(bio, bdev, + __blkdev_sectors_to_bio_pages(nr_sects), + REQ_OP_READ, gfp_mask); + bio->bi_iter.bi_sector = sector; + + while (nr_sects != 0) { + bool is_vaddr = is_vmalloc_addr(buf); + struct page *p; + + p = is_vaddr ? vmalloc_to_page(buf) : virt_to_page(buf); + sz = min((sector_t) PAGE_SIZE, nr_sects << 9); + + bi_size = bio_add_page(bio, p, sz, offset_in_page(buf)); + if (bi_size < sz) + return -EIO; + + nr_sects -= bi_size >> 9; + sector += bi_size >> 9; + buf += bi_size; + } + cond_resched(); + } + + *biop = bio; + return 0; +} + +/** + * __blkdev_issue_verify - generate number of verify operations + * @bdev: blockdev to issue + * @sector: start sector + * @nr_sects: number of sectors to verify + * @gfp_mask: memory allocation flags (for bio_alloc()) + * @biop: pointer to anchor bio + * + * Description: + * Verify a block range using hardware offload. + * + * The function will emulate verify operation if no explicit hardware + * offloading for verifying is provided. + */ +int __blkdev_issue_verify(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask, struct bio **biop) +{ + unsigned int max_verify_sectors = bdev_verify_sectors(bdev); + sector_t min_io_sect = (BIO_MAX_VECS << PAGE_SHIFT) >> 9; + struct bio *bio = *biop; + sector_t curr_sects; + char *buf; + + if (!max_verify_sectors) { + int ret = 0; + + buf = kmalloc(min_io_sect << 9, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + while (nr_sects > 0) { + curr_sects = min_t(sector_t, nr_sects, min_io_sect); + ret = __blkdev_emulate_verify(bdev, sector, curr_sects, + gfp_mask, &bio, buf); + if (ret) + break; + + if (bio) { + ret = submit_bio_wait(bio); + bio_put(bio); + bio = NULL; + } + + nr_sects -= curr_sects; + sector += curr_sects; + + } + /* set the biop to NULL since we have alrady completed above */ + *biop = NULL; + kfree(buf); + return ret; + } + + while (nr_sects) { + bio = blk_next_bio(bio, bdev, 0, REQ_OP_VERIFY, gfp_mask); + bio->bi_iter.bi_sector = sector; + + if (nr_sects > max_verify_sectors) { + bio->bi_iter.bi_size = max_verify_sectors << 9; + nr_sects -= max_verify_sectors; + sector += max_verify_sectors; + } else { + bio->bi_iter.bi_size = nr_sects << 9; + nr_sects = 0; + } + cond_resched(); + } + *biop = bio; + return 0; +} +EXPORT_SYMBOL_GPL(__blkdev_issue_verify); + +/** + * blkdev_issue_verify - verify a block range + * @bdev: blockdev to verify + * @sector: start sector + * @nr_sects: number of sectors to verify + * @gfp_mask: memory allocation flags (for bio_alloc) + * + * Description: + * Verify a block range using hardware offload. + */ +int blkdev_issue_verify(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask) +{ + sector_t bs_mask = (bdev_logical_block_size(bdev) >> 9) - 1; + struct bio *bio = NULL; + struct blk_plug plug; + int ret = 0; + + if ((sector | nr_sects) & bs_mask) + return -EINVAL; + + blk_start_plug(&plug); + ret = __blkdev_issue_verify(bdev, sector, nr_sects, gfp_mask, &bio); + if (ret == 0 && bio) { + ret = submit_bio_wait(bio); + bio_put(bio); + } + blk_finish_plug(&plug); + + return ret; +} +EXPORT_SYMBOL_GPL(blkdev_issue_verify); diff --git a/block/blk-merge.c b/block/blk-merge.c index 5abf5aa5a5f0..f19668c1b7bf 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -153,6 +153,20 @@ static struct bio *blk_bio_write_zeroes_split(struct request_queue *q, return bio_split(bio, q->limits.max_write_zeroes_sectors, GFP_NOIO, bs); } +static struct bio *blk_bio_verify_split(struct request_queue *q, + struct bio *bio, struct bio_set *bs, unsigned *nsegs) +{ + *nsegs = 0; + + if (!q->limits.max_verify_sectors) + return NULL; + + if (bio_sectors(bio) <= q->limits.max_verify_sectors) + return NULL; + + return bio_split(bio, q->limits.max_verify_sectors, GFP_NOIO, bs); +} + /* * Return the maximum number of sectors from the start of a bio that may be * submitted as a single request to a block device. If enough sectors remain, @@ -346,6 +360,10 @@ void __blk_queue_split(struct request_queue *q, struct bio **bio, split = blk_bio_write_zeroes_split(q, *bio, &q->bio_split, nr_segs); break; + case REQ_OP_VERIFY: + split = blk_bio_verify_split(q, *bio, &q->bio_split, + nr_segs); + break; default: split = blk_bio_segment_split(q, *bio, &q->bio_split, nr_segs); break; diff --git a/block/blk-settings.c b/block/blk-settings.c index 8bb9eef5310e..83fb42d42a91 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -43,6 +43,7 @@ void blk_set_default_limits(struct queue_limits *lim) lim->max_dev_sectors = 0; lim->chunk_sectors = 0; lim->max_write_zeroes_sectors = 0; + lim->max_verify_sectors = 0; lim->max_zone_append_sectors = 0; lim->max_discard_sectors = 0; lim->max_hw_discard_sectors = 0; @@ -80,6 +81,7 @@ void blk_set_stacking_limits(struct queue_limits *lim) lim->max_sectors = UINT_MAX; lim->max_dev_sectors = UINT_MAX; lim->max_write_zeroes_sectors = UINT_MAX; + lim->max_verify_sectors = UINT_MAX; lim->max_zone_append_sectors = UINT_MAX; } EXPORT_SYMBOL(blk_set_stacking_limits); @@ -202,6 +204,19 @@ void blk_queue_max_write_zeroes_sectors(struct request_queue *q, } EXPORT_SYMBOL(blk_queue_max_write_zeroes_sectors); +/** + * blk_queue_max_verify_sectors - set max sectors for a single verify + * + * @q: the request queue for the device + * @max_verify_sectors: maximum number of sectors to verify per command + **/ +void blk_queue_max_verify_sectors(struct request_queue *q, + unsigned int max_verify_sectors) +{ + q->limits.max_verify_sectors = max_verify_sectors; +} +EXPORT_SYMBOL(blk_queue_max_verify_sectors); + /** * blk_queue_max_zone_append_sectors - set max sectors for a single zone append * @q: the request queue for the device @@ -554,6 +569,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, t->max_dev_sectors = min_not_zero(t->max_dev_sectors, b->max_dev_sectors); t->max_write_zeroes_sectors = min(t->max_write_zeroes_sectors, b->max_write_zeroes_sectors); + t->max_verify_sectors = min(t->max_verify_sectors, + b->max_verify_sectors); t->max_zone_append_sectors = min(t->max_zone_append_sectors, b->max_zone_append_sectors); t->bounce = max(t->bounce, b->bounce); diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index c0303026752d..bae72999a230 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -113,6 +113,12 @@ queue_ra_store(struct request_queue *q, const char *page, size_t count) return ret; } +static ssize_t queue_verify_max_show(struct request_queue *q, char *page) +{ + return sprintf(page, "%llu\n", + (unsigned long long)q->limits.max_verify_sectors << 9); +} + static ssize_t queue_max_sectors_show(struct request_queue *q, char *page) { int max_sectors_kb = queue_max_sectors(q) >> 1; @@ -593,6 +599,7 @@ QUEUE_RO_ENTRY(queue_discard_zeroes_data, "discard_zeroes_data"); QUEUE_RO_ENTRY(queue_write_same_max, "write_same_max_bytes"); QUEUE_RO_ENTRY(queue_write_zeroes_max, "write_zeroes_max_bytes"); +QUEUE_RO_ENTRY(queue_verify_max, "verify_max_bytes"); QUEUE_RO_ENTRY(queue_zone_append_max, "zone_append_max_bytes"); QUEUE_RO_ENTRY(queue_zone_write_granularity, "zone_write_granularity"); @@ -650,6 +657,7 @@ static struct attribute *queue_attrs[] = { &queue_discard_zeroes_data_entry.attr, &queue_write_same_max_entry.attr, &queue_write_zeroes_max_entry.attr, + &queue_verify_max_entry.attr, &queue_zone_append_max_entry.attr, &queue_zone_write_granularity_entry.attr, &queue_nonrot_entry.attr, diff --git a/block/blk.h b/block/blk.h index b71e22c97d77..af0a4942812f 100644 --- a/block/blk.h +++ b/block/blk.h @@ -132,6 +132,9 @@ static inline bool rq_mergeable(struct request *rq) if (req_op(rq) == REQ_OP_WRITE_ZEROES) return false; + if (req_op(rq) == REQ_OP_VERIFY) + return false; + if (req_op(rq) == REQ_OP_ZONE_APPEND) return false; @@ -169,6 +172,9 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, if (unlikely(op == REQ_OP_WRITE_ZEROES)) return q->limits.max_write_zeroes_sectors; + if (unlikely(op == REQ_OP_VERIFY)) + return q->limits.max_verify_sectors; + return q->limits.max_sectors; } @@ -299,6 +305,7 @@ static inline bool blk_may_split(struct request_queue *q, struct bio *bio) case REQ_OP_DISCARD: case REQ_OP_SECURE_ERASE: case REQ_OP_WRITE_ZEROES: + case REQ_OP_VERIFY: return true; /* non-trivial splitting decisions */ default: break; diff --git a/block/ioctl.c b/block/ioctl.c index 60121e89052b..31094e14f42a 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -192,6 +192,39 @@ static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, return err; } +static int blk_ioctl_verify(struct block_device *bdev, fmode_t mode, + unsigned long arg) +{ + uint64_t range[2]; + struct address_space *mapping; + uint64_t start, end, len; + + if (!(mode & FMODE_READ)) + return -EBADF; + + if (copy_from_user(range, (void __user *)arg, sizeof(range))) + return -EFAULT; + + start = range[0]; + len = range[1]; + end = start + len - 1; + + if (start & 511) + return -EINVAL; + if (len & 511) + return -EINVAL; + if (end >= (uint64_t)i_size_read(bdev->bd_inode)) + return -EINVAL; + if (end < start) + return -EINVAL; + + /* Invalidate the page cache, including dirty pages */ + mapping = bdev->bd_inode->i_mapping; + truncate_inode_pages_range(mapping, start, end); + + return blkdev_issue_verify(bdev, start >> 9, len >> 9, GFP_KERNEL); +} + static int put_ushort(unsigned short __user *argp, unsigned short val) { return put_user(val, argp); @@ -483,6 +516,8 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, return blk_ioctl_secure_erase(bdev, mode, argp); case BLKZEROOUT: return blk_ioctl_zeroout(bdev, mode, arg); + case BLKVERIFY: + return blk_ioctl_verify(bdev, mode, arg); case BLKGETDISKSEQ: return put_u64(argp, bdev->bd_disk->diskseq); case BLKREPORTZONE: diff --git a/include/linux/bio.h b/include/linux/bio.h index 992ee987f273..31fa66c23485 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -55,7 +55,8 @@ static inline bool bio_has_data(struct bio *bio) bio->bi_iter.bi_size && bio_op(bio) != REQ_OP_DISCARD && bio_op(bio) != REQ_OP_SECURE_ERASE && - bio_op(bio) != REQ_OP_WRITE_ZEROES) + bio_op(bio) != REQ_OP_WRITE_ZEROES && + bio_op(bio) != REQ_OP_VERIFY) return true; return false; @@ -65,7 +66,8 @@ static inline bool bio_no_advance_iter(const struct bio *bio) { return bio_op(bio) == REQ_OP_DISCARD || bio_op(bio) == REQ_OP_SECURE_ERASE || - bio_op(bio) == REQ_OP_WRITE_ZEROES; + bio_op(bio) == REQ_OP_WRITE_ZEROES || + bio_op(bio) == REQ_OP_VERIFY; } static inline void *bio_data(struct bio *bio) @@ -176,7 +178,7 @@ static inline unsigned bio_segments(struct bio *bio) struct bvec_iter iter; /* - * We special case discard/write same/write zeroes, because they + * We special case discard/write same/write zeroes/verify, because they * interpret bi_size differently: */ @@ -184,6 +186,7 @@ static inline unsigned bio_segments(struct bio *bio) case REQ_OP_DISCARD: case REQ_OP_SECURE_ERASE: case REQ_OP_WRITE_ZEROES: + case REQ_OP_VERIFY: return 0; default: break; diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index a24d4078fb21..0d5383fc84ed 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -363,6 +363,8 @@ enum req_opf { REQ_OP_FLUSH = 2, /* discard sectors */ REQ_OP_DISCARD = 3, + /* Verify the sectors */ + REQ_OP_VERIFY = 6, /* securely erase sectors */ REQ_OP_SECURE_ERASE = 5, /* write the zero filled sector many times */ diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 22c477fadc0f..8a44f442af9d 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -296,6 +296,7 @@ struct queue_limits { unsigned int max_hw_discard_sectors; unsigned int max_secure_erase_sectors; unsigned int max_write_zeroes_sectors; + unsigned int max_verify_sectors; unsigned int max_zone_append_sectors; unsigned int discard_granularity; unsigned int discard_alignment; @@ -930,6 +931,8 @@ extern void blk_queue_max_discard_sectors(struct request_queue *q, unsigned int max_discard_sectors); extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q, unsigned int max_write_same_sectors); +extern void blk_queue_max_verify_sectors(struct request_queue *q, + unsigned int max_verify_sectors); extern void blk_queue_logical_block_size(struct request_queue *, unsigned int); extern void blk_queue_max_zone_append_sectors(struct request_queue *q, unsigned int max_zone_append_sectors); @@ -1079,6 +1082,12 @@ extern int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, unsigned flags); +extern int __blkdev_issue_verify(struct block_device *bdev, + sector_t sector, sector_t nr_sects, gfp_t gfp_mask, + struct bio **biop); +extern int blkdev_issue_verify(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask); + static inline int sb_issue_discard(struct super_block *sb, sector_t block, sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags) { @@ -1253,6 +1262,16 @@ static inline unsigned int bdev_write_zeroes_sectors(struct block_device *bdev) return 0; } +static inline unsigned int bdev_verify_sectors(struct block_device *bdev) +{ + struct request_queue *q = bdev_get_queue(bdev); + + if (q) + return q->limits.max_verify_sectors; + + return 0; +} + static inline bool bdev_nonrot(struct block_device *bdev) { return blk_queue_nonrot(bdev_get_queue(bdev)); diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index bdf7b404b3e7..ad0e5cb5cac4 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -185,6 +185,7 @@ struct fsxattr { #define BLKROTATIONAL _IO(0x12,126) #define BLKZEROOUT _IO(0x12,127) #define BLKGETDISKSEQ _IOR(0x12,128,__u64) +#define BLKVERIFY _IO(0x12,129) /* * A jump here: 130-136 are reserved for zoned block devices * (see uapi/linux/blkzoned.h) From patchwork Wed Jul 13 07:20:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 590743 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 BC06DCCA482 for ; Wed, 13 Jul 2022 07:21:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234734AbiGMHV5 (ORCPT ); Wed, 13 Jul 2022 03:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234719AbiGMHVr (ORCPT ); Wed, 13 Jul 2022 03:21:47 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2067.outbound.protection.outlook.com [40.107.100.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89DC4E1929; Wed, 13 Jul 2022 00:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UEsNmzoN4sKM5W5T4UPWOozhMyx2HzrJx00hVIsjCfVGkd2FzBObnHg52cSnBjxzJiogWpZ4vHu/fBxCkCBnq2EXq7gjzuBEP25c3BRdUChhP/7a6YxtXLq4QB+2XNrQAoVzXErWFh4O2R9vNqqKlAcu30kcpEgU35theQfTzRuboNT4yjCwWdAWVkum3m/YSF9826g1AqumHTTBxd6FTnz+w89TqjVKapk8kBCokqtPVFKtmYXudduph6rFGlAeHe/a1BieX7zPfQ6Nuggnu+HeZyx/Pq6suJ0jRxOkxhBC3QPWrzvXrFdWEkkaBBElhfwZdOdEVWA9CFHGDhCViQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=f2p2FMduZ/ueJzBUHzqONpkNWaY5p33gFfLGiUVmO18=; b=VSqITacEYyGFMUU8lCyjnHtfDvZP9RRjNVX0uqZCqxQSjBWHeL3/KmrQ4igxHvr4d5AZPpWAQ3OMBAESUjnhoEVUsLuedfEP3hAxBcBSLj3igzeyIBVGc4rGoyhGtuoQ+hgNz51w6IWFWM0jFRDQITcTGa1RzKL5bztxJUrTRahEXwcJdBg1BHVRZAZ2+9YZehQejPGl1S3+rvSFIwu/OWCBzXcSoVRJjeNsA/ALQXg634gAOhQ4+ZyeEJjqUQJorS6DOyxeHsTD5pJfW39F4/R8etTkiVs+vAMTALUnFnAlRw1lV4z7OM7S+43nMSw5xrwacbttp77Ij+bvEDKgwQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=kernel.dk smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f2p2FMduZ/ueJzBUHzqONpkNWaY5p33gFfLGiUVmO18=; b=nd8ksX7za0HN/kuEcWQzRj50wTZb5Pz/GnVrpMmy7/z8VXVkqPhuq9rqkJX2M3alRizucq+6LAXkeq0RUJDJ7CXhUqIgtQg5kI1FM5CJIUSPUZjnXHv2XAHEa5nz7zcV+6RMJQ+z/rwHJkXnXznWJcm7v2k6v87uihG2rWSLCGJbLANIFTspSkCOZwGrly9b7Q4k0VChkpKsggOvLd7Xt19qVBJEh5T0E0zFTnWX4aUGeZlajm4z90XQVWoXRXNQoqPWm/PUy1iLAARoNscJ5wxweoNLa1/sLrHm6woaYZEZgnEQpaI42HWeYRaLlT/FMdXclS9bxcHfjHW6Adw0Bg== Received: from DM6PR07CA0041.namprd07.prod.outlook.com (2603:10b6:5:74::18) by PH7PR12MB6467.namprd12.prod.outlook.com (2603:10b6:510:1f5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.26; Wed, 13 Jul 2022 07:21:38 +0000 Received: from DM6NAM11FT003.eop-nam11.prod.protection.outlook.com (2603:10b6:5:74:cafe::e3) by DM6PR07CA0041.outlook.office365.com (2603:10b6:5:74::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.17 via Frontend Transport; Wed, 13 Jul 2022 07:21:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by DM6NAM11FT003.mail.protection.outlook.com (10.13.173.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5438.12 via Frontend Transport; Wed, 13 Jul 2022 07:21:38 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 13 Jul 2022 07:21:37 +0000 Received: from dev.nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 13 Jul 2022 00:21:35 -0700 From: Chaitanya Kulkarni To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Chaitanya Kulkarni Subject: [PATCH V2 2/6] nvme: add support for the Verify command Date: Wed, 13 Jul 2022 00:20:15 -0700 Message-ID: <20220713072019.5885-3-kch@nvidia.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220713072019.5885-1-kch@nvidia.com> References: <20220713072019.5885-1-kch@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 120dc9d2-3079-4086-1380-08da64a0535d X-MS-TrafficTypeDiagnostic: PH7PR12MB6467:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FZTDSZiOpTjaQpZHwAfQUJ0QZCsHFHo+HrIe9LMqvy+F0M0e5Aw9MdwMWrrUYyZr/0H+//rubD/GQA6D3bLy7+qMAarWxgH/1UdttafHwvzeOBViw57wkYnJR5SrZp7c1KIjKTLKY7lsR1BnSjUYfcixFQpbq9tvhdFdqxxyNdCb2lU5czbRcTD5X/bGeKOP+1cIDsu7/+4FwO5NcIjFoV1ZLBVRVi+/oGvDmVh+6rAXhOIZjvRhF3F6rwqCAQMTxd9e/LJ2YkN5alySarZfVzfyCko/5x2QRMGhCMeLVPvzA/ydyRbB/G2VF6ZobfxnhKVtvbras5fMk9cNpduwoILcPzCCfsZQs57UD2pexo9T7bdtK01EWUF8nWXJqlj89ca8OU80oIUsU161lKBz5vkZfh07bbYqWp7iopJ5h5lvcjF3q6PIGvHpWG5sUBq5wA3ca+zrzL33fet+YVkVfxNqLNzbEulf1knEAsY46Y7kw569RsHmbl5Tng2DItYwIUEfYdMCLDqDZmtjiS2aYA+Dbc/BfG6xON85zCmaCC531mHzalHPuuq7gAY043QMQ6pGpbWdUTLLBQOLSMtgvay8uTqWtwale6Y0y7DiKhqisbCKSj9CL9sdl+wPgTFMp7izW/JtnolBcZvGbQstgxYOO0BVvwHRR9mv9d01K42ykk0NUYeWKyzj4L0ZzZ5sWA+L/N6YaNsJnr6Tjmbju4w7xhGvCgurFGzOKXwT639XLftj9z5zJzNcmv9JkQlO3F3KtImaah+D3MS/6mxpkXKSePazKidKhVikSuKzfy3aYuMUC9Cdjp+y3FskIVPduQ0zWBRpelIa3usbIa5MhHeG8PNvs+m6GALB7rZeNzlc90EYGOKPbSgtRO8JMhJE X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(376002)(39860400002)(396003)(136003)(346002)(46966006)(36840700001)(40470700004)(7406005)(1076003)(41300700001)(40460700003)(82740400003)(15650500001)(478600001)(2906002)(6666004)(7416002)(8936002)(40480700001)(36756003)(356005)(36860700001)(107886003)(16526019)(4326008)(8676002)(316002)(70206006)(83380400001)(5660300002)(54906003)(70586007)(82310400005)(2616005)(110136005)(26005)(186003)(7696005)(47076005)(426003)(336012)(81166007)(36900700001)(2101003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2022 07:21:38.1250 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 120dc9d2-3079-4086-1380-08da64a0535d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT003.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6467 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Allow verify operations (REQ_OP_VERIFY) on the block device, if the device supports optional command bit set for verify. Add support to setup verify command. Set maximum possible verify sectors in one verify command according to maximum hardware sectors supported by the controller. Signed-off-by: Chaitanya Kulkarni --- drivers/nvme/host/core.c | 31 +++++++++++++++++++++++++++++++ drivers/nvme/host/nvme.h | 1 + include/linux/nvme.h | 19 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 252ab0a4bf8d..8b09ccc16184 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -838,6 +838,19 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns, return BLK_STS_OK; } +static inline blk_status_t nvme_setup_verify(struct nvme_ns *ns, + struct request *req, struct nvme_command *cmnd) +{ + cmnd->verify.opcode = nvme_cmd_verify; + cmnd->verify.nsid = cpu_to_le32(ns->head->ns_id); + cmnd->verify.slba = + cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req))); + cmnd->verify.length = + cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1); + cmnd->verify.control = 0; + return BLK_STS_OK; +} + static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, struct request *req, struct nvme_command *cmnd, enum nvme_opcode op) @@ -943,6 +956,9 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req) case REQ_OP_WRITE_ZEROES: ret = nvme_setup_write_zeroes(ns, req, cmd); break; + case REQ_OP_VERIFY: + ret = nvme_setup_verify(ns, req, cmd); + break; case REQ_OP_DISCARD: ret = nvme_setup_discard(ns, req, cmd); break; @@ -1672,6 +1688,17 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns) blk_queue_max_write_zeroes_sectors(queue, UINT_MAX); } +static void nvme_config_verify(struct gendisk *disk, struct nvme_ns *ns) +{ + unsigned int sects = ns->ctrl->max_verify_sectors; + + if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_VERIFY)) + return; + + /* in case controller supports verify but vsl is 0 just use UINT_MAX */ + blk_queue_max_verify_sectors(disk->queue, sects ? sects : UINT_MAX); +} + static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b) { return uuid_equal(&a->uuid, &b->uuid) && @@ -1871,6 +1898,7 @@ static void nvme_update_disk_info(struct gendisk *disk, set_capacity_and_notify(disk, capacity); nvme_config_discard(disk, ns); + nvme_config_verify(disk, ns); blk_queue_max_write_zeroes_sectors(disk->queue, ns->ctrl->max_zeroes_sectors); } @@ -2971,6 +2999,9 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl) if (id->wzsl) ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl); + if (id->vsl) + ctrl->max_verify_sectors = nvme_mps_to_sectors(ctrl, id->vsl); + free_data: kfree(id); return ret; diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 7323a2f61126..3bb58282585d 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -279,6 +279,7 @@ struct nvme_ctrl { u32 max_discard_sectors; u32 max_discard_segments; u32 max_zeroes_sectors; + u32 max_verify_sectors; #ifdef CONFIG_BLK_DEV_ZONED u32 max_zone_append; #endif diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 07cfc922f8e4..967ec7257102 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -363,6 +363,7 @@ enum { NVME_CTRL_ONCS_WRITE_ZEROES = 1 << 3, NVME_CTRL_ONCS_RESERVATIONS = 1 << 5, NVME_CTRL_ONCS_TIMESTAMP = 1 << 6, + NVME_CTRL_ONCS_VERIFY = 1 << 7, NVME_CTRL_VWC_PRESENT = 1 << 0, NVME_CTRL_OACS_SEC_SUPP = 1 << 0, NVME_CTRL_OACS_NS_MNGT_SUPP = 1 << 3, @@ -1003,6 +1004,23 @@ struct nvme_write_zeroes_cmd { __le16 appmask; }; +struct nvme_verify_cmd { + __u8 opcode; + __u8 flags; + __u16 command_id; + __le32 nsid; + __u64 rsvd2; + __le64 metadata; + union nvme_data_ptr dptr; + __le64 slba; + __le16 length; + __le16 control; + __le32 rsvd3; + __le32 reftag; + __le16 eapptag; + __le16 eappmask; +}; + enum nvme_zone_mgmt_action { NVME_ZONE_CLOSE = 0x1, NVME_ZONE_FINISH = 0x2, @@ -1541,6 +1559,7 @@ struct nvme_command { struct nvme_format_cmd format; struct nvme_dsm_cmd dsm; struct nvme_write_zeroes_cmd write_zeroes; + struct nvme_verify_cmd verify; struct nvme_zone_mgmt_send_cmd zms; struct nvme_zone_mgmt_recv_cmd zmr; struct nvme_abort_cmd abort; From patchwork Wed Jul 13 07:20:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 590248 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 27AF8C433EF for ; Wed, 13 Jul 2022 07:22:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233739AbiGMHWP (ORCPT ); Wed, 13 Jul 2022 03:22:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234483AbiGMHWH (ORCPT ); Wed, 13 Jul 2022 03:22:07 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2047.outbound.protection.outlook.com [40.107.223.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4D0FDF629; Wed, 13 Jul 2022 00:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C4kkEVFHpWjAZCzG3q0b21FzYDAiKQUfkVcPedaFVdGauqI5Nk+n8Q/7OrwwIlqQjDzyxnbP7F86V+IQgcRt1RrOUcQvDwaokWXJliCKMAXrbRy3Uoo3hosHtUUiSlfdTJ3/rBwnUOS6KH60k06aD0PgsUEbwdVQlDwgAfFdlhaYWLj6PSzm6srLlgiwm/bDcCo3ajxHBzsLd6GpoeabMp4vIpymdt0bSH0I8Zxbhm8/jUxzoTSoVzrZC1KMlnz1+yrqsuBp3YKREcuiCUVwCZa83f2hIP+Um7YtTy8cYtEoa+bgSOGLHPSXO178y4WRsPyrJaPy5XotunglHsbDvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MPAH0iKcSq0C0K71QGumQc2JkeHS2CZJTBrVdORMWMQ=; b=b+MVMlBk/hrKCm4NQTw1al0fC8HeEAPHRzuAA/3KkXqmImP25s7LmVrpnFrs03AYihpI9Lx9uVJjGb2Woz1cu4RCjXXMHzkpmKRR6Olrr+nWQ9YK/tygdkiYRlAes+btgaOteYExS/pJxzyT/npYosvS164zU/iRJjzRpfXT6Ai80+5z+12CouoSpEhs6E9ivV1jfBWj+iy6/qxnsT2wbQmzfL6oE5DLObD9P6JSrgBUeoKzYNA9nS/tAAuE2xGalcgRgFt7umn6yRFmfwqbZbH+PTXSXpoWhldUMcdPTEq9kD3PNgWgV0Hnp3Lmp/V+RDJyxW4CcXd5WElxDiaYaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=kernel.dk smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MPAH0iKcSq0C0K71QGumQc2JkeHS2CZJTBrVdORMWMQ=; b=hJV7RyUuW9ZCtTHYZ+E3ik239x8554oZfrLg03omdY9yS+Ukn/2gDKwJTr5xsRceDV9Z/DkcPzR+SA1E+V/yJRGaQ2LK9c132UVThuoT/vOtBKEyJY5+LV66v5tQYHyEUYVvlxrwHh9w2tGEYYsaf8KjWof+1SnWBc7tnIbSucgcP7CumgRvtKaQ5qch1UlOoJOkhyLxwjo5OJD99ZDepvtLonjjJIpsuso33YTujshnJu2v3iEHs+GfmcuxaOt9wq0E5XZYbdu+WfB6u4vyeFFexNYCiwsxBkuQs+ra1ZdC0AaZgaqF9jvcWgahiyEvU0zWyjwiFSu9zRbJEZAA0g== Received: from MW4PR04CA0090.namprd04.prod.outlook.com (2603:10b6:303:6b::35) by BN6PR12MB1154.namprd12.prod.outlook.com (2603:10b6:404:1c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.20; Wed, 13 Jul 2022 07:21:57 +0000 Received: from CO1NAM11FT011.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6b:cafe::5a) by MW4PR04CA0090.outlook.office365.com (2603:10b6:303:6b::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.22 via Frontend Transport; Wed, 13 Jul 2022 07:21:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by CO1NAM11FT011.mail.protection.outlook.com (10.13.175.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5438.12 via Frontend Transport; Wed, 13 Jul 2022 07:21:56 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 13 Jul 2022 07:21:49 +0000 Received: from dev.nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 13 Jul 2022 00:21:47 -0700 From: Chaitanya Kulkarni To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Chaitanya Kulkarni Subject: [PATCH V2 3/6] nvmet: add Verify command support for bdev-ns Date: Wed, 13 Jul 2022 00:20:16 -0700 Message-ID: <20220713072019.5885-4-kch@nvidia.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220713072019.5885-1-kch@nvidia.com> References: <20220713072019.5885-1-kch@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2a633287-4f65-4c54-594e-08da64a05e1c X-MS-TrafficTypeDiagnostic: BN6PR12MB1154:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Gw226/i5mEY8bKlawik27Ze3RolJyXTicDsMlm8lu7JPL6MdHQvVSrt/nQCLWDdWxlJEFNoP+Sfq1yNXDPpMe6Z4XrB/k1WuZ/psWmGR4kDnP8FppWBwITZTLy8lE9txjMkccmj28mWfnzafhQlnv/cAYVnezi9o3LguZouDBaoVg5b/ShJmvSwisi2M3r/GlvsFoY4UnMoUURZpgpPcAdYpuEEqvyK3UwMY03V6P1VxrNLw05uDWJ9K7POQy9nilvt09nk2JbzAbkwQnHZUblrzxJeBzuQ+FtTv4S/kAm3VsEdtuFEFErvw/Jz8wFaZrpqbig6H24DnbHl1bM9zJ0mM/Peu5x+dkGjc9Le+C9h3KX0X1M8X4lrYkU5ndbFQcv0I7N9rmLi9b+SFiOr9jXHirJYBu/0vqvjQckbZ5s5gy3k8Lwnfdcda29HG3+ZEl1d8NXwWm0lpq56l8LSMoz1sWq3r8fHyLTap/x81twXcdHu8F1lXtR+U1kxgsvoP9CawtZ1IWtIrlv6FiJj732kgBucDl0JNrATYkmvXYf/Ed6//4nYDln8dzoxpYOyGBlG/it4hKAA+635VvhOOqfbcCrnLmni9hu60GrWOsR5Hx/bJKXmYSnsTqgDjPJ2vJgk0ovJOMAS1/+4HQBAQZX3gAWVa8Yfh/sthClZgmLt/W8TvlmGiH86sKnoDtYpvn4VZmkU5QvGtDHTHdoKkw7ETUPPIw1LZOkyOWOOnlR3dclSnL8FtHHTmiXMFCmiQw167qgaUMqBmDPO9FUnzxfLn2cyBqd4jt4qWIRxCjsWsdRoz3V6wYRR7SQ0Wcvajyp7E3UD3zbHkpEm4xglnz1e8zKoBY7NzDuDTihTC+xgo4JJtXqL68H41Pd19tAItDN7NvdzyNunLEdjLcis/jA== X-Forefront-Antispam-Report: CIP:12.22.5.234; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(136003)(39860400002)(376002)(396003)(346002)(40470700004)(46966006)(36840700001)(8936002)(7406005)(7416002)(336012)(47076005)(40480700001)(40460700003)(82310400005)(5660300002)(2906002)(15650500001)(26005)(356005)(36860700001)(83380400001)(82740400003)(41300700001)(36756003)(186003)(54906003)(110136005)(478600001)(81166007)(8676002)(7696005)(1076003)(70586007)(316002)(70206006)(4326008)(426003)(6666004)(107886003)(2616005)(16526019)(21314003)(2101003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2022 07:21:56.1713 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2a633287-4f65-4c54-594e-08da64a05e1c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.234]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT011.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1154 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add support for handling verify command on target. Call into __blkdev_issue_verify, which the block layer expands into the REQ_OP_VERIFY LBAs. Signed-off-by: Chaitanya Kulkarni --- drivers/nvme/target/admin-cmd.c | 3 ++- drivers/nvme/target/io-cmd-bdev.c | 38 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index 397daaf51f1b..495c3a31473a 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -431,7 +431,8 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req) id->nn = cpu_to_le32(NVMET_MAX_NAMESPACES); id->mnan = cpu_to_le32(NVMET_MAX_NAMESPACES); id->oncs = cpu_to_le16(NVME_CTRL_ONCS_DSM | - NVME_CTRL_ONCS_WRITE_ZEROES); + NVME_CTRL_ONCS_WRITE_ZEROES | + NVME_CTRL_ONCS_VERIFY); /* XXX: don't report vwc if the underlying device is write through */ id->vwc = NVME_CTRL_VWC_PRESENT; diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index 27a72504d31c..82c341f90f06 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -146,6 +146,7 @@ u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts) switch (req->cmd->common.opcode) { case nvme_cmd_dsm: case nvme_cmd_write_zeroes: + case nvme_cmd_verify: status = NVME_SC_ONCS_NOT_SUPPORTED | NVME_SC_DNR; break; default: @@ -171,6 +172,9 @@ u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts) req->error_slba = le64_to_cpu(req->cmd->write_zeroes.slba); break; + case nvme_cmd_verify: + req->error_slba = le64_to_cpu(req->cmd->verify.slba); + break; default: req->error_slba = 0; } @@ -442,6 +446,37 @@ static void nvmet_bdev_execute_write_zeroes(struct nvmet_req *req) } } +static void nvmet_bdev_execute_verify(struct nvmet_req *req) +{ + struct nvme_verify_cmd *verify = &req->cmd->verify; + struct bio *bio = NULL; + sector_t nr_sector; + sector_t sector; + int ret; + + if (!nvmet_check_transfer_len(req, 0)) + return; + + if (!bdev_verify_sectors(req->ns->bdev)) { + nvmet_req_complete(req, NVME_SC_INTERNAL | NVME_SC_DNR); + return; + } + + sector = le64_to_cpu(verify->slba) << (req->ns->blksize_shift - 9); + nr_sector = (((sector_t)le16_to_cpu(verify->length) + 1) << + (req->ns->blksize_shift - 9)); + + ret = __blkdev_issue_verify(req->ns->bdev, sector, nr_sector, + GFP_KERNEL, &bio); + if (bio) { + bio->bi_private = req; + bio->bi_end_io = nvmet_bio_done; + submit_bio(bio); + } else { + nvmet_req_complete(req, errno_to_nvme_status(req, ret)); + } +} + u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req) { switch (req->cmd->common.opcode) { @@ -460,6 +495,9 @@ u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req) case nvme_cmd_write_zeroes: req->execute = nvmet_bdev_execute_write_zeroes; return 0; + case nvme_cmd_verify: + req->execute = nvmet_bdev_execute_verify; + return 0; default: return nvmet_report_invalid_opcode(req); } From patchwork Wed Jul 13 07:20:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 590742 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 46D56CCA479 for ; Wed, 13 Jul 2022 07:22:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231162AbiGMHWZ (ORCPT ); Wed, 13 Jul 2022 03:22:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234420AbiGMHWM (ORCPT ); Wed, 13 Jul 2022 03:22:12 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2081.outbound.protection.outlook.com [40.107.243.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1175E2A1D; Wed, 13 Jul 2022 00:22:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UTKFMF2paG6yufYTAjQFKPrKZC+TyJNFwFaCUpvcu9IqkNqZcTUZwiUDATlbfSsJfAd2WIY8LiYqDajdXA1+HbWhpmi09T3kZW8/vorzbtIagiLk3+DGCBBT3l0dCIDyQZyhsBnmE2FyIt+LgvLpofVkRJDWMTtEfS1bl1W73Lh8smjnJz4CSlvroAmK8KdEQEZM0U1b9kYwBjUPJNIsl3lZIIkt6Mj3+X3QhNTEduNkNWQS3jzrwdP63vyvACeBSw6Zh3381jkv0DlHQYAoWJeGHbuYxvZm9mQJNx5r4fFdEIC2wqj9YgFxwTJgYYLc1AMkZphYKd35H1GBKLQzjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TEql+7Qc/6ZjUNhYo95lXJF79oRQEGSSmWcCMAsILWc=; b=kBwFN5nz1BpgyptWql432cPxDMsvJqxzjAnWrQMwEph8a/W1dxbtN0MHNnBbQTN7ndaNHBc+Jt0zBIX6QJBNUtqZhBCkoqhxaJddxY8f0W4mkL1U+rnAz1UUIc/WW4YtEGRP2V8X0IV7+PZnkpgshXZoSt13+iNd48aHi3UpLrwuPr1ojV7Lx3au7SssEzIvuIB9/OK6W+fvwhRiDZJ8QhpWxYcjk5tT+1VaD/CypjQqzBQY4sdFROt9BuAANwnnA8HCxns6OfIMkYIBWopkEWmuKKtYP6SKmMxUAWeiwSYOdry/nVR4fNobGLuTY8/QS8iAxUZv+CG8LZ6V/ZPHiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=kernel.dk smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TEql+7Qc/6ZjUNhYo95lXJF79oRQEGSSmWcCMAsILWc=; b=YyhXhAdjA5wuQDL5GVdgqOge6Jct9/qwjIqBi7KzPek9pdskboRMJkR28yqlqfxE9DceCFzy7PpmvlWOaD7VqyYWuGRc1hwAfmZ5q7V1CrZ29wrW7tLrULvf/xLU9o6I5T/QeuOGzlJZL/7DKmMmdFCADINXlQRNWxWlLXa4XjPUIBH+9DleLhloQTrNtUW14aPvjafOWHG0xH96m9Q/8LVYCWpgmL5hbIStufVNhVH5vfKcSfwTcCY6uvP/ixu4G7snxmVEIEF7wF8hO1QzRktRqTP9vSkI7nawufnDfXgrXI5dInIf2LG8vplC0q0YA1hhAUEX/lk5S/Yb96QomQ== Received: from MW2PR16CA0056.namprd16.prod.outlook.com (2603:10b6:907:1::33) by BY5PR12MB4641.namprd12.prod.outlook.com (2603:10b6:a03:1f7::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.16; Wed, 13 Jul 2022 07:22:03 +0000 Received: from CO1NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:907:1:cafe::b4) by MW2PR16CA0056.outlook.office365.com (2603:10b6:907:1::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.26 via Frontend Transport; Wed, 13 Jul 2022 07:22:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by CO1NAM11FT065.mail.protection.outlook.com (10.13.174.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5438.12 via Frontend Transport; Wed, 13 Jul 2022 07:22:03 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 13 Jul 2022 07:22:02 +0000 Received: from dev.nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 13 Jul 2022 00:22:00 -0700 From: Chaitanya Kulkarni To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Chaitanya Kulkarni Subject: [PATCH V2 4/6] nvmet: add Verify emulation support for bdev-ns Date: Wed, 13 Jul 2022 00:20:17 -0700 Message-ID: <20220713072019.5885-5-kch@nvidia.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220713072019.5885-1-kch@nvidia.com> References: <20220713072019.5885-1-kch@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8b768905-06b9-41ab-7e05-08da64a06255 X-MS-TrafficTypeDiagnostic: BY5PR12MB4641:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PW1Weqx/lFJ/zCsmMvW7lboCJnFZTpqs/yAWpuEipo+fkW1ve6dmburMRj69tScSgSyzNIrNvIFZUIUXkXxUNq8alnzs4rRKUhj4tLuTCRjYthZPhIQv9WIims+9edY0RhsbVn9rD61jt8CQTK8ad6DrRnyyIzsYySBbAoTLiOdw9w+qMwCEjdsZnxBD/5kgqRHXa82KI1ZfTsHA9cjHBZSW0X9/1Y5+2csxBawHSmBaT7FnHO0+aC7H7QCq1k1Zhxoe7ehui4/nrqFvIIAwvJwn0x6H+vzrsNOPyIKBRThbA0tCM4lRu4Hn5WRWnI+AjMuDdZmp/1erNQnc+DYYxhoJrLKRRGvf6tJYybYuewzPvUi7gScjxKa3cdZph9E2AaqxeishOD3TiDpOR1l9iKwxRCPnjZcmQv6epMMt6Q8xPUjW/hMbYSs03b/9zId/vhaEfGTz3jzwjU14/byhXtIyheJO9KPgUwP6pwgADvTRE5f9J0Aqeo8L/f18QWVdXcEkTHV5Oa9rwtsg3Y4wxdeMQcf1iGGkD8wLHCZRybrimJe/lDMkYyNI8sy2oWfFkSCkUs49IelnnUhta7BYS9HlVCEKPDnFpP6MXrwjKx8k9UXX2ARbxh28v37zR051BL5PSpDwSxATMHMmssqofHVWvu/JjMtDg3X4GGDMImCs4O/ZM+YOubROMV5ONKXX2rw0N9etEsTIqmdLWz0d7EzN7sdCA/7y+9z0WY0nWCSP8YeVtsY1ATgmOnMJRamuZmtcKJpkas8o1rq5VXlrVb507/CJ7tSQ9fmffRPrajjNKbMIixvrg8sL9IzfJU5CnlNM0qw49ifHV8pL2TbtjE6NuvtbyRb4Y8co9iQQfYuxDg60VAHVCRu6yNA2rWu3 X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(136003)(39860400002)(376002)(346002)(396003)(36840700001)(40470700004)(46966006)(1076003)(70586007)(186003)(8676002)(2616005)(16526019)(7416002)(316002)(107886003)(426003)(336012)(70206006)(4326008)(81166007)(6666004)(82310400005)(7696005)(47076005)(40480700001)(36756003)(41300700001)(478600001)(82740400003)(40460700003)(110136005)(54906003)(8936002)(356005)(2906002)(7406005)(36860700001)(83380400001)(15650500001)(26005)(5660300002)(2101003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2022 07:22:03.2567 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8b768905-06b9-41ab-7e05-08da64a06255 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4641 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Not all devices can support verify requests which can be mapped to the controller specific command. This patch adds a way to emulate REQ_OP_VERIFY for NVMeOF block device namespace. Signed-off-by: Chaitanya Kulkarni --- drivers/nvme/target/io-cmd-bdev.c | 48 ++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index 82c341f90f06..aec287d3b7d7 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -446,35 +446,63 @@ static void nvmet_bdev_execute_write_zeroes(struct nvmet_req *req) } } -static void nvmet_bdev_execute_verify(struct nvmet_req *req) +static void __nvmet_req_to_verify_sectors(struct nvmet_req *req, + sector_t *sects, sector_t *nr_sects) { struct nvme_verify_cmd *verify = &req->cmd->verify; + + *sects = le64_to_cpu(verify->slba) << (req->ns->blksize_shift - 9); + *nr_sects = (((sector_t)le16_to_cpu(verify->length) + 1) << + (req->ns->blksize_shift - 9)); +} + +static void nvmet_bdev_submit_emulate_verify(struct nvmet_req *req) +{ + sector_t nr_sector; + sector_t sector; + int ret = 0; + + __nvmet_req_to_verify_sectors(req, §or, &nr_sector); + if (!nr_sector) + goto out; + + /* blkdev_issue_verify() will automatically emulate */ + ret = blkdev_issue_verify(req->ns->bdev, sector, nr_sector, + GFP_KERNEL); +out: + nvmet_req_complete(req, + blk_to_nvme_status(req, errno_to_blk_status(ret))); +} + +static void nvmet_bdev_execute_verify(struct nvmet_req *req) +{ struct bio *bio = NULL; sector_t nr_sector; sector_t sector; - int ret; + int ret = 0; if (!nvmet_check_transfer_len(req, 0)) return; + __nvmet_req_to_verify_sectors(req, §or, &nr_sector); + if (!nr_sector) + goto out; + if (!bdev_verify_sectors(req->ns->bdev)) { - nvmet_req_complete(req, NVME_SC_INTERNAL | NVME_SC_DNR); + nvmet_bdev_submit_emulate_verify(req); return; } - sector = le64_to_cpu(verify->slba) << (req->ns->blksize_shift - 9); - nr_sector = (((sector_t)le16_to_cpu(verify->length) + 1) << - (req->ns->blksize_shift - 9)); - ret = __blkdev_issue_verify(req->ns->bdev, sector, nr_sector, GFP_KERNEL, &bio); - if (bio) { + if (ret == 0 && bio) { bio->bi_private = req; bio->bi_end_io = nvmet_bio_done; submit_bio(bio); - } else { - nvmet_req_complete(req, errno_to_nvme_status(req, ret)); + return; } +out: + nvmet_req_complete(req, errno_to_nvme_status(req, ret)); } u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req) From patchwork Wed Jul 13 07:20:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 590247 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 C21B7CCA479 for ; Wed, 13 Jul 2022 07:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234321AbiGMHWe (ORCPT ); Wed, 13 Jul 2022 03:22:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234292AbiGMHWS (ORCPT ); Wed, 13 Jul 2022 03:22:18 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2051.outbound.protection.outlook.com [40.107.93.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 828CDC1FD8; Wed, 13 Jul 2022 00:22:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WBJtgDEh0vIzyj5PBG8isN0efk4+e24Ve8SpHcVFu5JHlQF4ick4tt4RGRTOkCiIOjHMV9oxK7nRZBL+WU81DEbujjXrwzmu06tRVeDzKAJ367nncHOmjVShX9bAD+6GtmjG1LITgBWvmKDxqHd7rrcYzGPZ9S/no6Yr0wBELsAdsbcHaTxDSbBRP4QH5utENgI87CpT+bfmAXUch0xvSYdqrngOkuj3o07AEfpAZx8k2P3Yp4Eyq+cgC0Mu2PUB5+0dFLbN6P4J9DjKIEOWbrdhHxwalFOp1E0EeXk3gT7e+yl3twAEzX/KgWr3TvzBHAa+F49keCBsFvnMvrhpkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZL4ms3Oh7uy6X4sXiQwTR1+i7JzA2MjgsL6Shj7BWXw=; b=ICTQ/KHBxyGlRmePMVc3VBKm4KRGOCSdf4AVvsTNr4mEk6yhtcJ49s2C2PGmgIS2YOkCC6xH8ihV+JXEgEFN2+nbP6OShQje+hKzRII2G2YvbLAP18G+yj5grWFkYb4QZk8vOxK76FfBudkbA4Zo+5UGqMtIM+VNjWqY0E9A6EpSzHwSy9iPSjEXOueS/rJnZUAeUjbZ8ZmDo+cc6um+5Uwx6/3RrquNHSSgPxu2XEiO+LccVaoxounRMzt0XytCRr7BqV7abIpxkqle8dqmw+u/ebIGzyjuwOM4fXXHW96vi+DpD3VVo/J0k5NwmdNxZTX5m60czlL+VfUgUS/2jw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=kernel.dk smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZL4ms3Oh7uy6X4sXiQwTR1+i7JzA2MjgsL6Shj7BWXw=; b=o0hUw8qAlJrgm9nrFGhQ74Ti4jm2ArnRKXqT33bQr5LsVPhioJ8zXLIshX+T6j/Ynaj/1DvprB888P4P2ov/nhwPG4PaEDrWpqi3oUVnH5wj9imWakks2iChsheYdkbDiqQqtaAFBjGMgXAEgR2mdiuCkLZ/RjZLWl8m/LzP2XeBhBFhjgI94Jcgz0f2jmizWiMX2d2g+h9/PPqalid1/8cM/cqdT+EdagWWfb+ZVkiIAIzsoeJHSkT+Ho1I2NeU0hnQiwAKldsiE982arspOUE/j6QSFGZS2jRsaXnstuDQnboITskxHAWyXtQlSpHeor1Yu0Wl4utfKD6IA1qOng== Received: from MW4PR04CA0082.namprd04.prod.outlook.com (2603:10b6:303:6b::27) by DM6PR12MB2825.namprd12.prod.outlook.com (2603:10b6:5:75::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.20; Wed, 13 Jul 2022 07:22:15 +0000 Received: from CO1NAM11FT036.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6b:cafe::53) by MW4PR04CA0082.outlook.office365.com (2603:10b6:303:6b::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.23 via Frontend Transport; Wed, 13 Jul 2022 07:22:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by CO1NAM11FT036.mail.protection.outlook.com (10.13.174.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5438.12 via Frontend Transport; Wed, 13 Jul 2022 07:22:15 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 13 Jul 2022 07:22:14 +0000 Received: from dev.nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 13 Jul 2022 00:22:12 -0700 From: Chaitanya Kulkarni To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Chaitanya Kulkarni Subject: [PATCH V2 5/6] null_blk: add REQ_OP_VERIFY support Date: Wed, 13 Jul 2022 00:20:18 -0700 Message-ID: <20220713072019.5885-6-kch@nvidia.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220713072019.5885-1-kch@nvidia.com> References: <20220713072019.5885-1-kch@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 616d9819-8203-4a14-e120-08da64a06978 X-MS-TrafficTypeDiagnostic: DM6PR12MB2825:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qHHupalmu/uibIdfjj8jdoVsruiCnpAwq5XB6MTTM3rkKTNUg7fklAdrvoOV/LiBKizBv34SF/Qx178cHetPm/wMiCwJCdCUv/aAealueCvhI8o6VV4n5MisIM2XPquDFwtHpA4P7d6I6OFL+1q4lItLrVH3mp/W4nrAprZkbDhC4X7S2IKeB4gjbrR3X3V/O3IuOBGZiXpNQgrwMFfFsbsIh1XDTSZxV9zSbg0f/Q+N+RK1A3f15MjmdX1H9FEj1EezemZF9vPGBj49CyLZ55hYc439kWnJh58WPmxW16YNrZ/VyPo115/+fVZDpC8C7c+xFwgx9hBgKZLc602kQYvW2ZofbHCmEDcYWo9mA0ZLwXbeeFukxHLMPJgLQAAVyz0/MZ2MZvs0OoGnFwsnPFNDDzMQK0/oKzWlsLo1+quZ0JxA7a9w7hRTaEdF2zBoFLnZMihH+6Ld1DaTAjKrjrchITE/u9yPr0FprMEAwe81v+ulIxgnRzWWX9/CichYv9EVOlMjZnjaF4k4QNJhKTYn9RGb7gB95h++WMIO4OJLo8ReUMQeOEMwqu+JYi3T/2bQ2bpilpuy76L+PN0l5a7s77D8VsFHxYY+VVHuuW4423+6op+LMCwiowE37gF6ngOe4tr8n/qX+4M+STvyw9l3gogHAm0Qo+dSc1QZmfLv4qCyY7qXONBInNxJBK4PfgFuzZG5SaebPhBuLHGB7uxTbVwd7EVprPRm3UMvDOaxgcqGIxfn5WoCbxdGSZMwDnBQbv8RsjSjFakGKSMJkh/MxzM9aJWxk9yAWKYSr9vWIyvn4L+mmZ2gu1b0Zx7UsfW33w+dxbOnag9OJuFUZycl1864Cjd8n4sw5jHojdC5aX7uWs3vgYCeH89DbTyF X-Forefront-Antispam-Report: CIP:12.22.5.234; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(136003)(396003)(39860400002)(346002)(376002)(36840700001)(46966006)(40470700004)(186003)(36756003)(36860700001)(2906002)(70586007)(478600001)(82740400003)(83380400001)(336012)(82310400005)(40480700001)(426003)(356005)(40460700003)(16526019)(47076005)(316002)(1076003)(2616005)(7416002)(4326008)(107886003)(5660300002)(110136005)(7406005)(8936002)(70206006)(54906003)(41300700001)(26005)(7696005)(81166007)(8676002)(36900700001)(2101003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2022 07:22:15.2171 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 616d9819-8203-4a14-e120-08da64a06978 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.234]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT036.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2825 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add a new module parameter, configfs attribute to configure handling of the REQ_OP_VERIFY. This is needed for testing newly added REQ_OP_VERIFY block layer operation. Signed-off-by: Chaitanya Kulkarni --- drivers/block/null_blk/main.c | 20 +++++++++++++++++++- drivers/block/null_blk/null_blk.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index d44629538cc4..c31cad169595 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -77,6 +77,10 @@ enum { NULL_IRQ_TIMER = 2, }; +static bool g_verify = true; +module_param_named(verify, g_verify, bool, 0444); +MODULE_PARM_DESC(verify, "Allow REQ_OP_VERIFY processing. Default: true"); + static bool g_virt_boundary = false; module_param_named(virt_boundary, g_virt_boundary, bool, 0444); MODULE_PARM_DESC(virt_boundary, "Require a virtual boundary for the device. Default: False"); @@ -400,6 +404,7 @@ NULLB_DEVICE_ATTR(blocking, bool, NULL); NULLB_DEVICE_ATTR(use_per_node_hctx, bool, NULL); NULLB_DEVICE_ATTR(memory_backed, bool, NULL); NULLB_DEVICE_ATTR(discard, bool, NULL); +NULLB_DEVICE_ATTR(verify, bool, NULL); NULLB_DEVICE_ATTR(mbps, uint, NULL); NULLB_DEVICE_ATTR(cache_size, ulong, NULL); NULLB_DEVICE_ATTR(zoned, bool, NULL); @@ -522,6 +527,7 @@ static struct configfs_attribute *nullb_device_attrs[] = { &nullb_device_attr_power, &nullb_device_attr_memory_backed, &nullb_device_attr_discard, + &nullb_device_attr_verify, &nullb_device_attr_mbps, &nullb_device_attr_cache_size, &nullb_device_attr_badblocks, @@ -588,7 +594,7 @@ nullb_group_drop_item(struct config_group *group, struct config_item *item) static ssize_t memb_group_features_show(struct config_item *item, char *page) { return snprintf(page, PAGE_SIZE, - "memory_backed,discard,bandwidth,cache,badblocks,zoned,zone_size,zone_capacity,zone_nr_conv,zone_max_open,zone_max_active,blocksize,max_sectors,virt_boundary\n"); + "memory_backed,discard,verify,bandwidth,cache,badblocks,zoned,zone_size,zone_capacity,zone_nr_conv,zone_max_open,zone_max_active,blocksize,max_sectors,virt_boundary\n"); } CONFIGFS_ATTR_RO(memb_group_, features); @@ -651,6 +657,7 @@ static struct nullb_device *null_alloc_dev(void) dev->hw_queue_depth = g_hw_queue_depth; dev->blocking = g_blocking; dev->use_per_node_hctx = g_use_per_node_hctx; + dev->verify = g_verify; dev->zoned = g_zoned; dev->zone_size = g_zone_size; dev->zone_capacity = g_zone_capacity; @@ -1394,6 +1401,10 @@ blk_status_t null_process_cmd(struct nullb_cmd *cmd, return ret; } + /* currently implemented as noop */ + if (op == REQ_OP_VERIFY) + return 0; + if (dev->memory_backed) return null_handle_memory_backed(cmd, op, sector, nr_sectors); @@ -1769,6 +1780,12 @@ static void null_config_discard(struct nullb *nullb) blk_queue_max_discard_sectors(nullb->q, UINT_MAX >> 9); } +static void null_config_verify(struct nullb *nullb) +{ + blk_queue_max_verify_sectors(nullb->q, + nullb->dev->verify ? UINT_MAX >> 9 : 0); +} + static const struct block_device_operations null_bio_ops = { .owner = THIS_MODULE, .submit_bio = null_submit_bio, @@ -2058,6 +2075,7 @@ static int null_add_dev(struct nullb_device *dev) blk_queue_virt_boundary(nullb->q, PAGE_SIZE - 1); null_config_discard(nullb); + null_config_verify(nullb); if (config_item_name(&dev->item)) { /* Use configfs dir name as the device name */ diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h index 8359b43842f2..2a1df1bc8165 100644 --- a/drivers/block/null_blk/null_blk.h +++ b/drivers/block/null_blk/null_blk.h @@ -111,6 +111,7 @@ struct nullb_device { bool power; /* power on/off the device */ bool memory_backed; /* if data is stored in memory */ bool discard; /* if support discard */ + bool verify; /* if support verify */ bool zoned; /* if device is zoned */ bool virt_boundary; /* virtual boundary on/off for the device */ }; From patchwork Wed Jul 13 07:20:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 590741 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 CAF85CCA479 for ; Wed, 13 Jul 2022 07:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234569AbiGMHWq (ORCPT ); Wed, 13 Jul 2022 03:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234440AbiGMHWc (ORCPT ); Wed, 13 Jul 2022 03:22:32 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2056.outbound.protection.outlook.com [40.107.223.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2B42E2A19; Wed, 13 Jul 2022 00:22:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N8QHpme/PzxGqTqwsDTW/Y7Bvik8kphIV7peU2jC4015A2lr6fbs5RgsVW+yQ6ZuzloqMjKXgmJFhsA8gslAf3o1d+tmIR1xjKo90dOVEr8Ons5lz2QLvZolF2NMxLIJiLIjaKoBiVNPO39vZ2VL8q4wWXfaGpjk6Pyhdq+AOP2wbdzeQFyw7rJhLCfQ07wmOT/JMNt/qE5m/WAj8eBJ5ABN4DtdLsxz+m5g0Nt3ieMqSs6tRZuowzFS336jVBYm2vQErVqmPlo9XqM9AoRGSPpbU4NqyNxu4ScknNJCietTZSn2VxqA1N/nvgwmTgnTYfqep7ySN05mTPYxunvESQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GdM5KiJTOKaOqKlARvS1nTvEPZ1AO+iGJBYnQlmew5o=; b=ZwjHFOPT4tRcrnMszQwNiX8uakHYFO/9Riiu1v1+dhtFCdX9gQMPWlBWFdfMkzVvMwR9H/aL8XTKnbCY7Zt4OsJ8o9KmGIBfSIMzdj3xF9lbQ5FkzGJQU/3hTHKfXlZQ6Q+BvCYrsYK75VwCGTvqIYcTReahDXx0pYGcLOHguFGtXGLETPyIlBigvfWn+UfIgatjJ/fdhBb31vaPJBYMge6j+noRtl/6UlUarwSIuFdB2KbVjokLJ4zTIyGsaWRejaLF6F+tAUYuJEZaf5gMF8u+NP6932VXUQeYt2jhBBRMq5r9luqMrmKSPaEpQ4MQ3C0fKKtmQsAfSHpAdXQ2yQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=kernel.dk smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GdM5KiJTOKaOqKlARvS1nTvEPZ1AO+iGJBYnQlmew5o=; b=eM5DvZjrIenCoHVJ+euS5MBIx6O4PSQ9lzt01p3lx7CMwlCUBlbQh9Rh+X9oxPjS6K020ntBqG8S4dTBr9lLYEYUg1OK8DoUsztdjkbps+Y4u8KqzvQIH+3QAIhyVdqxBt3CIdsVfzamFoOQ4PdQnttkc2w2pPfdYF/YoFudWf1nNPIQSNr03tQW4pv3kZWW6ZlxRqAk4r1DYb4TKLkG+gI9Fl+Cu1DWLV44l6wiRDhSZ1tBmf4/OeZVyws0TGeUttPntNhQdraC5rZYwGk6zviT10JlcKnUmBUwZI/2czmj4TyCvTpEq7k0c6GG6hDmp6khvhPv8OcDXxkYi/xjow== Received: from MW4PR03CA0279.namprd03.prod.outlook.com (2603:10b6:303:b5::14) by DM5PR12MB1627.namprd12.prod.outlook.com (2603:10b6:4:10::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.16; Wed, 13 Jul 2022 07:22:29 +0000 Received: from CO1NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b5:cafe::f2) by MW4PR03CA0279.outlook.office365.com (2603:10b6:303:b5::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.19 via Frontend Transport; Wed, 13 Jul 2022 07:22:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT047.mail.protection.outlook.com (10.13.174.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5438.12 via Frontend Transport; Wed, 13 Jul 2022 07:22:28 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 13 Jul 2022 07:22:27 +0000 Received: from dev.nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 13 Jul 2022 00:22:25 -0700 From: Chaitanya Kulkarni To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , Chaitanya Kulkarni Subject: [PATCH V2 6/6] scsi: sd: add support for REQ_OP_VERIFY Date: Wed, 13 Jul 2022 00:20:19 -0700 Message-ID: <20220713072019.5885-7-kch@nvidia.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220713072019.5885-1-kch@nvidia.com> References: <20220713072019.5885-1-kch@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7aac256d-1c1c-46f6-92c7-08da64a0716d X-MS-TrafficTypeDiagnostic: DM5PR12MB1627:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8ec26Jg94V2AJOlwQEfKM80zlZ2+tD/Qp9BeD0p4m4/E6E7OpP7bmq6GWhIX3WwFRohvKg/30D4Uh7HftZ+O6mbC/6z2Ztjb/m8l0HmZ/mig7GRoSBBouPnMj6KQBTpi8Zlnhg0ueMs2wCUu0AhXNqw847C9YkdWCKZ+3U0SPGXockGBjsdVo8eqT6SKmphJdsX9KazbOgZFKGYRnADCoFhkzIcrm5/ZyElizH/GKKB5nZLjuZKIkegCJhAj/vGq/XltEnlCpY5v+dvyHUDfSpl4cvJktD2ytBnUDo7gUsvPGICqXq1zQJxGCnMxIeaYArsrPxyjOdPboRJdRA6HlAAeywrpcpcGiKnOOQF/yznajYCbC7qmxnNfLTs+3D6E6WJ/rDEGnGk/VOdKzilEyyngmZ9uSgQJ7cEHtBaGa/vM1b5960BqDLApmhbHc629c4WFOczWJNLoFt/L3vyZCalB9qENgcEyICH7p+hGCNQFOXj8F9ajm++JvrG5DxH82JLPawy1P40XBUpvRMRuNG7Sw35A1pKgZEc55sJQOS2+dvZhxxceTKftDqP7QqMBCvOyNIsu0DbflqqJP/wXwE+ndONqYEJiRfnQJn275b+iCThLXw1GFMXDeqW0pbOgOrWLbv2+DWtZvLQypU3ghNe3OYKn5a9djt6cMWSRgHZRH5invKZW3sz60+gTKOJcHtDAmXrsztWlu+p+KJbp5rMDQZBMsHRdC5Ttto5ZhInkGEe2bka3Cyu7KCzj92dP4FJR8A1PdbuxYg87aPrLFxv30GOZnDuDmzk1Jg0uTjJbkw8s6oIZdauuRrI23trWEhTcLKnVaNlQCwzsXfX9IOtZwVyAxbKswX7YFbIOxvPI+9L8FZMgxLroLdi2b0wD X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(396003)(136003)(39860400002)(346002)(376002)(46966006)(40470700004)(36840700001)(110136005)(4326008)(36860700001)(186003)(70586007)(478600001)(316002)(5660300002)(41300700001)(8676002)(70206006)(107886003)(8936002)(6666004)(1076003)(26005)(7416002)(81166007)(16526019)(54906003)(356005)(2616005)(82740400003)(7406005)(47076005)(426003)(336012)(2906002)(83380400001)(36756003)(40480700001)(40460700003)(82310400005)(7696005)(2101003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2022 07:22:28.5804 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7aac256d-1c1c-46f6-92c7-08da64a0716d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1627 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add support to handle REQ_OP_VERIFY req_op and map it on VERIFY (16) or VERIFY (10) in the sd driver. In case SCSI command VERIFY (16) is not supported use SCSI command VERIFY (10). Tested with scsi_debug. Signed-off-by: Chaitanya Kulkarni --- drivers/scsi/sd.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/scsi/sd.h | 5 ++ 2 files changed, 129 insertions(+) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index eb02d939dd44..8ba8bdd78ebd 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -101,6 +101,7 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC); static void sd_config_discard(struct scsi_disk *, unsigned int); static void sd_config_write_same(struct scsi_disk *); +static void sd_config_verify(struct scsi_disk *sdkp); static int sd_revalidate_disk(struct gendisk *); static void sd_unlock_native_capacity(struct gendisk *disk); static int sd_probe(struct device *); @@ -519,6 +520,43 @@ max_write_same_blocks_store(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RW(max_write_same_blocks); +static ssize_t +max_verify_blocks_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct scsi_disk *sdkp = to_scsi_disk(dev); + + return sprintf(buf, "%u\n", sdkp->max_verify_blocks); +} + +static ssize_t +max_verify_blocks_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct scsi_disk *sdkp = to_scsi_disk(dev); + struct scsi_device *sdp = sdkp->device; + unsigned long max; + int err; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (sdp->type != TYPE_DISK && sdp->type != TYPE_ZBC) + return -EINVAL; + + err = kstrtoul(buf, 10, &max); + + if (err) + return err; + + sdkp->max_verify_blocks = max; + + sd_config_verify(sdkp); + + return count; +} +static DEVICE_ATTR_RW(max_verify_blocks); + static ssize_t zoned_cap_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -579,6 +617,7 @@ static struct attribute *sd_disk_attrs[] = { &dev_attr_provisioning_mode.attr, &dev_attr_zeroing_mode.attr, &dev_attr_max_write_same_blocks.attr, + &dev_attr_max_verify_blocks.attr, &dev_attr_max_medium_access_timeouts.attr, &dev_attr_zoned_cap.attr, &dev_attr_max_retries.attr, @@ -1018,6 +1057,68 @@ static void sd_config_write_same(struct scsi_disk *sdkp) (logical_block_size >> 9)); } +static blk_status_t sd_setup_verify16_cmnd(struct scsi_cmnd *cmd, u64 lba, + u32 nr_blocks) +{ + cmd->cmd_len = 16; + cmd->cmnd[0] = VERIFY_16; + put_unaligned_be64(lba, &cmd->cmnd[2]); + put_unaligned_be32(nr_blocks, &cmd->cmnd[10]); + cmd->cmnd[14] = 0; + cmd->cmnd[15] = 0; + + return BLK_STS_OK; +} + +static blk_status_t sd_setup_verify10_cmnd(struct scsi_cmnd *cmd, u64 lba, + u32 nr_blocks) +{ + if (lba > 0xffffffff && nr_blocks > 0xffff) + return BLK_STS_NOTSUPP; + + cmd->cmd_len = 10; + cmd->cmnd[0] = VERIFY; + put_unaligned_be32((u32)lba, &cmd->cmnd[2]); + put_unaligned_be16((u16)nr_blocks, &cmd->cmnd[6]); + cmd->cmnd[9] = 0; + + return BLK_STS_OK; +} + +static blk_status_t sd_setup_verify_cmnd(struct scsi_cmnd *cmd) +{ + struct request *rq = scsi_cmd_to_rq(cmd); + struct scsi_disk *sdkp = scsi_disk(rq->q->disk); + struct scsi_device *sdp = cmd->device; + u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq)); + u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); + + if (!sdkp->verify16 && !sdkp->verify10) + goto out; + + cmd->allowed = SD_MAX_RETRIES; + cmd->sc_data_direction = DMA_NONE; + cmd->transfersize = 0; + /* skip veprotect / dpo / bytchk */ + cmd->cmnd[1] = 0; + + if (sdkp->verify16) + return sd_setup_verify16_cmnd(cmd, lba, nr_blocks); + if (sdkp->verify10) + return sd_setup_verify10_cmnd(cmd, lba, nr_blocks); +out: + return BLK_STS_TARGET; +} + +static void sd_config_verify(struct scsi_disk *sdkp) +{ + unsigned int max_verify_sectors = sdkp->max_verify_blocks; + unsigned int logical_bs = sdkp->device->sector_size; + struct request_queue *q = sdkp->disk->queue; + + blk_queue_max_verify_sectors(q, max_verify_sectors * (logical_bs >> 9)); +} + static blk_status_t sd_setup_flush_cmnd(struct scsi_cmnd *cmd) { struct request *rq = scsi_cmd_to_rq(cmd); @@ -1244,6 +1345,8 @@ static blk_status_t sd_init_command(struct scsi_cmnd *cmd) } case REQ_OP_WRITE_ZEROES: return sd_setup_write_zeroes_cmnd(cmd); + case REQ_OP_VERIFY: + return sd_setup_verify_cmnd(cmd); case REQ_OP_FLUSH: return sd_setup_flush_cmnd(cmd); case REQ_OP_READ: @@ -1935,6 +2038,7 @@ static int sd_done(struct scsi_cmnd *SCpnt) switch (req_op(req)) { case REQ_OP_DISCARD: case REQ_OP_WRITE_ZEROES: + case REQ_OP_VERIFY: case REQ_OP_ZONE_RESET: case REQ_OP_ZONE_RESET_ALL: case REQ_OP_ZONE_OPEN: @@ -3021,6 +3125,24 @@ static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer) sdkp->ws10 = 1; } +static void sd_read_verify(struct scsi_disk *sdkp, unsigned char *buffer) +{ + struct scsi_device *sdev = sdkp->device; + + if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, VERIFY_16)) { + sd_printk(KERN_DEBUG, sdkp, "VERIFY16 supported\n"); + sdkp->verify16 = 1; + sdkp->max_verify_blocks = SD_MAX_VERIFY16_BLOCKS; + return; + } + + if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, VERIFY)) { + sd_printk(KERN_DEBUG, sdkp, "VERIFY10 supported\n"); + sdkp->verify10 = 1; + sdkp->max_verify_blocks = SD_MAX_VERIFY10_BLOCKS; + } +} + static void sd_read_security(struct scsi_disk *sdkp, unsigned char *buffer) { struct scsi_device *sdev = sdkp->device; @@ -3264,6 +3386,7 @@ static int sd_revalidate_disk(struct gendisk *disk) sd_read_cache_type(sdkp, buffer); sd_read_app_tag_own(sdkp, buffer); sd_read_write_same(sdkp, buffer); + sd_read_verify(sdkp, buffer); sd_read_security(sdkp, buffer); sd_config_protection(sdkp); } @@ -3312,6 +3435,7 @@ static int sd_revalidate_disk(struct gendisk *disk) set_capacity_and_notify(disk, logical_to_sectors(sdp, sdkp->capacity)); sd_config_write_same(sdkp); + sd_config_verify(sdkp); kfree(buffer); /* diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 5eea762f84d1..249100e2ea1f 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -49,6 +49,8 @@ enum { SD_MAX_XFER_BLOCKS = 0xffffffff, SD_MAX_WS10_BLOCKS = 0xffff, SD_MAX_WS16_BLOCKS = 0x7fffff, + SD_MAX_VERIFY10_BLOCKS = 0xffff, + SD_MAX_VERIFY16_BLOCKS = 0xffffff, }; enum { @@ -118,6 +120,7 @@ struct scsi_disk { u32 max_xfer_blocks; u32 opt_xfer_blocks; u32 max_ws_blocks; + u32 max_verify_blocks; u32 max_unmap_blocks; u32 unmap_granularity; u32 unmap_alignment; @@ -145,6 +148,8 @@ struct scsi_disk { unsigned lbpvpd : 1; unsigned ws10 : 1; unsigned ws16 : 1; + unsigned verify10 : 1; + unsigned verify16 : 1; unsigned rc_basis: 2; unsigned zoned: 2; unsigned urswrz : 1;