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

Commit 1a4a7c46 authored by Dikshita Agarwal's avatar Dikshita Agarwal
Browse files

msm: vidc: add proper check for max secure instance allowed



Current driver design allows one additional secure instance
than max limit since the secure flags were updated later
for the current instance.
The change adds proper checks for the same.

Change-Id: If08e04bee09d91bb33604fea7debeda3da14850f
Signed-off-by: default avatarDikshita Agarwal <dikshita@codeaurora.org>
parent 2d0bbcbf
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -1024,6 +1024,11 @@ int msm_vdec_s_ctrl(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl)
		pdata = &property_val;
		dprintk(VIDC_DBG, "Setting secure mode to: %d\n",
				!!(inst->flags & VIDC_SECURE));
		if (msm_comm_check_for_inst_overload(inst->core)) {
			dprintk(VIDC_ERR,
				"Secure Instance reached Max limit, rejecting session\n");
			return -ENOTSUPP;
		}
		break;
	case V4L2_CID_MPEG_VIDC_VIDEO_EXTRADATA:
		property_id = HAL_PARAM_INDEX_EXTRADATA;
+2 −27
Original line number Diff line number Diff line
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -1608,31 +1608,6 @@ int msm_vidc_private(void *vidc_inst, unsigned int cmd,
	return rc;
}
EXPORT_SYMBOL(msm_vidc_private);

static bool msm_vidc_check_for_inst_overload(struct msm_vidc_core *core)
{
	u32 instance_count = 0;
	u32 secure_instance_count = 0;
	struct msm_vidc_inst *inst = NULL;
	bool overload = false;

	mutex_lock(&core->lock);
	list_for_each_entry(inst, &core->instances, list) {
		instance_count++;
		/* This flag is not updated yet for the current instance */
		if (inst->flags & VIDC_SECURE)
			secure_instance_count++;
	}
	mutex_unlock(&core->lock);

	/* Instance count includes current instance as well. */

	if ((instance_count > core->resources.max_inst_count) ||
		(secure_instance_count > core->resources.max_secure_inst_count))
		overload = true;
	return overload;
}

static int msm_vidc_try_set_ctrl(void *instance, struct v4l2_ctrl *ctrl)
{
	struct msm_vidc_inst *inst = instance;
@@ -1933,7 +1908,7 @@ void *msm_vidc_open(int core_id, int session_type)
	}

	msm_dcvs_try_enable(inst);
	if (msm_vidc_check_for_inst_overload(core)) {
	if (msm_comm_check_for_inst_overload(core)) {
		dprintk(VIDC_ERR,
			"Instance count reached Max limit, rejecting session");
		goto fail_init;
+24 −1
Original line number Diff line number Diff line
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -6967,3 +6967,26 @@ int msm_comm_set_color_format_constraints(struct msm_vidc_inst *inst,
		kfree(pconstraint);
	return rc;
}

bool msm_comm_check_for_inst_overload(struct msm_vidc_core *core)
{
	u32 instance_count = 0;
	u32 secure_instance_count = 0;
	struct msm_vidc_inst *inst = NULL;
	bool overload = false;

	mutex_lock(&core->lock);
	list_for_each_entry(inst, &core->instances, list) {
		instance_count++;
		if (inst->flags & VIDC_SECURE)
			secure_instance_count++;
	}
	mutex_unlock(&core->lock);

	/* Instance count includes current instance as well. */

	if ((instance_count > core->resources.max_inst_count) ||
		(secure_instance_count > core->resources.max_secure_inst_count))
		overload = true;
	return overload;
}
+2 −1
Original line number Diff line number Diff line
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -252,4 +252,5 @@ int msm_comm_release_mark_data(struct msm_vidc_inst *inst);
int msm_comm_qbuf_decode_batch(struct msm_vidc_inst *inst,
		struct msm_vidc_buffer *mbuf);
int msm_comm_num_queued_bufs(struct msm_vidc_inst *inst, u32 type);
bool msm_comm_check_for_inst_overload(struct msm_vidc_core *core);
#endif
+8 −36
Original line number Diff line number Diff line
@@ -170,14 +170,7 @@ static struct msm_vidc_common_data sm6150_common_data[] = {
	},
	{
		.key = "qcom,max-secure-instances",
		.value = 2,             /*
					 * As per design driver allows 3rd
					 * instance as well since the secure
					 * flags were updated later for the
					 * current instance. Hence total
					 * secure sessions would be
					 * max-secure-instances + 1.
					 */
		.value = 3,
	},
	{
		.key = "qcom,max-hw-load",
@@ -236,7 +229,7 @@ static struct msm_vidc_common_data trinket_common_data[] = {
	},
	{
		.key = "qcom,max-secure-instances",
		.value = 5,
		.value = 6,
	},
	{
		.key = "qcom,max-hw-load",
@@ -295,14 +288,7 @@ static struct msm_vidc_common_data sm8150_common_data[] = {
	},
	{
		.key = "qcom,max-secure-instances",
		.value = 2,             /*
					 * As per design driver allows 3rd
					 * instance as well since the secure
					 * flags were updated later for the
					 * current instance. Hence total
					 * secure sessions would be
					 * max-secure-instances + 1.
					 */
		.value = 3,
	},
	{
		.key = "qcom,max-hw-load",
@@ -378,14 +364,7 @@ static struct msm_vidc_common_data sdmmagpie_common_data_v0[] = {
	},
	{
		.key = "qcom,max-secure-instances",
		.value = 2,             /*
					 * As per design driver allows 3rd
					 * instance as well since the secure
					 * flags were updated later for the
					 * current instance. Hence total
					 * secure sessions would be
					 * max-secure-instances + 1.
					 */
		.value = 3,
	},
	{
		.key = "qcom,max-hw-load",
@@ -456,14 +435,7 @@ static struct msm_vidc_common_data sdmmagpie_common_data_v1[] = {
	},
	{
		.key = "qcom,max-secure-instances",
		.value = 2,             /*
					 * As per design driver allows 3rd
					 * instance as well since the secure
					 * flags were updated later for the
					 * current instance. Hence total
					 * secure sessions would be
					 * max-secure-instances + 1.
					 */
		.value = 3,
	},
	{
		.key = "qcom,max-hw-load",
@@ -538,7 +510,7 @@ static struct msm_vidc_common_data sdm845_common_data[] = {
	},
	{
		.key = "qcom,max-secure-instances",
		.value = 5,
		.value = 3,
	},
	{
		.key = "qcom,max-hw-load",
@@ -593,7 +565,7 @@ static struct msm_vidc_common_data sdm670_common_data_v0[] = {
	},
	{
		.key = "qcom,max-secure-instances",
		.value = 5,
		.value = 6,
	},
	{
		.key = "qcom,max-hw-load",
@@ -644,7 +616,7 @@ static struct msm_vidc_common_data sdm670_common_data_v1[] = {
	},
	{
		.key = "qcom,max-secure-instances",
		.value = 5,
		.value = 6,
	},
	{
		.key = "qcom,max-hw-load",