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

Commit 628e28a3 authored by Mitchel Humpherys's avatar Mitchel Humpherys
Browse files

gpu: ion: only secure buffers when supported



There are some targets where securing Ion buffers is not supported
through the TZ API used in the MSM secure buffer code. Currently, we
simply try the allocation and if it fails we let the clients secure it
themselves through some other means. However, due to a recent change to
the TZ error logging in the kernel, the current "ask for forgiveness"
approach results in logspam. Fix this by moving to an "ask for
permission" approach: if the TZ API to secure the buffers is not
available, don't attempt to use it.

Change-Id: Ie003d5139a0622ce9c18719ca2697525e23e7733
Signed-off-by: default avatarMitchel Humpherys <mitchelh@codeaurora.org>
parent 0dcf4ed8
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -492,7 +492,13 @@ static int ion_secure_cma_allocate(struct ion_heap *heap,
	if (buf) {
		int ret;

		if (!msm_secure_v2_is_supported()) {
			pr_debug("%s: securing buffers is not supported on this platform\n",
				__func__);
			ret = 1;
		} else {
			ret = msm_ion_secure_table(buf->table, 0, 0);
		}
		if (ret) {
			/*
			 * Don't treat the secure buffer failing here as an
@@ -516,6 +522,7 @@ static void ion_secure_cma_free(struct ion_buffer *buffer)
	struct ion_secure_cma_buffer_info *info = buffer->priv_virt;

	dev_dbg(sheap->dev, "Release buffer %p\n", buffer);
	if (msm_secure_v2_is_supported())
		msm_ion_unsecure_table(info->table);
	atomic_sub(buffer->size, &sheap->total_allocated);
	BUG_ON(atomic_read(&sheap->total_allocated) < 0);
+8 −0
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ int msm_ion_secure_table(struct sg_table *table, enum cp_mem_usage usage,

int msm_ion_unsecure_table(struct sg_table *table);

bool msm_secure_v2_is_supported(void);

#else
static inline int ion_cp_change_chunks_state(unsigned long chunks,
			unsigned int nchunks, unsigned int chunk_size,
@@ -123,6 +125,12 @@ int msm_ion_unsecure_table(struct sg_table *table)
{
	return -ENODEV;
}

bool msm_secure_v2_is_supported(void)
{
	return false;
}

#endif

#endif
+15 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ struct cp2_lock_req {

#define MEM_PROTECT_LOCK_ID2     0x0A
#define V2_CHUNK_SIZE		SZ_1M
#define FEATURE_ID_CP 12

static void secure_meta_add(struct secure_meta *meta)
{
@@ -281,3 +282,17 @@ int msm_ion_unsecure_buffer(struct ion_client *client,
out:
	return ret;
}

#define MAKE_CP_VERSION(major, minor, patch) \
	(((major & 0x3FF) << 22) | ((minor & 0x3FF) << 12) | (patch & 0xFFF))

bool msm_secure_v2_is_supported(void)
{
	int version = scm_get_feat_version(FEATURE_ID_CP);

	/*
	 * if the version is < 1.1.0 then dynamic buffer allocation is
	 * not supported
	 */
	return version >= MAKE_CP_VERSION(1, 1, 0);
}