Skip to contentSkip to conversation

drm/amd/amdgpu:save psp ring wptr in SRIOV to avoid attack

PATCH Superseded Jingwen Chen 3 participants 4 messages May 26, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/amdgpu:save psp ring wptr in SRIOV to avoid attack

From: Victor Zhao <[email protected]>

save psp ring wptr in SRIOV to avoid attack to avoid extra changes to MP0_SMN_C2PMSG_102 reg

Change-Id Idee78e8c1c781463048f2f6311fdc70488ef05b2
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 1 +
 drivers/gpu/drm/amd/amdgpu/psp_v11_0.c  | 3 ++-
 drivers/gpu/drm/amd/amdgpu/psp_v3_1.c   | 3 ++-
 4 files changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1 -0
index 55378c6b9722..20e06b3ec686 100644
@@ -2701,6 +2701,7 @@ int psp_ring_cmd_submit(struct psp_context *psp,
 	/* Update the write Pointer in DWORDs */
 	psp_write_ptr_reg = (psp_write_ptr_reg + rb_frame_size_dw) % ring_size_dw;
 	psp_ring_set_wptr(psp, psp_write_ptr_reg);
+	ring->ring_wptr = psp_write_ptr_reg;
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1 -0
index 46a5328e00e0..60aa99a39a74 100644
@@ -76,6 +76,7 @@ struct psp_ring
 	uint64_t			ring_mem_mc_addr;
 	void				*ring_mem_handle;
 	uint32_t			ring_size;
+	uint32_t			ring_wptr;
 };
 
 /* More registers may will be supported */
drivers/gpu/drm/amd/amdgpu/psp_v11_0.c +2 -1
index 1f2e7e35c91e..4a32b0c84ef4 100644
@@ -474,6 +474,7 @@ static int psp_v11_0_ring_create(struct psp_context *psp,
 			return ret;
 		}
 
+		ring->ring_wptr = 0;
 		/* Write low address of the ring to C2PMSG_102 */
 		psp_ring_reg = lower_32_bits(ring->ring_mem_mc_addr);
 		WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102, psp_ring_reg);
@@ -733,7 +734,7 @@ static uint32_t psp_v11_0_ring_get_wptr(struct psp_context *psp)
 	struct amdgpu_device *adev = psp->adev;
 
 	if (amdgpu_sriov_vf(adev))
-		data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102);
+		data = psp->km_ring.ring_wptr;
 	else
 		data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67);
 
drivers/gpu/drm/amd/amdgpu/psp_v3_1.c +2 -1
index f2e725f72d2f..160f78eb6403 100644
@@ -237,6 +237,7 @@ static int psp_v3_1_ring_create(struct psp_context *psp,
 			return ret;
 		}
 
+		ring->ring_wptr = 0;
 		/* Write low address of the ring to C2PMSG_102 */
 		psp_ring_reg = lower_32_bits(ring->ring_mem_mc_addr);
 		WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102, psp_ring_reg);
@@ -379,7 +380,7 @@ static uint32_t psp_v3_1_ring_get_wptr(struct psp_context *psp)
 	struct amdgpu_device *adev = psp->adev;
 
 	if (amdgpu_sriov_vf(adev))
-		data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102);
+		data = psp->km_ring.ring_wptr;
 	else
 		data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67);
 	return data;
Signature · 6 lines
2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v1 1/1
#1 lore raw

[AMD Official Use Only]

Quoted 101 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jingwen Chen
Sent: Wednesday, May 26, 2021 2:55 PM
To: [email protected]
Cc: Chen, JingWen <[email protected]>; Zhao, Victor <[email protected]>; Liu, Monk <[email protected]>
Subject: [PATCH] drm/amd/amdgpu:save psp ring wptr in SRIOV to avoid attack

From: Victor Zhao <[email protected]>

save psp ring wptr in SRIOV to avoid attack to avoid extra changes to MP0_SMN_C2PMSG_102 reg

Change-Id Idee78e8c1c781463048f2f6311fdc70488ef05b2

---

drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 1 +
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 1 +
drivers/gpu/drm/amd/amdgpu/psp_v11_0.c  | 3 ++-
drivers/gpu/drm/amd/amdgpu/psp_v3_1.c   | 3 ++-
4 files changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1 -0
index 55378c6b9722..20e06b3ec686 100644
@@ -2701,6 +2701,7 @@ int psp_ring_cmd_submit(struct psp_context *psp,
      /* Update the write Pointer in DWORDs */
      psp_write_ptr_reg = (psp_write_ptr_reg + rb_frame_size_dw) %
 ring_size_dw;
      psp_ring_set_wptr(psp, psp_write_ptr_reg);
+      ring->ring_wptr = psp_write_ptr_reg;
      return 0;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1 -0
index 46a5328e00e0..60aa99a39a74 100644
@@ -76,6 +76,7 @@ struct psp_ring
      uint64_t                        ring_mem_mc_addr;
      void                            *ring_mem_handle;
      uint32_t                        ring_size;
+      uint32_t                        ring_wptr;
 };
 
 /* More registers may will be supported */ diff --git

a/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c b/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c index 1f2e7e35c91e..4a32b0c84ef4 100644

drivers/gpu/drm/amd/amdgpu/psp_v11_0.c +1 -0
@@ -474,6 +474,7 @@ static int psp_v11_0_ring_create(struct psp_context
 *psp,
                      return ret;
              }
 
+              ring->ring_wptr = 0;
              /* Write low address of the ring to C2PMSG_102 */
              psp_ring_reg = lower_32_bits(ring->ring_mem_mc_addr);
              WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102,
psp_ring_reg); @@ -733,7 +734,7 @@ static uint32_t
psp_v11_0_ring_get_wptr(struct psp_context *psp)
      struct amdgpu_device *adev = psp->adev;

      if (amdgpu_sriov_vf(adev))
drivers/gpu/drm/amd/amdgpu/psp_v11_0.c +1 -1
-              data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102);
+              data = psp->km_ring.ring_wptr;
      else
              data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67);
drivers/gpu/drm/amd/amdgpu/psp_v3_1.c +1 -0
index f2e725f72d2f..160f78eb6403 100644
@@ -237,6 +237,7 @@ static int psp_v3_1_ring_create(struct psp_context *psp,
                      return ret;
              }
 
+              ring->ring_wptr = 0;
              /* Write low address of the ring to C2PMSG_102 */
              psp_ring_reg = lower_32_bits(ring->ring_mem_mc_addr);
              WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102,

psp_ring_reg); @@ -379,7 +380,7 @@ static uint32_t psp_v3_1_ring_get_wptr(struct psp_context *psp)

      struct amdgpu_device *adev = psp->adev;

      if (amdgpu_sriov_vf(adev))
drivers/gpu/drm/amd/amdgpu/psp_v3_1.c +1 -2
-              data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102);
+              data = psp->km_ring.ring_wptr;
      else
              data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67);
      return data;
--

2.25.1

Quoted 10 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.free
desktop.org%2Fmailman%2Flistinfo%2Famd- gfx&amp;data=04%7C01%7CEmily.Deng%40amd.com%7C36c0aa6490f94ad29ac 608d920133b77%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C6375 76089720049840%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJ QIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=PV29Nx wj0ASCRlw%2BHWal6Ghk%2FkLe6Qhxd2yCwA%2BiI9Q%3D&amp;reserved=0

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

#2 lore raw
In reply to Jingwen Chen

[AMD Official Use Only]

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+	ring->ring_wptr = psp_write_ptr_reg;

Put the cache mechanism into the callbacks please

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+		ring->ring_wptr = 0;

It is not needed

At last, try to put more details in the comment to let people know why we need this PSP WPTR cache mechanism

Thanks

------------------------------------------
Monk Liu | Cloud-GPU Core team
------------------------------------------

-----Original Message-----
From: Jingwen Chen <[email protected]>
Sent: Wednesday, May 26, 2021 2:55 PM
To: [email protected]
Cc: Liu, Monk <[email protected]>; Zhao, Victor <[email protected]>; Chen, JingWen <[email protected]>
Subject: [PATCH] drm/amd/amdgpu:save psp ring wptr in SRIOV to avoid attack

From: Victor Zhao <[email protected]>

save psp ring wptr in SRIOV to avoid attack to avoid extra changes to MP0_SMN_C2PMSG_102 reg

Change-Id Idee78e8c1c781463048f2f6311fdc70488ef05b2
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 1 +  drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 1 +  drivers/gpu/drm/amd/amdgpu/psp_v11_0.c  | 3 ++-
 drivers/gpu/drm/amd/amdgpu/psp_v3_1.c   | 3 ++-
 4 files changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1 -0
index 55378c6b9722..20e06b3ec686 100644
@@ -2701,6 +2701,7 @@ int psp_ring_cmd_submit(struct psp_context *psp,
 	/* Update the write Pointer in DWORDs */
 	psp_write_ptr_reg = (psp_write_ptr_reg + rb_frame_size_dw) % ring_size_dw;
 	psp_ring_set_wptr(psp, psp_write_ptr_reg);
+	ring->ring_wptr = psp_write_ptr_reg;
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1 -0
index 46a5328e00e0..60aa99a39a74 100644
@@ -76,6 +76,7 @@ struct psp_ring
 	uint64_t			ring_mem_mc_addr;
 	void				*ring_mem_handle;
 	uint32_t			ring_size;
+	uint32_t			ring_wptr;
 };
 
 /* More registers may will be supported */ diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c b/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c

index 1f2e7e35c91e..4a32b0c84ef4 100644

drivers/gpu/drm/amd/amdgpu/psp_v11_0.c +1 -0
@@ -474,6 +474,7 @@ static int psp_v11_0_ring_create(struct psp_context *psp,
 			return ret;
 		}
 
+		ring->ring_wptr = 0;
 		/* Write low address of the ring to C2PMSG_102 */
 		psp_ring_reg = lower_32_bits(ring->ring_mem_mc_addr);
 		WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102, psp_ring_reg); @@ -733,7 +734,7 @@ static uint32_t psp_v11_0_ring_get_wptr(struct psp_context *psp)

struct amdgpu_device *adev = psp->adev;

if (amdgpu_sriov_vf(adev))
- data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102);
+ data = psp->km_ring.ring_wptr;
else
data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67);

drivers/gpu/drm/amd/amdgpu/psp_v3_1.c +1 -0
index f2e725f72d2f..160f78eb6403 100644
@@ -237,6 +237,7 @@ static int psp_v3_1_ring_create(struct psp_context *psp,
 			return ret;
 		}
 
+		ring->ring_wptr = 0;
 		/* Write low address of the ring to C2PMSG_102 */
 		psp_ring_reg = lower_32_bits(ring->ring_mem_mc_addr);
 		WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102, psp_ring_reg); @@ -379,7 +380,7 @@ static uint32_t psp_v3_1_ring_get_wptr(struct psp_context *psp)

struct amdgpu_device *adev = psp->adev;

if (amdgpu_sriov_vf(adev))
- data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102);
+ data = psp->km_ring.ring_wptr;
else
data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67);
return data;
--
2.25.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#3 lore raw

Hi Monk,

New patch submitted according to your suggestion

Best Regards,
JingWen Chen

-----Original Message-----
From: Liu, Monk <[email protected]>
Sent: Wednesday, May 26, 2021 3:24 PM
To: Chen, JingWen <[email protected]>; [email protected]
Cc: Zhao, Victor <[email protected]>; Chen, JingWen <[email protected]>
Subject: RE: [PATCH] drm/amd/amdgpu:save psp ring wptr in SRIOV to avoid attack

[AMD Official Use Only]

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+	ring->ring_wptr = psp_write_ptr_reg;

Put the cache mechanism into the callbacks please

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+		ring->ring_wptr = 0;

It is not needed

At last, try to put more details in the comment to let people know why we need this PSP WPTR cache mechanism

Thanks

------------------------------------------
Monk Liu | Cloud-GPU Core team
------------------------------------------

-----Original Message-----
From: Jingwen Chen <[email protected]>
Sent: Wednesday, May 26, 2021 2:55 PM
To: [email protected]
Cc: Liu, Monk <[email protected]>; Zhao, Victor <[email protected]>; Chen, JingWen <[email protected]>
Subject: [PATCH] drm/amd/amdgpu:save psp ring wptr in SRIOV to avoid attack

From: Victor Zhao <[email protected]>

save psp ring wptr in SRIOV to avoid attack to avoid extra changes to MP0_SMN_C2PMSG_102 reg

Change-Id Idee78e8c1c781463048f2f6311fdc70488ef05b2
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 1 +  drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 1 +  drivers/gpu/drm/amd/amdgpu/psp_v11_0.c  | 3 ++-
 drivers/gpu/drm/amd/amdgpu/psp_v3_1.c   | 3 ++-
 4 files changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1 -0
index 55378c6b9722..20e06b3ec686 100644
@@ -2701,6 +2701,7 @@ int psp_ring_cmd_submit(struct psp_context *psp,
 	/* Update the write Pointer in DWORDs */
 	psp_write_ptr_reg = (psp_write_ptr_reg + rb_frame_size_dw) % ring_size_dw;
 	psp_ring_set_wptr(psp, psp_write_ptr_reg);
+	ring->ring_wptr = psp_write_ptr_reg;
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1 -0
index 46a5328e00e0..60aa99a39a74 100644
@@ -76,6 +76,7 @@ struct psp_ring
 	uint64_t			ring_mem_mc_addr;
 	void				*ring_mem_handle;
 	uint32_t			ring_size;
+	uint32_t			ring_wptr;
 };
 
 /* More registers may will be supported */ diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c b/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c

index 1f2e7e35c91e..4a32b0c84ef4 100644

drivers/gpu/drm/amd/amdgpu/psp_v11_0.c +1 -0
@@ -474,6 +474,7 @@ static int psp_v11_0_ring_create(struct psp_context *psp,
 			return ret;
 		}
 
+		ring->ring_wptr = 0;
 		/* Write low address of the ring to C2PMSG_102 */
 		psp_ring_reg = lower_32_bits(ring->ring_mem_mc_addr);
 		WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102, psp_ring_reg); @@ -733,7 +734,7 @@ static uint32_t psp_v11_0_ring_get_wptr(struct psp_context *psp)

struct amdgpu_device *adev = psp->adev;

if (amdgpu_sriov_vf(adev))
- data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102);
+ data = psp->km_ring.ring_wptr;
else
data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67);

drivers/gpu/drm/amd/amdgpu/psp_v3_1.c +1 -0
index f2e725f72d2f..160f78eb6403 100644
@@ -237,6 +237,7 @@ static int psp_v3_1_ring_create(struct psp_context *psp,
 			return ret;
 		}
 
+		ring->ring_wptr = 0;
 		/* Write low address of the ring to C2PMSG_102 */
 		psp_ring_reg = lower_32_bits(ring->ring_mem_mc_addr);
 		WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102, psp_ring_reg); @@ -379,7 +380,7 @@ static uint32_t psp_v3_1_ring_get_wptr(struct psp_context *psp)

struct amdgpu_device *adev = psp->adev;

if (amdgpu_sriov_vf(adev))
- data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102);
+ data = psp->km_ring.ring_wptr;
else
data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67);
return data;
--
2.25.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx