[PATCH 26/27] iov_iter: add import_kvec()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This explicitly sets up an ITER_KVEC from an iovec with kernel ranges
mapped.

Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
 include/linux/uio.h |  3 +++
 lib/iov_iter.c      | 35 ++++++++++++++++++++++++++---------
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/include/linux/uio.h b/include/linux/uio.h
index 55ce99ddb912..bbefdb421f6d 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -284,6 +284,9 @@ int compat_import_iovec(int type, const struct compat_iovec __user * uvector,
 int import_single_range(int type, void __user *buf, size_t len,
 		 struct iovec *iov, struct iov_iter *i);
 
+int import_kvec(int type, const struct kvec *kvecs, unsigned nr_segs,
+		size_t bytes, struct iov_iter *iter);
+
 int iov_iter_for_each_range(struct iov_iter *i, size_t bytes,
 			    int (*f)(struct kvec *vec, void *context),
 			    void *context);
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 7ebccb5c1637..a5b6dd691f37 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -431,25 +431,33 @@ int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes)
 }
 EXPORT_SYMBOL(iov_iter_fault_in_readable);
 
-void iov_iter_init(struct iov_iter *i, unsigned int direction,
-			const struct iovec *iov, unsigned long nr_segs,
-			size_t count)
+static void iov_iter_init_type(struct iov_iter *i, int type,
+			unsigned int direction, const struct iovec *iov,
+			unsigned long nr_segs, size_t count)
 {
 	WARN_ON(direction & ~(READ | WRITE));
 	direction &= READ | WRITE;
 
-	/* It will get better.  Eventually... */
-	if (uaccess_kernel()) {
-		i->type = ITER_KVEC | direction;
+	i->type = type | direction;
+	if (i->type == ITER_KVEC)
 		i->kvec = (struct kvec *)iov;
-	} else {
-		i->type = ITER_IOVEC | direction;
+	else
 		i->iov = iov;
-	}
+
 	i->nr_segs = nr_segs;
 	i->iov_offset = 0;
 	i->count = count;
 }
+
+void iov_iter_init(struct iov_iter *i, unsigned int direction,
+			const struct iovec *iov, unsigned long nr_segs,
+			size_t count)
+{
+	/* It will get better.  Eventually... */
+	int type = uaccess_kernel() ? ITER_KVEC : ITER_IOVEC;
+
+	iov_iter_init_type(i, type, direction, iov, nr_segs, count);
+}
 EXPORT_SYMBOL(iov_iter_init);
 
 static void memcpy_from_page(char *to, struct page *page, size_t offset, size_t len)
@@ -1582,6 +1590,15 @@ int import_iovec(int type, const struct iovec __user * uvector,
 }
 EXPORT_SYMBOL(import_iovec);
 
+int import_kvec(int type, const struct kvec *kvecs, unsigned nr_segs,
+		size_t bytes, struct iov_iter *iter)
+{
+	const struct iovec *p = (const struct iovec *) kvecs;
+
+	iov_iter_init_type(iter, ITER_KVEC, type, p, nr_segs, bytes);
+	return 0;
+}
+
 #ifdef CONFIG_COMPAT
 #include <linux/compat.h>
 
-- 
2.17.1




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux