drm/panthor: Protected mode support for Mali CSF GPUs
v2 cover drm/panthor: Protected mode support for Mali CSF GPUs
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/[email protected]/
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:
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(-)
Signature · 1 line
2.43.0
PATCH v2 1/7 drm/panthor: De-duplicate FW memory section sync
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.
--- drivers/gpu/drm/panthor/panthor_fw.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-)
drivers/gpu/drm/panthor/panthor_fw.c +6 -16
@@ -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 ); } }
Signature · 1 line
2.43.0
Re: [PATCH v2 1/7] drm/panthor: De-duplicate FW memory section sync
Quoted 10 lines · 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 <[email protected]>Reviewed-by Liviu Dudau <[email protected]>Signed-off-by Ketil Johnsen <[email protected]>
Quoted 69 lines
--- drivers/gpu/drm/panthor/panthor_fw.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-)drivers/gpu/drm/panthor/panthor_fw.c +6
-16@@ -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 ); } }
PATCH v2 2/7 drm/panthor: Minor scheduler refactoring
In reply to Ketil JohnsenFrom: Florent Tomasin <[email protected]>
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.
--- drivers/gpu/drm/panthor/panthor_sched.c | 126 ++++++++++++++---------- 1 file changed, 74 insertions(+), 52 deletions(-)
drivers/gpu/drm/panthor/panthor_sched.c +74 -52
@@ -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 *cfor (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 *cfor (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); } }
Signature · 1 line
2.43.0
Steven Price
maintainerRe: [PATCH v2 2/7] drm/panthor: Minor scheduler refactoring
Quoted 48 lines · Ketil Johnsen
From: Florent Tomasin <[email protected]>
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 <[email protected]>Co-developed-by Ketil Johnsen <[email protected]>Signed-off-by Ketil Johnsen <[email protected]>--- drivers/gpu/drm/panthor/panthor_sched.c | 126 ++++++++++++++---------- 1 file changed, 74 insertions(+), 52 deletions(-)drivers/gpu/drm/panthor/panthor_sched.c +26
-0@@ -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; +
drivers/gpu/drm/panthor/panthor_sched.c tick_ctx_cleanup(struct panthor_scheduler *sched, · line 2305
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_sched.c +10
-0+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 );
Shouldn't this use panthor_fw_csg_endpoint_req_update() like the previous code? Otherwise this breaks on hardware with panthor_fw_has_64bit_ep_req().
Thanks,
Steve
Quoted 121 lines
drivers/gpu/drm/panthor/panthor_sched.c +38
-52+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 *cfor (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 *cfor (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); } }
Liviu Dudau
maintainerRe: [PATCH v2 2/7] drm/panthor: Minor scheduler refactoring
In reply to Ketil JohnsenQuoted 30 lines · Ketil Johnsen
From: Florent Tomasin <[email protected]>
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 <[email protected]>Co-developed-by Ketil Johnsen <[email protected]>Signed-off-by Ketil Johnsen <[email protected]>--- drivers/gpu/drm/panthor/panthor_sched.c | 126 ++++++++++++++---------- 1 file changed, 74 insertions(+), 52 deletions(-)drivers/gpu/drm/panthor/panthor_sched.c +8
-0@@ -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 ))
drivers/gpu/drm/panthor/panthor_sched.c tick_ctx_cleanup(struct panthor_scheduler *sched, · line 2287
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_sched.c +10
-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,
I think the name of this function is misleading, as it doesn't reschedule anything, just updates the CSG's priority information. Maybe call it tick_ctx_update_group_prio ?
Quoted 8 lines
drivers/gpu/drm/panthor/panthor_sched.c +8
-0+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; +
drivers/gpu/drm/panthor/panthor_sched.c tick_ctx_cleanup(struct panthor_scheduler *sched, · line 2305
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_sched.c +10
-0+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 );
As Steven mentioned, this should use panthor_fw_csg_endpoint_req_update() instead.
Best regards,
Liviu
Quoted 124 lines
drivers/gpu/drm/panthor/panthor_sched.c +38
-52+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 *cfor (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 *cfor (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); } }Signature · 1 line
2.43.0
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯PATCH v2 3/7 drm/panthor: Explicit expansion of locked VM region
In reply to Ketil JohnsenCurrently 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.
--- drivers/gpu/drm/panthor/panthor_mmu.c | 87 +++++++++++++++++++-------- 1 file changed, 62 insertions(+), 25 deletions(-)
drivers/gpu/drm/panthor/panthor_mmu.c +62 -25
@@ -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); }
Signature · 1 line
2.43.0
Boris Brezillon
maintainerRe: [PATCH v2 3/7] drm/panthor: Explicit expansion of locked VM region
Quoted 127 lines · On Sun, 12 Jul 2026 15:54:35 +0200 Ketil Johnsen <[email protected]> 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 callpanthor_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 <[email protected]>--- drivers/gpu/drm/panthor/panthor_mmu.c | 87 +++++++++++++++++++-------- 1 file changed, 62 insertions(+), 25 deletions(-)drivers/gpu/drm/panthor/panthor_mmu.c +55
-21@@ -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);
drivers/gpu/drm/panthor/panthor_mmu.c static int panthor_gpuva_sm_step_remap(struct drm_gpuva_op *op, · line 2408
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_mmu.c +4
-4-/* 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?
Quoted 6 lines
drivers/gpu/drm/panthor/panthor_mmu.c +3
-0+if (ret) +return ret; +panthor_vm_unmap_pages (vm, unmap_start, unmap_range); }
Re: [PATCH v2 3/7] drm/panthor: Explicit expansion of locked VM region
In reply to Ketil JohnsenQuoted 8 lines · 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 callpanthor_vm_unlock_region()or not.Worth noting, there is currently no known issues with this as the code is written today.
Quoted 6 lines
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 <[email protected]>
Best regards,
Liviu
Quoted 132 lines
--- drivers/gpu/drm/panthor/panthor_mmu.c | 87 +++++++++++++++++++-------- 1 file changed, 62 insertions(+), 25 deletions(-)drivers/gpu/drm/panthor/panthor_mmu.c +62
-25@@ -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); }Signature · 1 line
2.43.0
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯PATCH v2 4/7 drm/panthor: Pass drm_file instead of panthor_file
In reply to Ketil JohnsenFrom: Boris Brezillon <[email protected]>
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.
--- 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(-)
drivers/gpu/drm/panthor/panthor_drv.c +16 -20
@@ -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);
drivers/gpu/drm/panthor/panthor_mmu.c +7 -4
@@ -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;
drivers/gpu/drm/panthor/panthor_mmu.h +3 -3
@@ -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);
drivers/gpu/drm/panthor/panthor_sched.c +22 -15
@@ -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;
drivers/gpu/drm/panthor/panthor_sched.h +10 -13
@@ -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
Signature · 1 line
2.43.0
Steven Price
maintainerRe: [PATCH v2 4/7] drm/panthor: Pass drm_file instead of panthor_file
Quoted 8 lines · Ketil Johnsen
From: Boris Brezillon <[email protected]>
Some sched helpers need info that are part of
drm_file, and we will soon need to calldrm_gem_object_lookup()frompanthor_group_create(). Let's prepare for that by passing adrm_fileinstead ofpanthor_fileto all current helpers taking apanthor_file, so we keep things consistent.Signed-off-by Boris Brezillon <[email protected]>
Missing SoB from Ketil.
Quoted 115 lines
--- 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(-)drivers/gpu/drm/panthor/panthor_drv.c +10
-15@@ -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); }
drivers/gpu/drm/panthor/panthor_drv.c static int panthor_mmap(struct file *filp, struct vm_area_struct *vma) · line 1703
Quoted 6 lines
drivers/gpu/drm/panthor/panthor_drv.c +1
-1@@ -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)
I can't see the corresponding update to the call-site for this function.
Thanks,
Steve
Quoted 276 lines
drivers/gpu/drm/panthor/panthor_drv.c +5
-4{ +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);drivers/gpu/drm/panthor/panthor_mmu.c +7
-4@@ -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;drivers/gpu/drm/panthor/panthor_mmu.h +3
-3@@ -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);drivers/gpu/drm/panthor/panthor_sched.c +22
-15@@ -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;drivers/gpu/drm/panthor/panthor_sched.h +10
-13@@ -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
PATCH v2 5/7 drm/panthor: Don't allocate protm_suspend_buf
In reply to Ketil JohnsenThe 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.
--- drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/gpu/drm/panthor/panthor_sched.c +4 -10
@@ -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),
Signature · 1 line
2.43.0
Re: [PATCH v2 5/7] drm/panthor: Don't allocate protm_suspend_buf
Quoted 5 lines · On Sun, 12 Jul 2026 15:54:37 +0200 Ketil Johnsen <[email protected]> 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 <[email protected]>
Quoted 37 lines
--- drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)drivers/gpu/drm/panthor/panthor_sched.c +4
-10@@ -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),
Re: [PATCH v2 5/7] drm/panthor: Don't allocate protm_suspend_buf
In reply to Ketil JohnsenQuoted 5 lines · 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 <[email protected]>
Quoted 37 lines
--- drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)drivers/gpu/drm/panthor/panthor_sched.c +4
-10@@ -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),
Re: [PATCH v2 5/7] drm/panthor: Don't allocate protm_suspend_buf
In reply to Ketil JohnsenQuoted 5 lines · 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 <[email protected]>
Best regards,
Liviu
Quoted 40 lines
--- drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)drivers/gpu/drm/panthor/panthor_sched.c +4
-10@@ -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),Signature · 1 line
2.43.0
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯PATCH v2 6/7 drm/panthor: Add support for entering and exiting protected mode
In reply to Ketil JohnsenFrom: Florent Tomasin <[email protected]>
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.
--- 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(-)
drivers/gpu/drm/panthor/panthor_device.c +1 -0
@@ -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)
drivers/gpu/drm/panthor/panthor_device.h +33 -0
@@ -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_irqgpu_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)
drivers/gpu/drm/panthor/panthor_fw.c +89 -1
102 lines not on this page · raw message
drivers/gpu/drm/panthor/panthor_fw.h +5 -0
@@ -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
drivers/gpu/drm/panthor/panthor_gpu.c +51 -2
90 lines not on this page · raw message
drivers/gpu/drm/panthor/panthor_gpu.h +4 -0
@@ -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
drivers/gpu/drm/panthor/panthor_mmu.c +27 -2
@@ -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)
drivers/gpu/drm/panthor/panthor_sched.c +319 -14
478 lines not on this page · raw message
drivers/gpu/drm/panthor/panthor_sched.h +4 -0
@@ -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
Signature · 1 line
2.43.0
Boris Brezillon
maintainerRe: [PATCH v2 6/7] drm/panthor: Add support for entering and exiting protected mode
Hi Ketil,
Quoted 117 lines · On Sun, 12 Jul 2026 15:54:38 +0200 Ketil Johnsen <[email protected]> wrote:
From: Florent Tomasin <[email protected]>
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 <[email protected]>Co-developed-by Paul Toadere <[email protected]>Signed-off-by Paul Toadere <[email protected]>Co-developed-by Samuel Percival <[email protected]>Signed-off-by Samuel Percival <[email protected]>Co-developed-by Ketil Johnsen <[email protected]>Signed-off-by Ketil Johnsen <[email protected]>--- 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(-)drivers/gpu/drm/panthor/panthor_device.c +1
-0@@ -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)drivers/gpu/drm/panthor/panthor_device.h +23
-0@@ -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_irqgpu_write (pirq->iomem,INT_MASK , pirq->mask); \ } +/** +* PANTHOR_IRQ_HANDLER_DECL() - Forward declare interrupt handlers helpers +*
drivers/gpu/drm/panthor/panthor_device.h static inline void panthor_ ## __name ## _irq_disable_events(struct panthor_irq · line 663
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_device.h +10
-0+* 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.
Quoted 19 lines
drivers/gpu/drm/panthor/panthor_device.h +0
-0extern struct workqueue_struct *panthor_cleanup_wq;static inline void gpu_write (void __iomem *iomem,u32 reg,u32 data)drivers/gpu/drm/panthor/panthor_fw.c +3
-1@@ -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 ;
drivers/gpu/drm/panthor/panthor_fw.c static void panthor_fw_ping_work(struct work_struct *work) · line 1447
Quoted 5 lines
drivers/gpu/drm/panthor/panthor_fw.c +2
-0@@ -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().
drivers/gpu/drm/panthor/panthor_fw.c static void panthor_fw_ping_work(struct work_struct *work) · line 1456
Quoted 9 lines
drivers/gpu/drm/panthor/panthor_fw.c +9
-0+{ +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.
drivers/gpu/drm/panthor/panthor_fw.c static void panthor_fw_ping_work(struct work_struct *work) · line 1460
Quoted 4 lines
drivers/gpu/drm/panthor/panthor_fw.c +4
-0+*/ + 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.
drivers/gpu/drm/panthor/panthor_fw.c static void panthor_fw_ping_work(struct work_struct *work) · line 1462
Quoted 2 lines
drivers/gpu/drm/panthor/panthor_fw.c +2
-0+ ((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;
}Quoted 10 lines
drivers/gpu/drm/panthor/panthor_fw.c +10
-0+ 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 =
drivers/gpu/drm/panthor/panthor_fw.c static void panthor_fw_ping_work(struct work_struct *work) · line 1482
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_fw.c +10
-0+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));
drivers/gpu/drm/panthor/panthor_fw.c static void panthor_fw_ping_work(struct work_struct *work) · line 1487
Quoted 5 lines
drivers/gpu/drm/panthor/panthor_fw.c +5
-0+ +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.
drivers/gpu/drm/panthor/panthor_fw.c static void panthor_fw_ping_work(struct work_struct *work) · line 1496
Quoted 9 lines
drivers/gpu/drm/panthor/panthor_fw.c +9
-0+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.
drivers/gpu/drm/panthor/panthor_fw.c static void panthor_fw_ping_work(struct work_struct *work) · line 1498
Quoted 2 lines
drivers/gpu/drm/panthor/panthor_fw.c +2
-0+*/ + ret =panthor_fw_protm_enter_wait (ptdev,500 );
500ms to enter PROTM sounds quite high too, no?
Quoted 4 lines
drivers/gpu/drm/panthor/panthor_fw.c +4
-0+if (ret) +drm_err (&ptdev->base, +"Wait for GPU protected mode enter timed out" ); +
drivers/gpu/drm/panthor/panthor_fw.c static void panthor_fw_ping_work(struct work_struct *work) · line 1512
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_fw.c +10
-0+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.
Quoted 41 lines
drivers/gpu/drm/panthor/panthor_fw.c +19
-0+ 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. drivers/gpu/drm/panthor/panthor_fw.h +5
-0@@ -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 drivers/gpu/drm/panthor/panthor_gpu.c +0
-0
drivers/gpu/drm/panthor/panthor_gpu.c struct panthor_gpu { · line 51
Quoted 6 lines
drivers/gpu/drm/panthor/panthor_gpu.c +3
-0@@ -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.
Quoted 56 lines
drivers/gpu/drm/panthor/panthor_gpu.c +32
-2};#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) {
drivers/gpu/drm/panthor/panthor_gpu.c static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status) · line 158
Quoted 8 lines
drivers/gpu/drm/panthor/panthor_gpu.c +5
-0@@ -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?
Quoted 51 lines
drivers/gpu/drm/panthor/panthor_gpu.c +11
-0+} +/** * 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 ); +}drivers/gpu/drm/panthor/panthor_gpu.h +4
-0@@ -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 drivers/gpu/drm/panthor/panthor_mmu.c +3
-0@@ -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) {
drivers/gpu/drm/panthor/panthor_mmu.c static int panthor_vm_lock_region(struct panthor_vm *vm, u64 start, u64 size) · line 1809
Quoted 10 lines
drivers/gpu/drm/panthor/panthor_mmu.c +7
-2-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).
drivers/gpu/drm/panthor/panthor_mmu.c static int panthor_vm_lock_region(struct panthor_vm *vm, u64 start, u64 size) · line 1811
Quoted 2 lines
drivers/gpu/drm/panthor/panthor_mmu.c +2
-0+*/ +
nit: you can drop this extra blank line.
Quoted 23 lines
drivers/gpu/drm/panthor/panthor_mmu.c +12
-0+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; }
drivers/gpu/drm/panthor/panthor_mmu.c static void panthor_vm_unlock_region(struct panthor_vm *vm) · line 1918
Quoted 7 lines
drivers/gpu/drm/panthor/panthor_mmu.c +3
-0@@ -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/
PATCH v2 7/7 drm/panthor: Expose protected rendering features
In reply to Ketil JohnsenFrom: Boris Brezillon <[email protected]>
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.
--- 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(-)
drivers/gpu/drm/panthor/panthor_device.h +3 -0
@@ -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; };
drivers/gpu/drm/panthor/panthor_drv.c +21 -2
@@ -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 dcase 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,
drivers/gpu/drm/panthor/panthor_fw.c +126 -28
231 lines not on this page · raw message
drivers/gpu/drm/panthor/panthor_fw.h +2 -0
@@ -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,
drivers/gpu/drm/panthor/panthor_gem.c +67 -35
186 lines not on this page · raw message
drivers/gpu/drm/panthor/panthor_gem.h +6 -1
@@ -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,
drivers/gpu/drm/panthor/panthor_sched.c +39 -6
70 lines not on this page · raw message
include/uapi/drm/panthor_drm.h +83 -2
121 lines not on this page · raw message
Signature · 1 line
2.43.0