drm/vc4: hdmi: Use a mutex to prevent concurrent framework access
authorMaxime Ripard <maxime@cerno.tech>
Mon, 25 Oct 2021 14:11:09 +0000 (16:11 +0200)
committerDom Cobley <popcornmix@gmail.com>
Mon, 21 Mar 2022 16:03:44 +0000 (16:03 +0000)
commit6ffe99e3c68bd913e94f5e3f7f1c8b1a79320fd0
tree355119de1720387e381b8283637298f2f4666884
parent0a69972f206fa72357764bb2d1d2661975b61455
drm/vc4: hdmi: Use a mutex to prevent concurrent framework access

The vc4 HDMI controller registers into the KMS, CEC and ALSA
frameworks.

However, no particular care is done to prevent the concurrent execution
of different framework hooks from happening at the same time.

In order to protect against that scenario, let's introduce a mutex that
relevant ALSA and KMS hooks will need to take to prevent concurrent
execution.

CEC is left out at the moment though, since the .get_modes and .detect
KMS hooks, when running cec_s_phys_addr_from_edid, can end up calling
CEC's .adap_enable hook. This introduces some reentrancy that isn't easy
to deal with properly.

The CEC hooks also don't share much state with the rest of the driver:
the registers are entirely separate, we don't share any variable, the
only thing that can conflict is the CEC clock divider setup that can be
affected by a mode set.

However, after discussing it, it looks like CEC should be able to
recover from this if it was to happen.

Link: https://lore.kernel.org/r/20211025141113.702757-6-maxime@cerno.tech
Fixes: bb7d78568814 ("drm/vc4: Add HDMI audio support")
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
drivers/gpu/drm/vc4/vc4_hdmi.c
drivers/gpu/drm/vc4/vc4_hdmi.h