From patchwork Mon Jun 6 11:11:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 579210 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C95A9C43334 for ; Mon, 6 Jun 2022 11:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234906AbiFFLLX (ORCPT ); Mon, 6 Jun 2022 07:11:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234907AbiFFLLV (ORCPT ); Mon, 6 Jun 2022 07:11:21 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82B49243EF1; Mon, 6 Jun 2022 04:11:19 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id x62so18300958ede.10; Mon, 06 Jun 2022 04:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IFBp15JiwiS1Ui+MoaGX6oHH82+d0+woWm07QI8KnOc=; b=LFlMGaJzCDNWX1JxMKWQn7CB9NO/Ikcus6L03o/BKI7iVrjuec52i0Km7VIR9H9Cql 4w6Oa2Y7VcIRTlPn4b2ZXsV4ZPJ2ZWqVOS0dT6bS8Rm/suH1aN7PSZoIK3QEY5Pi5zzQ POjGPm+UbqqU82EzvYiGvrgsL5b2Fs+gVVOso148VLre39of/DKak2+fc+YMVzxcdZef GH4oy0sZ4ECi7SVnwg9/mx9qLtFgjABUcOWEBm2nfjr3eLv4dTj8DjF6ERk9upeZ6itY bClGotVIXwMcLRAEILXEutsh1ne1c8v8rC1jyp28GVJ7+cOjcD3LNRfaP/fzfDDPnzJM NaTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IFBp15JiwiS1Ui+MoaGX6oHH82+d0+woWm07QI8KnOc=; b=jFjZcfDvT1yBa+ihBgs53lI5w/BrbV8RZicsAggfRkIWfaqVKdwBn6f1VdDvkNms4s dJZeAukrLvjxOizhEPRGqvNWizE2a/X1mEgASxMbvQ3tdlc0xmXSPGmOQB0HU3QTJNPh mkLL2I8kB/m5hpz+lu2D7DW8VW1c9jxXL6FSy9w2Za+tWgyriDIpnvkprja6rMR5pNp1 x21vxpoWeQrHkM2PsO6aBZ4WQPTN4Kn/jMjQVfNYLPsiyUjz1bEhkpBs4N6INePKplRB E7hYDnawkMDJ44GSmFShCaKWU7Ebrxdd1c+6NbE6oXXovUKaUZ6MlCQvzW1vGXSUtbI+ iGXQ== X-Gm-Message-State: AOAM531W+eZVmMrw3wl8wLecI2f1y9MXYzq6g+rDmjln1J35RsD+3C+h LThx7nxn3Ne/pa9SN/YJbv8= X-Google-Smtp-Source: ABdhPJxrMqy7/bwV0Me0abZxC+r6atKh3gom/y6hzmDfeiWt355IzqO+QcXitTaYTAdveBrUouYPzw== X-Received: by 2002:a05:6402:c8b:b0:42f:ac38:9c07 with SMTP id cm11-20020a0564020c8b00b0042fac389c07mr16589467edb.292.1654513877366; Mon, 06 Jun 2022 04:11:17 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id z14-20020a170906074e00b006fecf62536asm3843506ejb.188.2022.06.06.04.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 04:11:16 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Saravana Kannan , Sibi Sankar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH 1/5] PM / devfreq: Fix cpufreq passive unregister erroring on PROBE_DEFER Date: Mon, 6 Jun 2022 13:11:00 +0200 Message-Id: <20220606111104.14534-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220606111104.14534-1-ansuelsmth@gmail.com> References: <20220606111104.14534-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org With the passive governor, the cpu based scaling can PROBE_DEFER due to the fact that CPU policy are not ready. The cpufreq passive unregister notifier is called both from the GOV_START errors and for the GOV_STOP and assume the notifier is successfully registred every time. With GOV_START failing it's wrong to loop over each possible CPU since the register path has failed for some CPU policy not ready. Change the logic and unregister the notifer based on the current allocated parent_cpu_data list to correctly handle errors and the governor unregister path. Fixes: a03dacb0316f ("PM / devfreq: Add cpu based scaling support to passive governor") Signed-off-by: Christian 'Ansuel' Marangi --- drivers/devfreq/governor_passive.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c index 72c67979ebe1..09b6c852fccc 100644 --- a/drivers/devfreq/governor_passive.c +++ b/drivers/devfreq/governor_passive.c @@ -223,7 +223,7 @@ static int cpufreq_passive_unregister_notifier(struct devfreq *devfreq) struct devfreq_passive_data *p_data = (struct devfreq_passive_data *)devfreq->data; struct devfreq_cpu_data *parent_cpu_data; - int cpu, ret = 0; + int ret; if (p_data->nb.notifier_call) { ret = cpufreq_unregister_notifier(&p_data->nb, @@ -232,27 +232,16 @@ static int cpufreq_passive_unregister_notifier(struct devfreq *devfreq) return ret; } - for_each_possible_cpu(cpu) { - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); - if (!policy) { - ret = -EINVAL; - continue; - } - - parent_cpu_data = get_parent_cpu_data(p_data, policy); - if (!parent_cpu_data) { - cpufreq_cpu_put(policy); - continue; - } - + list_for_each_entry(parent_cpu_data, &p_data->cpu_data_list, node) { list_del(&parent_cpu_data->node); + if (parent_cpu_data->opp_table) dev_pm_opp_put_opp_table(parent_cpu_data->opp_table); + kfree(parent_cpu_data); - cpufreq_cpu_put(policy); } - return ret; + return 0; } static int cpufreq_passive_register_notifier(struct devfreq *devfreq) From patchwork Mon Jun 6 11:11:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 579724 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47879CCA47E for ; Mon, 6 Jun 2022 11:11:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234919AbiFFLLY (ORCPT ); Mon, 6 Jun 2022 07:11:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234905AbiFFLLX (ORCPT ); Mon, 6 Jun 2022 07:11:23 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E35AF244080; Mon, 6 Jun 2022 04:11:20 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id v1so17546071ejg.13; Mon, 06 Jun 2022 04:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5dkAFM0Ntd+L8H4UaOt5V9mbAusEKvzKxThmfKqM4zs=; b=TEU7MbFsD9GboY+2C1GNl01obmtEJfCtA84n7qy9cN3aY5jN1AdyJzlAvdS7qx88RM ncDnjPRncz0zLsn++zoOHtIcPl+vahRXoH61BElnLKTyr7oe3cqs84wfer+8yXCMLTt9 5JG282VRn+t0olG+N3Lz5d2jIBq69GbEE3bqmWfGIxSRm0gbCwS9n5thC3XQkIkDfWJa wLTiu6isNbM0c7X46eIV5x9NIYsvDfzwm8i7qWMcoossRZkMDSAYJ/vYVZWczCkfXWfn sjz99IdJPKWAWi/fZrExPee5uJCSICC2cA/OEkzgqLmYtLRPvJIfxURoqmeUQWcjPkQg PzuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5dkAFM0Ntd+L8H4UaOt5V9mbAusEKvzKxThmfKqM4zs=; b=abboXrXNqnK0mby7LfTf+pf8JTqSaXh70zldPiHEo5Vgn0pCkxRqHVjo1f57WX33Df GhkvBDtqKrgITpuFoe3rR5N9JIsjJG5ZiRpdEGhxRyGX8PUJfIKcEPzYr6J3OkyATVSw bQ3zQbcHSpx9lirHjmOBvBZ3O1SQglB+x+eq+zzxXIdyBPdHpC3q7R6VsJYRx7+Q2etR Ii1euaNcia8JVMsfpS7LcRfs82yV6m6brQnwg12Iu0Oc850/Nnu0a5sMcppvU+AohAqz OtM9l7iHEkdKqZqiRW8TkjsecS1/22MhzRB/rHGHhVHvJyo6hX02YXMOGkqkZqgmsIWq 2CYQ== X-Gm-Message-State: AOAM532WCOVXBMFxBDRtLEhoYntHoB6vIi4zZfBVGins5wVnevOiSg0H fc/bmOZLx5av1RdMDHkRdYM= X-Google-Smtp-Source: ABdhPJxohOMH19X1rkNAgT3/VwPn0GgVou8p/7lLyJsCir6/1AaIt0yoRMKAB7+YgGERbK6nfcuMfA== X-Received: by 2002:a17:907:6282:b0:6e0:c64a:60a7 with SMTP id nd2-20020a170907628200b006e0c64a60a7mr20791455ejc.349.1654513879169; Mon, 06 Jun 2022 04:11:19 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id z14-20020a170906074e00b006fecf62536asm3843506ejb.188.2022.06.06.04.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 04:11:18 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Saravana Kannan , Sibi Sankar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH 2/5] PM / devfreq: Fix kernel warning with cpufreq passive register fail Date: Mon, 6 Jun 2022 13:11:01 +0200 Message-Id: <20220606111104.14534-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220606111104.14534-1-ansuelsmth@gmail.com> References: <20220606111104.14534-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When the cpufreq passive register path from the passive governor fails, the cpufreq_passive_unregister is called and a kernel WARNING is always reported. This is caused by the fact that the devfreq driver already call the governor unregister with the GOV_STOP, for this reason the second cpufreq_passive_unregister always return error and a WARN is printed from the WARN_ON function. Remove the unregister call from the error handling of the cpufreq register notifier as it's fundamentally wrong and already handled by the devfreq core code. Fixes: a03dacb0316f ("PM / devfreq: Add cpu based scaling support to passive governor") Signed-off-by: Christian 'Ansuel' Marangi --- drivers/devfreq/governor_passive.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c index 09b6c852fccc..ab393c8174f4 100644 --- a/drivers/devfreq/governor_passive.c +++ b/drivers/devfreq/governor_passive.c @@ -325,7 +325,6 @@ static int cpufreq_passive_register_notifier(struct devfreq *devfreq) err_put_policy: cpufreq_cpu_put(policy); err: - WARN_ON(cpufreq_passive_unregister_notifier(devfreq)); return ret; } From patchwork Mon Jun 6 11:11:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 579209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFD69C433EF for ; Mon, 6 Jun 2022 11:11:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234924AbiFFLLY (ORCPT ); Mon, 6 Jun 2022 07:11:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234916AbiFFLLX (ORCPT ); Mon, 6 Jun 2022 07:11:23 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFCC4243B9F; Mon, 6 Jun 2022 04:11:21 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id q1so28234877ejz.9; Mon, 06 Jun 2022 04:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R47nGdJkeSXdG5g2pNh9Q4I5tiJ/be6HekFEcNu4EV4=; b=V/8HhtFY1N2DkViJnGkLXICIzYdplKhkbswJkK/ohG3lTrOEG/OXfHtYmXU8++26+9 QT9wEJ93C4wWo0roJWCCC4ib7Pj3sQz5aAC9xIbYWKfTCUiw0OtcxMGhGnhchk+CmVmd tdSWTE1RBc+oRFnY7SwNHJnUGrC+rLtIwKMMH/PNnuF5ATChvrn64zigxGdHekyqpONz on/QljA9yD+x4iRgFfhRFogGa/GZL7WWfVQsRBgMSowwSWA0ZihbNbFHoy3RZ3k9Eswz scSlFfY93iq60IV7SD/LECIaQWokbNPWbLcGn7HDHdEk7sCyDCTiFcHrkA76PM8JqIom RFmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R47nGdJkeSXdG5g2pNh9Q4I5tiJ/be6HekFEcNu4EV4=; b=FcydvmLOCDqqJ9PlX+FAWNP0ocZFEd+3vU3MfGtPf0oG4XOkj1GgaTMI1Fs2jW0W1j 61jLeK3dvjJJJinYCfu4sJmo7ADCaKXLkJ3k2f8L+nC2zVf3JqxNURe2eKK24GyayluW z6b4J1M31wIHhbQ1KZnA1Bk8bjaMOVUIAp8aw/kj6QVS4ewMVVyw9yhvXjQVvYrasATX 7qE57N4sz2RsBWSWirKoMHXTSpg7m1J7YKishLcWV1F5qWqsE5zWaM70bbGUF6wA5srh BYl8ZL00kecB+Un7dbJnLtu+fSwjm7bBu6DoYWJqAtRVFdzWOJc8w6tU2dqOfcmeMi6g nwzg== X-Gm-Message-State: AOAM532KTtka94is9tIGN6ovyU3N9arggbXs7l+eRqe/+2BtVGpszAeV AacmyvX8DMY+oc7gZCJRfDQ= X-Google-Smtp-Source: ABdhPJyvE0g+UVK1RH5lXnexxiW93ismWefpNl3rm2c6oQXMmJfftHEo1bSll/4IcZWYIQQpMwuGHw== X-Received: by 2002:a17:907:2d90:b0:6fe:cf3c:ac97 with SMTP id gt16-20020a1709072d9000b006fecf3cac97mr20177593ejc.742.1654513880439; Mon, 06 Jun 2022 04:11:20 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id z14-20020a170906074e00b006fecf62536asm3843506ejb.188.2022.06.06.04.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 04:11:20 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Saravana Kannan , Sibi Sankar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH 3/5] PM / devfreq: Fix kernel panic with cpu based scaling to passive gov Date: Mon, 6 Jun 2022 13:11:02 +0200 Message-Id: <20220606111104.14534-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220606111104.14534-1-ansuelsmth@gmail.com> References: <20220606111104.14534-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The cpufreq passive register notifier can PROBE_DEFER and the devfreq struct is freed and then reallocaed on probe retry. The current logic assume that the code can't PROBE_DEFER so the devfreq struct in the this variable in devfreq_passive_data is assumed to be (if already set) always correct. This cause kernel panic as the code try to access the wrong address. To correctly handle this, update the this variable in devfreq_passive_data to the devfreq reallocated struct. Fixes: a03dacb0316f ("PM / devfreq: Add cpu based scaling support to passive governor") Signed-off-by: Christian 'Ansuel' Marangi --- drivers/devfreq/governor_passive.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c index ab393c8174f4..528c8f3b25f0 100644 --- a/drivers/devfreq/governor_passive.c +++ b/drivers/devfreq/governor_passive.c @@ -395,8 +395,7 @@ static int devfreq_passive_event_handler(struct devfreq *devfreq, if (!p_data) return -EINVAL; - if (!p_data->this) - p_data->this = devfreq; + p_data->this = devfreq; switch (event) { case DEVFREQ_GOV_START: From patchwork Mon Jun 6 11:11:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 579723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C852C43334 for ; Mon, 6 Jun 2022 11:11:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234907AbiFFLL2 (ORCPT ); Mon, 6 Jun 2022 07:11:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234923AbiFFLL0 (ORCPT ); Mon, 6 Jun 2022 07:11:26 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12CC92640; Mon, 6 Jun 2022 04:11:23 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id v1so17546315ejg.13; Mon, 06 Jun 2022 04:11:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=08DiEbBYejssZPujjOWcKz4BeXd2GZ/9jLwByrkCNhA=; b=XnCwsEOzGeX5CbNWxzHLPFdXjge3FEfTNwF2Ij5NVJ3XXHrMo80WPebawtt4ZrI5Ly Jsw6yr50UeRn/ZiWc3Ok+o2COyab/PFih2tOHiDjuTTUH4ih4Tlu1EvYAPPn6PuOWtbX Z4E80FYXCQe4L410qSHFnkPlFw+fluuZUjrILUzRnv8ZGr06OXLnVVtQdavhWYw4lU4G DcLXhFinYFHPxP0RyqxIuIMNCs19KabNGfZRvKosPMSB447lhAExdVA2A6KWsBJL94Yq 4nzYPAmcDZT4zQC40JT4IMOY7J8kTmvZGHnXwB1M2rdVsPXwgKgEBcGa8YFYnXujPnYV x6xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=08DiEbBYejssZPujjOWcKz4BeXd2GZ/9jLwByrkCNhA=; b=p3o8C8UWhahKffcLPvGrF2aB95ERtFS1uOA3jZZn3lvcd2Ry/LsfV0GMxb86U2OBLO PbFcKxeV4H+9PPT0qOUhY92TG771bjnSoGD8F62LscPKi0Ck2UOz5FYmnYOE4kuxIobd pLHq29YVEXWI9s/k3rr7dIJCYbD7k9s3Ev8+nsDiNVC4Y2n7H/1f1cTWtgDaLIsPoQ3j 9UbYlE6LupffFUYsGJBxX3JRG13YZOMih8Rs+HijrdCE+Mt+LLeeLlPnzHEkpu7RmaE/ PAj4uRDFK5FIX07rO8vKe7kAfjW1uzu3le/mln7PazUoAOFIjmBftc4gsyvdDtVVnejn 9X+w== X-Gm-Message-State: AOAM532gZUak2ypQQRAVZtbKz5SLNZQfqGQvZAO6/jzRhfVzM5v6C5D0 rUx78tJhaZDzcSfg+IJdnN4= X-Google-Smtp-Source: ABdhPJzDcgyZRRT586Xr/ddAUi8sOHSnsj4jOnw2Fc5UfMV4OmD66jykNXXZ9/bsljYUboRS9xFUiQ== X-Received: by 2002:a17:906:ae92:b0:711:2b64:c829 with SMTP id md18-20020a170906ae9200b007112b64c829mr9268835ejb.89.1654513881939; Mon, 06 Jun 2022 04:11:21 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id z14-20020a170906074e00b006fecf62536asm3843506ejb.188.2022.06.06.04.11.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 04:11:21 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Saravana Kannan , Sibi Sankar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH 4/5] PM / devfreq: Rework freq_table to be local to devfreq struct Date: Mon, 6 Jun 2022 13:11:03 +0200 Message-Id: <20220606111104.14534-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220606111104.14534-1-ansuelsmth@gmail.com> References: <20220606111104.14534-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Currently we reference the freq_table to the profile defined one and we make changes on it. Devfreq never supported PROBE_DEFER before the cpu based scaling support to the passive governor and assumed that a devfreq device could only had error and be done with it. Now that a device can PROBE_DEFER a rework to the freq_table logic is required. If a device PROBE_DEFER on the GOV_START, the freq_table is already set in the device profile struct and its init is skipped. This is due to the fact that it's common for devs to declare this kind of struct static. This cause the devfreq logic to find a freq table declared (freq_table not NULL) with random data and poiting to the old addrs freed by devm. This problem CAN be solved by devs by clearing the freq_table in their profile struct on driver exit path but it should not be trusted and it looks to use a flawed logic. A better solution is to move the freq_table and max_state to the devfreq struct and never change the profile struct. This permit to correctly handle PROBE_DEFER since the devfreq struct is reallocated and contains new values. Also the profile struct should only be used to init the driver and should not be used by the devfreq to write the freq_table if it's not provided by the driver. Fixes: a03dacb0316f ("PM / devfreq: Add cpu based scaling support to passive governor") Signed-off-by: Christian 'Ansuel' Marangi --- drivers/devfreq/devfreq.c | 71 ++++++++++++++---------------- drivers/devfreq/governor_passive.c | 14 +++--- include/linux/devfreq.h | 4 ++ 3 files changed, 45 insertions(+), 44 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 01474daf4548..2e2b3b414d67 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -123,7 +123,7 @@ void devfreq_get_freq_range(struct devfreq *devfreq, unsigned long *min_freq, unsigned long *max_freq) { - unsigned long *freq_table = devfreq->profile->freq_table; + unsigned long *freq_table = devfreq->freq_table; s32 qos_min_freq, qos_max_freq; lockdep_assert_held(&devfreq->lock); @@ -133,11 +133,11 @@ void devfreq_get_freq_range(struct devfreq *devfreq, * The devfreq drivers can initialize this in either ascending or * descending order and devfreq core supports both. */ - if (freq_table[0] < freq_table[devfreq->profile->max_state - 1]) { + if (freq_table[0] < freq_table[devfreq->max_state - 1]) { *min_freq = freq_table[0]; - *max_freq = freq_table[devfreq->profile->max_state - 1]; + *max_freq = freq_table[devfreq->max_state - 1]; } else { - *min_freq = freq_table[devfreq->profile->max_state - 1]; + *min_freq = freq_table[devfreq->max_state - 1]; *max_freq = freq_table[0]; } @@ -169,8 +169,8 @@ static int devfreq_get_freq_level(struct devfreq *devfreq, unsigned long freq) { int lev; - for (lev = 0; lev < devfreq->profile->max_state; lev++) - if (freq == devfreq->profile->freq_table[lev]) + for (lev = 0; lev < devfreq->max_state; lev++) + if (freq == devfreq->freq_table[lev]) return lev; return -EINVAL; @@ -178,7 +178,6 @@ static int devfreq_get_freq_level(struct devfreq *devfreq, unsigned long freq) static int set_freq_table(struct devfreq *devfreq) { - struct devfreq_dev_profile *profile = devfreq->profile; struct dev_pm_opp *opp; unsigned long freq; int i, count; @@ -188,25 +187,22 @@ static int set_freq_table(struct devfreq *devfreq) if (count <= 0) return -EINVAL; - profile->max_state = count; - profile->freq_table = devm_kcalloc(devfreq->dev.parent, - profile->max_state, - sizeof(*profile->freq_table), - GFP_KERNEL); - if (!profile->freq_table) { - profile->max_state = 0; + devfreq->max_state = count; + devfreq->freq_table = devm_kcalloc(devfreq->dev.parent, + devfreq->max_state, + sizeof(*devfreq->freq_table), + GFP_KERNEL); + if (!devfreq->freq_table) return -ENOMEM; - } - for (i = 0, freq = 0; i < profile->max_state; i++, freq++) { + for (i = 0, freq = 0; i < devfreq->max_state; i++, freq++) { opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &freq); if (IS_ERR(opp)) { - devm_kfree(devfreq->dev.parent, profile->freq_table); - profile->max_state = 0; + devm_kfree(devfreq->dev.parent, devfreq->freq_table); return PTR_ERR(opp); } dev_pm_opp_put(opp); - profile->freq_table[i] = freq; + devfreq->freq_table[i] = freq; } return 0; @@ -246,7 +242,7 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) if (lev != prev_lev) { devfreq->stats.trans_table[ - (prev_lev * devfreq->profile->max_state) + lev]++; + (prev_lev * devfreq->max_state) + lev]++; devfreq->stats.total_trans++; } @@ -835,6 +831,9 @@ struct devfreq *devfreq_add_device(struct device *dev, if (err < 0) goto err_dev; mutex_lock(&devfreq->lock); + } else { + devfreq->freq_table = devfreq->profile->freq_table; + devfreq->max_state = devfreq->profile->max_state; } devfreq->scaling_min_freq = find_available_min_freq(devfreq); @@ -870,8 +869,8 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq->stats.trans_table = devm_kzalloc(&devfreq->dev, array3_size(sizeof(unsigned int), - devfreq->profile->max_state, - devfreq->profile->max_state), + devfreq->max_state, + devfreq->max_state), GFP_KERNEL); if (!devfreq->stats.trans_table) { mutex_unlock(&devfreq->lock); @@ -880,7 +879,7 @@ struct devfreq *devfreq_add_device(struct device *dev, } devfreq->stats.time_in_state = devm_kcalloc(&devfreq->dev, - devfreq->profile->max_state, + devfreq->max_state, sizeof(*devfreq->stats.time_in_state), GFP_KERNEL); if (!devfreq->stats.time_in_state) { @@ -1665,9 +1664,9 @@ static ssize_t available_frequencies_show(struct device *d, mutex_lock(&df->lock); - for (i = 0; i < df->profile->max_state; i++) + for (i = 0; i < df->max_state; i++) count += scnprintf(&buf[count], (PAGE_SIZE - count - 2), - "%lu ", df->profile->freq_table[i]); + "%lu ", df->freq_table[i]); mutex_unlock(&df->lock); /* Truncate the trailing space */ @@ -1690,7 +1689,7 @@ static ssize_t trans_stat_show(struct device *dev, if (!df->profile) return -EINVAL; - max_state = df->profile->max_state; + max_state = df->max_state; if (max_state == 0) return sprintf(buf, "Not Supported.\n"); @@ -1707,19 +1706,17 @@ static ssize_t trans_stat_show(struct device *dev, len += sprintf(buf + len, " :"); for (i = 0; i < max_state; i++) len += sprintf(buf + len, "%10lu", - df->profile->freq_table[i]); + df->freq_table[i]); len += sprintf(buf + len, " time(ms)\n"); for (i = 0; i < max_state; i++) { - if (df->profile->freq_table[i] - == df->previous_freq) { + if (df->freq_table[i] == df->previous_freq) len += sprintf(buf + len, "*"); - } else { + else len += sprintf(buf + len, " "); - } - len += sprintf(buf + len, "%10lu:", - df->profile->freq_table[i]); + + len += sprintf(buf + len, "%10lu:", df->freq_table[i]); for (j = 0; j < max_state; j++) len += sprintf(buf + len, "%10u", df->stats.trans_table[(i * max_state) + j]); @@ -1743,7 +1740,7 @@ static ssize_t trans_stat_store(struct device *dev, if (!df->profile) return -EINVAL; - if (df->profile->max_state == 0) + if (df->max_state == 0) return count; err = kstrtoint(buf, 10, &value); @@ -1751,11 +1748,11 @@ static ssize_t trans_stat_store(struct device *dev, return -EINVAL; mutex_lock(&df->lock); - memset(df->stats.time_in_state, 0, (df->profile->max_state * + memset(df->stats.time_in_state, 0, (df->max_state * sizeof(*df->stats.time_in_state))); memset(df->stats.trans_table, 0, array3_size(sizeof(unsigned int), - df->profile->max_state, - df->profile->max_state)); + df->max_state, + df->max_state)); df->stats.total_trans = 0; df->stats.last_update = get_jiffies_64(); mutex_unlock(&df->lock); diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c index 528c8f3b25f0..fe1937f32cc8 100644 --- a/drivers/devfreq/governor_passive.c +++ b/drivers/devfreq/governor_passive.c @@ -131,18 +131,18 @@ static int get_target_freq_with_devfreq(struct devfreq *devfreq, goto out; /* Use interpolation if required opps is not available */ - for (i = 0; i < parent_devfreq->profile->max_state; i++) - if (parent_devfreq->profile->freq_table[i] == *freq) + for (i = 0; i < parent_devfreq->max_state; i++) + if (parent_devfreq->freq_table[i] == *freq) break; - if (i == parent_devfreq->profile->max_state) + if (i == parent_devfreq->max_state) return -EINVAL; - if (i < devfreq->profile->max_state) { - child_freq = devfreq->profile->freq_table[i]; + if (i < devfreq->max_state) { + child_freq = devfreq->freq_table[i]; } else { - count = devfreq->profile->max_state; - child_freq = devfreq->profile->freq_table[count - 1]; + count = devfreq->max_state; + child_freq = devfreq->freq_table[count - 1]; } out: diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index dc10bee75a72..770a7532655c 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -185,6 +185,10 @@ struct devfreq { struct notifier_block nb; struct delayed_work work; + /* devfreq local freq_table */ + unsigned long *freq_table; + unsigned int max_state; + unsigned long previous_freq; struct devfreq_dev_status last_status; From patchwork Mon Jun 6 11:11:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 579208 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1FB5C433EF for ; Mon, 6 Jun 2022 11:11:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234939AbiFFLL3 (ORCPT ); Mon, 6 Jun 2022 07:11:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234928AbiFFLL0 (ORCPT ); Mon, 6 Jun 2022 07:11:26 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94C94244083; Mon, 6 Jun 2022 04:11:24 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id bg6so8401022ejb.0; Mon, 06 Jun 2022 04:11:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wyraSSKv1jqCeF4xZjEyVevZ1Z/RuxxufoUeosKgARw=; b=gN2URvSCIFgOIj8O3vyW2x9dmdcrp82nsm2WX4njUmTu4bFORwLbtjqUQU8x+fck5/ 31gwKtNU1a5H0bfMTIivsnB9OXhzYk5EFXLCBwXkiRXrSbgnKmm4uU0ksGSdorb/uItg cI6YEtfM4yPiT6eTKdgoyGsTLl170sxvzDWLmh6cx0z36k2HbVHYxheHP5TIz+cfmSH9 3GKjqWrI9/E3ugmjKVoi71jaAhSgliWOgm05f6O92ffQdfi7ijFV4vuCRUO5L24DqyTe IhDO3WgvpydxwqnyOTkm97JegQ+YK+I7n6FLrjsitlNvRFwUmsI41cajou11G3b7JHMD qREw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wyraSSKv1jqCeF4xZjEyVevZ1Z/RuxxufoUeosKgARw=; b=HDdipATkH5dKT7IQyrj+IbvkXVCh3N0Srmqyec2TdKVLpdr7SrGLr6hrzX95/NxKeb IXt4xUz8AYJZwGXKRJI9XxNYYtj9+lBWKBYhB6GVEmV03zOJ789v6w5cqDYUnG8hzQCv AdTHu2aOaQL6TGYmKSpjUibgcb3FUMZQwxWDjZUsidar4gBdUd26YcSnSAsMa+bI/SC9 iG3saA2nj13CLxnsJzOWh3feLNGRdpy+uGQz0vvjVYoUjSZZKyKM82UaQdX0cPBxJUOs YwxgiwJEEaApxxkiCPg/FcyH+XQHFQau3MGqsXRtqgo4kHert0jnWMadf+mf50gtIZGA uLjw== X-Gm-Message-State: AOAM5333HNF3ag9k9ZlTgNRKlFNAd58XeROzoo6dBsquUoTFa2Ge9RCD ndUiubPWQgPHTzILV3HdQV8= X-Google-Smtp-Source: ABdhPJz4/Ip6V9rfJ2HWlXYYsLe8Tc814tna4P3sefyGkr2iRltgw/iiLOx10uODvBsYar3ZdSoWUw== X-Received: by 2002:a17:907:7f20:b0:6fe:f0c8:8e6f with SMTP id qf32-20020a1709077f2000b006fef0c88e6fmr20586608ejc.453.1654513882936; Mon, 06 Jun 2022 04:11:22 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id z14-20020a170906074e00b006fecf62536asm3843506ejb.188.2022.06.06.04.11.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 04:11:22 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Saravana Kannan , Sibi Sankar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH 5/5] PM / devfreq: Mute warning on governor PROBE_DEFER Date: Mon, 6 Jun 2022 13:11:04 +0200 Message-Id: <20220606111104.14534-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220606111104.14534-1-ansuelsmth@gmail.com> References: <20220606111104.14534-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Don't print warning when a governor PROBE_DEFER as it's not a real GOV_START fail. Fixes: a03dacb0316f ("PM / devfreq: Add cpu based scaling support to passive governor") Signed-off-by: Christian 'Ansuel' Marangi --- drivers/devfreq/devfreq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 2e2b3b414d67..df6972bb0ce8 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -931,8 +931,8 @@ struct devfreq *devfreq_add_device(struct device *dev, err = devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_START, NULL); if (err) { - dev_err(dev, "%s: Unable to start governor for the device\n", - __func__); + dev_err_probe(dev, -EPROBE_DEFER, "%s: Unable to start governor for the device\n", + __func__); goto err_init; } create_sysfs_files(devfreq, devfreq->governor);