Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp939509ybl; Fri, 31 Jan 2020 10:44:35 -0800 (PST) X-Google-Smtp-Source: APXvYqwwwC8OVoU+rZU4H798a4bFO1KxTlbB/Szc+aXQMqs0OxAl8O2OxMhlPovb5ZI74VJib7gy X-Received: by 2002:a05:6830:1385:: with SMTP id d5mr9030867otq.61.1580496275046; Fri, 31 Jan 2020 10:44:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580496275; cv=none; d=google.com; s=arc-20160816; b=TJ7Po7dJWHMgRjv5HOM6emMiaXGsjE+vs6JXgJCRSjIqQFwgzn+9XkmalcGfGsfqNv foIpQ7YPd78R9y+UuUy3lFECvz4al7xVB30iIjuZ4Yd4n7z5662MQ5PJjm4ocyQBEoI1 EgFCdP2uEGHXwr3P4q8exYwhXGsgQ+Zx89xCtXtoqWpxBHbJzns74D/6W2UFXUoLA5Vy /kW7nXPS/zknnis6Tkfn3x8uIM6KmrG7GJMQlzSxA/yfKVdKADZpn4jZh569cl/k5dYs 8a0BAL3bd+yaMDmR+siFTi/UqfR6CUglMghpqElTrA8yrFP0KViYnRVzjdCWeY2eMQH0 QWDA== 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=slwH4YBF+8XdLOEIEFAeY6Th3gu6ZlAMUAGcyNVOTFQ=; b=GRACbtRUs+TnS4CE9Cv5dSHIeXiyK3TdAyEYO8TByCYRLjd2GM5Dd4aMWNBi376/us 9FbbR6KMOtHIho3Q94nC619VtyIa9AxwxDMF7PZs/dJPPuxfYjq5+a10+s9xdaTi1508 mQXA/qnj3VFUvZDF7vOdXQZDbrVttuJbFw1UrgAr7C3JcVcAUOCvsmZ6vLFI6WSdN41L 1dz80UHymP5p5nY4Vu+xYE52M4WPuXb9RkRhaPEq/Vjns7UBTDD9BLQ00XzcbX8b58Uz PigoNbkuWoFapZIhTYq1drtlVC4MnaXBp7sehSb/zISTxjvhQ5jvO3XWPlc8v78udVpi 6ptg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=LR+NMSKh; 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 w7si4989236oie.196.2020.01.31.10.44.23; Fri, 31 Jan 2020 10:44:35 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=LR+NMSKh; 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 S1726105AbgAaSn0 (ORCPT + 99 others); Fri, 31 Jan 2020 13:43:26 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:60324 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725909AbgAaSn0 (ORCPT ); Fri, 31 Jan 2020 13:43:26 -0500 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=slwH4YBF+8XdLOEIEFAeY6Th3gu6ZlAMUAGcyNVOTFQ=; b=LR+NMSKhSXm99rkO+NKrNhoyX fqzoGbEslkDTEsm3f5yo8TSt5+femkI3FSPYROwUkvlZVGcfOGq4ESMJo+wn8ntieYOI/oB4r1opF 9/lcH+TQqQtquw0juBsCRiVCRbRz/9cyetI8+7S6W/jOwO7tzFpPqbztlMgmKVUXVQ9Tk1fS/0sgM V+vTFSct+MiMeiEgZb3oczlUZHmqAtA2Gtrqi+729iicwQ22H5vKeSrjLQoxdS31CfTvpBNLI2+5Y GIxd84pnQ1Zd8BuoqnYUhPz5wB0A4xO8/3rh1IR9dr88JbGLqn3rJ9jrbnQubDvI/XbNBsIRPzjL8 UbpLFaqeQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ixbGF-0002oD-0G; Fri, 31 Jan 2020 18:43:23 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 90B97980E50; Fri, 31 Jan 2020 19:43:22 +0100 (CET) Date: Fri, 31 Jan 2020 19:43:22 +0100 From: Peter Zijlstra To: Eric Dumazet Cc: Will Deacon , Thomas Gleixner , "Paul E. McKenney" , the arch/x86 maintainers , LKML , Marco Elver Subject: Re: Confused about hlist_unhashed_lockless() Message-ID: <20200131184322.GA11457@worktop.programming.kicks-ass.net> References: <20200131164308.GA5175@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Fri, Jan 31, 2020 at 08:48:05AM -0800, Eric Dumazet wrote: > BUG: KCSAN: data-race in del_timer / detach_if_pending > diff --git a/include/linux/timer.h b/include/linux/timer.h > index 1e6650ed066d5d28251b0bd385fc37ef94c96532..0dc19a8c39c9e49a7cde3d34bfa4be8871cbc1c2 > 100644 > --- a/include/linux/timer.h > +++ b/include/linux/timer.h > @@ -164,7 +164,7 @@ static inline void destroy_timer_on_stack(struct > timer_list *timer) { } > */ > static inline int timer_pending(const struct timer_list * timer) > { > - return timer->entry.pprev != NULL; > + return !hlist_unhashed_lockless(&timer->entry); > } That's just completely wrong. Aside from any memory barrier issues that might or might not be there (I'm waaaay to tired atm to tell), the above code is perfectly fine. In fact, this is a KCSAN compiler infrastructure 'bug'. Any load that is only compared to zero is immune to load-tearing issues. The correct thing to do here is something like: static inline int timer_pending(const struct timer_list *timer) { /* * KCSAN compiler infrastructure is insuffiently clever to * realize that a 'load compared to zero' is immune to * load-tearing. */ return data_race(timer->entry.pprev != NULL); }