From nobody Sun Dec 05 01:03:25 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 EA54C189F48B; Sun, 5 Dec 2021 01:03:25 +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 4J67bd4s2xz4n27; Sun, 5 Dec 2021 01:03:25 +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 868066D8D; Sun, 5 Dec 2021 01:03:25 +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 1B513PHX020801; Sun, 5 Dec 2021 01:03:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B513PvD020800; Sun, 5 Dec 2021 01:03:25 GMT (envelope-from git) Date: Sun, 5 Dec 2021 01:03:25 GMT Message-Id: <202112050103.1B513PvD020800@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 2c52eba4f46e - stable/13 - linker_kldload_busy(): allow recursion 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2c52eba4f46e2cc9a4fda3a9e6e81e06fb8daf57 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638666205; 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=APy5NeOmpFS747Mh5ldeZRkpWcqxSJCB4Ic3ZHYrl/E=; b=fnNmX5Szlb5qpPokcm1jBHdoSv8ZXjLvVbk6lQFLHEIBth0T4T4ZikbWfw8xt5omIRdu8k tBUL/8/2O8z/lJqto/MxQxT3W70J3wtxIyprG/5H479Q6Vci4/JC7Fve70llcOXD1cSzBM YOFmG5HFy2k4xyDcRik7GalOsKnROZLMXcjwy0brchENJYuM6hKnBakPQ5Fjh1WysGKMU9 1VmU3hmK+dfk+PoMVIc4F61VSwKMFaAcI0DTtWUZbQbSQQ06dzYFOddZOSZsOHvNfpYdV3 v3FTNVyfQ5nJIjV3meGQBY0nWJmIYFvuu8BnXqZN9TRG1+1wRq/uUvYtvbCDEQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638666205; a=rsa-sha256; cv=none; b=aYvuK4dIyEKN15vv89EunUb/6hUBLH+fLBY698TG7TTqKgAbaYYU3AaOUSdimlC/WohXxF W1Qk6IkqRys2XnD7p6Ko9rzLCxT5PkyyupUV53Qf7Upwd6mQa6KT2Z+Lm3FZsQx+9VCdvP TTHjW/5cLPfP3416U4Z9iDZdtrDE6keJCjIbMGE7gE5raDRiTlQFUyiI8xCjQDTUotPYzG rF/z3zY1+Pt4mN63RwS08VS3z+VI6Nfydp1LaNm4Pac84WYe2cjNJ/k2tvYAv+mZeWiBAc FMSTs25Aul/LnrwOQURnP583NFXyeLnI9sQFNinNcjYWO7W3dQnmE233XaQdCw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=2c52eba4f46e2cc9a4fda3a9e6e81e06fb8daf57 commit 2c52eba4f46e2cc9a4fda3a9e6e81e06fb8daf57 Author: Konstantin Belousov AuthorDate: 2021-11-12 19:45:06 +0000 Commit: Konstantin Belousov CommitDate: 2021-12-05 01:02:57 +0000 linker_kldload_busy(): allow recursion PR: 259748 (cherry picked from commit 4f924a786ae08af496dfe55230f8fe1e2ca16150) --- sys/kern/kern_linker.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c index cb5d587bfbbc..a10c9a0cea7e 100644 --- a/sys/kern/kern_linker.c +++ b/sys/kern/kern_linker.c @@ -106,7 +106,8 @@ MALLOC_DEFINE(M_LINKER, "linker", "kernel linker"); linker_file_t linker_kernel_file; static struct sx kld_sx; /* kernel linker lock */ -static bool kld_busy; +static u_int kld_busy; +static struct thread *kld_busy_owner; /* * Load counter used by clients to determine if a linker file has been @@ -1065,7 +1066,9 @@ linker_kldload_busy(int flags) if ((flags & LINKER_UB_LOCKED) == 0) sx_xlock(&kld_sx); - while (kld_busy) { + while (kld_busy > 0) { + if (kld_busy_owner == curthread) + break; error = sx_sleep(&kld_busy, &kld_sx, (flags & LINKER_UB_PCATCH) != 0 ? PCATCH : 0, "kldbusy", 0); @@ -1075,7 +1078,8 @@ linker_kldload_busy(int flags) return (error); } } - kld_busy = true; + kld_busy++; + kld_busy_owner = curthread; if ((flags & LINKER_UB_UNLOCK) != 0) sx_xunlock(&kld_sx); return (0); @@ -1090,9 +1094,15 @@ linker_kldload_unbusy(int flags) if ((flags & LINKER_UB_LOCKED) == 0) sx_xlock(&kld_sx); - MPASS(kld_busy); - kld_busy = false; - wakeup(&kld_busy); + MPASS(kld_busy > 0); + if (kld_busy_owner != curthread) + panic("linker_kldload_unbusy done by not owning thread %p", + kld_busy_owner); + kld_busy--; + if (kld_busy == 0) { + kld_busy_owner = NULL; + wakeup(&kld_busy); + } sx_xunlock(&kld_sx); }