Re: [PATCH v4 4/4] uacce: ensure safe queue release with state management

From: Zhangfei Gao

Date: Mon Nov 10 2025 - 02:26:35 EST


On Wed, 22 Oct 2025 at 10:12, Chenghai Huang <huangchenghai2@xxxxxxxxxx> wrote:
>
> 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@xxxxxxxxxxxxxxx
> Signed-off-by: Chenghai Huang <huangchenghai2@xxxxxxxxxx>
> Signed-off-by: Yang Shen <shenyang39@xxxxxxxxxx>

Acked-by: Zhangfei Gao <zhangfei.gao@xxxxxxxxxx>

Thanks