Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4297367ybl; Mon, 26 Aug 2019 08:22:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMkTEluHXSbV8pZhxC0kkTJHT+PcOyOWH0ujXIScS6GBcBBmZDcK1iaqDp8kfMKDf8H4w+ X-Received: by 2002:a65:6401:: with SMTP id a1mr16937301pgv.42.1566832938421; Mon, 26 Aug 2019 08:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566832938; cv=none; d=google.com; s=arc-20160816; b=iadQklKw0DxGbT7xZYa0s2Wlviro4GN4p4HYsPTjYn0I9ngSVh1YTDdVdd3rg8/rOA hSh5z7zcgGa0ZG5axfXXJvl5Jak3BJNyB0y4+HEH8bsmwq20BBYSvZ+XXvux60FhQICz 8PrjlpUhenK3x4b/2Ry9CRqsEzSg9I0ARljLEHiTtTvagCbwsDGcOkqyIHUDpMWf/vHi jgxBtSo+Phoz1c3iFA/sd37Y6hu7Ez9sFXU5HPidkgIsgkLVM4XGbIzK0WU5ZkuYi6CK CK0n1R8YT4ufGPDU7bFsdFbeRtt86LGhhSnUS+XatHJMsOQBuxQGao1lJ3EdnlwHo7gG QZYw== 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; bh=dyA4JwfhhEIinsoWhT9YwcG35Gt9UKbGKkxUBuzsn9g=; b=l9c8hVhIbTb4ccMGB138tGLbYQTO5ifuuHNj+laI3bUlG6izwOLGFTw1utJlF25GxT eXUCFrvuYGmEKDPXqVtYnQcMwYMbWCn9QHqADLEazp+K5MKPzBRTYRrF4iS3yn8mwpPm K7G+L668vED8ceOdrgZqwkAgN/gdayRuBRRVvtOEOeMKHtbP9tgTfZ/ZEw/fQ+CY+dql JTQ/CdZwszGC2Fk6coovSjcFxp4HUgWKbCc7xawbS3AycDMYi9U8fw81hePi0Ttj9zQa CTWZOmIxiMSPgImzeXPd/TuX9nAylSYZoBMiYtWG8Ia6OMbmQ3d6HT1uDm0N5siaTYc6 t9DA== 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 k8si10765207pfp.255.2019.08.26.08.22.03; Mon, 26 Aug 2019 08:22:18 -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 S1731442AbfHZOLB (ORCPT + 99 others); Mon, 26 Aug 2019 10:11:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:50748 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728769AbfHZOLB (ORCPT ); Mon, 26 Aug 2019 10:11:01 -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 18760AC32; Mon, 26 Aug 2019 14:10:59 +0000 (UTC) Date: Mon, 26 Aug 2019 16:10:58 +0200 From: Petr Mladek To: Andrea Parri Cc: Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Brendan Higgins , Peter Zijlstra , John Ogness , Thomas Gleixner , Linus Torvalds , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: Re: numlist_push() barriers Re: [RFC PATCH v4 1/9] printk-rb: add a new printk ringbuffer implementation Message-ID: <20190826141058.y6idkqpjqkpbv5s7@pathway.suse.cz> References: <20190807222634.1723-1-john.ogness@linutronix.de> <20190807222634.1723-2-john.ogness@linutronix.de> <20190823092109.doduc36avylm5cds@pathway.suse.cz> <20190826083436.GA3047@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190826083436.GA3047@andrea> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 2019-08-26 10:34:36, Andrea Parri wrote: > > > + /* > > > + * bA: > > > + * > > > + * Setup the node to be a list terminator: next_id == id. > > > + */ > > > + WRITE_ONCE(n->next_id, id); > > > > Do we need WRITE_ONCE() here? > > Both "n" and "id" are given as parameters and do not change. > > The assigment must be done before "id" is set as nl->head_id. > > The ordering is enforced by cmpxchg_release(). > > (Disclaimer: this is still a very much debated issue...) > > According to the LKMM, this question boils down to the question: > > Is there "ordering"/synchronization between the above access and > the "matching accesses" bF and aA' to the same location? > > Again according to the LKMM's analysis, such synchronization is provided > by the RELEASE -> "reads-from" -> ADDR relation. (Encoding address dep. > in litmus tests is kind of tricky but possible, e.g., for the pattern in > question, we could write/model as follows: > > C S+ponarelease+addroncena > > { > int *y = &a; > } > > P0(int *x, int **y, int *a) > { > int *r0; > > *x = 2; > r0 = cmpxchg_release(y, a, x); > } > > P1(int *x, int **y) > { > int *r0; > > r0 = READ_ONCE(*y); > *r0 = 1; > } > > exists (1:r0=x /\ x=2) Which r0 the above exists rule refers to, please? Do both P0 and P1 define r0 by purpose? > Then > > $ herd7 -conf linux-kernel.cfg S+ponarelease+addroncena > Test S+ponarelease+addroncena Allowed > States 2 > 1:r0=a; x=2; > 1:r0=x; x=1; > No > Witnesses > Positive: 0 Negative: 2 > Condition exists (1:r0=x /\ x=2) > Observation S+ponarelease+addroncena Never 0 2 > Time S+ponarelease+addroncena 0.01 > Hash=7eaf7b5e95419a3c352d7fd50b9cd0d5 > > that is, the test is not racy and the "exists" clause is not satisfiable > in the LKMM. Notice that _if the READ_ONCE(*y) in P1 were replaced by a > plain read, then we would obtain: > > Test S+ponarelease+addrnana Allowed > States 2 > 1:r0=x; x=1; > 1:r0=x; x=2; Do you have any explanation how r0=x; x=2; could happen, please? Does the ommited READ_ONCE allows to do r0 = (*y) twice before and after *r0 = 1? Or the two operations P1 can be called in any order? I am sorry if it obvious. Feel free to ask me to re-read Paul's articles on LWN more times or point me to another resources. > Ok > Witnesses > Positive: 1 Negative: 1 > Flag data-race [ <-- the LKMM warns about a data-race ] > Condition exists (1:r0=x /\ x=2) > Observation S+ponarelease+addrnana Sometimes 1 1 > Time S+ponarelease+addrnana 0.00 > Hash=a61acf2e8e51c2129d33ddf5e4c76a49 > > N.B. This analysis generally depends on the assumption that every marked > access (e.g., the cmpxchg_release() called out above and the READ_ONCE() > heading the address dependencies) are _single-copy atomic, an assumption > which has been recently shown to _not be valid in such generality: > > https://lkml.kernel.org/r/20190821103200.kpufwtviqhpbuv2n@willie-the-truck So, it might be even worse. Do I get it correctly? Best Regards, Petr