Lines Matching refs:n
161 static void vhost_net_clear_ubuf_info(struct vhost_net *n) in vhost_net_clear_ubuf_info() argument
166 kfree(n->vqs[i].ubuf_info); in vhost_net_clear_ubuf_info()
167 n->vqs[i].ubuf_info = NULL; in vhost_net_clear_ubuf_info()
171 static int vhost_net_set_ubuf_info(struct vhost_net *n) in vhost_net_set_ubuf_info() argument
180 n->vqs[i].ubuf_info = kmalloc(sizeof(*n->vqs[i].ubuf_info) * in vhost_net_set_ubuf_info()
182 if (!n->vqs[i].ubuf_info) in vhost_net_set_ubuf_info()
188 vhost_net_clear_ubuf_info(n); in vhost_net_set_ubuf_info()
192 static void vhost_net_vq_reset(struct vhost_net *n) in vhost_net_vq_reset() argument
196 vhost_net_clear_ubuf_info(n); in vhost_net_vq_reset()
199 n->vqs[i].done_idx = 0; in vhost_net_vq_reset()
200 n->vqs[i].upend_idx = 0; in vhost_net_vq_reset()
201 n->vqs[i].ubufs = NULL; in vhost_net_vq_reset()
202 n->vqs[i].vhost_hlen = 0; in vhost_net_vq_reset()
203 n->vqs[i].sock_hlen = 0; in vhost_net_vq_reset()
705 struct vhost_net *n; in vhost_net_open() local
710 n = kmalloc(sizeof *n, GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT); in vhost_net_open()
711 if (!n) { in vhost_net_open()
712 n = vmalloc(sizeof *n); in vhost_net_open()
713 if (!n) in vhost_net_open()
718 kvfree(n); in vhost_net_open()
722 dev = &n->dev; in vhost_net_open()
723 vqs[VHOST_NET_VQ_TX] = &n->vqs[VHOST_NET_VQ_TX].vq; in vhost_net_open()
724 vqs[VHOST_NET_VQ_RX] = &n->vqs[VHOST_NET_VQ_RX].vq; in vhost_net_open()
725 n->vqs[VHOST_NET_VQ_TX].vq.handle_kick = handle_tx_kick; in vhost_net_open()
726 n->vqs[VHOST_NET_VQ_RX].vq.handle_kick = handle_rx_kick; in vhost_net_open()
728 n->vqs[i].ubufs = NULL; in vhost_net_open()
729 n->vqs[i].ubuf_info = NULL; in vhost_net_open()
730 n->vqs[i].upend_idx = 0; in vhost_net_open()
731 n->vqs[i].done_idx = 0; in vhost_net_open()
732 n->vqs[i].vhost_hlen = 0; in vhost_net_open()
733 n->vqs[i].sock_hlen = 0; in vhost_net_open()
737 vhost_poll_init(n->poll + VHOST_NET_VQ_TX, handle_tx_net, POLLOUT, dev); in vhost_net_open()
738 vhost_poll_init(n->poll + VHOST_NET_VQ_RX, handle_rx_net, POLLIN, dev); in vhost_net_open()
740 f->private_data = n; in vhost_net_open()
745 static void vhost_net_disable_vq(struct vhost_net *n, in vhost_net_disable_vq() argument
750 struct vhost_poll *poll = n->poll + (nvq - n->vqs); in vhost_net_disable_vq()
756 static int vhost_net_enable_vq(struct vhost_net *n, in vhost_net_enable_vq() argument
761 struct vhost_poll *poll = n->poll + (nvq - n->vqs); in vhost_net_enable_vq()
771 static struct socket *vhost_net_stop_vq(struct vhost_net *n, in vhost_net_stop_vq() argument
778 vhost_net_disable_vq(n, vq); in vhost_net_stop_vq()
784 static void vhost_net_stop(struct vhost_net *n, struct socket **tx_sock, in vhost_net_stop() argument
787 *tx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_TX].vq); in vhost_net_stop()
788 *rx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_RX].vq); in vhost_net_stop()
791 static void vhost_net_flush_vq(struct vhost_net *n, int index) in vhost_net_flush_vq() argument
793 vhost_poll_flush(n->poll + index); in vhost_net_flush_vq()
794 vhost_poll_flush(&n->vqs[index].vq.poll); in vhost_net_flush_vq()
797 static void vhost_net_flush(struct vhost_net *n) in vhost_net_flush() argument
799 vhost_net_flush_vq(n, VHOST_NET_VQ_TX); in vhost_net_flush()
800 vhost_net_flush_vq(n, VHOST_NET_VQ_RX); in vhost_net_flush()
801 if (n->vqs[VHOST_NET_VQ_TX].ubufs) { in vhost_net_flush()
802 mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
803 n->tx_flush = true; in vhost_net_flush()
804 mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
806 vhost_net_ubuf_put_and_wait(n->vqs[VHOST_NET_VQ_TX].ubufs); in vhost_net_flush()
807 mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
808 n->tx_flush = false; in vhost_net_flush()
809 atomic_set(&n->vqs[VHOST_NET_VQ_TX].ubufs->refcount, 1); in vhost_net_flush()
810 mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
816 struct vhost_net *n = f->private_data; in vhost_net_release() local
820 vhost_net_stop(n, &tx_sock, &rx_sock); in vhost_net_release()
821 vhost_net_flush(n); in vhost_net_release()
822 vhost_dev_stop(&n->dev); in vhost_net_release()
823 vhost_dev_cleanup(&n->dev, false); in vhost_net_release()
824 vhost_net_vq_reset(n); in vhost_net_release()
833 vhost_net_flush(n); in vhost_net_release()
834 kfree(n->dev.vqs); in vhost_net_release()
835 kvfree(n); in vhost_net_release()
904 static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd) in vhost_net_set_backend() argument
912 mutex_lock(&n->dev.mutex); in vhost_net_set_backend()
913 r = vhost_dev_check_owner(&n->dev); in vhost_net_set_backend()
921 vq = &n->vqs[index].vq; in vhost_net_set_backend()
922 nvq = &n->vqs[index]; in vhost_net_set_backend()
946 vhost_net_disable_vq(n, vq); in vhost_net_set_backend()
951 r = vhost_net_enable_vq(n, vq); in vhost_net_set_backend()
958 n->tx_packets = 0; in vhost_net_set_backend()
959 n->tx_zcopy_err = 0; in vhost_net_set_backend()
960 n->tx_flush = false; in vhost_net_set_backend()
968 vhost_zerocopy_signal_used(n, vq); in vhost_net_set_backend()
973 vhost_net_flush_vq(n, index); in vhost_net_set_backend()
977 mutex_unlock(&n->dev.mutex); in vhost_net_set_backend()
982 vhost_net_enable_vq(n, vq); in vhost_net_set_backend()
990 mutex_unlock(&n->dev.mutex); in vhost_net_set_backend()
994 static long vhost_net_reset_owner(struct vhost_net *n) in vhost_net_reset_owner() argument
1001 mutex_lock(&n->dev.mutex); in vhost_net_reset_owner()
1002 err = vhost_dev_check_owner(&n->dev); in vhost_net_reset_owner()
1010 vhost_net_stop(n, &tx_sock, &rx_sock); in vhost_net_reset_owner()
1011 vhost_net_flush(n); in vhost_net_reset_owner()
1012 vhost_dev_reset_owner(&n->dev, memory); in vhost_net_reset_owner()
1013 vhost_net_vq_reset(n); in vhost_net_reset_owner()
1015 mutex_unlock(&n->dev.mutex); in vhost_net_reset_owner()
1023 static int vhost_net_set_features(struct vhost_net *n, u64 features) in vhost_net_set_features() argument
1040 mutex_lock(&n->dev.mutex); in vhost_net_set_features()
1042 !vhost_log_access_ok(&n->dev)) { in vhost_net_set_features()
1043 mutex_unlock(&n->dev.mutex); in vhost_net_set_features()
1047 mutex_lock(&n->vqs[i].vq.mutex); in vhost_net_set_features()
1048 n->vqs[i].vq.acked_features = features; in vhost_net_set_features()
1049 n->vqs[i].vhost_hlen = vhost_hlen; in vhost_net_set_features()
1050 n->vqs[i].sock_hlen = sock_hlen; in vhost_net_set_features()
1051 mutex_unlock(&n->vqs[i].vq.mutex); in vhost_net_set_features()
1053 mutex_unlock(&n->dev.mutex); in vhost_net_set_features()
1057 static long vhost_net_set_owner(struct vhost_net *n) in vhost_net_set_owner() argument
1061 mutex_lock(&n->dev.mutex); in vhost_net_set_owner()
1062 if (vhost_dev_has_owner(&n->dev)) { in vhost_net_set_owner()
1066 r = vhost_net_set_ubuf_info(n); in vhost_net_set_owner()
1069 r = vhost_dev_set_owner(&n->dev); in vhost_net_set_owner()
1071 vhost_net_clear_ubuf_info(n); in vhost_net_set_owner()
1072 vhost_net_flush(n); in vhost_net_set_owner()
1074 mutex_unlock(&n->dev.mutex); in vhost_net_set_owner()
1081 struct vhost_net *n = f->private_data; in vhost_net_ioctl() local
1092 return vhost_net_set_backend(n, backend.index, backend.fd); in vhost_net_ioctl()
1103 return vhost_net_set_features(n, features); in vhost_net_ioctl()
1105 return vhost_net_reset_owner(n); in vhost_net_ioctl()
1107 return vhost_net_set_owner(n); in vhost_net_ioctl()
1109 mutex_lock(&n->dev.mutex); in vhost_net_ioctl()
1110 r = vhost_dev_ioctl(&n->dev, ioctl, argp); in vhost_net_ioctl()
1112 r = vhost_vring_ioctl(&n->dev, ioctl, argp); in vhost_net_ioctl()
1114 vhost_net_flush(n); in vhost_net_ioctl()
1115 mutex_unlock(&n->dev.mutex); in vhost_net_ioctl()