From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Tomeu Vizoso <tomeu@tomeuvizoso.net>, Oded Gabbay <ogabbay@kernel.org>
Cc: "Heiko Stuebner" <heiko@sntech.de>,
"Jeff Hugo" <jeff.hugo@oss.qualcomm.com>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Philipp Stanner" <phasta@kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>,
"Matthew Brost" <matthew.brost@intel.com>,
"Igor Paunovic" <royalnet026@gmail.com>,
"Midgy BALON" <midgy971@gmail.com>,
"Jiaxing Hu" <gahing@gahingwoo.com>,
dri-devel@lists.freedesktop.org,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
stable@vger.kernel.org, "Arun Iyengar" <aiyengar1990@gmail.com>
Subject: [PATCH v3 4/7] accel/rocket: Serialise core probe and removal
Date: Sat, 05 Dec 2026 06:51:08 +0000 [thread overview]
Message-ID: <20261205-rocket-fixes-v3-4-e5032fa408a3@gmail.com> (raw)
In-Reply-To: <20261205-rocket-fixes-v3-0-e5032fa408a3@gmail.com>
From: Arun Iyengar <aiyengar1990@gmail.com>
Igor Paunovic posted the slot part in "accel/rocket: keep core slots
stable across unbind and rebind" [1].
rocket_probe() takes slot num_cores, and rocket_remove() leaves the
slot's .dev set. Rebinding any core but the last probed one overwrites
a bound core's slot, and find_core_for_dev() then matches the stale
slot. rocket_open() uses cores[0].dev, which may be unbound. Two
unbinds through sysfs can run at once and race on num_cores.
Take the first free slot, clear it at removal, open on a bound core,
and serialise the three under a mutex.
Link: https://lore.kernel.org/all/20260922080114.44662-5-royalnet026@gmail.com/ [1]
Fixes: ed98261b4168 ("accel/rocket: Add a new driver for Rockchip's NPU")
Cc: stable@vger.kernel.org
Cc: Igor Paunovic <royalnet026@gmail.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/accel/rocket/rocket_drv.c | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
index e45b3c22b31e..bf8d118b932e 100644
--- a/drivers/accel/rocket/rocket_drv.c
+++ b/drivers/accel/rocket/rocket_drv.c
@@ -10,6 +10,7 @@
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/iommu.h>
+#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
@@ -26,6 +27,8 @@
static struct platform_device *drm_dev;
static struct rocket_device *rdev;
static void *rdev_group;
+/* Serialises core probe, removal and the use of a core's .dev in open */
+static DEFINE_MUTEX(rocket_cores_lock);
static void
rocket_vm_destroy(struct kref *kref)
@@ -83,6 +86,7 @@ rocket_open(struct drm_device *dev, struct drm_file *file)
{
struct rocket_device *rdev = to_rocket_device(dev);
struct rocket_file_priv *rocket_priv;
+ unsigned int core;
int ret;
if (!try_module_get(THIS_MODULE))
@@ -95,7 +99,17 @@ rocket_open(struct drm_device *dev, struct drm_file *file)
}
rocket_priv->rdev = rdev;
- rocket_priv->vm = rocket_vm_create(rdev->cores[0].dev);
+ rocket_priv->vm = ERR_PTR(-ENODEV);
+
+ scoped_guard(mutex, &rocket_cores_lock) {
+ for (core = 0; core < rdev->max_cores; core++) {
+ if (rdev->cores[core].dev) {
+ rocket_priv->vm = rocket_vm_create(rdev->cores[core].dev);
+ break;
+ }
+ }
+ }
+
if (IS_ERR(rocket_priv->vm)) {
ret = PTR_ERR(rocket_priv->vm);
goto err_free;
@@ -195,11 +209,14 @@ static int rocket_core_hw_index(struct device *dev)
static int rocket_probe(struct platform_device *pdev)
{
int index = rocket_core_hw_index(&pdev->dev);
+ unsigned int core;
int ret;
if (index < 0)
return index;
+ guard(mutex)(&rocket_cores_lock);
+
if (rdev == NULL) {
/* First core probing, initialize DRM device. */
rdev_group = devres_open_group(&drm_dev->dev, NULL, GFP_KERNEL);
@@ -217,7 +234,12 @@ static int rocket_probe(struct platform_device *pdev)
devres_close_group(&drm_dev->dev, rdev_group);
}
- unsigned int core = rdev->num_cores;
+ /* Cores can unbind and rebind in any order */
+ for (core = 0; core < rdev->max_cores; core++)
+ if (!rdev->cores[core].dev)
+ break;
+ if (WARN_ON(core == rdev->max_cores))
+ return -EBUSY;
dev_set_drvdata(&pdev->dev, rdev);
@@ -229,6 +251,7 @@ static int rocket_probe(struct platform_device *pdev)
ret = rocket_core_init(&rdev->cores[core]);
if (ret) {
+ rdev->cores[core].dev = NULL;
rdev->num_cores--;
if (rdev->num_cores == 0) {
@@ -246,12 +269,16 @@ static int find_core_for_dev(struct device *dev);
static void rocket_remove(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- int core = find_core_for_dev(dev);
+ int core;
+
+ guard(mutex)(&rocket_cores_lock);
+ core = find_core_for_dev(dev);
if (core < 0)
return;
rocket_core_fini(&rdev->cores[core]);
+ rdev->cores[core].dev = NULL;
rdev->num_cores--;
if (rdev->num_cores == 0) {
--
2.55.0
WARNING: multiple messages have this Message-ID (diff)
From: Arun Iyengar <aiyengar1990@gmail.com>
To: Tomeu Vizoso <tomeu@tomeuvizoso.net>, Oded Gabbay <ogabbay@kernel.org>
Cc: "Heiko Stuebner" <heiko@sntech.de>,
"Jeff Hugo" <jeff.hugo@oss.qualcomm.com>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Philipp Stanner" <phasta@kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>,
"Matthew Brost" <matthew.brost@intel.com>,
"Igor Paunovic" <royalnet026@gmail.com>,
"Midgy BALON" <midgy971@gmail.com>,
"Jiaxing Hu" <gahing@gahingwoo.com>,
dri-devel@lists.freedesktop.org,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
stable@vger.kernel.org, "Arun Iyengar" <aiyengar1990@gmail.com>
Subject: [PATCH v3 4/7] accel/rocket: Serialise core probe and removal
Date: Sat, 05 Dec 2026 06:51:08 +0000 [thread overview]
Message-ID: <20261205-rocket-fixes-v3-4-e5032fa408a3@gmail.com> (raw)
In-Reply-To: <20261205-rocket-fixes-v3-0-e5032fa408a3@gmail.com>
Igor Paunovic posted the slot part in "accel/rocket: keep core slots
stable across unbind and rebind" [1].
rocket_probe() takes slot num_cores, and rocket_remove() leaves the
slot's .dev set. Rebinding any core but the last probed one overwrites
a bound core's slot, and find_core_for_dev() then matches the stale
slot. rocket_open() uses cores[0].dev, which may be unbound. Two
unbinds through sysfs can run at once and race on num_cores.
Take the first free slot, clear it at removal, open on a bound core,
and serialise the three under a mutex.
Link: https://lore.kernel.org/all/20260922080114.44662-5-royalnet026@gmail.com/ [1]
Fixes: ed98261b4168 ("accel/rocket: Add a new driver for Rockchip's NPU")
Cc: stable@vger.kernel.org
Cc: Igor Paunovic <royalnet026@gmail.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/accel/rocket/rocket_drv.c | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
index e45b3c22b31e..bf8d118b932e 100644
--- a/drivers/accel/rocket/rocket_drv.c
+++ b/drivers/accel/rocket/rocket_drv.c
@@ -10,6 +10,7 @@
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/iommu.h>
+#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
@@ -26,6 +27,8 @@
static struct platform_device *drm_dev;
static struct rocket_device *rdev;
static void *rdev_group;
+/* Serialises core probe, removal and the use of a core's .dev in open */
+static DEFINE_MUTEX(rocket_cores_lock);
static void
rocket_vm_destroy(struct kref *kref)
@@ -83,6 +86,7 @@ rocket_open(struct drm_device *dev, struct drm_file *file)
{
struct rocket_device *rdev = to_rocket_device(dev);
struct rocket_file_priv *rocket_priv;
+ unsigned int core;
int ret;
if (!try_module_get(THIS_MODULE))
@@ -95,7 +99,17 @@ rocket_open(struct drm_device *dev, struct drm_file *file)
}
rocket_priv->rdev = rdev;
- rocket_priv->vm = rocket_vm_create(rdev->cores[0].dev);
+ rocket_priv->vm = ERR_PTR(-ENODEV);
+
+ scoped_guard(mutex, &rocket_cores_lock) {
+ for (core = 0; core < rdev->max_cores; core++) {
+ if (rdev->cores[core].dev) {
+ rocket_priv->vm = rocket_vm_create(rdev->cores[core].dev);
+ break;
+ }
+ }
+ }
+
if (IS_ERR(rocket_priv->vm)) {
ret = PTR_ERR(rocket_priv->vm);
goto err_free;
@@ -195,11 +209,14 @@ static int rocket_core_hw_index(struct device *dev)
static int rocket_probe(struct platform_device *pdev)
{
int index = rocket_core_hw_index(&pdev->dev);
+ unsigned int core;
int ret;
if (index < 0)
return index;
+ guard(mutex)(&rocket_cores_lock);
+
if (rdev == NULL) {
/* First core probing, initialize DRM device. */
rdev_group = devres_open_group(&drm_dev->dev, NULL, GFP_KERNEL);
@@ -217,7 +234,12 @@ static int rocket_probe(struct platform_device *pdev)
devres_close_group(&drm_dev->dev, rdev_group);
}
- unsigned int core = rdev->num_cores;
+ /* Cores can unbind and rebind in any order */
+ for (core = 0; core < rdev->max_cores; core++)
+ if (!rdev->cores[core].dev)
+ break;
+ if (WARN_ON(core == rdev->max_cores))
+ return -EBUSY;
dev_set_drvdata(&pdev->dev, rdev);
@@ -229,6 +251,7 @@ static int rocket_probe(struct platform_device *pdev)
ret = rocket_core_init(&rdev->cores[core]);
if (ret) {
+ rdev->cores[core].dev = NULL;
rdev->num_cores--;
if (rdev->num_cores == 0) {
@@ -246,12 +269,16 @@ static int find_core_for_dev(struct device *dev);
static void rocket_remove(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- int core = find_core_for_dev(dev);
+ int core;
+
+ guard(mutex)(&rocket_cores_lock);
+ core = find_core_for_dev(dev);
if (core < 0)
return;
rocket_core_fini(&rdev->cores[core]);
+ rdev->cores[core].dev = NULL;
rdev->num_cores--;
if (rdev->num_cores == 0) {
--
2.55.0
WARNING: multiple messages have this Message-ID (diff)
From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Tomeu Vizoso <tomeu@tomeuvizoso.net>, Oded Gabbay <ogabbay@kernel.org>
Cc: "Heiko Stuebner" <heiko@sntech.de>,
"Jeff Hugo" <jeff.hugo@oss.qualcomm.com>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Philipp Stanner" <phasta@kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>,
"Matthew Brost" <matthew.brost@intel.com>,
"Igor Paunovic" <royalnet026@gmail.com>,
"Midgy BALON" <midgy971@gmail.com>,
"Jiaxing Hu" <gahing@gahingwoo.com>,
dri-devel@lists.freedesktop.org,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
stable@vger.kernel.org, "Arun Iyengar" <aiyengar1990@gmail.com>
Subject: [PATCH v3 4/7] accel/rocket: Serialise core probe and removal
Date: Sat, 05 Dec 2026 06:51:08 +0000 [thread overview]
Message-ID: <20261205-rocket-fixes-v3-4-e5032fa408a3@gmail.com> (raw)
In-Reply-To: <20261205-rocket-fixes-v3-0-e5032fa408a3@gmail.com>
From: Arun Iyengar <aiyengar1990@gmail.com>
Igor Paunovic posted the slot part in "accel/rocket: keep core slots
stable across unbind and rebind" [1].
rocket_probe() takes slot num_cores, and rocket_remove() leaves the
slot's .dev set. Rebinding any core but the last probed one overwrites
a bound core's slot, and find_core_for_dev() then matches the stale
slot. rocket_open() uses cores[0].dev, which may be unbound. Two
unbinds through sysfs can run at once and race on num_cores.
Take the first free slot, clear it at removal, open on a bound core,
and serialise the three under a mutex.
Link: https://lore.kernel.org/all/20260922080114.44662-5-royalnet026@gmail.com/ [1]
Fixes: ed98261b4168 ("accel/rocket: Add a new driver for Rockchip's NPU")
Cc: stable@vger.kernel.org
Cc: Igor Paunovic <royalnet026@gmail.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/accel/rocket/rocket_drv.c | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/drivers/accel/rocket/rocket_drv.c b/drivers/accel/rocket/rocket_drv.c
index e45b3c22b31e..bf8d118b932e 100644
--- a/drivers/accel/rocket/rocket_drv.c
+++ b/drivers/accel/rocket/rocket_drv.c
@@ -10,6 +10,7 @@
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/iommu.h>
+#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
@@ -26,6 +27,8 @@
static struct platform_device *drm_dev;
static struct rocket_device *rdev;
static void *rdev_group;
+/* Serialises core probe, removal and the use of a core's .dev in open */
+static DEFINE_MUTEX(rocket_cores_lock);
static void
rocket_vm_destroy(struct kref *kref)
@@ -83,6 +86,7 @@ rocket_open(struct drm_device *dev, struct drm_file *file)
{
struct rocket_device *rdev = to_rocket_device(dev);
struct rocket_file_priv *rocket_priv;
+ unsigned int core;
int ret;
if (!try_module_get(THIS_MODULE))
@@ -95,7 +99,17 @@ rocket_open(struct drm_device *dev, struct drm_file *file)
}
rocket_priv->rdev = rdev;
- rocket_priv->vm = rocket_vm_create(rdev->cores[0].dev);
+ rocket_priv->vm = ERR_PTR(-ENODEV);
+
+ scoped_guard(mutex, &rocket_cores_lock) {
+ for (core = 0; core < rdev->max_cores; core++) {
+ if (rdev->cores[core].dev) {
+ rocket_priv->vm = rocket_vm_create(rdev->cores[core].dev);
+ break;
+ }
+ }
+ }
+
if (IS_ERR(rocket_priv->vm)) {
ret = PTR_ERR(rocket_priv->vm);
goto err_free;
@@ -195,11 +209,14 @@ static int rocket_core_hw_index(struct device *dev)
static int rocket_probe(struct platform_device *pdev)
{
int index = rocket_core_hw_index(&pdev->dev);
+ unsigned int core;
int ret;
if (index < 0)
return index;
+ guard(mutex)(&rocket_cores_lock);
+
if (rdev == NULL) {
/* First core probing, initialize DRM device. */
rdev_group = devres_open_group(&drm_dev->dev, NULL, GFP_KERNEL);
@@ -217,7 +234,12 @@ static int rocket_probe(struct platform_device *pdev)
devres_close_group(&drm_dev->dev, rdev_group);
}
- unsigned int core = rdev->num_cores;
+ /* Cores can unbind and rebind in any order */
+ for (core = 0; core < rdev->max_cores; core++)
+ if (!rdev->cores[core].dev)
+ break;
+ if (WARN_ON(core == rdev->max_cores))
+ return -EBUSY;
dev_set_drvdata(&pdev->dev, rdev);
@@ -229,6 +251,7 @@ static int rocket_probe(struct platform_device *pdev)
ret = rocket_core_init(&rdev->cores[core]);
if (ret) {
+ rdev->cores[core].dev = NULL;
rdev->num_cores--;
if (rdev->num_cores == 0) {
@@ -246,12 +269,16 @@ static int find_core_for_dev(struct device *dev);
static void rocket_remove(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- int core = find_core_for_dev(dev);
+ int core;
+
+ guard(mutex)(&rocket_cores_lock);
+ core = find_core_for_dev(dev);
if (core < 0)
return;
rocket_core_fini(&rdev->cores[core]);
+ rdev->cores[core].dev = NULL;
rdev->num_cores--;
if (rdev->num_cores == 0) {
--
2.55.0
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
next prev parent reply other threads:[~2026-12-05 6:51 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 6:51 [PATCH v3 0/7] accel/rocket: Fix teardown with a job on the NPU Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar
2026-12-05 6:51 ` [PATCH v3 1/7] accel/rocket: Wait for in-flight jobs before releasing the file's BOs Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar
2026-12-05 6:51 ` [PATCH v3 2/7] accel/rocket: Reset the core before detaching its IOMMU Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar
2026-12-05 6:51 ` [PATCH v3 3/7] accel/rocket: Stop the scheduler before releasing the IOMMU group Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar
2026-12-05 6:51 ` Arun Iyengar via B4 Relay [this message]
2026-12-05 6:51 ` [PATCH v3 4/7] accel/rocket: Serialise core probe and removal Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar
2026-12-05 7:16 ` sashiko-bot
2026-12-05 6:51 ` [PATCH v3 5/7] accel/rocket: Reset the core at unbind Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar
2026-12-05 6:51 ` [PATCH v3 6/7] accel/rocket: Free the jobs left at scheduler teardown Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar
2026-12-05 6:51 ` [PATCH v3 7/7] accel/rocket: Move open files off a core at unbind Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar via B4 Relay
2026-12-05 6:51 ` Arun Iyengar
2026-12-05 7:31 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205-rocket-fixes-v3-4-e5032fa408a3@gmail.com \
--to=devnull+aiyengar1990.gmail.com@kernel.org \
--cc=aiyengar1990@gmail.com \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gahing@gahingwoo.com \
--cc=heiko@sntech.de \
--cc=jeff.hugo@oss.qualcomm.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=matthew.brost@intel.com \
--cc=midgy971@gmail.com \
--cc=ogabbay@kernel.org \
--cc=phasta@kernel.org \
--cc=royalnet026@gmail.com \
--cc=stable@vger.kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tomeu@tomeuvizoso.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.