Commit aad9a1ce authored by Al Viro's avatar Al Viro

vhost: switch vhost get_indirect() to iov_iter, kill memcpy_fromiovec()

Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: kvm@vger.kernel.org
Cc: virtualization@lists.linux-foundation.org
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 8ae5e030
...@@ -1125,6 +1125,7 @@ static int get_indirect(struct vhost_virtqueue *vq, ...@@ -1125,6 +1125,7 @@ static int get_indirect(struct vhost_virtqueue *vq,
struct vring_desc desc; struct vring_desc desc;
unsigned int i = 0, count, found = 0; unsigned int i = 0, count, found = 0;
u32 len = vhost32_to_cpu(vq, indirect->len); u32 len = vhost32_to_cpu(vq, indirect->len);
struct iov_iter from;
int ret; int ret;
/* Sanity check */ /* Sanity check */
...@@ -1142,6 +1143,7 @@ static int get_indirect(struct vhost_virtqueue *vq, ...@@ -1142,6 +1143,7 @@ static int get_indirect(struct vhost_virtqueue *vq,
vq_err(vq, "Translation failure %d in indirect.\n", ret); vq_err(vq, "Translation failure %d in indirect.\n", ret);
return ret; return ret;
} }
iov_iter_init(&from, READ, vq->indirect, ret, len);
/* We will use the result as an address to read from, so most /* We will use the result as an address to read from, so most
* architectures only need a compiler barrier here. */ * architectures only need a compiler barrier here. */
...@@ -1164,8 +1166,8 @@ static int get_indirect(struct vhost_virtqueue *vq, ...@@ -1164,8 +1166,8 @@ static int get_indirect(struct vhost_virtqueue *vq,
i, count); i, count);
return -EINVAL; return -EINVAL;
} }
if (unlikely(memcpy_fromiovec((unsigned char *)&desc, if (unlikely(copy_from_iter(&desc, sizeof(desc), &from) !=
vq->indirect, sizeof desc))) { sizeof(desc))) {
vq_err(vq, "Failed indirect descriptor: idx %d, %zx\n", vq_err(vq, "Failed indirect descriptor: idx %d, %zx\n",
i, (size_t)vhost64_to_cpu(vq, indirect->addr) + i * sizeof desc); i, (size_t)vhost64_to_cpu(vq, indirect->addr) + i * sizeof desc);
return -EINVAL; return -EINVAL;
......
...@@ -135,7 +135,6 @@ static inline void iov_iter_reexpand(struct iov_iter *i, size_t count) ...@@ -135,7 +135,6 @@ static inline void iov_iter_reexpand(struct iov_iter *i, size_t count)
size_t csum_and_copy_to_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); size_t csum_and_copy_to_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i);
size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i);
int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len);
int memcpy_fromiovecend(unsigned char *kdata, const struct iovec *iov, int memcpy_fromiovecend(unsigned char *kdata, const struct iovec *iov,
int offset, int len); int offset, int len);
int memcpy_toiovecend(const struct iovec *v, unsigned char *kdata, int memcpy_toiovecend(const struct iovec *v, unsigned char *kdata,
......
...@@ -2,31 +2,6 @@ ...@@ -2,31 +2,6 @@
#include <linux/export.h> #include <linux/export.h>
#include <linux/uio.h> #include <linux/uio.h>
/*
* Copy iovec to kernel. Returns -EFAULT on error.
*
* Note: this modifies the original iovec.
*/
int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len)
{
while (len > 0) {
if (iov->iov_len) {
int copy = min_t(unsigned int, len, iov->iov_len);
if (copy_from_user(kdata, iov->iov_base, copy))
return -EFAULT;
len -= copy;
kdata += copy;
iov->iov_base += copy;
iov->iov_len -= copy;
}
iov++;
}
return 0;
}
EXPORT_SYMBOL(memcpy_fromiovec);
/* /*
* Copy kernel to iovec. Returns -EFAULT on error. * Copy kernel to iovec. Returns -EFAULT on error.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment