From patchwork Mon Feb 20 10:53:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 59440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1289613wrn; Mon, 20 Feb 2023 04:54:15 -0800 (PST) X-Google-Smtp-Source: AK7set/ko+XQ3TRPJYgSTP7JP7GuC8/VYXSHRN4k6SrMIAhz1x42dTrMqWXEenR3RLOiXhCcKMeR X-Received: by 2002:a05:6402:25c2:b0:49e:4786:a0e2 with SMTP id x2-20020a05640225c200b0049e4786a0e2mr167722edb.14.1676897655661; Mon, 20 Feb 2023 04:54:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676897655; cv=none; d=google.com; s=arc-20160816; b=zQuWyOIOLwKY7FISH+nB09RcBMGQMjqWo4ZBMrUIRoMpa+Mbn6SwBt2dFGEfmdEw4p XlvxS1ZLcTNu1dGySs2GNfLa3LaojLxu8260YlFBskN7HB1iU0kfYxLATgNJMhFr8nT7 VDKZEjxeNLQ4qWGS8WFt5V9OCmDCkxrvq7zC8l5V7++EKYimWWHrhrKcwz8CEM3qgDqv 4DKcOAU7T3HNApD8kG+Xr113MoaQL5oVWpFWxUfkpqKNY/1EO3AAufrYiBRE/WLnrCyx moQIE3/I/0jCDN+A7Ur62pHrC3lb31LV/KXAwVGfTHpzfRSsbHmQ3nWJjaoirxYA6EaI dUyQ== 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=XGNkx5qSzlaIQS0bmijGetWK2+jr9bxd+0INHc6HMjSkYCcwiEpdfoZu7ILZKlXvSP S1vO1mQ5KnQd1f7MjZXTDGN63+thI/udHl44cLALb1XBrmvjB1wV/fnJvvFynpPDIbjL idV4o3z2W2lbKtOHkpLNlrdPvjpaSjnbaNhOyYZWsNcRUAA1SVrv3CEQ5zAby/6OwfYG JGiaRP+zSWS8puX8GXIkdS0e6+qr4ZBOvKELCObjqYCKLO9LIRFm7ke8wxN26Eb423zN ucm+qo0+PkEdLIrLHFwr7HI1zYsWC/WbpGFs2Kjt5MPrcrymBMWU5hTheO5rbO4MXGA4 0/vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=rvb4p4s8; 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 r20-20020aa7cfd4000000b004accbbe353dsi4144829edy.182.2023.02.20.04.53.51; Mon, 20 Feb 2023 04:54:15 -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=rvb4p4s8; 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 S232212AbjBTMuG (ORCPT + 99 others); Mon, 20 Feb 2023 07:50:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232134AbjBTMtb (ORCPT ); Mon, 20 Feb 2023 07:49:31 -0500 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ACC31D921 for ; Mon, 20 Feb 2023 04:48:52 -0800 (PST) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20230220124851epoutp03f648050e2c5a07d7784258a28d53e7c5~FiTzu1csT2305723057epoutp03V for ; Mon, 20 Feb 2023 12:48:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20230220124851epoutp03f648050e2c5a07d7784258a28d53e7c5~FiTzu1csT2305723057epoutp03V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1676897331; bh=xxiDP6QZKfeqkiRLoXjxlMN+FlItKe4BO652Ksxx5Yk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rvb4p4s828aNF+EMJ0SMueQ08Q8Q+Dx+98xkLJoCt9BFmxRb7qJcHwT98PT6hhWA0 YbH63omXTe4A0f/0hW42jIZlmkbo7sLINKHZIKIW0/NNB6azu9rRIy3rXdOQSBDHdJ G9mw1bvUWa08BZJU8OGtanHeGxpC4AEjDLCyBdek= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20230220124850epcas5p16d10e6638f58a2515de2b776d0de93ae~FiTy_AN3w2067920679epcas5p1a; Mon, 20 Feb 2023 12:48:50 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.178]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4PL2KX2zpcz4x9Px; Mon, 20 Feb 2023 12:48:48 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id D4.59.06765.03C63F36; Mon, 20 Feb 2023 21:48:48 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20230220105529epcas5p447cd449f13da54794e391b78bd1f5956~Fgw1DkzdR2307823078epcas5p4Q; Mon, 20 Feb 2023 10:55:29 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230220105529epsmtrp1f7f3bedff31f86864840edd7f762c623~Fgw1Cf1mh2429224292epsmtrp1q; Mon, 20 Feb 2023 10:55:29 +0000 (GMT) X-AuditID: b6c32a4b-46dfa70000011a6d-cf-63f36c30aefe Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 9E.0A.17995.1A153F36; Mon, 20 Feb 2023 19:55:29 +0900 (KST) Received: from green5.sa.corp.samsungelectronics.net (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230220105525epsmtip221cf243ac5da4c7cb295706198a8dd86~FgwyAn1a80747307473epsmtip2z; Mon, 20 Feb 2023 10:55:25 +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: bvanassche@acm.org, hare@suse.de, ming.lei@redhat.com, damien.lemoal@opensource.wdc.com, anuj20.g@samsung.com, joshi.k@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 v7 7/8] dm: Add support for copy offload. Date: Mon, 20 Feb 2023 16:23:30 +0530 Message-Id: <20230220105336.3810-8-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20230220105336.3810-1-nj.shetty@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Tf1CTdRzHeZ5nezbI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WlZcgqrOi9VJcaxnAW4 Exi9RvhB2yIVkTGyBPYcyypZ1b8WIRzd1Ijs5O2Pq49+po0+4RtnYiV329N9Ako1w3b8eX6T tG6+IztYU/3WnJhWYqi44XesTDpqw9+n3byArrATox3fMdnqh00hw9MbC3JLXMXNt7sTvELL C4/20l7yYGtEyHZxvVLjzGYPeW47kqDqSZotDvDMnPTacnhX9fcDpSmTTdVRmlD3gyJ5zU+f EdMMd2Jdl7foT2uYc2PEbuf+jsHhvJH8U2LfoLB+a7exT2DEOstf4ZYi+mqI/A4XBdJnzw7W /IjTNfxSGEc8drgPyqNsJRLFLvXAXnyuWBWqTl0okLfQ+30L9Q2Gs1Ld1NjxfVmpU0Ug8Fbw hpzJGjfuWzKNcbGyAAmq4mR/AS8xISlUAwAA X-CMS-MailID: 20230220105529epcas5p447cd449f13da54794e391b78bd1f5956 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230220105529epcas5p447cd449f13da54794e391b78bd1f5956 References: <20230220105336.3810-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=ham 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?1758354635882477522?= X-GMAIL-MSGID: =?utf-8?q?1758354635882477522?= 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);