From mboxrd@z Thu Jan 1 00:00:00 1970 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 89359606A31F for ; Sun, 6 Dec 2026 07:41:17 +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=C+awcA0M Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B55D410E009; Sun, 6 Dec 2026 07:41:11 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id E41D310E009 for ; Sun, 6 Dec 2026 07:41:04 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 104F360141; Sun, 6 Dec 2026 07:41:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A07AD1F0092B; Sun, 6 Dec 2026 07:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796542863; bh=mZexuRq6QWF5z77ZkQFVzHZ3xi4dQ9qdB5Kuw1BYNZs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=C+awcA0MV8u13YIdAzBkjLyPNWTixFa9UEDw5MvGdzX+ulkpntGopxj8KZOE2ZNiB bIyQ62akqjHJ66P8vqV/Ud3ND+qzXv0MZO2zBd9A40ML66jU4BdxMUESmjQMTHcKJ2 wXrAbC6bvpbCcPCg7ui14p5+qzuXA5R3AyknYmGOLkPw9okKSpfnvpJm2XB4mGvWag 2N6V2azjuCUegx/SDPrUJHIY1DliQ8uJ0HYlAYFg6ZaPnn+CU0cz4AGymPExydcv72 f1xvCuSwEDu1M6aJqpA+bPzc6CVa0iQXMfn+4/CLMiVNG1FggPWMVhXWoKd8i2lNV5 CwRGgqRiLcd2A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 5/7] accel/rocket: Reset the core at unbind To: "Arun Iyengar" Cc: dri-devel@lists.freedesktop.org, media-ci@linuxtv.org In-Reply-To: <20261206-rocket-fixes-v4-5-75a6279bce98@gmail.com> References: <20261206-rocket-fixes-v4-0-75a6279bce98@gmail.com> <20261206-rocket-fixes-v4-5-75a6279bce98@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 07:41:03 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-11.1 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 2 potential issues to consider: - [Medium] accel/rocket: rocket_job_fini() calls rocket_core_reset() without RPM ref - [Medium] accel/rocket: rocket_job_timedout() NO_HANG races with drm_sched_fini() -- commit 370f6efb177fdda3477d63fbe322d2349ae0184c Author: Arun Iyengar accel/rocket: Reset the core at unbind This commit marks the core as removing during rocket_job_fini(), runs rocket_reset_work() before calling drm_sched_fini(), rejects new jobs in rocket_job_run(), and returns DRM_GPU_SCHED_STAT_NO_HANG from rocket_job_timedout() once removal has started. > diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/roc= ket_job.c > index d83306eaeb864..b44101800f854 100644 > --- a/drivers/accel/rocket/rocket_job.c > +++ b/drivers/accel/rocket/rocket_job.c [ ... ] > @@ -453,6 +456,10 @@ static enum drm_gpu_sched_stat rocket_job_timedout(s= truct drm_sched_job *sched_j > struct rocket_device *rdev =3D job->rdev; > struct rocket_core *core =3D sched_to_core(rdev, sched_job->sched); > =20 > + /* The reset work queued by rocket_job_fini() resets the core */ > + if (READ_ONCE(core->removing)) > + return DRM_GPU_SCHED_STAT_NO_HANG; > + > dev_err(core->dev, "NPU job timed out"); > =20 > atomic_set(&core->reset.pending, 1); [Severity: Medium] Can returning DRM_GPU_SCHED_STAT_NO_HANG here race with drm_sched_fini() and leave sched->work_tdr armed on core->reset.wq after it is destroyed? rocket_job_fini() runs rocket_reset_work(), which calls drm_sched_start(). That restarts submit_wq and re-arms work_tdr while jobs remain on pending_list. If work_tdr fires before work_free_job drains pending_list, drm_sched_job_timedout() calls drm_sched_run_free_queue(), whose pause_submit check is not serialized with drm_sched_wqueue_stop(): CPU0 (reset.wq / work_tdr) CPU1 (rocket_job_fini) drm_sched_job_timedout() rocket_job_timedout() -> DRM_GPU_SCHED_STAT_NO_HANG drm_sched_run_free_queue() !drm_sched_is_stopped() drm_sched_fini() drm_sched_wqueue_stop() pause_submit =3D true cancel_work_sync(work_free_job) queue_work(..., work_free_job) cancel_delayed_work_sync(work_tdr) destroy_workqueue(submit_wq) drm_sched_free_job_work() drm_sched_start_timeout() destroy_workqueue(core->reset.wq) delayed_work_timer_fn() queue_work(core->reset.wq, ...) <-- use-after-free When drm_sched_wqueue_start() queues work_run_job before work_free_job while credit_count is 0, a second job can be on pending_list, so the stray work_free_job re-arms work_tdr after cancel_delayed_work_sync() has already returned. When the timer later fires, it accesses the destroyed core->reset.wq. With .cancel_job added in commit "accel/rocket: Free the jobs left at scheduler teardown", drm_sched_cancel_remaining_jobs() also races with the stray work_free_job and double frees the rocket_job. Skipping drm_sched_start() in rocket_reset() when core->removing is set avoids restarting submit_wq and work_tdr during unbind. [ ... ] > @@ -553,6 +562,14 @@ int rocket_job_init(struct rocket_core *core) > =20 > void rocket_job_fini(struct rocket_core *core) > { > + /* > + * drm_sched_fini() leaves the job on the NPU. Reset the core on the > + * timeout queue, after any running timeout; that cancels pending jobs. > + */ > + WRITE_ONCE(core->removing, true); > + queue_work(core->reset.wq, &core->reset.work); > + flush_work(&core->reset.work); > + > drm_sched_fini(&core->sched); > =20 > cancel_work_sync(&core->reset.work); [Severity: Medium] Does flushing rocket_reset_work() here call rocket_core_reset() without holding a runtime PM reference? In rocket_reset(), pm_runtime_get_if_active() is dropped right after clearing interrupts rather than held across rocket_core_reset(), and rocket_core_reset() still runs when pm_runtime_get_if_active() returns 0 and no job is in flight. On an idle unbind, __device_release_driver() calls pm_runtime_put_sync() before device_remove(), so core->dev is already runtime-suspended or has its autosuspend timer armed when rocket_job_fini() runs. rocket_core_reset() then toggles the AXI/AHB soft resets while the clocks and power domain are off, or concurrently with rockchip_pd_power() running rockchip_pmu_set_idle_request(), risking a PMU idle handshake timeout or power-domain power-off failure. This breaks the runtime PM invariant from commit 36161ff0c00f ("accel/rocket: let the core suspend after a reset"). Holding the pm_runtime_get_if_active() reference across rocket_core_reset() and skipping the reset when already suspended would avoid both. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206-rocket-fix= es-v4-0-75a6279bce98@gmail.com?part=3D5