From nobody Fri Oct 3 23:02:07 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A7272F618C; Fri, 22 Aug 2025 10:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755859151; cv=none; b=ewZZb9E/PpQl3uhPjZXbF/pIdkfI6P4ARFZ1SXMbuTHRV7BTeRMJHyUZbHWywoXjoJAx2479Bnt6UFHKYcZksTaJTCKodwnPtybyNDujPC0YzFVyuJZYAu3hF+5xmIwgKDSJWbLR8+Re43EmSqEUblKYUs2rD0SlKKmJO9uy8xI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755859151; c=relaxed/simple; bh=GnK95vZF7a4CQYiNAcMKdQH4omH9tGqgBncXs86DROk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W2gXfG3++APzsYh9lpNND6I5EuRZV6BLGAgXNoDHM8xeI627ITNIGJDZef2jTWTd9zmKOuqHSgu/c1YgnzdPXcBZYSZQVc98eaMaJj6oKI+Nh4zXX2IyFCIm/j7KIerk1i8I2UwiyXkcuL7PL2DVbEDcUMbmCpW7RRCMvBGaPbE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4c7c6h15T6z1R921; Fri, 22 Aug 2025 18:36:12 +0800 (CST) Received: from dggemv712-chm.china.huawei.com (unknown [10.1.198.32]) by mail.maildlp.com (Postfix) with ESMTPS id 2BB52140109; Fri, 22 Aug 2025 18:39:06 +0800 (CST) Received: from kwepemq200001.china.huawei.com (7.202.195.16) by dggemv712-chm.china.huawei.com (10.1.198.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 18:39:05 +0800 Received: from localhost.huawei.com (10.90.31.46) by kwepemq200001.china.huawei.com (7.202.195.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 18:39:05 +0800 From: Chenghai Huang To: , , CC: , , , , , , , Subject: [PATCH 1/4] uacce: fix for cdev memory leak Date: Fri, 22 Aug 2025 18:39:01 +0800 Message-ID: <20250822103904.3776304-2-huangchenghai2@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250822103904.3776304-1-huangchenghai2@huawei.com> References: <20250822103904.3776304-1-huangchenghai2@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemq200001.china.huawei.com (7.202.195.16) Content-Type: text/plain; charset="utf-8" From: Wenkai Lin If adding uacce cdev to the system fails, it could be due to two reasons: either the device's devt exists when the failure occurs, or the device_add operation fails. In the latter case, cdev_del will be executed, but in the former case, it will not, leading to a resource leak. Therefore, it is necessary to perform the cdev_del action during abnormal exit. Fixes: 015d239ac014 ("uacce: add uacce driver") Signed-off-by: Wenkai Lin Signed-off-by: Chenghai Huang --- drivers/misc/uacce/uacce.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c index 42e7d2a2a90c..3604f722ed60 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; =20 @@ -529,7 +531,14 @@ int uacce_register(struct uacce_device *uacce) uacce->cdev->ops =3D &uacce_fops; uacce->cdev->owner =3D THIS_MODULE; =20 - return cdev_device_add(uacce->cdev, &uacce->dev); + ret =3D cdev_device_add(uacce->cdev, &uacce->dev); + if (ret) { + cdev_del(uacce->cdev); + uacce->cdev =3D NULL; + return ret; + } + + return 0; } EXPORT_SYMBOL_GPL(uacce_register); =20 --=20 2.33.0 From nobody Fri Oct 3 23:02:07 2025 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACAA92F6171; Fri, 22 Aug 2025 10:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755859151; cv=none; b=m1GhqArN36BqE/MrUfVC3RuimMTXPE+U8nAwR7AcAhRtxS6p09gQCnfZD2qq7q6Bz5DBSMu8RU/HA0/HI2Pg9TxLhjjm/RDsvR/rKXd6nc+MoH76G5MaHkRqHlijQD4cHIT4h/kIX7g316WlvXbqMYohiqTO+MnR/AO34jkDnow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755859151; c=relaxed/simple; bh=IiJu0dAgX0GTEfaCVdzfvEOkWBNEAnnQwElMQNlxcfE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WthnmCW6b6GHDsjocYYawYq4u2RTDtTT0X1aRUG+QWg08lob+8/CC4/amosNs0O/uPPa7p+aULN7qwzJleYaUX5T4e6AKcHoXJYHUKAog/FFeH53katguvHmYM+9XAlhYqsoTQrQamT//AW3m6d+HIyK/Sc9qybhM3gLue1w4yg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4c7c4y59nKzdcWF; Fri, 22 Aug 2025 18:34:42 +0800 (CST) Received: from dggemv705-chm.china.huawei.com (unknown [10.3.19.32]) by mail.maildlp.com (Postfix) with ESMTPS id 9D23A1400CD; Fri, 22 Aug 2025 18:39:06 +0800 (CST) Received: from kwepemq200001.china.huawei.com (7.202.195.16) by dggemv705-chm.china.huawei.com (10.3.19.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 18:39:06 +0800 Received: from localhost.huawei.com (10.90.31.46) by kwepemq200001.china.huawei.com (7.202.195.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 18:39:05 +0800 From: Chenghai Huang To: , , CC: , , , , , , , Subject: [PATCH 2/4] uacce: fix isolate sysfs check condition Date: Fri, 22 Aug 2025 18:39:02 +0800 Message-ID: <20250822103904.3776304-3-huangchenghai2@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250822103904.3776304-1-huangchenghai2@huawei.com> References: <20250822103904.3776304-1-huangchenghai2@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemq200001.china.huawei.com (7.202.195.16) Content-Type: text/plain; charset="utf-8" The uacce supports device isolation feature. If the driver implements the isolate_err_threshold_read and isolate_err_threshold_write callbacks, the uacce will create sysfs files. Users can read and configure isolation policies through sysfs. Currently, if either isolate_err_threshold_read or isolate_err_threshold_write callback exists, sysfs files are created. However, accessing a non-existent callback may cause a system panic. Therefore, sysfs files are only created when both isolate_err_threshold_read and isolate_err_threshold_write are present. Fixes: e3e289fbc0b5 ("uacce: supports device isolation feature") Signed-off-by: Chenghai Huang --- drivers/misc/uacce/uacce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c index 3604f722ed60..6a38809ca819 100644 --- a/drivers/misc/uacce/uacce.c +++ b/drivers/misc/uacce/uacce.c @@ -441,7 +441,7 @@ static umode_t uacce_dev_is_visible(struct kobject *kob= j, return 0; =20 if (attr =3D=3D &dev_attr_isolate_strategy.attr && - (!uacce->ops->isolate_err_threshold_read && + (!uacce->ops->isolate_err_threshold_read || !uacce->ops->isolate_err_threshold_write)) return 0; =20 --=20 2.33.0 From nobody Fri Oct 3 23:02:07 2025 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 179142F6185; Fri, 22 Aug 2025 10:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755859151; cv=none; b=ojU1K5tFnWDKdM2aeyRxCxyPR3KfEoe+5SrqEZfXD8KnLwy7TVsIKcPbyaZk52AJAVrsSxMNH1CETJBZfT/vCgR/OGPbagpcvafKKQcz1TewnfDI8FguOZwKvzirrwjNSwApWlFjfeswHcPgjRniHhH63JhOOv+ZkYVS35hN1Cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755859151; c=relaxed/simple; bh=dTmHS+SXwmigGt+qIm+6F1mMEbPr3KsBXmdDhWkQLv8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lHtOCDVDlOotU6JjI1nZbpSVx+FPOhxshyS2i768BLCld/b8F4zo4hXbVE1wLbU85idxTfKTd8RjCRcKi0s6l3Bauz4OMmPoj5fKQRnVQ90b3NpFSbH+0XxzkvacKQU8KRuiZH6Wonb5u+hxxX8yvREy9byW8GuWvniPuxdx4kU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4c7c4k6LskzPqWq; Fri, 22 Aug 2025 18:34:30 +0800 (CST) Received: from dggemv705-chm.china.huawei.com (unknown [10.3.19.32]) by mail.maildlp.com (Postfix) with ESMTPS id D3534140257; Fri, 22 Aug 2025 18:39:06 +0800 (CST) Received: from kwepemq200001.china.huawei.com (7.202.195.16) by dggemv705-chm.china.huawei.com (10.3.19.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 18:39:06 +0800 Received: from localhost.huawei.com (10.90.31.46) by kwepemq200001.china.huawei.com (7.202.195.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 18:39:06 +0800 From: Chenghai Huang To: , , CC: , , , , , , , Subject: [PATCH 3/4] uacce: implement mremap in uacce_vm_ops to return -EPERM Date: Fri, 22 Aug 2025 18:39:03 +0800 Message-ID: <20250822103904.3776304-4-huangchenghai2@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250822103904.3776304-1-huangchenghai2@huawei.com> References: <20250822103904.3776304-1-huangchenghai2@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemq200001.china.huawei.com (7.202.195.16) Content-Type: text/plain; charset="utf-8" From: Yang Shen The current uacce_vm_ops does not support the mremap operation of vm_operations_struct. Implement .mremap to return -EPERM to remind users Fixes: 015d239ac014 ("uacce: add uacce driver") Signed-off-by: Yang Shen Signed-off-by: Chenghai Huang --- 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 6a38809ca819..531a24145ba4 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) } } =20 +static int uacce_vma_mremap(struct vm_area_struct *area) +{ + return -EPERM; +} + static const struct vm_operations_struct uacce_vm_ops =3D { .close =3D uacce_vma_close, + .mremap =3D uacce_vma_mremap, }; =20 static int uacce_fops_mmap(struct file *filep, struct vm_area_struct *vma) --=20 2.33.0 From nobody Fri Oct 3 23:02:07 2025 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A6AF2F5483; Fri, 22 Aug 2025 10:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755859152; cv=none; b=bXyNZmB6FE2KGlsffi8OCljXCyTLV5JciOOHV43mNJ7axP5COP6/ShzU0hmADuQJssIB2PmZiHms3dUPEVCx3MJ2JxXWlh0sKURlfHBEBf8VQ3NJtg3k1ybhXq3UpSobxGlVF7FCW4YIGucJsCVi4SOHy8/84Kqa5x4V/uW5dWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755859152; c=relaxed/simple; bh=5OW9O5RwyETlN8vXUqm94SQB4JN1rvICtu20k9gCrQM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KcIQZnYGOvXwEcClnZmLPHy6rjItgIhXFv8gaI7nF5puC+gIDn2yw83M8eV/KsDxHQ2XE9BPxb7KuidS2UxNQZFObkOhhsWvfMqTHM8CEGDSjMQ7NRzcnlIt00VKbMALhjEZbZYtjsFfONTFZcmAxlGs+jiLZDeg9P9FfSX1DFA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4c7c6j3dN8z1R8yS; Fri, 22 Aug 2025 18:36:13 +0800 (CST) Received: from dggemv706-chm.china.huawei.com (unknown [10.3.19.33]) by mail.maildlp.com (Postfix) with ESMTPS id 816F6140258; Fri, 22 Aug 2025 18:39:07 +0800 (CST) Received: from kwepemq200001.china.huawei.com (7.202.195.16) by dggemv706-chm.china.huawei.com (10.3.19.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 18:39:07 +0800 Received: from localhost.huawei.com (10.90.31.46) by kwepemq200001.china.huawei.com (7.202.195.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 22 Aug 2025 18:39:06 +0800 From: Chenghai Huang To: , , CC: , , , , , , , Subject: [PATCH 4/4] uacce: ensure safe queue release with state management Date: Fri, 22 Aug 2025 18:39:04 +0800 Message-ID: <20250822103904.3776304-5-huangchenghai2@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20250822103904.3776304-1-huangchenghai2@huawei.com> References: <20250822103904.3776304-1-huangchenghai2@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To kwepemq200001.china.huawei.com (7.202.195.16) Content-Type: text/plain; charset="utf-8" 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") Signed-off-by: Chenghai Huang Signed-off-by: Yang Shen --- 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 531a24145ba4..8a78edb545a1 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; } =20 -static int uacce_put_queue(struct uacce_queue *q) +static int uacce_stop_queue(struct uacce_queue *q) { struct uacce_device *uacce =3D q->uacce; =20 - if ((q->state =3D=3D UACCE_Q_STARTED) && uacce->ops->stop_queue) + if (q->state !=3D UACCE_Q_STARTED) + return 0; + + if (uacce->ops->stop_queue) uacce->ops->stop_queue(q); =20 - if ((q->state =3D=3D UACCE_Q_INIT || q->state =3D=3D UACCE_Q_STARTED) && - uacce->ops->put_queue) + q->state =3D UACCE_Q_INIT; + + return 0; +} + +static void uacce_put_queue(struct uacce_queue *q) +{ + struct uacce_device *uacce =3D q->uacce; + + uacce_stop_queue(q); + + if (q->state !=3D UACCE_Q_INIT) + return; + + if (uacce->ops->put_queue) uacce->ops->put_queue(q); =20 q->state =3D UACCE_Q_ZOMBIE; - - return 0; } =20 static long uacce_fops_unl_ioctl(struct file *filep, @@ -80,7 +94,7 @@ static long uacce_fops_unl_ioctl(struct file *filep, ret =3D uacce_start_queue(q); break; case UACCE_CMD_PUT_Q: - ret =3D uacce_put_queue(q); + ret =3D uacce_stop_queue(q); break; default: if (uacce->ops->ioctl) --=20 2.33.0