Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp91229iof; Sun, 5 Jun 2022 22:05:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLufL/T1gUoSCHW8vos0iy1kS5Ig0GKqIaDr9IBOnk1l70Z9XOuOG7E8hWQ8JwtKQnOgwo X-Received: by 2002:a17:90b:17c7:b0:1e8:5136:c32a with SMTP id me7-20020a17090b17c700b001e85136c32amr12561179pjb.43.1654491913455; Sun, 05 Jun 2022 22:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654491913; cv=none; d=google.com; s=arc-20160816; b=FNcFnYA6j9ljK5whgefs0pzb4k+Qxj7aEk2b0hWSZofN23VehneMMT5Lj1wBcBEwp4 vZZktvMGUs01o57YF5BtIAdWGkX/7U4c1PHaV7/HubFUUjUTonTcVDW4HK8tF+kBBJUz nMvQQCSeUHsi21MPsgPWY6J56GHhRVlPz+SjrPtPzm4CIAUEPrRvob3gyly+W2r+STJw L10SuvZ0YnW4sxQpyKcCWL7G/793ZwHVoCXXcuG9UkbUSqLUiDMNIhGRJ4xNUOkeAkFz hW7j0wzfZvF23kMzCiNB4RPpIRuHqQD2CNugVvTN6W4LafzndsGWPzzvuKDaSg0mmVuj Pssw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AljJCbAPQ8p2MJntfFkazaNHjiTWVH5YR+2uEmH7Wjw=; b=y6MagcwlGOv0/+TtMteqlIN5UWIBmHPy0Vh/UwrFAqy+5n2Q3L8ADSUVf7aAInPgah yB3RUsAAzQOm048IT9Esm6oaby55xbUpfUeZHq7Ksv4EkrkF4duwNwR0bjaHJoL4z2Nq 115vw0x5PluirmknZ3MFqoubKa//rl5MBp6BTwWo6+9bT0/SWMXj+jJpOdN4i3fKU7R2 Ybzm1BEdaKrEDCCZDQ5121nXfYIRnq9knnvLeby1P04UlO/GYnX4IujcTko0X0qbYwB3 PzYF3CEvHs0p+izmcHQlb2A3P9O2GUY7/iaLpmlmje4xjHQU5lJ4wGOMEeA1wXiPqqkW mNcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mahsqZlr; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id o15-20020a170902d4cf00b00161a0786fc3si15802492plg.60.2022.06.05.22.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:05:13 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mahsqZlr; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C49267B9CF; Sun, 5 Jun 2022 21:14:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345774AbiFCRyy (ORCPT + 99 others); Fri, 3 Jun 2022 13:54:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345975AbiFCRui (ORCPT ); Fri, 3 Jun 2022 13:50:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B510DECE; Fri, 3 Jun 2022 10:46:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AF730604EF; Fri, 3 Jun 2022 17:46:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6CEDC385A9; Fri, 3 Jun 2022 17:46:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654278413; bh=Lsl4MGIj+lFgH3ZgJ+tEmOVp6Tpf+jsCIrpUeJnyOnc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mahsqZlrfDNO74CTk91BrnrQoRUD4i/BKqkmB4FXNPo2PPFYHk8WSf+AkMzf2u2LS jkE6cu7nUXpYt4xaW8DBWgAFtN97qh4q6ERFlOx4vKB8WMWZgbXIxEQWyXGpXZjp4h RThMTPBy9aPE4e2BmXM73N71HVDYf03jRA64bh2M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , Alexander Duyck , Al Viro , Davidlohr Bueso , Kuniyuki Iwashima , "Soheil Hassas Yeganeh" , "Sridhar Samudrala" , Andrew Morton Subject: [PATCH 5.10 09/53] pipe: make poll_usage boolean and annotate its access Date: Fri, 3 Jun 2022 19:42:54 +0200 Message-Id: <20220603173818.990315783@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173818.716010877@linuxfoundation.org> References: <20220603173818.716010877@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kuniyuki Iwashima commit f485922d8fe4e44f6d52a5bb95a603b7c65554bb upstream. 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/20220322002653.33865-1-kuniyu@amazon.co.jp Link: https://lkml.kernel.org/r/20220322002653.33865-2-kuniyu@amazon.co.jp Fixes: 3b844826b6c6 ("pipe: avoid unnecessary EPOLLET wakeups under normal loads") Signed-off-by: Kuniyuki Iwashima Cc: Alexander Duyck Cc: Al Viro Cc: Davidlohr Bueso Cc: Kuniyuki Iwashima Cc: "Soheil Hassas Yeganeh" Cc: "Sridhar Samudrala" Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/pipe.c | 2 +- include/linux/pipe_fs_i.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- a/fs/pipe.c +++ b/fs/pipe.c @@ -652,7 +652,7 @@ pipe_poll(struct file *filp, poll_table unsigned int head, tail; /* Epoll has some historical nasty semantics, this enables them */ - pipe->poll_usage = 1; + WRITE_ONCE(pipe->poll_usage, true); /* * Reading pipe state only -- no need for acquiring the semaphore. --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h @@ -71,7 +71,7 @@ struct pipe_inode_info { unsigned int files; unsigned int r_counter; unsigned int w_counter; - unsigned int poll_usage; + bool poll_usage; struct page *tmp_page; struct fasync_struct *fasync_readers; struct fasync_struct *fasync_writers;