Skip to content

Commit ee5128b

Browse files
committed
Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into staging
# gpg: Signature made Wed 15 Jul 2020 14:49:07 BST # gpg: using RSA key EF04965B398D6211 # gpg: Good signature from "Jason Wang (Jason Wang on RedHat) <[email protected]>" [marginal] # gpg: WARNING: This key is not certified with sufficiently trusted signatures! # gpg: It is not certain that the signature belongs to the owner. # Primary key fingerprint: 215D 46F4 8246 689E C77F 3562 EF04 965B 398D 6211 * remotes/jasowang/tags/net-pull-request: ftgmac100: fix dblac write test net: detect errors from probing vnet hdr flag for TAP devices net: check if the file descriptor is valid before using it qemu-options.hx: Clean up and fix typo for colo-compare net/colo-compare.c: Expose compare "max_queue_size" to users hw/net: Added CSO for IPv6 virtio-net: fix removal of failover device Signed-off-by: Peter Maydell <[email protected]>
2 parents 8746309 + a134321 commit ee5128b

File tree

15 files changed

+188
-77
lines changed

15 files changed

+188
-77
lines changed

hw/net/ftgmac100.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,16 +810,18 @@ static void ftgmac100_write(void *opaque, hwaddr addr,
810810
s->phydata = value & 0xffff;
811811
break;
812812
case FTGMAC100_DBLAC: /* DMA Burst Length and Arbitration Control */
813-
if (FTGMAC100_DBLAC_TXDES_SIZE(s->dblac) < sizeof(FTGMAC100Desc)) {
813+
if (FTGMAC100_DBLAC_TXDES_SIZE(value) < sizeof(FTGMAC100Desc)) {
814814
qemu_log_mask(LOG_GUEST_ERROR,
815-
"%s: transmit descriptor too small : %d bytes\n",
816-
__func__, FTGMAC100_DBLAC_TXDES_SIZE(s->dblac));
815+
"%s: transmit descriptor too small: %" PRIx64
816+
" bytes\n", __func__,
817+
FTGMAC100_DBLAC_TXDES_SIZE(value));
817818
break;
818819
}
819-
if (FTGMAC100_DBLAC_RXDES_SIZE(s->dblac) < sizeof(FTGMAC100Desc)) {
820+
if (FTGMAC100_DBLAC_RXDES_SIZE(value) < sizeof(FTGMAC100Desc)) {
820821
qemu_log_mask(LOG_GUEST_ERROR,
821-
"%s: receive descriptor too small : %d bytes\n",
822-
__func__, FTGMAC100_DBLAC_RXDES_SIZE(s->dblac));
822+
"%s: receive descriptor too small : %" PRIx64
823+
" bytes\n", __func__,
824+
FTGMAC100_DBLAC_RXDES_SIZE(value));
823825
break;
824826
}
825827
s->dblac = value;

hw/net/net_tx_pkt.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,18 +468,27 @@ static void net_tx_pkt_do_sw_csum(struct NetTxPkt *pkt)
468468
/* num of iovec without vhdr */
469469
uint32_t iov_len = pkt->payload_frags + NET_TX_PKT_PL_START_FRAG - 1;
470470
uint16_t csl;
471-
struct ip_header *iphdr;
472471
size_t csum_offset = pkt->virt_hdr.csum_start + pkt->virt_hdr.csum_offset;
472+
uint16_t l3_proto = eth_get_l3_proto(iov, 1, iov->iov_len);
473473

474474
/* Put zero to checksum field */
475475
iov_from_buf(iov, iov_len, csum_offset, &csum, sizeof csum);
476476

477477
/* Calculate L4 TCP/UDP checksum */
478478
csl = pkt->payload_len;
479479

480+
csum_cntr = 0;
481+
cso = 0;
480482
/* add pseudo header to csum */
481-
iphdr = pkt->vec[NET_TX_PKT_L3HDR_FRAG].iov_base;
482-
csum_cntr = eth_calc_ip4_pseudo_hdr_csum(iphdr, csl, &cso);
483+
if (l3_proto == ETH_P_IP) {
484+
csum_cntr = eth_calc_ip4_pseudo_hdr_csum(
485+
pkt->vec[NET_TX_PKT_L3HDR_FRAG].iov_base,
486+
csl, &cso);
487+
} else if (l3_proto == ETH_P_IPV6) {
488+
csum_cntr = eth_calc_ip6_pseudo_hdr_csum(
489+
pkt->vec[NET_TX_PKT_L3HDR_FRAG].iov_base,
490+
csl, pkt->l4proto, &cso);
491+
}
483492

484493
/* data checksum */
485494
csum_cntr +=

hw/net/virtio-net.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3416,6 +3416,7 @@ static void virtio_net_device_unrealize(DeviceState *dev)
34163416
g_free(n->vlans);
34173417

34183418
if (n->failover) {
3419+
device_listener_unregister(&n->primary_listener);
34193420
g_free(n->primary_device_id);
34203421
g_free(n->standby_id);
34213422
qobject_unref(n->primary_device_dict);

include/qemu/sockets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
1818
int socket_set_cork(int fd, int v);
1919
int socket_set_nodelay(int fd);
2020
void qemu_set_block(int fd);
21+
int qemu_try_set_nonblock(int fd);
2122
void qemu_set_nonblock(int fd);
2223
int socket_set_fast_reuse(int fd);
2324

net/colo-compare.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static bool colo_compare_active;
5959
static QemuMutex event_mtx;
6060
static QemuCond event_complete_cond;
6161
static int event_unhandled_count;
62+
static uint32_t max_queue_size;
6263

6364
/*
6465
* + CompareState ++
@@ -222,7 +223,7 @@ static void fill_pkt_tcp_info(void *data, uint32_t *max_ack)
222223
*/
223224
static int colo_insert_packet(GQueue *queue, Packet *pkt, uint32_t *max_ack)
224225
{
225-
if (g_queue_get_length(queue) <= MAX_QUEUE_SIZE) {
226+
if (g_queue_get_length(queue) <= max_queue_size) {
226227
if (pkt->ip->ip_p == IPPROTO_TCP) {
227228
fill_pkt_tcp_info(pkt, max_ack);
228229
g_queue_insert_sorted(queue,
@@ -1134,6 +1135,37 @@ static void compare_set_expired_scan_cycle(Object *obj, Visitor *v,
11341135
s->expired_scan_cycle = value;
11351136
}
11361137

1138+
static void get_max_queue_size(Object *obj, Visitor *v,
1139+
const char *name, void *opaque,
1140+
Error **errp)
1141+
{
1142+
uint32_t value = max_queue_size;
1143+
1144+
visit_type_uint32(v, name, &value, errp);
1145+
}
1146+
1147+
static void set_max_queue_size(Object *obj, Visitor *v,
1148+
const char *name, void *opaque,
1149+
Error **errp)
1150+
{
1151+
Error *local_err = NULL;
1152+
uint32_t value;
1153+
1154+
visit_type_uint32(v, name, &value, &local_err);
1155+
if (local_err) {
1156+
goto out;
1157+
}
1158+
if (!value) {
1159+
error_setg(&local_err, "Property '%s.%s' requires a positive value",
1160+
object_get_typename(obj), name);
1161+
goto out;
1162+
}
1163+
max_queue_size = value;
1164+
1165+
out:
1166+
error_propagate(errp, local_err);
1167+
}
1168+
11371169
static void compare_pri_rs_finalize(SocketReadState *pri_rs)
11381170
{
11391171
CompareState *s = container_of(pri_rs, CompareState, pri_rs);
@@ -1251,6 +1283,11 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
12511283
s->expired_scan_cycle = REGULAR_PACKET_CHECK_MS;
12521284
}
12531285

1286+
if (!max_queue_size) {
1287+
/* Set default queue size to 1024 */
1288+
max_queue_size = MAX_QUEUE_SIZE;
1289+
}
1290+
12541291
if (find_and_check_chardev(&chr, s->pri_indev, errp) ||
12551292
!qemu_chr_fe_init(&s->chr_pri_in, chr, errp)) {
12561293
return;
@@ -1370,6 +1407,10 @@ static void colo_compare_init(Object *obj)
13701407
compare_get_expired_scan_cycle,
13711408
compare_set_expired_scan_cycle, NULL, NULL);
13721409

1410+
object_property_add(obj, "max_queue_size", "uint32",
1411+
get_max_queue_size,
1412+
set_max_queue_size, NULL, NULL);
1413+
13731414
s->vnet_hdr = false;
13741415
object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr,
13751416
compare_set_vnet_hdr);

net/socket.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,13 +725,18 @@ int net_init_socket(const Netdev *netdev, const char *name,
725725
}
726726

727727
if (sock->has_fd) {
728-
int fd;
728+
int fd, ret;
729729

730730
fd = monitor_fd_param(cur_mon, sock->fd, errp);
731731
if (fd == -1) {
732732
return -1;
733733
}
734-
qemu_set_nonblock(fd);
734+
ret = qemu_try_set_nonblock(fd);
735+
if (ret < 0) {
736+
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
737+
name, fd);
738+
return -1;
739+
}
735740
if (!net_socket_fd_init(peer, "socket", name, fd, 1, sock->mcast,
736741
errp)) {
737742
return -1;

net/tap-bsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
211211
{
212212
}
213213

214-
int tap_probe_vnet_hdr(int fd)
214+
int tap_probe_vnet_hdr(int fd, Error **errp)
215215
{
216216
return 0;
217217
}

net/tap-linux.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,15 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
147147
}
148148
}
149149

150-
int tap_probe_vnet_hdr(int fd)
150+
int tap_probe_vnet_hdr(int fd, Error **errp)
151151
{
152152
struct ifreq ifr;
153153

154154
if (ioctl(fd, TUNGETIFF, &ifr) != 0) {
155-
error_report("TUNGETIFF ioctl() failed: %s", strerror(errno));
156-
return 0;
155+
/* TUNGETIFF is available since kernel v2.6.27 */
156+
error_setg_errno(errp, errno,
157+
"Unable to query TUNGETIFF on FD %d", fd);
158+
return -1;
157159
}
158160

159161
return ifr.ifr_flags & IFF_VNET_HDR;

net/tap-solaris.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
207207
{
208208
}
209209

210-
int tap_probe_vnet_hdr(int fd)
210+
int tap_probe_vnet_hdr(int fd, Error **errp)
211211
{
212212
return 0;
213213
}

net/tap-stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
3737
{
3838
}
3939

40-
int tap_probe_vnet_hdr(int fd)
40+
int tap_probe_vnet_hdr(int fd, Error **errp)
4141
{
4242
return 0;
4343
}

0 commit comments

Comments
 (0)