1 commit d7d3d8f1ee4435e32bc6c93187798b7e2e3170a9
2 Author: David Woodhouse <David.Woodhouse@intel.com>
3 Date: Thu Nov 29 23:28:30 2012 +0000
5 solos-pci: remove list_vccs() debugging function
7 No idea why we've gone so long dumping a list of VCCs with vci==0 on
10 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
12 commit c93967bfd3a3dffa759a3f28370167bf3cdbc3d0
13 Author: David Woodhouse <David.Woodhouse@intel.com>
14 Date: Thu Nov 29 23:27:20 2012 +0000
16 solos-pci: use GFP_KERNEL where possible, not GFP_ATOMIC
18 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
20 commit ad6999e17ae4f7b99f6d28f425ae970acb115347
21 Author: David Woodhouse <David.Woodhouse@intel.com>
22 Date: Thu Nov 29 23:15:30 2012 +0000
24 solos-pci: clean up pclose() function
26 - Flush pending TX skbs from the queue rather than waiting for them all to
27 complete (suggested by Krzysztof Mazur <krzysiek@podlesie.net>).
28 - Clear ATM_VF_ADDR only when the PKT_PCLOSE packet has been submitted.
29 - Don't clear ATM_VF_READY at all — vcc_destroy_socket() does that for us.
31 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
33 commit 2547e97f29d6d69d567947d5ef90b6b4fbcaf565
34 Author: David Woodhouse <David.Woodhouse@intel.com>
35 Date: Wed Nov 28 10:15:05 2012 +0000
37 pppoatm: optimise PPP channel wakeups after sock_owned_by_user()
39 We don't need to schedule the wakeup tasklet on *every* unlock; only if we
40 actually blocked the channel in the first place.
42 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
43 Acked-by: Krzysztof Mazur <krzysiek@podlesie.net>
45 commit 990b0884a2e9668c08e9daa4d70a54d65329cb6f
46 Author: Krzysztof Mazur <krzysiek@podlesie.net>
47 Date: Wed Nov 28 09:08:04 2012 +0100
49 br2684: allow assign only on a connected socket
51 The br2684 does not check if used vcc is in connected state,
52 causing potential Oops in pppoatm_send() when vcc->send() is called
53 on not fully connected socket.
55 Now br2684 can be assigned only on connected sockets; otherwise
56 -EINVAL error is returned.
58 Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
59 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
61 commit f49b6da01f0abebb17f6241473d53018d923f6b0
62 Author: Nathan Williams <nathan@traverse.com.au>
63 Date: Tue Nov 27 17:34:09 2012 +1100
65 solos-pci: Fix leak of skb received for unknown vcc
67 ... and ensure that the next skb is set up for RX in the DMA case.
69 Signed-off-by: Nathan Williams <nathan@traverse.com.au>
70 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
72 commit a61d37ff4a555886c4ebe31d2c6d893afb6f4d3c
73 Author: David Woodhouse <David.Woodhouse@intel.com>
74 Date: Wed Nov 28 00:46:45 2012 +0000
76 br2684: fix module_put() race
78 The br2684 code used module_put() during unassignment from vcc with
79 hope that we have BKL. This assumption is no longer true.
81 Now owner field in atmvcc is used to move this module_put()
82 to vcc_destroy_socket().
84 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
85 Acked-by: Krzysztof Mazur <krzysiek@podlesie.net>
87 commit c52f40629884ddc62c7af445fd5d620fdb466fb2
88 Author: David Woodhouse <David.Woodhouse@intel.com>
89 Date: Wed Nov 28 00:05:52 2012 +0000
91 pppoatm: fix missing wakeup in pppoatm_send()
93 Now that we can return zero from pppoatm_send() for reasons *other* than
94 the queue being full, that means we can't depend on a subsequent call to
95 pppoatm_pop() waking the queue, and we might leave it stalled
98 Use the ->release_cb() callback to wake the queue after the sock is
101 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
102 Acked-by: Krzysztof Mazur <krzysiek@podlesie.net>
104 commit 35826e7372fe39b7db7930eda0267c82d68d1a4c
105 Author: David Woodhouse <dwmw2@infradead.org>
106 Date: Tue Nov 27 23:28:36 2012 +0000
108 br2684: don't send frames on not-ready vcc
110 Avoid submitting packets to a vcc which is being closed. Things go badly
111 wrong when the ->pop method gets later called after everything's been
114 Use the ATM socket lock for synchronisation with vcc_destroy_socket(),
115 which clears the ATM_VF_READY bit under the same lock. Otherwise, we
116 could end up submitting a packet to the device driver even after its
117 ->ops->close method has been called. And it could call the vcc's ->pop
118 method after the protocol has been shut down. Which leads to a panic.
120 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
121 Acked-by: Krzysztof Mazur <krzysiek@podlesie.net>
123 commit 7f940dde65de4a707f3dd723bb6ce9de90ca1eab
124 Author: David Woodhouse <David.Woodhouse@intel.com>
125 Date: Wed Nov 28 00:03:11 2012 +0000
127 atm: add release_cb() callback to vcc
129 The immediate use case for this is that it will allow us to ensure that a
130 pppoatm queue is woken after it has to drop a packet due to the sock being
133 Note that 'release_cb' is called when the socket is *unlocked*. This is
134 not to be confused with vcc_release() — which probably ought to be called
137 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
138 Acked-by: Krzysztof Mazur <krzysiek@podlesie.net>
140 commit def1b2f9083f84d0a77730e537c76429914d17c1
141 Author: David Woodhouse <David.Woodhouse@intel.com>
142 Date: Tue Nov 27 23:49:24 2012 +0000
144 solos-pci: wait for pending TX to complete when releasing vcc
146 We should no longer be calling the old pop routine for the vcc, after
147 vcc_release() has completed. Make sure we wait for any pending TX skbs
148 to complete, by waiting for our own PKT_PCLOSE control skb to be sent.
150 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
152 commit 397ff16dce53888ec693b3718640be2560204751
153 Author: Krzysztof Mazur <krzysiek@podlesie.net>
154 Date: Tue Nov 6 23:17:02 2012 +0100
156 pppoatm: do not inline pppoatm_may_send()
158 The pppoatm_may_send() is quite heavy and it's called three times
159 in pppoatm_send() and inlining costs more than 200 bytes of code
160 (more than 10% of total pppoatm driver code size).
162 add/remove: 1/0 grow/shrink: 0/1 up/down: 132/-367 (-235)
163 function old new delta
164 pppoatm_may_send - 132 +132
165 pppoatm_send 900 533 -367
167 Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
168 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
170 commit 071d93931a75dc1f82f0baa9959613af81c5a032
171 Author: Krzysztof Mazur <krzysiek@podlesie.net>
172 Date: Sat Nov 10 23:33:19 2012 +0100
174 pppoatm: drop frames to not-ready vcc
176 The vcc_destroy_socket() closes vcc before the protocol is detached
177 from vcc by calling vcc->push() with NULL skb. This leaves some time
178 window, where the protocol may call vcc->send() on closed vcc
181 Now pppoatm_send(), like vcc_sendmsg(), checks for vcc flags that
182 indicate that vcc is not ready. If the vcc is not ready we just
183 drop frame. Queueing frames is much more complicated because we
184 don't have callbacks that inform us about vcc flags changes.
186 Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
187 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
189 commit 3ac108006fd7f20cb8fc8ea2287f1497bcda00a1
190 Author: Krzysztof Mazur <krzysiek@podlesie.net>
191 Date: Tue Nov 6 23:17:00 2012 +0100
193 pppoatm: take ATM socket lock in pppoatm_send()
195 The pppoatm_send() does not take any lock that will prevent concurrent
196 vcc_sendmsg(). This causes two problems:
198 - there is no locking between checking the send queue size
199 with atm_may_send() and incrementing sk_wmem_alloc,
200 and the real queue size can be a little higher than sk_sndbuf
202 - the vcc->sendmsg() can be called concurrently. I'm not sure
203 if it's allowed. Some drivers (eni, nicstar, ...) seem
204 to assume it will never happen.
206 Now pppoatm_send() takes ATM socket lock, the same that is used
207 in vcc_sendmsg() and other ATM socket functions. The pppoatm_send()
208 is called with BH disabled, so bh_lock_sock() is used instead
211 Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
212 Cc: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
213 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
215 commit e41faed9cde1acce657f75a0b19a1787e9850d3f
216 Author: Krzysztof Mazur <krzysiek@podlesie.net>
217 Date: Tue Nov 6 23:16:59 2012 +0100
219 pppoatm: fix module_put() race
221 The pppoatm used module_put() during unassignment from vcc with
222 hope that we have BKL. This assumption is no longer true.
224 Now owner field in atmvcc is used to move this module_put()
225 to vcc_destroy_socket().
227 Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
228 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
230 commit 3b1a914595f3f9beb9e38ff3ddc7bdafa092ba22
231 Author: Krzysztof Mazur <krzysiek@podlesie.net>
232 Date: Tue Nov 6 23:16:58 2012 +0100
234 pppoatm: allow assign only on a connected socket
236 The pppoatm does not check if used vcc is in connected state,
237 causing an Oops in pppoatm_send() when vcc->send() is called
238 on not fully connected socket.
240 Now pppoatm can be assigned only on connected sockets; otherwise
241 -EINVAL error is returned.
243 Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
244 Cc: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
245 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
247 commit ec809bd817dfa1905283468e4c813684ed4efe78
248 Author: Krzysztof Mazur <krzysiek@podlesie.net>
249 Date: Tue Nov 6 23:16:57 2012 +0100
251 atm: add owner of push() callback to atmvcc
253 The atm is using atmvcc->push(vcc, NULL) callback to notify protocol
254 that vcc will be closed and protocol must detach from it. This callback
255 is usually used by protocol to decrement module usage count by module_put(),
256 but it leaves small window then module is still used after module_put().
258 Now the owner of push() callback is kept in atmvcc and
259 module_put(atmvcc->owner) is called after the protocol is detached from vcc.
261 Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
262 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
263 Acked-by: Chas Williams <chas@cmf.nrl.navy.mil>
265 commit ae088d663beebb3cad0e7abaac67ee61a7c578d5
266 Author: David Woodhouse <dwmw2@infradead.org>
267 Date: Sun Nov 25 12:06:52 2012 +0000
269 atm: br2684: Fix excessive queue bloat
271 There's really no excuse for an additional wmem_default of buffering
272 between the netdev queue and the ATM device. Two packets (one in-flight,
273 and one ready to send) ought to be fine. It's not as if it should take
274 long to get another from the netdev queue when we need it.
276 If necessary we can make the queue space configurable later, but I don't
277 think it's likely to be necessary.
279 cf. commit 9d02daf754238adac48fa075ee79e7edd3d79ed3 (pppoatm: Fix
280 excessive queue bloat) which did something very similar for PPPoATM.
282 Note that there is a tremendously unlikely race condition which may
283 result in qspace temporarily going negative. If a CPU running the
284 br2684_pop() function goes off into the weeds for a long period of time
285 after incrementing qspace to 1, but before calling netdev_wake_queue()...
286 and another CPU ends up calling br2684_start_xmit() and *stopping* the
287 queue again before the first CPU comes back, the netdev queue could
288 end up being woken when qspace has already reached zero.
290 An alternative approach to coping with this race would be to check in
291 br2684_start_xmit() for qspace==0 and return NETDEV_TX_BUSY, but just
292 using '> 0' and '< 1' for comparison instead of '== 0' and '!= 0' is
293 simpler. It just warranted a mention of *why* we do it that way...
295 Move the call to atmvcc->send() to happen *after* the accounting and
296 potentially stopping the netdev queue, in br2684_xmit_vcc(). This matters
297 if the ->send() call suffers an immediate failure, because it'll call
298 br2684_pop() with the offending skb before returning. We want that to
299 happen *after* we've done the initial accounting for the packet in
300 question. Also make it return an appropriate success/failure indication
303 Tested by running 'ping -l 1000 bottomless.aaisp.net.uk' from within my
304 network, with only a single PPPoE-over-BR2684 link running. And after
305 setting txqueuelen on the nas0 interface to something low (5, in fact).
306 Before the patch, we'd see about 15 packets being queued and a resulting
307 latency of ~56ms being reached. After the patch, we see only about 8,
308 which is fairly much what we expect. And a max latency of ~36ms. On this
309 OpenWRT box, wmem_default is 163840.
311 Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
312 Reviewed-by: Krzysztof Mazur <krzysiek@podlesie.net>
313 Signed-off-by: David S. Miller <davem@davemloft.net>
315 --- a/drivers/atm/solos-pci.c
316 +++ b/drivers/atm/solos-pci.c
317 @@ -92,6 +92,7 @@ struct pkt_hdr {
320 struct solos_skb_cb {
321 + struct completion c;
325 @@ -164,7 +165,6 @@ static void fpga_queue(struct solos_card
326 static uint32_t fpga_tx(struct solos_card *);
327 static irqreturn_t solos_irq(int irq, void *dev_id);
328 static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
329 -static int list_vccs(int vci);
330 static int atm_init(struct solos_card *, struct device *);
331 static void atm_remove(struct solos_card *);
332 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
333 @@ -710,7 +710,8 @@ void solos_bh(unsigned long card_arg)
334 dev_warn(&card->dev->dev, "Received packet for unknown VPI.VCI %d.%d on port %d\n",
335 le16_to_cpu(header->vpi), le16_to_cpu(header->vci),
338 + dev_kfree_skb_any(skb);
341 atm_charge(vcc, skb->truesize);
343 @@ -790,44 +791,6 @@ static struct atm_vcc *find_vcc(struct a
347 -static int list_vccs(int vci)
349 - struct hlist_head *head;
350 - struct atm_vcc *vcc;
351 - struct hlist_node *node;
356 - read_lock(&vcc_sklist_lock);
358 - head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
359 - sk_for_each(s, node, head) {
362 - printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
368 - for(i = 0; i < VCC_HTABLE_SIZE; i++){
369 - head = &vcc_hash[i];
370 - sk_for_each(s, node, head) {
373 - printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
380 - read_unlock(&vcc_sklist_lock);
385 static int popen(struct atm_vcc *vcc)
387 struct solos_card *card = vcc->dev->dev_data;
388 @@ -840,7 +803,7 @@ static int popen(struct atm_vcc *vcc)
392 - skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
393 + skb = alloc_skb(sizeof(*header), GFP_KERNEL);
396 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
397 @@ -857,8 +820,6 @@ static int popen(struct atm_vcc *vcc)
399 set_bit(ATM_VF_ADDR, &vcc->flags);
400 set_bit(ATM_VF_READY, &vcc->flags);
406 @@ -866,10 +827,21 @@ static int popen(struct atm_vcc *vcc)
407 static void pclose(struct atm_vcc *vcc)
409 struct solos_card *card = vcc->dev->dev_data;
410 - struct sk_buff *skb;
411 + unsigned char port = SOLOS_CHAN(vcc->dev);
412 + struct sk_buff *skb, *tmpskb;
413 struct pkt_hdr *header;
415 - skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
416 + /* Remove any yet-to-be-transmitted packets from the pending queue */
417 + spin_lock(&card->tx_queue_lock);
418 + skb_queue_walk_safe(&card->tx_queue[port], skb, tmpskb) {
419 + if (SKB_CB(skb)->vcc == vcc) {
420 + skb_unlink(skb, &card->tx_queue[port]);
421 + solos_pop(vcc, skb);
424 + spin_unlock(&card->tx_queue_lock);
426 + skb = alloc_skb(sizeof(*header), GFP_KERNEL);
428 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n");
430 @@ -881,15 +853,21 @@ static void pclose(struct atm_vcc *vcc)
431 header->vci = cpu_to_le16(vcc->vci);
432 header->type = cpu_to_le16(PKT_PCLOSE);
434 - fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
435 + init_completion(&SKB_CB(skb)->c);
437 - clear_bit(ATM_VF_ADDR, &vcc->flags);
438 - clear_bit(ATM_VF_READY, &vcc->flags);
439 + fpga_queue(card, port, skb, NULL);
441 + if (!wait_for_completion_timeout(&SKB_CB(skb)->c, 5 * HZ))
442 + dev_warn(&card->dev->dev, "Timeout waiting for VCC close on port %d\n",
445 /* Hold up vcc_destroy_socket() (our caller) until solos_bh() in the
446 tasklet has finished processing any incoming packets (and, more to
447 the point, using the vcc pointer). */
448 tasklet_unlock_wait(&card->tlet);
450 + clear_bit(ATM_VF_ADDR, &vcc->flags);
455 @@ -1010,9 +988,12 @@ static uint32_t fpga_tx(struct solos_car
457 atomic_inc(&vcc->stats->tx);
458 solos_pop(vcc, oldskb);
461 + struct pkt_hdr *header = (void *)oldskb->data;
462 + if (le16_to_cpu(header->type) == PKT_PCLOSE)
463 + complete(&SKB_CB(oldskb)->c);
464 dev_kfree_skb_irq(oldskb);
469 /* For non-DMA TX, write the 'TX start' bit for all four ports simultaneously */
470 @@ -1246,7 +1227,7 @@ static int atm_init(struct solos_card *c
471 card->atmdev[i]->phy_data = (void *)(unsigned long)i;
472 atm_dev_signal_change(card->atmdev[i], ATM_PHY_SIG_FOUND);
474 - skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
475 + skb = alloc_skb(sizeof(*header), GFP_KERNEL);
477 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in atm_init()\n");
479 @@ -1343,6 +1324,8 @@ static struct pci_driver fpga_driver = {
481 static int __init solos_pci_init(void)
483 + BUILD_BUG_ON(sizeof(struct solos_skb_cb) > sizeof(((struct sk_buff *)0)->cb));
485 printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
486 return pci_register_driver(&fpga_driver);
488 --- a/include/linux/atmdev.h
489 +++ b/include/linux/atmdev.h
490 @@ -307,6 +307,7 @@ struct atm_vcc {
491 struct atm_dev *dev; /* device back pointer */
492 struct atm_qos qos; /* QOS */
493 struct atm_sap sap; /* SAP */
494 + void (*release_cb)(struct atm_vcc *vcc); /* release_sock callback */
495 void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
496 void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* optional */
497 int (*push_oam)(struct atm_vcc *vcc,void *cell);
498 @@ -314,6 +315,7 @@ struct atm_vcc {
499 void *dev_data; /* per-device data */
500 void *proto_data; /* per-protocol data */
501 struct k_atm_aal_stats *stats; /* pointer to AAL stats group */
502 + struct module *owner; /* owner of ->push function */
503 /* SVC part --- may move later ------------------------------------- */
504 short itf; /* interface number */
505 struct sockaddr_atmsvc local;
506 --- a/net/atm/br2684.c
507 +++ b/net/atm/br2684.c
508 @@ -68,12 +68,15 @@ struct br2684_vcc {
509 /* keep old push, pop functions for chaining */
510 void (*old_push)(struct atm_vcc *vcc, struct sk_buff *skb);
511 void (*old_pop)(struct atm_vcc *vcc, struct sk_buff *skb);
512 + void (*old_release_cb)(struct atm_vcc *vcc);
513 + struct module *old_owner;
514 enum br2684_encaps encaps;
515 struct list_head brvccs;
516 #ifdef CONFIG_ATM_BR2684_IPFILTER
517 struct br2684_filter filter;
518 #endif /* CONFIG_ATM_BR2684_IPFILTER */
519 unsigned copies_needed, copies_failed;
524 @@ -181,18 +184,15 @@ static struct notifier_block atm_dev_not
525 static void br2684_pop(struct atm_vcc *vcc, struct sk_buff *skb)
527 struct br2684_vcc *brvcc = BR2684_VCC(vcc);
528 - struct net_device *net_dev = skb->dev;
530 - pr_debug("(vcc %p ; net_dev %p )\n", vcc, net_dev);
531 + pr_debug("(vcc %p ; net_dev %p )\n", vcc, brvcc->device);
532 brvcc->old_pop(vcc, skb);
537 - if (atm_may_send(vcc, 0))
538 - netif_wake_queue(net_dev);
540 + /* If the queue space just went up from zero, wake */
541 + if (atomic_inc_return(&brvcc->qspace) == 1)
542 + netif_wake_queue(brvcc->device);
546 * Send a packet out a particular vcc. Not to useful right now, but paves
547 * the way for multiple vcc's per itf. Returns true if we can send,
548 @@ -256,16 +256,30 @@ static int br2684_xmit_vcc(struct sk_buf
549 ATM_SKB(skb)->atm_options = atmvcc->atm_options;
550 dev->stats.tx_packets++;
551 dev->stats.tx_bytes += skb->len;
552 - atmvcc->send(atmvcc, skb);
554 - if (!atm_may_send(atmvcc, 0)) {
555 + if (atomic_dec_return(&brvcc->qspace) < 1) {
556 + /* No more please! */
557 netif_stop_queue(brvcc->device);
558 - /*check for race with br2684_pop*/
559 - if (atm_may_send(atmvcc, 0))
560 - netif_start_queue(brvcc->device);
561 + /* We might have raced with br2684_pop() */
562 + if (unlikely(atomic_read(&brvcc->qspace) > 0))
563 + netif_wake_queue(brvcc->device);
567 + /* If this fails immediately, the skb will be freed and br2684_pop()
568 + will wake the queue if appropriate. Just return an error so that
569 + the stats are updated correctly */
570 + return !atmvcc->send(atmvcc, skb);
573 +static void br2684_release_cb(struct atm_vcc *atmvcc)
575 + struct br2684_vcc *brvcc = BR2684_VCC(atmvcc);
577 + if (atomic_read(&brvcc->qspace) > 0)
578 + netif_wake_queue(brvcc->device);
580 + if (brvcc->old_release_cb)
581 + brvcc->old_release_cb(atmvcc);
584 static inline struct br2684_vcc *pick_outgoing_vcc(const struct sk_buff *skb,
585 @@ -279,6 +293,8 @@ static netdev_tx_t br2684_start_xmit(str
587 struct br2684_dev *brdev = BRPRIV(dev);
588 struct br2684_vcc *brvcc;
589 + struct atm_vcc *atmvcc;
590 + netdev_tx_t ret = NETDEV_TX_OK;
592 pr_debug("skb_dst(skb)=%p\n", skb_dst(skb));
593 read_lock(&devs_lock);
594 @@ -289,9 +305,26 @@ static netdev_tx_t br2684_start_xmit(str
595 dev->stats.tx_carrier_errors++;
596 /* netif_stop_queue(dev); */
598 - read_unlock(&devs_lock);
599 - return NETDEV_TX_OK;
602 + atmvcc = brvcc->atmvcc;
604 + bh_lock_sock(sk_atm(atmvcc));
606 + if (test_bit(ATM_VF_RELEASED, &atmvcc->flags) ||
607 + test_bit(ATM_VF_CLOSE, &atmvcc->flags) ||
608 + !test_bit(ATM_VF_READY, &atmvcc->flags)) {
609 + dev->stats.tx_dropped++;
610 + dev_kfree_skb(skb);
614 + if (sock_owned_by_user(sk_atm(atmvcc))) {
615 + netif_stop_queue(brvcc->device);
616 + ret = NETDEV_TX_BUSY;
620 if (!br2684_xmit_vcc(skb, dev, brvcc)) {
622 * We should probably use netif_*_queue() here, but that
623 @@ -303,8 +336,11 @@ static netdev_tx_t br2684_start_xmit(str
624 dev->stats.tx_errors++;
625 dev->stats.tx_fifo_errors++;
628 + bh_unlock_sock(sk_atm(atmvcc));
630 read_unlock(&devs_lock);
631 - return NETDEV_TX_OK;
636 @@ -377,9 +413,10 @@ static void br2684_close_vcc(struct br26
637 list_del(&brvcc->brvccs);
638 write_unlock_irq(&devs_lock);
639 brvcc->atmvcc->user_back = NULL; /* what about vcc->recvq ??? */
640 + brvcc->atmvcc->release_cb = brvcc->old_release_cb;
641 brvcc->old_push(brvcc->atmvcc, NULL); /* pass on the bad news */
642 + module_put(brvcc->old_owner);
644 - module_put(THIS_MODULE);
647 /* when AAL5 PDU comes in: */
648 @@ -504,6 +541,13 @@ static int br2684_regvcc(struct atm_vcc
649 brvcc = kzalloc(sizeof(struct br2684_vcc), GFP_KERNEL);
653 + * Allow two packets in the ATM queue. One actually being sent, and one
654 + * for the ATM 'TX done' handler to send. It shouldn't take long to get
655 + * the next one from the netdev queue, when we need it. More than that
656 + * would be bufferbloat.
658 + atomic_set(&brvcc->qspace, 2);
659 write_lock_irq(&devs_lock);
660 net_dev = br2684_find_dev(&be.ifspec);
661 if (net_dev == NULL) {
662 @@ -546,9 +590,13 @@ static int br2684_regvcc(struct atm_vcc
663 brvcc->encaps = (enum br2684_encaps)be.encaps;
664 brvcc->old_push = atmvcc->push;
665 brvcc->old_pop = atmvcc->pop;
666 + brvcc->old_release_cb = atmvcc->release_cb;
667 + brvcc->old_owner = atmvcc->owner;
669 atmvcc->push = br2684_push;
670 atmvcc->pop = br2684_pop;
671 + atmvcc->release_cb = br2684_release_cb;
672 + atmvcc->owner = THIS_MODULE;
674 /* initialize netdev carrier state */
675 if (atmvcc->dev->signal == ATM_PHY_SIG_LOST)
676 @@ -687,10 +735,13 @@ static int br2684_ioctl(struct socket *s
678 if (!capable(CAP_NET_ADMIN))
680 - if (cmd == ATM_SETBACKEND)
681 + if (cmd == ATM_SETBACKEND) {
682 + if (sock->state != SS_CONNECTED)
684 return br2684_regvcc(atmvcc, argp);
687 return br2684_create(argp);
689 #ifdef CONFIG_ATM_BR2684_IPFILTER
691 if (atmvcc->push != br2684_push)
692 --- a/net/atm/common.c
693 +++ b/net/atm/common.c
694 @@ -126,10 +126,19 @@ static void vcc_write_space(struct sock
698 +static void vcc_release_cb(struct sock *sk)
700 + struct atm_vcc *vcc = atm_sk(sk);
702 + if (vcc->release_cb)
703 + vcc->release_cb(vcc);
706 static struct proto vcc_proto = {
708 .owner = THIS_MODULE,
709 .obj_size = sizeof(struct atm_vcc),
710 + .release_cb = vcc_release_cb,
713 int vcc_create(struct net *net, struct socket *sock, int protocol, int family)
714 @@ -156,7 +165,9 @@ int vcc_create(struct net *net, struct s
715 atomic_set(&sk->sk_rmem_alloc, 0);
719 vcc->push_oam = NULL;
720 + vcc->release_cb = NULL;
721 vcc->vpi = vcc->vci = 0; /* no VCI/VPI yet */
722 vcc->atm_options = vcc->aal_options = 0;
723 sk->sk_destruct = vcc_sock_destruct;
724 @@ -175,6 +186,7 @@ static void vcc_destroy_socket(struct so
725 vcc->dev->ops->close(vcc);
727 vcc->push(vcc, NULL); /* atmarpd has no push */
728 + module_put(vcc->owner);
730 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
731 atm_return(vcc, skb->truesize);
732 --- a/net/atm/pppoatm.c
733 +++ b/net/atm/pppoatm.c
734 @@ -60,6 +60,8 @@ struct pppoatm_vcc {
735 struct atm_vcc *atmvcc; /* VCC descriptor */
736 void (*old_push)(struct atm_vcc *, struct sk_buff *);
737 void (*old_pop)(struct atm_vcc *, struct sk_buff *);
738 + void (*old_release_cb)(struct atm_vcc *);
739 + struct module *old_owner;
740 /* keep old push/pop for detaching */
741 enum pppoatm_encaps encaps;
743 @@ -107,6 +109,24 @@ static void pppoatm_wakeup_sender(unsign
744 ppp_output_wakeup((struct ppp_channel *) arg);
747 +static void pppoatm_release_cb(struct atm_vcc *atmvcc)
749 + struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc);
752 + * As in pppoatm_pop(), it's safe to clear the BLOCKED bit here because
753 + * the wakeup *can't* race with pppoatm_send(). They both hold the PPP
754 + * channel's ->downl lock. And the potential race with *setting* it,
755 + * which leads to the double-check dance in pppoatm_may_send(), doesn't
756 + * exist here. In the sock_owned_by_user() case in pppoatm_send(), we
757 + * set the BLOCKED bit while the socket is still locked. We know that
758 + * ->release_cb() can't be called until that's done.
760 + if (test_and_clear_bit(BLOCKED, &pvcc->blocked))
761 + tasklet_schedule(&pvcc->wakeup_tasklet);
762 + if (pvcc->old_release_cb)
763 + pvcc->old_release_cb(atmvcc);
766 * This gets called every time the ATM card has finished sending our
767 * skb. The ->old_pop will take care up normal atm flow control,
768 @@ -151,12 +171,11 @@ static void pppoatm_unassign_vcc(struct
769 pvcc = atmvcc_to_pvcc(atmvcc);
770 atmvcc->push = pvcc->old_push;
771 atmvcc->pop = pvcc->old_pop;
772 + atmvcc->release_cb = pvcc->old_release_cb;
773 tasklet_kill(&pvcc->wakeup_tasklet);
774 ppp_unregister_channel(&pvcc->chan);
775 atmvcc->user_back = NULL;
777 - /* Gee, I hope we have the big kernel lock here... */
778 - module_put(THIS_MODULE);
781 /* Called when an AAL5 PDU comes in */
782 @@ -165,9 +184,13 @@ static void pppoatm_push(struct atm_vcc
783 struct pppoatm_vcc *pvcc = atmvcc_to_pvcc(atmvcc);
785 if (skb == NULL) { /* VCC was closed */
786 + struct module *module;
788 pr_debug("removing ATMPPP VCC %p\n", pvcc);
789 + module = pvcc->old_owner;
790 pppoatm_unassign_vcc(atmvcc);
791 atmvcc->push(atmvcc, NULL); /* Pass along bad news */
792 + module_put(module);
795 atm_return(atmvcc, skb->truesize);
796 @@ -211,7 +234,7 @@ error:
797 ppp_input_error(&pvcc->chan, 0);
800 -static inline int pppoatm_may_send(struct pppoatm_vcc *pvcc, int size)
801 +static int pppoatm_may_send(struct pppoatm_vcc *pvcc, int size)
804 * It's not clear that we need to bother with using atm_may_send()
805 @@ -269,10 +292,33 @@ static inline int pppoatm_may_send(struc
806 static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb)
808 struct pppoatm_vcc *pvcc = chan_to_pvcc(chan);
809 + struct atm_vcc *vcc;
812 ATM_SKB(skb)->vcc = pvcc->atmvcc;
813 pr_debug("(skb=0x%p, vcc=0x%p)\n", skb, pvcc->atmvcc);
814 if (skb->data[0] == '\0' && (pvcc->flags & SC_COMP_PROT))
815 (void) skb_pull(skb, 1);
817 + vcc = ATM_SKB(skb)->vcc;
818 + bh_lock_sock(sk_atm(vcc));
819 + if (sock_owned_by_user(sk_atm(vcc))) {
821 + * Needs to happen (and be flushed, hence test_and_) before we unlock
822 + * the socket. It needs to be seen by the time our ->release_cb gets
825 + test_and_set_bit(BLOCKED, &pvcc->blocked);
828 + if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
829 + test_bit(ATM_VF_CLOSE, &vcc->flags) ||
830 + !test_bit(ATM_VF_READY, &vcc->flags)) {
831 + bh_unlock_sock(sk_atm(vcc));
833 + return DROP_PACKET;
836 switch (pvcc->encaps) { /* LLC encapsulation needed */
838 if (skb_headroom(skb) < LLC_LEN) {
839 @@ -285,8 +331,10 @@ static int pppoatm_send(struct ppp_chann
845 + bh_unlock_sock(sk_atm(vcc));
848 } else if (!pppoatm_may_send(pvcc, skb->truesize))
850 memcpy(skb_push(skb, LLC_LEN), pppllc, LLC_LEN);
851 @@ -296,6 +344,7 @@ static int pppoatm_send(struct ppp_chann
855 + bh_unlock_sock(sk_atm(vcc));
856 pr_debug("Trying to send without setting encaps!\n");
859 @@ -305,9 +354,12 @@ static int pppoatm_send(struct ppp_chann
860 ATM_SKB(skb)->atm_options = ATM_SKB(skb)->vcc->atm_options;
861 pr_debug("atm_skb(%p)->vcc(%p)->dev(%p)\n",
862 skb, ATM_SKB(skb)->vcc, ATM_SKB(skb)->vcc->dev);
863 - return ATM_SKB(skb)->vcc->send(ATM_SKB(skb)->vcc, skb)
864 + ret = ATM_SKB(skb)->vcc->send(ATM_SKB(skb)->vcc, skb)
866 + bh_unlock_sock(sk_atm(vcc));
869 + bh_unlock_sock(sk_atm(vcc));
871 * We don't have space to send this SKB now, but we might have
872 * already applied SC_COMP_PROT compression, so may need to undo
873 @@ -362,6 +414,8 @@ static int pppoatm_assign_vcc(struct atm
874 atomic_set(&pvcc->inflight, NONE_INFLIGHT);
875 pvcc->old_push = atmvcc->push;
876 pvcc->old_pop = atmvcc->pop;
877 + pvcc->old_owner = atmvcc->owner;
878 + pvcc->old_release_cb = atmvcc->release_cb;
879 pvcc->encaps = (enum pppoatm_encaps) be.encaps;
880 pvcc->chan.private = pvcc;
881 pvcc->chan.ops = &pppoatm_ops;
882 @@ -377,7 +431,9 @@ static int pppoatm_assign_vcc(struct atm
883 atmvcc->user_back = pvcc;
884 atmvcc->push = pppoatm_push;
885 atmvcc->pop = pppoatm_pop;
886 + atmvcc->release_cb = pppoatm_release_cb;
887 __module_get(THIS_MODULE);
888 + atmvcc->owner = THIS_MODULE;
890 /* re-process everything received between connection setup and
892 @@ -406,6 +462,8 @@ static int pppoatm_ioctl(struct socket *
894 if (!capable(CAP_NET_ADMIN))
896 + if (sock->state != SS_CONNECTED)
898 return pppoatm_assign_vcc(atmvcc, argp);