Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7bece025 authored by Jilai Wang's avatar Jilai Wang
Browse files

msm: npu: Unload networks when driver handle is closed



If user process is killed during network execution, all related
networks need to be unloaded during driver handle is closed to avoid
resource leakage.

Change-Id: I993ef4bfdc11319ccf5bccda500814e143c0c316
Signed-off-by: default avatarJilai Wang <jilaiw@codeaurora.org>
parent 5457aada
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1114,6 +1114,8 @@ static int npu_close(struct inode *inode, struct file *file)
	struct npu_client *client = file->private_data;
	struct npu_kevent *kevent;

	npu_host_cleanup_networks(client);

	while (!list_empty(&client->evt_list)) {
		kevent = list_first_entry(&client->evt_list,
			struct npu_kevent, list);
+31 −0
Original line number Diff line number Diff line
@@ -1736,3 +1736,34 @@ int32_t npu_host_loopback_test(struct npu_device *npu_dev)

	return ret;
}

void npu_host_cleanup_networks(struct npu_client *client)
{
	int i;
	struct npu_device *npu_dev = client->npu_dev;
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;
	struct msm_npu_unload_network_ioctl unload_req;
	struct msm_npu_unmap_buf_ioctl unmap_req;
	struct npu_network *network;
	struct npu_ion_buf *ion_buf;

	for (i = 0; i < MAX_LOADED_NETWORK; i++) {
		network = &host_ctx->networks[i];
		if (network->client == client) {
			pr_warn("network %d is not unloaded before close\n",
				network->network_hdl);
			unload_req.network_hdl = network->network_hdl;
			npu_host_unload_network(client, &unload_req);
		}
	}

	/* unmap all remaining buffers */
	while (!list_empty(&client->mapped_buffer_list)) {
		ion_buf = list_first_entry(&client->mapped_buffer_list,
			struct npu_ion_buf, list);
		pr_warn("unmap buffer %x:%x\n", ion_buf->fd, ion_buf->iova);
		unmap_req.buf_ion_hdl = ion_buf->fd;
		unmap_req.npu_phys_addr = ion_buf->iova;
		npu_host_unmap_buf(client, &unmap_req);
	}
}
+1 −0
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ int32_t npu_host_exec_network_v2(struct npu_client *client,
	struct msm_npu_exec_network_ioctl_v2 *exec_ioctl,
	struct msm_npu_patch_buf_info *patch_buf_info);
int32_t npu_host_loopback_test(struct npu_device *npu_dev);
void npu_host_cleanup_networks(struct npu_client *client);

void npu_dump_debug_timeout_stats(struct npu_device *npu_dev);
void npu_dump_cal_state(struct npu_device *npu_dev);