From owner-svn-src-head@freebsd.org Mon Aug 28 03:13:17 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8D523E04702; Mon, 28 Aug 2017 03:13:17 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5A6B56697C; Mon, 28 Aug 2017 03:13:17 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v7S3DGil005011; Mon, 28 Aug 2017 03:13:16 GMT (envelope-from np@FreeBSD.org) Received: (from np@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7S3DG2N005008; Mon, 28 Aug 2017 03:13:16 GMT (envelope-from np@FreeBSD.org) Message-Id: <201708280313.v7S3DG2N005008@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: np set sender to np@FreeBSD.org using -f From: Navdeep Parhar Date: Mon, 28 Aug 2017 03:13:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r322960 - in head/sys/dev/cxgbe: . common X-SVN-Group: head X-SVN-Commit-Author: np X-SVN-Commit-Paths: in head/sys/dev/cxgbe: . common X-SVN-Commit-Revision: 322960 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Aug 2017 03:13:17 -0000 Author: np Date: Mon Aug 28 03:13:16 2017 New Revision: 322960 URL: https://svnweb.freebsd.org/changeset/base/322960 Log: cxgbe(4): Verify that the driver accesses the firmware mailbox in a thread-safe manner. MFC after: 3 days Modified: head/sys/dev/cxgbe/adapter.h head/sys/dev/cxgbe/common/t4_hw.c head/sys/dev/cxgbe/t4_main.c Modified: head/sys/dev/cxgbe/adapter.h ============================================================================== --- head/sys/dev/cxgbe/adapter.h Mon Aug 28 02:42:20 2017 (r322959) +++ head/sys/dev/cxgbe/adapter.h Mon Aug 28 03:13:16 2017 (r322960) @@ -151,7 +151,7 @@ enum { /* adapter flags */ FULL_INIT_DONE = (1 << 0), FW_OK = (1 << 1), - /* INTR_DIRECT = (1 << 2), No longer used. */ + CHK_MBOX_ACCESS = (1 << 2), MASTER_PF = (1 << 3), ADAP_SYSCTL_CTX = (1 << 4), /* TOM_INIT_DONE= (1 << 5), No longer used */ Modified: head/sys/dev/cxgbe/common/t4_hw.c ============================================================================== --- head/sys/dev/cxgbe/common/t4_hw.c Mon Aug 28 02:42:20 2017 (r322959) +++ head/sys/dev/cxgbe/common/t4_hw.c Mon Aug 28 03:13:16 2017 (r322960) @@ -286,6 +286,9 @@ int t4_wr_mbox_meat_timeout(struct adapter *adap, int __be64 cmd_rpl[MBOX_LEN/8]; u32 pcie_fw; + if (adap->flags & CHK_MBOX_ACCESS) + ASSERT_SYNCHRONIZED_OP(adap); + if ((size & 15) || size > MBOX_LEN) return -EINVAL; Modified: head/sys/dev/cxgbe/t4_main.c ============================================================================== --- head/sys/dev/cxgbe/t4_main.c Mon Aug 28 02:42:20 2017 (r322959) +++ head/sys/dev/cxgbe/t4_main.c Mon Aug 28 03:13:16 2017 (r322960) @@ -1221,6 +1221,15 @@ t4_attach(device_t dev) goto done; } + /* + * Ensure thread-safe mailbox access (in debug builds). + * + * So far this was the only thread accessing the mailbox but various + * ifnets and sysctls are about to be created and their handlers/ioctls + * will access the mailbox from different threads. + */ + sc->flags |= CHK_MBOX_ACCESS; + rc = bus_generic_attach(dev); if (rc != 0) { device_printf(dev, @@ -1336,6 +1345,7 @@ t4_detach_common(device_t dev) sc = device_get_softc(dev); + sc->flags &= ~CHK_MBOX_ACCESS; if (sc->flags & FULL_INIT_DONE) { if (!(sc->flags & IS_VF)) t4_intr_disable(sc);