Skip to content

Commit 2370eba

Browse files
vizhaoalexdeucher
authored andcommitted
drm/amd/amdgpu:save psp ring wptr to avoid attack
[Why] When some tools performing psp mailbox attack, the readback value of register can be a random value which may break psp. [How] Use a psp wptr cache machanism to aovid the change made by attack. v2: unify change and add detailed reason Signed-off-by: Victor Zhao <[email protected]> Signed-off-by: Jingwen Chen <[email protected]> Reviewed-by: Monk Liu <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent c5699e2 commit 2370eba

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct psp_ring
7676
uint64_t ring_mem_mc_addr;
7777
void *ring_mem_handle;
7878
uint32_t ring_size;
79+
uint32_t ring_wptr;
7980
};
8081

8182
/* More registers may will be supported */

drivers/gpu/drm/amd/amdgpu/psp_v11_0.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ static uint32_t psp_v11_0_ring_get_wptr(struct psp_context *psp)
720720
struct amdgpu_device *adev = psp->adev;
721721

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

@@ -734,6 +734,7 @@ static void psp_v11_0_ring_set_wptr(struct psp_context *psp, uint32_t value)
734734
if (amdgpu_sriov_vf(adev)) {
735735
WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102, value);
736736
WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_101, GFX_CTRL_CMD_ID_CONSUME_CMD);
737+
psp->km_ring.ring_wptr = value;
737738
} else
738739
WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67, value);
739740
}

drivers/gpu/drm/amd/amdgpu/psp_v3_1.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static uint32_t psp_v3_1_ring_get_wptr(struct psp_context *psp)
379379
struct amdgpu_device *adev = psp->adev;
380380

381381
if (amdgpu_sriov_vf(adev))
382-
data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102);
382+
data = psp->km_ring.ring_wptr;
383383
else
384384
data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67);
385385
return data;
@@ -394,6 +394,7 @@ static void psp_v3_1_ring_set_wptr(struct psp_context *psp, uint32_t value)
394394
/* send interrupt to PSP for SRIOV ring write pointer update */
395395
WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_101,
396396
GFX_CTRL_CMD_ID_CONSUME_CMD);
397+
psp->km_ring.ring_wptr = value;
397398
} else
398399
WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67, value);
399400
}

0 commit comments

Comments
 (0)