Skip to contentSkip to conversation

2.5.27 fix potential spinlocking race.

PATCH In review Trond Myklebust 3 participants 4 messages Jul 23, 2002 – Jul 24, 2002

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

PATCH 1/1 2.5.27 fix potential spinlocking race.

In case of socket transmission errors etc. kfree_skb(), and hence xprt_write_space() can potentially get called outside of a bh-safe context.

Cheers,
Trond

net/sunrpc/xprt.c +2 -2
diff -u --recursive --new-file linux-2.5.27/net/sunrpc/xprt.c linux-2.5.27-fix_wspace/net/sunrpc/xprt.c
@@ -966,10 +966,10 @@
 		return;
 
 	if (!xprt_test_and_set_wspace(xprt)) {
-		spin_lock(&xprt->sock_lock);
+		spin_lock_bh(&xprt->sock_lock);
 		if (xprt->snd_task && xprt->snd_task->tk_rpcwait == &xprt->pending)
 			rpc_wake_up_task(xprt->snd_task);
-		spin_unlock(&xprt->sock_lock);
+		spin_unlock_bh(&xprt->sock_lock);
 	}
 
 	if (test_bit(SOCK_NOSPACE, &sock->flags)) {
#1 lore raw

In case of socket transmission errors etc. kfree_skb(), and hence xprt_write_space() can potentially get called outside of a bh-safe context.

kfree_skb must occur within a BH context or better context.

When HW interrupt handlers free packets they use kfree_skb_irq() which schedules a software interrupt to really perform the kfree_skb work.

Therefore kfree_skb must always be invoked in BH or better context.

I think we need to reevaluate this situation before we apply this patch :-)

#2 lore raw
Quoted 6 lines · David S. Miller

In case of socket transmission errors etc. kfree_skb(), and hence xprt_write_space() can potentially get called outside of a bh-safe context.

kfree_skb must occur within a BH context or better context.

I think you're talking past each other.

Trond noticed that kfree_skb() can be called from a _non_ bh context, ie process context. So it needs to protect itself against other bh's on this CPU (which it wouldn't need to do if it was only called from a bh context).

So it's exactly your "better context" that is at stake here.

Linus

#3 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

" " == Linus Torvalds <[email protected]> writes:

> Trond noticed that kfree_skb() can be called from a _non_ bh > context, ie process context. So it needs to protect itself > against other bh's on this CPU (which it wouldn't need to do if > it was only called from a bh context).

> So it's exactly your "better context" that is at stake here.

Precisely. Not coming from a computer science background, the jargon sometimes gets the better of me ;-)

I was playing around with ip_build_xmit_slow() looking at alternatives for fixing the MSG_DONTWAIT fragmentation bug mentioned on this list a couple of weeks ago, when I noticed that it can call kfree_skb() from a process context. This again means that write_space() can get called without being wrapped in a local_bh_disable()/local_bh_enable() - style protection against softirqs.

Cheers,
Trond