tuntap: move socket to tun_file

To implement multiqueue in tuntap, each queue were abstracted as a socket and
exposted as a file descriptor to userspace. So this patch move moves socket
structure from tun_device to tun_file in order to let it possbile for
multiple sockets to be attached to tun/tap device.

As socket were initialized during file opening. To keep backward compatibility
for the attributes (such as sndbuf, socket filter, vnet_hdr_sz) of socket for
persistent device. This patch also store those attributes in tun_struct, and
re-initialize them for the new socket when the files were attached to the
device.

Signed-off-by: Jason Wang <jasowang@redhat.com>
tuntap: RCUify dereferencing between tun_struct and tun_file

Signed-off-by: Jason Wang <jasowang@redhat.com>
tuntap: introduce multiqueue flags

Add flags to be used by creating multiqueue tuntap device.

Signed-off-by: Jason Wang <jasowang@redhat.com>
tuntap: multiqueue support

This patch converts tun/tap to a multiqueue devices and expose the multiqueue
queues as multiple file descriptors to userspace.Internally, an array of
pointers to tun_file were introduced in the device, so multiple tun_tfiles were
allowed to be attached to the device as multiple queues. To synchronize the
control path with data path, RCU is used to protected the references from both
sides - tun_file and tun_struct.

As we could have multiple sockets now, so the limit number of packets per socket
were set to by diviging the tx queue length by the number of queues.

Tx queue selecting were based the rx hash of the packet to make sure a flow have
a consistent queue to be transmitted. In the future, more policys may be added.

Signed-off-by: Jason Wang <jasowang@redhat.com>
tuntap: add ioctl to attach or detach a file form tuntap device

Sometimes usespace may need to active/deactive a queue, this could be done by
detaching and attaching a file from tuntap device.

This patch introduces a new ioctls - TUNSETQUEUE which could be used to do
this. Flag IFF_ATTACH_QUEUE were introduced to do attaching while
IFF_DETACH_QUEUE were introduced to do the detaching.

Signed-off-by: Jason Wang <jasowang@redhat.com>
tuntap: choose the txq based on rxq

Signed-off-by: Jason Wang <jasowang@redhat.com>
virtio-ring: move queue_index to vring_virtqueue

Instead of storing the queue index in transport-specific virtio structs,
this patch moves them to vring_virtqueue and introduces an helper to get
the value.  This lets drivers simplify their management and tracing of
virtqueues.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
virtio: introduce an API to set affinity for a virtqueue

Sometimes, virtio device need to configure irq affinity hint to maximize the
performance. Instead of just exposing the irq of a virtqueue, this patch
introduce an API to set the affinity for a virtqueue.

The api is best-effort, the affinity hint may not be set as expected due to
platform support, irq sharing or irq type. Currently, only pci method were
implemented and we set the affinity according to:

- if device uses INTX, we just ignore the request
- if device has per vq vector, we force the affinity hint
- if the virtqueues share MSI, make the affinity OR over all affinities
  requested

Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
virtio_net: Introduce VIRTIO_NET_F_MULTIQUEUE

Introduce VIRTIO_NET_F_MULTIQUEUE.

Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
virtio_net: multiqueue support

This addes multiqueue support to virtio_net driver. This feature is negotiated
through VIRTIO_NET_F_MULTIQUEUE.

The driver expects the number of rx/tx queue paris is equal to the number of
vcpus. To maximize the performance under this per-cpu rx/tx queue pairs, some
optimization were introduced:

- Txq selection is based on the processor id in order to avoid contending a lock
 whose owner may exits to host.
- Since the txq/txq were per-cpu, affinity hint were set to the cpu that owns
 the queue pairs.

This aslo patch let the virtio_net driver can negotiate the number of queues it
wishes to use through control virtqueue and export an ethtool interface to let
use tweak it.

As current multiqueue virtio-net implementation has optimizations on per-cpu
virtuqueues, so only two modes were support:

- single queue pair mode
- multiple queue paris mode, the number of queues matches the number of vcpus

The single queue mode were used by default currently due to regression of
multiqueue mode in some test (especially in stream test).

Since virtio core does not support paritially deleting virtqueues, so during
mode switching the whole virtqueue were deleted and the driver would re-create
the virtqueues it would used.

btw. The queue number negotiating were defered to .ndo_open(), this is because
only after feature negotitaion could we send the command to control virtqueue
(as it may also use event index).

Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
seamless migration between sq and mq

Signed-off-by: Jason Wang <jasowang@redhat.com>