Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp870459rdb; Wed, 6 Dec 2023 02:12:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IH328h7SQ1eyhd88tarGbpOHweJqi54kWZKJE1YFTSHSoF7u45q9ThtOCwSOzFpPXD5eutv X-Received: by 2002:a05:6870:b51f:b0:1fb:75b:12ec with SMTP id v31-20020a056870b51f00b001fb075b12ecmr723610oap.62.1701857573911; Wed, 06 Dec 2023 02:12:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701857573; cv=none; d=google.com; s=arc-20160816; b=zlxHq5pLqNPHoBCCS607vVczuSXHMh5b20Gtii+Y4eBB7vBq5IvzsIOLPWkg8fFQfP JrGftznDjbuRpEhNKEbwzF2Wx2ypPn7KV2iwi7c4q2Q0MvnuQ+pS8LclDD8c5/OZnM03 BhfwixJsR3im6uM9VAPWMAsHEC94fKi0ioe9z8g6OhSP8isjZDbv3kOiJCvbZ6eGqGwx ZDiU1PTHTUn9vZfBWEaDucuJi7fmOQvCAAOY00KnNqntdYKcrJx+75+JCPtvPaY9FNn9 Y0Ao1ivazZnD27Zk0XvO+hbC+rAIqVRZ7SIN85dcAFbIyvsUW365ELQgDV8fhEJsUTw0 xh3Q== 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=vUmnCkDPVKAomoDbL/LzqNJSOMEo+hX7Rt95xB1wr2E=; fh=CLy6Yt7X3R3g63FkLqfkJTUh9I0/R59DzG55U5R3DOE=; b=dW3LlQ8iKkzC1XlDoMXPui4DZs1sVqQ5d2HtIcZIfbAiOQvzn9VzLoihlD339KSj9f N07/o/GUbQ3e/bH0SlQCX7FVHqiKNsXIzrFCaiNB+XASfU41RrwQzqtjm+LR1dqTeXNB 0sGZ6Dy4evImOslJSPDXz7NibBOaC/cMwCq2Extgz2IA9+ENBy250m0oPFKGp54WrYHM Kgo11Vcb+MmI+zsE3t7iboWkueJWmK3T31QRqn1S1/2nKRIxJt7ZCXMGCCJLIHyGFwli oCENrjuU+vddgt1/ylw/o5/9B22rgT8H2Le/sC6q64mvCa07on4PMmMJ6k89ZKBCqaV7 fehQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=KqByg77n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id c10-20020a65420a000000b005c657587706si7486214pgq.228.2023.12.06.02.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 02:12:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=KqByg77n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 2FF89803BE92; Wed, 6 Dec 2023 02:12:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377541AbjLFKMg (ORCPT + 99 others); Wed, 6 Dec 2023 05:12:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377544AbjLFKMc (ORCPT ); Wed, 6 Dec 2023 05:12:32 -0500 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABF1CD6F for ; Wed, 6 Dec 2023 02:12:36 -0800 (PST) Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20231206101234epoutp0276b4f2d73a7683725d5873e8c1fad473~eNm3fMd1D2309923099epoutp02Z for ; Wed, 6 Dec 2023 10:12:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20231206101234epoutp0276b4f2d73a7683725d5873e8c1fad473~eNm3fMd1D2309923099epoutp02Z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1701857554; bh=vUmnCkDPVKAomoDbL/LzqNJSOMEo+hX7Rt95xB1wr2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KqByg77ns7Ftfh/iSyw1FE0X9KoX53pCfRlXGZizpC8WuakukSG3cCRs71EhTTcv4 SWM5XNQf+5hnr/Lf412nWG1WPFyqucYycg4t2oJARPTql2f8oS1CxsiIBnwC4SMK46 pvmHRQgZkxpurBGtzmew/ThtntxrYhtLy85homjU= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20231206101234epcas5p3d2021e6e34c58b154e7090c86f997ba8~eNm20kUqr0791407914epcas5p37; Wed, 6 Dec 2023 10:12:34 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.177]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4SlY9r0DV3z4x9Pw; Wed, 6 Dec 2023 10:12:32 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 64.22.09672.F0940756; Wed, 6 Dec 2023 19:12:31 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20231206101231epcas5p1756d9f527df621f3a0eebb37ca257f06~eNm0Wee4t1084010840epcas5p1B; Wed, 6 Dec 2023 10:12:31 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231206101231epsmtrp241901a3d3967ff948874ef6197994654~eNm0UoYOX1007210072epsmtrp2W; Wed, 6 Dec 2023 10:12:31 +0000 (GMT) X-AuditID: b6c32a4b-60bfd700000025c8-7c-6570490f4a3d Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id E2.62.08817.F0940756; Wed, 6 Dec 2023 19:12:31 +0900 (KST) Received: from localhost.localdomain (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231206101227epsmtip2deeb866484ba7d4dc0142cdd65304b11~eNmwjZbBJ0221302213epsmtip2H; Wed, 6 Dec 2023 10:12:27 +0000 (GMT) From: Kanchan Joshi To: Jens Axboe , Jonathan Corbet , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , dm-devel@lists.linux.dev, Keith Busch , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Alexander Viro , Christian Brauner Cc: martin.petersen@oracle.com, linux-scsi@vger.kernel.org, nitheshshetty@gmail.com, anuj1072538@gmail.com, gost.dev@samsung.com, mcgrof@kernel.org, Nitesh Shetty , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v18 09/12] dm: Add support for copy offload Date: Wed, 6 Dec 2023 15:32:41 +0530 Message-Id: <20231206100253.13100-10-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206100253.13100-1-joshi.k@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA01TbVBUVRju3Hv37i4TuC0yHMmU7tSoyNfGQmdBigrzpuUw9Kf8sy67dxaG ZXfdj0SdpkXiQxCWDzU+Q4ii2IwPNwKElKUgmACV4dNkCHcHFWQRrFDEaZeL5b/nec/znud5 3zOHhwufkH68JLWB0allKor0IFq6d+0M2vSelgm9VhWOGvp7cHT/r1UCWW6aSTTXvQSQ/UoW QOdrKgk0caUNQ99ZfsVQkW0UIMdIGYY6J3ej6sxaAnV09hFouL2CRFXfOLgod6yVRHW9TzA0 XuAAqDB7BEOt9jSAWlarcPTDnJNAv02+iIbWejkxkG4ru8mlh6aaCHp4wEg3158i6Yu1n9G3 L5YC+tKEiaS/yi/m0HnpCyR93zFJ0M6fR0g631oP6OXmbXSz/R4W53UoeU8iI1MwOn9GLdco ktTKaOrAh9J3pOERoaIgkQS9TvmrZSlMNBX7flzQu0kq1xIo/09kKqOrFCfT66mQN/boNEYD 45+o0RuiKUarUGnF2mC9LEVvVCuD1YwhUhQa+lq4S3g4OdE5/xDTLm9JnR+14iaQ75MD+Dwo EMPefjsnB3jwhIJLAHZkP9ggSwAuZjwlfwNosn6N5QDeestcD4+tdwJ4tbqRZMkygNduD+Nu ESnYBa8WG90WmwXf47CtSeTW4IIJDA5cbsHcB96CKNiyWslxY0LwKlw41wTc2FMggYXtWRw2 33ZYev0frhvzXfXi2Rqc1bwA+0rthBvjLk36j+W42wAKqvhwotvkSsR1kVi4upW9xhve7bVy WewHlxc6SRbL4fXSQYzFBniro2sDvwkz+s3ro+CuURraQ1gnL5i3at9YgyfMzhSy6pfhVJFj I7Av/LOklsNKaLjwmGCXcxrAP9JzOQVge9kz+cueyV/2v9l5gNeDLYxWn6Jk9OHaMDVz9L9X lWtSmsH6Rwg40ApmpheDbQDjARuAPJza7Kka0jBCT4Xs2HFGp5HqjCpGbwPhrgUX4n4+co3r J6k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WKPRmj kSk1WlVizNEkpRlMPjoqygIemD7H2AFGATuAFC6ZJVI4k1ixKEGWeprlkg5zWgWrsYO5FCEJ F434dAliOlGWzB5nWTXL/XMxij8nHSOvFh+o0R0nzygGvV2jPrnladPhtCWvUt0bv15ujSMN T1vbe2Olzx5n+xr59q35Dv88x9LmbTs74/OF5TXijH1SscfY6Ne3ddpyjQv7xh/CkmS2NbfZ 0SUQvvDvlun5wrvPG+Qny8Qtu+pzAiLZB2bHiiOu6Q3DF35JU9tt7vC1qbgrvsD3HvxIifbe iAzdaDx7ernuyfWfnW+qB4XP0/xf6+sMr0YWXNztPGSOi91L7DsSWP0ue8HtKuuJg6aIxV4n V+Dd8vImXVbxpNcWKpjmkGe4Dv18uyaOU81e/65Ul6OVWlP2f1BZTf2/hzPFeV2xO9TN46uV 3M3Emj8jEkJzTLYyCuc0sr8K69AIVwMAAA== X-CMS-MailID: 20231206101231epcas5p1756d9f527df621f3a0eebb37ca257f06 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231206101231epcas5p1756d9f527df621f3a0eebb37ca257f06 References: <20231206100253.13100-1-joshi.k@samsung.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 06 Dec 2023 02:12:51 -0800 (PST) From: Nitesh Shetty 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 | 37 +++++++++++++++++++++++++++++++++++ drivers/md/dm.c | 7 +++++++ include/linux/device-mapper.h | 3 +++ 3 files changed, 47 insertions(+) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 198d38b53322..a3e1695d111f 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1899,6 +1899,38 @@ 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 !q->limits.max_copy_sectors; +} + +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) { @@ -1981,6 +2013,11 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, q->limits.discard_misaligned = 0; } + if (!dm_table_supports_copy(t)) { + q->limits.max_copy_sectors = 0; + q->limits.max_copy_hw_sectors = 0; + } + 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 8dcabf84d866..c209348a0064 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1721,6 +1721,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 772ab4d74d94..d840ed38516c 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -397,6 +397,9 @@ 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); -- 2.35.1.500.gb896f729e2