Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1228020ybx; Thu, 7 Nov 2019 09:03:44 -0800 (PST) X-Google-Smtp-Source: APXvYqyCYzq2SXFRNExLwpu8p2I7Ea46ofNgMTuC/19g9eDYD513pdEux0qxdTpV0SnA1Gp+2OzX X-Received: by 2002:a5d:5686:: with SMTP id f6mr3988338wrv.231.1573146224607; Thu, 07 Nov 2019 09:03:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573146224; cv=none; d=google.com; s=arc-20160816; b=HhP9pLbhJ6Ma5whHqFRiyXl05ENf0Tqs+6Nk40Oaagv0mHZhg4VDveeXGOzR9ul/6x XQiiTuyfe9bn3OgZvE9Nw1D6R6tRpAHa84Sr+tq+p6d8YJjFX8aou/Gh/6/K5kfRwaqE VYn0Djb0O+wwiQnLvGbCDVJm20z7hkNg3fw2ehAdTUB+2nUZ+AJudEtbtwLUm2MfsBIT IdErOjhCqF5PI0KxqmQ7YHvsoqvkvkRtDwYy6CmzzovspaHqsQKhRvgm+uGD0509gjXl CdU8f8XLJ1HwUZ7id2f2AjLv8RmpgclPzxzqdHqOfLeYiV8bcgq08UPoFDQnaRzWXnWb 7skw== 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=54zJYTA6CYjgn0y4dsSw2cHqSfHEeR/LXlBnsZVQsbs=; b=WtfejcnDQZ701ePd/WpBaYTpBcu5p925PK+B1Ts9hGp475++SIn/t1D6r1EJu7eAaw wj4DUaD8MreeoVv7rg++YncaAyal9zC/J46v3hXosoRRJaG4Oo3xnlR9PsX3BJ2mN6VA ZdsATuQyEQ8Zl7NVW4XCAtcDuZb41QLPIwVBtJdCETZERKmf9YqJ87/otdWZHTntdiYy G29qgGdl5JH9TQL83i8bf2KbTM7B43yEwW481BYFzH0LS0w+ByUDx1TRmP40FCuGXU0w oqMsvyY2iJzWfnEdIqfJOOIQ1MWkSHUHMlDzV8Q+uNm6enuFTc3hCUed93qmPeCvSS8w eTbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="OlemqC/3"; 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 t4si2060739edc.171.2019.11.07.09.03.21; Thu, 07 Nov 2019 09:03:44 -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=@google.com header.s=20161025 header.b="OlemqC/3"; 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 S2389491AbfKGRAC (ORCPT + 99 others); Thu, 7 Nov 2019 12:00:02 -0500 Received: from mail-il1-f195.google.com ([209.85.166.195]:35237 "EHLO mail-il1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729692AbfKGRAB (ORCPT ); Thu, 7 Nov 2019 12:00:01 -0500 Received: by mail-il1-f195.google.com with SMTP id z12so2466280ilp.2 for ; Thu, 07 Nov 2019 09:00:01 -0800 (PST) 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=54zJYTA6CYjgn0y4dsSw2cHqSfHEeR/LXlBnsZVQsbs=; b=OlemqC/3HDaxtIPWv5ZDga3wwveV1kqTbSf3cjh11xFe9FcbnciERfEJDJkmVBX5QJ t52vt2RR2Txhhyp+cezqP9bUPsPrV/hB/UbNdAieyHG8pv3S7ZpIjIjsEtHQpgxYH4tj pcAVfslVR1ueqL6MNLAeqaAjOMZ8K5eXcltGgZ4akvpnAttQorNGCyPShFfrSbwBfB2x H/eImmsolpDLaBOCWyy5h73OgUVKwTre9CYt9WblFu++Xa9WSbD7ySVJvtCknwjyJLce UEvsnMnzo3u8clIAgKpCZ+kEEq8DIixwR4pYv5AV62RSDPR6Y9o17CKKL3dNKCeE2u5b L5SQ== 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=54zJYTA6CYjgn0y4dsSw2cHqSfHEeR/LXlBnsZVQsbs=; b=n7Uujgz2W71RdYo4ONhprU6L0pypvJn4yvG7nQAPL+h+Y8t61+0eulX5PuUED5Ud/9 oNBgs766nk9JT3nBzqCjWkgTyG9yfZ0eRC9bSWxXANIOTIKLI8jM4ES5f00RTdUpganu T4SNp1magA9pNBOSE+4xJ/RZ24W4xivtgnBYDvL3pRb5xQBbQzEXDr3EDzlQKl+g0Mdt 9SvysNEmFdx9rhUnJOvWrM43/SEnzirC3S5j+6vJnpCrLTv0vIBIKBKT4kkAZlk5UEz2 WXlfEZ0Imi33BNA3pY0/2dw9yhMJUn1xN+XXrtHVcn2ga3J2AWZxxa4iFE/cRf305ZgG xNtQ== X-Gm-Message-State: APjAAAUQfgYxDhxrFEUvHYMywZu+Ckn3CKOLbPSse2Ec9s2kSXdxZgIb yT5dB3KtrRdkxLVXomdQ+QHpXHyonYQ9ARASujD3tg== X-Received: by 2002:a92:109c:: with SMTP id 28mr5758698ilq.142.1573146000389; Thu, 07 Nov 2019 09:00:00 -0800 (PST) MIME-Version: 1.0 References: <20191106174804.74723-1-edumazet@google.com> <157307905904.29376.8711513726869840596.tip-bot2@tip-bot2> <20191107085255.GK20975@paulmck-ThinkPad-P72> <20191107161149.GQ20975@paulmck-ThinkPad-P72> <20191107165428.GR20975@paulmck-ThinkPad-P72> In-Reply-To: <20191107165428.GR20975@paulmck-ThinkPad-P72> From: Eric Dumazet Date: Thu, 7 Nov 2019 08:59:49 -0800 Message-ID: Subject: Re: [tip: timers/core] hrtimer: Annotate lockless access to timer->state To: paulmck@kernel.org Cc: LKML , linux-tip-commits@vger.kernel.org, syzbot , Thomas Gleixner , Ingo Molnar , Borislav Petkov 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, 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.