From nobody Thu Jun 06 20:42:56 2024 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 4VwGVm5y6Bz5MxS0; Thu, 06 Jun 2024 20:42:56 +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 4VwGVm5KZrz4qFL; Thu, 6 Jun 2024 20:42:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717706576; 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=X37iVPx7SkopSCraHL+SO9ZQUUREDZsPmc/MinC6xow=; b=b6dgZv+3xg72B0CY6re2X8bU1vCkQrGFRxF1F/PMii/WCkOYiblTliaqh2mOLgNM8bhvvH pO0JqZ/aMuhp1JxW3XGNAU29HZiAcJJguaQ2eja89S+Ur5f3kfhZs65eEdL6h+eaMIXZFk rJh4ez9hrEcwFDvXIZvSo7MG5IW1WmVXYl0E17Dk2hQt+g329U8621JelnBOSgsch9/wAv Ja2ZeNcBc0exr5ISlGl0/31CXdbXL0K7IRW7wDdNHhdOjF5xWTx2rkQ4G2kFB5qJEcMfO5 bL+I57g96ga118QBW3AcHWMfllmh7cxnp7hjA9XQKOWLsm0s1xlu5pPQKKpZtQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717706576; a=rsa-sha256; cv=none; b=NwR24XUmec23MNAQ5VtrLM4edHSfO6gbckt7w4902y6A9vxPBcADYCbBr0eB8+lqDHXvDJ 4dfXXK+Tz1YqOlD6Qsu17cWC0Df03kzukesFQBiBky7+T298+e0ExD5gG+CW4pHEc4/s4W 8kOKchAWhZkbmF/BM0efw5P0ehkUI3V4gyC6iRQNbLXaud4ug//8+lLR6RPyvEdZ9djHQs 9Vk72frqHMIGbVoQbYQ0d2PeCgPYAiNOvgWrmAUkpWaNGNNzwYR7GwngUMyhp8+gEhtSWt QgQnuUlcpotOjzNMVOh+TjgVO/YiGXD4qTiP0S5IuHugMlhWnFauAQza/2Abfg== 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=1717706576; 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=X37iVPx7SkopSCraHL+SO9ZQUUREDZsPmc/MinC6xow=; b=TZQqa9eTFRIUz8700a5eh2H8F0M4sATXOfTENT2s4CjZpn6SLfI+LJgZnQ6VPlT0CTUv15 TUYJo2TXdHaF5l39T2yK8eIai2MAX281Ft7jrMPQYTs+fuc3tGMLT9v9unZLpgTzZZL3sZ pM7XwNnl3f1pW3BAraK+yP67UUugX3eUAtlZx6pnjLI5pZ7vBoOhRZ65TRuutwYxlku2hv 2A/ACJqDPgKTe2FABEsa5la6rVIgdOP83GFfQUTm+NRy0nHkh4JyOawpYY0lpiWH7CLcSc Vs13uE3CJzZ2fi0cr15/gBnhw6dRukkck+tanJPfv0J0d949fu7qWKsFhw+uiw== 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 4VwGVm4w0pz11Hf; Thu, 6 Jun 2024 20:42:56 +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 456KguFw046123; Thu, 6 Jun 2024 20:42:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 456Kgus0046120; Thu, 6 Jun 2024 20:42:56 GMT (envelope-from git) Date: Thu, 6 Jun 2024 20:42:56 GMT Message-Id: <202406062042.456Kgus0046120@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 613723bac219 - main - linuxkpi: Allow ida_destroy and idr_destroy to be called multiple times 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 613723bac219cb08ac1ad0afd3e07850d7fccc10 Auto-Submitted: auto-generated The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=613723bac219cb08ac1ad0afd3e07850d7fccc10 commit 613723bac219cb08ac1ad0afd3e07850d7fccc10 Author: Austin Shafer AuthorDate: 2024-06-06 20:42:06 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-06-06 20:42:06 +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 --- 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 583e2c237198..59c375194689 100644 --- a/sys/compat/linuxkpi/common/src/linux_idr.c +++ b/sys/compat/linuxkpi/common/src/linux_idr.c @@ -178,6 +178,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) { @@ -802,4 +810,5 @@ ida_destroy(struct ida *ida) { idr_destroy(&ida->idr); free(ida->free_bitmap, M_IDR); + ida->free_bitmap = NULL; }