From nobody Fri Jan 19 17:17:28 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TGmWs1nhSz56xYq; Fri, 19 Jan 2024 17:17:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TGmWs1Gxmz4Mg9; Fri, 19 Jan 2024 17:17:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705684649; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BKTPVEVklAflXfhzuh6BgvMFv0BehqIqZpTdTV2mXUk=; b=Igqy/fRPH7qiFMG9PgbnyYLcIocBNcYjwpQM9gvP3QKjQlCTnUITzaeeAErAd0J7mwmytr 5pAwjAma6f8G+haAqn8l2Idsgt/o/EAM0cUvZIdHj2kzKHjLLVUDcC1Ax0CicxjIJM54f7 h1/GO2bcU2uYdtGjk8jDoD+ATAUeQ8U2Z45oROZJBsPlVyqYcnlqDiT3cO919ASIts1s6X yxrwMDyus+tdp6ocIz/xNcpwPUioCHfq/TSg/00EvSRcAoo3LyXk0EzHIde6LH4st7wpH7 qkHKxy0KPWT2zqEKZLXe3Ypk9sioS9KK6DFC/tFDe+HWhRGynxPrngF6zI805g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705684649; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BKTPVEVklAflXfhzuh6BgvMFv0BehqIqZpTdTV2mXUk=; b=dVUhJhl0/G3T9zsEwakF897SWhzFYVotZw5jw6fX5M013rBrUCVtIbb+eKY+2wDMrCnp0T DbTvjXiTbh800I3HqRwp/z9ZbGafsx4OrYyJr+u3jgmVUX0OMjJIkJrMnDRdp2dkagTyD2 ImX1AyzY7D8dnkL/hlNPiEL/YvP5IxIrZ/8cTqv5Nece3L0+Op5D+HZ01F/5BSp5ivkOz9 YZsQBhd27DyzgV+kQKjGyU4uMgTxrMIe4hW0SIaYPeB0UDrq0Qu25V3RLUAURYvjJLwxoA A3NdSb//LLvfUF7jnX51aF/IpPwbaCdj9A4IEfKDPFQkTd/NRrvodswib0exKg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705684649; a=rsa-sha256; cv=none; b=ODS+lmhU9u6I3mpmEpRyHhc4RChrIapDsYVWw/qUTnM99jV394t+9uA0das3pOU7wtzBVW pya6Wfhw9oEhYMkBJeynjPLCtutA+49tq5qE/tXz3F0gVdEglEqHtt3nYtJwiaMZaornEm NYq8tlMC+hfo2omoUI1rEcGn7ZPoAVUQ2krwdPq8NwYxN3aJRM8owh/4nivCaqcormEVDw RF7TVKBx6MOgNCLNo7YO9Ot/yB167HmfWdAbZpQRA79mOLhsVsqVquAfpJVlC7FSYD1YF0 49dTezCqk9qze32TnqJZmlVOtajEvht/18afBluixUTOQWHt311JjcT9Mm1lzg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TGmWs0DZkz10P0; Fri, 19 Jan 2024 17:17:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40JHHSWx096753; Fri, 19 Jan 2024 17:17:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40JHHSxV096750; Fri, 19 Jan 2024 17:17:28 GMT (envelope-from git) Date: Fri, 19 Jan 2024 17:17:28 GMT Message-Id: <202401191717.40JHHSxV096750@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 0d2cce768cbc - stable/14 - mpi3mr: Don't hold fwevt_lock over call to taskqueue_drain List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 0d2cce768cbcdd97efd027661c53611c122492ce Auto-Submitted: auto-generated The branch stable/14 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=0d2cce768cbcdd97efd027661c53611c122492ce commit 0d2cce768cbcdd97efd027661c53611c122492ce Author: Warner Losh AuthorDate: 2023-11-29 01:48:48 +0000 Commit: Alexander Motin CommitDate: 2024-01-19 17:16:49 +0000 mpi3mr: Don't hold fwevt_lock over call to taskqueue_drain Holding fwevt_lock when we call taskqueue_drain can lead to deadlock because it's draining a queue needs fwevt_lock to do work, so that other thread will try to take out the lock and block, making the thread never finish and taskqueue_drain never complete. There's a witness warning/error for this which was exposed when the lock was converted to a MTX_DEF lock from a MTX_SPIN prior to committing to the FreeBSD tree. The lock appears to be to protect against additional items being added to the event list while we're doing a reset. Since the taskqueue is blocked, items can get added to the list, but won't be processed during the reset, but there is still a (likely small) race between the taskqueue_drain and the taskqueue_block calls where an interrupt could fire on another CPU, resulting in a task being enqueued and started before the block can take effect. The only way to fix that race is to turn off interrupt processing during a reset. So we replace a deadlock with a smaller race. Sponsored by: Netflix Reviewed by: sumit.saxena_broadcom.com, mav, jhb Differential Revision: https://reviews.freebsd.org/D42537 (cherry picked from commit b411372b7d17ae7e5d6c944732d41b979bde2ac4) --- sys/dev/mpi3mr/mpi3mr.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sys/dev/mpi3mr/mpi3mr.c b/sys/dev/mpi3mr/mpi3mr.c index 86535383b8f0..592b0f02cdd7 100644 --- a/sys/dev/mpi3mr/mpi3mr.c +++ b/sys/dev/mpi3mr/mpi3mr.c @@ -2785,7 +2785,6 @@ int mpi3mr_initialize_ioc(struct mpi3mr_softc *sc, U8 init_type) mtx_init(&sc->sense_buf_q_lock, "Sense buffer Queue lock", NULL, MTX_SPIN); mtx_init(&sc->chain_buf_lock, "Chain buffer lock", NULL, MTX_SPIN); mtx_init(&sc->cmd_pool_lock, "Command pool lock", NULL, MTX_DEF); -// mtx_init(&sc->fwevt_lock, "Firmware Event lock", NULL, MTX_SPIN); mtx_init(&sc->fwevt_lock, "Firmware Event lock", NULL, MTX_DEF); mtx_init(&sc->target_lock, "Target lock", NULL, MTX_SPIN); mtx_init(&sc->reset_mutex, "Reset lock", NULL, MTX_DEF); @@ -5826,11 +5825,14 @@ static int mpi3mr_issue_reset(struct mpi3mr_softc *sc, U16 reset_type, inline void mpi3mr_cleanup_event_taskq(struct mpi3mr_softc *sc) { - mtx_lock(&sc->fwevt_lock); - taskqueue_drain(sc->cam_sc->ev_tq, &sc->cam_sc->ev_task); + /* + * Block the taskqueue before draining. This means any new tasks won't + * be queued to a worker thread. But it doesn't stop the current workers + * that are running. taskqueue_drain waits for those correctly in the + * case of thread backed taskqueues. + */ taskqueue_block(sc->cam_sc->ev_tq); - mtx_unlock(&sc->fwevt_lock); - return; + taskqueue_drain(sc->cam_sc->ev_tq, &sc->cam_sc->ev_task); } /**