Skip to contentSkip to conversation

skbuff: update sk truesize in pskb_expand_head

PATCH In review [email protected] 3 participants 6 messages Oct 14, 2011 – Oct 15, 2011

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

PATCH 1/1 skbuff: update sk truesize in pskb_expand_head

when pskb_expand_head reallocates header of &sk_buff, the sk truesize should be updated simultaneously

---
 net/core/skbuff.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
net/core/skbuff.c +1 -0
index 387703f..48e0be9 100644
@@ -920,6 +920,7 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
 	}
 	off = (data + nhead) - skb->head;
 
+	skb->truesize += (size - (skb_end_pointer(skb) - skb->head));
 	skb->head     = data;
 adjust_others:
 	skb->data    += off;
Signature · 1 line
1.7.1
maintainer
#1 lore raw

From: [email protected]
Date: Fri, 14 Oct 2011 15:39:30 +0800

Quoted 4 lines

when pskb_expand_head reallocates header of &sk_buff, the sk truesize should be updated simultaneously

I know you did not test this patch at all.

You can't modify the truesize because packets passed to this routine are often attached to a socket, thus if you change the truesize the socket memory accouting will be adjusted incorrectly later when the SKB is freed up.

Most SKB modifying functions have to operate with this restriction.

#4 lore raw
In reply to [email protected]

Le vendredi 14 octobre 2011 à 15:39 +0800, [email protected] a écrit :

Quoted 13 lines

when pskb_expand_head reallocates header of &sk_buff, the sk truesize should be updated simultaneously

---
 net/core/skbuff.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
net/core/skbuff.c +0 -0
index 387703f..48e0be9 100644

net/core/skbuff.c int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail, · line 926

Quoted 7 lines
net/core/skbuff.c +1 -0
@@ -920,6 +920,7 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
 	}
 	off = (data + nhead) - skb->head;
 
+	skb->truesize += (size - (skb_end_pointer(skb) - skb->head));
 	skb->head     = data;
 adjust_others:
 	skb->data    += off;

I dont believe this is needed or complete patch.

Callers that need an updated truesize do the adjustement.

#2 lore raw
In reply to David Miller

2011/10/14 David Miller <[email protected]>:

Quoted 8 lines

From: [email protected]
Date: Fri, 14 Oct 2011 15:39:30 +0800

Quoted 4 lines

when pskb_expand_head reallocates header of &sk_buff, the sk truesize should be updated simultaneously

Quoted 10 lines

I know you did not test this patch at all.

You can't modify the truesize because packets passed to this routine are often attached to a socket, thus if you change the truesize the socket memory accouting will be adjusted incorrectly later when the SKB is freed up.

Most SKB modifying functions have to operate with this restriction.

I am sorry I do not know how to test it in fact.

But I believe the adjustment is right here
About incorrectly impact on socket, I am consider it, but I still no idea about it.

Thanks.

#5 lore raw
In reply to Eric Dumazet

2011/10/14 Eric Dumazet <[email protected]>:

Quoted 7 lines

Le vendredi 14 octobre 2011 à 15:39 +0800, [email protected] a écrit :

I dont believe this is needed or complete patch.

Callers that need an updated truesize do the adjustement.

If we think the size which needs to adjust is small, we can ignore it, I accept it.

if Let caller to adjust it, I think the caller is hard to get the adjustment.

Do you think the below adjustment is needed?

void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
int size)

{
	skb_fill_page_desc(skb, i, page, off, size);
	skb->len += size;
	skb->data_len += size;

- skb->truesize += size;
+ skb->truesize += PAGE_SIZE;
}

Thanks
-Qing

maintainer
#3 lore raw
In reply to RongQing Li

From: RongQing Li <[email protected]>
Date: Sat, 15 Oct 2011 11:52:22 +0800

Quoted 2 lines

About incorrectly impact on socket, I am consider it, but I still no idea about it.

Sockets attach themselves to packets, and assign a destructor.

This destructor atomically decrements the receive or send buffer space used, and amount decremented is skb->truesize.

Therefore if you change skb->truesize on such an SKB, the wrong amount will be decremented when the destructor is called.

This is a very fundamental aspec of SKB handling, perhaps you should familiarize yourself with SKBs a little bit more before modifying code which manages them.