Message ID | 20221213232207.113607-7-marijn.suijten@somainline.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp420791wrn; Tue, 13 Dec 2022 15:29:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf6dO4KMhf5S2VHsqTXet76rSeXoh9R8PsIYFlJJ/hP57ZQXiyK36FSZ88psDgGWnSPYDydu X-Received: by 2002:a17:906:18e2:b0:78d:f455:c381 with SMTP id e2-20020a17090618e200b0078df455c381mr18962461ejf.39.1670974183734; Tue, 13 Dec 2022 15:29:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670974183; cv=none; d=google.com; s=arc-20160816; b=A1YWnrkLkdVpby7b8uIVILys7FiH6j1qCQGpnNbKfz12Lum1eJFXN8X+ZQ4PaADA37 UhXv/ocb42qWYmklbXrPX1fvti9XhFnhCkAQmqfEuYTteDoxTRyimlcki5rozKenm2NT aUD8sks/cGRKPfOlGsaTufcXNLSK1XXi2P2T/2zyOFsOsRXjjNiz4wKU667jwIM2j+He 0hLjMmQGpXuE1MblMLHYOI6BD/sBE/TXTy880jq31GjDB2mSCgMhsFx4ObWpgiDEcwj9 g7nVeIXw5pL6g/a/EycF80Tvm+EIXUGR6PHWH9ZvM/PQWSOtG1bQH4zWN93teF3JRq0U WuXQ== 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=JOP0dVOpQcmGg6AFef1F6zxF08zmDbJ4uoMKByDlzSw=; b=AnVCb6qr6In1lZ6Fd0yNu8uPMpjWMsh/sNI/zuVBktPHxzFucj+SQA/Ujk/Y4p6V0v kOMhnE+rZzilHr8uhWnMCBnwV1FlaW6p2zvksbOWFdi6zWWhqm17FT2GGblhKCo/C1bJ /O8SVYRQneXCwa3vHlyHdmyqCax86q++4kB3aeqWhykcSCrnQt3HLGXrVsgjbKVf6bwn E+HCyo7gy/+R5MCvX4ZINttJjmwFXXOShGoiNGhEo1KHypqHzzcEKB8uIpI1EE3G6nQ4 /Y0SuiW6Lr66ZD5+no5+D0vPkqEDO7w4062Q+wKgdlP86WG8l+4b/74NQLHbWTNJFWrN D7Sg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a170906794900b007830e41ed56si11067404ejo.431.2022.12.13.15.29.19; Tue, 13 Dec 2022 15:29:43 -0800 (PST) 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 S237065AbiLMXXQ (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Tue, 13 Dec 2022 18:23:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237009AbiLMXW6 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 13 Dec 2022 18:22:58 -0500 Received: from relay02.th.seeweb.it (relay02.th.seeweb.it [5.144.164.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7681362D1 for <linux-kernel@vger.kernel.org>; Tue, 13 Dec 2022 15:22:41 -0800 (PST) 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 3D61C202EE; Wed, 14 Dec 2022 00:22:39 +0100 (CET) From: Marijn Suijten <marijn.suijten@somainline.org> To: phone-devel@vger.kernel.org, Rob Clark <robdclark@gmail.com>, Abhinav Kumar <quic_abhinavk@quicinc.com>, Dmitry Baryshkov <dmitry.baryshkov@linaro.org>, Vinod Koul <vkoul@kernel.org> Cc: ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>, Konrad Dybcio <konrad.dybcio@somainline.org>, Martin Botka <martin.botka@somainline.org>, Jami Kettunen <jami.kettunen@somainline.org>, Marijn Suijten <marijn.suijten@somainline.org>, Sean Paul <sean@poorly.run>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, Stephen Boyd <swboyd@chromium.org>, Bjorn Andersson <andersson@kernel.org>, Jessica Zhang <quic_jesszhan@quicinc.com>, =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= <ville.syrjala@linux.intel.com>, Kuogee Hsieh <quic_khsieh@quicinc.com>, Jani Nikula <jani.nikula@intel.com>, sunliming <sunliming@kylinos.cn>, Sam Ravnborg <sam@ravnborg.org>, Haowen Bai <baihaowen@meizu.com>, Konrad Dybcio <konrad.dybcio@linaro.org>, Loic Poulain <loic.poulain@linaro.org>, Vinod Polimera <quic_vpolimer@quicinc.com>, Douglas Anderson <dianders@chromium.org>, Vladimir Lypak <vladimir.lypak@gmail.com>, linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 6/6] drm/msm/dpu: Disallow unallocated (DSC) resources to be returned Date: Wed, 14 Dec 2022 00:22:07 +0100 Message-Id: <20221213232207.113607-7-marijn.suijten@somainline.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221213232207.113607-1-marijn.suijten@somainline.org> References: <20221213232207.113607-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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752143425828280487?= X-GMAIL-MSGID: =?utf-8?q?1752143425828280487?= |
Series |
drm/msm: DSC Electric Boogaloo for sm8[12]50
|
|
Commit Message
Marijn Suijten
Dec. 13, 2022, 11:22 p.m. UTC
In the event that the topology requests resources that have not been
created by the system (because they are typically not represented in
dpu_mdss_cfg ^1), the resource(s) in global_state (in this case DSC
blocks) remain NULL but will still be returned out of
dpu_rm_get_assigned_resources, where the caller expects to get an array
containing num_blks valid pointers (but instead gets these NULLs).
To prevent this from happening, where null-pointer dereferences
typically result in a hard-to-debug platform lockup, num_blks shouldn't
increase past NULL blocks and will print an error and break instead.
After all, max_blks represents the static size of the maximum number of
blocks whereas the actual amount varies per platform.
In the specific case of DSC initial resource allocation should behave
more like LMs and CTLs where NULL resources are skipped. The current
hardcoded mapping of DSC blocks should be loosened separately as DPU
5.0.0 introduced a crossbar where DSC blocks can be "somewhat" freely
bound to any PP and CTL, but that hardcoding currently means that we
will return an error when the topology reserves a DSC that isn't
available, instead of looking for the next free one.
^1: which can happen after a git rebase ended up moving additions to
_dpu_cfg to a different struct which has the same patch context.
Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org>
---
drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 10 ++++++++++
1 file changed, 10 insertions(+)
Comments
On 14/12/2022 01:22, Marijn Suijten wrote: > In the event that the topology requests resources that have not been > created by the system (because they are typically not represented in > dpu_mdss_cfg ^1), the resource(s) in global_state (in this case DSC > blocks) remain NULL but will still be returned out of > dpu_rm_get_assigned_resources, where the caller expects to get an array > containing num_blks valid pointers (but instead gets these NULLs). > > To prevent this from happening, where null-pointer dereferences > typically result in a hard-to-debug platform lockup, num_blks shouldn't > increase past NULL blocks and will print an error and break instead. > After all, max_blks represents the static size of the maximum number of > blocks whereas the actual amount varies per platform. > > In the specific case of DSC initial resource allocation should behave > more like LMs and CTLs where NULL resources are skipped. The current > hardcoded mapping of DSC blocks should be loosened separately as DPU > 5.0.0 introduced a crossbar where DSC blocks can be "somewhat" freely > bound to any PP and CTL, but that hardcoding currently means that we > will return an error when the topology reserves a DSC that isn't > available, instead of looking for the next free one. > > ^1: which can happen after a git rebase ended up moving additions to > _dpu_cfg to a different struct which has the same patch context. > > Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> > --- > drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c > index 73b3442e7467..dcbf03d2940a 100644 > --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c > +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c > @@ -496,6 +496,11 @@ static int _dpu_rm_reserve_dsc(struct dpu_rm *rm, > > /* check if DSC required are allocated or not */ > for (i = 0; i < num_dsc; i++) { > + if (!rm->dsc_blks[i]) { > + DPU_ERROR("DSC %d does not exist\n", i); > + return -EIO; > + } > + > if (global_state->dsc_to_enc_id[i]) { > DPU_ERROR("DSC %d is already allocated\n", i); > return -EIO; > @@ -660,6 +665,11 @@ int dpu_rm_get_assigned_resources(struct dpu_rm *rm, > blks_size, enc_id); > break; > } > + if (!hw_blks[i]) { > + DPU_ERROR("No more resource %d available to assign to enc %d\n", > + type, enc_id); > + break; > + } > blks[num_blks++] = hw_blks[i]; > } > These two chunks should come as two separate patches, each having it's own Fixes tag.
On 2022-12-14 20:56:30, Dmitry Baryshkov wrote: > On 14/12/2022 01:22, Marijn Suijten wrote: > > In the event that the topology requests resources that have not been > > created by the system (because they are typically not represented in > > dpu_mdss_cfg ^1), the resource(s) in global_state (in this case DSC > > blocks) remain NULL but will still be returned out of > > dpu_rm_get_assigned_resources, where the caller expects to get an array > > containing num_blks valid pointers (but instead gets these NULLs). > > > > To prevent this from happening, where null-pointer dereferences > > typically result in a hard-to-debug platform lockup, num_blks shouldn't > > increase past NULL blocks and will print an error and break instead. > > After all, max_blks represents the static size of the maximum number of > > blocks whereas the actual amount varies per platform. > > > > In the specific case of DSC initial resource allocation should behave > > more like LMs and CTLs where NULL resources are skipped. The current > > hardcoded mapping of DSC blocks should be loosened separately as DPU > > 5.0.0 introduced a crossbar where DSC blocks can be "somewhat" freely > > bound to any PP and CTL, but that hardcoding currently means that we > > will return an error when the topology reserves a DSC that isn't > > available, instead of looking for the next free one. > > > > ^1: which can happen after a git rebase ended up moving additions to > > _dpu_cfg to a different struct which has the same patch context. > > > > Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> > > --- > > drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 10 ++++++++++ > > 1 file changed, 10 insertions(+) > > > > diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c > > index 73b3442e7467..dcbf03d2940a 100644 > > --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c > > +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c > > @@ -496,6 +496,11 @@ static int _dpu_rm_reserve_dsc(struct dpu_rm *rm, > > > > /* check if DSC required are allocated or not */ > > for (i = 0; i < num_dsc; i++) { > > + if (!rm->dsc_blks[i]) { > > + DPU_ERROR("DSC %d does not exist\n", i); > > + return -EIO; > > + } > > + > > if (global_state->dsc_to_enc_id[i]) { > > DPU_ERROR("DSC %d is already allocated\n", i); > > return -EIO; > > @@ -660,6 +665,11 @@ int dpu_rm_get_assigned_resources(struct dpu_rm *rm, > > blks_size, enc_id); > > break; > > } > > + if (!hw_blks[i]) { > > + DPU_ERROR("No more resource %d available to assign to enc %d\n", > > + type, enc_id); > > + break; > > + } > > blks[num_blks++] = hw_blks[i]; > > } > > > > These two chunks should come as two separate patches, each having it's > own Fixes tag. Ack. They are indeed addressing different issues (with the same outcome) with differing "backportability". Will address in v2, thanks for pointing it out (and missing a Fixes: in the first place, of which we already have so many...). - Marijn
diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c index 73b3442e7467..dcbf03d2940a 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c @@ -496,6 +496,11 @@ static int _dpu_rm_reserve_dsc(struct dpu_rm *rm, /* check if DSC required are allocated or not */ for (i = 0; i < num_dsc; i++) { + if (!rm->dsc_blks[i]) { + DPU_ERROR("DSC %d does not exist\n", i); + return -EIO; + } + if (global_state->dsc_to_enc_id[i]) { DPU_ERROR("DSC %d is already allocated\n", i); return -EIO; @@ -660,6 +665,11 @@ int dpu_rm_get_assigned_resources(struct dpu_rm *rm, blks_size, enc_id); break; } + if (!hw_blks[i]) { + DPU_ERROR("No more resource %d available to assign to enc %d\n", + type, enc_id); + break; + } blks[num_blks++] = hw_blks[i]; }