drm/panthor: Coherency related fixes
Subsystems (3)
v2 cover drm/panthor: Coherency related fixes
This patch series contains 3 cache coherency related fixes for the Panthor driver.
- The first fix, regarding the Inner-shareability, is mandatory to ensure things work on all platforms (including Juno FPGA) when no_coherency protocol is selected.
- The second fix regarding the coherency feature/enable register is required to avoid potential misalignment on certain platforms.
- The third fix, regarding the potential overwrite of buffer objects, has been prepared speculatively & it may not be required in practice.
v2:
- Added r-b tags for the first 2 patches
Akash Goel (3):
drm/panthor: Update memattr programing to align with GPU spec drm/panthor: Explicitly set the coherency mode drm/panthor: Prevent potential overwrite of buffer objects
drivers/gpu/drm/panthor/panthor_device.c | 22 ++++++++++++++++++- drivers/gpu/drm/panthor/panthor_gem.h | 10 +++++++++ drivers/gpu/drm/panthor/panthor_gpu.c | 9 ++++++++ drivers/gpu/drm/panthor/panthor_mmu.c | 28 +++++++++++++++++------- 4 files changed, 60 insertions(+), 9 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/3 drm/panthor: Update memattr programing to align with GPU spec
Mali GPU Arch spec forbids the GPU PTEs to indicate Inner or Outer shareability when no_coherency protocol is selected. Doing so results in unexpected or undesired snooping of the CPU caches on some platforms, such as Juno FPGA, causing functional issues. For example the boot of MCU firmware fails as GPU ends up reading stale data for the FW memory pages from the CPU's cache. The FW memory pages are initialized with uncached mapping when the device is not reported to be dma-coherent. The shareability bits are set to inner-shareable when IOMMU_CACHE flag is passed to map_pages() callback and IOMMU_CACHE flag is passed by Panthor driver when memory needs to be mapped as cached on the GPU side.
IOMMU_CACHE seems to imply cache coherent and is probably not fit for purpose for the memory that is mapped as cached on GPU side but doesn't need to remain coherent with the CPU.
This commit updates the programming of MEMATTR register to use MIDGARD_INNER instead of CPU_INNER when coherency is disabled. That way the inner-shareability specified in the GPU PTEs would map to Mali's internal-shareable mode, which is always supported by the GPU regardless of the coherency protocal and is required by the Userspace driver to ensure coherency between the shader cores.
v2:
- Added R-b tags
--- drivers/gpu/drm/panthor/panthor_mmu.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/gpu/drm/panthor/panthor_mmu.c +15 -8
@@ -1927,7 +1927,7 @@ struct panthor_heap_pool *panthor_vm_get_heap_pool(struct panthor_vm *vm, bool creturn pool; } -static u64 mair_to_memattr (u64 mair) +static u64 mair_to_memattr (u64 mair,bool coherent) {u64 memattr =0 ;u32 i;
@@ -1946,14 +1946,21 @@ static u64 mair_to_memattr(u64 mair)AS_MEMATTR_AARCH64_SH_MIDGARD_INNER |AS_MEMATTR_AARCH64_INNER_ALLOC_EXPL (false, false); }else { -/* Use SH_CPU_INNER mode so SH_IS, which is used when -* IOMMU_CACHE is set, actually maps to the standard -* definition of inner-shareable and not Mali's -* internal-shareable mode. -*/ out_attr =AS_MEMATTR_AARCH64_INNER_OUTER_WB | -AS_MEMATTR_AARCH64_SH_CPU_INNER |AS_MEMATTR_AARCH64_INNER_ALLOC_EXPL (inner &1 , inner &2 ); +/* Use SH_MIDGARD_INNER mode when device isn't coherent, +* so SH_IS, which is used when IOMMU_CACHE is set, maps +* to Mali's internal-shareable mode. As per the Mali +* Spec, inner and outer-shareable modes aren't allowed +* for WB memory when coherency is disabled. +* Use SH_CPU_INNER mode when coherency is enabled, so +* that SH_IS actually maps to the standard definition of +* inner-shareable. +*/ +if (!coherent) + out_attr |=AS_MEMATTR_AARCH64_SH_MIDGARD_INNER ; +else + out_attr |=AS_MEMATTR_AARCH64_SH_CPU_INNER ; } memattr |= (u64 )out_attr << (8 * i);
@@ -2325,7 +2332,7 @@ panthor_vm_create(struct panthor_device *ptdev, bool for_mcu, goto err_sched_fini; mair =io_pgtable_ops_to_pgtable (vm->pgtbl_ops)->cfg.arm_lpae_s1_cfg.mair; - vm->memattr =mair_to_memattr (mair); + vm->memattr =mair_to_memattr (mair, ptdev->coherent);mutex_lock (&ptdev->mmu->vm.lock);list_add_tail (&vm->node, &ptdev->mmu->vm.list);
Signature · 1 line
2.25.1
PATCH v2 2/3 drm/panthor: Explicitly set the coherency mode
In reply to Akash GoelThis commit fixes the potential misalignment between the value of device tree property "dma-coherent" and default value of COHERENCY_ENABLE register.
Panthor driver didn't explicitly program the COHERENCY_ENABLE register with the desired coherency mode. The default value of COHERENCY_ENABLE register is implementation defined, so it may not be always aligned with the "dma-coherent" property value.
The commit also checks the COHERENCY_FEATURES register to confirm that the coherency protocol is actually supported or not.
v2:
- Added R-b tags
--- drivers/gpu/drm/panthor/panthor_device.c | 22 +++++++++++++++++++++- drivers/gpu/drm/panthor/panthor_gpu.c | 9 +++++++++ 2 files changed, 30 insertions(+), 1 deletion(-)
drivers/gpu/drm/panthor/panthor_device.c +21 -1
@@ -22,6 +22,24 @@#include "panthor_regs.h" #include "panthor_sched.h" +static int panthor_gpu_coherency_init (struct panthor_device *ptdev) +{ + ptdev->coherent =device_get_dma_attr (ptdev->base.dev) ==DEV_DMA_COHERENT ; + +if (!ptdev->coherent) +return 0 ; + +/* Check if the ACE-Lite coherency protocol is actually supported by the GPU. +* ACE protocol has never been supported for command stream frontend GPUs. +*/ +if ((gpu_read (ptdev,GPU_COHERENCY_FEATURES ) & +GPU_COHERENCY_PROT_BIT (ACE_LITE ))) +return 0 ; + +drm_err (&ptdev->base,"Coherency not supported by the device" ); +return -ENOTSUPP ; +} +static int panthor_clk_init (struct panthor_device *ptdev) { ptdev->clks.core =devm_clk_get (ptdev->base.dev,NULL );
@@ -156,7 +174,9 @@ int panthor_device_init(struct panthor_device *ptdev)struct page *p;int ret; - ptdev->coherent =device_get_dma_attr (ptdev->base.dev) ==DEV_DMA_COHERENT ; + ret =panthor_gpu_coherency_init (ptdev); +if (ret) +return ret;init_completion (&ptdev->unplug.done); ret =drmm_mutex_init (&ptdev->base, &ptdev->unplug.lock);
drivers/gpu/drm/panthor/panthor_gpu.c +9 -0
@@ -77,6 +77,12 @@ static const struct panthor_model gpu_models[] = { GPU_IRQ_RESET_COMPLETED | \ GPU_IRQ_CLEAN_CACHES_COMPLETED) +static void panthor_gpu_coherency_set (struct panthor_device *ptdev) +{ +gpu_write (ptdev,GPU_COHERENCY_PROTOCOL , + ptdev->coherent ?GPU_COHERENCY_PROT_BIT (ACE_LITE ) :GPU_COHERENCY_NONE ); +} +static void panthor_gpu_init_info (struct panthor_device *ptdev) {const struct panthor_model *model;
@@ -365,6 +371,9 @@ int panthor_gpu_l2_power_on(struct panthor_device *ptdev) hweight64(ptdev->gpu_info.shader_present)); } +/* Set the desired coherency mode before the power up of L2 */ +panthor_gpu_coherency_set (ptdev); +return panthor_gpu_power_on (ptdev,L2 ,1 ,20000 ); }
Signature · 1 line
2.25.1
PATCH v2 3/3 drm/panthor: Prevent potential overwrite of buffer objects
In reply to Akash GoelAll CPU mappings are forced as uncached for Panthor buffer objects when system(IO) coherency is disabled. Physical backing for Panthor BOs is allocated by shmem, which clears the pages also after allocation. But there is no explicit cache flush done after the clearing of pages. So it could happen that there are dirty cachelines in the CPU cache for the BOs, when they are accessed from the CPU side through uncached CPU mapping, and the eviction of cachelines overwrites the data of BOs.
This commit tries to avoid the potential overwrite scenario.
v2:
- no change
--- drivers/gpu/drm/panthor/panthor_gem.h | 10 ++++++++++ drivers/gpu/drm/panthor/panthor_mmu.c | 5 +++++ 2 files changed, 15 insertions(+)
drivers/gpu/drm/panthor/panthor_gem.h +10 -0
@@ -46,6 +46,16 @@ struct panthor_gem_object {/** @flags: Combination of drm_panthor_bo_flags flags. */ u32 flags; + +/** +* @cleaned: The buffer object pages have been cleaned. +* +* There could be dirty CPU cachelines for the pages of buffer object +* after allocation, as shmem will zero out the pages. The cachelines +* need to be cleaned if the pages are going to be accessed with an +* uncached CPU mapping. +*/ +bool cleaned; };/**
drivers/gpu/drm/panthor/panthor_mmu.c +5 -0
@@ -1249,6 +1249,11 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx, op_ctx->map.sgt = sgt; +if (bo->base.map_wc && !bo->cleaned) { +dma_sync_sgtable_for_device (vm->ptdev->base.dev, sgt,DMA_TO_DEVICE ); + bo->cleaned = true; + } + preallocated_vm_bo =drm_gpuvm_bo_create (&vm->base, &bo->base.base);if (!preallocated_vm_bo) {if (!bo->base.base.import_attach)
Signature · 1 line
2.25.1
Liviu Dudau
maintainerQuoted 10 lines · Akash Goel
This patch series contains 3 cache coherency related fixes for the Panthor driver.
- The first fix, regarding the Inner-shareability, is mandatory to ensure things work on all platforms (including Juno FPGA) whenno_coherencyprotocol is selected.
- The second fix regarding the coherency feature/enable register is required to avoid potential misalignment on certain platforms.
- The third fix, regarding the potential overwrite of buffer objects, has been prepared speculatively & it may not be required in practice.
Quoted 6 lines
v2:
- Added r-b tags for the first 2 patchesAkash Goel (3):
drm/panthor: Update memattr programing to align with GPU spec drm/panthor: Explicitly set the coherency mode
Pushed the first two patches to drm-misc-next.
Best regards,
Liviu
Quoted 11 lines
drm/panthor: Prevent potential overwrite of buffer objects
drivers/gpu/drm/panthor/panthor_device.c | 22 ++++++++++++++++++- drivers/gpu/drm/panthor/panthor_gem.h | 10 +++++++++ drivers/gpu/drm/panthor/panthor_gpu.c | 9 ++++++++ drivers/gpu/drm/panthor/panthor_mmu.c | 28 +++++++++++++++++------- 4 files changed, 60 insertions(+), 9 deletions(-)Signature · 1 line
2.25.1
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯