mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kamal Mostafa <kamal@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	kernel-team@lists.ubuntu.com
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Vince Weaver <vincent.weaver@maine.edu>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>,
	Kamal Mostafa <kamal@canonical.com>
Subject: [PATCH 3.19.y-ckt 082/102] perf: Fix PERF_EVENT_IOC_PERIOD migration race
Date: Tue, 22 Sep 2015 10:52:18 -0700	[thread overview]
Message-ID: <1442944358-1248-83-git-send-email-kamal@canonical.com> (raw)
In-Reply-To: <1442944358-1248-1-git-send-email-kamal@canonical.com>

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

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

From: Peter Zijlstra <peterz@infradead.org>

commit c7999c6f3fed9e383d3131474588f282ae6d56b9 upstream.

I ran the perf fuzzer, which triggered some WARN()s which are due to
trying to stop/restart an event on the wrong CPU.

Use the normal IPI pattern to ensure we run the code on the correct CPU.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: bad7192b842c ("perf: Fix PERF_EVENT_IOC_PERIOD to force-reset the period")
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 kernel/events/core.c | 75 ++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 55 insertions(+), 20 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 3262aa5..3527176 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3729,28 +3729,21 @@ static void perf_event_for_each(struct perf_event *event,
 	mutex_unlock(&ctx->mutex);
 }
 
-static int perf_event_period(struct perf_event *event, u64 __user *arg)
-{
-	struct perf_event_context *ctx = event->ctx;
-	int ret = 0, active;
+struct period_event {
+	struct perf_event *event;
 	u64 value;
+};
 
-	if (!is_sampling_event(event))
-		return -EINVAL;
-
-	if (copy_from_user(&value, arg, sizeof(value)))
-		return -EFAULT;
-
-	if (!value)
-		return -EINVAL;
+static int __perf_event_period(void *info)
+{
+	struct period_event *pe = info;
+	struct perf_event *event = pe->event;
+	struct perf_event_context *ctx = event->ctx;
+	u64 value = pe->value;
+	bool active;
 
-	raw_spin_lock_irq(&ctx->lock);
+	raw_spin_lock(&ctx->lock);
 	if (event->attr.freq) {
-		if (value > sysctl_perf_event_sample_rate) {
-			ret = -EINVAL;
-			goto unlock;
-		}
-
 		event->attr.sample_freq = value;
 	} else {
 		event->attr.sample_period = value;
@@ -3769,11 +3762,53 @@ static int perf_event_period(struct perf_event *event, u64 __user *arg)
 		event->pmu->start(event, PERF_EF_RELOAD);
 		perf_pmu_enable(ctx->pmu);
 	}
+	raw_spin_unlock(&ctx->lock);
 
-unlock:
+	return 0;
+}
+
+static int perf_event_period(struct perf_event *event, u64 __user *arg)
+{
+	struct period_event pe = { .event = event, };
+	struct perf_event_context *ctx = event->ctx;
+	struct task_struct *task;
+	u64 value;
+
+	if (!is_sampling_event(event))
+		return -EINVAL;
+
+	if (copy_from_user(&value, arg, sizeof(value)))
+		return -EFAULT;
+
+	if (!value)
+		return -EINVAL;
+
+	if (event->attr.freq && value > sysctl_perf_event_sample_rate)
+		return -EINVAL;
+
+	task = ctx->task;
+	pe.value = value;
+
+	if (!task) {
+		cpu_function_call(event->cpu, __perf_event_period, &pe);
+		return 0;
+	}
+
+retry:
+	if (!task_function_call(task, __perf_event_period, &pe))
+		return 0;
+
+	raw_spin_lock_irq(&ctx->lock);
+	if (ctx->is_active) {
+		raw_spin_unlock_irq(&ctx->lock);
+		task = ctx->task;
+		goto retry;
+	}
+
+	__perf_event_period(&pe);
 	raw_spin_unlock_irq(&ctx->lock);
 
-	return ret;
+	return 0;
 }
 
 static const struct file_operations perf_fops;
-- 
1.9.1


  parent reply	other threads:[~2015-09-22 17:54 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-22 17:50 [3.19.y-ckt stable] Linux 3.19.8-ckt7 stable review Kamal Mostafa
2015-09-22 17:50 ` [PATCH 3.19.y-ckt 001/102] [3.19-stable only] Revert "dmaengine: pl330: Fix overflow when reporting residue in memcpy" Kamal Mostafa
2015-09-22 17:50 ` [PATCH 3.19.y-ckt 002/102] x86/ldt: Make modify_ldt synchronous Kamal Mostafa
2015-09-22 17:50 ` [PATCH 3.19.y-ckt 003/102] x86/ldt: Correct LDT access in single stepping logic Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 004/102] x86/ldt: Correct FPU emulation access to LDT Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 005/102] md: flush ->event_work before stopping array Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 006/102] ipmi/powernv: Fix minor locking bug Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 007/102] ipv6: addrconf: validate new MTU before applying it Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 008/102] virtio-net: drop NETIF_F_FRAGLIST Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 009/102] RDS: verify the underlying transport exists before creating a connection Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 010/102] xen/gntdev: convert priv->lock to a mutex Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 011/102] xen/gntdevt: Fix race condition in gntdev_release() Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 012/102] PCI: Restore PCI_MSIX_FLAGS_BIRMASK definition Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 013/102] USB: qcserial/option: make AT URCs work for Sierra Wireless MC7305/MC7355 Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 014/102] USB: qcserial: Add support for Dell Wireless 5809e 4G Modem Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 015/102] nfsd: Drop BUG_ON and ignore SECLABEL on absent filesystem Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 016/102] usb: chipidea: ehci_init_driver is intended to call one time Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 017/102] crypto: qat - Fix invalid synchronization between register/unregister sym algs Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 018/102] crypto: ixp4xx - Remove bogus BUG_ON on scattered dst buffer Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 019/102] mfd: arizona: Fix initialisation of the PM runtime Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 020/102] xen-blkfront: don't add indirect pages to list when !feature_persistent Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 021/102] xen-blkback: replace work_pending with work_busy in purge_persistent_gnt() Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 022/102] usb: gadget: f_uac2: fix calculation of uac2->p_interval Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 023/102] hwrng: core - correct error check of kthread_run call Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 024/102] USB: sierra: add 1199:68AB device ID Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 025/102] regmap: regcache-rbtree: Clean new present bits on present bitmap resize Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 026/102] target/iscsi: Fix double free of a TUR followed by a solicited NOPOUT Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 027/102] rbd: fix copyup completion race Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 028/102] md/raid1: extend spinlock to protect raid1_end_read_request against inconsistencies Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 029/102] target: REPORT LUNS should return LUN 0 even for dynamic ACLs Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 030/102] MIPS: Fix sched_getaffinity with MT FPAFF enabled Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 031/102] MIPS: Malta: Don't reinitialise RTC Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 032/102] MIPS: do_mcheck: Fix kernel code dump with EVA Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 033/102] MIPS: show_stack: Fix stack trace " Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 034/102] MIPS: Export get_c0_perfcount_int() Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 035/102] rtlwifi: rtl8723be: Add module parameter for MSI interrupts Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 036/102] MIPS: Flush RPS on kernel entry with EVA Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 037/102] usb: udc: core: add device_del() call to error pathway Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 038/102] xhci: fix off by one error in TRB DMA address boundary check Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 039/102] drivers/usb: Delete XHCI command timer if necessary Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 040/102] staging: vt6655: vnt_bss_info_changed check conf->beacon_rate is not NULL Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 041/102] dm: fix dm_merge_bvec regression on 32 bit systems Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 042/102] perf: Fix fasync handling on inherited events Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 043/102] drm/dp-mst: Remove debug WARN_ON Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 044/102] ALSA: fireworks/firewire-lib: add support for recent firmware quirk Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 045/102] mm, vmscan: Do not wait for page writeback for GFP_NOFS allocations Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 046/102] MIPS: Make set_pte() SMP safe Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 047/102] ipc: modify message queue accounting to not take kernel data structures into account Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 048/102] ocfs2: fix BUG in ocfs2_downconvert_thread_do_work() Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 049/102] fsnotify: fix oops in fsnotify_clear_marks_by_group_flags() Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 050/102] KVM: x86: Use adjustment in guest cycles when handling MSR_IA32_TSC_ADJUST Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 051/102] x86/xen: build "Xen PV" APIC driver for domU as well Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 052/102] cpuset: use trialcs->mems_allowed as a temp variable Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 053/102] drm/dp/mst: Remove port after removing connector Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 054/102] localmodconfig: Use Kbuild files too Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 055/102] dm thin metadata: delete btrees when releasing metadata snapshot Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 056/102] dm btree: add ref counting ops for the leaves of top level btrees Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 057/102] drm/radeon: add new OLAND pci id Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 058/102] libiscsi: Fix host busy blocking during connection teardown Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 059/102] libfc: Fix fc_exch_recv_req() error path Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 060/102] libfc: Fix fc_fcp_cleanup_each_cmd() Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 061/102] sd: Fix maximum I/O size for BLOCK_PC requests Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 062/102] EDAC, ppc4xx: Access mci->csrows array elements properly Kamal Mostafa
2015-09-22 17:51 ` [PATCH 3.19.y-ckt 063/102] crypto: caam - fix memory corruption in ahash_final_ctx Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 064/102] drm/vmwgfx: Fix execbuf locking issues Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 065/102] mm/hwpoison: fix page refcount of unknown non LRU page Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 066/102] ipc,sem: fix use after free on IPC_RMID after a task using same semaphore set exits Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 067/102] ipc/sem.c: update/correct memory barriers Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 068/102] MIPS: Fix seccomp syscall argument for MIPS64 Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 069/102] x86/ldt: Further fix FPU emulation Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 070/102] drm/i915: Flag the execlists context object as dirty after every use Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 071/102] fnic: Use the local variable instead of I/O flag to acquire io_req_lock in fnic_queuecommand() to avoid deadloack Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 072/102] SCSI: Fix NULL pointer dereference in runtime PM Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 073/102] ALSA: usb-audio: Fix runtime PM unbalance Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 074/102] x86/xen: make CONFIG_XEN depend on CONFIG_X86_LOCAL_APIC Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 075/102] Input: gpio_keys_polled - request GPIO pin as input Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 076/102] PCI: Don't use 64-bit bus addresses on PA-RISC Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 077/102] ALSA: usb: Add native DSD support for Gustard DAC-X20U Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 078/102] Add factory recertified Crucial M500s to blacklist Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 079/102] arm64: KVM: Fix host crash when injecting a fault into a 32bit guest Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 080/102] batman-adv: protect tt_local_entry from concurrent delete events Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 081/102] ip6_gre: release cached dst on tunnel removal Kamal Mostafa
2015-09-22 17:52 ` Kamal Mostafa [this message]
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 083/102] net: Fix RCU splat in af_key Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 084/102] bna: fix interrupts storm caused by erroneous packets Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 085/102] net: Fix skb_set_peeked use-after-free bug Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 086/102] rds: fix an integer overflow test in rds_info_getsockopt() Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 087/102] fq_codel: explicitly reset flows in ->reset() Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 088/102] bridge: netlink: account for the IFLA_BRPORT_PROXYARP attribute size and policy Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 089/102] batman-adv: fix kernel crash due to missing NULL checks Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 090/102] fbdev: select versatile helpers for the integrator Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 091/102] rocker: free netdevice during netdevice removal Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 092/102] udp: fix dst races with multicast early demux Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 093/102] net: phy: add locking to phy_read_mmd_indirect()/phy_write_mmd_indirect() Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 094/102] sparc64: Fix userspace FPU register corruptions Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 095/102] rtnetlink: verify IFLA_VF_INFO attributes before passing them to driver Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 096/102] net/tipc: initialize security state for new connection socket Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 097/102] net: pktgen: fix race between pktgen_thread_worker() and kthread_stop() Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 098/102] net: Fix skb csum races when peeking Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 099/102] ipv6: lock socket in ip6_datagram_connect() Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 100/102] Revert "sit: Add gro callbacks to sit_offload" Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 101/102] bonding: correct the MAC address for "follow" fail_over_mac policy Kamal Mostafa
2015-09-22 17:52 ` [PATCH 3.19.y-ckt 102/102] netlink: don't hold mutex in rcu callback when releasing mmapd ring Kamal Mostafa

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=1442944358-1248-83-git-send-email-kamal@canonical.com \
    --to=kamal@canonical.com \
    --cc=kernel-team@lists.ubuntu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=vincent.weaver@maine.edu \
    /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®