Commit 9f1abbe9 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost

Pull vhost bugfix from Michael Tsirkin:
 "This fixes configs with vhost vsock behind a viommu"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
  vhost/vsock: add IOTLB API support
parents 1d011777 e13a6915
...@@ -30,7 +30,12 @@ ...@@ -30,7 +30,12 @@
#define VHOST_VSOCK_PKT_WEIGHT 256 #define VHOST_VSOCK_PKT_WEIGHT 256
enum { enum {
VHOST_VSOCK_FEATURES = VHOST_FEATURES, VHOST_VSOCK_FEATURES = VHOST_FEATURES |
(1ULL << VIRTIO_F_ACCESS_PLATFORM)
};
enum {
VHOST_VSOCK_BACKEND_FEATURES = (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2)
}; };
/* Used to track all the vhost_vsock instances on the system. */ /* Used to track all the vhost_vsock instances on the system. */
...@@ -94,6 +99,9 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock, ...@@ -94,6 +99,9 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
if (!vhost_vq_get_backend(vq)) if (!vhost_vq_get_backend(vq))
goto out; goto out;
if (!vq_meta_prefetch(vq))
goto out;
/* Avoid further vmexits, we're already processing the virtqueue */ /* Avoid further vmexits, we're already processing the virtqueue */
vhost_disable_notify(&vsock->dev, vq); vhost_disable_notify(&vsock->dev, vq);
...@@ -449,6 +457,9 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work) ...@@ -449,6 +457,9 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
if (!vhost_vq_get_backend(vq)) if (!vhost_vq_get_backend(vq))
goto out; goto out;
if (!vq_meta_prefetch(vq))
goto out;
vhost_disable_notify(&vsock->dev, vq); vhost_disable_notify(&vsock->dev, vq);
do { do {
u32 len; u32 len;
...@@ -766,8 +777,12 @@ static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features) ...@@ -766,8 +777,12 @@ static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features)
mutex_lock(&vsock->dev.mutex); mutex_lock(&vsock->dev.mutex);
if ((features & (1 << VHOST_F_LOG_ALL)) && if ((features & (1 << VHOST_F_LOG_ALL)) &&
!vhost_log_access_ok(&vsock->dev)) { !vhost_log_access_ok(&vsock->dev)) {
mutex_unlock(&vsock->dev.mutex); goto err;
return -EFAULT; }
if ((features & (1ULL << VIRTIO_F_ACCESS_PLATFORM))) {
if (vhost_init_device_iotlb(&vsock->dev, true))
goto err;
} }
for (i = 0; i < ARRAY_SIZE(vsock->vqs); i++) { for (i = 0; i < ARRAY_SIZE(vsock->vqs); i++) {
...@@ -778,6 +793,10 @@ static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features) ...@@ -778,6 +793,10 @@ static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features)
} }
mutex_unlock(&vsock->dev.mutex); mutex_unlock(&vsock->dev.mutex);
return 0; return 0;
err:
mutex_unlock(&vsock->dev.mutex);
return -EFAULT;
} }
static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl, static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl,
...@@ -811,6 +830,18 @@ static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl, ...@@ -811,6 +830,18 @@ static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl,
if (copy_from_user(&features, argp, sizeof(features))) if (copy_from_user(&features, argp, sizeof(features)))
return -EFAULT; return -EFAULT;
return vhost_vsock_set_features(vsock, features); return vhost_vsock_set_features(vsock, features);
case VHOST_GET_BACKEND_FEATURES:
features = VHOST_VSOCK_BACKEND_FEATURES;
if (copy_to_user(argp, &features, sizeof(features)))
return -EFAULT;
return 0;
case VHOST_SET_BACKEND_FEATURES:
if (copy_from_user(&features, argp, sizeof(features)))
return -EFAULT;
if (features & ~VHOST_VSOCK_BACKEND_FEATURES)
return -EOPNOTSUPP;
vhost_set_backend_features(&vsock->dev, features);
return 0;
default: default:
mutex_lock(&vsock->dev.mutex); mutex_lock(&vsock->dev.mutex);
r = vhost_dev_ioctl(&vsock->dev, ioctl, argp); r = vhost_dev_ioctl(&vsock->dev, ioctl, argp);
...@@ -823,6 +854,34 @@ static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl, ...@@ -823,6 +854,34 @@ static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl,
} }
} }
static ssize_t vhost_vsock_chr_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
struct file *file = iocb->ki_filp;
struct vhost_vsock *vsock = file->private_data;
struct vhost_dev *dev = &vsock->dev;
int noblock = file->f_flags & O_NONBLOCK;
return vhost_chr_read_iter(dev, to, noblock);
}
static ssize_t vhost_vsock_chr_write_iter(struct kiocb *iocb,
struct iov_iter *from)
{
struct file *file = iocb->ki_filp;
struct vhost_vsock *vsock = file->private_data;
struct vhost_dev *dev = &vsock->dev;
return vhost_chr_write_iter(dev, from);
}
static __poll_t vhost_vsock_chr_poll(struct file *file, poll_table *wait)
{
struct vhost_vsock *vsock = file->private_data;
struct vhost_dev *dev = &vsock->dev;
return vhost_chr_poll(file, dev, wait);
}
static const struct file_operations vhost_vsock_fops = { static const struct file_operations vhost_vsock_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = vhost_vsock_dev_open, .open = vhost_vsock_dev_open,
...@@ -830,6 +889,9 @@ static const struct file_operations vhost_vsock_fops = { ...@@ -830,6 +889,9 @@ static const struct file_operations vhost_vsock_fops = {
.llseek = noop_llseek, .llseek = noop_llseek,
.unlocked_ioctl = vhost_vsock_dev_ioctl, .unlocked_ioctl = vhost_vsock_dev_ioctl,
.compat_ioctl = compat_ptr_ioctl, .compat_ioctl = compat_ptr_ioctl,
.read_iter = vhost_vsock_chr_read_iter,
.write_iter = vhost_vsock_chr_write_iter,
.poll = vhost_vsock_chr_poll,
}; };
static struct miscdevice vhost_vsock_misc = { static struct miscdevice vhost_vsock_misc = {
......
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