From nobody Fri Jan 19 17:17:31 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 4TGmWv56gTz56xSr; Fri, 19 Jan 2024 17:17:31 +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 4TGmWv3BKVz4MXR; Fri, 19 Jan 2024 17:17:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705684651; 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=kp4tTnwNbIg8oIkGwgoprTBee1WoAxTzEz4PETC+umQ=; b=yTMbc7+T7Nl4MLuNne2v7Ry8a0iBPTe8cSWcd/Cdcf0O9yABQcVG5fQIjxUuRbkfvhNxxV dX5XtY7xfKNmGN+PXKnsSwq6acKIX9+MaO2ftXAdsyf+KRG4LhF8NZ7YJSQaLi6vbAea0E xC1NxWN/V3MaT4iHHZLw3lyljxmQyf7YmUmdHRIPob0eYQ/fzzOAmKJ44+FpME7twwuGv7 O/y0yqUmu78GwdRAJdbSLu3OE2w331VVnw5ZSAD4e6ETrACZtXVHo3mh/Kz9mPmWnBfVqm pGVs190zd2n6krxTTsoTKBP0VbSXInMlEGmbFEy3DQxjbtH3T/SlJsQ2aQaCpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705684651; 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=kp4tTnwNbIg8oIkGwgoprTBee1WoAxTzEz4PETC+umQ=; b=RzPSWnF50hBXRQiCtcJI894hJtGrKctHgjeqRFI/vZLZ6GqGqP8CLkqMvv+iHsOzTTitz3 Dw4AGwbHBKByk2tN+By1VYHJjwzDVf7JIFszIiwrlMvKh1yCm28hhO1H3AETqYHCKOJ0tD PNDo+quXLfI0QKnAJhbQZVGs7keHgfq9MtpPpBv2uDNWY0mC9ocMyCPwOCn7mKAU67alhf JnfLuPTcQ1jUrPmrOpr8bgdw3+XKfhBwfPfMYIpeDdIXpOMb5V494fMHBEFvoLkqiQjSMY IjPn4NSCjChTNqQ5ConlvsOuFfZJCruFSkhhdDeS4i4KRc3QTuyyRUIzHIKWpg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705684651; a=rsa-sha256; cv=none; b=HI6jvF8CFmCLG6T512F0zTVFcV2Ohiyx0Qrr1s8kc5UDgwgvCxMSq3fILiTidIAi3vTbZz EFsEu8Ij8ZwSioDNzqmIz4+ETJpgrIJilDlTRH91Nczw9UeXO1PJz6M7aDov1ub0W/BAuT SCg0mT8PLNJmv2RdnJP3+VUuCdmtwcWqNGR0GvoT+CqYZiDHo0DIPEyHNKU/L5sQlgbh2q DZMMzCvW1in/+dgkFPAmHZpgQGzYlnSUiErMjV2S77XtC7ApOCRIZcLB2yLZLYRrGmHErj JOg31M+PtFlYCPLYrXDNA4ObHQLRfmxlsgWsRH6XhRF0A6Z6cCjQ+Ub/tqK7Eg== 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 4TGmWv23Sgz10tx; Fri, 19 Jan 2024 17:17:31 +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 40JHHVPp096859; Fri, 19 Jan 2024 17:17:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40JHHVx5096856; Fri, 19 Jan 2024 17:17:31 GMT (envelope-from git) Date: Fri, 19 Jan 2024 17:17:31 GMT Message-Id: <202401191717.40JHHVx5096856@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: 54fa0d10f68c - stable/14 - mpi3mr: Reduce the scope of the reset_mutext 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: 54fa0d10f68c81722c341ae4277d0c5634babd48 Auto-Submitted: auto-generated The branch stable/14 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=54fa0d10f68c81722c341ae4277d0c5634babd48 commit 54fa0d10f68c81722c341ae4277d0c5634babd48 Author: Warner Losh AuthorDate: 2023-11-29 01:49:08 +0000 Commit: Alexander Motin CommitDate: 2024-01-19 17:16:49 +0000 mpi3mr: Reduce the scope of the reset_mutext Reduce the scope of reset_mutext to protect the msleep in the watch dog thread as well as the MPI3MR_FLAGS_SHUTDOWN bit. Use it to protect the wakeup in mpi3mr_detach so this thread can exit sooner when we're trying to do an orderly shutdown. Optimize the flow to check the sleep and other conditions before going to sleep. It's an open question if this should protect sc->unrecoverable, and if we should wakeup the watchdog thread when we set it. We might also want to move too booleans for the three flags that we have now in mpi3mr_flags. There are a number of U8s that should really be bools and we might want to also group them together to pack softc better. Sponsored by: Netflix Reviewed by: mav Differential Revision: https://reviews.freebsd.org/D42539 (cherry picked from commit 7c4913093a759adf2e4c7d65535aee04aadee4df) --- sys/dev/mpi3mr/mpi3mr.c | 26 +++++++++++++++++--------- sys/dev/mpi3mr/mpi3mr_pci.c | 4 +++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/sys/dev/mpi3mr/mpi3mr.c b/sys/dev/mpi3mr/mpi3mr.c index 7bb834430dbc..f6c4bb4496e6 100644 --- a/sys/dev/mpi3mr/mpi3mr.c +++ b/sys/dev/mpi3mr/mpi3mr.c @@ -3038,9 +3038,6 @@ mpi3mr_watchdog_thread(void *arg) sc->watchdog_thread_active = 1; mtx_lock(&sc->reset_mutex); for (;;) { - /* Sleep for 1 second and check the queue status */ - msleep(&sc->watchdog_chan, &sc->reset_mutex, PRIBIO, - "mpi3mr_watchdog", 1 * hz); if (sc->mpi3mr_flags & MPI3MR_FLAGS_SHUTDOWN || (sc->unrecoverable == 1)) { mpi3mr_dprint(sc, MPI3MR_INFO, @@ -3049,20 +3046,21 @@ mpi3mr_watchdog_thread(void *arg) "Hardware critical error", __func__); break; } + mtx_unlock(&sc->reset_mutex); if ((sc->prepare_for_reset) && ((sc->prepare_for_reset_timeout_counter++) >= MPI3MR_PREPARE_FOR_RESET_TIMEOUT)) { mpi3mr_soft_reset_handler(sc, MPI3MR_RESET_FROM_CIACTVRST_TIMER, 1); - continue; + goto sleep; } ioc_status = mpi3mr_regread(sc, MPI3_SYSIF_IOC_STATUS_OFFSET); if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) { mpi3mr_soft_reset_handler(sc, MPI3MR_RESET_FROM_FIRMWARE, 0); - continue; + goto sleep; } ioc_state = mpi3mr_get_iocstate(sc); @@ -3078,7 +3076,7 @@ mpi3mr_watchdog_thread(void *arg) "diag save in progress\n"); } if ((sc->diagsave_timeout++) <= MPI3_SYSIF_DIAG_SAVE_TIMEOUT) - continue; + goto sleep; } mpi3mr_print_fault_info(sc); sc->diagsave_timeout = 0; @@ -3089,12 +3087,12 @@ mpi3mr_watchdog_thread(void *arg) "Controller requires system power cycle or complete reset is needed," "fault code: 0x%x. marking controller as unrecoverable\n", fault); sc->unrecoverable = 1; - goto out; + break; } if ((fault == MPI3_SYSIF_FAULT_CODE_DIAG_FAULT_RESET) || (fault == MPI3_SYSIF_FAULT_CODE_SOFT_RESET_IN_PROGRESS) || (sc->reset_in_progress)) - goto out; + break; if (fault == MPI3_SYSIF_FAULT_CODE_CI_ACTIVATION_RESET) mpi3mr_soft_reset_handler(sc, MPI3MR_RESET_FROM_CIACTIV_FAULT, 0); @@ -3108,8 +3106,18 @@ mpi3mr_watchdog_thread(void *arg) mpi3mr_print_fault_info(sc); mpi3mr_soft_reset_handler(sc, sc->reset.reason, 1); } +sleep: + mtx_lock(&sc->reset_mutex); + /* + * Sleep for 1 second if we're not exiting, then loop to top + * to poll exit status and hardware health. + */ + if ((sc->mpi3mr_flags & MPI3MR_FLAGS_SHUTDOWN) == 0 && + !sc->unrecoverable) { + msleep(&sc->watchdog_chan, &sc->reset_mutex, PRIBIO, + "mpi3mr_watchdog", 1 * hz); + } } -out: mtx_unlock(&sc->reset_mutex); sc->watchdog_thread_active = 0; mpi3mr_kproc_exit(0); diff --git a/sys/dev/mpi3mr/mpi3mr_pci.c b/sys/dev/mpi3mr/mpi3mr_pci.c index 4935ac0d519c..eaf73022291d 100644 --- a/sys/dev/mpi3mr/mpi3mr_pci.c +++ b/sys/dev/mpi3mr/mpi3mr_pci.c @@ -635,13 +635,15 @@ mpi3mr_pci_detach(device_t dev) if (!sc->secure_ctrl) return 0; - sc->mpi3mr_flags |= MPI3MR_FLAGS_SHUTDOWN; if (sc->sysctl_tree != NULL) sysctl_ctx_free(&sc->sysctl_ctx); + mtx_lock(&sc->reset_mutex); + sc->mpi3mr_flags |= MPI3MR_FLAGS_SHUTDOWN; if (sc->watchdog_thread_active) wakeup(&sc->watchdog_chan); + mtx_unlock(&sc->reset_mutex); while (sc->reset_in_progress && (i < PEND_IOCTLS_COMP_WAIT_TIME)) { i++;