Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2921849ybb; Mon, 30 Mar 2020 16:08:07 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsu3/c/N5AhNsCiehylIIsXRm2sx/mUOtD3L5P7xHVJDxR+xVMw2gJkjMKl5p/A1mhhJrRX X-Received: by 2002:aca:b743:: with SMTP id h64mr315280oif.176.1585609687387; Mon, 30 Mar 2020 16:08:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585609687; cv=none; d=google.com; s=arc-20160816; b=SFClNFtPQumnaVvNn6UKKTvBQR9XjsOm6mZs65do0kZTQd/vwTR9B29ku4DK6AtBMA hkIHx9wwKm8C+ziMNxynskv75xCGGZ7ZL49FklUICgGgIn3+IB3QfHpGVFhPcS5meMD7 tmvi0FWFZFSfqp680PiWwnBo9kLF5rOJvAgPU+/efQZu4mAnh9TuyO2K9rQLGqppONbj Zy1lCBG9yd7yhQ2OgYjAukPEHTVdKPnqV/VXO+hqxpQyL7/y+Y85VeO/gefcWVjTroiW nzQ68+h5DULCnEReqkb8fd369K/jOa8HyZGzHXNP5T18mCkSWGT6CAGGqHKyAccK2QKv w4vg== 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:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=Nc2gtTD9f8CJ6x+wSCVUJxgSloUmCZrf5MGUGtp6H2E=; b=aNhzhU8M6Tr+hBb6+lVK5wk+THa7zlDae348nnt52nQEwE5RebDHbBljRdN/+dq8Ne PU/OowbG/uWYCJtk7FqFldVc/cqcV5ShrwFMHobLd3IL89YMDcR6Xm2pG/o4d+m20Wtp maskeAdazMiU4iv7l7Z/MSIRWnBSyRAInGaMuhgZqW2pszD+2wCTqyFfFdG4BA0AO1u1 9f5oIKGdyzolVlrmsrZazSUol25Q6YH7lT/lnM21ilzMGeITCpZWujPi1ZVGBWK3h1u8 SKL3XCAB8rrXuSzvRpoJCXQ83Cugslc3dt3hNyovglVJLwbSvvxyMa/vkrh8J4+F7DS3 csfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dGAFrVwc; 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 y123si6407889oia.141.2020.03.30.16.07.55; Mon, 30 Mar 2020 16:08:07 -0700 (PDT) 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=dGAFrVwc; 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 S1729358AbgC3XF5 (ORCPT + 99 others); Mon, 30 Mar 2020 19:05:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:60028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728987AbgC3XF5 (ORCPT ); Mon, 30 Mar 2020 19:05:57 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (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 E7CDB20733; Mon, 30 Mar 2020 23:05:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585609556; bh=sZoG49IlE//Cd5eYwc8Z5AQTYaI/Iwc0/gOeae7abfU=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=dGAFrVwci1oqhpIsKl9e9+zoXRjlgxHw5cpzSTUVgiES3WLX3ScneiKQilOC6lGcZ XNawhAWA3v2G4nG3wtxPEVFjvFb1Mh1GTLuJLeJxcfZntUMVSTQJtiGPphMx3BDEpL ndPHqyKu/FUvPHQAgJPIuod7vfZ1BCr9hfKUTdjg= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id BE5CA3523140; Mon, 30 Mar 2020 16:05:55 -0700 (PDT) Date: Mon, 30 Mar 2020 16:05:55 -0700 From: "Paul E. McKenney" To: Will Deacon Cc: linux-kernel@vger.kernel.org, Eric Dumazet , Jann Horn , Kees Cook , Maddie Stone , Marco Elver , Peter Zijlstra , Thomas Gleixner , kernel-team@android.com, kernel-hardening@lists.openwall.com Subject: Re: [RFC PATCH 01/21] list: Remove hlist_unhashed_lockless() Message-ID: <20200330230555.GX19865@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200324153643.15527-1-will@kernel.org> <20200324153643.15527-2-will@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200324153643.15527-2-will@kernel.org> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 24, 2020 at 03:36:23PM +0000, Will Deacon wrote: > Commit c54a2744497d ("list: Add hlist_unhashed_lockless()") added a > "lockless" variant of hlist_unhashed() that uses READ_ONCE() to access > the 'pprev' pointer of the 'hlist_node', the intention being that this > could be used by 'timer_pending()' to silence a KCSAN warning. As well > as forgetting to add the caller, the patch also sprinkles > {READ,WRITE}_ONCE() invocations over the standard (i.e. non-RCU) hlist > code, which is undesirable for a number of reasons: > > 1. It gives the misleading impression that the non-RCU hlist code is > in some way lock-free (despite the notable absence of any memory > barriers!) and silences KCSAN in such cases. > > 2. It unnecessarily penalises code generation for non-RCU hlist users > > 3. It makes it difficult to introduce list integrity checks because > of the possibility of concurrent callers. > > Retain the {READ,WRITE}_ONCE() invocations for the RCU hlist code, but > remove them from the non-RCU implementation. Remove the unused > 'hlist_unhashed_lockless()' function entirely and add the READ_ONCE() > to hlist_unhashed(), as we do already for hlist_empty() already. > > Cc: Eric Dumazet > Cc: Thomas Gleixner > Cc: Paul E. McKenney > Cc: Peter Zijlstra > Signed-off-by: Will Deacon No objection, however 90c018942c2b ("timer: Use hlist_unhashed_lockless() in timer_pending()") in -tip must change from hlist_unhashed_lockless() to hlist_unhashed(). Easy fix, though, so: Acked-by: Paul E. McKenney > --- > include/linux/list.h | 33 ++++++++++----------------------- > 1 file changed, 10 insertions(+), 23 deletions(-) > > diff --git a/include/linux/list.h b/include/linux/list.h > index 884216db3246..4fed5a0f9b77 100644 > --- a/include/linux/list.h > +++ b/include/linux/list.h > @@ -777,19 +777,6 @@ static inline void INIT_HLIST_NODE(struct hlist_node *h) > * node in unhashed state, but hlist_nulls_del() does not. > */ > static inline int hlist_unhashed(const struct hlist_node *h) > -{ > - return !h->pprev; > -} > - > -/** > - * hlist_unhashed_lockless - Version of hlist_unhashed for lockless use > - * @h: Node to be checked > - * > - * This variant of hlist_unhashed() must be used in lockless contexts > - * to avoid potential load-tearing. The READ_ONCE() is paired with the > - * various WRITE_ONCE() in hlist helpers that are defined below. > - */ > -static inline int hlist_unhashed_lockless(const struct hlist_node *h) > { > return !READ_ONCE(h->pprev); > } > @@ -852,11 +839,11 @@ static inline void hlist_del_init(struct hlist_node *n) > static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) > { > struct hlist_node *first = h->first; > - WRITE_ONCE(n->next, first); > + n->next = first; > if (first) > - WRITE_ONCE(first->pprev, &n->next); > + first->pprev = &n->next; > WRITE_ONCE(h->first, n); > - WRITE_ONCE(n->pprev, &h->first); > + n->pprev = &h->first; > } > > /** > @@ -867,9 +854,9 @@ static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) > 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); > + n->pprev = next->pprev; > + n->next = next; > + next->pprev = &n->next; > WRITE_ONCE(*(n->pprev), n); > } > > @@ -881,12 +868,12 @@ static inline void hlist_add_before(struct hlist_node *n, > static inline void hlist_add_behind(struct hlist_node *n, > struct hlist_node *prev) > { > - WRITE_ONCE(n->next, prev->next); > - WRITE_ONCE(prev->next, n); > - WRITE_ONCE(n->pprev, &prev->next); > + n->next = prev->next; > + prev->next = n; > + n->pprev = &prev->next; > > if (n->next) > - WRITE_ONCE(n->next->pprev, &n->next); > + n->next->pprev = &n->next; > } > > /** > -- > 2.20.1 >