Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 959E2606A320 for ; Tue, 1 Dec 2026 16:02:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=II+GNHQI Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3628310E3DB; Tue, 1 Dec 2026 16:02:34 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id AF07010FA84 for ; Tue, 1 Dec 2026 16:02:27 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 5839941711; Tue, 1 Dec 2026 16:02:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B84A51F00926; Tue, 1 Dec 2026 16:02:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796140946; bh=3yomr2W6yTuXL6Kqm+ClDRt4Xsqw40EWuE0RtVeeEZo=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=II+GNHQIcf69uVCylX43Rli4OnZyO67nLVCYDuYlUgw8b8cja42s8Vgr3y2PGMJOt GjAdVHnXDyy3Lx0Wln9Txzov9toqwZlyKY609MRrkwzeohtcUAmfZw4dtv1Hv6Gp9K JvAozaeRDdeKau9wnkUrY6NHCnh7RxZT2wzWWog6ZP+qXrYnwksEX0mcnUErD+YRhw +QjYecgXcTHTfH9XKJJVmVWdF+h7Q1K7QweO6SnnPOBESVhwce+lLpby7GchdKlquC O+AncHQkcagnbXrhww5UfKZMHWRyWzVDjdnb+UZJt5dH2na4UN+20RSrj74ftVDcjM TnK5EFRm6TkPw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC v3 2/4] drm/amdgpu: Cleanup on ring failure To: "Tvrtko Ursulin" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261201154232.78320-3-tvrtko.ursulin@igalia.com> References: <20261201154232.78320-1-tvrtko.ursulin@igalia.com> <20261201154232.78320-3-tvrtko.ursulin@igalia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 16:02:26 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "amd-gfx" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/amdgpu: NULL deref and double fini in amdgpu_fence_driver_fini_ring() -- commit 189f0a18b562d59559b39f2a462dcfb86a6bfab5 Author: Tvrtko Ursulin drm/amdgpu: Cleanup on ring failure This commit updates amdgpu_ring_init() and amdgpu_ring_fini() to clean up allocated writeback slots, buffer objects, and the fence driver when ring initialization fails, introducing amdgpu_fence_driver_fini_ring(). > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/= amd/amdgpu/amdgpu_fence.c > index d0a6901532fd6..1f1c28b200ffa 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c > @@ -577,31 +577,43 @@ void amdgpu_fence_driver_isr_toggle(struct amdgpu_d= evice *adev, bool stop) > } > } > =20 > -void amdgpu_fence_driver_sw_fini(struct amdgpu_device *adev) > +/** > + * amdgpu_fence_driver_fini_ring - fini the fence driver > + * for the requested ring. > + * > + * @ring: ring to fini the fence driver on > + * > + * Cleanup the fence driver for the requested ring (all asics). > + */ > +void amdgpu_fence_driver_fini_ring(struct amdgpu_ring *ring) > { > - unsigned int i, j; > + unsigned int i; > =20 > - for (i =3D 0; i < AMDGPU_MAX_RINGS; i++) { > - struct amdgpu_ring *ring =3D adev->rings[i]; > + if (!ring) > + return; > =20 > - if (!ring || !ring->fence_drv.initialized) > - continue; > + /* > + * Notice we check for sched.ops since there's some > + * override on the meaning of sched.ready by amdgpu. > + * The natural check would be sched.ready, which is > + * set as drm_sched_init() finishes... > + */ > + if (ring->sched.ops) > + drm_sched_fini(&ring->sched); > =20 > - /* > - * Notice we check for sched.ops since there's some > - * override on the meaning of sched.ready by amdgpu. > - * The natural check would be sched.ready, which is > - * set as drm_sched_init() finishes... > - */ > - if (ring->sched.ops) > - drm_sched_fini(&ring->sched); > - > - for (j =3D 0; j <=3D ring->fence_drv.num_fences_mask; ++j) > - dma_fence_put(ring->fence_drv.fences[j]); > - kfree(ring->fence_drv.fences); > - ring->fence_drv.fences =3D NULL; > - ring->fence_drv.initialized =3D false; > - } > + for (i =3D 0; i <=3D ring->fence_drv.num_fences_mask; ++i) > + dma_fence_put(ring->fence_drv.fences[i]); > + kfree(ring->fence_drv.fences); > + ring->fence_drv.fences =3D NULL; > + ring->fence_drv.initialized =3D false; > +} [Severity: High] Can amdgpu_fence_driver_fini_ring() dereference a NULL ring->fence_drv.fences pointer? In amdgpu_ring_init(), ring->adev and adev->rings[ring->idx] are populated before calling amdgpu_fence_driver_init_ring(), which sets ring->fence_drv.num_fences_mask before allocating ring->fence_drv.fences: drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c:amdgpu_fence_driver_init_ring() { ... ring->fence_drv.num_fences_mask =3D ring->num_hw_submission * 2 - 1; spin_lock_init(&ring->fence_drv.lock); ring->fence_drv.fences =3D kzalloc_objs(*ring->fence_drv.fences, ring->num_hw_submission * 2); if (!ring->fence_drv.fences) return -ENOMEM; ... } Because amdgpu_fence_driver_fini_ring() drops the !ring->fence_drv.initialized check and loops with i <=3D num_fences_mask without checking whether ring->fence_drv.fences is non-NULL, an allocation failure in amdgpu_fence_driver_init_ring() leaves the ring registered in adev->rings[] with fences =3D=3D NULL, causing a NULL pointer dereference at ring->fence_drv.fences[0] during subsequent teardown. In addition, amdgpu_fence_driver_fini_ring() leaves num_fences_mask and ring->sched.ops set after freeing ring->fence_drv.fences, so calling it a second time on the same ring (for instance, when both amdgpu_ring_fini() and amdgpu_fence_driver_sw_fini() run on a ring) will call drm_sched_fini() twice and dereference NULL at ring->fence_drv.fences[0]. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201154232.7832= 0-1-tvrtko.ursulin@igalia.com?part=3D2