From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.251.105.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796059052; b=hDZxfDGJ4jkcb/fhq8JXy2+qM5+sXNPjCo5GpsZQhvwXuImBdfywUp/AsyijuqnZsSlb Cp+t+SYDWUAxx+HyjWfd8U6Vo0AEv1GPfDjLxiUpShFCZn2OkH9XPuM5tcaVJqmkUbFAg qWeOSqq+eSdwIqlQ+I6sX4SfpKvq6JR/Kxi+yP1SWabPpPSTNmNts2LQFuO4sQ6Dvz6q1 IVBohyadZWgqafsQnrFKPFpK7mAM0tZ5kSp0B6UojZC32qmqxAGtGjTLXg88fWmGImxgd SX2HOw7muWDleOVIF1wwkjuQAXoMUPlijjw1K1dk7q/wzN4Kb2N6nfk8j+yuWhq/6NA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796059052; h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject: Message-ID:In-Reply-To:References:Organization:X-Mailer:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=YcJyN2StKNPP2myNTuT0NfJKgrBPm3SN5JBAyBENR60=; b=5jR/ujV1r2hgguV6qZkKAn26TaDDwKm3zc0pz2y7vTETJDdzBe8KGsV3V3RqJ3B24I20 7LZNvkvInxXLNv14BIqd/xSgJOJAec9+CwW4GnQfYKMBijVAud8DF3d9tDKXNLsH8yigI tmdEbmwYzoihPJyJpruLBPcAzHNlnMDbBehdSMf79pCtWFrVxsKiKVH8DT1CMMoveQLV0 QxKbR0Ik5jR6CsvElszQdErEH95M6soHUOQ/9z8eAAIkAEVzwNlp/tqg9j8wfycuLg6fP T2TmFZUaDKBZoTBTrGqG2+1hG9CVPH/oe3yxcrcXkUSSQHXrJ62DpgvZ03MGcOw2dkg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=cWdmII+s; arc=none smtp.remote-ip=148.251.105.195 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE0D3606A336; Mon, 30 Nov 2026 17:17:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CE0D3606A336 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=cWdmII+s DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1796059050; bh=iFVIfutW7wI5Bqtd0zm+Az/7j8J9bpRRiLe+kl9RXvk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=cWdmII+savXYCqZA4LJNKIVv9cdmbLiBAmZVc6mH0L9ezxzCKCBqMdx6BIyS/j0rY nmkhGriVJj6UKfxrTR+xEJJzTjQiQpn1Si38PsIn+Hm7VKrUJAbW431NAMMp/exPBV BIsDOPcsmfJ54HpswulgT3aVGpF1S3qH4omGwN4s1wygd6ZB2a1LKs06M+6/3TenPz bnu/NLoSFkfVPg3WaidlGvVc0/Ne7hfmMsjNBAWJdW7NL8UD8Maq93rnZzgijVq3gw F490+jsGy+Vd1DSy7RNMHHpjMZoera2eVezd7toBE34flmQ4Z7EN3bvrO3ht+W+lfV xTK7wIsHLVW/g== Received: from fedora1.home (unknown [100.64.0.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by bali.collaboradmins.com (Postfix) with ESMTPSA id 4754417E04DD; Mon, 30 Nov 2026 18:17:29 +0100 (CET) Date: Mon, 30 Nov 2026 18:17:20 +0100 From: Boris Brezillon To: Ketil Johnsen Cc: Steven Price , Liviu Dudau , Akash Goel , Karunika Choo , Lukas Zapolskas , Chris Diamand , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Daniel Almeida , Alice Ryhl , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Florent Tomasin , Paul Toadere , Samuel Percival Subject: Re: [PATCH v5 05/13] drm/panthor: Add support for entering and exiting protected mode Message-ID: <20261130181720.62e9b252@fedora1.home> In-Reply-To: <20261116112601.3483649-6-ketil.johnsen@arm.com> References: <20261116112601.3483649-1-ketil.johnsen@arm.com> <20261116112601.3483649-6-ketil.johnsen@arm.com> Organization: Collabora X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-redhat-linux-gnu) X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 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