From: "Huang\, Ying" <ying.huang@intel.com>
To: Joel Fernandes <joelaf@google.com>
Cc: <linux-kernel@vger.kernel.org>, Huang Ying <ying.huang@intel.com>,
Ingo Molnar <mingo@kernel.org>, Will Deacon <will.deacon@arm.com>,
"Paul McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [RFC] llist: Fix code comments about llist_del_first locking
Date: Fri, 09 Dec 2016 08:35:50 +0800 [thread overview]
Message-ID: <878trq3pnd.fsf@yhuang-dev.intel.com> (raw)
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")
Joel Fernandes <joelaf@google.com> 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 <ying.huang@intel.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
> Signed-off-by: Joel Fernandes <joelaf@google.com>
> ---
> 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 | | | -
> *
next prev parent reply other threads:[~2016-12-09 0:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-08 21:54 [RFC] llist: Fix code comments about llist_del_first locking Joel Fernandes
2016-12-09 0:35 ` Huang, Ying [this message]
2016-12-09 0:42 ` Joel Fernandes
2016-12-09 0:43 ` Joel Fernandes
2016-12-09 2:12 ` Huang, Ying
2016-12-09 2:22 ` Joel Fernandes
2016-12-09 2:26 ` Huang, Ying
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878trq3pnd.fsf@yhuang-dev.intel.com \
--to=ying.huang@intel.com \
--cc=joelaf@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).