Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp293268ybi; Fri, 31 May 2019 01:23:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgQYHexveexaM5quCIbKJjfV17OxbvJW16v/gK1CKPYuazZFyM5a+3BQXj7kPDrJfM5bhn X-Received: by 2002:a17:90a:344c:: with SMTP id o70mr7506121pjb.21.1559290992815; Fri, 31 May 2019 01:23:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559290992; cv=none; d=google.com; s=arc-20160816; b=XwFly5x4Wy40DGoMLIvU6W0DUIWu047A1qRkD6asHJTzdMK2GPxIgB4O7/rIra/JYc KtBMy5Sxlv0sdgzikRw49uwiH36Oi9ONBzivaHwnbWL6Y884Ce50XD6Fn/Cm1hL6lv0v qLOHe9KmpF2Y7zBPq9pw+fxryW0oDVyNJXEzxTFBe4md8+0Ssh/u5Ng3xnllvM7yRSdV jB9BL2bN+N5HXS6nVBkCVGkEh511xXkrWL4V7fcIzkjV/KFOpX0gGV3zs1dom7AxF35h uoON7RW4NIrhkcF6Nzz3m9DtWl+9Sa3srv8/IAGk8LkUqF9Rkzf1S6YmpnCWFit0+7TD SmbQ== 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:dkim-signature; bh=69CupxyG5Rlyr8SYoaqVqCnhz38WNqA+v67FqR5/kA4=; b=FO8nmXbnNkEQoH0xl96bl87kSndljn8KwIX0iNGHRCJc3oviqcp8zaBVPzofpJJ+KZ g94Aiu5Y4whD5bdej56ry82CFsHtYZBdzaamO/7QW9qplD0Zg61uZuhN1bZFdbDu8pXN ksfCX4VATUvaoMOPluoG1KqnAkfbqjVD3IdG7a5K8ra/wV8JsHOFYiFI3dAIxWSC87Q0 XZ87j8y7SzwPGESqQ92ryc5TvGinPQkcic1pI88QLIBbA2lEzD+ccntP0KbNy/8KOcLN eafABNhGCuQiijDTBB9lp1Fva9dgScSdPPKhnUWrdM4z6GHOQVoaEa6HzsBsZsC8bXYv Fs+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Py1T06+W; 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 d4si5409003pla.358.2019.05.31.01.22.56; Fri, 31 May 2019 01:23:12 -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=Py1T06+W; 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 S1725963AbfEaIVR (ORCPT + 99 others); Fri, 31 May 2019 04:21:17 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:45044 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726158AbfEaIVR (ORCPT ); Fri, 31 May 2019 04:21:17 -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-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding: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=69CupxyG5Rlyr8SYoaqVqCnhz38WNqA+v67FqR5/kA4=; b=Py1T06+Wo7xMPlKFUiERWjzbv 4c72RFv3/ROXRSF66bTCVr+EkGC6sZuioZ99pCQFjfZ27+Bx9YChKXZMOpm+IchXIHjfdY2VN2OaI 3/c2WeHU6g9KJvxlKv3OBcJSGnckKLMx2r/E2CwJUI7dXDy9grF/CA1yy9M+v4Wo41I26lMZJEsN+ iLy526y4tQXbawv107JkqCYMW0gefHicqzR18/krhuXs3pS8G9HZXFpF3qKXQmuYF07vMq05atpAU E00BtBHHTL65hUgUCFcNURZZbqy74Uho7oqzdRbs8PAFTbiGKQk7922Sm620B6h/zl8BwmeYmGJtO NpjS1yIiQ==; 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 1hWcmo-0006v5-IY; Fri, 31 May 2019 08:21:14 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E7F1E201B8CFE; Fri, 31 May 2019 10:21:12 +0200 (CEST) Date: Fri, 31 May 2019 10:21:12 +0200 From: Peter Zijlstra To: Vineet Gupta Cc: Will Deacon , "Paul E. McKenney" , arcml , lkml , "linux-arch@vger.kernel.org" Subject: Re: single copy atomicity for double load/stores on 32-bit systems Message-ID: <20190531082112.GH2623@hirez.programming.kicks-ass.net> References: <2fd3a455-6267-5d21-c530-41964a4f6ce9@synopsys.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2fd3a455-6267-5d21-c530-41964a4f6ce9@synopsys.com> 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, May 30, 2019 at 11:22:42AM -0700, Vineet Gupta wrote: > Hi Peter, > > Had an interesting lunch time discussion with our hardware architects pertinent to > "minimal guarantees expected of a CPU" section of memory-barriers.txt > > > | (*) These guarantees apply only to properly aligned and sized scalar > | variables. "Properly sized" currently means variables that are > | the same size as "char", "short", "int" and "long". "Properly > | aligned" means the natural alignment, thus no constraints for > | "char", two-byte alignment for "short", four-byte alignment for > | "int", and either four-byte or eight-byte alignment for "long", > | on 32-bit and 64-bit systems, respectively. > > > I'm not sure how to interpret "natural alignment" for the case of double > load/stores on 32-bit systems where the hardware and ABI allow for 4 byte > alignment (ARCv2 LDD/STD, ARM LDRD/STRD ....) Natural alignment: !((uintptr_t)ptr % sizeof(*ptr)) For any u64 type, that would give 8 byte alignment. the problem otherwise being that your data spans two lines/pages etc.. > I presume (and the question) that lkmm doesn't expect such 8 byte load/stores to > be atomic unless 8-byte aligned > > ARMv7 arch ref manual seems to confirm this. Quoting > > | LDM, LDC, LDC2, LDRD, STM, STC, STC2, STRD, PUSH, POP, RFE, SRS, VLDM, VLDR, > | VSTM, and VSTR instructions are executed as a sequence of word-aligned word > | accesses. Each 32-bit word access is guaranteed to be single-copy atomic. A > | subsequence of two or more word accesses from the sequence might not exhibit > | single-copy atomicity > > While it seems reasonable form hardware pov to not implement such atomicity by > default it seems there's an additional burden on application writers. They could > be happily using a lockless algorithm with just a shared flag between 2 threads > w/o need for any explicit synchronization. If you're that careless with lockless code, you deserve all the pain you get. > But upgrade to a new compiler which > aggressively "packs" struct rendering long long 32-bit aligned (vs. 64-bit before) > causing the code to suddenly stop working. Is the onus on them to declare such > memory as c11 atomic or some such. When a programmer wants guarantees they already need to know wth they're doing. And I'll stand by my earlier conviction that any architecture that has a native u64 (be it a 64bit arch or a 32bit with double-width instructions) but has an ABI that allows u32 alignment on them is daft.