From: Boris Brezillon <boris.brezillon@collabora.com>
To: Ketil Johnsen <ketil.johnsen@arm.com>
Cc: Steven Price <steven.price@arm.com>,
Liviu Dudau <liviu.dudau@arm.com>,
Akash Goel <akash.goel@arm.com>,
Karunika Choo <karunika.choo@arm.com>,
Lukas Zapolskas <lukas.zapolskas@arm.com>,
Chris Diamand <chris.diamand@arm.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Daniel Almeida <daniel.almeida@collabora.com>,
Alice Ryhl <aliceryhl@google.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
rust-for-linux@vger.kernel.org,
Florent Tomasin <florent.tomasin@arm.com>,
Paul Toadere <paul.toadere@arm.com>,
Samuel Percival <samuel.percival@arm.com>
Subject: Re: [PATCH v5 05/13] drm/panthor: Add support for entering and exiting protected mode
Date: Mon, 30 Nov 2026 18:17:20 +0100 [thread overview]
Message-ID: <20261130181720.62e9b252@fedora1.home> (raw)
In-Reply-To: <20261116112601.3483649-6-ketil.johnsen@arm.com>
Hi Ketil,
Just a few drive-by comments to start with. I'll try to do a more
extensive review of this patch tomorrow.
On Mon, 16 Nov 2026 12:25:53 +0100
Ketil Johnsen <ketil.johnsen@arm.com> wrote:
> +
> +static bool protm_block_timeout(struct panthor_vm *vm)
> +{
> + /* Blocking of protected mode needs some explanation.
> + *
> + * GPU behavior we try to handle:
> + * - Issuing MMU/AS commands during protm will have no effect.
> + * - Exit of protm will resume normal work execution automatically.
> + *
> + * We do not want to block VM operations just because we are in protm.
> + * Process N being blocked from mapping memory just because process P
> + * is running in protm is seemingly unfair, so we want to avoid that.
> + *
> + * We also do not want to unschedule normal groups each time we enter
> + * protm. This would just add latency before these groups can resume
> + * execution after protm exit. We want GPU to resume this automatically.
> + *
> + * Combining our desires with the GPU protm limitations is challenging,
> + * but this is how we are doing it:
> + *
> + * - Before every affected MMU/AS operations, we block the scheduler/GPU
> + * from entering protm.
> + * - If the GPU is not in protm, then we proceed as normal.
> + * - If the GPU is in protm (or about to enter, or have just exited),
> + * then we proceed with additional logic. This is what we try to
> + * handle right here in this function.
> + * - Processes which execute work in protm will preempt protm (itself).
> + * Preemption is not ideal, but it mainly affects itself.
> + * - Processes which do not execute work in protm, but have an active
> + * AS, will insert an empty page table (TRANSTAB) before continuing.
> + * - Continuing will potentially issue AS commands which will be
> + * ignored, but that is fine in this case.
> + * - We use the page fault handler to restore the correct page
> + * table. We should only see this once GPU have exited protm and
> + * resumed execution of normal work.
> + * - Processes with no active AS will need no further consideration,
> + * since VM ops to these will never touch the GPU HW anyway.
I wonder if this could be documented in a more central place, so we can
refer to this explanation in other places (like in the fault handler
where we test against the empty page table, with no further explanation
on why this is done).
> + */
> +
> + enum protm_block_result res;
> +
> + res = panthor_sched_protm_block_timeout(vm->ptdev, vm);
> + if (res == PROTM_BLOCK_ERROR)
> + return false;
> +
> + if (res == PROTM_BLOCK_DORMANT)
> + panthor_mmu_set_empty_pt(vm);
> +
> + return true;
> +}
> +
[...]
> @@ -1847,6 +1927,79 @@ static void panthor_vm_unlock_region(struct panthor_vm *vm)
> mutex_unlock(&ptdev->mmu->as.slots_lock);
> }
>
> +static bool handle_as_fault_locked(struct panthor_device *ptdev, u32 as)
> +{
> + struct panthor_mmu *mmu = ptdev->mmu;
> + struct panthor_vm *vm = mmu->as.slots[as].vm;
> + struct io_pgtable_cfg *cfg;
> + u64 actual_transtab;
> + u32 empty_transtab_low;
> + u32 cur_transtab_low;
> + int ret;
> +
> + lockdep_assert_held(&ptdev->mmu->as.slots_lock);
> +
> + if (!vm)
> + return false;
> +
> + cfg = &io_pgtable_ops_to_pgtable(vm->pgtbl_ops)->cfg;
> + actual_transtab = cfg->arm_lpae_s1_cfg.ttbr;
> + empty_transtab_low = (u32)(actual_transtab + vm->empty_transtab_offset);
> + cur_transtab_low = gpu_read(mmu->iomem, AS_TRANSTAB(as));
> +
> + if (cur_transtab_low != empty_transtab_low)
> + return false;
We probably need a comment pointing the reader to the detailed
explanation of how it works (which you wrote already, it just needs to
refer to it).
> +
> + gpu_write(mmu->iomem, AS_TRANSTAB(as), (u32)actual_transtab);
> + ret = as_send_cmd_and_wait(ptdev, as, AS_COMMAND_UPDATE);
Is there something preventing a LOCK/UNLOCK AS sequence from crossing a
PROTM mode transition? If not, I think we should re-apply any pending
lock here before updating the AS.
> +
> + return ret ? false : true;
> +}
> +
[...]
> +enum protm_block_result
> +panthor_sched_protm_block_timeout(struct panthor_device *ptdev,
> + struct panthor_vm *vm)
> +{
> + struct panthor_scheduler *sched = ptdev->scheduler;
> + int ret;
> +
> + if (!sched)
> + return PROTM_BLOCK_NORMAL;
> +
> + down_read(&sched->protm.lock);
> +
> + if (!sched->protm.active_group)
> + return PROTM_BLOCK_NORMAL; /* All good, we are in normal mode */
> +
> + /* We will only exit protected mode for the passed vm and the MCU VM.
> + * Other VMs have no active CSG work, so MMU updates can proceed,
> + * although with special caution (delayed updates)!
> + */
> + if (sched->protm.active_group->vm != vm && !panthor_vm_for_mcu(vm))
> + return PROTM_BLOCK_DORMANT; /* Specified VM can proceed, with caution. */
You can drop the comment next to `return PROTM_BLOCK_DORMANT;` since
it's all explained detailed in the comment before the if (). In
general, I'm not a huge fan of this "mix code and comment on the same
line" pattern.
> +
> + /* Give GPU a chance to finish ongoing protm work by itself */
> + ret = panthor_fw_protm_exit_wait(ptdev, 5);
> + if (!ret)
> + return PROTM_BLOCK_NORMAL; /* All good, we are back to normal mode */
> +
> + /* We do not want this function to fail, because that can lead to
> + * innocent processes failing. That is why we wait up to 2x the job
> + * timeout for GPU to exit protm here. This shall cover the worst case
> + * where protm work hangs and we must rely on job timeout to recover.
> + */
> + ret = panthor_fw_protm_exit(ptdev, JOB_TIMEOUT_MS << 1);
> + if (ret)
> + up_read(&sched->protm.lock);
We've been discussing a synchronization mechanism relying on dma_fences,
which will hopefully address some of the concerns I have with this
rwsem-based approach:
- the fact the timeout exists in two places instead of just one (I'd
expect us to re-use the timer we have in panthor_sched.c to force
re-evaluation more often than we would normally do when groups operate
in normal mode)
- the fact the timeout itself is quite huge (10s) to cover for the case
where the PROTM section takes too long to execute (there should really
be a smaller tick period in that case, so we can exit early)
- the fact a timeout/fault scheduling a RESET might cause some
stalls because the PROTM lock might be held in read mode for a huge
amount of time (timeout of 10s, again), before the RESET logic can
acquire it to re-initialize the PROTM state (currently not an issue
because we don't acquire the PROTM lock in the reset path, but still
- the fact we might block a VM bind queue in its run_job() function,
waiting for a PROTM exit, when ::run_job() is expected to not block
for too long
and probably other things I don't remember of. With a fence-based
serialization approach, not only we can integrate gracefully with the
drm_sched dependency model for our VM_BIND queue (::prepare_job() can
return the PROTM fence to wait on before the job is considered for
execution), but it also solves the potential deadlock in the
recovery path by allowing us to signal the PROTM fence with an error
right after we've issued a RESET, which will naturally unblock things
and properly model the fact a RESET (slow RESET) is effectively a PROTM
exit.
> +
> + return ret ? PROTM_BLOCK_ERROR : PROTM_BLOCK_NORMAL;
> +}
Regards,
Boris
next prev parent reply other threads:[~2026-11-30 17:17 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 01/13] drm/panthor: De-duplicate FW memory section sync Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 02/13] drm/panthor: Minor scheduler refactoring Ketil Johnsen
2026-11-27 16:36 ` Steven Price
2026-11-16 11:25 ` [PATCH v5 03/13] drm/panthor: Pass drm_file instead of panthor_file Ketil Johnsen
2026-11-27 16:53 ` Steven Price
2026-11-16 11:25 ` [PATCH v5 04/13] drm/panthor: Don't allocate protm_suspend_buf Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 05/13] drm/panthor: Add support for entering and exiting protected mode Ketil Johnsen
2026-11-30 17:17 ` Boris Brezillon [this message]
2026-11-16 11:25 ` [PATCH v5 06/13] drm/panthor: New function for FW section map flags Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 07/13] drm/panthor: Keep size and VA in FW section obj Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 08/13] drm/panthor: Refactor GEM usage flags assignment Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 09/13] drm/panthor: Create kernel BO from existing GEM Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 10/13] drm/panthor: Use a copy of suspend buffer sizes Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 11/13] drm/panthor: Support FW init of protm Ketil Johnsen
2026-11-16 18:00 ` kernel test robot
2026-11-16 11:26 ` [PATCH v5 12/13] drm/panthor: Protm support for groups Ketil Johnsen
2026-11-16 11:26 ` [PATCH v5 13/13] drm/panthor: Bump version to expose protm feature Ketil Johnsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130181720.62e9b252@fedora1.home \
--to=boris.brezillon@collabora.com \
--cc=airlied@gmail.com \
--cc=akash.goel@arm.com \
--cc=aliceryhl@google.com \
--cc=chris.diamand@arm.com \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=florent.tomasin@arm.com \
--cc=karunika.choo@arm.com \
--cc=ketil.johnsen@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liviu.dudau@arm.com \
--cc=lukas.zapolskas@arm.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=paul.toadere@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=samuel.percival@arm.com \
--cc=simona@ffwll.ch \
--cc=steven.price@arm.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox