Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2681037ybc; Wed, 13 Nov 2019 19:37:43 -0800 (PST) X-Google-Smtp-Source: APXvYqx1/cMx5Tw+Rlwq30pTN8Id2xhqYncoXlpvK70xzEjXjBkXn3ZjuW0kmH7CQ17Rf8Iyl6EP X-Received: by 2002:a17:907:20d2:: with SMTP id qq18mr6227479ejb.305.1573702663713; Wed, 13 Nov 2019 19:37:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573702663; cv=none; d=google.com; s=arc-20160816; b=IuoL+uBCAU6j5DYVzmvDJiv6fUB9+xyKPeofHk4v/FhhIEE2gbGbpNvRN9ap+IYqTz X3oyoUkEoOlZimxuZYeIoq5n6m8fjmvN46NRrUvz5sVd/Q05D57mYcP1NR6hA5zaaomr MvOu7eNe2zPI8tb+rS10tjEZdYAHZ60F5DrvhlL3MX9Aj7dMTXwIdXwrlDaTfjdu7xDr FaHDO8XFdQj0AzHp2BQWYjIP7lcUCq3zazhIpud7SFvvMH09fel2TZGDzDxf7xInnFGf Z8zzPDur4njB67J0ucO0ld+vq5PsSdLd08DOOOBpsC23s5QH5ZqbITX9AWRQ2TIR2NHO o9ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Zfh62teJf2BZgYM+/0fl1CP/Fxqn42ZyCR+MYxF6pao=; b=EGhPOPEyUr3w1JrQFcZ0HoIKdeMRaeiABHLz9rReUeYEGNjjlMrYW6+XoBMrF3fvMH Ck1bNBfeaV2uOQPIFIGrHPAD1HaWU06WfN86zTeM3dw7oUswmgkjW0MRrwx1KQPPouWF 7nmsr7yzLflT5USteW3jyFLCDXRpf9CFfpl1NCxORZH99hRmSscZdw+wlzhDuiyqyMOH JJTnGRpMvFfBxZ46aCZOUyaVXDIOQbc0xgbhwdO1TBj/TrVGAtkNaDGff5jLhfyPrd+q VXIfsZfWH/qqegZ0Ua2IyuGbnXoxYElrPT2Hf/4nW0j+Q4MVFRv/yA21MafpN7/BbmHz ncRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="nd/6bCe2"; 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 p20si2495164ejj.394.2019.11.13.19.37.18; Wed, 13 Nov 2019 19:37:43 -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="nd/6bCe2"; 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 S1726528AbfKNDgZ (ORCPT + 99 others); Wed, 13 Nov 2019 22:36:25 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:45095 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726393AbfKNDgZ (ORCPT ); Wed, 13 Nov 2019 22:36:25 -0500 Received: by mail-pf1-f193.google.com with SMTP id z4so3130301pfn.12 for ; Wed, 13 Nov 2019 19:36:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Zfh62teJf2BZgYM+/0fl1CP/Fxqn42ZyCR+MYxF6pao=; b=nd/6bCe2vLCNQ17q5z7dsZZ6wNxHSpI/uvIqp+SR/3RkVRWmA+ilxHFQGn9YJMLbRb GyRObG+7zxD5yfnZyYCV/VhA5BLdTRtiVT9ZVO92wlD24yDUdmZFxVGryOUUj202EtO3 hkfyADFg4kF46NGnccgEiC3BPsiSUurZK3EbGZWTcymyAiYI3UfF+tL16x4O6Kxmyk2M MSG50fTYjnV23yftGr9RwuAHBORRbXXRTQ8QtbdcDWZdEeD18P5xL6Bk8I1VBXwYwTt3 bElr/gYWXcJz8qBBlL04OiCXr3zgqOOqSPbtFxw6YZgtCjbAXwTojEo3+btxTrZWfXFn avLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Zfh62teJf2BZgYM+/0fl1CP/Fxqn42ZyCR+MYxF6pao=; b=Jq8wgM4QLLo70GlP+tK/MjzVQ3dye1Oa61Gxmw67KG6wzisXSh/xq2sCjWYk3s+tt5 cmePMVkIN0wS7OLRONSAHm6HJtzHKQJWA/qH95DiuZf3lWRbVwKXtxn3MyJg37ytiIzo ELosxYl5aXH76XW4nD0vNwUq2afx0vbr8lickUQUQOjPIMo6PqC0aTucIIbVrp0/B0rM QHCJJ1IUyJL1tRRcTZaKuR4SwUrMpZKLZXThf/vp964MZZYwFelqw5vn7hRZOLXAwCxy p6bsAV0f6VcD6iJW5pRP54TCPkx7IWkSsVMOWpIBImz/iTRYhf4LptHwOHiSH8oSa+iH b15g== X-Gm-Message-State: APjAAAV5fmlVYXGvpk1Nf91ukNyqJDCj9vWeBuU5vz6H6WDRdUKN7frG jpyTOm2Ql/5NwNo6uJbKYnPQkg== X-Received: by 2002:a63:6e82:: with SMTP id j124mr7689659pgc.115.1573702584525; Wed, 13 Nov 2019 19:36:24 -0800 (PST) Received: from localhost ([122.171.110.253]) by smtp.gmail.com with ESMTPSA id c21sm4222858pgh.25.2019.11.13.19.36.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Nov 2019 19:36:23 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , Bjorn Andersson , Amit Kucheria , linux-kernel@vger.kernel.org Subject: [PATCH] cpufreq: Register cpufreq drivers only after CPU devices are registered Date: Thu, 14 Nov 2019 09:06:17 +0530 Message-Id: X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- @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. @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. 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