并发、DMA/IOMMU、安全与故障排查

并发、DMA/IOMMU、安全与故障排查

1. 并发域

该目录跨越:

  • process context ioctl/sysfs;
  • fbcon/console;
  • IRQ;
  • workqueue/timer;
  • runtime/system PM;
  • dma-buf/fence callbacks;
  • remove/shutdown。

单一mutex不能覆盖所有域。

2. 锁层次

建议固定顺序:

1
2
3
4
5
global/service
-> device
-> session
-> queue/job
-> buffer

IRQ只使用spinlock/atomic和短临界区;等待fence时不能持有阻止producer运行的锁。

3. Job状态

明确:

1
NEW -> QUEUED -> RUNNING -> DONE/ERROR/CANCELLED

只有一个路径负责最终free和fence signal,避免timeout与IRQ同时完成导致double free。

4. Remove顺序

1
2
3
4
5
6
7
8
9
remove userspace entry
-> reject new open/ioctl
-> cancel/drain pending work
-> mask IRQ
-> stop/reset hardware
-> complete active jobs with error
-> detach/unmap dma-buf/IOMMU
-> disable PM/clock
-> free device

5. DMA边界

所有plane计算使用checked arithmetic:

1
required = offset + stride * (height - 1) + last_line_bytes

还需考虑chroma subsampling、compressed modifiers、alignment和address width。

6. IOMMU

IOMMU限制设备可访问范围,但不能弥补:

  • 同一mapped buffer内部越界;
  • secure buffer误授权;
  • use-after-unmap;
  • 错误DMA direction;
  • cache同步遗漏。

7. Fence

  • import input fence;
  • job依赖满足后调度;
  • completion/error都signal output fence;
  • close/remove不能留下永不signal fence;
  • 检测或避免依赖环。

8. Userspace ABI

ioctl结构需:

  • 固定宽度类型;
  • reserved清零;
  • version/size;
  • copy_from_user完整检查;
  • pointer compat处理;
  • 数组count上限;
  • command/register白名单。

9. 设备节点权限

/dev/fbN可读取屏幕;RGA/MPP等节点可驱动高带宽DMA。按最小权限配置udev/SELinux,容器中不要默认透传。

10. 信息泄露

  • 新buffer先清零;
  • 不把未初始化register/result复制给用户;
  • debugfs不输出physical address;
  • crash dump避免包含受保护视频帧;
    -释放敏感metadata前清理。

11. DoS

限制:

  • 每session outstanding jobs;
  • imported buffer数/总字节;
  • timeout;
  • debug dump频率;
  • fault reset频率;
  • 最大分辨率和寄存器消息长度。

12. 故障定位路径

1
2
3
4
5
6
7
8
9
10
11
12
Kconfig/module
-> DT match/status
-> probe resources
-> device node/sysfs
-> open/ioctl
-> buffer import
-> IOMMU map
-> clock/PM
-> job queue
-> hardware start
-> IRQ/fence
-> display consumer

13. 关键观测

  • dmesg probe/reset/IOMMU fault;
  • /sys/kernel/debug/dri/0/state
  • debugfs/procfs job/session;
  • /proc/interrupts
  • clock/power-domain;
  • dma-buf/fence信息;
  • PWM/backlight;
  • tracepoints/ftrace。

14. 典型症状

症状 可能原因
ioctl永久等待 IRQ丢失、fence未signal、timeout失效
IOMMU fault size/offset、提前unmap、错误domain
随机花屏 producer/consumer同步、stride/format、cache
suspend后hang active job未drain、clock恢复顺序
remove崩溃 open/session/IRQ仍引用对象
性能低 DDR/QoS、重复copy、频繁PM、core策略

15. 配置裁剪

保留RK3588实际使用的DRM、bridge/panel、backlight、RGA/MPP backend;关闭无关legacy fb、vehicle、tunnel、proc/debugfs。裁剪后需回归boot logo、console、suspend、视频、合成和异常reset。

文章互动

阅读 --

留言

0 条留言

正在加载留言…