Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2446055rdh; Sun, 29 Oct 2023 17:13:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUoE+W9k6bybwpq2u6HBdyT+3wikDCcbsAEYs0JFmXvwYt/GLc/PWTxOhY+gDV4+/WyPTx X-Received: by 2002:a05:6a20:e687:b0:13c:988c:e885 with SMTP id mz7-20020a056a20e68700b0013c988ce885mr6514477pzb.56.1698624786540; Sun, 29 Oct 2023 17:13:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698624786; cv=none; d=google.com; s=arc-20160816; b=TGFP+Mxc7tUEv85Smo3AMVBM61Ltkpwc7V0yZex+ohXw5c54I4h5vpEd7wUxoibr0d RBFHshL6rOvxyVXS2tl6vXZkQZADWPJuzDnZD9i6M2kaZQMkF9tfQpTe15QTz2/RjkfP JFaDimuIogyCAuQZzXggQB42rNRlCynu3yBDGa49aUmHQg0Jag9nZkfZewCvTcm9kcV1 yFwvdyXu6SLPlucSHfBJo2zlilCs1rbPpgIcJpuDZsda3NuTH33jSo85wvD3iLEmQKRx 93NuLprIqI8YNnfQCpumB0m5bZCTK+shPFFuRyZ3+FilwsOlMHForjGvsyGn5KCOM2uW BiGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cgDqnmaU8GCYumXY+Sm0+eFFbPyMGM7f5ej3NF2uidU=; fh=i6/rc3erehMNFkaVNadaXi6XZEZ15EorCOiwHt4KAAY=; b=xwUrudbQiz6M2Re1Cb79rbi5b+FIksvbywqT7WGXiRyGB8ooiDlRzhzPO4g4RIUety E+P/DYM8HPPwpr12PvK5StVaR+pIxe3gLMQgRxnmv6ini2LCRingxE9ytg3UIqgeOVys ZqfR6XmH3acpWju+AU/36VD67d+xxRYScR+079+0zpiQb6nM6fg56x1j0VimMo4o44pd UXiBijnftfaozQHYjy/6tfhtzKS1O/KWbX3kBHeg34Znmz+l0u5xnuofYKD6BQRTm8bH +qOcxUNk1VjYPmFQjxn+5K+elRJlDsgyOr5ML2xKDaI4yXlPHGFWQ0fhdbLlN1fTfexs uyUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eznq8qIv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id d20-20020a056a0010d400b006b2562dbd24si4222812pfu.220.2023.10.29.17.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 17:13:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eznq8qIv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 8FEF98057455; Sun, 29 Oct 2023 17:13:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230481AbjJ3AMu (ORCPT + 99 others); Sun, 29 Oct 2023 20:12:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231312AbjJ3AMn (ORCPT ); Sun, 29 Oct 2023 20:12:43 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9461D7D; Sun, 29 Oct 2023 15:55:57 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EED33C433CA; Sun, 29 Oct 2023 22:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698620148; bh=ZZQxw68ufr291FUHWJMZVT6Kvaw2JkgJY6lRE6iV3fk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eznq8qIvnq9iopUqFkMrflUixS3sZpKei8XfngPK57fijIFAv3mLu9VBTzQwQQbVr 3j4u3imN+Mnq6W9hU0uqIjwKI5U7RG4SR6zg0YFWqb+jS5AycEzDzHWduzZT/NITHH 8ufBlSn6jeHnzMCZAbu1A3Yu4OkLGxGjLq3DK19FovtXM5KLsbRZ+/nRL94J7qCLUp BWinjQQT56QjHx2Gj9+9RM3tfodXCFDHBwXamj//Ux5g1vHJo7q4mJQ3RWJD7ROwtl QB+dGEb+vUT/1qnsTqkvMGKHqQlGyyldJeJ59v/9CoRoO9NIndBTCLggYTmTIvwiVr 7nRPCK7NjInvg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Karolina Stolarek , =?UTF-8?q?Christian=20K=C3=B6nig?= , Sasha Levin , ray.huang@amd.com, airlied@gmail.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 6.5 31/52] drm/ttm: Reorder sys manager cleanup step Date: Sun, 29 Oct 2023 18:53:18 -0400 Message-ID: <20231029225441.789781-31-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231029225441.789781-1-sashal@kernel.org> References: <20231029225441.789781-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.5.9 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sun, 29 Oct 2023 17:13:03 -0700 (PDT) From: Karolina Stolarek [ Upstream commit 3b401e30c249849d803de6c332dad2a595a58658 ] With the current cleanup flow, we could trigger a NULL pointer dereference if there is a delayed destruction of a BO with a system resource that gets executed on drain_workqueue() call, as we attempt to free a resource using an already released resource manager. Remove the device from the device list and drain its workqueue before releasing the system domain manager in ttm_device_fini(). Signed-off-by: Karolina Stolarek Reviewed-by: Christian König Link: https://patchwork.freedesktop.org/patch/msgid/20231016121525.2237838-1-karolina.stolarek@intel.com Signed-off-by: Christian König Signed-off-by: Sasha Levin --- drivers/gpu/drm/ttm/ttm_device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c index 7726a72befc54..d48b39132b324 100644 --- a/drivers/gpu/drm/ttm/ttm_device.c +++ b/drivers/gpu/drm/ttm/ttm_device.c @@ -232,10 +232,6 @@ void ttm_device_fini(struct ttm_device *bdev) struct ttm_resource_manager *man; unsigned i; - man = ttm_manager_type(bdev, TTM_PL_SYSTEM); - ttm_resource_manager_set_used(man, false); - ttm_set_driver_manager(bdev, TTM_PL_SYSTEM, NULL); - mutex_lock(&ttm_global_mutex); list_del(&bdev->device_list); mutex_unlock(&ttm_global_mutex); @@ -243,6 +239,10 @@ void ttm_device_fini(struct ttm_device *bdev) drain_workqueue(bdev->wq); destroy_workqueue(bdev->wq); + man = ttm_manager_type(bdev, TTM_PL_SYSTEM); + ttm_resource_manager_set_used(man, false); + ttm_set_driver_manager(bdev, TTM_PL_SYSTEM, NULL); + spin_lock(&bdev->lru_lock); for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) if (list_empty(&man->lru[0])) -- 2.42.0