Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3536007ybg; Fri, 25 Oct 2019 05:42:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRTDgWkpVG741oauprfwWScGbwygKSHaveQ/dfaAlAiBNn+NYKbjEN6+CbUKx8c4OboDlO X-Received: by 2002:a50:b901:: with SMTP id m1mr3659172ede.203.1572007367069; Fri, 25 Oct 2019 05:42:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572007367; cv=none; d=google.com; s=arc-20160816; b=VHdaXpORqb4jL0ionp8fAzejFOq5ePH61F5W/WOlLOP/WkdbMaai149Q3hv1YzJ/K6 8che3rl/RG3e7JM1Vwn+tUiApTxBZULeSIF0cDnRiD4geXu+vc/XMNcLvBZHNotDcCdB heq3MKGs9Iwc++3+duK2KNGsdja7ga3LhYdXrzjrJR9V+WaRYL1qCLdMEqEprS8tUneP +BwfKPgIW5DQyE3woGVoRjFz3gOKkXe8CNJj7uLwbWOAH+C7mRdm0qbOyYeU7gKq4Ac2 Trpn9354Ws73jvklEPXfuZ0ATloeQYue8ymamQC9xGTg33bGtUzyn0+E/eGpenbDJcgh JOYg== 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:dkim-signature; bh=fn71rS6ReHvy4UBLvwf94Jworjf0D0oVW+GNxGRscwE=; b=HQPjUUuOfpAV0VHmbJpUoFg3iXZyCSNzRr80fgBvFmpKKTLbjMm7pel266fe4k4wHy nFNiUpN9aGSKQOaPVme7ib9qkyJ35GhuY0swz1YRIjVEm+60uIhzfejZaSFZQe9Jkq2+ YUuYQAWuWmx/x0NBWZNbdetTL4gkSjDF+WFt/BpctL/SbWrzFrUj53OVu4PrdWMT05jl vpdZMze3pUFEnok+sefu0laRgR+wzZkjdd6zdqB7c3qV0wEbXhcVzwDLvMfRqijbC6dw FXGBulIiqhupVOpgfv2TfHjdSLZizUJ1Gz09MuQcw3z0mEWfp5xU1rCjB559bIsrnL9p ZWeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fCanMbbT; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11si1247966edb.100.2019.10.25.05.42.23; Fri, 25 Oct 2019 05:42:47 -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=pass header.i=@google.com header.s=20161025 header.b=fCanMbbT; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730557AbfJXLvf (ORCPT + 99 others); Thu, 24 Oct 2019 07:51:35 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:38477 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729203AbfJXLve (ORCPT ); Thu, 24 Oct 2019 07:51:34 -0400 Received: by mail-qk1-f193.google.com with SMTP id p4so23101922qkf.5 for ; Thu, 24 Oct 2019 04:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fn71rS6ReHvy4UBLvwf94Jworjf0D0oVW+GNxGRscwE=; b=fCanMbbThrjQ8BD1rKmwg7faRCTM9M3H48xUKhe8TvnCH1bzJfuGFeLvZ5W6+aAXV0 nm6R1jR9Hsv7ETPrzmmHJ6GzAoOKpw2yuc/ZnWZqvLypmiRPxlSBrFUYOowfg02DQCx5 nGOBmTZtj219z7P+SAO7uKe3pZChryDOLtwiIwUENGEvMy11k338XaT3srqPR4vgoWsb u+qIimV7ArVdxpwHJLD+te8PR7+I5bheOqtXrCcddeXoyFpVv0/2TEOlen9dBOUbLtiq Uth+M7QzikkXJPW/M9656ra3UVRFKMxE0TtCvOWisoK0c/gWpOo5fbJlJrxQxJWy9fVG fYGg== 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=fn71rS6ReHvy4UBLvwf94Jworjf0D0oVW+GNxGRscwE=; b=AgQe3DaU8HHXsW9HmksNcATWid5UZLeP37XqhPwTfEZGO7z8zoSmgsXVV5K+kfBQ8p +kV5q4OLHgFH37AQt2Te5skTuziLHeaSyFPeJbwLsAZyrjolr0IlC6pGAyVfWa2ysqro pqxd649oiCLxsAZATmZqWrToGvx5iYek8uN08aFz4QgAT/SOHqlbzCPggqR7H+QLnwFz 1ZYs0YYfVjkphQf/Gm18EAGPFVwi9qgcqq1X+Fgon8nootL2A+raIhATncfp2gNX7KXI lfYOTSV1knp3WvRgmEzurX5U8e/UFm6jYOH/o/N3qCGbnmUqiITpGUJ4BmrD0scPu/rF 1gaA== X-Gm-Message-State: APjAAAWgmhLtlCUwm/tfPhs68Ojrdb0u1GG5vzN1ahetZqY0V47bZL8h C/Z3zVr5exIDrkVziJJrBrskeYTtGr+1Eu36Wnozeg== X-Received: by 2002:a37:4a87:: with SMTP id x129mr2134986qka.43.1571917893077; Thu, 24 Oct 2019 04:51:33 -0700 (PDT) MIME-Version: 1.0 References: <20191009114809.8643-1-christian.brauner@ubuntu.com> <20191021113327.22365-1-christian.brauner@ubuntu.com> <20191023121603.GA16344@andrea.guest.corp.microsoft.com> <20191024113155.GA7406@andrea.guest.corp.microsoft.com> In-Reply-To: <20191024113155.GA7406@andrea.guest.corp.microsoft.com> From: Dmitry Vyukov Date: Thu, 24 Oct 2019 13:51:20 +0200 Message-ID: Subject: Re: [PATCH v6] taskstats: fix data-race To: Andrea Parri Cc: Christian Brauner , Will Deacon , LKML , bsingharora@gmail.com, Marco Elver , stable , syzbot , syzkaller-bugs 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 Thu, Oct 24, 2019 at 1:32 PM Andrea Parri wrote: > > > How these later loads can be completely independent of the pointer > > value? They need to obtain the pointer value from somewhere. And this > > can only be done by loaded it. And if a thread loads a pointer and > > then dereferences that pointer, that's a data/address dependency and > > we assume this is now covered by READ_ONCE. > > The "dependency" I was considering here is a dependency _between the > load of sig->stats in taskstats_tgid_alloc() and the (program-order) > later loads of *(sig->stats) in taskstats_exit(). Roughly speaking, > such a dependency should correspond to a dependency chain at the asm > or registers level from the first load to the later loads; e.g., in: > > Thread [register r0 contains the address of sig->stats] > > A: LOAD r1,[r0] // LOAD_ACQUIRE sig->stats > ... > B: LOAD r2,[r0] // LOAD *(sig->stats) > C: LOAD r3,[r2] > > there would be no such dependency from A to C. Compare, e.g., with: > > Thread [register r0 contains the address of sig->stats] > > A: LOAD r1,[r0] // LOAD_ACQUIRE sig->stats > ... > C: LOAD r3,[r1] // LOAD *(sig->stats) > > AFAICT, there's no guarantee that the compilers will generate such a > dependency from the code under discussion. Fixing this by making A ACQUIRE looks like somewhat weird code pattern to me (though correct). B is what loads the address used to read indirect data, so B ought to be ACQUIRE (or LOAD-DEPENDS which we get from READ_ONCE). What you are suggesting is: addr = ptr.load(memory_order_acquire); if (addr) { addr = ptr.load(memory_order_relaxed); data = *addr; } whereas the canonical/non-convoluted form of this pattern is: addr = ptr.load(memory_order_consume); if (addr) data = *addr; Moreover the second load of ptr is not even atomic in our case, so it is a subject to another data race?