mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Christoph Lameter <cl@linux.com>
Cc: Huang Ying <ying.huang@intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [listll] Fix fetching of head->first in lockless lists.
Date: Thu, 4 Aug 2011 11:17:25 -0400	[thread overview]
Message-ID: <20110804151725.GA21597@Krystal> (raw)
In-Reply-To: <alpine.DEB.2.00.1108040942360.24277@router.home>

* Christoph Lameter (cl@linux.com) wrote:
> 
> The fetching of head->first must occur in the cmpxchg loop.
> 
> With the current code head->first may change after the content were assigned to
> the "entry" variable. Entry then not be change anymore in the loop and be
> used as old_entry for the cmpxchg. The cmpxchg will then therefore
> compare "entry" to list->head. This will always fail if list->head has
> changed. The restarting of the loop will not fetch head->first again. So
> we could have a hang there.
> 
> I guess this only works now because the compiler optimizations pull
> the fetching of head->first into the loop.

Hi Christoph,

The cmpxchg re-fetch the head->first (this is its return value). The:

  } while ((entry = cmpxchg(&head->first, old_entry, new)) != old_entry);

Takes care of the re-read and populating "entry" with an updated value.

So the patch you propose here is useless.

Thanks,

Mathieu

> 
> Signed-off-by: Christoph Lameter <cl@linux.com>
> 
> ---
>  lib/llist.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> Index: linux-2.6/lib/llist.c
> ===================================================================
> --- linux-2.6.orig/lib/llist.c	2011-08-04 09:34:30.000000000 -0500
> +++ linux-2.6/lib/llist.c	2011-08-04 09:35:08.000000000 -0500
> @@ -42,8 +42,8 @@ void llist_add(struct llist_node *new, s
>  	BUG_ON(in_nmi());
>  #endif
> 
> -	entry = head->first;
>  	do {
> +		entry = head->first;
>  		old_entry = entry;
>  		new->next = entry;
>  		cpu_relax();
> @@ -66,8 +66,8 @@ void llist_add_batch(struct llist_node *
>  	BUG_ON(in_nmi());
>  #endif
> 
> -	entry = head->first;
>  	do {
> +		entry = head->first;
>  		old_entry = entry;
>  		new_last->next = entry;
>  		cpu_relax();
> @@ -97,8 +97,8 @@ struct llist_node *llist_del_first(struc
>  	BUG_ON(in_nmi());
>  #endif
> 
> -	entry = head->first;
>  	do {
> +		entry = head->first;
>  		if (entry == NULL)
>  			return NULL;
>  		old_entry = entry;

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

  reply	other threads:[~2011-08-04 15:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-04 14:45 Christoph Lameter
2011-08-04 15:17 ` Mathieu Desnoyers [this message]
2011-08-04 15:25   ` Christoph Lameter
2011-08-04 15:26     ` Christoph Lameter

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=20110804151725.GA21597@Krystal \
    --to=mathieu.desnoyers@efficios.com \
    --cc=ak@linux.intel.com \
    --cc=cl@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ying.huang@intel.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

all inboxes | Powered by JetHome®