Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp348038pxf; Wed, 7 Apr 2021 00:37:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfZg/hbynJqEsgCFBGfE8alCzyID15K2ukppYLJQlX7o8R/2rQqWyub336ttm/hlE1s/dW X-Received: by 2002:a92:c56f:: with SMTP id b15mr1708672ilj.41.1617781074328; Wed, 07 Apr 2021 00:37:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617781074; cv=none; d=google.com; s=arc-20160816; b=vHm7vaG3+T9SLstiPCcEtsiXhhhvAMIt7LFhTn3fr12Jd6tJ+ZWGSk8Zm6yDogEt+Z 5m59obVkLEt7AIL85e2WMqO3ngEOpERQ7yRkLW+Jdn4MqJ1c73PEwr4WloUSRMxuhpZY SfePyxvzs7IsZnjP1BhFcp1aCm2u55mKWSxbvqYT9vklxPckipzwcgZHNsRlYmQOyfUm GMbzPO0rUbt/bu+65muyWMoasAFx2vu3VoQ3xPj0ClKF8so8eo27JxCOTHKfdZBmPFsc cnbWOcVfExVseJ+TUkpKqNLK+LbRlWDKX2CnRIF/g32BKWqSkcfBjlKCOGFMtgdXofJI mxQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=HjIY6aWZ/uvHhM5BKnP3jscK0FBNItngTC5eimC1oFI=; b=Nl78O+SFrlgUe1DsbiD8+C13w/iGV5eTwtMjBBoJf644ZltRi/SL3us/dVCcb2HZDu mnLNBCCHI7oNY57EawKlVXXRjXP6kDePv18vKSVS+Hp4ZxRLRYnJfsSBXSZkUU7pOoPr Q6NhP4GBNO4mmRyOGqgbGnpDcHKQkQ/8vHvuBRTDSfsmzLO6VTH36VtvO9kHyHyXDTB/ RNjyY6tIaAI+vJTij7TNm2ofvwhLV5Slfw3fIz53U2aPWgonaEN2eYxakYsjQp9rxIDj hdD/lCq18Qoe7ZXvUIlJD101mOHV2cX6ViwOyXPmGxC5d30lwH3xZoHaKMciD2ZSbx9n /TFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V+JG4luC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r9si152791jap.88.2021.04.07.00.37.42; Wed, 07 Apr 2021 00:37:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V+JG4luC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346915AbhDFRZh (ORCPT + 99 others); Tue, 6 Apr 2021 13:25:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232578AbhDFRZf (ORCPT ); Tue, 6 Apr 2021 13:25:35 -0400 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A429C06174A; Tue, 6 Apr 2021 10:25:27 -0700 (PDT) Received: by mail-qv1-xf2c.google.com with SMTP id fn8so2709266qvb.5; Tue, 06 Apr 2021 10:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=HjIY6aWZ/uvHhM5BKnP3jscK0FBNItngTC5eimC1oFI=; b=V+JG4luCR0b56/p+Hv4EgOuljif4M7BrF1R+nfoI5OsEwCVXQqTm/WwMZ681EicIT+ jf1Uwmh7DH9rA54IBEqp/nq7K6NXga/xs1A+ItmZm9vokyJcjNPKYj7O5qcA53sA/Twp 2o8bvMag0JtT8juqcTglS+J12WkTotgnB/WApgui2mLBFslT1KL/GQ6e+qHE8b9eravs GdiEE9jfH5w/LeYxWmNa5+3jLpkvlMXRlL5RYS0sYuwKUTcVktfyuynNAASH3pallAwB wq2kdPf+QEEK58vg9OfEGamcBLde0344bTdvxQutG8G6qYTURwgul5zLA6SXB1tqWxa/ 8Q7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=HjIY6aWZ/uvHhM5BKnP3jscK0FBNItngTC5eimC1oFI=; b=SsnW7AMJlmBZ45JfFWikH6O/K0TuRalBy98amYpwsFHg6/vrYxwqfvYVSWRIjGWwqt OiPDM5eBnab6/rw90dOpFi3Cb7q6xGA+T/8MxIynkAiS/nU1BPNDIphEzng6wrkNX3oo 5w5xZCS0tjyva9MwM3hjROkVbHRfhTe5N3R38YMqVA1aAkAMvairyUzumaRI7iLQVWE+ MkBjsc/pSySUtct3Hjsnox9RUG2hxjEms/eLbKP48Uo1k2aBEyDzgcHmvVHKp016kzxY eO3usm8VnjGT3keW2/4jN4vAog+sERXaETzXX5/la63+kuX3En1fSIOiL/zs38AKs2kQ u5SQ== X-Gm-Message-State: AOAM530ARfPsK5AUDnFDVmLsZHTWMLbWMwj0MiIfYBzmifyLzLGTa3bH 1z/zsQUe0egXbL38wS/VlcfE1TYpeJw= X-Received: by 2002:ad4:4cca:: with SMTP id i10mr29832924qvz.49.1617729926315; Tue, 06 Apr 2021 10:25:26 -0700 (PDT) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id x14sm16025449qkx.112.2021.04.06.10.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 10:25:25 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailauth.nyi.internal (Postfix) with ESMTP id 2BABF27C0054; Tue, 6 Apr 2021 13:25:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 06 Apr 2021 13:25:25 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudejhedgiedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdortddttddvnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrth htvghrnheptdevvdfhkeevuedtueetgeefvdeuveehteelfeehfeelteetuefffeelleel ueevnecuffhomhgrihhnpehrihhstghvrdhorhhgpdhkvghrnhgvlhdrohhrghenucfkph epudefuddruddtjedrudegjedruddvieenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonh grlhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvghnghep pehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvg X-ME-Proxy: Received: from localhost (unknown [131.107.147.126]) by mail.messagingengine.com (Postfix) with ESMTPA id 9C6FD1080063; Tue, 6 Apr 2021 13:25:23 -0400 (EDT) Date: Wed, 7 Apr 2021 01:24:12 +0800 From: Boqun Feng To: Guo Ren Cc: Peter Zijlstra , linux-riscv , Linux Kernel Mailing List , linux-csky@vger.kernel.org, linux-arch , Guo Ren , Will Deacon , Ingo Molnar , Waiman Long , Arnd Bergmann , Anup Patel Subject: Re: [PATCH v4 3/4] locking/qspinlock: Add ARCH_USE_QUEUED_SPINLOCKS_XCHG32 Message-ID: References: <1616868399-82848-1-git-send-email-guoren@kernel.org> <1616868399-82848-4-git-send-email-guoren@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 31, 2021 at 11:22:35PM +0800, Guo Ren wrote: > On Mon, Mar 29, 2021 at 8:50 PM Peter Zijlstra wrote: > > > > On Mon, Mar 29, 2021 at 08:01:41PM +0800, Guo Ren wrote: > > > u32 a = 0x55aa66bb; > > > u16 *ptr = &a; > > > > > > CPU0 CPU1 > > > ========= ========= > > > xchg16(ptr, new) while(1) > > > WRITE_ONCE(*(ptr + 1), x); > > > > > > When we use lr.w/sc.w implement xchg16, it'll cause CPU0 deadlock. > > > > Then I think your LL/SC is broken. > No, it's not broken LR.W/SC.W. Quote <8.3 Eventual Success of > Store-Conditional Instructions>: > > "As a consequence of the eventuality guarantee, if some harts in an > execution environment are > executing constrained LR/SC loops, and no other harts or devices in > the execution environment > execute an unconditional store or AMO to that reservation set, then at > least one hart will > eventually exit its constrained LR/SC loop. By contrast, if other > harts or devices continue to > write to that reservation set, it is not guaranteed that any hart will > exit its LR/SC loop." > > So I think it's a feature of LR/SC. How does the above code (also use > ll.w/sc.w to implement xchg16) running on arm64? > > 1: ldxr > eor > cbnz ... 2f > stxr > cbnz ... 1b // I think it would deadlock for arm64. > > "LL/SC fwd progress" which you have mentioned could guarantee stxr > success? How hardware could do that? > Actually, "old" riscv standard does provide fwd progress ;-) In https://riscv.org/wp-content/uploads/2017/05/riscv-spec-v2.2.pdf Section "7.2 Load-Reserved/Store-Conditional Instructions": """ One advantage of CAS is that it guarantees that some hart eventually makes progress, whereas an LR/SC atomic sequence could livelock indefinitely on some systems. To avoid this concern, we added an architectural guarantee of forward progress to LR/SC atomic sequences. The restrictions on LR/SC sequence contents allows an implementation to **capture a cache line on the LR and complete the LR/SC sequence by holding off remote cache interventions for a bounded short time**. """ The guarantee is removed later due to "Earlier versions of this specification imposed a stronger starvation-freedom guarantee. However, the weaker livelock-freedom guarantee is sufficient to implement the C11 and C++11 languages, and is substantially easier to provide in some microarchitectural styles." But I take it as an example that hardware can guarantee this. Regards, Boqun > > > > That also means you really don't want to build super complex locking > > primitives on top, because that live-lock will percolate through. > > > > Step 1 would be to get your architecute fixed such that it can provide > > fwd progress guarantees for LL/SC. Otherwise there's absolutely no point > > in building complex systems with it. > -- > Best Regards > Guo Ren > > ML: https://lore.kernel.org/linux-csky/