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 8516C606A322 for ; Sat, 5 Dec 2026 07:31:49 +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=FGNaVoyP Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AB4F110E0F7; Sat, 5 Dec 2026 07:31:42 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 868E310E0F7 for ; Sat, 5 Dec 2026 07:31:36 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 3CD07453E6; Sat, 5 Dec 2026 07:31:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AB861F0092B; Sat, 5 Dec 2026 07:31:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796455896; bh=9eajC8hNHBeQeLVkyn5+XNtLRz/Zu3sr+oeFXFdzPig=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=FGNaVoyPuNBDITzyQwtz5DKVYtFQupPVPsAOslhKgfDhW1yqe87nSKe+CJDd8/dy4 lrqLZ4vr0k6V2aK10wuymUgXFwuOok71UwSqDPenVLyzs3mHY0OiYy5gOlbKkUa/wG yh0DB81cfw+Ssp3R+irSL6zPrKMMPjexDi3XxmqFFL2rO+0pUby25xottznDc9Ykjk o7+BGhEqvjLMV8i0isZWbc+gjOtjoX6zkTvHUgSyZ99dwbsxvK5mnJohYpwklTwAql XPs6ht48nGIOYxJfxCdtQhP3uz6Qx5qC8oqMINQaeZGQnm6cefemQZ3BU/ErFJDgHd XFCKL7AZYBHmA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 7/7] accel/rocket: Move open files off a core at unbind To: "Arun Iyengar" Cc: dri-devel@lists.freedesktop.org, media-ci@linuxtv.org In-Reply-To: <20261205-rocket-fixes-v3-7-e5032fa408a3@gmail.com> References: <20261205-rocket-fixes-v3-0-e5032fa408a3@gmail.com> <20261205-rocket-fixes-v3-7-e5032fa408a3@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 07:31:35 +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 3 potential issues to consider: - [High] accel/rocket: race in rocket_job_entity_init() exposes unready probing cores - [High] accel/rocket: UAF in drm_sched_entity_kill_jobs_work() on killed entities - [Medium] accel/rocket: rocket_job_reinit_entities() stalls all files under sched_lock -- commit 37e3f5c25d668bb6f35862e014c225d955407863 Author: Arun Iyengar accel/rocket: Move open files off a core at unbind This commit tracks open files on rdev->files and rebuilds their DRM schedul= er entities on core bind and unbind so entities do not stay on a freed run que= ue. It also switches rdev->cores and rdev->sched_lock to drmm_* allocations so files closed after the last core unbinds can still access them. > diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/roc= ket_job.c > index 53f0751d7a1ec..7ad593984d3aa 100644 > --- a/drivers/accel/rocket/rocket_job.c > +++ b/drivers/accel/rocket/rocket_job.c [ ... ] > @@ -520,6 +525,62 @@ static irqreturn_t rocket_job_irq_handler(int irq, v= oid *data) > return IRQ_WAKE_THREAD; > } > =20 > +/* Build the entity on the cores that are up. Called with sched_lock hel= d. */ > +static int rocket_job_entity_init(struct rocket_file_priv *rocket_priv) > +{ > + struct rocket_device *rdev =3D rocket_priv->rdev; > + unsigned int core, n =3D 0; > + int ret; > + > + for (core =3D 0; core < rdev->max_cores; core++) { > + struct rocket_core *c =3D &rdev->cores[core]; > + > + if (!READ_ONCE(c->removing) && drm_sched_wqueue_ready(&c->sched)) > + rocket_priv->scheds[n++] =3D &c->sched; > + } [Severity: High] Can rocket_job_entity_init() expose a probing core before rocket_core_init() has finished setting up runtime PM and hardware state? rocket_open() drops rocket_cores_lock before calling rocket_job_open(), whi= le rocket_probe() runs rocket_core_init() without holding rdev->sched_lock. Because rocket_job_init() calls drm_sched_init() before pm_runtime_enable(), pm_runtime_resume_and_get(), and the VERSION register reads, a concurrently opened file can pick up the half-initialized core: CPU0 (rocket_probe) CPU1 (rocket_open) rocket_core_init() rocket_job_init() drm_sched_init() sched->ready =3D true rocket_job_open() rocket_job_entity_init() adds probing core to scheds rocket_job_run() pm_runtime_resume_and_get() <-- -EACCES pm_runtime_enable() In addition, core->removing and sched->ready are written with plain stores = in rocket_job_init() and drm_sched_init() and read via drm_sched_wqueue_ready() with no shared lock or release/acquire ordering. On weakly ordered ARM64 (RK3588), drm_sched_entity_init() can observe sched->ready before sched->sched_rq is visible, leaving entity->rq NULL or uninitialized and risking a NULL pointer dereference in drm_sched_job_arm(). Marking a core schedulable under rdev->sched_lock only after rocket_core_init() finishes runtime PM and hardware initialization would close both races. [ ... ] > +void rocket_job_reinit_entities(struct rocket_device *rdev) > +{ > + struct rocket_file_priv *rocket_priv; > + > + guard(mutex)(&rdev->sched_lock); > + > + list_for_each_entry(rocket_priv, &rdev->files, node) { > + guard(mutex)(&rocket_priv->entity_lock); > + > + if (rocket_priv->closed) > + continue; > + > + if (rocket_priv->num_scheds) { > + drm_sched_entity_destroy(&rocket_priv->sched_entity); > + rocket_priv->num_scheds =3D 0; > + > + /* Close waits only for last_job_fence: no second job on the NPU */ > + if (rocket_priv->last_job_fence) > + dma_fence_wait(rocket_priv->last_job_fence, false); > + } [Severity: High] Can asynchronous killed-job cleanup in drm_sched_entity_kill_jobs_work() use-after-free rdev->cores and rdev after the last core unbinds and the file closes? When drm_sched_entity_flush() returns early with jobs still queued (for example on SIGKILL in rocket_job_reinit_entities(), or after its 1-second timeout in rocket_job_close()), drm_sched_entity_fini() calls drm_sched_entity_kill(), which schedules drm_sched_entity_kill_jobs_work() = on system_wq. Neither rocket_job_reinit_entities(), rocket_job_close(), nor drm_sched_fini() waits for that work because last_job_fence is only updated in rocket_job_run() and never covers killed queued jobs, and queued jobs do not hold a drm_dev_get() or module reference: CPU0 (unbind / close) kworker (system_wq) rocket_job_close() drm_sched_entity_destroy() drm_sched_entity_flush() /* times out or SIGKILL */ drm_sched_entity_kill() schedule_work(&job->work) dma_fence_wait(last_job_fence) drm_release() -> drm_dev_put() drm_managed_release() kfree(rdev->cores) kfree(rdev) drm_sched_entity_kill_jobs_work() job->sched->ops->free_job(job) <-- use-after-free Separately, if a core bind or partial unbind task receives SIGKILL while rocket_job_reinit_entities() is in wait_event_killable() inside drm_sched_entity_flush(), drm_sched_entity_fini() kills queued jobs belongi= ng to unrelated healthy clients with -ESRCH. > + > + rocket_job_entity_init(rocket_priv); > + } > +} [Severity: Medium] Does holding rdev->sched_lock across drm_sched_entity_destroy() and uninterruptible dma_fence_wait() for every open file cause unnecessary glob= al stalls on core bind and partial unbind? rocket_job_reinit_entities() drains and rebuilds every file's entity sequentially under rdev->sched_lock (and rocket_cores_lock) even on core bind, where no run queue is being freed, and for entities running on healthy cores during a single-core unbind. While rdev->sched_lock is held, concurrent rocket_job_push() callers block on it while already holding their BO dma_resv locks, starving healthy NPU cores and stalling other dma_resv lockers as well as rocket_open() and rocket_job_close(). Calling drm_sched_entity_modify_sched() under rdev->sched_lock would update entity->sched_list in place on bind and for entities on healthy cores during partial unbind, reserving drm_sched_entity_destroy() only for entities assigned to the removing core (or when no cores remain). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205-rocket-fix= es-v3-0-e5032fa408a3@gmail.com?part=3D7