summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/vhost/vhost.c6
-rw-r--r--include/linux/uio.h1
-rw-r--r--lib/iovec.c25
3 files changed, 4 insertions, 28 deletions
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index cb807d0ea498..2ee28266fd07 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1125,6 +1125,7 @@ static int get_indirect(struct vhost_virtqueue *vq,
1125 struct vring_desc desc; 1125 struct vring_desc desc;
1126 unsigned int i = 0, count, found = 0; 1126 unsigned int i = 0, count, found = 0;
1127 u32 len = vhost32_to_cpu(vq, indirect->len); 1127 u32 len = vhost32_to_cpu(vq, indirect->len);
1128 struct iov_iter from;
1128 int ret; 1129 int ret;
1129 1130
1130 /* Sanity check */ 1131 /* Sanity check */
@@ -1142,6 +1143,7 @@ static int get_indirect(struct vhost_virtqueue *vq,
1142 vq_err(vq, "Translation failure %d in indirect.\n", ret); 1143 vq_err(vq, "Translation failure %d in indirect.\n", ret);
1143 return ret; 1144 return ret;
1144 } 1145 }
1146 iov_iter_init(&from, READ, vq->indirect, ret, len);
1145 1147
1146 /* We will use the result as an address to read from, so most 1148 /* We will use the result as an address to read from, so most
1147 * architectures only need a compiler barrier here. */ 1149 * architectures only need a compiler barrier here. */
@@ -1164,8 +1166,8 @@ static int get_indirect(struct vhost_virtqueue *vq,
1164 i, count); 1166 i, count);
1165 return -EINVAL; 1167 return -EINVAL;
1166 } 1168 }
1167 if (unlikely(memcpy_fromiovec((unsigned char *)&desc, 1169 if (unlikely(copy_from_iter(&desc, sizeof(desc), &from) !=
1168 vq->indirect, sizeof desc))) { 1170 sizeof(desc))) {
1169 vq_err(vq, "Failed indirect descriptor: idx %d, %zx\n", 1171 vq_err(vq, "Failed indirect descriptor: idx %d, %zx\n",
1170 i, (size_t)vhost64_to_cpu(vq, indirect->addr) + i * sizeof desc); 1172 i, (size_t)vhost64_to_cpu(vq, indirect->addr) + i * sizeof desc);
1171 return -EINVAL; 1173 return -EINVAL;
diff --git a/include/linux/uio.h b/include/linux/uio.h
index 1c5e453f7ea9..af3439f4ebf2 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -135,7 +135,6 @@ static inline void iov_iter_reexpand(struct iov_iter *i, size_t count)
135size_t csum_and_copy_to_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); 135size_t csum_and_copy_to_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i);
136size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); 136size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i);
137 137
138int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len);
139int memcpy_fromiovecend(unsigned char *kdata, const struct iovec *iov, 138int memcpy_fromiovecend(unsigned char *kdata, const struct iovec *iov,
140 int offset, int len); 139 int offset, int len);
141int memcpy_toiovecend(const struct iovec *v, unsigned char *kdata, 140int memcpy_toiovecend(const struct iovec *v, unsigned char *kdata,
diff --git a/lib/iovec.c b/lib/iovec.c
index 2d99cb4a5006..4a90875c64ae 100644
--- a/lib/iovec.c
+++ b/lib/iovec.c
@@ -3,31 +3,6 @@
3#include <linux/uio.h> 3#include <linux/uio.h>
4 4
5/* 5/*
6 * Copy iovec to kernel. Returns -EFAULT on error.
7 *
8 * Note: this modifies the original iovec.
9 */
10
11int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len)
12{
13 while (len > 0) {
14 if (iov->iov_len) {
15 int copy = min_t(unsigned int, len, iov->iov_len);
16 if (copy_from_user(kdata, iov->iov_base, copy))
17 return -EFAULT;
18 len -= copy;
19 kdata += copy;
20 iov->iov_base += copy;
21 iov->iov_len -= copy;
22 }
23 iov++;
24 }
25
26 return 0;
27}
28EXPORT_SYMBOL(memcpy_fromiovec);
29
30/*
31 * Copy kernel to iovec. Returns -EFAULT on error. 6 * Copy kernel to iovec. Returns -EFAULT on error.
32 */ 7 */
33 8