diff mbox series

[26/27] iov_iter: add import_kvec()

Message ID 20181130165646.27341-27-axboe@kernel.dk (mailing list archive)
State New, archived
Headers show
Series [01/27] aio: fix failure to put the file pointer | expand

Commit Message

Jens Axboe Nov. 30, 2018, 4:56 p.m. UTC
This explicitly sets up an ITER_KVEC from an iovec with kernel ranges
mapped.

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

Comments

Al Viro Nov. 30, 2018, 7:17 p.m. UTC | #1
On Fri, Nov 30, 2018 at 09:56:45AM -0700, Jens Axboe wrote:
> This explicitly sets up an ITER_KVEC from an iovec with kernel ranges
> mapped.

> +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;
> +}

What the hell is wrong with existing iov_iter_kvec()?
Jens Axboe Nov. 30, 2018, 8:15 p.m. UTC | #2
On 11/30/18 12:17 PM, Al Viro wrote:
> On Fri, Nov 30, 2018 at 09:56:45AM -0700, Jens Axboe wrote:
>> This explicitly sets up an ITER_KVEC from an iovec with kernel ranges
>> mapped.
> 
>> +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;
>> +}
> 
> What the hell is wrong with existing iov_iter_kvec()?

Hah, looks like I overlooked that. Not sure how anyone could look at
lib/iov_iter.c and not get lost in the beauty of it.
diff mbox series

Patch

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>