30
30
#define VHOST_VSOCK_PKT_WEIGHT 256
31
31
32
32
enum {
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 )
34
39
};
35
40
36
41
/* 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
99
if (!vhost_vq_get_backend (vq ))
95
100
goto out ;
96
101
102
+ if (!vq_meta_prefetch (vq ))
103
+ goto out ;
104
+
97
105
/* Avoid further vmexits, we're already processing the virtqueue */
98
106
vhost_disable_notify (& vsock -> dev , vq );
99
107
@@ -449,6 +457,9 @@ static void vhost_vsock_handle_tx_kick(struct vhost_work *work)
449
457
if (!vhost_vq_get_backend (vq ))
450
458
goto out ;
451
459
460
+ if (!vq_meta_prefetch (vq ))
461
+ goto out ;
462
+
452
463
vhost_disable_notify (& vsock -> dev , vq );
453
464
do {
454
465
u32 len ;
@@ -766,8 +777,12 @@ static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features)
766
777
mutex_lock (& vsock -> dev .mutex );
767
778
if ((features & (1 << VHOST_F_LOG_ALL )) &&
768
779
!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 ;
771
786
}
772
787
773
788
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
793
}
779
794
mutex_unlock (& vsock -> dev .mutex );
780
795
return 0 ;
796
+
797
+ err :
798
+ mutex_unlock (& vsock -> dev .mutex );
799
+ return - EFAULT ;
781
800
}
782
801
783
802
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
830
if (copy_from_user (& features , argp , sizeof (features )))
812
831
return - EFAULT ;
813
832
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 ;
814
845
default :
815
846
mutex_lock (& vsock -> dev .mutex );
816
847
r = vhost_dev_ioctl (& vsock -> dev , ioctl , argp );
@@ -823,13 +854,44 @@ static long vhost_vsock_dev_ioctl(struct file *f, unsigned int ioctl,
823
854
}
824
855
}
825
856
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
+
826
885
static const struct file_operations vhost_vsock_fops = {
827
886
.owner = THIS_MODULE ,
828
887
.open = vhost_vsock_dev_open ,
829
888
.release = vhost_vsock_dev_release ,
830
889
.llseek = noop_llseek ,
831
890
.unlocked_ioctl = vhost_vsock_dev_ioctl ,
832
891
.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 ,
833
895
};
834
896
835
897
static struct miscdevice vhost_vsock_misc = {
0 commit comments