net.c (2e26af79b7e24e9644a6c16ad4dca61501fb4b3f) | net.c (22fa90c7fb479694d6affebc049d21f06b714be6) |
---|---|
1/* Copyright (C) 2009 Red Hat, Inc. 2 * Author: Michael S. Tsirkin <mst@redhat.com> 3 * 4 * This work is licensed under the terms of the GNU GPL, version 2. 5 * 6 * virtio-net server in host kernel. 7 */ 8 9#include <linux/compat.h> 10#include <linux/eventfd.h> 11#include <linux/vhost.h> 12#include <linux/virtio_net.h> 13#include <linux/miscdevice.h> 14#include <linux/module.h> 15#include <linux/moduleparam.h> 16#include <linux/mutex.h> 17#include <linux/workqueue.h> | 1/* Copyright (C) 2009 Red Hat, Inc. 2 * Author: Michael S. Tsirkin <mst@redhat.com> 3 * 4 * This work is licensed under the terms of the GNU GPL, version 2. 5 * 6 * virtio-net server in host kernel. 7 */ 8 9#include <linux/compat.h> 10#include <linux/eventfd.h> 11#include <linux/vhost.h> 12#include <linux/virtio_net.h> 13#include <linux/miscdevice.h> 14#include <linux/module.h> 15#include <linux/moduleparam.h> 16#include <linux/mutex.h> 17#include <linux/workqueue.h> |
18#include <linux/rcupdate.h> | |
19#include <linux/file.h> 20#include <linux/slab.h> 21 22#include <linux/net.h> 23#include <linux/if_packet.h> 24#include <linux/if_arp.h> 25#include <linux/if_tun.h> 26#include <linux/if_macvlan.h> --- 717 unchanged lines hidden (view full) --- 744static int vhost_net_enable_vq(struct vhost_net *n, 745 struct vhost_virtqueue *vq) 746{ 747 struct vhost_net_virtqueue *nvq = 748 container_of(vq, struct vhost_net_virtqueue, vq); 749 struct vhost_poll *poll = n->poll + (nvq - n->vqs); 750 struct socket *sock; 751 | 18#include <linux/file.h> 19#include <linux/slab.h> 20 21#include <linux/net.h> 22#include <linux/if_packet.h> 23#include <linux/if_arp.h> 24#include <linux/if_tun.h> 25#include <linux/if_macvlan.h> --- 717 unchanged lines hidden (view full) --- 743static int vhost_net_enable_vq(struct vhost_net *n, 744 struct vhost_virtqueue *vq) 745{ 746 struct vhost_net_virtqueue *nvq = 747 container_of(vq, struct vhost_net_virtqueue, vq); 748 struct vhost_poll *poll = n->poll + (nvq - n->vqs); 749 struct socket *sock; 750 |
752 sock = rcu_dereference_protected(vq->private_data, 753 lockdep_is_held(&vq->mutex)); | 751 sock = vq->private_data; |
754 if (!sock) 755 return 0; 756 757 return vhost_poll_start(poll, sock->file); 758} 759 760static struct socket *vhost_net_stop_vq(struct vhost_net *n, 761 struct vhost_virtqueue *vq) 762{ 763 struct socket *sock; 764 765 mutex_lock(&vq->mutex); | 752 if (!sock) 753 return 0; 754 755 return vhost_poll_start(poll, sock->file); 756} 757 758static struct socket *vhost_net_stop_vq(struct vhost_net *n, 759 struct vhost_virtqueue *vq) 760{ 761 struct socket *sock; 762 763 mutex_lock(&vq->mutex); |
766 sock = rcu_dereference_protected(vq->private_data, 767 lockdep_is_held(&vq->mutex)); | 764 sock = vq->private_data; |
768 vhost_net_disable_vq(n, vq); | 765 vhost_net_disable_vq(n, vq); |
769 rcu_assign_pointer(vq->private_data, NULL); | 766 vq->private_data = NULL; |
770 mutex_unlock(&vq->mutex); 771 return sock; 772} 773 774static void vhost_net_stop(struct vhost_net *n, struct socket **tx_sock, 775 struct socket **rx_sock) 776{ 777 *tx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_TX].vq); --- 139 unchanged lines hidden (view full) --- 917 } 918 sock = get_socket(fd); 919 if (IS_ERR(sock)) { 920 r = PTR_ERR(sock); 921 goto err_vq; 922 } 923 924 /* start polling new socket */ | 767 mutex_unlock(&vq->mutex); 768 return sock; 769} 770 771static void vhost_net_stop(struct vhost_net *n, struct socket **tx_sock, 772 struct socket **rx_sock) 773{ 774 *tx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_TX].vq); --- 139 unchanged lines hidden (view full) --- 914 } 915 sock = get_socket(fd); 916 if (IS_ERR(sock)) { 917 r = PTR_ERR(sock); 918 goto err_vq; 919 } 920 921 /* start polling new socket */ |
925 oldsock = rcu_dereference_protected(vq->private_data, 926 lockdep_is_held(&vq->mutex)); | 922 oldsock = vq->private_data; |
927 if (sock != oldsock) { 928 ubufs = vhost_net_ubuf_alloc(vq, 929 sock && vhost_sock_zcopy(sock)); 930 if (IS_ERR(ubufs)) { 931 r = PTR_ERR(ubufs); 932 goto err_ubufs; 933 } 934 935 vhost_net_disable_vq(n, vq); | 923 if (sock != oldsock) { 924 ubufs = vhost_net_ubuf_alloc(vq, 925 sock && vhost_sock_zcopy(sock)); 926 if (IS_ERR(ubufs)) { 927 r = PTR_ERR(ubufs); 928 goto err_ubufs; 929 } 930 931 vhost_net_disable_vq(n, vq); |
936 rcu_assign_pointer(vq->private_data, sock); | 932 vq->private_data = sock; |
937 r = vhost_init_used(vq); 938 if (r) 939 goto err_used; 940 r = vhost_net_enable_vq(n, vq); 941 if (r) 942 goto err_used; 943 944 oldubufs = nvq->ubufs; --- 17 unchanged lines hidden (view full) --- 962 vhost_net_flush_vq(n, index); 963 fput(oldsock->file); 964 } 965 966 mutex_unlock(&n->dev.mutex); 967 return 0; 968 969err_used: | 933 r = vhost_init_used(vq); 934 if (r) 935 goto err_used; 936 r = vhost_net_enable_vq(n, vq); 937 if (r) 938 goto err_used; 939 940 oldubufs = nvq->ubufs; --- 17 unchanged lines hidden (view full) --- 958 vhost_net_flush_vq(n, index); 959 fput(oldsock->file); 960 } 961 962 mutex_unlock(&n->dev.mutex); 963 return 0; 964 965err_used: |
970 rcu_assign_pointer(vq->private_data, oldsock); | 966 vq->private_data = oldsock; |
971 vhost_net_enable_vq(n, vq); 972 if (ubufs) 973 vhost_net_ubuf_put_wait_and_free(ubufs); 974err_ubufs: 975 fput(sock->file); 976err_vq: 977 mutex_unlock(&vq->mutex); 978err: --- 177 unchanged lines hidden --- | 967 vhost_net_enable_vq(n, vq); 968 if (ubufs) 969 vhost_net_ubuf_put_wait_and_free(ubufs); 970err_ubufs: 971 fput(sock->file); 972err_vq: 973 mutex_unlock(&vq->mutex); 974err: --- 177 unchanged lines hidden --- |