Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp571648ybi; Fri, 31 May 2019 05:58:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7SKWHvI8rypv+55AWy+8s+fIDdy3OXGoBvqz7E0Q+uKF6rwddS1LrPmo5rdZxkRKo2hfJ X-Received: by 2002:a63:a055:: with SMTP id u21mr111737pgn.5.1559307511611; Fri, 31 May 2019 05:58:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559307511; cv=none; d=google.com; s=arc-20160816; b=M4QmsNV3uwv+5U9mxDdZ2baEIbz8mbdCqLFDlyOghfs+sJ5BiCDYXfKRU517ef9cXS PjJQTMsq8InISrRcfjWq6vw1DJskXzpn1StA91n+AHIoggHyOmaPWHqmWNc365avE4f5 ZIgWMbQHLEleSxYUqE237yWf1/4fG0/3tB2ATP2npR9xqgaxE7tPV8bPPKnSnkCl3LpU BcvSbHjLn2NYfHoSqtrd6ih1OaLIGXBU3Gf7yg7cAubGnGWpp6Agh5BaBJgk5ksTTrDR mDPoBCq8yU40KjvnTCB0APb0d6GMcnB8f6DaiLVwVhil82u/L3Qy8hnBMcGAuqJlEUiq 0BzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=b7LZUjLK+tz7tL5KZ+QWL/HSU+BQsQv0VhQ9biougFE=; b=fIbsmXOWwlC7ESmrXzTh821CpPQmIfsh9aX8AUbhddToYJtbd1ZZ6iYCPssgUZNZet cFEzNQipYTXo9kU9pkohUWEP3KUYxl24/ZSEtPS5TvsEHiZYTu6FdzjGADu5+yX6fnho DXmYnXz7EKNIqRygYQXUuhPqqHyjmV/LguBzNyvTlzzsTcj77iV7CKYBgjgZqYMZaI63 kF2FPXaUehyFXoIApRx2t39sLzW7iQAmP30lQ6VtcantElmhkrMfo2aG0a1UJw/WicfE q083S6Qa3WcqfvEfMUAsXTEV4ePsSyf/8J+9O9vgLWyi3fCzGWGCVyfzY7GY3C/vT3gY ZM9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=dnNcxCqp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d125si6110789pgc.414.2019.05.31.05.58.15; Fri, 31 May 2019 05:58:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=dnNcxCqp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727369AbfEaM4q (ORCPT + 99 others); Fri, 31 May 2019 08:56:46 -0400 Received: from merlin.infradead.org ([205.233.59.134]:60442 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726518AbfEaM4q (ORCPT ); Fri, 31 May 2019 08:56:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=b7LZUjLK+tz7tL5KZ+QWL/HSU+BQsQv0VhQ9biougFE=; b=dnNcxCqpe9gxZNCePCsB0Rzaz cDX1Yd7t3nwxYksQyUWkEUmzG3JcbBhftpTZzS0A3uP6pGYK1xztq6Ix4ph8jdN6Zck6GIHpA/quQ wIROK7thdgA6ZvTR30lN/U8CKkwEsCcKTUXsJzQyGqj/VTBZKDDpkxTZaz9X9En7Rno59hRmD8WfR MREiTGTimM5TAZCCqeJ3zPU48+JAbHzp+796Xy01vY+T41Gc7RqyYgSVuwnGQZmYfay5z7VFo6UaM IjYXfXBhK2pFCDJ2BIc2W4lBlpX7q5tutch4NbXEVMVsj2AeU9sSdmVT/tJfNlcNhgjJUKRmSWFzS HkETcVSUw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hWh5K-0007Mv-OF; Fri, 31 May 2019 12:56:38 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 6631320274AFF; Fri, 31 May 2019 14:56:36 +0200 (CEST) Date: Fri, 31 May 2019 14:56:36 +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 06/13] epoll: introduce helpers for adding/removing events to uring Message-ID: <20190531125636.GZ2606@hirez.programming.kicks-ass.net> References: <20190516085810.31077-1-rpenyaev@suse.de> <20190516085810.31077-7-rpenyaev@suse.de> <20190531095607.GC17637@hirez.programming.kicks-ass.net> <274e29d102133f3be1f309c66cb0af36@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <274e29d102133f3be1f309c66cb0af36@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 Fri, May 31, 2019 at 01:15:21PM +0200, Roman Penyaev wrote: > On 2019-05-31 11:56, Peter Zijlstra wrote: > > On Thu, May 16, 2019 at 10:58:03AM +0200, Roman Penyaev wrote: > > > +static inline bool ep_add_event_to_uring(struct epitem *epi, > > > __poll_t pollflags) > > > +{ > > > + struct eventpoll *ep = epi->ep; > > > + struct epoll_uitem *uitem; > > > + bool added = false; > > > + > > > + if (WARN_ON(!pollflags)) > > > + return false; > > > + > > > + uitem = &ep->user_header->items[epi->bit]; > > > + /* > > > + * Can be represented as: > > > + * > > > + * was_ready = uitem->ready_events; > > > + * uitem->ready_events &= ~EPOLLREMOVED; > > > + * uitem->ready_events |= pollflags; > > > + * if (!was_ready) { > > > + * // create index entry > > > + * } > > > + * > > > + * See the big comment inside ep_remove_user_item(), why it is > > > + * important to mask EPOLLREMOVED. > > > + */ > > > + if (!atomic_or_with_mask(&uitem->ready_events, > > > + pollflags, EPOLLREMOVED)) { > > > + unsigned int i, *item_idx, index_mask; > > > + > > > + /* > > > + * Item was not ready before, thus we have to insert > > > + * new index to the ring. > > > + */ > > > + > > > + index_mask = ep_max_index_nr(ep) - 1; > > > + i = __atomic_fetch_add(&ep->user_header->tail, 1, > > > + __ATOMIC_ACQUIRE); > > > + item_idx = &ep->user_index[i & index_mask]; > > > + > > > + /* Signal with a bit, which is > 0 */ > > > + *item_idx = epi->bit + 1; > > > > Did you just increment the user visible tail pointer before you filled > > the data? That is, can the concurrent userspace observe the increment > > before you put credible data in its place? > > No, the "data" is the "ready_events" mask, which was updated before, > using cmpxchg, atomic_or_with_mask() call. All I need is to put an > index of just updated item to the uring. > > Userspace, in its turn, gets the index from the ring and then checks > the mask. But where do you write the index into the shared memory? That index should be written before you publish the new tail.