Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4033871ybl; Mon, 3 Feb 2020 11:14:16 -0800 (PST) X-Google-Smtp-Source: APXvYqwobmdiqb5ug41Xd3RdA/DW/iy3M2CzNpbKa20kGwn8/jZknTmX0WEOXg20Afrozv5r0Saa X-Received: by 2002:a05:6808:611:: with SMTP id y17mr388159oih.146.1580757256677; Mon, 03 Feb 2020 11:14:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580757256; cv=none; d=google.com; s=arc-20160816; b=mmvf5kUAWizkKF/80VQ/i+tIaepxpAVPlKIIcy56CHamQk3tNhX/3rUfu3gfnRFBoB yLTmc55stZ4bPEf3wLNtBmrmAlSUxqLuwciQCo9fMjyUuew5ot/BEvNazu1r5YCIgpWp 4R1o8pNSyZWc27nA9lj817yBXmBkmOxD0RFh6RyHO8DCrsgHWzTMv74CaEuDRGc+s/3W MnvziuKFKXNX/gKxJLlb3iV7OtdZ6tTI176EiexOKdD+mZjasKRrzF6Y0+nxBILGWDPO rxFFY4eeJqwfQ6kRWxs1LTyPth+0bCuasgfvK0fj7N4MoVnHGNtT4LSC6GjfNF6H0ooT xTWw== 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=p8Qj2uLVBX/7jV3+2/yeMNOycftVBG4WXlsSS0FrwIA=; b=BY/JuIKdpPlAWAHfdsXahvswDHZopR0Nw6DxpPVeX6kVa+rD1uvr3rakNiktTHnS8L bTieVxgR5NzxIUJg7TW+XtriDETkGNDOAX9M6HKtR04258Okk1hEqXPeSvyNbRyWXxdo soxRaymVtRkczjWfKwb6b6FZgH4rr/jA9AuUG7PDTPaHzFqLo5Ie4ejRLCne43qNPXn6 XgjLYdS4XpN82jTnN5YhBwp4XzflKytE2X0dZHeHYzP/sovopMFlAVyFDSrEXkwCRIhx ogSaYdSOdNj0IKYn5ZgHRx2RDzmt7K1wIyq4mhJT2s+wJtj2zFq1n+yGwALQtCWZspX8 LP9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m83JC6On; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e26si4504146oii.88.2020.02.03.11.14.04; Mon, 03 Feb 2020 11:14:16 -0800 (PST) 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=@kernel.org header.s=default header.b=m83JC6On; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729730AbgBCS1n (ORCPT + 98 others); Mon, 3 Feb 2020 13:27:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:34800 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727124AbgBCS1n (ORCPT ); Mon, 3 Feb 2020 13:27:43 -0500 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E5DA72082E; Mon, 3 Feb 2020 18:27:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580754462; bh=0BstmI3p+nE92cj5WvZfcDoqlVcc3+pYnKpm6RsOL3M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=m83JC6OnLDFTNf70zDGiojrB0WGaT6y/KLoEml5T/LD7vZ423WW9x07Im02EtKAil ji8IZ8lXqnoL5b7+m/ba6iNIugWLYegBvKLv1agUA++QFzXNjmvbHCSjMu5F5PTEfy SHAR+w1HBgDRXWJnSicBztoa3EYoXMRPaS6o9iJM= Date: Mon, 3 Feb 2020 18:27:37 +0000 From: Will Deacon To: "Paul E. McKenney" Cc: David Laight , 'Eric Dumazet' , Peter Zijlstra , Thomas Gleixner , the arch/x86 maintainers , LKML , Marco Elver Subject: Re: Confused about hlist_unhashed_lockless() Message-ID: <20200203182737.GB12136@willie-the-truck> References: <20200131164308.GA5175@willie-the-truck> <20200131184322.GA11457@worktop.programming.kicks-ass.net> <26258e70c35e4c108173a27317e64a0b@AcuMS.aculab.com> <20200203155839.GK2935@paulmck-ThinkPad-P72> <20200203160227.GA7274@willie-the-truck> <20200203172947.GM2935@paulmck-ThinkPad-P72> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200203172947.GM2935@paulmck-ThinkPad-P72> 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 Hi Paul, On Mon, Feb 03, 2020 at 09:29:47AM -0800, Paul E. McKenney wrote: > On Mon, Feb 03, 2020 at 04:02:28PM +0000, Will Deacon wrote: > > On Mon, Feb 03, 2020 at 07:58:39AM -0800, Paul E. McKenney wrote: > > > On Mon, Feb 03, 2020 at 03:45:54PM +0000, David Laight wrote: > > > > From: Eric Dumazet > > > > > Sent: 31 January 2020 18:53 > > > > > > > > > > On Fri, Jan 31, 2020 at 10:48 AM Eric Dumazet wrote: > > > > > > > > > > > > > > > > > This is nice, now with have data_race() > > > > > > > > > > > > Remember these patches were sent 2 months ago, at a time we were > > > > > > trying to sort out things. > > > > > > > > > > > > data_race() was merged a few days ago. > > > > > > > > > > Well, actually data_race() is not there yet anyway. > > > > > > > > Shouldn't it be NO_DATA_RACE() ?? > > > > > > No, because you use data_race() when there really are data races, but you > > > want KCSAN to ignore them. For example, diagnostic code that doesn't > > > participate in the actual concurrency design and that doesn't run all > > > that often might use data_race(). For another example, if a developer > > > knew that data races existed, but that the compiler could not reasonably > > > do anything untoward with those data races, that developer might well > > > choose to use data_race() instead of READ_ONCE(). Especially if the > > > access in question was on a fastpath where helpful compiler optimizations > > > would be prohibited by use of READ_ONCE(). > > > > Yes, and in this particular case I think we can remove some WRITE_ONCE()s > > from the non-RCU hlist code too (similarly for hlist_nulls). > > Quite possibly, but we should take them case by case. READ_ONCE() > really does protect against some optimizations, while data_race() does > not at all. Agreed, and I plan to send patches for review so we can discuss them in more detail then. > But yes, in some cases you want to -avoid- using READ_ONCE() and > WRITE_ONCE() so that KCSAN can do its job. For example, given a per-CPU > variable that is only supposed to be accessed from the corresponding CPU > except for reads by diagnostic code, you should have the main algorithm > use plain C-language reads and writes, and have the diagnostic code > use data_race(). This allows KCSAN to correctly flag bugs that access > this per-CPU variable off-CPU while leaving the diagnostic code alone. Yes, and in a similar vein I think the WRITE_ONCE() additions to the hlist code may hide unintentional racy access to the hlist where I would argue that the correct behaviour is either to acknowledge the data race (like the timer code) or to use the RCU variant. The problem with what's currently in mainline is that it reads a bit like the non-RCU hlist is directly usable as a lock-free list implementation, which really isn't the case. > Seem reasonable? It does to me, but we should probably try to apply this a bit more consistently in patch review. Adding {READ,WRITE}_ONCE() until the sanitiser shuts up is easy, but picking that apart later on is a real challenge. Will