* [PATCH v6 0/4] uacce: driver fixes for memory leaks and state management
@ 2025-12-02 6:12 Chenghai Huang
2025-12-02 6:12 ` [PATCH v6 1/4] uacce: fix cdev handling in the cleanup path Chenghai Huang
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Chenghai Huang @ 2025-12-02 6:12 UTC (permalink / raw)
To: gregkh, zhangfei.gao, wangzhou1
Cc: linux-kernel, linux-crypto, fanghao11, shenyang39, liulongfang,
qianweili, linwenkai6
This patch series addresses several issues in the uacce:
1.Fix cdev handling in the cleanup path.
2.Fix sysfs file creation conditions.
3.Add error reporting for unsupported mremap operations.
4.Ensuring safe queue release with proper state management.
---
Changes in v6:
- In patch 1, if cdev_device_add() fails, it will automatically free the cdev, however,
we need to set uacce->cdev to NULL to prevent cdev_device_del() from being called.
- Link to v5: https://lore.kernel.org/all/20251111093536.3729-1-huangchenghai2@huawei.com/
Changes in v5:
- There is no memory leak issue when cdev_device_add fails, but it is necessary
to check a flag to avoid calling cdev_device_del during abnormal exit.
- Link to v4: https://lore.kernel.org/all/20251022021149.1771168-1-huangchenghai2@huawei.com/
Changes in v4:
- Revert the interception of sysfs creation for isolate_strategy.
- Link to v3: https://lore.kernel.org/all/20251021135003.786588-1-huangchenghai2@huawei.com/
Changes in v3:
- Move the checks for the 'isolate_strategy_show' and
'isolate_strategy_store' functions to their respective call sites.
- Use kobject_put to release the cdev memory instead of modifying
cdev to be a static structure member.
- Link to v2: https://lore.kernel.org/all/20250916144811.1799687-1-huangchenghai2@huawei.com/
Changes in v2:
- Use cdev_init to allocate cdev memory to ensure that memory leaks
are avoided.
- Supplement the reason for intercepting the remapping operation.
- Add "cc: stable@vger.kernel.org" to paths with fixed.
- Link to v1: https://lore.kernel.org/all/20250822103904.3776304-1-huangchenghai2@huawei.com/
Chenghai Huang (2):
uacce: fix isolate sysfs check condition
uacce: ensure safe queue release with state management
Wenkai Lin (1):
uacce: fix cdev handling in the cleanup path
Yang Shen (1):
uacce: implement mremap in uacce_vm_ops to return -EPERM
drivers/misc/uacce/uacce.c | 48 +++++++++++++++++++++++++++++++-------
1 file changed, 40 insertions(+), 8 deletions(-)
--
2.33.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v6 1/4] uacce: fix cdev handling in the cleanup path
2025-12-02 6:12 [PATCH v6 0/4] uacce: driver fixes for memory leaks and state management Chenghai Huang
@ 2025-12-02 6:12 ` Chenghai Huang
2025-12-02 7:49 ` Zhangfei Gao
2025-12-02 6:12 ` [PATCH v6 2/4] uacce: fix isolate sysfs check condition Chenghai Huang
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Chenghai Huang @ 2025-12-02 6:12 UTC (permalink / raw)
To: gregkh, zhangfei.gao, wangzhou1
Cc: linux-kernel, linux-crypto, fanghao11, shenyang39, liulongfang,
qianweili, linwenkai6
From: Wenkai Lin <linwenkai6@hisilicon.com>
When cdev_device_add fails, it internally releases the cdev memory,
and if cdev_device_del is then executed, it will cause a hang error.
To fix it, we check the return value of cdev_device_add() and clear
uacce->cdev to avoid calling cdev_device_del in the uacce_remove.
Fixes: 015d239ac014 ("uacce: add uacce driver")
Cc: stable@vger.kernel.org
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
drivers/misc/uacce/uacce.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c
index 42e7d2a2a90c..43d215fb8c73 100644
--- a/drivers/misc/uacce/uacce.c
+++ b/drivers/misc/uacce/uacce.c
@@ -519,6 +519,8 @@ EXPORT_SYMBOL_GPL(uacce_alloc);
*/
int uacce_register(struct uacce_device *uacce)
{
+ int ret;
+
if (!uacce)
return -ENODEV;
@@ -529,7 +531,11 @@ int uacce_register(struct uacce_device *uacce)
uacce->cdev->ops = &uacce_fops;
uacce->cdev->owner = THIS_MODULE;
- return cdev_device_add(uacce->cdev, &uacce->dev);
+ ret = cdev_device_add(uacce->cdev, &uacce->dev);
+ if (ret)
+ uacce->cdev = NULL;
+
+ return ret;
}
EXPORT_SYMBOL_GPL(uacce_register);
--
2.33.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v6 2/4] uacce: fix isolate sysfs check condition
2025-12-02 6:12 [PATCH v6 0/4] uacce: driver fixes for memory leaks and state management Chenghai Huang
2025-12-02 6:12 ` [PATCH v6 1/4] uacce: fix cdev handling in the cleanup path Chenghai Huang
@ 2025-12-02 6:12 ` Chenghai Huang
2025-12-02 6:12 ` [PATCH v6 3/4] uacce: implement mremap in uacce_vm_ops to return -EPERM Chenghai Huang
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Chenghai Huang @ 2025-12-02 6:12 UTC (permalink / raw)
To: gregkh, zhangfei.gao, wangzhou1
Cc: linux-kernel, linux-crypto, fanghao11, shenyang39, liulongfang,
qianweili, linwenkai6
uacce supports the device isolation feature. If the driver
implements the isolate_err_threshold_read and
isolate_err_threshold_write callback functions, uacce will create
sysfs files now. Users can read and configure the isolation policy
through sysfs. Currently, sysfs files are created as long as either
isolate_err_threshold_read or isolate_err_threshold_write callback
functions are present.
However, accessing a non-existent callback function may cause the
system to crash. Therefore, intercept the creation of sysfs if
neither read nor write exists; create sysfs if either is supported,
but intercept unsupported operations at the call site.
Fixes: e3e289fbc0b5 ("uacce: supports device isolation feature")
Cc: stable@vger.kernel.org
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Acked-by: Zhangfei Gao <zhangfei.gao@linaro.org>
---
drivers/misc/uacce/uacce.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c
index 43d215fb8c73..b0b3c1562d52 100644
--- a/drivers/misc/uacce/uacce.c
+++ b/drivers/misc/uacce/uacce.c
@@ -382,6 +382,9 @@ static ssize_t isolate_strategy_show(struct device *dev, struct device_attribute
struct uacce_device *uacce = to_uacce_device(dev);
u32 val;
+ if (!uacce->ops->isolate_err_threshold_read)
+ return -ENOENT;
+
val = uacce->ops->isolate_err_threshold_read(uacce);
return sysfs_emit(buf, "%u\n", val);
@@ -394,6 +397,9 @@ static ssize_t isolate_strategy_store(struct device *dev, struct device_attribut
unsigned long val;
int ret;
+ if (!uacce->ops->isolate_err_threshold_write)
+ return -ENOENT;
+
if (kstrtoul(buf, 0, &val) < 0)
return -EINVAL;
--
2.33.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v6 3/4] uacce: implement mremap in uacce_vm_ops to return -EPERM
2025-12-02 6:12 [PATCH v6 0/4] uacce: driver fixes for memory leaks and state management Chenghai Huang
2025-12-02 6:12 ` [PATCH v6 1/4] uacce: fix cdev handling in the cleanup path Chenghai Huang
2025-12-02 6:12 ` [PATCH v6 2/4] uacce: fix isolate sysfs check condition Chenghai Huang
@ 2025-12-02 6:12 ` Chenghai Huang
2025-12-02 6:12 ` [PATCH v6 4/4] uacce: ensure safe queue release with state management Chenghai Huang
2026-01-06 2:38 ` [PATCH v6 0/4] uacce: driver fixes for memory leaks and " huangchenghai
4 siblings, 0 replies; 8+ messages in thread
From: Chenghai Huang @ 2025-12-02 6:12 UTC (permalink / raw)
To: gregkh, zhangfei.gao, wangzhou1
Cc: linux-kernel, linux-crypto, fanghao11, shenyang39, liulongfang,
qianweili, linwenkai6
From: Yang Shen <shenyang39@huawei.com>
The current uacce_vm_ops does not support the mremap operation of
vm_operations_struct. Implement .mremap to return -EPERM to remind
users.
The reason we need to explicitly disable mremap is that when the
driver does not implement .mremap, it uses the default mremap
method. This could lead to a risk scenario:
An application might first mmap address p1, then mremap to p2,
followed by munmap(p1), and finally munmap(p2). Since the default
mremap copies the original vma's vm_private_data (i.e., q) to the
new vma, both munmap operations would trigger vma_close, causing
q->qfr to be freed twice(qfr will be set to null here, so repeated
release is ok).
Fixes: 015d239ac014 ("uacce: add uacce driver")
Cc: stable@vger.kernel.org
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Acked-by: Zhangfei Gao <zhangfei.gao@linaro.org>
---
drivers/misc/uacce/uacce.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c
index b0b3c1562d52..c061c6fa1c5e 100644
--- a/drivers/misc/uacce/uacce.c
+++ b/drivers/misc/uacce/uacce.c
@@ -214,8 +214,14 @@ static void uacce_vma_close(struct vm_area_struct *vma)
}
}
+static int uacce_vma_mremap(struct vm_area_struct *area)
+{
+ return -EPERM;
+}
+
static const struct vm_operations_struct uacce_vm_ops = {
.close = uacce_vma_close,
+ .mremap = uacce_vma_mremap,
};
static int uacce_fops_mmap(struct file *filep, struct vm_area_struct *vma)
--
2.33.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v6 4/4] uacce: ensure safe queue release with state management
2025-12-02 6:12 [PATCH v6 0/4] uacce: driver fixes for memory leaks and state management Chenghai Huang
` (2 preceding siblings ...)
2025-12-02 6:12 ` [PATCH v6 3/4] uacce: implement mremap in uacce_vm_ops to return -EPERM Chenghai Huang
@ 2025-12-02 6:12 ` Chenghai Huang
2026-01-06 2:38 ` [PATCH v6 0/4] uacce: driver fixes for memory leaks and " huangchenghai
4 siblings, 0 replies; 8+ messages in thread
From: Chenghai Huang @ 2025-12-02 6:12 UTC (permalink / raw)
To: gregkh, zhangfei.gao, wangzhou1
Cc: linux-kernel, linux-crypto, fanghao11, shenyang39, liulongfang,
qianweili, linwenkai6
Directly calling `put_queue` carries risks since it cannot
guarantee that resources of `uacce_queue` have been fully released
beforehand. So adding a `stop_queue` operation for the
UACCE_CMD_PUT_Q command and leaving the `put_queue` operation to
the final resource release ensures safety.
Queue states are defined as follows:
- UACCE_Q_ZOMBIE: Initial state
- UACCE_Q_INIT: After opening `uacce`
- UACCE_Q_STARTED: After `start` is issued via `ioctl`
When executing `poweroff -f` in virt while accelerator are still
working, `uacce_fops_release` and `uacce_remove` may execute
concurrently. This can cause `uacce_put_queue` within
`uacce_fops_release` to access a NULL `ops` pointer. Therefore, add
state checks to prevent accessing freed pointers.
Fixes: 015d239ac014 ("uacce: add uacce driver")
Cc: stable@vger.kernel.org
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: Yang Shen <shenyang39@huawei.com>
Acked-by: Zhangfei Gao <zhangfei.gao@linaro.org>
---
drivers/misc/uacce/uacce.c | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c
index c061c6fa1c5e..6d71355528d3 100644
--- a/drivers/misc/uacce/uacce.c
+++ b/drivers/misc/uacce/uacce.c
@@ -40,20 +40,34 @@ static int uacce_start_queue(struct uacce_queue *q)
return 0;
}
-static int uacce_put_queue(struct uacce_queue *q)
+static int uacce_stop_queue(struct uacce_queue *q)
{
struct uacce_device *uacce = q->uacce;
- if ((q->state == UACCE_Q_STARTED) && uacce->ops->stop_queue)
+ if (q->state != UACCE_Q_STARTED)
+ return 0;
+
+ if (uacce->ops->stop_queue)
uacce->ops->stop_queue(q);
- if ((q->state == UACCE_Q_INIT || q->state == UACCE_Q_STARTED) &&
- uacce->ops->put_queue)
+ q->state = UACCE_Q_INIT;
+
+ return 0;
+}
+
+static void uacce_put_queue(struct uacce_queue *q)
+{
+ struct uacce_device *uacce = q->uacce;
+
+ uacce_stop_queue(q);
+
+ if (q->state != UACCE_Q_INIT)
+ return;
+
+ if (uacce->ops->put_queue)
uacce->ops->put_queue(q);
q->state = UACCE_Q_ZOMBIE;
-
- return 0;
}
static long uacce_fops_unl_ioctl(struct file *filep,
@@ -80,7 +94,7 @@ static long uacce_fops_unl_ioctl(struct file *filep,
ret = uacce_start_queue(q);
break;
case UACCE_CMD_PUT_Q:
- ret = uacce_put_queue(q);
+ ret = uacce_stop_queue(q);
break;
default:
if (uacce->ops->ioctl)
--
2.33.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v6 1/4] uacce: fix cdev handling in the cleanup path
2025-12-02 6:12 ` [PATCH v6 1/4] uacce: fix cdev handling in the cleanup path Chenghai Huang
@ 2025-12-02 7:49 ` Zhangfei Gao
0 siblings, 0 replies; 8+ messages in thread
From: Zhangfei Gao @ 2025-12-02 7:49 UTC (permalink / raw)
To: Chenghai Huang
Cc: gregkh, wangzhou1, linux-kernel, linux-crypto, fanghao11,
shenyang39, liulongfang, qianweili, linwenkai6
On Tue, 2 Dec 2025 at 14:13, Chenghai Huang <huangchenghai2@huawei.com> wrote:
>
> From: Wenkai Lin <linwenkai6@hisilicon.com>
>
> When cdev_device_add fails, it internally releases the cdev memory,
> and if cdev_device_del is then executed, it will cause a hang error.
> To fix it, we check the return value of cdev_device_add() and clear
> uacce->cdev to avoid calling cdev_device_del in the uacce_remove.
>
> Fixes: 015d239ac014 ("uacce: add uacce driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
> Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Acked-by: Zhangfei Gao <zhangfei.gao@linaro.org>
Thanks
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v6 0/4] uacce: driver fixes for memory leaks and state management
2025-12-02 6:12 [PATCH v6 0/4] uacce: driver fixes for memory leaks and state management Chenghai Huang
` (3 preceding siblings ...)
2025-12-02 6:12 ` [PATCH v6 4/4] uacce: ensure safe queue release with state management Chenghai Huang
@ 2026-01-06 2:38 ` huangchenghai
2026-01-16 15:43 ` Greg KH
4 siblings, 1 reply; 8+ messages in thread
From: huangchenghai @ 2026-01-06 2:38 UTC (permalink / raw)
To: gregkh, zhangfei.gao, wangzhou1
Cc: linux-kernel, linux-crypto, fanghao11, shenyang39, liulongfang,
qianweili, linwenkai6
Kindly ping for this fix.
Cheers,
Chenghai
在 2025/12/2 14:12, Chenghai Huang 写道:
> This patch series addresses several issues in the uacce:
> 1.Fix cdev handling in the cleanup path.
> 2.Fix sysfs file creation conditions.
> 3.Add error reporting for unsupported mremap operations.
> 4.Ensuring safe queue release with proper state management.
>
> ---
> Changes in v6:
> - In patch 1, if cdev_device_add() fails, it will automatically free the cdev, however,
> we need to set uacce->cdev to NULL to prevent cdev_device_del() from being called.
> - Link to v5: https://lore.kernel.org/all/20251111093536.3729-1-huangchenghai2@huawei.com/
>
> Changes in v5:
> - There is no memory leak issue when cdev_device_add fails, but it is necessary
> to check a flag to avoid calling cdev_device_del during abnormal exit.
> - Link to v4: https://lore.kernel.org/all/20251022021149.1771168-1-huangchenghai2@huawei.com/
>
> Changes in v4:
> - Revert the interception of sysfs creation for isolate_strategy.
> - Link to v3: https://lore.kernel.org/all/20251021135003.786588-1-huangchenghai2@huawei.com/
>
> Changes in v3:
> - Move the checks for the 'isolate_strategy_show' and
> 'isolate_strategy_store' functions to their respective call sites.
> - Use kobject_put to release the cdev memory instead of modifying
> cdev to be a static structure member.
> - Link to v2: https://lore.kernel.org/all/20250916144811.1799687-1-huangchenghai2@huawei.com/
>
> Changes in v2:
> - Use cdev_init to allocate cdev memory to ensure that memory leaks
> are avoided.
> - Supplement the reason for intercepting the remapping operation.
> - Add "cc: stable@vger.kernel.org" to paths with fixed.
> - Link to v1: https://lore.kernel.org/all/20250822103904.3776304-1-huangchenghai2@huawei.com/
>
> Chenghai Huang (2):
> uacce: fix isolate sysfs check condition
> uacce: ensure safe queue release with state management
>
> Wenkai Lin (1):
> uacce: fix cdev handling in the cleanup path
>
> Yang Shen (1):
> uacce: implement mremap in uacce_vm_ops to return -EPERM
>
> drivers/misc/uacce/uacce.c | 48 +++++++++++++++++++++++++++++++-------
> 1 file changed, 40 insertions(+), 8 deletions(-)
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v6 0/4] uacce: driver fixes for memory leaks and state management
2026-01-06 2:38 ` [PATCH v6 0/4] uacce: driver fixes for memory leaks and " huangchenghai
@ 2026-01-16 15:43 ` Greg KH
0 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2026-01-16 15:43 UTC (permalink / raw)
To: huangchenghai
Cc: zhangfei.gao, wangzhou1, linux-kernel, linux-crypto, fanghao11,
shenyang39, liulongfang, qianweili, linwenkai6
On Tue, Jan 06, 2026 at 10:38:46AM +0800, huangchenghai wrote:
> Kindly ping for this fix.
>
Sorry for the delay, looks good, now queued up!
greg k-h
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-01-16 15:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-02 6:12 [PATCH v6 0/4] uacce: driver fixes for memory leaks and state management Chenghai Huang
2025-12-02 6:12 ` [PATCH v6 1/4] uacce: fix cdev handling in the cleanup path Chenghai Huang
2025-12-02 7:49 ` Zhangfei Gao
2025-12-02 6:12 ` [PATCH v6 2/4] uacce: fix isolate sysfs check condition Chenghai Huang
2025-12-02 6:12 ` [PATCH v6 3/4] uacce: implement mremap in uacce_vm_ops to return -EPERM Chenghai Huang
2025-12-02 6:12 ` [PATCH v6 4/4] uacce: ensure safe queue release with state management Chenghai Huang
2026-01-06 2:38 ` [PATCH v6 0/4] uacce: driver fixes for memory leaks and " huangchenghai
2026-01-16 15:43 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox