[v2] drm/i915/gvt: Double check batch buffer size after copy

Submitted by Zhang, Tina on June 10, 2019, 6:09 a.m.

Details

Message ID 20190610060916.609-1-tina.zhang@intel.com
State New
Headers show
Series "drm/i915/gvt: Double check batch buffer size after copy" ( rev: 2 ) in Intel GVT devel

Not browsing as part of any series.

Commit Message

Zhang, Tina June 10, 2019, 6:09 a.m.
Double check the size of the privilege buffer to make sure the size
remains unchanged after copy.

v2:
- Use lightweight way to audit batch buffer end. (Yan)

Cc: Yan Zhao <yan.y.zhao@intel.com>
Signed-off-by: Tina Zhang <tina.zhang@intel.com>
---
 drivers/gpu/drm/i915/gvt/cmd_parser.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/gvt/cmd_parser.c b/drivers/gpu/drm/i915/gvt/cmd_parser.c
index 6ea88270c818..56a8ada0089d 100644
--- a/drivers/gpu/drm/i915/gvt/cmd_parser.c
+++ b/drivers/gpu/drm/i915/gvt/cmd_parser.c
@@ -1716,6 +1716,29 @@  static int find_bb_size(struct parser_exec_state *s, unsigned long *bb_size)
 	return 0;
 }
 
+static int audit_bb_end(struct parser_exec_state *s, void *va)
+{
+	struct intel_vgpu *vgpu = s->vgpu;
+	u32 cmd = *(u32 *)va;
+	const struct cmd_info *info;
+
+	info = get_cmd_info(s->vgpu->gvt, cmd, s->ring_id);
+	if (info == NULL) {
+		gvt_vgpu_err("unknown cmd 0x%x, opcode=0x%x, addr_type=%s, ring %d, workload=%p\n",
+			cmd, get_opcode(cmd, s->ring_id),
+			(s->buf_addr_type == PPGTT_BUFFER) ?
+			"ppgtt" : "ggtt", s->ring_id, s->workload);
+		return -EBADRQC;
+	}
+
+	if ((info->opcode == OP_MI_BATCH_BUFFER_END) ||
+	    ((info->opcode == OP_MI_BATCH_BUFFER_START) &&
+	     (BATCH_BUFFER_2ND_LEVEL_BIT(cmd) == 0)))
+		return 0;
+
+	return -EBADRQC;
+}
+
 static int perform_bb_shadow(struct parser_exec_state *s)
 {
 	struct intel_vgpu *vgpu = s->vgpu;
@@ -1788,6 +1811,10 @@  static int perform_bb_shadow(struct parser_exec_state *s)
 		goto err_unmap;
 	}
 
+	ret = audit_bb_end(s, bb->va + start_offset + bb_size - 4);
+	if (ret)
+		goto err_unmap;
+
 	INIT_LIST_HEAD(&bb->list);
 	list_add(&bb->list, &s->workload->shadow_bb);
 

Comments

Discussed with Yan. Seems we need v3 for this patch. 
Thanks.

BR,
Tina

> -----Original Message-----
> From: Zhang, Tina
> Sent: Monday, June 10, 2019 2:09 PM
> To: intel-gvt-dev@lists.freedesktop.org
> Cc: Zhang, Tina <tina.zhang@intel.com>; zhenyuw@linux.intel.com; Yuan,
> Hang <hang.yuan@intel.com>; Zhao, Yan Y <yan.y.zhao@intel.com>
> Subject: [PATCH v2] drm/i915/gvt: Double check batch buffer size after copy
> 
> Double check the size of the privilege buffer to make sure the size remains
> unchanged after copy.
> 
> v2:
> - Use lightweight way to audit batch buffer end. (Yan)
> 
> Cc: Yan Zhao <yan.y.zhao@intel.com>
> Signed-off-by: Tina Zhang <tina.zhang@intel.com>
> ---
>  drivers/gpu/drm/i915/gvt/cmd_parser.c | 27
> +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/cmd_parser.c
> b/drivers/gpu/drm/i915/gvt/cmd_parser.c
> index 6ea88270c818..56a8ada0089d 100644
> --- a/drivers/gpu/drm/i915/gvt/cmd_parser.c
> +++ b/drivers/gpu/drm/i915/gvt/cmd_parser.c
> @@ -1716,6 +1716,29 @@ static int find_bb_size(struct parser_exec_state
> *s, unsigned long *bb_size)
>  	return 0;
>  }
> 
> +static int audit_bb_end(struct parser_exec_state *s, void *va) {
> +	struct intel_vgpu *vgpu = s->vgpu;
> +	u32 cmd = *(u32 *)va;
> +	const struct cmd_info *info;
> +
> +	info = get_cmd_info(s->vgpu->gvt, cmd, s->ring_id);
> +	if (info == NULL) {
> +		gvt_vgpu_err("unknown cmd 0x%x, opcode=0x%x,
> addr_type=%s, ring %d, workload=%p\n",
> +			cmd, get_opcode(cmd, s->ring_id),
> +			(s->buf_addr_type == PPGTT_BUFFER) ?
> +			"ppgtt" : "ggtt", s->ring_id, s->workload);
> +		return -EBADRQC;
> +	}
> +
> +	if ((info->opcode == OP_MI_BATCH_BUFFER_END) ||
> +	    ((info->opcode == OP_MI_BATCH_BUFFER_START) &&
> +	     (BATCH_BUFFER_2ND_LEVEL_BIT(cmd) == 0)))
> +		return 0;
> +
> +	return -EBADRQC;
> +}
> +
>  static int perform_bb_shadow(struct parser_exec_state *s)  {
>  	struct intel_vgpu *vgpu = s->vgpu;
> @@ -1788,6 +1811,10 @@ static int perform_bb_shadow(struct
> parser_exec_state *s)
>  		goto err_unmap;
>  	}
> 
> +	ret = audit_bb_end(s, bb->va + start_offset + bb_size - 4);
> +	if (ret)
> +		goto err_unmap;
> +
>  	INIT_LIST_HEAD(&bb->list);
>  	list_add(&bb->list, &s->workload->shadow_bb);
> 
> --
> 2.17.1