Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933197AbcLIAfy (ORCPT ); Thu, 8 Dec 2016 19:35:54 -0500 Received: from mga02.intel.com ([134.134.136.20]:11895 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932817AbcLIAfx (ORCPT ); Thu, 8 Dec 2016 19:35:53 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,322,1477983600"; d="scan'208";a="200647135" From: "Huang\, Ying" To: Joel Fernandes Cc: , Huang Ying , Ingo Molnar , Will Deacon , "Paul McKenney" Subject: Re: [RFC] llist: Fix code comments about llist_del_first locking References: <1481234081-61472-1-git-send-email-joelaf@google.com> Date: Fri, 09 Dec 2016 08:35:50 +0800 In-Reply-To: <1481234081-61472-1-git-send-email-joelaf@google.com> (Joel Fernandes's message of "Thu, 8 Dec 2016 13:54:40 -0800") Message-ID: <878trq3pnd.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2689 Lines: 61 Joel Fernandes writes: > Usage llist_del_first needs lock protection, however the table in the > comments of llist.h show a '-'. Correct this, and also add better > comments on top. > > Cc: Huang Ying > Cc: Ingo Molnar > Cc: Will Deacon > Cc: Paul McKenney > Signed-off-by: Joel Fernandes > --- > include/linux/llist.h | 19 ++++++++++--------- > 1 file changed, 10 insertions(+), 9 deletions(-) > > diff --git a/include/linux/llist.h b/include/linux/llist.h > index fd4ca0b..15e4949 100644 > --- a/include/linux/llist.h > +++ b/include/linux/llist.h > @@ -3,14 +3,15 @@ > /* > * Lock-less NULL terminated single linked list > * > - * If there are multiple producers and multiple consumers, llist_add > - * can be used in producers and llist_del_all can be used in > - * consumers. They can work simultaneously without lock. But > - * llist_del_first can not be used here. Because llist_del_first > - * depends on list->first->next does not changed if list->first is not > - * changed during its operation, but llist_del_first, llist_add, > - * llist_add (or llist_del_all, llist_add, llist_add) sequence in > - * another consumer may violate that. > + * If there are multiple producers and multiple consumers, llist_add can be > + * used in producers and llist_del_all can be used in consumers. They can work > + * simultaneously without lock. But llist_del_first will need to use a lock > + * with any other operation (ABA problem). This is because llist_del_first > + * depends on list->first->next not changing but there's no way to be sure > + * about that and the cmpxchg in llist_del_first may succeed if list->first is > + * the same after concurrent operations. For example, a llist_del_first, > + * llist_add, llist_add (or llist_del_all, llist_add, llist_add) sequence in > + * another consumer may cause violations. > * > * If there are multiple producers and one consumer, llist_add can be > * used in producers and llist_del_all or llist_del_first can be used > @@ -19,7 +20,7 @@ > * This can be summarized as follow: > * > * | add | del_first | del_all > - * add | - | - | - > + * add | - | L | - If there are only one consumer which only calls llist_del_first(), lock is unnecessary. So '-' is shown here originally. But if there are multiple consumers which call llist_del_first() or llist_del_all(), lock is needed. Best Regards, Huang, Ying > * del_first | | L | L > * del_all | | | - > *