Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp867688ybl; Fri, 31 Jan 2020 09:22:14 -0800 (PST) X-Google-Smtp-Source: APXvYqyOUZHx9fyQP3SpaOrNGp1+e6vxLyTw9Jp3AGWow/hS1DQeNgUaJOHADlNz1eJm4nWbTM9N X-Received: by 2002:a05:6830:2102:: with SMTP id i2mr8282559otc.123.1580491334470; Fri, 31 Jan 2020 09:22:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580491334; cv=none; d=google.com; s=arc-20160816; b=ifa6XnB0Fndx9/lHeS9XB9aVFYCq2JBDDuAP7r2DgjIl7nTBlo7Rcxvy/WutXxFE/x R2OPgPEKS9pmL7mgjZPWmNqxzb3poXrPw1RUHIJWJ0gI3f15lEgSStQVKGCrhMe/CWZn kmRbZT5mKe8ef00jehUpn6pzNgO09GFvpDGOBv868oIn56LrreOI0JEaPAPrSOIeBaUG IteHcJpdT5LqelxPxzXH4COzRDEhwPv4jSJBeXP6kgX7XEn56JaZkkUGaGVzNVBufhCp 8WbIlIdOkPUbC186SNspLUpwSpo1GgufjCSePx2L0gdxh/22FqW0blhkfDrL7vayPmm8 EQFw== 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=GdwJABZ/9Sn8HVIYCqeKtt2Graz6/ghy4gM0O5jimkI=; b=qd/RWUfwweAWolgnS+IWQ+XN644lVKkudWjH0F23kGTaralY18K6LoINOpl4QeU9uB mTQzEMt71r7F9cJNjXX+whKnO0thtcSjMOKjcZ+XY133l4BkdqpVx66oolGCno+rPYlt TaJfKvmWWwPcr/u70Xfl00c6JhHKxJa2MglWYtRvwqHw5031dc1meifrUCdxeT08eg1b PcnT7ZLgo2pzR/ZrOOT5WturupgFkIKHFxfvdtuBlZaedNHZlco/p9XyI5tXUqwOd2P4 aw0Cy1Ao303BxwrrVzhzZNguYDaNOYQiqvuWzn7qMJQV7PAY8dUwpDnTAKzKGLkgo7kZ KQdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zghBy1Lz; 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 v14si4594816oto.127.2020.01.31.09.22.00; Fri, 31 Jan 2020 09:22:14 -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=zghBy1Lz; 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 S1726793AbgAaRVE (ORCPT + 99 others); Fri, 31 Jan 2020 12:21:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:44026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726139AbgAaRVE (ORCPT ); Fri, 31 Jan 2020 12:21:04 -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 F17EC206D5; Fri, 31 Jan 2020 17:21:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580491263; bh=8igFNYqYVgzz8ufkSfnU3Ql7xpwSAK1V0KyAZMEOiSA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zghBy1Lzh7+sMfv0GK3+2FqtKUKrvPcYIx7m30xVHsXD4TsCGzHkgDhv5VG5XSV9K wDKxmPvlmYehJxauRZPj2dBOx+1LTB8uRC4FPMotz0pddLu4zfb0yHx7NpiPurvRom pd2eOM1EePnA9WrOZQ6hYZtclmqrNW9ec8hnj1D0= Date: Fri, 31 Jan 2020 17:20:58 +0000 From: Will Deacon To: Eric Dumazet Cc: Thomas Gleixner , "Paul E. McKenney" , the arch/x86 maintainers , LKML , Peter Zijlstra Subject: Re: Confused about hlist_unhashed_lockless() Message-ID: <20200131172058.GB5517@willie-the-truck> References: <20200131164308.GA5175@willie-the-truck> <20200131165718.GA5517@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 09:06:27AM -0800, Eric Dumazet wrote: > On Fri, Jan 31, 2020 at 8:57 AM Will Deacon wrote: > > On Fri, Jan 31, 2020 at 08:48:05AM -0800, Eric Dumazet wrote: > > > On Fri, Jan 31, 2020 at 8:43 AM Will Deacon wrote: > > > > Then running these two concurrently on the same node means that > > > > hlist_unhashed_lockless() doesn't really tell you anything about whether > > > > or not the node is reachable in the list (i.e. there is another node > > > > with a next pointer pointing to it). In other words, I think all of > > > > these outcomes are permitted: > > > > > > > > hlist_unhashed_lockless(n) n reachable in list > > > > 0 0 (No reordering) > > > > 0 1 (No reordering) > > > > 1 0 (No reordering) > > > > 1 1 (Reorder first and last WRITE_ONCEs) > > > > > > > > So I must be missing some details about the use-case here. Please could > > > > you enlighten me? The RCU implementation permits only the first three > > > > outcomes afaict, why not use that and leave non-RCU hlist as it was? > > > > > > > > > > I guess the following has been lost : > > > > Thanks, although... > > > > > Author: Eric Dumazet > > > Date: Thu Nov 7 11:23:14 2019 -0800 > > > > > > timer: use hlist_unhashed_lockless() in timer_pending() > > > > > > timer_pending() is mostly used in lockless contexts. > > > > ... my point above still stands: the value returned by > > hlist_unhashed_lockless() doesn't tell you anything about whether or > > not the timer is reachable in the hlist or not. The comment above > > timer_pending() also states that: > > > > | Callers must ensure serialization wrt. other operations done to > > | this timer, e.g. interrupt contexts, or other CPUs on SMP. > > > > If that is intended to preclude list operations, shouldn't we use an > > RCU hlist instead of throwing {READ,WRITE}_ONCE() at the problem to > > shut the sanitiser up without actually fixing anything? :( > > > Sorry, but timer_pending() requires no serialization. Then we should update the comment! Without serialisation, timer_pending() as currently implemented does not reliably tell you whether the timer is in the hlist. Is that not a problem? Using an RCU hlist does not introduce serialisation, but does at least rule out the case where timer_pending() returns false for a timer that /is/ reachable in the list by another CPU. > The only thing we need is a READ_ONCE() so that compiler is not allowed > to optimize out stuff like > > loop() { > if (timer_pending()) > something; If that was the case, then you wouldn't need to touch hlist_add_before() at all so there's got to be more to it than that or we can revert that part of the patch. Will