Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3476847ybg; Fri, 25 Oct 2019 04:50:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyoYvuU6tpQr+0KmRY2wy3Ifjp6LOf8BBjjMoRGnOabinjl4zRGrkaImIAe20Yru4vN3ENf X-Received: by 2002:a17:906:13c6:: with SMTP id g6mr2405062ejc.2.1572004242973; Fri, 25 Oct 2019 04:50:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572004242; cv=none; d=google.com; s=arc-20160816; b=nBUXIiU5RC4yuW4FWg5ikQpOu9yDQylMUpDZ9s9d9ZOpkNIA9/k9L/lewS6ru9uZvy 1THIAdDiXp9JLqK9MQ/6Hee+5581HB0UnC1dF54k+FfriMH4x1gnws5+KiAQ/MDw1W1b IlfwPwL4WbwhH+RnBI46fWq/VU3KxFlrjV9VwccP5MdOS574nchSX4p/qx8268pTy6vE qko5La7Auhpg9rOoBOx0gC5OjNv7owMyMbsessXlPcZyVSMWnJSRjbsGgZu1uCPQnBfp U8tPaT9/ese+qUJkR0cdZz5Aat/6n/VnAnJmpnHcC6wtv4X+ME/ZDSJzmavrlKWKqAbS bE3Q== 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; bh=ezqbNh15duAOX1v5yZVQ7n93181cP/lXsuMK608ICgc=; b=tkBX/sTMEfaOsoeXimr/gXS41Kp52782vOiVY/aZsFfdwOBXUx6dm2OBu+9txPEW1E txvHwkoz2vHKBtSz7W/EuyUWSoxEBWGUsjHRW5rxrrANqaohmO7wx3zU+kTjYD7keZCR sumvPdIEiVyLluYDjbj1XU18GMbtKgtHZUbOLWR38zZ6FB1jlZGB6NAlhSX6UWSRKQRV d1nsY6hJi1j5d0fISGjPkFcBTxE6Wfy63KT/642Pyz3xwe3ZMn+qRW2CAFdyxelN8Go2 76rKedpY3fm3jJYiA9pzPX6l6n7wp7gmbWh5M5946hzOjVuVJPAEf6E9K9DrjjMshGoL 8EoA== 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 ox5si1051624ejb.252.2019.10.25.04.50.19; Fri, 25 Oct 2019 04:50:42 -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 S2502507AbfJXNVo (ORCPT + 99 others); Thu, 24 Oct 2019 09:21:44 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:38776 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730061AbfJXNVo (ORCPT ); Thu, 24 Oct 2019 09:21:44 -0400 Received: from [213.220.153.21] (helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iNd3Z-0002J4-Se; Thu, 24 Oct 2019 13:21:37 +0000 Date: Thu, 24 Oct 2019 15:21:37 +0200 From: Christian Brauner To: Dmitry Vyukov Cc: Andrea Parri , Will Deacon , LKML , bsingharora@gmail.com, Marco Elver , stable , syzbot , syzkaller-bugs Subject: Re: [PATCH v6] taskstats: fix data-race Message-ID: <20191024132136.jknzt7rgjssgv5b6@wittgenstein> 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> <20191024130502.GA11335@andrea.guest.corp.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 03:13:48PM +0200, Dmitry Vyukov wrote: > On Thu, Oct 24, 2019 at 3:05 PM Andrea Parri wrote: > > > > On Thu, Oct 24, 2019 at 01:51:20PM +0200, Dmitry Vyukov wrote: > > > 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; > > > > No, I'd rather be suggesting: > > > > addr = ptr.load(memory_order_acquire); > > if (addr) > > data = *addr; > > > > since I'd not expect any form of encouragement to rely on "consume" or > > on "READ_ONCE() + true-address-dependency" from myself. ;-) > > But why? I think kernel contains lots of such cases and it seems to be > officially documented by the LKMM: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/memory-model/Documentation/explanation.txt > address dependencies and ppo You mean this section: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/memory-model/Documentation/explanation.txt#n955 and specifically: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/memory-model/Documentation/explanation.txt#n982 ?