From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev,
"Steven Rostedt (Google)" <rostedt@goodmis.org>,
Zheng Yejian <zhengyejian1@huawei.com>
Subject: [PATCH 5.4 39/92] ring-buffer: Fix race while reader and writer are on the same page
Date: Tue, 18 Apr 2023 14:21:14 +0200 [thread overview]
Message-ID: <20230418120306.209350216@linuxfoundation.org> (raw)
In-Reply-To: <20230418120304.658273364@linuxfoundation.org>
From: Zheng Yejian <zhengyejian1@huawei.com>
commit 6455b6163d8c680366663cdb8c679514d55fc30c upstream.
When user reads file 'trace_pipe', kernel keeps printing following logs
that warn at "cpu_buffer->reader_page->read > rb_page_size(reader)" in
rb_get_reader_page(). It just looks like there's an infinite loop in
tracing_read_pipe(). This problem occurs several times on arm64 platform
when testing v5.10 and below.
Call trace:
rb_get_reader_page+0x248/0x1300
rb_buffer_peek+0x34/0x160
ring_buffer_peek+0xbc/0x224
peek_next_entry+0x98/0xbc
__find_next_entry+0xc4/0x1c0
trace_find_next_entry_inc+0x30/0x94
tracing_read_pipe+0x198/0x304
vfs_read+0xb4/0x1e0
ksys_read+0x74/0x100
__arm64_sys_read+0x24/0x30
el0_svc_common.constprop.0+0x7c/0x1bc
do_el0_svc+0x2c/0x94
el0_svc+0x20/0x30
el0_sync_handler+0xb0/0xb4
el0_sync+0x160/0x180
Then I dump the vmcore and look into the problematic per_cpu ring_buffer,
I found that tail_page/commit_page/reader_page are on the same page while
reader_page->read is obviously abnormal:
tail_page == commit_page == reader_page == {
.write = 0x100d20,
.read = 0x8f9f4805, // Far greater than 0xd20, obviously abnormal!!!
.entries = 0x10004c,
.real_end = 0x0,
.page = {
.time_stamp = 0x857257416af0,
.commit = 0xd20, // This page hasn't been full filled.
// .data[0...0xd20] seems normal.
}
}
The root cause is most likely the race that reader and writer are on the
same page while reader saw an event that not fully committed by writer.
To fix this, add memory barriers to make sure the reader can see the
content of what is committed. Since commit a0fcaaed0c46 ("ring-buffer: Fix
race between reset page and reading page") has added the read barrier in
rb_get_reader_page(), here we just need to add the write barrier.
Link: https://lore.kernel.org/linux-trace-kernel/20230325021247.2923907-1-zhengyejian1@huawei.com
Cc: stable@vger.kernel.org
Fixes: 77ae365eca89 ("ring-buffer: make lockless")
Suggested-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Zheng Yejian <zhengyejian1@huawei.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
kernel/trace/ring_buffer.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -2532,6 +2532,10 @@ rb_set_commit_to_write(struct ring_buffe
if (RB_WARN_ON(cpu_buffer,
rb_is_reader_page(cpu_buffer->tail_page)))
return;
+ /*
+ * No need for a memory barrier here, as the update
+ * of the tail_page did it for this page.
+ */
local_set(&cpu_buffer->commit_page->page->commit,
rb_page_write(cpu_buffer->commit_page));
rb_inc_page(cpu_buffer, &cpu_buffer->commit_page);
@@ -2545,6 +2549,8 @@ rb_set_commit_to_write(struct ring_buffe
while (rb_commit_index(cpu_buffer) !=
rb_page_write(cpu_buffer->commit_page)) {
+ /* Make sure the readers see the content of what is committed. */
+ smp_wmb();
local_set(&cpu_buffer->commit_page->page->commit,
rb_page_write(cpu_buffer->commit_page));
RB_WARN_ON(cpu_buffer,
@@ -3920,7 +3926,12 @@ rb_get_reader_page(struct ring_buffer_pe
/*
* Make sure we see any padding after the write update
- * (see rb_reset_tail())
+ * (see rb_reset_tail()).
+ *
+ * In addition, a writer may be writing on the reader page
+ * if the page has not been fully filled, so the read barrier
+ * is also needed to make sure we see the content of what is
+ * committed by the writer (see rb_set_commit_to_write()).
*/
smp_rmb();
next prev parent reply other threads:[~2023-04-18 12:31 UTC|newest]
Thread overview: 103+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-18 12:20 [PATCH 5.4 00/92] 5.4.241-rc1 review Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 01/92] scsi: ses: Handle enclosure with just a primary component gracefully Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 02/92] x86/PCI: Add quirk for AMD XHCI controller that loses MSI-X state in D3hot Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 03/92] cgroup/cpuset: Wake up cpuset_attach_wq tasks in cpuset_cancel_attach() Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 04/92] Revert "treewide: Replace DECLARE_TASKLET() with DECLARE_TASKLET_OLD()" Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 05/92] treewide: Replace DECLARE_TASKLET() with DECLARE_TASKLET_OLD() Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 06/92] smb3: fix problem with null cifs super block with previous patch Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 07/92] pinctrl: amd: Use irqchip template Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 08/92] pinctrl: amd: disable and mask interrupts on probe Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 09/92] pinctrl: amd: Disable and mask interrupts on resume Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 10/92] pwm: cros-ec: Explicitly set .polarity in .get_state() Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 11/92] pwm: sprd: " Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 12/92] wifi: mac80211: fix invalid drv_sta_pre_rcu_remove calls for non-uploaded sta Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 13/92] icmp: guard against too small mtu Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 14/92] net: dont let netpoll invoke NAPI if in xmit context Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 15/92] sctp: check send stream number after wait_for_sndbuf Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 16/92] ipv6: Fix an uninit variable access bug in __ip6_make_skb() Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 17/92] gpio: davinci: Add irq chip flag to skip set wake Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 18/92] sunrpc: only free unix grouplist after RCU settles Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 19/92] NFSD: callback request does not use correct credential for AUTH_SYS Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 20/92] xhci: also avoid the XHCI_ZERO_64B_REGS quirk with a passthrough iommu Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 21/92] USB: serial: cp210x: add Silicon Labs IFS-USB-DATACABLE IDs Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 22/92] usb: typec: altmodes/displayport: Fix configure initial pin assignment Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 23/92] USB: serial: option: add Telit FE990 compositions Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 24/92] USB: serial: option: add Quectel RM500U-CN modem Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 25/92] iio: adc: ti-ads7950: Set `can_sleep` flag for GPIO chip Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 26/92] iio: dac: cio-dac: Fix max DAC write value check for 12-bit Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 27/92] tty: serial: sh-sci: Fix transmit end interrupt handler Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 28/92] tty: serial: sh-sci: Fix Rx on RZ/G2L SCI Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 29/92] tty: serial: fsl_lpuart: avoid checking for transfer complete when UARTCTRL_SBK is asserted in lpuart32_tx_empty Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 30/92] nilfs2: fix potential UAF of struct nilfs_sc_info in nilfs_segctor_thread() Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 31/92] nilfs2: fix sysfs interface lifetime Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 32/92] ALSA: hda/realtek: Add quirk for Clevo X370SNW Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 33/92] perf/core: Fix the same task check in perf_event_set_output Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 34/92] ftrace: Mark get_lock_parent_ip() __always_inline Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 35/92] can: j1939: j1939_tp_tx_dat_new(): fix out-of-bounds memory access Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 36/92] tracing: Free error logs of tracing instances Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 37/92] net_sched: prevent NULL dereference if default qdisc setup failed Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 38/92] drm/panfrost: Fix the panfrost_mmu_map_fault_addr() error path Greg Kroah-Hartman
2023-04-18 12:21 ` Greg Kroah-Hartman [this message]
2023-04-18 12:21 ` [PATCH 5.4 40/92] mm/swap: fix swap_info_struct race between swapoff and get_swap_pages() Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 41/92] irqdomain: Look for existing mapping only once Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 42/92] irqdomain: Refactor __irq_domain_alloc_irqs() Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 43/92] irqdomain: Fix mapping-creation race Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 44/92] Revert "pinctrl: amd: Disable and mask interrupts on resume" Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 45/92] ALSA: emu10k1: fix capture interrupt handler unlinking Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 46/92] ALSA: hda/sigmatel: add pin overrides for Intel DP45SG motherboard Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 47/92] ALSA: i2c/cs8427: fix iec958 mixer control deactivation Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 48/92] ALSA: firewire-tascam: add missing unwind goto in snd_tscm_stream_start_duplex() Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 49/92] ALSA: hda/sigmatel: fix S/PDIF out on Intel D*45* motherboards Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 50/92] Bluetooth: L2CAP: Fix use-after-free in l2cap_disconnect_{req,rsp} Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 51/92] Bluetooth: Fix race condition in hidp_session_thread Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 52/92] btrfs: print checksum type and implementation at mount time Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 53/92] btrfs: fix fast csum implementation detection Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 54/92] mtdblock: tolerate corrected bit-flips Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 55/92] mtd: rawnand: meson: fix bitmask for length in command word Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 56/92] mtd: rawnand: stm32_fmc2: remove unsupported EDO mode Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 57/92] 9p/xen : Fix use after free bug in xen_9pfs_front_remove due to race condition Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 58/92] niu: Fix missing unwind goto in niu_alloc_channels() Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 59/92] qlcnic: check pci_reset_function result Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 60/92] sctp: fix a potential overflow in sctp_ifwdtsn_skip Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 61/92] RDMA/core: Fix GID entry ref leak when create_ah fails Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 62/92] udp6: fix potential access to stale information Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 63/92] net: macb: fix a memory corruption in extended buffer descriptor mode Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 64/92] power: supply: cros_usbpd: reclassify "default case!" as debug Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 65/92] i2c: imx-lpi2c: clean rx/tx buffers upon new message Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 66/92] efi: sysfb_efi: Add quirk for Lenovo Yoga Book X91F/L Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 67/92] drm: panel-orientation-quirks: Add quirk for Lenovo Yoga Book X90F Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 68/92] verify_pefile: relax wrapper length check Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 69/92] asymmetric_keys: log on fatal failures in PE/pkcs7 Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 70/92] ubi: Fix failure attaching when vid_hdr offset equals to (sub)page size Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 71/92] mtd: ubi: wl: Fix a couple of kernel-doc issues Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 72/92] ubi: Fix deadlock caused by recursively holding work_sem Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 73/92] i2c: ocores: generate stop condition after timeout in polling mode Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 74/92] watchdog: sbsa_wdog: Make sure the timeout programming is within the limits Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 75/92] coresight-etm4: Fix for() loop drvdata->nr_addr_cmp range bug Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 76/92] xfs: show the proper user quota options Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 77/92] xfs: merge the projid fields in struct xfs_icdinode Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 78/92] xfs: ensure that the inode uid/gid match values match the icdinode ones Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 79/92] xfs: remove the icdinode di_uid/di_gid members Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 80/92] xfs: remove the kuid/kgid conversion wrappers Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 81/92] xfs: add a new xfs_sb_version_has_v3inode helper Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 82/92] xfs: only check the superblock version for dinode size calculation Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 83/92] xfs: simplify di_flags2 inheritance in xfs_ialloc Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 84/92] xfs: simplify a check in xfs_ioctl_setattr_check_cowextsize Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 85/92] xfs: remove the di_version field from struct icdinode Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 86/92] xfs: fix up non-directory creation in SGID directories Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 87/92] xfs: set inode size after creating symlink Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 88/92] xfs: report corruption only as a regular error Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 89/92] xfs: shut down the filesystem if we screw up quota reservation Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 90/92] xfs: consider shutdown in bmapbt cursor delete assert Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 91/92] xfs: dont reuse busy extents on extent trim Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 92/92] xfs: force log and push AIL to clear pinned inodes when aborting mount Greg Kroah-Hartman
2023-04-18 14:12 ` [PATCH 5.4 00/92] 5.4.241-rc1 review Chris Paterson
2023-04-18 16:36 ` Florian Fainelli
2023-04-18 21:28 ` Shuah Khan
2023-04-19 3:34 ` Guenter Roeck
2023-04-19 7:41 ` Naresh Kamboju
2023-04-19 7:58 ` Cyril Hrubis
2023-04-21 8:04 ` Petr Vorel
2023-04-24 6:36 ` Yang Xu (Fujitsu)
2023-04-19 12:37 ` Harshit Mogalapalli
2023-04-19 13:30 ` zhouzhixiu
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=20230418120306.209350216@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=patches@lists.linux.dev \
--cc=rostedt@goodmis.org \
--cc=stable@vger.kernel.org \
--cc=zhengyejian1@huawei.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;
as well as URLs for NNTP newsgroup(s).