Compose a frame from crtc_state, but take the gamma LUT from crtc->state,
which may already be newer: the worker runs from the vblank timer and can
fall behind a commit. Such a frame combines the planes of one state with
the LUT of another; the CRC and the writeback output can then be wrong.

Read crtc_state->base.gamma_lut instead, and clear the derived fields when
there is no LUT.

Fixes: db1f254f2cfa ("drm/vkms: Add support to 1D gamma LUT")
Signed-off-by: Oarora Etimis <[email protected]>
---
 drivers/gpu/drm/vkms/vkms_composer.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_composer.c 
b/drivers/gpu/drm/vkms/vkms_composer.c
index 0fc915a954ba..ed3c8f1a8db6 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -609,6 +609,7 @@ void vkms_composer_worker(struct work_struct *work)
                                                          struct 
vkms_crtc_state,
                                                          composer_work);
        struct drm_crtc *crtc = crtc_state->base.crtc;
+       struct drm_property_blob *gamma_lut = crtc_state->base.gamma_lut;
        struct vkms_writeback_job *active_wb = crtc_state->active_writeback;
        struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
        bool crc_pending, wb_pending;
@@ -625,19 +626,22 @@ void vkms_composer_worker(struct work_struct *work)
        crtc_state->frame_end = 0;
        crtc_state->crc_pending = false;
 
-       if (crtc->state->gamma_lut) {
+       /* crtc->state may be newer than the state this frame is built from. */
+       if (gamma_lut && gamma_lut->length) {
                s64 max_lut_index_fp;
                s64 u16_max_fp = drm_int2fixp(0xffff);
 
-               crtc_state->gamma_lut.base = (struct drm_color_lut 
*)crtc->state->gamma_lut->data;
+               crtc_state->gamma_lut.base = (struct drm_color_lut 
*)gamma_lut->data;
                crtc_state->gamma_lut.lut_length =
-                       crtc->state->gamma_lut->length / sizeof(struct 
drm_color_lut);
+                       gamma_lut->length / sizeof(struct drm_color_lut);
                max_lut_index_fp = 
drm_int2fixp(crtc_state->gamma_lut.lut_length - 1);
-               crtc_state->gamma_lut.channel_value2index_ratio = 
drm_fixp_div(max_lut_index_fp,
-                                                                              
u16_max_fp);
+               crtc_state->gamma_lut.channel_value2index_ratio =
+                       drm_fixp_div(max_lut_index_fp, u16_max_fp);
 
        } else {
                crtc_state->gamma_lut.base = NULL;
+               crtc_state->gamma_lut.lut_length = 0;
+               crtc_state->gamma_lut.channel_value2index_ratio = 0;
        }
 
        spin_unlock_irq(&out->composer_lock);
-- 
2.55.0

Reply via email to