Message ID | 20220207141348.4235-5-nj.shetty@samsung.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add Copy offload support | expand |
Hi Nitesh, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on axboe-block/for-next] [also build test WARNING on next-20220208] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch] url: https://github.com/0day-ci/linux/commits/Nitesh-Shetty/block-make-bio_map_kern-non-static/20220207-231407 base: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next config: i386-randconfig-c001 (https://download.01.org/0day-ci/archive/20220209/202202091048.qDQvi6ab-lkp@intel.com/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> cocci warnings: (new ones prefixed by >>) >> block/ioctl.c:145:10-17: WARNING opportunity for memdup_user vim +145 block/ioctl.c 126 127 static int blk_ioctl_copy(struct block_device *bdev, fmode_t mode, 128 unsigned long arg) 129 { 130 struct copy_range crange, *ranges; 131 size_t payload_size = 0; 132 int ret; 133 134 if (!(mode & FMODE_WRITE)) 135 return -EBADF; 136 137 if (copy_from_user(&crange, (void __user *)arg, sizeof(crange))) 138 return -EFAULT; 139 140 if (unlikely(!crange.nr_range || crange.reserved || crange.nr_range >= MAX_COPY_NR_RANGE)) 141 return -EINVAL; 142 143 payload_size = (crange.nr_range * sizeof(struct range_entry)) + sizeof(crange); 144 > 145 ranges = kmalloc(payload_size, GFP_KERNEL); 146 if (!ranges) 147 return -ENOMEM; 148 149 if (copy_from_user(ranges, (void __user *)arg, payload_size)) { 150 ret = -EFAULT; 151 goto out; 152 } 153 154 ret = blkdev_issue_copy(bdev, ranges->nr_range, ranges->range_list, bdev, GFP_KERNEL, 0); 155 if (copy_to_user((void __user *)arg, ranges, payload_size)) 156 ret = -EFAULT; 157 out: 158 kfree(ranges); 159 return ret; 160 } 161 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff --git a/block/ioctl.c b/block/ioctl.c index 4a86340133e4..d77f6143287e 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -124,6 +124,41 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, return err; } +static int blk_ioctl_copy(struct block_device *bdev, fmode_t mode, + unsigned long arg) +{ + struct copy_range crange, *ranges; + size_t payload_size = 0; + int ret; + + if (!(mode & FMODE_WRITE)) + return -EBADF; + + if (copy_from_user(&crange, (void __user *)arg, sizeof(crange))) + return -EFAULT; + + if (unlikely(!crange.nr_range || crange.reserved || crange.nr_range >= MAX_COPY_NR_RANGE)) + return -EINVAL; + + payload_size = (crange.nr_range * sizeof(struct range_entry)) + sizeof(crange); + + ranges = kmalloc(payload_size, GFP_KERNEL); + if (!ranges) + return -ENOMEM; + + if (copy_from_user(ranges, (void __user *)arg, payload_size)) { + ret = -EFAULT; + goto out; + } + + ret = blkdev_issue_copy(bdev, ranges->nr_range, ranges->range_list, bdev, GFP_KERNEL, 0); + if (copy_to_user((void __user *)arg, ranges, payload_size)) + ret = -EFAULT; +out: + kfree(ranges); + return ret; +} + static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, unsigned long arg) { @@ -455,6 +490,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 55bca8f6e8ed..190911ea4311 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -78,6 +78,14 @@ struct range_entry { __u64 comp_len; }; +struct copy_range { + __u64 nr_range; + __u64 reserved; + + /* Range_list always must be at the end */ + struct range_entry range_list[]; +}; + /* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */ #define FILE_DEDUPE_RANGE_SAME 0 #define FILE_DEDUPE_RANGE_DIFFERS 1 @@ -199,6 +207,7 @@ struct fsxattr { #define BLKROTATIONAL _IO(0x12,126) #define BLKZEROOUT _IO(0x12,127) #define BLKGETDISKSEQ _IOR(0x12,128,__u64) +#define BLKCOPY _IOWR(0x12, 129, struct copy_range) /* * A jump here: 130-136 are reserved for zoned block devices * (see uapi/linux/blkzoned.h)