Message ID | 20221221231943.1961117-5-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 c7csp33097wrn; Wed, 21 Dec 2022 15:21:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXvikKZWRs0spVLmXSzTcKWC2Cmdq9SBaQfXyGuc+ULIe8c7w12N7GVPV8krSE1UvmV6D5WA X-Received: by 2002:a17:90a:af85:b0:223:f385:bb72 with SMTP id w5-20020a17090aaf8500b00223f385bb72mr3773109pjq.49.1671664884171; Wed, 21 Dec 2022 15:21:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671664884; cv=none; d=google.com; s=arc-20160816; b=YJ2c0FDYYOCtek9PJNANOFCklR8MFFMOy8+zqlWX3HUk8NrP3BEQ3ojsc8kR8BSOQR IH7bxIZMqzJiSdXJ+tYdBxPqzwbZbOApg8Ju8rQruBI6Jnk/NrO18PvVi6A3ju1zatCB 9Cn+0XY62ZtLa12/QXwJ+D8jMQXLhgk+5UFiLW6MWHWqb7We0cHdKIH8yIkoP3pwCxhd gzw7gOfoeukVLdg67q/R2aohI8rZTx3/oQSud49MJ4x8G+OPyZOfkWb+niZyI2CXaoY/ vxO7XbHVHotyaVETxIiSksXkkW0xH3M1KKiEJZpCgh/I2+mgIXvvEgccs75xRkDQzt9x kwqw== 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=0cmCp9RNGU8Fh4k8dTCRzSOlhqWUEp+hXBr/T2dc0rY=; b=jfhwgd1Mdi4RGu7evrT+sceeEnpZ4DMDDMMemuL39gs5h2/sl1kfglGX+R7qYR8sCw dssvWNOIEThBrbf0ELCWjUEWNtRnJSvfscJk9nAbpnWlj4fEZL7gD81BGmDfdovyxymp Dn0PGuoxPiC5ualUuDRS3rOX0zlqYAejFvEHRMhZgMkLfWgCnytn0sMf/4jVJJvp6HlD j4mRlQEcB9vL2yOyvkZPqGabL8z5wfMnwhYQiHE3WN48LAH1gS0VsDR4OQ+6Ad2YyGRT 2bmcnOTmXJ/TvLCWiht76WozZBTr8IqU0aTcGSllqaMLQ+0/cVBYgukFkjDVoOXv0YOx L6Gw== 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 na17-20020a17090b4c1100b001fd8713170csi3209954pjb.179.2022.12.21.15.20.58; Wed, 21 Dec 2022 15:21:24 -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 S235092AbiLUXUS (ORCPT <rfc822;pacteraone@gmail.com> + 99 others); Wed, 21 Dec 2022 18:20:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234949AbiLUXUF (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 21 Dec 2022 18:20:05 -0500 Received: from relay02.th.seeweb.it (relay02.th.seeweb.it [IPv6:2001:4b7a:2000:18::163]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8CD724F15 for <linux-kernel@vger.kernel.org>; Wed, 21 Dec 2022 15:20:03 -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 74115203C9; Thu, 22 Dec 2022 00:20:01 +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, Drew Davenport <ddavenport@chromium.org> Subject: [PATCH v2 4/8] drm/msm/dpu: Disallow unallocated resources to be returned Date: Thu, 22 Dec 2022 00:19:39 +0100 Message-Id: <20221221231943.1961117-5-marijn.suijten@somainline.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221221231943.1961117-1-marijn.suijten@somainline.org> References: <20221221231943.1961117-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?1752867677519345956?= X-GMAIL-MSGID: =?utf-8?q?1752867677519345956?= |
Series |
drm/msm: DSC Electric Boogaloo for sm8[12]50
|
|
Commit Message
Marijn Suijten
Dec. 21, 2022, 11:19 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.
^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.
Fixes: bb00a452d6f7 ("drm/msm/dpu: Refactor resource manager")
Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org>
---
drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 5 +++++
1 file changed, 5 insertions(+)
Comments
On 22/12/2022 01:19, 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. > > ^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. > > Fixes: bb00a452d6f7 ("drm/msm/dpu: Refactor resource manager") > Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> > --- > drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 5 +++++ > 1 file changed, 5 insertions(+) I think the patch is not fully correct. Please check resource availability during allocation. I wouldn't expect an error from get_assigned_resources because of resource exhaustion.
On 09/01/2023 01:28, Dmitry Baryshkov wrote: > On 22/12/2022 01:19, 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. >> >> ^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. >> >> Fixes: bb00a452d6f7 ("drm/msm/dpu: Refactor resource manager") >> Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> >> --- >> drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 5 +++++ >> 1 file changed, 5 insertions(+) > > I think the patch is not fully correct. Please check resource > availability during allocation. I wouldn't expect an error from > get_assigned_resources because of resource exhaustion. > Another option, since allocation functions (except DSC) already have these safety checks: check error message to mention internal inconstency: allocated resource doesn't exist.
On 2023-01-09 01:30:29, Dmitry Baryshkov wrote: > On 09/01/2023 01:28, Dmitry Baryshkov wrote: > > On 22/12/2022 01:19, 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. > >> > >> ^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. > >> > >> Fixes: bb00a452d6f7 ("drm/msm/dpu: Refactor resource manager") > >> Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> > >> --- > >> drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 5 +++++ > >> 1 file changed, 5 insertions(+) > > > > I think the patch is not fully correct. Please check resource > > availability during allocation. I wouldn't expect an error from > > get_assigned_resources because of resource exhaustion. Theoretically patch 5/8 should take care of this, and we should never reach this failure condition. Emphasis on /should/, this may happen again if/when another block type is added with sub-par resource allocation and assignment implementation. > Another option, since allocation functions (except DSC) already have > these safety checks: check error message to mention internal > inconstency: allocated resource doesn't exist. Is this a suggestion for the wording of the error message? - Marijn
On Mon, 9 Jan 2023 at 10:24, Marijn Suijten <marijn.suijten@somainline.org> wrote: > > On 2023-01-09 01:30:29, Dmitry Baryshkov wrote: > > On 09/01/2023 01:28, Dmitry Baryshkov wrote: > > > On 22/12/2022 01:19, 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. > > >> > > >> ^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. > > >> > > >> Fixes: bb00a452d6f7 ("drm/msm/dpu: Refactor resource manager") > > >> Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> > > >> --- > > >> drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 5 +++++ > > >> 1 file changed, 5 insertions(+) > > > > > > I think the patch is not fully correct. Please check resource > > > availability during allocation. I wouldn't expect an error from > > > get_assigned_resources because of resource exhaustion. > > Theoretically patch 5/8 should take care of this, and we should never > reach this failure condition. Emphasis on /should/, this may happen > again if/when another block type is added with sub-par resource > allocation and assignment implementation. Yeah. Maybe swapping 4/8 and 5/8 makes sense. > > > Another option, since allocation functions (except DSC) already have > > these safety checks: check error message to mention internal > > inconstency: allocated resource doesn't exist. > > Is this a suggestion for the wording of the error message? Yes. Because the current message makes one think that it is output during allocation / assignment to encoder, while this is a safety net. > > - Marijn -- With best wishes Dmitry
On 2023-01-09 11:06:45, Dmitry Baryshkov wrote: > On Mon, 9 Jan 2023 at 10:24, Marijn Suijten > <marijn.suijten@somainline.org> wrote: > > > > On 2023-01-09 01:30:29, Dmitry Baryshkov wrote: > > > On 09/01/2023 01:28, Dmitry Baryshkov wrote: > > > > On 22/12/2022 01:19, 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. > > > >> > > > >> ^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. > > > >> > > > >> Fixes: bb00a452d6f7 ("drm/msm/dpu: Refactor resource manager") > > > >> Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> > > > >> --- > > > >> drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 5 +++++ > > > >> 1 file changed, 5 insertions(+) > > > > > > > > I think the patch is not fully correct. Please check resource > > > > availability during allocation. I wouldn't expect an error from > > > > get_assigned_resources because of resource exhaustion. > > > > Theoretically patch 5/8 should take care of this, and we should never > > reach this failure condition. Emphasis on /should/, this may happen > > again if/when another block type is added with sub-par resource > > allocation and assignment implementation. > > Yeah. Maybe swapping 4/8 and 5/8 makes sense. Ack. > > > Another option, since allocation functions (except DSC) already have > > > these safety checks: check error message to mention internal > > > inconstency: allocated resource doesn't exist. > > > > Is this a suggestion for the wording of the error message? > > Yes. Because the current message makes one think that it is output > during allocation / assignment to encoder, while this is a safety net. Good. So the patch is correct, just the wording is off, which I fully agree on. This isn't allocating anything, just handing out what was previously allocated (and is a safety net). - Marijn
On 09/01/2023 19:12, Marijn Suijten wrote: > On 2023-01-09 11:06:45, Dmitry Baryshkov wrote: >> On Mon, 9 Jan 2023 at 10:24, Marijn Suijten >> <marijn.suijten@somainline.org> wrote: >>> >>> On 2023-01-09 01:30:29, Dmitry Baryshkov wrote: >>>> On 09/01/2023 01:28, Dmitry Baryshkov wrote: >>>>> On 22/12/2022 01:19, 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. >>>>>> >>>>>> ^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. >>>>>> >>>>>> Fixes: bb00a452d6f7 ("drm/msm/dpu: Refactor resource manager") >>>>>> Signed-off-by: Marijn Suijten <marijn.suijten@somainline.org> >>>>>> --- >>>>>> drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 5 +++++ >>>>>> 1 file changed, 5 insertions(+) >>>>> >>>>> I think the patch is not fully correct. Please check resource >>>>> availability during allocation. I wouldn't expect an error from >>>>> get_assigned_resources because of resource exhaustion. >>> >>> Theoretically patch 5/8 should take care of this, and we should never >>> reach this failure condition. Emphasis on /should/, this may happen >>> again if/when another block type is added with sub-par resource >>> allocation and assignment implementation. >> >> Yeah. Maybe swapping 4/8 and 5/8 makes sense. > > Ack. > >>>> Another option, since allocation functions (except DSC) already have >>>> these safety checks: check error message to mention internal >>>> inconstency: allocated resource doesn't exist. >>> >>> Is this a suggestion for the wording of the error message? >> >> Yes. Because the current message makes one think that it is output >> during allocation / assignment to encoder, while this is a safety net. > > Good. So the patch is correct, just the wording is off, which I fully > agree on. This isn't allocating anything, just handing out what was > previously allocated (and is a safety net). Yes. Please excuse me if my original message was not 100% clear. > > - 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..8471d04bff50 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c @@ -660,6 +660,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]; }