Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp202993rwb; Tue, 13 Dec 2022 16:16:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf75I5fAL9Su0bHyqbF1Ih6GoZtcfcY6Ydej/uCizhu0OkqNnA8mPFx30QL4GQgpdTHS86/v X-Received: by 2002:a17:90a:f104:b0:219:fb5:d54c with SMTP id cc4-20020a17090af10400b002190fb5d54cmr23295199pjb.15.1670976986843; Tue, 13 Dec 2022 16:16:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670976986; cv=none; d=google.com; s=arc-20160816; b=kFJ19mepddluIm8vu4fjs4bme3UwHFLfPTvkLcnRGR9bBn8xSnYwxMdw6E0gePlNwK ZUsENKq/h3OpVS+pQkbaaXX3xkZaU3LmZtAKY/GgJjMch7Ek1AxQ/Xw6LtCFatOCTjdf 0NFbLPrmPVpkt1Jo6w+eVae0oHNcUfFMmX8hdM4mEs+qESsYWQMPNMdCkKYJYbxXjjRx b5p4vLyIREhg7R/hnxrprDFgVLCu5Hp773DOuFML/4ZzMIW2BE7k7uq73eUUZ7ZjLsYP fQZwRqLrR+8XH/3PT4zsEjMxHBJab2A/2YT1a6aMyanNcuTrOAqZJSRezybh9yUJ7bkd QKgg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x20-20020a17090a8a9400b0021425cf457fsi411941pjn.32.2022.12.13.16.16.03; Tue, 13 Dec 2022 16:16:26 -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 + 72 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 ); 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 ; 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 To: phone-devel@vger.kernel.org, Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Vinod Koul Cc: ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno , Konrad Dybcio , Martin Botka , Jami Kettunen , Marijn Suijten , Sean Paul , David Airlie , Daniel Vetter , Stephen Boyd , Bjorn Andersson , Jessica Zhang , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Kuogee Hsieh , Jani Nikula , sunliming , Sam Ravnborg , Haowen Bai , Konrad Dybcio , Loic Poulain , Vinod Polimera , 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: [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: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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]; } -- 2.38.1