From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 650B0C4320E for ; Wed, 18 Aug 2021 16:17:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 449B3610FD for ; Wed, 18 Aug 2021 16:17:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231218AbhHRQSZ (ORCPT ); Wed, 18 Aug 2021 12:18:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:43382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbhHRQSZ (ORCPT ); Wed, 18 Aug 2021 12:18:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8EDA6610A5; Wed, 18 Aug 2021 16:17:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629303470; bh=KPxieBci0vXg8rmYUy2so8SGtGACKhwfHUnpqQywB2U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YuZGxSb/qbJrnZ105zWsST1nzc3m5MixjmBIDb4Cqpf+Tw8XhntQlWVGRMwhIoXA7 PTtnTQEfAVvrGpcExRjt1ERSU8HOof1WS87z7lpzbE0XvNK4dmam1hUQ3Cb5tmEtl4 LQdsyFAHM06VRTXPscO6q5RGPRNYJ/p7auy1fidt0ulyrYV7J2rObWzPJh2wayByhW dD+K4DCpaPYtgRQUC0W7yQJz5RhyNsOdzq4PlthfwTFNMccSyBzUQf5XqVN5Xpf+0R eu2xlTZQILiBAamLWqT4orjL/dDPccR6l4KllQOYQis8vh+mMut2C5ziIwpIkHE3eK usfw3LYHare6w== Date: Wed, 18 Aug 2021 09:17:50 -0700 From: "Darrick J. Wong" To: Nitesh Shetty Cc: SelvaKumar S , linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-api@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@redhat.com, kbusch@kernel.org, axboe@kernel.dk, damien.lemoal@wdc.com, asml.silence@gmail.com, johannes.thumshirn@wdc.com, hch@lst.de, willy@infradead.org, kch@kernel.org, martin.petersen@oracle.com, mpatocka@redhat.com, bvanassche@acm.org, snitzer@redhat.com, agk@redhat.com, selvajove@gmail.com, joshiiitr@gmail.com, nj.shetty@samsung.com, joshi.k@samsung.com, javier.gonz@samsung.com Subject: Re: [PATCH 4/7] block: Introduce a new ioctl for simple copy Message-ID: <20210818161750.GF12664@magnolia> References: <20210817101423.12367-1-selvakuma.s1@samsung.com> <20210817101423.12367-5-selvakuma.s1@samsung.com> <20210817233613.GA12597@magnolia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On Wed, Aug 18, 2021 at 09:07:54PM +0530, Nitesh Shetty wrote: > On Wed, Aug 18, 2021 at 5:06 AM Darrick J. Wong wrote: > > > > On Tue, Aug 17, 2021 at 03:44:20PM +0530, SelvaKumar S wrote: > > > From: Nitesh Shetty > > > > > > Add new BLKCOPY ioctl that offloads copying of one or more sources ranges > > > to a destination in the device. COPY ioctl accepts a 'copy_range' > > > structure that contains destination (in sectors), no of sources and > > > pointer to the array of source ranges. Each source range is represented by > > > 'range_entry' that contains start and length of source ranges (in sectors) > > > > > > MAX_COPY_NR_RANGE, limits the number of entries for the IOCTL and > > > MAX_COPY_TOTAL_LENGTH limits the total copy length, IOCTL can handle. > > > > > > Example code, to issue BLKCOPY: > > > /* Sample example to copy three source-ranges [0, 8] [16, 8] [32,8] to > > > * [64,24], on the same device */ > > > > > > int main(void) > > > { > > > int ret, fd; > > > struct range_entry source_range[] = {{.src = 0, .len = 8}, > > > {.src = 16, .len = 8}, {.src = 32, .len = 8},}; > > > struct copy_range cr; > > > > > > cr.dest = 64; > > > cr.nr_range = 3; > > > cr.range_list = (__u64)&source_range; > > > > > > fd = open("/dev/nvme0n1", O_RDWR); > > > if (fd < 0) return 1; > > > > > > ret = ioctl(fd, BLKCOPY, &cr); > > > if (ret < 0) printf("copy failure\n"); > > > > > > close(fd); > > > > > > return ret; > > > } > > > > > > Signed-off-by: Nitesh Shetty > > > Signed-off-by: SelvaKumar S > > > Signed-off-by: Kanchan Joshi > > > --- > > > block/ioctl.c | 33 +++++++++++++++++++++++++++++++++ > > > include/uapi/linux/fs.h | 8 ++++++++ > > > 2 files changed, 41 insertions(+) > > > > > > diff --git a/block/ioctl.c b/block/ioctl.c > > > index eb0491e90b9a..2af56d01e9fe 100644 > > > --- a/block/ioctl.c > > > +++ b/block/ioctl.c > > > @@ -143,6 +143,37 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, > > > GFP_KERNEL, flags); > > > } > > > > > > +static int blk_ioctl_copy(struct block_device *bdev, fmode_t mode, > > > + unsigned long arg) > > > +{ > > > + struct copy_range crange; > > > + struct range_entry *rlist; > > > + int ret; > > > + > > > + if (!(mode & FMODE_WRITE)) > > > + return -EBADF; > > > + > > > + if (copy_from_user(&crange, (void __user *)arg, sizeof(crange))) > > > + return -EFAULT; > > > + > > > + rlist = kmalloc_array(crange.nr_range, sizeof(*rlist), > > > + GFP_KERNEL); > > > + if (!rlist) > > > + return -ENOMEM; > > > + > > > + if (copy_from_user(rlist, (void __user *)crange.range_list, > > > + sizeof(*rlist) * crange.nr_range)) { > > > + ret = -EFAULT; > > > + goto out; > > > + } > > > + > > > + ret = blkdev_issue_copy(bdev, crange.nr_range, rlist, bdev, crange.dest, > > > + GFP_KERNEL, 0); > > > +out: > > > + kfree(rlist); > > > + return ret; > > > +} > > > + > > > static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, > > > unsigned long arg) > > > { > > > @@ -468,6 +499,8 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, > > > case BLKSECDISCARD: > > > return blk_ioctl_discard(bdev, mode, arg, > > > BLKDEV_DISCARD_SECURE); > > > + case BLKCOPY: > > > + return blk_ioctl_copy(bdev, mode, arg); > > > case BLKZEROOUT: > > > return blk_ioctl_zeroout(bdev, mode, arg); > > > case BLKGETDISKSEQ: > > > diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h > > > index 7a97b588d892..4183688ff398 100644 > > > --- a/include/uapi/linux/fs.h > > > +++ b/include/uapi/linux/fs.h > > > @@ -76,6 +76,13 @@ struct range_entry { > > > __u64 len; > > > }; > > > > > > +struct copy_range { > > > + __u64 dest; > > > + __u64 nr_range; > > > > If the maximum number of elements in the range list is 1<<12, there's no > > need for this to be larger than a u16, right? > > > > > + __u64 range_list; > > > > Pointers embedded in a structure are /not/ a good idea, because this > > will create a lot of compatibility headaches for 32-bit binaries running > > on 64-bit kernels. Please just make the size of this header structure > > a multiple of 8 bytes and put the range_entry list immediately after it. > > > > struct copy_range { > > __s64 dest_offset; > > __u32 nr_range_entries; > > __u32 flags; > > __u64 reserved[2]; > > }; > > > > struct __user range_entry *re = ((struct range_entry *)(copyhead + 1)); > > > > copy_from_user(&urk, re...); > > > > --D > > > Thanks, this is better. 'Reserved' field was there to be used for > future extension of the interface. > Now that you mentioned 'flags', it seems we can do away with > 'reserved' fields altogether? We still want the reserved-must-be-zero fields so that adding the first field or two doesn't require changes to the pointer arithmetic. Also, I suppose you could make the relationship between copy_range and range_entry more explicit: struct copy_range { __s64 dest_offset; __u32 nr_range_entries; __u32 flags; __u64 reserved[2]; /* must come last */ struct range_entry entries[]; }; struct __user range_entry *re = ©head->entries[0]; --D > > Regards, > Nitesh Shetty From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E177DC4338F for ; Wed, 18 Aug 2021 16:18:17 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A3A9060231 for ; Wed, 18 Aug 2021 16:18:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A3A9060231 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jXVTcOAxSh6ThmeFOudUzLz/yQOcJgq9C0RQ9Rztio8=; b=Hu67n37DP0DtNj iwB+gzOpFtM38Pb4TYNTnJAsCJXg3HCd3PgBY5R2OjWz8FDKxkxZt0Ypj99Qzz3YBM/SCdkVlLrDm kunPh5mvkN8Cy+z5brPwNNn2lUrO5YP6l8DiLbfMg4hAKitrJ6HEdbm9KN410hgKWr4/4XSB7C+qF ZCO7HP/MS4cFbgxaNIAclC3fvDUOh1TznzltI95ZP7N0ln2yEC8cARc81vm5DO04ybrJVQ4jH0JzF +Q99lDnposJnbm16zx/isoTAyw6DaAk2JyC/VY9FSbn/ppn7sKLIuOa1f+zOqYd2KwCNi4WOtZIAr ShvfNaFEmAyLLRTXxyGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mGOGI-0069k4-FB; Wed, 18 Aug 2021 16:17:54 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mGOGE-0069il-W6 for linux-nvme@lists.infradead.org; Wed, 18 Aug 2021 16:17:52 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8EDA6610A5; Wed, 18 Aug 2021 16:17:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629303470; bh=KPxieBci0vXg8rmYUy2so8SGtGACKhwfHUnpqQywB2U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YuZGxSb/qbJrnZ105zWsST1nzc3m5MixjmBIDb4Cqpf+Tw8XhntQlWVGRMwhIoXA7 PTtnTQEfAVvrGpcExRjt1ERSU8HOof1WS87z7lpzbE0XvNK4dmam1hUQ3Cb5tmEtl4 LQdsyFAHM06VRTXPscO6q5RGPRNYJ/p7auy1fidt0ulyrYV7J2rObWzPJh2wayByhW dD+K4DCpaPYtgRQUC0W7yQJz5RhyNsOdzq4PlthfwTFNMccSyBzUQf5XqVN5Xpf+0R eu2xlTZQILiBAamLWqT4orjL/dDPccR6l4KllQOYQis8vh+mMut2C5ziIwpIkHE3eK usfw3LYHare6w== Date: Wed, 18 Aug 2021 09:17:50 -0700 From: "Darrick J. Wong" To: Nitesh Shetty Cc: SelvaKumar S , linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-api@vger.kernel.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@redhat.com, kbusch@kernel.org, axboe@kernel.dk, damien.lemoal@wdc.com, asml.silence@gmail.com, johannes.thumshirn@wdc.com, hch@lst.de, willy@infradead.org, kch@kernel.org, martin.petersen@oracle.com, mpatocka@redhat.com, bvanassche@acm.org, snitzer@redhat.com, agk@redhat.com, selvajove@gmail.com, joshiiitr@gmail.com, nj.shetty@samsung.com, joshi.k@samsung.com, javier.gonz@samsung.com Subject: Re: [PATCH 4/7] block: Introduce a new ioctl for simple copy Message-ID: <20210818161750.GF12664@magnolia> References: <20210817101423.12367-1-selvakuma.s1@samsung.com> <20210817101423.12367-5-selvakuma.s1@samsung.com> <20210817233613.GA12597@magnolia> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210818_091751_156748_14C232E9 X-CRM114-Status: GOOD ( 33.86 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org On Wed, Aug 18, 2021 at 09:07:54PM +0530, Nitesh Shetty wrote: > On Wed, Aug 18, 2021 at 5:06 AM Darrick J. Wong wrote: > > > > On Tue, Aug 17, 2021 at 03:44:20PM +0530, SelvaKumar S wrote: > > > From: Nitesh Shetty > > > > > > Add new BLKCOPY ioctl that offloads copying of one or more sources ranges > > > to a destination in the device. COPY ioctl accepts a 'copy_range' > > > structure that contains destination (in sectors), no of sources and > > > pointer to the array of source ranges. Each source range is represented by > > > 'range_entry' that contains start and length of source ranges (in sectors) > > > > > > MAX_COPY_NR_RANGE, limits the number of entries for the IOCTL and > > > MAX_COPY_TOTAL_LENGTH limits the total copy length, IOCTL can handle. > > > > > > Example code, to issue BLKCOPY: > > > /* Sample example to copy three source-ranges [0, 8] [16, 8] [32,8] to > > > * [64,24], on the same device */ > > > > > > int main(void) > > > { > > > int ret, fd; > > > struct range_entry source_range[] = {{.src = 0, .len = 8}, > > > {.src = 16, .len = 8}, {.src = 32, .len = 8},}; > > > struct copy_range cr; > > > > > > cr.dest = 64; > > > cr.nr_range = 3; > > > cr.range_list = (__u64)&source_range; > > > > > > fd = open("/dev/nvme0n1", O_RDWR); > > > if (fd < 0) return 1; > > > > > > ret = ioctl(fd, BLKCOPY, &cr); > > > if (ret < 0) printf("copy failure\n"); > > > > > > close(fd); > > > > > > return ret; > > > } > > > > > > Signed-off-by: Nitesh Shetty > > > Signed-off-by: SelvaKumar S > > > Signed-off-by: Kanchan Joshi > > > --- > > > block/ioctl.c | 33 +++++++++++++++++++++++++++++++++ > > > include/uapi/linux/fs.h | 8 ++++++++ > > > 2 files changed, 41 insertions(+) > > > > > > diff --git a/block/ioctl.c b/block/ioctl.c > > > index eb0491e90b9a..2af56d01e9fe 100644 > > > --- a/block/ioctl.c > > > +++ b/block/ioctl.c > > > @@ -143,6 +143,37 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, > > > GFP_KERNEL, flags); > > > } > > > > > > +static int blk_ioctl_copy(struct block_device *bdev, fmode_t mode, > > > + unsigned long arg) > > > +{ > > > + struct copy_range crange; > > > + struct range_entry *rlist; > > > + int ret; > > > + > > > + if (!(mode & FMODE_WRITE)) > > > + return -EBADF; > > > + > > > + if (copy_from_user(&crange, (void __user *)arg, sizeof(crange))) > > > + return -EFAULT; > > > + > > > + rlist = kmalloc_array(crange.nr_range, sizeof(*rlist), > > > + GFP_KERNEL); > > > + if (!rlist) > > > + return -ENOMEM; > > > + > > > + if (copy_from_user(rlist, (void __user *)crange.range_list, > > > + sizeof(*rlist) * crange.nr_range)) { > > > + ret = -EFAULT; > > > + goto out; > > > + } > > > + > > > + ret = blkdev_issue_copy(bdev, crange.nr_range, rlist, bdev, crange.dest, > > > + GFP_KERNEL, 0); > > > +out: > > > + kfree(rlist); > > > + return ret; > > > +} > > > + > > > static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, > > > unsigned long arg) > > > { > > > @@ -468,6 +499,8 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, > > > case BLKSECDISCARD: > > > return blk_ioctl_discard(bdev, mode, arg, > > > BLKDEV_DISCARD_SECURE); > > > + case BLKCOPY: > > > + return blk_ioctl_copy(bdev, mode, arg); > > > case BLKZEROOUT: > > > return blk_ioctl_zeroout(bdev, mode, arg); > > > case BLKGETDISKSEQ: > > > diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h > > > index 7a97b588d892..4183688ff398 100644 > > > --- a/include/uapi/linux/fs.h > > > +++ b/include/uapi/linux/fs.h > > > @@ -76,6 +76,13 @@ struct range_entry { > > > __u64 len; > > > }; > > > > > > +struct copy_range { > > > + __u64 dest; > > > + __u64 nr_range; > > > > If the maximum number of elements in the range list is 1<<12, there's no > > need for this to be larger than a u16, right? > > > > > + __u64 range_list; > > > > Pointers embedded in a structure are /not/ a good idea, because this > > will create a lot of compatibility headaches for 32-bit binaries running > > on 64-bit kernels. Please just make the size of this header structure > > a multiple of 8 bytes and put the range_entry list immediately after it. > > > > struct copy_range { > > __s64 dest_offset; > > __u32 nr_range_entries; > > __u32 flags; > > __u64 reserved[2]; > > }; > > > > struct __user range_entry *re = ((struct range_entry *)(copyhead + 1)); > > > > copy_from_user(&urk, re...); > > > > --D > > > Thanks, this is better. 'Reserved' field was there to be used for > future extension of the interface. > Now that you mentioned 'flags', it seems we can do away with > 'reserved' fields altogether? We still want the reserved-must-be-zero fields so that adding the first field or two doesn't require changes to the pointer arithmetic. Also, I suppose you could make the relationship between copy_range and range_entry more explicit: struct copy_range { __s64 dest_offset; __u32 nr_range_entries; __u32 flags; __u64 reserved[2]; /* must come last */ struct range_entry entries[]; }; struct __user range_entry *re = ©head->entries[0]; --D > > Regards, > Nitesh Shetty _______________________________________________ Linux-nvme mailing list Linux-nvme@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10256C4338F for ; Wed, 18 Aug 2021 16:18:10 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 797B060231 for ; Wed, 18 Aug 2021 16:18:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 797B060231 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=tempfail smtp.mailfrom=redhat.com Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-218-ngg7NhJ2NOOzD5TPIOMaOg-1; Wed, 18 Aug 2021 12:18:06 -0400 X-MC-Unique: ngg7NhJ2NOOzD5TPIOMaOg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C2D21082925; Wed, 18 Aug 2021 16:18:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 651595DAA5; Wed, 18 Aug 2021 16:18:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F39DF4BB7C; Wed, 18 Aug 2021 16:18:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17IGHwOJ020444 for ; Wed, 18 Aug 2021 12:17:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id D016A2077FDF; Wed, 18 Aug 2021 16:17:58 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CA6E2204471A for ; Wed, 18 Aug 2021 16:17:56 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B36218A01A0 for ; Wed, 18 Aug 2021 16:17:56 +0000 (UTC) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-485-HdORhql6Oc6dOW-0J34rVw-1; Wed, 18 Aug 2021 12:17:52 -0400 X-MC-Unique: HdORhql6Oc6dOW-0J34rVw-1 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8EDA6610A5; Wed, 18 Aug 2021 16:17:50 +0000 (UTC) Date: Wed, 18 Aug 2021 09:17:50 -0700 From: "Darrick J. Wong" To: Nitesh Shetty Message-ID: <20210818161750.GF12664@magnolia> References: <20210817101423.12367-1-selvakuma.s1@samsung.com> <20210817101423.12367-5-selvakuma.s1@samsung.com> <20210817233613.GA12597@magnolia> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: dm-devel@redhat.com Cc: snitzer@redhat.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, hch@lst.de, agk@redhat.com, bvanassche@acm.org, linux-scsi@vger.kernel.org, willy@infradead.org, nj.shetty@samsung.com, kch@kernel.org, SelvaKumar S , selvajove@gmail.com, linux-block@vger.kernel.org, mpatocka@redhat.com, javier.gonz@samsung.com, kbusch@kernel.org, axboe@kernel.dk, damien.lemoal@wdc.com, joshi.k@samsung.com, martin.petersen@oracle.com, linux-api@vger.kernel.org, johannes.thumshirn@wdc.com, linux-fsdevel@vger.kernel.org, joshiiitr@gmail.com, asml.silence@gmail.com Subject: Re: [dm-devel] [PATCH 4/7] block: Introduce a new ioctl for simple copy X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dm-devel-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Wed, Aug 18, 2021 at 09:07:54PM +0530, Nitesh Shetty wrote: > On Wed, Aug 18, 2021 at 5:06 AM Darrick J. Wong wrote: > > > > On Tue, Aug 17, 2021 at 03:44:20PM +0530, SelvaKumar S wrote: > > > From: Nitesh Shetty > > > > > > Add new BLKCOPY ioctl that offloads copying of one or more sources ranges > > > to a destination in the device. COPY ioctl accepts a 'copy_range' > > > structure that contains destination (in sectors), no of sources and > > > pointer to the array of source ranges. Each source range is represented by > > > 'range_entry' that contains start and length of source ranges (in sectors) > > > > > > MAX_COPY_NR_RANGE, limits the number of entries for the IOCTL and > > > MAX_COPY_TOTAL_LENGTH limits the total copy length, IOCTL can handle. > > > > > > Example code, to issue BLKCOPY: > > > /* Sample example to copy three source-ranges [0, 8] [16, 8] [32,8] to > > > * [64,24], on the same device */ > > > > > > int main(void) > > > { > > > int ret, fd; > > > struct range_entry source_range[] = {{.src = 0, .len = 8}, > > > {.src = 16, .len = 8}, {.src = 32, .len = 8},}; > > > struct copy_range cr; > > > > > > cr.dest = 64; > > > cr.nr_range = 3; > > > cr.range_list = (__u64)&source_range; > > > > > > fd = open("/dev/nvme0n1", O_RDWR); > > > if (fd < 0) return 1; > > > > > > ret = ioctl(fd, BLKCOPY, &cr); > > > if (ret < 0) printf("copy failure\n"); > > > > > > close(fd); > > > > > > return ret; > > > } > > > > > > Signed-off-by: Nitesh Shetty > > > Signed-off-by: SelvaKumar S > > > Signed-off-by: Kanchan Joshi > > > --- > > > block/ioctl.c | 33 +++++++++++++++++++++++++++++++++ > > > include/uapi/linux/fs.h | 8 ++++++++ > > > 2 files changed, 41 insertions(+) > > > > > > diff --git a/block/ioctl.c b/block/ioctl.c > > > index eb0491e90b9a..2af56d01e9fe 100644 > > > --- a/block/ioctl.c > > > +++ b/block/ioctl.c > > > @@ -143,6 +143,37 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, > > > GFP_KERNEL, flags); > > > } > > > > > > +static int blk_ioctl_copy(struct block_device *bdev, fmode_t mode, > > > + unsigned long arg) > > > +{ > > > + struct copy_range crange; > > > + struct range_entry *rlist; > > > + int ret; > > > + > > > + if (!(mode & FMODE_WRITE)) > > > + return -EBADF; > > > + > > > + if (copy_from_user(&crange, (void __user *)arg, sizeof(crange))) > > > + return -EFAULT; > > > + > > > + rlist = kmalloc_array(crange.nr_range, sizeof(*rlist), > > > + GFP_KERNEL); > > > + if (!rlist) > > > + return -ENOMEM; > > > + > > > + if (copy_from_user(rlist, (void __user *)crange.range_list, > > > + sizeof(*rlist) * crange.nr_range)) { > > > + ret = -EFAULT; > > > + goto out; > > > + } > > > + > > > + ret = blkdev_issue_copy(bdev, crange.nr_range, rlist, bdev, crange.dest, > > > + GFP_KERNEL, 0); > > > +out: > > > + kfree(rlist); > > > + return ret; > > > +} > > > + > > > static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, > > > unsigned long arg) > > > { > > > @@ -468,6 +499,8 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, > > > case BLKSECDISCARD: > > > return blk_ioctl_discard(bdev, mode, arg, > > > BLKDEV_DISCARD_SECURE); > > > + case BLKCOPY: > > > + return blk_ioctl_copy(bdev, mode, arg); > > > case BLKZEROOUT: > > > return blk_ioctl_zeroout(bdev, mode, arg); > > > case BLKGETDISKSEQ: > > > diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h > > > index 7a97b588d892..4183688ff398 100644 > > > --- a/include/uapi/linux/fs.h > > > +++ b/include/uapi/linux/fs.h > > > @@ -76,6 +76,13 @@ struct range_entry { > > > __u64 len; > > > }; > > > > > > +struct copy_range { > > > + __u64 dest; > > > + __u64 nr_range; > > > > If the maximum number of elements in the range list is 1<<12, there's no > > need for this to be larger than a u16, right? > > > > > + __u64 range_list; > > > > Pointers embedded in a structure are /not/ a good idea, because this > > will create a lot of compatibility headaches for 32-bit binaries running > > on 64-bit kernels. Please just make the size of this header structure > > a multiple of 8 bytes and put the range_entry list immediately after it. > > > > struct copy_range { > > __s64 dest_offset; > > __u32 nr_range_entries; > > __u32 flags; > > __u64 reserved[2]; > > }; > > > > struct __user range_entry *re = ((struct range_entry *)(copyhead + 1)); > > > > copy_from_user(&urk, re...); > > > > --D > > > Thanks, this is better. 'Reserved' field was there to be used for > future extension of the interface. > Now that you mentioned 'flags', it seems we can do away with > 'reserved' fields altogether? We still want the reserved-must-be-zero fields so that adding the first field or two doesn't require changes to the pointer arithmetic. Also, I suppose you could make the relationship between copy_range and range_entry more explicit: struct copy_range { __s64 dest_offset; __u32 nr_range_entries; __u32 flags; __u64 reserved[2]; /* must come last */ struct range_entry entries[]; }; struct __user range_entry *re = ©head->entries[0]; --D > > Regards, > Nitesh Shetty -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel