Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2833739ybc; Wed, 13 Nov 2019 23:04:39 -0800 (PST) X-Google-Smtp-Source: APXvYqwgtzphUmRiJOLPBYMlYfkiDE2Nc4Jr2qvbCG/+LwgNBHG4oEziZIsM80/KzmWu2P9EBtQo X-Received: by 2002:a05:6402:134f:: with SMTP id y15mr8401449edw.147.1573715079807; Wed, 13 Nov 2019 23:04:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573715079; cv=none; d=google.com; s=arc-20160816; b=Fhr+geC9ohMs7UUdwBsUehETiwW9CbXoE9yJc7A8UpFgp0YrIlEow/UDasT8eV1gPo /5KcXHl6Qv+XM65AXZWg62nR41YtI5Q+46QFMoh0PFRxnhd/XPl9viaDszCMxFvRq+5q kWDvyzNiIyoDKw/9eKW9X3R9sfzXKxTziIxhug0/V8YcX2vqKT2Jk7KiGtKhhzooug9L kAhpVPAMb4UCrpMvXJQ67Vn9t/XzRtLC6Ywp5g4SJDkE9pXzCo6vtwNElCuATm2oeBRe ytCcSJhBJ6W6dYl0nfhT8VD+XtPJ64k9rwgnXuhI96RW98zrBLQmDlRiTil5uL4YA3AW hA9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=EDWEwzVGX/Z+LhLTkyUvC+5Du7NTkM6wxTPRe/Giii8=; b=lZ1InFJXH58sdi1NIIH6fQ1/EewcEOkCIjpSvQL8d8gpOa7UnYrqsmROa4fbMZzJ6l RpXrobNFDekt/cXQ2KMzK4wbqWyMCZxtt4rmaA8NKd57OLzp47SYJgIe6ogCq0eQDalN S4/gckLmdM37pexXoJ8kKJvBiPTTeBQxeH0ZR5ylkWuv8pSQ/jcm2zuObhkp1lhxQBdF sfjKT3i4G1lY62OkDPqOdOZHk6VcE+BiWnj+w8Xlyu9TBorh2DVmqxTCBDsmqushhnHY 7eId16cWXwunw+E8+Xche6WX6XjjNASbor4KVyZZt6YW7Idjw90sX3dckNvd4oke/+s4 rmPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UtbncTT5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d27si105397ejt.116.2019.11.13.23.04.15; Wed, 13 Nov 2019 23:04:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UtbncTT5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726214AbfKNHDb (ORCPT + 99 others); Thu, 14 Nov 2019 02:03:31 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:42804 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbfKNHDb (ORCPT ); Thu, 14 Nov 2019 02:03:31 -0500 Received: by mail-qk1-f195.google.com with SMTP id m4so4103019qke.9 for ; Wed, 13 Nov 2019 23:03:30 -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=EDWEwzVGX/Z+LhLTkyUvC+5Du7NTkM6wxTPRe/Giii8=; b=UtbncTT5Mcc2iIxq5EcLUpW7wJHJqWv8QO2+J5fJlVFCEKzUMU5n5sb5QktLpIhMz2 7KOrmoB0hBSJW7Jfarnzt6rl7JNhTDWuQNhRB231fK/g3Oq6ngxWLeoE96tVh5jJvzGm zP38uDDRcefnZkkzU3OhCff95r3cUiY+6gFvPKECiCeyS3BBMbqdZK+H6VPpmQzbi4Jx INOelEZ0IE4w7v5zmqQ0nQAX5XYXwfhmuC+YJbbcsqy+2dzkcLeSSg8MToX+pqMKeD9/ EyUGf+wYRR4BEdHvV7l2ZvyjbA0SXCWhSNrCUxjZxm5+WKiGBg/p3lgNs8QOaoQ80w8w ytCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EDWEwzVGX/Z+LhLTkyUvC+5Du7NTkM6wxTPRe/Giii8=; b=gjkp5112hNamaakX5V88so+5PvzzT7kX6lzkz1f8BDl3veU4yHnFYQUFW61v+9qubw rD7pm0yMrUMuzcHoMFPWrZVcHjHXs0F1OkJM2gBSbRSbM7X5rwZCuxSqPzZwAprs4HrY w5ZcshasgBFbCdwepXfmYJbwdYI3tJKpV8tR2ig+jFUT8BYH67gY642PJlW10iVra1rP N0aKkgIu3zTi5BA2iEHIV1obC+PI4oZsIQSfVSCgctoq9EifgCu67TjmUioJii6+OGSA Uk9z8opO4uQjgKy5ncR2OjDAzGz+QXhhQlSQOFcsNMoNd8cKUoIPoPtS4szl7sljkJQ4 410w== X-Gm-Message-State: APjAAAVj459nQe+xvVvkTu6V80jLnbgoPlrGR0dIPsXud1ckaoZpL/Us 0vFMB1W4aOS8GJ0PMgxrjR6GaIRM/4i95SRKmXLnEg== X-Received: by 2002:a37:5603:: with SMTP id k3mr6327873qkb.346.1573715009867; Wed, 13 Nov 2019 23:03:29 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kucheria Date: Thu, 14 Nov 2019 12:33:18 +0530 Message-ID: Subject: Re: [PATCH] cpufreq: Register cpufreq drivers only after CPU devices are registered To: Viresh Kumar , Daniel Lezcano Cc: Rafael Wysocki , Linux PM list , Vincent Guittot , Bjorn Andersson , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 14, 2019 at 9:06 AM Viresh Kumar wrote: > > The cpufreq core heavily depends on the availability of the struct > device for CPUs and if they aren't available at the time cpufreq driver > is registered, we will never succeed in making cpufreq work. > > This happens due to following sequence of events: > > - cpufreq_register_driver() > - subsys_interface_register() > - return 0; //successful registration of driver > > ... at a later point of time > > - register_cpu(); > - device_register(); > - bus_probe_device(); > - sif->add_dev(); > - cpufreq_add_dev(); > - get_cpu_device(); //FAILS > - per_cpu(cpu_sys_devices, num) = &cpu->dev; //used by get_cpu_device() > - return 0; //CPU registered successfully > > Because the per-cpu variable cpu_sys_devices is set only after the CPU > device is regsitered, cpufreq will never be able to get it when > cpufreq_add_dev() is called. > > This patch avoids this failure by making sure device structure of at > least CPU0 is available when the cpufreq driver is registered, else > return -EPROBE_DEFER. > > Reported-by: Bjorn Andersson > Signed-off-by: Amit Kucheria > Signed-off-by: Viresh Kumar Tested-by: Amit Kucheria > --- > @Amit: I have added your sob without asking as you were involved in > getting us to this patch, you did a lot of testing yesterday to find the > root cause. SoB for the SoB :-) > @Rafael: This fixes the issues reported by Bjorn on Amit's series and so > should land before Amit's series, if at all this is acceptable to you. > Thanks. My series was going to get merged through the thermal tree. Currently it is hosted here[1] for linux-next testing. We could sign-off this patch to the thermal tree or bring the series into the PM tree. Up to Rafael and you. [1] https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git/log/?h=thermal/linux-next > drivers/cpufreq/cpufreq.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > index 681c1b5f0a1a..05293b43e56d 100644 > --- a/drivers/cpufreq/cpufreq.c > +++ b/drivers/cpufreq/cpufreq.c > @@ -2641,6 +2641,13 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) > if (cpufreq_disabled()) > return -ENODEV; > > + /* > + * The cpufreq core depends heavily on the availability of device > + * structure, make sure they are available before proceeding further. > + */ > + if (!get_cpu_device(0)) > + return -EPROBE_DEFER; > + > if (!driver_data || !driver_data->verify || !driver_data->init || > !(driver_data->setpolicy || driver_data->target_index || > driver_data->target) || > -- > 2.21.0.rc0.269.g1a574e7a288b >