From nobody Thu Aug 01 22:27:34 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 4WZk9g1RFzz5RZK0; Thu, 01 Aug 2024 22:27:35 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WZk9f5xZDz4Yx6; Thu, 1 Aug 2024 22:27:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722551254; 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=XpYWqUBW86OTSTOuGft+lA5WNhqQ1we3Ojp/coW0yrk=; b=RDhd2LHga2D7P09xAxXrjnO/LR6lFyfdLMTKxKPSRVRJblSmPiw/D/UIS3CSObkhj9aryD M8+vroDIH53/a6fzZIqwgjU3os1EGwzrcgCgeO+jkrKaFjqSSeFL0oKgHZ9O5A7u1gpTdT hl82EuA0cMTkJZG9STcY4LhOIhxRUh4JWaq+Thb+MGGkc/xB5ZMufzKWhnfnjT4E8dPsov KrmAuzRlWJ4flf6sG30fnB3RdqvNCJhlTr1qMXj1IF0jMyIfQxU3yv5Z0crbqIa08Q6GcG q1DKs4b2RxiKcMAhpJWs2B6qvxTVmOlGtqwZUoboDP4MBCFhii5imtmDSBQoBA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722551254; a=rsa-sha256; cv=none; b=BnSfVauLbwwVSQR3W7OR6ZABGrGcSrLx2p1/nXOwfPY9emRV8XWX+KLnmcu3Py4m18qFp8 +A/MvpRIsAjBoOmW6/9Hwg1+N2TZwpmf+zDa94c/BMawIBZtWbspYek1Nk6Mcpud2obUsq ruKYccUMRAMATm6uTfO1VkI8M8KI6qRzlBv5TVkaIu+EJu0pWDs1pVcnZw97UbMEOBAorC KZkhfkgMQ8tTxBDC6mwIlW6+H9lrrEubnWvsouCJ06xggRLCMySffU0dlYntyl+/sxsGYD kzhLRmHAmP50o63VjnAzXqahXdTuDRg/WKN0E9SGjQ7AEWp89cSEVUl7TJdJlA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722551254; 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=XpYWqUBW86OTSTOuGft+lA5WNhqQ1we3Ojp/coW0yrk=; b=rgGx9tuaxcv/5Ueo04NI4f3jP2pUmsKfJJYZMgL3+2nqHdK2YEpNxUu1ItXHzKyuvTtK0r LoXLCVrH3HdyVDv6FBQYzwjymvT8X2VS04/T23J6LZpxfd7D56hRIBLZKRSGoS6cen4pkm Ax5j1LEPDKUBf4ge78puDiMgQ+P/S042YDPD7cL7pqPWqp9hIZi7o0MMY/4sgFKg5RF7Tx yryufev/VMEQUXNKuoWEmV9roDyl3LbnF5A8z7SSIqEM/QwsQ5R4tSFrtPd4Hk2HyhJmgD 9Ph9YtbsotvI+aG4b7mmZFeeY9VM7/EFDl5WBK2mqzyZFhMyrnUOidYRIeEjSA== 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 4WZk9f5YXKz13GK; Thu, 1 Aug 2024 22:27:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 471MRYu8027381; Thu, 1 Aug 2024 22:27:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 471MRYtK027378; Thu, 1 Aug 2024 22:27:34 GMT (envelope-from git) Date: Thu, 1 Aug 2024 22:27:34 GMT Message-Id: <202408012227.471MRYtK027378@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: 89e485e04d54 - stable/14 - linuxkpi: Allow ida_destroy and idr_destroy to be called multiple times 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 89e485e04d547b236f32e3d4eb9ece0684ef01e0 Auto-Submitted: auto-generated The branch stable/14 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=89e485e04d547b236f32e3d4eb9ece0684ef01e0 commit 89e485e04d547b236f32e3d4eb9ece0684ef01e0 Author: Austin Shafer AuthorDate: 2024-06-06 20:42:06 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-08-01 21:09:39 +0000 linuxkpi: Allow ida_destroy and idr_destroy to be called multiple times This fixes some weird behavior triggered by nvidia-drm.ko: some DRM cleanup functions will be called multiple times, leading to a double free. drm_mode_config_cleanup will be called twice, causing ida_destroy to be called twice. Although calling the cleanup twice doesn't seem very clean, on Linux this seems to be permissable as it handles it just fine. Not doing these checks causes mutex panics and double frees. In order to preserve this behavior this change checks if the objects have already been destroyed and bails if so. This fixes the panic seen when unloading the nvidia-drm driver. MFC after: 1 week Reviewed by: bz, manu Differential revision: https://reviews.freebsd.org/D44865 (cherry picked from commit 613723bac219cb08ac1ad0afd3e07850d7fccc10) --- sys/compat/linuxkpi/common/src/linux_idr.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/compat/linuxkpi/common/src/linux_idr.c b/sys/compat/linuxkpi/common/src/linux_idr.c index b80f8c168d45..8d7f76c7964b 100644 --- a/sys/compat/linuxkpi/common/src/linux_idr.c +++ b/sys/compat/linuxkpi/common/src/linux_idr.c @@ -179,6 +179,14 @@ idr_destroy(struct idr *idr) { struct idr_layer *il, *iln; + /* + * This idr can be reused, and this function might be called multiple times + * without a idr_init(). Check if this is the case. If we do not do this + * then the mutex will panic while asserting that it is valid. + */ + if (mtx_initialized(&idr->lock) == 0) + return; + idr_remove_all(idr); mtx_lock(&idr->lock); for (il = idr->free; il != NULL; il = iln) { @@ -803,4 +811,5 @@ ida_destroy(struct ida *ida) { idr_destroy(&ida->idr); free(ida->free_bitmap, M_IDR); + ida->free_bitmap = NULL; }