Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2258386rwb; Wed, 5 Oct 2022 11:20:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4fDTTlUaFaPW3vFT3xwSfUE2K45cWdMu87fSUApXweJnaLMEEjweUIh44KmbE9sH4bHku7 X-Received: by 2002:a17:906:5d04:b0:722:f46c:b891 with SMTP id g4-20020a1709065d0400b00722f46cb891mr732398ejt.4.1664994031216; Wed, 05 Oct 2022 11:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664994031; cv=none; d=google.com; s=arc-20160816; b=qQPfdsN9drdqbXpuSPJlBxdbrw191gVbnHNo7xBpF5mJXgTtgnHNZHPmLHv5/Pvbm1 NfpmXpyXs8Araoxrflup3abCJeqNz5zffF6WITKfhYPSYWoVhjcxE5C4587jlKVoPx4J 5cC/hSBgco3g7TEQ6vg2d8U6SDB4XllWXCW9+uVFU0+RuHkQBXJI/9vYRfP2r6muGw2V q0/L7cUHhR5DV2l8x+DCrxAsn1CkR3DPiDIRMr3Ykcg5rZA1W/Me3gHFD0JIRCdgKys4 q56GsUIsEyvBtPPiRpeOZt/3xiiaCMaCbhigMf+wMVy8xyx0b6TAEkPw+dHpGVb5lghy uoaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=BdVv9YHozTP1GizUGQFS0aUJMfzUDUlyQp/EEnBBoF4=; b=xyPHn3yfXfTDsyU5fARIWRlnSRlIn8b6A7KlSdLMNuGaYwUs0erJYEC6E7Lvfwdtcr 20/JljEPfyOjbSSzndkgaJZxcDAeP9diGuZkGSFECxIoERi21Hjz2vPGw04zenfphcjn g1bKbPLxcjjWnQIiXisqCLcR8jCGMI9N2jZ4bGyOXRfUcp32XE17CKybYP+OnNoD8re6 Nc/teKhOfqh1STYR+2s4m3a2KcA0aULeqejucWIATSlzUtxUq/rVg1//gsvrFolTX+56 DbHvLr5wvaDyo29vuSUswMEwNcMhvhQDwS0ur4J9XZIvLuUkGwsxUnxOrYRAOTBmey4H rc4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i3-20020a0564020f0300b00459548157c7si5491324eda.407.2022.10.05.11.19.59; Wed, 05 Oct 2022 11:20:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230491AbiJESR7 (ORCPT + 99 others); Wed, 5 Oct 2022 14:17:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230487AbiJESR2 (ORCPT ); Wed, 5 Oct 2022 14:17:28 -0400 Received: from relay05.th.seeweb.it (relay05.th.seeweb.it [IPv6:2001:4b7a:2000:18::166]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 168417FE5D for ; Wed, 5 Oct 2022 11:17:26 -0700 (PDT) Received: from localhost.localdomain (94-209-172-39.cable.dynamic.v4.ziggo.nl [94.209.172.39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by m-r2.th.seeweb.it (Postfix) with ESMTPSA id 9BF103EF3C; Wed, 5 Oct 2022 20:17:24 +0200 (CEST) From: Marijn Suijten To: phone-devel@vger.kernel.org, Rob Clark , Dmitry Baryshkov , Vinod Koul Cc: ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno , Konrad Dybcio , Martin Botka , Jami Kettunen , Marijn Suijten , Daniel Vetter , Abhinav Kumar , Sean Paul , Thomas Zimmermann , Javier Martinez Canillas , Alex Deucher , Douglas Anderson , Vladimir Lypak , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, David Airlie Subject: [PATCH v2 7/7] drm/msm/dsi: Prevent signed BPG offsets from bleeding into adjacent bits Date: Wed, 5 Oct 2022 20:16:57 +0200 Message-Id: <20221005181657.784375-8-marijn.suijten@somainline.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221005181657.784375-1-marijn.suijten@somainline.org> References: <20221005181657.784375-1-marijn.suijten@somainline.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The bpg_offset array contains negative BPG offsets which fill the full 8 bits of a char thanks to two's complement: this however results in those bits bleeding into the next field when the value is packed into DSC PPS by the drm_dsc_helper function, which only expects range_bpg_offset to contain 6-bit wide values. As a consequence random slices appear corrupted on-screen (tested on a Sony Tama Akatsuki device with sdm845). Use AND operators to limit these two's complement values to 6 bits, similar to the AMD and i915 drivers. Fixes: b9080324d6ca ("drm/msm/dsi: add support for dsc data") Signed-off-by: Marijn Suijten --- drivers/gpu/drm/msm/dsi/dsi_host.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c index 4717d49d76be..b3cff3d3aa85 100644 --- a/drivers/gpu/drm/msm/dsi/dsi_host.c +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c @@ -1806,7 +1806,11 @@ static int dsi_populate_dsc_params(struct msm_dsi_host *msm_host, struct drm_dsc for (i = 0; i < DSC_NUM_BUF_RANGES; i++) { dsc->rc_range_params[i].range_min_qp = min_qp[i]; dsc->rc_range_params[i].range_max_qp = max_qp[i]; - dsc->rc_range_params[i].range_bpg_offset = bpg_offset[i]; + /* + * Range BPG Offset contains two's-complement signed values that fill + * 8 bits, yet the registers and DCS PPS field are only 6 bits wide. + */ + dsc->rc_range_params[i].range_bpg_offset = bpg_offset[i] & DSC_RANGE_BPG_OFFSET_MASK; } dsc->initial_offset = 6144; /* Not bpp 12 */ -- 2.38.0