From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4131AC04AB6 for ; Fri, 31 May 2019 09:56:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 145F526747 for ; Fri, 31 May 2019 09:56:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="GVEIhX3i" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727217AbfEaJ4W (ORCPT ); Fri, 31 May 2019 05:56:22 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:44530 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726002AbfEaJ4V (ORCPT ); Fri, 31 May 2019 05:56:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=T/f6xtXjUGNf45hEkflxN0bquHarry9NS4GCdXw6I0M=; b=GVEIhX3ihMVMz7nHk3GGeL09f HpIxgJJZhhrAKwMZ4dijsJ8DMeE6iK95J1jTSmWa5qSQIlILadqiYaMe4n8iGKQpz/HMnaEw3+AtV 1ayEHsRH7QaTKuAaqUbkq2r18KHKCbI+BzcKF6M5oQDvRWeDd9zHfeWdOMA7Ug4bMUK2nZwEUFfyb Cm577lhPr/B+QDoV6qDDG5JjstK9TmJRXpgp4TcStnBmAXKYvLPRmcU2Cnnxdl8OxfyDHwM3Ct6nJ zm6fAlJckmI4XHnZZfgWA3WXjTbI0g+LSb6Vu16/NbAXRuqL8P0eg2CH7iJRf1aKUg7I/vY0+d9RY cOuWieZ1w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hWeGo-0002Vc-O9; Fri, 31 May 2019 09:56:18 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 511FA201D5AB1; Fri, 31 May 2019 11:56:16 +0200 (CEST) Date: Fri, 31 May 2019 11:56:16 +0200 From: Peter Zijlstra To: Roman Penyaev Cc: azat@libevent.org, akpm@linux-foundation.org, viro@zeniv.linux.org.uk, torvalds@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 07/13] epoll: call ep_add_event_to_uring() from ep_poll_callback() Message-ID: <20190531095616.GD17637@hirez.programming.kicks-ass.net> References: <20190516085810.31077-1-rpenyaev@suse.de> <20190516085810.31077-8-rpenyaev@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190516085810.31077-8-rpenyaev@suse.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 16, 2019 at 10:58:04AM +0200, Roman Penyaev wrote: > Each ep_poll_callback() is called when fd calls wakeup() on epfd. > So account new event in user ring. > > The tricky part here is EPOLLONESHOT. Since we are lockless we > have to be deal with ep_poll_callbacks() called in paralle, thus > use cmpxchg to clear public event bits and filter out concurrent > call from another cpu. > > Signed-off-by: Roman Penyaev > Cc: Andrew Morton > Cc: Al Viro > Cc: Linus Torvalds > Cc: linux-fsdevel@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > > diff --git a/fs/eventpoll.c b/fs/eventpoll.c > index 2f551c005640..55612da9651e 100644 > --- a/fs/eventpoll.c > +++ b/fs/eventpoll.c > @@ -1407,6 +1407,29 @@ struct file *get_epoll_tfile_raw_ptr(struct file *file, int tfd, > } > #endif /* CONFIG_CHECKPOINT_RESTORE */ > > +/** > + * Atomically clear public event bits and return %true if the old value has > + * public event bits set. > + */ > +static inline bool ep_clear_public_event_bits(struct epitem *epi) > +{ > + __poll_t old, flags; > + > + /* > + * Here we race with ourselves and with ep_modify(), which can > + * change the event bits. In order not to override events updated > + * by ep_modify() we have to do cmpxchg. > + */ > + > + old = epi->event.events; > + do { > + flags = old; > + } while ((old = cmpxchg(&epi->event.events, flags, > + flags & EP_PRIVATE_BITS)) != flags); > + > + return flags & ~EP_PRIVATE_BITS; > +} AFAICT epi->event.events also has normal writes to it, eg. in ep_modify(). A number of architectures cannot handle concurrent normal writes and cmpxchg() to the same variable.