Skip to content

Commit

Permalink
virtio-net: restore VIRTIO_HDR_F_DATA_VALID on receiving
Browse files Browse the repository at this point in the history
Commit 501db51 ("virtio: don't set VIRTIO_NET_HDR_F_DATA_VALID on
xmit") in fact disables VIRTIO_HDR_F_DATA_VALID on receiving path too,
fixing this by adding a hint (has_data_valid) and set it only on the
receiving path.

Cc: Rolf Neugebauer <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
Acked-by: Rolf Neugebauer <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jasowang authored and davem330 committed Jan 20, 2017
1 parent 69fed99 commit 6391a44
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion drivers/net/macvtap.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
return -EINVAL;

if (virtio_net_hdr_from_skb(skb, &vnet_hdr,
macvtap_is_little_endian(q)))
macvtap_is_little_endian(q), true))
BUG();

if (copy_to_iter(&vnet_hdr, sizeof(vnet_hdr), iter) !=
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ static ssize_t tun_put_user(struct tun_struct *tun,
return -EINVAL;

if (virtio_net_hdr_from_skb(skb, &gso,
tun_is_little_endian(tun))) {
tun_is_little_endian(tun), true)) {
struct skb_shared_info *sinfo = skb_shinfo(skb);
pr_err("unexpected GSO type: "
"0x%x, gso_size %d, hdr_len %d\n",
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
hdr = skb_vnet_hdr(skb);

if (virtio_net_hdr_from_skb(skb, &hdr->hdr,
virtio_is_little_endian(vi->vdev)))
virtio_is_little_endian(vi->vdev), false))
BUG();

if (vi->mergeable_rx_bufs)
Expand Down
6 changes: 5 additions & 1 deletion include/linux/virtio_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,

static inline int virtio_net_hdr_from_skb(const struct sk_buff *skb,
struct virtio_net_hdr *hdr,
bool little_endian)
bool little_endian,
bool has_data_valid)
{
memset(hdr, 0, sizeof(*hdr)); /* no info leak */

Expand Down Expand Up @@ -91,6 +92,9 @@ static inline int virtio_net_hdr_from_skb(const struct sk_buff *skb,
skb_checksum_start_offset(skb));
hdr->csum_offset = __cpu_to_virtio16(little_endian,
skb->csum_offset);
} else if (has_data_valid &&
skb->ip_summed == CHECKSUM_UNNECESSARY) {
hdr->flags = VIRTIO_NET_HDR_F_DATA_VALID;
} /* else everything is zero */

return 0;
Expand Down
4 changes: 2 additions & 2 deletions net/packet/af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ static int packet_rcv_vnet(struct msghdr *msg, const struct sk_buff *skb,
return -EINVAL;
*len -= sizeof(vnet_hdr);

if (virtio_net_hdr_from_skb(skb, &vnet_hdr, vio_le()))
if (virtio_net_hdr_from_skb(skb, &vnet_hdr, vio_le(), true))
return -EINVAL;

return memcpy_to_msg(msg, (void *)&vnet_hdr, sizeof(vnet_hdr));
Expand Down Expand Up @@ -2237,7 +2237,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
if (po->has_vnet_hdr) {
if (virtio_net_hdr_from_skb(skb, h.raw + macoff -
sizeof(struct virtio_net_hdr),
vio_le())) {
vio_le(), true)) {
spin_lock(&sk->sk_receive_queue.lock);
goto drop_n_account;
}
Expand Down

0 comments on commit 6391a44

Please sign in to comment.