Skip to content

Commit 9bbe60a

Browse files
dwmw2davem330
authored andcommitted
atm: Preserve value of skb->truesize when accounting to vcc
ATM accounts for in-flight TX packets in sk_wmem_alloc of the VCC on which they are to be sent. But it doesn't take ownership of those packets from the sock (if any) which originally owned them. They should remain owned by their actual sender until they've left the box. There's a hack in pskb_expand_head() to avoid adjusting skb->truesize for certain skbs, precisely to avoid messing up sk_wmem_alloc accounting. Ideally that hack would cover the ATM use case too, but it doesn't — skbs which aren't owned by any sock, for example PPP control frames, still get their truesize adjusted when the low-level ATM driver adds headroom. This has always been an issue, it seems. The truesize of a packet increases, and sk_wmem_alloc on the VCC goes negative. But this wasn't for normal traffic, only for control frames. So I think we just got away with it, and we probably needed to send 2GiB of LCP echo frames before the misaccounting would ever have caused a problem and caused atm_may_send() to start refusing packets. Commit 14afee4 ("net: convert sock.sk_wmem_alloc from atomic_t to refcount_t") did exactly what it was intended to do, and turned this mostly-theoretical problem into a real one, causing PPPoATM to fail immediately as sk_wmem_alloc underflows and atm_may_send() *immediately* starts refusing to allow new packets. The least intrusive solution to this problem is to stash the value of skb->truesize that was accounted to the VCC, in a new member of the ATM_SKB(skb) structure. Then in atm_pop_raw() subtract precisely that value instead of the then-current value of skb->truesize. Fixes: 158f323 ("net: adjust skb->truesize in pskb_expand_head()") Signed-off-by: David Woodhouse <[email protected]> Tested-by: Kevin Darbyshire-Bryant <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0841d98 commit 9bbe60a

File tree

8 files changed

+23
-14
lines changed

8 files changed

+23
-14
lines changed

include/linux/atmdev.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ struct atmphy_ops {
214214
struct atm_skb_data {
215215
struct atm_vcc *vcc; /* ATM VCC */
216216
unsigned long atm_options; /* ATM layer options */
217+
unsigned int acct_truesize; /* truesize accounted to vcc */
217218
};
218219

219220
#define VCC_HTABLE_SIZE 32
@@ -241,6 +242,20 @@ void vcc_insert_socket(struct sock *sk);
241242

242243
void atm_dev_release_vccs(struct atm_dev *dev);
243244

245+
static inline void atm_account_tx(struct atm_vcc *vcc, struct sk_buff *skb)
246+
{
247+
/*
248+
* Because ATM skbs may not belong to a sock (and we don't
249+
* necessarily want to), skb->truesize may be adjusted,
250+
* escaping the hack in pskb_expand_head() which avoids
251+
* doing so for some cases. So stash the value of truesize
252+
* at the time we accounted it, and atm_pop_raw() can use
253+
* that value later, in case it changes.
254+
*/
255+
refcount_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
256+
ATM_SKB(skb)->acct_truesize = skb->truesize;
257+
ATM_SKB(skb)->atm_options = vcc->atm_options;
258+
}
244259

245260
static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
246261
{

net/atm/br2684.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ static int br2684_xmit_vcc(struct sk_buff *skb, struct net_device *dev,
252252

253253
ATM_SKB(skb)->vcc = atmvcc = brvcc->atmvcc;
254254
pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, atmvcc, atmvcc->dev);
255-
refcount_add(skb->truesize, &sk_atm(atmvcc)->sk_wmem_alloc);
256-
ATM_SKB(skb)->atm_options = atmvcc->atm_options;
255+
atm_account_tx(atmvcc, skb);
257256
dev->stats.tx_packets++;
258257
dev->stats.tx_bytes += skb->len;
259258

net/atm/clip.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ static netdev_tx_t clip_start_xmit(struct sk_buff *skb,
381381
memcpy(here, llc_oui, sizeof(llc_oui));
382382
((__be16 *) here)[3] = skb->protocol;
383383
}
384-
refcount_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
385-
ATM_SKB(skb)->atm_options = vcc->atm_options;
384+
atm_account_tx(vcc, skb);
386385
entry->vccs->last_use = jiffies;
387386
pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n", skb, vcc, vcc->dev);
388387
old = xchg(&entry->vccs->xoff, 1); /* assume XOFF ... */

net/atm/common.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,9 @@ int vcc_sendmsg(struct socket *sock, struct msghdr *m, size_t size)
630630
goto out;
631631
}
632632
pr_debug("%d += %d\n", sk_wmem_alloc_get(sk), skb->truesize);
633-
refcount_add(skb->truesize, &sk->sk_wmem_alloc);
633+
atm_account_tx(vcc, skb);
634634

635635
skb->dev = NULL; /* for paths shared with net_device interfaces */
636-
ATM_SKB(skb)->atm_options = vcc->atm_options;
637636
if (!copy_from_iter_full(skb_put(skb, size), size, &m->msg_iter)) {
638637
kfree_skb(skb);
639638
error = -EFAULT;

net/atm/lec.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,8 @@ lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
182182
struct net_device *dev = skb->dev;
183183

184184
ATM_SKB(skb)->vcc = vcc;
185-
ATM_SKB(skb)->atm_options = vcc->atm_options;
185+
atm_account_tx(vcc, skb);
186186

187-
refcount_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
188187
if (vcc->send(vcc, skb) < 0) {
189188
dev->stats.tx_dropped++;
190189
return;

net/atm/mpc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,7 @@ static int send_via_shortcut(struct sk_buff *skb, struct mpoa_client *mpc)
555555
sizeof(struct llc_snap_hdr));
556556
}
557557

558-
refcount_add(skb->truesize, &sk_atm(entry->shortcut)->sk_wmem_alloc);
559-
ATM_SKB(skb)->atm_options = entry->shortcut->atm_options;
558+
atm_account_tx(entry->shortcut, skb);
560559
entry->shortcut->send(entry->shortcut, skb);
561560
entry->packets_fwded++;
562561
mpc->in_ops->put(entry);

net/atm/pppoatm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,7 @@ static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb)
350350
return 1;
351351
}
352352

353-
refcount_add(skb->truesize, &sk_atm(ATM_SKB(skb)->vcc)->sk_wmem_alloc);
354-
ATM_SKB(skb)->atm_options = ATM_SKB(skb)->vcc->atm_options;
353+
atm_account_tx(vcc, skb);
355354
pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n",
356355
skb, ATM_SKB(skb)->vcc, ATM_SKB(skb)->vcc->dev);
357356
ret = ATM_SKB(skb)->vcc->send(ATM_SKB(skb)->vcc, skb)

net/atm/raw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ static void atm_pop_raw(struct atm_vcc *vcc, struct sk_buff *skb)
3535
struct sock *sk = sk_atm(vcc);
3636

3737
pr_debug("(%d) %d -= %d\n",
38-
vcc->vci, sk_wmem_alloc_get(sk), skb->truesize);
39-
WARN_ON(refcount_sub_and_test(skb->truesize, &sk->sk_wmem_alloc));
38+
vcc->vci, sk_wmem_alloc_get(sk), ATM_SKB(skb)->acct_truesize);
39+
WARN_ON(refcount_sub_and_test(ATM_SKB(skb)->acct_truesize, &sk->sk_wmem_alloc));
4040
dev_kfree_skb_any(skb);
4141
sk->sk_write_space(sk);
4242
}

0 commit comments

Comments
 (0)