* [PATCH v2 0/3] drm/panthor: Coherency related fixes
@ 2024-10-30 22:54 Akash Goel
2024-10-30 22:54 ` [PATCH v2 1/3] drm/panthor: Update memattr programing to align with GPU spec Akash Goel
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Akash Goel @ 2024-10-30 22:54 UTC (permalink / raw)
To: boris.brezillon, liviu.dudau, steven.price
Cc: dri-devel, linux-kernel, mihail.atanassov, ketil.johnsen,
florent.tomasin, maarten.lankhorst, mripard, tzimmermann,
airlied, daniel, nd, 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) 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(-)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] drm/panthor: Update memattr programing to align with GPU spec
2024-10-30 22:54 [PATCH v2 0/3] drm/panthor: Coherency related fixes Akash Goel
@ 2024-10-30 22:54 ` Akash Goel
2024-10-30 22:54 ` [PATCH v2 2/3] drm/panthor: Explicitly set the coherency mode Akash Goel
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Akash Goel @ 2024-10-30 22:54 UTC (permalink / raw)
To: boris.brezillon, liviu.dudau, steven.price
Cc: dri-devel, linux-kernel, mihail.atanassov, ketil.johnsen,
florent.tomasin, maarten.lankhorst, mripard, tzimmermann,
airlied, daniel, nd, Akash Goel
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
Signed-off-by: Akash Goel <akash.goel@arm.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Steven Price <steven.price@arm.com>
---
drivers/gpu/drm/panthor/panthor_mmu.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index f3ee5d2753f1..f522a116c1b1 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1927,7 +1927,7 @@ struct panthor_heap_pool *panthor_vm_get_heap_pool(struct panthor_vm *vm, bool c
return 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);
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] drm/panthor: Explicitly set the coherency mode
2024-10-30 22:54 [PATCH v2 0/3] drm/panthor: Coherency related fixes Akash Goel
2024-10-30 22:54 ` [PATCH v2 1/3] drm/panthor: Update memattr programing to align with GPU spec Akash Goel
@ 2024-10-30 22:54 ` Akash Goel
2024-10-30 22:54 ` [PATCH v2 3/3] drm/panthor: Prevent potential overwrite of buffer objects Akash Goel
2024-11-20 11:50 ` [PATCH v2 0/3] drm/panthor: Coherency related fixes Liviu Dudau
3 siblings, 0 replies; 5+ messages in thread
From: Akash Goel @ 2024-10-30 22:54 UTC (permalink / raw)
To: boris.brezillon, liviu.dudau, steven.price
Cc: dri-devel, linux-kernel, mihail.atanassov, ketil.johnsen,
florent.tomasin, maarten.lankhorst, mripard, tzimmermann,
airlied, daniel, nd, Akash Goel
This 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
Signed-off-by: Akash Goel <akash.goel@arm.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Steven Price <steven.price@arm.com>
---
drivers/gpu/drm/panthor/panthor_device.c | 22 +++++++++++++++++++++-
drivers/gpu/drm/panthor/panthor_gpu.c | 9 +++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c
index 4082c8f2951d..984615f4ed27 100644
--- a/drivers/gpu/drm/panthor/panthor_device.c
+++ b/drivers/gpu/drm/panthor/panthor_device.c
@@ -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);
diff --git a/drivers/gpu/drm/panthor/panthor_gpu.c b/drivers/gpu/drm/panthor/panthor_gpu.c
index 5251d8764e7d..1e24f08a519a 100644
--- a/drivers/gpu/drm/panthor/panthor_gpu.c
+++ b/drivers/gpu/drm/panthor/panthor_gpu.c
@@ -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);
}
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] drm/panthor: Prevent potential overwrite of buffer objects
2024-10-30 22:54 [PATCH v2 0/3] drm/panthor: Coherency related fixes Akash Goel
2024-10-30 22:54 ` [PATCH v2 1/3] drm/panthor: Update memattr programing to align with GPU spec Akash Goel
2024-10-30 22:54 ` [PATCH v2 2/3] drm/panthor: Explicitly set the coherency mode Akash Goel
@ 2024-10-30 22:54 ` Akash Goel
2024-11-20 11:50 ` [PATCH v2 0/3] drm/panthor: Coherency related fixes Liviu Dudau
3 siblings, 0 replies; 5+ messages in thread
From: Akash Goel @ 2024-10-30 22:54 UTC (permalink / raw)
To: boris.brezillon, liviu.dudau, steven.price
Cc: dri-devel, linux-kernel, mihail.atanassov, ketil.johnsen,
florent.tomasin, maarten.lankhorst, mripard, tzimmermann,
airlied, daniel, nd, Akash Goel
All 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
Signed-off-by: Akash Goel <akash.goel@arm.com>
---
drivers/gpu/drm/panthor/panthor_gem.h | 10 ++++++++++
drivers/gpu/drm/panthor/panthor_mmu.c | 5 +++++
2 files changed, 15 insertions(+)
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
index e43021cf6d45..4b0f43f1edf1 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.h
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
@@ -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;
};
/**
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index f522a116c1b1..d8cc9e7d064e 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -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)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/3] drm/panthor: Coherency related fixes
2024-10-30 22:54 [PATCH v2 0/3] drm/panthor: Coherency related fixes Akash Goel
` (2 preceding siblings ...)
2024-10-30 22:54 ` [PATCH v2 3/3] drm/panthor: Prevent potential overwrite of buffer objects Akash Goel
@ 2024-11-20 11:50 ` Liviu Dudau
3 siblings, 0 replies; 5+ messages in thread
From: Liviu Dudau @ 2024-11-20 11:50 UTC (permalink / raw)
To: Akash Goel
Cc: boris.brezillon, steven.price, dri-devel, linux-kernel,
mihail.atanassov, ketil.johnsen, florent.tomasin,
maarten.lankhorst, mripard, tzimmermann, airlied, daniel, nd
On Wed, Oct 30, 2024 at 10:54:04PM +0000, Akash Goel wrote:
> 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
Pushed the first two patches to drm-misc-next.
Best regards,
Liviu
> 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(-)
>
> --
> 2.25.1
>
--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-20 11:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-30 22:54 [PATCH v2 0/3] drm/panthor: Coherency related fixes Akash Goel
2024-10-30 22:54 ` [PATCH v2 1/3] drm/panthor: Update memattr programing to align with GPU spec Akash Goel
2024-10-30 22:54 ` [PATCH v2 2/3] drm/panthor: Explicitly set the coherency mode Akash Goel
2024-10-30 22:54 ` [PATCH v2 3/3] drm/panthor: Prevent potential overwrite of buffer objects Akash Goel
2024-11-20 11:50 ` [PATCH v2 0/3] drm/panthor: Coherency related fixes Liviu Dudau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®