From patchwork Thu Oct 19 11:01:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 155486 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp334346vqb; Thu, 19 Oct 2023 05:08:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1yE6tIXhpvkQOckcUBdKDz51k/FSa3CDZTvxe6YN1A1TwH+b4eR8zQhiARXLhoRvv48zM X-Received: by 2002:a05:6358:515c:b0:166:94b8:da17 with SMTP id 28-20020a056358515c00b0016694b8da17mr1778184rwj.16.1697717283468; Thu, 19 Oct 2023 05:08:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697717283; cv=none; d=google.com; s=arc-20160816; b=T7LCJxGjwoAlfFj8AyBuGr3MOh9hK3qS4nn9kCS8YdoFcTBRwMc3f3Uj6CJDIGkzlS kMJW6j0rZznMnZnJ+r+CBQJS9vvG1YV6Ch8Wr61Pw0SCkQLK9Z262b14Fo01qhM96FC5 8j9EcUoIm76FQ8Q+oA3WJAE6zY3is2xs76kUiA4eitflJR8Qofin6o4mdWZXK1my6/TT ZFARhn8izJOpKgo9d0Mi4M5Hts6YOyCMmx4+JuvCBl75rgX1jFIGp0BoWCqyaT8mXVrP 1LDNQa6ylCHHMxjuPfVtZont3rLt8cr/DsbohqF1EYJljg2nPIDHbCqOJBYS/Pod7SF9 R1pg== 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=zohq6qFcyNQPlL9CW1gp72Nbdr99RwoaaLJ8/DxbinM=; fh=W5LPimNbUMehQJgmHg0+5GaEuznZ6A1AIkAsYqVdg3Q=; b=BL7LuG1EinPCsVxas2Gw2p3P05IvxGhnWr/I/Y9BInDifz0O27esQOR5UiqfcduCKE lC79kCua+r9cwQTwhyor5LGTovA00piTCCoOOkDaxRFTFOjtG9Af5mlbuKBBapz26iaS 4CaNy/dP7lzORSJJ9Ddlpx1ty2MEl+04gtjbs1W3W2++0JZPYlquDyxCuAjwjILqPT+/ vM6852m13RvSx/ULSC4GQcbwJRmerB4jTLYr3Q3UekaGEMaxEm4EFVlpv1y3kReDcHP8 QRES6gPcpQ+WUkHPi6Cam6TcQbeefgylYlR7/OYYCWLe1gsHwFUG0ya7JxA7UIW2x9vr L2Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=JDl4vw1L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id m16-20020a63fd50000000b005ab2613a571si4441091pgj.495.2023.10.19.05.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:08:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=JDl4vw1L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 347D08191641; Thu, 19 Oct 2023 05:08:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345695AbjJSMHq (ORCPT + 25 others); Thu, 19 Oct 2023 08:07:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345681AbjJSMG6 (ORCPT ); Thu, 19 Oct 2023 08:06:58 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFBD319AF for ; Thu, 19 Oct 2023 05:04:57 -0700 (PDT) Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20231019120422epoutp01b9ef3ac8931557518e3806ca65d34f0c~PgKxZViSn2690526905epoutp01X for ; Thu, 19 Oct 2023 12:04:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20231019120422epoutp01b9ef3ac8931557518e3806ca65d34f0c~PgKxZViSn2690526905epoutp01X DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1697717062; bh=zohq6qFcyNQPlL9CW1gp72Nbdr99RwoaaLJ8/DxbinM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JDl4vw1LaT2LyinfulQYW6csi/HhxvNaCruB4fMxU2JB9Sp2yqzg4uwWbwmmz3FOl 0Po/tS0qLhKvFyq/RjO7iraHxyGCobJbG4YWXzHmD+6bwNTtb1KGF8zjdKH/TFDL/0 Bs0Q/ifOnlEV5WeKSJfHbEp3Vi2B1Gpbp8DvzixM= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20231019120421epcas5p2ca9ad98c31f6d0eb8fdfe0d602c01635~PgKw7Ku2B1623216232epcas5p2p; Thu, 19 Oct 2023 12:04:21 +0000 (GMT) Received: from epsmgec5p1new.samsung.com (unknown [182.195.38.178]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4SB5x04FSzz4x9Py; Thu, 19 Oct 2023 12:04:20 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmgec5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id FF.73.08567.44B11356; Thu, 19 Oct 2023 21:04:20 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20231019110945epcas5p3760e2ce59477ab804b05248a54f107c9~PfbFu3DLz0645906459epcas5p3z; Thu, 19 Oct 2023 11:09:45 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231019110945epsmtrp2f0b61f4e94ea6e37abaf3e68083fd493~PfbFt7v-Q1629616296epsmtrp2s; Thu, 19 Oct 2023 11:09:45 +0000 (GMT) X-AuditID: b6c32a44-617fd70000002177-54-65311b44fb8c Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id E9.17.18939.97E01356; Thu, 19 Oct 2023 20:09:45 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231019110941epsmtip1fbaf6e8874504f8fef365afa997ee3ce~PfbCS2Oja2755327553epsmtip1i; Thu, 19 Oct 2023 11:09:41 +0000 (GMT) From: Nitesh Shetty To: Jens Axboe , Jonathan Corbet , Alasdair Kergon , Mike Snitzer , 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 v17 09/12] dm: Add support for copy offload Date: Thu, 19 Oct 2023 16:31:37 +0530 Message-Id: <20231019110147.31672-10-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231019110147.31672-1-nj.shetty@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Ta0xTZxj2O+dwaEkgBwr6AZs2ZyEbMKAdUL+qbIsSPBv9wXQ/trmMdfSs rUBb2yJsiQGHwAbj4pA4CgoTNxTRTkBSLIymchlsQAiTmxZdAMdtMOSyS4Wttej897zP9zzv 7cvLwX1y3QM4SpWe1aqkKTTpQTTfCg4Oiw0UsoJmUyAy9nbhaHnNTqArtmISzd96CNCUJQ+g 6gvnCDRmacHQ5SudGPrKOgzQ9G0DhtrGQ9E3uRcJ1NrWQ6Chm5Ukqvpu2h0VjJhIVNu9iaHR kmmATFMnAWq2V+Ho2vwSgX4cD0QDG91ur+9gWgw2d2Zg4jrBDPWlMQ11X5BM48VMZqaxHDDm sSySqSkqdWMKsxdJZnl6nGCWfrhNMkVNdYBZadjJNEz9jiV4vZe8T8FKZayWz6qS1DKlSh5D xx9OPJAYLRIIw4RitJvmq6SpbAwdK0kIi1OmOOan+celKWkOKkGq09ERr+7TqtP0LF+h1ulj aFYjS9FEacJ10lRdmkoermL1e4QCwSvRDuGHyYrP+xdxTYd/Rv3kIJ4FHvjmAw4HUlFw7jqd Dzw4PpQZwNU+M+YKHgK4NtFOPg2GO3rxJ46r9c/lA66DbwHwjx6eS5ODwa6ODcKpIalQ+NO/ HCfvS+XgsP3uAnAGODWGwb72Zszp5lF7YY29ws2JCSoIzpavk07s6eDryrq3ikXA4nveTprr oL8vuIC7JN6wp3yKcGKc2gWzb1TgzvyQquDC+skF0uWNhRPW3U4NpHhwrrvJ3YUD4MpiG+nC 6fDymUuky3sKQMOIAbgeXoM5vcWPe8CpYGi8GeGin4dlvdcwV10vWGifwly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jSLSxgLbH492xWEJtFQFXi5cxvYBt4 geKrph5nhrhCX6L/viBImBMovKF7EdhiIQEriQcLHrNDlAtKnJz5hAXEZhaQl2jeOpt5AqPA LCSpWUhSCxiZVjGKphYU56bnJhcY6hUn5haX5qXrJefnbmIEx69W0A7GZev/6h1iZOJgPMQo wcGsJMKr6mGQKsSbklhZlVqUH19UmpNafIhRmoNFSZxXOaczRUggPbEkNTs1tSC1CCbLxMEp 1cA0IeS2M/dbgwuNn6xZF6wyehPxxWLf7ZdnlE8/fa99OLSzalGIw63n03R52qMlIs6JMiz9 8X3HpYXf0qQ1OF5pXmU8rPGu4Jnnpc27FLM2+oqtfbxsyu+XAoc8fVXuzbVuKOI7bv6Yt+r9 hRs1lv7l6895OL46utpuPY+zysEC3RJRnycTpoR3ykdrvdtrfuNapc7uovAA2ayjbN5tX9ZK 52lyuM63ubH2ZOjnqsMJVWGJvmxXtrd1mx2fq5McMTm6/9MW079yaz7fW/pdYekNTd0Y/dgW 9gkzJqpeXKJpKz/FINPiiLDUVJ6/H09OuXu251NT2u+aqAd79k/ua/54ZpWxYMa0RS4rVxSt DJ01RYmlOCPRUIu5qDgRACRDesFOAwAA X-CMS-MailID: 20231019110945epcas5p3760e2ce59477ab804b05248a54f107c9 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231019110945epcas5p3760e2ce59477ab804b05248a54f107c9 References: <20231019110147.31672-1-nj.shetty@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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:08:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780185598346093406 X-GMAIL-MSGID: 1780185598346093406 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 37b48f63ae6a..8803c351624c 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1878,6 +1878,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) { @@ -1960,6 +1992,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 64a1f306c96c..eca336487d44 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1714,6 +1714,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 69d0435c7ebb..98db52d1c773 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -396,6 +396,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);