Tue Mar 6 18:29:24 2012 UTC ()
bnx_start() is not MP-safe, so do not create the bnx_alloc_pkts()'s
workqueue MPSAFE. This could lead to bnx_start() being running at
the same time on 2 CPUs, with packets being sent twice.
Problem found and reported by Beverly Schwartz and Greg Troxel.


(bouyer)
diff -r1.45 -r1.46 src/sys/dev/pci/if_bnx.c

cvs diff -r1.45 -r1.46 src/sys/dev/pci/if_bnx.c (expand / switch to unified diff)

--- src/sys/dev/pci/if_bnx.c 2011/09/22 08:42:53 1.45
+++ src/sys/dev/pci/if_bnx.c 2012/03/06 18:29:23 1.46
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_bnx.c,v 1.45 2011/09/22 08:42:53 jym Exp $ */ 1/* $NetBSD: if_bnx.c,v 1.46 2012/03/06 18:29:23 bouyer Exp $ */
2/* $OpenBSD: if_bnx.c,v 1.85 2009/11/09 14:32:41 dlg Exp $ */ 2/* $OpenBSD: if_bnx.c,v 1.85 2009/11/09 14:32:41 dlg Exp $ */
3 3
4/*- 4/*-
5 * Copyright (c) 2006 Broadcom Corporation 5 * Copyright (c) 2006 Broadcom Corporation
6 * David Christensen <davidch@broadcom.com>. All rights reserved. 6 * David Christensen <davidch@broadcom.com>. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE. 31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35#if 0 35#if 0
36__FBSDID("$FreeBSD: src/sys/dev/bce/if_bce.c,v 1.3 2006/04/13 14:12:26 ru Exp $"); 36__FBSDID("$FreeBSD: src/sys/dev/bce/if_bce.c,v 1.3 2006/04/13 14:12:26 ru Exp $");
37#endif 37#endif
38__KERNEL_RCSID(0, "$NetBSD: if_bnx.c,v 1.45 2011/09/22 08:42:53 jym Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: if_bnx.c,v 1.46 2012/03/06 18:29:23 bouyer Exp $");
39 39
40/* 40/*
41 * The following controllers are supported by this driver: 41 * The following controllers are supported by this driver:
42 * BCM5706C A2, A3 42 * BCM5706C A2, A3
43 * BCM5706S A2, A3 43 * BCM5706S A2, A3
44 * BCM5708C B1, B2 44 * BCM5708C B1, B2
45 * BCM5708S B1, B2 45 * BCM5708S B1, B2
46 * BCM5709C A1, C0 46 * BCM5709C A1, C0
47 * BCM5709S A1, C0 47 * BCM5709S A1, C0
48 * BCM5716 C0 48 * BCM5716 C0
49 * 49 *
50 * The following controllers are not supported by this driver: 50 * The following controllers are not supported by this driver:
51 *  51 *
@@ -697,27 +697,27 @@ bnx_attach(device_t parent, device_t sel @@ -697,27 +697,27 @@ bnx_attach(device_t parent, device_t sel
697 /* Hookup IRQ last. */ 697 /* Hookup IRQ last. */
698 sc->bnx_intrhand = pci_intr_establish(pc, ih, IPL_NET, bnx_intr, sc); 698 sc->bnx_intrhand = pci_intr_establish(pc, ih, IPL_NET, bnx_intr, sc);
699 if (sc->bnx_intrhand == NULL) { 699 if (sc->bnx_intrhand == NULL) {
700 aprint_error_dev(self, "couldn't establish interrupt"); 700 aprint_error_dev(self, "couldn't establish interrupt");
701 if (intrstr != NULL) 701 if (intrstr != NULL)
702 aprint_error(" at %s", intrstr); 702 aprint_error(" at %s", intrstr);
703 aprint_error("\n"); 703 aprint_error("\n");
704 goto bnx_attach_fail; 704 goto bnx_attach_fail;
705 } 705 }
706 aprint_normal_dev(sc->bnx_dev, "interrupting at %s\n", intrstr); 706 aprint_normal_dev(sc->bnx_dev, "interrupting at %s\n", intrstr);
707 707
708 /* create workqueue to handle packet allocations */ 708 /* create workqueue to handle packet allocations */
709 if (workqueue_create(&sc->bnx_wq, device_xname(self), 709 if (workqueue_create(&sc->bnx_wq, device_xname(self),
710 bnx_alloc_pkts, sc, PRI_NONE, IPL_NET, WQ_MPSAFE) != 0) { 710 bnx_alloc_pkts, sc, PRI_NONE, IPL_NET, 0) != 0) {
711 aprint_error_dev(self, "failed to create workqueue\n"); 711 aprint_error_dev(self, "failed to create workqueue\n");
712 goto bnx_attach_fail; 712 goto bnx_attach_fail;
713 } 713 }
714 714
715 sc->bnx_mii.mii_ifp = ifp; 715 sc->bnx_mii.mii_ifp = ifp;
716 sc->bnx_mii.mii_readreg = bnx_miibus_read_reg; 716 sc->bnx_mii.mii_readreg = bnx_miibus_read_reg;
717 sc->bnx_mii.mii_writereg = bnx_miibus_write_reg; 717 sc->bnx_mii.mii_writereg = bnx_miibus_write_reg;
718 sc->bnx_mii.mii_statchg = bnx_miibus_statchg; 718 sc->bnx_mii.mii_statchg = bnx_miibus_statchg;
719 719
720 /* Handle any special PHY initialization for SerDes PHYs. */ 720 /* Handle any special PHY initialization for SerDes PHYs. */
721 bnx_init_media(sc); 721 bnx_init_media(sc);
722 722
723 sc->bnx_ec.ec_mii = &sc->bnx_mii; 723 sc->bnx_ec.ec_mii = &sc->bnx_mii;