From nobody Sun Nov 28 08:36:22 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 1CE9418C522D; Sun, 28 Nov 2021 08:36:23 +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 4J21zV4GPMz4jym; Sun, 28 Nov 2021 08:36:22 +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 730094002; Sun, 28 Nov 2021 08:36:22 +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 1AS8aMrF073382; Sun, 28 Nov 2021 08:36:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AS8aMBD073381; Sun, 28 Nov 2021 08:36:22 GMT (envelope-from git) Date: Sun, 28 Nov 2021 08:36:22 GMT Message-Id: <202111280836.1AS8aMBD073381@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 4f924a786ae0 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 4f924a786ae08af496dfe55230f8fe1e2ca16150 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638088582; 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=XaBFjrepKSPZt4L7t4Vbm+z7tCj1sRUCBPrORupBcFc=; b=r+x2Za+Xpzo1k67xP0Nj/R5lXbPuyC3vgHnWrI8zjnr6Fhx5w6P+F1Coj6Pi3IqB5GOe+Z Ai7XkIQeWtlZgKaLj6+luxbWlMwnTs4FgKZpnyqLWThDl7ZME4VKjpaGJLH0PHtLF2IX+1 jyka/H8l9kNWYy2dhvx+JOwWaXNdBo8IUFWWbZyr2Og4xe7NRqDrqXbop2NLYcX4D3u3fy U/O8ztmf81/vv/vT/CziqRKnYMGOWlQ8N/Ue37aDgzO2ECmU2TAa8RBSuDPd+KYMsXFDGq EjAI+BbPJrxIVtOBFl0OvacLD985qLHSekz//hsITrdZNqJp6IImYC2PN/kqLQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638088582; a=rsa-sha256; cv=none; b=uWtI4j+wg8yhwvUY+iuswt4zZ6bcovkAe8NbSZ7xHa+RfODKf07n8ggo7JkfbqJe+xsulF Npz/eIOwjORtR4/VDkyM5gy4J5Gj3k/1zzYjqSXzEvXHfwHvqMM5FQg1tL6IHtn6ZSiC9W C4CoaHVL1gby9LkqavgtcbOTUw7c18xJ+WE9P6Z3NSmRrHfZvC+n3DlAtTTuKDTZRq2BVR HoATKlUn1llsLnPXjkaFxvKVPjaeFx5I4+eKZkB/E8qWIawyo8GAvBSNSshIIAtLIbY3F+ OTAvkl1HL/LnvpdDw/p6vaXieAGjSJ46pxRClGgMil0wivUTrwY8XHgwRDv87g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4f924a786ae08af496dfe55230f8fe1e2ca16150 commit 4f924a786ae08af496dfe55230f8fe1e2ca16150 Author: Konstantin Belousov AuthorDate: 2021-11-12 19:45:06 +0000 Commit: Konstantin Belousov CommitDate: 2021-11-28 08:36:09 +0000 linker_kldload_busy(): allow recursion Some drivers recursively loads modules by explicit calls to kldload during initialization, which might occur during kldload. PR: 259748 Reported and tested by: thj Reviewed by: markj Sponsored by: Nvidia networking MFC after: 1 week Differential revision: https://reviews.freebsd.org/D32972 --- 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 bcdbb467e84e..1337d2c0b278 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); }