Skip to content

Commit f485922

Browse files
q2venakpm00
authored andcommitted
pipe: make poll_usage boolean and annotate its access
Patch series "Fix data-races around epoll reported by KCSAN." This series suppresses a false positive KCSAN's message and fixes a real data-race. This patch (of 2): pipe_poll() runs locklessly and assigns 1 to poll_usage. Once poll_usage is set to 1, it never changes in other places. However, concurrent writes of a value trigger KCSAN, so let's make KCSAN happy. BUG: KCSAN: data-race in pipe_poll / pipe_poll write to 0xffff8880042f6678 of 4 bytes by task 174 on cpu 3: pipe_poll (fs/pipe.c:656) ep_item_poll.isra.0 (./include/linux/poll.h:88 fs/eventpoll.c:853) do_epoll_wait (fs/eventpoll.c:1692 fs/eventpoll.c:1806 fs/eventpoll.c:2234) __x64_sys_epoll_wait (fs/eventpoll.c:2246 fs/eventpoll.c:2241 fs/eventpoll.c:2241) do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:113) write to 0xffff8880042f6678 of 4 bytes by task 177 on cpu 1: pipe_poll (fs/pipe.c:656) ep_item_poll.isra.0 (./include/linux/poll.h:88 fs/eventpoll.c:853) do_epoll_wait (fs/eventpoll.c:1692 fs/eventpoll.c:1806 fs/eventpoll.c:2234) __x64_sys_epoll_wait (fs/eventpoll.c:2246 fs/eventpoll.c:2241 fs/eventpoll.c:2241) do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:113) Reported by Kernel Concurrency Sanitizer on: CPU: 1 PID: 177 Comm: epoll_race Not tainted 5.17.0-58927-gf443e374ae13 #6 Hardware name: Red Hat KVM, BIOS 1.11.0-2.amzn2 04/01/2014 Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: 3b84482 ("pipe: avoid unnecessary EPOLLET wakeups under normal loads") Signed-off-by: Kuniyuki Iwashima <[email protected]> Cc: Alexander Duyck <[email protected]> Cc: Al Viro <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Kuniyuki Iwashima <[email protected]> Cc: "Soheil Hassas Yeganeh" <[email protected]> Cc: "Sridhar Samudrala" <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent d1bd5fa commit f485922

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

fs/pipe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ pipe_poll(struct file *filp, poll_table *wait)
653653
unsigned int head, tail;
654654

655655
/* Epoll has some historical nasty semantics, this enables them */
656-
pipe->poll_usage = 1;
656+
WRITE_ONCE(pipe->poll_usage, true);
657657

658658
/*
659659
* Reading pipe state only -- no need for acquiring the semaphore.

include/linux/pipe_fs_i.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct pipe_inode_info {
7171
unsigned int files;
7272
unsigned int r_counter;
7373
unsigned int w_counter;
74-
unsigned int poll_usage;
74+
bool poll_usage;
7575
struct page *tmp_page;
7676
struct fasync_struct *fasync_readers;
7777
struct fasync_struct *fasync_writers;

0 commit comments

Comments
 (0)