Skip to content

Commit c55fa3c

Browse files
Francois Romieudavem330
authored andcommitted
atm: remove an unnecessary loop
Andrey reported this kernel warning: WARNING: CPU: 0 PID: 4114 at kernel/sched/core.c:7737 __might_sleep+0x149/0x1a0 do not call blocking ops when !TASK_RUNNING; state=1 set at [<ffffffff813fcb22>] prepare_to_wait+0x182/0x530 The deeply nested alloc_skb is a problem. Diagnosis: nesting is wrong. It makes zero sense. Fix it and the implicit task state change problem automagically goes away. alloc_skb() does not need to be in the "while" loop. alloc_skb() does not need to be in the {prepare_to_wait/add_wait_queue ... finish_wait/remove_wait_queue} block. I claim that: - alloc_tx() should only perform the "wait_for_decent_tx_drain" part - alloc_skb() ought to be done directly in vcc_sendmsg - alloc_skb() failure can be handled gracefully in vcc_sendmsg - alloc_skb() may use a (m->msg_flags & MSG_DONTWAIT) dependent GFP_{KERNEL / ATOMIC} flag Reported-by: Andrey Konovalov <andreyknvl@google.com> Reviewed-and-Tested-by: Chas Williams <3chas3@gmail.com> Signed-off-by: Chas Williams <3chas3@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent be086e7 commit c55fa3c

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

‎net/atm/common.c‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,16 @@ static void vcc_remove_socket(struct sock *sk)
6262
write_unlock_irq(&vcc_sklist_lock);
6363
}
6464

65-
static struct sk_buff *alloc_tx(struct atm_vcc *vcc, unsigned int size)
65+
static bool vcc_tx_ready(struct atm_vcc *vcc, unsigned int size)
6666
{
67-
struct sk_buff *skb;
6867
struct sock *sk = sk_atm(vcc);
6968

7069
if (sk_wmem_alloc_get(sk) && !atm_may_send(vcc, size)) {
7170
pr_debug("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n",
7271
sk_wmem_alloc_get(sk), size, sk->sk_sndbuf);
73-
return NULL;
72+
return false;
7473
}
75-
while (!(skb = alloc_skb(size, GFP_KERNEL)))
76-
schedule();
77-
pr_debug("%d += %d\n", sk_wmem_alloc_get(sk), skb->truesize);
78-
atomic_add(skb->truesize, &sk->sk_wmem_alloc);
79-
return skb;
74+
return true;
8075
}
8176

8277
static void vcc_sock_destruct(struct sock *sk)
@@ -606,7 +601,7 @@ int vcc_sendmsg(struct socket *sock, struct msghdr *m, size_t size)
606601
eff = (size+3) & ~3; /* align to word boundary */
607602
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
608603
error = 0;
609-
while (!(skb = alloc_tx(vcc, eff))) {
604+
while (!vcc_tx_ready(vcc, eff)) {
610605
if (m->msg_flags & MSG_DONTWAIT) {
611606
error = -EAGAIN;
612607
break;
@@ -628,6 +623,15 @@ int vcc_sendmsg(struct socket *sock, struct msghdr *m, size_t size)
628623
finish_wait(sk_sleep(sk), &wait);
629624
if (error)
630625
goto out;
626+
627+
skb = alloc_skb(eff, GFP_KERNEL);
628+
if (!skb) {
629+
error = -ENOMEM;
630+
goto out;
631+
}
632+
pr_debug("%d += %d\n", sk_wmem_alloc_get(sk), skb->truesize);
633+
atomic_add(skb->truesize, &sk->sk_wmem_alloc);
634+
631635
skb->dev = NULL; /* for paths shared with net_device interfaces */
632636
ATM_SKB(skb)->atm_options = vcc->atm_options;
633637
if (!copy_from_iter_full(skb_put(skb, size), size, &m->msg_iter)) {

0 commit comments

Comments
 (0)