Re: [PATCH v2 2/4] drm/verisilicon: nuke planes' atomic_enable hooks

From: Icenowy Zheng

Date: Wed Nov 18 2026 - 09:55:23 EST


在 2026-11-17二的 08:39 +0100,Thomas Zimmermann写道:
> Hi
>
> Am 17.11.26 um 08:34 schrieb Icenowy Zheng:
> > 在 2026-11-17二的 08:25 +0100,Thomas Zimmermann写道:
> > > Hi
> > >
> > > Am 17.11.26 um 06:19 schrieb Icenowy Zheng:
> > > [...]
> > > > > > Sure, but is that a problem for this hardware?
> > > > > For the cursor plane, the unchecked coordinate might be
> > > > > improper
> > > > > for
> > > > > the registers.
> > > > >
> > > > > For the primary plane, if the plane is found to be totally
> > > > > off by
> > > > > drm_atomic_helper_check_plane_state(), the check for
> > > > > can_position,
> > > > > which is below the code snippet I referenced, would be
> > > > > bypassed,
> > > > > and
> > > > > such plane would be programmed to be visible by the
> > > > > atomic_update
> > > > > hook
> > > > > even if it shouldn't be visible.
> > > > Well I am now thinking that bound-but-invisible situation is
> > > > commonly
> > > > ignored by drivers.
> > > >
> > > > For drm/verisilicon, maybe I'd remove both atomic_disable and
> > > > atomic_enable; however I think the atomic helpers may need some
> > > > flag to
> > > > consider bound-but-invisible planes when calling
> > > > atomic_{dis,en}able.
> > > I don't think I really understand what you're up to, but it seems
> > > you're
> > > overthinking the whole thing. Other drivers only care about plane
> > > on/off
> > Well I don't know whether I am overthinking...
> >
> > Enabled but invisible planes are explicitly allowed in
> > drm_atomic_helper_check_plane_state(), and even the can_position
> > check
> > is bypassed in such case (so such a configuration can even appear
> > on
> > primary planes). In addition, in most implementations for
> > atomic_check,
> > the invisible situations have the validity check explicitly
> > skipped, so
> > just disallow enabled-but-invisible planes in atomic_check would
> > make
> > the behavior quite different with most drivers.
> >
> > Maybe I should craft some "evil" programs to check for this
> > situation.
>
> If you can make an igt test case for broken plane coordinates, go for
> it.

Well the behavior here is possible to be examined with modetest.

My conclusion is that off-screen plane coordinates is really something
needed to be handled. I think I am not overthinking, but I will drop
both atomic_enable and atomic_disable for symmetry in the next revision
of this patchset.

In the following tests, connector 48 is connected to a HDMI sink (a
capture card) with a preferred mode at 1280x720@60, CRTC 46 is second
CRTC (which is hardwired to the HDMI connector), plane 41 is the
primary plane of CRTC 46 and plane 43 is the cursor plane of CRTC 46.

`modetest -s 48:1280x720 -P 43@46:64x64+200+200@AR24` properly creates
a 64x64 overlay at (200, 200).

`modetest -s 48:1280x720 -P 41@46:1280x720@XR24` changes the whole
primary plane to a overlay pattern.

`modetest -s 48:1280x720 -P 41@46:1280x720+200+200@XR24` displays SMPTE
pattern (instead of overlay pattern) on the primary plane, and the
plane operation fails with `failed to enable plane: Invalid argument`
error message (which means an offseted position of the primary plane is
rejected).

With no patch applied to v7.4-rc3 drm/verisilicon:

`modetest -s 48:1280x720 -P 43@46:64x64+2000+2000@AR24` crashes the
kernel with NULL pointer dereference caused by
vs_cursor_plane_atomic_disable() called by
vs_cursor_plane_atomic_update().

With vs_cursor_plane_atomic_disable() call removed from
vs_cursor_plane_atomic_update():

`modetest -s 48:1280x720 -P 43@46:64x64+2000+2000@AR24` leaves dirty
state in the cursor configuration registers, and the cursor is fully
visible when it shouldn't (when running after setting the cursor at
(200, 200), the cursor is left at (200, 200) instead of being hidden).

Even `modetest -s 48:1280x720 -P 43@46:40x64+2000+2000@AR24` in this
case shows the cursor plane despite the hardware only accepts squared
cursors because of the validity check of off-screen planes is skipped
(which means programming registers in atomic_update callback is now not
safe).

Then, with PATCH v2 3/4 from this patchset applied:

`modetest -s 48:1280x720 -P 41@46:1280x720+2000+2000@XR24` leaves a
black screen, without any error message (because the off-screen
position of the primary plane isn't rejected and makes the plane
invisible).

Then, with vs_primary_plane_atomic_disable() call removed from
vs_primary_plane_atomic_update():

`modetest -s 48:1280x720 -P 41@46:1280x720+2000+2000@XR24` displays
SMPTE pattern (instead of overlay pattern) on the primary plane, and no
error message is shown.

Thanks,
Icenowy

>
> Best regards
> Thomas
>
> >
> > Thanks,
> > Icenowy
> >
> > > and the contained image. That's also what the 3 callbacks are
> > > for. It
> > > usually works nicely. Hence me asking. But maybe verisilicon is
> > > different, IDK.
> > >
> > > My suggestion is therefore to remove _enable and _disable and
> > > keep
> > > all
> > > logic in _update.
> > >
> > > atomic_update()
> > > {
> > >       if (plane_state->visible) {
> > >           // do update
> > >           // enable hw plane
> > >       } else {
> > >           // disable hw plane
> > >       }
> > > }
> > >
> > > If you have any special cases where you want visible to be false
> > > (or
> > > true), detect them in atomic_check and set the flags accordingly.
> > >
> > > atomic_check()
> > > {
> > > drm_atomic_helper_check_plane_state()     if (awkward coords)
> > >            plane_state->visible = false;
> > > }
> > >
> > > Best regards
> > > Thomas
> > >
> > > > Thanks,
> > > > Icenowy
> > > >
> > > > > Thanks,
> > > > > Icenowy
> > > > >
> > > > > > Best regards
> > > > > > Thomas
> > > > > >
> > > > > > > The end of drm_atomic_helper_check_plane_state() says:
> > > > > > >
> > > > > > > ```
> > > > > > > if (!plane_state->visible)
> > > > > > > /*
> > > > > > > * Plane isn't visible; some drivers can
> > > > > > > handle
> > > > > > > this
> > > > > > > * so we just return success here. 
> > > > > > > Drivers
> > > > > > > that
> > > > > > > can't
> > > > > > > * (including those that use the primary
> > > > > > > plane
> > > > > > > helper's
> > > > > > > * update function) will return an error
> > > > > > > from
> > > > > > > their
> > > > > > > * update_plane handler.
> > > > > > > */
> > > > > > > return 0;
> > > > > > > ```
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Icenowy
> > > > > > >
> > > > > > > > [1]
> > > > > > > > https://elixir.bootlin.com/linux/v7.3.1/source/drivers/gpu/drm/drm_atomic_helper.c#L3030
> > > > > > > >
> > > > > > > > Best regards
> > > > > > > > Thomas
> > > > > > > >
> > > > > > > > >      };
> > > > > > > > >     
> > > > > > > > > diff --git
> > > > > > > > > a/drivers/gpu/drm/verisilicon/vs_primary_plane.c
> > > > > > > > > b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
> > > > > > > > > index 8e94491693019..fca692f4f7d5c 100644
> > > > > > > > > --- a/drivers/gpu/drm/verisilicon/vs_primary_plane.c
> > > > > > > > > +++ b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
> > > > > > > > > @@ -59,25 +59,6 @@ static void
> > > > > > > > > vs_primary_plane_commit(struct
> > > > > > > > > vs_dc
> > > > > > > > > *dc, unsigned int output)
> > > > > > > > >       VSDC_FB_CONFIG_EX_COMMIT);
> > > > > > > > >      }
> > > > > > > > >     
> > > > > > > > > -static void vs_primary_plane_atomic_enable(struct
> > > > > > > > > drm_plane
> > > > > > > > > *plane,
> > > > > > > > > -    struct
> > > > > > > > > drm_atomic_commit *atomic_state)
> > > > > > > > > -{
> > > > > > > > > - struct drm_plane_state *state =
> > > > > > > > > drm_atomic_get_new_plane_state(atomic_state,
> > > > > > > > > -
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >        plane);
> > > > > > > > > - struct drm_crtc *crtc = state->crtc;
> > > > > > > > > - struct vs_crtc *vcrtc =
> > > > > > > > > drm_crtc_to_vs_crtc(crtc);
> > > > > > > > > - unsigned int output = vcrtc->id;
> > > > > > > > > - struct vs_dc *dc = vcrtc->dc;
> > > > > > > > > -
> > > > > > > > > - regmap_set_bits(dc->regs,
> > > > > > > > > VSDC_FB_CONFIG_EX(output),
> > > > > > > > > - VSDC_FB_CONFIG_EX_FB_EN);
> > > > > > > > > - regmap_update_bits(dc->regs,
> > > > > > > > > VSDC_FB_CONFIG_EX(output),
> > > > > > > > > -
> > > > > > > > > VSDC_FB_CONFIG_EX_DISPLAY_ID_MASK,
> > > > > > > > > -
> > > > > > > > > VSDC_FB_CONFIG_EX_DISPLAY_ID(output));
> > > > > > > > > -
> > > > > > > > > - vs_primary_plane_commit(dc, output);
> > > > > > > > > -}
> > > > > > > > > -
> > > > > > > > >      static void
> > > > > > > > > vs_primary_plane_atomic_disable(struct
> > > > > > > > > drm_plane
> > > > > > > > > *plane,
> > > > > > > > >           struct
> > > > > > > > > drm_atomic_commit *atomic_state)
> > > > > > > > >      {
> > > > > > > > > @@ -144,13 +125,18 @@ static void
> > > > > > > > > vs_primary_plane_atomic_update(struct drm_plane
> > > > > > > > > *plane,
> > > > > > > > >       regmap_write(dc->regs,
> > > > > > > > > VSDC_FB_BLEND_CONFIG(output),
> > > > > > > > >      
> > > > > > > > > VSDC_FB_BLEND_CONFIG_BLEND_DISABLE);
> > > > > > > > >     
> > > > > > > > > + regmap_set_bits(dc->regs,
> > > > > > > > > VSDC_FB_CONFIG_EX(output),
> > > > > > > > > + VSDC_FB_CONFIG_EX_FB_EN);
> > > > > > > > > + regmap_update_bits(dc->regs,
> > > > > > > > > VSDC_FB_CONFIG_EX(output),
> > > > > > > > > +
> > > > > > > > > VSDC_FB_CONFIG_EX_DISPLAY_ID_MASK,
> > > > > > > > > +
> > > > > > > > > VSDC_FB_CONFIG_EX_DISPLAY_ID(output));
> > > > > > > > > +
> > > > > > > > >       vs_primary_plane_commit(dc, output);
> > > > > > > > >      }
> > > > > > > > >     
> > > > > > > > >      static const struct drm_plane_helper_funcs
> > > > > > > > > vs_primary_plane_helper_funcs = {
> > > > > > > > >       .atomic_check =
> > > > > > > > > vs_primary_plane_atomic_check,
> > > > > > > > >       .atomic_update =
> > > > > > > > > vs_primary_plane_atomic_update,
> > > > > > > > > - .atomic_enable =
> > > > > > > > > vs_primary_plane_atomic_enable,
> > > > > > > > >       .atomic_disable =
> > > > > > > > > vs_primary_plane_atomic_disable,
> > > > > > > > >      };
> > > > > > > > >