Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp796903rwl; Wed, 29 Mar 2023 08:35:00 -0700 (PDT) X-Google-Smtp-Source: AKy350a+YxS8IxtYgYilEgFEH0A4sPNzD7sfy5/PRl2fPRva4gwXD9VTWLB7sqcO992FT/Nni3U/ X-Received: by 2002:a17:906:c20e:b0:920:388c:5c60 with SMTP id d14-20020a170906c20e00b00920388c5c60mr21868702ejz.41.1680104100050; Wed, 29 Mar 2023 08:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680104100; cv=none; d=google.com; s=arc-20160816; b=EeYZoWzWcMtwnfpfTL6rZ35FpycI/s7cNqEIKlIDDIGzB5NYh5K4LMhEWxuty6Y8Ko CEtBXPHtVMDKBzBgLP7swTa/3uu5yeZH8zpkc+hfkc3jolSGZGaDO+3ZbTRZQPbZANU3 R10BUsb+MMvHBndK3ZpCnd0MKqUdgPdzNWpkMHieA7xLwaMQU4znUvzcmlBJg48b11AS abNi0ALY5MKCvsa1ZsicLb6fZGSw/ItYHqgF9TyR7RzFrwFu3DZwEDPj55/3xHBERkKL dKpf2rEboLYA4y8EfogzKr9SbXQb09Ed8RppupSvCwYoGYIjdMeQfKlAAtF8tb54wuJv brTQ== 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=0CtoX3v/W4RKFaDOc3LBzA7OjTHP1VSVjXB8jFz9GoE=; b=Eew8BXb1aHDwItVfd6t84NezES7rulpulPcJ8GwiVq5IPbxtQJxqx0uzYGVcAuR95V 2/GSAqY5NeirJpoJuxzhWpNtLznNFCr2083m0Jy1FHXsm0ErVwOs7XFxrlKU5EhFa8us 8WPzM3Kl6+uiME2qYGNpgN7ob5HLqnJpSBojZOlw4YCkW6swBQB0z9xBV8D50s21Efnm Sb0Kjupkzxmf+x0IBitbmxY/vuDk1MA/LoT69vq8Je5zbCz7utECjq+tq/EEef/hdEh3 aOHOa4XglA/QYkYvCvLJOB2tPqvG9tujS+vzQCTWCM3IFj7fji331ZIKiBDHms4WtcOI k91g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=EtoLdu5v; 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 v19-20020a17090690d300b00921792d069dsi34311184ejw.608.2023.03.29.08.34.35; Wed, 29 Mar 2023 08:35:00 -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=EtoLdu5v; 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 S229803AbjC2PcM (ORCPT + 99 others); Wed, 29 Mar 2023 11:32:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230295AbjC2Pbx (ORCPT ); Wed, 29 Mar 2023 11:31:53 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B1D740C1 for ; Wed, 29 Mar 2023 08:31:51 -0700 (PDT) Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20230329153149epoutp045164a3563406c8ab7c625e8074144b8d~Q7ZrAR9GY1358413584epoutp04E for ; Wed, 29 Mar 2023 15:31:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20230329153149epoutp045164a3563406c8ab7c625e8074144b8d~Q7ZrAR9GY1358413584epoutp04E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1680103909; bh=0CtoX3v/W4RKFaDOc3LBzA7OjTHP1VSVjXB8jFz9GoE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=EtoLdu5vwxx2HZ8aBliIx2FLkrTfNki6mKPYVnQVtcWPVKJe69h2Sq17wcz57sOmf B7UfkErwSLNGi6kuJSeGvOqfDYKpPvloVM3XGHNWicPQ3USwamEQoS2NzFi4vAtp1P ShJhTTQYtl5oYqW2azD5BkXotv4iRslzJCXnVKDM= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20230329153149epcas5p437b54757fee362a3440d07c08a7ae3b7~Q7ZqaDJ5R2635826358epcas5p4H; Wed, 29 Mar 2023 15:31:49 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.176]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4PmrBW2pdLz4x9Pt; Wed, 29 Mar 2023 15:31:47 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id E6.DD.10528.3E954246; Thu, 30 Mar 2023 00:31:47 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20230329124320epcas5p10454736bde745b4de754fd513bca7b30~Q5GjozHU20813008130epcas5p1E; Wed, 29 Mar 2023 12:43:20 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230329124320epsmtrp2200bdf3aadaa5cb7c5c9dc4ecf4954ab~Q5GjnsrBH2573425734epsmtrp2U; Wed, 29 Mar 2023 12:43:20 +0000 (GMT) X-AuditID: b6c32a49-e75fa70000012920-d0-642459e3764d Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id D0.58.18071.86234246; Wed, 29 Mar 2023 21:43:20 +0900 (KST) Received: from green5 (unknown [107.110.206.5]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230329124316epsmtip2a58f2078f77962c21ecbb6192f187e71~Q5GgnZnR_1265312653epsmtip2e; Wed, 29 Mar 2023 12:43:16 +0000 (GMT) Date: Wed, 29 Mar 2023 18:12:36 +0530 From: Nitesh Shetty To: Christian Brauner Cc: Anuj Gupta , Jens Axboe , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Keith Busch , Christoph Hellwig , Sagi Grimberg , James Smart , Chaitanya Kulkarni , Alexander Viro , bvanassche@acm.org, hare@suse.de, ming.lei@redhat.com, damien.lemoal@opensource.wdc.com, joshi.k@samsung.com, nitheshshetty@gmail.com, gost.dev@samsung.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v8 4/9] fs, block: copy_file_range for def_blk_ops for direct block device. Message-ID: <20230329124236.GB3895@green5> MIME-Version: 1.0 In-Reply-To: <20230329-glitter-drainpipe-bdf9d3876ac4@brauner> User-Agent: Mutt/1.9.4 (2018-02-28) X-Brightmail-Tracker: H4sIAAAAAAAAA02Te0xTZxjG853Tnh5cuh0B40c7pVSQCXKpK91hA2HTsEMkGY4EM5asNvQI ld7Wy3RAMlBgwQSvk8SKsxLDEAQmt3GrSInjFmCTW0A7tlmGg1BuBjTcVjhl8b/f+7zP873f JR+Oups4PFyhNtA6tUwpxHaw6tsP+Ac9/8JXHloySZBV3b+i5LnLayh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78OvJs1sC95V9rzQ5s2Rxuj2SQ7UpSbuNEpi9 Des8sI6OjovRWyvGu0I3l3LKm2nxYPeL9qRVGit9NqRYQRmZ/KQQR+r+nV9p7hTqYOodQUHs JHt8/fzqz8KPJ1zRM+w/K95sYzqVrkK9dn+rw2GPeeJK5b5a9mukT1PaEnt6du7nyfeHNpht S9cEKTby5z3POrxi5dgWQDU2ighVilQchitV0j8NAO+/bQMAAA== X-CMS-MailID: 20230329124320epcas5p10454736bde745b4de754fd513bca7b30 X-Msg-Generator: CA Content-Type: multipart/mixed; boundary="----KU2CxbTk4.ftA7vvsvzLW4bt.-m_7jRTbTuK1k18jgDVn8pS=_11875f_" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230327084244epcas5p1b0ede867e558ff6faf258de3656a8aa4 References: <20230327084103.21601-1-anuj20.g@samsung.com> <20230327084103.21601-5-anuj20.g@samsung.com> <20230329-glitter-drainpipe-bdf9d3876ac4@brauner> X-Spam-Status: No, score=-2.5 required=5.0 tests=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 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 ------KU2CxbTk4.ftA7vvsvzLW4bt.-m_7jRTbTuK1k18jgDVn8pS=_11875f_ Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline On Wed, Mar 29, 2023 at 02:14:40PM +0200, Christian Brauner wrote: > On Mon, Mar 27, 2023 at 02:10:52PM +0530, Anuj Gupta wrote: > > From: Nitesh Shetty > > > > For direct block device opened with O_DIRECT, use copy_file_range to > > issue device copy offload, and fallback to generic_copy_file_range incase > > device copy offload capability is absent. > > Modify checks to allow bdevs to use copy_file_range. > > > > Suggested-by: Ming Lei > > Signed-off-by: Anuj Gupta > > Signed-off-by: Nitesh Shetty > > --- > > block/blk-lib.c | 22 ++++++++++++++++++++++ > > block/fops.c | 20 ++++++++++++++++++++ > > fs/read_write.c | 11 +++++++++-- > > include/linux/blkdev.h | 3 +++ > > 4 files changed, 54 insertions(+), 2 deletions(-) > > > > diff --git a/block/blk-lib.c b/block/blk-lib.c > > index a21819e59b29..c288573c7e77 100644 > > --- a/block/blk-lib.c > > +++ b/block/blk-lib.c > > @@ -475,6 +475,28 @@ static inline bool blk_check_copy_offload(struct request_queue *q_in, > > return blk_queue_copy(q_in) && blk_queue_copy(q_out); > > } > > > > +int 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 end_io, void *private, gfp_t gfp_mask) > > +{ > > + struct request_queue *in_q = bdev_get_queue(bdev_in); > > + struct request_queue *out_q = bdev_get_queue(bdev_out); > > + int ret = -EINVAL; > > Why initialize to -EINVAL if blk_copy_sanity_check() initializes it > right away anyway? > acked. > > + bool offload = false; > > Same thing with initializing offload. > acked > > + > > + ret = blk_copy_sanity_check(bdev_in, pos_in, bdev_out, pos_out, len); > > + if (ret) > > + return ret; > > + > > + offload = blk_check_copy_offload(in_q, out_q); > > + if (offload) > > + ret = __blk_copy_offload(bdev_in, pos_in, bdev_out, pos_out, > > + len, end_io, private, gfp_mask); > > + > > + return ret; > > +} > > +EXPORT_SYMBOL_GPL(blkdev_copy_offload); > > + > > /* > > * @bdev_in: source block device > > * @pos_in: source offset > > diff --git a/block/fops.c b/block/fops.c > > index d2e6be4e3d1c..3b7c05831d5c 100644 > > --- a/block/fops.c > > +++ b/block/fops.c > > @@ -611,6 +611,25 @@ 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)); > > + int comp_len = 0; > > + > > + if ((file_in->f_iocb_flags & IOCB_DIRECT) && > > + (file_out->f_iocb_flags & IOCB_DIRECT)) > > + comp_len = blkdev_copy_offload(in_bdev, pos_in, out_bdev, > > + pos_out, len, NULL, NULL, GFP_KERNEL); > > + if (comp_len != len) > > + comp_len = generic_copy_file_range(file_in, pos_in + comp_len, > > + file_out, pos_out + comp_len, len - comp_len, flags); > > I'm not deeply familiar with this code but this looks odd. It at least > seems possible that comp_len could be -EINVAL and len 20 at which point > you'd be doing len - comp_len aka 20 - 22 = -2 in generic_copy_file_range(). comp_len should be 0 incase of error. We do agree, some function description needs to be updated. We will recheck this completion path to make sure not to return negative value, incase of failure. Thank You, Nitesh Shetty ------KU2CxbTk4.ftA7vvsvzLW4bt.-m_7jRTbTuK1k18jgDVn8pS=_11875f_ Content-Type: text/plain; charset="utf-8" ------KU2CxbTk4.ftA7vvsvzLW4bt.-m_7jRTbTuK1k18jgDVn8pS=_11875f_--