Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1234763ybx; Thu, 7 Nov 2019 09:08:50 -0800 (PST) X-Google-Smtp-Source: APXvYqxu0jfEXjbdGVQPviriO6CtegQJr/9oINYwijnc77AmeL/RwR/Pu09YM2F385QcSNsqipr/ X-Received: by 2002:a50:fa4a:: with SMTP id c10mr4729881edq.51.1573146530636; Thu, 07 Nov 2019 09:08:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573146530; cv=none; d=google.com; s=arc-20160816; b=PZ52ps5qWvZrAMUpKqZ9Wy/MU7D+2LF4qVDLwHJveHNkQcgSR1awl/dHPDoN/ly2uK t30I893wcuIPPBdmU5DnEWBveIj+eUSliwO8XRXVX6rkwIn9/PaR+wF/OoVbCCnYl28X Qrvkqb/ZSkzMjEkS7Xe8ljW3mtOZ2hmYAs4nvb83xDDtHCAs1j5rnqxaBsSgLIRHWSIn orwOPGXaCioqcaD4b4+5W6rQSPxKIZ0HPpMf7nQmqkU3Re5NRuCuEpstxOvK8rJeu5yk Z9iGSRnAdvCbeip+g6FbDC6pbTGrkIuI89P7uxGzm27CSZBzRo4J4u9t07mFud1UMN7U ggnA== 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:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=cynPH61bTNlz+Pz8AyW32pE6MLK4gPJXFugLLZJALyc=; b=BDNCnu2dAtB+CglQFqtLSgq3IHo+GoA85d3tLUMVPdEIx2XOVLj7t9AVuUXgy+SR0+ XvHqPH91+OWFayLdoh7aTpwlAA6lccceEE0Akf3qn0Ip7d/KFKO5RKP8zdjf1s2EQF8c +thNAdqqXrZDg1u6YxZj9pmuqgJMXeQ1kKeesEgYn+1PmbnQ+Y4tyX6935964ZnWc0zh 60YqxsDw+G9oXa0F8UGfop3zvIA7+2Z+aiWMZcq5PNVPYGUbu6u2qmBF9Wyy5qnSMfw4 6C7O0xgUFsRi0jCJ2yfXwqJqsFaccJVBJVP1bBdd6hVOeTAk68XE/rYxlRK68soYNTKA 54Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FULeloc2; 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 f2si2062906ejf.231.2019.11.07.09.08.24; Thu, 07 Nov 2019 09:08:50 -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=FULeloc2; 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 S1730600AbfKGRHm (ORCPT + 99 others); Thu, 7 Nov 2019 12:07:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:56832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726231AbfKGRHm (ORCPT ); Thu, 7 Nov 2019 12:07:42 -0500 Received: from paulmck-ThinkPad-P72.home (unknown [109.144.209.93]) (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 9AB93206BA; Thu, 7 Nov 2019 17:07:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573146461; bh=fPQk1CB2fD+joQiucvbdrbH/MOkp35H8ljloJnhHVes=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=FULeloc2Cw14BMI0w6LnhBrCrhL9bUi4jg/5JduqcxU4Ybfb829eYbVWNWZF4gheK tDIboebsOwypoS5vF4/mx2IY93cqYQEIFnewH7V4EQyDY5/XgXLycehA4w0EAzQA5j ZK841bxgxlWiZqX0XKC7AuXoB+tVohNI61d9Kd+s= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id A09D13522919; Thu, 7 Nov 2019 09:07:38 -0800 (PST) Date: Thu, 7 Nov 2019 09:07:38 -0800 From: "Paul E. McKenney" To: Eric Dumazet Cc: LKML , linux-tip-commits@vger.kernel.org, syzbot , Thomas Gleixner , Ingo Molnar , Borislav Petkov Subject: Re: [tip: timers/core] hrtimer: Annotate lockless access to timer->state Message-ID: <20191107170738.GT20975@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <157307905904.29376.8711513726869840596.tip-bot2@tip-bot2> <20191107085255.GK20975@paulmck-ThinkPad-P72> <20191107161149.GQ20975@paulmck-ThinkPad-P72> <20191107165428.GR20975@paulmck-ThinkPad-P72> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 07, 2019 at 08:59:49AM -0800, Eric Dumazet wrote: > On Thu, Nov 7, 2019 at 8:54 AM Paul E. McKenney wrote: > > > > On Thu, Nov 07, 2019 at 08:39:42AM -0800, Eric Dumazet wrote: > > > On Thu, Nov 7, 2019 at 8:35 AM Eric Dumazet wrote: > > > > > > > > On Thu, Nov 7, 2019 at 8:11 AM Paul E. McKenney wrote: > > > > > > > > > > OK, so this is due to timer_pending() lockless access to ->entry.pprev > > > > > to determine whether or not the timer is on the list. New one on me! > > > > > > > > > > Given that use case, I don't have an objection to your patch to list.h. > > > > > > > > > > Except... > > > > > > > > > > Would it make sense to add a READ_ONCE() to hlist_unhashed() > > > > > and to then make timer_pending() invoke hlist_unhashed()? That > > > > > would better confine the needed uses of READ_ONCE(). > > > > > > > > Sounds good to me, I had the same idea but was too lazy to look at the > > > > history of timer_pending() > > > > to check if the pprev pointer check was really the same underlying idea. > > > > > > Note that forcing READ_ONCE() in hlist_unhashed() might force the compiler > > > to read the pprev pointer twice in some cases. > > > > > > This was one of the reason for me to add skb_queue_empty_lockless() > > > variant in include/linux/skbuff.h > > > > Ouch! > > > > > /** > > > * skb_queue_empty_lockless - check if a queue is empty > > > * @list: queue head > > > * > > > * Returns true if the queue is empty, false otherwise. > > > * This variant can be used in lockless contexts. > > > */ > > > static inline bool skb_queue_empty_lockless(const struct sk_buff_head *list) > > > { > > > return READ_ONCE(list->next) == (const struct sk_buff *) list; > > > } > > > > > > So maybe add a hlist_unhashed_lockless() to clearly document why > > > callers are using the lockless variant ? > > > > That sounds like a reasonable approach to me. There aren't all that > > many uses of hlist_unhashed(), so a name change should not be a problem. > > Maybe I was not clear : I did not rename skb_queue_empty() > I chose to add another helper. > > Contexts that can safely use skb_queue_empty() still continue to use > it, since it might help > the compiler to generate better code. > > So If I add hlist_unhashed_lockless(), I would only use it from > timer_pending() at first. > > Then an audit of the code might reveal other potential users. OK, yes, that approach does make more sense, and thank you for the clarification. Thanx, Paul