From patchwork Mon May 22 10:41:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 13250159 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29188C77B73 for ; Mon, 22 May 2023 11:10:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE506280008; Mon, 22 May 2023 07:10:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B47E6280001; Mon, 22 May 2023 07:10:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94B87280008; Mon, 22 May 2023 07:10:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 859CB280001 for ; Mon, 22 May 2023 07:10:57 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5E97C40D7F for ; Mon, 22 May 2023 11:10:57 +0000 (UTC) X-FDA: 80817623754.06.58EF9BA Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by imf02.hostedemail.com (Postfix) with ESMTP id 2F76380014 for ; Mon, 22 May 2023 11:10:53 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=jLE+yCJo; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf02.hostedemail.com: domain of nj.shetty@samsung.com designates 203.254.224.33 as permitted sender) smtp.mailfrom=nj.shetty@samsung.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684753854; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1P2BJZZ/eKH4o2N5bmfZBmLKhHrfzdv6MvJHTRtfiUg=; b=ZxiBs61Pn/JYcQDeY39ePwS1hc2qX7r0t/KlYVz/sFFAQyaOlBbjFO3TY75LKQ+F+jTD0h Rhlxu8ofGjtzzkapErnzAhtf0NJw1DTdkCSHYDmcIn5NJFoHxlW/sLKwDs2VwgheMSzi7s TNVsA8XtX3uXBnBNIyEaYGTGw6RijQQ= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=jLE+yCJo; dmarc=pass (policy=none) header.from=samsung.com; spf=pass (imf02.hostedemail.com: domain of nj.shetty@samsung.com designates 203.254.224.33 as permitted sender) smtp.mailfrom=nj.shetty@samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684753854; a=rsa-sha256; cv=none; b=rOMEPPEJdXQCdq4GVJ1JiXs1nnGXFSjagk8qaVOBx+LYKCKClONpHhGbXoqyOQ+rjrdSL+ WtZLeGvcgMWLKGCOCfHnhgL708mnkTJ5ig3lo7NnGlpeZJAZaqedZccVeAOQ25BgNfsmHz RF7F699cf75CdtK9d13ESe1Tqgk4gw0= Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20230522111050epoutp030b130901e4eea01377bddae604dd9f4a~hcrOFPAmV1243312433epoutp03i for ; Mon, 22 May 2023 11:10:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20230522111050epoutp030b130901e4eea01377bddae604dd9f4a~hcrOFPAmV1243312433epoutp03i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1684753851; bh=1P2BJZZ/eKH4o2N5bmfZBmLKhHrfzdv6MvJHTRtfiUg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jLE+yCJo8rvze8zKIR8qt3EOxKGuGd03XPUXqBHnhPs1YE3N0sLxRcSK2P5eWlrjq 4wd+Du4UGcQIEuOHc9pL7PX+sxhrubgdkZMF78VBXxodKUC5dBvyGzVjcXWjgLSjNQ 9m96fpyinsxILizzTk/Bie6+VYhmXsBYJgPpWARQ= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20230522111050epcas5p21210becde80901bedfb5279ff1dc37df~hcrNhmLR22481324813epcas5p20; Mon, 22 May 2023 11:10:50 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.175]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4QPvrS5yCpz4x9Q2; Mon, 22 May 2023 11:10:48 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id F7.03.54880.8BD4B646; Mon, 22 May 2023 20:10:48 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20230522104648epcas5p2286a988d89b1befdb49984ebbefb25fd~hcWON8qBh1654016540epcas5p2X; Mon, 22 May 2023 10:46:48 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230522104647epsmtrp2f54f4efe0a6063ed075b8ef1db5011c5~hcWOMewuQ3249732497epsmtrp2V; Mon, 22 May 2023 10:46:47 +0000 (GMT) X-AuditID: b6c32a49-8c5ff7000001d660-e1-646b4db84c65 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id A2.FF.28392.7184B646; Mon, 22 May 2023 19:46:47 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230522104643epsmtip2f74158f3b9d3a6a02b917f21da70e2c6~hcWKbW10-1645716457epsmtip23; Mon, 22 May 2023 10:46:43 +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 , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton Cc: martin.petersen@oracle.com, linux-scsi@vger.kernel.org, James.Bottomley@HansenPartnership.com, bvanassche@acm.org, hare@suse.de, ming.lei@redhat.com, dlemoal@kernel.org, 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, linux-mm@kvack.org Subject: [PATCH v11 7/9] dm: Add support for copy offload Date: Mon, 22 May 2023 16:11:38 +0530 Message-Id: <20230522104146.2856-8-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20230522104146.2856-1-nj.shetty@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Ta0xTZxjOd045LWQdR8DsA6MrNQsD5VIs3VeFMQcxB5kRtmXJbikdPdAO elkvwkg2uekyGPdJZsVxW5Q7chnBAtPVaLnI2GSANOEyUqYTBVuygWmQFQ5u/nve532f5718 +Ti4Vxfbj6NQ6WmtSprOJzxYPTcCA4J7T6TJwizzwah9+BaOqtpbCJRbuoGj5pkSAi3dcABU +fgJjuavRaOB5QtuaPr6VQz115VjqLH5JoY6Sjior9aOoZubjwhUbp4EaHHCiKEB6wHUPzDE QuOmKgLNtmy6oepLi2xUONVLoMuWpxgyV+RhqNeWA1CPsxpHbUsrLDRo3YPGNixuyLleRbyx jxr/PZ4yzo0S1FXjDJsam+1gUZXlwwTV1R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Snx49/emUr94ucfVkz64zZb4wKJxb2+YZNYamy3+4ySCf/n0xd/s6dFWjot nSvaLfe37cjpjF1waEfFweh9Kteh2emsxpbM/YG6zxo8ZGr7btGrvTMt5oWaK0u//0PNGlI0 KyOg3qD5F3kRmWl6AwAA X-CMS-MailID: 20230522104648epcas5p2286a988d89b1befdb49984ebbefb25fd X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230522104648epcas5p2286a988d89b1befdb49984ebbefb25fd References: <20230522104146.2856-1-nj.shetty@samsung.com> X-Rspamd-Queue-Id: 2F76380014 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ix5fk1seshbzenhbbk3qeq1mnerefns4 X-HE-Tag: 1684753853-701708 X-HE-Meta: U2FsdGVkX1+fw/7GBQL7qWw99x7EbAiOgEfOAVV+ufPKrboW1DAMakpBedMFjO//z2twUV7NvvCqfPak7lMeCgk4EILOwSMGJybMsbsTMFBBDdThIeJ032grbYKvjXRnBJJpM5LLEHj6H3NZQTNbvJdb41I7pt0YXlk+4vuTWcdJ/yS4kMkWqOwYBtIBx2cJmJEiKLwk6BwKr6rlUodqZkC7BpochE8C5JRkOWBpfQeK81FZN57/QUL2fU7ZmkMKoboe3H3mBKKDN221XbjoNlpLjJPJckj72thgxiqajTgIv49MWgSU8Z8l3GTodqxPO+zXDRNEL4SDu+T7TZgF6eU000qpZMPbGm12mV0dnIwc8scQkeVjZVFIHmYH2lStgjEdutJIaTEU6U5ZbPg1MFcabkeHwkXZOq+xnBvQsCRvFNK/rC60T4qVPw+xN5Fppc6urv5s+WFDtFdT6yYMXtjG7EfG4j6NAJQIZPRzBOnN3oXKAchV0d7lTXPMn4uBUPamjdDUTyndose4PugogYbmyxIg+vbCmVBFVLCkgrF51RiDuKGLVsQWw+LWDfQCLM+UFYQjMB8GHstOvn87pl/Fyg5sWIMez9UexlX7GMLP5IUxxqaWiKEskssvsLm5EU0s4L1rLiuBjIk1WSNZIJ8HW/UqErJwstW2XnNcIizIPbi/eoz1QG3AHDuqpA89ZQGcvGE8RYi6tflYyySW28Lw8UCxrzUPQNUZI3JPUUk2uQiUVutt29hw5oI/P70f4LySSU3ON/jGPFiXJZ/pH0yEMKx9Xg+HW9vmzFLRmCy3+MaKHuLJyP4mz1iMqez0HPiAD6oDu7ICScmi8XXYJjhqVQKM/yqLnwyMXQsmTuLBprKNO556GF64Km1L8uIsC9Y+v2K5j5EUX+BcWoQmA9/kvrbZYu1ODfXDMM3ATSgEadQHerjwSzuqQKCLlb5YLcGpg3kiBukaRIBm/eV INbCju7D aqCDiSMQvjPqGcBSElKNFYIK93uA/kuYckPMIpA0Y1s1lvBWIuhDE6qfXhp4o3WfxU3z+o8LnnPNHIblr7fTNIAYyJsEeXpgwKe+7 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 | 41 +++++++++++++++++++++++++++++++++++ drivers/md/dm.c | 7 ++++++ include/linux/device-mapper.h | 5 +++++ 3 files changed, 53 insertions(+) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 1398f1d6e83e..b3269271e761 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1867,6 +1867,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) { @@ -1949,6 +1982,14 @@ 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); + 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 3b694ba3a106..ab9069090a7d 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1720,6 +1720,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 a52d2b9a6846..04016bd76e73 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -398,6 +398,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);