Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1854852yba; Thu, 25 Apr 2019 06:51:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkCq1a8Pe+CFRcbX9g2OlNBIw/xF7Hrj13rJOVmMutXsET4GbnQ+BE5YAZ4TSldpuVkrCP X-Received: by 2002:a63:f707:: with SMTP id x7mr36889759pgh.343.1556200263704; Thu, 25 Apr 2019 06:51:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556200263; cv=none; d=google.com; s=arc-20160816; b=UE2g5uxkmiUfj7iPLR+bzzH/eoMC6oaiXd1n/Jo1gGehlYGDJkOdS9jpWpgKOARiU2 0DVYQ6oLR2tMUQpGosjzBYH8ySkmER25DuzSlye6cquY3Fy/dhN9S7VQk9jRHa8/UzQy HtMQLbf/9ZppQ0ZZX+zXAZC41gKC21jY882GqelLR1a/di3frAJUFR2SmbE0ZgDOVJ+o +fxrix36ESb1nJYznDgHU7a71BhOq7Zzg437Rm9ICS54aRBOfxc+2Jpsx7/0WISXu2YE LAjUgr/tUtoDHgQ7yjp4YMN5CphM/2TW8SqEyIbsEfN7mlNuVMQSIHewyfFTsxwvKc9/ 4JvA== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pPtMBVUTCJglIJ029BF5lLSw6NXULkk4/tedW3lLCSY=; b=R2vHBmCFXhYM6E+8TjwQSpZv6cPdIBgvl/lYU/4nXbExus6B4vQ3v8MCXO98wtijH7 CHSm23LzAIO4sCnnTVtNUSPmeqVyrF9klXnFCbY4xDbB3VhyoqkIqu+pZHGVoSJfJDko 6VkoTobhcrwnlep2O/70skqL1lgDHjBy2otltXPlVQG+PBrMuvX1eLT57NqBXvq9ZYKN am5/cVbd1unqD1Jer6tl8iUbQBN1csXJQbc4HmfLcK5n0G/ZW4dNet/NqjYcg2IUB/cx kfVPRYwnTEOwlfmhKZ/4KSE+TFowyXb52rmzFDT5nqd6w3HAJTKzLnMbU5drlKXddqag Y+dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=gfGWPw49; 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 t18si8272967plr.71.2019.04.25.06.50.47; Thu, 25 Apr 2019 06:51:03 -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=bombadil.20170209 header.b=gfGWPw49; 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 S1729878AbfDYM0k (ORCPT + 99 others); Thu, 25 Apr 2019 08:26:40 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:36696 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728476AbfDYM0k (ORCPT ); Thu, 25 Apr 2019 08:26:40 -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-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To: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=pPtMBVUTCJglIJ029BF5lLSw6NXULkk4/tedW3lLCSY=; b=gfGWPw49Z+/4b1/zSJch/d0rs5 hWocoQ6J7Gl1yKSQiue1HfFwPKOcc6q2KU57TJeO9et8XZJfPhgr+b6YTIsLekS6yCZ7mznqMyOL3 bwUkSLbueJpTuoaZExDjv/IkF4aRWGLRsDrMynrgN1qtWt+Etu5xDE6t1fmq5n96AyNsHUZKkndDi U1R/heyu+LjTGcOqRdXdh2uGeu7axwC+I97PRZ2UPMnUt6wdhRx7zPILEFbkWvXlR3WS/eeDap5cM 8g/ZdeQg6YDfRExEo1PtRa61Q/RVV6zti1ZKBv7M10OD846wj7bHfSAzIJxKU5ivfnKbqDZdXM/+x PPtGTnlg==; 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 1hJdS9-0008Ny-DW; Thu, 25 Apr 2019 12:26:13 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id BCB7229C22B18; Thu, 25 Apr 2019 14:26:11 +0200 (CEST) Date: Thu, 25 Apr 2019 14:26:11 +0200 From: Peter Zijlstra To: huangpei@loongson.cn Cc: Paul Burton , "stern@rowland.harvard.edu" , "akiyks@gmail.com" , "andrea.parri@amarulasolutions.com" , "boqun.feng@gmail.com" , "dlustig@nvidia.com" , "dhowells@redhat.com" , "j.alglave@ucl.ac.uk" , "luc.maranget@inria.fr" , "npiggin@gmail.com" , "paulmck@linux.ibm.com" , "will.deacon@arm.com" , "linux-kernel@vger.kernel.org" , "torvalds@linux-foundation.org" , Huacai Chen Subject: Re: Re: Re: [RFC][PATCH 2/5] mips/atomic: Fix loongson_llsc_mb() wreckage Message-ID: <20190425122611.GT4038@hirez.programming.kicks-ass.net> References: <20190424123656.484227701@infradead.org> <20190424124421.636767843@infradead.org> <20190424211759.52xraajqwudc2fza@pburton-laptop> <2b2b07cc.bf42.16a52dc4e4d.Coremail.huangpei@loongson.cn> <20190425073348.GV11158@hirez.programming.kicks-ass.net> <5b13fd3b.c031.16a54452744.Coremail.huangpei@loongson.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5b13fd3b.c031.16a54452744.Coremail.huangpei@loongson.cn> 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, Apr 25, 2019 at 07:32:59PM +0800, huangpei@loongson.cn wrote: > > > If it is not LL/SC but other memory access from B on V, A's ll/sc can > > > follow the atomic semantics even if A violate the coherence protocol > > > in the same situation. > > > > *shudder*... > > > > C atomic-set > > > > { > > atomic_set(v, 1); > > } This is the initial state. > > > > > P1(atomic_t *v) > > { > > atomic_add_unless(v, 1, 0); > > } > > > > P2(atomic_t *v) > > { > > atomic_set(v, 0); > > } > > > > exists > > (v=2) > > > > So that one will still work? (that is, v=2 is forbidden) > > you mean C,P1, P2 on 3 different CPU? I do not know much about LKMM, can explain the test case more explicit? The 'C' is the language identifier, the 'atomic-set' is the litmus name. The unnamed block give the initial conditions. Pn blocks give code sequences for CPU n The 'exists' clause is evaluated after all Pn blocks are done. There's others in this thread that can point you to many papers and resources on these litmus test thingies. So basically the initial value of @v is set to 1. Then CPU-1 does atomic_add_unless(v, 1, 0) CPU-2 does atomic_set(v, 0) If CPU1 goes first, it will see 1, which is not 0 and thus add 1 to 1 and obtains 2. Then CPU2 goes and writes 0, so the exist clause sees v==0 and doesn't observe 2. The other way around, CPU-2 goes first, writes a 0, then CPU-1 goes and observes the 0, finds it matches 0 and doesn't add. Again, the exist clause will find 0 doesn't match 2. This all goes unstuck if interleaved like: CPU-1 CPU-2 xor t0, t0 1: ll t0, v bez t0, 2f sw t0, v add t0, t1 sc t0, v beqz t0, 1b (sorry if I got the MIPS asm wrong; it's not something I normally write) And the store-word from CPU-2 doesn't make the SC from CPU-1 fail.