[PATCH v2] net: check for refcount if pop a stacked dst_entry

Previous thread: [PATCH net-next-2.6] raw: avoid two atomics in xmit by Eric Dumazet on Friday, June 4, 2010 - 1:23 am. (2 messages)

Next thread: by info@citytaxi.com.hr on Friday, June 4, 2010 - 3:47 am. (1 message)
From: Steffen Klassert
Date: Friday, June 4, 2010 - 3:40 am

I see the warning below frequently when I'm running iperf on a IPsec
connection. It seems that dst_pop() drops a refcount on a noref
dst_entry. I was able to fix this by changing dst_pop() to a new
function skb_dst_pop() which uses skb_dst_drop(skb) instead of
dst_release(dst) to drop the reference if necessary. I'll send the
patch that fixed the issue for me in repy to this mail.
I don't know that much about the noref work, so I'm not sure whether
this is the right fix, but I got rid of the warning at least.

Steffen

Jun  4 10:21:24 mainline kernel: [ 1334.203913] WARNING: at /home/secunet/git/linux-sinafe-2.6/net/core/dst.c:276 xfrm_output_resume+0x2d3/0x35e()
Jun  4 10:21:24 mainline kernel: [ 1334.203915] Hardware name:         
Jun  4 10:21:24 mainline kernel: [ 1334.203916] Modules linked in: authenc esp4 xfrm4_mode_tunnel aes_x86_64 aes_generic cbc sha1_generic xfrm_user ipv6 acpi_cpufreq mperf cpufreq_userspace cpufreq_stats cpufreq_ondemand freq_table cpufreq_conservative cpufreq_powersave container fan video output sbs sbshc battery af_packet ac fuse loop option usb_wwan usbserial sr_mod cdrom iTCO_wdt ehci_hcd thermal uhci_hcd serio_raw psmouse tpm_tis tpm tpm_bios iTCO_vendor_support pcspkr processor thermal_sys evdev usbcore button ata_generic
Jun  4 10:21:24 mainline kernel: [ 1334.203944] Pid: 3337, comm: dd Tainted: G        W   2.6.35-rc1+ #276
Jun  4 10:21:24 mainline kernel: [ 1334.203946] Call Trace:
Jun  4 10:21:24 mainline kernel: [ 1334.203947]  <IRQ>  [<ffffffff81261fbb>] ? xfrm_output_resume+0x2d3/0x35e
Jun  4 10:21:24 mainline kernel: [ 1334.203952]  [<ffffffff81261fbb>] ? xfrm_output_resume+0x2d3/0x35e
Jun  4 10:21:24 mainline kernel: [ 1334.203955]  [<ffffffff8102700d>] ? warn_slowpath_common+0x78/0x8d
Jun  4 10:21:24 mainline kernel: [ 1334.203958]  [<ffffffff81261fbb>] ? xfrm_output_resume+0x2d3/0x35e
Jun  4 10:21:24 mainline kernel: [ 1334.203961]  [<ffffffff8122bbe0>] ? ip_queue_xmit+0x2bc/0x304
Jun  4 10:21:24 mainline kernel: [ 1334.203964]  ...
From: Steffen Klassert
Date: Friday, June 4, 2010 - 3:41 am

xfrm triggers a warning if dst_pop() drops a refcount
on a noref dst. This patch changes dst_pop() to
skb_dst_pop(). skb_dst_pop() drops the refcnt only
on a refcounted dst.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 include/net/dst.h      |    6 +++---
 net/xfrm/xfrm_output.c |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/net/dst.h b/include/net/dst.h
index 612069b..acd1538 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -250,11 +250,11 @@ static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev)
  * Linux networking.  Thus, destinations are stackable.
  */
 
-static inline struct dst_entry *dst_pop(struct dst_entry *dst)
+static inline struct dst_entry *skb_dst_pop(struct sk_buff *skb)
 {
-	struct dst_entry *child = dst_clone(dst->child);
+	struct dst_entry *child = dst_clone(skb_dst(skb)->child);
 
-	dst_release(dst);
+	skb_dst_drop(skb);
 	return child;
 }
 
diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
index 6a32915..db62a06 100644
--- a/net/xfrm/xfrm_output.c
+++ b/net/xfrm/xfrm_output.c
@@ -95,7 +95,7 @@ resume:
 			goto error_nolock;
 		}
 
-		dst = dst_pop(dst);
+		dst = skb_dst_pop(skb);
 		if (!dst) {
 			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
 			err = -EHOSTUNREACH;
-- 
1.5.6.5

--

From: Eric Dumazet
Date: Friday, June 4, 2010 - 3:51 am

Hmm, this might fix the thing, but we probably can do it without the
dst_clone(), if you replace the 

skb_dst_set(skb, dst);

by 

skb_dst_set_noref(skb, dst);



--

From: Steffen Klassert
Date: Friday, June 4, 2010 - 4:23 am

Yes, this should work too. I'll update the patch to use
skb_dst_set_noref() in xfrm_output_one() and remove the 
dst_clone() in skb_dst_pop().
--

From: Steffen Klassert
Date: Friday, June 4, 2010 - 4:57 am

xfrm triggers a warning if dst_pop() drops a refcount
on a noref dst. This patch changes dst_pop() to
skb_dst_pop(). skb_dst_pop() drops the refcnt only
on a refcounted dst. Also we don't clone the child
dst_entry, so it is not refcounted and we can use
skb_dst_set_noref() in xfrm_output_one().

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 include/net/dst.h      |    6 +++---
 net/xfrm/xfrm_output.c |    4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/net/dst.h b/include/net/dst.h
index 612069b..81d1413 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -250,11 +250,11 @@ static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev)
  * Linux networking.  Thus, destinations are stackable.
  */
 
-static inline struct dst_entry *dst_pop(struct dst_entry *dst)
+static inline struct dst_entry *skb_dst_pop(struct sk_buff *skb)
 {
-	struct dst_entry *child = dst_clone(dst->child);
+	struct dst_entry *child = skb_dst(skb)->child;
 
-	dst_release(dst);
+	skb_dst_drop(skb);
 	return child;
 }
 
diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
index 6a32915..a3cca0a 100644
--- a/net/xfrm/xfrm_output.c
+++ b/net/xfrm/xfrm_output.c
@@ -95,13 +95,13 @@ resume:
 			goto error_nolock;
 		}
 
-		dst = dst_pop(dst);
+		dst = skb_dst_pop(skb);
 		if (!dst) {
 			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
 			err = -EHOSTUNREACH;
 			goto error_nolock;
 		}
-		skb_dst_set(skb, dst);
+		skb_dst_set_noref(skb, dst);
 		x = dst->xfrm;
 	} while (x && !(x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL));
 
-- 
1.5.6.5

--

From: Eric Dumazet
Date: Friday, June 4, 2010 - 5:06 am

Thanks a lot Steffen !

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>



--

From: David Miller
Date: Friday, June 4, 2010 - 3:58 pm

From: Eric Dumazet <eric.dumazet@gmail.com>

Applied, thanks guys!
--

Previous thread: [PATCH net-next-2.6] raw: avoid two atomics in xmit by Eric Dumazet on Friday, June 4, 2010 - 1:23 am. (2 messages)

Next thread: by info@citytaxi.com.hr on Friday, June 4, 2010 - 3:47 am. (1 message)