Net patches
Subsystems (2)
The big change here is the new vmxnet3 emulated NIC.
The following changes since commit fe6344a05fba26e16863fefcb823242e579b0991:
Remove device_tree.o from hw/moxie/Makefile.objs. (2013-03-24 11:30:04 +0100)
are available in the git repository at:
git://github.com/stefanha/qemu.git net
for you to fetch changes up to d32fcad366e5f45d33dab2ee4de0e5729439680b:
net: increase buffer size to accommodate Jumbo frame pkts (2013-03-25 11:14:07 +0100)
----------------------------------------------------------------
Dmitry Fleytman (5):
Checksum-related utility functions
net: iovec checksum calculator
Common definitions for VMWARE devices Packet abstraction for VMWARE network devices VMXNET3 device implementation
Scott Feldman (1):
net: increase buffer size to accommodate Jumbo frame pkts
Stefan Hajnoczi (1):
net: use socket_set_nodelay() for -netdev socket
default-configs/pci.mak | 1 + hw/Makefile.objs | 2 + hw/pci/pci.h | 1 + hw/vmware_utils.h | 143 +++ hw/vmxnet3.c | 2461 +++++++++++++++++++++++++++++++++++++++++++++++ hw/vmxnet3.h | 760 +++++++++++++++ hw/vmxnet_debug.h | 115 +++ hw/vmxnet_rx_pkt.c | 187 ++++ hw/vmxnet_rx_pkt.h | 174 ++++ hw/vmxnet_tx_pkt.c | 567 +++++++++++ hw/vmxnet_tx_pkt.h | 148 +++ include/net/checksum.h | 26 +- include/net/eth.h | 347 +++++++ include/net/net.h | 5 + net/Makefile.objs | 1 + net/checksum.c | 42 +- net/eth.c | 217 +++++ net/net.c | 2 +- net/socket.c | 7 +- net/tap.c | 7 +- net/vde.c | 2 +- 21 files changed, 5198 insertions(+), 17 deletions(-) create mode 100644 hw/vmware_utils.h create mode 100644 hw/vmxnet3.c create mode 100644 hw/vmxnet3.h create mode 100644 hw/vmxnet_debug.h create mode 100644 hw/vmxnet_rx_pkt.c create mode 100644 hw/vmxnet_rx_pkt.h create mode 100644 hw/vmxnet_tx_pkt.c create mode 100644 hw/vmxnet_tx_pkt.h create mode 100644 include/net/eth.h create mode 100644 net/eth.c
Signature · 1 line
1.8.1.4
PATCH 1/7 net: use socket_set_nodelay() for -netdev socket
Reduce -netdev socket latency by disabling the Nagle algorithm on SOCK_STREAM sockets in net/socket.c. Since we are tunelling Ethernet over TCP we shouldn't artificially delay outgoing packets, let the guest decide packet scheduling.
I already get sub-millisecond -netdev socket ping times on localhost, so there was no measurable difference in my testing. This won't hurt though and may improve remote socket performance.
--- net/socket.c | 3 +++ 1 file changed, 3 insertions(+)
net/socket.c +3 -0
@@ -438,6 +438,9 @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, s->fd = fd; s->listen_fd =-1 ; +/* Disable Nagle algorithm on TCP sockets to reduce latency */ +socket_set_nodelay (fd); +if (is_connected) {net_socket_connect (s); }else {
Signature · 1 line
1.8.1.4
PATCH 2/7 Checksum-related utility functions
In reply to Stefan HajnocziFrom: Dmitry Fleytman <[email protected]>
net_checksum_add_cont()
checksum calculation for scattered data with odd chunk sizes
net_raw_checksum()
checksum calculation for a buffer
--- include/net/checksum.h | 14 +++++++++++++- net/checksum.c | 13 +++++++------ 2 files changed, 20 insertions(+), 7 deletions(-)
include/net/checksum.h +13 -1
@@ -20,10 +20,22 @@#include <stdint.h> -uint32_t net_checksum_add (int len,uint8_t *buf); +uint32_t net_checksum_add_cont (int len,uint8_t *buf,int seq);uint16_t net_checksum_finish (uint32_t sum);uint16_t net_checksum_tcpudp (uint16_t length,uint16_t proto,uint8_t *addrs,uint8_t *buf);void net_checksum_calculate (uint8_t *data,int length); +static inline uint32_t +net_checksum_add (int len,uint8_t *buf) +{ +return net_checksum_add_cont (len, buf,0 ); +} + +static inline uint16_t +net_raw_checksum (uint8_t *data,int length) +{ +return net_checksum_finish (net_checksum_add (length, data)); +} +#endif /* QEMU_NET_CHECKSUM_H */
net/checksum.c +7 -6
@@ -20,16 +20,17 @@#define PROTO_TCP 6#define PROTO_UDP 17 -uint32_t net_checksum_add (int len,uint8_t *buf) +uint32_t net_checksum_add_cont (int len,uint8_t *buf,int seq) {uint32_t sum =0 ;int i; -for (i =0 ; i < len; i++) { -if (i &1 ) - sum += (uint32_t )buf[i]; -else - sum += (uint32_t )buf[i] <<8 ; +for (i = seq; i < seq + len; i++) { +if (i &1 ) { + sum += (uint32_t )buf[i - seq]; + }else { + sum += (uint32_t )buf[i - seq] <<8 ; + } }return sum; }
Signature · 1 line
1.8.1.4
PATCH 3/7 net: iovec checksum calculator
In reply to Stefan HajnocziFrom: Dmitry Fleytman <[email protected]>
--- include/net/checksum.h | 12 ++++++++++++ net/checksum.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
include/net/checksum.h +12 -0
@@ -38,4 +38,16 @@ net_raw_checksum(uint8_t *data, int length) return net_checksum_finish(net_checksum_add(length, data)); } +/** +* net_checksum_add_iov: scatter-gather vector checksumming +* +* @iov: input scatter-gather array +* @iov_cnt: number of array elements +* @iov_off: starting iov offset for checksumming +* @size: length of data to be checksummed +*/ +uint32_t net_checksum_add_iov (const struct iovec *iov, +const unsigned int iov_cnt, +uint32_t iov_off,uint32_t size); +#endif /* QEMU_NET_CHECKSUM_H */
net/checksum.c +29 -0
@@ -15,6 +15,7 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ +#include "qemu-common.h" #include "net/checksum.h" #define PROTO_TCP 6
@@ -84,3 +85,31 @@ void net_checksum_calculate(uint8_t *data, int length) data[14 +hlen+csum_offset] = csum >>8 ; data[14 +hlen+csum_offset+1 ] = csum &0xff ; } + +uint32_t +net_checksum_add_iov (const struct iovec *iov,const unsigned int iov_cnt, +uint32_t iov_off,uint32_t size) +{ +size_t iovec_off, buf_off; +unsigned int i; +uint32_t res =0 ; +uint32_t seq =0 ; + + iovec_off =0 ; + buf_off =0 ; +for (i =0 ; i < iov_cnt && size; i++) { +if (iov_off < (iovec_off + iov[i].iov_len)) { +size_t len =MIN ((iovec_off + iov[i].iov_len) - iov_off , size); +void *chunk_buf = iov[i].iov_base + (iov_off - iovec_off); + + res +=net_checksum_add_cont (len, chunk_buf, seq); + seq += len; + + buf_off += len; + iov_off += len; + size -= len; + } + iovec_off += iov[i].iov_len; + } +return res; +}
Signature · 1 line
1.8.1.4
PATCH 4/7 Common definitions for VMWARE devices
In reply to Stefan HajnocziFrom: Dmitry Fleytman <[email protected]>
--- hw/vmware_utils.h | 143 ++++++++++++++++++++++ hw/vmxnet_debug.h | 115 ++++++++++++++++++ include/net/eth.h | 347 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/Makefile.objs | 1 + net/eth.c | 217 ++++++++++++++++++++++++++++++++++ 5 files changed, 823 insertions(+) create mode 100644 hw/vmware_utils.h create mode 100644 hw/vmxnet_debug.h create mode 100644 include/net/eth.h create mode 100644 net/eth.c
hw/vmware_utils.h new file +143 -0
@@ -0,0 +1,143 @@ +/* +* QEMU VMWARE paravirtual devices - auxiliary code +* +* Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com) +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Dmitry Fleytman <[email protected]> +* Yan Vugenfirer <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#ifndef VMWARE_UTILS_H +#define VMWARE_UTILS_H + +#include "qemu/range.h" + +#ifndef VMW_SHPRN +#define VMW_SHPRN (fmt, ...) do {} while (0) +#endif + +/* +* Shared memory access functions with byte swap support +* Each function contains printout for reverse-engineering needs +* +*/ +static inline void +vmw_shmem_read (hwaddr addr,void *buf,int len) +{ +VMW_SHPRN ("SHMEM r: %" PRIx64", len: %d to %p" , addr, len, buf); +cpu_physical_memory_read (addr, buf, len); +} + +static inline void +vmw_shmem_write (hwaddr addr,void *buf,int len) +{ +VMW_SHPRN ("SHMEM w: %" PRIx64", len: %d to %p" , addr, len, buf); +cpu_physical_memory_write (addr, buf, len); +} + +static inline void +vmw_shmem_rw (hwaddr addr,void *buf,int len,int is_write) +{ +VMW_SHPRN ("SHMEM r/w: %" PRIx64", len: %d (to %p), is write: %d" , + addr, len, buf, is_write); + +cpu_physical_memory_rw (addr, buf, len, is_write); +} + +static inline void +vmw_shmem_set (hwaddr addr,uint8 val,int len) +{ +int i; +VMW_SHPRN ("SHMEM set: %" PRIx64", len: %d (value 0x%X)" , addr, len, val); + +for (i =0 ; i < len; i++) { +cpu_physical_memory_write (addr + i, &val,1 ); + } +} + +static inline uint32_t +vmw_shmem_ld8 (hwaddr addr) +{ +uint8_t res =ldub_phys (addr); +VMW_SHPRN ("SHMEM load8: %" PRIx64" (value 0x%X)" , addr, res); +return res; +} + +static inline void +vmw_shmem_st8 (hwaddr addr,uint8_t value) +{ +VMW_SHPRN ("SHMEM store8: %" PRIx64" (value 0x%X)" , addr, value); +stb_phys (addr, value); +} + +static inline uint32_t +vmw_shmem_ld16 (hwaddr addr) +{ +uint16_t res =lduw_le_phys (addr); +VMW_SHPRN ("SHMEM load16: %" PRIx64" (value 0x%X)" , addr, res); +return res; +} + +static inline void +vmw_shmem_st16 (hwaddr addr,uint16_t value) +{ +VMW_SHPRN ("SHMEM store16: %" PRIx64" (value 0x%X)" , addr, value); +stw_le_phys (addr, value); +} + +static inline uint32_t +vmw_shmem_ld32 (hwaddr addr) +{ +uint32_t res =ldl_le_phys (addr); +VMW_SHPRN ("SHMEM load32: %" PRIx64" (value 0x%X)" , addr, res); +return res; +} + +static inline void +vmw_shmem_st32 (hwaddr addr,uint32_t value) +{ +VMW_SHPRN ("SHMEM store32: %" PRIx64" (value 0x%X)" , addr, value); +stl_le_phys (addr, value); +} + +static inline uint64_t +vmw_shmem_ld64 (hwaddr addr) +{ +uint64_t res =ldq_le_phys (addr); +VMW_SHPRN ("SHMEM load64: %" PRIx64" (value %" PRIx64")" , addr, res); +return res; +} + +static inline void +vmw_shmem_st64 (hwaddr addr,uint64_t value) +{ +VMW_SHPRN ("SHMEM store64: %" PRIx64" (value %" PRIx64")" , addr, value); +stq_le_phys (addr, value); +} + +/* Macros for simplification of operations on array-style registers */ + +/* +* Whether <addr> lies inside of array-style register defined by <base>, +* number of elements (<cnt>) and element size (<regsize>) +* +*/ +#define VMW_IS_MULTIREG_ADDR (addr, base, cnt, regsize) \ + range_covers_byte(base, cnt * regsize, addr) + +/* +* Returns index of given register (<addr>) in array-style register defined by +* <base> and element size (<regsize>) +* +*/ +#define VMW_MULTIREG_IDX_BY_ADDR (addr, base, regsize) \ + (((addr) - (base)) / (regsize)) + +#endif
hw/vmxnet_debug.h new file +115 -0
115 lines not on this page · raw message
include/net/eth.h new file +347 -0
347 lines not on this page · raw message
net/Makefile.objs +1 -0
@@ -1,6 +1,7 @@ common-obj-y = net.o queue.o checksum.o util.o hub.o common-obj-y += socket.o common-obj-y += dump.o +common-obj-y += eth.o common-obj-$(CONFIG_POSIX) += tap.o common-obj-$(CONFIG_LINUX) += tap-linux.o common-obj-$(CONFIG_WIN32) += tap-win32.o
net/eth.c new file +217 -0
217 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH 5/7 Packet abstraction for VMWARE network devices
In reply to Stefan HajnocziFrom: Dmitry Fleytman <[email protected]>
--- hw/Makefile.objs | 1 + hw/vmxnet_rx_pkt.c | 187 ++++++++++++++++++ hw/vmxnet_rx_pkt.h | 174 ++++++++++++++++ hw/vmxnet_tx_pkt.c | 567 +++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/vmxnet_tx_pkt.h | 148 ++++++++++++++ 5 files changed, 1077 insertions(+) create mode 100644 hw/vmxnet_rx_pkt.c create mode 100644 hw/vmxnet_rx_pkt.h create mode 100644 hw/vmxnet_tx_pkt.c create mode 100644 hw/vmxnet_tx_pkt.h
hw/Makefile.objs +1 -0
@@ -119,6 +119,7 @@ common-obj-$(CONFIG_PCNET_PCI) += pcnet-pci.o common-obj-$(CONFIG_PCNET_COMMON) += pcnet.o common-obj-$(CONFIG_E1000_PCI) += e1000.o common-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o +common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet_tx_pkt.o vmxnet_rx_pkt.o common-obj-$(CONFIG_SMC91C111) += smc91c111.o common-obj-$(CONFIG_LAN9118) += lan9118.o
hw/vmxnet_rx_pkt.c new file +187 -0
187 lines not on this page · raw message
hw/vmxnet_rx_pkt.h new file +174 -0
174 lines not on this page · raw message
hw/vmxnet_tx_pkt.c new file +567 -0
567 lines not on this page · raw message
hw/vmxnet_tx_pkt.h new file +148 -0
148 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH 6/7 VMXNET3 device implementation
In reply to Stefan HajnocziFrom: Dmitry Fleytman <[email protected]>
--- default-configs/pci.mak | 1 + hw/Makefile.objs | 1 + hw/pci/pci.h | 1 + hw/vmxnet3.c | 2461 +++++++++++++++++++++++++++++++++++++++++++++++ hw/vmxnet3.h | 760 +++++++++++++++ 5 files changed, 3224 insertions(+) create mode 100644 hw/vmxnet3.c create mode 100644 hw/vmxnet3.h
default-configs/pci.mak +1 -0
@@ -13,6 +13,7 @@ CONFIG_LSI_SCSI_PCI=y CONFIG_MEGASAS_SCSI_PCI=y CONFIG_RTL8139_PCI=y CONFIG_E1000_PCI=y +CONFIG_VMXNET3_PCI=y CONFIG_IDE_CORE=y CONFIG_IDE_QDEV=y CONFIG_IDE_PCI=y
hw/Makefile.objs +1 -0
@@ -120,6 +120,7 @@ common-obj-$(CONFIG_PCNET_COMMON) += pcnet.o common-obj-$(CONFIG_E1000_PCI) += e1000.o common-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet_tx_pkt.o vmxnet_rx_pkt.o +common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet3.o common-obj-$(CONFIG_SMC91C111) += smc91c111.o common-obj-$(CONFIG_LAN9118) += lan9118.o
hw/pci/pci.h +1 -0
@@ -60,6 +60,7 @@#define PCI_DEVICE_ID_VMWARE_NET 0x0720#define PCI_DEVICE_ID_VMWARE_SCSI 0x0730#define PCI_DEVICE_ID_VMWARE_IDE 0x1729 +#define PCI_DEVICE_ID_VMWARE_VMXNET3 0x07B0/* Intel (0x8086) */ #define PCI_DEVICE_ID_INTEL_82551IT 0x1209
hw/vmxnet3.c new file +2461 -0
2,461 lines not on this page · raw message
hw/vmxnet3.h new file +760 -0
518 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.1.4
Part of the diff is not shown here. View the raw message.
PATCH 7/7 net: increase buffer size to accommodate Jumbo frame pkts
In reply to Stefan HajnocziFrom: Scott Feldman <[email protected]>
Socket buffer sizes were hard-coded to 4K for VDE and socket netdevs. Bump this up to 68K (ala tap netdev) to handle maximum GSO packet size (64k) plus plenty of room for the ethernet and virtio_net headers.
Originally, ran into this limitation when using -netdev UDP sockets to connect VM-to-VM, where VM interface is configure with MTU=9000. (Using virtio_net NIC model). Test is simple: ping -M do -s 8500 <target>. This test will attempt to ping with unfragmented packet of given size. Without patch, size is limited to < 4K (minus protocol hdrs). With patch, ping test works with pkt size up to 9000 (again, minus protocol hdrs).
v2: per Stefan, increase buf size to (4096+65536) as done in tap and apply
to vde and socket netdevs.
v1: increase buf size to 12K just for -netdev UDP sockets
--- include/net/net.h | 5 +++++ net/net.c | 2 +- net/socket.c | 4 ++-- net/tap.c | 7 +------ net/vde.c | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-)
include/net/net.h +5 -0
@@ -11,6 +11,11 @@#define MAX_QUEUE_NUM 1024 +/* Maximum GSO packet size (64k) plus plenty of room for +* the ethernet and virtio_net headers +*/ +#define NET_BUFSIZE (4096 + 65536) +struct MACAddr {uint8_t a[6 ]; };
net/net.c +1 -1
@@ -497,7 +497,7 @@ ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size)static ssize_t nc_sendv_compat (NetClientState *nc,const struct iovec *iov,int iovcnt) { -uint8_t buffer[4096 ]; +uint8_t buffer[NET_BUFSIZE ];size_t offset; offset =iov_to_buf (iov, iovcnt,0 , buffer,sizeof (buffer));
net/socket.c +2 -2
@@ -40,7 +40,7 @@ typedef struct NetSocketState {unsigned int index;unsigned int packet_len;unsigned int send_index;/* number of bytes sent (only SOCK_STREAM) */ -uint8_t buf[4096 ]; +uint8_t buf[NET_BUFSIZE ];struct sockaddr_in dgram_dst;/* contains inet host and port destination iff connectionless (SOCK_DGRAM) */ IOHandler *send_fn;/* differs between SOCK_STREAM/SOCK_DGRAM */ bool read_poll;/* waiting to receive data? */
@@ -146,7 +146,7 @@ static void net_socket_send(void *opaque)NetSocketState *s = opaque;int size, err;unsigned l; -uint8_t buf1[4096 ]; +uint8_t buf1[NET_BUFSIZE ];const uint8_t *buf; size =qemu_recv (s->fd, buf1,sizeof (buf1),0 );
net/tap.c +1 -6
@@ -44,17 +44,12 @@#include "hw/vhost_net.h" -/* Maximum GSO packet size (64k) plus plenty of room for -* the ethernet and virtio_net headers -*/ -#define TAP_BUFSIZE (4096 + 65536) - typedef struct TAPState { NetClientState nc; int fd; char down_script[1024]; char down_script_arg[128]; - uint8_t buf[TAP_BUFSIZE]; + uint8_t buf[NET_BUFSIZE]; bool read_poll; bool write_poll; bool using_vnet_hdr;
net/vde.c +1 -1
@@ -39,7 +39,7 @@ typedef struct VDEState {static void vde_to_qemu (void *opaque) {VDEState *s = opaque; -uint8_t buf[4096 ]; +uint8_t buf[NET_BUFSIZE ];int size; size =vde_recv (s->vde, (char *)buf,sizeof (buf),0 );
Signature · 1 line
1.8.1.4