Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp730656ybi; Fri, 31 May 2019 08:07:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAEf+vzVRTX4Je3d+I3ipFcCwdjE7DBDXbHnZA68kIow0YAJrcteJM1XwXeLpVpQQYkr10 X-Received: by 2002:a17:902:a508:: with SMTP id s8mr9884757plq.186.1559315273621; Fri, 31 May 2019 08:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559315273; cv=none; d=google.com; s=arc-20160816; b=J/9VUt774Ej90GmD6Q2lrg2uQwdDBhI0CiRkNqIEczGg1yXHJ50KFU8WPM0uj63NBm spDprA1yz6nnteSThdyRGMAbUO5MDUPZMHnx5dx+B3SwP5FIp5geS3FuMCTisPwW97nR bl7ioCIFFHhwE6DrbfQflbt91MvMV9B6AO3bWi1ZXfn4UZ4i1M/uvVO5E+0E30S7xsQd qPAzQ70dN2MMvbGEZ/UCoKyO5C0vocO3ilqx4fPJMu4W4LAQp/HUxxcUl3Joofq40YVD dMWgAPbJJGO297OvmbXs1jETOXYN7vMoa3AGvZ7Bve+EVzGLCZHEJGENTghBRAnyuGzi k/0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version; bh=WFkzRNpzII0S+wD7xgBXeZWHaQ62ycLKty4Q1AhLioY=; b=ofcadEgCHXUw7/CV25BarIEO1U826j3cUlixBBL/L31FmbWCuu2WuAc+G17DvzgmLO wPsxVXxqWojfqrC+Co7sEYiui4gVoVyMT9TxMBvQ9j6OBNcyL8mdRN/AswkCkAeJjCUG MRinBfSkBw2Cb5Pe3+riRu8E/OrbaxyVi1kJPV3Xpw4Fsf+NP/Alu5Tb5xY6TMvh6Tab 6/nrGRsKnXT+83ZQgz0vCJc/dBKX++uCqvplCXnGMUG8bBYkNU1T/0xfYHR5nNGANdhJ NXHvJkRAsIzFiCzXqwVc4uIqPV9ibUBYqGQxNSfRS6wrbzslXodWQcGLJzdcKBTVaW17 m4jQ== ARC-Authentication-Results: i=1; mx.google.com; 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 o4si6245818pgg.49.2019.05.31.08.07.29; Fri, 31 May 2019 08:07:53 -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; 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 S1726816AbfEaPFR (ORCPT + 99 others); Fri, 31 May 2019 11:05:17 -0400 Received: from mx2.suse.de ([195.135.220.15]:39034 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726037AbfEaPFR (ORCPT ); Fri, 31 May 2019 11:05:17 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4236DAD9C; Fri, 31 May 2019 15:05:16 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 31 May 2019 17:05:16 +0200 From: Roman Penyaev To: Peter Zijlstra 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() In-Reply-To: <20190531130516.GA2606@hirez.programming.kicks-ass.net> References: <20190516085810.31077-1-rpenyaev@suse.de> <20190516085810.31077-8-rpenyaev@suse.de> <20190531095616.GD17637@hirez.programming.kicks-ass.net> <98971429dc36e8a2e3417af1744de2b2@suse.de> <20190531130516.GA2606@hirez.programming.kicks-ass.net> Message-ID: <8dc64c770b693aeb2040cca7ec697a7a@suse.de> X-Sender: rpenyaev@suse.de User-Agent: Roundcube Webmail Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-05-31 15:05, Peter Zijlstra wrote: > On Fri, May 31, 2019 at 01:22:54PM +0200, Roman Penyaev wrote: >> On 2019-05-31 11:56, Peter Zijlstra wrote: >> > On Thu, May 16, 2019 at 10:58:04AM +0200, Roman Penyaev wrote: > >> > > +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. >> >> Yes, we race with the current function and with ep_modify(). Then, >> ep_modify() >> should do something as the following: >> >> - epi->event.events = event->events >> + xchg(&epi->event.events, event->events); >> >> Is that ok? > > That should be correct, but at that point I think we should also always > read the thing with READ_ONCE() to avoid load-tearing. And I suspect it > then becomes sensible to change the type to atomic_t. But it seems if we afraid of load tearing that should be fixed separately, independently of this patchset, because epi->event.events is updated in ep_modify() and races with ep_poll_callback(), which reads the value in couple of places. Probably nothing terrible will happen, because eventually event comes or just ignored. > atomic_set() vs atomic_cmpxchg() only carries the extra overhead on > those 'dodgy' platforms. > >> Just curious: what are these archs? > > Oh, lovely stuff like parisc, sparc32 and arc-eznps. See > arch/parisc/lib/bitops.c:__cmpxchg_*() for example :/ Those systems > only > have a single truly atomic op (something from the xchg / test-and-set > family) and the rest is fudged on top of that. Locks, nice. -- Roman