Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp3145430imd; Mon, 29 Oct 2018 02:24:21 -0700 (PDT) X-Google-Smtp-Source: AJdET5f3vCdds2knbuKTEgYm+YScMe0yHWZBVPegdPpgULIfy/5wWOLi3TzwSYgoXSZXlXPhz85o X-Received: by 2002:a63:8549:: with SMTP id u70mr13024630pgd.401.1540805061188; Mon, 29 Oct 2018 02:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540805061; cv=none; d=google.com; s=arc-20160816; b=edS11ApLnOBk/9KU5zI3dkXTdkGCx+HukNdvphp4ZzABcfnojhoKhfCYEyWmb+eOgR /cIh6fj782fedfxTWNBUy8JITi5F+DZgXhLifEr0CKFA8W+5cM1aIxcUfHeoY6gZ62rD 4sXWd2rd3njR18OwAitWQ8m5PkSj/SU/2sR8N+1gKLP5aJ2hFfFFSdOaaPurStJL6FZ7 nrV5dFiubQ0VAUVSmPJQOQPKSpOMHVxQfKDHN8W5X15CpuC4KJwdjgVAD/II7fg3YwRV FhCADC+Q1rOnrFA66HjKDUxZb5wj0fqKngintL/BaUPTeSOG/F78d/cmGjveauKzU8p9 zCSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=gIbHfazCbL427uhX0bEmyj805xEbvdrUodbO/C3xOVI=; b=EhKd0WlYJcZBOcsye47ssCMLp3eoGcCq/fs7XKdFv6Gr5MEK5Vh3QYepDA4Bz98iD5 2CrpALzDwpilbEUMTj50Z6AkQca5ZRkN1JDPp3RSVT3dAr4I5zsSl7lE3WTZhYzVyFTT HpGFQNfZ8L+K+QeGax4IU2EgrPKjJ/9Iy6MRn2Dbo3RL8OYY9fpkIkMQA9WzSREowg3r rVzUCS+fPppk0lpBs9/AfzH5M8Uu2Eg9ka64K9ATQtzmiw2cc+tAPyEEEdV77Q1kzOeo GZF5KMAcJTpMrJ9gwvwtTG6/lNU686yYMw1pKvNXe0KcjXtsY/ISBaTbm70dNJridYIW qTcg== 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 202-v6si20054477pgb.63.2018.10.29.02.24.05; Mon, 29 Oct 2018 02:24:21 -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 S1729595AbeJ2SLM (ORCPT + 99 others); Mon, 29 Oct 2018 14:11:12 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:33235 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729466AbeJ2SLM (ORCPT ); Mon, 29 Oct 2018 14:11:12 -0400 Received: by mail-qt1-f194.google.com with SMTP id i15-v6so8379243qtr.0 for ; Mon, 29 Oct 2018 02:23:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gIbHfazCbL427uhX0bEmyj805xEbvdrUodbO/C3xOVI=; b=RqPIdTglozNMGVasdCwYbGdxwSCWIfsdO+svXSZFJ2jeyn6IRoiOxJQMi16Ce9GV6i k2P5Vonc81TI532KJjOiQ8BxsTdcpDVo6OYwKbsCiLXZJPgTkVRzMfdpKxHXg6l7jSED sWUwWlWTzX4PQKHny3L6UbNbuOe3h1QIsgO9Qi5dg39mw/iegtYOAzt42mcAMls4iObR kVZ/H2XmKqEp4BeugYFc99TFuj/kT+sgE+NKSsFSKzQiFc9pkDeZl4uepXi5T3BrdCp/ 7m5Xl1FiWNX9pd3UQVwjNXsD9oijJ4sarto/kDwV4RauXt5d+wyj4scmvsfFaTrNNMlH 8cpA== X-Gm-Message-State: AGRZ1gLbpto8KpOijn0bEdQdK9YYCxvn+6DhoCQk5YbfmDDUw0yvBuC+ FygL74Yk5vO2argRf0X5DbLE4wt50wlwUldq4F0= X-Received: by 2002:a0c:e202:: with SMTP id q2mr392880qvl.180.1540805003420; Mon, 29 Oct 2018 02:23:23 -0700 (PDT) MIME-Version: 1.0 References: <20181028230627.GA3420@andrea> <20181028231003.GA4021@andrea> <20181029012042.GR4170@linux.ibm.com> In-Reply-To: <20181029012042.GR4170@linux.ibm.com> From: Arnd Bergmann Date: Mon, 29 Oct 2018 10:23:07 +0100 Message-ID: Subject: Re: [RFR] Store tearing To: Paul McKenney Cc: andrea.parri@amarulasolutions.com, Peter Zijlstra , Josh Triplett , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 29, 2018 at 2:21 AM Paul E. McKenney wrote: > > On Mon, Oct 29, 2018 at 12:10:03AM +0100, Andrea Parri wrote: > > Hopefully, with Paul's proper email address this time, > > > > Andrea > > > > On Mon, Oct 29, 2018 at 12:06:27AM +0100, Andrea Parri wrote: > > > Hi, > > > > > > memory-barriers.txt says: > > > > > > [on "store tearing"] > > > > > > "In fact, a recent bug (since fixed) caused GCC to incorrectly use > > > this optimization in a volatile store.". > > > > > > I was wondering if you could help me retrieve some reference/discussions > > > about this? > > This was quite some time ago, but it involved a 32-bit volatile store > of a constant such as 0x10001. The machine in question had a narrow > store-immediate instruction, so the compiler emitted a pair of 16-bit > store-immediate instructions. This bug was fixed, though only after > significant screaming and shouting. A related issue I remember was on ARMv5 (an architecture without unaligned access) where a function like )not sure if this specific one triggers it, but something like it did) struct my_registers { u32 a; u32 b; u32 c; } __attribute__((packed)); #define __raw_writel(p, v) do { (volatile u32 __iomem *)(p) = (v); } while (0) void my_write_a(struct my_registers __iomem *r, u32 val) { __raw_writel(&r->a, val); } The above is undefined behavior because we cast from an unaligned data type to a 32-bit aligned type, and gcc resolved this by turning the intended 32-bit store into a set of 8 bit stores. We worked around this by changing __raw_writel() into a inline assembly that always uses a 32-bit store. Arnd