• Sudeep Holla's avatar
    cpufreq: check if policy is inactive early in __cpufreq_get() · cafd389b
    Sudeep Holla authored
    [ Upstream commit 2f661962 ]
    
    cpuinfo_cur_freq gets current CPU frequency as detected by hardware
    while scaling_cur_freq last known CPU frequency. Some platforms may not
    allow checking the CPU frequency of an offline CPU or the associated
    resources may have been released via cpufreq_exit when the CPU gets
    offlined, in which case the policy would have been invalidated already.
    If we attempt to get current frequency from the hardware, it may result
    in hang or crash.
    
    For example on Juno, I see:
    
    Unable to handle kernel NULL pointer dereference at virtual address 0000000000000188
    [0000000000000188] pgd=0000000000000000
    Internal error: Oops: 96000004 [#1] PREEMPT SMP
    Modules linked in:
    CPU: 5 PID: 4202 Comm: cat Not tainted 4.20.0-08251-ga0f2c0318a15-dirty #87
    Hardware name: ARM LTD ARM Juno Development Platform/ARM Juno Development Platform
    pstate: 40000005 (nZcv daif -PAN -UAO)
    pc : scmi_cpufreq_get_rate+0x34/0xb0
    lr : scmi_cpufreq_get_rate+0x34/0xb0
    Call trace:
     scmi_cpufreq_get_rate+0x34/0xb0
     __cpufreq_get+0x34/0xc0
     show_cpuinfo_cur_freq+0x24/0x78
     show+0x40/0x60
     sysfs_kf_seq_show+0xc0/0x148
     kernfs_seq_show+0x44/0x50
     seq_read+0xd4/0x480
     kernfs_fop_read+0x15c/0x208
     __vfs_read+0x60/0x188
     vfs_read+0x94/0x150
     ksys_read+0x6c/0xd8
     __arm64_sys_read+0x24/0x30
     el0_svc_common+0x78/0x100
     el0_svc_handler+0x38/0x78
     el0_svc+0x8/0xc
    ---[ end trace 3d1024e58f77f6b2 ]---
    
    So fix the issue by checking if the policy is invalid early in
    __cpufreq_get before attempting to get the current frequency.
    Signed-off-by: 's avatarSudeep Holla <sudeep.holla@arm.com>
    Acked-by: 's avatarViresh Kumar <viresh.kumar@linaro.org>
    Signed-off-by: 's avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
    Signed-off-by: 's avatarSasha Levin <sashal@kernel.org>
    cafd389b
Name
Last commit
Last update
..
Kconfig Loading commit data...
Kconfig.arm Loading commit data...
Kconfig.powerpc Loading commit data...
Kconfig.x86 Loading commit data...
Makefile Loading commit data...
acpi-cpufreq.c Loading commit data...
amd_freq_sensitivity.c Loading commit data...
arm_big_little.c Loading commit data...
arm_big_little.h Loading commit data...
armada-37xx-cpufreq.c Loading commit data...
bmips-cpufreq.c Loading commit data...
brcmstb-avs-cpufreq.c Loading commit data...
cppc_cpufreq.c Loading commit data...
cpufreq-dt-platdev.c Loading commit data...
cpufreq-dt.c Loading commit data...
cpufreq-dt.h Loading commit data...
cpufreq-nforce2.c Loading commit data...
cpufreq.c Loading commit data...
cpufreq_conservative.c Loading commit data...
cpufreq_governor.c Loading commit data...
cpufreq_governor.h Loading commit data...
cpufreq_governor_attr_set.c Loading commit data...
cpufreq_ondemand.c Loading commit data...
cpufreq_ondemand.h Loading commit data...
cpufreq_performance.c Loading commit data...
cpufreq_powersave.c Loading commit data...
cpufreq_stats.c Loading commit data...
cpufreq_userspace.c Loading commit data...
davinci-cpufreq.c Loading commit data...
e_powersaver.c Loading commit data...
elanfreq.c Loading commit data...
freq_table.c Loading commit data...
gx-suspmod.c Loading commit data...
highbank-cpufreq.c Loading commit data...
ia64-acpi-cpufreq.c Loading commit data...
imx6q-cpufreq.c Loading commit data...
intel_pstate.c Loading commit data...
kirkwood-cpufreq.c Loading commit data...
longhaul.c Loading commit data...
longhaul.h Loading commit data...
longrun.c Loading commit data...
loongson1-cpufreq.c Loading commit data...
loongson2_cpufreq.c Loading commit data...
maple-cpufreq.c Loading commit data...
mediatek-cpufreq.c Loading commit data...
mvebu-cpufreq.c Loading commit data...
omap-cpufreq.c Loading commit data...
p4-clockmod.c Loading commit data...
pasemi-cpufreq.c Loading commit data...
pcc-cpufreq.c Loading commit data...
pmac32-cpufreq.c Loading commit data...
pmac64-cpufreq.c Loading commit data...
powernow-k6.c Loading commit data...
powernow-k7.c Loading commit data...
powernow-k7.h Loading commit data...
powernow-k8.c Loading commit data...
powernow-k8.h Loading commit data...
powernv-cpufreq.c Loading commit data...
ppc_cbe_cpufreq.c Loading commit data...
ppc_cbe_cpufreq.h Loading commit data...
ppc_cbe_cpufreq_pervasive.c Loading commit data...
ppc_cbe_cpufreq_pmi.c Loading commit data...
pxa2xx-cpufreq.c Loading commit data...
pxa3xx-cpufreq.c Loading commit data...
qcom-cpufreq-kryo.c Loading commit data...
qoriq-cpufreq.c Loading commit data...
s3c2410-cpufreq.c Loading commit data...
s3c2412-cpufreq.c Loading commit data...
s3c2416-cpufreq.c Loading commit data...
s3c2440-cpufreq.c Loading commit data...
s3c24xx-cpufreq-debugfs.c Loading commit data...
s3c24xx-cpufreq.c Loading commit data...
s3c64xx-cpufreq.c Loading commit data...
s5pv210-cpufreq.c Loading commit data...
sa1100-cpufreq.c Loading commit data...
sa1110-cpufreq.c Loading commit data...
sc520_freq.c Loading commit data...
scmi-cpufreq.c Loading commit data...
scpi-cpufreq.c Loading commit data...
sfi-cpufreq.c Loading commit data...
sh-cpufreq.c Loading commit data...
sparc-us2e-cpufreq.c Loading commit data...
sparc-us3-cpufreq.c Loading commit data...
spear-cpufreq.c Loading commit data...
speedstep-centrino.c Loading commit data...
speedstep-ich.c Loading commit data...
speedstep-lib.c Loading commit data...
speedstep-lib.h Loading commit data...
speedstep-smi.c Loading commit data...
sti-cpufreq.c Loading commit data...
tango-cpufreq.c Loading commit data...
tegra124-cpufreq.c Loading commit data...
tegra186-cpufreq.c Loading commit data...
tegra20-cpufreq.c Loading commit data...
ti-cpufreq.c Loading commit data...
unicore2-cpufreq.c Loading commit data...
vexpress-spc-cpufreq.c Loading commit data...