From patchwork Mon Jun 13 13:42:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 581889 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 BEABEC43334 for ; Mon, 13 Jun 2022 18:05:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233192AbiFMSC7 (ORCPT ); Mon, 13 Jun 2022 14:02:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240342AbiFMSCX (ORCPT ); Mon, 13 Jun 2022 14:02:23 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82143CF2; Mon, 13 Jun 2022 06:45:13 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id a15so7218762wrh.2; Mon, 13 Jun 2022 06:45:13 -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=2TiwGsa9nhGWe7+rjdwUgqJf1443Z5iWoonROnv/enI=; b=mEL3wQ8T2LeY5SU36naJDyiASdHtl4q0VUV82LiKzKEaMXr9uNpCPzSC/fzlemCX3c 1BhPAQnyxeymprUMBKsoN7gRdOYKZFJ6VjNLujxM53rCFeMjyxz1uBm9Opqn4DOFBZn6 fhzSbIUtooKP/U4vKPywT3sjiTCu1XPID8weEOXY5aWUr/7kZTTQ05eTIXm/vr50j6Bs gKShYU7L+VMlBzlI4DcyhwdrhuoQp3EH7sl5C+6M7g1PA3IySMC+E5LMCdtoyQfnllR2 9dHYKRXU2OJKrx77GJAGZuqIxZ9MvBfN6RurXx0wCNrt+4iY6Hp/X4CY0WENWoYw8ezx B5tw== 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=2TiwGsa9nhGWe7+rjdwUgqJf1443Z5iWoonROnv/enI=; b=KVJMxatHVXN7RdCBHGGJILAh7pSa8QxsmFxZE47NQUsdoMtd1GqE2VmPTdgKeSe0ED 1xaxc8tlYZlrMuVslGNy3eMPxhMjCjld+QL1JAs51T9mjGp5E9IGH2OCmmcM2+Qnbc0Q GoSccGKYqypl5I5cssbSbg3AlTeL9BInSP0va30nowxUzQmOhjJetNO2rs7Sa9EbX0WS qNj7XZtvv7OWAu8qg6H8rILJKEV21heiYOoULs6KStGxJH5yvlF9bd/DZHjqQPouzXiD pgpAboH0RfNvC31B+NgTdmQx7CnMqgKlronOwfcTrVfiM1e2oRNUUeBjSkZfpjVgKbiJ 2rzQ== X-Gm-Message-State: AOAM531r+EmPi7z3LsMG5DfKYRwozSBcXvTgFjNQmQ4fXvI0zXr6XCsX RXbkRi0vXKXC5rRXEdXjxBk= X-Google-Smtp-Source: ABdhPJy7LALH5l6Qt0uy4Ii18rMrF1XbBDKA5/jx7q4sxmDC1uHryoMXSm6dQnFK3gUJymmE1qUlSw== X-Received: by 2002:adf:d084:0:b0:213:b515:6a06 with SMTP id y4-20020adfd084000000b00213b5156a06mr55211863wrh.702.1655127911783; Mon, 13 Jun 2022 06:45:11 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id i1-20020a5d5221000000b002103aebe8absm8647510wra.93.2022.06.13.06.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 06:45:11 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Sibi Sankar , Saravana Kannan , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH v2 1/5] PM / devfreq: Fix cpufreq passive unregister erroring on PROBE_DEFER Date: Mon, 13 Jun 2022 15:42:09 +0200 Message-Id: <20220613134213.8904-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613134213.8904-1-ansuelsmth@gmail.com> References: <20220613134213.8904-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..6252f109f8d1 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_safe(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 13 13:42:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 581887 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 2AB50CCA483 for ; Mon, 13 Jun 2022 18:05:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243039AbiFMSDI (ORCPT ); Mon, 13 Jun 2022 14:03:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242039AbiFMSCY (ORCPT ); Mon, 13 Jun 2022 14:02:24 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52449D43; Mon, 13 Jun 2022 06:45:14 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id a15so7218824wrh.2; Mon, 13 Jun 2022 06:45:14 -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=Eyb0gzzBMaZAiHZGYYnJBj5umG33L2ZCgocNe/btits=; b=POBeCUtP2bRjkE8xG8FepF04OX9JLidQUypChR17MOEDStRDopytquh3SHns8KSgZt 66N29qRsjzwrb8DLhGpCcqoGgxA10SMXOLA3cVpe41qGm+mRkEETZ8YpHr83QtRfe+I3 /8W4NynY9JWXkbQsA4Ag2v/UcgTSt/iSRpoju81g29x8uxiQQvt9N4tKt73HWhC6oKYN GgvbuUKBYSNo2SAjOUSCyP2Jm9/7KvtZe4SoOAeS0OADqhtfplAEvF8H/bJU9nFChTh8 Q0KOK4G+iCNqOvct/Y18ttSII1J0HVgjOTwmfWH5JLvf3TmBKxG6jZbls+Z411DtHIs5 Fa+g== 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=Eyb0gzzBMaZAiHZGYYnJBj5umG33L2ZCgocNe/btits=; b=XuuKW3zPtNzSRs+Sbge2Vxns2XuRhpPksn8KgJCF4OxVffdWsEJDAyOVuZVt1sk0Mj EzrALy5fx0VZdqC6XRQV/H3kViweznzLG7FlLhzEchdCo53X86Zh3dTtHnhzCHbWIvaE CfeeruKiD/MjA7LONWFWFMunr90H4s4ZbXGsq7Dv1FMD/8d1Yq9PULPWpuwto53bnin0 PiH8bHte4n69+SgZ28dy27GSXBuVl4a2RgKPmmITF/Yl+kwwj8cOlvQVEaJUKlfjS5Nx 18CgbMNP39wEX0I4TkDRxE4w99MadPoY9UdLeOE3148LGLg63ws1AFSjTn7mM5zMCavd qQEQ== X-Gm-Message-State: AOAM531LP94icO9rTGVLJW1tzWBOeh9Wc5VHK9e+CZ1oMoRY1OnVtryJ eQzmVPMZVC1ia9EyycBmGb8= X-Google-Smtp-Source: ABdhPJz2pbmpIApaOG7ch0omubRyWUhWs8eyCgKuj08tEh4cWJp66mZgAsiwdGQ8m6S31d5lgoaKGA== X-Received: by 2002:adf:ffc7:0:b0:210:2bba:f431 with SMTP id x7-20020adfffc7000000b002102bbaf431mr58377219wrs.495.1655127912771; Mon, 13 Jun 2022 06:45:12 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id i1-20020a5d5221000000b002103aebe8absm8647510wra.93.2022.06.13.06.45.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 06:45:12 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Sibi Sankar , Saravana Kannan , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH v2 2/5] PM / devfreq: Fix kernel warning with cpufreq passive register fail Date: Mon, 13 Jun 2022 15:42:10 +0200 Message-Id: <20220613134213.8904-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613134213.8904-1-ansuelsmth@gmail.com> References: <20220613134213.8904-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 6252f109f8d1..b1d3a1e7e3f4 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 13 13:42:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 581564 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 D0DCFCCA47B for ; Mon, 13 Jun 2022 18:05:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242420AbiFMSDG (ORCPT ); Mon, 13 Jun 2022 14:03:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244033AbiFMSCZ (ORCPT ); Mon, 13 Jun 2022 14:02:25 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54E02D45; Mon, 13 Jun 2022 06:45:15 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id a15so7218889wrh.2; Mon, 13 Jun 2022 06:45:15 -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=1QoX2JQbzTzugkblZY0snlzVou25XBMyzOT7SKDqoAA=; b=Clp/O2p1aA1nDN8gmHP/R3hfmo89E0ncB1dnJ219MtJgsBw1h9f322TWPjv2PVPXY/ bcuIEqS98Qg0CVAyeiaq0nhwqFNDQ6fQWgqc5Hl44ARIzBCh1pa3t8e8d49ldIe8q/uD WKicSiC0edjaJwasmmX23rDqyNWxbbI/ZYl1g4Sz17nFLoPNK+rjTZhcESJgibJVHhC9 9MPIvyP9zt72nPBnjc7Is4B0bkRitYNg7yxE/LJevn6njuF3Om4p/HuQXBepy7aVS4Bo V7CUy4RmFPbNwXGMC34Clk5+DhYyLd05FJOPFLekS5oWjT40iC+tHA6eBajTp5ODZvV4 /rRA== 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=1QoX2JQbzTzugkblZY0snlzVou25XBMyzOT7SKDqoAA=; b=AV1edM0YLagDiY3FgmNgINJHN/go7/cAusrCurfLQlue7b2izaMxZvmigkLUUEEqVP W+VN6M/NLM0Q/UWDUQg3cXHIZ4yz0Xy+BEcFQ8CSE57hd8ZGsO6VThlkfyO0ZvxYAyrt YEQEx1JKcICAKQkUor1pC7TzLG0H3kqv7BZS6kug5+jevibm61tnlJ3dAo9YBdWTKqIN xukA+ADcFicD8eIjQiNOv3AlWHQCUIcxJPJavzGT72VDuv6yOFpRuFowXOV9X99YlVi0 NT2lpi7WC7CXY713RHgQNJybnTHo1vyK6KutPMptZJzw+A0MCu5BytYTE3YzGMzMWDPL I4UQ== X-Gm-Message-State: AOAM533Ossi5GXyWZbKZdlxCWibakAUoYooquj84cFfUgQjEBUWdrNWC Im9aYliz+/qLUfuHIbRfD4U= X-Google-Smtp-Source: ABdhPJyilTmFwSNB9Dn6TA5YXf7cMgAkdbRaWjcfOaCNkCnh+TKlFLJg2xI3JkMsR0O0v69lYmQryw== X-Received: by 2002:a05:6000:1f12:b0:216:642e:e2f2 with SMTP id bv18-20020a0560001f1200b00216642ee2f2mr45976872wrb.414.1655127913692; Mon, 13 Jun 2022 06:45:13 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id i1-20020a5d5221000000b002103aebe8absm8647510wra.93.2022.06.13.06.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 06:45:13 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Sibi Sankar , Saravana Kannan , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH v2 3/5] PM / devfreq: Fix kernel panic with cpu based scaling to passive gov Date: Mon, 13 Jun 2022 15:42:11 +0200 Message-Id: <20220613134213.8904-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613134213.8904-1-ansuelsmth@gmail.com> References: <20220613134213.8904-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 b1d3a1e7e3f4..f7f223555c4b 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 13 13:42:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 581563 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 E782FCCA480 for ; Mon, 13 Jun 2022 18:05:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232797AbiFMSDE (ORCPT ); Mon, 13 Jun 2022 14:03:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244048AbiFMSCZ (ORCPT ); Mon, 13 Jun 2022 14:02:25 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FCF7D86; Mon, 13 Jun 2022 06:45:16 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id h19so3979704wrc.12; Mon, 13 Jun 2022 06:45:16 -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=7J1RZ6X9kazquigx9MwMeTUi4mfuY9AlAZNKixNA8f4=; b=FpyuNE2iPOb/Ymq2Sm99g0D0zqrxeeyPElRCg+jgOhmafBLtZgyNdYx3E5CY4RTWY2 A2kpmVsGw6MAqNmIltO9KXk+glye5tbdEatCfQ7CDHJCkD9knWVhVat9dGFhRz89Qq/7 7r5vRz9LOGhl/PynZUNcdh3iXD+8IWBO4YO2/6r1heD3Si6MmyMD56Q0v4ZQzWMybviH RUHN4KnpoJR4werBvDUi73+4bBBd1v1ETmTVJhIyltkF+D3hfn7U80nrsdhfyrlHXXTj /u8OgPpD/Zzkp1iQuKGuUjrNPeO3/0AuRPV/Ufp/8Ocff3ST8nVGFX1HdCTUWHr3jpA2 QzLA== 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=7J1RZ6X9kazquigx9MwMeTUi4mfuY9AlAZNKixNA8f4=; b=mJW3ZfWjoSuZxQ0F/rrO71QlKgO6/6FG6XtEdQnAyzFHpbCGwOZEA7kLud5CHjSKM1 NZHsd95EPd412gFyJ/6Vd9Gu5pXFC+bmyxpb/2O/S2v9jo/aHagMZ06JYe1Usjx9wRtk i2q4qIXC4IAwQjMMSvC7/NJ5RKg1naGkLHmU+VdbH7jC9ib4JQ5x3h2IqFh8xaKK3wgl XuJOsYuKTWNpUpdiR+3fWBkhHmB+A/ARyixG9qICTDW0RZ4RkPmmWv/lkI1dg0B2H6Wc dA+BKYrkG0Hy6dpqsM8APxUY1HY60ptqFXSiwMVnDiwCS5byIjnAJeVZxBABTgJEnxFD /VFA== X-Gm-Message-State: AOAM531xbBk81vye5YUnnGkT+WhCfhQ9Z3BYLIc76naWnbP9vwCKVVyS V4kBR5cxQfl60yCVCpZ75FEzrY694H8= X-Google-Smtp-Source: ABdhPJzy32/rNaYJmIn7BxzWo3YOus0hUCp/ww/KOcl+4VPoxYNpCJ20KmLfkipw6M6uSi00ev9LCg== X-Received: by 2002:a05:6000:228:b0:210:3433:64d1 with SMTP id l8-20020a056000022800b00210343364d1mr56841624wrz.103.1655127914697; Mon, 13 Jun 2022 06:45:14 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id i1-20020a5d5221000000b002103aebe8absm8647510wra.93.2022.06.13.06.45.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 06:45:14 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Sibi Sankar , Saravana Kannan , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH v2 4/5] PM / devfreq: Rework freq_table to be local to devfreq struct Date: Mon, 13 Jun 2022 15:42:12 +0200 Message-Id: <20220613134213.8904-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613134213.8904-1-ansuelsmth@gmail.com> References: <20220613134213.8904-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 f7f223555c4b..bfa79b460dcd 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 13 13:42:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 581562 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 3F94DCCA482 for ; Mon, 13 Jun 2022 18:05:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243233AbiFMSDI (ORCPT ); Mon, 13 Jun 2022 14:03:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244051AbiFMSCZ (ORCPT ); Mon, 13 Jun 2022 14:02:25 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C9C2D89; Mon, 13 Jun 2022 06:45:17 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id z9so2995744wmf.3; Mon, 13 Jun 2022 06:45:17 -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=J87NyDPNSiU1rQKYzpcOjhK4eIXKQc6HaI8Zo+0rj+kofa3hwUYB15zd0OVwwl0zLI NKXBDCSmRlGZ8V2x2/6co0IlmdEA+FaDXzwMTT5Od52UJd/NBeafBVra/pGTwjy5LStU mw1wiQhrTfSnrEHCrALkAL72ws9o3SLhX4mt5aX/eR/pnNGm38oQ31x8+FhkFy0n4VBl VOAyOixqd8lbFTI0BDgZ+tSltUMYf09AABWK47q5LKYa2FuVhYplKEazj3Q4Kclai727 XIFdig5c2iRtn7PgyUIbsZNFi6Rkop/4ZFMpeJylc6X8hQzmzUbeRPaDiBR/hHe2lf3h TAHA== 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=w0OlXg0pZyTFko1ZdN4M/r+iKbv+Cqltrykwff30YTl1UavXFUeKUGkbLmSB9nDyV2 sjMGpeJnTBziUnRcY/cNENwIUk2XjP+uV7yqpHkzXmQ8WtxfqOMrHiq5mmKiSrhjLoIg Y8UNo9NDeSgtKG8w0i7QsCBj+wyadw/wOJh16tOvRInxsRsxzXY9XWuwgH9IfthGuEUy Mh7CAg8Eiq9NX4ds6ZRoK7sVy2THWncLKm9s5FjvoMBe19HQkoNbiAlqSTE/VecfnOMj kh9xYmRXM0Oq9xNjlwIRtgotQ32Bg5MOegZQ7PbREqcczWnyFzKVgc2A7fSPwT95PjTj ddpA== X-Gm-Message-State: AOAM533x0KMm5VLB5N/kICoPApdxC4xedSsCGTQ/ykTAQpSkGu2pQcKT u7c6tLSbtCr/si3t/37lZjc= X-Google-Smtp-Source: ABdhPJx7Jm4v2NF4tcGT0yyIRXFuX+doT8y0QitWBmRUlV/6XJPlqijbB2tYMkQHcKA9eg2MQxBaGw== X-Received: by 2002:a05:600c:35d2:b0:39c:8490:abbf with SMTP id r18-20020a05600c35d200b0039c8490abbfmr13106105wmq.86.1655127915690; Mon, 13 Jun 2022 06:45:15 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id i1-20020a5d5221000000b002103aebe8absm8647510wra.93.2022.06.13.06.45.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 06:45:15 -0700 (PDT) From: Christian 'Ansuel' Marangi To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Sibi Sankar , Saravana Kannan , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian 'Ansuel' Marangi Subject: [PATCH v2 5/5] PM / devfreq: Mute warning on governor PROBE_DEFER Date: Mon, 13 Jun 2022 15:42:13 +0200 Message-Id: <20220613134213.8904-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613134213.8904-1-ansuelsmth@gmail.com> References: <20220613134213.8904-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);