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

Commit 2b6084f1 authored by Hareesh Gundu's avatar Hareesh Gundu
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 1996ec83
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -241,11 +241,13 @@ 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_list;
	int source_nelems;
	int dest_vmid;
	int dest_perms;
	struct sg_table *sgt;
	struct scatterlist *sg;
	struct ion_cma_buffer_info *info = buffer->priv_virt;

	source_nelems = count_set_bits(buffer->flags & ION_FLAGS_CP_MASK);
@@ -262,7 +264,8 @@ 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_list, source_nelems,
	sgt = info->table;
	ret = hyp_assign_table(sgt, source_vm_list, source_nelems,
			       &dest_vmid, &dest_perms, 1);
	if (ret) {
		pr_err("%s: Not freeing memory since assign failed\n",
@@ -270,6 +273,9 @@ static void ion_secure_cma_free(struct ion_buffer *buffer)
		goto out_free_source;
	}

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

	ion_cma_free(buffer);
out_free_source:
	kfree(source_vm_list);
@@ -280,13 +286,15 @@ static int ion_secure_cma_allocate(
			struct ion_buffer *buffer, unsigned long len,
			unsigned long align, unsigned long flags)
{
	int ret = 0;
	int i, ret = 0;
	int count;
	int source_vm;
	int *dest_vm_list = NULL;
	int *dest_perms = NULL;
	int dest_nelems;
	struct ion_cma_buffer_info *info;
	struct sg_table *sgt;
	struct scatterlist *sg;

	source_vm = VMID_HLOS;

@@ -321,13 +329,18 @@ static int ion_secure_cma_allocate(
	}

	info = buffer->priv_virt;
	ret = hyp_assign_table(info->table, &source_vm, 1,
			dest_vm_list, dest_perms, dest_nelems);
	sgt = info->table;
	ret = hyp_assign_table(sgt, &source_vm, 1, dest_vm_list, dest_perms,
			       dest_nelems);
	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));

	kfree(dest_vm_list);
	kfree(dest_perms);
	return ret;