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

Commit 5d57b20e authored by Hareesh Gundu's avatar Hareesh Gundu Committed by Gerrit - the friendly Code Review server
Browse files

ion: Set the page private bit for secure CMA buffers



Set the private page bit on each sg of secure CMA buffers
to inform other entities, which import these buffers as an
fd, that this memory is secure.

Change-Id: I2f012443f99a90e20afd7e43b62b751c3eea4be3
Signed-off-by: default avatarHareesh Gundu <hareeshg@codeaurora.org>
parent ec33cbd8
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -237,10 +237,12 @@ void ion_cma_heap_destroy(struct ion_heap *heap)

static void ion_secure_cma_free(struct ion_buffer *buffer)
{
	int ret = 0;
	int i, ret = 0;
	int source_vm;
	int dest_vmid;
	int dest_perms;
	struct sg_table *sgt;
	struct scatterlist *sg;
	struct ion_cma_buffer_info *info = buffer->priv_virt;

	source_vm = get_secure_vmid(buffer->flags);
@@ -251,14 +253,17 @@ static void ion_secure_cma_free(struct ion_buffer *buffer)
	dest_vmid = VMID_HLOS;
	dest_perms = PERM_READ | PERM_WRITE | PERM_EXEC;

	ret = hyp_assign_table(info->table, &source_vm, 1,
				&dest_vmid, &dest_perms, 1);
	sgt = info->table;
	ret = hyp_assign_table(sgt, &source_vm, 1, &dest_vmid, &dest_perms, 1);
	if (ret) {
		pr_err("%s: Not freeing memory since assign failed\n",
							__func__);
		return;
	}

	for_each_sg(sgt->sgl, sg, sgt->nents, i)
		ClearPagePrivate(sg_page(sgt->sgl));

	ion_cma_free(buffer);
}

@@ -266,11 +271,13 @@ static int ion_secure_cma_allocate(struct ion_heap *heap,
			struct ion_buffer *buffer, unsigned long len,
			unsigned long align, unsigned long flags)
{
	int ret = 0;
	int i, ret = 0;
	int source_vm;
	int dest_vm;
	int dest_perms;
	struct ion_cma_buffer_info *info;
	struct sg_table *sgt;
	struct scatterlist *sg;

	source_vm = VMID_HLOS;
	dest_vm = get_secure_vmid(flags);
@@ -287,12 +294,17 @@ static int ion_secure_cma_allocate(struct ion_heap *heap,
	}

	info = buffer->priv_virt;
	ret = hyp_assign_table(info->table, &source_vm, 1,
				&dest_vm, &dest_perms, 1);
	sgt = info->table;
	ret = hyp_assign_table(sgt, &source_vm, 1, &dest_vm, &dest_perms, 1);
	if (ret) {
		pr_err("%s: Assign call failed\n", __func__);
		goto err;
	}

	/* Set the private bit to indicate that we've secured this */
	for_each_sg(sgt->sgl, sg, sgt->nents, i)
		SetPagePrivate(sg_page(sgt->sgl));

	return ret;

err: