Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp853483ybl; Fri, 31 Jan 2020 09:08:10 -0800 (PST) X-Google-Smtp-Source: APXvYqweYmwyzsAMPF+glfoczHPJoKb98bDEOAURJGsnbMJRqbYF4JPq7pw6P2YcVKoR5DoHU6Kx X-Received: by 2002:a9d:74c5:: with SMTP id a5mr8774473otl.229.1580490489951; Fri, 31 Jan 2020 09:08:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580490489; cv=none; d=google.com; s=arc-20160816; b=I/UTZnia2k5pQhSr77dnkBMTugKLbx/yezV49t6ZgXH0W+4B+Tedq8XqZhpJOaGU+7 255hQ0dlMX4VgCJg5SFI0cLiFKQQwYXRVfvoq5Bvg/plOlHLENxH13+29Lt6Si3thmcP Jc8QOQfzGp+05n2RVmyXx/w/DLWAVFZj1Io1dYNCusbT0UUWzK64ZANIBe6EHSzzq+7s GqpkrmS0MJigSpehnevFLyiCjVlTpSdqdAvR0hrrV1NK0DDEznIilGgCrSkVZqeQRw1A 2pIOwLg/Cg+nfELlobalHM0PE8rJDh4fPgNRQu5XCU6uVCeqam7cd1e4lnLbMK4QGL88 d9ag== 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=1FwCXU85/DYT+g9qFs5HT07hGg5Z75Y3d9H26QRE81Q=; b=FJIU1x6YdmDJtKv2cZCtIHzYI8TPX5CegfNYqaL/aEHoOkwTJpmUzy6A7zWlecfIp+ 2EqU4oyhXI8pFKn6gtMRadxC0ZcJQt+ipeZxBE8nubsukwKlKTKM9KeoMxr/vK+jknFb 1ywuSRYsuUH/tnUrSzLLWsmwX0Ldu1OZY3WkXKRQQ7z50raks7ctnLkdCJGuatFE1CsK mUvV5UMsbUxNumNCWRJn6SDAZ+IcPE6kfabUgTfL2cNx2YYvEF9vucZCdXpaxih18gpX 7Wjj0FlB7kQbVlzUyQdlERtD3tphaUONwg6mTM9yjAeJKyCJzsbvpwsGbJuqLRYaCzIF NL+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=i6hJnNZZ; 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 s22si5531403otq.100.2020.01.31.09.07.56; Fri, 31 Jan 2020 09:08:09 -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=i6hJnNZZ; 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 S1726959AbgAaRGl (ORCPT + 99 others); Fri, 31 Jan 2020 12:06:41 -0500 Received: from mail-yw1-f45.google.com ([209.85.161.45]:38160 "EHLO mail-yw1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbgAaRGl (ORCPT ); Fri, 31 Jan 2020 12:06:41 -0500 Received: by mail-yw1-f45.google.com with SMTP id 10so5390028ywv.5 for ; Fri, 31 Jan 2020 09:06:39 -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=1FwCXU85/DYT+g9qFs5HT07hGg5Z75Y3d9H26QRE81Q=; b=i6hJnNZZIpxGgX7i+XKFx18XZV0oIC9DW/vMZd79FnXZTLFZmiqmdDXGrli3XeKWay hdyMM/PXjKTTztenZOe7FFUS0+9FmFa0Xx2BDopmJSmu7jiA2/KaNlX1qW0xSpBnwA/n 1MPqgYwnX+ewjpnbBHfqXbcjq3MjUA5de01ozExT/uEfX8WnVev1GvGB2L9tZIot+MN3 iN/N81CBfzZTHtNYLU4xLDn9NSldniScns33Z23oAiyiC364C0YzgUg7o5GiKXrilEoA e8RmsgZnWZ4ebH79tSBg3MouUHux5vaCt7a5gVebEnAv3GFqRm5CV5aor9l8AXIvkxEx RZLg== 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=1FwCXU85/DYT+g9qFs5HT07hGg5Z75Y3d9H26QRE81Q=; b=JWUZ5MoUmFchG443hRmQDxxM8ZAo+VkAKKQ8O5hp2aab5lhzc8avoXY3YEMFtUx6ND WjUWOp/PWNNRW6/8uz3wxDiMd1A3qFzUeh53RKg810TMC83FatqZYI5CWIiJ61QW70tt B8XLt6D+SulVR7GbAgiGhnG1j0yw7QJwrW0NIwKGV0rHQLPVADKFvZvYiKoq0sNz5tIg 06Xi9qUlUp5wqICiL4SfUVUrcZEQBdVc0g6bFfb0W7j9MiFtl0pNJeennnEm9xjQVpuA 56f1QqYJtodfaYKxCnE8SztNPsOv+FOV4CQ0N12dUaeecuG533qkmBKEGD6xUuAAwo0w NrZQ== X-Gm-Message-State: APjAAAXpHJ96BwuJt+ZAok7uLrDbbSsfqmoxMfuAtoumyCAnZizyy7vG Sw/pFopuTkE0SZH1j7ztoOnY8khGn3FOCUV7gXbPzQ== X-Received: by 2002:a0d:c701:: with SMTP id j1mr1630125ywd.52.1580490398485; Fri, 31 Jan 2020 09:06:38 -0800 (PST) MIME-Version: 1.0 References: <20200131164308.GA5175@willie-the-truck> <20200131165718.GA5517@willie-the-truck> In-Reply-To: <20200131165718.GA5517@willie-the-truck> From: Eric Dumazet Date: Fri, 31 Jan 2020 09:06:27 -0800 Message-ID: Subject: Re: Confused about hlist_unhashed_lockless() To: Will Deacon Cc: Thomas Gleixner , "Paul E. McKenney" , "the arch/x86 maintainers" , LKML , Peter Zijlstra 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 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: > > > I just ran into c54a2744497d ("list: Add hlist_unhashed_lockless()") > > > but I'm a bit confused about what it's trying to achieve. It also seems > > > to have been merged without any callers (even in -next) -- was that > > > intentional? > > > > > > My main source of confusion is the lack of memory barriers. For example, > > > if you look at the following pair of functions: > > > > > > > > > static inline int hlist_unhashed_lockless(const struct hlist_node *h) > > > { > > > return !READ_ONCE(h->pprev); > > > } > > > > > > static inline void hlist_add_before(struct hlist_node *n, > > > struct hlist_node *next) > > > { > > > WRITE_ONCE(n->pprev, next->pprev); > > > WRITE_ONCE(n->next, next); > > > WRITE_ONCE(next->pprev, &n->next); > > > WRITE_ONCE(*(n->pprev), n); > > > } > > > > > > > > > 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. 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; }