From patchwork Thu Jan 12 11:59:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 42437 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3884932wrt; Thu, 12 Jan 2023 05:40:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXu2L4NBDpOGn3GzZ/qUEU/0V0HUUBB1yYHEU4HyKMiuU6VlDx97eTtfmgqMiE4wbUUlV3sJ X-Received: by 2002:a17:907:2056:b0:84d:44dd:e03a with SMTP id pg22-20020a170907205600b0084d44dde03amr14131811ejb.57.1673530848262; Thu, 12 Jan 2023 05:40:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673530848; cv=none; d=google.com; s=arc-20160816; b=Yf0GwJAE/KfPiWN7b3iq47AczwHpCQH8pMGf+f5Do/rqn0hqwUTJhaRSvns9/9pKoD F2AsGhpwDu0ophn4oQ53LuswmdSbBZ+EfJgcx9qBMNhe4azen9hN9y6o9BuckooW4AG8 QAG85RbJ3jcAERXHGcH+6+R3dOco2U7fVs2mCy7z+Mp6mckQ7vFm8AhEXf6zALVMlwFh nhB3CUqBeUsUiXeOTnDORP1n67pto6Bl297RHRda4EYMDYji+Wgie+mokHLvjChhq9cC THL+9J+01wzgFEZ2XLzq7mNJrdwGHSjD0vKZfa/EX3a5Rn3bNr3H1jd3cv7+lLnbpn6v lv5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type :content-transfer-encoding:mime-version:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=xxiDP6QZKfeqkiRLoXjxlMN+FlItKe4BO652Ksxx5Yk=; b=KsMc9i9l1bZMdC0LpyOecqJCtcCz4u8LTKJSqZ/sctNMZKMd10VEgYaIIYAyee3n3W 3F787pUkgRjsMYqEI5ICNYV0oXtw0UukBXKNbPNvea8AkB5rZemajCtn0AreOSs+WIpH hTCyEetZH4cbogUnrkbcy9W9iarAaco4gzk/sgiHwEqQ0dHI2vTF236HOJpJiESt7FbD 0svpBMzeyaS9E9t9/yuLJ/+/tnUNL3ofJf6eeRdkKxexAqiWkiHBB+5TYoB1hfJwG9qf TexnpPgaFTnnfdjWmGkl50hDfGPcv4zawPlvSWioiE42JsD0QCJ94rBk09JRUjfuHraT 0hPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=jsce4rKG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne26-20020a1709077b9a00b0077d854aa10dsi20411860ejc.57.2023.01.12.05.40.24; Thu, 12 Jan 2023 05:40:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=jsce4rKG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234424AbjALNjY (ORCPT + 99 others); Thu, 12 Jan 2023 08:39:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233291AbjALNiI (ORCPT ); Thu, 12 Jan 2023 08:38:08 -0500 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E49BF4FD4E for ; Thu, 12 Jan 2023 05:37:35 -0800 (PST) Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230112133731epoutp02cdae4723ebe5aeaa024bcced244206d7~5k0LQoBwT1978419784epoutp02a for ; Thu, 12 Jan 2023 13:37:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230112133731epoutp02cdae4723ebe5aeaa024bcced244206d7~5k0LQoBwT1978419784epoutp02a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1673530651; bh=xxiDP6QZKfeqkiRLoXjxlMN+FlItKe4BO652Ksxx5Yk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jsce4rKGyQiKl5XjIg2wDNbmjh3Netg8iOt/reKPr5u/kcNPlRih5QBUjLplK7rg8 R3LkEkIOWwJmTrSSpnOu6g1Kfd7Aw89Pd90Ow90PWoxrjSb/pThd6us15374NyqwJZ 3M+A5wx1WMsCYjLE+WOAzOPnxptThHYYUYabSwt4= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20230112133730epcas5p3115034feada6d2eb43b03735703670da~5k0J99zGe0296902969epcas5p3_; Thu, 12 Jan 2023 13:37:30 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.179]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4Nt5Fh4n3gz4x9Pv; Thu, 12 Jan 2023 13:37:28 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id F2.7D.62806.81D00C36; Thu, 12 Jan 2023 22:37:28 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20230112120210epcas5p41524bba73af1dcf283d21b9c7ee9d239~5jg63K7pf1219512195epcas5p45; Thu, 12 Jan 2023 12:02:10 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230112120210epsmtrp104d470e1504fcb5fa6721c082d747ad3~5jg62S8B62544625446epsmtrp1L; Thu, 12 Jan 2023 12:02:10 +0000 (GMT) X-AuditID: b6c32a4a-ea5fa7000000f556-d4-63c00d18ac89 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 63.C5.02211.2C6FFB36; Thu, 12 Jan 2023 21:02:10 +0900 (KST) Received: from green5.sa.corp.samsungelectronics.net (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230112120207epsmtip27ad59d8d34c5e51703861416dce1293a~5jg4PDTug1331213312epsmtip2v; Thu, 12 Jan 2023 12:02:07 +0000 (GMT) From: Nitesh Shetty To: Jens Axboe , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Keith Busch , Christoph Hellwig , Sagi Grimberg , James Smart , Chaitanya Kulkarni , Alexander Viro Cc: anuj20.g@samsung.com, joshi.k@samsung.com, p.raghav@samsung.com, nitheshshetty@gmail.com, gost.dev@samsung.com, Nitesh Shetty , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v6 7/9] dm: Add support for copy offload. Date: Thu, 12 Jan 2023 17:29:01 +0530 Message-Id: <20230112115908.23662-8-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20230112115908.23662-1-nj.shetty@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Tf1AUZRjH59099hbkcjmwXnGKa5UacPhxBLQQKDMYblpKxWTZMLgd290N x915e6fJTMMRSMKAB1l/sDh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v3GPX2pOg8p2J8YW1boPOubYVK5Ni7ui6 P2DsMFY0Frcr/Lz19+pDPEW/XmeXnlnxv8M1xWhBi3pJ2eHmN/Mntv/k33tH5tuG4oWXzC7c 37rj3sbqhIuBLTt705OfLekxu10xhe9RUKLv9GCO8o+BZcYeK1d8urL6RFvlBzfbs4eOnWSP ShaUdvv4osjP94vsnYRnwreaedby3FWQmG3Yd+Zp/7qCHyf27UlRYinOSDTUYi4qTgQAPbEw lTkDAAA= X-CMS-MailID: 20230112120210epcas5p41524bba73af1dcf283d21b9c7ee9d239 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230112120210epcas5p41524bba73af1dcf283d21b9c7ee9d239 References: <20230112115908.23662-1-nj.shetty@samsung.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754824282617586204?= X-GMAIL-MSGID: =?utf-8?q?1754824282617586204?= Before enabling copy for dm target, check if underlying devices and dm target support copy. Avoid split happening inside dm target. Fail early if the request needs split, currently splitting copy request is not supported. Signed-off-by: Nitesh Shetty --- drivers/md/dm-table.c | 42 +++++++++++++++++++++++++++++++++++ drivers/md/dm.c | 7 ++++++ include/linux/device-mapper.h | 5 +++++ 3 files changed, 54 insertions(+) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 8541d5688f3a..4a1bbbb2493b 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1875,6 +1875,39 @@ static bool dm_table_supports_nowait(struct dm_table *t) return true; } +static int device_not_copy_capable(struct dm_target *ti, struct dm_dev *dev, + sector_t start, sector_t len, void *data) +{ + struct request_queue *q = bdev_get_queue(dev->bdev); + + return !blk_queue_copy(q); +} + +static bool dm_table_supports_copy(struct dm_table *t) +{ + struct dm_target *ti; + unsigned int i; + + for (i = 0; i < t->num_targets; i++) { + ti = dm_table_get_target(t, i); + + if (!ti->copy_offload_supported) + return false; + + /* + * target provides copy support (as implied by setting + * 'copy_offload_supported') + * and it relies on _all_ data devices having copy support. + */ + if (!ti->type->iterate_devices || + ti->type->iterate_devices(ti, + device_not_copy_capable, NULL)) + return false; + } + + return true; +} + static int device_not_discard_capable(struct dm_target *ti, struct dm_dev *dev, sector_t start, sector_t len, void *data) { @@ -1957,6 +1990,15 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, q->limits.discard_misaligned = 0; } + if (!dm_table_supports_copy(t)) { + blk_queue_flag_clear(QUEUE_FLAG_COPY, q); + /* Must also clear copy limits... */ + q->limits.max_copy_sectors = 0; + q->limits.max_copy_sectors_hw = 0; + } else { + blk_queue_flag_set(QUEUE_FLAG_COPY, q); + } + if (!dm_table_supports_secure_erase(t)) q->limits.max_secure_erase_sectors = 0; diff --git a/drivers/md/dm.c b/drivers/md/dm.c index b424a6ee27ba..0b04093fbeb2 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1690,6 +1690,13 @@ static blk_status_t __split_and_process_bio(struct clone_info *ci) if (unlikely(ci->is_abnormal_io)) return __process_abnormal_io(ci, ti); + if ((unlikely(op_is_copy(ci->bio->bi_opf)) && + max_io_len(ti, ci->sector) < ci->sector_count)) { + DMERR("Error, IO size(%u) > max target size(%llu)\n", + ci->sector_count, max_io_len(ti, ci->sector)); + return BLK_STS_IOERR; + } + /* * Only support bio polling for normal IO, and the target io is * exactly inside the dm_io instance (verified in dm_poll_dm_io) diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index 04c6acf7faaa..da4e77e81011 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -379,6 +379,11 @@ struct dm_target { * bio_set_dev(). NOTE: ideally a target should _not_ need this. */ bool needs_bio_set_dev:1; + + /* + * copy offload is supported + */ + bool copy_offload_supported:1; }; void *dm_per_bio_data(struct bio *bio, size_t data_size);