From: Sasha Levin <Alexander.Levin@microsoft.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Fenghua Yu <fenghua.yu@intel.com>,
Tony Luck <tony.luck@intel.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
Peter Zijlstra <peterz@infradead.org>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Sebastian Siewior <bigeasy@linutronix.de>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Michael Ellerman <mpe@ellerman.id.au>, Tejun Heo <tj@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Len Brown <lenb@kernel.org>,
Sasha Levin <Alexander.Levin@microsoft.com>
Subject: [PATCH AUTOSEL for 3.18 12/53] cpufreq/sh: Replace racy task affinity logic
Date: Thu, 8 Mar 2018 05:03:11 +0000 [thread overview]
Message-ID: <20180308050230.8876-12-alexander.levin@microsoft.com> (raw)
In-Reply-To: <20180308050230.8876-1-alexander.levin@microsoft.com>
From: Thomas Gleixner <tglx@linutronix.de>
[ Upstream commit 205dcc1ecbc566cbc20acf246e68de3b080b3ecf ]
The target() callback must run on the affected cpu. This is achieved by
temporarily setting the affinity of the calling thread to the requested CPU
and reset it to the original affinity afterwards.
That's racy vs. concurrent affinity settings for that thread resulting in
code executing on the wrong CPU.
Replace it by work_on_cpu(). All call pathes which invoke the callbacks are
already protected against CPU hotplug.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Sebastian Siewior <bigeasy@linutronix.de>
Cc: linux-pm@vger.kernel.org
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Tejun Heo <tj@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Len Brown <lenb@kernel.org>
Link: http://lkml.kernel.org/r/20170412201042.958216363@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
---
drivers/cpufreq/sh-cpufreq.c | 45 ++++++++++++++++++++++++++------------------
1 file changed, 27 insertions(+), 18 deletions(-)
diff --git a/drivers/cpufreq/sh-cpufreq.c b/drivers/cpufreq/sh-cpufreq.c
index 86628e22b2a3..719c3d9f07fb 100644
--- a/drivers/cpufreq/sh-cpufreq.c
+++ b/drivers/cpufreq/sh-cpufreq.c
@@ -30,54 +30,63 @@
static DEFINE_PER_CPU(struct clk, sh_cpuclk);
+struct cpufreq_target {
+ struct cpufreq_policy *policy;
+ unsigned int freq;
+};
+
static unsigned int sh_cpufreq_get(unsigned int cpu)
{
return (clk_get_rate(&per_cpu(sh_cpuclk, cpu)) + 500) / 1000;
}
-/*
- * Here we notify other drivers of the proposed change and the final change.
- */
-static int sh_cpufreq_target(struct cpufreq_policy *policy,
- unsigned int target_freq,
- unsigned int relation)
+static long __sh_cpufreq_target(void *arg)
{
- unsigned int cpu = policy->cpu;
+ struct cpufreq_target *target = arg;
+ struct cpufreq_policy *policy = target->policy;
+ int cpu = policy->cpu;
struct clk *cpuclk = &per_cpu(sh_cpuclk, cpu);
- cpumask_t cpus_allowed;
struct cpufreq_freqs freqs;
struct device *dev;
long freq;
- cpus_allowed = current->cpus_allowed;
- set_cpus_allowed_ptr(current, cpumask_of(cpu));
-
- BUG_ON(smp_processor_id() != cpu);
+ if (smp_processor_id() != cpu)
+ return -ENODEV;
dev = get_cpu_device(cpu);
/* Convert target_freq from kHz to Hz */
- freq = clk_round_rate(cpuclk, target_freq * 1000);
+ freq = clk_round_rate(cpuclk, target->freq * 1000);
if (freq < (policy->min * 1000) || freq > (policy->max * 1000))
return -EINVAL;
- dev_dbg(dev, "requested frequency %u Hz\n", target_freq * 1000);
+ dev_dbg(dev, "requested frequency %u Hz\n", target->freq * 1000);
freqs.old = sh_cpufreq_get(cpu);
freqs.new = (freq + 500) / 1000;
freqs.flags = 0;
- cpufreq_freq_transition_begin(policy, &freqs);
- set_cpus_allowed_ptr(current, &cpus_allowed);
+ cpufreq_freq_transition_begin(target->policy, &freqs);
clk_set_rate(cpuclk, freq);
- cpufreq_freq_transition_end(policy, &freqs, 0);
+ cpufreq_freq_transition_end(target->policy, &freqs, 0);
dev_dbg(dev, "set frequency %lu Hz\n", freq);
-
return 0;
}
+/*
+ * Here we notify other drivers of the proposed change and the final change.
+ */
+static int sh_cpufreq_target(struct cpufreq_policy *policy,
+ unsigned int target_freq,
+ unsigned int relation)
+{
+ struct cpufreq_target data = { .policy = policy, .freq = target_freq };
+
+ return work_on_cpu(policy->cpu, __sh_cpufreq_target, &data);
+}
+
static int sh_cpufreq_verify(struct cpufreq_policy *policy)
{
struct clk *cpuclk = &per_cpu(sh_cpuclk, policy->cpu);
--
2.14.1
next prev parent reply other threads:[~2018-03-08 5:08 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-08 5:03 [PATCH AUTOSEL for 3.18 01/53] usb: gadget: dummy_hcd: Fix wrong power status bit clear/reset in dummy_hub_control() Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 02/53] perf session: Don't rely on evlist in pipe mode Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 04/53] scsi: sg: close race condition in sg_remove_sfp_usercontext() Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 03/53] scsi: sg: check for valid direction before starting the request Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 05/53] kprobes/x86: Fix kprobe-booster not to boost far call instructions Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 06/53] kprobes/x86: Set kprobes pages read-only Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 07/53] wil6210: fix memory access violation in wil_memcpy_from/toio_32 Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 09/53] x86: i8259: export legacy_pic symbol Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 08/53] platform/x86: asus-nb-wmi: Add wapf4 quirk for the X302UA Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 10/53] Input: ar1021_i2c - fix too long name in driver's device table Sasha Levin
2018-03-08 5:03 ` Sasha Levin [this message]
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 11/53] ACPI/processor: Replace racy task affinity logic Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 14/53] i2c: i2c-scmi: add a MS HID Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 13/53] genirq: Use irqd_get_trigger_type to compare the trigger type for shared IRQs Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 16/53] [media] media/dvb-core: Race condition when writing to CAM Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 15/53] net: ipv6: send unsolicited NA on admin up Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 18/53] ath: Fix updating radar flags for coutry code India Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 17/53] spi: dw: Disable clock after unregistering the host Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 21/53] tcp: remove poll() flakes with FastOpen Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 20/53] KVM: PPC: Book3S PR: Exit KVM on failed mapping Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 19/53] scsi: virtio_scsi: Always try to read VPD pages Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 23/53] ALSA: hda - Fix headset microphone detection for ASUS N551 and N751 Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 22/53] e1000e: fix timing for 82579 Gigabit Ethernet controller Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 24/53] IB/ipoib: Update broadcast object if PKey value was changed in index 0 Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 25/53] HSI: ssi_protocol: double free in ssip_pn_xmit() Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 27/53] mmc: host: omap_hsmmc: checking for NULL instead of IS_ERR() Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 26/53] Fix driver usage of 128B WQEs when WQ_CREATE is V1 Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 28/53] wan: pc300too: abort path on failure Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 29/53] qlcnic: fix unchecked return value Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 31/53] rndis_wlan: add return value validation Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 30/53] scsi: mac_esp: Replace bogus memory barrier with spinlock Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 32/53] Btrfs: send, fix file hole not being preserved due to inline extent Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 33/53] mac80211: don't parse encrypted management frames in ieee80211_frame_acked Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 34/53] mfd: palmas: Reset the POWERHOLD mux during power off Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 36/53] ipmi/watchdog: fix wdog hang on panic waiting for ipmi response Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 35/53] ARM: DRA7: clockdomain: Change the CLKTRCTRL of CM_PCIE_CLKSTCTRL to SW_WKUP Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 37/53] bnx2x: Align RX buffers Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 38/53] power: supply: pda_power: move from timer to delayed_work Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 40/53] ia64: fix module loading for gcc-5.4 Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 39/53] md/raid10: skip spare disk as 'first' disk Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 41/53] video: fbdev: udlfb: Fix buffer on stack Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 42/53] sm501fb: don't return zero on failure path in sm501fb_start() Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 44/53] drm/msm: fix leak in failed get_pages Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 43/53] cifs: small underflow in cnvrtDosUnixTm() Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 46/53] media: [RESEND] media: dvb-frontends: Add delay to Si2168 restart Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 45/53] media: bt8xx: Fix err 'bt878_probe()' Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 48/53] IB/ipoib: Avoid memory leak if the SA returns a different DGID Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 47/53] mmc: avoid removing non-removable hosts during suspend Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 50/53] vgacon: Set VGA struct resource types Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 49/53] RDMA/cma: Use correct size when writing netlink stats Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 51/53] drm/omap: DMM: Check for DMM readiness after successful transaction commit Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 53/53] clk: si5351: Rename internal plls to avoid name collisions Sasha Levin
2018-03-08 5:03 ` [PATCH AUTOSEL for 3.18 52/53] pinctrl: Really force states during suspend/resume Sasha Levin
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=20180308050230.8876-12-alexander.levin@microsoft.com \
--to=alexander.levin@microsoft.com \
--cc=benh@kernel.crashing.org \
--cc=bigeasy@linutronix.de \
--cc=davem@davemloft.net \
--cc=fenghua.yu@intel.com \
--cc=herbert@gondor.apana.org.au \
--cc=jiangshanlai@gmail.com \
--cc=lenb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mpe@ellerman.id.au \
--cc=peterz@infradead.org \
--cc=rjw@rjwysocki.net \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=tony.luck@intel.com \
/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
all inboxes | Powered by JetHome®