linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Sudeep Holla <sudeep.holla@arm.com>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.20 12/92] cpufreq: check if policy is inactive early in __cpufreq_get()
Date: Mon, 18 Feb 2019 14:42:15 +0100	[thread overview]
Message-ID: <20190218133455.804291561@linuxfoundation.org> (raw)
In-Reply-To: <20190218133454.668268457@linuxfoundation.org>

4.20-stable review patch.  If anyone has any objections, please let me know.

------------------

[ Upstream commit 2f66196208c98b3d1b4294edffb2c5a8197be899 ]

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: Sudeep Holla <sudeep.holla@arm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/cpufreq/cpufreq.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 7aa3dcad2175..df34a12a388f 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1530,17 +1530,16 @@ static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
 {
 	unsigned int ret_freq = 0;
 
-	if (!cpufreq_driver->get)
+	if (unlikely(policy_is_inactive(policy)) || !cpufreq_driver->get)
 		return ret_freq;
 
 	ret_freq = cpufreq_driver->get(policy->cpu);
 
 	/*
-	 * Updating inactive policies is invalid, so avoid doing that.  Also
-	 * if fast frequency switching is used with the given policy, the check
+	 * If fast frequency switching is used with the given policy, the check
 	 * against policy->cur is pointless, so skip it in that case too.
 	 */
-	if (unlikely(policy_is_inactive(policy)) || policy->fast_switch_enabled)
+	if (policy->fast_switch_enabled)
 		return ret_freq;
 
 	if (ret_freq && policy->cur &&
@@ -1569,10 +1568,7 @@ unsigned int cpufreq_get(unsigned int cpu)
 
 	if (policy) {
 		down_read(&policy->rwsem);
-
-		if (!policy_is_inactive(policy))
-			ret_freq = __cpufreq_get(policy);
-
+		ret_freq = __cpufreq_get(policy);
 		up_read(&policy->rwsem);
 
 		cpufreq_cpu_put(policy);
-- 
2.19.1




  parent reply	other threads:[~2019-02-18 13:45 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-18 13:42 [PATCH 4.20 00/92] 4.20.11-stable review Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 01/92] dt-bindings: eeprom: at24: add "atmel,24c2048" compatible string Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 02/92] eeprom: at24: add support for 24c2048 Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 03/92] blk-mq: fix a hung issue when fsync Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 04/92] drm/amdgpu/sriov:Correct pfvf exchange logic Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 05/92] ACPI: NUMA: Use correct type for printing addresses on i386-PAE Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 06/92] perf stat: Fix endless wait for child process Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 07/92] perf report: Fix wrong iteration count in --branch-history Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 08/92] perf test shell: Use a fallback to get the pathname in vfs_getname Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 09/92] soc: renesas: r8a774c0-sysc: Fix initialization order of 3DG-{A,B} Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 10/92] tools uapi: fix RISC-V 64-bit support Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 11/92] riscv: fix trace_sys_exit hook Greg Kroah-Hartman
2019-02-18 13:42 ` Greg Kroah-Hartman [this message]
2019-02-18 13:42 ` [PATCH 4.20 13/92] csky: fixup relocation error with 807 & 860 Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 14/92] csky: fixup CACHEV1 store instruction fast retire Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 15/92] csky: fixup compile error with pte_alloc Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 16/92] irqchip/csky: fixup handle_irq_perbit break irq Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 17/92] drm/amd/powerplay: avoid possible buffer overflow Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 18/92] drm/bridge: tc358767: add bus flags Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 19/92] drm/bridge: tc358767: add defines for DP1_SRCCTRL & PHY_2LANE Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 20/92] drm/bridge: tc358767: fix single lane configuration Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 21/92] drm/bridge: tc358767: fix initial DP0/1_SRCCTRL value Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 22/92] drm/bridge: tc358767: reject modes which require too much BW Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 23/92] drm/bridge: tc358767: fix output H/V syncs Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 24/92] nvme-pci: use the same attributes when freeing host_mem_desc_bufs Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 25/92] nvme-pci: fix out of bounds access in nvme_cqe_pending Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 26/92] nvme-multipath: zero out ANA log buffer Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 27/92] nvme: pad fake subsys NQN vid and ssvid with zeros Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 28/92] nvme: introduce NVME_QUIRK_IGNORE_DEV_SUBNQN Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 29/92] drm/amdgpu: fix CPDMA hang in PRT mode for VEGA20 Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 30/92] drm/amdgpu: set WRITE_BURST_LENGTH to 64B to workaround SDMA1 hang Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 31/92] drm/amdgpu: disable system memory page tables for now Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 32/92] ARM: dts: da850-evm: Correct the audio codec regulators Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 33/92] ARM: dts: da850-evm: Correct the sound card name Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 34/92] ARM: dts: da850-lcdk: Correct the audio codec regulators Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 35/92] ARM: dts: da850-lcdk: Correct the sound card name Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 36/92] ARM: dts: kirkwood: Fix polarity of GPIO fan lines Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 37/92] csky: fixup compile error with CPU 810 Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 38/92] gpio: pl061: handle failed allocations Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 39/92] drm/nouveau: Dont disable polling in fallback mode Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 40/92] drm/nouveau/falcon: avoid touching registers if engine is off Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 41/92] cifs: Limit memory used by lock request calls to a page Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 42/92] CIFS: Fix credits calculation for cancelled requests Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 43/92] CIFS: Move credit processing to mid callbacks for SMB3 Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 44/92] CIFS: Fix error paths in writeback code Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 45/92] kvm: sev: Fail KVM_SEV_INIT if already initialized Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 46/92] CIFS: Fix credit calculations in compound mid callback Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 47/92] CIFS: Do not assume one credit for async responses Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 48/92] CIFS: Fix mounts if the client is low on credits Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 49/92] gpio: mxc: move gpio noirq suspend/resume to syscore phase Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 50/92] Revert "Input: elan_i2c - add ACPI ID for touchpad in ASUS Aspire F5-573G" Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 51/92] Input: elan_i2c - add ACPI ID for touchpad in Lenovo V330-15ISK Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 52/92] arm64: dts: rockchip: enable usb-host regulators at boot on rk3328-rock64 Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 53/92] ARM: OMAP5+: Fix inverted nirq pin interrupts with irq_set_type Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 54/92] perf/core: Fix impossible ring-buffer sizes warning Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 55/92] perf/x86: Add check_period PMU callback Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.20 56/92] ALSA: hda - Add quirk for HP EliteBook 840 G5 Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 57/92] ALSA: usb-audio: Fix implicit fb endpoint setup by quirk Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 58/92] ALSA: pcm: Revert capture stream behavior change in blocking mode Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 59/92] ASoC: hdmi-codec: fix oops on re-probe Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 60/92] tools uapi: fix Alpha support Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 61/92] riscv: Add pte bit to distinguish swap from invalid Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 62/92] x86/kvm/nVMX: read from MSR_IA32_VMX_PROCBASED_CTLS2 only when it is available Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 63/92] kvm: vmx: Fix entry number check for add_atomic_switch_msr() Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 64/92] mmc: sunxi: Disable HS-DDR mode for H5 eMMC controller by default Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 65/92] mmc: sunxi: Filter out unsupported modes declared in the device tree Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 66/92] mmc: block: handle complete_work on separate workqueue Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 67/92] Input: bma150 - register input device after setting private data Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 68/92] Input: elantech - enable 3rd button support on Fujitsu CELSIUS H780 Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 69/92] Revert "nfsd4: return default lease period" Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 70/92] Revert "mm: dont reclaim inodes with many attached pages" Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 71/92] Revert "mm: slowly shrink slabs with a relatively small number of objects" Greg Kroah-Hartman
2019-02-18 15:30   ` Rik van Riel
2019-02-18 16:16     ` Greg Kroah-Hartman
2019-02-18 17:38       ` Michal Hocko
2019-02-18 18:57         ` Roman Gushchin
2019-02-18 19:14           ` Michal Hocko
2019-02-18 19:30             ` Roman Gushchin
2019-02-18 19:34     ` Sasha Levin
2019-02-19 18:43       ` Wolfgang Walter
2019-02-18 13:43 ` [PATCH 4.20 72/92] mm: proc: smaps_rollup: fix pss_locked calculation Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 73/92] alpha: fix page fault handling for r16-r18 targets Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 74/92] alpha: Fix Eiger NR_IRQS to 128 Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 75/92] s390/suspend: fix stack setup in swsusp_arch_suspend Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 76/92] s390/zcrypt: fix specification exception on z196 during ap probe Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 77/92] tracing: probeevent: Correctly update remaining space in dynamic area Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 78/92] x86/platform/UV: Use efi_runtime_lock to serialise BIOS calls Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 79/92] powerpc/64s: Fix possible corruption on big endian due to pgd/pud_present() Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 80/92] scsi: sd: fix entropy gathering for most rotational disks Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 81/92] signal: Restore the stop PTRACE_EVENT_EXIT Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 82/92] crypto: ccree - fix resume race condition on init Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 83/92] md/raid1: dont clear bitmap bits on interrupted recovery Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 84/92] x86/a.out: Clear the dump structure initially Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 85/92] sunrpc: fix 4 more call sites that were using stack memory with a scatterlist Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 86/92] dm crypt: dont overallocate the integrity tag space Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 87/92] dm thin: fix bug where bio that overwrites thin block ignores FUA Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 88/92] drm: Use array_size() when creating lease Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 89/92] drm/vkms: Fix license inconsistent Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 90/92] drm/sched: Always trace the dependencies we wait on, to fix a race Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 91/92] drm/i915: Block fbdev HPD processing during suspend Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.20 92/92] drm/i915: Prevent a race during I915_GEM_MMAP ioctl with WC set Greg Kroah-Hartman
2019-02-19  5:48 ` [PATCH 4.20 00/92] 4.20.11-stable review Naresh Kamboju
2019-02-19 12:47   ` Greg Kroah-Hartman
2019-02-19 17:39 ` Guenter Roeck
2019-02-20  9:04   ` Greg Kroah-Hartman
2019-02-20  0:16 ` shuah

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190218133455.804291561@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=sudeep.holla@arm.com \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).