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

Commit 87ef5f34 authored by Jilai Wang's avatar Jilai Wang
Browse files

msm: npu: Use mutex to protect map/unmap to avoid race condition



If multiple processes call map/unmap funciton concurrently, it's
possible to cause data structure corruption while both of them
accesses the same buffer at the same time. This change is to use
mutex to avoid this problem.

Change-Id: I44236a7ae991c0cbd50c36c17cd4cb8e11705a7f
Signed-off-by: default avatarJilai Wang <jilaiw@codeaurora.org>
parent f84134c2
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -1400,8 +1400,16 @@ int32_t npu_host_get_info(struct npu_device *npu_dev,
int32_t npu_host_map_buf(struct npu_client *client,
			struct msm_npu_map_buf_ioctl *map_ioctl)
{
	return npu_mem_map(client, map_ioctl->buf_ion_hdl, map_ioctl->size,
	struct npu_device *npu_dev = client->npu_dev;
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;
	int ret;

	mutex_lock(&host_ctx->lock);
	ret = npu_mem_map(client, map_ioctl->buf_ion_hdl, map_ioctl->size,
		&map_ioctl->npu_phys_addr);
	mutex_unlock(&host_ctx->lock);

	return ret;
}

int32_t npu_host_unmap_buf(struct npu_client *client,
@@ -1419,8 +1427,11 @@ int32_t npu_host_unmap_buf(struct npu_client *client,
		&host_ctx->fw_deinit_done, NW_CMD_TIMEOUT))
		NPU_WARN("npu: wait for fw_deinit_done time out\n");

	mutex_lock(&host_ctx->lock);
	npu_mem_unmap(client, unmap_ioctl->buf_ion_hdl,
		unmap_ioctl->npu_phys_addr);
	mutex_unlock(&host_ctx->lock);

	return 0;
}