# DF-3791 — Missing upstream fix `022debad063e` ("drm/atomic: Add drm_atomic_state->duplicated")

DragonFlyBSD `sys/dev/drm/drm_atomic_helper.c` (≈ Linux v5.0-rc vintage) does not
carry upstream commit 022debad063e (torvalds, 2019-02-05, first released in
v5.2-rc1). That commit:

1. adds a `duplicated` flag to `struct drm_atomic_state`,
2. sets it in `drm_atomic_helper_duplicate_state()`,
3. gates the "unregistered connector" rejection in `update_connector_routing()`
   with `!state->duplicated`.

Without it, `drm_atomic_helper_resume()` fails its atomic check whenever any
connector that was part of the suspended configuration has been unregistered
(hot-unplug / DP-MST topology change) while the machine was suspended, and the
entire display configuration fails to restore (all outputs stay dark, kernel
console dead until userspace manages a fresh modeset).

## Local evidence

* `sys/dev/drm/drm_atomic_helper.c:325` — the guard is missing:
  ```c
  if (drm_connector_is_unregistered(connector) && crtc_state->active) {
          ... return -EINVAL;
  ```
  upstream v5.2+: `if (!state->duplicated && drm_connector_is_unregistered(...) && ...)`
* `sys/dev/drm/drm_atomic_helper.c:3840-3901` — `drm_atomic_helper_duplicate_state()`
  never sets a duplicated flag (the field does not exist anywhere in
  `sys/dev/drm/include/drm/`).
* Resume path that then dies: `drm_atomic_helper_commit_duplicated_state()`
  (`:3230`) → `drm_atomic_commit()` → `drm_atomic_helper_check_modeset()` →
  `update_connector_routing()` (`:325` returns -EINVAL).
* In-tree users of the broken suspend/resume pair:
  `sys/dev/drm/amd/display/amdgpu_dm/amdgpu_dm.c:710` / `:908`
  (`drm_atomic_helper_suspend` / `drm_atomic_helper_resume`) and
  `sys/dev/drm/i915/intel_display.c:6381` (i915 suspend).

## What upstream says (commit 022debad063e)

> Since commit 39b50c603878 ("drm/atomic_helper: Stop modesets on
> unregistered connectors harder") we've been failing atomic checks if they try
> to enable new displays on unregistered connectors. This is fine except for
> the one situation that breaks atomic assumptions: suspend/resume. If a
> connector is unregistered before we attempt to restore the atomic state, we
> end up failing the atomic check that happens when trying to restore the
> state during resume.

## Reproduce (requires real GPU hardware — NOT possible on this guest)

1. Boot DFly with amdgpu or i915 KMS on a machine with a hot-pluggable
   display (DP or DP-MST dock).
2. `acpiconf -s 4` (suspend to RAM) with the display configured.
3. Unplug the display / dock while suspended.
4. Resume. Expected on vulnerable kernel: `drm_atomic_helper_resume()` fails
   with -EINVAL ("[CONNECTOR:n] is not registered"), outputs never re-enable.
   Expected with fix applied: resume restores the remaining outputs.

The provided QEMU guest has no DRM-capable GPU (QEMU std VGA 0x1111:1234, no
in-tree driver, drm.ko not loaded, /dev/dri absent) — see `env.txt`. Runtime
verification is therefore impossible on this guest; the finding is proven at
source level by direct diff against the upstream fix.
