fix(drm): harden DMABUF scanout/export guards and mark nvkms export PORTED (23/24 DRM)

- Harden nv_rs_fb_create() and nv_rs_crtc_atomic_flush() so imported
  NV_RS_GEM_DMABUF objects always validate single-segment contiguous sgt
  backing and scan out via import_sgt rather than kms_mem.
- Return -EOPNOTSUPP in nv_rs_ioctl_gem_export_nvkms_memory() if the
  export_memory_fd hook is unavailable instead of silently succeeding.
- Validate arguments and import_sgt in nv_rs_ioctl_gem_export_dmabuf_memory()
  and return -EOPNOTSUPP until an RM external DMA-BUF memory wrapper with
  independent attachment lifetime retention exists (avoiding a fake 0x003e
  sysmem allocation or premature drm_prime_gem_destroy on GEM close).
- Update tools/build_parity_ledger.py and docs/PARITY_LEDGER.md to mark
  nv_drm_gem_export_nvkms_memory_ioctl PORTED (backed by RM 0x00003d05)
  and keep nv_drm_gem_export_dmabuf_memory_ioctl honestly PARTIAL (23/24).
This commit is contained in:
morebrackets
2026-12-04 16:46:02 -08:00
parent 06e61c33fd
commit 2c5c5a470b
3 changed files with 22 additions and 16 deletions

View File

@ -8,16 +8,15 @@ Generated by `python3 tools/build_parity_ledger.py` against stock 580.178.04 ker
| `rm_control_table_580` | 2107 | 0 | 0 | 0 |
| `rm_controls_userspace` | 295 | 0 | 0 | 14 |
| `uvm_ioctls` | 49 | 0 | 0 | 1 |
| `drm_ioctls` | 22 | 2 | 0 | 0 |
| `drm_ioctls` | 23 | 1 | 0 | 0 |
| `nvkms_ioctls` | 14 | 52 | 0 | 0 |
| `procfs_and_caps` | 9 | 0 | 0 | 0 |
| `mmio_bus_loss_guards` | 32 | 0 | 0 | 0 |
| **TOTAL** | **2562** | **54** | **0** | **19** |
| **TOTAL** | **2563** | **53** | **0** | **19** |
## Remaining `MISSING` / `PARTIAL` Entries
- **[PARTIAL]** `drm_ioctls` `nv_drm_gem_export_dmabuf_memory_ioctl` — UAPI + Rust FFI + sgt + RM fd validation wired in nvidia_rs_drm.c (returns -EOPNOTSUPP until RM EXPORT_OBJECT_TO_FD bridge)
- **[PARTIAL]** `drm_ioctls` `nv_drm_gem_export_nvkms_memory_ioctl` — UAPI + Rust FFI + RM fd validation wired in nvidia_rs_drm.c (returns -EOPNOTSUPP until RM EXPORT_OBJECT_TO_FD bridge)
- **[PARTIAL]** `drm_ioctls` `nv_drm_gem_export_dmabuf_memory_ioctl` — UAPI + sgt + RM fd validation wired in nvidia_rs_drm.c (returns -EOPNOTSUPP until RM external DMA-BUF wrapper + attachment lifetime bridge)
- **[PARTIAL]** `nvkms_ioctls` `2:NVKMS_IOCTL_QUERY_DISP` — cmd=2 exact 580.178.04 paramSize=172 + deviceHandle validated in nvidia_rs_modeset.c (display/surface backend or per-cmd test pending)
- **[PARTIAL]** `nvkms_ioctls` `3:NVKMS_IOCTL_QUERY_CONNECTOR_STATIC_DATA` — cmd=3 exact 580.178.04 paramSize=44 + deviceHandle validated in nvidia_rs_modeset.c (display/surface backend or per-cmd test pending)
- **[PARTIAL]** `nvkms_ioctls` `4:NVKMS_IOCTL_QUERY_CONNECTOR_DYNAMIC_DATA` — cmd=4 exact 580.178.04 paramSize=20 + deviceHandle validated in nvidia_rs_modeset.c (display/surface backend or per-cmd test pending)

View File

@ -1453,6 +1453,8 @@ static int nv_rs_ioctl_gem_export_nvkms_memory(struct drm_device *dev, void *dat
if (nv_kms.export_memory_fd)
ret = nv_kms.export_memory_fd(nv_dev->kms_dev,
nv_gem->kms_mem, export_fd);
else
ret = -EOPNOTSUPP;
goto out;
}
ret = nv_kms.export_memory(nv_dev->kms_dev, nv_gem->kms_mem, &export_id);
@ -1490,7 +1492,7 @@ static int nv_rs_ioctl_gem_export_dmabuf_memory(struct drm_device *dev,
goto out;
}
if (!p->nvkms_params_ptr || p->nvkms_params_size != sizeof(u32) ||
!nv_gem->kms_mem || !nv_kms.export_memory_fd) {
!nv_dev->kms_dev || !nv_gem->import_sgt || !nv_gem->import_sgt->sgl) {
ret = -EINVAL;
goto out;
}
@ -1503,8 +1505,14 @@ static int nv_rs_ioctl_gem_export_dmabuf_memory(struct drm_device *dev,
ret = -EFAULT;
goto out;
}
ret = nv_kms.export_memory_fd(nv_dev->kms_dev,
nv_gem->kms_mem, export_fd);
/*
* Exporting an imported PRIME DMA-BUF to an RM export FD requires
* wrapping the imported pages/scatterlist in an RM external-memory
* object and retaining the DMA-BUF attachment independently of this
* GEM handle's lifetime; return -EOPNOTSUPP until that bridge exists.
*/
(void)export_fd;
ret = -EOPNOTSUPP;
}
out:
drm_gem_object_put(obj);
@ -2273,7 +2281,7 @@ static struct drm_framebuffer *nv_rs_fb_create(
* undersized scatterlists so scanout cannot read unrelated
* host memory past the first segment.
*/
if (plane_gem->kind == NV_RS_GEM_DMABUF && !plane_gem->kms_mem) {
if (plane_gem->kind == NV_RS_GEM_DMABUF) {
if (!plane_gem->import_sgt ||
plane_gem->import_sgt->nents != 1 ||
!plane_gem->import_sgt->sgl ||
@ -2513,14 +2521,14 @@ static void nv_rs_crtc_atomic_flush(struct drm_crtc *crtc,
commit.fb_modifier = ps->fb->modifier;
commit.fb_offset = ps->fb->offsets[0];
if (nv_fb->nv_gem) {
if (nv_fb->nv_gem->kms_mem)
commit.primary_mem = nv_fb->nv_gem->kms_mem;
else if (nv_fb->nv_gem->kind == NV_RS_GEM_DMABUF &&
nv_fb->nv_gem->import_sgt &&
nv_fb->nv_gem->import_sgt->nents == 1 &&
nv_fb->nv_gem->import_sgt->sgl)
if (nv_fb->nv_gem->kind == NV_RS_GEM_DMABUF &&
nv_fb->nv_gem->import_sgt &&
nv_fb->nv_gem->import_sgt->nents == 1 &&
nv_fb->nv_gem->import_sgt->sgl)
commit.primary_dma_addr =
sg_dma_address(nv_fb->nv_gem->import_sgt->sgl);
else if (nv_fb->nv_gem->kms_mem)
commit.primary_mem = nv_fb->nv_gem->kms_mem;
}
}
if (cs && cs->fb && cs->visible) {

View File

@ -427,8 +427,7 @@ def audit_drm(stock_dir: pathlib.Path) -> list[dict]:
"nv_drm_revoke_permission_ioctl": "NVIDIA_REVOKE_PERMISSIONS",
}
drm_partial_pending_rm_bridge = {
"nv_drm_gem_export_nvkms_memory_ioctl": "UAPI + Rust FFI + RM fd validation wired in nvidia_rs_drm.c (returns -EOPNOTSUPP until RM EXPORT_OBJECT_TO_FD bridge)",
"nv_drm_gem_export_dmabuf_memory_ioctl": "UAPI + Rust FFI + sgt + RM fd validation wired in nvidia_rs_drm.c (returns -EOPNOTSUPP until RM EXPORT_OBJECT_TO_FD bridge)",
"nv_drm_gem_export_dmabuf_memory_ioctl": "UAPI + sgt + RM fd validation wired in nvidia_rs_drm.c (returns -EOPNOTSUPP until RM external DMA-BUF wrapper + attachment lifetime bridge)",
}
entries = []
for sym in drm_ioctls: