From patchwork Fri Dec 22 06:12:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 182565 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp899481dyi; Thu, 21 Dec 2023 23:32:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsHyUxO4bdR66DLZNsX69LTBbjqqffS70d1cj5RNc7kjK440kZqJ3boSZHQvWvRBk5oGHZ X-Received: by 2002:a05:620a:51:b0:77f:7cf5:3739 with SMTP id t17-20020a05620a005100b0077f7cf53739mr2703372qkt.19.1703230354385; Thu, 21 Dec 2023 23:32:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703230354; cv=none; d=google.com; s=arc-20160816; b=hE/q3IRQpR2lXKPg8Etj0yhIDxjfUdf8kpuq+YINAoWXgQujQz0U5er8uyQQkFGex7 bFo0jJDLs6EkF+g+8BDdQ5nWxpIcOdB8/Yx4QCLE+OFjV4oG/WvPPPfRp0SbbCTiwaII vrCfy0aBe5472lzowEmBlAC5yRi+pEy7tW7l1POxjfH38eUVa7KwkgW0EYzA4SlVeVIe EG5HYTDibYCqEN8EZUkpAL4Vy/pR9wI3mqEdfaK/D/xONGFqx3PvbytFhCDiQ2slZQK/ O5iuJr8SeL2p4rSQxEPxgJNL7bHjzsVhWT3VVTw1cANIIJjxNnEslzvSE/NKgDafK4e1 +ZeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=4LYQ4Z8s8Ktq3w5D+hMl2cEBoY0WGnDBr6jEXEQrqz8=; fh=VlGIuj4ltDvQwfJtc25qeqnITB9G68kSSsxINcCgb7s=; b=MJRpAwi1ZFCeUgRJamlT13zADhq4BzWoD24uvbHy84ACjkX68NaR0riABQP75zp9pk /BBFs60SVhiYeygG5b6tniyA+Ot73WOlbzhtuYmlq1KKVmfdARqHLpRszlYUXHChGwhi Omc1NQ0yqncWgrPxdlkH6niH7SZgZXf+sdRy/bxULo3hyNSd/to355R8BObY4hLPlQRc TV/3rsEpRNHWMBTLb/GDsW6ddiP1UUGo2nkXiNYp0rjeeSVkqYypNdjwnG6WbQ003cxt Y+1YYMFZ+CWk4myeiSRrg5s9YwO7fjLjUmw6gAYjeMZ0m/Y1iLbMywjhJbnC9PZpYF/U f1zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=q83dtxB9; spf=pass (google.com: domain of linux-kernel+bounces-9442-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9442-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id dt16-20020a05620a479000b0078120b9897csi2777905qkb.451.2023.12.21.23.32.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:32:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9442-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=q83dtxB9; spf=pass (google.com: domain of linux-kernel+bounces-9442-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9442-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 210241C21277 for ; Fri, 22 Dec 2023 07:32:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F4E515AD7; Fri, 22 Dec 2023 07:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="q83dtxB9" X-Original-To: linux-kernel@vger.kernel.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC35CFC1F for ; Fri, 22 Dec 2023 07:31:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20231222073151epoutp0310d4d6a9021122f8db83dac0c2360581~jFvGvJ0Tf3148331483epoutp03- for ; Fri, 22 Dec 2023 07:31:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20231222073151epoutp0310d4d6a9021122f8db83dac0c2360581~jFvGvJ0Tf3148331483epoutp03- DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1703230311; bh=4LYQ4Z8s8Ktq3w5D+hMl2cEBoY0WGnDBr6jEXEQrqz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q83dtxB9YIyXJRgt801wVaoW+Ss00prinXLjkI7Z1xRirEB/dzzhuVTHiHRw+/qyr UuyrOoeiUG5Yu0bx+T6K4tKrxtK12Tm26ED8zhaEVJ3hOy5S4pXYDdy2kYz/d1L2C2 Mqi6z8Nv1c1fh0brAzcT2PBb5gc6x2wIZ53xHOqU= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20231222073150epcas5p3ad1077464d13a44c29f119619c5633ab~jFvGKb1H-2805628056epcas5p3Z; Fri, 22 Dec 2023 07:31:50 +0000 (GMT) Received: from epsmgec5p1new.samsung.com (unknown [182.195.38.179]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4SxJs03BD7z4x9Q2; Fri, 22 Dec 2023 07:31:48 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmgec5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id C5.34.08567.46B35856; Fri, 22 Dec 2023 16:31:48 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20231222062055epcas5p2f8d3738628d50a52c1b7da80ca6d68fe~jExLWFClN0448404484epcas5p2V; Fri, 22 Dec 2023 06:20:55 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231222062055epsmtrp29f9c2de2937929e82acecb1a65de64b8~jExLVECoj1637116371epsmtrp2W; Fri, 22 Dec 2023 06:20:55 +0000 (GMT) X-AuditID: b6c32a44-617fd70000002177-43-65853b64a85c Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id A9.B8.08817.7CA25856; Fri, 22 Dec 2023 15:20:55 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231222062051epsmtip26ae1566d805a06d00a45a4a05eea4f16~jExHx61j_0362603626epsmtip2F; Fri, 22 Dec 2023 06:20:51 +0000 (GMT) From: Nitesh Shetty 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 , Hannes Reinecke , Kanchan Joshi , Anuj Gupta , 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 v19 01/12] block: Introduce queue limits and sysfs for copy-offload support Date: Fri, 22 Dec 2023 11:42:55 +0530 Message-Id: <20231222061313.12260-2-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231222061313.12260-1-nj.shetty@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Ta1BUZRjuO+dwWFDkgFifq9l2NAy57eqyfIuQTDHOGdNkqH7IDMHGngFa 2N12F9HUxLgoFBcxDRaQ6xQXE4GFWJRkQe6hY4TAjtDEQCo3AxRUBoh1ofz3vM/7vPd5Obh9 viWXEyHXsCq5JJImrYnaZicnV+neBJY/YbRDFZ2tOJp+ukCgb9IXcVQ+mEai8eYZgEYazwKU X5hLoIFGPYZuFGZgqLS8BUMty5Mkymi6B9BorxZDDUZnVJBYTKAbDR0E6qnPIVHej6OW6Nu+ OhL91LaEof70UYDOn+vFUN3IGYBqF/JwdHX8MYHajVvQncU2C98tjF47aMncGaokmJ7uaKaq LIlkqotPMw+rswBzfSCWZIpSL1gwKXFTJDM9aiSYx7/2kkyqrgww1V0nmNmqbUzVyCTmbxso 8w5nJVJWxWPloQpphDzMh/7w4+APgj1EfIGrQIw8aZ5cEsX60H4H/V33R0Su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ulR+iawMAAA== X-CMS-MailID: 20231222062055epcas5p2f8d3738628d50a52c1b7da80ca6d68fe X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231222062055epcas5p2f8d3738628d50a52c1b7da80ca6d68fe References: <20231222061313.12260-1-nj.shetty@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785966471722276540 X-GMAIL-MSGID: 1785966471722276540 Add device limits as sysfs entries, - copy_max_bytes (RW) - copy_max_hw_bytes (RO) Above limits help to split the copy payload in block layer. copy_max_bytes: maximum total length of copy in single payload. copy_max_hw_bytes: Reflects the device supported maximum limit. Reviewed-by: Hannes Reinecke Reviewed-by: Luis Chamberlain Signed-off-by: Nitesh Shetty Signed-off-by: Kanchan Joshi Signed-off-by: Anuj Gupta --- Documentation/ABI/stable/sysfs-block | 23 ++++++++++++++++++ block/blk-settings.c | 24 +++++++++++++++++++ block/blk-sysfs.c | 36 ++++++++++++++++++++++++++++ include/linux/blkdev.h | 13 ++++++++++ 4 files changed, 96 insertions(+) diff --git a/Documentation/ABI/stable/sysfs-block b/Documentation/ABI/stable/sysfs-block index 1fe9a553c37b..96ba701e57da 100644 --- a/Documentation/ABI/stable/sysfs-block +++ b/Documentation/ABI/stable/sysfs-block @@ -155,6 +155,29 @@ Description: last zone of the device which may be smaller. +What: /sys/block//queue/copy_max_bytes +Date: August 2023 +Contact: linux-block@vger.kernel.org +Description: + [RW] This is the maximum number of bytes that the block layer + will allow for a copy request. This is always smaller or + equal to the maximum size allowed by the hardware, indicated by + 'copy_max_hw_bytes'. An attempt to set a value higher than + 'copy_max_hw_bytes' will truncate this to 'copy_max_hw_bytes'. + Writing '0' to this file will disable offloading copies for this + device, instead copy is done via emulation. + + +What: /sys/block//queue/copy_max_hw_bytes +Date: August 2023 +Contact: linux-block@vger.kernel.org +Description: + [RO] This is the maximum number of bytes that the hardware + will allow for single data copy request. + A value of 0 means that the device does not support + copy offload. + + What: /sys/block//queue/crypto/ Date: February 2022 Contact: linux-block@vger.kernel.org diff --git a/block/blk-settings.c b/block/blk-settings.c index 0046b447268f..4441711ac364 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -59,6 +59,8 @@ void blk_set_default_limits(struct queue_limits *lim) lim->zoned = BLK_ZONED_NONE; lim->zone_write_granularity = 0; lim->dma_alignment = 511; + lim->max_copy_hw_sectors = 0; + lim->max_copy_sectors = 0; } /** @@ -82,6 +84,8 @@ void blk_set_stacking_limits(struct queue_limits *lim) lim->max_dev_sectors = UINT_MAX; lim->max_write_zeroes_sectors = UINT_MAX; lim->max_zone_append_sectors = UINT_MAX; + lim->max_copy_hw_sectors = UINT_MAX; + lim->max_copy_sectors = UINT_MAX; } EXPORT_SYMBOL(blk_set_stacking_limits); @@ -183,6 +187,22 @@ void blk_queue_max_discard_sectors(struct request_queue *q, } EXPORT_SYMBOL(blk_queue_max_discard_sectors); +/* + * blk_queue_max_copy_hw_sectors - set max sectors for a single copy payload + * @q: the request queue for the device + * @max_copy_sectors: maximum number of sectors to copy + */ +void blk_queue_max_copy_hw_sectors(struct request_queue *q, + unsigned int max_copy_sectors) +{ + if (max_copy_sectors > (BLK_COPY_MAX_BYTES >> SECTOR_SHIFT)) + max_copy_sectors = BLK_COPY_MAX_BYTES >> SECTOR_SHIFT; + + q->limits.max_copy_hw_sectors = max_copy_sectors; + q->limits.max_copy_sectors = max_copy_sectors; +} +EXPORT_SYMBOL_GPL(blk_queue_max_copy_hw_sectors); + /** * blk_queue_max_secure_erase_sectors - set max sectors for a secure erase * @q: the request queue for the device @@ -578,6 +598,10 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, t->max_segment_size = min_not_zero(t->max_segment_size, b->max_segment_size); + t->max_copy_sectors = min(t->max_copy_sectors, b->max_copy_sectors); + t->max_copy_hw_sectors = min(t->max_copy_hw_sectors, + b->max_copy_hw_sectors); + t->misaligned |= b->misaligned; alignment = queue_limit_alignment_offset(b, start); diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 0b2d04766324..7193a1f015f9 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -199,6 +199,37 @@ static ssize_t queue_discard_zeroes_data_show(struct request_queue *q, char *pag return queue_var_show(0, page); } +static ssize_t queue_copy_hw_max_show(struct request_queue *q, char *page) +{ + return sprintf(page, "%llu\n", (unsigned long long) + q->limits.max_copy_hw_sectors << SECTOR_SHIFT); +} + +static ssize_t queue_copy_max_show(struct request_queue *q, char *page) +{ + return sprintf(page, "%llu\n", (unsigned long long) + q->limits.max_copy_sectors << SECTOR_SHIFT); +} + +static ssize_t queue_copy_max_store(struct request_queue *q, const char *page, + size_t count) +{ + unsigned long max_copy; + ssize_t ret = queue_var_store(&max_copy, page, count); + + if (ret < 0) + return ret; + + if (max_copy & (queue_logical_block_size(q) - 1)) + return -EINVAL; + + max_copy >>= SECTOR_SHIFT; + q->limits.max_copy_sectors = min_t(unsigned int, max_copy, + q->limits.max_copy_hw_sectors); + + return count; +} + static ssize_t queue_write_same_max_show(struct request_queue *q, char *page) { return queue_var_show(0, page); @@ -517,6 +548,9 @@ QUEUE_RO_ENTRY(queue_nr_zones, "nr_zones"); QUEUE_RO_ENTRY(queue_max_open_zones, "max_open_zones"); QUEUE_RO_ENTRY(queue_max_active_zones, "max_active_zones"); +QUEUE_RO_ENTRY(queue_copy_hw_max, "copy_max_hw_bytes"); +QUEUE_RW_ENTRY(queue_copy_max, "copy_max_bytes"); + QUEUE_RW_ENTRY(queue_nomerges, "nomerges"); QUEUE_RW_ENTRY(queue_rq_affinity, "rq_affinity"); QUEUE_RW_ENTRY(queue_poll, "io_poll"); @@ -634,6 +668,8 @@ static struct attribute *queue_attrs[] = { &queue_discard_max_entry.attr, &queue_discard_max_hw_entry.attr, &queue_discard_zeroes_data_entry.attr, + &queue_copy_hw_max_entry.attr, + &queue_copy_max_entry.attr, &queue_write_same_max_entry.attr, &queue_write_zeroes_max_entry.attr, &queue_zone_append_max_entry.attr, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 51fa7ffdee83..d5019967a908 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -309,6 +309,9 @@ struct queue_limits { unsigned int discard_alignment; unsigned int zone_write_granularity; + unsigned int max_copy_hw_sectors; + unsigned int max_copy_sectors; + unsigned short max_segments; unsigned short max_integrity_segments; unsigned short max_discard_segments; @@ -893,6 +896,8 @@ extern void blk_queue_chunk_sectors(struct request_queue *, unsigned int); extern void blk_queue_max_segments(struct request_queue *, unsigned short); extern void blk_queue_max_discard_segments(struct request_queue *, unsigned short); +extern void blk_queue_max_copy_hw_sectors(struct request_queue *q, + unsigned int max_copy_sectors); void blk_queue_max_secure_erase_sectors(struct request_queue *q, unsigned int max_sectors); extern void blk_queue_max_segment_size(struct request_queue *, unsigned int); @@ -1211,6 +1216,14 @@ static inline unsigned int bdev_discard_granularity(struct block_device *bdev) return bdev_get_queue(bdev)->limits.discard_granularity; } +/* maximum copy offload length, this is set to 128MB based on current testing */ +#define BLK_COPY_MAX_BYTES (1 << 27) + +static inline unsigned int bdev_max_copy_sectors(struct block_device *bdev) +{ + return bdev_get_queue(bdev)->limits.max_copy_sectors; +} + static inline unsigned int bdev_max_secure_erase_sectors(struct block_device *bdev) { From patchwork Fri Dec 22 06:12:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 182566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp899694dyi; Thu, 21 Dec 2023 23:33:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2fdnMA1ptW4NBedI02jaPxJ4gBcjDpcd5L66ayNC9weN4VHdweqt5IZva4ng5YeX/lKVg X-Received: by 2002:a05:6214:12c9:b0:67f:9341:76c1 with SMTP id s9-20020a05621412c900b0067f934176c1mr836941qvv.118.1703230389046; Thu, 21 Dec 2023 23:33:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703230389; cv=none; d=google.com; s=arc-20160816; b=QLvnWp8EqV/9befaKBom6w4ym4GpBUxo73vNth+M+nV/cmMA6cPO7SqM/25+uZsHnL izeMWmwpkD8OF7j9lNihg/azv13uaXlHGPDc5xlyKV8t224TBFDcLReC80mJaKORoxtF KE/xmwe8jlDZ6lhBriMqvCgl5i7++GzK2mTrzZxdZ4FVVMnkm0nBHpbUDgFO7Gal2N+t AlrFbghAwfJ2Y1Jh+HEngwMNdRdDQG/9L2ab/85dvDn3eN9Q0DOIwO+sAEOaiU6mk7sF Ep3EelquvjpMoFtY+imIa9B6TIv3jjhqXYjVDOV5oCxEwM0RnbbdggvtdKbS76K5/Ck1 IV+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=zNOpXkz6e9K4rFrmmQNgX1f5/CjWsYrydMLP3nTXSzc=; fh=9rDloXW+e2/ZoH88HsM3UklKkST3M4aGZ4dfkAoIOME=; b=1LIvpseimOGIDfbdeUlQn6crmhDQ5GUHi/Hlgao/RXp0/fjkwQu6dGz1qVj7gDU02t 7xKXDPvHos14mMwVelByOXBaAc5Y1WQ6X+tCABtHk53G2GHScBuGgC7DUb0VtCWE4lZu mcSIhMu74YZSpK22Y3gIj/Znpn0gmvgiG2QxsxcRPORx1tx3D+NjGgVCZIfQJhoDeWyw S6xQr4pQOLLnGfYoTRA0o990x1sSK41vtlRlxA52om9JKcIPAXSNT6JiRFtQGANpOE7p CZX0rSXazxWcjpP2xUfB1+e2My7ZBFjuK78RRYeIdlNRvUzIos6/e3+WYzvihBSPUMCF z99A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=phC5LFnU; spf=pass (google.com: domain of linux-kernel+bounces-9443-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9443-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id l12-20020a0ce08c000000b0067f8600c0eesi2717959qvk.366.2023.12.21.23.33.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:33:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9443-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=phC5LFnU; spf=pass (google.com: domain of linux-kernel+bounces-9443-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9443-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C3B0B1C24B52 for ; Fri, 22 Dec 2023 07:33:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B0B1182DF; Fri, 22 Dec 2023 07:32:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="phC5LFnU" X-Original-To: linux-kernel@vger.kernel.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5179171C5 for ; Fri, 22 Dec 2023 07:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20231222073158epoutp039ff5ef93dc26e48a2c4de5e1ad91d168~jFvNCOG7l3148331483epoutp03E for ; Fri, 22 Dec 2023 07:31:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20231222073158epoutp039ff5ef93dc26e48a2c4de5e1ad91d168~jFvNCOG7l3148331483epoutp03E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1703230318; bh=zNOpXkz6e9K4rFrmmQNgX1f5/CjWsYrydMLP3nTXSzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=phC5LFnUhaYBtBLfoaA92T9OVJdUd8/M5ylcTrjUzn620b5adR5b+qTX9qAd72zom /tdo8Ah7uVci5ca9oHben0r41djzySP0+daH/gj8VI5Vv6Tzh++1bdswcFikr1Opcw acaTfpXVDhVq/helfZEWh9dtZR+h2PICUilyFSRI= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20231222073157epcas5p34cf86fc659d43f490607f3bc1d3b26ce~jFvMhFlNH0585105851epcas5p3V; Fri, 22 Dec 2023 07:31:57 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.178]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4SxJs76bj4z4x9Q0; Fri, 22 Dec 2023 07:31:55 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id E5.37.10009.B6B35856; Fri, 22 Dec 2023 16:31:55 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20231222062105epcas5p1c21613f0c44451d579ae4cd24003cca2~jExUqR4Ov1748217482epcas5p19; Fri, 22 Dec 2023 06:21:05 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231222062105epsmtrp23d848ed4420c0c59a8032b1b8568ec1d~jExUpUc2E1647616476epsmtrp2S; Fri, 22 Dec 2023 06:21:05 +0000 (GMT) X-AuditID: b6c32a4a-ff1ff70000002719-e4-65853b6b8346 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 11.93.08755.1DA25856; Fri, 22 Dec 2023 15:21:05 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231222062102epsmtip2e916b9b662132bc0cb3cccba89ce6c13~jExRPlMhy0303903039epsmtip2W; Fri, 22 Dec 2023 06:21:01 +0000 (GMT) From: Nitesh Shetty 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 , Anuj Gupta , 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 v19 02/12] Add infrastructure for copy offload in block and request layer. Date: Fri, 22 Dec 2023 11:42:56 +0530 Message-Id: <20231222061313.12260-3-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231222061313.12260-1-nj.shetty@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01TfVCTdRz39zzPHjYTewSKHxA2V5mIwEawfryJV0aPRScd3VUKBwsegQO2 tReU6gpS4kXkZQLGcIwXzUBkCUSADmlUxHt3wNAlKXebehCKcGJCVFuD8r/P9/v9fL6v92Xj Ticd3NkpYgUjE4vSeORGor3Xa4dPakgOw7dc90e6gZ9wdP/BCoE+L1nF0fmpYhLN9i4AZO7J BaimTkOgaz2dGGo4/yOGVAYjQJYJNYb0Jm9U+8UZAl3W9xNorOs0ibRfWRzQ8ckOEp3r+wtD V0ssAJXmTWCow5wNUPuKFkfNs/cI9LPJA42u9rH2uNGd6ikHevS3iwQ9NqykWxrzSbr1zGf0 ndZKQF+6lkXS9UUnWfSJo3dJ+r7FRND3uidIuqitEdCLLVvpFvMcFrX5QGpoMiNKZGRcRpwg SUwRJ4Xx3oyOezUuUMgX+AiC0Ms8rliUzoTx9kZG+USkpFk3weNmiNKUVleUSC7n+e0OlUmU CoabLJErwniMNDFNGiD1lYvS5Upxkq+YUQQL+Hz/QCsxPjW5v+oXUroccqSifZWVBQb4BYDD hlQArB05BQrARrYTdQnA4dkKB7uxAODvXVmkjeVELQF49frr64oqVR1pJ+kBHLqhZ9mNHAwu nbtjlbPZJOUNB/9m2wQuVBMOOy8KbByc+hODqtsGli3gTMXA/i+XMBsmqBfg0GA1sGFHKhiO Nv9B2PJAyg8W39hic3OoEHh7uZ5lp2yB/ZVmwoZx6ll49Nsq3JYfUjoOLFusJe2d7oULx+pY duwMZ/raHOzYHS7e1a9xDsOGsq9Ju/gYgOpJNbAHwmHOQDFuawKnvKCuy8/u9oTlA82YvfBm eGLFjNn9jrCjeh0/B5t0NWv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MuYR7w/ZPJxODQwVKQ ByiKpMNh1xjF6wF0Mw6/X8rE+AGn83CoG/MK+W1/ej18ZegU8EzQ0+H9rvOAZxEdDbvrvhH8 IUjPgYWv/HjZh46Brh8VgvFC0dDmspDjcT9oK3YQPON0CMy8UoIXAVr/n6X/zyoFmAkEcUq1 PEWuliqladyuCDUrV2vSUiI2K+Rm8PfbYaHNoMn0MaIDYBToAJDCJQEixawsTiySsXsyOJVi k0qTyqk7wFSKkASKAoeOycR0CpvObec4Jaf652KUT7AWa7GHaU+J31ZXmaUtCZPMS+YbWjeL do60DV0LeGRJr83a4ro46fZykz7fc/Nx7FKB99ODRe++HrevTXEHi+Kt4g1PK458iTrjvr67 rHHVSO6v9ndvx06WdykOtcqTwBbTMm1rZM7hR/pQH1cyNb0HhLtDWVVu3+vooKPxLzX1E/cP S6zsknU5GYGF0voZkbEr+z8LCyjo78jtn4LvwxITZsYpU2can+0Q+nUnJtWtWfDcEGesJiUN 8+veLMe2s9mKvfmnDU2KhsH4mgk9iijT0ox12QkbKj0fB1c7NU03z3t6jKOjxaJvMpdqhW7e ypDF+5ObNjreD0ysGq5+4tJZLRJCvZWVhuEqNfsbD7KTz1wDAAA= X-CMS-MailID: 20231222062105epcas5p1c21613f0c44451d579ae4cd24003cca2 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231222062105epcas5p1c21613f0c44451d579ae4cd24003cca2 References: <20231222061313.12260-1-nj.shetty@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785966508429822815 X-GMAIL-MSGID: 1785966508429822815 We add two new opcode REQ_OP_COPY_DST, REQ_OP_COPY_SRC. Since copy is a composite operation involving src and dst sectors/lba, each needs to be represented by a separate bio to make it compatible with device mapper. We expect caller to take a plug and send bio with destination information, followed by bio with source information. Once the dst bio arrives we form a request and wait for source bio. Upon arrival of source bio we merge these two bio's and send corresponding request down to device driver. Merging non copy offload bio is avoided by checking for copy specific opcodes in merge function. Signed-off-by: Nitesh Shetty Signed-off-by: Anuj Gupta --- block/blk-core.c | 7 +++++++ block/blk-merge.c | 41 +++++++++++++++++++++++++++++++++++++++ block/blk.h | 16 +++++++++++++++ block/elevator.h | 1 + include/linux/bio.h | 6 +----- include/linux/blk_types.h | 10 ++++++++++ 6 files changed, 76 insertions(+), 5 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 2eca76ccf4ee..51c6cc3022f4 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -121,6 +121,8 @@ static const char *const blk_op_name[] = { REQ_OP_NAME(ZONE_FINISH), REQ_OP_NAME(ZONE_APPEND), REQ_OP_NAME(WRITE_ZEROES), + REQ_OP_NAME(COPY_SRC), + REQ_OP_NAME(COPY_DST), REQ_OP_NAME(DRV_IN), REQ_OP_NAME(DRV_OUT), }; @@ -800,6 +802,11 @@ void submit_bio_noacct(struct bio *bio) if (!q->limits.max_write_zeroes_sectors) goto not_supported; break; + case REQ_OP_COPY_SRC: + case REQ_OP_COPY_DST: + if (!q->limits.max_copy_sectors) + goto not_supported; + break; default: break; } diff --git a/block/blk-merge.c b/block/blk-merge.c index 65e75efa9bd3..bcb55ba48107 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -158,6 +158,20 @@ static struct bio *bio_split_write_zeroes(struct bio *bio, return bio_split(bio, lim->max_write_zeroes_sectors, GFP_NOIO, bs); } +static struct bio *bio_split_copy(struct bio *bio, + const struct queue_limits *lim, + unsigned int *nsegs) +{ + *nsegs = 1; + if (bio_sectors(bio) <= lim->max_copy_sectors) + return NULL; + /* + * We don't support splitting for a copy bio. End it with EIO if + * splitting is required and return an error pointer. + */ + return ERR_PTR(-EIO); +} + /* * Return the maximum number of sectors from the start of a bio that may be * submitted as a single request to a block device. If enough sectors remain, @@ -366,6 +380,12 @@ struct bio *__bio_split_to_limits(struct bio *bio, case REQ_OP_WRITE_ZEROES: split = bio_split_write_zeroes(bio, lim, nr_segs, bs); break; + case REQ_OP_COPY_SRC: + case REQ_OP_COPY_DST: + split = bio_split_copy(bio, lim, nr_segs); + if (IS_ERR(split)) + return NULL; + break; default: split = bio_split_rw(bio, lim, nr_segs, bs, get_max_io_size(bio, lim) << SECTOR_SHIFT); @@ -922,6 +942,9 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) if (!rq_mergeable(rq) || !bio_mergeable(bio)) return false; + if (blk_copy_offload_mergable(rq, bio)) + return true; + if (req_op(rq) != bio_op(bio)) return false; @@ -951,6 +974,8 @@ enum elv_merge blk_try_merge(struct request *rq, struct bio *bio) { if (blk_discard_mergable(rq)) return ELEVATOR_DISCARD_MERGE; + else if (blk_copy_offload_mergable(rq, bio)) + return ELEVATOR_COPY_OFFLOAD_MERGE; else if (blk_rq_pos(rq) + blk_rq_sectors(rq) == bio->bi_iter.bi_sector) return ELEVATOR_BACK_MERGE; else if (blk_rq_pos(rq) - bio_sectors(bio) == bio->bi_iter.bi_sector) @@ -1053,6 +1078,20 @@ static enum bio_merge_status bio_attempt_discard_merge(struct request_queue *q, return BIO_MERGE_FAILED; } +static enum bio_merge_status bio_attempt_copy_offload_merge(struct request *req, + struct bio *bio) +{ + if (req->__data_len != bio->bi_iter.bi_size) + return BIO_MERGE_FAILED; + + req->biotail->bi_next = bio; + req->biotail = bio; + req->nr_phys_segments++; + req->__data_len += bio->bi_iter.bi_size; + + return BIO_MERGE_OK; +} + static enum bio_merge_status blk_attempt_bio_merge(struct request_queue *q, struct request *rq, struct bio *bio, @@ -1073,6 +1112,8 @@ static enum bio_merge_status blk_attempt_bio_merge(struct request_queue *q, break; case ELEVATOR_DISCARD_MERGE: return bio_attempt_discard_merge(q, rq, bio); + case ELEVATOR_COPY_OFFLOAD_MERGE: + return bio_attempt_copy_offload_merge(rq, bio); default: return BIO_MERGE_NONE; } diff --git a/block/blk.h b/block/blk.h index 08a358bc0919..3d51d7827abb 100644 --- a/block/blk.h +++ b/block/blk.h @@ -159,6 +159,20 @@ static inline bool blk_discard_mergable(struct request *req) return false; } +/* + * Copy offload sends a pair of bio with REQ_OP_COPY_DST and REQ_OP_COPY_SRC + * operation by taking a plug. + * Initially DST bio is sent which forms a request and + * waits for SRC bio to arrive. Once SRC bio arrives + * we merge it and send request down to driver. + */ +static inline bool blk_copy_offload_mergable(struct request *req, + struct bio *bio) +{ + return (req_op(req) == REQ_OP_COPY_DST && + bio_op(bio) == REQ_OP_COPY_SRC); +} + static inline unsigned int blk_rq_get_max_segments(struct request *rq) { if (req_op(rq) == REQ_OP_DISCARD) @@ -300,6 +314,8 @@ static inline bool bio_may_exceed_limits(struct bio *bio, case REQ_OP_DISCARD: case REQ_OP_SECURE_ERASE: case REQ_OP_WRITE_ZEROES: + case REQ_OP_COPY_SRC: + case REQ_OP_COPY_DST: return true; /* non-trivial splitting decisions */ default: break; diff --git a/block/elevator.h b/block/elevator.h index 7ca3d7b6ed82..eec442bbf384 100644 --- a/block/elevator.h +++ b/block/elevator.h @@ -18,6 +18,7 @@ enum elv_merge { ELEVATOR_FRONT_MERGE = 1, ELEVATOR_BACK_MERGE = 2, ELEVATOR_DISCARD_MERGE = 3, + ELEVATOR_COPY_OFFLOAD_MERGE = 4, }; struct blk_mq_alloc_data; diff --git a/include/linux/bio.h b/include/linux/bio.h index 41d417ee1349..ed746738755a 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -53,11 +53,7 @@ static inline unsigned int bio_max_segs(unsigned int nr_segs) */ static inline bool bio_has_data(struct bio *bio) { - if (bio && - bio->bi_iter.bi_size && - bio_op(bio) != REQ_OP_DISCARD && - bio_op(bio) != REQ_OP_SECURE_ERASE && - bio_op(bio) != REQ_OP_WRITE_ZEROES) + if (bio && (bio_op(bio) == REQ_OP_READ || bio_op(bio) == REQ_OP_WRITE)) return true; return false; diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index b29ebd53417d..344dd3740a87 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -395,6 +395,10 @@ enum req_op { /* reset all the zone present on the device */ REQ_OP_ZONE_RESET_ALL = (__force blk_opf_t)17, + /* copy offload src and dst operation */ + REQ_OP_COPY_SRC = (__force blk_opf_t)18, + REQ_OP_COPY_DST = (__force blk_opf_t)19, + /* Driver private requests */ REQ_OP_DRV_IN = (__force blk_opf_t)34, REQ_OP_DRV_OUT = (__force blk_opf_t)35, @@ -483,6 +487,12 @@ static inline bool op_is_write(blk_opf_t op) return !!(op & (__force blk_opf_t)1); } +static inline bool op_is_copy(blk_opf_t op) +{ + return ((op & REQ_OP_MASK) == REQ_OP_COPY_SRC || + (op & REQ_OP_MASK) == REQ_OP_COPY_DST); +} + /* * Check if the bio or request is one that needs special treatment in the * flush state machine. From patchwork Fri Dec 22 06:12:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 182567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp899873dyi; Thu, 21 Dec 2023 23:33:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgl8IMvP9Bbg4WNTkNU6Hi28m/odPsRtzBLVxOsrB6aBjpygX0ongxlS6vk2onnIvAU8Bp X-Received: by 2002:a50:9f88:0:b0:552:34d5:85a1 with SMTP id c8-20020a509f88000000b0055234d585a1mr424443edf.4.1703230416471; Thu, 21 Dec 2023 23:33:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703230416; cv=none; d=google.com; s=arc-20160816; b=hEfN7mtArxGEwahVGXeuMWRygwy9xoGr9LL/Qt6CVZGOxxdb0g2pjqOwmfPGPT2LaR LfwO0eTbQlchnXU3tfm7g27kWbk+ownNRfx31EIFGNjKRVYeIBXNgtk0HHOPuaD/cfpt p8x7e6n4Thewdy3/gJ3GBw9M4cRupspXfimbkcuZOx7KprIgS8LPoVLRRzhwdobWvBCh mbZFG3b/Kmub6ayOHqNoYcQ7OCzQfHynGbVf+WpS6yeE++MoXJLslaRjszD1//O2JOgI mUykspK14p/NZ+oifQIoI5DtCoSemsFMEWYZdBmY55erOtTD3RZ90sOwiP6Kfz//SUsi 1dUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=in2AYpVTNT76lhCvnjMvG4KI3Pxm2pxWCaKDykGs2IQ=; fh=ynswjdvCI3+z3c9qNEmqaETRdNjcpsTGSRuF33qVHus=; b=ctcG1OBNDmoyoFTm0I5NBSJ3CML84VtruF/0AXN34itKGUHThf8E/RA124SatYBtpo PbEV94OKnAjB9WV9KBvrSCqv+Y3jth4iHP2Ugf+Xb6MZD3R4cZ6p/+6duvj+dM/uWuB1 /vKpDCSZkidoB+3lQ7xY3HBZd9U7qRQ4vu+CDCzp+/D7XC4plmaj9rL7nziwhuGLZwa9 3FesjOLvLANM8YsQ0xjwzA3awvICElbcGr37R1cczNracBOz3xeyaua3HXzPcvxRvjLs ksdZbaZRspHLVl8PLI9uminSgctVnMzAcEeGHQSzb1IJLuSXxzbMxka2G7V+NC3Gzn48 kFSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=hHNBJwOC; spf=pass (google.com: domain of linux-kernel+bounces-9444-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9444-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y2-20020a50bb02000000b005535abb0f31si1542430ede.552.2023.12.21.23.33.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:33:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9444-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=hHNBJwOC; spf=pass (google.com: domain of linux-kernel+bounces-9444-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9444-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E4EA71F25ADF for ; Fri, 22 Dec 2023 07:33:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 063F21B271; Fri, 22 Dec 2023 07:32:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="hHNBJwOC" X-Original-To: linux-kernel@vger.kernel.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2E391864D for ; Fri, 22 Dec 2023 07:32:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20231222073203epoutp035f1703d8c86b06aaa82345376dbd2a5c~jFvRw5g262966029660epoutp03H for ; Fri, 22 Dec 2023 07:32:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20231222073203epoutp035f1703d8c86b06aaa82345376dbd2a5c~jFvRw5g262966029660epoutp03H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1703230323; bh=in2AYpVTNT76lhCvnjMvG4KI3Pxm2pxWCaKDykGs2IQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hHNBJwOCVuRDfHAagqT9Z+x9WW0s/NAstiErN3maDCSWCPPRSz7umM5rC0x9Q9XLr +taDxjQO2p5WLWjHkm9UymzFsclp/wajTfoITBCLpZZWMENq6l2u956fSqz3hDpfsK dr8k/QBVQnI74VF53gAhrKnlsS5ziyPulGaTVbhQ= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20231222073202epcas5p208adfa9360db1984ca7359d690abbe15~jFvQzndsb1857018570epcas5p2M; Fri, 22 Dec 2023 07:32:02 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.182]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4SxJsD1KdBz4x9Pr; Fri, 22 Dec 2023 07:32:00 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 17.90.09672.F6B35856; Fri, 22 Dec 2023 16:31:59 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20231222062116epcas5p2ff54b405039a65f107b2a570b113c501~jExeRsijg0448404484epcas5p2K; Fri, 22 Dec 2023 06:21:16 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231222062116epsmtrp12c1cdf9606a1bb1630bcab4b6c5d24e0~jExeQkTWF1607116071epsmtrp1n; Fri, 22 Dec 2023 06:21:16 +0000 (GMT) X-AuditID: b6c32a4b-60bfd700000025c8-69-65853b6f38e2 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id F1.C8.08817.BDA25856; Fri, 22 Dec 2023 15:21:15 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231222062112epsmtip24391c108c8dd8663d9345d5960bcf949~jExawUa6O0303903039epsmtip2a; Fri, 22 Dec 2023 06:21:12 +0000 (GMT) From: Nitesh Shetty 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 , Hannes Reinecke , Anuj Gupta , 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 v19 03/12] block: add copy offload support Date: Fri, 22 Dec 2023 11:42:57 +0530 Message-Id: <20231222061313.12260-4-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231222061313.12260-1-nj.shetty@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Te0xTVxzHc+5tLwUtXgqGQ1HsurgNEGilwOEp85WbsSxsi/9gGDb0hkKh bdoyx8YmiIBjQUBgw4I8hCgvYVDGeD9KGApzMhGZTISxoisvhziMMuZaC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IyF+A5O3ff5HKvT38/OOCV34OLK6K/5Gy6WOjv7Ht3lxf7EqPFImzTj1/Rvi6aduW3z cuXVXi1nvnNnZB0su4OvyVxdfPKJ38GvkgeW//jHt5F9kdNTj3Uxpl5+5jUrgmZ+WmCXPtP4 la/E/4tXtqi2ray+Xbvr2dZ04XsLdln7PNetMTAQ4fzcJvu4jf2aQcZX5yMxjubNvx6U7+a2 2eX4b5Pop1+FlzYFnfdunZDLc1vgQfusO5e/5z2ZeYN9ZdenRYYGpmXH58Rv3KJSwMt0VDY8 6FO/iOeOuflXPv90nj1JzD8kUDHhyCXfjUosxRmJhlrMRcWJAO1ue45jAwAA X-CMS-MailID: 20231222062116epcas5p2ff54b405039a65f107b2a570b113c501 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231222062116epcas5p2ff54b405039a65f107b2a570b113c501 References: <20231222061313.12260-1-nj.shetty@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785966537435598719 X-GMAIL-MSGID: 1785966537435598719 Introduce blkdev_copy_offload to perform copy offload. Issue REQ_OP_COPY_DST with destination info along with taking a plug. This flows till request layer and waits for src bio to arrive. Issue REQ_OP_COPY_SRC with source info and this bio reaches request layer and merges with dst request. For any reason, if a request comes to the driver with only one of src/dst bio, we fail the copy offload. Larger copy will be divided, based on max_copy_sectors limit. Reviewed-by: Hannes Reinecke Signed-off-by: Anuj Gupta Signed-off-by: Nitesh Shetty --- block/blk-lib.c | 204 +++++++++++++++++++++++++++++++++++++++++ include/linux/blkdev.h | 4 + 2 files changed, 208 insertions(+) diff --git a/block/blk-lib.c b/block/blk-lib.c index e59c3069e835..f03cb4bc3134 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -10,6 +10,22 @@ #include "blk.h" +/* Keeps track of all outstanding copy IO */ +struct blkdev_copy_io { + atomic_t refcount; + ssize_t copied; + int status; + struct task_struct *waiter; + void (*endio)(void *private, int status, ssize_t copied); + void *private; +}; + +/* Keeps track of single outstanding copy offload IO */ +struct blkdev_copy_offload_io { + struct blkdev_copy_io *cio; + loff_t offset; +}; + static sector_t bio_discard_limit(struct block_device *bdev, sector_t sector) { unsigned int discard_granularity = bdev_discard_granularity(bdev); @@ -115,6 +131,194 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, } EXPORT_SYMBOL(blkdev_issue_discard); +static inline ssize_t blkdev_copy_sanity_check(struct block_device *bdev_in, + loff_t pos_in, + struct block_device *bdev_out, + loff_t pos_out, size_t len) +{ + unsigned int align = max(bdev_logical_block_size(bdev_out), + bdev_logical_block_size(bdev_in)) - 1; + + if ((pos_in & align) || (pos_out & align) || (len & align) || !len || + len >= BLK_COPY_MAX_BYTES) + return -EINVAL; + + return 0; +} + +static inline void blkdev_copy_endio(struct blkdev_copy_io *cio) +{ + if (cio->endio) { + cio->endio(cio->private, cio->status, cio->copied); + kfree(cio); + } else { + struct task_struct *waiter = cio->waiter; + + WRITE_ONCE(cio->waiter, NULL); + blk_wake_io_task(waiter); + } +} + +/* + * This must only be called once all bios have been issued so that the refcount + * can only decrease. This just waits for all bios to complete. + * Returns the length of bytes copied or error + */ +static ssize_t blkdev_copy_wait_for_completion_io(struct blkdev_copy_io *cio) +{ + ssize_t ret; + + for (;;) { + __set_current_state(TASK_UNINTERRUPTIBLE); + if (!READ_ONCE(cio->waiter)) + break; + blk_io_schedule(); + } + __set_current_state(TASK_RUNNING); + ret = cio->copied; + kfree(cio); + + return ret; +} + +static void blkdev_copy_offload_src_endio(struct bio *bio) +{ + struct blkdev_copy_offload_io *offload_io = bio->bi_private; + struct blkdev_copy_io *cio = offload_io->cio; + + if (bio->bi_status) { + cio->copied = min_t(ssize_t, offload_io->offset, cio->copied); + if (!cio->status) + cio->status = blk_status_to_errno(bio->bi_status); + } + bio_put(bio); + kfree(offload_io); + + if (atomic_dec_and_test(&cio->refcount)) + blkdev_copy_endio(cio); +} + +/* + * @bdev: block device + * @pos_in: source offset + * @pos_out: destination offset + * @len: length in bytes to be copied + * @endio: endio function to be called on completion of copy operation, + * for synchronous operation this should be NULL + * @private: endio function will be called with this private data, + * for synchronous operation this should be NULL + * @gfp_mask: memory allocation flags (for bio_alloc) + * + * For synchronous operation returns the length of bytes copied or error + * For asynchronous operation returns -EIOCBQUEUED or error + * + * Description: + * Copy source offset to destination offset within block device, using + * device's native copy offload feature. + * We perform copy operation using 2 bio's. + * 1. We take a plug and send a REQ_OP_COPY_DST bio along with destination + * sector and length. Once this bio reaches request layer, we form a + * request and wait for dst bio to arrive. + * 2. We issue REQ_OP_COPY_SRC bio along with source sector, length. + * Once this bio reaches request layer and find a request with previously + * sent destination info we merge the source bio and return. + * 3. Release the plug and request is sent to driver + * This design works only for drivers with request queue. + */ +ssize_t blkdev_copy_offload(struct block_device *bdev, loff_t pos_in, + loff_t pos_out, size_t len, + void (*endio)(void *, int, ssize_t), + void *private, gfp_t gfp) +{ + struct blkdev_copy_io *cio; + struct blkdev_copy_offload_io *offload_io; + struct bio *src_bio, *dst_bio; + size_t rem, chunk; + size_t max_copy_bytes = bdev_max_copy_sectors(bdev) << SECTOR_SHIFT; + ssize_t ret; + struct blk_plug plug; + + if (!max_copy_bytes) + return -EOPNOTSUPP; + + ret = blkdev_copy_sanity_check(bdev, pos_in, bdev, pos_out, len); + if (ret) + return ret; + + cio = kzalloc(sizeof(*cio), gfp); + if (!cio) + return -ENOMEM; + atomic_set(&cio->refcount, 1); + cio->waiter = current; + cio->endio = endio; + cio->private = private; + + /* + * If there is a error, copied will be set to least successfully + * completed copied length + */ + cio->copied = len; + for (rem = len; rem > 0; rem -= chunk) { + chunk = min(rem, max_copy_bytes); + + offload_io = kzalloc(sizeof(*offload_io), gfp); + if (!offload_io) + goto err_free_cio; + offload_io->cio = cio; + /* + * For partial completion, we use offload_io->offset to truncate + * successful copy length + */ + offload_io->offset = len - rem; + + dst_bio = bio_alloc(bdev, 0, REQ_OP_COPY_DST, gfp); + if (!dst_bio) + goto err_free_offload_io; + dst_bio->bi_iter.bi_size = chunk; + dst_bio->bi_iter.bi_sector = pos_out >> SECTOR_SHIFT; + + blk_start_plug(&plug); + src_bio = blk_next_bio(dst_bio, bdev, 0, REQ_OP_COPY_SRC, gfp); + if (!src_bio) + goto err_free_dst_bio; + src_bio->bi_iter.bi_size = chunk; + src_bio->bi_iter.bi_sector = pos_in >> SECTOR_SHIFT; + src_bio->bi_end_io = blkdev_copy_offload_src_endio; + src_bio->bi_private = offload_io; + + atomic_inc(&cio->refcount); + submit_bio(src_bio); + blk_finish_plug(&plug); + pos_in += chunk; + pos_out += chunk; + } + + if (atomic_dec_and_test(&cio->refcount)) + blkdev_copy_endio(cio); + if (endio) + return -EIOCBQUEUED; + + return blkdev_copy_wait_for_completion_io(cio); + +err_free_dst_bio: + bio_put(dst_bio); +err_free_offload_io: + kfree(offload_io); +err_free_cio: + cio->copied = min_t(ssize_t, cio->copied, (len - rem)); + cio->status = -ENOMEM; + if (rem == len) { + ret = cio->status; + kfree(cio); + return ret; + } + if (cio->endio) + return cio->status; + + return blkdev_copy_wait_for_completion_io(cio); +} +EXPORT_SYMBOL_GPL(blkdev_copy_offload); + static int __blkdev_issue_write_zeroes(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, unsigned flags) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index d5019967a908..cd940de16750 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1042,6 +1042,10 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop); int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp); +ssize_t blkdev_copy_offload(struct block_device *bdev, loff_t pos_in, + loff_t pos_out, size_t len, + void (*endio)(void *, int, ssize_t), + void *private, gfp_t gfp_mask); #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */ #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */ From patchwork Fri Dec 22 06:12:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 182568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp900009dyi; Thu, 21 Dec 2023 23:34:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUFDjigXNyKkVekWO2PiIdVs88cbyGQteURYF9sg5/1BK9GVS828JEcdJyhFKteeV9L7Cg X-Received: by 2002:a17:902:e5c8:b0:1d4:1642:e482 with SMTP id u8-20020a170902e5c800b001d41642e482mr1163580plf.11.1703230440773; Thu, 21 Dec 2023 23:34:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703230440; cv=none; d=google.com; s=arc-20160816; b=hRZpQHv7kxcXpMjFak0fN9Zc6XZKkwLF8xQHRwJOYTFybljRZ7bJHT0bqx3tDV85uY 4EmdV45t4BOPHHw/Aej7CIr8znBy3t8fjVP4twMTih4I4K1wG3pDHLOgI6kiLe8fBwbV rNrkG6yMy+aukjwU4GqlDScRd3rSalCkvBV0ga92wZwhCFZK9wK+LkWVMn51eUWVZ8sr QaDS7w604I7QKD78wpl4UZudUgluGACuZwQBXfVIUbCl6MMIXyhxzyxLb5zv+WKHlRks WxbUuJpZy8h8GInqpgMrxMELAD3JTdoIpqaJKLYkoP8kVaswsKLcyfd2N6SB1Q1f0ya4 dPqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=9frU+oN9cW84tUmQ8PszwC/fCsF2sdAWZkWnbtQtafI=; fh=jhjQ+Y7R1HQ5qz8BK5oypmWhn4JSLYPdhpE+5fpivNY=; b=Yn26YCcUb6FFd16blQXkYPTONQrxKuCtONR3nKHIu17xdJD5Tor/CJhG7wRhAFHUbE caLT0OcaTf5pszrQCEon2OoYymTPWIGR1xU/tS+imiEeYKNzgjQ+svQvNYWvt8eiSOv3 6O81tTAmlujhZd1J7GthA1sX0eY6iUIkCZT2laW7DKt/8MUXkm4NPljf+YHtM+eVYA88 B5tMJvLMe1s7oji+wNrt8pnK9kGcLJHTu6ZnnXMeDrwTiiyy/Fg7g4tM0MGRxUNklV5m hHcjC3wQzfHkwxIqzNdAnnYyQ69iOvJm248cMCdBuswEdE10/evKBi2GmTkJuPC05pBV b7Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=MBG6W+jJ; spf=pass (google.com: domain of linux-kernel+bounces-9445-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9445-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k10-20020a170902c40a00b001d3f1b7685esi2877454plk.547.2023.12.21.23.34.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:34:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9445-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=MBG6W+jJ; spf=pass (google.com: domain of linux-kernel+bounces-9445-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9445-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 84CE6288592 for ; Fri, 22 Dec 2023 07:34:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45FC61F951; Fri, 22 Dec 2023 07:32:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="MBG6W+jJ" X-Original-To: linux-kernel@vger.kernel.org Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49E551CAA9 for ; Fri, 22 Dec 2023 07:32:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20231222073210epoutp019aaa77096a3e000e2c86e248f52474f3~jFvYwhf2H3090430904epoutp01A for ; Fri, 22 Dec 2023 07:32:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20231222073210epoutp019aaa77096a3e000e2c86e248f52474f3~jFvYwhf2H3090430904epoutp01A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1703230330; bh=9frU+oN9cW84tUmQ8PszwC/fCsF2sdAWZkWnbtQtafI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MBG6W+jJ6LXb2iwYngYt7WcqC/DsvTBvk2L1UI78B7u8NPXmC+f+gTDa/bK0P/BIC pC6W8eqA12L3T7vCfjCl+LynObzh9uf/iyXCjjYX9PtXoiToD10Mj1T/av/jys8hNz wIB/Vntuws6no3thzjAHjGnyvRYU5Sdlj7CS8QGQ= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20231222073210epcas5p2d828fcd26c2acef7da1ed7d5eaed9d97~jFvYP30bG2130021300epcas5p2M; Fri, 22 Dec 2023 07:32:10 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.174]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4SxJsM5XBzz4x9Q9; Fri, 22 Dec 2023 07:32:07 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 0F.D2.09634.77B35856; Fri, 22 Dec 2023 16:32:07 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20231222062126epcas5p382f390cbedd5351c49adf07121d18448~jExoFy5wl0194201942epcas5p3T; Fri, 22 Dec 2023 06:21:26 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231222062126epsmtrp131e61b114be345c1c8edb06d53480a52~jExoEtGIY1607116071epsmtrp1s; Fri, 22 Dec 2023 06:21:26 +0000 (GMT) X-AuditID: b6c32a49-159fd700000025a2-6d-65853b773aa6 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 8B.DE.18939.6EA25856; Fri, 22 Dec 2023 15:21:26 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231222062122epsmtip234bd0da50619d5d996eaf8c8abad787c~jExkq0fXB0344503445epsmtip2p; Fri, 22 Dec 2023 06:21:22 +0000 (GMT) From: Nitesh Shetty 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 , Vincent Fu , Anuj Gupta , 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 v19 04/12] block: add emulation for copy Date: Fri, 22 Dec 2023 11:42:58 +0530 Message-Id: <20231222061313.12260-5-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231222061313.12260-1-nj.shetty@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01TaVBTVxjtfe/xCMxEn2jbm1QwE0sdF5bYJF5EilbF50QrTqd1pq2lGXiF DNnMAlbaKQgBDbJWbAkiVKgLIluQYSkWgRBFlHYUUGYAWxNKQUuBQasgNiFo/Xe+851zv+XO x8K9fnDnsmRKHaNRSuV80pOoa1u9yi8+2MAEHrOsQpWdHTiamJ4h0OHsZzi6MJBForG2SYBs LWkAFZ8uJNDdlgYMnb9gwVBuay9A9h4Thpr716IfU0sJ9HPzNQLdajxJoqIzdneU3ldPorPW OQzdybYDlHOkB0P1tiSA6maKcFQxNk6gq/1vofvpRwDqfmZ128ylG0wD7nT3YDVB37qhp2vK jpK0ufRbesScD+imu4kkXZL5nRudkfw3SU/Y+wl6/HIPSWfWlgF6qsaHrrE9xMIXfRK7KYaR RjEaHqOMVEXJlNEhfMmHEVsjROJAgZ8gCG3g85RSBRPC37Yr3C9MJnesg8+Lk8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p382f390cbedd5351c49adf07121d18448 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231222062126epcas5p382f390cbedd5351c49adf07121d18448 References: <20231222061313.12260-1-nj.shetty@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785966562847959551 X-GMAIL-MSGID: 1785966562847959551 For the devices which does not support copy, copy emulation is added. It is required for in-kernel users like fabrics, where file descriptor is not available and hence they can't use copy_file_range. Copy-emulation is implemented by reading from source into memory and writing to the corresponding destination. At present in kernel user of emulation is fabrics. Signed-off-by: Nitesh Shetty Signed-off-by: Vincent Fu Signed-off-by: Anuj Gupta --- block/blk-lib.c | 223 +++++++++++++++++++++++++++++++++++++++++ include/linux/blkdev.h | 4 + 2 files changed, 227 insertions(+) diff --git a/block/blk-lib.c b/block/blk-lib.c index f03cb4bc3134..9d5fe177308c 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -26,6 +26,20 @@ struct blkdev_copy_offload_io { loff_t offset; }; +/* Keeps track of single outstanding copy emulation IO */ +struct blkdev_copy_emulation_io { + struct blkdev_copy_io *cio; + struct work_struct emulation_work; + void *buf; + ssize_t buf_len; + loff_t pos_in; + loff_t pos_out; + ssize_t len; + struct block_device *bdev_in; + struct block_device *bdev_out; + gfp_t gfp; +}; + static sector_t bio_discard_limit(struct block_device *bdev, sector_t sector) { unsigned int discard_granularity = bdev_discard_granularity(bdev); @@ -319,6 +333,215 @@ ssize_t blkdev_copy_offload(struct block_device *bdev, loff_t pos_in, } EXPORT_SYMBOL_GPL(blkdev_copy_offload); +static void *blkdev_copy_alloc_buf(ssize_t req_size, ssize_t *alloc_size, + gfp_t gfp) +{ + int min_size = PAGE_SIZE; + char *buf; + + while (req_size >= min_size) { + buf = kvmalloc(req_size, gfp); + if (buf) { + *alloc_size = req_size; + return buf; + } + req_size >>= 1; + } + + return NULL; +} + +static struct bio *bio_map_buf(void *data, unsigned int len, gfp_t gfp) +{ + unsigned long kaddr = (unsigned long)data; + unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT; + unsigned long start = kaddr >> PAGE_SHIFT; + const int nr_pages = end - start; + bool is_vmalloc = is_vmalloc_addr(data); + struct page *page; + int offset, i; + struct bio *bio; + + bio = bio_kmalloc(nr_pages, gfp); + if (!bio) + return ERR_PTR(-ENOMEM); + bio_init(bio, NULL, bio->bi_inline_vecs, nr_pages, 0); + + if (is_vmalloc) { + flush_kernel_vmap_range(data, len); + bio->bi_private = data; + } + + offset = offset_in_page(kaddr); + for (i = 0; i < nr_pages; i++) { + unsigned int bytes = PAGE_SIZE - offset; + + if (len <= 0) + break; + + if (bytes > len) + bytes = len; + + if (!is_vmalloc) + page = virt_to_page(data); + else + page = vmalloc_to_page(data); + if (bio_add_page(bio, page, bytes, offset) < bytes) { + /* we don't support partial mappings */ + bio_uninit(bio); + kfree(bio); + return ERR_PTR(-EINVAL); + } + + data += bytes; + len -= bytes; + offset = 0; + } + + return bio; +} + +static void blkdev_copy_emulation_work(struct work_struct *work) +{ + struct blkdev_copy_emulation_io *emulation_io = container_of(work, + struct blkdev_copy_emulation_io, emulation_work); + struct blkdev_copy_io *cio = emulation_io->cio; + struct bio *read_bio, *write_bio; + loff_t pos_in = emulation_io->pos_in, pos_out = emulation_io->pos_out; + ssize_t rem, chunk; + int ret = 0; + + for (rem = emulation_io->len; rem > 0; rem -= chunk) { + chunk = min_t(int, emulation_io->buf_len, rem); + + read_bio = bio_map_buf(emulation_io->buf, + emulation_io->buf_len, + emulation_io->gfp); + if (IS_ERR(read_bio)) { + ret = PTR_ERR(read_bio); + break; + } + read_bio->bi_opf = REQ_OP_READ | REQ_SYNC; + bio_set_dev(read_bio, emulation_io->bdev_in); + read_bio->bi_iter.bi_sector = pos_in >> SECTOR_SHIFT; + read_bio->bi_iter.bi_size = chunk; + ret = submit_bio_wait(read_bio); + kfree(read_bio); + if (ret) + break; + + write_bio = bio_map_buf(emulation_io->buf, + emulation_io->buf_len, + emulation_io->gfp); + if (IS_ERR(write_bio)) { + ret = PTR_ERR(write_bio); + break; + } + write_bio->bi_opf = REQ_OP_WRITE | REQ_SYNC; + bio_set_dev(write_bio, emulation_io->bdev_out); + write_bio->bi_iter.bi_sector = pos_out >> SECTOR_SHIFT; + write_bio->bi_iter.bi_size = chunk; + ret = submit_bio_wait(write_bio); + kfree(write_bio); + if (ret) + break; + + pos_in += chunk; + pos_out += chunk; + } + cio->status = ret; + kvfree(emulation_io->buf); + kfree(emulation_io); + blkdev_copy_endio(cio); +} + +static inline ssize_t queue_max_hw_bytes(struct request_queue *q) +{ + return min_t(ssize_t, queue_max_hw_sectors(q) << SECTOR_SHIFT, + queue_max_segments(q) << PAGE_SHIFT); +} +/* + * @bdev_in: source block device + * @pos_in: source offset + * @bdev_out: destination block device + * @pos_out: destination offset + * @len: length in bytes to be copied + * @endio: endio function to be called on completion of copy operation, + * for synchronous operation this should be NULL + * @private: endio function will be called with this private data, + * for synchronous operation this should be NULL + * @gfp_mask: memory allocation flags (for bio_alloc) + * + * For synchronous operation returns the length of bytes copied or error + * For asynchronous operation returns -EIOCBQUEUED or error + * + * Description: + * If native copy offload feature is absent, caller can use this function + * to perform copy. + * We store information required to perform the copy along with temporary + * buffer allocation. We async punt copy emulation to a worker. And worker + * performs copy in 2 steps. + * 1. Read data from source to temporary buffer + * 2. Write data to destination from temporary buffer + */ +ssize_t blkdev_copy_emulation(struct block_device *bdev_in, loff_t pos_in, + struct block_device *bdev_out, loff_t pos_out, + size_t len, void (*endio)(void *, int, ssize_t), + void *private, gfp_t gfp) +{ + struct request_queue *in = bdev_get_queue(bdev_in); + struct request_queue *out = bdev_get_queue(bdev_out); + struct blkdev_copy_emulation_io *emulation_io; + struct blkdev_copy_io *cio; + ssize_t ret; + size_t max_hw_bytes = min(queue_max_hw_bytes(in), + queue_max_hw_bytes(out)); + + ret = blkdev_copy_sanity_check(bdev_in, pos_in, bdev_out, pos_out, len); + if (ret) + return ret; + + cio = kzalloc(sizeof(*cio), gfp); + if (!cio) + return -ENOMEM; + + cio->waiter = current; + cio->copied = len; + cio->endio = endio; + cio->private = private; + + emulation_io = kzalloc(sizeof(*emulation_io), gfp); + if (!emulation_io) + goto err_free_cio; + emulation_io->cio = cio; + INIT_WORK(&emulation_io->emulation_work, blkdev_copy_emulation_work); + emulation_io->pos_in = pos_in; + emulation_io->pos_out = pos_out; + emulation_io->len = len; + emulation_io->bdev_in = bdev_in; + emulation_io->bdev_out = bdev_out; + emulation_io->gfp = gfp; + + emulation_io->buf = blkdev_copy_alloc_buf(min(max_hw_bytes, len), + &emulation_io->buf_len, gfp); + if (!emulation_io->buf) + goto err_free_emulation_io; + + schedule_work(&emulation_io->emulation_work); + + if (cio->endio) + return -EIOCBQUEUED; + + return blkdev_copy_wait_for_completion_io(cio); + +err_free_emulation_io: + kfree(emulation_io); +err_free_cio: + kfree(cio); + return -ENOMEM; +} +EXPORT_SYMBOL_GPL(blkdev_copy_emulation); + static int __blkdev_issue_write_zeroes(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, unsigned flags) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index cd940de16750..80867c9fd602 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1046,6 +1046,10 @@ ssize_t blkdev_copy_offload(struct block_device *bdev, loff_t pos_in, loff_t pos_out, size_t len, void (*endio)(void *, int, ssize_t), void *private, gfp_t gfp_mask); +ssize_t blkdev_copy_emulation(struct block_device *bdev_in, loff_t pos_in, + struct block_device *bdev_out, loff_t pos_out, + size_t len, void (*endio)(void *, int, ssize_t), + void *private, gfp_t gfp); #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */ #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */ From patchwork Fri Dec 22 06:12:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 182569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp900156dyi; Thu, 21 Dec 2023 23:34:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFBngXxsxh71Wk8IyoCrDkfyklaee86NNeFnrBxG3zZCUzyuoySRgp0pIOlYTqxNQTXt82 X-Received: by 2002:a17:906:50a:b0:a02:bc2d:e026 with SMTP id j10-20020a170906050a00b00a02bc2de026mr455099eja.46.1703230468108; Thu, 21 Dec 2023 23:34:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703230468; cv=none; d=google.com; s=arc-20160816; b=1KU+wQpOkFhZe6xzrtnj7Dks2P9c5/lJ/XAGey5GnXFW/tB1kO7SHQkTztXnQZJ1su mqduKFjdBPrOlItEPAnQhifff6dQA2F/VxEqW4/gxX14n/9Wel/9SAGkOiIdYLM6dsq7 Y2ODBLzWB2Ysen/dwxvmR/AKFc/nD5RTzOkoTQuVAVgWnEixJYxkI01DGel9xTyXB60X FrMfE/RLvY8Pf3QFTYyWWNm0qc8CX0UVKPeKd2Oy2EXPqd46YEfCpmoZr0xw5LfESyxk TbIpAFQ2efZbUlkLpgG5gtb3QaTVkZqNQz35xuVBXOBCPcX2QNSM67AWD3RzHlEjvHsd yQxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=WyEZwCEcMZEgd+uPDvb2WQHlAKDzDTA2b4v6jEJOw5k=; fh=Ah9URUT0YMcW0AdypunxP2ZkdaXV7jPEsLx7S1j82es=; b=yGhlot2mnAo0q5N2cFawZGYeAPw+xTTel9WDYztDbYRsbPLrAcKYgs17ubtn3/Hf8h IM1biGyCW80Qtxc76V7aL2hzG+0k7xTa6R328Cb/E35eukj2fnGtAMJhaOXZqN3c5SGy 8a5Cxj9cvet2aDtjNQIldxSyGbW02BuiYwk6Qy0ayhybFW55L1ro7KF5Rgog3WxGDzzJ vM4AbNhgj9PH8mQ+92sq3ZiFCLXsny/kUVSqi9CFQmHGKHD8FPwNMlulJPSjufLxn7PT tWOy1AcouwDa9yk8HCJ3kXnIzZaLeVKjvUcM2VLSrE+e3aDv4e4NLG95NREqlcZZ9Po3 chdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=aFFNXEWc; spf=pass (google.com: domain of linux-kernel+bounces-9446-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9446-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l22-20020a170907915600b00a269fa420c0si1461701ejs.555.2023.12.21.23.34.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:34:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9446-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=aFFNXEWc; spf=pass (google.com: domain of linux-kernel+bounces-9446-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9446-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8EB521F26012 for ; Fri, 22 Dec 2023 07:34:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9E03219FA; Fri, 22 Dec 2023 07:32:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="aFFNXEWc" X-Original-To: linux-kernel@vger.kernel.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 849871EB4B for ; Fri, 22 Dec 2023 07:32:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20231222073216epoutp033d321ab0524045635d3d1a678ddcae9d~jFvds3hAD2965229652epoutp039 for ; Fri, 22 Dec 2023 07:32:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20231222073216epoutp033d321ab0524045635d3d1a678ddcae9d~jFvds3hAD2965229652epoutp039 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1703230336; bh=WyEZwCEcMZEgd+uPDvb2WQHlAKDzDTA2b4v6jEJOw5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aFFNXEWcDSD08Jt4soITZ4CqvtFquJiYPLx0JiGHGyIuKL+tH5o9yZKacBbvZ7Xhv PrUqQ07BqhP1aOUJ7RAM0MbQO44oIDoqpipf5559/APFr+SAQWTyYAsfmfsIKF1JcH heaUv64PVHtIzO+3iUTb9CURktKTFXKaXl5vVvvg= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20231222073215epcas5p3d382a2a311619cd6cbaeddbeb22c4db8~jFvdKbJmw0585105851epcas5p31; Fri, 22 Dec 2023 07:32:15 +0000 (GMT) Received: from epsmgec5p1new.samsung.com (unknown [182.195.38.177]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4SxJsT44Cmz4x9Q1; Fri, 22 Dec 2023 07:32:13 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmgec5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 9A.54.08567.D7B35856; Fri, 22 Dec 2023 16:32:13 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20231222062136epcas5p18f39a4dea2e66c56c652f29c0dc85a15~jExxKy2F72292622926epcas5p1C; Fri, 22 Dec 2023 06:21:36 +0000 (GMT) Received: from epsmgmc1p1new.samsung.com (unknown [182.195.42.40]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231222062136epsmtrp2e00b9a0c775dac9476ac12096c995dc0~jExxJ2QAp1637116371epsmtrp2K; Fri, 22 Dec 2023 06:21:36 +0000 (GMT) X-AuditID: b6c32a44-3abff70000002177-7e-65853b7d75e0 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmc1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 20.3D.07368.0FA25856; Fri, 22 Dec 2023 15:21:36 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231222062132epsmtip2ec4c90b353e75c0a4e1c894584ccc4c5~jExtyQ-Ok0362303623epsmtip2U; Fri, 22 Dec 2023 06:21:32 +0000 (GMT) From: Nitesh Shetty 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, Anuj Gupta , Hannes Reinecke , 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 v19 05/12] fs/read_write: Enable copy_file_range for block device. Date: Fri, 22 Dec 2023 11:42:59 +0530 Message-Id: <20231222061313.12260-6-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231222061313.12260-1-nj.shetty@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Te1BUZRTvu3f3smALFyT7XIZiNmkQXGCL3T5UhFG0O8VMBGiN0wzcYa/A ALvbPjJsQhCQR8oCYhNL8hKpBUaUl8tjzUDeKRnyLEpHIHINB8ggGZdYLpT//c7vnN/vfOd8 c3i4U7GNgBcn1zAqOZ0gJOw4zZ07PUWf78lgfOtWBKiuvxtH809WOOhU3jMc1UzqCGTuXABo 6kYmQGUVFzho/EYLhtorCjBkqOnCUEHHCEDTw3oMmSa8UPnpSg5qN/Vx0FDr1wQqrZq2QV+M Ggn0TY8FQ2N50wDlZw1jyDiVClDzSimOLpsfc1DvhAsafNbDDRJQLfpJG2rw16scauiWlqqv ziaohsqT1GxDEaDaxlMI6mLuOS51Nm2OoOanJzjU4+vDBJXbWA2ohoHPqMX6V6j6qT+xUIej 8XtjGVrGqNwYebRCFiePCRC+Gx55IFIi9RWLxP7oLaGbnE5kAoTBIaGiQ3EJaysRun1CJ2jX qFBarRb67NurUmg1jFusQq0JEDJKWY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-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231222062136epcas5p18f39a4dea2e66c56c652f29c0dc85a15 References: <20231222061313.12260-1-nj.shetty@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785966591212928808 X-GMAIL-MSGID: 1785966591212928808 From: Anuj Gupta This is a prep patch. Allow copy_file_range to work for block devices. Relaxing generic_copy_file_checks allows us to reuse the existing infra, instead of adding a new user interface for block copy offload. Change generic_copy_file_checks to use ->f_mapping->host for both inode_in and inode_out. Allow block device in generic_file_rw_checks. Reviewed-by: Hannes Reinecke Signed-off-by: Anuj Gupta Signed-off-by: Nitesh Shetty --- fs/read_write.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 4771701c896b..f0f52bf48f57 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1405,8 +1405,8 @@ static int generic_copy_file_checks(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, size_t *req_count, unsigned int flags) { - struct inode *inode_in = file_inode(file_in); - struct inode *inode_out = file_inode(file_out); + struct inode *inode_in = file_in->f_mapping->host; + struct inode *inode_out = file_out->f_mapping->host; uint64_t count = *req_count; loff_t size_in; int ret; @@ -1708,7 +1708,9 @@ int generic_file_rw_checks(struct file *file_in, struct file *file_out) /* Don't copy dirs, pipes, sockets... */ if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode)) return -EISDIR; - if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) + if (!S_ISREG(inode_in->i_mode) && !S_ISBLK(inode_in->i_mode)) + return -EINVAL; + if ((inode_in->i_mode & S_IFMT) != (inode_out->i_mode & S_IFMT)) return -EINVAL; if (!(file_in->f_mode & FMODE_READ) || From patchwork Fri Dec 22 06:13:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 182571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp900432dyi; Thu, 21 Dec 2023 23:35:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHr72DK+Yl1dI9f7me5ijxo2P2/MyqfQnPd3Ig1I1mJtb7wHIVAhHzCakwL2if5Z/BkaFE X-Received: by 2002:a05:6a20:1602:b0:195:3bfc:b303 with SMTP id l2-20020a056a20160200b001953bfcb303mr173139pzj.30.1703230516869; Thu, 21 Dec 2023 23:35:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703230516; cv=none; d=google.com; s=arc-20160816; b=AgjkDzfQ9E5kITbu25eeGLt/UdhSZ3GK5prcB7sxp4N2IAiKLi6U/vIuh1bMyKsdMx uO1hArTpguy2hPRMgR4gEeQOuXDmjpL4AKto2UwnOVMtvLJeJhP5pa+wlTkJVY9ERMs5 kOLdagzxABmEEVQS9+bhcZ/bhK7fW1hA0oZqI51om8Hc+ArTy+q4VQYlmP0x5DW/EvN5 z/lDoNJIHnVT6gEOZrSl3FLlSAC6eCe9NnTrjNKW3q0WNmuQOIFVkN/jNpKYvvfi/mw3 69XgtceXl5B9Y59Ho4a2TTe8NVIy3NfPwSgIXh/iHIoKycyOYROeJbQunDGhRJlno9xT I2jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=5DXoDTvrI2mWMm1I9eg06D4Nr/8IY38fu2o2A+1efIw=; fh=ynswjdvCI3+z3c9qNEmqaETRdNjcpsTGSRuF33qVHus=; b=gUYGHVvQNRM0dYH/FDmJsHT8DEI1TErxUpyiPC926JFDsWoXRtouiczUHWUXuCB7Pp N4YXCMdJuLCqdweKEUWwOvkFPi9YSNMsJ+Z5Q7B7PDHvvMK9+FTd4LoPnQQFEYILCgA8 8vlVpKjHtC5bDhjE1cBFatngaZsARYSsuQxtovTuJiHpBEl+n5Cj8EUXObH+KYQ0szcR AyoPAnv2oryRipuf1UTgK0ceuTy22I0pIctMI+pM7/BvTxMnkYHH7UVSwvXRNXKUKZ9x kh7UGRjOcOMrXELEYHgZ1Csuh/DHm29Zb6+9uzS08+jlw26ETl1i98H08Wbiw7aDCP21 w5Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=dKhqRgVS; spf=pass (google.com: domain of linux-kernel+bounces-9448-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9448-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s5-20020a056a0008c500b006d98bdbc167si465537pfu.178.2023.12.21.23.35.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:35:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9448-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=dKhqRgVS; spf=pass (google.com: domain of linux-kernel+bounces-9448-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9448-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 32FFC28631D for ; Fri, 22 Dec 2023 07:35:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACCECFC1F; Fri, 22 Dec 2023 07:32:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="dKhqRgVS" X-Original-To: linux-kernel@vger.kernel.org Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96C4FC8CB for ; Fri, 22 Dec 2023 07:32:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20231222073234epoutp0203edd5cc7dd769004c8732be00c9fd91~jFvudWr-I1950219502epoutp02k for ; Fri, 22 Dec 2023 07:32:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20231222073234epoutp0203edd5cc7dd769004c8732be00c9fd91~jFvudWr-I1950219502epoutp02k DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1703230354; bh=5DXoDTvrI2mWMm1I9eg06D4Nr/8IY38fu2o2A+1efIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dKhqRgVSXcXQyiilTsaCkVy5pRIDAvEC7ErrwQ8xpx1l/xEBHZSgeYNCrucPei9Zo JqGj21zakV4ygG3C30OG52w6UAxMH5o4BsoakpX3f0WARVihgP7yK2q8JknhLTyrmw OYXbGZ8LkWaOxWMummLjDLgppUD0MrivG1m2VSCI= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20231222073233epcas5p2c6275650c592fa37f2a425f2acec9f3e~jFvt4zDsg2130021300epcas5p2q; Fri, 22 Dec 2023 07:32:33 +0000 (GMT) Received: from epsmgec5p1-new.samsung.com (unknown [182.195.38.181]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4SxJsq3yRfz4x9Q1; Fri, 22 Dec 2023 07:32:31 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmgec5p1-new.samsung.com (Symantec Messaging Gateway) with SMTP id 4F.A9.19369.F8B35856; Fri, 22 Dec 2023 16:32:31 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20231222062147epcas5p4353805c045bac87c459f488d0f5b8c86~jEx7MZwT80435204352epcas5p4J; Fri, 22 Dec 2023 06:21:47 +0000 (GMT) Received: from epsmgmc1p1new.samsung.com (unknown [182.195.42.40]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231222062147epsmtrp219873d3dc5f8da5a57edb2fc5bba60ce~jEx7KnPV21637116371epsmtrp2Q; Fri, 22 Dec 2023 06:21:47 +0000 (GMT) X-AuditID: b6c32a50-c99ff70000004ba9-12-65853b8f7f92 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmc1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 85.3D.07368.AFA25856; Fri, 22 Dec 2023 15:21:46 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231222062143epsmtip29f2629f9af58673581da4b45db15f459~jEx3wdbaS0362603626epsmtip2P; Fri, 22 Dec 2023 06:21:43 +0000 (GMT) From: Nitesh Shetty 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 , Hannes Reinecke , Anuj Gupta , 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 v19 06/12] fs, block: copy_file_range for def_blk_ops for direct block device Date: Fri, 22 Dec 2023 11:43:00 +0530 Message-Id: <20231222061313.12260-7-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231222061313.12260-1-nj.shetty@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Te1BUZRSf797L3bvmyuXh+LFMhhsMgcGyudCHCORozm1sAsfpHyiXHbg8 WvbR7pJoU0GwukosC0rlFg+BInk/xAFcxCB5GQkxrEARTbNgEygKLkwQGstC+d/v/M75fef8 zjeHwl2LOHwqRaFl1QppqoDcRlzr9vMPyAvTsUElfXxUP9CDo0e2VQJ9alzDUfVkHolmuxcA st48C1BpWRGBxm+2YchcVoChK9W3MFTQZQFoetSEoY6JvejymQoCmTv6CTTS/jWJSr6d5qCc u60kqux9gqEx4zRA+fpRDLVaMwG6tlqCo7rZeQL1TXiiO2u9Tq/xmTbTJIe581sjwYwMpjFN VedIprniE+bP5kuAuT6eQTLlhgtOTG7WA5J5ND1BMPM3RknGcLUKMM23P2QWm3YzTdb7WLRz jOxAMitNYNVerCJemZCiSAoXHD0uOSQJDgkSBYhC0asCL4VUzoYLDr8ZHXAkJXV9JQKvD6Sp aetUtFSjEQgjDqiVa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g-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231222062147epcas5p4353805c045bac87c459f488d0f5b8c86 References: <20231222061313.12260-1-nj.shetty@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785966642800656289 X-GMAIL-MSGID: 1785966642800656289 For direct block device opened with O_DIRECT, use copy_file_range to issue device copy offload, or use generic_copy_file_range in case device copy offload capability is absent or the device files are not open with O_DIRECT. Reviewed-by: Hannes Reinecke Signed-off-by: Anuj Gupta Signed-off-by: Nitesh Shetty --- block/fops.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/block/fops.c b/block/fops.c index 0abaac705daf..6ca46ea1f358 100644 --- a/block/fops.c +++ b/block/fops.c @@ -747,6 +747,30 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } +static ssize_t blkdev_copy_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t len, unsigned int flags) +{ + struct block_device *in_bdev = I_BDEV(bdev_file_inode(file_in)); + struct block_device *out_bdev = I_BDEV(bdev_file_inode(file_out)); + ssize_t copied = 0; + + if ((in_bdev == out_bdev) && bdev_max_copy_sectors(in_bdev) && + (file_in->f_iocb_flags & IOCB_DIRECT) && + (file_out->f_iocb_flags & IOCB_DIRECT)) { + copied = blkdev_copy_offload(in_bdev, pos_in, pos_out, len, + NULL, NULL, GFP_KERNEL); + if (copied < 0) + copied = 0; + } else { + copied = generic_copy_file_range(file_in, pos_in + copied, + file_out, pos_out + copied, + len - copied, flags); + } + + return copied; +} + #define BLKDEV_FALLOC_FL_SUPPORTED \ (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \ FALLOC_FL_ZERO_RANGE | FALLOC_FL_NO_HIDE_STALE) @@ -851,6 +875,7 @@ const struct file_operations def_blk_fops = { .splice_read = filemap_splice_read, .splice_write = iter_file_splice_write, .fallocate = blkdev_fallocate, + .copy_file_range = blkdev_copy_file_range, }; static __init int blkdev_init(void) From patchwork Fri Dec 22 06:13:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 182572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp900526dyi; Thu, 21 Dec 2023 23:35:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEFwfg8JDynCRhvj+V00LMl6AdDt4jkQMZD2u4cWQqz9b1dANDpUsJZ1tWpTBZ5MJOK57qK X-Received: by 2002:a50:cd84:0:b0:553:88f2:e948 with SMTP id p4-20020a50cd84000000b0055388f2e948mr469942edi.51.1703230540766; Thu, 21 Dec 2023 23:35:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703230540; cv=none; d=google.com; s=arc-20160816; b=BdtNQ2uTktAlXeXTG2nBzkuDx5oA69JtOxJmwdBWAzOjFTomfahhkcclZEvfltTTZ2 ZKkkbVLtDg1uYV99xOrFsKdBjYPNGPUUhOX5p6V7H01xdtggYWyrmwtUCfEHJZRrcAyo 7zVnFDiOPcNbjm7ahDEHlGm9NEo46iN0QXOHDcTi0QcR/7m4lGKM6xADIVqoL/tU8MWZ KCuHmvMyjX76YDGb77z/snb/xWmgtHGI/FojnAjbqOzwhjlOYdpd3jgzAHprESVQ6/65 cNxI/xfvpJwFgdwYkrVnUAy2CV7WeYpaIjuK9lhAHobav4vLpJF0dnNQbenyE4e0drqp envQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=p/9yh3tUv4Curw5H7Y3DMkbb1qxhGWe31pfXNHDD36M=; fh=NEWly8etNTvj/pAqVABs5PoBrnzj0dY1QJJ2dhcEJtk=; b=QjSI7gcZEaXRdFIk8KG815Ii47UdyChnK7R2aRKntNLk9MSMCRiTE4voS7h5q1MwF/ bvlHP4HrR1yOm3ZfxEy0+nSAQNDt6SeMBt7pbIfylBwuOTAk2tnsYQ630RsmE+kqarsM SlLh2HRnmP3n1emxRHRrv2R0bvSYI6Q0TniZavvaJpvVyWMVFCZzhuf43te3bDBpZ+N2 yk/0aYZ8Qp7oX+TqpdW/F2Z19tRiabkQEMM939hv36Je/FgP/BhMcWqxm9FYPTgPyWHQ f46R3wwvef7iVnzq7QGKZyIQRXefFaDHJiM7MutA4Z7vu6Ltgf/mG6dSaOggcUU08lis Znsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=HQdnt7LE; spf=pass (google.com: domain of linux-kernel+bounces-9449-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9449-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id co12-20020a0564020c0c00b0055461881bb7si114648edb.676.2023.12.21.23.35.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:35:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9449-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=HQdnt7LE; spf=pass (google.com: domain of linux-kernel+bounces-9449-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9449-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3A1A51F26132 for ; Fri, 22 Dec 2023 07:35:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C67F315AE4; Fri, 22 Dec 2023 07:32:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="HQdnt7LE" X-Original-To: linux-kernel@vger.kernel.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C7BADF59 for ; Fri, 22 Dec 2023 07:32:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20231222073236epoutp03d16ba8ee0fffcd5b023ab0c78f37c8a6~jFvxDHImJ2965029650epoutp03L for ; Fri, 22 Dec 2023 07:32:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20231222073236epoutp03d16ba8ee0fffcd5b023ab0c78f37c8a6~jFvxDHImJ2965029650epoutp03L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1703230356; bh=p/9yh3tUv4Curw5H7Y3DMkbb1qxhGWe31pfXNHDD36M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HQdnt7LExveo9gWi23t+Xe5XS+IlQxTZ+0nVye9NYm32s2ajX3fTa2m17YiEX9OOs crcsUz5U3MaFCqy4lWL+CpOGotPPSE9qDZ3kwNDKeAH1jRHiYbNrMyq0HHMDG22Q4K xDt+pJvJhlhzDFOmv/8ReXsqH+nzWd4h1r+dpHJE= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20231222073235epcas5p29cfc218b2f42d06223c8e55091a2b289~jFvvzs2Qz2132821328epcas5p2w; Fri, 22 Dec 2023 07:32:35 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.176]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4SxJst1H3Zz4x9Px; Fri, 22 Dec 2023 07:32:34 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 6E.47.10009.19B35856; Fri, 22 Dec 2023 16:32:34 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20231222062157epcas5p35537549a1610815931e43618e045f3ff~jEyE_mD8h0194101941epcas5p3I; Fri, 22 Dec 2023 06:21:57 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231222062157epsmtrp106db83d3fe8e2b7e66b731d8cdac586c~jEyE9HsE41657416574epsmtrp1C; Fri, 22 Dec 2023 06:21:57 +0000 (GMT) X-AuditID: b6c32a4a-ff1ff70000002719-3e-65853b91625e Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 0B.C8.08817.50B25856; Fri, 22 Dec 2023 15:21:57 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231222062153epsmtip2458d39b115507ab8971489f478b6b9ab~jEyBP8YTh0362603626epsmtip2S; Fri, 22 Dec 2023 06:21:53 +0000 (GMT) From: Nitesh Shetty 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 , Hannes Reinecke , Kanchan Joshi , =?utf-8?q?Javier_Gonz=C3=A1lez?= , Anuj Gupta , 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 v19 07/12] nvme: add copy offload support Date: Fri, 22 Dec 2023 11:43:01 +0530 Message-Id: <20231222061313.12260-8-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231222061313.12260-1-nj.shetty@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Ta1ATVxTu3d1sAjW6RqsXRGViW6oIJBrojQh1xNZtYRg6Hdsp0ykNZAUE kjQPseIUkIcahrcohKIIaUVAUaCUp5WXUaBSyxAaKiA1VBGpAlVnQKSEQOu/75zvfPd859w5 HJz3PdueEy5TM0qZJJJP2hI1rZudXLI8kxjBT+MYqui4jqOJpzMEOpoxi6OygXQSjbVOAmS+ dgygwqICApmu1WGosSgLQxfK2jF0784UG7XPjZMoq8UI0EivDkNN/c7oXLKeQI1NNwnUU/8d ic7+MMJGKX21JDpveImh3zNGAMo83ouhWnM8QDUzZ3F0aewxgW70r0PdswbWLge6TjfAprsH rxB0zy8aurL0BElX6WPpB1V5gG4wxZF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Z5o0v+pw4re/ndwqmcQR+6sT0zqtNuTskQLpwXukVktJR2hUsiGGVr YdcCaa2KqXB0UBd74o83OTK3a/Kj1mr8kkPXOMKLNleF5PB/fe8gtknalva1yn48k9L2HBVP iih1nDRITKrU0v8B4p9TkYUDAAA= X-CMS-MailID: 20231222062157epcas5p35537549a1610815931e43618e045f3ff X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231222062157epcas5p35537549a1610815931e43618e045f3ff References: <20231222061313.12260-1-nj.shetty@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785966667048815977 X-GMAIL-MSGID: 1785966667048815977 Current design only supports single source range. We receive a request with REQ_OP_COPY_DST. Parse this request which consists of dst(1st) and src(2nd) bios. Form a copy command (TP 4065) trace event support for nvme_copy_cmd. Set the device copy limits to queue limits. Reviewed-by: Hannes Reinecke Signed-off-by: Kanchan Joshi Signed-off-by: Nitesh Shetty Signed-off-by: Javier González Signed-off-by: Anuj Gupta --- drivers/nvme/host/constants.c | 1 + drivers/nvme/host/core.c | 79 +++++++++++++++++++++++++++++++++++ drivers/nvme/host/trace.c | 19 +++++++++ include/linux/blkdev.h | 1 + include/linux/nvme.h | 43 +++++++++++++++++-- 5 files changed, 140 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/constants.c b/drivers/nvme/host/constants.c index 20f46c230885..2f504a2b1fe8 100644 --- a/drivers/nvme/host/constants.c +++ b/drivers/nvme/host/constants.c @@ -19,6 +19,7 @@ static const char * const nvme_ops[] = { [nvme_cmd_resv_report] = "Reservation Report", [nvme_cmd_resv_acquire] = "Reservation Acquire", [nvme_cmd_resv_release] = "Reservation Release", + [nvme_cmd_copy] = "Copy Offload", [nvme_cmd_zone_mgmt_send] = "Zone Management Send", [nvme_cmd_zone_mgmt_recv] = "Zone Management Receive", [nvme_cmd_zone_append] = "Zone Append", diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 8ebdfd623e0f..c398546e4edc 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -765,6 +765,63 @@ static inline void nvme_setup_flush(struct nvme_ns *ns, cmnd->common.nsid = cpu_to_le32(ns->head->ns_id); } +static inline blk_status_t nvme_setup_copy_offload(struct nvme_ns *ns, + struct request *req, + struct nvme_command *cmnd) +{ + struct nvme_copy_range *range = NULL; + struct bio *bio; + u64 dst_lba = 0, src_lba = 0, n_lba = 0; + u16 nr_range = 1, control = 0, seg = 1; + + if (blk_rq_nr_phys_segments(req) != BLK_COPY_MAX_SEGMENTS) + return BLK_STS_IOERR; + + /* + * First bio contains information about destination and last bio + * contains information about source. + */ + __rq_for_each_bio(bio, req) { + if (seg == blk_rq_nr_phys_segments(req)) { + src_lba = nvme_sect_to_lba(ns, bio->bi_iter.bi_sector); + if (n_lba != bio->bi_iter.bi_size >> ns->lba_shift) + return BLK_STS_IOERR; + } else { + dst_lba = nvme_sect_to_lba(ns, bio->bi_iter.bi_sector); + n_lba = bio->bi_iter.bi_size >> ns->lba_shift; + } + seg++; + } + + if (req->cmd_flags & REQ_FUA) + control |= NVME_RW_FUA; + + if (req->cmd_flags & REQ_FAILFAST_DEV) + control |= NVME_RW_LR; + + memset(cmnd, 0, sizeof(*cmnd)); + cmnd->copy.opcode = nvme_cmd_copy; + cmnd->copy.nsid = cpu_to_le32(ns->head->ns_id); + cmnd->copy.control = cpu_to_le16(control); + cmnd->copy.sdlba = cpu_to_le64(dst_lba); + cmnd->copy.nr_range = 0; + + range = kmalloc_array(nr_range, sizeof(*range), + GFP_ATOMIC | __GFP_NOWARN); + if (!range) + return BLK_STS_RESOURCE; + + range[0].slba = cpu_to_le64(src_lba); + range[0].nlb = cpu_to_le16(n_lba - 1); + + req->special_vec.bv_page = virt_to_page(range); + req->special_vec.bv_offset = offset_in_page(range); + req->special_vec.bv_len = sizeof(*range) * nr_range; + req->rq_flags |= RQF_SPECIAL_PAYLOAD; + + return BLK_STS_OK; +} + static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req, struct nvme_command *cmnd) { @@ -1007,6 +1064,11 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req) case REQ_OP_ZONE_APPEND: ret = nvme_setup_rw(ns, req, cmd, nvme_cmd_zone_append); break; + case REQ_OP_COPY_DST: + ret = nvme_setup_copy_offload(ns, req, cmd); + break; + case REQ_OP_COPY_SRC: + return BLK_STS_IOERR; default: WARN_ON_ONCE(1); return BLK_STS_IOERR; @@ -1758,6 +1820,21 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns) blk_queue_max_write_zeroes_sectors(queue, UINT_MAX); } +static void nvme_config_copy(struct gendisk *disk, struct nvme_ns *ns, + struct nvme_id_ns *id) +{ + struct nvme_ctrl *ctrl = ns->ctrl; + struct request_queue *q = disk->queue; + + if (!(ctrl->oncs & NVME_CTRL_ONCS_COPY)) { + blk_queue_max_copy_hw_sectors(q, 0); + return; + } + + blk_queue_max_copy_hw_sectors(q, nvme_lba_to_sect(ns, + le16_to_cpu(id->mssrl))); +} + static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b) { return uuid_equal(&a->uuid, &b->uuid) && @@ -1961,6 +2038,7 @@ static void nvme_update_disk_info(struct gendisk *disk, set_capacity_and_notify(disk, capacity); nvme_config_discard(disk, ns); + nvme_config_copy(disk, ns, id); blk_queue_max_write_zeroes_sectors(disk->queue, ns->ctrl->max_zeroes_sectors); } @@ -4708,6 +4786,7 @@ static inline void _nvme_check_size(void) BUILD_BUG_ON(sizeof(struct nvme_download_firmware) != 64); BUILD_BUG_ON(sizeof(struct nvme_format_cmd) != 64); BUILD_BUG_ON(sizeof(struct nvme_dsm_cmd) != 64); + BUILD_BUG_ON(sizeof(struct nvme_copy_command) != 64); BUILD_BUG_ON(sizeof(struct nvme_write_zeroes_cmd) != 64); BUILD_BUG_ON(sizeof(struct nvme_abort_cmd) != 64); BUILD_BUG_ON(sizeof(struct nvme_get_log_page_command) != 64); diff --git a/drivers/nvme/host/trace.c b/drivers/nvme/host/trace.c index 1c36fcedea20..82c6aef77c31 100644 --- a/drivers/nvme/host/trace.c +++ b/drivers/nvme/host/trace.c @@ -150,6 +150,23 @@ static const char *nvme_trace_read_write(struct trace_seq *p, u8 *cdw10) return ret; } +static const char *nvme_trace_copy(struct trace_seq *p, u8 *cdw10) +{ + const char *ret = trace_seq_buffer_ptr(p); + u64 sdlba = get_unaligned_le64(cdw10); + u8 nr_range = get_unaligned_le16(cdw10 + 8); + u16 control = get_unaligned_le16(cdw10 + 10); + u32 dsmgmt = get_unaligned_le32(cdw10 + 12); + u32 reftag = get_unaligned_le32(cdw10 + 16); + + trace_seq_printf(p, + "sdlba=%llu, nr_range=%u, ctrl=0x%x, dsmgmt=%u, reftag=%u", + sdlba, nr_range, control, dsmgmt, reftag); + trace_seq_putc(p, 0); + + return ret; +} + static const char *nvme_trace_dsm(struct trace_seq *p, u8 *cdw10) { const char *ret = trace_seq_buffer_ptr(p); @@ -243,6 +260,8 @@ const char *nvme_trace_parse_nvm_cmd(struct trace_seq *p, return nvme_trace_zone_mgmt_send(p, cdw10); case nvme_cmd_zone_mgmt_recv: return nvme_trace_zone_mgmt_recv(p, cdw10); + case nvme_cmd_copy: + return nvme_trace_copy(p, cdw10); default: return nvme_trace_common(p, cdw10); } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 80867c9fd602..24016fbcd409 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1226,6 +1226,7 @@ static inline unsigned int bdev_discard_granularity(struct block_device *bdev) /* maximum copy offload length, this is set to 128MB based on current testing */ #define BLK_COPY_MAX_BYTES (1 << 27) +#define BLK_COPY_MAX_SEGMENTS 2 static inline unsigned int bdev_max_copy_sectors(struct block_device *bdev) { diff --git a/include/linux/nvme.h b/include/linux/nvme.h index 44325c068b6a..4afd2cd1a629 100644 --- a/include/linux/nvme.h +++ b/include/linux/nvme.h @@ -344,7 +344,7 @@ struct nvme_id_ctrl { __u8 nvscc; __u8 nwpc; __le16 acwu; - __u8 rsvd534[2]; + __le16 ocfs; __le32 sgls; __le32 mnan; __u8 rsvd544[224]; @@ -372,6 +372,7 @@ enum { NVME_CTRL_ONCS_WRITE_ZEROES = 1 << 3, NVME_CTRL_ONCS_RESERVATIONS = 1 << 5, NVME_CTRL_ONCS_TIMESTAMP = 1 << 6, + NVME_CTRL_ONCS_COPY = 1 << 8, NVME_CTRL_VWC_PRESENT = 1 << 0, NVME_CTRL_OACS_SEC_SUPP = 1 << 0, NVME_CTRL_OACS_NS_MNGT_SUPP = 1 << 3, @@ -421,7 +422,10 @@ struct nvme_id_ns { __le16 npdg; __le16 npda; __le16 nows; - __u8 rsvd74[18]; + __le16 mssrl; + __le32 mcl; + __u8 msrc; + __u8 rsvd91[11]; __le32 anagrpid; __u8 rsvd96[3]; __u8 nsattr; @@ -838,6 +842,7 @@ enum nvme_opcode { nvme_cmd_resv_report = 0x0e, nvme_cmd_resv_acquire = 0x11, nvme_cmd_resv_release = 0x15, + nvme_cmd_copy = 0x19, nvme_cmd_zone_mgmt_send = 0x79, nvme_cmd_zone_mgmt_recv = 0x7a, nvme_cmd_zone_append = 0x7d, @@ -861,7 +866,8 @@ enum nvme_opcode { nvme_opcode_name(nvme_cmd_resv_release), \ nvme_opcode_name(nvme_cmd_zone_mgmt_send), \ nvme_opcode_name(nvme_cmd_zone_mgmt_recv), \ - nvme_opcode_name(nvme_cmd_zone_append)) + nvme_opcode_name(nvme_cmd_zone_append), \ + nvme_opcode_name(nvme_cmd_copy)) @@ -1038,6 +1044,36 @@ struct nvme_dsm_range { __le64 slba; }; +struct nvme_copy_command { + __u8 opcode; + __u8 flags; + __u16 command_id; + __le32 nsid; + __u64 rsvd2; + __le64 metadata; + union nvme_data_ptr dptr; + __le64 sdlba; + __u8 nr_range; + __u8 rsvd12; + __le16 control; + __le16 rsvd13; + __le16 dspec; + __le32 ilbrt; + __le16 lbat; + __le16 lbatm; +}; + +struct nvme_copy_range { + __le64 rsvd0; + __le64 slba; + __le16 nlb; + __le16 rsvd18; + __le32 rsvd20; + __le32 eilbrt; + __le16 elbat; + __le16 elbatm; +}; + struct nvme_write_zeroes_cmd { __u8 opcode; __u8 flags; @@ -1802,6 +1838,7 @@ struct nvme_command { struct nvme_download_firmware dlfw; struct nvme_format_cmd format; struct nvme_dsm_cmd dsm; + struct nvme_copy_command copy; struct nvme_write_zeroes_cmd write_zeroes; struct nvme_zone_mgmt_send_cmd zms; struct nvme_zone_mgmt_recv_cmd zmr; From patchwork Fri Dec 22 06:13:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 182573 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp900677dyi; Thu, 21 Dec 2023 23:36:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5f/qJ1a8VcOIwFvMRNLjexg5BXuwdgfVDbEPQQmHxKDwSN0hFoAWdkrqSqI77qiyIlHfL X-Received: by 2002:a05:6a00:198e:b0:6ce:2731:47b4 with SMTP id d14-20020a056a00198e00b006ce273147b4mr1280645pfl.20.1703230571293; Thu, 21 Dec 2023 23:36:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703230571; cv=none; d=google.com; s=arc-20160816; b=uJIUqP0hteh+5CYRx6qP2dw25o85fy9Xs6KLpUHvLRQJhutbntDGfkaWQc43eXh3hJ 2o+QZAN7+ichabRJ80GA9Kvjq7LRCUJGZYR0855UilquheGdprAYRXC+KS1McyGFm9t0 Ul0QUlrshAAQuCHm+uwnwGfnRH9jks07v+yqfYvY+1GdEF1CVsmgFTez5c35KF91AfUv QByMvlOuCEVCT8TecHwZKl506WIZn9scztfbFmnsAQMKtomkxodoh32nFCjDFdwJAmAE 4WMKKTGQ3y+r8sckkkY5OCht3CpvGvwrk4UmiAicf8iKHGxhLX4D9eZUgn0pZIiOcv21 X6+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=vH0s1GVcNF5IA3K6MXsproiU6tEBb+c/9OtwFqb8YN4=; fh=ynswjdvCI3+z3c9qNEmqaETRdNjcpsTGSRuF33qVHus=; b=hv88/Kl1NkDP7NmK6svBSuCZ5mH+iTl6nOOtno+j1u3pdARXjrb1E0H0mtj76ZrkbS h53KZWd2i4IoTyta7c6QcI7n4zEXW7XlmWGXjw59ET8Yyibx5fkYuTkMF91DYOXqjK9y py4Zn6jDXXvDVJzdjE6MIMrOeYJyM9uiPnc7xtQfaHTTK/db4YRmhlnuRTXZwAYSxenZ wplUU1aVZOhUO7RdHCXWdJ6sKDgDXBpM4vOsJwK4qAGPDcQHgEQi6ZHJdZQVnxa3LhYT ZgUpmTtYFOKMFO6/L+yICtwKMCLjYKaCy13Xvpe3OjRYRVVuD7Np1HLNo+V7zOGkXIdB u+bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=FplPGCKR; spf=pass (google.com: domain of linux-kernel+bounces-9450-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9450-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bw37-20020a056a0204a500b005cdaa16ac24si2935439pgb.238.2023.12.21.23.36.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:36:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9450-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=FplPGCKR; spf=pass (google.com: domain of linux-kernel+bounces-9450-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9450-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0F45F28242C for ; Fri, 22 Dec 2023 07:36:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2E071F171; Fri, 22 Dec 2023 07:32:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="FplPGCKR" X-Original-To: linux-kernel@vger.kernel.org Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A65F14F75 for ; Fri, 22 Dec 2023 07:32:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20231222073240epoutp01cb173ff15f0e81e81f2e6f8aee7bcf15~jFv0TNVLg3051630516epoutp01c for ; Fri, 22 Dec 2023 07:32:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20231222073240epoutp01cb173ff15f0e81e81f2e6f8aee7bcf15~jFv0TNVLg3051630516epoutp01c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1703230360; bh=vH0s1GVcNF5IA3K6MXsproiU6tEBb+c/9OtwFqb8YN4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FplPGCKR029A4lfxdOC+GddH0APSg6svbDnNIZR3sS97/Gy9XougBczm2xFGJdEkW deJ6j7Fnybm1uxPVJWhAbed8IshbiwcheX9JU98o97RenB7Fb6RG7Jhbmu20vkWP6b QgNSNp+sGEY2QXshxR5Y3gFONEwHPEwlaSMWNmtM= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20231222073239epcas5p373b8f0edde693b3ef67ca791b2c270db~jFvzYYFg51077210772epcas5p3C; Fri, 22 Dec 2023 07:32:39 +0000 (GMT) Received: from epsmgec5p1new.samsung.com (unknown [182.195.38.182]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4SxJsx6LPqz4x9Pr; Fri, 22 Dec 2023 07:32:37 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmgec5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id F9.64.08567.59B35856; Fri, 22 Dec 2023 16:32:37 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20231222062207epcas5p4a5e0db868dd96cf4ed614a0283d11c7e~jEyOfFzYV2962329623epcas5p4a; Fri, 22 Dec 2023 06:22:07 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231222062207epsmtrp1c653c77027174202dee60229bbf4fedd~jEyOcuX9p1657416574epsmtrp1Y; Fri, 22 Dec 2023 06:22:07 +0000 (GMT) X-AuditID: b6c32a44-617fd70000002177-c5-65853b9595a8 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 6E.93.08755.F0B25856; Fri, 22 Dec 2023 15:22:07 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231222062204epsmtip2614200aae659e182071c956838100583~jEyK_zSUv0303503035epsmtip2K; Fri, 22 Dec 2023 06:22:03 +0000 (GMT) From: Nitesh Shetty 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 , Hannes Reinecke , Anuj Gupta , 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 v19 08/12] nvmet: add copy command support for bdev and file ns Date: Fri, 22 Dec 2023 11:43:02 +0530 Message-Id: <20231222061313.12260-9-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231222061313.12260-1-nj.shetty@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Te0xTZxT3u/fSFreOS9H4Uac2dVtEhLZCy8dLF+ngJm4ZhixuhAUaekMJ 0HZ9TJ1s42F5RkDQbZQ36MbDwHgMi4AayGBiRAwDBKNuSHUMAZFJDQiupWXzv9855/f7fuec L4eFc0qZXFa8UkdrlLJEPm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2em6fJVPGrZqX78pmvHJa9f9mHWB/0M/XG8rkvPJ 5W+6cJXJvzihuCpZSuCQtmdMhXSz6KyHLFOepcgutK5ivxL7a4FMhrhcsfrkpm+S52+3HPs7 b9VGfsaSl+9P2EXHWaa/WahioDRRsNo7zHGSA9dJkc/3Xp/5brNy19G9kss0D83k3KoY/ydn BuMX6ZypXz3+Z+1aJVZzXmtn0zS5l0//nFLyP8VQWLF0yf7wW75evyozfkun7Jiz+M5dvdtr A8Q/vt84WaXWXmf7spjF9eHqMziWBO9foMRSnJFoqMVcVJwIAHdlVgtkAwAA X-CMS-MailID: 20231222062207epcas5p4a5e0db868dd96cf4ed614a0283d11c7e X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231222062207epcas5p4a5e0db868dd96cf4ed614a0283d11c7e References: <20231222061313.12260-1-nj.shetty@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785966699575298656 X-GMAIL-MSGID: 1785966699575298656 Add support for handling nvme_cmd_copy command on target. For bdev-ns if backing device supports copy offload we call device copy offload (blkdev_copy_offload). In case of absence of device copy offload capability, we use copy emulation (blkdev_copy_emulation) For file-ns we call vfs_copy_file_range to service our request. Currently target always shows copy capability by setting NVME_CTRL_ONCS_COPY in controller ONCS. loop target has copy support, which can be used to test copy offload. trace event support for nvme_cmd_copy. Reviewed-by: Hannes Reinecke Signed-off-by: Nitesh Shetty Signed-off-by: Anuj Gupta --- drivers/nvme/target/admin-cmd.c | 9 +++- drivers/nvme/target/io-cmd-bdev.c | 71 +++++++++++++++++++++++++++++++ drivers/nvme/target/io-cmd-file.c | 50 ++++++++++++++++++++++ drivers/nvme/target/nvmet.h | 1 + drivers/nvme/target/trace.c | 19 +++++++++ 5 files changed, 148 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index 39cb570f833d..4e1a6ca09937 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -433,8 +433,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req) id->nn = cpu_to_le32(NVMET_MAX_NAMESPACES); id->mnan = cpu_to_le32(NVMET_MAX_NAMESPACES); id->oncs = cpu_to_le16(NVME_CTRL_ONCS_DSM | - NVME_CTRL_ONCS_WRITE_ZEROES); - + NVME_CTRL_ONCS_WRITE_ZEROES | NVME_CTRL_ONCS_COPY); /* XXX: don't report vwc if the underlying device is write through */ id->vwc = NVME_CTRL_VWC_PRESENT; @@ -536,6 +535,12 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req) if (req->ns->bdev) nvmet_bdev_set_limits(req->ns->bdev, id); + else { + id->msrc = (__force u8)to0based(BIO_MAX_VECS - 1); + id->mssrl = cpu_to_le16(BIO_MAX_VECS << + (PAGE_SHIFT - SECTOR_SHIFT)); + id->mcl = cpu_to_le32(le16_to_cpu(id->mssrl)); + } /* * We just provide a single LBA format that matches what the diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index f11400a908f2..f974858ae5a0 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -46,6 +46,18 @@ void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id) id->npda = id->npdg; /* NOWS = Namespace Optimal Write Size */ id->nows = to0based(bdev_io_opt(bdev) / bdev_logical_block_size(bdev)); + + if (bdev_max_copy_sectors(bdev)) { + id->msrc = id->msrc; + id->mssrl = cpu_to_le16((bdev_max_copy_sectors(bdev) << + SECTOR_SHIFT) / bdev_logical_block_size(bdev)); + id->mcl = cpu_to_le32((__force u32)id->mssrl); + } else { + id->msrc = (__force u8)to0based(BIO_MAX_VECS - 1); + id->mssrl = cpu_to_le16((BIO_MAX_VECS << PAGE_SHIFT) / + bdev_logical_block_size(bdev)); + id->mcl = cpu_to_le32((__force u32)id->mssrl); + } } void nvmet_bdev_ns_disable(struct nvmet_ns *ns) @@ -451,6 +463,61 @@ static void nvmet_bdev_execute_write_zeroes(struct nvmet_req *req) } } +static void nvmet_bdev_copy_endio(void *private, int status, + ssize_t copied) +{ + struct nvmet_req *rq = (struct nvmet_req *)private; + u16 nvme_status; + + if (copied == rq->copy_len) + rq->cqe->result.u32 = cpu_to_le32(1); + else + rq->cqe->result.u32 = cpu_to_le32(0); + + nvme_status = errno_to_nvme_status(rq, status); + nvmet_req_complete(rq, nvme_status); +} + +/* + * At present we handle only one range entry, since copy offload is aligned with + * copy_file_range, only one entry is passed from block layer. + */ +static void nvmet_bdev_execute_copy(struct nvmet_req *rq) +{ + struct nvme_copy_range range; + struct nvme_command *cmd = rq->cmd; + ssize_t ret; + off_t dst, src; + + u16 status; + + status = nvmet_copy_from_sgl(rq, 0, &range, sizeof(range)); + if (status) + goto err_rq_complete; + + dst = le64_to_cpu(cmd->copy.sdlba) << rq->ns->blksize_shift; + src = le64_to_cpu(range.slba) << rq->ns->blksize_shift; + rq->copy_len = ((__force size_t)range.nlb + 1) << rq->ns->blksize_shift; + + if (bdev_max_copy_sectors(rq->ns->bdev)) { + ret = blkdev_copy_offload(rq->ns->bdev, dst, src, rq->copy_len, + nvmet_bdev_copy_endio, + (void *)rq, GFP_KERNEL); + } else { + ret = blkdev_copy_emulation(rq->ns->bdev, dst, + rq->ns->bdev, src, rq->copy_len, + nvmet_bdev_copy_endio, + (void *)rq, GFP_KERNEL); + } + if (ret == -EIOCBQUEUED) + return; + + rq->cqe->result.u32 = cpu_to_le32(0); + status = errno_to_nvme_status(rq, ret); +err_rq_complete: + nvmet_req_complete(rq, status); +} + u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req) { switch (req->cmd->common.opcode) { @@ -469,6 +536,10 @@ u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req) case nvme_cmd_write_zeroes: req->execute = nvmet_bdev_execute_write_zeroes; return 0; + case nvme_cmd_copy: + req->execute = nvmet_bdev_execute_copy; + return 0; + default: return nvmet_report_invalid_opcode(req); } diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c index 2d068439b129..0a8337596f0c 100644 --- a/drivers/nvme/target/io-cmd-file.c +++ b/drivers/nvme/target/io-cmd-file.c @@ -322,6 +322,47 @@ static void nvmet_file_dsm_work(struct work_struct *w) } } +static void nvmet_file_copy_work(struct work_struct *w) +{ + struct nvmet_req *req = container_of(w, struct nvmet_req, f.work); + int nr_range = req->cmd->copy.nr_range + 1; + u16 status = 0; + int src, id; + ssize_t len, ret; + loff_t pos; + + pos = le64_to_cpu(req->cmd->copy.sdlba) << req->ns->blksize_shift; + if (unlikely(pos + req->transfer_len > req->ns->size)) { + nvmet_req_complete(req, errno_to_nvme_status(req, -ENOSPC)); + return; + } + + for (id = 0 ; id < nr_range; id++) { + struct nvme_copy_range range; + + status = nvmet_copy_from_sgl(req, id * sizeof(range), &range, + sizeof(range)); + if (status) + break; + + src = (le64_to_cpu(range.slba) << (req->ns->blksize_shift)); + len = (le16_to_cpu(range.nlb) + 1) << (req->ns->blksize_shift); + ret = vfs_copy_file_range(req->ns->file, src, req->ns->file, + pos, len, COPY_FILE_SPLICE); + pos += ret; + if (ret != len) { + req->cqe->result.u32 = cpu_to_le32(id); + if (ret < 0) + status = errno_to_nvme_status(req, ret); + else + status = errno_to_nvme_status(req, -EIO); + break; + } + } + + nvmet_req_complete(req, status); +} + static void nvmet_file_execute_dsm(struct nvmet_req *req) { if (!nvmet_check_data_len_lte(req, nvmet_dsm_len(req))) @@ -330,6 +371,12 @@ static void nvmet_file_execute_dsm(struct nvmet_req *req) queue_work(nvmet_wq, &req->f.work); } +static void nvmet_file_execute_copy(struct nvmet_req *req) +{ + INIT_WORK(&req->f.work, nvmet_file_copy_work); + queue_work(nvmet_wq, &req->f.work); +} + static void nvmet_file_write_zeroes_work(struct work_struct *w) { struct nvmet_req *req = container_of(w, struct nvmet_req, f.work); @@ -376,6 +423,9 @@ u16 nvmet_file_parse_io_cmd(struct nvmet_req *req) case nvme_cmd_write_zeroes: req->execute = nvmet_file_execute_write_zeroes; return 0; + case nvme_cmd_copy: + req->execute = nvmet_file_execute_copy; + return 0; default: return nvmet_report_invalid_opcode(req); } diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 6c8acebe1a1a..b648baeb52cf 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -405,6 +405,7 @@ struct nvmet_req { struct device *p2p_client; u16 error_loc; u64 error_slba; + size_t copy_len; }; #define NVMET_MAX_MPOOL_BVEC 16 diff --git a/drivers/nvme/target/trace.c b/drivers/nvme/target/trace.c index bff454d46255..551fdf029381 100644 --- a/drivers/nvme/target/trace.c +++ b/drivers/nvme/target/trace.c @@ -92,6 +92,23 @@ static const char *nvmet_trace_dsm(struct trace_seq *p, u8 *cdw10) return ret; } +static const char *nvmet_trace_copy(struct trace_seq *p, u8 *cdw10) +{ + const char *ret = trace_seq_buffer_ptr(p); + u64 sdlba = get_unaligned_le64(cdw10); + u8 nr_range = get_unaligned_le16(cdw10 + 8); + u16 control = get_unaligned_le16(cdw10 + 10); + u32 dsmgmt = get_unaligned_le32(cdw10 + 12); + u32 reftag = get_unaligned_le32(cdw10 + 16); + + trace_seq_printf(p, + "sdlba=%llu, nr_range=%u, ctrl=1x%x, dsmgmt=%u, reftag=%u", + sdlba, nr_range, control, dsmgmt, reftag); + trace_seq_putc(p, 0); + + return ret; +} + static const char *nvmet_trace_common(struct trace_seq *p, u8 *cdw10) { const char *ret = trace_seq_buffer_ptr(p); @@ -129,6 +146,8 @@ const char *nvmet_trace_parse_nvm_cmd(struct trace_seq *p, return nvmet_trace_read_write(p, cdw10); case nvme_cmd_dsm: return nvmet_trace_dsm(p, cdw10); + case nvme_cmd_copy: + return nvmet_trace_copy(p, cdw10); default: return nvmet_trace_common(p, cdw10); } From patchwork Fri Dec 22 06:13:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 182574 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp900756dyi; Thu, 21 Dec 2023 23:36:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8A5Iy5IfrWjg4aWOKbvUC5+1Gx+BIc5DKNfYeT4RLmyfkYAvMDcz+MtQRduQJTVieGosS X-Received: by 2002:aa7:838d:0:b0:6d6:aa3d:b44 with SMTP id u13-20020aa7838d000000b006d6aa3d0b44mr867486pfm.53.1703230590427; Thu, 21 Dec 2023 23:36:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703230590; cv=none; d=google.com; s=arc-20160816; b=L0XAAr0hWk4bEh1+GmCQoqHLCn5F4fQb9BereqJkUw3XWfS5x370dDkV/cuMcTQnBb gc1MG6Wohpca+y2VbKgNdRS8MhNmRF9hhugVxp75h/R3G0xLdp/69lMyh1VKhy7IbTO6 dma4gsaFZiTsHO6+PUFPN9cFTrRK3oSV1xVBg4WiKZCLsmdoBlxTcMFPHgqcpz1F5NMu JGQQ9ikS89LZ/1PLQIXChcqYBQfavp5idN/mBPes305v+P1s8yj2mZiC5dWbOMcBMQeX JMQyeDl1pduQu6Nz8WAF7/X4M5QDpjPm7LHK81GGl1vsRCcypmqfzjCpG0ImaWTcEBQy ahDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=pMi2KJ6tLswDpsWtY8Cv4RkPJ8GSgmmvRnoKG+rEJEY=; fh=CLy6Yt7X3R3g63FkLqfkJTUh9I0/R59DzG55U5R3DOE=; b=kteqDGlvJQ+lm0Ll09u+2BCWwfVW7/+rWNf8torXu9C5FNn3WM4hXYaZEDd5/i6tI8 mzJfUFvU5vMy0P14pczq4/LiRDC37zivneU5ELneqhR8VQVeYg6ZbUuyBjXvNRBP03db 1CalRV2xe+7tlmjMueWrmVNvG6Rdu/Wb/OMkuXsgnOyWofwjOhmA3rsrZvGRRpUnH/aj TPJ2h8ajFWzLNFG7qDoouENoOIctWarNF4IOSgT6P24hh0WKy8SXRzH2gz35wf3ofpZP Z/7u5jp79+Nx4P9fYWYFFrSmc48U0aVEJyPCfQTBYDiMOZn32pV/2iWW7uoPOKQk9+EW NqEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=TSOhTFeF; spf=pass (google.com: domain of linux-kernel+bounces-9451-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9451-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id r24-20020aa78b98000000b006d343912d55si2575954pfd.405.2023.12.21.23.36.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:36:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9451-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=TSOhTFeF; spf=pass (google.com: domain of linux-kernel+bounces-9451-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9451-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3242F282135 for ; Fri, 22 Dec 2023 07:36:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B44E1224C9; Fri, 22 Dec 2023 07:32:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="TSOhTFeF" X-Original-To: linux-kernel@vger.kernel.org Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7ACA417753 for ; Fri, 22 Dec 2023 07:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20231222073242epoutp042bcda2162ab47ff56c94f3f85a247a1c~jFv2zktW41596515965epoutp044 for ; Fri, 22 Dec 2023 07:32:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20231222073242epoutp042bcda2162ab47ff56c94f3f85a247a1c~jFv2zktW41596515965epoutp044 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1703230363; bh=pMi2KJ6tLswDpsWtY8Cv4RkPJ8GSgmmvRnoKG+rEJEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TSOhTFeFlnbAmcgPAmTSIxpXkzJbWyYVOR/BbHGhrYVoDYjcpgFDMErK79OtWaF1r S/e08ibmE3EDAv/rf/gvr1l0UkSE9DKQC63yTSmD+Wyq9+lCRaWOZkJa/9t9bGeQ9t b4aJUrpKB885cTMXUedwABL2WXe8JTSjrOoXzdxE= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20231222073242epcas5p2e4a4a09ff56f17c4452a1166e77b29c0~jFv2NhXCV1857018570epcas5p2Q; Fri, 22 Dec 2023 07:32:42 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.176]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4SxJt10fm4z4x9Pp; Fri, 22 Dec 2023 07:32:41 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id F2.57.10009.89B35856; Fri, 22 Dec 2023 16:32:40 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20231222062217epcas5p1263b3a88c9e94933ab44be1df86ccfbe~jEyXpfPu-1003410034epcas5p1v; Fri, 22 Dec 2023 06:22:17 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231222062217epsmtrp18acad7daa76e95f3898780e78c18a5a2~jEyXoMX6s1657416574epsmtrp1e; Fri, 22 Dec 2023 06:22:17 +0000 (GMT) X-AuditID: b6c32a4a-ff1ff70000002719-50-65853b988906 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 4B.EE.18939.91B25856; Fri, 22 Dec 2023 15:22:17 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231222062214epsmtip2890709eff5394d61ae1d575ca7ebbd62~jEyUbT6GN0344503445epsmtip2_; Fri, 22 Dec 2023 06:22:13 +0000 (GMT) From: Nitesh Shetty 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 v19 09/12] dm: Add support for copy offload Date: Fri, 22 Dec 2023 11:43:03 +0530 Message-Id: <20231222061313.12260-10-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231222061313.12260-1-nj.shetty@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Te0xTdxTH97v39lLYqpcC2w+cWjs1gIO2ULofCnMZZN69EEfiHy5ZqXAH hNI2LRXZS96yMh6iGKkgDAhMIHSFjhWYE3GjgjLisCBsuqEF5xpF2BgLBFhL0fnf93zOOb/z +OWwcW6xmx87RZHOqBUyOZ/0IDovBwQEndmTzwi770Ugw2A/jmbnlwjUcquURPbLcwDZeo8D VFtXTaDx3i4MnW/5EUPlfaMATVn1GLowsQt9WdBAoO8uDBBopLuKRDWNU26oaMxMoibLCoZu lk0BdKLQiiGzLRugzqUaHLXZZwh0ZWITGl62sF6DdJf+lhs9fNtI0CNDWrq9+XOS7mg4Rv/R UQnonvEskq4vOcmii3MfkvTs1ARBz3xvJekSUzOg/2rfQrfbHmCxGw6lRiQzskRGzWMUCcrE FEVSJP/tOGmUNEwiFAWJwtErfJ5ClsZE8qPfiQ16I0XuWAKfd0Qm1zpQrEyj4QtejVArtekM L1mpSY/kM6pEuUqsCtbI0jRa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APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231222062217epcas5p1263b3a88c9e94933ab44be1df86ccfbe References: <20231222061313.12260-1-nj.shetty@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785966719201980767 X-GMAIL-MSGID: 1785966719201980767 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 23c32cd1f1d8..c98bb3908bd4 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); From patchwork Fri Dec 22 06:13:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 182575 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp900886dyi; Thu, 21 Dec 2023 23:36:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IG08ac5GcenOsJm/ke53LzUjqOURiyoMNZO0/qjJMNjEWsEAn+2QC7LlXqp8CbJm1jqyPWt X-Received: by 2002:a17:902:ce89:b0:1d4:13ca:ab26 with SMTP id f9-20020a170902ce8900b001d413caab26mr721209plg.68.1703230617780; Thu, 21 Dec 2023 23:36:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703230617; cv=none; d=google.com; s=arc-20160816; b=L5EgmpX6h6k67VAQmZXDwasUsn/H2v5o/iBM15RgkpxekhMBKiFGhxmMUD07GyldIX oqX9NRxvyaOhDpgZGavrGzTRySif9b9HK5NRlLJyQbmHVGS+2SS/8/No/O6qzqkyChDP rVwYCTxq60sjZpnl/ES+8ugiMCj3hO6dzk7WBYdgiNGR3ZEI2jxwsjXTClO0DeUioP8L aSgREKxpu7C88mr2O2h+/mOl8MG93snsEW8kiDZ8gKXMIV/5ePMrpPfpG1yCPGRlaXZA ZwOqADjxjs6F6Zr6c3NJqKbE6KyIxwlxSrJ5xoHn5100XrXmrSV3L0oSWOB9btrZYnZ7 +J/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=ve1xdmhje+5EA/lKMdfQIcdO/aY9KnYalMJf/3V4ggw=; fh=8nq/0iv5anXW/Yb5mzpSqdTSgzj3s6Wh77WDNPA3/ss=; b=LeBIaUj9AMyKYEbOFlTx4A061GfOeTxB7ARy12E4200EYzmjL8wsoY2zrCIAp3NspA QN6R2wUUBHBj6OFL6lP/VoP9biVW1s4vdvetpOOQU8CR0zHYKM8TA7KHFjhSsYj54EJg u/Ze1nAP9Q/oAIgYqmHtSH5CyG96j8emqkBNxZot1gegmE/yFns42TK9qi7P8gNSdl4C U3FHydzP25qT8+zB69FPpgFcDmB8bROsTKnjQWLMk04PGWAWtiFq2Qp+O6ZRkRDtUjRb iMQKfiM8MUesVor0nTXNozyeWQ7ikc/s2Txd87xngpjLcEfHrpJljkxUlEKJ8aFDnB8M VK1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=Q21mH9Zm; spf=pass (google.com: domain of linux-kernel+bounces-9452-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9452-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o2-20020a1709026b0200b001d3fc142ad9si2714670plk.289.2023.12.21.23.36.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:36:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9452-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=Q21mH9Zm; spf=pass (google.com: domain of linux-kernel+bounces-9452-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9452-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3BAD82839FD for ; Fri, 22 Dec 2023 07:36:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 194CE22EE6; Fri, 22 Dec 2023 07:32:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="Q21mH9Zm" X-Original-To: linux-kernel@vger.kernel.org Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30CD62233E for ; Fri, 22 Dec 2023 07:32:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20231222073246epoutp043cbaa7b24ea55521cabea1bdc597d5cb~jFv6HL9Xt1645016450epoutp04z for ; Fri, 22 Dec 2023 07:32:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20231222073246epoutp043cbaa7b24ea55521cabea1bdc597d5cb~jFv6HL9Xt1645016450epoutp04z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1703230366; bh=ve1xdmhje+5EA/lKMdfQIcdO/aY9KnYalMJf/3V4ggw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q21mH9Zm9xMHWN1RohqpyRB/kDqKo80T9NL+ATnKx4Tw5i9a8GaEhAiBgZ4QgAKNs qce2pKdwswSXK1VZ6ZRttNyLGg8V0tNpExZQj2BI4HOtAWp9E9qd33KCq28BlW+VRk sCHrEN+mZZeX3qdh92eXhnUHX1UMCgbYmjTjK4Mg= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20231222073245epcas5p1b3c6e576644a2b573d2d065012ce9e43~jFv5ghx-m2925829258epcas5p1O; Fri, 22 Dec 2023 07:32:45 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.174]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4SxJt40yHnz4x9Py; Fri, 22 Dec 2023 07:32:44 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id D4.23.09634.B9B35856; Fri, 22 Dec 2023 16:32:44 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20231222062227epcas5p34a8e2395fc03b456b5fdb4b858e01d15~jEygs7JbK0954409544epcas5p3_; Fri, 22 Dec 2023 06:22:27 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231222062227epsmtrp14c1dc293656af35d18e50f68a873c1d4~jEygr3APY1655116551epsmtrp1C; Fri, 22 Dec 2023 06:22:27 +0000 (GMT) X-AuditID: b6c32a49-eebff700000025a2-ca-65853b9ba4cb Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id E5.A3.08755.32B25856; Fri, 22 Dec 2023 15:22:27 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231222062223epsmtip2fb23343255634a8809e53ce3053828e7~jEydWR4t50300703007epsmtip2R; Fri, 22 Dec 2023 06:22:23 +0000 (GMT) From: Nitesh Shetty 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 , Hannes Reinecke , 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 v19 10/12] dm: Enable copy offload for dm-linear target Date: Fri, 22 Dec 2023 11:43:04 +0530 Message-Id: <20231222061313.12260-11-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231222061313.12260-1-nj.shetty@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01TaVBTVxTufe/l5cEQfIC2F9CWSaedAdnSAl42i1XjE5yBqaXj2FqahlfC AEnIItT+KAi4YAWJtcWwiEgtokNGgpS1ZbHG4AKtxUDaKJ2yUwSxyiiLTQi0/vvOOd93z/nO nUPhrqe4HlSyVMUqpKJUPulINHR5e/uVhuexgUd6caTrvoajh4/nCXTRUkiiya5ZgIbaDwNU UVlGoIH2Jgy1VmowdOHizxjSdN4FaLhPi6E280Z09lAVgVrbjAS601xKojPnh7nomKmRRN8b ljDUf2IYoKIjfRhqHMoGqGH+DI5qJ6cJdN3siXoWDZwod6ZJa+EyPfcuE8ydW2qmruYoyeir vmTG9KcB0zKQRTLnCk5ymOM5D0jm4bCZYKZ/7COZgvoawOhvfME8qnuVqRuawuLW7E2JkLCi RFbhxUrFssRkaVIkP2Z3wtaE4JBAgZ8gFG3ie0lFaWwkf9uuOD9hcqp1G3yv/aJUtTUVJ1Iq +QGbIxQytYr1ksiUqkg+K09MlQfJ/ZWiNKVamuQvZVVhgsDAt4KtxE9SJFf+ngPyWk7mzZJe LAu0E/nAgYJ0EDTf7+XkA0fKlW4B8KzJRNiDWQDLWg7iNpYr/QRAfY9iVVEyWo7ZSW0AdpZU cu1BHga7RopBPqAokt4IbzynbIK19CUcNl0W2Dg4/RSDOdXXga3gRu+ADwaNy3MQ9Btw/OQ1 jk3Lo8Nh+69ONgjpAFh438XGcLBmR5+d49gwj3aBxtNDy0qcfg3mXCnBbc9DWu8AqweGV6xt g3WDs5gdu8EJQz3Xjj3geOGhFZwBL3xdTdrFuQBqTVpgL7wD87oLcdsQOO0Ndc0B9vQGeKq7 FrM3dobH54dW3ufBxvJV/Dq8pKsg7dgd3p3LJu1eGLj00yb7qgoAtPxzlXsCeGlf8KN9wY/2 /84VAK8B7qxcmZbEKoPlAimb8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sIejHszW1wl7n0emh+ PdMlIb0cZn6c7Up4TbmOn8XuG3h0CGxyGEiX5tKzYVOezT0Fp+dDzf18PAvQ2v+Q9j90HWA6 4Mcq1Qq5Qh2sDI5m48VqqUIdFy0XH4pR6IH748KlRvBQ91VsARgFLABSuMCXGxN0juVxZdKE k6wq5qAqLopVW8BcihDwufyedBmPlktj2aMsq2RV/yhGefknYlsiLO3hsWCgtsqkkdXw7ZaE /vjLgdr0NTmSzRmvjn9NNQVcCZL1eYvG/7zn7MdC7o6LOdsWLsjuEYYIjUWx6/3ZSyMrxwxP kiKb1YrTzlVp3qPyL0G5xS9jJgaz94V2eY8EbE2ZIR38UVWnb5ME7d0i26iT9JisOxaFcm7J C3ZfDVsdMm/O25yNkjFtmiqwt7Jk9HOt1TL8zHqsvHPySVty3dqiiUM+4c6KvbvOruOV/Twy UNnavWd7zeDZrdTOvnpz4IH0UkLcfS+FdYSrRLeXNnYXdPguuTY5lpmh3JxkG5i1LksUrE+s Tn7asJiN4IskQn5LfGXhJ7/whjBvZ72AUEdKg4W4Si39C4HaAd1gAwAA X-CMS-MailID: 20231222062227epcas5p34a8e2395fc03b456b5fdb4b858e01d15 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231222062227epcas5p34a8e2395fc03b456b5fdb4b858e01d15 References: <20231222061313.12260-1-nj.shetty@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785966747831584896 X-GMAIL-MSGID: 1785966747831584896 Setting copy_offload_supported flag to enable offload. Reviewed-by: Hannes Reinecke Signed-off-by: Nitesh Shetty --- drivers/md/dm-linear.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c index 2d3e186ca87e..cfec2fac28e1 100644 --- a/drivers/md/dm-linear.c +++ b/drivers/md/dm-linear.c @@ -62,6 +62,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->num_discard_bios = 1; ti->num_secure_erase_bios = 1; ti->num_write_zeroes_bios = 1; + ti->copy_offload_supported = 1; ti->private = lc; return 0; From patchwork Fri Dec 22 06:13:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 182576 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp901016dyi; Thu, 21 Dec 2023 23:37:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4CffbXj/kfhcl10hh8ior6AMkHZHaHZo2MfpbZLq0eMt3s1h6kM9q+1o3VUd+hH83n4h5 X-Received: by 2002:a17:907:2d8c:b0:a26:97ef:7a69 with SMTP id gt12-20020a1709072d8c00b00a2697ef7a69mr561523ejc.52.1703230645953; Thu, 21 Dec 2023 23:37:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703230645; cv=none; d=google.com; s=arc-20160816; b=Eob3emo0JkSort3WJSyCHyc+9BCe8odQG3v8UQdPmUFQbKn6v/Df82BT/BsVkYdm4m tZWBt88PL4qsUSWNPPW7eEoAI/uBIb2lQ1dgk09vqOzR5WHswJLVPrDVAUtM3lzGU3Dk LvcV5k6mROB4fGwyL2oPEMEc1hHSuDdH7OR8BQ9K4VvjfKLot7Vt1ZX5h8l/2g125vzJ aJv/hg55nAM4hNpkyhvsV+GXkZqLbHJHtIbaCrd5D9S+HpC8hZJ77zZ1/T9DDkmx17K7 7sGsBJFXPIuBprV9zQvWW0f4fhTMn5bZOu05I2xuzgbjZpf+yhOZ8SX7apb6sgEohwk+ VLQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=Q0pzwoO8FGWSOp2naz3g5BT4IBzXcQeY3AEFwmS1OLc=; fh=ynswjdvCI3+z3c9qNEmqaETRdNjcpsTGSRuF33qVHus=; b=DspzjuCmDuFct2Zboko7Eo6m72BfRrXLieaV0sY9HqRt114R+AsqwSWS2+4YMc6ndE tJsJUROXzu3o+8iOs8r2TAyvWGdQSOfxetJLrjeL1cNTK8XRDMTHE6te3Le6I+0qMHMR GBB49WkIHn2mSlQotv7FaUw8JNsFV1UZssWpmJ0JAGsS7uxn6edxm1qGPan1ODhBiCXZ /cJRsEZ/fK3oa33yf3fxkWevWC4etFW0AldaahOPJ58DZSAMtSQa34aZCYDA64cnBX4A 1vAt7hhAt7aGXM34dPuY4jzYplCMETsQUWlJoK3FK8HmESDw+j98PMjbxtP0fyOZPAGG FyaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="u6/pyKiR"; spf=pass (google.com: domain of linux-kernel+bounces-9453-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9453-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ks15-20020a170906f84f00b00a234b6c0e0fsi1514201ejb.746.2023.12.21.23.37.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:37:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9453-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="u6/pyKiR"; spf=pass (google.com: domain of linux-kernel+bounces-9453-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9453-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 66B101F232FA for ; Fri, 22 Dec 2023 07:37:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 195E123756; Fri, 22 Dec 2023 07:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="u6/pyKiR" X-Original-To: linux-kernel@vger.kernel.org Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04B3822EF3 for ; Fri, 22 Dec 2023 07:32:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20231222073251epoutp0149cacb048ff83ac05def1be9e5cf091b~jFv_qNedQ2995829958epoutp01e for ; Fri, 22 Dec 2023 07:32:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20231222073251epoutp0149cacb048ff83ac05def1be9e5cf091b~jFv_qNedQ2995829958epoutp01e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1703230371; bh=Q0pzwoO8FGWSOp2naz3g5BT4IBzXcQeY3AEFwmS1OLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u6/pyKiR4nJilbs/nHNIzIALHBG3JbtDMF4BLoWRbQ8HSC2Ny6pfO3uIivnnbAO3D wewRSM0hc0eFPgPLaj+Xf49wYGe+aY3vHzKbrg4q24eMHWt/RpG4+F5KbNXGwpeoa6 bAu3PPNiHJpFtm4lMFevAXea+l6V48SLDWXOvxZ4= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20231222073250epcas5p14c52bc5a11e8cbb01b1668064dc1999b~jFv9cgZb32275422754epcas5p1e; Fri, 22 Dec 2023 07:32:50 +0000 (GMT) Received: from epsmgec5p1-new.samsung.com (unknown [182.195.38.174]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4SxJt81Fsyz4x9Q7; Fri, 22 Dec 2023 07:32:48 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmgec5p1-new.samsung.com (Symantec Messaging Gateway) with SMTP id 7F.B9.19369.0AB35856; Fri, 22 Dec 2023 16:32:48 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20231222062237epcas5p4ec8dd02068efc7f0fca133a4241ca308~jEyqMMj4Z0902509025epcas5p4S; Fri, 22 Dec 2023 06:22:37 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231222062237epsmtrp213b0b000da4a86971afba36caf47b248~jEyqK1Qpd1720617206epsmtrp2L; Fri, 22 Dec 2023 06:22:37 +0000 (GMT) X-AuditID: b6c32a50-9e1ff70000004ba9-46-65853ba0b2af Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id F7.D8.08817.D2B25856; Fri, 22 Dec 2023 15:22:37 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231222062233epsmtip22a1d209c2a01750ffee5de9c57802f9f~jEymvdoyd0303903039epsmtip2u; Fri, 22 Dec 2023 06:22:33 +0000 (GMT) From: Nitesh Shetty 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 , Hannes Reinecke , Anuj Gupta , 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 v19 11/12] null: Enable trace capability for null block Date: Fri, 22 Dec 2023 11:43:05 +0530 Message-Id: <20231222061313.12260-12-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231222061313.12260-1-nj.shetty@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Te0zTVxTHd3+/8qNQCz8eZte6MVLDNmDQVkq9vNRFgj91JN3YJG5mUOGX lgBt0wIyZVuZAo43KG7W8Zi6MaCRRxF5VaEGERrGH4Y62GRh0o2CkwFDo6RuLYXN/z73e8/3 nHvOzWHi3hddOcw0eRatkksyuIQ7o+tW4JshDVEFNL9M64JaR2/jaGl1jYG+qLThqOV+BYEW bi0DNDtQBFDDpVoGmhzowVD/pWoMNbUMYajaaAbIMqHFkGEqGH1beIWB+g0jDHS39xsC1X9v cUUl97oJ1Dj8HEM/VVoAqjozgaHu2XyAutbqcXR1YZGB7kxtR+O2YZe9HKpHe9+VGp9uZ1B3 x7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N9ULOV71cunMgLIK7peCdVTbsyJkmPDGCdd137ZIk89NjwfYi60hrUcQ13eXMPZnsfP7s aYFubdb7UpvziFLo6uqaEpDYR4uiBIRWIZOKcI1W9hvNZliTZAMAAA== X-CMS-MailID: 20231222062237epcas5p4ec8dd02068efc7f0fca133a4241ca308 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231222062237epcas5p4ec8dd02068efc7f0fca133a4241ca308 References: <20231222061313.12260-1-nj.shetty@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785966777648172005 X-GMAIL-MSGID: 1785966777648172005 This is a prep patch to enable copy trace capability. At present only zoned null_block is using trace, so we decoupled trace and zoned dependency to make it usable in null_blk driver also. Reviewed-by: Hannes Reinecke Signed-off-by: Nitesh Shetty Signed-off-by: Anuj Gupta --- drivers/block/null_blk/Makefile | 2 -- drivers/block/null_blk/main.c | 3 +++ drivers/block/null_blk/trace.h | 2 ++ drivers/block/null_blk/zoned.c | 1 - 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/block/null_blk/Makefile b/drivers/block/null_blk/Makefile index 84c36e512ab8..672adcf0ad24 100644 --- a/drivers/block/null_blk/Makefile +++ b/drivers/block/null_blk/Makefile @@ -5,7 +5,5 @@ ccflags-y += -I$(src) obj-$(CONFIG_BLK_DEV_NULL_BLK) += null_blk.o null_blk-objs := main.o -ifeq ($(CONFIG_BLK_DEV_ZONED), y) null_blk-$(CONFIG_TRACING) += trace.o -endif null_blk-$(CONFIG_BLK_DEV_ZONED) += zoned.o diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 3021d58ca51c..1b40c674f62b 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -11,6 +11,9 @@ #include #include "null_blk.h" +#define CREATE_TRACE_POINTS +#include "trace.h" + #undef pr_fmt #define pr_fmt(fmt) "null_blk: " fmt diff --git a/drivers/block/null_blk/trace.h b/drivers/block/null_blk/trace.h index 6b2b370e786f..91446c34eac2 100644 --- a/drivers/block/null_blk/trace.h +++ b/drivers/block/null_blk/trace.h @@ -30,6 +30,7 @@ static inline void __assign_disk_name(char *name, struct gendisk *disk) } #endif +#ifdef CONFIG_BLK_DEV_ZONED TRACE_EVENT(nullb_zone_op, TP_PROTO(struct nullb_cmd *cmd, unsigned int zone_no, unsigned int zone_cond), @@ -67,6 +68,7 @@ TRACE_EVENT(nullb_report_zones, TP_printk("%s nr_zones=%u", __print_disk_name(__entry->disk), __entry->nr_zones) ); +#endif /* CONFIG_BLK_DEV_ZONED */ #endif /* _TRACE_NULLB_H */ diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c index 55c5b48bc276..9694461a31a4 100644 --- a/drivers/block/null_blk/zoned.c +++ b/drivers/block/null_blk/zoned.c @@ -3,7 +3,6 @@ #include #include "null_blk.h" -#define CREATE_TRACE_POINTS #include "trace.h" #undef pr_fmt From patchwork Fri Dec 22 06:13:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 182577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp901136dyi; Thu, 21 Dec 2023 23:37:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFAEBCePf0wHoqUnELSmbvoZqvbU+VriwFhGXpJlmn8Yo3zPIQaS5Ta8nBwoGDOjHAU3reg X-Received: by 2002:ac8:5c49:0:b0:425:a20d:ebf1 with SMTP id j9-20020ac85c49000000b00425a20debf1mr1051004qtj.135.1703230671744; Thu, 21 Dec 2023 23:37:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703230671; cv=none; d=google.com; s=arc-20160816; b=E//REFeCClblJdAlU/T7o3CSD+MsBxFyLqNfTUEz+/bkEH8mkcSyJXeCHpzDK2RkY5 oC1OKTUAHRRWgpKV8hWcoTZC67p1KZqEC31L7jMTtv+BB1DVQvVqVhTKSoJerAS/hT1p VPNmau1stlUEstGV1RSCvMUFLelMYhwkKexmLmkKtFTKUnM6HIJco2w4X8lV05r4zyf7 hcWNvdZwEuyGofCdszl+Kh5hdRs4RIajFUh9ed2knjBQRg2+pUQ6we8QaDUqq0hN7u8+ Wx0tg5GngiJiZmUEttMlY0hCPS3VF3b6yZM6Uvq5rWwZqFXHtkS/ZwejXQHRRbVpfDf9 IcQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:dlp-filter:cms-type:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter; bh=gdF/wOMKugvH3378GVUkXSQTheU2+tEf4koM7BLSTqc=; fh=eY+2Gu6s2B5N9z7wVfi2n7SOdh6AGrdRFGM0pmEmIbE=; b=cBvf4K/q9vErqn8oC3exg58CLdRgFU196xhpPVvSBgwkpiq/TOGB1WFyvcDG4DS7+H pI3q9LFqBI8+YNdt6mnFXXbvyx4B7NEjNnsLzuPSsud8qYqEAK2tP1XYKGI9v9ROq/xU uH2th+kP18hsyOWp55u0FeaJrhNubs75xzeWjIho13qtuOv9XZgI6KrPQjA51DH7M3r7 Go+iil6paujutv1GriBWN5C8ZzHrY6eOvPLNt+o5+hCYZNPDfuX61oXs71kwyW7Goq2V 6Fw5ITnP060kXTutSoPwdTLgKdNnU5p4b7HgGb71/VSHU2oK/gR0Qy2XHqj7kWQi95IH ASuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=cHTeEEHD; spf=pass (google.com: domain of linux-kernel+bounces-9454-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9454-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m18-20020a05622a055200b004254224603csi3924363qtx.539.2023.12.21.23.37.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 23:37:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9454-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=cHTeEEHD; spf=pass (google.com: domain of linux-kernel+bounces-9454-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9454-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 798821C25256 for ; Fri, 22 Dec 2023 07:37:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B88B5241FF; Fri, 22 Dec 2023 07:33:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="cHTeEEHD" X-Original-To: linux-kernel@vger.kernel.org Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66DAA2374C for ; Fri, 22 Dec 2023 07:32:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20231222073254epoutp04e6cece7f3f92a2a7c47b9a4e869223ec~jFwBvuXuB1596515965epoutp04A for ; Fri, 22 Dec 2023 07:32:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20231222073254epoutp04e6cece7f3f92a2a7c47b9a4e869223ec~jFwBvuXuB1596515965epoutp04A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1703230374; bh=gdF/wOMKugvH3378GVUkXSQTheU2+tEf4koM7BLSTqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cHTeEEHD4GNkzWNv6eTZqmKPtPXdJKUZPn/655lcCQOFn2Z6uQmJfSn1Th03+STr/ Ho6KlLBKpF15Aso4B3fAmwrWCpQBvaa7ZfyV7pDeZTYLeKn9JTVcy1UFqlnJibpGBi m9vq38tx4NtPjfT+hZ2qsOct3qDZcOUmZh2V6hRk= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20231222073253epcas5p412bcd55be87879719d1db2fdf5a4af8e~jFwBAl_tL2514625146epcas5p4K; Fri, 22 Dec 2023 07:32:53 +0000 (GMT) Received: from epsmgec5p1new.samsung.com (unknown [182.195.38.177]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4SxJtD5PGNz4x9Q1; Fri, 22 Dec 2023 07:32:52 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmgec5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id C9.74.08567.4AB35856; Fri, 22 Dec 2023 16:32:52 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20231222062248epcas5p4623168200a168ae2f895df4221368d66~jEy0En_fu0903809038epcas5p4h; Fri, 22 Dec 2023 06:22:48 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231222062248epsmtrp1088c62ec57e799bad9ace7097f36eaf2~jEy0DmXzk1655116551epsmtrp1W; Fri, 22 Dec 2023 06:22:48 +0000 (GMT) X-AuditID: b6c32a44-3abff70000002177-e8-65853ba4252f Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 51.FE.18939.73B25856; Fri, 22 Dec 2023 15:22:48 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231222062244epsmtip26cf587d2c278da63c0ced776226aa9da~jEywWeSb_0303503035epsmtip2O; Fri, 22 Dec 2023 06:22:44 +0000 (GMT) From: Nitesh Shetty 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 , Hannes Reinecke , Damien Le Moal , Anuj Gupta , Vincent Fu , 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 v19 12/12] null_blk: add support for copy offload Date: Fri, 22 Dec 2023 11:43:06 +0530 Message-Id: <20231222061313.12260-13-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20231222061313.12260-1-nj.shetty@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Ta1BUZRie75yzZxca6gCin4SJa0moXBaX7eOWMlw8TQ5DpcboD9zgCAzs xb1Ixjgutw0hASUcWeMiMAlIy8jN5SKjkFyzrQRcYYDSxQxCAlM0Atr1oPnveZ/ved7bNy8P d6jhOvMSpCpGIRUn8UlbornL3c2jMiCT8a44twXV9XfjaO7xIoHS8pdwdGksj0TTXfMAma99 CdDiTSOOysqLCXTnWguG2svPYKj60g0MnekcBmhySIehqyPb0AVtJYHar/YR6FbrNyQq/XaS i3JuG0h0sWcZQ6b8SYBOZw1hyGBOBah5sRRH+ulZAvWOvInu5WQBZFzq4exyoVt0Y1zaOH6Z oG/dVNP1NSdJuqHyBP2goQjQbXc0JF2RW8ChT6U/JOmWzAkOPTc5QtCzHUMkndtYA+iGgRT6 Uf1bdL15BoukDiQGxjPiWEbhykhjZLEJ0rgg/oefRIdE+4q8BR4CP/Qe31UqljBB/NA9kR7h CUmWDfFdj4qT1BYqUqxU8r3eD1TI1CrGNV6mVAXxGXlsklwo91SKJUq1NM5Tyqj8Bd7ePr4W 4aHE+Kn+blL+c/jnVU9+5WqA3j8b8HiQEsJnJ12ygS3PgWoDcPziAMkG8wAWrpi4LwPzn/OW wOa547e0Uox9aAGw1tQH2CATg8bUGa41L0ltgwMrPKthDVWLw5bLAqsGp57isKKnh7RqHKlg WFISadUQ1Duw+ayWY8V2VADM67tOsO15wbwJeyttY6F//6diVWIP+4rMhBXj1EaY3nQet6aH VJcNHP3uJGAbDYWPHxUSLHaEUz2NqwM4wz/ytKs4GVZ/XUWy5gwAdbd1q+adMLM/D7c2gVPu sK7Vi6U3wMJ+PcYWfh2eWjRjLG8HDSUv8GZYW1dGsng9HF5IXcU0LB/Q4uyucgHMvqvD8oGr 7pWBdK8MpPu/dBnAa8B6Rq6UxDExvnKBlEl++ckxMkk9e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X5DFcWQ+7QfV3e0LO5D2hurRZY7a6W898dOwoAjorbB7wkQu6stgd+E44cg47QYz 7hfhGkBr/0Pa/1ApwCrBcjZRIYuWRSZuFCskMkVSfLQ4MkFWCxYe4HGgARhr5sUWgFHAAiCF i1z4CV5KVsCPkpxOYeUJYfIkKauwAFeKEK3kr5VeiBLQ0ZIT7HGWTWTl/yhGOa1Ow652Vqzr 1XQFTrl37ak5ONint/i6r+vYZOfdTqraUjK7dAspMcwEufgp248RRYfyW5Pj3hXmlllvxVnV BpVK7rtiZcC0NWX9SS/zDbUHiggQ9ynJMY/Xn9+6iavSi8MvaQvdmyaLOjX+4e1+wm9jISap Mz/C+qKRa7Pq65qb1mRrp30iBWLtcG+ysmff0V0681mj4fKOgvIjJfbpoL0puw/f5bwJUY66 n7nedO2H9HX/R1e9sb1GuIuaWxVYGpB1yll2TBEdlBomDhXFpcZ2KpRh56qfW5bkN89tzznC TRHuEc7WxfirhjPFmw7ofhcJy2fY2JCbZ4uDd+58mOUfLCIUMZKNHrhcIfkDEazyDnADAAA= X-CMS-MailID: 20231222062248epcas5p4623168200a168ae2f895df4221368d66 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231222062248epcas5p4623168200a168ae2f895df4221368d66 References: <20231222061313.12260-1-nj.shetty@samsung.com> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785966804849480975 X-GMAIL-MSGID: 1785966804849480975 Implementation is based on existing read and write infrastructure. copy_max_bytes: A new configfs and module parameter is introduced, which can be used to set hardware/driver supported maximum copy limit. Only request based queue mode will support for copy offload. Added tracefs support to copy IO tracing. Reviewed-by: Hannes Reinecke Suggested-by: Damien Le Moal Signed-off-by: Anuj Gupta Signed-off-by: Nitesh Shetty Signed-off-by: Vincent Fu --- Documentation/block/null_blk.rst | 5 ++ drivers/block/null_blk/main.c | 97 ++++++++++++++++++++++++++++++- drivers/block/null_blk/null_blk.h | 1 + drivers/block/null_blk/trace.h | 23 ++++++++ 4 files changed, 123 insertions(+), 3 deletions(-) diff --git a/Documentation/block/null_blk.rst b/Documentation/block/null_blk.rst index 4dd78f24d10a..6153e02fcf13 100644 --- a/Documentation/block/null_blk.rst +++ b/Documentation/block/null_blk.rst @@ -149,3 +149,8 @@ zone_size=[MB]: Default: 256 zone_nr_conv=[nr_conv]: Default: 0 The number of conventional zones to create when block device is zoned. If zone_nr_conv >= nr_zones, it will be reduced to nr_zones - 1. + +copy_max_bytes=[size in bytes]: Default: COPY_MAX_BYTES + A module and configfs parameter which can be used to set hardware/driver + supported maximum copy offload limit. + COPY_MAX_BYTES(=128MB at present) is defined in fs.h diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 1b40c674f62b..e6f476ad45a6 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -160,6 +160,10 @@ static int g_max_sectors; module_param_named(max_sectors, g_max_sectors, int, 0444); MODULE_PARM_DESC(max_sectors, "Maximum size of a command (in 512B sectors)"); +static unsigned long g_copy_max_bytes = BLK_COPY_MAX_BYTES; +module_param_named(copy_max_bytes, g_copy_max_bytes, ulong, 0444); +MODULE_PARM_DESC(copy_max_bytes, "Maximum size of a copy command (in bytes)"); + static unsigned int nr_devices = 1; module_param(nr_devices, uint, 0444); MODULE_PARM_DESC(nr_devices, "Number of devices to register"); @@ -412,6 +416,7 @@ NULLB_DEVICE_ATTR(home_node, uint, NULL); NULLB_DEVICE_ATTR(queue_mode, uint, NULL); NULLB_DEVICE_ATTR(blocksize, uint, NULL); NULLB_DEVICE_ATTR(max_sectors, uint, NULL); +NULLB_DEVICE_ATTR(copy_max_bytes, uint, NULL); NULLB_DEVICE_ATTR(irqmode, uint, NULL); NULLB_DEVICE_ATTR(hw_queue_depth, uint, NULL); NULLB_DEVICE_ATTR(index, uint, NULL); @@ -553,6 +558,7 @@ static struct configfs_attribute *nullb_device_attrs[] = { &nullb_device_attr_queue_mode, &nullb_device_attr_blocksize, &nullb_device_attr_max_sectors, + &nullb_device_attr_copy_max_bytes, &nullb_device_attr_irqmode, &nullb_device_attr_hw_queue_depth, &nullb_device_attr_index, @@ -659,7 +665,8 @@ static ssize_t memb_group_features_show(struct config_item *item, char *page) "poll_queues,power,queue_mode,shared_tag_bitmap,size," "submit_queues,use_per_node_hctx,virt_boundary,zoned," "zone_capacity,zone_max_active,zone_max_open," - "zone_nr_conv,zone_offline,zone_readonly,zone_size\n"); + "zone_nr_conv,zone_offline,zone_readonly,zone_size," + "copy_max_bytes\n"); } CONFIGFS_ATTR_RO(memb_group_, features); @@ -725,6 +732,7 @@ static struct nullb_device *null_alloc_dev(void) dev->queue_mode = g_queue_mode; dev->blocksize = g_bs; dev->max_sectors = g_max_sectors; + dev->copy_max_bytes = g_copy_max_bytes; dev->irqmode = g_irqmode; dev->hw_queue_depth = g_hw_queue_depth; dev->blocking = g_blocking; @@ -1274,6 +1282,81 @@ static int null_transfer(struct nullb *nullb, struct page *page, return err; } +static inline int nullb_setup_copy(struct nullb *nullb, struct request *req, + bool is_fua) +{ + sector_t sector_in = 0, sector_out = 0; + loff_t offset_in, offset_out; + void *in, *out; + ssize_t chunk, rem = 0; + struct bio *bio; + struct nullb_page *t_page_in, *t_page_out; + u16 seg = 1; + int status = -EIO; + + if (blk_rq_nr_phys_segments(req) != BLK_COPY_MAX_SEGMENTS) + return status; + + /* + * First bio contains information about destination and last bio + * contains information about source. + */ + __rq_for_each_bio(bio, req) { + if (seg == blk_rq_nr_phys_segments(req)) { + sector_in = bio->bi_iter.bi_sector; + if (rem != bio->bi_iter.bi_size) + return status; + } else { + sector_out = bio->bi_iter.bi_sector; + rem = bio->bi_iter.bi_size; + } + seg++; + } + + trace_nullb_copy_op(req, sector_out << SECTOR_SHIFT, + sector_in << SECTOR_SHIFT, rem); + + spin_lock_irq(&nullb->lock); + while (rem > 0) { + chunk = min_t(size_t, nullb->dev->blocksize, rem); + offset_in = (sector_in & SECTOR_MASK) << SECTOR_SHIFT; + offset_out = (sector_out & SECTOR_MASK) << SECTOR_SHIFT; + + if (null_cache_active(nullb) && !is_fua) + null_make_cache_space(nullb, PAGE_SIZE); + + t_page_in = null_lookup_page(nullb, sector_in, false, + !null_cache_active(nullb)); + if (!t_page_in) + goto err; + t_page_out = null_insert_page(nullb, sector_out, + !null_cache_active(nullb) || + is_fua); + if (!t_page_out) + goto err; + + in = kmap_local_page(t_page_in->page); + out = kmap_local_page(t_page_out->page); + + memcpy(out + offset_out, in + offset_in, chunk); + kunmap_local(out); + kunmap_local(in); + __set_bit(sector_out & SECTOR_MASK, t_page_out->bitmap); + + if (is_fua) + null_free_sector(nullb, sector_out, true); + + rem -= chunk; + sector_in += chunk >> SECTOR_SHIFT; + sector_out += chunk >> SECTOR_SHIFT; + } + + status = 0; +err: + spin_unlock_irq(&nullb->lock); + return status; +} + static int null_handle_rq(struct nullb_cmd *cmd) { struct request *rq = cmd->rq; @@ -1283,13 +1366,16 @@ static int null_handle_rq(struct nullb_cmd *cmd) sector_t sector = blk_rq_pos(rq); struct req_iterator iter; struct bio_vec bvec; + bool fua = rq->cmd_flags & REQ_FUA; + + if (op_is_copy(req_op(rq))) + return nullb_setup_copy(nullb, rq, fua); spin_lock_irq(&nullb->lock); rq_for_each_segment(bvec, rq, iter) { len = bvec.bv_len; err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset, - op_is_write(req_op(rq)), sector, - rq->cmd_flags & REQ_FUA); + op_is_write(req_op(rq)), sector, fua); if (err) { spin_unlock_irq(&nullb->lock); return err; @@ -2074,6 +2160,9 @@ static int null_validate_conf(struct nullb_device *dev) return -EINVAL; } + if (dev->queue_mode == NULL_Q_BIO) + dev->copy_max_bytes = 0; + return 0; } @@ -2193,6 +2282,8 @@ static int null_add_dev(struct nullb_device *dev) dev->max_sectors = queue_max_hw_sectors(nullb->q); dev->max_sectors = min(dev->max_sectors, BLK_DEF_MAX_SECTORS); blk_queue_max_hw_sectors(nullb->q, dev->max_sectors); + blk_queue_max_copy_hw_sectors(nullb->q, + dev->copy_max_bytes >> SECTOR_SHIFT); if (dev->virt_boundary) blk_queue_virt_boundary(nullb->q, PAGE_SIZE - 1); diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h index 929f659dd255..e82e53a2e2df 100644 --- a/drivers/block/null_blk/null_blk.h +++ b/drivers/block/null_blk/null_blk.h @@ -107,6 +107,7 @@ struct nullb_device { unsigned int queue_mode; /* block interface */ unsigned int blocksize; /* block size */ unsigned int max_sectors; /* Max sectors per command */ + unsigned long copy_max_bytes; /* Max copy offload length in bytes */ unsigned int irqmode; /* IRQ completion handler */ unsigned int hw_queue_depth; /* queue depth */ unsigned int index; /* index of the disk, only valid with a disk */ diff --git a/drivers/block/null_blk/trace.h b/drivers/block/null_blk/trace.h index 91446c34eac2..2f2c1d1c2b48 100644 --- a/drivers/block/null_blk/trace.h +++ b/drivers/block/null_blk/trace.h @@ -70,6 +70,29 @@ TRACE_EVENT(nullb_report_zones, ); #endif /* CONFIG_BLK_DEV_ZONED */ +TRACE_EVENT(nullb_copy_op, + TP_PROTO(struct request *req, + sector_t dst, sector_t src, size_t len), + TP_ARGS(req, dst, src, len), + TP_STRUCT__entry( + __array(char, disk, DISK_NAME_LEN) + __field(enum req_op, op) + __field(sector_t, dst) + __field(sector_t, src) + __field(size_t, len) + ), + TP_fast_assign( + __entry->op = req_op(req); + __assign_disk_name(__entry->disk, req->q->disk); + __entry->dst = dst; + __entry->src = src; + __entry->len = len; + ), + TP_printk("%s req=%-15s: dst=%llu, src=%llu, len=%lu", + __print_disk_name(__entry->disk), + blk_op_str(__entry->op), + __entry->dst, __entry->src, __entry->len) +); #endif /* _TRACE_NULLB_H */ #undef TRACE_INCLUDE_PATH