Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp571747pxm; Wed, 2 Mar 2022 23:27:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMes+lxjYMrAvSzNjYmHcNfcltdNjxUlWxFpG7MU6TH58LEMVhHahsscYX5Gv3PKqNU4/F X-Received: by 2002:a17:906:af79:b0:6ce:61d3:7e9b with SMTP id os25-20020a170906af7900b006ce61d37e9bmr26204725ejb.191.1646292462727; Wed, 02 Mar 2022 23:27:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646292462; cv=none; d=google.com; s=arc-20160816; b=TeGjxLsyo64iMM16OaRSxTwb8+ELJexFxMGdBRUZNOGES0/r6m/40tuqD4wcsQtkmk trQ8lSl6xBCzdJrxA55VHvtVMkvnh+mq9cYGopOdbv2E6+8U/1xJ6NJSHjycJVASuEc6 ejYP/ukUUq6NgcP9yXIFEhsHkpGQF3i9UO2NWEdZzs/HHjhKgaiCL68dIBEyC9uWX+jQ FMs6WNfdoI10ih5YTwrWMaNuIXJotYC+wTg491s3dDuX62v6Kmj6sUcZO1+dVE30V6lu UOj6NyDoAlQfw/esxDLLLOU1yeDxHiD/bZXiNFwXFzyYNOGGwjau/5yqJPSDoW35kuF7 NJhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8HcPSO5J8NY98uQ2bWJs7uIQP8jHLYwpTbsEfnFQ6Kc=; b=Gcsdv/H5fcuF7OZlOqEM2LoQb71RmT1zh/D5QGZOKskwqSIOS2DZsnUA4RKGFVMF5k CQ2n39DljlcCtK7V36jPtB/owhb2rm/THa1mx/oJ2/UsQRigIburgolVFC1qOVufhyKh Fa/pdshVzktGGCFInZlYUeb0nt6hTqQ7WqkUqwcwMCJCU3P11f9cnNp+CM/s6sUvnea6 hmq1LZS5AbeIqqBC5/I8jtGvksIa+rm/exeBfGMhEbFod00l0Px0wFQ1fxLDQtdcD+VG 0S1OTtBaJuvr4Q1DmJKVmZe32LUdNIYdkwi1Oq2IKVxVPATjryVhFFEnoGO/KD+J2eHN Zx0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gTke+FKo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w3-20020a50d983000000b003fed229a560si787614edj.97.2022.03.02.23.27.20; Wed, 02 Mar 2022 23:27:42 -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; dkim=pass header.i=@linaro.org header.s=google header.b=gTke+FKo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230094AbiCCHHX (ORCPT + 99 others); Thu, 3 Mar 2022 02:07:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbiCCHHW (ORCPT ); Thu, 3 Mar 2022 02:07:22 -0500 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86077D1083 for ; Wed, 2 Mar 2022 23:06:37 -0800 (PST) Received: by mail-qv1-xf2c.google.com with SMTP id jr3so3426587qvb.11 for ; Wed, 02 Mar 2022 23:06:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8HcPSO5J8NY98uQ2bWJs7uIQP8jHLYwpTbsEfnFQ6Kc=; b=gTke+FKomJbgtcblPcwsyJWe1O1L6dpL9xC4RB6BmIQnJe61/Dn8IPPfiaiEFr3pzf cwte0nVrO20l0utome+glbq+FWdU8ecw/C9Y7YDd4Wkdq9iKIGbFinT2OC/yS8LFpBu9 7L/5SFrcap2IzLDmsBnp4TI+7PXWQM34ZWKhdG/ZPSdSyJLh/cGYduiAwJG8qtjSIPyk Ur3JoeO5XqWfcJbtg6nqKuuahdnRmHZZPuPcPeQl/MYyuK66DakMDDQMVcvmxbPUOpL8 ToNc5/wke8v8P7RhoZym3z027YVlaIZIb+Rf3qNOZPX2zKW66lgI8mxh+SI1XK4NXyqZ 0qWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8HcPSO5J8NY98uQ2bWJs7uIQP8jHLYwpTbsEfnFQ6Kc=; b=V0xMEz04F9be/kfovPCkq2fFIkYrLg86nQ35udtaCRuBCl8fPZnfljQGQDoPYZGVqO VadaUbaPrvKTSBU1bHZ3iGs405K9HDGSO7mEBgULYKNqy7jruGZ9SVkPpUVzsBdT9SSd 91Z2THWCOYDUpkX3YqzCKSR1tssjFxy1E0shjTq0JChaE35i7Uq1JYk20vUEjaHJ3yQv UqV0eXGpqsNtcrM7Iv08cHZvznivswwHVCqWf/Dw6cGZsnHdSrCQGYf0g0Z+jsNbffqJ /8iZij7vYYEOouLSuYpZcfvtL/2czwvilCF4sZVq2WLzJr3aSRggEDdfIsJmdZl4qJhV ILRA== X-Gm-Message-State: AOAM530bn7HZVv5MYKTErGy23gqRu/Oi9b1mJ+QG18pL/x6zzwcCICkC vFqRSuyhtvjaRqaZnl84s8i3Q7N68c06NsqzJYHgpQ== X-Received: by 2002:ad4:5883:0:b0:432:b007:962b with SMTP id dz3-20020ad45883000000b00432b007962bmr22084284qvb.55.1646291196714; Wed, 02 Mar 2022 23:06:36 -0800 (PST) MIME-Version: 1.0 References: <20220219183310.557435-1-robdclark@gmail.com> <6f1225ea-d889-9cf8-3a3d-181e319bd453@linaro.org> In-Reply-To: From: Dmitry Baryshkov Date: Thu, 3 Mar 2022 10:06:25 +0300 Message-ID: Subject: Re: [PATCH] drm/msm/gpu: Fix crash on devices without devfreq support To: Rob Clark Cc: dri-devel , freedreno , linux-arm-msm , Rob Clark , Linux Kernel Functional Testing , Anders Roxell , Sean Paul , Abhinav Kumar , David Airlie , Daniel Vetter , open list Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Wed, 23 Feb 2022 at 18:46, Rob Clark wrote: > > On Tue, Feb 22, 2022 at 7:11 PM Dmitry Baryshkov > wrote: > > > > On 19/02/2022 21:33, Rob Clark wrote: > > > From: Rob Clark > > > > > > Avoid going down devfreq paths on devices where devfreq is not > > > initialized. > > > > > > Reported-by: Linux Kernel Functional Testing > > > Reported-by: Anders Roxell > > > Signed-off-by: Rob Clark > > > --- > > > drivers/gpu/drm/msm/msm_gpu_devfreq.c | 31 +++++++++++++++++++++------ > > > 1 file changed, 25 insertions(+), 6 deletions(-) > > > > > > diff --git a/drivers/gpu/drm/msm/msm_gpu_devfreq.c b/drivers/gpu/drm/msm/msm_gpu_devfreq.c > > > index 9bf319be11f6..26a3669a97b3 100644 > > > --- a/drivers/gpu/drm/msm/msm_gpu_devfreq.c > > > +++ b/drivers/gpu/drm/msm/msm_gpu_devfreq.c > > > @@ -83,12 +83,17 @@ static struct devfreq_dev_profile msm_devfreq_profile = { > > > static void msm_devfreq_boost_work(struct kthread_work *work); > > > static void msm_devfreq_idle_work(struct kthread_work *work); > > > > > > +static bool has_devfreq(struct msm_gpu *gpu) > > > +{ > > > + return !!gpu->funcs->gpu_busy; > > > > I see that devfreq init will be skipped if gpu_busy is NULL. > > Can we use gpu->devfreq instead of this condition? > > We could, but then we couldn't also use the same has_devfreq() helper > in msm_devfreq_init(). I thought it was clearer to use the same > helper everywhere. Well... It is not clear at first glance how gpu_busy is related to devfreq. On the other hand, if gpu->devfreq is NULL, it's obvious that devfreq is not initialized. I'd propose to use if (gpu->funcs->gpu_busy) to check if we can init devfreq and after that to check (gpu->devfreq) as a way to know whether the devfreq is available. > > > I noticed that you have replaced some of gpu->devfreq checks with > > has_devreq() calls. Is there any difference? > > It amounts to the same thing because if you don't have gpu_busy, then > devfreq is never initialized. I just thought it clearer to use the > same check in all places. See my comment above. > > BR, > -R > > > > +} > > > + > > > void msm_devfreq_init(struct msm_gpu *gpu) > > > { > > > struct msm_gpu_devfreq *df = &gpu->devfreq; > > > > > > /* We need target support to do devfreq */ > > > - if (!gpu->funcs->gpu_busy) > > > + if (!has_devfreq(gpu)) > > > return; > > > > > > dev_pm_qos_add_request(&gpu->pdev->dev, &df->idle_freq, > > > @@ -149,6 +154,9 @@ void msm_devfreq_cleanup(struct msm_gpu *gpu) > > > { > > > struct msm_gpu_devfreq *df = &gpu->devfreq; > > > > > > + if (!has_devfreq(gpu)) > > > + return; > > > + > > > devfreq_cooling_unregister(gpu->cooling); > > > dev_pm_qos_remove_request(&df->boost_freq); > > > dev_pm_qos_remove_request(&df->idle_freq); > > > @@ -156,16 +164,24 @@ void msm_devfreq_cleanup(struct msm_gpu *gpu) > > > > > > void msm_devfreq_resume(struct msm_gpu *gpu) > > > { > > > - gpu->devfreq.busy_cycles = 0; > > > - gpu->devfreq.time = ktime_get(); > > > + struct msm_gpu_devfreq *df = &gpu->devfreq; > > > > > > - devfreq_resume_device(gpu->devfreq.devfreq); > > > + if (!has_devfreq(gpu)) > > > + return; > > > + > > > + df->busy_cycles = 0; > > > + df->time = ktime_get(); > > > + > > > + devfreq_resume_device(df->devfreq); > > > } > > > > > > void msm_devfreq_suspend(struct msm_gpu *gpu) > > > { > > > struct msm_gpu_devfreq *df = &gpu->devfreq; > > > > > > + if (!has_devfreq(gpu)) > > > + return; > > > + > > > devfreq_suspend_device(df->devfreq); > > > > > > cancel_idle_work(df); > > > @@ -185,6 +201,9 @@ void msm_devfreq_boost(struct msm_gpu *gpu, unsigned factor) > > > struct msm_gpu_devfreq *df = &gpu->devfreq; > > > uint64_t freq; > > > > > > + if (!has_devfreq(gpu)) > > > + return; > > > + > > > freq = get_freq(gpu); > > > freq *= factor; > > > > > > @@ -207,7 +226,7 @@ void msm_devfreq_active(struct msm_gpu *gpu) > > > struct devfreq_dev_status status; > > > unsigned int idle_time; > > > > > > - if (!df->devfreq) > > > + if (!has_devfreq(gpu)) > > > return; > > > > > > /* > > > @@ -253,7 +272,7 @@ void msm_devfreq_idle(struct msm_gpu *gpu) > > > { > > > struct msm_gpu_devfreq *df = &gpu->devfreq; > > > > > > - if (!df->devfreq) > > > + if (!has_devfreq(gpu)) > > > return; > > > > > > msm_hrtimer_queue_work(&df->idle_work, ms_to_ktime(1), > > > > > > -- > > With best wishes > > Dmitry -- With best wishes Dmitry