From nobody Wed Nov 29 01:55:32 2023 X-Original-To: dev-commits-src-main@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 4Sg2Td09WCz52tNv; Wed, 29 Nov 2023 01:55:33 +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 4Sg2Tc5fhZz3gnp; Wed, 29 Nov 2023 01:55:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701222932; 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=eCNzM7mNvEAuE1y5M6iHcyocpS1mlV17XZaQ4RRNvO4=; b=RKIU3pec4TD7gjIBMY1H4SHyC6qTWwOHJrbzlrsR83t+bA6vrXSx20RwOYcYjYGT8LPeE8 ctDEtFsk38e0pamWH91ZvBX6jciOHUsViMq1WGwgJzVyjUINsXvdG8LS1YuHt0uwDzQCXB PA5djBjmiuxGYiNZwkYyz1CfK3VjtqXMLjE4zILWC+vCUuZjTxMGTJ0PzbS0En2Qu9KV5b xhAvMUZzN2vxwvB4DlOKnyOupz5IhwlPM5lnlfI0BOe/8r10q6f68uDY7HI+yJ61WjXqUX MFxFY/sTvgbTmqc86e6KhRHkM3kLwVUhdhJq+YctX+3Yaln/PjlN8T8mIE3RMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701222932; 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=eCNzM7mNvEAuE1y5M6iHcyocpS1mlV17XZaQ4RRNvO4=; b=Cvbc1BZiWFdq8w9wNN9Tf3HtyTFE92utvpY3pCzgXHfGCprp/Sf/gLpotpDWpCiUKegdff 10kXSQT+ddPHHDrT+lIJj80OkGY2ygbobyls74SEIjni1IFogLlWsMBG7LNFRpHtjTuaVc IpWX3AYA5+xinX/jyz+oEtLiZhbQrVwa1d/2YemJBRByL3qdgLpIYw+zc3NQQopxvih4nx lOtPqz0Jn6JNI81nFtzDPFvrpAbJyYt0DtEXrVUnDsovkQBoQlhjv89n0GkyTXzpvGj7Gq 8Zo0vCwF+zz5G0XngCIBNu1Azvi3IUADjSaW/ub7Ukma1/KAlLLf3NcSUZr4ew== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701222932; a=rsa-sha256; cv=none; b=oROmL+WV1yPTcmeXgMYDrg0vi1h5WwkCsoxFz4CADXdedGdxuZWekwJf3bXJcxXd6WAcOg ulx0AYwVNKVxuwAPSXBA/JrrUsSKsYmoLuXhFrygcUal/wXGCgebjD+oc+UVcDI7f+0KNG uQceY73Nw+wzTEISvsjhQ8UjlMmgEcJ3m2Ccim04nlXBBAEpUvVjsio19LPPHYDuE/XA8y eV96rMINfqQK2eGi2TKyU5YaHUx035/145xRhKUdSRKU+gFYTxiVo1F6LAVd/xFRsySNj9 uUQm6GMc1X491G3EOFodXbFLy7DltLllv436yUuf7H0bniwBGqstkz+FhQMS/w== 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 4Sg2Tc4mR7zmhf; Wed, 29 Nov 2023 01:55:32 +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 3AT1tWsq064256; Wed, 29 Nov 2023 01:55:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AT1tWjh064253; Wed, 29 Nov 2023 01:55:32 GMT (envelope-from git) Date: Wed, 29 Nov 2023 01:55:32 GMT Message-Id: <202311290155.3AT1tWjh064253@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 7c4913093a75 - main - mpi3mr: Reduce the scope of the reset_mutext List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7c4913093a759adf2e4c7d65535aee04aadee4df Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=7c4913093a759adf2e4c7d65535aee04aadee4df commit 7c4913093a759adf2e4c7d65535aee04aadee4df Author: Warner Losh AuthorDate: 2023-11-29 01:49:08 +0000 Commit: Warner Losh CommitDate: 2023-11-29 01:49:08 +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 --- 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 9a052c98d13e..a2e43850d9b5 100644 --- a/sys/dev/mpi3mr/mpi3mr.c +++ b/sys/dev/mpi3mr/mpi3mr.c @@ -3037,9 +3037,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, @@ -3048,20 +3045,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); @@ -3077,7 +3075,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; @@ -3088,12 +3086,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); @@ -3107,8 +3105,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++;