Skip to contentSkip to conversation

core: adjust checks for calling skb_copy_bits in skb_try_coalesce

PATCH In review [email protected] 2 participants 6 messages Sep 20, 2012

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

PATCH 1/1 core: adjust checks for calling skb_copy_bits in skb_try_coalesce

From: Li RongQing <[email protected]>

Ensure that frags and frags_list of dst skb are empty if need to call skb_copy_bits, or else it will break the data sequence.

---
 net/core/skbuff.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
net/core/skbuff.c +4 -4
index fe00d12..f0b9446 100644
@@ -3455,15 +3455,15 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
 	if (skb_cloned(to))
 		return false;
 
-	if (len <= skb_tailroom(to)) {
+	if (skb_has_frag_list(to) || skb_has_frag_list(from))
+		return false;
+
+	if (len <= skb_tailroom(to) && !skb_shinfo(to)->nr_frags) {
 		BUG_ON(skb_copy_bits(from, 0, skb_put(to, len), len));
 		*delta_truesize = 0;
 		return true;
 	}
 
-	if (skb_has_frag_list(to) || skb_has_frag_list(from))
-		return false;
-
 	if (skb_headlen(from) != 0) {
 		struct page *page;
 		unsigned int offset;
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 25 lines · On Thu, 2012-09-20 at 11:19 +0800, [email protected] wrote:

From: Li RongQing <[email protected]>

Ensure that frags and frags_list of dst skb are empty if need to call skb_copy_bits, or else it will break the data sequence.

---
 net/core/skbuff.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
net/core/skbuff.c +4 -1
index fe00d12..f0b9446 100644
@@ -3455,15 +3455,15 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
 	if (skb_cloned(to))
 		return false;
 
-	if (len <= skb_tailroom(to)) {
+	if (skb_has_frag_list(to) || skb_has_frag_list(from))
+		return false;
+
+	if (len <= skb_tailroom(to) && !skb_shinfo(to)->nr_frags) {
 		BUG_ON(skb_copy_bits(from, 0, skb_put(to, len), len));

net/core/skbuff.c bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, · line 3469

Quoted 10 lines
net/core/skbuff.c +0 -3
 		*delta_truesize = 0;
 		return true;
 	}
 
-	if (skb_has_frag_list(to) || skb_has_frag_list(from))
-		return false;
-
 	if (skb_headlen(from) != 0) {
 		struct page *page;
 		unsigned int offset;

This is not needed at all.

#2 lore raw
Quoted 5 lines
Quoted 1 line
              unsigned int offset;

This is not needed at all.

I think the below modification maybe needed,
if (len <= skb_tailroom(to) && !skb_shinfo(to)->nr_frags) { ..
}

First skb A is added to skb TO frags, since the len is larger than skb_tailroot(TO), but second len of skb B is less than skb_tailroot(To) which will call skb_copy_bits.

Of cause, this kinds of cases maybe only exist on my mind.

-Roy

#3 lore raw
Quoted 11 lines · RongQing Li
Quoted 5 lines
Quoted 1 line
              unsigned int offset;

This is not needed at all.

I think the below modification maybe needed,
if (len <= skb_tailroom(to) && !skb_shinfo(to)->nr_frags) { ..
}

Quoted 6 lines

First skb A is added to skb TO frags, since the len is larger than skb_tailroot(TO), but second len of skb B is less than skb_tailroot(To) which will call skb_copy_bits.

Of cause, this kinds of cases maybe only exist on my mind.

Did you read skb_tailroom(to) definition by any chance ?

static inline int skb_tailroom(const struct sk_buff *skb)

{
        return skb_is_nonlinear(skb) ? 0 : skb->end - skb->tail;
}

Current code is fine, because if @to is linear, its ... linear.

#4 lore raw
Quoted 11 lines

Did you read skb_tailroom(to) definition by any chance ?

static inline int skb_tailroom(const struct sk_buff *skb)

{
        return skb_is_nonlinear(skb) ? 0 : skb->end - skb->tail;
}

Current code is fine, because if @to is linear, its ... linear.

I am wrong, thanks.

#5 lore raw
Quoted 2 lines · RongQing Li

I am wrong, thanks.

Thanks for taking a look at this stuff ;)