All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v2 1/5] virtio_net: Simplify call sites for virtio_net_hdr_{from,to}_skb().
@ 2016-11-18 23:40 Jarno Rajahalme
  2016-11-18 23:40 ` [PATCH net-next v2 2/5] virtio_net.h: Fix comment Jarno Rajahalme
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Jarno Rajahalme @ 2016-11-18 23:40 UTC (permalink / raw)
  To: netdev; +Cc: jarno

No point storing the return value of virtio_net_hdr_to_skb() or
virtio_net_hdr_from_skb() to a variable when the value is used only
once as a boolean in an immediately following if statement.

Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
---
 drivers/net/macvtap.c | 5 ++---
 drivers/net/tun.c     | 8 +++-----
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
index 070e329..5da9861 100644
--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
@@ -821,9 +821,8 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q,
 		if (iov_iter_count(iter) < vnet_hdr_len)
 			return -EINVAL;
 
-		ret = virtio_net_hdr_from_skb(skb, &vnet_hdr,
-					      macvtap_is_little_endian(q));
-		if (ret)
+		if (virtio_net_hdr_from_skb(skb, &vnet_hdr,
+					    macvtap_is_little_endian(q)))
 			BUG();
 
 		if (copy_to_iter(&vnet_hdr, sizeof(vnet_hdr), iter) !=
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 1588469..3b8d8cc 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1252,8 +1252,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
 		return -EFAULT;
 	}
 
-	err = virtio_net_hdr_to_skb(skb, &gso, tun_is_little_endian(tun));
-	if (err) {
+	if (virtio_net_hdr_to_skb(skb, &gso, tun_is_little_endian(tun))) {
 		this_cpu_inc(tun->pcpu_stats->rx_frame_errors);
 		kfree_skb(skb);
 		return -EINVAL;
@@ -1367,9 +1366,8 @@ static ssize_t tun_put_user(struct tun_struct *tun,
 		if (iov_iter_count(iter) < vnet_hdr_sz)
 			return -EINVAL;
 
-		ret = virtio_net_hdr_from_skb(skb, &gso,
-					      tun_is_little_endian(tun));
-		if (ret) {
+		if (virtio_net_hdr_from_skb(skb, &gso,
+					    tun_is_little_endian(tun))) {
 			struct skb_shared_info *sinfo = skb_shinfo(skb);
 			pr_err("unexpected GSO type: "
 			       "0x%x, gso_size %d, hdr_len %d\n",
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next v2 2/5] virtio_net.h: Fix comment.
  2016-11-18 23:40 [PATCH net-next v2 1/5] virtio_net: Simplify call sites for virtio_net_hdr_{from,to}_skb() Jarno Rajahalme
@ 2016-11-18 23:40 ` Jarno Rajahalme
  2016-11-19 15:37   ` David Miller
  2016-11-18 23:40 ` [PATCH net-next v2 3/5] virtio_net: Do not clear memory for struct virtio_net_hdr twice Jarno Rajahalme
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Jarno Rajahalme @ 2016-11-18 23:40 UTC (permalink / raw)
  To: netdev; +Cc: jarno

Fix incorrent comment after the final #endif.

Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
---
 include/linux/virtio_net.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 1c912f8..74f1e33 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -98,4 +98,4 @@ static inline int virtio_net_hdr_from_skb(const struct sk_buff *skb,
 	return 0;
 }
 
-#endif /* _LINUX_VIRTIO_BYTEORDER */
+#endif /* _LINUX_VIRTIO_NET_H */
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next v2 3/5] virtio_net: Do not clear memory for struct virtio_net_hdr twice.
  2016-11-18 23:40 [PATCH net-next v2 1/5] virtio_net: Simplify call sites for virtio_net_hdr_{from,to}_skb() Jarno Rajahalme
  2016-11-18 23:40 ` [PATCH net-next v2 2/5] virtio_net.h: Fix comment Jarno Rajahalme
@ 2016-11-18 23:40 ` Jarno Rajahalme
  2016-11-19 15:37   ` David Miller
  2016-11-18 23:40 ` [PATCH net-next v2 4/5] af_packet: Use virtio_net_hdr_to_skb() Jarno Rajahalme
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Jarno Rajahalme @ 2016-11-18 23:40 UTC (permalink / raw)
  To: netdev; +Cc: jarno

virtio_net_hdr_from_skb() clears the memory for the header, so there
is no point for the callers to do the same.

Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
---
 drivers/net/tun.c          | 3 +--
 include/linux/virtio_net.h | 2 +-
 net/packet/af_packet.c     | 2 --
 3 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 3b8d8cc..64e694c 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1360,8 +1360,7 @@ static ssize_t tun_put_user(struct tun_struct *tun,
 	}
 
 	if (vnet_hdr_sz) {
-		struct virtio_net_hdr gso = { 0 }; /* no info leak */
-		int ret;
+		struct virtio_net_hdr gso;
 
 		if (iov_iter_count(iter) < vnet_hdr_sz)
 			return -EINVAL;
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 74f1e33..6620400 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -58,7 +58,7 @@ static inline int virtio_net_hdr_from_skb(const struct sk_buff *skb,
 					  struct virtio_net_hdr *hdr,
 					  bool little_endian)
 {
-	memset(hdr, 0, sizeof(*hdr));
+	memset(hdr, 0, sizeof(*hdr));   /* no info leak */
 
 	if (skb_is_gso(skb)) {
 		struct skb_shared_info *sinfo = skb_shinfo(skb);
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index d2238b2..abe6c0b 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1970,8 +1970,6 @@ static unsigned int run_filter(struct sk_buff *skb,
 static int __packet_rcv_vnet(const struct sk_buff *skb,
 			     struct virtio_net_hdr *vnet_hdr)
 {
-	*vnet_hdr = (const struct virtio_net_hdr) { 0 };
-
 	if (virtio_net_hdr_from_skb(skb, vnet_hdr, vio_le()))
 		BUG();
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next v2 4/5] af_packet: Use virtio_net_hdr_to_skb().
  2016-11-18 23:40 [PATCH net-next v2 1/5] virtio_net: Simplify call sites for virtio_net_hdr_{from,to}_skb() Jarno Rajahalme
  2016-11-18 23:40 ` [PATCH net-next v2 2/5] virtio_net.h: Fix comment Jarno Rajahalme
  2016-11-18 23:40 ` [PATCH net-next v2 3/5] virtio_net: Do not clear memory for struct virtio_net_hdr twice Jarno Rajahalme
@ 2016-11-18 23:40 ` Jarno Rajahalme
  2016-11-19 15:37   ` David Miller
  2016-11-18 23:40 ` [PATCH net-next v2 5/5] af_packet: Use virtio_net_hdr_from_skb() directly Jarno Rajahalme
  2016-11-19 15:37 ` [PATCH net-next v2 1/5] virtio_net: Simplify call sites for virtio_net_hdr_{from,to}_skb() David Miller
  4 siblings, 1 reply; 10+ messages in thread
From: Jarno Rajahalme @ 2016-11-18 23:40 UTC (permalink / raw)
  To: netdev; +Cc: jarno

Use the common virtio_net_hdr_to_skb() instead of open coding it.
Other call sites were changed by commit fd2a0437dc, but this one was
missed, maybe because it is split in two parts of the source code.

Interim comparisons of 'vnet_hdr->gso_type' still work as both the
vnet_hdr and skb notion of gso_type is zero when there is no gso.

Fixes: fd2a0437dc ("virtio_net: introduce virtio_net_hdr_{from,to}_skb")
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
---
 net/packet/af_packet.c | 51 +++-----------------------------------------------
 1 file changed, 3 insertions(+), 48 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index abe6c0b..1816b77 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2388,8 +2388,6 @@ static void tpacket_set_protocol(const struct net_device *dev,
 
 static int __packet_snd_vnet_parse(struct virtio_net_hdr *vnet_hdr, size_t len)
 {
-	unsigned short gso_type = 0;
-
 	if ((vnet_hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
 	    (__virtio16_to_cpu(vio_le(), vnet_hdr->csum_start) +
 	     __virtio16_to_cpu(vio_le(), vnet_hdr->csum_offset) + 2 >
@@ -2401,29 +2399,6 @@ static int __packet_snd_vnet_parse(struct virtio_net_hdr *vnet_hdr, size_t len)
 	if (__virtio16_to_cpu(vio_le(), vnet_hdr->hdr_len) > len)
 		return -EINVAL;
 
-	if (vnet_hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
-		switch (vnet_hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
-		case VIRTIO_NET_HDR_GSO_TCPV4:
-			gso_type = SKB_GSO_TCPV4;
-			break;
-		case VIRTIO_NET_HDR_GSO_TCPV6:
-			gso_type = SKB_GSO_TCPV6;
-			break;
-		case VIRTIO_NET_HDR_GSO_UDP:
-			gso_type = SKB_GSO_UDP;
-			break;
-		default:
-			return -EINVAL;
-		}
-
-		if (vnet_hdr->gso_type & VIRTIO_NET_HDR_GSO_ECN)
-			gso_type |= SKB_GSO_TCP_ECN;
-
-		if (vnet_hdr->gso_size == 0)
-			return -EINVAL;
-	}
-
-	vnet_hdr->gso_type = gso_type;	/* changes type, temporary storage */
 	return 0;
 }
 
@@ -2443,27 +2418,6 @@ static int packet_snd_vnet_parse(struct msghdr *msg, size_t *len,
 	return __packet_snd_vnet_parse(vnet_hdr, *len);
 }
 
-static int packet_snd_vnet_gso(struct sk_buff *skb,
-			       struct virtio_net_hdr *vnet_hdr)
-{
-	if (vnet_hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
-		u16 s = __virtio16_to_cpu(vio_le(), vnet_hdr->csum_start);
-		u16 o = __virtio16_to_cpu(vio_le(), vnet_hdr->csum_offset);
-
-		if (!skb_partial_csum_set(skb, s, o))
-			return -EINVAL;
-	}
-
-	skb_shinfo(skb)->gso_size =
-		__virtio16_to_cpu(vio_le(), vnet_hdr->gso_size);
-	skb_shinfo(skb)->gso_type = vnet_hdr->gso_type;
-
-	/* Header must be checked, and gso_segs computed. */
-	skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
-	skb_shinfo(skb)->gso_segs = 0;
-	return 0;
-}
-
 static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
 		void *frame, struct net_device *dev, void *data, int tp_len,
 		__be16 proto, unsigned char *addr, int hlen, int copylen,
@@ -2723,7 +2677,8 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
 			}
 		}
 
-		if (po->has_vnet_hdr && packet_snd_vnet_gso(skb, vnet_hdr)) {
+		if (po->has_vnet_hdr && virtio_net_hdr_to_skb(skb, vnet_hdr,
+							      vio_le())) {
 			tp_len = -EINVAL;
 			goto tpacket_error;
 		}
@@ -2914,7 +2869,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 	packet_pick_tx_queue(dev, skb);
 
 	if (po->has_vnet_hdr) {
-		err = packet_snd_vnet_gso(skb, &vnet_hdr);
+		err = virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le());
 		if (err)
 			goto out_free;
 		len += sizeof(vnet_hdr);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next v2 5/5] af_packet: Use virtio_net_hdr_from_skb() directly.
  2016-11-18 23:40 [PATCH net-next v2 1/5] virtio_net: Simplify call sites for virtio_net_hdr_{from,to}_skb() Jarno Rajahalme
                   ` (2 preceding siblings ...)
  2016-11-18 23:40 ` [PATCH net-next v2 4/5] af_packet: Use virtio_net_hdr_to_skb() Jarno Rajahalme
@ 2016-11-18 23:40 ` Jarno Rajahalme
  2016-11-19 15:37   ` David Miller
  2016-11-19 15:37 ` [PATCH net-next v2 1/5] virtio_net: Simplify call sites for virtio_net_hdr_{from,to}_skb() David Miller
  4 siblings, 1 reply; 10+ messages in thread
From: Jarno Rajahalme @ 2016-11-18 23:40 UTC (permalink / raw)
  To: netdev; +Cc: jarno

Remove static function __packet_rcv_vnet(), which only called
virtio_net_hdr_from_skb() and BUG()ged out if an error code was
returned.  Instead, call virtio_net_hdr_from_skb() from the former
call sites of __packet_rcv_vnet() and actually use the error handling
code that is already there.

Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
---
 net/packet/af_packet.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 1816b77..fab9bbf 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1967,15 +1967,6 @@ static unsigned int run_filter(struct sk_buff *skb,
 	return res;
 }
 
-static int __packet_rcv_vnet(const struct sk_buff *skb,
-			     struct virtio_net_hdr *vnet_hdr)
-{
-	if (virtio_net_hdr_from_skb(skb, vnet_hdr, vio_le()))
-		BUG();
-
-	return 0;
-}
-
 static int packet_rcv_vnet(struct msghdr *msg, const struct sk_buff *skb,
 			   size_t *len)
 {
@@ -1985,7 +1976,7 @@ static int packet_rcv_vnet(struct msghdr *msg, const struct sk_buff *skb,
 		return -EINVAL;
 	*len -= sizeof(vnet_hdr);
 
-	if (__packet_rcv_vnet(skb, &vnet_hdr))
+	if (virtio_net_hdr_from_skb(skb, &vnet_hdr, vio_le()))
 		return -EINVAL;
 
 	return memcpy_to_msg(msg, (void *)&vnet_hdr, sizeof(vnet_hdr));
@@ -2244,8 +2235,9 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
 	spin_unlock(&sk->sk_receive_queue.lock);
 
 	if (po->has_vnet_hdr) {
-		if (__packet_rcv_vnet(skb, h.raw + macoff -
-					   sizeof(struct virtio_net_hdr))) {
+		if (virtio_net_hdr_from_skb(skb, h.raw + macoff -
+					    sizeof(struct virtio_net_hdr),
+					    vio_le())) {
 			spin_lock(&sk->sk_receive_queue.lock);
 			goto drop_n_account;
 		}
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next v2 1/5] virtio_net: Simplify call sites for virtio_net_hdr_{from,to}_skb().
  2016-11-18 23:40 [PATCH net-next v2 1/5] virtio_net: Simplify call sites for virtio_net_hdr_{from,to}_skb() Jarno Rajahalme
                   ` (3 preceding siblings ...)
  2016-11-18 23:40 ` [PATCH net-next v2 5/5] af_packet: Use virtio_net_hdr_from_skb() directly Jarno Rajahalme
@ 2016-11-19 15:37 ` David Miller
  4 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2016-11-19 15:37 UTC (permalink / raw)
  To: jarno; +Cc: netdev

From: Jarno Rajahalme <jarno@ovn.org>
Date: Fri, 18 Nov 2016 15:40:38 -0800

> No point storing the return value of virtio_net_hdr_to_skb() or
> virtio_net_hdr_from_skb() to a variable when the value is used only
> once as a boolean in an immediately following if statement.
> 
> Signed-off-by: Jarno Rajahalme <jarno@ovn.org>

Applied.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next v2 2/5] virtio_net.h: Fix comment.
  2016-11-18 23:40 ` [PATCH net-next v2 2/5] virtio_net.h: Fix comment Jarno Rajahalme
@ 2016-11-19 15:37   ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2016-11-19 15:37 UTC (permalink / raw)
  To: jarno; +Cc: netdev

From: Jarno Rajahalme <jarno@ovn.org>
Date: Fri, 18 Nov 2016 15:40:39 -0800

> Fix incorrent comment after the final #endif.
> 
> Signed-off-by: Jarno Rajahalme <jarno@ovn.org>

Applied.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next v2 3/5] virtio_net: Do not clear memory for struct virtio_net_hdr twice.
  2016-11-18 23:40 ` [PATCH net-next v2 3/5] virtio_net: Do not clear memory for struct virtio_net_hdr twice Jarno Rajahalme
@ 2016-11-19 15:37   ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2016-11-19 15:37 UTC (permalink / raw)
  To: jarno; +Cc: netdev

From: Jarno Rajahalme <jarno@ovn.org>
Date: Fri, 18 Nov 2016 15:40:40 -0800

> virtio_net_hdr_from_skb() clears the memory for the header, so there
> is no point for the callers to do the same.
> 
> Signed-off-by: Jarno Rajahalme <jarno@ovn.org>

Applied.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next v2 4/5] af_packet: Use virtio_net_hdr_to_skb().
  2016-11-18 23:40 ` [PATCH net-next v2 4/5] af_packet: Use virtio_net_hdr_to_skb() Jarno Rajahalme
@ 2016-11-19 15:37   ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2016-11-19 15:37 UTC (permalink / raw)
  To: jarno; +Cc: netdev

From: Jarno Rajahalme <jarno@ovn.org>
Date: Fri, 18 Nov 2016 15:40:41 -0800

> Use the common virtio_net_hdr_to_skb() instead of open coding it.
> Other call sites were changed by commit fd2a0437dc, but this one was
> missed, maybe because it is split in two parts of the source code.
> 
> Interim comparisons of 'vnet_hdr->gso_type' still work as both the
> vnet_hdr and skb notion of gso_type is zero when there is no gso.
> 
> Fixes: fd2a0437dc ("virtio_net: introduce virtio_net_hdr_{from,to}_skb")
> Signed-off-by: Jarno Rajahalme <jarno@ovn.org>

Applied.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next v2 5/5] af_packet: Use virtio_net_hdr_from_skb() directly.
  2016-11-18 23:40 ` [PATCH net-next v2 5/5] af_packet: Use virtio_net_hdr_from_skb() directly Jarno Rajahalme
@ 2016-11-19 15:37   ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2016-11-19 15:37 UTC (permalink / raw)
  To: jarno; +Cc: netdev

From: Jarno Rajahalme <jarno@ovn.org>
Date: Fri, 18 Nov 2016 15:40:42 -0800

> Remove static function __packet_rcv_vnet(), which only called
> virtio_net_hdr_from_skb() and BUG()ged out if an error code was
> returned.  Instead, call virtio_net_hdr_from_skb() from the former
> call sites of __packet_rcv_vnet() and actually use the error handling
> code that is already there.
> 
> Signed-off-by: Jarno Rajahalme <jarno@ovn.org>

Applied.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-11-19 15:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-18 23:40 [PATCH net-next v2 1/5] virtio_net: Simplify call sites for virtio_net_hdr_{from,to}_skb() Jarno Rajahalme
2016-11-18 23:40 ` [PATCH net-next v2 2/5] virtio_net.h: Fix comment Jarno Rajahalme
2016-11-19 15:37   ` David Miller
2016-11-18 23:40 ` [PATCH net-next v2 3/5] virtio_net: Do not clear memory for struct virtio_net_hdr twice Jarno Rajahalme
2016-11-19 15:37   ` David Miller
2016-11-18 23:40 ` [PATCH net-next v2 4/5] af_packet: Use virtio_net_hdr_to_skb() Jarno Rajahalme
2016-11-19 15:37   ` David Miller
2016-11-18 23:40 ` [PATCH net-next v2 5/5] af_packet: Use virtio_net_hdr_from_skb() directly Jarno Rajahalme
2016-11-19 15:37   ` David Miller
2016-11-19 15:37 ` [PATCH net-next v2 1/5] virtio_net: Simplify call sites for virtio_net_hdr_{from,to}_skb() David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.