From nobody Mon Dec 13 11:51:00 2021 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 4D42D18E3DCD; Mon, 13 Dec 2021 11:51:01 +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 4JCKb90FsJz4gDP; Mon, 13 Dec 2021 11:51:01 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 DDE40142B2; Mon, 13 Dec 2021 11:51:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BDBp0b6078737; Mon, 13 Dec 2021 11:51:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BDBp0jV078736; Mon, 13 Dec 2021 11:51:00 GMT (envelope-from git) Date: Mon, 13 Dec 2021 11:51:00 GMT Message-Id: <202112131151.1BDBp0jV078736@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andriy Gapon Subject: git: df472af034e7 - main - mmc_sim: fix setting of the mutex name 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: avg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: df472af034e7726dea533ac7f44440dad4ba6a34 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639396261; 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=T+r9nU/mfgIRM6MZvns3JCIn0jGX7xP+13q4ZuncGDc=; b=eSOK5OxnTxZ0eBzYfFxFbUHpDN3kVoA0sULJrL9tK2ZrGyAUy96ESmb/x4S/oZxbyQ9Rkr SeG1yTEuQt7S2Nt8xAMSvG1Us6ys8Cnn22a/ETfHAGq4qU6oIIDkSkVXirGm5y1E0vwTLY PzL5s+aIWBqPCwKS4wmrM6K7OFkXciOt6hDwc/FZVGRo4r0btK/m23jDNmmPxorqw5mVqd hP/cRYWQh+aEyiFy3y5AcKA1gBisetw67VrADIAennJR+j15W7DG3YcphRy5cl1HXwHD6E wg0Ze+a+Pr51vJ9HJ19C0p/bgOBIrDJe/7ajCr1jZMMf0TeNF6HtqW8acsUAOw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639396261; a=rsa-sha256; cv=none; b=mvh+nqJaVMfXHmi+5/zfCXfMjTWRPht6vKreNdOlZ3a0s6clxmgx5ObIkVsnbVLIbArM6u CsZ/C5UgrKSdp0gX1BTGG+IAgnBUpvfR4yoJa/5S2XWpi0w9vAdfGWOxu7znCAhZfudzO3 N0piGS+qj7+RshtSNIaiNAmjwoCNQniCbm0bB18gfJZixMeodflhGYm8SqwujsoDxZIZC8 0eVv4VjAo1u8oFi3IZpklA6t5zLmRXQohh9AFhVtC9jb9EgliO06k5PfCDLNAyoRC3AHjq NFTFaqgYjXzQylPYkLPx1rhQ4F51bHnhx8yWcPZnPe5MoWrgy3LXRW76dkd2rQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=df472af034e7726dea533ac7f44440dad4ba6a34 commit df472af034e7726dea533ac7f44440dad4ba6a34 Author: Andriy Gapon AuthorDate: 2021-11-26 14:00:45 +0000 Commit: Andriy Gapon CommitDate: 2021-12-13 11:40:47 +0000 mmc_sim: fix setting of the mutex name To quote the manual: The pointer passed in as name and type is saved rather than the data it points to. The data pointed to must remain stable until the mutex is destroyed. It seems that the type is actually copied, but the name is stored as a pointer indeed. mmc_cam_sim_alloc used a name stored on stack. So, a corrupt mutex name would be reported. For example: lock order reversal: (sleepable after non-sleepable) 1st 0xd7285b20 <8A>P@P@^D^A (aw_mmc_sim, sleep mutex) @ /usr/devel/git/orange/sys/cam/cam_xpt.c:2804 This change moves the name to struct mmc_sim. Also, that name is used as the sim name as well. Unused mtx_name variable is removed too. --- sys/cam/mmc/mmc_sim.c | 9 +++------ sys/cam/mmc/mmc_sim.h | 1 + 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/sys/cam/mmc/mmc_sim.c b/sys/cam/mmc/mmc_sim.c index 45d706f61d0a..792551a93511 100644 --- a/sys/cam/mmc/mmc_sim.c +++ b/sys/cam/mmc/mmc_sim.c @@ -191,7 +191,6 @@ mmc_cam_sim_default_action(struct cam_sim *sim, union ccb *ccb) int mmc_cam_sim_alloc(device_t dev, const char *name, struct mmc_sim *mmc_sim) { - char sim_name[64], mtx_name[64]; mmc_sim->dev = dev; @@ -199,13 +198,11 @@ mmc_cam_sim_alloc(device_t dev, const char *name, struct mmc_sim *mmc_sim) goto fail; } - snprintf(sim_name, sizeof(sim_name), "%s_sim", name); - snprintf(mtx_name, sizeof(mtx_name), "%s_mtx", name); - - mtx_init(&mmc_sim->mtx, sim_name, NULL, MTX_DEF); + snprintf(mmc_sim->name, sizeof(mmc_sim->name), "%s_sim", name); + mtx_init(&mmc_sim->mtx, mmc_sim->name, NULL, MTX_DEF); mmc_sim->sim = cam_sim_alloc(mmc_cam_sim_default_action, mmc_cam_default_poll, - name, mmc_sim, device_get_unit(dev), + mmc_sim->name, mmc_sim, device_get_unit(dev), &mmc_sim->mtx, 1, 1, mmc_sim->devq); if (mmc_sim->sim == NULL) { diff --git a/sys/cam/mmc/mmc_sim.h b/sys/cam/mmc/mmc_sim.h index 2b1159a9758e..10bd183c307d 100644 --- a/sys/cam/mmc/mmc_sim.h +++ b/sys/cam/mmc/mmc_sim.h @@ -33,6 +33,7 @@ struct mmc_sim { struct mmc_cam_sim_softc *sc; struct mtx mtx; + char name[64]; struct cam_devq *devq; struct cam_sim *sim; device_t dev;