From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796453468; b=DvIgHNkdLHpEfcADepVstFqf/QDyrC0LjeknPaNPCRj3yBJ+z93dZUJ/QRRA8cZXZ3iP XS0AsFvYn69Ix/mMIxZhoSPt8twMaq+91625QWDWRsPEuzf+h1xQspjE/FK38Dh6CGkXE Kdu4CP5sszTsOXc/9czdIKhszZxxj8a7zTYZ6DddFGrln66AlerMfei02B8rk+EY55PC0 F1YDMrVUB5QghvtU9dLKQg9cMspDsMPQJ7o4BvCKJ9txJ0USMO3fOOkoc6ZyUjMEeSkRa xL6ieMdTxG49YyZJ/0W1OqVTbKg2yIiVY4VRRcW+EbERbsayUpG2usEQcQ6z81bIHSA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796453468; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=rJumSuMMY0syzt5or6Ovb1UPaUp1EAggpVUMpcanAwc=; b=IK+UVcIIRPIhSLUGohBKsXcg2C6+Qkixlr7KgG22AxdVk01iouwpkBf2uvNax2F4GgSY DDnoljQePZvsBadlSIbBM5rRrdiEXxV9gjQr8/oJUPQHA/JC4r9/TH9uilnbOeKoKMNsg 5vMqpJNlyWc9VED3Ye/w4cvU6l0/3BPmrXJPFHlb4L7g8Wt9eombaN7znd0Q0+jLL7sl+ 8UR2fUc115ci9FVELK+VfoEw13IX3XzjDHOKe+Fbc3OJnBNOodL6mdEd9iDQXH5R3Sdcg ipQ0VABF6ak23iSmcsRIFydIkQ8aJ0KPfO5rZUnur31+h09s4r8PkxNEAskDk4wLrhg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fvdppGR6; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87B3F606A68D; Sat, 5 Dec 2026 06:51:08 +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=fvdppGR6 Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796453468; b=YdkAqieRhCZSSVc0Sfccw31bC0i/phMFFf+9N26m8HadMz0FKji5zsM21E0TfrSBW1Q9 tHaniA6nfEpWu2N0Gh4+hJhonWj9JH9v/ytUEs8JzvXcAMrg8/s30lqo5TqV969ep7V3j kC6GVox91jiDAmfL4YCtsbqZVsYncRYGEiBIRpSj0K3WIanp2BEWRlA2a6SPdGeqrAxBd 6cDzsYgJ3OZefA/zIn8xrjTgPzUhK8qabO8gVzcN8FPfHnoc6JVqeCn7ILxZqBf9Cnu2r TxJ+N6ncSDrBgINyk8czbnUl+ji5BNdJXdaQANxaimRk6trwslJ01tPdviLxtx6Xb4w== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796453468; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=rJumSuMMY0syzt5or6Ovb1UPaUp1EAggpVUMpcanAwc=; b=J2QPRJcxtXHCz+CSQfIDYUPt0k3hnQMpDRBPDit75jcuCw/qAg2rRSOfYJpMSLG32BPD vDZb/vT0KYaEj1+Jw/457x6xSHwWbO7wLMbxyQwYtcDnV8fYywB4Vh60GB2x4Ibnnmhaf WwPWs57GH1nyWiZiCH+LRxbwuXyK4J0Nql3JOXNR0//uVkKJhDtMVEnm0MTL95M4iyQ1M dq8H36+Ti18y2uK/QG57RgSBQkK5rfcykjdpUOjwJe249/EKRVhqYpj+Wfk7mo20YaS6V eAPBrU3gPEjCZTAurBC3l+FC2Fa46DEp9Myuqn/ljtjUOHUda7diPUWrvvhgVfkULfQ== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (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.kernel.org (Postfix) with ESMTPS id E8ADB1F00A12; Sat, 5 Dec 2026 06:51:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796453468; bh=rJumSuMMY0syzt5or6Ovb1UPaUp1EAggpVUMpcanAwc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=fvdppGR6sgqrrIC6gzI3vZoo9KE5pCkaMmgUN/9uuGMr6RbkPMm7up9tisGcc8o6D J1QL/qMSLIfyKkvQdT79mzqdH83H1jzHrgFUaPgq3r2Qe7+G0ioFgs/M/TfLIbfuFK umWDfSrnIsg1Ph42bd0dJlFF3SN+04kCDGJKiUoIvITej+MeQWQioQJt5vpuPUIcAI ChjAWM9t1Tx2q/FF+38DI92vqeakSjThZiA9dXtaTTWDSZjG+CVZ4WfKCjQf5oRqZF Wc69j3F3KGeJmyhExAKZJj+/iMQAx3B0qy+l2PXSUExYOIGKXJkAxi80iXPzwMgd/S OaIvuFZVWDoGw== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 741D4501D9; Sat, 5 Dec 2026 06:51:06 +0000 (UTC) From: Arun Iyengar via B4 Relay Date: Sat, 05 Dec 2026 06:51:08 +0000 Subject: [PATCH v3 4/7] accel/rocket: Serialise core probe and removal X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261205-rocket-fixes-v3-4-e5032fa408a3@gmail.com> References: <20261205-rocket-fixes-v3-0-e5032fa408a3@gmail.com> In-Reply-To: <20261205-rocket-fixes-v3-0-e5032fa408a3@gmail.com> To: Tomeu Vizoso , Oded Gabbay Cc: Heiko Stuebner , Jeff Hugo , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Philipp Stanner , Danilo Krummrich , Matthew Brost , Igor Paunovic , Midgy BALON , Jiaxing Hu , 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 X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796453465; l=4067; i=aiyengar1990@gmail.com; s=20261110; h=from:subject:message-id; bh=Dz0yfsou6PyN5/7iDpu87UlwZy/uUZ/e89dP7/PCwZE=; b=i+BgF1dLPUr+dXPqWrJhR7B6BppggfXYVxFCy+R45MdyG+uJq3xwjhBxIcq30hVSz5kg5qRkt A34CGXMK3QXDgVNartdld7pSYis8+42jAr3LiA38cfGdcHHYvpHrIqQ X-Developer-Key: i=aiyengar1990@gmail.com; a=ed25519; pk=zXpRgUTrhaFe6jLyPqbBy3ccfkj04w0g2690Wv3mg+0= X-Endpoint-Received: by B4 Relay for aiyengar1990@gmail.com/20261110 with auth_id=1480 X-Original-From: Arun Iyengar Reply-To: aiyengar1990@gmail.com Content-Transfer-Encoding: 7bit From: Arun Iyengar 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 Signed-off-by: Arun Iyengar --- 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 #include #include +#include #include #include #include @@ -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