3030#define VHOST_VSOCK_PKT_WEIGHT 256
3131
3232enum {
33- VHOST_VSOCK_FEATURES = VHOST_FEATURES ,
33+ VHOST_VSOCK_FEATURES = VHOST_FEATURES |
34+ (1ULL << VIRTIO_F_ACCESS_PLATFORM )
35+ };
36+
37+ enum {
38+ VHOST_VSOCK_BACKEND_FEATURES = (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2 )
3439};
3540
3641/* Used to track all the vhost_vsock instances on the system. */
@@ -94,6 +99,9 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
9499 if (!vhost_vq_get_backend (vq ))
95100 goto out ;
96101
102+ if (!vq_meta_prefetch (vq ))
103+ goto out ;
104+
97105 /* Avoid further vmexits, we're already processing the virtqueue */
98106 vhost_disable_notify (& vsock -> dev , vq );
99107
@@ -449,6 +457,9 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
449457 if (!vhost_vq_get_backend (vq ))
450458 goto out ;
451459
460+ if (!vq_meta_prefetch (vq ))
461+ goto out ;
462+
452463 vhost_disable_notify (& vsock -> dev , vq );
453464 do {
454465 u32 len ;
@@ -766,8 +777,12 @@ static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features)
766777 mutex_lock (& vsock -> dev .mutex );
767778 if ((features & (1 << VHOST_F_LOG_ALL )) &&
768779 !vhost_log_access_ok (& vsock -> dev )) {
769- mutex_unlock (& vsock -> dev .mutex );
770- return - EFAULT ;
780+ goto err ;
781+ }
782+
783+ if ((features & (1ULL << VIRTIO_F_ACCESS_PLATFORM ))) {
784+ if (vhost_init_device_iotlb (& vsock -> dev , true))
785+ goto err ;
771786 }
772787
773788 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)
778793 }
779794 mutex_unlock (& vsock -> dev .mutex );
780795 return 0 ;
796+
797+ err :
798+ mutex_unlock (& vsock -> dev .mutex );
799+ return - EFAULT ;
781800}
782801
783802static 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,
811830 if (copy_from_user (& features , argp , sizeof (features )))
812831 return - EFAULT ;
813832 return vhost_vsock_set_features (vsock , features );
833+ case VHOST_GET_BACKEND_FEATURES :
834+ features = VHOST_VSOCK_BACKEND_FEATURES ;
835+ if (copy_to_user (argp , & features , sizeof (features )))
836+ return - EFAULT ;
837+ return 0 ;
838+ case VHOST_SET_BACKEND_FEATURES :
839+ if (copy_from_user (& features , argp , sizeof (features )))
840+ return - EFAULT ;
841+ if (features & ~VHOST_VSOCK_BACKEND_FEATURES )
842+ return - EOPNOTSUPP ;
843+ vhost_set_backend_features (& vsock -> dev , features );
844+ return 0 ;
814845 default :
815846 mutex_lock (& vsock -> dev .mutex );
816847 r = vhost_dev_ioctl (& vsock -> dev , ioctl , argp );
@@ -823,13 +854,44 @@ static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl,
823854 }
824855}
825856
857+ static ssize_t vhost_vsock_chr_read_iter (struct kiocb * iocb , struct iov_iter * to )
858+ {
859+ struct file * file = iocb -> ki_filp ;
860+ struct vhost_vsock * vsock = file -> private_data ;
861+ struct vhost_dev * dev = & vsock -> dev ;
862+ int noblock = file -> f_flags & O_NONBLOCK ;
863+
864+ return vhost_chr_read_iter (dev , to , noblock );
865+ }
866+
867+ static ssize_t vhost_vsock_chr_write_iter (struct kiocb * iocb ,
868+ struct iov_iter * from )
869+ {
870+ struct file * file = iocb -> ki_filp ;
871+ struct vhost_vsock * vsock = file -> private_data ;
872+ struct vhost_dev * dev = & vsock -> dev ;
873+
874+ return vhost_chr_write_iter (dev , from );
875+ }
876+
877+ static __poll_t vhost_vsock_chr_poll (struct file * file , poll_table * wait )
878+ {
879+ struct vhost_vsock * vsock = file -> private_data ;
880+ struct vhost_dev * dev = & vsock -> dev ;
881+
882+ return vhost_chr_poll (file , dev , wait );
883+ }
884+
826885static const struct file_operations vhost_vsock_fops = {
827886 .owner = THIS_MODULE ,
828887 .open = vhost_vsock_dev_open ,
829888 .release = vhost_vsock_dev_release ,
830889 .llseek = noop_llseek ,
831890 .unlocked_ioctl = vhost_vsock_dev_ioctl ,
832891 .compat_ioctl = compat_ptr_ioctl ,
892+ .read_iter = vhost_vsock_chr_read_iter ,
893+ .write_iter = vhost_vsock_chr_write_iter ,
894+ .poll = vhost_vsock_chr_poll ,
833895};
834896
835897static struct miscdevice vhost_vsock_misc = {
0 commit comments