From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
Yabin Cui <yabinc@google.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Jiri Olsa <jolsa@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Stephane Eranian <eranian@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Vince Weaver <vincent.weaver@maine.edu>,
acme@kernel.org, mark.rutland@arm.com, namhyung@kernel.org,
Ingo Molnar <mingo@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 4.9 06/20] perf/ring_buffer: Add ordering to rb->nest increment
Date: Sat, 8 Jun 2019 07:47:42 -0400 [thread overview]
Message-ID: <20190608114756.9742-6-sashal@kernel.org> (raw)
In-Reply-To: <20190608114756.9742-1-sashal@kernel.org>
From: Peter Zijlstra <peterz@infradead.org>
[ Upstream commit 3f9fbe9bd86c534eba2faf5d840fd44c6049f50e ]
Similar to how decrementing rb->next too early can cause data_head to
(temporarily) be observed to go backward, so too can this happen when
we increment too late.
This barrier() ensures the rb->head load happens after the increment,
both the one in the 'goto again' path, as the one from
perf_output_get_handle() -- albeit very unlikely to matter for the
latter.
Suggested-by: Yabin Cui <yabinc@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: acme@kernel.org
Cc: mark.rutland@arm.com
Cc: namhyung@kernel.org
Fixes: ef60777c9abd ("perf: Optimize the perf_output() path by removing IRQ-disables")
Link: http://lkml.kernel.org/r/20190517115418.309516009@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/events/ring_buffer.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 524744a38d61..8e8b903b7613 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -49,6 +49,15 @@ static void perf_output_put_handle(struct perf_output_handle *handle)
unsigned long head;
again:
+ /*
+ * In order to avoid publishing a head value that goes backwards,
+ * we must ensure the load of @rb->head happens after we've
+ * incremented @rb->nest.
+ *
+ * Otherwise we can observe a @rb->head value before one published
+ * by an IRQ/NMI happening between the load and the increment.
+ */
+ barrier();
head = local_read(&rb->head);
/*
--
2.20.1
next prev parent reply other threads:[~2019-06-08 11:50 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-08 11:47 [PATCH AUTOSEL 4.9 01/20] perf/x86/intel/ds: Fix EVENT vs. UEVENT PEBS constraints Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 02/20] selftests: netfilter: missing error check when setting up veth interface Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 03/20] mISDN: make sure device name is NUL terminated Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 04/20] x86/CPU/AMD: Don't force the CPB cap when running under a hypervisor Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 05/20] perf/ring_buffer: Fix exposing a temporarily decreased data_head Sasha Levin
2019-06-08 11:47 ` Sasha Levin [this message]
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 07/20] gpio: fix gpio-adp5588 build errors Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 08/20] net: tulip: de4x5: Drop redundant MODULE_DEVICE_TABLE() Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 09/20] i2c: dev: fix potential memory leak in i2cdev_ioctl_rdwr Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 10/20] configfs: Fix use-after-free when accessing sd->s_dentry Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 11/20] perf data: Fix 'strncat may truncate' build failure with recent gcc Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 12/20] perf record: Fix s390 missing module symbol and warning for non-root users Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 13/20] ia64: fix build errors by exporting paddr_to_nid() Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 14/20] KVM: PPC: Book3S: Use new mutex to synchronize access to rtas token list Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 15/20] KVM: PPC: Book3S HV: Don't take kvm->lock around kvm_for_each_vcpu Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 16/20] net: sh_eth: fix mdio access in sh_eth_close() for R-Car Gen2 and RZ/A1 SoCs Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 17/20] scsi: libcxgbi: add a check for NULL pointer in cxgbi_check_route() Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 18/20] scsi: smartpqi: properly set both the DMA mask and the coherent DMA mask Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 19/20] scsi: libsas: delete sas port if expander discover failed Sasha Levin
2019-06-08 11:47 ` [PATCH AUTOSEL 4.9 20/20] mlxsw: spectrum: Prevent force of 56G 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=20190608114756.9742-6-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=acme@kernel.org \
--cc=acme@redhat.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=namhyung@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 \
--cc=yabinc@google.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
Powered by JetHome