Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp830514ybl; Fri, 31 Jan 2020 08:44:30 -0800 (PST) X-Google-Smtp-Source: APXvYqy56c6xzrvDOYYygUdDt9CQK+IQSv/kX7KVMWV1fw4hyxENwA8GtNHJM6SQ0VNvowdhh9lT X-Received: by 2002:a05:6808:b13:: with SMTP id s19mr6558472oij.119.1580489070346; Fri, 31 Jan 2020 08:44:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580489070; cv=none; d=google.com; s=arc-20160816; b=yPinOXxyoOeZUMv9mp7nISdUKJptSreyX1xL7e3oPk8MEsZtNBWfqeMtTkN/4k5Sec Gr0k1iCmI3ks+zNx8XZ+QxQItLX+3DXdSYQdxUjJzTVk0bnwqfpyn4Kht/SGgJJgu1hu yK8PrxwoUIh34hzcqR5UIHS4r5lAbatrYv7Vv70vK/ZSDowxSUYk7Bg+7RILzC/FvhnP 3r5iJX5BuqIKsjvnNOVx6ZEo+11W2sju658SQ7sE0prECcwD7B9AcBnftGSmMtVa4YRA vJAmbnWedapsqlQcMxcspbX7ErpQDNl3fh6oahypEibwRMEhtH3oCYlLSxsEXjiB1SWX P16g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=qie/Cip48BzOZtbes33RknwDwvJprbJ0hQGpSzDfP7c=; b=EXPWPeN28+j2T9Fs1SAmUUd0cCkit+BA4qq/3Z3yHujJlQdb2AX0F1KaS+k4tWHA+U aKIS8x6qzuDqkaDd/xwNdAQIVk+S8BL2EerzZzec67IWZsg5DlQ5fOYwWICfVyymDQ1f yG7z6B5N3BGvMBt1VlzXPb2DpYVTr9pGWA1IqvzCLQsUzVvlM1bpKha58jFvxPKdnpZv qE3GUV0byfiZWWZWrg0TTgcUrw3wvF+QXrkPEobvKgLk3vTRDS6Tas/1lRE8zsm6J1Ml p1CnLUrcDwzHGOUqwitEEEmfCS3BMrBkEhLrkw38GF23ZW09eAOcDVTqxxoaR0+F7XFt o3Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w7kEy2wV; 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 t184si4691685oig.184.2020.01.31.08.44.17; Fri, 31 Jan 2020 08:44:30 -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=w7kEy2wV; 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 S1726859AbgAaQnO (ORCPT + 99 others); Fri, 31 Jan 2020 11:43:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:32926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726193AbgAaQnO (ORCPT ); Fri, 31 Jan 2020 11:43:14 -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 B0E5D206F0; Fri, 31 Jan 2020 16:43:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580488993; bh=hHKzqvOSq4QPPeuz3N7dN9CkLNuC6IH23w3s//vJPHI=; h=Date:From:To:Cc:Subject:From; b=w7kEy2wVsluR4k+4Rv29HNE3tkubymRytuEWPimy6JuRNvHwhJnYEJRXwIzzwK94t 8BDJUquBWk56MX8621sOD8nBKcddW/b0DAR0QAuMdPPgDFGC0k8Xhy1qhCBeEwrujX 3HgMI7u/emGPflroz8i/KAkZrR/5UnApSE1yRdjw= Date: Fri, 31 Jan 2020 16:43:09 +0000 From: Will Deacon To: edumazet@google.com, tglx@linutronix.de, paulmck@kernel.org Cc: x86@kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org Subject: Confused about hlist_unhashed_lockless() Message-ID: <20200131164308.GA5175@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 Hi folks, 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? Cheers, Will