drm/msm: a6xx: Make sure the SQE microcode is safe
Subsystems (4)
PATCH v2 1/1 drm/msm: a6xx: Make sure the SQE microcode is safe
Most a6xx targets have security issues that were fixed with new versions of the microcode(s). Make sure that we are booting with a safe version of the microcode for the target and print a message and error if not.
v2: Add more informative error messages and fix typos
---
drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 77 ++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 13 deletions(-)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +64 -13
@@ -522,28 +522,73 @@ static int a6xx_cp_init(struct msm_gpu *gpu)return a6xx_idle (gpu, ring) ?0 : -EINVAL ; } -static void a6xx_ucode_check_version (struct a6xx_gpu *a6xx_gpu, +/* +* Check that the microcode version is new enough to include several key +* security fixes. Return true if the ucode is safe. +*/ +static bool a6xx_ucode_check_version (struct a6xx_gpu *a6xx_gpu,struct drm_gem_object *obj) { +struct adreno_gpu *adreno_gpu = &a6xx_gpu->base; +struct msm_gpu *gpu = &adreno_gpu->base;u32 *buf =msm_gem_get_vaddr (obj); +bool ret = false;if (IS_ERR (buf)) -return ; +return false;/* -* If the lowest nibble is 0xa that is an indication that this microcode -* has been patched. The actual version is in dword [3] but we only care -* about the patchlevel which is the lowest nibble of dword [3] -* -* Otherwise check that the firmware is greater than or equal to 1.90 -* which was the first version that had this fix built in +* Targets up to a640 (a618, a630 and a640) need to check for a +* microcode version that is patched to support the whereami opcode or +* one that is new enough to include it by default. */ -if (((buf[0 ] &0xf ) ==0xa ) && (buf[2 ] &0xf ) >=1 ) - a6xx_gpu->has_whereami = true; -else if ((buf[0 ] &0xfff ) >0x190 ) - a6xx_gpu->has_whereami = true; +if (adreno_is_a618 (adreno_gpu) ||adreno_is_a630 (adreno_gpu) || +adreno_is_a640 (adreno_gpu)) { +/* +* If the lowest nibble is 0xa that is an indication that this +* microcode has been patched. The actual version is in dword +* [3] but we only care about the patchlevel which is the lowest +* nibble of dword [3] +* +* Otherwise check that the firmware is greater than or equal +* to 1.90 which was the first version that had this fix built +* in +*/ +if ((((buf[0 ] &0xf ) ==0xa ) && (buf[2 ] &0xf ) >=1 ) || + (buf[0 ] &0xfff ) >=0x190 ) { + a6xx_gpu->has_whereami = true; + ret = true; + goto out; + } +DRM_DEV_ERROR (&gpu->pdev->dev, +"a630 SQE ucode is too old. Have version %x need at least %x\n" , + buf[0 ] &0xfff ,0x190 ); + }else { +/* +* a650 tier targets don't need whereami but still need to be +* equal to or newer than 1.95 for other security fixes +*/ +if (adreno_is_a650 (adreno_gpu)) { +if ((buf[0 ] &0xfff ) >=0x195 ) { + ret = true; + goto out; + } + +DRM_DEV_ERROR (&gpu->pdev->dev, +"a650 SQE ucode is too old. Have version %x need at least %x\n" , + buf[0 ] &0xfff ,0x195 ); + } + +/* +* When a660 is added those targets should return true here +* since those have all the critical security fixes built in +* from the start +*/ + } +out:msm_gem_put_vaddr (obj); +return ret; }static int a6xx_ucode_init (struct msm_gpu *gpu)
@@ -566,7 +611,13 @@ static int a6xx_ucode_init(struct msm_gpu *gpu) }msm_gem_object_set_name (a6xx_gpu->sqe_bo,"sqefw" ); -a6xx_ucode_check_version (a6xx_gpu, a6xx_gpu->sqe_bo); +if (!a6xx_ucode_check_version (a6xx_gpu, a6xx_gpu->sqe_bo)) { +msm_gem_unpin_iova (a6xx_gpu->sqe_bo, gpu->aspace); +drm_gem_object_put (a6xx_gpu->sqe_bo); + + a6xx_gpu->sqe_bo =NULL ; +return -EPERM ; + } } gpu_write64(gpu, REG_A6XX_CP_SQE_INSTR_BASE_LO,
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 85 lines · Jordan Crouse
Most a6xx targets have security issues that were fixed with new versions of the microcode(s). Make sure that we are booting with a safe version of the microcode for the target and print a message and error if not.
v2: Add more informative error messages and fix typos
Signed-off-by Jordan Crouse <[email protected]>---
drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 77 ++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 13 deletions(-)drivers/gpu/drm/msm/adreno/a6xx_gpu.c +44
-12@@ -522,28 +522,73 @@ static int a6xx_cp_init(struct msm_gpu *gpu)return a6xx_idle (gpu, ring) ?0 : -EINVAL ; } -static void a6xx_ucode_check_version (struct a6xx_gpu *a6xx_gpu, +/* +* Check that the microcode version is new enough to include several key +* security fixes. Return true if the ucode is safe. +*/ +static bool a6xx_ucode_check_version (struct a6xx_gpu *a6xx_gpu,struct drm_gem_object *obj) { +struct adreno_gpu *adreno_gpu = &a6xx_gpu->base; +struct msm_gpu *gpu = &adreno_gpu->base;u32 *buf =msm_gem_get_vaddr (obj); +bool ret = false;if (IS_ERR (buf)) -return ; +return false;/* -* If the lowest nibble is 0xa that is an indication that this microcode -* has been patched. The actual version is in dword [3] but we only care -* about the patchlevel which is the lowest nibble of dword [3] -* -* Otherwise check that the firmware is greater than or equal to 1.90 -* which was the first version that had this fix built in +* Targets up to a640 (a618, a630 and a640) need to check for a +* microcode version that is patched to support the whereami opcode or +* one that is new enough to include it by default. */ -if (((buf[0 ] &0xf ) ==0xa ) && (buf[2 ] &0xf ) >=1 ) - a6xx_gpu->has_whereami = true; -else if ((buf[0 ] &0xfff ) >0x190 ) - a6xx_gpu->has_whereami = true; +if (adreno_is_a618 (adreno_gpu) ||adreno_is_a630 (adreno_gpu) || +adreno_is_a640 (adreno_gpu)) { +/* +* If the lowest nibble is 0xa that is an indication that this +* microcode has been patched. The actual version is in dword +* [3] but we only care about the patchlevel which is the lowest +* nibble of dword [3] +* +* Otherwise check that the firmware is greater than or equal +* to 1.90 which was the first version that had this fix built +* in +*/ +if ((((buf[0 ] &0xf ) ==0xa ) && (buf[2 ] &0xf ) >=1 ) || + (buf[0 ] &0xfff ) >=0x190 ) { + a6xx_gpu->has_whereami = true; + ret = true; + goto out; + } +DRM_DEV_ERROR (&gpu->pdev->dev, +"a630 SQE ucode is too old. Have version %x need at least %x\n" , + buf[0 ] &0xfff ,0x190 ); + }else { +/* +* a650 tier targets don't need whereami but still need to be +* equal to or newer than 1.95 for other security fixes +*/ +if (adreno_is_a650 (adreno_gpu)) { +if ((buf[0 ] &0xfff ) >=0x195 ) { + ret = true; + goto out; + } +
drivers/gpu/drm/msm/adreno/a6xx_gpu.c static int a6xx_cp_init(struct msm_gpu *gpu) · line 587
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +10
-0+DRM_DEV_ERROR (&gpu->pdev->dev, +"a650 SQE ucode is too old. Have version %x need at least %x\n" , + buf[0 ] &0xfff ,0x195 ); + } + +/* +* When a660 is added those targets should return true here +* since those have all the critical security fixes built in +* from the start +*/
Or we can just initialize 'ret' as true.
-Akhil
Quoted 13 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +3
-1+ } +out:msm_gem_put_vaddr (obj); +return ret; }static int a6xx_ucode_init (struct msm_gpu *gpu)@@ -566,7 +611,13 @@ static int a6xx_ucode_init(struct msm_gpu *gpu) }msm_gem_object_set_name (a6xx_gpu->sqe_bo,"sqefw" ); -a6xx_ucode_check_version (a6xx_gpu, a6xx_gpu->sqe_bo);
drivers/gpu/drm/msm/adreno/a6xx_gpu.c static int a6xx_ucode_init(struct msm_gpu *gpu) · line 623
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +7
-0+if (!a6xx_ucode_check_version (a6xx_gpu, a6xx_gpu->sqe_bo)) { +msm_gem_unpin_iova (a6xx_gpu->sqe_bo, gpu->aspace); +drm_gem_object_put (a6xx_gpu->sqe_bo); + + a6xx_gpu->sqe_bo =NULL ; +return -EPERM ; + } } gpu_write64(gpu, REG_A6XX_CP_SQE_INSTR_BASE_LO,
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 85 lines · Akhil P Oommen
Quoted 84 lines · Jordan Crouse
Most a6xx targets have security issues that were fixed with new versions of the microcode(s). Make sure that we are booting with a safe version of the microcode for the target and print a message and error if not.
v2: Add more informative error messages and fix typos
Signed-off-by Jordan Crouse <[email protected]>---
drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 77 ++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 13 deletions(-)drivers/gpu/drm/msm/adreno/a6xx_gpu.c +47
-12@@ -522,28 +522,73 @@ static int a6xx_cp_init(struct msm_gpu *gpu)return a6xx_idle (gpu, ring) ?0 : -EINVAL ; } -static void a6xx_ucode_check_version (struct a6xx_gpu *a6xx_gpu, +/* +* Check that the microcode version is new enough to include several key +* security fixes. Return true if the ucode is safe. +*/ +static bool a6xx_ucode_check_version (struct a6xx_gpu *a6xx_gpu,struct drm_gem_object *obj) { +struct adreno_gpu *adreno_gpu = &a6xx_gpu->base; +struct msm_gpu *gpu = &adreno_gpu->base;u32 *buf =msm_gem_get_vaddr (obj); +bool ret = false;if (IS_ERR (buf)) -return ; +return false;/* -* If the lowest nibble is 0xa that is an indication that this microcode -* has been patched. The actual version is in dword [3] but we only care -* about the patchlevel which is the lowest nibble of dword [3] -* -* Otherwise check that the firmware is greater than or equal to 1.90 -* which was the first version that had this fix built in +* Targets up to a640 (a618, a630 and a640) need to check for a +* microcode version that is patched to support the whereami opcode or +* one that is new enough to include it by default. */ -if (((buf[0 ] &0xf ) ==0xa ) && (buf[2 ] &0xf ) >=1 ) - a6xx_gpu->has_whereami = true; -else if ((buf[0 ] &0xfff ) >0x190 ) - a6xx_gpu->has_whereami = true; +if (adreno_is_a618 (adreno_gpu) ||adreno_is_a630 (adreno_gpu) || +adreno_is_a640 (adreno_gpu)) { +/* +* If the lowest nibble is 0xa that is an indication that this +* microcode has been patched. The actual version is in dword +* [3] but we only care about the patchlevel which is the lowest +* nibble of dword [3] +* +* Otherwise check that the firmware is greater than or equal +* to 1.90 which was the first version that had this fix built +* in +*/ +if ((((buf[0 ] &0xf ) ==0xa ) && (buf[2 ] &0xf ) >=1 ) || + (buf[0 ] &0xfff ) >=0x190 ) { + a6xx_gpu->has_whereami = true; + ret = true; + goto out; + } +DRM_DEV_ERROR (&gpu->pdev->dev, +"a630 SQE ucode is too old. Have version %x need at least %x\n" , + buf[0 ] &0xfff ,0x190 ); + }else { +/* +* a650 tier targets don't need whereami but still need to be +* equal to or newer than 1.95 for other security fixes +*/ +if (adreno_is_a650 (adreno_gpu)) { +if ((buf[0 ] &0xfff ) >=0x195 ) { + ret = true; + goto out; + } + +DRM_DEV_ERROR (&gpu->pdev->dev, +"a650 SQE ucode is too old. Have version %x need at least %x\n" , + buf[0 ] &0xfff ,0x195 );
Quoted 8 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c static int a6xx_cp_init(struct msm_gpu *gpu) · line 587
Quoted 7 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +7
-0+ } + +/* +* When a660 is added those targets should return true here +* since those have all the critical security fixes built in +* from the start +*/ Or we can just initialize 'ret' as true.
I thought about it and I think I want to force an accept list here instead of letting new targets get by with an implicit pass.
Jordan
Quoted 22 lines
-Akhil
Quoted 20 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +10
-1+ } +out:msm_gem_put_vaddr (obj); +return ret; }static int a6xx_ucode_init (struct msm_gpu *gpu)@@ -566,7 +611,13 @@ static int a6xx_ucode_init(struct msm_gpu *gpu) }msm_gem_object_set_name (a6xx_gpu->sqe_bo,"sqefw" ); -a6xx_ucode_check_version (a6xx_gpu, a6xx_gpu->sqe_bo); +if (!a6xx_ucode_check_version (a6xx_gpu, a6xx_gpu->sqe_bo)) { +msm_gem_unpin_iova (a6xx_gpu->sqe_bo, gpu->aspace); +drm_gem_object_put (a6xx_gpu->sqe_bo); + + a6xx_gpu->sqe_bo =NULL ; +return -EPERM ; + } } gpu_write64(gpu, REG_A6XX_CP_SQE_INSTR_BASE_LO,
Signature · 6 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Akhil P Oommen
Reviewed-byQuoted 45 lines · Jordan Crouse
Quoted 44 lines · Akhil P Oommen
Quoted 43 lines · Jordan Crouse
Most a6xx targets have security issues that were fixed with new versions of the microcode(s). Make sure that we are booting with a safe version of the microcode for the target and print a message and error if not.
v2: Add more informative error messages and fix typos
Signed-off-by Jordan Crouse <[email protected]>---
drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 77 ++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 13 deletions(-)drivers/gpu/drm/msm/adreno/a6xx_gpu.c +11
-8@@ -522,28 +522,73 @@ static int a6xx_cp_init(struct msm_gpu *gpu)return a6xx_idle (gpu, ring) ?0 : -EINVAL ; } -static void a6xx_ucode_check_version (struct a6xx_gpu *a6xx_gpu, +/* +* Check that the microcode version is new enough to include several key +* security fixes. Return true if the ucode is safe. +*/ +static bool a6xx_ucode_check_version (struct a6xx_gpu *a6xx_gpu,struct drm_gem_object *obj) { +struct adreno_gpu *adreno_gpu = &a6xx_gpu->base; +struct msm_gpu *gpu = &adreno_gpu->base;u32 *buf =msm_gem_get_vaddr (obj); +bool ret = false;if (IS_ERR (buf)) -return ; +return false;/* -* If the lowest nibble is 0xa that is an indication that this microcode -* has been patched. The actual version is in dword [3] but we only care -* about the patchlevel which is the lowest nibble of dword [3] -* -* Otherwise check that the firmware is greater than or equal to 1.90 -* which was the first version that had this fix built in +* Targets up to a640 (a618, a630 and a640) need to check for a +* microcode version that is patched to support the whereami opcode or
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c static int a6xx_cp_init(struct msm_gpu *gpu) · line 546
Quoted 8 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +3
-4+* one that is new enough to include it by default. */ -if (((buf[0 ] &0xf ) ==0xa ) && (buf[2 ] &0xf ) >=1 ) - a6xx_gpu->has_whereami = true; -else if ((buf[0 ] &0xfff ) >0x190 ) - a6xx_gpu->has_whereami = true; +if (adreno_is_a618 (adreno_gpu) ||adreno_is_a630 (adreno_gpu) || +adreno_is_a640 (adreno_gpu)) {
nit: I feel a 'switch(revn)' would be more readable.
-Akhil
Quoted 42 lines
Quoted 33 lines
Quoted 33 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +33
-0+/* +* If the lowest nibble is 0xa that is an indication that this +* microcode has been patched. The actual version is in dword +* [3] but we only care about the patchlevel which is the lowest +* nibble of dword [3] +* +* Otherwise check that the firmware is greater than or equal +* to 1.90 which was the first version that had this fix built +* in +*/ +if ((((buf[0 ] &0xf ) ==0xa ) && (buf[2 ] &0xf ) >=1 ) || + (buf[0 ] &0xfff ) >=0x190 ) { + a6xx_gpu->has_whereami = true; + ret = true; + goto out; + } +DRM_DEV_ERROR (&gpu->pdev->dev, +"a630 SQE ucode is too old. Have version %x need at least %x\n" , + buf[0 ] &0xfff ,0x190 ); + }else { +/* +* a650 tier targets don't need whereami but still need to be +* equal to or newer than 1.95 for other security fixes +*/ +if (adreno_is_a650 (adreno_gpu)) { +if ((buf[0 ] &0xfff ) >=0x195 ) { + ret = true; + goto out; + } + +DRM_DEV_ERROR (&gpu->pdev->dev, +"a650 SQE ucode is too old. Have version %x need at least %x\n" , + buf[0 ] &0xfff ,0x195 );Quoted 8 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c static int a6xx_cp_init(struct msm_gpu *gpu) · line 587
Quoted 7 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +7
-0+ } + +/* +* When a660 is added those targets should return true here +* since those have all the critical security fixes built in +* from the start +*/ Or we can just initialize 'ret' as true.
Quoted 28 lines
I thought about it and I think I want to force an accept list here instead of letting new targets get by with an implicit pass.
Jordan
Quoted 22 lines
-Akhil
Quoted 20 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +10
-1+ } +out:msm_gem_put_vaddr (obj); +return ret; }static int a6xx_ucode_init (struct msm_gpu *gpu)@@ -566,7 +611,13 @@ static int a6xx_ucode_init(struct msm_gpu *gpu) }msm_gem_object_set_name (a6xx_gpu->sqe_bo,"sqefw" ); -a6xx_ucode_check_version (a6xx_gpu, a6xx_gpu->sqe_bo); +if (!a6xx_ucode_check_version (a6xx_gpu, a6xx_gpu->sqe_bo)) { +msm_gem_unpin_iova (a6xx_gpu->sqe_bo, gpu->aspace); +drm_gem_object_put (a6xx_gpu->sqe_bo); + + a6xx_gpu->sqe_bo =NULL ; +return -EPERM ; + } } gpu_write64(gpu, REG_A6XX_CP_SQE_INSTR_BASE_LO,
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hello,
Quoted 7 lines · Jordan Crouse
Most a6xx targets have security issues that were fixed with new versions of the microcode(s). Make sure that we are booting with a safe version of the microcode for the target and print a message and error if not.
v2: Add more informative error messages and fix typos
Signed-off-by Jordan Crouse <[email protected]>
[skipped]
drivers/gpu/drm/msm/adreno/a6xx_gpu.c static int a6xx_cp_init(struct msm_gpu *gpu) · line 576
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +10
-0+ }else { +/* +* a650 tier targets don't need whereami but still need to be +* equal to or newer than 1.95 for other security fixes +*/ +if (adreno_is_a650 (adreno_gpu)) { +if ((buf[0 ] &0xfff ) >=0x195 ) { + ret = true; + goto out; + }
I think this is incorrect. The latest firmware i have here also fails this check, with the buf[0] = 0x016dd099, so buf[0] & 0xfff = 0x099.
Could you please confirm the versioning?
Quoted 33 lines
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +21
-1+ +DRM_DEV_ERROR (&gpu->pdev->dev, +"a650 SQE ucode is too old. Have version %x need at least %x\n" , + buf[0 ] &0xfff ,0x195 ); + } + +/* +* When a660 is added those targets should return true here +* since those have all the critical security fixes built in +* from the start +*/ + } +out:msm_gem_put_vaddr (obj); +return ret; }static int a6xx_ucode_init (struct msm_gpu *gpu)@@ -566,7 +611,13 @@ static int a6xx_ucode_init(struct msm_gpu *gpu) }msm_gem_object_set_name (a6xx_gpu->sqe_bo,"sqefw" ); -a6xx_ucode_check_version (a6xx_gpu, a6xx_gpu->sqe_bo); +if (!a6xx_ucode_check_version (a6xx_gpu, a6xx_gpu->sqe_bo)) { +msm_gem_unpin_iova (a6xx_gpu->sqe_bo, gpu->aspace); +drm_gem_object_put (a6xx_gpu->sqe_bo); + + a6xx_gpu->sqe_bo =NULL ; +return -EPERM ; + } } gpu_write64(gpu, REG_A6XX_CP_SQE_INSTR_BASE_LO,
Signature · 6 lines
With best wishes Dmitry _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
This patch was applied to qcom/linux.git (refs/heads/for-next):
Hello:
This patch was applied to qcom/linux.git (refs/heads/for-next):
Quoted 9 lines · On Tue, 9 Feb 2021 17:52:05 -0700 you wrote:
Most a6xx targets have security issues that were fixed with new versions of the microcode(s). Make sure that we are booting with a safe version of the microcode for the target and print a message and error if not.
v2: Add more informative error messages and fix typos
Signed-off-by Jordan Crouse <[email protected]>[...]
Here is the summary with links:
- [v2] drm/msm: a6xx: Make sure the SQE microcode is safe
https://git.kernel.org/qcom/c/8490f02a3ca4
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html