From patchwork Tue Jun 14 11:06:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 581877 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 4C224C43334 for ; Tue, 14 Jun 2022 11:07:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355812AbiFNLH0 (ORCPT ); Tue, 14 Jun 2022 07:07:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241869AbiFNLHZ (ORCPT ); Tue, 14 Jun 2022 07:07:25 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 352391C2; Tue, 14 Jun 2022 04:07:23 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id y19so16439614ejq.6; Tue, 14 Jun 2022 04:07: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=1nFYikEZQyy7dcuLpIYSHTQjryLYDTf8L+QZXU1RkIA=; b=QS+9nJAugz9WPCBTtO6v5P2CE7DxfNzf6c8HFpXvyccj0UpFO/HlaYRL01gRyCJwSm krROrCcBtCRH1ET0pgUE3o8iOzVLxRu7Ag1kPO/Nz5YnsUbUElUA6D4SAs8AFiJS152X NtcHZD1gh9C5OApmH9ufLKOx4j+Z0BIBtgYjV8pF1wle2qpodY6todKJWAox1jbGZMDc 1mS5KL+5snp0NQLbCW2r2QE8IlVeYPJaZjW1ERGFUvLYtkL27mfnRyrLup3nkd0mt+wt LwqNgRpp2R0IhqPYFLzY9qzty+KljSd8m7AfkiMLLuayX0jtnP7Ajkt+q3swucU2jMlT SWtg== 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=1nFYikEZQyy7dcuLpIYSHTQjryLYDTf8L+QZXU1RkIA=; b=GcL1h5imv3wYrKMolpJE38Fi7cdXKbwON9uKJcZC83EM3+XczZpa+fHxmqhRYMuKFS wdNJ78PjGzIr8mRHaCUKnO55g3r+SGfsEmlu3xQvxdD+r7zGI7QDka9UQ7fz7POoMUhk spC8kxcosAE9D+GqUuDkBWdPfGX+UVi+eusvdNSA4M9hzaX4uAj+1SkMSvl3BFSx/hpW BVKI4j+DMWN52KJPmjD+eVzvNU8Z7MAFEYS92pmosXng5/xJ0ief5DpkyVz099vNJ1Cd W9xAcaT3VnyL1cA0UdZ/loMwAJg+hQZWHZ8jqsk+p/sR1qOf1Yh1AHpnxWHGo5CW0RH9 bSzQ== X-Gm-Message-State: AOAM530VoONla89ARzuleeu7AgULBBee77Bz1k6ay4QCIkbdMD+Vkryo PSvs5U+aSPDeAVkO4IkwoY0= X-Google-Smtp-Source: ABdhPJzhBZAqXGSKoy4zcGJmq9W2gGQRovFlV7OvqS6GK/RC/Izv4TSuHzZiMmJRTLN7tbg+0Ouhkw== X-Received: by 2002:a17:906:fb0f:b0:715:7e23:bbbc with SMTP id lz15-20020a170906fb0f00b007157e23bbbcmr3762937ejb.373.1655204841530; Tue, 14 Jun 2022 04:07: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 cb2-20020a0564020b6200b00433b5f22864sm6867456edb.20.2022.06.14.04.07.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 04:07:21 -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 v3 1/5] PM / devfreq: Fix cpufreq passive unregister erroring on PROBE_DEFER Date: Tue, 14 Jun 2022 13:06:57 +0200 Message-Id: <20220614110701.31240-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220614110701.31240-1-ansuelsmth@gmail.com> References: <20220614110701.31240-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 | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c index 72c67979ebe1..0188c32f5198 100644 --- a/drivers/devfreq/governor_passive.c +++ b/drivers/devfreq/governor_passive.c @@ -222,8 +222,8 @@ 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; + struct devfreq_cpu_data *parent_cpu_data, *tmp; + 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, tmp, &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 Tue Jun 14 11:06:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 581876 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 889FDC433EF for ; Tue, 14 Jun 2022 11:07:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356110AbiFNLH2 (ORCPT ); Tue, 14 Jun 2022 07:07:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356034AbiFNLH1 (ORCPT ); Tue, 14 Jun 2022 07:07:27 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F49CB96; Tue, 14 Jun 2022 04:07:25 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id u12so16413067eja.8; Tue, 14 Jun 2022 04:07:25 -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=TQRKcneckEoQfUsqmL/gDuP5mWDW/X0t3xQBfS3Jwuo=; b=kLGoYYcwIJ6dy51CeEEDy8kuyJs/x+mXeTbeBBcigCk4pJ4loGmskQ2xP1f2ONBfye wRKi0C6TScDpNEXIuRFNvYCRlWfPBWmA+spZXr/h/vNRAAzf9IDJs6f9CIQJ3hcE65Jr IUJFT4NfwQ4wAEcLEhuPIAEyQQw08rTMn6HidDUirxEmFs6kyFIC9KzsEoGqMiCu47mw 7BcPS+t2f5jDNYCn3VLXbjztNBru6Q6Y0jnut68IptCKvUgDitrAcWNHA1aMAcU71qYT glL8NwhWp8jKkrKr8psUW3onOiilQqp9EeeDRTgYd6kKgQgNDky6P3EeqlLI8KetXqsz u6kg== 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=TQRKcneckEoQfUsqmL/gDuP5mWDW/X0t3xQBfS3Jwuo=; b=W8Ki+Ck9o0hUD6q+/dlwTx54VQCEGsQ4J/1ASUpDjeuq5lqcxSNipqyskg9GcD8wrC 5+cGdHP4bQed+uiOhOfoXWSbJKmiy/96WHcuNdtJAXe0uFgeZoE8DUzmxzQ/wwnaubLr NW56ki21DTKqoL5o0WybByAYveF/c655gP9xCChai/BLob3rP1xv6witT+ZiPnuuo/po QrDH1/eOzLNuXuoz2kkA60VJIE8OR/0UngrrcZEryFJ1f4gcKNl+W1arTkmza3hEpxnH ik6t1jf5DdlAcQWTGWiSK3jR2xgoSUA2DbydWd//5LGPbInaAjKG7yAMEkBVltD51oZI ms6A== X-Gm-Message-State: AOAM532/FkgZNqcan5lrUJ0RgItxqTnfCqu1KwHKmuxPdaZGU8c/mnYX f5DcAaKYZiMO82/mrfN8Fwo= X-Google-Smtp-Source: ABdhPJztbuXyv1YfbeZOKjCqoXuR2KgLu6Mte9TpLLqB9kpU8+xb6nsz8Nu7M7RYMAu7rQlpAA3Wng== X-Received: by 2002:a17:907:7f2a:b0:711:dbde:19a1 with SMTP id qf42-20020a1709077f2a00b00711dbde19a1mr3736907ejc.87.1655204843822; Tue, 14 Jun 2022 04:07:23 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id cb2-20020a0564020b6200b00433b5f22864sm6867456edb.20.2022.06.14.04.07.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 04:07:23 -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 v3 3/5] PM / devfreq: Fix kernel panic with cpu based scaling to passive gov Date: Tue, 14 Jun 2022 13:06:59 +0200 Message-Id: <20220614110701.31240-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220614110701.31240-1-ansuelsmth@gmail.com> References: <20220614110701.31240-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 3c3322adea03..be8aa6830413 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 Tue Jun 14 11:07: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: 581875 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 815CBC433EF for ; Tue, 14 Jun 2022 11:07:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241869AbiFNLHc (ORCPT ); Tue, 14 Jun 2022 07:07:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356147AbiFNLHa (ORCPT ); Tue, 14 Jun 2022 07:07:30 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E6DBEB7; Tue, 14 Jun 2022 04:07:27 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id m20so16400893ejj.10; Tue, 14 Jun 2022 04:07:27 -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=B02DeuPO+BZECqpvp/HqctH5+yuZhfdhDrn4GY1DbZ1slBnwpFZFJI7APngu8tHNIm IKOiauuMDwdK69gedR8dslBR/BKsp0swY2J45WBTHgyHy+PcBlb3+GetSipQBZldnru/ N1PxRO3KhPGcDJGv2fTqrlKnyQ5N3JkltnBARkms4JjPrkHZx7aQ7BUAksbPTssIhFsQ o45dJqMUI2KjWNriW47ltltFr8lAYgpX8Ws6AiqXgoCMnUpddzc1ugJx6pDgJQsL6E44 dUiNfkyWXv2m+TjNOazTDH4sWLAlG6+Pes4n7gy9YjEEdg22AojGOhG/A3OhtF+fK4J+ Kf0A== 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=efzsyZ9j33r42vtStk5oFm28GsIniLT8EJzvEnkvXIVsdsbt/tekYxbUKN6SsZEiYZ kNfOYF/IC3sGLeR3awfpn9M1qIxzI+fI2kWE1N+j6Z01VEUb3zI+GpywxAugtZ1nkqUQ i74XLBBiSMHrP/TSGxhmPnbTY95ODTFiYj7QSg3netTF3NJ6jOOZNShrgbtKHtXyF6O3 ANRxBTjc3pRG2shhjBLTqeeXPZmSU3QrwxucAEgRmRuamnGXN44KGlwByb9yIToDJ2vY ujZPdj8a9qurEZsShgGE6uFUYqiNUWL5gUW/lQiXvyX78z08/3I9RXgz8tgcf81vG7kG uDJQ== X-Gm-Message-State: AOAM532sUo9uzFiOTCQBlppgEICwdUj8qzYu1PGw3atKypYerFg/W/sz 4IkfVMvtlYTTGVhr7zGvhEM= X-Google-Smtp-Source: AGRyM1ugMGU1GzBQZaCq6t82MbN9CwgPTCVr+506Anu6EgxBOpCVd7X6Nc3zIURwowiLXvicDNoUyQ== X-Received: by 2002:a17:906:8416:b0:705:6a1b:e8ef with SMTP id n22-20020a170906841600b007056a1be8efmr3648558ejx.614.1655204846265; Tue, 14 Jun 2022 04:07:26 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id cb2-20020a0564020b6200b00433b5f22864sm6867456edb.20.2022.06.14.04.07.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 04:07:25 -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 v3 5/5] PM / devfreq: Mute warning on governor PROBE_DEFER Date: Tue, 14 Jun 2022 13:07:01 +0200 Message-Id: <20220614110701.31240-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220614110701.31240-1-ansuelsmth@gmail.com> References: <20220614110701.31240-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);