drm/tyr: implement GPU reset API
Subsystems (4)
Onur Özkan
reviewercover drm/tyr: implement GPU reset API
This series adds GPU reset handling support for Tyr in a new module drivers/gpu/drm/tyr/driver.rs which encapsulates the low-level reset controller internals and exposes a ResetHandle API to the driver.
The reset module owns reset state, queueing and execution ordering through OrderedQueue and handles duplicate/concurrent reset requests with a pending flag.
Apart from the reset module, the first 3 patches:
- Fixes a potential reset-complete stale state bug by clearing completed state before doing soft reset.
- Adds Work::disable_sync() (wrapper of bindings::disable_work_sync).
- Adds OrderedQueue support.
Runtime tested on hardware by Deborah Brouwer (see [1]) and myself.
[1]: https://gitlab.freedesktop.org/panfrost/linux/-/merge_requests/63#note_3364131
---
Onur Özkan (4):
drm/tyr: clear reset IRQ before soft reset
rust: add Work::disable_sync
rust: add ordered workqueue wrapper
drm/tyr: add GPU reset handling
drivers/gpu/drm/tyr/driver.rs | 38 +++---- drivers/gpu/drm/tyr/reset.rs | 180 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + rust/helpers/workqueue.c | 6 ++ rust/kernel/workqueue.rs | 62 ++++++++++++ 5 files changed, 260 insertions(+), 27 deletions(-) create mode 100644 drivers/gpu/drm/tyr/reset.rs
base-commit: 0ccc0dac94bf2f5c6eb3e9e7f1014cd9dddf009f
Signature · 1 line
2.51.2
Onur Özkan
reviewerPATCH RESEND 1/4 drm/tyr: clear reset IRQ before soft reset
Clear RESET_COMPLETED before writing GPU_CMD_SOFT_RESET.
This is also used in drivers/gpu/drm/panfrost/panfrost_gpu.c::panfrost_gpu_soft_reset and avoids seeing old reset-complete status from a previous reset.
--- drivers/gpu/drm/tyr/driver.rs | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/tyr/driver.rs +2 -0
@@ -91,6 +91,8 @@ unsafe impl Send for TyrDrmDeviceData {}unsafe impl Sync for TyrDrmDeviceData {}fn issue_soft_reset (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { +// Clear any stale reset-complete IRQ state before issuing a new soft reset. + regs::GPU_IRQ_CLEAR .write (dev, iomem, regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED )?; regs::GPU_CMD .write (dev, iomem, regs::GPU_CMD_SOFT_RESET )?; poll::read_poll_timeout(
Signature · 1 line
2.51.2
Onur Özkan
reviewerPATCH RESEND 2/4 rust: add Work::disable_sync
In reply to Onur ÖzkanAdd Work::disable_sync() as a safe wrapper for disable_work_sync().
Drivers can use this during teardown to stop new queueing and wait for queued or running work to finish before dropping related resources.
--- rust/kernel/workqueue.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
rust/kernel/workqueue.rs +15 -0
@@ -530,6 +530,21 @@ pub unsafe fn raw_get(ptr: *const Self) -> *mut bindings::work_struct {// the compiler does not complain that the `work` field is unused. unsafe {Opaque ::cast_into (core::ptr::addr_of!((*ptr).work)) } } + +/// Disables this work item and waits for queued/running executions to finish. +/// +/// # Safety +/// +/// Must be called from a sleepable context if the work was last queued on a non-BH +/// workqueue. +#[inline] +pub unsafe fn disable_sync (&self) { +let ptr: *const Self = self; +// SAFETY: `self` points to a valid initialized work. +let raw_work =unsafe {Self ::raw_get (ptr) }; +// SAFETY: `raw_work` is a valid embedded `work_struct`. +unsafe { bindings::disable_work_sync (raw_work) }; + } }/// Declares that a type contains a [`Work<T, ID>`].
Signature · 1 line
2.51.2
Onur Özkan
reviewerPATCH RESEND 3/4 rust: add ordered workqueue wrapper
In reply to Onur ÖzkanAdd an owned OrderedQueue wrapper for alloc_ordered_workqueue() and destroy_workqueue().
This gives Rust drivers a simple way to create and own an ordered workqueue with automatic cleanup in Drop.
--- rust/helpers/workqueue.c | 6 +++++ rust/kernel/workqueue.rs | 47 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+)
rust/helpers/workqueue.c +6 -0
@@ -14,3 +14,9 @@ __rust_helper void rust_helper_init_work_with_key(struct work_struct *work,INIT_LIST_HEAD (&work->entry); work->func = func; } + +__rust_helper struct workqueue_struct * +rust_helper_alloc_ordered_workqueue (const char *name,unsigned int flags) +{ +return alloc_ordered_workqueue ("%s" , flags, name); +}
rust/kernel/workqueue.rs +47 -0
59 lines not on this page · raw message
Signature · 1 line
2.51.2
Onur Özkan
reviewerPATCH RESEND 4/4 drm/tyr: add GPU reset handling
In reply to Onur ÖzkanMove Tyr reset logic into a new reset module and add async reset work.
This adds:
- ResetHandle with internal controller state
- a dedicated ordered reset workqueue
- a pending flag to avoid duplicate queued resets
- run_reset() as the shared synchronous reset helper
Probe now calls reset::run_reset() before normal init. Driver data now keeps ResetHandle so reset work is drained before clocks and regulators are dropped.
--- drivers/gpu/drm/tyr/driver.rs | 40 +++----- drivers/gpu/drm/tyr/reset.rs | 180 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + 3 files changed, 192 insertions(+), 29 deletions(-) create mode 100644 drivers/gpu/drm/tyr/reset.rs
drivers/gpu/drm/tyr/driver.rs +11 -29
@@ -6,11 +6,8 @@ OptionalClk, // }, device::{ - Bound, - Core, - Device, // + Core, // }, - devres::Devres, dma::{ Device as DmaDevice, DmaMask, //
@@ -22,10 +19,7 @@ Registered, UnregisteredDevice, // }, - io::poll, - new_mutex, - of, - platform, + new_mutex, of, platform, prelude::*, regulator, regulator::Regulator,
@@ -35,17 +29,15 @@ Arc, Mutex, // }, - time, // };use crate ::{ file::TyrDrmFileData , fw::Firmware , gem::BoData , - gpu, gpu::GpuInfo , mmu::Mmu , - regs,// + reset,// };pub (crate )type IoMem = kernel::io::mem::IoMem <SZ_2M >;
@@ -62,6 +54,11 @@ pub(crate) struct TyrPlatformDriverData {#[pin_data] pub (crate )struct TyrDrmDeviceData { +// `ResetHandle::drop()` drains queued/running works and this must happen +// before clocks/regulators are dropped. So keep this field before them to +// ensure the correct drop order. +pub (crate ) reset: reset::ResetHandle , +pub (crate ) pdev:ARef <platform::Device >,pub (crate ) fw:Arc <Firmware >,
@@ -90,22 +87,6 @@ unsafe impl Send for TyrDrmDeviceData {}// SAFETY: This will be removed in a future patch. unsafe impl Sync for TyrDrmDeviceData {} -fn issue_soft_reset (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { -// Clear any stale reset-complete IRQ state before issuing a new soft reset. - regs::GPU_IRQ_CLEAR .write (dev, iomem, regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED )?; - regs::GPU_CMD .write (dev, iomem, regs::GPU_CMD_SOFT_RESET )?; - - poll::read_poll_timeout ( - || regs::GPU_IRQ_RAWSTAT .read (dev, iomem), - |status| *status & regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED !=0 , - time::Delta ::from_millis (1 ), - time::Delta ::from_millis (100 ), - ) - .inspect_err (|_|dev_err! (dev,"GPU reset failed." ))?; - -Ok (()) -} - kernel::of_device_table!(OF_TABLE ,MODULE_OF_TABLE ,
@@ -138,8 +119,7 @@ fn probe(let request = pdev.io_request_by_index (0 ).ok_or (ENODEV )?;let iomem =Arc ::pin_init (request.iomap_sized ::<SZ_2M >(),GFP_KERNEL )?; -issue_soft_reset (pdev.as_ref (), &iomem)?; - gpu::l2_power_on (pdev.as_ref (), &iomem)?; + reset::run_reset (pdev.as_ref (), &iomem)?;let gpu_info =GpuInfo ::new (pdev.as_ref (), &iomem)?; gpu_info.log (pdev);
@@ -153,6 +133,7 @@ fn probe(let uninit_ddev =UnregisteredDevice ::<TyrDrmDriver >::new (pdev.as_ref ())?;let platform:ARef <platform::Device > = pdev.into (); +let reset = reset::ResetHandle ::new (platform.clone (), iomem.clone ())?;let mmu =Mmu ::new (pdev, iomem.as_arc_borrow (), &gpu_info)?;
@@ -178,6 +159,7 @@ fn probe( _mali: mali_regulator, _sram: sram_regulator, }), + reset, gpu_info, });let ddev =Registration ::new_foreign_owned (uninit_ddev, pdev.as_ref (), data,0 )?;
drivers/gpu/drm/tyr/reset.rs new file +180 -0
180 lines not on this page · raw message
drivers/gpu/drm/tyr/tyr.rs +1 -0
@@ -14,6 +14,7 @@mod gpu;mod mmu;mod regs; +mod reset;mod slot;mod vm;
Signature · 1 line
2.51.2
Alice Ryhl
maintainerQuoted 19 lines · Onur Özkan
This series adds GPU reset handling support for Tyr in a new module
drivers/gpu/drm/tyr/driver.rswhich encapsulates the low-level reset controller internals and exposes a ResetHandle API to the driver.The reset module owns reset state, queueing and execution ordering through OrderedQueue and handles duplicate/concurrent reset requests with a pending flag.
Apart from the reset module, the first 3 patches:
- Fixes a potential reset-complete stale state bug by clearing completed state before doing soft reset.
- AddsWork::disable_sync()(wrapper ofbindings::disable_work_sync).
- Adds OrderedQueue support.Runtime tested on hardware by Deborah Brouwer (see [1]) and myself.
[1]: https://gitlab.freedesktop.org/panfrost/linux/-/merge_requests/63#note_3364131
Quoted 7 lines
---
Onur Özkan (4):
drm/tyr: clear reset IRQ before soft reset
rust: addWork::disable_sync
rust: add ordered workqueue wrapper
I actually added ordered workqueue support here:
https://lore.kernel.org/all/[email protected]/
Alice
Onur Özkan
reviewerQuoted 30 lines · On Fri, 13 Mar 2026 09:52:16 +0000 Alice Ryhl <[email protected]> wrote:
Quoted 21 lines · Onur Özkan
This series adds GPU reset handling support for Tyr in a new module
drivers/gpu/drm/tyr/driver.rswhich encapsulates the low-level reset controller internals and exposes a ResetHandle API to the driver.The reset module owns reset state, queueing and execution ordering through OrderedQueue and handles duplicate/concurrent reset requests with a pending flag.
Apart from the reset module, the first 3 patches:
- Fixes a potential reset-complete stale state bug by clearing completed state before doing soft reset.
- AddsWork::disable_sync()(wrapper ofbindings::disable_work_sync).
- Adds OrderedQueue support.Runtime tested on hardware by Deborah Brouwer (see [1]) and myself.
[1]:
https://gitlab.freedesktop.org/panfrost/linux/-/merge_requests/63#note_3364131Quoted 7 lines
---
Onur Özkan (4):
drm/tyr: clear reset IRQ before soft reset
rust: addWork::disable_sync
rust: add ordered workqueue wrapper
Quoted 4 lines
I actually added ordered workqueue support here:
https://lore.kernel.org/all/[email protected]/Alice
That's cool. I guess this will wait until your patch lands unless we want to combine them into a single series.
- Onur
Alice Ryhl
maintainerQuoted 34 lines · Onur Özkan
Quoted 30 lines · On Fri, 13 Mar 2026 09:52:16 +0000 Alice Ryhl <[email protected]> wrote:
Quoted 28 lines · Onur Özkan
This series adds GPU reset handling support for Tyr in a new module
drivers/gpu/drm/tyr/driver.rswhich encapsulates the low-level reset controller internals and exposes a ResetHandle API to the driver.The reset module owns reset state, queueing and execution ordering through OrderedQueue and handles duplicate/concurrent reset requests with a pending flag.
Apart from the reset module, the first 3 patches:
- Fixes a potential reset-complete stale state bug by clearing completed state before doing soft reset.
- AddsWork::disable_sync()(wrapper ofbindings::disable_work_sync).
- Adds OrderedQueue support.Runtime tested on hardware by Deborah Brouwer (see [1]) and myself.
[1]:
https://gitlab.freedesktop.org/panfrost/linux/-/merge_requests/63#note_3364131---
Onur Özkan (4):
drm/tyr: clear reset IRQ before soft reset
rust: addWork::disable_sync
rust: add ordered workqueue wrapper
Quoted 7 lines
Quoted 4 lines
I actually added ordered workqueue support here:
https://lore.kernel.org/all/[email protected]/Alice
That's cool. I guess this will wait until your patch lands unless we want to combine them into a single series.
You can just say in your cover letter that your series depends on mine.
Alice
Alice Ryhl
maintainerRe: [PATCH v1 RESEND 2/4] rust: add Work::disable_sync
In reply to Onur ÖzkanQuoted 17 lines · Onur Özkan
Add
Work::disable_sync()as a safe wrapper fordisable_work_sync().Drivers can use this during teardown to stop new queueing and wait for queued or running work to finish before dropping related resources.
Tested-by Deborah Brouwer <[email protected]>Signed-off-by Onur Özkan <[email protected]>--- rust/kernel/workqueue.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+)rust/kernel/workqueue.rs +0
-0
rust/kernel/workqueue.rs pub unsafe fn raw_get(ptr: *const Self) -> *mut bindings::work_struct { · line 539
Quoted 10 lines
rust/kernel/workqueue.rs +7
-0@@ -530,6 +530,21 @@ pub unsafe fn raw_get(ptr: *const Self) -> *mut bindings::work_struct {// the compiler does not complain that the `work` field is unused. unsafe {Opaque ::cast_into (core::ptr::addr_of!((*ptr).work)) } } + +/// Disables this work item and waits for queued/running executions to finish. +/// +/// # Safety +/// +/// Must be called from a sleepable context if the work was last queued on a non-BH +/// workqueue.
We generally do not make functions unsafe just because they might sleep.
Alice
Daniel Almeida
maintainerRe: [PATCH v1 RESEND 4/4] drm/tyr: add GPU reset handling
In reply to Onur ÖzkanQuoted 229 lines · Onur Özkan
Move Tyr reset logic into a new reset module and add async reset work.
This adds:
- ResetHandle with internal controller state
- a dedicated ordered reset workqueue
- a pending flag to avoid duplicate queued resets
-run_reset()as the shared synchronous reset helperProbe now calls
reset::run_reset()before normal init. Driver data now keeps ResetHandle so reset work is drained before clocks and regulators are dropped.Tested-by Deborah Brouwer <[email protected]>Signed-off-by Onur Özkan <[email protected]>---
drivers/gpu/drm/tyr/driver.rs | 40 +++----- drivers/gpu/drm/tyr/reset.rs | 180 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + 3 files changed, 192 insertions(+), 29 deletions(-)create mode 100644
drivers/gpu/drm/tyr/reset.rsdrivers/gpu/drm/tyr/driver.rs +8
-27@@ -6,11 +6,8 @@ OptionalClk, // }, device::{ - Bound, - Core, - Device, // + Core, // }, - devres::Devres, dma::{ Device as DmaDevice, DmaMask, //@@ -22,10 +19,7 @@ Registered, UnregisteredDevice, // }, - io::poll, - new_mutex, - of, - platform, + new_mutex, of, platform, prelude::*, regulator, regulator::Regulator,@@ -35,17 +29,15 @@ Arc, Mutex, // }, - time, // };use crate ::{ file::TyrDrmFileData , fw::Firmware , gem::BoData , - gpu, gpu::GpuInfo , mmu::Mmu , - regs,// + reset,// };pub (crate )type IoMem = kernel::io::mem::IoMem <SZ_2M >;@@ -62,6 +54,11 @@ pub(crate) struct TyrPlatformDriverData {#[pin_data] pub (crate )struct TyrDrmDeviceData { +// `ResetHandle::drop()` drains queued/running works and this must happen +// before clocks/regulators are dropped. So keep this field before them to +// ensure the correct drop order. +pub (crate ) reset: reset::ResetHandle , +pub (crate ) pdev:ARef <platform::Device >,pub (crate ) fw:Arc <Firmware >,@@ -90,22 +87,6 @@ unsafe impl Send for TyrDrmDeviceData {}// SAFETY: This will be removed in a future patch. unsafe impl Sync for TyrDrmDeviceData {} -fn issue_soft_reset (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { -// Clear any stale reset-complete IRQ state before issuing a new soft reset. - regs::GPU_IRQ_CLEAR .write (dev, iomem, regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED )?; - regs::GPU_CMD .write (dev, iomem, regs::GPU_CMD_SOFT_RESET )?; - - poll::read_poll_timeout ( - || regs::GPU_IRQ_RAWSTAT .read (dev, iomem), - |status| *status & regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED !=0 , - time::Delta ::from_millis (1 ), - time::Delta ::from_millis (100 ), - ) - .inspect_err (|_|dev_err! (dev,"GPU reset failed." ))?; - -Ok (()) -} -kernel::of_device_table!(
OF_TABLE,
MODULE_OF_TABLE,drivers/gpu/drm/tyr/driver.rs +3
-2@@ -138,8 +119,7 @@ fn probe(let request = pdev.io_request_by_index (0 ).ok_or (ENODEV )?;let iomem =Arc ::pin_init (request.iomap_sized ::<SZ_2M >(),GFP_KERNEL )?; -issue_soft_reset (pdev.as_ref (), &iomem)?; - gpu::l2_power_on (pdev.as_ref (), &iomem)?; + reset::run_reset (pdev.as_ref (), &iomem)?;let gpu_info =GpuInfo ::new (pdev.as_ref (), &iomem)?; gpu_info.log (pdev);@@ -153,6 +133,7 @@ fn probe(let uninit_ddev =UnregisteredDevice ::<TyrDrmDriver >::new (pdev.as_ref ())?;let platform:ARef <platform::Device > = pdev.into (); +let reset = reset::ResetHandle ::new (platform.clone (), iomem.clone ())?;let mmu =Mmu ::new (pdev, iomem.as_arc_borrow (), &gpu_info)?;@@ -178,6 +159,7 @@ fn probe( _mali: mali_regulator, _sram: sram_regulator, }), + reset, gpu_info, });let ddev =Registration ::new_foreign_owned (uninit_ddev, pdev.as_ref (), data,0 )?;drivers/gpu/drm/tyr/reset.rs new file +89
-0@@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0 or MIT + +//! Provides asynchronous reset handling for the Tyr DRM driver via +//! [`ResetHandle`], which runs reset work on a dedicated ordered +//! workqueue and avoids duplicate pending resets. + +use kernel::{ + device::{ +Bound , +Device ,// + }, + devres::Devres , + io::poll, + platform, + prelude::*, + sync::{ + aref::ARef , + atomic::{ +Acquire , +Atomic , +Relaxed , +Release ,// + }, +Arc , + }, + time, + workqueue::{ + self, +Work ,// + }, +}; + +use crate ::{ + driver::IoMem , + gpu, + regs,// +}; + +/// Manages asynchronous GPU reset handling and ensures only a single reset +/// work is pending at a time. +#[pin_data] +struct Controller { +/// Platform device reference needed for reset operations and logging. + pdev:ARef <platform::Device >, +/// Mapped register space needed for reset operations. + iomem:Arc <Devres <IoMem >>, +/// Atomic flag for controlling the scheduling pending state. + pending:Atomic <bool >, +/// Dedicated ordered workqueue for reset operations. + wq: workqueue::OrderedQueue , +/// Work item backing async reset processing. +#[pin] + work:Work <Controller >, +} + +kernel::impl_has_work! { +impl HasWork <Controller >for Controller { self.work } +} + +impl workqueue::WorkItem for Controller { +type Pointer =Arc <Self >; + +fn run (this:Arc <Self >) { + this.reset_work (); + } +} + +impl Controller { +/// Creates a [`Controller`] instance. +fn new (pdev:ARef <platform::Device >, iomem:Arc <Devres <IoMem >>) ->Result <Arc <Self >> { +let wq = workqueue::OrderedQueue ::new (c"tyr-reset-wq" ,0 )?; + +Arc ::pin_init ( +try_pin_init! (Self { + pdev, + iomem, + pending:Atomic ::new (false ), + wq, + work <- kernel::new_work!("tyr::reset" ), + }), +GFP_KERNEL , + ) + } + +/// Processes one scheduled reset request. +/// +/// Panthor reference: +/// - drivers/gpu/drm/panthor/panthor_device.c::panthor_device_reset_work() +fn reset_work (self: &Arc <Self >) {
drivers/gpu/drm/tyr/reset.rs line 99
Quoted 10 lines
drivers/gpu/drm/tyr/reset.rs new file +10
-0+dev_info! (self.pdev.as_ref (),"GPU reset work is started.\n" ); + +// SAFETY: `Controller` is part of driver-private data and only exists +// while the platform device is bound. +let pdev =unsafe { self.pdev.as_ref ().as_bound () }; +if let Err (e) =run_reset (pdev, &self.iomem) { +dev_err! (self.pdev.as_ref (),"GPU reset failed: {:?}\n" , e); + }else { +dev_info! (self.pdev.as_ref (),"GPU reset work is done.\n" ); + }
Can we have more descriptive strings here? A user cares little for implementation details such as “reset work”, what they care about is that the hardware is undergoing a reset.
drivers/gpu/drm/tyr/reset.rs line 107
Quoted 8 lines
drivers/gpu/drm/tyr/reset.rs new file +8
-0+ + self.pending.store (false ,Release ); + } +} + +/// Reset handle that shuts down pending work gracefully on drop. +pub (crate )struct ResetHandle (Arc <Controller >); +
Why is this an Arc? There seems to be a single owner?
Quoted 89 lines
drivers/gpu/drm/tyr/reset.rs new file +73
-0+impl ResetHandle { +/// Creates a [`ResetHandle`] instance. +pub (crate )fn new (pdev:ARef <platform::Device >, iomem:Arc <Devres <IoMem >>) ->Result <Self > { +Ok (Self (Controller ::new (pdev, iomem)?)) + } + +/// Schedules reset work. +#[expect(dead_code)] +pub (crate )fn schedule (&self) { +// TODO: Similar to `panthor_device_schedule_reset()` in Panthor, add a +// power management check once Tyr supports it. + +// Keep only one reset request running or queued. If one is already pending, +// we ignore new schedule requests. +if self.0 .pending.cmpxchg (false ,true ,Relaxed ).is_ok () + && self.0 .wq.enqueue (self.0 .clone ()).is_err () + { + self.0 .pending.store (false ,Release ); + } + } + +/// Returns true if a reset is queued or in progress. +/// +/// Note that the state can change immediately after the return. +#[inline] +#[expect(dead_code)] +pub (crate )fn is_pending (&self) ->bool { + self.0 .pending.load (Acquire ) + } +} + +impl Drop for ResetHandle { +fn drop (&mut self) { +// Drain queued/running work and block future queueing attempts for this +// work item before clocks/regulators are torn down. +// SAFETY: drop executes in a sleepable context. +unsafe { self.0 .work.disable_sync () }; + } +} + +/// Issues a soft reset command and waits for reset-complete IRQ status. +fn issue_soft_reset (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { +// Clear any stale reset-complete IRQ state before issuing a new soft reset. + regs::GPU_IRQ_CLEAR .write (dev, iomem, regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED )?; + regs::GPU_CMD .write (dev, iomem, regs::GPU_CMD_SOFT_RESET )?; + + poll::read_poll_timeout ( + || regs::GPU_IRQ_RAWSTAT .read (dev, iomem), + |status| *status & regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED !=0 , + time::Delta ::from_millis (1 ), + time::Delta ::from_millis (100 ), + ) + .inspect_err (|_|dev_err! (dev,"GPU reset failed." ))?; + +Ok (()) +} + +/// Runs one synchronous GPU reset pass. +/// +/// Its visibility is `pub(super)` only so the probe path can run an +/// initial reset; it is not part of this module's public API. +/// +/// On success, the GPU is left in a state suitable for reinitialization. +/// +/// The reset sequence is as follows: +/// 1. Trigger a GPU soft reset. +/// 2. Wait for the reset-complete IRQ status. +/// 3. Power L2 back on. +pub (super )fn run_reset (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { +issue_soft_reset (dev, iomem)?; + gpu::l2_power_on (dev, iomem)?; +Ok (()) +}drivers/gpu/drm/tyr/tyr.rs +1
-0@@ -14,6 +14,7 @@mod gpu;mod mmu;mod regs; +mod reset;mod slot;mod vm;Signature · 1 line
2.51.2
Onur Özkan
reviewerRe: [PATCH v1 RESEND 4/4] drm/tyr: add GPU reset handling
Quoted 251 lines · On Fri, 13 Mar 2026 11:56:58 -0300 Daniel Almeida…
Quoted 251 lines · Onur Özkan
Move Tyr reset logic into a new reset module and add async reset work.
This adds:
- ResetHandle with internal controller state
- a dedicated ordered reset workqueue
- a pending flag to avoid duplicate queued resets
-run_reset()as the shared synchronous reset helperProbe now calls
reset::run_reset()before normal init. Driver data now keeps ResetHandle so reset work is drained before clocks and regulators are dropped.Tested-by Deborah Brouwer <[email protected]>Signed-off-by Onur Özkan <[email protected]>---
drivers/gpu/drm/tyr/driver.rs| 40 +++-----drivers/gpu/drm/tyr/reset.rs| 180
++++++++++++++++++++++++++++++++++drivers/gpu/drm/tyr/tyr.rs|
1 + 3 files changed, 192 insertions(+), 29 deletions(-)
create mode 100644drivers/gpu/drm/tyr/reset.rs(quoted diff) +0
-0
b/drivers/gpu/drm/tyr/driver.rsindexf7951804e4e0..c80238a21ff2100644 ---a/drivers/gpu/drm/tyr/driver.rs
+++b/drivers/gpu/drm/tyr/driver.rsdrivers/gpu/drm/tyr/driver.rs +4
-11@@ -6,11 +6,8 @@ OptionalClk, // }, device::{ - Bound, - Core, - Device, // + Core, // }, - devres::Devres, dma::{ Device as DmaDevice, DmaMask, //@@ -22,10 +19,7 @@ Registered, UnregisteredDevice, // }, - io::poll, - new_mutex, - of, - platform, + new_mutex, of, platform, prelude::*, regulator, regulator::Regulator,@@ -35,17 +29,15 @@ Arc, Mutex, // }, - time, // };use crate ::{ file::TyrDrmFileData , fw::Firmware , gem::BoData , - gpu, gpu::GpuInfo , mmu::Mmu , - regs,// + reset,// };pub (crate )type IoMem = kernel::io::mem::IoMem <SZ_2M >;@@ -62,6 +54,11 @@ pub(crate) struct TyrPlatformDriverData {#[pin_data] pub (crate )struct TyrDrmDeviceData { +// `ResetHandle::drop()` drains queued/running works and this must happen
+ // before clocks/regulators are dropped. So keep this field
before them todrivers/gpu/drm/tyr/driver.rs +3
-2+// ensure the correct drop order. + pub(crate) reset: reset::ResetHandle, + pub(crate) pdev: ARef<platform::Device>, pub(crate) fw: Arc<Firmware>,@@ -90,22 +87,6 @@ unsafe impl Send for TyrDrmDeviceData {}// SAFETY: This will be removed in a future patch. unsafe impl Sync for TyrDrmDeviceData {} -fn issue_soft_reset (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { -// Clear any stale reset-complete IRQ state before issuing a new soft reset.
- regs::GPU_IRQ_CLEAR.write(dev, iomem,regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED)?;drivers/gpu/drm/tyr/driver.rs +0
-5- regs::GPU_CMD .write (dev, iomem, regs::GPU_CMD_SOFT_RESET )?; - - poll::read_poll_timeout ( - || regs::GPU_IRQ_RAWSTAT .read (dev, iomem), - |status| *status & regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED!= 0,
drivers/gpu/drm/tyr/driver.rs +0
-8- time::Delta::from_millis(1), - time::Delta::from_millis(100), - ) - .inspect_err (|_|dev_err! (dev,"GPU reset failed." ))?; - -Ok (()) -} -kernel::of_device_table!(
OF_TABLE,
MODULE_OF_TABLE,drivers/gpu/drm/tyr/driver.rs +1
-2@@ -138,8 +119,7 @@ fn probe(let request = pdev.io_request_by_index (0 ).ok_or (ENODEV )?;let iomem =Arc ::pin_init (request.iomap_sized ::<SZ_2M >(),GFP_KERNEL )?; -issue_soft_reset (pdev.as_ref (), &iomem)?; - gpu::l2_power_on (pdev.as_ref (), &iomem)?; + reset::run_reset (pdev.as_ref (), &iomem)?;let gpu_info =GpuInfo ::new (pdev.as_ref (), &iomem)?;gpu_info.log(pdev);(quoted diff) +0
-0@@ -153,6 +133,7 @@ fn probe( let uninit_ddev =UnregisteredDevice::<TyrDrmDriver>::new(pdev.as_ref())?; let
platform: ARef<platform::Device> =pdev.into();
+ let reset = reset::ResetHandle::new(platform.clone(),iomem.clone())?;let mmu = Mmu::new(pdev, iomem.as_arc_borrow(), &gpu_info)?;drivers/gpu/drm/tyr/driver.rs +1
-0@@ -178,6 +159,7 @@ fn probe( _mali: mali_regulator, _sram: sram_regulator, }), + reset, gpu_info, }); let ddev = Registration::new_foreign_owned(uninit_ddev,
pdev.as_ref(), data, 0)?; diff --gita/drivers/gpu/drm/tyr/reset.rsb/drivers/gpu/drm/tyr/reset.rsnew file mode 100644 index 000000000000..29dfae98b0dddrivers/gpu/drm/tyr/reset.rs new file +39
-0@@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0 or MIT + +//! Provides asynchronous reset handling for the Tyr DRM driver via +//! [`ResetHandle`], which runs reset work on a dedicated ordered +//! workqueue and avoids duplicate pending resets. + +use kernel::{ + device::{ +Bound , +Device ,// + }, + devres::Devres , + io::poll, + platform, + prelude::*, + sync::{ + aref::ARef , + atomic::{ +Acquire , +Atomic , +Relaxed , +Release ,// + }, +Arc , + }, + time, + workqueue::{ + self, +Work ,// + }, +}; + +use crate ::{ + driver::IoMem , + gpu, + regs,// +}; + +/// Manages asynchronous GPU reset handling and ensures only a single reset +/// work is pending at a time.
drivers/gpu/drm/tyr/reset.rs new file +3
-0+#[pin_data] +struct Controller { +/// Platform device reference needed for reset operations and logging.
drivers/gpu/drm/tyr/reset.rs new file +27
-0+ pdev: ARef<platform::Device>, + /// Mapped register space needed for reset operations. + iomem: Arc<Devres<IoMem>>, + /// Atomic flag for controlling the scheduling pending state. + pending: Atomic<bool>, + /// Dedicated ordered workqueue for reset operations. + wq: workqueue::OrderedQueue, +/// Work item backing async reset processing. +#[pin] + work: Work<Controller>, +} + +kernel::impl_has_work! { +impl HasWork <Controller >for Controller { self.work } +} + +impl workqueue::WorkItem for Controller { +type Pointer =Arc <Self >; + +fn run (this:Arc <Self >) { + this.reset_work (); + } +} + +impl Controller { +/// Creates a [`Controller`] instance. + fn new(pdev: ARef<platform::Device>, iomem:Arc<Devres<IoMem>>) -> Result<Arc<Self>> {
drivers/gpu/drm/tyr/reset.rs new file +18
-0+let wq = workqueue::OrderedQueue ::new (c"tyr-reset-wq" ,0 )?; + +Arc ::pin_init ( +try_pin_init! (Self { + pdev, + iomem, + pending:Atomic ::new (false ), + wq, + work <- kernel::new_work!("tyr::reset" ), + }), +GFP_KERNEL , + ) + } + +/// Processes one scheduled reset request. +/// +/// Panthor reference: +/// - drivers/gpu/drm/panthor/panthor_device.c::panthor_device_reset_work()
drivers/gpu/drm/tyr/reset.rs new file +2
-0+fn reset_work (self: &Arc <Self >) { + dev_info!(self.pdev.as_ref(), "GPU reset work isstarted.\n"); +
+ // SAFETY:Controlleris part of driver-private data and
only existsdrivers/gpu/drm/tyr/reset.rs new file +4
-0+// while the platform device is bound. +let pdev =unsafe { self.pdev.as_ref ().as_bound () }; +if let Err (e) =run_reset (pdev, &self.iomem) { + dev_err!(self.pdev.as_ref(), "GPU reset failed:{:?}\n", e);
Quoted 9 lines
Quoted 4 lines
drivers/gpu/drm/tyr/reset.rs new file +2
-0+ }else { + dev_info!(self.pdev.as_ref(), "GPU reset work isdone.\n");
+ }Can we have more descriptive strings here? A user cares little for implementation details such as “reset work”, what they care about is that the hardware is undergoing a reset.
Sure, I will update it.
Quoted 11 lines
drivers/gpu/drm/tyr/reset.rs line 107
Quoted 8 lines
drivers/gpu/drm/tyr/reset.rs new file +8
-0+ + self.pending.store (false ,Release ); + } +} + +/// Reset handle that shuts down pending work gracefully on drop. +pub (crate )struct ResetHandle (Arc <Controller >); +Why is this an Arc? There seems to be a single owner?
Once we queue reset work, the workqueue needs its own ref so Controller stays alive until the worker runs and returns. ResetHandle keeps the normal ref and the queued work holds the extra one.
Regards,
Onur
Quoted 101 lines
Quoted 99 lines
drivers/gpu/drm/tyr/reset.rs new file +3
-0+impl ResetHandle { +/// Creates a [`ResetHandle`] instance. + pub(crate) fn new(pdev: ARef<platform::Device>, iomem:Arc<Devres<IoMem>>) -> Result<Self> {
drivers/gpu/drm/tyr/reset.rs new file +7
-0+Ok (Self (Controller ::new (pdev, iomem)?)) + } + +/// Schedules reset work. +#[expect(dead_code)] +pub (crate )fn schedule (&self) { +// TODO: Similar to `panthor_device_schedule_reset()` in Panthor, add a
drivers/gpu/drm/tyr/reset.rs new file +3
-0+// power management check once Tyr supports it. + +// Keep only one reset request running or queued. If one is already pending,
drivers/gpu/drm/tyr/reset.rs new file +11
-0+// we ignore new schedule requests. +if self.0 .pending.cmpxchg (false ,true ,Relaxed ).is_ok () + && self.0 .wq.enqueue (self.0 .clone ()).is_err () + { + self.0 .pending.store (false ,Release ); + } + } + +/// Returns true if a reset is queued or in progress. +/// +/// Note that the state can change immediately after the return.
drivers/gpu/drm/tyr/reset.rs new file +10
-0+#[inline] +#[expect(dead_code)] +pub (crate )fn is_pending (&self) ->bool { + self.0 .pending.load (Acquire ) + } +} + +impl Drop for ResetHandle { +fn drop (&mut self) { +// Drain queued/running work and block future queueing attempts for this
drivers/gpu/drm/tyr/reset.rs new file +7
-0+// work item before clocks/regulators are torn down. +// SAFETY: drop executes in a sleepable context. +unsafe { self.0 .work.disable_sync () }; + } +} + +/// Issues a soft reset command and waits for reset-complete IRQ status. +fn issue_soft_reset(dev: &Device<Bound>, iomem:
&Devres<IoMem>) -> Result {
+ // Clear any stale reset-complete IRQ state before issuing a
new soft reset.
+ regs::GPU_IRQ_CLEAR.write(dev, iomem,regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED)?;drivers/gpu/drm/tyr/reset.rs new file +5
-0+ regs::GPU_CMD .write (dev, iomem, regs::GPU_CMD_SOFT_RESET )?; + + poll::read_poll_timeout ( + || regs::GPU_IRQ_RAWSTAT .read (dev, iomem), + |status| *status & regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED!= 0,
drivers/gpu/drm/tyr/reset.rs new file +11
-0+ time::Delta::from_millis(1), + time::Delta::from_millis(100), + ) + .inspect_err (|_|dev_err! (dev,"GPU reset failed." ))?; + +Ok (()) +} + +/// Runs one synchronous GPU reset pass. +/// +/// Its visibility is `pub(super)` only so the probe path can run an +/// initial reset; it is not part of this module's public API.
drivers/gpu/drm/tyr/reset.rs new file +2
-0+/// +/// On success, the GPU is left in a state suitable for reinitialization. +///
drivers/gpu/drm/tyr/reset.rs new file +5
-0+/// The reset sequence is as follows: +/// 1. Trigger a GPU soft reset. +/// 2. Wait for the reset-complete IRQ status. +/// 3. Power L2 back on. +pub(super) fn run_reset(dev: &Device<Bound>, iomem:&Devres<IoMem>) -> Result {
drivers/gpu/drm/tyr/reset.rs new file +4
-0+issue_soft_reset (dev, iomem)?; + gpu::l2_power_on (dev, iomem)?; +Ok (()) +}drivers/gpu/drm/tyr/tyr.rs +1
-0@@ -14,6 +14,7 @@mod gpu;mod mmu;mod regs; +mod reset;mod slot;mod vm;Signature · 1 line
2.51.2
Onur Özkan
reviewerRe: [PATCH v1 RESEND 2/4] rust: add Work::disable_sync
In reply to Alice RyhlQuoted 36 lines · On Fri, 13 Mar 2026 13:00:13 +0100 Alice Ryhl <[email protected]> wrote:
Quoted 28 lines · Onur Özkan
Add
Work::disable_sync()as a safe wrapper fordisable_work_sync().Drivers can use this during teardown to stop new queueing and wait for queued or running work to finish before dropping related resources.
Tested-by Deborah Brouwer <[email protected]>Signed-off-by Onur Özkan <[email protected]>--- rust/kernel/workqueue.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+)rust/kernel/workqueue.rs +2
-0@@ -530,6 +530,21 @@ pub unsafe fn raw_get(ptr: *const Self) -> *mut bindings::work_struct { // the compiler does not complain that the `work` field is unused. unsafe {Opaque ::cast_into (core::ptr::addr_of!((*ptr).work)) } } + +/// Disables this work item and waits for queued/running executions to finish.
rust/kernel/workqueue.rs +4
-0+/// +/// # Safety +/// +/// Must be called from a sleepable context if the work was Quoted 2 lines
last queued on a non-BH
+ /// workqueue.We generally do not make functions unsafe just because they might sleep.
Quoted 1 line
Alice
I will convert that into a "# Note" in the next version.
Regards,
Onur
Re: [PATCH v1 RESEND 1/4] drm/tyr: clear reset IRQ before soft reset
In reply to Onur ÖzkanQuoted 8 lines · On Fri, 13 Mar 2026 12:16:41 +0300 Onur Özkan <[email protected]> wrote:
Clear
RESET_COMPLETEDbefore writingGPU_CMD_SOFT_RESET.This is also used in drivers/gpu/drm/panfrost/panfrost_gpu.c::panfrost_gpu_soft_reset and avoids seeing old reset-complete status from a previous reset.
Tested-by Deborah Brouwer <[email protected]>Signed-off-by Onur Özkan <[email protected]>
Quoted 17 lines
--- drivers/gpu/drm/tyr/driver.rs | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/tyr/driver.rs +2
-0@@ -91,6 +91,8 @@ unsafe impl Send for TyrDrmDeviceData {}unsafe impl Sync for TyrDrmDeviceData {}fn issue_soft_reset (dev: &Device <Bound >, iomem: &Devres <IoMem >) ->Result { +// Clear any stale reset-complete IRQ state before issuing a new soft reset. + regs::GPU_IRQ_CLEAR .write (dev, iomem, regs::GPU_IRQ_RAWSTAT_RESET_COMPLETED )?; regs::GPU_CMD .write (dev, iomem, regs::GPU_CMD_SOFT_RESET )?; poll::read_poll_timeout(
Re: [PATCH v1 RESEND 4/4] drm/tyr: add GPU reset handling
In reply to Onur ÖzkanQuoted 22 lines · On Fri, 13 Mar 2026 12:16:44 +0300 Onur Özkan <[email protected]> wrote:
drivers/gpu/drm/tyr/reset.rs new file +22
-0+impl Controller { +/// Creates a [`Controller`] instance. +fn new (pdev:ARef <platform::Device >, iomem:Arc <Devres <IoMem >>) ->Result <Arc <Self >> { +let wq = workqueue::OrderedQueue ::new (c"tyr-reset-wq" ,0 )?; + +Arc ::pin_init ( +try_pin_init! (Self { + pdev, + iomem, + pending:Atomic ::new (false ), + wq, + work <- kernel::new_work!("tyr::reset" ), + }), +GFP_KERNEL , + ) + } + +/// Processes one scheduled reset request. +/// +/// Panthor reference: +/// - drivers/gpu/drm/panthor/panthor_device.c::panthor_device_reset_work() +fn reset_work (self: &Arc <Self >) {
drivers/gpu/drm/tyr/reset.rs line 99
Quoted 10 lines
drivers/gpu/drm/tyr/reset.rs new file +10
-0+dev_info! (self.pdev.as_ref (),"GPU reset work is started.\n" ); + +// SAFETY: `Controller` is part of driver-private data and only exists +// while the platform device is bound. +let pdev =unsafe { self.pdev.as_ref ().as_bound () }; +if let Err (e) =run_reset (pdev, &self.iomem) { +dev_err! (self.pdev.as_ref (),"GPU reset failed: {:?}\n" , e); + }else { +dev_info! (self.pdev.as_ref (),"GPU reset work is done.\n" ); + }
Unfortunately, the reset operation is not as simple as instructing the GPU to reset, it's a complex synchronization process where you need to try to gracefully put various components on hold before you reset, and then resume those after the reset is effective. Of course, with what we currently have in-tree, there's not much to suspend/resume, but I think I'd prefer to design the thing so we can progressively add more components without changing the reset logic too much.
I would probably start with a Resettable trait that has the {pre,post}_reset() methods that exist in Panthor.
The other thing we need is a way for those components to know when a reset is about to happen so they can postpone some actions they were planning in order to not further delay the reset, or end up with actions that fail because the HW is already unusable. Not too sure how we want to handle that though. Panthor is currently sprinkled with panthor_device_reset_is_pending() calls in key places, but that's still very manual, maybe we can automate that a bit more in Tyr, dunno.
Quoted 4 lines
drivers/gpu/drm/tyr/reset.rs new file +4
-0+ + self.pending.store (false ,Release ); + } +}
Onur Özkan
reviewerRe: [PATCH v1 RESEND 4/4] drm/tyr: add GPU reset handling
Hi Boris,
Quoted 49 lines · On Thu, 19 Mar 2026 12:08:28 +0100 Boris Brezillon…
Quoted 35 lines · On Fri, 13 Mar 2026 12:16:44 +0300 Onur Özkan <[email protected]> wrote:
drivers/gpu/drm/tyr/reset.rs new file +3
-0+impl Controller { +/// Creates a [`Controller`] instance. + fn new(pdev: ARef<platform::Device>, iomem:Arc<Devres<IoMem>>) -> Result<Arc<Self>> {
drivers/gpu/drm/tyr/reset.rs new file +18
-0+let wq = workqueue::OrderedQueue ::new (c"tyr-reset-wq" ,0 )?; + +Arc ::pin_init ( +try_pin_init! (Self { + pdev, + iomem, + pending:Atomic ::new (false ), + wq, + work <- kernel::new_work!("tyr::reset" ), + }), +GFP_KERNEL , + ) + } + +/// Processes one scheduled reset request. +/// +/// Panthor reference: +/// - drivers/gpu/drm/panthor/panthor_device.c::panthor_device_reset_work()
(quoted diff) +2
-0+ fn reset_work(self: &Arc<Self>) { + dev_info!(self.pdev.as_ref(), "GPU reset work isstarted.\n"); +
+ // SAFETY:Controlleris part of driver-private data and
only existsdrivers/gpu/drm/tyr/reset.rs new file +4
-0+// while the platform device is bound. +let pdev =unsafe { self.pdev.as_ref ().as_bound () }; +if let Err (e) =run_reset (pdev, &self.iomem) { + dev_err!(self.pdev.as_ref(), "GPU reset failed:{:?}\n", e);
(quoted diff) +2
-0+ } else { + dev_info!(self.pdev.as_ref(), "GPU reset work isQuoted 2 lines
done.\n");
+ }Unfortunately, the reset operation is not as simple as instructing the GPU to reset, it's a complex synchronization process where you need to try to gracefully put various components on hold before you reset, and then resume those after the reset is effective. Of course, with what we currently have in-tree, there's not much to suspend/resume, but I think I'd prefer to design the thing so we can progressively add more components without changing the reset logic too much.
Quoted 2 lines
I would probably start with a Resettable trait that has the {pre,post}_reset() methods that exist in Panthor.
Yeah, I checked Panthor and it has these functions for the reset logic. I will implement that in v2 and will dig further to see if there is anything else to cover in regards to proper syncing.
Quoted 10 lines
The other thing we need is a way for those components to know when a reset is about to happen so they can postpone some actions they were planning in order to not further delay the reset, or end up with actions that fail because the HW is already unusable. Not too sure how we want to handle that though. Panthor is currently sprinkled with
panthor_device_reset_is_pending()calls in key places, but that's still very manual, maybe we can automate that a bit more in Tyr, dunno.
Hmm, sounds like a perfect guard use-case. Is it possible to require users to access the hw behind a guard (e.g., try_access_hw())? We would then check if a reset is in progress and hold the user or return an error until the reset is complete.
Thanks,
Onur
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/tyr/reset.rs new file +4
-0+ + self.pending.store (false ,Release ); + } +}
Onur Özkan
reviewerQuoted 37 lines
This series adds GPU reset handling support for Tyr in a new module
drivers/gpu/drm/tyr/driver.rswhich encapsulates the low-level reset controller internals and exposes a ResetHandle API to the driver.The reset module owns reset state, queueing and execution ordering through OrderedQueue and handles duplicate/concurrent reset requests with a pending flag.
Apart from the reset module, the first 3 patches:
- Fixes a potential reset-complete stale state bug by clearing completed state before doing soft reset.
- AddsWork::disable_sync()(wrapper ofbindings::disable_work_sync).
- Adds OrderedQueue support.Runtime tested on hardware by Deborah Brouwer (see [1]) and myself.
[1]: https://gitlab.freedesktop.org/panfrost/linux/-/merge_requests/63#note_3364131
---
Onur Özkan (4):
drm/tyr: clear reset IRQ before soft reset
rust: addWork::disable_sync
rust: add ordered workqueue wrapper
drm/tyr: add GPU reset handlingdrivers/gpu/drm/tyr/driver.rs | 38 +++---- drivers/gpu/drm/tyr/reset.rs | 180 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + rust/helpers/workqueue.c | 6 ++ rust/kernel/workqueue.rs | 62 ++++++++++++ 5 files changed, 260 insertions(+), 27 deletions(-) create mode 100644 drivers/gpu/drm/tyr/reset.rs
Quoted 4 lines
base-commit:
0ccc0dac94bf2f5c6eb3e9e7f1014cd9dddf009fSignature · 1 line
2.51.2
Hi all,
Writing the current status of this work, I have 2 blockers to move forward.
1- GPU unplug API
On the existing C side, reset failure handling eventually needs to unplug the device, and that path is part of the broader reset flow in:
- srctree/drivers/gpu/drm/panthor/panthor_device.c
This is part of [1] and as far as I understand, it is still work in progress. For Tyr, I currently keep this as a placeholder (todo!("unplug the GPU")) in the reset path, because I do not want to introduce temporary or partial unplug handling in this series before the unplug design is settled.
[1]: https://gitlab.freedesktop.org/panfrost/linux/-/work_items/29
2- Design decisions for reset handling
The second blocker is the design around how Resettable (a generic pre_reset post_reset hook trait) implemeter should stop admitting new work, drain in-flight operations and recover after reset.
My current understanding is that the cleanest approach is to keep reset.rs responsible only for reset orchestration:
- schedule reset work
- call pre_reset() hooks
- perform the hardware reset
- call post_reset() hooks
- propagate failure.
Then, each Resettable implementer should own its local recovery logic.
This is also how the existing C implementation is structured. The reset worker is centralized, but recovery is implemented by the participating subsystems:
- srctree/drivers/gpu/drm/panthor/panthor_sched.c
- srctree/drivers/gpu/drm/panthor/panthor_fw.c
- srctree/drivers/gpu/drm/panthor/panthor_mmu.c
More specifically, the existing C side has hooks such as:
- panthor_sched_pre_reset() / panthor_sched_post_reset()
- panthor_fw_pre_reset() / panthor_fw_post_reset()
- panthor_mmu_pre_reset() / panthor_mmu_post_reset()
The reason I am leaning in the same direction for Tyr is that "stop new work", "drain" and "resume" are not generic operations. They depend on the implementer.
Because of that, I think reset.rs should not have a global guard/checking API for all of this.
Comments and suggestions are very welcome.
Regards,
Onur
Daniel Almeida
maintainerRe: [PATCH v1 RESEND 4/4] drm/tyr: add GPU reset handling
In reply to Boris BrezillonQuoted 51 lines · Boris Brezillon
Quoted 22 lines · On Fri, 13 Mar 2026 12:16:44 +0300 Onur Özkan <[email protected]> wrote:
drivers/gpu/drm/tyr/reset.rs new file +22
-0+impl Controller { +/// Creates a [`Controller`] instance. +fn new (pdev:ARef <platform::Device >, iomem:Arc <Devres <IoMem >>) ->Result <Arc <Self >> { +let wq = workqueue::OrderedQueue ::new (c"tyr-reset-wq" ,0 )?; + +Arc ::pin_init ( +try_pin_init! (Self { + pdev, + iomem, + pending:Atomic ::new (false ), + wq, + work <- kernel::new_work!("tyr::reset" ), + }), +GFP_KERNEL , + ) + } + +/// Processes one scheduled reset request. +/// +/// Panthor reference: +/// - drivers/gpu/drm/panthor/panthor_device.c::panthor_device_reset_work() +fn reset_work (self: &Arc <Self >) {drivers/gpu/drm/tyr/reset.rs line 99
Quoted 10 lines
drivers/gpu/drm/tyr/reset.rs new file +10
-0+dev_info! (self.pdev.as_ref (),"GPU reset work is started.\n" ); + +// SAFETY: `Controller` is part of driver-private data and only exists +// while the platform device is bound. +let pdev =unsafe { self.pdev.as_ref ().as_bound () }; +if let Err (e) =run_reset (pdev, &self.iomem) { +dev_err! (self.pdev.as_ref (),"GPU reset failed: {:?}\n" , e); + }else { +dev_info! (self.pdev.as_ref (),"GPU reset work is done.\n" ); + }Unfortunately, the reset operation is not as simple as instructing the GPU to reset, it's a complex synchronization process where you need to try to gracefully put various components on hold before you reset, and then resume those after the reset is effective. Of course, with what we currently have in-tree, there's not much to suspend/resume, but I think I'd prefer to design the thing so we can progressively add more components without changing the reset logic too much.
I would probably start with a Resettable trait that has the {pre,post}_reset() methods that exist in Panthor.
Quoted 8 lines
The other thing we need is a way for those components to know when a reset is about to happen so they can postpone some actions they were planning in order to not further delay the reset, or end up with actions that fail because the HW is already unusable. Not too sure how we want to handle that though. Panthor is currently sprinkled with
panthor_device_reset_is_pending()calls in key places, but that's still very manual, maybe we can automate that a bit more in Tyr, dunno.
We could have an enum where one of the variants is Resetting, and the other one gives access to whatever state is not accessible while resets are in progress.
Something like
pub enum TyrData {
Active(ActiveTyrData),
ResetInProgress(ActiveTyrData)
}
fn access() -> Option<&ActiveTyrData> {
… // if the “ResetInProgress” variant is active, return None
}
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/tyr/reset.rs new file +4
-0+ + self.pending.store (false ,Release ); + } +}
Onur Özkan
reviewerRe: [PATCH v1 RESEND 4/4] drm/tyr: add GPU reset handling
Quoted 66 lines · On Fri, 03 Apr 2026 12:01:09 -0300 Daniel Almeida…
Quoted 51 lines · Boris Brezillon
Quoted 22 lines · On Fri, 13 Mar 2026 12:16:44 +0300 Onur Özkan <[email protected]> wrote:
drivers/gpu/drm/tyr/reset.rs new file +22
-0+impl Controller { +/// Creates a [`Controller`] instance. +fn new (pdev:ARef <platform::Device >, iomem:Arc <Devres <IoMem >>) ->Result <Arc <Self >> { +let wq = workqueue::OrderedQueue ::new (c"tyr-reset-wq" ,0 )?; + +Arc ::pin_init ( +try_pin_init! (Self { + pdev, + iomem, + pending:Atomic ::new (false ), + wq, + work <- kernel::new_work!("tyr::reset" ), + }), +GFP_KERNEL , + ) + } + +/// Processes one scheduled reset request. +/// +/// Panthor reference: +/// - drivers/gpu/drm/panthor/panthor_device.c::panthor_device_reset_work() +fn reset_work (self: &Arc <Self >) {drivers/gpu/drm/tyr/reset.rs line 99
Quoted 10 lines
drivers/gpu/drm/tyr/reset.rs new file +10
-0+dev_info! (self.pdev.as_ref (),"GPU reset work is started.\n" ); + +// SAFETY: `Controller` is part of driver-private data and only exists +// while the platform device is bound. +let pdev =unsafe { self.pdev.as_ref ().as_bound () }; +if let Err (e) =run_reset (pdev, &self.iomem) { +dev_err! (self.pdev.as_ref (),"GPU reset failed: {:?}\n" , e); + }else { +dev_info! (self.pdev.as_ref (),"GPU reset work is done.\n" ); + }Unfortunately, the reset operation is not as simple as instructing the GPU to reset, it's a complex synchronization process where you need to try to gracefully put various components on hold before you reset, and then resume those after the reset is effective. Of course, with what we currently have in-tree, there's not much to suspend/resume, but I think I'd prefer to design the thing so we can progressively add more components without changing the reset logic too much.
I would probably start with a Resettable trait that has the {pre,post}_reset() methods that exist in Panthor.
Quoted 8 lines
The other thing we need is a way for those components to know when a reset is about to happen so they can postpone some actions they were planning in order to not further delay the reset, or end up with actions that fail because the HW is already unusable. Not too sure how we want to handle that though. Panthor is currently sprinkled with
panthor_device_reset_is_pending()calls in key places, but that's still very manual, maybe we can automate that a bit more in Tyr, dunno.We could have an enum where one of the variants is Resetting, and the other one gives access to whatever state is not accessible while resets are in progress.
Something like
Quoted 9 lines
pub enum TyrData {
Active(ActiveTyrData),
ResetInProgress(ActiveTyrData)
}fn
access()-> Option<&ActiveTyrData> {
… // if the “ResetInProgress” variant is active, return None
}
That's an interesting approach, but if it's all about fn access function, we can already do that with a simple atomic state e.g.,:
// The state flag in reset::Controller
state: Atomic<ResetState>
fn access(&self) -> Option<&Arc<Devres<IoMem>>> {
match self.state.load(Relaxed) {
ResetState::Idle => Some(&self.iomem),
_ => None,
}
}What do you think? Would this be sufficient?
Btw, a sample code snippet from the caller side would be very helpful for designing this further. That part is kind a blurry for me.
Thanks,
Onur
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/tyr/reset.rs new file +4
-0+ + self.pending.store (false ,Release ); + } +}
Daniel Almeida
maintainerRe: [PATCH v1 RESEND 4/4] drm/tyr: add GPU reset handling
Hi Onur,
Quoted 99 lines · Onur Özkan
Quoted 66 lines · On Fri, 03 Apr 2026 12:01:09 -0300 Daniel Almeida…
Quoted 51 lines · Boris Brezillon
Quoted 22 lines · On Fri, 13 Mar 2026 12:16:44 +0300 Onur Özkan <[email protected]> wrote:
drivers/gpu/drm/tyr/reset.rs new file +22
-0+impl Controller { +/// Creates a [`Controller`] instance. +fn new (pdev:ARef <platform::Device >, iomem:Arc <Devres <IoMem >>) ->Result <Arc <Self >> { +let wq = workqueue::OrderedQueue ::new (c"tyr-reset-wq" ,0 )?; + +Arc ::pin_init ( +try_pin_init! (Self { + pdev, + iomem, + pending:Atomic ::new (false ), + wq, + work <- kernel::new_work!("tyr::reset" ), + }), +GFP_KERNEL , + ) + } + +/// Processes one scheduled reset request. +/// +/// Panthor reference: +/// - drivers/gpu/drm/panthor/panthor_device.c::panthor_device_reset_work() +fn reset_work (self: &Arc <Self >) {drivers/gpu/drm/tyr/reset.rs line 99
Quoted 10 lines
drivers/gpu/drm/tyr/reset.rs new file +10
-0+dev_info! (self.pdev.as_ref (),"GPU reset work is started.\n" ); + +// SAFETY: `Controller` is part of driver-private data and only exists +// while the platform device is bound. +let pdev =unsafe { self.pdev.as_ref ().as_bound () }; +if let Err (e) =run_reset (pdev, &self.iomem) { +dev_err! (self.pdev.as_ref (),"GPU reset failed: {:?}\n" , e); + }else { +dev_info! (self.pdev.as_ref (),"GPU reset work is done.\n" ); + }Unfortunately, the reset operation is not as simple as instructing the GPU to reset, it's a complex synchronization process where you need to try to gracefully put various components on hold before you reset, and then resume those after the reset is effective. Of course, with what we currently have in-tree, there's not much to suspend/resume, but I think I'd prefer to design the thing so we can progressively add more components without changing the reset logic too much.
I would probably start with a Resettable trait that has the {pre,post}_reset() methods that exist in Panthor.
Quoted 8 lines
The other thing we need is a way for those components to know when a reset is about to happen so they can postpone some actions they were planning in order to not further delay the reset, or end up with actions that fail because the HW is already unusable. Not too sure how we want to handle that though. Panthor is currently sprinkled with
panthor_device_reset_is_pending()calls in key places, but that's still very manual, maybe we can automate that a bit more in Tyr, dunno.We could have an enum where one of the variants is Resetting, and the other one gives access to whatever state is not accessible while resets are in progress.
Something like
Quoted 9 lines
pub enum TyrData {
Active(ActiveTyrData),
ResetInProgress(ActiveTyrData)
}fn
access()-> Option<&ActiveTyrData> {
… // if the “ResetInProgress” variant is active, return None
}That's an interesting approach, but if it's all about
fn accessfunction, we can already do that with a simple atomic state e.g.,:// The state flag in
reset::Controller
state: Atomic<ResetState>fn
access(&self)-> Option<&Arc<Devres<IoMem>>> {
matchself.state.load(Relaxed){ResetState::Idle=>Some(&self.iomem),
_ => None,
}
}What do you think? Would this be sufficient?
Btw, a sample code snippet from the caller side would be very helpful for designing this further. That part is kind a blurry for me.
Quoted 8 lines
Thanks,
OnurQuoted 5 lines
Quoted 5 lines
drivers/gpu/drm/tyr/reset.rs line 103
Quoted 5 lines
drivers/gpu/drm/tyr/reset.rs new file +4
-0+ + self.pending.store (false ,Release ); + } +}
I think that there are two things we're trying to implement correctly:
1) Deny access to a subset of the state while a reset is in progress
2) Wait for anyone accessing 1) to finish before starting a reset
IIUC, using Atomic<T> can solve 1 by bailing if the "reset in progress" flag/variant is set, but I don't think it implements 2? One would have to implement more logic to block until the state is not being actively used.
Now, there are probably easier ways to solve this, but I propose that we do the extra legwork to make this explicit and enforceable by the type system.
How about introducing a r/w semaphore abstraction? It seems to correctly encode the logic we want:
a) multiple users can access the state if no reset is pending ("read" side)
b) the reset code can block until the state is no longer being accessed (the "write" side)
In Tyr, this would roughly map to something like:
struct TyrData {
reset_gate: RwSem<ActiveHwState>
// other, always accessible members
}
impl TyrData {
fn try_access(&self) -> Option<ReadGuard<'_, ActiveHwState>> {...}
}
Where ActiveHwState contains the fw/mmu/sched blocks (these are not upstream yet, Deborah has a series that will introduce the fw block that should land soon) and perhaps more.
Now, the reset logic would be roughly:
fn reset_work(tdev: Arc<TyrDevice>) {
// Block until nobody else is accessing the hw, prevent others from // initiating new accesses too..
let _guard = tdev.reset_gate.write();
// pre_reset() all Resettable implementors
... reset
// post_Reset all Resettable implementors
}
Now, for every block that might touch a resource that would be unavailable during a reset, we enforce a try_access() via the type system, and ensure that the reset cannot start while the guard is alive. In particular, ioctls would look like:
fn ioctl_foo(...) {
let hw = tdev.reset_gate.try_access()?;
// resets are blocked while the guard is alive, no other way to access that state otherwise
}
The code will not compile otherwise, so long as we keep the state in ActiveHwState, i.e.:
protected by the r/w sem.
This looks like an improvement over Panthor, since Panthor relies on manually canceling work that access hw state via cancel_work_sync(), and gating new work submissions on the "reset_in_progress" flag, i.e.:
/**
* sched_queue_work() - Queue a scheduler work.
* @sched: Scheduler object.
* @wname: Work name.
*
* Conditionally queues a scheduler work if no reset is pending/in-progress. */
#define sched_queue_work(sched, wname) \
do { \
if (!atomic_read(&(sched)->reset.in_progress) && \
!panthor_device_reset_is_pending((sched)->ptdev)) \queue_work((sched)->wq, &(sched)->wname ## _work); \
} while (0)
Thoughts?
— Daniel
Alice Ryhl
maintainerRe: [PATCH v1 RESEND 4/4] drm/tyr: add GPU reset handling
Quoted 183 lines · Daniel Almeida
Hi Onur,
Quoted 99 lines · Onur Özkan
Quoted 66 lines · On Fri, 03 Apr 2026 12:01:09 -0300 Daniel Almeida…
Quoted 51 lines · Boris Brezillon
Quoted 22 lines · On Fri, 13 Mar 2026 12:16:44 +0300 Onur Özkan <[email protected]> wrote:
drivers/gpu/drm/tyr/reset.rs new file +22
-0+impl Controller { +/// Creates a [`Controller`] instance. +fn new (pdev:ARef <platform::Device >, iomem:Arc <Devres <IoMem >>) ->Result <Arc <Self >> { +let wq = workqueue::OrderedQueue ::new (c"tyr-reset-wq" ,0 )?; + +Arc ::pin_init ( +try_pin_init! (Self { + pdev, + iomem, + pending:Atomic ::new (false ), + wq, + work <- kernel::new_work!("tyr::reset" ), + }), +GFP_KERNEL , + ) + } + +/// Processes one scheduled reset request. +/// +/// Panthor reference: +/// - drivers/gpu/drm/panthor/panthor_device.c::panthor_device_reset_work() +fn reset_work (self: &Arc <Self >) {drivers/gpu/drm/tyr/reset.rs line 99
Quoted 10 lines
drivers/gpu/drm/tyr/reset.rs new file +10
-0+dev_info! (self.pdev.as_ref (),"GPU reset work is started.\n" ); + +// SAFETY: `Controller` is part of driver-private data and only exists +// while the platform device is bound. +let pdev =unsafe { self.pdev.as_ref ().as_bound () }; +if let Err (e) =run_reset (pdev, &self.iomem) { +dev_err! (self.pdev.as_ref (),"GPU reset failed: {:?}\n" , e); + }else { +dev_info! (self.pdev.as_ref (),"GPU reset work is done.\n" ); + }Unfortunately, the reset operation is not as simple as instructing the GPU to reset, it's a complex synchronization process where you need to try to gracefully put various components on hold before you reset, and then resume those after the reset is effective. Of course, with what we currently have in-tree, there's not much to suspend/resume, but I think I'd prefer to design the thing so we can progressively add more components without changing the reset logic too much.
I would probably start with a Resettable trait that has the {pre,post}_reset() methods that exist in Panthor.
Quoted 8 lines
The other thing we need is a way for those components to know when a reset is about to happen so they can postpone some actions they were planning in order to not further delay the reset, or end up with actions that fail because the HW is already unusable. Not too sure how we want to handle that though. Panthor is currently sprinkled with
panthor_device_reset_is_pending()calls in key places, but that's still very manual, maybe we can automate that a bit more in Tyr, dunno.We could have an enum where one of the variants is Resetting, and the other one gives access to whatever state is not accessible while resets are in progress.
Something like
Quoted 9 lines
pub enum TyrData {
Active(ActiveTyrData),
ResetInProgress(ActiveTyrData)
}fn
access()-> Option<&ActiveTyrData> {
… // if the “ResetInProgress” variant is active, return None
}That's an interesting approach, but if it's all about
fn accessfunction, we can already do that with a simple atomic state e.g.,:// The state flag in
reset::Controller
state: Atomic<ResetState>fn
access(&self)-> Option<&Arc<Devres<IoMem>>> {
matchself.state.load(Relaxed){ResetState::Idle=>Some(&self.iomem),
_ => None,
}
}What do you think? Would this be sufficient?
Btw, a sample code snippet from the caller side would be very helpful for designing this further. That part is kind a blurry for me.
Quoted 8 lines
Thanks,
OnurQuoted 5 lines
Quoted 5 lines
drivers/gpu/drm/tyr/reset.rs line 103
Quoted 5 lines
drivers/gpu/drm/tyr/reset.rs new file +4
-0+ + self.pending.store (false ,Release ); + } +}I think that there are two things we're trying to implement correctly:
1) Deny access to a subset of the state while a reset is in progress
2) Wait for anyone accessing 1) to finish before starting a resetIIUC, using Atomic<T> can solve 1 by bailing if the "reset in progress" flag/variant is set, but I don't think it implements 2? One would have to implement more logic to block until the state is not being actively used.
Now, there are probably easier ways to solve this, but I propose that we do the extra legwork to make this explicit and enforceable by the type system.
How about introducing a r/w semaphore abstraction? It seems to correctly encode the logic we want:
a) multiple users can access the state if no reset is pending ("read" side)
b) the reset code can block until the state is no longer being accessed (the "write" side)In Tyr, this would roughly map to something like:
struct TyrData {
reset_gate: RwSem<ActiveHwState>
// other, always accessible members
}impl TyrData {
fntry_access(&self)-> Option<ReadGuard<'_, ActiveHwState>> {...}
}Where ActiveHwState contains the fw/mmu/sched blocks (these are not upstream yet, Deborah has a series that will introduce the fw block that should land soon) and perhaps more.
Now, the reset logic would be roughly:
fn
reset_work(tdev: Arc<TyrDevice>){
// Block until nobody else is accessing the hw, prevent others from // initiating new accesses too..
let_guard=tdev.reset_gate.write();//
pre_reset()all Resettable implementors... reset
//
post_Resetall Resettable implementors
}Now, for every block that might touch a resource that would be unavailable during a reset, we enforce a
try_access()via the type system, and ensure that the reset cannot start while the guard is alive. In particular, ioctls would look like:fn
ioctl_foo(...){
let hw =tdev.reset_gate.try_access()?;
// resets are blocked while the guard is alive, no other way to access that state otherwise
}The code will not compile otherwise, so long as we keep the state in ActiveHwState, i.e.:
protected by the r/w sem.This looks like an improvement over Panthor, since Panthor relies on manually canceling work that access hw state via
cancel_work_sync(), and gating new work submissions on the "reset_in_progress" flag, i.e.:/**
*sched_queue_work()- Queue a scheduler work.
* @sched: Scheduler object.
* @wname: Work name.
*
* Conditionally queues a scheduler work if no reset is pending/in-progress. */
#definesched_queue_work(sched, wname)\
do { \
Quoted 7 lines
if (!atomic_read(&(sched)->reset.in_progress) && \ !panthor_device_reset_is_pending((sched)->ptdev)) \
queue_work((sched)->wq, &(sched)->wname ## _work); \
} while (0)Thoughts?
I don't think a semaphore is the right answer. I think SRCU plus a counter makes more sense. (With a sentinal value reserved for "currently resetting".)
When you begin using the hardware, you start an srcu critical region and read the counter. If the counter has the sentinel value, you know the hardware is resetting and you fail. Otherwise you record the couter and proceed.
If at any point you release the srcu critical region and want to re-acquire it to continue the same ongoing work, then you must ensure that the counter still has the same value. This ensures that if the GPU is reset, then even if the reset has finished by the time you come back, you still fail because the counter has changed.
Another option could be to rely on the existing Device unbind logic. Entirely remove the class device and run the full unbind procedure, cleaning up all devm work etc. Then once that has finished, probe the device again and start from scratch. After all, GPU reset does not have to be a cheap operation.
Alice
Daniel Almeida
maintainerRe: [PATCH v1 RESEND 4/4] drm/tyr: add GPU reset handling
Quoted 81 lines
Quoted 81 lines
I think that there are two things we're trying to implement correctly:
1) Deny access to a subset of the state while a reset is in progress
2) Wait for anyone accessing 1) to finish before starting a resetIIUC, using Atomic<T> can solve 1 by bailing if the "reset in progress" flag/variant is set, but I don't think it implements 2? One would have to implement more logic to block until the state is not being actively used.
Now, there are probably easier ways to solve this, but I propose that we do the extra legwork to make this explicit and enforceable by the type system.
How about introducing a r/w semaphore abstraction? It seems to correctly encode the logic we want:
a) multiple users can access the state if no reset is pending ("read" side)
b) the reset code can block until the state is no longer being accessed (the "write" side)In Tyr, this would roughly map to something like:
struct TyrData {
reset_gate: RwSem<ActiveHwState>
// other, always accessible members
}impl TyrData {
fntry_access(&self)-> Option<ReadGuard<'_, ActiveHwState>> {...}
}Where ActiveHwState contains the fw/mmu/sched blocks (these are not upstream yet, Deborah has a series that will introduce the fw block that should land soon) and perhaps more.
Now, the reset logic would be roughly:
fn
reset_work(tdev: Arc<TyrDevice>){
// Block until nobody else is accessing the hw, prevent others from // initiating new accesses too..
let_guard=tdev.reset_gate.write();//
pre_reset()all Resettable implementors... reset
//
post_Resetall Resettable implementors
}Now, for every block that might touch a resource that would be unavailable during a reset, we enforce a
try_access()via the type system, and ensure that the reset cannot start while the guard is alive. In particular, ioctls would look like:fn
ioctl_foo(...){
let hw =tdev.reset_gate.try_access()?;
// resets are blocked while the guard is alive, no other way to access that state otherwise
}The code will not compile otherwise, so long as we keep the state in ActiveHwState, i.e.:
protected by the r/w sem.This looks like an improvement over Panthor, since Panthor relies on manually canceling work that access hw state via
cancel_work_sync(), and gating new work submissions on the "reset_in_progress" flag, i.e.:/**
*sched_queue_work()- Queue a scheduler work.
* @sched: Scheduler object.
* @wname: Work name.
*
* Conditionally queues a scheduler work if no reset is pending/in-progress. */
#definesched_queue_work(sched, wname)\
do { \if (!atomic_read(&(sched)->reset.in_progress) && \ !panthor_device_reset_is_pending((sched)->ptdev)) \
queue_work((sched)->wq, &(sched)->wname ## _work); \
} while (0)
Quoted 5 lines
Quoted 1 line
Thoughts?
I don't think a semaphore is the right answer. I think SRCU plus a counter makes more sense. (With a sentinal value reserved for "currently resetting".)
Can you expand a bit on why you think r/w semaphores are not the answer? They seem to correctly encode the logic we want.
Quoted 11 lines
When you begin using the hardware, you start an srcu critical region and read the counter. If the counter has the sentinel value, you know the hardware is resetting and you fail. Otherwise you record the couter and proceed.
If at any point you release the srcu critical region and want to re-acquire it to continue the same ongoing work, then you must ensure that the counter still has the same value. This ensures that if the GPU is reset, then even if the reset has finished by the time you come back, you still fail because the counter has changed.
We don't want to "come back”, anything that is in-flight must complete, i.e.:
the reset logic must wait for in-flight jobs, because the work has already been dispatched to the hardware. We do want to forbid more work from being queued while a reset is pending, though.
Quoted 9 lines
Another option could be to rely on the existing Device unbind logic. Entirely remove the class device and run the full unbind procedure, cleaning up all devm work etc. Then once that has finished, probe the device again and start from scratch. After all, GPU reset does not have to be a cheap operation.
Alice
What about all resources associated with this class device? Userspace would be holding handles to resources that are effectively gone.
In any case, I'm not trying to push this r/w semaphore thing as "the right thing", and if the "srcu + counter" idea turns out to be better, great! :)
The problem is what Boris said recently, though: there's a delay between the point of "we need a reset" and the reset worker being scheduled.
In the design I proposed, there would be a window of time in which:
1) the hardware is in an invalid state, and must be reset
2) the reset worker hasn't run yet, so the "write" lock has not been taken
3) due to 2, the submit() logic sees the hardware as available, and queues more work
4) the work from 3 now gets to execute even though the hardware is crashed
— Daniel
Re: [PATCH v1 RESEND 4/4] drm/tyr: add GPU reset handling
Quoted 12 lines · On Fri, 10 Apr 2026 10:00:56 -0300 Daniel Almeida…
Quoted 11 lines
When you begin using the hardware, you start an srcu critical region and read the counter. If the counter has the sentinel value, you know the hardware is resetting and you fail. Otherwise you record the couter and proceed.
If at any point you release the srcu critical region and want to re-acquire it to continue the same ongoing work, then you must ensure that the counter still has the same value. This ensures that if the GPU is reset, then even if the reset has finished by the time you come back, you still fail because the counter has changed.
Quoted 3 lines
We don't want to "come back”, anything that is in-flight must complete, i.e.:
the reset logic must wait for in-flight jobs, because the work has already been dispatched to the hardware.
I assume you meant s/in-flight jobs/in-flight works/, because the whole point of a reset is to recover for in-flight GPU jobs that hanged the GPU, so if you have to wait for them to land, you're screwed :P.
Onur Özkan
reviewerRe: [PATCH v1 RESEND 4/4] drm/tyr: add GPU reset handling
In reply to Alice RyhlQuoted 208 lines · On Fri, 10 Apr 2026 07:56:38 +0000 Alice Ryhl <[email protected]> wrote:
Quoted 183 lines · Daniel Almeida
Hi Onur,
Quoted 99 lines · Onur Özkan
Quoted 66 lines · On Fri, 03 Apr 2026 12:01:09 -0300 Daniel Almeida…
Quoted 51 lines · Boris Brezillon
Quoted 22 lines · On Fri, 13 Mar 2026 12:16:44 +0300 Onur Özkan <[email protected]> wrote:
drivers/gpu/drm/tyr/reset.rs new file +22
-0+impl Controller { +/// Creates a [`Controller`] instance. +fn new (pdev:ARef <platform::Device >, iomem:Arc <Devres <IoMem >>) ->Result <Arc <Self >> { +let wq = workqueue::OrderedQueue ::new (c"tyr-reset-wq" ,0 )?; + +Arc ::pin_init ( +try_pin_init! (Self { + pdev, + iomem, + pending:Atomic ::new (false ), + wq, + work <- kernel::new_work!("tyr::reset" ), + }), +GFP_KERNEL , + ) + } + +/// Processes one scheduled reset request. +/// +/// Panthor reference: +/// - drivers/gpu/drm/panthor/panthor_device.c::panthor_device_reset_work() +fn reset_work (self: &Arc <Self >) {drivers/gpu/drm/tyr/reset.rs line 99
Quoted 10 lines
drivers/gpu/drm/tyr/reset.rs new file +10
-0+dev_info! (self.pdev.as_ref (),"GPU reset work is started.\n" ); + +// SAFETY: `Controller` is part of driver-private data and only exists +// while the platform device is bound. +let pdev =unsafe { self.pdev.as_ref ().as_bound () }; +if let Err (e) =run_reset (pdev, &self.iomem) { +dev_err! (self.pdev.as_ref (),"GPU reset failed: {:?}\n" , e); + }else { +dev_info! (self.pdev.as_ref (),"GPU reset work is done.\n" ); + }Unfortunately, the reset operation is not as simple as instructing the GPU to reset, it's a complex synchronization process where you need to try to gracefully put various components on hold before you reset, and then resume those after the reset is effective. Of course, with what we currently have in-tree, there's not much to suspend/resume, but I think I'd prefer to design the thing so we can progressively add more components without changing the reset logic too much.
I would probably start with a Resettable trait that has the {pre,post}_reset() methods that exist in Panthor.
Quoted 8 lines
The other thing we need is a way for those components to know when a reset is about to happen so they can postpone some actions they were planning in order to not further delay the reset, or end up with actions that fail because the HW is already unusable. Not too sure how we want to handle that though. Panthor is currently sprinkled with
panthor_device_reset_is_pending()calls in key places, but that's still very manual, maybe we can automate that a bit more in Tyr, dunno.We could have an enum where one of the variants is Resetting, and the other one gives access to whatever state is not accessible while resets are in progress.
Something like
Quoted 9 lines
pub enum TyrData {
Active(ActiveTyrData),
ResetInProgress(ActiveTyrData)
}fn
access()-> Option<&ActiveTyrData> {
… // if the “ResetInProgress” variant is active, return None
}That's an interesting approach, but if it's all about
fn accessfunction, we can already do that with a simple atomic state e.g.,:// The state flag in
reset::Controller
state: Atomic<ResetState>fn
access(&self)-> Option<&Arc<Devres<IoMem>>> {
matchself.state.load(Relaxed){ResetState::Idle=>Some(&self.iomem),
_ => None,
}
}What do you think? Would this be sufficient?
Btw, a sample code snippet from the caller side would be very helpful for designing this further. That part is kind a blurry for me.
Quoted 8 lines
Thanks,
OnurQuoted 5 lines
Quoted 5 lines
drivers/gpu/drm/tyr/reset.rs line 103
Quoted 5 lines
drivers/gpu/drm/tyr/reset.rs new file +4
-0+ + self.pending.store (false ,Release ); + } +}I think that there are two things we're trying to implement correctly:
1) Deny access to a subset of the state while a reset is in progress
2) Wait for anyone accessing 1) to finish before starting a resetIIUC, using Atomic<T> can solve 1 by bailing if the "reset in progress" flag/variant is set, but I don't think it implements 2? One would have to implement more logic to block until the state is not being actively used.
Now, there are probably easier ways to solve this, but I propose that we do the extra legwork to make this explicit and enforceable by the type system.
How about introducing a r/w semaphore abstraction? It seems to correctly encode the logic we want:
a) multiple users can access the state if no reset is pending ("read" side)
b) the reset code can block until the state is no longer being accessed (the "write" side)In Tyr, this would roughly map to something like:
struct TyrData {
reset_gate: RwSem<ActiveHwState>
// other, always accessible members
}impl TyrData {
fntry_access(&self)-> Option<ReadGuard<'_, ActiveHwState>> {...}
}Where ActiveHwState contains the fw/mmu/sched blocks (these are not upstream yet, Deborah has a series that will introduce the fw block that should land soon) and perhaps more.
Now, the reset logic would be roughly:
fn
reset_work(tdev: Arc<TyrDevice>){
// Block until nobody else is accessing the hw, prevent others from // initiating new accesses too..
let_guard=tdev.reset_gate.write();//
pre_reset()all Resettable implementors... reset
//
post_Resetall Resettable implementors
}Now, for every block that might touch a resource that would be unavailable during a reset, we enforce a
try_access()via the type system, and ensure that the reset cannot start while the guard is alive. In particular, ioctls would look like:fn
ioctl_foo(...){
let hw =tdev.reset_gate.try_access()?;
// resets are blocked while the guard is alive, no other way to access that state otherwise
}The code will not compile otherwise, so long as we keep the state in ActiveHwState, i.e.:
protected by the r/w sem.This looks like an improvement over Panthor, since Panthor relies on manually canceling work that access hw state via
cancel_work_sync(), and gating new work submissions on the "reset_in_progress" flag, i.e.:/**
*sched_queue_work()- Queue a scheduler work.
* @sched: Scheduler object.
* @wname: Work name.
*
* Conditionally queues a scheduler work if no reset is pending/in-progress. */
#definesched_queue_work(sched, wname)\
do { \Quoted 7 lines
if (!atomic_read(&(sched)->reset.in_progress) && \ !panthor_device_reset_is_pending((sched)->ptdev)) \
queue_work((sched)->wq, &(sched)->wname ## _work); \
} while (0)Thoughts?
I don't think a semaphore is the right answer. I think SRCU plus a counter makes more sense. (With a sentinal value reserved for "currently resetting".)
When you begin using the hardware, you start an srcu critical region and read the counter. If the counter has the sentinel value, you know the hardware is resetting and you fail. Otherwise you record the couter and proceed.
If at any point you release the srcu critical region and want to re-acquire it to continue the same ongoing work, then you must ensure that the counter still has the same value. This ensures that if the GPU is reset, then even if the reset has finished by the time you come back, you still fail because the counter has changed.
Quoted 7 lines
Another option could be to rely on the existing Device unbind logic. Entirely remove the class device and run the full unbind procedure, cleaning up all devm work etc. Then once that has finished, probe the device again and start from scratch. After all, GPU reset does not have to be a cheap operation.
Alice
Anybody working on the SRCU support or do we need to write one?
Ignoring the sync primitive for a moment (since there is no clear consensus yet), I was trying to figure out the HW access API around a closure.
I wonder if something like this (roughly, haven't implemented or compiled it yet) would make sense:
struct HwGate {
// srcu, I guess?
}
struct HwGuard<'a> {
gate: &'a HwGate,
hw: &'a ActiveHw,
}
struct ActiveHw {
// mmu, fw, ...
}
struct Controller {
...
hw: ActiveHw,
}
impl Controller {
fn with_hw<R>(&self, f: impl FnOnce(&HwGuard<'_>) -> Result<R>) -> Result<R> {
let guard = self.gate.lock(&self.hw)?;
f(&guard)
}
}and TyrDrmDeviceData would hava a helper wrapper:
impl TyrDrmDeviceData {
fn with_hw<R>(&self, f: impl FnOnce(&ActiveHwState) -> Result<R>) -> Result<R> {
self.reset.with_hw(f) // maybe find a better name for "reset"
}
}Then the user can use it like this:
let driver: TyrDrmDeviceData = ...;
driver.with_hw(|hw| {
let mmu = hw.mmu;
...
})Any thoughts?
- Onur
Onur Özkan
reviewerRe: [PATCH v1 RESEND 4/4] drm/tyr: add GPU reset handling
Quoted 269 lines · On Sat, 11 Apr 2026 08:52:15 +0300 Onur Özkan <[email protected]> wrote:
Quoted 208 lines · On Fri, 10 Apr 2026 07:56:38 +0000 Alice Ryhl <[email protected]> wrote:
Quoted 183 lines · Daniel Almeida
Hi Onur,
Quoted 99 lines · Onur Özkan
Quoted 66 lines · On Fri, 03 Apr 2026 12:01:09 -0300 Daniel Almeida…
Quoted 51 lines · Boris Brezillon
Quoted 22 lines · On Fri, 13 Mar 2026 12:16:44 +0300 Onur Özkan <[email protected]> wrote:
(quoted diff) +22
-0+impl Controller { + /// Creates a [`Controller`] instance. + fn new(pdev: ARef<platform::Device>, iomem: Arc<Devres<IoMem>>) -> Result<Arc<Self>> { + let wq = workqueue::OrderedQueue::new(c"tyr-reset-wq", 0)?; + + Arc::pin_init( + try_pin_init!(Self { + pdev, + iomem, + pending: Atomic::new(false), + wq, + work <- kernel::new_work!("tyr::reset"), + }), + GFP_KERNEL, + ) + } + + /// Processes one scheduled reset request. + /// + /// Panthor reference: + /// - drivers/gpu/drm/panthor/panthor_device.c::panthor_device_reset_work() + fn reset_work(self: &Arc<Self>) {Review
Quoted 10 lines
(quoted diff) +10
-0+ dev_info!(self.pdev.as_ref(), "GPU reset work is started.\n"); + + // SAFETY: `Controller` is part of driver-private data and only exists + // while the platform device is bound. + let pdev = unsafe { self.pdev.as_ref().as_bound() }; + if let Err(e) = run_reset(pdev, &self.iomem) { + dev_err!(self.pdev.as_ref(), "GPU reset failed: {:?}\n", e); + } else { + dev_info!(self.pdev.as_ref(), "GPU reset work is done.\n"); + }Unfortunately, the reset operation is not as simple as instructing the GPU to reset, it's a complex synchronization process where you need to try to gracefully put various components on hold before you reset, and then resume those after the reset is effective. Of course, with what we currently have in-tree, there's not much to suspend/resume, but I think I'd prefer to design the thing so we can progressively add more components without changing the reset logic too much.
I would probably start with a Resettable trait that has the {pre,post}_reset() methods that exist in Panthor.
Quoted 8 lines
The other thing we need is a way for those components to know when a reset is about to happen so they can postpone some actions they were planning in order to not further delay the reset, or end up with actions that fail because the HW is already unusable. Not too sure how we want to handle that though. Panthor is currently sprinkled with
panthor_device_reset_is_pending()calls in key places, but that's still very manual, maybe we can automate that a bit more in Tyr, dunno.We could have an enum where one of the variants is Resetting, and the other one gives access to whatever state is not accessible while resets are in progress.
Something like
Quoted 9 lines
pub enum TyrData {
Active(ActiveTyrData),
ResetInProgress(ActiveTyrData)
}fn
access()-> Option<&ActiveTyrData> {
… // if the “ResetInProgress” variant is active, return None
}That's an interesting approach, but if it's all about
fn accessfunction, we can already do that with a simple atomic state e.g.,:// The state flag in
reset::Controller
state: Atomic<ResetState>fn
access(&self)-> Option<&Arc<Devres<IoMem>>> {
matchself.state.load(Relaxed){ResetState::Idle=>Some(&self.iomem),
_ => None,
}
}What do you think? Would this be sufficient?
Btw, a sample code snippet from the caller side would be very helpful for designing this further. That part is kind a blurry for me.
Quoted 8 lines
Thanks,
OnurQuoted 5 lines
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +4
-0+ + self.pending.store(false, Release); + } +}I think that there are two things we're trying to implement correctly:
1) Deny access to a subset of the state while a reset is in progress
2) Wait for anyone accessing 1) to finish before starting a resetIIUC, using Atomic<T> can solve 1 by bailing if the "reset in progress" flag/variant is set, but I don't think it implements 2? One would have to implement more logic to block until the state is not being actively used.
Now, there are probably easier ways to solve this, but I propose that we do the extra legwork to make this explicit and enforceable by the type system.
How about introducing a r/w semaphore abstraction? It seems to correctly encode the logic we want:
a) multiple users can access the state if no reset is pending ("read" side)
b) the reset code can block until the state is no longer being accessed (the "write" side)In Tyr, this would roughly map to something like:
struct TyrData {
reset_gate: RwSem<ActiveHwState>
// other, always accessible members
}impl TyrData {
fntry_access(&self)-> Option<ReadGuard<'_, ActiveHwState>> {...}
}Where ActiveHwState contains the fw/mmu/sched blocks (these are not upstream yet, Deborah has a series that will introduce the fw block that should land soon) and perhaps more.
Now, the reset logic would be roughly:
fn
reset_work(tdev: Arc<TyrDevice>){
// Block until nobody else is accessing the hw, prevent others from // initiating new accesses too..
let_guard=tdev.reset_gate.write();//
pre_reset()all Resettable implementors... reset
//
post_Resetall Resettable implementors
}Now, for every block that might touch a resource that would be unavailable during a reset, we enforce a
try_access()via the type system, and ensure that the reset cannot start while the guard is alive. In particular, ioctls would look like:fn
ioctl_foo(...){
let hw =tdev.reset_gate.try_access()?;
// resets are blocked while the guard is alive, no other way to access that state otherwise
}The code will not compile otherwise, so long as we keep the state in ActiveHwState, i.e.:
protected by the r/w sem.This looks like an improvement over Panthor, since Panthor relies on manually canceling work that access hw state via
cancel_work_sync(), and gating new work submissions on the "reset_in_progress" flag, i.e.:/**
*sched_queue_work()- Queue a scheduler work.
* @sched: Scheduler object.
* @wname: Work name.
*
* Conditionally queues a scheduler work if no reset is pending/in-progress. */
#definesched_queue_work(sched, wname)\
do { \Quoted 7 lines
if (!atomic_read(&(sched)->reset.in_progress) && \ !panthor_device_reset_is_pending((sched)->ptdev)) \
queue_work((sched)->wq, &(sched)->wname ## _work); \
} while (0)Thoughts?
I don't think a semaphore is the right answer. I think SRCU plus a counter makes more sense. (With a sentinal value reserved for "currently resetting".)
When you begin using the hardware, you start an srcu critical region and read the counter. If the counter has the sentinel value, you know the hardware is resetting and you fail. Otherwise you record the couter and proceed.
If at any point you release the srcu critical region and want to re-acquire it to continue the same ongoing work, then you must ensure that the counter still has the same value. This ensures that if the GPU is reset, then even if the reset has finished by the time you come back, you still fail because the counter has changed.
Quoted 7 lines
Another option could be to rely on the existing Device unbind logic. Entirely remove the class device and run the full unbind procedure, cleaning up all devm work etc. Then once that has finished, probe the device again and start from scratch. After all, GPU reset does not have to be a cheap operation.
Alice
Anybody working on the SRCU support or do we need to write one?
Ignoring the sync primitive for a moment (since there is no clear consensus yet), I was trying to figure out the HW access API around a closure.
I wonder if something like this (roughly, haven't implemented or compiled it yet) would make sense:
struct HwGate { // srcu, I guess? } struct HwGuard<'a> { gate: &'a HwGate, hw: &'a ActiveHw, } struct ActiveHw { // mmu, fw, ... } struct Controller { ... hw: ActiveHw, } impl Controller { fn with_hw<R>(&self, f: impl FnOnce(&HwGuard<'_>) -> Result<R>) -> Result<R> { let guard = self.gate.lock(&self.hw)?; f(&guard) } }and TyrDrmDeviceData would hava a helper wrapper:
impl TyrDrmDeviceData { fn with_hw<R>(&self, f: impl FnOnce(&ActiveHwState) -> Result<R>) -> Result<R> { self.reset.with_hw(f) // maybe find a better name for "reset" } }Then the user can use it like this:
let driver: TyrDrmDeviceData = ...; driver.with_hw(|hw| { let mmu = hw.mmu; ... })
Quoted 3 lines
Any thoughts?
- Onur
I forgot to mention that with the closure approach, we can easily inject additional operations into hardware access like preventing the access if a reset work has been queued but not started yet, which was one of the key considerations bringed up by Boris during the Thursday call.
- Onur