Skip to contentSkip to conversation

net: openvswitch: don't call pad_packet if not necessary

PATCH Applied [email protected] 3 participants 3 messages Nov 14, 2019 – Nov 15, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: openvswitch: don't call pad_packet if not necessary

From: Tonghao Zhang <[email protected]>

The nla_put_u16/nla_put_u32 makes sure that
*attrlen is align. The call tree is that:

nla_put_u16/nla_put_u32
-> nla_put attrlen = sizeof(u16) or sizeof(u32)
-> __nla_put attrlen
-> __nla_reserve attrlen
-> skb_put(skb, nla_total_size(attrlen))

nla_total_size returns the total length of attribute including padding.

Cc Joe Stringer <[email protected]>
Cc William Tu <[email protected]>
---
 net/openvswitch/datapath.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
net/openvswitch/datapath.c +8 -14
index 8ce1f773378d..93d4991ddc1f 100644
@@ -487,23 +487,17 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
 	}
 
 	/* Add OVS_PACKET_ATTR_MRU */
-	if (upcall_info->mru) {
-		if (nla_put_u16(user_skb, OVS_PACKET_ATTR_MRU,
-				upcall_info->mru)) {
-			err = -ENOBUFS;
-			goto out;
-		}
-		pad_packet(dp, user_skb);
+	if (upcall_info->mru &&
+	    nla_put_u16(user_skb, OVS_PACKET_ATTR_MRU, upcall_info->mru)) {
+		err = -ENOBUFS;
+		goto out;
 	}
 
 	/* Add OVS_PACKET_ATTR_LEN when packet is truncated */
-	if (cutlen > 0) {
-		if (nla_put_u32(user_skb, OVS_PACKET_ATTR_LEN,
-				skb->len)) {
-			err = -ENOBUFS;
-			goto out;
-		}
-		pad_packet(dp, user_skb);
+	if (cutlen > 0 &&
+	    nla_put_u32(user_skb, OVS_PACKET_ATTR_LEN, skb->len)) {
+		err = -ENOBUFS;
+		goto out;
 	}
 
 	/* Add OVS_PACKET_ATTR_HASH */
Signature · 1 line
2.23.0
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · On Thu, Nov 14, 2019 at 7:51 AM <[email protected]> wrote:

From: Tonghao Zhang <[email protected]>

The nla_put_u16/nla_put_u32 makes sure that
*attrlen is align. The call tree is that:

nla_put_u16/nla_put_u32

  -> nla_put            attrlen = sizeof(u16) or sizeof(u32)
  -> __nla_put          attrlen
  -> __nla_reserve      attrlen

-> skb_put(skb, nla_total_size(attrlen))

Quoted 7 lines

nla_total_size returns the total length of attribute including padding.

Cc Joe Stringer <[email protected]>
Cc William Tu <[email protected]>

---

maintainer Applied
#2 lore raw
In reply to [email protected]

From: [email protected]
Date: Thu, 14 Nov 2019 23:51:08 +0800

Quoted 11 lines

From: Tonghao Zhang <[email protected]>

The nla_put_u16/nla_put_u32 makes sure that
*attrlen is align. The call tree is that:

nla_put_u16/nla_put_u32
-> nla_put attrlen = sizeof(u16) or sizeof(u32)
-> __nla_put attrlen
-> __nla_reserve attrlen
-> skb_put(skb, nla_total_size(attrlen))

Quoted 6 lines

nla_total_size returns the total length of attribute including padding.

Cc Joe Stringer <[email protected]>
Cc William Tu <[email protected]>

Applied, thanks.