* [PATCH v2 0/7] drm/panthor: Protected mode support for Mali CSF GPUs
@ 2026-07-12 13:54 Ketil Johnsen
2026-07-12 13:54 ` [PATCH v2 1/7] drm/panthor: De-duplicate FW memory section sync Ketil Johnsen
` (6 more replies)
0 siblings, 7 replies; 11+ messages in thread
From: Ketil Johnsen @ 2026-07-12 13:54 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, Ketil Johnsen
Hi,
This is a patch series covering the support for protected mode execution in
Mali Panthor CSF kernel driver.
It builds on the initial RFC posted by Florent Tomasin back in January of 2025.
The initial RFC can be found here:
https://lore.kernel.org/lkml/cover.1738228114.git.florent.tomasin@arm.com/
The Mali CSF GPUs come with the support for protected mode execution at the
HW level. This feature requires two main changes in the kernel driver:
1) Configure the GPU with a protected buffer. The system must provide a DMA
heap from which the driver can get protected buffers.
It can be a carved-out memory or dynamically allocated protected memory region.
Some system includes a trusted FW which is in charge of the protected memory.
This problem is integration specific and the responsibility to allocate the
required protected memory from the correct and system specific DMA heap is
left to user space (Mesa). Panthor CSF driver must be handed the needed
buffers via new IOCTLs.
2) Handle enter and exit of the GPU HW from normal to protected mode of execution.
FW sends a request for protected mode entry to the kernel driver.
The acknowledgment of that request is a scheduling decision. Effectively,
protected mode execution should not overrule normal mode of execution.
A fair distribution of execution time will guaranty the overall performance
of the device, including the UI (usually executing in normal mode),
will not regress when a protected mode job is submitted by an application.
Background
----------
Current Mali Panthor CSF driver does not allow a user space application to
execute protected jobs on the GPU. This use case is quite common on end-user-device.
A user may want to watch a video or render content that is under a "Digital Right
Management" protection, or launch an application with user private data.
1) User-space:
In order for an application to execute protected jobs on a Mali CSF GPU the
user space application must submit jobs to the GPU within a "protected regions"
(range of commands to execute in protected mode).
Find here an example of a command buffer that contains protected commands:
```
<--- Normal mode ---><--- Protected mode ---><--- Normal mode --->
+-------------------------------------------------------------------------+
| ... | CMD_0 | ... | CMD_N | PROT_REGION | CMD_N+1 | ... | CMD_N+M | ... |
+-------------------------------------------------------------------------+
```
The PROT_REGION command acts as a barrier to notify the HW of upcoming
protected jobs. It also defines the number of commands to execute in protected
mode.
The Mesa definition of the opcode can be found here:
https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/panfrost/lib/genxml/v10.xml?ref_type=heads#L763
2) Kernel-space:
When loading the FW image, the Kernel driver must also load the data section of
CSF FW that comes from the protected memory, in order to allow FW to execute in
protected mode.
Important: this memory is not owned by any process. It is a GPU device level
protected memory.
In addition, when a CSG (group) is created, it must have a protected suspend buffer.
This memory is allocated within the kernel but bound to a specific CSG that belongs
to a process. The kernel owns this allocation and does not allow user space mapping.
The format of the data in this buffer is only known by the FW and does not need to
be shared with other entities. The purpose of this buffer is the same as the normal
suspend buffer but for protected mode. FW will use it to suspend the execution of
PROT_REGION before returning to normal mode of execution.
Design decisions
----------------
The earlier versions (RFC and v1) relied on in-kernel allocation of protected
DMA-bufs, both for the required FW memory (system wide), and per group
suspend buffers (per process). This is no longer needed.
Starting with v2, this is now changed and it is user space which is responsible
for supplying these buffers.
Only a user space processes with elevated privileges (CAP_SYS_MODULE) is trusted
to provide the system wide protected FW memory. This only needs to happen once
per boot, and is needed before any non-privileged processes can make use of
protected rendering.
The Mali Panthor CSF kernel driver will handle enter/exit of protected
mode with a fair consideration of the job scheduling.
If the system integrator does not provide a protected DMA heap, the driver
will not allow any protected mode execution.
Patch series
------------
[PATCHES 1-5]:
These are refactoring to aid the implementation of the protected rendering
feature itself.
* drm/panthor: De-duplicate FW memory section sync
* drm/panthor: Minor scheduler refactoring
* drm/panthor: Explicit expansion of locked VM region
* drm/panthor: Pass drm_file instead of panthor_file - NEW
* drm/panthor: Don't allocate protm_suspend_buf - NEW
[PATCH 6]:
This patch implements the logic to handle enter/exit of the GPU protected
mode in Panthor CSF driver.
Note: To ease the handling of faults from protected mode, only a single CSG is
allowed to execute while in protected mode. It must be the top priority one.
* drm/panthor: Add support for entering and exiting protected mode
[PATCH 7]:
The final patch exposes this feature via the uAPI and adds the necessary
handling/use of user space provided protected memory.
* drm/panthor: Expose protected rendering features - NEW
Testing
-------
1) Platform and development environment
Any platform containing a Mali CSF type of GPU and a protected memory allocator
that is based on DMA Heap can be used. For example, it can be a physical platform
or a simulator such as Arm Total Compute FVPs platforms. Reference to the latter:
https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms/Total%20Compute%20FVPs
2) Mesa:
PanVK support can be found here:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40044
Changes in v2:
- Patches 1-5: Refactoring/prep work patches are either new or have only minor changes.
- Patch 6: Heavily reworked, although conceptually similar to v1.
- Patch 7: New
- All old code for in-kernel allocation of protected memory has been dropped.
There are no longer any dependencies on dma-heap changes.
Boris Brezillon (2):
drm/panthor: Pass drm_file instead of panthor_file
drm/panthor: Expose protected rendering features
Florent Tomasin (2):
drm/panthor: Minor scheduler refactoring
drm/panthor: Add support for entering and exiting protected mode
Ketil Johnsen (3):
drm/panthor: De-duplicate FW memory section sync
drm/panthor: Explicit expansion of locked VM region
drm/panthor: Don't allocate protm_suspend_buf
drivers/gpu/drm/panthor/panthor_device.c | 1 +
drivers/gpu/drm/panthor/panthor_device.h | 36 ++
drivers/gpu/drm/panthor/panthor_drv.c | 59 ++-
drivers/gpu/drm/panthor/panthor_fw.c | 272 +++++++++--
drivers/gpu/drm/panthor/panthor_fw.h | 7 +
drivers/gpu/drm/panthor/panthor_gem.c | 102 +++--
drivers/gpu/drm/panthor/panthor_gem.h | 7 +-
drivers/gpu/drm/panthor/panthor_gpu.c | 53 ++-
drivers/gpu/drm/panthor/panthor_gpu.h | 4 +
drivers/gpu/drm/panthor/panthor_mmu.c | 123 +++--
drivers/gpu/drm/panthor/panthor_mmu.h | 6 +-
drivers/gpu/drm/panthor/panthor_sched.c | 545 +++++++++++++++++++----
drivers/gpu/drm/panthor/panthor_sched.h | 27 +-
include/uapi/drm/panthor_drm.h | 85 +++-
14 files changed, 1080 insertions(+), 247 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 1/7] drm/panthor: De-duplicate FW memory section sync
2026-07-12 13:54 [PATCH v2 0/7] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
@ 2026-07-12 13:54 ` Ketil Johnsen
2026-07-12 13:54 ` [PATCH v2 2/7] drm/panthor: Minor scheduler refactoring Ketil Johnsen
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Ketil Johnsen @ 2026-07-12 13:54 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, Ketil Johnsen
Handle the sync to device of FW memory sections inside
panthor_fw_init_section_mem() so that the callers do not have to.
This small improvement is also critical for protected FW sections,
so we avoid issuing memory transactions to protected memory from
CPU running in normal mode.
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
drivers/gpu/drm/panthor/panthor_fw.c | 22 ++++++----------------
1 file changed, 6 insertions(+), 16 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index 986151681b246..389f9182fac16 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -449,6 +449,7 @@ static void panthor_fw_init_section_mem(struct panthor_device *ptdev,
struct panthor_fw_section *section)
{
bool was_mapped = !!section->mem->kmap;
+ struct sg_table *sgt;
int ret;
if (!section->data.size &&
@@ -467,6 +468,11 @@ static void panthor_fw_init_section_mem(struct panthor_device *ptdev,
if (!was_mapped)
panthor_kernel_bo_vunmap(section->mem);
+
+ /* An sgt should have been requested when the kernel BO was GPU-mapped. */
+ sgt = to_panthor_bo(section->mem->obj)->dmap.sgt;
+ if (!drm_WARN_ON_ONCE(&ptdev->base, !sgt))
+ dma_sync_sgtable_for_device(ptdev->base.dev, sgt, DMA_TO_DEVICE);
}
/**
@@ -629,7 +635,6 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
section_size = hdr.va.end - hdr.va.start;
if (section_size) {
u32 cache_mode = hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_MASK;
- struct panthor_gem_object *bo;
u32 vm_map_flags = 0;
u64 va = hdr.va.start;
@@ -666,14 +671,6 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
}
panthor_fw_init_section_mem(ptdev, section);
-
- bo = to_panthor_bo(section->mem->obj);
-
- /* An sgt should have been requested when the kernel BO was GPU-mapped. */
- if (drm_WARN_ON_ONCE(&ptdev->base, !bo->dmap.sgt))
- return -EINVAL;
-
- dma_sync_sgtable_for_device(ptdev->base.dev, bo->dmap.sgt, DMA_TO_DEVICE);
}
if (hdr.va.start == CSF_MCU_SHARED_REGION_START)
@@ -727,17 +724,10 @@ panthor_reload_fw_sections(struct panthor_device *ptdev, bool full_reload)
struct panthor_fw_section *section;
list_for_each_entry(section, &ptdev->fw->sections, node) {
- struct sg_table *sgt;
-
if (!full_reload && !(section->flags & CSF_FW_BINARY_IFACE_ENTRY_WR))
continue;
panthor_fw_init_section_mem(ptdev, section);
-
- /* An sgt should have been requested when the kernel BO was GPU-mapped. */
- sgt = to_panthor_bo(section->mem->obj)->dmap.sgt;
- if (!drm_WARN_ON_ONCE(&ptdev->base, !sgt))
- dma_sync_sgtable_for_device(ptdev->base.dev, sgt, DMA_TO_DEVICE);
}
}
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 2/7] drm/panthor: Minor scheduler refactoring
2026-07-12 13:54 [PATCH v2 0/7] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
2026-07-12 13:54 ` [PATCH v2 1/7] drm/panthor: De-duplicate FW memory section sync Ketil Johnsen
@ 2026-07-12 13:54 ` Ketil Johnsen
2026-07-12 13:54 ` [PATCH v2 3/7] drm/panthor: Explicit expansion of locked VM region Ketil Johnsen
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Ketil Johnsen @ 2026-07-12 13:54 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, Florent Tomasin, Ketil Johnsen
From: Florent Tomasin <florent.tomasin@arm.com>
Refactor parts of the group scheduling logic into new helper functions.
This will simplify addition of the protected mode feature.
Remove redundant assignments of csg_slot.
Signed-off-by: Florent Tomasin <florent.tomasin@arm.com>
Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
drivers/gpu/drm/panthor/panthor_sched.c | 126 ++++++++++++++----------
1 file changed, 74 insertions(+), 52 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index 5b34032deff81..465f1b86249f8 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -2267,12 +2267,75 @@ tick_ctx_cleanup(struct panthor_scheduler *sched,
}
}
+static void
+tick_ctx_evict_group(struct panthor_scheduler *sched,
+ struct panthor_csg_slots_upd_ctx *upd_ctx,
+ struct panthor_group *group)
+{
+ struct panthor_device *ptdev = sched->ptdev;
+
+ if (drm_WARN_ON(&ptdev->base, group->csg_id < 0))
+ return;
+
+ csgs_upd_ctx_queue_reqs(ptdev, upd_ctx, group->csg_id,
+ group_can_run(group) ?
+ CSG_STATE_SUSPEND : CSG_STATE_TERMINATE,
+ CSG_STATE_MASK);
+}
+
+static void
+tick_ctx_reschedule_group(struct panthor_scheduler *sched,
+ struct panthor_csg_slots_upd_ctx *upd_ctx,
+ struct panthor_group *group,
+ int new_csg_prio)
+{
+ struct panthor_device *ptdev = sched->ptdev;
+ struct panthor_fw_csg_iface *csg_iface;
+ struct panthor_csg_slot *csg_slot;
+
+ if (group->csg_id < 0)
+ return;
+
+ csg_iface = panthor_fw_get_csg_iface(ptdev, group->csg_id);
+ csg_slot = &sched->csg_slots[group->csg_id];
+
+ if (csg_slot->priority != new_csg_prio) {
+ panthor_fw_update_reqs(csg_iface, endpoint_req,
+ CSG_EP_REQ_PRIORITY(new_csg_prio),
+ CSG_EP_REQ_PRIORITY_MASK);
+ csgs_upd_ctx_queue_reqs(ptdev, upd_ctx, group->csg_id,
+ csg_iface->output->ack ^ CSG_ENDPOINT_CONFIG,
+ CSG_ENDPOINT_CONFIG);
+ }
+}
+
+static void
+tick_ctx_schedule_group(struct panthor_scheduler *sched,
+ struct panthor_csg_slots_upd_ctx *upd_ctx,
+ struct panthor_group *group,
+ int csg_id, int csg_prio)
+{
+ struct panthor_device *ptdev = sched->ptdev;
+ struct panthor_fw_csg_iface *csg_iface =
+ panthor_fw_get_csg_iface(ptdev, csg_id);
+
+ group_bind_locked(group, csg_id);
+ csg_slot_prog_locked(ptdev, csg_id, csg_prio);
+
+ csgs_upd_ctx_queue_reqs(ptdev, upd_ctx, csg_id,
+ group->state == PANTHOR_CS_GROUP_SUSPENDED ?
+ CSG_STATE_RESUME : CSG_STATE_START,
+ CSG_STATE_MASK);
+ csgs_upd_ctx_queue_reqs(ptdev, upd_ctx, csg_id,
+ csg_iface->output->ack ^ CSG_ENDPOINT_CONFIG,
+ CSG_ENDPOINT_CONFIG);
+}
+
static void
tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *ctx)
{
struct panthor_group *group, *tmp;
struct panthor_device *ptdev = sched->ptdev;
- struct panthor_csg_slot *csg_slot;
int prio, new_csg_prio = MAX_CSG_PRIO, i;
u32 free_csg_slots = 0;
struct panthor_csg_slots_upd_ctx upd_ctx;
@@ -2282,44 +2345,13 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
for (prio = PANTHOR_CSG_PRIORITY_COUNT - 1; prio >= 0; prio--) {
/* Suspend or terminate evicted groups. */
- list_for_each_entry(group, &ctx->old_groups[prio], run_node) {
- bool term = !group_can_run(group);
- int csg_id = group->csg_id;
-
- if (drm_WARN_ON(&ptdev->base, csg_id < 0))
- continue;
-
- csg_slot = &sched->csg_slots[csg_id];
- csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id,
- term ? CSG_STATE_TERMINATE : CSG_STATE_SUSPEND,
- CSG_STATE_MASK);
- }
+ list_for_each_entry(group, &ctx->old_groups[prio], run_node)
+ tick_ctx_evict_group(sched, &upd_ctx, group);
/* Update priorities on already running groups. */
- list_for_each_entry(group, &ctx->groups[prio], run_node) {
- struct panthor_fw_csg_iface *csg_iface;
- int csg_id = group->csg_id;
-
- if (csg_id < 0) {
- new_csg_prio--;
- continue;
- }
-
- csg_slot = &sched->csg_slots[csg_id];
- csg_iface = panthor_fw_get_csg_iface(ptdev, csg_id);
- if (csg_slot->priority == new_csg_prio) {
- new_csg_prio--;
- continue;
- }
-
- panthor_fw_csg_endpoint_req_update(ptdev, csg_iface,
- CSG_EP_REQ_PRIORITY(new_csg_prio),
- CSG_EP_REQ_PRIORITY_MASK);
- csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id,
- csg_iface->output->ack ^ CSG_ENDPOINT_CONFIG,
- CSG_ENDPOINT_CONFIG);
- new_csg_prio--;
- }
+ list_for_each_entry(group, &ctx->groups[prio], run_node)
+ tick_ctx_reschedule_group(sched, &upd_ctx, group,
+ new_csg_prio--);
}
ret = csgs_upd_ctx_apply_locked(ptdev, &upd_ctx);
@@ -2355,28 +2387,18 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
for (prio = PANTHOR_CSG_PRIORITY_COUNT - 1; prio >= 0; prio--) {
list_for_each_entry(group, &ctx->groups[prio], run_node) {
int csg_id = group->csg_id;
- struct panthor_fw_csg_iface *csg_iface;
+ int csg_prio = new_csg_prio--;
- if (csg_id >= 0) {
- new_csg_prio--;
+ if (csg_id >= 0)
continue;
- }
csg_id = ffs(free_csg_slots) - 1;
if (drm_WARN_ON(&ptdev->base, csg_id < 0))
break;
- csg_iface = panthor_fw_get_csg_iface(ptdev, csg_id);
- csg_slot = &sched->csg_slots[csg_id];
- group_bind_locked(group, csg_id);
- csg_slot_prog_locked(ptdev, csg_id, new_csg_prio--);
- csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id,
- group->state == PANTHOR_CS_GROUP_SUSPENDED ?
- CSG_STATE_RESUME : CSG_STATE_START,
- CSG_STATE_MASK);
- csgs_upd_ctx_queue_reqs(ptdev, &upd_ctx, csg_id,
- csg_iface->output->ack ^ CSG_ENDPOINT_CONFIG,
- CSG_ENDPOINT_CONFIG);
+ tick_ctx_schedule_group(sched, &upd_ctx, group, csg_id,
+ csg_prio);
+
free_csg_slots &= ~BIT(csg_id);
}
}
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 3/7] drm/panthor: Explicit expansion of locked VM region
2026-07-12 13:54 [PATCH v2 0/7] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
2026-07-12 13:54 ` [PATCH v2 1/7] drm/panthor: De-duplicate FW memory section sync Ketil Johnsen
2026-07-12 13:54 ` [PATCH v2 2/7] drm/panthor: Minor scheduler refactoring Ketil Johnsen
@ 2026-07-12 13:54 ` Ketil Johnsen
2026-07-13 6:56 ` Boris Brezillon
2026-07-12 13:54 ` [PATCH v2 4/7] drm/panthor: Pass drm_file instead of panthor_file Ketil Johnsen
` (3 subsequent siblings)
6 siblings, 1 reply; 11+ messages in thread
From: Ketil Johnsen @ 2026-07-12 13:54 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, Ketil Johnsen
Currently the panthor_vm_lock_region() function will implicitly expand
an already locked VM region. This can be problematic because the caller
do not reliably know if it needs to call panthor_vm_unlock_region()
or not.
Worth noting, there is currently no known issues with this as the code
is written today.
This change introduces panthor_vm_expand_region() which will only work
if there is already a locked VM region. This again means that the
original lock and unlock functions can work as a pair. This pairing is
needed for subsequent protected memory changes.
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
drivers/gpu/drm/panthor/panthor_mmu.c | 87 +++++++++++++++++++--------
1 file changed, 62 insertions(+), 25 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index 1f6b9242279c2..b82b01013611c 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1774,20 +1774,49 @@ static const char *access_type_name(struct panthor_device *ptdev,
}
}
+static int panthor_vm_apply_as_lock(struct panthor_vm *vm, u64 region)
+{
+ struct panthor_device *ptdev = vm->ptdev;
+
+ lockdep_assert_held(&ptdev->mmu->as.slots_lock);
+
+ gpu_write64(ptdev->mmu->iomem, AS_LOCKADDR(vm->as.id), region);
+ return as_send_cmd_and_wait(ptdev, vm->as.id, AS_COMMAND_LOCK);
+}
+
static int panthor_vm_lock_region(struct panthor_vm *vm, u64 start, u64 size)
{
struct panthor_device *ptdev = vm->ptdev;
int ret = 0;
- /* sm_step_remap() can call panthor_vm_lock_region() to account for
- * the wider unmap needed when doing a partial huge page unamp. We
- * need to ignore the lock if it's already part of the locked region.
- */
- if (start >= vm->locked_region.start &&
- start + size <= vm->locked_region.start + vm->locked_region.size)
- return 0;
+ if (drm_WARN_ON(&ptdev->base, vm->locked_region.size))
+ return -EINVAL;
+
+ mutex_lock(&ptdev->mmu->as.slots_lock);
+ if (vm->as.id >= 0 && size) {
+ u64 region = pack_region_range(ptdev, &start, &size);
+
+ ret = panthor_vm_apply_as_lock(vm, region);
+ }
- /* sm_step_remap() may need a locked region that isn't a strict superset
+ if (!ret) {
+ vm->locked_region.start = start;
+ vm->locked_region.size = size;
+ }
+ mutex_unlock(&ptdev->mmu->as.slots_lock);
+
+ return ret;
+}
+
+static int panthor_vm_expand_locked_region(struct panthor_vm *vm,
+ u64 start, u64 size)
+{
+ struct panthor_device *ptdev = vm->ptdev;
+ u64 end;
+ int ret = 0;
+
+ /* This function is here to handle the following case:
+ * sm_step_remap() may need a locked region that isn't a strict superset
* of the original one because of having to extend unmap boundaries beyond
* it to deal with partial unmaps of transparent huge pages. What we want
* in those cases is to lock the union of both regions. The new region must
@@ -1795,25 +1824,30 @@ static int panthor_vm_lock_region(struct panthor_vm *vm, u64 start, u64 size)
* boundaries in a remap operation can only shift up or down respectively,
* but never otherwise.
*/
- if (vm->locked_region.size) {
- u64 end = max(vm->locked_region.start + vm->locked_region.size,
- start + size);
- drm_WARN_ON_ONCE(&vm->ptdev->base, (start + size <= vm->locked_region.start) ||
- (start >= vm->locked_region.start + vm->locked_region.size));
+ /* This function can only expand an already locked region */
+ if (drm_WARN_ON(&ptdev->base, !vm->locked_region.size))
+ return -EINVAL;
+
+ /* Early out if requested range is already locked */
+ if (start >= vm->locked_region.start &&
+ start + size <= vm->locked_region.start + vm->locked_region.size)
+ return 0;
- start = min(start, vm->locked_region.start);
- size = end - start;
- }
+ end = max(vm->locked_region.start + vm->locked_region.size,
+ start + size);
+
+ drm_WARN_ON_ONCE(&ptdev->base, (start + size <= vm->locked_region.start) ||
+ (start >= vm->locked_region.start + vm->locked_region.size));
+
+ start = min(start, vm->locked_region.start);
+ size = end - start;
mutex_lock(&ptdev->mmu->as.slots_lock);
if (vm->as.id >= 0 && size) {
- /* Lock the region that needs to be updated */
- gpu_write64(ptdev->mmu->iomem, AS_LOCKADDR(vm->as.id),
- pack_region_range(ptdev, &start, &size));
+ u64 region = pack_region_range(ptdev, &start, &size);
- /* If the lock succeeded, update the locked_region info. */
- ret = as_send_cmd_and_wait(ptdev, vm->as.id, AS_COMMAND_LOCK);
+ ret = panthor_vm_apply_as_lock(vm, region);
}
if (!ret) {
@@ -2367,11 +2401,14 @@ static int panthor_gpuva_sm_step_remap(struct drm_gpuva_op *op,
*/
unmap_hugepage_align(&op->remap, &unmap_start, &unmap_range);
- /* If the range changed, we might have to lock a wider region to guarantee
- * atomicity. panthor_vm_lock_region() bails out early if the new region
- * is already part of the locked region, so no need to do this check here.
+ /* If the range changed, we might have to lock a wider region to
+ * guarantee atomicity.
*/
- panthor_vm_lock_region(vm, unmap_start, unmap_range);
+ ret = panthor_vm_expand_locked_region(vm, unmap_start,
+ unmap_range);
+ if (ret)
+ return ret;
+
panthor_vm_unmap_pages(vm, unmap_start, unmap_range);
}
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 4/7] drm/panthor: Pass drm_file instead of panthor_file
2026-07-12 13:54 [PATCH v2 0/7] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (2 preceding siblings ...)
2026-07-12 13:54 ` [PATCH v2 3/7] drm/panthor: Explicit expansion of locked VM region Ketil Johnsen
@ 2026-07-12 13:54 ` Ketil Johnsen
2026-07-12 13:54 ` [PATCH v2 5/7] drm/panthor: Don't allocate protm_suspend_buf Ketil Johnsen
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Ketil Johnsen @ 2026-07-12 13:54 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel
From: Boris Brezillon <boris.brezillon@collabora.com>
Some sched helpers need info that are part of drm_file, and we will
soon need to call drm_gem_object_lookup() from panthor_group_create().
Let's prepare for that by passing a drm_file instead of panthor_file to
all current helpers taking a panthor_file, so we keep things consistent.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/panthor/panthor_drv.c | 36 +++++++++++-------------
drivers/gpu/drm/panthor/panthor_mmu.c | 11 +++++---
drivers/gpu/drm/panthor/panthor_mmu.h | 6 ++--
drivers/gpu/drm/panthor/panthor_sched.c | 37 +++++++++++++++----------
drivers/gpu/drm/panthor/panthor_sched.h | 23 +++++++--------
5 files changed, 58 insertions(+), 55 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index 106da676fd2ee..e18ee2d7a8e6f 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -1111,7 +1111,6 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
static int panthor_ioctl_group_submit(struct drm_device *ddev, void *data,
struct drm_file *file)
{
- struct panthor_file *pfile = file->driver_priv;
struct drm_panthor_group_submit *args = data;
struct drm_panthor_queue_submit *jobs_args;
struct panthor_submit_ctx ctx;
@@ -1136,8 +1135,7 @@ static int panthor_ioctl_group_submit(struct drm_device *ddev, void *data,
const struct drm_panthor_queue_submit *qsubmit = &jobs_args[i];
struct drm_sched_job *job;
- job = panthor_job_create(pfile, args->group_handle, qsubmit,
- file->client_id);
+ job = panthor_job_create(file, args->group_handle, qsubmit);
if (IS_ERR(job)) {
ret = PTR_ERR(job);
goto out_cleanup_submit_ctx;
@@ -1217,19 +1215,17 @@ static int panthor_ioctl_group_submit(struct drm_device *ddev, void *data,
static int panthor_ioctl_group_destroy(struct drm_device *ddev, void *data,
struct drm_file *file)
{
- struct panthor_file *pfile = file->driver_priv;
struct drm_panthor_group_destroy *args = data;
if (args->pad)
return -EINVAL;
- return panthor_group_destroy(pfile, args->group_handle);
+ return panthor_group_destroy(file, args->group_handle);
}
static int panthor_ioctl_group_create(struct drm_device *ddev, void *data,
struct drm_file *file)
{
- struct panthor_file *pfile = file->driver_priv;
struct drm_panthor_group_create *args = data;
struct drm_panthor_queue_create *queue_args;
int ret;
@@ -1245,7 +1241,7 @@ static int panthor_ioctl_group_create(struct drm_device *ddev, void *data,
if (ret)
goto out;
- ret = panthor_group_create(pfile, args, queue_args, file->client_id);
+ ret = panthor_group_create(file, args, queue_args);
if (ret < 0)
goto out;
args->group_handle = ret;
@@ -1259,10 +1255,9 @@ static int panthor_ioctl_group_create(struct drm_device *ddev, void *data,
static int panthor_ioctl_group_get_state(struct drm_device *ddev, void *data,
struct drm_file *file)
{
- struct panthor_file *pfile = file->driver_priv;
struct drm_panthor_group_get_state *args = data;
- return panthor_group_get_state(pfile, args);
+ return panthor_group_get_state(file, args);
}
static int panthor_ioctl_tiler_heap_create(struct drm_device *ddev, void *data,
@@ -1605,6 +1600,7 @@ panthor_open(struct drm_device *ddev, struct drm_file *file)
if (!pfile)
return -ENOMEM;
+ file->driver_priv = pfile;
pfile->ptdev = ptdev;
pfile->user_mmio.offset = DRM_PANTHOR_USER_MMIO_OFFSET;
@@ -1619,19 +1615,18 @@ panthor_open(struct drm_device *ddev, struct drm_file *file)
#endif
- ret = panthor_vm_pool_create(pfile);
+ ret = panthor_vm_pool_create(file);
if (ret)
goto err_free_file;
- ret = panthor_group_pool_create(pfile);
+ ret = panthor_group_pool_create(file);
if (ret)
goto err_destroy_vm_pool;
- file->driver_priv = pfile;
return 0;
err_destroy_vm_pool:
- panthor_vm_pool_destroy(pfile);
+ panthor_vm_pool_destroy(file);
err_free_file:
kfree(pfile);
@@ -1643,8 +1638,8 @@ panthor_postclose(struct drm_device *ddev, struct drm_file *file)
{
struct panthor_file *pfile = file->driver_priv;
- panthor_group_pool_destroy(pfile);
- panthor_vm_pool_destroy(pfile);
+ panthor_group_pool_destroy(file);
+ panthor_vm_pool_destroy(file);
kfree(pfile);
}
@@ -1704,11 +1699,13 @@ static int panthor_mmap(struct file *filp, struct vm_area_struct *vma)
}
static void panthor_gpu_show_fdinfo(struct panthor_device *ptdev,
- struct panthor_file *pfile,
+ struct drm_file *file,
struct drm_printer *p)
{
+ struct panthor_file *pfile = file->driver_priv;
+
if (ptdev->profile_mask & PANTHOR_DEVICE_PROFILING_ALL)
- panthor_fdinfo_gather_group_samples(pfile);
+ panthor_fdinfo_gather_group_samples(file);
if (ptdev->profile_mask & PANTHOR_DEVICE_PROFILING_TIMESTAMP) {
#ifdef CONFIG_ARM_ARCH_TIMER
@@ -1728,11 +1725,10 @@ static void panthor_gpu_show_fdinfo(struct panthor_device *ptdev,
static void panthor_show_internal_memory_stats(struct drm_printer *p, struct drm_file *file)
{
char *drv_name = file->minor->dev->driver->name;
- struct panthor_file *pfile = file->driver_priv;
struct drm_memory_stats stats = {0};
- panthor_fdinfo_gather_group_mem_info(pfile, &stats);
- panthor_vm_heaps_sizes(pfile, &stats);
+ panthor_fdinfo_gather_group_mem_info(file, &stats);
+ panthor_vm_heaps_sizes(file, &stats);
drm_fdinfo_print_size(p, drv_name, "resident", "memory", stats.resident);
drm_fdinfo_print_size(p, drv_name, "active", "memory", stats.active);
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index b82b01013611c..ed2ae5a6008d1 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1693,8 +1693,9 @@ panthor_vm_pool_get_vm(struct panthor_vm_pool *pool, u32 handle)
* Note that VMs can outlive the pool they were created from if other
* objects hold a reference to there VMs.
*/
-void panthor_vm_pool_destroy(struct panthor_file *pfile)
+void panthor_vm_pool_destroy(struct drm_file *file)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_vm *vm;
unsigned long i;
@@ -1716,8 +1717,9 @@ void panthor_vm_pool_destroy(struct panthor_file *pfile)
*
* Return: 0 on success, a negative error code otherwise.
*/
-int panthor_vm_pool_create(struct panthor_file *pfile)
+int panthor_vm_pool_create(struct drm_file *file)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_gem_object *dummy;
int ret;
@@ -1738,7 +1740,7 @@ int panthor_vm_pool_create(struct panthor_file *pfile)
return 0;
err_destroy_vm_pool:
- panthor_vm_pool_destroy(pfile);
+ panthor_vm_pool_destroy(file);
return ret;
}
@@ -2186,8 +2188,9 @@ struct panthor_heap_pool *panthor_vm_get_heap_pool(struct panthor_vm *vm, bool c
* Calculate all heap chunk sizes in all heap pools bound to a VM. If the VM
* is active, record the size as active as well.
*/
-void panthor_vm_heaps_sizes(struct panthor_file *pfile, struct drm_memory_stats *stats)
+void panthor_vm_heaps_sizes(struct drm_file *file, struct drm_memory_stats *stats)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_vm *vm;
unsigned long i;
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.h b/drivers/gpu/drm/panthor/panthor_mmu.h
index 3522fbbce369c..e6945b6b61fc8 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.h
+++ b/drivers/gpu/drm/panthor/panthor_mmu.h
@@ -38,7 +38,7 @@ int panthor_vm_as(struct panthor_vm *vm);
struct panthor_heap_pool *
panthor_vm_get_heap_pool(struct panthor_vm *vm, bool create);
-void panthor_vm_heaps_sizes(struct panthor_file *pfile, struct drm_memory_stats *stats);
+void panthor_vm_heaps_sizes(struct drm_file *file, struct drm_memory_stats *stats);
struct panthor_vm *panthor_vm_get(struct panthor_vm *vm);
void panthor_vm_put(struct panthor_vm *vm);
@@ -65,8 +65,8 @@ void panthor_vm_add_job_fence_to_bos_resvs(struct panthor_vm *vm,
struct dma_resv *panthor_vm_resv(struct panthor_vm *vm);
struct drm_gem_object *panthor_vm_root_gem(struct panthor_vm *vm);
-void panthor_vm_pool_destroy(struct panthor_file *pfile);
-int panthor_vm_pool_create(struct panthor_file *pfile);
+void panthor_vm_pool_destroy(struct drm_file *file);
+int panthor_vm_pool_create(struct drm_file *file);
int panthor_vm_pool_create_vm(struct panthor_device *ptdev,
struct panthor_vm_pool *pool,
struct drm_panthor_vm_create *args);
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index 465f1b86249f8..dc77a174a3368 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -3043,8 +3043,9 @@ static void update_fdinfo_stats(struct panthor_job *job)
}
}
-void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile)
+void panthor_fdinfo_gather_group_samples(struct drm_file *file)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_group *group;
unsigned long i;
@@ -3655,11 +3656,11 @@ static void add_group_kbo_sizes(struct panthor_device *ptdev,
#define MAX_GROUPS_PER_POOL 128
-int panthor_group_create(struct panthor_file *pfile,
+int panthor_group_create(struct drm_file *file,
const struct drm_panthor_group_create *group_args,
- const struct drm_panthor_queue_create *queue_args,
- u64 drm_client_id)
+ const struct drm_panthor_queue_create *queue_args)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_device *ptdev = pfile->ptdev;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_scheduler *sched = ptdev->scheduler;
@@ -3756,7 +3757,8 @@ int panthor_group_create(struct panthor_file *pfile,
goto err_put_group;
for (i = 0; i < group_args->queues.count; i++) {
- group->queues[i] = group_create_queue(group, &queue_args[i], drm_client_id, gid, i);
+ group->queues[i] = group_create_queue(group, &queue_args[i],
+ file->client_id, gid, i);
if (IS_ERR(group->queues[i])) {
ret = PTR_ERR(group->queues[i]);
group->queues[i] = NULL;
@@ -3796,8 +3798,9 @@ int panthor_group_create(struct panthor_file *pfile,
return ret;
}
-int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle)
+int panthor_group_destroy(struct drm_file *file, u32 group_handle)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_device *ptdev = pfile->ptdev;
struct panthor_scheduler *sched = ptdev->scheduler;
@@ -3842,9 +3845,10 @@ static struct panthor_group *group_from_handle(struct panthor_group_pool *pool,
return group;
}
-int panthor_group_get_state(struct panthor_file *pfile,
+int panthor_group_get_state(struct drm_file *file,
struct drm_panthor_group_get_state *get_state)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_device *ptdev = pfile->ptdev;
struct panthor_scheduler *sched = ptdev->scheduler;
@@ -3874,8 +3878,9 @@ int panthor_group_get_state(struct panthor_file *pfile,
return 0;
}
-int panthor_group_pool_create(struct panthor_file *pfile)
+int panthor_group_pool_create(struct drm_file *file)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool;
gpool = kzalloc_obj(*gpool);
@@ -3887,8 +3892,9 @@ int panthor_group_pool_create(struct panthor_file *pfile)
return 0;
}
-void panthor_group_pool_destroy(struct panthor_file *pfile)
+void panthor_group_pool_destroy(struct drm_file *file)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_group *group;
unsigned long i;
@@ -3897,7 +3903,7 @@ void panthor_group_pool_destroy(struct panthor_file *pfile)
return;
xa_for_each(&gpool->xa, i, group)
- panthor_group_destroy(pfile, i);
+ panthor_group_destroy(file, i);
xa_destroy(&gpool->xa);
kfree(gpool);
@@ -3912,9 +3918,10 @@ void panthor_group_pool_destroy(struct panthor_file *pfile)
*
*/
void
-panthor_fdinfo_gather_group_mem_info(struct panthor_file *pfile,
+panthor_fdinfo_gather_group_mem_info(struct drm_file *file,
struct drm_memory_stats *stats)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_group *group;
unsigned long i;
@@ -3977,11 +3984,11 @@ struct panthor_vm *panthor_job_vm(struct drm_sched_job *sched_job)
}
struct drm_sched_job *
-panthor_job_create(struct panthor_file *pfile,
+panthor_job_create(struct drm_file *file,
u16 group_handle,
- const struct drm_panthor_queue_submit *qsubmit,
- u64 drm_client_id)
+ const struct drm_panthor_queue_submit *qsubmit)
{
+ struct panthor_file *pfile = file->driver_priv;
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_job *job;
u32 credits;
@@ -4052,7 +4059,7 @@ panthor_job_create(struct panthor_file *pfile,
ret = drm_sched_job_init(&job->base,
&job->group->queues[job->queue_idx]->entity,
- credits, job->group, drm_client_id);
+ credits, job->group, file->client_id);
if (ret)
goto err_put_job;
diff --git a/drivers/gpu/drm/panthor/panthor_sched.h b/drivers/gpu/drm/panthor/panthor_sched.h
index 9a8692de8aded..be7e1c8b4f563 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.h
+++ b/drivers/gpu/drm/panthor/panthor_sched.h
@@ -15,31 +15,28 @@ struct drm_panthor_queue_create;
struct drm_panthor_group_get_state;
struct drm_panthor_queue_submit;
struct panthor_device;
-struct panthor_file;
struct panthor_group_pool;
struct panthor_job;
-int panthor_group_create(struct panthor_file *pfile,
+int panthor_group_create(struct drm_file *file,
const struct drm_panthor_group_create *group_args,
- const struct drm_panthor_queue_create *queue_args,
- u64 drm_client_id);
-int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle);
-int panthor_group_get_state(struct panthor_file *pfile,
+ const struct drm_panthor_queue_create *queue_args);
+int panthor_group_destroy(struct drm_file *file, u32 group_handle);
+int panthor_group_get_state(struct drm_file *file,
struct drm_panthor_group_get_state *get_state);
struct drm_sched_job *
-panthor_job_create(struct panthor_file *pfile,
+panthor_job_create(struct drm_file *file,
u16 group_handle,
- const struct drm_panthor_queue_submit *qsubmit,
- u64 drm_client_id);
+ const struct drm_panthor_queue_submit *qsubmit);
struct drm_sched_job *panthor_job_get(struct drm_sched_job *job);
struct panthor_vm *panthor_job_vm(struct drm_sched_job *sched_job);
void panthor_job_put(struct drm_sched_job *job);
void panthor_job_update_resvs(struct drm_exec *exec, struct drm_sched_job *job);
-int panthor_group_pool_create(struct panthor_file *pfile);
-void panthor_group_pool_destroy(struct panthor_file *pfile);
-void panthor_fdinfo_gather_group_mem_info(struct panthor_file *pfile,
+int panthor_group_pool_create(struct drm_file *file);
+void panthor_group_pool_destroy(struct drm_file *file);
+void panthor_fdinfo_gather_group_mem_info(struct drm_file *pfile,
struct drm_memory_stats *stats);
int panthor_sched_init(struct panthor_device *ptdev);
@@ -53,6 +50,6 @@ void panthor_sched_report_mmu_fault(struct panthor_device *ptdev);
void panthor_sched_prepare_for_vm_destruction(struct panthor_device *ptdev);
void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events);
-void panthor_fdinfo_gather_group_samples(struct panthor_file *pfile);
+void panthor_fdinfo_gather_group_samples(struct drm_file *file);
#endif
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 5/7] drm/panthor: Don't allocate protm_suspend_buf
2026-07-12 13:54 [PATCH v2 0/7] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (3 preceding siblings ...)
2026-07-12 13:54 ` [PATCH v2 4/7] drm/panthor: Pass drm_file instead of panthor_file Ketil Johnsen
@ 2026-07-12 13:54 ` Ketil Johnsen
2026-07-13 7:02 ` Boris Brezillon
2026-07-12 13:54 ` [PATCH v2 6/7] drm/panthor: Add support for entering and exiting protected mode Ketil Johnsen
2026-07-12 13:54 ` [PATCH v2 7/7] drm/panthor: Expose protected rendering features Ketil Johnsen
6 siblings, 1 reply; 11+ messages in thread
From: Ketil Johnsen @ 2026-07-12 13:54 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, Ketil Johnsen
The PROTM suspend buffer is only needed if the group is going to
use PROTM in the first place, so let's not assume we need one until
we're being asked to.
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index dc77a174a3368..86c0f12b09e11 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -3642,9 +3642,11 @@ static void add_group_kbo_sizes(struct panthor_device *ptdev,
if (drm_WARN_ON(&ptdev->base, ptdev != group->ptdev))
return;
- group->fdinfo.kbo_sizes += group->suspend_buf->obj->size;
- group->fdinfo.kbo_sizes += group->protm_suspend_buf->obj->size;
group->fdinfo.kbo_sizes += group->syncobjs->obj->size;
+ group->fdinfo.kbo_sizes += group->suspend_buf->obj->size;
+
+ if (group->protm_suspend_buf)
+ group->fdinfo.kbo_sizes += group->protm_suspend_buf->obj->size;
for (i = 0; i < group->queue_count; i++) {
queue = group->queues[i];
@@ -3724,14 +3726,6 @@ int panthor_group_create(struct drm_file *file,
goto err_put_group;
}
- suspend_size = csg_iface->control->protm_suspend_size;
- group->protm_suspend_buf = panthor_fw_alloc_suspend_buf_mem(ptdev, suspend_size);
- if (IS_ERR(group->protm_suspend_buf)) {
- ret = PTR_ERR(group->protm_suspend_buf);
- group->protm_suspend_buf = NULL;
- goto err_put_group;
- }
-
group->syncobjs = panthor_kernel_bo_create(ptdev, group->vm,
group_args->queues.count *
sizeof(struct panthor_syncobj_64b),
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 6/7] drm/panthor: Add support for entering and exiting protected mode
2026-07-12 13:54 [PATCH v2 0/7] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (4 preceding siblings ...)
2026-07-12 13:54 ` [PATCH v2 5/7] drm/panthor: Don't allocate protm_suspend_buf Ketil Johnsen
@ 2026-07-12 13:54 ` Ketil Johnsen
2026-07-13 8:37 ` Boris Brezillon
2026-07-12 13:54 ` [PATCH v2 7/7] drm/panthor: Expose protected rendering features Ketil Johnsen
6 siblings, 1 reply; 11+ messages in thread
From: Ketil Johnsen @ 2026-07-12 13:54 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, Florent Tomasin, Paul Toadere,
Samuel Percival, Ketil Johnsen
From: Florent Tomasin <florent.tomasin@arm.com>
This patch modifies the Panthor driver code to allow handling
of the GPU HW protected mode enter and exit.
The logic added by this patch includes:
- the mechanisms needed for entering and exiting protected mode.
- the handling of protected mode IRQs and FW interactions.
- the scheduler changes needed to decide when to enter
protected mode based on CSG scheduling.
- GPU fault handling during protected mode execution.
Note that the submission of a protected mode jobs are done
from the user space.
The following is a summary of how protected mode is entered
and exited:
- When the GPU detects a protected mode job needs to be
executed, an IRQ is sent to the CPU to notify the kernel
driver that the job is blocked until the GPU has entered
protected mode. The entering of protected mode is controlled
by the kernel driver.
- The Mali Panthor CSF driver will schedule a tick and evaluate
which CS in the CSG to schedule on slot needs protected mode.
If the priority of the CSG is not sufficiently high, the
protected mode job will not progress until the CSG is
scheduled at top priority.
- The Panthor scheduler notifies the GPU that the blocked
protected jobs will soon be able to progress.
- Once all CSG and CS slots are updated, the scheduler
requests the GPU to enter protected mode and waits for
it to be acknowledged.
- If successful, all protected mode jobs will resume execution
while normal mode jobs block until the GPU exits
protected mode, or the kernel driver rotates the CSGs
and forces the GPU to exit protected mode.
- If unsuccessful, the scheduler will request a GPU reset.
- Faults during protected mode are reported GPU wide, and not as
CSG/CS errors. We allow only one CSG to run in protected mode at a
time so we know which CSG to blame for the fault.
- All faults during protected mode are handled with a GPU reset.
- When a protected mode job is suspended as a result of
the CSGs rotation, the GPU will send an IRQ to the CPU
to notify that the protected mode job needs to resume.
This sequence will continue so long the user space is
submitting protected mode jobs.
Signed-off-by: Florent Tomasin <florent.tomasin@arm.com>
Co-developed-by: Paul Toadere <paul.toadere@arm.com>
Signed-off-by: Paul Toadere <paul.toadere@arm.com>
Co-developed-by: Samuel Percival <samuel.percival@arm.com>
Signed-off-by: Samuel Percival <samuel.percival@arm.com>
Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
drivers/gpu/drm/panthor/panthor_device.c | 1 +
drivers/gpu/drm/panthor/panthor_device.h | 33 +++
drivers/gpu/drm/panthor/panthor_fw.c | 90 +++++-
drivers/gpu/drm/panthor/panthor_fw.h | 5 +
drivers/gpu/drm/panthor/panthor_gpu.c | 53 +++-
drivers/gpu/drm/panthor/panthor_gpu.h | 4 +
drivers/gpu/drm/panthor/panthor_mmu.c | 29 +-
drivers/gpu/drm/panthor/panthor_sched.c | 333 ++++++++++++++++++++++-
drivers/gpu/drm/panthor/panthor_sched.h | 4 +
9 files changed, 533 insertions(+), 19 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c
index bd417d6ae8c00..c0cdefd330799 100644
--- a/drivers/gpu/drm/panthor/panthor_device.c
+++ b/drivers/gpu/drm/panthor/panthor_device.c
@@ -172,6 +172,7 @@ int panthor_device_init(struct panthor_device *ptdev)
ptdev->soc_data = of_device_get_match_data(ptdev->base.dev);
+ init_rwsem(&ptdev->protm.lock);
init_completion(&ptdev->unplug.done);
ret = drmm_mutex_init(&ptdev->base, &ptdev->unplug.lock);
if (ret)
diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h
index 35679bfa1f3a6..e5df42f095717 100644
--- a/drivers/gpu/drm/panthor/panthor_device.h
+++ b/drivers/gpu/drm/panthor/panthor_device.h
@@ -332,6 +332,26 @@ struct panthor_device {
struct list_head node;
} gems;
#endif
+ /** @protm: Protected mode related data. */
+ struct {
+ /**
+ * @lock: Lock to prevent MMU operations during protected mode.
+ *
+ * The MMU HW will silently ignore commands issued when the
+ * GPU is in protected mode. It is important that we handle this
+ * for some of the MMU HW interactions.
+ *
+ * panthor_vm_lock_region() will down this as a reader, and
+ * this will prevent any new transition into protected mode.
+ * panthor_vm_lock_region() will then wait for GPU to return
+ * to normal mode before proceeding.
+ * It is now safe to carry out page table modifications.
+ * Only the switch into protected mode itself will down this
+ * as a writer. The wait for GPU to leave protected mode
+ * in panthor_vm_lock_region() will ensure this is enough.
+ */
+ struct rw_semaphore lock;
+ } protm;
};
struct panthor_gpu_usage {
@@ -628,6 +648,19 @@ static inline void panthor_ ## __name ## _irq_disable_events(struct panthor_irq
gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
}
+/**
+ * PANTHOR_IRQ_HANDLER_DECL() - Forward declare interrupt handlers helpers
+ *
+ * Exposes the IRQ helper functions panthor_xxx_irq_enable_events() and
+ * panthor_xxx_disable_events(), so these can be used from within the
+ * IRQ handler itself.
+ */
+#define PANTHOR_IRQ_HANDLER_DECL(__name) \
+static inline void panthor_ ## __name ## _irq_enable_events( \
+ struct panthor_irq *pirq, u32 mask); \
+static inline void panthor_ ## __name ## _irq_disable_events( \
+ struct panthor_irq *pirq, u32 mask);
+
extern struct workqueue_struct *panthor_cleanup_wq;
static inline void gpu_write(void __iomem *iomem, u32 reg, u32 data)
diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index 389f9182fac16..76792f9175b57 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -1035,7 +1035,9 @@ static void panthor_fw_init_global_iface(struct panthor_device *ptdev)
GLB_CFG_PROGRESS_TIMER |
GLB_CFG_POWEROFF_TIMER |
GLB_IDLE_EN |
- GLB_IDLE;
+ GLB_IDLE |
+ GLB_PROTM_ENTER |
+ GLB_PROTM_EXIT;
if (panthor_fw_has_glb_state(ptdev))
glb_iface->input->ack_irq_mask |= GLB_STATE_MASK;
@@ -1441,6 +1443,92 @@ static void panthor_fw_ping_work(struct work_struct *work)
}
}
+static int panthor_fw_protm_enter_wait(struct panthor_device *ptdev,
+ u32 timeout_ms)
+{
+ struct panthor_fw_global_iface *glb_iface =
+ panthor_fw_get_glb_iface(ptdev);
+ int ret;
+
+ /* Poll for the entry of protected mode.
+ * GLB_PROTM_EXIT is also checked as it may happen that FW enters and
+ * exits protected mode very quickly and so the GPU_STATUS_PROTM_ACTIVE
+ * bit is seen as 0 throughout the polling.
+ */
+ ret = wait_event_timeout(ptdev->fw->req_waitqueue,
+ (panthor_gpu_status(ptdev) &
+ GPU_STATUS_PROTM_ACTIVE) ||
+ ((glb_iface->input->req ^ glb_iface->output->ack) &
+ GLB_PROTM_EXIT),
+ msecs_to_jiffies(timeout_ms));
+ if (!ret)
+ return -ETIMEDOUT;
+
+ return 0;
+}
+
+int panthor_fw_protm_enter(struct panthor_device *ptdev)
+{
+ struct panthor_fw_global_iface *glb_iface =
+ panthor_fw_get_glb_iface(ptdev);
+ u32 acked;
+ int ret;
+
+ /* Restart the watchdog timer, so it doesn't hit immediately
+ * after entering protected mode, since this will cause GPU
+ * to exit protected mode to respond to the ping request.
+ */
+ mod_delayed_work(ptdev->reset.wq, &ptdev->fw->watchdog.ping_work,
+ msecs_to_jiffies(PING_INTERVAL_MS));
+
+ panthor_fw_toggle_reqs(glb_iface, req, ack, GLB_PROTM_ENTER);
+ panthor_fw_ring_doorbell(ptdev, CSF_GLB_DOORBELL_ID);
+
+ ret = panthor_fw_glb_wait_acks(ptdev, GLB_PROTM_ENTER, &acked, 4000);
+ if (ret) {
+ drm_err(&ptdev->base,
+ "Wait for FW protected mode acknowledge timed out");
+ return ret;
+ }
+
+ /* Wait for the GPU to actually enter protected mode.
+ * There would be some time gap between FW sending the
+ * ACK for GLB_PROTM_ENTER and GPU entering protected mode.
+ */
+ ret = panthor_fw_protm_enter_wait(ptdev, 500);
+ if (ret)
+ drm_err(&ptdev->base,
+ "Wait for GPU protected mode enter timed out");
+
+ return ret;
+}
+
+int panthor_fw_protm_exit_wait(struct panthor_device *ptdev, u32 timeout_ms)
+{
+ int ret;
+
+ ret = wait_event_timeout(ptdev->fw->req_waitqueue,
+ !(panthor_gpu_status(ptdev) &
+ GPU_STATUS_PROTM_ACTIVE),
+ msecs_to_jiffies(timeout_ms));
+ if (!ret)
+ return -ETIMEDOUT;
+
+ return 0;
+}
+
+int panthor_fw_protm_exit(struct panthor_device *ptdev)
+{
+ struct panthor_fw_global_iface *glb_iface =
+ panthor_fw_get_glb_iface(ptdev);
+
+ /* Send PING request to force an exit */
+ panthor_fw_toggle_reqs(glb_iface, req, ack, GLB_PING);
+ panthor_fw_ring_doorbell(ptdev, CSF_GLB_DOORBELL_ID);
+
+ return panthor_fw_protm_exit_wait(ptdev, 500);
+}
+
/**
* panthor_fw_init() - Initialize FW related data.
* @ptdev: Device.
diff --git a/drivers/gpu/drm/panthor/panthor_fw.h b/drivers/gpu/drm/panthor/panthor_fw.h
index a99a9b6f4825c..78658d64b807e 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.h
+++ b/drivers/gpu/drm/panthor/panthor_fw.h
@@ -529,4 +529,9 @@ static inline int panthor_fw_resume(struct panthor_device *ptdev)
int panthor_fw_init(struct panthor_device *ptdev);
void panthor_fw_unplug(struct panthor_device *ptdev);
+int panthor_fw_protm_enter(struct panthor_device *ptdev);
+int panthor_fw_protm_exit(struct panthor_device *ptdev);
+int panthor_fw_protm_exit_wait(struct panthor_device *ptdev,
+ u32 timeout_ms);
+
#endif
diff --git a/drivers/gpu/drm/panthor/panthor_gpu.c b/drivers/gpu/drm/panthor/panthor_gpu.c
index e52c5675981f5..9054ac251fd3e 100644
--- a/drivers/gpu/drm/panthor/panthor_gpu.c
+++ b/drivers/gpu/drm/panthor/panthor_gpu.c
@@ -46,6 +46,9 @@ struct panthor_gpu {
/** @cache_flush_lock: Lock to serialize cache flushes */
struct mutex cache_flush_lock;
+
+ /** @protm_fault: True if a GPU_IRQ_PROTM_FAULT has been raised */
+ bool protm_fault;
};
#define GPU_INTERRUPTS_MASK \
@@ -86,10 +89,42 @@ static void panthor_gpu_l2_config_set(struct panthor_device *ptdev)
gpu_write(gpu->iomem, GPU_L2_CONFIG, l2_config);
}
+PANTHOR_IRQ_HANDLER_DECL(gpu);
+
static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status)
{
struct panthor_gpu *gpu = ptdev->gpu;
+ if (status & GPU_IRQ_PROTM_FAULT) {
+ /* Make a note of this fault before we clear the interrupt.
+ * This ensures panthor_gpu_protm_fault_pending() can always
+ * give an accurate answer.
+ *
+ * There is a race we need to handle between two interrupts,
+ * this GPU_IRQ_PROTM_FAULT and JOB_INT_GLOBAL_IF with the
+ * GLB_PROTM_EXIT event.
+ *
+ * Although GPU_IRQ_PROTM_FAULT is always raised first,
+ * processing of GLB_PROTM_EXIT could still execute first.
+ * The handling of GLB_PROTM_EXIT MUST know if a
+ * GPU_IRQ_PROTM_FAULT has been raised or not, otherwise it
+ * could incorrectly think everything is fine and resume
+ * with normal scheduling to early.
+ *
+ * We still need to do fault handling (reset) here as well,
+ * because some failures during protected mode do not
+ * automatically exit protected mode (no GLB_PROTM_EXIT).
+ * This means there is a slim chance we do two GPU resets
+ * instead of just one. This is not ideal, but should be safe.
+ */
+ WRITE_ONCE(gpu->protm_fault, true);
+
+ drm_warn(&ptdev->base, "GPU Fault in protected mode\n");
+ panthor_gpu_irq_disable_events(&ptdev->gpu->irq,
+ GPU_IRQ_PROTM_FAULT);
+ panthor_device_schedule_reset(ptdev);
+ }
+
gpu_write(gpu->irq.iomem, INT_CLEAR, status);
if (tracepoint_enabled(gpu_power_status) && (status & GPU_POWER_INTERRUPTS_MASK))
@@ -106,8 +141,6 @@ static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status)
fault_status, panthor_exception_name(ptdev, fault_status & 0xFF),
address);
}
- if (status & GPU_IRQ_PROTM_FAULT)
- drm_warn(&ptdev->base, "GPU Fault in protected mode\n");
spin_lock(&ptdev->gpu->reqs_lock);
if (status & ptdev->gpu->pending_reqs) {
@@ -118,6 +151,13 @@ static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status)
}
PANTHOR_IRQ_HANDLER(gpu, panthor_gpu_irq_handler);
+bool panthor_gpu_protm_fault_pending(struct panthor_device *ptdev)
+{
+ return READ_ONCE(ptdev->gpu->protm_fault) ||
+ gpu_read(ptdev->gpu->irq.iomem, INT_RAWSTAT) &
+ GPU_IRQ_PROTM_FAULT;
+}
+
/**
* panthor_gpu_unplug() - Called when the GPU is unplugged.
* @ptdev: Device to unplug.
@@ -380,6 +420,10 @@ int panthor_gpu_soft_reset(struct panthor_device *ptdev)
unsigned long flags;
spin_lock_irqsave(&ptdev->gpu->reqs_lock, flags);
+
+ WRITE_ONCE(ptdev->gpu->protm_fault, false);
+ panthor_gpu_irq_enable_events(&ptdev->gpu->irq, GPU_IRQ_PROTM_FAULT);
+
if (!drm_WARN_ON(&ptdev->base,
ptdev->gpu->pending_reqs & GPU_IRQ_RESET_COMPLETED)) {
ptdev->gpu->pending_reqs |= GPU_IRQ_RESET_COMPLETED;
@@ -480,3 +524,8 @@ int panthor_gpu_coherency_init(struct panthor_device *ptdev)
drm_err(&ptdev->base, "Coherency not supported by the device");
return -ENOTSUPP;
}
+
+u32 panthor_gpu_status(struct panthor_device *ptdev)
+{
+ return gpu_read(ptdev->gpu->iomem, GPU_STATUS);
+}
diff --git a/drivers/gpu/drm/panthor/panthor_gpu.h b/drivers/gpu/drm/panthor/panthor_gpu.h
index f615feb056094..00ec9a8c5d7fd 100644
--- a/drivers/gpu/drm/panthor/panthor_gpu.h
+++ b/drivers/gpu/drm/panthor/panthor_gpu.h
@@ -60,4 +60,8 @@ u64 panthor_gpu_get_cycle_count(struct panthor_device *ptdev);
int panthor_gpu_coherency_init(struct panthor_device *ptdev);
+u32 panthor_gpu_status(struct panthor_device *ptdev);
+
+bool panthor_gpu_protm_fault_pending(struct panthor_device *ptdev);
+
#endif
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index ed2ae5a6008d1..75c484118f6ba 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1794,11 +1794,30 @@ static int panthor_vm_lock_region(struct panthor_vm *vm, u64 start, u64 size)
if (drm_WARN_ON(&ptdev->base, vm->locked_region.size))
return -EINVAL;
+ /* Prevent GPU from entering protected mode */
+ panthor_sched_protm_block(ptdev);
+
mutex_lock(&ptdev->mmu->as.slots_lock);
if (vm->as.id >= 0 && size) {
- u64 region = pack_region_range(ptdev, &start, &size);
+ mutex_unlock(&ptdev->mmu->as.slots_lock);
- ret = panthor_vm_apply_as_lock(vm, region);
+ /* Wait for GPU to exit protected mode.
+ * There is a slim chance that the GPU has faulted in protected
+ * mode. Such failures are handled with a GPU reset.
+ * That is why we temporary release the as.slots_lock, while we
+ * wait for protected mode to exit, since the same lock will
+ * be acquired during the GPU reset procedure.
+ */
+
+ panthor_sched_protm_exit(ptdev);
+
+ mutex_lock(&ptdev->mmu->as.slots_lock);
+
+ if (vm->as.id >= 0 && size) {
+ u64 region = pack_region_range(ptdev, &start, &size);
+
+ ret = panthor_vm_apply_as_lock(vm, region);
+ }
}
if (!ret) {
@@ -1807,6 +1826,9 @@ static int panthor_vm_lock_region(struct panthor_vm *vm, u64 start, u64 size)
}
mutex_unlock(&ptdev->mmu->as.slots_lock);
+ if (ret)
+ panthor_sched_protm_unblock(ptdev);
+
return ret;
}
@@ -1890,6 +1912,9 @@ static void panthor_vm_unlock_region(struct panthor_vm *vm)
vm->locked_region.start = 0;
vm->locked_region.size = 0;
mutex_unlock(&ptdev->mmu->as.slots_lock);
+
+ /* Let scheduler know it is safe to enter protected mode again */
+ panthor_sched_protm_unblock(ptdev);
}
static void panthor_mmu_irq_handler(struct panthor_device *ptdev, u32 status)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index 86c0f12b09e11..efa53b0a05d38 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -309,6 +309,17 @@ struct panthor_scheduler {
*/
struct list_head stopped_groups;
} reset;
+
+ /** @protm: Protected mode related fields. */
+ struct {
+ /**
+ * @active_group: The active protected group.
+ *
+ * We only allow one protected group to run at the same time,
+ * as it makes it easier to handle faults in protected mode.
+ */
+ struct panthor_group *active_group;
+ } protm;
};
/**
@@ -571,6 +582,16 @@ struct panthor_group {
/** @fatal_queues: Bitmask reflecting the queues that hit a fatal exception. */
u32 fatal_queues;
+ /**
+ * @protm_pending_queues: Bitmask reflecting the queues that have raised
+ * a CS_PROTM_PENDING.
+ *
+ * The GPU will set the bit associated to the queue pending protected
+ * mode when a PROT_REGION command is executing or when trying to resume
+ * previously suspended protected mode jobs.
+ */
+ u32 protm_pending_queues;
+
/** @tiler_oom: Mask of queues that have a tiler OOM event to process. */
atomic_t tiler_oom;
@@ -1054,6 +1075,7 @@ group_unbind_locked(struct panthor_group *group)
slot = &ptdev->scheduler->csg_slots[group->csg_id];
panthor_vm_idle(group->vm);
group->csg_id = -1;
+ group->protm_pending_queues = 0;
/* Tiler OOM events will be re-issued next time the group is scheduled. */
atomic_set(&group->tiler_oom, 0);
@@ -1473,6 +1495,27 @@ csg_slot_prog_locked(struct panthor_device *ptdev, u32 csg_id, u32 priority)
return 0;
}
+static void
+cs_slot_process_protm_pending_event_locked(struct panthor_device *ptdev,
+ u32 csg_id, u32 cs_id)
+{
+ struct panthor_scheduler *sched = ptdev->scheduler;
+ struct panthor_csg_slot *csg_slot = &sched->csg_slots[csg_id];
+ struct panthor_group *group = csg_slot->group;
+
+ lockdep_assert_held(&sched->lock);
+
+ if (!group)
+ return;
+
+ /* Do not allow user space work to switch into protected mode, as we
+ * do not fully support this quite yet.
+ */
+ group->fatal_queues |= BIT(cs_id);
+
+ sched_queue_delayed_work(sched, tick, 0);
+}
+
static void
cs_slot_process_fatal_event_locked(struct panthor_device *ptdev,
u32 csg_id, u32 cs_id)
@@ -1719,6 +1762,9 @@ static bool cs_slot_process_irq_locked(struct panthor_device *ptdev,
if (events & CS_TILER_OOM)
cs_slot_process_tiler_oom_event_locked(ptdev, csg_id, cs_id);
+ if (events & CS_PROTM_PENDING)
+ cs_slot_process_protm_pending_event_locked(ptdev, csg_id, cs_id);
+
/* We don't acknowledge the TILER_OOM event since its handling is
* deferred to a separate work.
*/
@@ -1849,6 +1895,34 @@ static void sched_process_idle_event_locked(struct panthor_device *ptdev)
sched_queue_delayed_work(ptdev->scheduler, tick, 0);
}
+static void sched_process_protm_exit_event_locked(struct panthor_device *ptdev)
+{
+ struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
+ struct panthor_scheduler *sched = ptdev->scheduler;
+
+ lockdep_assert_held(&sched->lock);
+
+ /* Acknowledge the protm exit */
+ panthor_fw_update_reqs(glb_iface, req, glb_iface->output->ack,
+ GLB_PROTM_EXIT);
+
+ /* If there are pending fault from protected mode execution, then early
+ * out here. The GPU_IRQ_PROTM_FAULT handling will trigger the propper
+ * error recovery via a GPU reset.
+ */
+ if (panthor_gpu_protm_fault_pending(ptdev))
+ return;
+
+ /* Protected mode exited successfully. Clear protm.active_group so that
+ * tick_work() is unblocked to schedule new work.
+ */
+
+ group_put(sched->protm.active_group);
+ sched->protm.active_group = NULL;
+
+ sched_queue_delayed_work(sched, tick, 0);
+}
+
/**
* sched_process_global_irq_locked() - Process the scheduling part of a global IRQ
* @ptdev: Device.
@@ -1864,6 +1938,9 @@ static void sched_process_global_irq_locked(struct panthor_device *ptdev)
ack = READ_ONCE(glb_iface->output->ack);
evts = (req ^ ack) & GLB_EVT_MASK;
+ if (evts & GLB_PROTM_EXIT)
+ sched_process_protm_exit_event_locked(ptdev);
+
if (evts & GLB_IDLE)
sched_process_idle_event_locked(ptdev);
}
@@ -1873,23 +1950,87 @@ static void process_fw_events_work(struct work_struct *work)
struct panthor_scheduler *sched = container_of(work, struct panthor_scheduler,
fw_events_work);
u32 events = atomic_xchg(&sched->fw_events, 0);
+ u32 csg_events = events & ~JOB_INT_GLOBAL_IF;
struct panthor_device *ptdev = sched->ptdev;
mutex_lock(&sched->lock);
+ while (csg_events) {
+ u32 csg_id = ffs(csg_events) - 1;
+
+ sched_process_csg_irq_locked(ptdev, csg_id);
+ csg_events &= ~BIT(csg_id);
+ }
+
if (events & JOB_INT_GLOBAL_IF) {
sched_process_global_irq_locked(ptdev);
events &= ~JOB_INT_GLOBAL_IF;
}
- while (events) {
- u32 csg_id = ffs(events) - 1;
+ mutex_unlock(&sched->lock);
+}
- sched_process_csg_irq_locked(ptdev, csg_id);
- events &= ~BIT(csg_id);
- }
+static void handle_protm_fault(struct panthor_device *ptdev)
+{
+ struct panthor_scheduler *sched = ptdev->scheduler;
+ u32 csg_id;
+ struct panthor_group *protm_group;
- mutex_unlock(&sched->lock);
+ guard(mutex)(&sched->lock);
+
+ protm_group = sched->protm.active_group;
+
+ if (!protm_group || !panthor_gpu_protm_fault_pending(ptdev))
+ return;
+
+ protm_group->fatal_queues |= GENMASK(protm_group->queue_count - 1, 0);
+
+ /* Different kinds of faults during protected mode can give different
+ * behavior/state.
+ * Case 1) The fault keeps the GPU in protected mode.
+ * In this case, the request to exit protected mode below will
+ * fail and we need to take some further action.
+ * Case 2) The fault do not keep the GPU in protected mode.
+ * In this case, the request to exit protected
+ * mode below will succeed, and we don't need to take any
+ * further action right here.
+ */
+ if (!panthor_fw_protm_exit(ptdev))
+ return;
+
+ /* GPU failed to exit protected mode.
+ * Mark all CSGs as suspended and unbind them, so that they are
+ * unaffected by the GPU reset itself.
+ * We can not suspend the groups in this case, because we are stuck
+ * in protected mode. That is also the reason it is safe to unbind
+ * without suspending first (the groups are already "suspended").
+ * The failing protected group will be scheduled for termination.
+ */
+
+ for (csg_id = 0; csg_id < sched->csg_slot_count; csg_id++) {
+ struct panthor_group *group = sched->csg_slots[csg_id].group;
+
+ if (!group)
+ continue;
+
+ group_get(group);
+
+ group->state = PANTHOR_CS_GROUP_SUSPENDED;
+ sched_process_csg_irq_locked(ptdev, group->csg_id);
+ group_unbind_locked(group);
+
+ drm_WARN_ON(&group->ptdev->base, !list_empty(&group->run_node));
+
+ if (group_can_run(group)) {
+ list_add(&group->run_node,
+ &sched->groups.idle[group->priority]);
+ } else {
+ list_del_init(&group->wait_node);
+ group_queue_work(group, term);
+ }
+
+ group_put(group);
+ }
}
/**
@@ -1935,6 +2076,12 @@ static void csgs_upd_ctx_init(struct panthor_csg_slots_upd_ctx *ctx)
memset(ctx, 0, sizeof(*ctx));
}
+static void csgs_upd_ctx_ring_doorbell(struct panthor_csg_slots_upd_ctx *ctx,
+ u32 csg_id)
+{
+ ctx->update_mask |= BIT(csg_id);
+}
+
static void csgs_upd_ctx_queue_reqs(struct panthor_device *ptdev,
struct panthor_csg_slots_upd_ctx *ctx,
u32 csg_id, u32 value, u32 mask)
@@ -1945,7 +2092,8 @@ static void csgs_upd_ctx_queue_reqs(struct panthor_device *ptdev,
ctx->requests[csg_id].value = (ctx->requests[csg_id].value & ~mask) | (value & mask);
ctx->requests[csg_id].mask |= mask;
- ctx->update_mask |= BIT(csg_id);
+
+ csgs_upd_ctx_ring_doorbell(ctx, csg_id);
}
static int csgs_upd_ctx_apply_locked(struct panthor_device *ptdev,
@@ -1962,8 +2110,12 @@ static int csgs_upd_ctx_apply_locked(struct panthor_device *ptdev,
while (update_slots) {
struct panthor_fw_csg_iface *csg_iface;
u32 csg_id = ffs(update_slots) - 1;
+ u32 req_mask = ctx->requests[csg_id].mask;
update_slots &= ~BIT(csg_id);
+ if (!req_mask)
+ continue;
+
csg_iface = panthor_fw_get_csg_iface(ptdev, csg_id);
panthor_fw_update_reqs(csg_iface, req,
ctx->requests[csg_id].value,
@@ -1980,6 +2132,9 @@ static int csgs_upd_ctx_apply_locked(struct panthor_device *ptdev,
int ret;
update_slots &= ~BIT(csg_id);
+ if (!req_mask)
+ continue;
+
csg_iface = panthor_fw_get_csg_iface(ptdev, csg_id);
ret = panthor_fw_csg_wait_acks(ptdev, csg_id, req_mask, &acked, 100);
@@ -2016,6 +2171,7 @@ struct panthor_sched_tick_ctx {
bool immediate_tick;
bool stop_tick;
u32 csg_upd_failed_mask;
+ struct panthor_group *protm_group;
};
static bool
@@ -2057,6 +2213,10 @@ tick_ctx_pick_groups_from_list(const struct panthor_scheduler *sched,
if (!owned_by_tick_ctx)
group_get(group);
+ /* Only the first pick is allowed to request switch to protm */
+ if (ctx->group_count == 0 && group->protm_pending_queues)
+ ctx->protm_group = group;
+
ctx->group_count++;
/* If we have more than one active group with the same priority,
@@ -2214,6 +2374,48 @@ static void group_term_work(struct work_struct *work)
group_put(group);
}
+static int panthor_sched_protm_enter(struct panthor_device *ptdev)
+{
+ struct panthor_scheduler *sched = ptdev->scheduler;
+ int ret;
+
+ lockdep_assert_held(&sched->lock);
+
+ if (drm_WARN_ON(&ptdev->base, sched->protm.active_group))
+ return 0;
+
+ down_write(&ptdev->protm.lock);
+ ret = panthor_fw_protm_enter(ptdev);
+ up_write(&ptdev->protm.lock);
+
+ return ret;
+}
+
+void panthor_sched_protm_block(struct panthor_device *ptdev)
+{
+ down_read(&ptdev->protm.lock);
+}
+
+void panthor_sched_protm_unblock(struct panthor_device *ptdev)
+{
+ up_read(&ptdev->protm.lock);
+}
+
+int panthor_sched_protm_exit(struct panthor_device *ptdev)
+{
+ int ret;
+
+ /* First, wait a little bit for FW to exit protected mode on its own.
+ * Only if that fails do we request a protected mode exit.
+ */
+
+ ret = panthor_fw_protm_exit_wait(ptdev, 5);
+ if (ret)
+ ret = panthor_fw_protm_exit(ptdev);
+
+ return ret;
+}
+
static void
tick_ctx_cleanup(struct panthor_scheduler *sched,
struct panthor_sched_tick_ctx *ctx)
@@ -2331,6 +2533,46 @@ tick_ctx_schedule_group(struct panthor_scheduler *sched,
CSG_ENDPOINT_CONFIG);
}
+static void
+tick_ctx_handle_protm_group(struct panthor_scheduler *sched,
+ struct panthor_csg_slots_upd_ctx *upd_ctx,
+ struct panthor_group *group)
+{
+ struct panthor_device *ptdev = sched->ptdev;
+ struct panthor_fw_csg_iface *csg_iface;
+ u32 q;
+
+ if (drm_WARN_ON(&ptdev->base, group->csg_id < 0))
+ return;
+
+ csg_iface = panthor_fw_get_csg_iface(ptdev, group->csg_id);
+
+ if (!group->protm_pending_queues)
+ return;
+
+ for (q = 0; q < group->queue_count; q++) {
+ struct panthor_fw_cs_iface *cs_iface;
+
+ if (!(group->protm_pending_queues & BIT(q)))
+ continue;
+
+ cs_iface = panthor_fw_get_cs_iface(ptdev, group->csg_id, q);
+
+ /* Ack any pending CS_PROTM_PENDING so it can run in protm */
+ if ((cs_iface->output->ack ^ cs_iface->input->req) &
+ CS_PROTM_PENDING) {
+ panthor_fw_update_reqs(cs_iface, req,
+ cs_iface->output->ack,
+ CS_PROTM_PENDING);
+ group->protm_pending_queues &= ~BIT(q);
+ }
+ }
+
+ panthor_fw_toggle_reqs(csg_iface, doorbell_req, doorbell_ack,
+ group->protm_pending_queues);
+ csgs_upd_ctx_ring_doorbell(upd_ctx, group->csg_id);
+}
+
static void
tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *ctx)
{
@@ -2403,6 +2645,9 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
}
}
+ if (ctx->protm_group)
+ tick_ctx_handle_protm_group(sched, &upd_ctx, ctx->protm_group);
+
ret = csgs_upd_ctx_apply_locked(ptdev, &upd_ctx);
if (ret) {
panthor_device_schedule_reset(ptdev);
@@ -2443,6 +2688,20 @@ tick_ctx_apply(struct panthor_scheduler *sched, struct panthor_sched_tick_ctx *c
sched->used_csg_slot_count = ctx->group_count;
sched->might_have_idle_groups = ctx->idle_group_count > 0;
+
+ if (ctx->protm_group) {
+ ret = panthor_sched_protm_enter(ptdev);
+ if (ret) {
+ panthor_device_schedule_reset(ptdev);
+ ctx->csg_upd_failed_mask = U32_MAX;
+ }
+
+ if (drm_WARN_ON(&ptdev->base, sched->protm.active_group))
+ group_put(sched->protm.active_group);
+
+ sched->protm.active_group = ctx->protm_group;
+ group_get(sched->protm.active_group);
+ }
}
static u64
@@ -2499,6 +2758,26 @@ static void tick_work(struct work_struct *work)
if (panthor_device_reset_is_pending(sched->ptdev))
goto out_unlock;
+ if (sched->protm.active_group) {
+ bool rt_groups_waiting =
+ !list_empty(&sched->groups.runnable[PANTHOR_CSG_PRIORITY_RT]);
+
+ if (full_tick || rt_groups_waiting) {
+ /* We allow preemption in this case, but we must
+ * ensure we are fully out of protected mode first.
+ * We rely on the GLB_PROTM_EXIT (or error recovery)
+ * to get a new tick.
+ */
+ if (panthor_fw_protm_exit(ptdev)) {
+ drm_err(&ptdev->base,
+ "Failed to exit protected mode");
+ panthor_device_schedule_reset(ptdev);
+ }
+ }
+
+ goto out_unlock;
+ }
+
tick_ctx_init(sched, &ctx);
if (ctx.csg_upd_failed_mask)
goto out_cleanup_ctx;
@@ -2551,13 +2830,34 @@ static void tick_work(struct work_struct *work)
}
/* If we have free CSG slots left, pick idle groups */
- for (prio = PANTHOR_CSG_PRIORITY_COUNT - 1;
- prio >= 0 && !tick_ctx_is_full(sched, &ctx);
- prio--) {
- /* Check the old_group queue first to avoid reprogramming the slots */
- tick_ctx_pick_groups_from_list(sched, &ctx, &ctx.old_groups[prio], false, true);
- tick_ctx_pick_groups_from_list(sched, &ctx, &sched->groups.idle[prio],
- false, false);
+ if (ctx.protm_group) {
+ /* Pick only idle groups with equal or lower priority than the
+ * group triggering protected mode. Do not bother picking
+ * unscheduled idle groups.
+ */
+ for (prio = ctx.protm_group->priority;
+ prio >= 0 && !tick_ctx_is_full(sched, &ctx);
+ prio--)
+ tick_ctx_pick_groups_from_list(sched, &ctx,
+ &ctx.old_groups[prio],
+ false, true);
+ } else {
+ /* No switch to protected, just pick any idle group according
+ * to priority
+ */
+ for (prio = PANTHOR_CSG_PRIORITY_COUNT - 1;
+ prio >= 0 && !tick_ctx_is_full(sched, &ctx);
+ prio--) {
+ /* Check the old_group queue first to avoid
+ * reprogramming the slots
+ */
+ tick_ctx_pick_groups_from_list(sched, &ctx,
+ &ctx.old_groups[prio],
+ false, true);
+ tick_ctx_pick_groups_from_list(sched, &ctx,
+ &sched->groups.idle[prio],
+ false, false);
+ }
}
tick_ctx_apply(sched, &ctx);
@@ -2979,6 +3279,8 @@ void panthor_sched_pre_reset(struct panthor_device *ptdev)
cancel_work_sync(&sched->sync_upd_work);
cancel_delayed_work_sync(&sched->tick_work);
+ handle_protm_fault(ptdev);
+
panthor_sched_suspend(ptdev);
/* Stop all groups that might still accept jobs, so we don't get passed
@@ -3004,6 +3306,9 @@ void panthor_sched_post_reset(struct panthor_device *ptdev, bool reset_failed)
mutex_lock(&sched->reset.lock);
+ group_put(sched->protm.active_group);
+ sched->protm.active_group = NULL;
+
list_for_each_entry_safe(group, group_tmp, &sched->reset.stopped_groups, run_node) {
/* Consider all previously running group as terminated if the
* reset failed.
diff --git a/drivers/gpu/drm/panthor/panthor_sched.h b/drivers/gpu/drm/panthor/panthor_sched.h
index be7e1c8b4f563..fa4a914c9d05a 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.h
+++ b/drivers/gpu/drm/panthor/panthor_sched.h
@@ -52,4 +52,8 @@ void panthor_sched_report_fw_events(struct panthor_device *ptdev, u32 events);
void panthor_fdinfo_gather_group_samples(struct drm_file *file);
+void panthor_sched_protm_block(struct panthor_device *ptdev);
+void panthor_sched_protm_unblock(struct panthor_device *ptdev);
+int panthor_sched_protm_exit(struct panthor_device *ptdev);
+
#endif
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 7/7] drm/panthor: Expose protected rendering features
2026-07-12 13:54 [PATCH v2 0/7] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
` (5 preceding siblings ...)
2026-07-12 13:54 ` [PATCH v2 6/7] drm/panthor: Add support for entering and exiting protected mode Ketil Johnsen
@ 2026-07-12 13:54 ` Ketil Johnsen
6 siblings, 0 replies; 11+ messages in thread
From: Ketil Johnsen @ 2026-07-12 13:54 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Daniel Almeida, Alice Ryhl
Cc: dri-devel, linux-kernel, Ketil Johnsen
From: Boris Brezillon <boris.brezillon@collabora.com>
Extensions to Panthor uAPI:
- New IOCTL for user space to provide protected FW memory.
- New query for checking protected rendering availability/status
and requirements.
- Extends group creation to allow user space to provide a protected
suspend buffer.
The Mali GPU FW needs some protected memory when executing in protected
mode. This FW memory section is assigned a VA during device init.
A user space process with the needed privileges (CAP_SYS_MODULE) must
provide a suitable memory buffer before the Mali GPU is capable of
executing in protected mode.
Processes who want to execute in protected mode must also ensure they
pass a protected suspend buffer during group creation.
Added panthor_kernel_bo_import() to allow user provided buffers.
Refactor panthor_kernel_bo_create() to allow shared code with the
new import variant.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
---
drivers/gpu/drm/panthor/panthor_device.h | 3 +
drivers/gpu/drm/panthor/panthor_drv.c | 23 +++-
drivers/gpu/drm/panthor/panthor_fw.c | 154 ++++++++++++++++++-----
drivers/gpu/drm/panthor/panthor_fw.h | 2 +
drivers/gpu/drm/panthor/panthor_gem.c | 102 +++++++++------
drivers/gpu/drm/panthor/panthor_gem.h | 7 +-
drivers/gpu/drm/panthor/panthor_sched.c | 45 ++++++-
include/uapi/drm/panthor_drm.h | 85 ++++++++++++-
8 files changed, 347 insertions(+), 74 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h
index e5df42f095717..c3fab0a1b77b2 100644
--- a/drivers/gpu/drm/panthor/panthor_device.h
+++ b/drivers/gpu/drm/panthor/panthor_device.h
@@ -351,6 +351,9 @@ struct panthor_device {
* in panthor_vm_lock_region() will ensure this is enough.
*/
struct rw_semaphore lock;
+
+ /** @info: Protected mode info. */
+ struct drm_panthor_protm_info info;
} protm;
};
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index e18ee2d7a8e6f..6be9f33483e7b 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -178,11 +178,13 @@ panthor_get_uobj_array(const struct drm_panthor_obj_array *in, u32 min_stride,
PANTHOR_UOBJ_DECL(struct drm_panthor_mmu_info, page_size_bitmap), \
PANTHOR_UOBJ_DECL(struct drm_panthor_timestamp_info, current_timestamp), \
PANTHOR_UOBJ_DECL(struct drm_panthor_group_priorities_info, pad), \
+ PANTHOR_UOBJ_DECL(struct drm_panthor_protm_info, pad), \
PANTHOR_UOBJ_DECL(struct drm_panthor_sync_op, timeline_value), \
PANTHOR_UOBJ_DECL(struct drm_panthor_queue_submit, syncs), \
PANTHOR_UOBJ_DECL(struct drm_panthor_queue_create, ringbuf_size), \
PANTHOR_UOBJ_DECL(struct drm_panthor_vm_bind_op, syncs), \
- PANTHOR_UOBJ_DECL(struct drm_panthor_bo_sync_op, size))
+ PANTHOR_UOBJ_DECL(struct drm_panthor_bo_sync_op, size), \
+ PANTHOR_UOBJ_DECL(struct drm_panthor_protm_init, pad))
/**
* PANTHOR_UOBJ_SET() - Copy a kernel object to a user object.
@@ -959,6 +961,10 @@ static int panthor_ioctl_dev_query(struct drm_device *ddev, void *data, struct d
args->size = sizeof(ptdev->mmu_info);
return 0;
+ case DRM_PANTHOR_DEV_QUERY_PROTM_INFO:
+ args->size = sizeof(ptdev->protm.info);
+ return 0;
+
default:
return -EINVAL;
}
@@ -992,6 +998,9 @@ static int panthor_ioctl_dev_query(struct drm_device *ddev, void *data, struct d
case DRM_PANTHOR_DEV_QUERY_MMU_INFO:
return PANTHOR_UOBJ_SET(args->pointer, args->size, ptdev->mmu_info);
+ case DRM_PANTHOR_DEV_QUERY_PROTM_INFO:
+ return PANTHOR_UOBJ_SET(args->pointer, args->size, ptdev->protm.info);
+
default:
return -EINVAL;
}
@@ -1589,6 +1598,12 @@ static int panthor_ioctl_bo_query_info(struct drm_device *ddev, void *data,
return 0;
}
+static int panthor_ioctl_protm_init(struct drm_device *ddev, void *data,
+ struct drm_file *file)
+{
+ return panthor_fw_protm_init(file, data);
+}
+
static int
panthor_open(struct drm_device *ddev, struct drm_file *file)
{
@@ -1665,6 +1680,7 @@ static const struct drm_ioctl_desc panthor_drm_driver_ioctls[] = {
PANTHOR_IOCTL(SET_USER_MMIO_OFFSET, set_user_mmio_offset, DRM_RENDER_ALLOW),
PANTHOR_IOCTL(BO_SYNC, bo_sync, DRM_RENDER_ALLOW),
PANTHOR_IOCTL(BO_QUERY_INFO, bo_query_info, DRM_RENDER_ALLOW),
+ PANTHOR_IOCTL(PROTM_INIT, protm_init, DRM_RENDER_ALLOW),
};
static int panthor_mmap(struct file *filp, struct vm_area_struct *vma)
@@ -1785,6 +1801,9 @@ static void panthor_debugfs_init(struct drm_minor *minor)
* - 1.8 - extends DEV_QUERY_TIMESTAMP_INFO with flags
* - 1.9 - adds DRM_PANTHOR_DEV_QUERY_MMU_INFO query
* - adds DRM_PANTHOR_VM_BIND_OP_MAP_SPARSE flag
+ * - 1.10 - adds DRM_IOCTL_PANTHOR_PROTM_INIT ioctl
+ * - adds DRM_PANTHOR_DEV_QUERY_PROTM_INFO query
+ * - adds drm_panthor_group_create::protected_suspend_bo_handle
*/
static const struct drm_driver panthor_drm_driver = {
.driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ |
@@ -1798,7 +1817,7 @@ static const struct drm_driver panthor_drm_driver = {
.name = "panthor",
.desc = "Panthor DRM driver",
.major = 1,
- .minor = 9,
+ .minor = 10,
.gem_prime_import_sg_table = panthor_gem_prime_import_sg_table,
.gem_prime_import = panthor_gem_prime_import,
diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index 76792f9175b57..d282aef84ce4f 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -13,8 +13,10 @@
#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/capability.h>
#include <drm/drm_drv.h>
+#include <drm/drm_file.h>
#include <drm/drm_managed.h>
#include <drm/drm_print.h>
@@ -198,6 +200,12 @@ struct panthor_fw_section {
/** @size: Size of @buf in bytes. */
size_t size;
} data;
+
+ /** @size: Section size. */
+ size_t size;
+
+ /** @va: Section VA. */
+ u32 va;
};
#define CSF_MCU_SHARED_REGION_START 0x04000000ULL
@@ -246,6 +254,9 @@ struct panthor_fw {
/** @shared_section: The section containing the FW interfaces. */
struct panthor_fw_section *shared_section;
+ /** @protm_section: The protected mode section. */
+ struct panthor_fw_section *protm_section;
+
/** @iface: FW interfaces. */
struct panthor_fw_iface iface;
@@ -255,6 +266,9 @@ struct panthor_fw {
struct delayed_work ping_work;
} watchdog;
+ /** @protm_init_lock: Used to serialize protm initialization. */
+ struct mutex protm_init_lock;
+
/**
* @req_waitqueue: FW request waitqueue.
*
@@ -542,6 +556,30 @@ panthor_fw_alloc_suspend_buf_mem(struct panthor_device *ptdev, size_t size)
"FW suspend buffer");
}
+static u32 section_vm_map_flags(const struct panthor_fw_section *section)
+{
+ u32 cache_mode = section->flags & CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_MASK;
+ u32 vm_map_flags = 0;
+
+ if (!(section->flags & CSF_FW_BINARY_IFACE_ENTRY_WR))
+ vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_READONLY;
+
+ if (!(section->flags & CSF_FW_BINARY_IFACE_ENTRY_EX))
+ vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC;
+
+ /* TODO: CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_*_COHERENT are mapped to
+ * non-cacheable for now. We might want to introduce a new
+ * IOMMU_xxx flag (or abuse IOMMU_MMIO, which maps to device
+ * memory and is currently not used by our driver) for
+ * AS_MEMATTR_AARCH64_SHARED memory, so we can take benefit
+ * of IO-coherent systems.
+ */
+ if (cache_mode != CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_CACHED)
+ vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED;
+
+ return vm_map_flags;
+}
+
static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
const struct firmware *fw,
struct panthor_fw_binary_iter *iter,
@@ -550,7 +588,6 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
ssize_t vm_pgsz = panthor_vm_page_size(ptdev->fw->vm);
struct panthor_fw_binary_section_entry_hdr hdr;
struct panthor_fw_section *section;
- u32 section_size;
u32 name_len;
int ret;
@@ -588,12 +625,6 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
return -EINVAL;
}
- if (hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT) {
- drm_warn(&ptdev->base,
- "Firmware protected mode entry is not supported, ignoring");
- return 0;
- }
-
if (hdr.va.start == CSF_MCU_SHARED_REGION_START &&
!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_SHARED)) {
drm_err(&ptdev->base,
@@ -632,36 +663,34 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
section->name = name;
}
- section_size = hdr.va.end - hdr.va.start;
- if (section_size) {
- u32 cache_mode = hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_MASK;
- u32 vm_map_flags = 0;
- u64 va = hdr.va.start;
+ section->size = hdr.va.end - hdr.va.start;
+ section->va = hdr.va.start;
- if (!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_WR))
- vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_READONLY;
+ if (hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT) {
+ if (ptdev->fw->protm_section) {
+ drm_err(&ptdev->base, "Only one protected section supported\n");
+ return -EINVAL;
+ }
- if (!(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_EX))
- vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC;
+ ptdev->protm.info.fw_protected_sections_size = ALIGN(section->size, vm_pgsz);
+ ptdev->fw->protm_section = section;
+ }
- /* TODO: CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_*_COHERENT are mapped to
- * non-cacheable for now. We might want to introduce a new
- * IOMMU_xxx flag (or abuse IOMMU_MMIO, which maps to device
- * memory and is currently not used by our driver) for
- * AS_MEMATTR_AARCH64_SHARED memory, so we can take benefit
- * of IO-coherent systems.
- */
- if (cache_mode != CSF_FW_BINARY_IFACE_ENTRY_CACHE_MODE_CACHED)
- vm_map_flags |= DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED;
+ /* Defer the section->mem creation if this is a protected entry.
+ * This will be populated when DRM_IOCTL_PANTHOR_PROTM_INIT is called.
+ */
+ if (section->size && !(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT)) {
+ u32 vm_map_flags = section_vm_map_flags(section);
section->mem = panthor_kernel_bo_create(ptdev, panthor_fw_vm(ptdev),
- section_size,
+ section->size,
DRM_PANTHOR_BO_NO_MMAP,
- vm_map_flags, va, "FW section");
+ vm_map_flags, section->va,
+ "FW section");
if (IS_ERR(section->mem))
return PTR_ERR(section->mem);
- if (drm_WARN_ON(&ptdev->base, section->mem->va_node.start != hdr.va.start))
+ if (drm_WARN_ON(&ptdev->base, section->mem->va_node.start != section->va))
return -EINVAL;
if (section->flags & CSF_FW_BINARY_IFACE_ENTRY_SHARED) {
@@ -942,6 +971,11 @@ static int panthor_init_csg_iface(struct panthor_device *ptdev,
return -EINVAL;
}
+ if (!csg_idx) {
+ ptdev->protm.info.group_protected_suspend_buf_size =
+ csg_iface->control->protm_suspend_size;
+ }
+
if (csg_idx > 0) {
struct panthor_fw_csg_iface *first_csg_iface =
panthor_fw_get_csg_iface(ptdev, 0);
@@ -1529,6 +1563,66 @@ int panthor_fw_protm_exit(struct panthor_device *ptdev)
return panthor_fw_protm_exit_wait(ptdev, 500);
}
+int panthor_fw_protm_init(struct drm_file *file,
+ struct drm_panthor_protm_init *args)
+{
+ struct panthor_file *pfile = file->driver_priv;
+ struct panthor_device *ptdev = pfile->ptdev;
+ struct panthor_fw_section *protm_section = ptdev->fw->protm_section;
+ struct drm_gem_object *obj;
+ u32 vm_map_flags;
+ int cookie, ret = 0;
+
+ if (!capable(CAP_SYS_MODULE))
+ return -EPERM;
+
+ if (args->pad)
+ return -EINVAL;
+
+ if (!protm_section || !protm_section->size)
+ return -EINVAL;
+
+ guard(mutex)(&ptdev->fw->protm_init_lock);
+
+ if (ptdev->protm.info.state & DRM_PANTHOR_PROTM_INITIALIZED)
+ return 0;
+
+ if (!drm_dev_enter(&ptdev->base, &cookie))
+ return -ENODEV;
+
+ obj = drm_gem_object_lookup(file, args->fw_protected_sections_bo_handle);
+ if (!obj) {
+ ret = -ENOENT;
+ goto out_dev_exit;
+ }
+
+ if (obj->size < ptdev->protm.info.fw_protected_sections_size) {
+ ret = -EINVAL;
+ goto out_gem_put;
+ }
+
+ vm_map_flags = section_vm_map_flags(protm_section);
+
+ protm_section->mem = panthor_kernel_bo_import(ptdev, panthor_fw_vm(ptdev),
+ to_panthor_bo(obj),
+ vm_map_flags, protm_section->va,
+ protm_section->size);
+ if (IS_ERR(protm_section->mem)) {
+ ret = PTR_ERR(protm_section->mem);
+ protm_section->mem = NULL;
+ goto out_gem_put;
+ }
+
+ ptdev->protm.info.state |= DRM_PANTHOR_PROTM_INITIALIZED;
+
+out_gem_put:
+ drm_gem_object_put(obj);
+
+out_dev_exit:
+ drm_dev_exit(cookie);
+ return ret;
+}
+
/**
* panthor_fw_init() - Initialize FW related data.
* @ptdev: Device.
@@ -1550,6 +1644,10 @@ int panthor_fw_init(struct panthor_device *ptdev)
INIT_LIST_HEAD(&fw->sections);
INIT_DELAYED_WORK(&fw->watchdog.ping_work, panthor_fw_ping_work);
+ ret = drmm_mutex_init(&ptdev->base, &fw->protm_init_lock);
+ if (ret)
+ return ret;
+
irq = platform_get_irq_byname(to_platform_device(ptdev->base.dev), "job");
if (irq <= 0)
return -ENODEV;
diff --git a/drivers/gpu/drm/panthor/panthor_fw.h b/drivers/gpu/drm/panthor/panthor_fw.h
index 78658d64b807e..dbd3e58f04eb6 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.h
+++ b/drivers/gpu/drm/panthor/panthor_fw.h
@@ -529,6 +529,8 @@ static inline int panthor_fw_resume(struct panthor_device *ptdev)
int panthor_fw_init(struct panthor_device *ptdev);
void panthor_fw_unplug(struct panthor_device *ptdev);
+int panthor_fw_protm_init(struct drm_file *file,
+ struct drm_panthor_protm_init *args);
int panthor_fw_protm_enter(struct panthor_device *ptdev);
int panthor_fw_protm_exit(struct panthor_device *ptdev);
int panthor_fw_protm_exit_wait(struct panthor_device *ptdev,
diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
index 9855df7381947..69ef4b6012b4f 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.c
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
@@ -74,14 +74,14 @@ static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo)
mutex_unlock(&ptdev->gems.lock);
}
-static void panthor_gem_debugfs_set_usage_flags(struct panthor_gem_object *bo, u32 usage_flags)
+static void panthor_gem_debugfs_add_usage_flags(struct panthor_gem_object *bo, u32 usage_flags)
{
- bo->debugfs.flags = usage_flags;
- panthor_gem_debugfs_bo_add(bo);
+ atomic_or(usage_flags, &bo->debugfs.flags);
}
#else
+static void panthor_gem_debugfs_bo_add(struct panthor_gem_object *bo) {}
static void panthor_gem_debugfs_bo_rm(struct panthor_gem_object *bo) {}
-static void panthor_gem_debugfs_set_usage_flags(struct panthor_gem_object *bo, u32 usage_flags) {}
+static void panthor_gem_debugfs_add_usage_flags(struct panthor_gem_object *bo, u32 usage_flags) {}
static void panthor_gem_debugfs_bo_init(struct panthor_gem_object *bo) {}
#endif
@@ -1027,7 +1027,7 @@ panthor_gem_create(struct drm_device *dev, size_t size, uint32_t flags,
bo->base.resv = bo->exclusive_vm_root_gem->resv;
}
- panthor_gem_debugfs_set_usage_flags(bo, usage_flags);
+ panthor_gem_debugfs_bo_add(bo);
return bo;
err_put:
@@ -1253,7 +1253,9 @@ void panthor_kernel_bo_destroy(struct panthor_kernel_bo *bo)
panthor_kernel_bo_vunmap(bo);
drm_WARN_ON(bo->obj->dev,
- to_panthor_bo(bo->obj)->exclusive_vm_root_gem != panthor_vm_root_gem(vm));
+ to_panthor_bo(bo->obj)->exclusive_vm_root_gem &&
+ (to_panthor_bo(bo->obj)->exclusive_vm_root_gem !=
+ panthor_vm_root_gem(vm)));
panthor_vm_unmap_range(vm, bo->va_node.start, bo->va_node.size);
panthor_vm_free_va(vm, &bo->va_node);
if (vm == panthor_fw_vm(ptdev))
@@ -1264,46 +1266,32 @@ void panthor_kernel_bo_destroy(struct panthor_kernel_bo *bo)
}
/**
- * panthor_kernel_bo_create() - Create and map a GEM object to a VM
+ * panthor_kernel_bo_import() - Create a kernel BO from an existing GEM object
* @ptdev: Device.
* @vm: VM to map the GEM to.
- * @size: Size of the buffer object.
- * @bo_flags: Combination of drm_panthor_bo_flags flags.
+ * @bo: BO to use for our kernel BO.
* @vm_map_flags: Combination of drm_panthor_vm_bind_op_flags (only those
* that are related to map operations).
* @gpu_va: GPU address assigned when mapping to the VM.
* If gpu_va == PANTHOR_VM_KERNEL_AUTO_VA, the virtual address will be
* automatically allocated.
- * @name: Descriptive label of the BO's contents
+ * @vm_map_size: Size of the BO to map to the VM.
*
* Return: A valid pointer in case of success, an ERR_PTR() otherwise.
*/
struct panthor_kernel_bo *
-panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
- size_t size, u32 bo_flags, u32 vm_map_flags,
- u64 gpu_va, const char *name)
+panthor_kernel_bo_import(struct panthor_device *ptdev, struct panthor_vm *vm,
+ struct panthor_gem_object *bo,
+ u32 vm_map_flags, u64 gpu_va, u32 vm_map_size)
{
struct panthor_kernel_bo *kbo;
- struct panthor_gem_object *bo;
- u32 debug_flags = PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL;
int ret;
- if (drm_WARN_ON(&ptdev->base, !vm))
- return ERR_PTR(-EINVAL);
-
kbo = kzalloc_obj(*kbo);
if (!kbo)
return ERR_PTR(-ENOMEM);
- if (vm == panthor_fw_vm(ptdev))
- debug_flags |= PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED;
-
- bo = panthor_gem_create(&ptdev->base, size, bo_flags, vm, debug_flags);
- if (IS_ERR(bo)) {
- ret = PTR_ERR(bo);
- goto err_free_kbo;
- }
-
+ drm_gem_object_get(&bo->base);
kbo->obj = &bo->base;
if (vm == panthor_fw_vm(ptdev)) {
@@ -1312,24 +1300,26 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
goto err_put_obj;
}
- panthor_gem_kernel_bo_set_label(kbo, name);
-
/* The system and GPU MMU page size might differ, which becomes a
* problem for FW sections that need to be mapped at explicit address
* since our PAGE_SIZE alignment might cover a VA range that's
* expected to be used for another section.
* Make sure we never map more than we need.
*/
- size = ALIGN(size, panthor_vm_page_size(vm));
- ret = panthor_vm_alloc_va(vm, gpu_va, size, &kbo->va_node);
+ vm_map_size = ALIGN(vm_map_size, panthor_vm_page_size(vm));
+ ret = panthor_vm_alloc_va(vm, gpu_va, vm_map_size, &kbo->va_node);
if (ret)
goto err_unpin;
- ret = panthor_vm_map_bo_range(vm, bo, 0, size, kbo->va_node.start, vm_map_flags);
+ ret = panthor_vm_map_bo_range(vm, bo, 0, vm_map_size,
+ kbo->va_node.start, vm_map_flags);
if (ret)
goto err_free_va;
kbo->vm = panthor_vm_get(vm);
+ if (vm == panthor_fw_vm(ptdev))
+ panthor_gem_debugfs_add_usage_flags(bo, PANTHOR_DEBUGFS_GEM_USAGE_FLAG_FW_MAPPED);
+
return kbo;
err_free_va:
@@ -1341,12 +1331,54 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
err_put_obj:
drm_gem_object_put(&bo->base);
-
-err_free_kbo:
kfree(kbo);
return ERR_PTR(ret);
}
+/**
+ * panthor_kernel_bo_create() - Create and map a GEM object to a VM
+ * @ptdev: Device.
+ * @vm: VM to map the GEM to.
+ * @size: Size of the buffer object.
+ * @bo_flags: Combination of drm_panthor_bo_flags flags.
+ * @vm_map_flags: Combination of drm_panthor_vm_bind_op_flags (only those
+ * that are related to map operations).
+ * @gpu_va: GPU address assigned when mapping to the VM.
+ * If gpu_va == PANTHOR_VM_KERNEL_AUTO_VA, the virtual address will be
+ * automatically allocated.
+ * @name: Descriptive label of the BO's contents
+ *
+ * Return: A valid pointer in case of success, an ERR_PTR() otherwise.
+ */
+struct panthor_kernel_bo *
+panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
+ size_t size, u32 bo_flags, u32 vm_map_flags,
+ u64 gpu_va, const char *name)
+{
+ struct panthor_kernel_bo *kbo;
+ struct panthor_gem_object *bo;
+
+ if (drm_WARN_ON(&ptdev->base, !vm))
+ return ERR_PTR(-EINVAL);
+
+ bo = panthor_gem_create(&ptdev->base, size, bo_flags, vm, 0);
+ if (IS_ERR(bo))
+ return ERR_CAST(bo);
+
+ kbo = panthor_kernel_bo_import(ptdev, vm, bo, vm_map_flags, gpu_va,
+ size);
+ if (!IS_ERR(kbo)) {
+ panthor_gem_debugfs_add_usage_flags(bo, PANTHOR_DEBUGFS_GEM_USAGE_FLAG_KERNEL);
+ panthor_gem_kernel_bo_set_label(kbo, name);
+ }
+
+ /* panthor_kernel_bo_import() acquires a GEM ref if the import succeeds, so
+ * we can release it unconditionally here.
+ */
+ drm_gem_object_put(&bo->base);
+ return kbo;
+}
+
/**
* panthor_dummy_bo_create() - Create a Panthor BO meant to back sparse bindings.
* @ptdev: Device.
@@ -1642,9 +1674,9 @@ static void panthor_gem_debugfs_bo_print(struct panthor_gem_object *bo,
enum panthor_gem_reclaim_state reclaim_state = bo->reclaim_state;
unsigned int refcount = kref_read(&bo->base.refcount);
int reclaimed_count = atomic_read(&bo->reclaimed_count);
+ u32 gem_usage_flags = atomic_read(&bo->debugfs.flags);
char creator_info[32] = {};
size_t resident_size;
- u32 gem_usage_flags = bo->debugfs.flags;
u32 gem_state_flags = 0;
/* Skip BOs being destroyed. */
diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
index 5ae37d0d3646f..7e88f5dcbff54 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.h
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
@@ -62,7 +62,7 @@ struct panthor_gem_debugfs {
} creator;
/** @flags: Combination of panthor_debugfs_gem_usage_flags flags */
- u32 flags;
+ atomic_t flags;
};
/**
@@ -318,6 +318,11 @@ panthor_kernel_bo_vunmap(struct panthor_kernel_bo *bo)
}
}
+struct panthor_kernel_bo *
+panthor_kernel_bo_import(struct panthor_device *ptdev, struct panthor_vm *vm,
+ struct panthor_gem_object *bo,
+ u32 vm_map_flags, u64 gpu_va, u32 vm_map_size);
+
struct panthor_kernel_bo *
panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
size_t size, u32 bo_flags, u32 vm_map_flags,
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index efa53b0a05d38..15c7bb34a865d 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -1508,10 +1508,15 @@ cs_slot_process_protm_pending_event_locked(struct panthor_device *ptdev,
if (!group)
return;
- /* Do not allow user space work to switch into protected mode, as we
- * do not fully support this quite yet.
+ /* Do not allow user space work to switch into protected mode if we
+ * do not support protected mode on this device.
+ * User space should query (and init) this support before attempting
+ * to use such GPU instructions.
*/
- group->fatal_queues |= BIT(cs_id);
+ if (!(ptdev->protm.info.state & DRM_PANTHOR_PROTM_INITIALIZED))
+ group->fatal_queues |= BIT(cs_id);
+ else
+ group->protm_pending_queues |= BIT(cs_id);
sched_queue_delayed_work(sched, tick, 0);
}
@@ -3962,6 +3967,7 @@ static void add_group_kbo_sizes(struct panthor_device *ptdev,
}
#define MAX_GROUPS_PER_POOL 128
+#define GROUP_CREATE_FLAGS DRM_PANTHOR_GROUP_CREATE_PROTECTED
int panthor_group_create(struct drm_file *file,
const struct drm_panthor_group_create *group_args,
@@ -3976,9 +3982,6 @@ int panthor_group_create(struct drm_file *file,
u32 gid, i, suspend_size;
int ret;
- if (group_args->pad)
- return -EINVAL;
-
if (group_args->priority >= PANTHOR_CSG_PRIORITY_COUNT)
return -EINVAL;
@@ -4031,6 +4034,36 @@ int panthor_group_create(struct drm_file *file,
goto err_put_group;
}
+ if (group_args->protected_suspend_bo_handle) {
+ struct drm_gem_object *obj;
+
+ obj = drm_gem_object_lookup(file, group_args->protected_suspend_bo_handle);
+ if (!obj) {
+ ret = -ENOENT;
+ goto err_put_group;
+ }
+
+ if (obj->size < ptdev->protm.info.group_protected_suspend_buf_size) {
+ drm_gem_object_put(obj);
+ ret = -EINVAL;
+ goto err_put_group;
+ }
+
+ suspend_size = csg_iface->control->protm_suspend_size;
+ group->protm_suspend_buf =
+ panthor_kernel_bo_import(ptdev, panthor_fw_vm(ptdev),
+ to_panthor_bo(obj),
+ DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC,
+ PANTHOR_VM_KERNEL_AUTO_VA,
+ suspend_size);
+ drm_gem_object_put(obj);
+ if (IS_ERR(group->protm_suspend_buf)) {
+ ret = PTR_ERR(group->protm_suspend_buf);
+ group->protm_suspend_buf = NULL;
+ goto err_put_group;
+ }
+ }
+
group->syncobjs = panthor_kernel_bo_create(ptdev, group->vm,
group_args->queues.count *
sizeof(struct panthor_syncobj_64b),
diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h
index a2ff0f4ec6915..a0ed16041e178 100644
--- a/include/uapi/drm/panthor_drm.h
+++ b/include/uapi/drm/panthor_drm.h
@@ -154,6 +154,11 @@ enum drm_panthor_ioctl_id {
* This is useful for imported BOs.
*/
DRM_PANTHOR_BO_QUERY_INFO,
+
+ /**
+ * @DRM_PANTHOR_PROTM_INIT: Device-wide initialize of protected mode.
+ */
+ DRM_PANTHOR_PROTM_INIT,
};
/**
@@ -256,6 +261,11 @@ enum drm_panthor_dev_query_type {
/** @DRM_PANTHOR_DEV_QUERY_MMU_INFO: Query MMU information. */
DRM_PANTHOR_DEV_QUERY_MMU_INFO,
+
+ /**
+ * @DRM_PANTHOR_DEV_QUERY_PROTM_INFO: Query supported protected rendering information.
+ */
+ DRM_PANTHOR_DEV_QUERY_PROTM_INFO,
};
/**
@@ -517,6 +527,51 @@ struct drm_panthor_group_priorities_info {
__u8 pad[3];
};
+/**
+ * enum drm_panthor_protm_state_flags - Describes the state of the protected mode feature.
+ *
+ * List of GPU states which can be used by the GPU to access protected memory.
+ */
+enum drm_panthor_protm_state_flags {
+ /**
+ * @DRM_PANTHOR_PROTM_INITIALIZED: Device-wide initialization of the
+ * protected mode feature is done.
+ */
+ DRM_PANTHOR_PROTM_INITIALIZED = 1 << 0,
+};
+
+/**
+ * struct drm_panthor_protm_info - Protected mode info.
+ *
+ * Structure grouping all queryable information relating to protected mode.
+ */
+struct drm_panthor_protm_info {
+ /**
+ * @state: Combination of enum drm_panthor_protm_state_flags flags.
+ */
+ __u32 state;
+
+ /**
+ * @fw_protected_sections_size: Size of all the protected FW sections.
+ *
+ * Size of the protected buffer to pass through
+ * DRM_IOCTL_PANTHOR_PROTM_INIT.
+ */
+ __u32 fw_protected_sections_size;
+
+ /**
+ * @group_protected_suspend_buf_size: Size of the group suspend buffer.
+ *
+ * This must be used to allocate a protected BO that's big enough to use
+ * as a protected suspend buffer when a group supports protected
+ * rendering.
+ */
+ __u32 group_protected_suspend_buf_size;
+
+ /** @pad: MBZ. */
+ __u32 pad;
+};
+
/**
* struct drm_panthor_dev_query - Arguments passed to DRM_PANTHOR_IOCTL_DEV_QUERY
*/
@@ -901,8 +956,14 @@ struct drm_panthor_group_create {
/** @priority: Group priority (see enum drm_panthor_group_priority). */
__u8 priority;
- /** @pad: Padding field, MBZ. */
- __u32 pad;
+ /**
+ * @protected_suspend_bo_handle: BO to use as a protected suspend buffer.
+ *
+ * This BO must have been allocated from a protected DMA-BUF heap and
+ * imported in panthor. It's size must be at least
+ * drm_panthor_protm_info::group_protected_suspend_buf_size.
+ */
+ __u32 protected_suspend_bo_handle;
/**
* @compute_core_mask: Mask encoding cores that can be used for compute jobs.
@@ -1270,6 +1331,24 @@ struct drm_panthor_bo_query_info {
__u32 pad;
};
+/**
+ * struct drm_panthor_protm_init - Protected mode initialization arguments.
+ */
+struct drm_panthor_protm_init {
+ /**
+ * @fw_protected_sections_bo_handle: Handle of the BO to use for the FW protected
+ * sections.
+ *
+ * This BO must have been allocated from a protected DMA-BUF heap and
+ * imported in panthor. It's size must be at least
+ * drm_panthor_protm_info::fw_protected_sections_size.
+ */
+ __u32 fw_protected_sections_bo_handle;
+
+ /** @pad: MBZ. */
+ __u32 pad;
+};
+
/**
* DRM_IOCTL_PANTHOR() - Build a Panthor IOCTL number
* @__access: Access type. Must be R, W or RW.
@@ -1320,6 +1399,8 @@ enum {
DRM_IOCTL_PANTHOR(WR, BO_SYNC, bo_sync),
DRM_IOCTL_PANTHOR_BO_QUERY_INFO =
DRM_IOCTL_PANTHOR(WR, BO_QUERY_INFO, bo_query_info),
+ DRM_IOCTL_PANTHOR_PROTM_INIT =
+ DRM_IOCTL_PANTHOR(WR, PROTM_INIT, protm_init),
};
#if defined(__cplusplus)
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 3/7] drm/panthor: Explicit expansion of locked VM region
2026-07-12 13:54 ` [PATCH v2 3/7] drm/panthor: Explicit expansion of locked VM region Ketil Johnsen
@ 2026-07-13 6:56 ` Boris Brezillon
0 siblings, 0 replies; 11+ messages in thread
From: Boris Brezillon @ 2026-07-13 6:56 UTC (permalink / raw)
To: Ketil Johnsen
Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Daniel Almeida,
Alice Ryhl, dri-devel, linux-kernel
On Sun, 12 Jul 2026 15:54:35 +0200
Ketil Johnsen <ketil.johnsen@arm.com> wrote:
> Currently the panthor_vm_lock_region() function will implicitly expand
> an already locked VM region. This can be problematic because the caller
> do not reliably know if it needs to call panthor_vm_unlock_region()
> or not.
>
> Worth noting, there is currently no known issues with this as the code
> is written today.
>
> This change introduces panthor_vm_expand_region() which will only work
> if there is already a locked VM region. This again means that the
> original lock and unlock functions can work as a pair. This pairing is
> needed for subsequent protected memory changes.
>
> Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
> ---
> drivers/gpu/drm/panthor/panthor_mmu.c | 87 +++++++++++++++++++--------
> 1 file changed, 62 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index 1f6b9242279c2..b82b01013611c 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -1774,20 +1774,49 @@ static const char *access_type_name(struct panthor_device *ptdev,
> }
> }
>
> +static int panthor_vm_apply_as_lock(struct panthor_vm *vm, u64 region)
> +{
> + struct panthor_device *ptdev = vm->ptdev;
> +
> + lockdep_assert_held(&ptdev->mmu->as.slots_lock);
> +
> + gpu_write64(ptdev->mmu->iomem, AS_LOCKADDR(vm->as.id), region);
> + return as_send_cmd_and_wait(ptdev, vm->as.id, AS_COMMAND_LOCK);
> +}
> +
> static int panthor_vm_lock_region(struct panthor_vm *vm, u64 start, u64 size)
> {
> struct panthor_device *ptdev = vm->ptdev;
> int ret = 0;
>
> - /* sm_step_remap() can call panthor_vm_lock_region() to account for
> - * the wider unmap needed when doing a partial huge page unamp. We
> - * need to ignore the lock if it's already part of the locked region.
> - */
> - if (start >= vm->locked_region.start &&
> - start + size <= vm->locked_region.start + vm->locked_region.size)
> - return 0;
> + if (drm_WARN_ON(&ptdev->base, vm->locked_region.size))
> + return -EINVAL;
> +
> + mutex_lock(&ptdev->mmu->as.slots_lock);
> + if (vm->as.id >= 0 && size) {
> + u64 region = pack_region_range(ptdev, &start, &size);
> +
> + ret = panthor_vm_apply_as_lock(vm, region);
> + }
>
> - /* sm_step_remap() may need a locked region that isn't a strict superset
> + if (!ret) {
> + vm->locked_region.start = start;
> + vm->locked_region.size = size;
> + }
> + mutex_unlock(&ptdev->mmu->as.slots_lock);
> +
> + return ret;
> +}
> +
> +static int panthor_vm_expand_locked_region(struct panthor_vm *vm,
> + u64 start, u64 size)
> +{
> + struct panthor_device *ptdev = vm->ptdev;
> + u64 end;
> + int ret = 0;
> +
> + /* This function is here to handle the following case:
> + * sm_step_remap() may need a locked region that isn't a strict superset
> * of the original one because of having to extend unmap boundaries beyond
> * it to deal with partial unmaps of transparent huge pages. What we want
> * in those cases is to lock the union of both regions. The new region must
> @@ -1795,25 +1824,30 @@ static int panthor_vm_lock_region(struct panthor_vm *vm, u64 start, u64 size)
> * boundaries in a remap operation can only shift up or down respectively,
> * but never otherwise.
> */
> - if (vm->locked_region.size) {
> - u64 end = max(vm->locked_region.start + vm->locked_region.size,
> - start + size);
>
> - drm_WARN_ON_ONCE(&vm->ptdev->base, (start + size <= vm->locked_region.start) ||
> - (start >= vm->locked_region.start + vm->locked_region.size));
> + /* This function can only expand an already locked region */
> + if (drm_WARN_ON(&ptdev->base, !vm->locked_region.size))
> + return -EINVAL;
> +
> + /* Early out if requested range is already locked */
> + if (start >= vm->locked_region.start &&
> + start + size <= vm->locked_region.start + vm->locked_region.size)
> + return 0;
>
> - start = min(start, vm->locked_region.start);
> - size = end - start;
> - }
> + end = max(vm->locked_region.start + vm->locked_region.size,
> + start + size);
> +
> + drm_WARN_ON_ONCE(&ptdev->base, (start + size <= vm->locked_region.start) ||
> + (start >= vm->locked_region.start + vm->locked_region.size));
> +
> + start = min(start, vm->locked_region.start);
> + size = end - start;
>
> mutex_lock(&ptdev->mmu->as.slots_lock);
> if (vm->as.id >= 0 && size) {
> - /* Lock the region that needs to be updated */
> - gpu_write64(ptdev->mmu->iomem, AS_LOCKADDR(vm->as.id),
> - pack_region_range(ptdev, &start, &size));
> + u64 region = pack_region_range(ptdev, &start, &size);
>
> - /* If the lock succeeded, update the locked_region info. */
> - ret = as_send_cmd_and_wait(ptdev, vm->as.id, AS_COMMAND_LOCK);
> + ret = panthor_vm_apply_as_lock(vm, region);
> }
>
> if (!ret) {
> @@ -2367,11 +2401,14 @@ static int panthor_gpuva_sm_step_remap(struct drm_gpuva_op *op,
> */
> unmap_hugepage_align(&op->remap, &unmap_start, &unmap_range);
>
> - /* If the range changed, we might have to lock a wider region to guarantee
> - * atomicity. panthor_vm_lock_region() bails out early if the new region
> - * is already part of the locked region, so no need to do this check here.
> + /* If the range changed, we might have to lock a wider region to
> + * guarantee atomicity.
> */
> - panthor_vm_lock_region(vm, unmap_start, unmap_range);
> + ret = panthor_vm_expand_locked_region(vm, unmap_start,
> + unmap_range);
Could we add the panthor_vm_lock_region() error check in a commit coming
before this one, and maybe flag it for backport, with a Fixes tag?
> + if (ret)
> + return ret;
> +
> panthor_vm_unmap_pages(vm, unmap_start, unmap_range);
> }
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 5/7] drm/panthor: Don't allocate protm_suspend_buf
2026-07-12 13:54 ` [PATCH v2 5/7] drm/panthor: Don't allocate protm_suspend_buf Ketil Johnsen
@ 2026-07-13 7:02 ` Boris Brezillon
0 siblings, 0 replies; 11+ messages in thread
From: Boris Brezillon @ 2026-07-13 7:02 UTC (permalink / raw)
To: Ketil Johnsen
Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Daniel Almeida,
Alice Ryhl, dri-devel, linux-kernel
On Sun, 12 Jul 2026 15:54:37 +0200
Ketil Johnsen <ketil.johnsen@arm.com> wrote:
> The PROTM suspend buffer is only needed if the group is going to
> use PROTM in the first place, so let's not assume we need one until
> we're being asked to.
>
> Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index dc77a174a3368..86c0f12b09e11 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -3642,9 +3642,11 @@ static void add_group_kbo_sizes(struct panthor_device *ptdev,
> if (drm_WARN_ON(&ptdev->base, ptdev != group->ptdev))
> return;
>
> - group->fdinfo.kbo_sizes += group->suspend_buf->obj->size;
> - group->fdinfo.kbo_sizes += group->protm_suspend_buf->obj->size;
> group->fdinfo.kbo_sizes += group->syncobjs->obj->size;
> + group->fdinfo.kbo_sizes += group->suspend_buf->obj->size;
> +
> + if (group->protm_suspend_buf)
> + group->fdinfo.kbo_sizes += group->protm_suspend_buf->obj->size;
>
> for (i = 0; i < group->queue_count; i++) {
> queue = group->queues[i];
> @@ -3724,14 +3726,6 @@ int panthor_group_create(struct drm_file *file,
> goto err_put_group;
> }
>
> - suspend_size = csg_iface->control->protm_suspend_size;
> - group->protm_suspend_buf = panthor_fw_alloc_suspend_buf_mem(ptdev, suspend_size);
> - if (IS_ERR(group->protm_suspend_buf)) {
> - ret = PTR_ERR(group->protm_suspend_buf);
> - group->protm_suspend_buf = NULL;
> - goto err_put_group;
> - }
> -
> group->syncobjs = panthor_kernel_bo_create(ptdev, group->vm,
> group_args->queues.count *
> sizeof(struct panthor_syncobj_64b),
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 6/7] drm/panthor: Add support for entering and exiting protected mode
2026-07-12 13:54 ` [PATCH v2 6/7] drm/panthor: Add support for entering and exiting protected mode Ketil Johnsen
@ 2026-07-13 8:37 ` Boris Brezillon
0 siblings, 0 replies; 11+ messages in thread
From: Boris Brezillon @ 2026-07-13 8:37 UTC (permalink / raw)
To: Ketil Johnsen
Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Daniel Almeida,
Alice Ryhl, dri-devel, linux-kernel, Florent Tomasin,
Paul Toadere, Samuel Percival
Hi Ketil,
On Sun, 12 Jul 2026 15:54:38 +0200
Ketil Johnsen <ketil.johnsen@arm.com> wrote:
> From: Florent Tomasin <florent.tomasin@arm.com>
>
> This patch modifies the Panthor driver code to allow handling
> of the GPU HW protected mode enter and exit.
>
> The logic added by this patch includes:
> - the mechanisms needed for entering and exiting protected mode.
> - the handling of protected mode IRQs and FW interactions.
> - the scheduler changes needed to decide when to enter
> protected mode based on CSG scheduling.
> - GPU fault handling during protected mode execution.
>
> Note that the submission of a protected mode jobs are done
> from the user space.
>
> The following is a summary of how protected mode is entered
> and exited:
> - When the GPU detects a protected mode job needs to be
> executed, an IRQ is sent to the CPU to notify the kernel
> driver that the job is blocked until the GPU has entered
> protected mode. The entering of protected mode is controlled
> by the kernel driver.
> - The Mali Panthor CSF driver will schedule a tick and evaluate
> which CS in the CSG to schedule on slot needs protected mode.
> If the priority of the CSG is not sufficiently high, the
> protected mode job will not progress until the CSG is
> scheduled at top priority.
> - The Panthor scheduler notifies the GPU that the blocked
> protected jobs will soon be able to progress.
> - Once all CSG and CS slots are updated, the scheduler
> requests the GPU to enter protected mode and waits for
> it to be acknowledged.
> - If successful, all protected mode jobs will resume execution
> while normal mode jobs block until the GPU exits
> protected mode, or the kernel driver rotates the CSGs
> and forces the GPU to exit protected mode.
> - If unsuccessful, the scheduler will request a GPU reset.
> - Faults during protected mode are reported GPU wide, and not as
> CSG/CS errors. We allow only one CSG to run in protected mode at a
> time so we know which CSG to blame for the fault.
> - All faults during protected mode are handled with a GPU reset.
> - When a protected mode job is suspended as a result of
> the CSGs rotation, the GPU will send an IRQ to the CPU
> to notify that the protected mode job needs to resume.
>
> This sequence will continue so long the user space is
> submitting protected mode jobs.
>
> Signed-off-by: Florent Tomasin <florent.tomasin@arm.com>
> Co-developed-by: Paul Toadere <paul.toadere@arm.com>
> Signed-off-by: Paul Toadere <paul.toadere@arm.com>
> Co-developed-by: Samuel Percival <samuel.percival@arm.com>
> Signed-off-by: Samuel Percival <samuel.percival@arm.com>
> Co-developed-by: Ketil Johnsen <ketil.johnsen@arm.com>
> Signed-off-by: Ketil Johnsen <ketil.johnsen@arm.com>
> ---
> drivers/gpu/drm/panthor/panthor_device.c | 1 +
> drivers/gpu/drm/panthor/panthor_device.h | 33 +++
> drivers/gpu/drm/panthor/panthor_fw.c | 90 +++++-
> drivers/gpu/drm/panthor/panthor_fw.h | 5 +
> drivers/gpu/drm/panthor/panthor_gpu.c | 53 +++-
> drivers/gpu/drm/panthor/panthor_gpu.h | 4 +
> drivers/gpu/drm/panthor/panthor_mmu.c | 29 +-
> drivers/gpu/drm/panthor/panthor_sched.c | 333 ++++++++++++++++++++++-
> drivers/gpu/drm/panthor/panthor_sched.h | 4 +
> 9 files changed, 533 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c
> index bd417d6ae8c00..c0cdefd330799 100644
> --- a/drivers/gpu/drm/panthor/panthor_device.c
> +++ b/drivers/gpu/drm/panthor/panthor_device.c
> @@ -172,6 +172,7 @@ int panthor_device_init(struct panthor_device *ptdev)
>
> ptdev->soc_data = of_device_get_match_data(ptdev->base.dev);
>
> + init_rwsem(&ptdev->protm.lock);
> init_completion(&ptdev->unplug.done);
> ret = drmm_mutex_init(&ptdev->base, &ptdev->unplug.lock);
> if (ret)
> diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h
> index 35679bfa1f3a6..e5df42f095717 100644
> --- a/drivers/gpu/drm/panthor/panthor_device.h
> +++ b/drivers/gpu/drm/panthor/panthor_device.h
> @@ -332,6 +332,26 @@ struct panthor_device {
> struct list_head node;
> } gems;
> #endif
> + /** @protm: Protected mode related data. */
> + struct {
> + /**
> + * @lock: Lock to prevent MMU operations during protected mode.
> + *
> + * The MMU HW will silently ignore commands issued when the
> + * GPU is in protected mode. It is important that we handle this
> + * for some of the MMU HW interactions.
> + *
> + * panthor_vm_lock_region() will down this as a reader, and
> + * this will prevent any new transition into protected mode.
> + * panthor_vm_lock_region() will then wait for GPU to return
> + * to normal mode before proceeding.
> + * It is now safe to carry out page table modifications.
> + * Only the switch into protected mode itself will down this
> + * as a writer. The wait for GPU to leave protected mode
> + * in panthor_vm_lock_region() will ensure this is enough.
> + */
> + struct rw_semaphore lock;
> + } protm;
> };
>
> struct panthor_gpu_usage {
> @@ -628,6 +648,19 @@ static inline void panthor_ ## __name ## _irq_disable_events(struct panthor_irq
> gpu_write(pirq->iomem, INT_MASK, pirq->mask); \
> }
>
> +/**
> + * PANTHOR_IRQ_HANDLER_DECL() - Forward declare interrupt handlers helpers
> + *
> + * Exposes the IRQ helper functions panthor_xxx_irq_enable_events() and
> + * panthor_xxx_disable_events(), so these can be used from within the
> + * IRQ handler itself.
> + */
> +#define PANTHOR_IRQ_HANDLER_DECL(__name) \
> +static inline void panthor_ ## __name ## _irq_enable_events( \
> + struct panthor_irq *pirq, u32 mask); \
> +static inline void panthor_ ## __name ## _irq_disable_events( \
> + struct panthor_irq *pirq, u32 mask);
> +
This should all be gone when [1] lands, but for the time being, and
assuming the IRQ handler overhaul doesn't make it before this PROTM
series, I think I'd prefer if those were manually defined where needed.
> extern struct workqueue_struct *panthor_cleanup_wq;
>
> static inline void gpu_write(void __iomem *iomem, u32 reg, u32 data)
> diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
> index 389f9182fac16..76792f9175b57 100644
> --- a/drivers/gpu/drm/panthor/panthor_fw.c
> +++ b/drivers/gpu/drm/panthor/panthor_fw.c
> @@ -1035,7 +1035,9 @@ static void panthor_fw_init_global_iface(struct panthor_device *ptdev)
> GLB_CFG_PROGRESS_TIMER |
> GLB_CFG_POWEROFF_TIMER |
> GLB_IDLE_EN |
> - GLB_IDLE;
> + GLB_IDLE |
> + GLB_PROTM_ENTER |
> + GLB_PROTM_EXIT;
>
> if (panthor_fw_has_glb_state(ptdev))
> glb_iface->input->ack_irq_mask |= GLB_STATE_MASK;
> @@ -1441,6 +1443,92 @@ static void panthor_fw_ping_work(struct work_struct *work)
> }
> }
>
> +static int panthor_fw_protm_enter_wait(struct panthor_device *ptdev,
> + u32 timeout_ms)
Looks like this is only used in one place, so I'd inline the content
of this function in panthor_fw_protm_enter().
> +{
> + struct panthor_fw_global_iface *glb_iface =
> + panthor_fw_get_glb_iface(ptdev);
> + int ret;
> +
> + /* Poll for the entry of protected mode.
> + * GLB_PROTM_EXIT is also checked as it may happen that FW enters and
> + * exits protected mode very quickly and so the GPU_STATUS_PROTM_ACTIVE
> + * bit is seen as 0 throughout the polling.
Is there a risk that PROTM_EXIT is acknowledged before we had a chance
to check it, or do we hold the scheduler lock when protm_enter_wait()
is called? If the race exists, I'd be tempted to rework the thing so it can't
happen, maybe with some sort of atomic counter counting the number of times
PROTM was entered, which would turn the check into something like
old_protm_entered_count < atomic_read(fw->protm.entered_count)
That implies reading the counter before the PROTM_ENTER request is sent,
of course. I also see this protm.entered_count as a useful metric to
expose through debugfs.
> + */
> + ret = wait_event_timeout(ptdev->fw->req_waitqueue,
> + (panthor_gpu_status(ptdev) &
> + GPU_STATUS_PROTM_ACTIVE) ||
Why not simply use the PROTM_ENTER event in GLB_ACK_IRQ_MASK for that?
It looks like it would give us exactly what we want, instead of this
transient PROTM_ACTIVE bit in the GPU_STATUS reg, and we're in control
of when we acknowledge the event, so no risk of losing it.
As mentioned above, we probably want a counter so the IRQ handler can
report the progress without the risk of losing the event because it
got acknowledged before we had a chance to see it.
> + ((glb_iface->input->req ^ glb_iface->output->ack) &
> + GLB_PROTM_EXIT),
For multi-conditionals like that, I tend to prefer helper functions
to keep the code readable.
static bool protm_entered(struct panthor_device *ptdev)
{
struct panthor_fw_global_iface *glb_iface;
if (panthor_gpu_status(ptdev) & GPU_STATUS_PROTM_ACTIVE)
return true;
glb_iface = panthor_fw_get_glb_iface(ptdev);
if ((glb_iface->input->req ^ glb_iface->output->ack) & GLB_PROTM_EXIT)
return true;
return false;
}
> + msecs_to_jiffies(timeout_ms));
> + if (!ret)
> + return -ETIMEDOUT;
> +
> + return 0;
> +}
> +
> +int panthor_fw_protm_enter(struct panthor_device *ptdev)
> +{
> + struct panthor_fw_global_iface *glb_iface =
> + panthor_fw_get_glb_iface(ptdev);
> + u32 acked;
> + int ret;
> +
> + /* Restart the watchdog timer, so it doesn't hit immediately
> + * after entering protected mode, since this will cause GPU
> + * to exit protected mode to respond to the ping request.
> + */
> + mod_delayed_work(ptdev->reset.wq, &ptdev->fw->watchdog.ping_work,
> + msecs_to_jiffies(PING_INTERVAL_MS));
nit:
mod_delayed_work(ptdev->reset.wq, &ptdev->fw->watchdog.ping_work,
msecs_to_jiffies(PING_INTERVAL_MS));
> +
> + panthor_fw_toggle_reqs(glb_iface, req, ack, GLB_PROTM_ENTER);
> + panthor_fw_ring_doorbell(ptdev, CSF_GLB_DOORBELL_ID);
> +
> + ret = panthor_fw_glb_wait_acks(ptdev, GLB_PROTM_ENTER, &acked, 4000);
Are you sure you meant 4000ms? Looks unexpectedly high to me.
> + if (ret) {
> + drm_err(&ptdev->base,
> + "Wait for FW protected mode acknowledge timed out");
> + return ret;
> + }
> +
> + /* Wait for the GPU to actually enter protected mode.
> + * There would be some time gap between FW sending the
> + * ACK for GLB_PROTM_ENTER and GPU entering protected mode.
Oh, that explains why you're using GPU_STATUS and not PROTM_ENTER ack,
my bad. I think I'd still prefer entered/exited_count counters to keep
track of those, and then the GPU_STATUS check on top.
> + */
> + ret = panthor_fw_protm_enter_wait(ptdev, 500);
500ms to enter PROTM sounds quite high too, no?
> + if (ret)
> + drm_err(&ptdev->base,
> + "Wait for GPU protected mode enter timed out");
> +
> + return ret;
> +}
> +
> +int panthor_fw_protm_exit_wait(struct panthor_device *ptdev, u32 timeout_ms)
> +{
> + int ret;
> +
> + ret = wait_event_timeout(ptdev->fw->req_waitqueue,
> + !(panthor_gpu_status(ptdev) &
> + GPU_STATUS_PROTM_ACTIVE),
Is there anything preventing PROTM_ENTER requests from being queued while
we're waiting? The protm lock maybe? If that's the case, I'd expect some
lockdep_assert_held() to make sure this is truly the case.
> + msecs_to_jiffies(timeout_ms));
> + if (!ret)
> + return -ETIMEDOUT;
> +
> + return 0;
> +}
> +
> +int panthor_fw_protm_exit(struct panthor_device *ptdev)
> +{
> + struct panthor_fw_global_iface *glb_iface =
> + panthor_fw_get_glb_iface(ptdev);
> +
> + /* Send PING request to force an exit */
> + panthor_fw_toggle_reqs(glb_iface, req, ack, GLB_PING);
> + panthor_fw_ring_doorbell(ptdev, CSF_GLB_DOORBELL_ID);
> +
> + return panthor_fw_protm_exit_wait(ptdev, 500);
> +}
> +
> /**
> * panthor_fw_init() - Initialize FW related data.
> * @ptdev: Device.
> diff --git a/drivers/gpu/drm/panthor/panthor_fw.h b/drivers/gpu/drm/panthor/panthor_fw.h
> index a99a9b6f4825c..78658d64b807e 100644
> --- a/drivers/gpu/drm/panthor/panthor_fw.h
> +++ b/drivers/gpu/drm/panthor/panthor_fw.h
> @@ -529,4 +529,9 @@ static inline int panthor_fw_resume(struct panthor_device *ptdev)
> int panthor_fw_init(struct panthor_device *ptdev);
> void panthor_fw_unplug(struct panthor_device *ptdev);
>
> +int panthor_fw_protm_enter(struct panthor_device *ptdev);
> +int panthor_fw_protm_exit(struct panthor_device *ptdev);
> +int panthor_fw_protm_exit_wait(struct panthor_device *ptdev,
> + u32 timeout_ms);
> +
> #endif
> diff --git a/drivers/gpu/drm/panthor/panthor_gpu.c b/drivers/gpu/drm/panthor/panthor_gpu.c
> index e52c5675981f5..9054ac251fd3e 100644
> --- a/drivers/gpu/drm/panthor/panthor_gpu.c
> +++ b/drivers/gpu/drm/panthor/panthor_gpu.c
> @@ -46,6 +46,9 @@ struct panthor_gpu {
>
> /** @cache_flush_lock: Lock to serialize cache flushes */
> struct mutex cache_flush_lock;
> +
> + /** @protm_fault: True if a GPU_IRQ_PROTM_FAULT has been raised */
> + bool protm_fault;
Is this protected with some lock? If it is, it should probably be documented,
if not, I suspect we want an atomic instead.
> };
>
> #define GPU_INTERRUPTS_MASK \
> @@ -86,10 +89,42 @@ static void panthor_gpu_l2_config_set(struct panthor_device *ptdev)
> gpu_write(gpu->iomem, GPU_L2_CONFIG, l2_config);
> }
>
> +PANTHOR_IRQ_HANDLER_DECL(gpu);
> +
> static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status)
> {
> struct panthor_gpu *gpu = ptdev->gpu;
>
> + if (status & GPU_IRQ_PROTM_FAULT) {
> + /* Make a note of this fault before we clear the interrupt.
> + * This ensures panthor_gpu_protm_fault_pending() can always
> + * give an accurate answer.
> + *
> + * There is a race we need to handle between two interrupts,
> + * this GPU_IRQ_PROTM_FAULT and JOB_INT_GLOBAL_IF with the
> + * GLB_PROTM_EXIT event.
> + *
> + * Although GPU_IRQ_PROTM_FAULT is always raised first,
> + * processing of GLB_PROTM_EXIT could still execute first.
> + * The handling of GLB_PROTM_EXIT MUST know if a
> + * GPU_IRQ_PROTM_FAULT has been raised or not, otherwise it
> + * could incorrectly think everything is fine and resume
> + * with normal scheduling to early.
> + *
> + * We still need to do fault handling (reset) here as well,
> + * because some failures during protected mode do not
> + * automatically exit protected mode (no GLB_PROTM_EXIT).
> + * This means there is a slim chance we do two GPU resets
> + * instead of just one. This is not ideal, but should be safe.
> + */
> + WRITE_ONCE(gpu->protm_fault, true);
> +
> + drm_warn(&ptdev->base, "GPU Fault in protected mode\n");
> + panthor_gpu_irq_disable_events(&ptdev->gpu->irq,
> + GPU_IRQ_PROTM_FAULT);
> + panthor_device_schedule_reset(ptdev);
> + }
> +
> gpu_write(gpu->irq.iomem, INT_CLEAR, status);
>
> if (tracepoint_enabled(gpu_power_status) && (status & GPU_POWER_INTERRUPTS_MASK))
> @@ -106,8 +141,6 @@ static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status)
> fault_status, panthor_exception_name(ptdev, fault_status & 0xFF),
> address);
> }
> - if (status & GPU_IRQ_PROTM_FAULT)
> - drm_warn(&ptdev->base, "GPU Fault in protected mode\n");
>
> spin_lock(&ptdev->gpu->reqs_lock);
> if (status & ptdev->gpu->pending_reqs) {
> @@ -118,6 +151,13 @@ static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status)
> }
> PANTHOR_IRQ_HANDLER(gpu, panthor_gpu_irq_handler);
>
> +bool panthor_gpu_protm_fault_pending(struct panthor_device *ptdev)
> +{
> + return READ_ONCE(ptdev->gpu->protm_fault) ||
> + gpu_read(ptdev->gpu->irq.iomem, INT_RAWSTAT) &
> + GPU_IRQ_PROTM_FAULT;
Why do we need both? Is this not enough to check for GPU_IRQ_PROTM_FAULT
in INT_RAWSTAT? Is too slow to go all the way through the peripheral bus
to read the reg?
> +}
> +
> /**
> * panthor_gpu_unplug() - Called when the GPU is unplugged.
> * @ptdev: Device to unplug.
> @@ -380,6 +420,10 @@ int panthor_gpu_soft_reset(struct panthor_device *ptdev)
> unsigned long flags;
>
> spin_lock_irqsave(&ptdev->gpu->reqs_lock, flags);
> +
> + WRITE_ONCE(ptdev->gpu->protm_fault, false);
> + panthor_gpu_irq_enable_events(&ptdev->gpu->irq, GPU_IRQ_PROTM_FAULT);
> +
> if (!drm_WARN_ON(&ptdev->base,
> ptdev->gpu->pending_reqs & GPU_IRQ_RESET_COMPLETED)) {
> ptdev->gpu->pending_reqs |= GPU_IRQ_RESET_COMPLETED;
> @@ -480,3 +524,8 @@ int panthor_gpu_coherency_init(struct panthor_device *ptdev)
> drm_err(&ptdev->base, "Coherency not supported by the device");
> return -ENOTSUPP;
> }
> +
> +u32 panthor_gpu_status(struct panthor_device *ptdev)
> +{
> + return gpu_read(ptdev->gpu->iomem, GPU_STATUS);
> +}
> diff --git a/drivers/gpu/drm/panthor/panthor_gpu.h b/drivers/gpu/drm/panthor/panthor_gpu.h
> index f615feb056094..00ec9a8c5d7fd 100644
> --- a/drivers/gpu/drm/panthor/panthor_gpu.h
> +++ b/drivers/gpu/drm/panthor/panthor_gpu.h
> @@ -60,4 +60,8 @@ u64 panthor_gpu_get_cycle_count(struct panthor_device *ptdev);
>
> int panthor_gpu_coherency_init(struct panthor_device *ptdev);
>
> +u32 panthor_gpu_status(struct panthor_device *ptdev);
> +
> +bool panthor_gpu_protm_fault_pending(struct panthor_device *ptdev);
> +
> #endif
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index ed2ae5a6008d1..75c484118f6ba 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -1794,11 +1794,30 @@ static int panthor_vm_lock_region(struct panthor_vm *vm, u64 start, u64 size)
> if (drm_WARN_ON(&ptdev->base, vm->locked_region.size))
> return -EINVAL;
>
> + /* Prevent GPU from entering protected mode */
> + panthor_sched_protm_block(ptdev);
> +
> mutex_lock(&ptdev->mmu->as.slots_lock);
> if (vm->as.id >= 0 && size) {
> - u64 region = pack_region_range(ptdev, &start, &size);
> + mutex_unlock(&ptdev->mmu->as.slots_lock);
>
> - ret = panthor_vm_apply_as_lock(vm, region);
> + /* Wait for GPU to exit protected mode.
> + * There is a slim chance that the GPU has faulted in protected
> + * mode. Such failures are handled with a GPU reset.
> + * That is why we temporary release the as.slots_lock, while we
> + * wait for protected mode to exit, since the same lock will
> + * be acquired during the GPU reset procedure.
This gets tricky if we start having to wait for the reset to be effective
in the panthor_vm_lock_region() path. Until now, what was expected was:
if the AS command fails/times-out, we schedule a reset, and fail the operation.
This relates back to another comment I made in the previous revision, where
I didn't quite get how the VM operation was prevented while the GPU is
in PROTM. I'd really like us to prevent any VM update on a resident AS for the
whole time the GPU is in PROTM. Which implies taking the protm lock in read
mode **and** waiting for the PROTM_EXIT event (or
protm.entered_count == protm.exited_count if you track those with counters)
before anything else. This is basically what you do here, but I don't like the
fact this lock+wait-protm-exit is mixed with the concept of AS locking instead
of being its own thing, and leaving the responsibility to acquire+wait+release
to panthor_vm_exec_op(). With that changed, I don't think we'd need
panthor_vm_expand_locked_region() (though it might be good to have regardless).
If it's something you need to do in multiple places, we might want to make it
its own DEFINE_GUARD_COND (basically overloading the existing rwsem one).
> + */
> +
nit: you can drop this extra blank line.
> + panthor_sched_protm_exit(ptdev);
> +
> + mutex_lock(&ptdev->mmu->as.slots_lock);
> +
> + if (vm->as.id >= 0 && size) {
> + u64 region = pack_region_range(ptdev, &start, &size);
> +
> + ret = panthor_vm_apply_as_lock(vm, region);
> + }
> }
>
> if (!ret) {
> @@ -1807,6 +1826,9 @@ static int panthor_vm_lock_region(struct panthor_vm *vm, u64 start, u64 size)
> }
> mutex_unlock(&ptdev->mmu->as.slots_lock);
>
> + if (ret)
> + panthor_sched_protm_unblock(ptdev);
> +
> return ret;
> }
>
> @@ -1890,6 +1912,9 @@ static void panthor_vm_unlock_region(struct panthor_vm *vm)
> vm->locked_region.start = 0;
> vm->locked_region.size = 0;
> mutex_unlock(&ptdev->mmu->as.slots_lock);
> +
> + /* Let scheduler know it is safe to enter protected mode again */
> + panthor_sched_protm_unblock(ptdev);
> }
I'm stopping here for now, but I'll try to finish the review before the end of
the week.
Regards,
Boris
[1]https://lore.kernel.org/dri-devel/20260625-panthor-signal-from-irq-v5-10-8836a74e0ef9@collabora.com/
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-07-13 8:38 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-12 13:54 [PATCH v2 0/7] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
2026-07-12 13:54 ` [PATCH v2 1/7] drm/panthor: De-duplicate FW memory section sync Ketil Johnsen
2026-07-12 13:54 ` [PATCH v2 2/7] drm/panthor: Minor scheduler refactoring Ketil Johnsen
2026-07-12 13:54 ` [PATCH v2 3/7] drm/panthor: Explicit expansion of locked VM region Ketil Johnsen
2026-07-13 6:56 ` Boris Brezillon
2026-07-12 13:54 ` [PATCH v2 4/7] drm/panthor: Pass drm_file instead of panthor_file Ketil Johnsen
2026-07-12 13:54 ` [PATCH v2 5/7] drm/panthor: Don't allocate protm_suspend_buf Ketil Johnsen
2026-07-13 7:02 ` Boris Brezillon
2026-07-12 13:54 ` [PATCH v2 6/7] drm/panthor: Add support for entering and exiting protected mode Ketil Johnsen
2026-07-13 8:37 ` Boris Brezillon
2026-07-12 13:54 ` [PATCH v2 7/7] drm/panthor: Expose protected rendering features Ketil Johnsen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox