Skip to contentSkip to conversation

drm/amdgpu:Added support for MV packet

PATCH Superseded James Zhu 4 participants 7 messages Mar 29, 2018 – Apr 4, 2018 5 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

James Zhu

author
#0 lore raw

PATCH 1/1 drm/amdgpu:Added support for MV packet

Motion vector packet needs support in physic mode.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +24 -0
index 4dfa868..ef6b780 100644
@@ -767,6 +767,18 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx)
 			if (r)
 				goto out;
 			break;
+
+		case 0x0500000d: /* MV buffer */
+			r = amdgpu_vce_validate_bo(p, ib_idx, idx + 3,
+							idx + 2, 0, 0);
+			if (r)
+				goto out;
+
+			r = amdgpu_vce_validate_bo(p, ib_idx, idx + 8,
+							idx + 7, 0, 0);
+			if (r)
+				goto out;
+			break;
 		}
 
 		idx += len / 4;
@@ -884,6 +896,18 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx)
 				goto out;
 			break;
 
+		case 0x0500000d: /* MV buffer */
+			r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 3,
+							idx + 2, 0, 0);
+			if (r)
+				goto out;
+
+			r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 8,
+							idx + 7, 0, 0);
+			if (r)
+				goto out;
+			break;
+
 		default:
 			DRM_ERROR("invalid VCE command (0x%x)!\n", cmd);
 			r = -EINVAL;
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1522357350-7872-1-git-send-email-James.Zhu-5C7GfCeVMHo@public.gmane.org

#2 lore raw

Am 29.03.2018 um 23:02 schrieb James Zhu:

Quoted 17 lines

Motion vector packet needs support in physic mode.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 24 ++++++++++++++++++++++++
  1 file changed, 24 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -0
index 4dfa868..ef6b780 100644
@@ -767,6 +767,18 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx)
  			if (r)
  				goto out;
  			break;
+
+		case 0x0500000d: /* MV buffer */

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx) · line 781

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +10 -0
+			r = amdgpu_vce_validate_bo(p, ib_idx, idx + 3,
+							idx + 2, 0, 0);
+			if (r)
+				goto out;
+
+			r = amdgpu_vce_validate_bo(p, ib_idx, idx + 8,
+							idx + 7, 0, 0);
+			if (r)
+				goto out;
+			break;

You need to specify a size here or otherwise userspace could allocate only a 4kb buffer and hope that VCE write over the end of the buffer.

Since the MVs are easily controllable userspace can hope to hit and fill a page table with this. That would be a security hole you can push an elephant through, taking over the whole system with that is just a typing exercise.

Regards,
Christian.

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +5 -0
  		}
 
  		idx += len / 4;
@@ -884,6 +896,18 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx)
  				goto out;
  			break;
 
+		case 0x0500000d: /* MV buffer */
+			r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 3,
+							idx + 2, 0, 0);
+			if (r)
+				goto out;

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx) · line 913

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +7 -0
+
+			r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 8,
+							idx + 7, 0, 0);
+			if (r)
+				goto out;
+			break;
+
  		default:
  			DRM_ERROR("invalid VCE command (0x%x)!\n", cmd);
  			r = -EINVAL;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): de5a8e06-1549-2647-932a-f64a4a96b3c3-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#4 lore raw
Quoted 32 lines · Christian König

Am 29.03.2018 um 23:02 schrieb James Zhu:

Quoted 18 lines

Motion vector packet needs support in physic mode.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 24 ++++++++++++++++++++++++

  1 file changed, 24 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -0
index 4dfa868..ef6b780 100644
@@ -767,6 +767,18 @@ int amdgpu_vce_ring_parse_cs(struct 
 amdgpu_cs_parser *p, uint32_t ib_idx)
               if (r)
                   goto out;
               break;
+
+        case 0x0500000d: /* MV buffer */

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_ring_parse_cs(struct · line 782

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +10 -0
+            r = amdgpu_vce_validate_bo(p, ib_idx, idx + 3,
+                            idx + 2, 0, 0);
+            if (r)
+                goto out;
+
+            r = amdgpu_vce_validate_bo(p, ib_idx, idx + 8,
+                            idx + 7, 0, 0);
+            if (r)
+                goto out;
+            break;

You need to specify a size here or otherwise userspace could allocate only a 4kb buffer and hope that VCE write over the end of the buffer.

Quoted 5 lines

Since the MVs are easily controllable userspace can hope to hit and fill a page table with this. That would be a security hole you can push an elephant through, taking over the whole system with that is just a typing exercise.

Regards,
Christian.

Hi Christian,

The first buffer is for input frame, I saw encode doesn't specify the size.
The 2nd buffer is for mv dump buffer, the size should be fixed with ALIGN(enc.width, 16) * ALIGN(enc.height, 16) / 8 which is less than 4k. Since IB doesn't pass down this value. how to specify the size for this case?

Best Regards!
James Zhu

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0 -0
           }
             idx += len / 4;
@@ -884,6 +896,18 @@ int amdgpu_vce_ring_parse_cs(struct 
 amdgpu_cs_parser *p, uint32_t ib_idx)
                   goto out;
               break;

  +        case 0x0500000d: /* MV buffer */
+            r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 3, +                            idx + 2, 0, 0);
+            if (r)
+                goto out;
+
+            r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 8,

Quoted 9 lines
Quoted 8 lines

+                            idx + 7, 0, 0);
+            if (r)
+                goto out;
+            break;
+
          default:
              DRM_ERROR("invalid VCE command (0x%x)!\n", cmd); r = -EINVAL;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): ebbfe0e7-6930-c142-5ea6-13fcc7caba17-5C7GfCeVMHo@public.gmane.org

#6 lore raw

Am 02.04.2018 um 22:27 schrieb James Zhu:

Quoted 35 lines · Christian König
Quoted 32 lines

Am 29.03.2018 um 23:02 schrieb James Zhu:

Quoted 18 lines

Motion vector packet needs support in physic mode.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 24 ++++++++++++++++++++++++

  1 file changed, 24 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -0
index 4dfa868..ef6b780 100644
@@ -767,6 +767,18 @@ int amdgpu_vce_ring_parse_cs(struct 
 amdgpu_cs_parser *p, uint32_t ib_idx)
               if (r)
                   goto out;
               break;
+
+        case 0x0500000d: /* MV buffer */

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_ring_parse_cs(struct · line 782

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +10 -0
+            r = amdgpu_vce_validate_bo(p, ib_idx, idx + 3,
+                            idx + 2, 0, 0);
+            if (r)
+                goto out;
+
+            r = amdgpu_vce_validate_bo(p, ib_idx, idx + 8,
+                            idx + 7, 0, 0);
+            if (r)
+                goto out;
+            break;

You need to specify a size here or otherwise userspace could allocate only a 4kb buffer and hope that VCE write over the end of the buffer.

Quoted 8 lines
Quoted 5 lines

Since the MVs are easily controllable userspace can hope to hit and fill a page table with this. That would be a security hole you can push an elephant through, taking over the whole system with that is just a typing exercise.

Regards,
Christian.

Hi Christian,

The first buffer is for input frame, I saw encode doesn't specify the size.

Good point, that makes this far less problematic, but I still think correct size handling would be nice to have.

Take a look at the second pass for the encode command, size handling is there:

Quoted 5 lines

                case 0x03000001: /* encode */
                        r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 10, idx + 9, *size, 0);
                        if (r)
                                goto out;

If I'm not completely mistake you just need to specify "*size" and "*size / 3" as parameters for your call to amdgpu_vce_cs_reloc as well.

Quoted 1 line

The 2nd buffer is for mv dump buffer, the size should be fixed with ALIGN(enc.width, 16) * ALIGN(enc.height, 16) / 8 which is less than 4k. Since IB doesn't pass down this value. how to specify the size for this case?

Why do you think that ALIGN(enc.width, 16) * ALIGN(enc.height, 16) / 8 is less than 4k? If I do the math correctly for a 1920x1088 input picture that should be around 255k.

*size should be size of the input picture in bytes (luma+chroma), so something like "*ALIGN(size * 3 / 2 / 8, 256) / 8" should do it.

Regards,
Christian.

Quoted 26 lines

Best Regards!
James Zhu

Quoted 22 lines
Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0 -0
           }
             idx += len / 4;
@@ -884,6 +896,18 @@ int amdgpu_vce_ring_parse_cs(struct 
 amdgpu_cs_parser *p, uint32_t ib_idx)
                   goto out;
               break;

  +        case 0x0500000d: /* MV buffer */
+            r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 3, +                            idx + 2, 0, 0);
+            if (r)
+                goto out;

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +7 -0
+
+            r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 8,
+                            idx + 7, 0, 0);
+            if (r)
+                goto out;
+            break;
+

          default:
              DRM_ERROR("invalid VCE command (0x%x)!\n", cmd); r = -EINVAL;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 5138ab5e-8056-93f3-a635-bec2d17c8d5c-5C7GfCeVMHo@public.gmane.org

#8 lore raw

Hi Christian,

Thanks for correction.

Since MV dump is not normal encoding, its size is HxW/8. So the 2nd buffer size if  1/12 of the 1st one.

Thanks and Best Regards!

James Zhu

Quoted 57 lines · Christian König

Am 02.04.2018 um 22:27 schrieb James Zhu:

Quoted 36 lines · Christian König
Quoted 33 lines

Am 29.03.2018 um 23:02 schrieb James Zhu:

Quoted 19 lines

Motion vector packet needs support in physic mode.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 24
++++++++++++++++++++++++

  1 file changed, 24 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -0
index 4dfa868..ef6b780 100644
@@ -767,6 +767,18 @@ int amdgpu_vce_ring_parse_cs(struct 
 amdgpu_cs_parser *p, uint32_t ib_idx)
               if (r)
                   goto out;
               break;
+
+        case 0x0500000d: /* MV buffer */

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_ring_parse_cs(struct · line 782

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +10 -0
+            r = amdgpu_vce_validate_bo(p, ib_idx, idx + 3,
+                            idx + 2, 0, 0);
+            if (r)
+                goto out;
+
+            r = amdgpu_vce_validate_bo(p, ib_idx, idx + 8,
+                            idx + 7, 0, 0);
+            if (r)
+                goto out;
+            break;

You need to specify a size here or otherwise userspace could allocate only a 4kb buffer and hope that VCE write over the end of the buffer.

Quoted 8 lines
Quoted 5 lines

Since the MVs are easily controllable userspace can hope to hit and fill a page table with this. That would be a security hole you can push an elephant through, taking over the whole system with that is just a typing exercise.

Regards,
Christian.

Hi Christian,

The first buffer is for input frame, I saw encode doesn't specify the size.

Good point, that makes this far less problematic, but I still think correct size handling would be nice to have.

Take a look at the second pass for the encode command, size handling is there:

Quoted 5 lines

                case 0x03000001: /* encode */
                        r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 10, idx + 9, *size, 0);
                        if (r)
                                goto out;

If I'm not completely mistake you just need to specify "*size" and "*size / 3" as parameters for your call to amdgpu_vce_cs_reloc as well.

Quoted 36 lines
Quoted 1 line

The 2nd buffer is for mv dump buffer, the size should be fixed with ALIGN(enc.width, 16) * ALIGN(enc.height, 16) / 8 which is less than 4k. Since IB doesn't pass down this value. how to specify the size for this case?

Why do you think that ALIGN(enc.width, 16) * ALIGN(enc.height, 16) / 8 is less than 4k? If I do the math correctly for a 1920x1088 input picture that should be around 255k.

*size should be size of the input picture in bytes (luma+chroma), so something like "*ALIGN(size * 3 / 2 / 8, 256) / 8" should do it.

Regards,
Christian.

Quoted 26 lines

Best Regards!
James Zhu

Quoted 22 lines
Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0 -0
           }
             idx += len / 4;
@@ -884,6 +896,18 @@ int amdgpu_vce_ring_parse_cs(struct 
 amdgpu_cs_parser *p, uint32_t ib_idx)
                   goto out;
               break;

  +        case 0x0500000d: /* MV buffer */
+            r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 3, +                            idx + 2, 0, 0);
+            if (r)
+                goto out;

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +7 -0
+
+            r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 8,
+                            idx + 7, 0, 0);
+            if (r)
+                goto out;
+            break;
+

          default:
              DRM_ERROR("invalid VCE command (0x%x)!\n", cmd); r = -EINVAL;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#9 lore raw

PATCH v2 1/1 drm/amdgpu:Added support for MV packet

In reply to a message not in the archive

Motion vector packet needs support in physic mode.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +24 -0
index a33804b..d7261e0 100644
@@ -755,6 +755,18 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx)
 			if (r)
 				goto out;
 			break;
+
+		case 0x0500000d: /* MV buffer */
+			r = amdgpu_vce_validate_bo(p, ib_idx, idx + 3,
+							idx + 2, 0, 0);
+			if (r)
+				goto out;
+
+			r = amdgpu_vce_validate_bo(p, ib_idx, idx + 8,
+							idx + 7, 0, 0);
+			if (r)
+				goto out;
+			break;
 		}
 
 		idx += len / 4;
@@ -860,6 +872,18 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx)
 				goto out;
 			break;
 
+		case 0x0500000d: /* MV buffer */
+			r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 3,
+							idx + 2, *size, 0);
+			if (r)
+				goto out;
+
+			r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 8,
+							idx + 7, *size / 12, 0);
+			if (r)
+				goto out;
+			break;
+
 		default:
 			DRM_ERROR("invalid VCE command (0x%x)!\n", cmd);
 			r = -EINVAL;
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1522766956-22431-1-git-send-email-James.Zhu-5C7GfCeVMHo@public.gmane.org

#11 lore raw

Am 03.04.2018 um 16:49 schrieb James Zhu:

Quoted 3 lines

Motion vector packet needs support in physic mode.

Quoted 36 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 24 ++++++++++++++++++++++++
  1 file changed, 24 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +17 -0
index a33804b..d7261e0 100644
@@ -755,6 +755,18 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx)
  			if (r)
  				goto out;
  			break;
+
+		case 0x0500000d: /* MV buffer */
+			r = amdgpu_vce_validate_bo(p, ib_idx, idx + 3,
+							idx + 2, 0, 0);
+			if (r)
+				goto out;
+
+			r = amdgpu_vce_validate_bo(p, ib_idx, idx + 8,
+							idx + 7, 0, 0);
+			if (r)
+				goto out;
+			break;
  		}
 
  		idx += len / 4;
@@ -860,6 +872,18 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx)
  				goto out;
  			break;
 
+		case 0x0500000d: /* MV buffer */
+			r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 3,
+							idx + 2, *size, 0);
+			if (r)
+				goto out;

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx) · line 889

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +7 -0
+
+			r = amdgpu_vce_cs_reloc(p, ib_idx, idx + 8,
+							idx + 7, *size / 12, 0);
+			if (r)
+				goto out;
+			break;
+
  		default:
  			DRM_ERROR("invalid VCE command (0x%x)!\n", cmd);
  			r = -EINVAL;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx