diff mbox series

[for-next,v11,11/13] block: add blk_rq_map_user_io

Message ID 20220929120632.64749-12-anuj20.g@samsung.com (mailing list archive)
State Superseded
Headers show
Series [for-next,v11,01/13] io_uring: add io_uring_cmd_import_fixed | expand

Commit Message

Anuj Gupta Sept. 29, 2022, 12:06 p.m. UTC
Create a helper blk_rq_map_user_io for mapping of vectored as well as
non-vectored requests. This will help in saving dupilcation of code at few
places in scsi and nvme.

Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Suggested-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-map.c        | 36 ++++++++++++++++++++++++++++++++++++
 include/linux/blk-mq.h |  2 ++
 2 files changed, 38 insertions(+)

Comments

Christoph Hellwig Sept. 29, 2022, 1:28 p.m. UTC | #1
On Thu, Sep 29, 2022 at 05:36:30PM +0530, Anuj Gupta wrote:
> Create a helper blk_rq_map_user_io for mapping of vectored as well as
> non-vectored requests. This will help in saving dupilcation of code at few
> places in scsi and nvme.
> 
> Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
> Suggested-by: Christoph Hellwig <hch@lst.de>

This looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

but it should be early on in this series.  Certainly before the fixebufs
addition, and probably also before the nvme refactoring.
kernel test robot Sept. 30, 2022, 4:15 a.m. UTC | #2
Hi Anuj,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on axboe-block/for-next]
[also build test WARNING on next-20220929]
[cannot apply to mkp-scsi/for-next jejb-scsi/for-next linus/master v6.0-rc7]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Anuj-Gupta/io_uring-add-io_uring_cmd_import_fixed/20220929-210700
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
config: x86_64-randconfig-a005
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/68e5d069227ee13ab1d6cd51a78f83d12db14608
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Anuj-Gupta/io_uring-add-io_uring_cmd_import_fixed/20220929-210700
        git checkout 68e5d069227ee13ab1d6cd51a78f83d12db14608
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> block/blk-map.c:720:13: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
           } else if (buf_len) {
                      ^~~~~~~
   block/blk-map.c:724:9: note: uninitialized use occurs here
           return ret;
                  ^~~
   block/blk-map.c:720:9: note: remove the 'if' if its condition is always true
           } else if (buf_len) {
                  ^~~~~~~~~~~~~
   block/blk-map.c:696:9: note: initialize the variable 'ret' to silence this warning
           int ret;
                  ^
                   = 0
   1 warning generated.


vim +720 block/blk-map.c

   691	
   692	int blk_rq_map_user_io(struct request *req, struct rq_map_data *map_data,
   693			void __user *ubuf, unsigned long buf_len, gfp_t gfp_mask,
   694			bool vec, int iov_count, bool check_iter_count, int rw)
   695	{
   696		int ret;
   697	
   698		if (vec) {
   699			struct iovec fast_iov[UIO_FASTIOV];
   700			struct iovec *iov = fast_iov;
   701			struct iov_iter iter;
   702	
   703			ret = import_iovec(rw, ubuf, iov_count ? iov_count : buf_len,
   704					UIO_FASTIOV, &iov, &iter);
   705			if (ret < 0)
   706				return ret;
   707	
   708			if (iov_count) {
   709				/* SG_IO howto says that the shorter of the two wins */
   710				iov_iter_truncate(&iter, buf_len);
   711				if (check_iter_count && !iov_iter_count(&iter)) {
   712					kfree(iov);
   713					return -EINVAL;
   714				}
   715			}
   716	
   717			ret = blk_rq_map_user_iov(req->q, req, map_data, &iter,
   718					gfp_mask);
   719			kfree(iov);
 > 720		} else if (buf_len) {
   721			ret = blk_rq_map_user(req->q, req, map_data, ubuf, buf_len,
   722					gfp_mask);
   723		}
   724		return ret;
   725	}
   726	EXPORT_SYMBOL(blk_rq_map_user_io);
   727
diff mbox series

Patch

diff --git a/block/blk-map.c b/block/blk-map.c
index ffab5d2d8d6d..74ee496c2d3a 100644
--- a/block/blk-map.c
+++ b/block/blk-map.c
@@ -689,6 +689,42 @@  int blk_rq_map_user(struct request_queue *q, struct request *rq,
 }
 EXPORT_SYMBOL(blk_rq_map_user);
 
+int blk_rq_map_user_io(struct request *req, struct rq_map_data *map_data,
+		void __user *ubuf, unsigned long buf_len, gfp_t gfp_mask,
+		bool vec, int iov_count, bool check_iter_count, int rw)
+{
+	int ret;
+
+	if (vec) {
+		struct iovec fast_iov[UIO_FASTIOV];
+		struct iovec *iov = fast_iov;
+		struct iov_iter iter;
+
+		ret = import_iovec(rw, ubuf, iov_count ? iov_count : buf_len,
+				UIO_FASTIOV, &iov, &iter);
+		if (ret < 0)
+			return ret;
+
+		if (iov_count) {
+			/* SG_IO howto says that the shorter of the two wins */
+			iov_iter_truncate(&iter, buf_len);
+			if (check_iter_count && !iov_iter_count(&iter)) {
+				kfree(iov);
+				return -EINVAL;
+			}
+		}
+
+		ret = blk_rq_map_user_iov(req->q, req, map_data, &iter,
+				gfp_mask);
+		kfree(iov);
+	} else if (buf_len) {
+		ret = blk_rq_map_user(req->q, req, map_data, ubuf, buf_len,
+				gfp_mask);
+	}
+	return ret;
+}
+EXPORT_SYMBOL(blk_rq_map_user_io);
+
 /**
  * blk_rq_unmap_user - unmap a request with user data
  * @bio:	       start of bio list
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 50811d0fb143..ba18e9bdb799 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -985,6 +985,8 @@  struct rq_map_data {
 
 int blk_rq_map_user(struct request_queue *, struct request *,
 		struct rq_map_data *, void __user *, unsigned long, gfp_t);
+int blk_rq_map_user_io(struct request *, struct rq_map_data *,
+		void __user *, unsigned long, gfp_t, bool, int, bool, int);
 int blk_rq_map_user_iov(struct request_queue *, struct request *,
 		struct rq_map_data *, const struct iov_iter *, gfp_t);
 int blk_rq_unmap_user(struct bio *);