Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1203486ybx; Thu, 7 Nov 2019 08:41:48 -0800 (PST) X-Google-Smtp-Source: APXvYqzsg6HhckS35NDcKrz+DKZ75DA/X3d/1bmaqO21bm2mbuIpqnv1JAp105SLMQkR2/yvMvpJ X-Received: by 2002:a50:fd03:: with SMTP id i3mr4683176eds.70.1573144908678; Thu, 07 Nov 2019 08:41:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573144908; cv=none; d=google.com; s=arc-20160816; b=hv9bXeFf37PMSH8RSHt4WXxMPj5ssX398TVlJ0XAinAGgC9CrCDv7eHcDcbunhxUsn vlBkUXtcZt6HPx0SNGCSk+pj+XcNuFchKp6QVuYRtnRjwfGpPxS7/doTq54D6UxOju3O rVSj40KSZPMwDsbxAfHDKpeQM+1wN6txKQsxmN4ODIQ3ed2lVVachtN6NorXjUudLoIr 67gCtCkcVde3MPv6vn0i70Qt+XWBwp0eiyeP/9DZg0jym1N1XXOm3bgHpgOFeUxRCXkM 53UbdZRV26YSMyNP1tOr/VHBZlTOkOGbGhI1X1z8iVWg/Ph/TSDG5+dPzNcGCxNUrASC QrEA== 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=YmNJnREVJGnaaEVeLxsBm0Njwp2E0f+PM+J5gi1eqbs=; b=Iw91JBznbxgTuLJjfJBvafHf+3FSB+oSUEmNuyF38aG9wWAaZWiR1p2QOjJ6jRAVjW Nr+pg7KqgjigFOjn06DMwLUn4T8Ossnn+Be23UQBV41B0KO4hV55nw1BVhe0BRZN85Hq 7QCdnUfsxm4TI6czUgW7bA5BXGX7J9QWLRn9OkLUcWsfRerETL5aK2u7cPdfqSLKSqpW pwBwLuYvbr7vMnrRcjPj5EzZoNl6A+SjmcM7SxQvVX9iMEtZkSKfl2nBfYZMdOvRYeT0 TnW7jOKwotiqGH1ClmPcnFq0G4NzCZRxWlQ9OUi9FB61KwanwVNKJHxZAfqIAH/+k2Pm JPKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="XHHvp/NM"; 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 jx16si1808062ejb.353.2019.11.07.08.41.25; Thu, 07 Nov 2019 08:41:48 -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="XHHvp/NM"; 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 S2388911AbfKGQj4 (ORCPT + 99 others); Thu, 7 Nov 2019 11:39:56 -0500 Received: from mail-io1-f66.google.com ([209.85.166.66]:32824 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729692AbfKGQj4 (ORCPT ); Thu, 7 Nov 2019 11:39:56 -0500 Received: by mail-io1-f66.google.com with SMTP id j13so3028998ioe.0 for ; Thu, 07 Nov 2019 08:39:54 -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=YmNJnREVJGnaaEVeLxsBm0Njwp2E0f+PM+J5gi1eqbs=; b=XHHvp/NMTOUmt9odTSBMZfZ6Fd8oFGBV5ygxerSm6CUQkj7ciP+w9t/z9I7wZ+NKvR sbhCHs533hdvNMpzNvR/eRFAC6rdZ+ayQz6cnV7+n4suiJP1wbEsHwXy++pN+cUxvwyC wItRJCyzaUHuqZJVTFYiV/Xbog9iVK/UP+R/y8iCJaWeAIg1+rM5gXj9f5WukG8IEn+x crAwkkOeooSkUZ6LceStLCHVMz+68i7i5aJmuCQ0oonZiiU3/Kl+XLd0CmLcpE7ow9KW rV+jeXdW9KSB3aukqxaBiRMkKTZ5m2kwJKqzpfV8nxjyWyymINNvWJ5AJmf9E6l7g78V Fzfg== 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=YmNJnREVJGnaaEVeLxsBm0Njwp2E0f+PM+J5gi1eqbs=; b=bV57vfUJIcBlooeqPiMRdGqEK1dwiCzfw7SiktNE091L1edqwBtk7cbUlUL91BXFl1 Y6Q4c4T3/aCvp7Y8O319osM1KPaQn9IznHjETfZyymPmHPk45UuAMK0eE1Q2I9ieN+FF FGCP4FHvEZ+FNivChXj9wLXgadrokDPmCZ+MczPV0qVOaMDpCVtwgFrz74PZNkUEHTWi 1XP1LEh1t+xWeKH+DogKrHPBgkEywwNW/C2OeDyEazWhBTRM4UfGVRK0JyVdiNqmPw7p htje7ND+rCzeEK17olloV3cAafgR2JZCcNSDMeMlGsEL1hozqe4S5G9c9Ffu9YPcniO0 LYTQ== X-Gm-Message-State: APjAAAXs1uiM/DTxgMFG3Q9xHVrBjZaMQOQjYQ8cC40Jh52iXpwWX5tq JK0I6BPa0cFfVWcaIjFMsYj5kFG587C9nD1xv7i2ld59P1g= X-Received: by 2002:a5d:8953:: with SMTP id b19mr4691034iot.168.1573144793781; Thu, 07 Nov 2019 08:39:53 -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> In-Reply-To: From: Eric Dumazet Date: Thu, 7 Nov 2019 08:39:42 -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: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 /** * 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 ?