Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3845742rwb; Sun, 9 Oct 2022 12:12:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7NDIDNaYYj9BZR6mmYOpJ8ZezADPV8kwusT3kKTqWmkQnwzIltCVbIxi4DWnmK5Dv11h00 X-Received: by 2002:a17:903:2349:b0:178:111b:e6da with SMTP id c9-20020a170903234900b00178111be6damr15390773plh.70.1665342713242; Sun, 09 Oct 2022 12:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665342713; cv=none; d=google.com; s=arc-20160816; b=nL71JcTWp0rDHbuyCoARg8YzPEmtZQRmdzklcvsxnVLUoHYM+tEcsqqqOe2H6h8ku2 apAxS/vcvHrJl8ekxIsoPmjLCS5IZppERMg5oRPuY6qmRW5zCBaK37k4QOrQdScJ7GZB GRpA27GFEKnYMVNhkpE0gCDBfOZKjhRyLUC4Tf5zzbvUDa5tv0eUXGNkWeLlNTYc6vCp P0UE535HdlLkbLqPpoKlfU4CZw86DjpII2c1aVcEP1a7oI/MW6K/Es4TqcM/h7IzP0ZR q252BrXO6u68YDSgCttujCwH6oGuuBKQa9iZkxUt0CNvWucwp90NmmzAbq0tY5mX1wE7 bC9A== 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=8hXhUkr41zcBlmmCFLiuXrW1Zbo3gQuvOGsM6YQnSj8=; b=XBq+D+oyEUe1T3crJ6mPSKNL9DkgUJoZbb9NkkYqIPijYg+fZyOWkMc6Db2pUWRoM8 t3WOjMC7Eg2x30HaZVif7djfm9glmYmW5kzqhpDzCvQcH/73Jx2ElbP+mihUvgQ7kt2U MTx9yr65GrrDoLBDqp9QBCVE13J3Or0Y0aQAKDbqDH5phhAciuMHLxm1loxdUWg++uxs fzdtpLD9CTVzrGOff+GMrQhwmB0/VhSt36onUa1tc2EyPpwtxPpWHwznQmrEpAH7CLov hmWSWGqHQGAYlws1EUVBXnflK6e+jr7PGVROV08eYss1ReNaEs9E9KVKRTsRyOlRUAJk 6UXQ== 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 f18-20020a170902f39200b0018040bdb798si7344863ple.242.2022.10.09.12.11.41; Sun, 09 Oct 2022 12:11:53 -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 S230380AbiJISxz (ORCPT + 99 others); Sun, 9 Oct 2022 14:53:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbiJISxn (ORCPT ); Sun, 9 Oct 2022 14:53:43 -0400 Received: from relay02.th.seeweb.it (relay02.th.seeweb.it [5.144.164.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFCC729829; Sun, 9 Oct 2022 11:53:42 -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-r1.th.seeweb.it (Postfix) with ESMTPSA id C9E781F986; Sun, 9 Oct 2022 20:53:40 +0200 (CEST) From: Marijn Suijten To: phone-devel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno , Konrad Dybcio , Martin Botka , Jami Kettunen , Marijn Suijten , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Daniel Vetter , Vinod Koul , Douglas Anderson , Vladimir Lypak , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 10/10] drm/msm/dsi: Prevent signed BPG offsets from bleeding into adjacent bits Date: Sun, 9 Oct 2022 20:53:15 +0200 Message-Id: <20221009185316.462522-3-marijn.suijten@somainline.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221009184824.457416-1-marijn.suijten@somainline.org> References: <20221009184824.457416-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,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 46032c576a59..c5c2d70ac27d 100644 --- a/drivers/gpu/drm/msm/dsi/dsi_host.c +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c @@ -1804,7 +1804,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