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 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0CF79CA5FB1 for ; Wed, 30 Sep 2026 08:10:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1436906.1655564 (Exim 4.92) (envelope-from ) id 1xBpO3-0006Fc-O3; Wed, 30 Sep 2026 08:09:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1436906.1655564; Wed, 30 Sep 2026 08:09:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xBpO3-0006FV-Kx; Wed, 30 Sep 2026 08:09:59 +0000 Received: by outflank-mailman (input) for mailman id 1436906; Wed, 30 Sep 2026 08:09:57 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xBpO1-0006FO-Rc for xen-devel@lists.xenproject.org; Wed, 30 Sep 2026 08:09:57 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.96) (envelope-from ) id 1xBpNz-006bW1-39; Wed, 30 Sep 2026 08:09:56 +0000 Received: from 224.pool85-54-217.dynamic.orange.es ([85.54.217.224] helo=localhost) by xenbits.xenproject.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xBpNz-00ApRZ-2o; Wed, 30 Sep 2026 08:09:56 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xenproject.org; s=20200302mail; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=GHIFH86UtOfNvIv7a+gfoCH7CvUd8xSKwPiGHsMnkEs=; b=Em/RtcHWtOtWuCcyusqfXpWCfb 4gMcPzeBGEu5jJkMO/tk1LAaONxBDS3I2BtgFqCIUJJchOvHJs5PSU1CLf8UvCK452zWejO3M8Wjm 9i2Gh8q7FV5/TXVKYy4D7IcR7K3byNyVY358WTBtZWcCUBXq79poBflemh18kwx0uCVw=; Date: Wed, 30 Sep 2026 10:09:49 +0200 From: Roger Pau =?utf-8?B?TW9ubsOp?= To: Jan Beulich Cc: Alejandro Vallejo , xen-devel@lists.xenproject.org, Andrew Cooper , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini Subject: Re: [PATCH v2 1/3] xen/rcu: introduce the concept of RCU epoch Message-ID: References: <20260925163025.65217-1-roger@xenproject.org> <20260925163025.65217-2-roger@xenproject.org> <50d1df6c-d969-470b-9b40-ca171c60618d@suse.com> <3e600ac0-3096-4cfb-967b-c6d87d8c04e6@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3e600ac0-3096-4cfb-967b-c6d87d8c04e6@suse.com> On Wed, Sep 30, 2026 at 07:58:55AM +0200, Jan Beulich wrote: > On 30.09.2026 00:14, Alejandro Vallejo wrote: > > On Tue Sep 29, 2026 at 4:52 PM CEST, Jan Beulich wrote: > >> On 29.09.2026 16:20, Roger Pau Monné wrote: > >>> On Mon, Sep 28, 2026 at 10:24:04AM +0200, Alejandro Vallejo wrote: > >>>> On Fri Sep 25, 2026 at 6:30 PM CEST, Roger Pau Monne wrote: > >>>>> static inline void rcu_quiesce_disable(void) > >>>>> { > >>>>> + unsigned int cpu = smp_processor_id(); > >>>>> + > >>>>> preempt_disable(); > >>>>> - this_cpu(rcu_lock_cnt)++; > >>>>> - barrier(); > >>>>> + if ( !ACCESS_ONCE(per_cpu(rcu_lock_cnt, cpu))++ ) > >>>>> + ACCESS_ONCE(per_cpu(rcu_lock_epoch, cpu)) = ACCESS_ONCE(rcu_epoch); > >>>> > >>>> I'm not terribly convinced about using ACCESS_ONCE() for atomic > >>>> accesses. In particular... > >>>> > >>>>> + smp_mb(); > >>>>> } > >>>>> > >>>>> static inline void rcu_quiesce_enable(void) > >>>>> { > >>>>> - barrier(); > >>>>> - this_cpu(rcu_lock_cnt)--; > >>>>> + > >>>>> + smp_mb(); > >>>>> + ACCESS_ONCE(this_cpu(rcu_lock_cnt))--; > >>>> > >>>> ... this variable is to be read by remote CPUs and autodecrement seems > >>>> like the wrong tool for an atomic decrement. > >>> > >>> I can use {read,write}_atomic() instead, but there's been a tendency > >>> to phase out the usage of those functions. On x86 this should be a > >>> plain `addl` or `subl` instruction (the non-locked version of > >>> atomic_{inc,dec}()). > > > > I don't think the compiler can merge volatile reads and writes. It can > > shatter them (thus my fear), but they are meant to be distinct because > > each might have different side effects. Jan already mentioned this in > > other words. > > > > You don't need an atomic decrement though, just an atomic write. Note > > IRQs restore it on exit and other CPUs don't write to it. > > > > unsigned int *lock_cnt = &this_cpu(rcu_lock_cnt); > > write_atomic(lock_cnt, *lock_cnt - 1); > > > > and this yields a plain mov, through a static inline stub (plus the > > mov from the read access + dec) > > > > The problem with ACCESS_ONCE() is that the write isn't guaranteed to be > > atomic. > > It may not be properly written down anywhere, but at least the compilers > we use are known to not tear aligned accesses up to a machine word in > width. Then I possibly don't need the ACCESS_ONCE() at all, as I was using it to guarantee unshattered accesses. However this should be written somewhere, maybe in docs/process/coding-best-practices.pandoc? Thanks, Roger.