Skip to content

Commit

Permalink
tap: Add USO support to tap device.
Browse files Browse the repository at this point in the history
Passing additional parameters (USOv4 and USOv6 offloads) when
setting TAP offloads

Signed-off-by: Yuri Benditovich <[email protected]>
Signed-off-by: Andrew Melnychenko <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
  • Loading branch information
AndrewAtDaynix authored and jasowang committed Sep 18, 2023
1 parent 005ad32 commit 2ab0ec3
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion hw/net/e1000e_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2852,7 +2852,7 @@ e1000e_update_rx_offloads(E1000ECore *core)

if (core->has_vnet) {
qemu_set_offload(qemu_get_queue(core->owner_nic)->peer,
cso_state, 0, 0, 0, 0);
cso_state, 0, 0, 0, 0, 0, 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion hw/net/igb_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2753,7 +2753,7 @@ igb_update_rx_offloads(IGBCore *core)

if (core->has_vnet) {
qemu_set_offload(qemu_get_queue(core->owner_nic)->peer,
cso_state, 0, 0, 0, 0);
cso_state, 0, 0, 0, 0, 0, 0);
}
}

Expand Down
4 changes: 3 additions & 1 deletion hw/net/virtio-net.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,9 @@ static void virtio_net_apply_guest_offloads(VirtIONet *n)
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO4)),
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO6)),
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_ECN)),
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO)));
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO)),
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO4)),
!!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO6)));
}

static uint64_t virtio_net_guest_offloads_by_features(uint32_t features)
Expand Down
2 changes: 2 additions & 0 deletions hw/net/vmxnet3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,8 @@ static void vmxnet3_update_features(VMXNET3State *s)
s->lro_supported,
s->lro_supported,
0,
0,
0,
0);
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/net/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ typedef bool (HasVnetHdr)(NetClientState *);
typedef bool (HasVnetHdrLen)(NetClientState *, int);
typedef bool (GetUsingVnetHdr)(NetClientState *);
typedef void (UsingVnetHdr)(NetClientState *, bool);
typedef void (SetOffload)(NetClientState *, int, int, int, int, int);
typedef void (SetOffload)(NetClientState *, int, int, int, int, int, int, int);
typedef int (GetVnetHdrLen)(NetClientState *);
typedef void (SetVnetHdrLen)(NetClientState *, int);
typedef int (SetVnetLE)(NetClientState *, bool);
Expand Down Expand Up @@ -192,7 +192,7 @@ bool qemu_has_vnet_hdr_len(NetClientState *nc, int len);
bool qemu_get_using_vnet_hdr(NetClientState *nc);
void qemu_using_vnet_hdr(NetClientState *nc, bool enable);
void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
int ecn, int ufo);
int ecn, int ufo, int uso4, int uso6);
int qemu_get_vnet_hdr_len(NetClientState *nc);
void qemu_set_vnet_hdr_len(NetClientState *nc, int len);
int qemu_set_vnet_le(NetClientState *nc, bool is_le);
Expand Down
4 changes: 2 additions & 2 deletions net/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,13 @@ void qemu_using_vnet_hdr(NetClientState *nc, bool enable)
}

void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
int ecn, int ufo)
int ecn, int ufo, int uso4, int uso6)
{
if (!nc || !nc->info->set_offload) {
return;
}

nc->info->set_offload(nc, csum, tso4, tso6, ecn, ufo);
nc->info->set_offload(nc, csum, tso4, tso6, ecn, ufo, uso4, uso6);
}

int qemu_get_vnet_hdr_len(NetClientState *nc)
Expand Down
2 changes: 1 addition & 1 deletion net/netmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static void netmap_set_vnet_hdr_len(NetClientState *nc, int len)
}

static void netmap_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
int ecn, int ufo)
int ecn, int ufo, int uso4, int uso6)
{
NetmapState *s = DO_UPCAST(NetmapState, nc, nc);

Expand Down
2 changes: 1 addition & 1 deletion net/tap-bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
}

void tap_fd_set_offload(int fd, int csum, int tso4,
int tso6, int ecn, int ufo)
int tso6, int ecn, int ufo, int uso4, int uso6)
{
}

Expand Down
15 changes: 12 additions & 3 deletions net/tap-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
}

void tap_fd_set_offload(int fd, int csum, int tso4,
int tso6, int ecn, int ufo)
int tso6, int ecn, int ufo, int uso4, int uso6)
{
unsigned int offload = 0;

Expand All @@ -256,13 +256,22 @@ void tap_fd_set_offload(int fd, int csum, int tso4,
offload |= TUN_F_TSO_ECN;
if (ufo)
offload |= TUN_F_UFO;
if (uso4) {
offload |= TUN_F_USO4;
}
if (uso6) {
offload |= TUN_F_USO6;
}
}

if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
offload &= ~TUN_F_UFO;
offload &= ~(TUN_F_USO4 | TUN_F_USO6);
if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
offload &= ~TUN_F_UFO;
if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
strerror(errno));
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions net/tap-linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@
#define TUN_F_TSO6 0x04 /* I can handle TSO for IPv6 packets */
#define TUN_F_TSO_ECN 0x08 /* I can handle TSO with ECN bits. */
#define TUN_F_UFO 0x10 /* I can handle UFO packets */
#define TUN_F_USO4 0x20 /* I can handle USO for IPv4 packets */
#define TUN_F_USO6 0x40 /* I can handle USO for IPv6 packets */

#endif /* QEMU_TAP_LINUX_H */
2 changes: 1 addition & 1 deletion net/tap-solaris.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
}

void tap_fd_set_offload(int fd, int csum, int tso4,
int tso6, int ecn, int ufo)
int tso6, int ecn, int ufo, int uso4, int uso6)
{
}

Expand Down
2 changes: 1 addition & 1 deletion net/tap-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
}

void tap_fd_set_offload(int fd, int csum, int tso4,
int tso6, int ecn, int ufo)
int tso6, int ecn, int ufo, int uso4, int uso6)
{
}

Expand Down
2 changes: 1 addition & 1 deletion net/tap-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ static void tap_using_vnet_hdr(NetClientState *nc, bool using_vnet_hdr)
}

static void tap_set_offload(NetClientState *nc, int csum, int tso4,
int tso6, int ecn, int ufo)
int tso6, int ecn, int ufo, int uso4, int uso6)
{
}

Expand Down
6 changes: 3 additions & 3 deletions net/tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ static int tap_set_vnet_be(NetClientState *nc, bool is_be)
}

static void tap_set_offload(NetClientState *nc, int csum, int tso4,
int tso6, int ecn, int ufo)
int tso6, int ecn, int ufo, int uso4, int uso6)
{
TAPState *s = DO_UPCAST(TAPState, nc, nc);
if (s->fd < 0) {
return;
}

tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo);
tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo, uso4, uso6);
}

static void tap_exit_notify(Notifier *notifier, void *data)
Expand Down Expand Up @@ -414,7 +414,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
s->using_vnet_hdr = false;
s->has_ufo = tap_probe_has_ufo(s->fd);
s->enabled = true;
tap_set_offload(&s->nc, 0, 0, 0, 0, 0);
tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0);
/*
* Make sure host header length is set correctly in tap:
* it might have been modified by another instance of qemu.
Expand Down
3 changes: 2 additions & 1 deletion net/tap_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp);
int tap_probe_vnet_hdr(int fd, Error **errp);
int tap_probe_vnet_hdr_len(int fd, int len);
int tap_probe_has_ufo(int fd);
void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo);
void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo,
int uso4, int uso6);
void tap_fd_set_vnet_hdr_len(int fd, int len);
int tap_fd_set_vnet_le(int fd, int vnet_is_le);
int tap_fd_set_vnet_be(int fd, int vnet_is_be);
Expand Down

0 comments on commit 2ab0ec3

Please sign in to comment.