Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp20362789rwd; Thu, 29 Jun 2023 00:59:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5R07E3BOpIfSNtmSfJru4XiF9DyjNMi3wY29/Q9xwSfirmwpxxoupBE6wZ4NNNYyRe+Ioj X-Received: by 2002:a05:6a20:394c:b0:123:3f03:68f9 with SMTP id r12-20020a056a20394c00b001233f0368f9mr26911125pzg.61.1688025585540; Thu, 29 Jun 2023 00:59:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688025585; cv=none; d=google.com; s=arc-20160816; b=QRMU/O3KxCuCOG32EFeRtpEqFnK7kGc5Te7xuEfasj6Pzv5Y/UPXwpo88pgj/ac6sy E6aVkdtkZvnhebbwUvMf3lClZfmoN5ZGyJEWNGg34rxN4bSThZdF70flSroOAqFC9K6x Wt21fAZwSnoBVxlmEr07nJFUhKFAQz0dXqzDe4Do4eLViJWsMBc5hgE8TaqUcajK0apT rUaMl6uXbFxsmCMrtvje8js1nd6+8AVJSJ8rKbcyF5+8M6lmfkLKVyjFSi/F6ZlcJ9XR wdeJ64FDlC36y7/MPF6n/ZRiz0mVFRfpTil7mB7LGiT0ufePSLJT5mErpKEyn0XOvEmP vdhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type:user-agent :in-reply-to:mime-version:message-id:subject:cc:to:from:date :dkim-signature:dkim-filter; bh=bEnyTEmII6xaca+iNsVYjy6viqZWXFnJIZrx7zCVjP0=; fh=URER+EPEsA8zfVkm3y3O64jmBpjQQ0x/NPujXlvKP8k=; b=YI0XpM+pEAgI57QnELHNsoFjOpaQW21wK9AyJgdfxoPVtdFq4d2gZ8TuaqU4hq9pmp geWghuircV9+63Pvm7swm0rtd9TElC6Z00TFAYE1gJLN0dy+LwTwHmuxRVwQywI1a6wG oFDVlbPJh0Nepxnlfr39+B5Pea2COrhE+Bk+9n6r9c2XSbHuMUZnRrd1K9wJE4ajt3cE WmcfBtTyey+nZOepSL+WQlZwIDFfqUEMBgUzmQz6sCCXv8PKf0pbcU5GPPp/CKxwZqWm 4pIgrDn9GUhj5a6OWDLvEYdQOXErWrphDS08ij+PR+roQFExds7mqEjf7kOSrAsye0lB plfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=tupVTkRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e8-20020a17090301c800b001b850a9686dsi1093284plh.279.2023.06.29.00.59.31; Thu, 29 Jun 2023 00:59:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=tupVTkRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232425AbjF2HsX (ORCPT + 99 others); Thu, 29 Jun 2023 03:48:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231949AbjF2Hre (ORCPT ); Thu, 29 Jun 2023 03:47:34 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A075102 for ; Thu, 29 Jun 2023 00:47:28 -0700 (PDT) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20230629074725epoutp01a015b5064a8c774d63946eb49528c1a9~tEadTjS7z2635526355epoutp01q for ; Thu, 29 Jun 2023 07:47:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20230629074725epoutp01a015b5064a8c774d63946eb49528c1a9~tEadTjS7z2635526355epoutp01q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1688024845; bh=bEnyTEmII6xaca+iNsVYjy6viqZWXFnJIZrx7zCVjP0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=tupVTkRLjt9OJG6Ai4n9BuIh1n2O/ONf7MdlJq7aTy+4COlwk4/+lMeHWY+cpgADU g1qasXFmeDm7IxXJRstx+33AVcgdyfES/uecmckX3VoivWz8G0yzB35Lhi3KYuWZtP 0vY69s+3vCtSzKKNvOMLfAjcQNI/2f+3g3g+fX0M= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20230629074724epcas5p377d1eca0472f465e4e406badb25c08c4~tEacgdOPQ0843708437epcas5p3w; Thu, 29 Jun 2023 07:47:24 +0000 (GMT) Received: from epsmgec5p1-new.samsung.com (unknown [182.195.38.174]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4Qs9XC1NWkz4x9Q7; Thu, 29 Jun 2023 07:47:23 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmgec5p1-new.samsung.com (Symantec Messaging Gateway) with SMTP id 57.62.55173.B073D946; Thu, 29 Jun 2023 16:47:23 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20230628160713epcas5p36c081366246fbaec7e4a0c0f6923b4b1~s3ljk_4D62429624296epcas5p3j; Wed, 28 Jun 2023 16:07:13 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230628160713epsmtrp11aadd144fdb002419decec98bb14c3b9~s3ljigv9V0551805518epsmtrp1R; Wed, 28 Jun 2023 16:07:13 +0000 (GMT) X-AuditID: b6c32a50-e61c07000001d785-59-649d370b7485 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id B6.C2.34491.1BA5C946; Thu, 29 Jun 2023 01:07:13 +0900 (KST) Received: from green245 (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230628160702epsmtip232aea2d90a898b8697d094fe374ecf51~s3lZS98o93059830598epsmtip2l; Wed, 28 Jun 2023 16:07:01 +0000 (GMT) Date: Wed, 28 Jun 2023 21:33:54 +0530 From: Nitesh Shetty To: Damien Le Moal Cc: Jens Axboe , Jonathan Corbet , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Keith Busch , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Alexander Viro , Christian Brauner , martin.petersen@oracle.com, linux-scsi@vger.kernel.org, willy@infradead.org, hare@suse.de, djwong@kernel.org, bvanassche@acm.org, ming.lei@redhat.com, nitheshshetty@gmail.com, gost.dev@samsung.com, 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: Re: [PATCH v13 2/9] block: Add copy offload support infrastructure Message-ID: <20230628160354.lfzwxyb2i32tkp7d@green245> MIME-Version: 1.0 In-Reply-To: User-Agent: NeoMutt/20171215 X-Brightmail-Tracker: H4sIAAAAAAAAA02Tf0xTVxTHd99rX4uk5PFDuSsTWZlTIPyoFrggCHMGXgbLyNAsc1nwhb5Q BrS1LYKyKOJkAgLKjwULCE4Zv1QmuK0yEEZ1/IrBDSkRAxIt6ACpwuYgFVjLg8X/Pud7vufc e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Crj3nZstfa/ OgmPTvPKJ0vyKottlHgMlnsZy64ovXru1veHrBK22x0ar8euf1ZdKJ34JfQYZ52KUVr24olH A2un8zNsinVdxLW57nTXulzXzuPTy6s8us2dFNPzhbd/q0m006gqnXVK4syRtl/VE349eed1 zqTi38uP9isFyi5E3ipeeC93ymam195f5i5+oPS9cpXvL3OLbTWLrWb7Saeabr0yafaf6+rH zxgs9rvGZG6+5lBSwrX16y4rJfxRC9pr1x6oZ9h1721bxvYJnuc+1Yo90O1f8Lj1k47ZpnrL mVvPr7+qtuf6ujkGEat2hp/ruBTPNUfuH+sarq/L3ilfb9iwVuDBv9fBnMI7SlcrsRRnJBpq MRcVJwIAraR+hIEDAAA= X-CMS-MailID: 20230628160713epcas5p36c081366246fbaec7e4a0c0f6923b4b1 X-Msg-Generator: CA Content-Type: multipart/mixed; boundary="----CHyoCALg6LzvWsSTaVDWulLjyDTSZVBAz8-9IIrQs0inuafE=_961cb_" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230627184010epcas5p4bb6581408d9b67bbbcad633fb26689c9 References: <20230627183629.26571-1-nj.shetty@samsung.com> <20230627183629.26571-3-nj.shetty@samsung.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ------CHyoCALg6LzvWsSTaVDWulLjyDTSZVBAz8-9IIrQs0inuafE=_961cb_ Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Disposition: inline On 23/06/28 03:45PM, Damien Le Moal wrote: >On 6/28/23 03:36, Nitesh Shetty wrote: >> Introduce blkdev_copy_offload which takes similar arguments as >> copy_file_range and performs copy offload between two bdevs. > >I am confused... I thought it was discussed to only allow copy offload only >within a single bdev for now... Did I missi something ? > Yes, you are right. copy is supported within single bdev only. We will update this. >> Introduce REQ_OP_COPY_DST, REQ_OP_COPY_SRC operation. >> Issue REQ_OP_COPY_DST with destination info along with taking a plug. >> This flows till request layer and waits for src bio to get merged. >> Issue REQ_OP_COPY_SRC with source info and this bio reaches request >> layer and merges with dst request. >> For any reason, if request comes to driver with either only one of src/dst >> info we fail the copy offload. >> >> Larger copy will be divided, based on max_copy_sectors limit. >> >> Suggested-by: Christoph Hellwig >> Signed-off-by: Anuj Gupta >> Signed-off-by: Nitesh Shetty >> --- >> block/blk-core.c | 5 ++ >> block/blk-lib.c | 177 ++++++++++++++++++++++++++++++++++++++ >> block/blk-merge.c | 21 +++++ >> block/blk.h | 9 ++ >> block/elevator.h | 1 + >> include/linux/bio.h | 4 +- >> include/linux/blk_types.h | 21 +++++ >> include/linux/blkdev.h | 4 + >> 8 files changed, 241 insertions(+), 1 deletion(-) >> >> diff --git a/block/blk-core.c b/block/blk-core.c >> index 99d8b9812b18..e6714391c93f 100644 >> --- a/block/blk-core.c >> +++ b/block/blk-core.c >> @@ -796,6 +796,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 (!blk_queue_copy(q)) >> + goto not_supported; >> + break; >> default: >> break; >> } >> diff --git a/block/blk-lib.c b/block/blk-lib.c >> index e59c3069e835..10c3eadd5bf6 100644 >> --- a/block/blk-lib.c >> +++ b/block/blk-lib.c >> @@ -115,6 +115,183 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, >> } >> EXPORT_SYMBOL(blkdev_issue_discard); >> >> +/* >> + * For synchronous copy offload/emulation, wait and process all in-flight BIOs. >> + * 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 make it through >> + * blkdev_copy_(offload/emulate)_(read/write)_endio. >> + */ >> +static ssize_t blkdev_copy_wait_io_completion(struct cio *cio) >> +{ >> + ssize_t ret; >> + >> + if (cio->endio) >> + return 0; >> + >> + if (atomic_read(&cio->refcount)) { >> + __set_current_state(TASK_UNINTERRUPTIBLE); >> + blk_io_schedule(); >> + } >> + >> + ret = cio->comp_len; >> + kfree(cio); >> + >> + return ret; >> +} >> + >> +static void blkdev_copy_offload_read_endio(struct bio *bio) >> +{ >> + struct cio *cio = bio->bi_private; >> + sector_t clen; >> + >> + if (bio->bi_status) { >> + clen = (bio->bi_iter.bi_sector << SECTOR_SHIFT) - cio->pos_out; >> + cio->comp_len = min_t(sector_t, clen, cio->comp_len); >> + } >> + bio_put(bio); >> + >> + if (!atomic_dec_and_test(&cio->refcount)) >> + return; >> + if (cio->endio) { >> + cio->endio(cio->private, cio->comp_len); >> + kfree(cio); >> + } else >> + blk_wake_io_task(cio->waiter); > >Curly brackets around else missing. > Acked. >> +} >> + >> +/* >> + * __blkdev_copy_offload - Use device's native copy offload feature. >> + * we perform copy operation by sending 2 bio. >> + * 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 src bio to arrive. >> + * 2. We issue REQ_OP_COPY_SRC bio along with source sector and 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 >> + * >> + * Returns the length of bytes copied or error if encountered >> + */ >> +static ssize_t __blkdev_copy_offload( >> + struct block_device *bdev_in, loff_t pos_in, >> + struct block_device *bdev_out, loff_t pos_out, >> + size_t len, cio_iodone_t endio, void *private, gfp_t gfp_mask) >> +{ >> + struct cio *cio; >> + struct bio *read_bio, *write_bio; >> + sector_t rem, copy_len, max_copy_len; >> + struct blk_plug plug; >> + >> + cio = kzalloc(sizeof(struct cio), GFP_KERNEL); >> + if (!cio) >> + return -ENOMEM; >> + atomic_set(&cio->refcount, 0); >> + cio->waiter = current; >> + cio->endio = endio; >> + cio->private = private; >> + >> + max_copy_len = min(bdev_max_copy_sectors(bdev_in), >> + bdev_max_copy_sectors(bdev_out)) << SECTOR_SHIFT; > >According to patch 1, this can end up being 0, so the loop below will be infinite. > Agreed. As you suggested earlier, once we remove copy_offload parameter and checking copy_max_sector to identify copy offload capabilty should solve this. Thank you, Nitesh Shetty ------CHyoCALg6LzvWsSTaVDWulLjyDTSZVBAz8-9IIrQs0inuafE=_961cb_ Content-Type: text/plain; charset="utf-8" ------CHyoCALg6LzvWsSTaVDWulLjyDTSZVBAz8-9IIrQs0inuafE=_961cb_--