[PATCH 2/9] drm/tyr: report mmu page faults
From: Daniel Almeida
Date: Fri Nov 27 2026 - 21:16:24 EST
A page fault sets the address space's bit in the mmu IRQ and records the
fault in that address space's FAULTSTATUS and FAULTADDRESS registers.
Tyr keeps every mmu IRQ source masked, so page faults go unreported.
Unmask the page-fault interrupt of every present address space, and log
each fault with its address space, address, exception type, access type
and source.
Nothing resolves the fault yet, and an address space that faulted can
fault again, so mask its page-fault interrupt once the fault is reported
to avoid interrupt storms, like panthor does.
Signed-off-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
---
drivers/gpu/drm/tyr/driver.rs | 4 +-
drivers/gpu/drm/tyr/mmu/irq.rs | 120 ++++++++++++++++++++++++++++++++++++-----
2 files changed, 108 insertions(+), 16 deletions(-)
diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs
index 44ff1f522902..1fb91d0757f7 100644
--- a/drivers/gpu/drm/tyr/driver.rs
+++ b/drivers/gpu/drm/tyr/driver.rs
@@ -82,7 +82,7 @@ pub(crate) struct TyrDrmRegistrationData<'drm> {
// `TyrIrqRegistration::drop()` writes to the GPU registers, so keep this
// field before the clocks and regulators.
- _mmu_irq: Pin<KBox<TyrIrqRegistration<'drm, MmuIrq>>>,
+ _mmu_irq: Pin<KBox<TyrIrqRegistration<'drm, MmuIrq<'drm>>>>,
#[pin]
clks: Mutex<Clocks>,
@@ -155,7 +155,7 @@ fn probe<'bound>(
// SAFETY: The registration ends up in `TyrDrmRegistrationData`, which `_reg`
// drops at unbind, and every error path before that drops it.
- let mmu_irq = unsafe { mmu_irq_init(pdev, hw.clone()) }?;
+ let mmu_irq = unsafe { mmu_irq_init(pdev, hw.clone(), &gpu_info) }?;
let firmware = Firmware::new(
pdev.as_ref(),
diff --git a/drivers/gpu/drm/tyr/mmu/irq.rs b/drivers/gpu/drm/tyr/mmu/irq.rs
index 7f8b02613e9e..53ff1b2151ee 100644
--- a/drivers/gpu/drm/tyr/mmu/irq.rs
+++ b/drivers/gpu/drm/tyr/mmu/irq.rs
@@ -5,30 +5,61 @@
//! The MMU IRQ reports page faults and completed commands for each address space.
use kernel::{
- device::Bound,
- io::Io,
+ device::{
+ Bound,
+ Device, //
+ },
+ io::{
+ register::Array,
+ Io, //
+ },
+ num::casts::FromSafeCast,
platform,
prelude::*,
- sync::Arc, //
+ sync::{
+ atomic::{
+ ordering,
+ Atomic, //
+ },
+ Arc, //
+ }, //
};
use crate::{
driver::IoMem,
+ gpu::GpuInfo,
irq::{
TyrIrqRegistration,
TyrIrqTrait, //
},
- regs::mmu_control::{
- IRQ_CLEAR,
- IRQ_MASK,
- IRQ_RAWSTAT,
- IRQ_STATUS, //
+ regs::{
+ gpu_control::AS_PRESENT,
+ join_u64,
+ mmu_control::{
+ mmu_as_control::{
+ FAULTADDRESS_HI,
+ FAULTADDRESS_LO,
+ FAULTSTATUS, //
+ },
+ IRQ_CLEAR,
+ IRQ_MASK,
+ IRQ_RAWSTAT,
+ IRQ_STATUS, //
+ }, //
},
reset::HwGate, //
};
/// The MMU IRQ, signalling events from the address spaces.
-pub(crate) struct MmuIrq;
+pub(crate) struct MmuIrq<'a> {
+ /// Device used for logging.
+ dev: &'a Device<Bound>,
+ /// Shared gate that coordinates hardware access with GPU reset.
+ hw: Arc<HwGate<'a>>,
+ /// Interrupt sources to unmask: the page-fault bit of each present address
+ /// space that has not faulted yet.
+ mask: Atomic<u32>,
+}
/// Requests a threaded IRQ registration for the MMU IRQ.
///
@@ -39,8 +70,14 @@
pub(crate) unsafe fn mmu_irq_init<'a>(
pdev: &'a platform::Device<Bound>,
hw: Arc<HwGate<'a>>,
-) -> Result<Pin<KBox<TyrIrqRegistration<'a, MmuIrq>>>> {
- let mmu_irq = MmuIrq;
+ gpu_info: &GpuInfo,
+) -> Result<Pin<KBox<TyrIrqRegistration<'a, MmuIrq<'a>>>>> {
+ let present = AS_PRESENT::from_raw(gpu_info.as_present).present().get();
+ let mmu_irq = MmuIrq {
+ dev: pdev.as_ref(),
+ hw: hw.clone(),
+ mask: Atomic::new(IRQ_MASK::zeroed().try_with_page_fault(present)?.into_raw()),
+ };
// Ensure interrupt sources are disabled until the handler is registered.
mmu_irq.clear_mask(hw.access().iomem());
@@ -48,7 +85,41 @@ pub(crate) unsafe fn mmu_irq_init<'a>(
unsafe { TyrIrqRegistration::request(pdev, c"mmu", c"tyr-mmu", mmu_irq, hw) }
}
-impl TyrIrqTrait for MmuIrq {
+impl MmuIrq<'_> {
+ /// Logs the page fault reported by address space `as_nr`.
+ fn report_fault(&self, io: &IoMem<'_>, as_nr: usize) -> Result {
+ let fault = io.read(FAULTSTATUS::try_at(as_nr).ok_or(EINVAL)?);
+ let address = join_u64(
+ io.read(FAULTADDRESS_LO::try_at(as_nr).ok_or(EINVAL)?)
+ .into_raw(),
+ io.read(FAULTADDRESS_HI::try_at(as_nr).ok_or(EINVAL)?)
+ .into_raw(),
+ );
+
+ match fault.exception_type() {
+ Ok(exception) => dev_err!(
+ self.dev,
+ "Page fault in AS{} at VA {:#018x}: {:?} on {:?} access, source {:#x}\n",
+ as_nr,
+ address,
+ exception,
+ fault.access_type(),
+ fault.source_id().get()
+ ),
+ Err(_) => dev_err!(
+ self.dev,
+ "Page fault in AS{} at VA {:#018x}: FAULTSTATUS {:#010x}\n",
+ as_nr,
+ address,
+ fault.into_raw()
+ ),
+ }
+
+ Ok(())
+ }
+}
+
+impl TyrIrqTrait for MmuIrq<'_> {
fn read_status(&self, io: &IoMem<'_>) -> u32 {
io.read(IRQ_STATUS).into_raw()
}
@@ -70,8 +141,29 @@ fn clear_status(&self, io: &IoMem<'_>, status: u32) {
}
fn mask(&self) -> u32 {
- IRQ_MASK::zeroed().into_raw()
+ self.mask.load(ordering::Relaxed)
}
- fn handle(&self, _status: u32) {}
+ fn handle(&self, status: u32) {
+ let faults = IRQ_RAWSTAT::from_raw(status).page_fault();
+ let hw_guard = self.hw.access();
+ let io = hw_guard.iomem();
+
+ let mut pending = faults.get();
+ while pending != 0 {
+ // The lowest set bit is the next address space that faulted.
+ let as_nr = usize::from_safe_cast(pending.trailing_zeros());
+ pending &= pending - 1;
+
+ let _ = self.report_fault(io, as_nr);
+ }
+
+ // Nothing resolves these faults yet, and an address space that faulted
+ // can fault again, so stop reporting to avoid storms.
+ let faulted = IRQ_MASK::zeroed().with_page_fault(faults).into_raw();
+ self.mask.store(
+ self.mask.load(ordering::Relaxed) & !faulted,
+ ordering::Relaxed,
+ );
+ }
}
--
2.56.0