mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: paulmck@linux.vnet.ibm.com, linux-kernel@vger.kernel.org
Subject: Re: Memory barrier question.
Date: Sat, 30 Oct 2010 08:11:11 +0200	[thread overview]
Message-ID: <1288419071.2680.648.camel@edumazet-laptop> (raw)
In-Reply-To: <201010301448.ADJ35414.VOFHtQOJOFLSMF@I-love.SAKURA.ne.jp>

Le samedi 30 octobre 2010 à 14:48 +0900, Tetsuo Handa a écrit :
> Paul E. McKenney wrote:
> > For the CPU, let's take it by type of architecture...
> > 
> > First, let's get the UP-only architectures out of the way.  These would
> > always see their changes in order, so woiuld always see "hello".
> 
> Of course.
> 
> > Second, let's consider the TSO architectures, including x86, SPARC,
> > PA-RISC, and IBM Mainframe.  On these architectures, reads are not
> > reordered by the CPU, so if they see the new pointer, they will also
> > see the new characters -- hence "hello".
> 
> Yes.
> 
> > Next, let's consider weakly ordered systems that respect dependency
> > ordering (ARM, PowerPC, Itanium).  The load of the pointer would
> > always be ordered with respect to any dereference of the pointer,
> > so they would always see "hello".
> 
> I'm relieved to hear that.
> 
> > This leave DEC Alpha.  In this architecture, smp_read_barrier_depends()
> > expands to smp_rmb(), which forces the ordering as required.  So
> > Alpha also sees "hello."
> 
> Yes.
> 
> > I believe that this covers all of the cases.
> > 
> > Am I missing anything?
> 
> You are right. Regarding list elements, they are appropriately protected.
> 
> 
> 
> Then, what about list heads that are dynamically allocated/initialized?
> 
> sruct hashed_word {
> 	struct list_head list;
> 	void *key;
> 	char *buf;
> };
> static struct list_head tables[1u << TABLEBIT];
> static void (*some_callback) (void *);
> 

typedef void (*some_callback_t) (void *);

static some_callback_t __rcu *some_callback;

> static void init(void)
> {
> 	int i;
> 	/* Initialize the table. */
> 	for (i = 0; i < (1u << TABLEBIT); i++)
> 		INIT_LIST_HEAD(&tables[i]);
> 	smp_wmb();
> 	/* Allow other CPUs to access the table. */
> 	some_callback = func;

rcu_assign_pointer(some_callback, func);

> }
> 
> /*
>  * This function is called by
>  *
>  *	if (some_callback)
>  *		some_callback(some_ptr);
>  *
>  * rather than
>  *
>  *	func(some_ptr);

well no, see later.

>  *
>  * .
>  */
> static void func(void *some_ptr)
> {
> 	struct hashed_word *ptr;
> 	struct list_head *table = &tables[hash_ptr(some_ptr, TABLEBIT)];
> 	/* We must make sure that readers see table->next != NULL. */


> 	smp_rmb();
Nope.. delete this

> 	rcu_read_lock();
> 	list_for_each_entry_rcu(ptr, table, list) {
> 		if (ptr->key != some_ptr)
> 			continue;
> 		printk("%s\n", ptr->buf);
> 		break;
> 	}
> 	rcu_read_unlock();
> }
> 
> How can I make sure INIT_LIST_HEAD() in init() takes effect?
> Is smp_rmb() appropriate?

Please avoid smp_rmb()/smb_wmb() and use RCU api only.

some_callback_t *ptr;

rcu_read_lock();
ptr = rcu_dereference(some_callback);
if (ptr) {
	list_for_each_entry_rcu(aux, table, list) {
 		if (aux->key != ptr)
 			continue;
 		printk("%s\n", aux->buf);
 		break;
 	}
 }
rcu_read_unlock();




  reply	other threads:[~2010-10-30  6:11 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-29 13:23 Tetsuo Handa
2010-10-29 15:09 ` Paul E. McKenney
2010-10-30  5:48   ` Tetsuo Handa
2010-10-30  6:11     ` Eric Dumazet [this message]
2010-10-30 12:40       ` Tetsuo Handa
  -- strict thread matches above, loose matches on Subject: below --
2010-09-20 10:34 memory " George Spelvin
2010-09-15 14:36 Miklos Szeredi
2010-09-15 19:12 ` Rafael J. Wysocki
2010-09-16 11:55 ` David Howells
2010-09-16 13:42   ` Miklos Szeredi
2010-09-16 14:30   ` David Howells
2010-09-16 15:03     ` Paul E. McKenney
2010-09-16 16:06       ` Miklos Szeredi
2010-09-16 16:37         ` Paul E. McKenney
2010-09-16 16:56           ` Miklos Szeredi
2010-09-16 17:09             ` James Bottomley
2010-09-16 17:17               ` Miklos Szeredi
2010-09-16 17:40                 ` James Bottomley
2010-09-17 21:49                 ` Benjamin Herrenschmidt
2010-09-17 23:12                   ` Paul E. McKenney
2010-09-19  2:47                     ` Benjamin Herrenschmidt
2010-09-19 15:26                       ` Paul E. McKenney
2010-09-19 20:15                         ` Miklos Szeredi
2010-09-19 21:59                           ` Paul E. McKenney
2010-09-20  0:58                             ` James Bottomley
2010-09-20  1:29                               ` Paul E. McKenney
2010-09-20 16:01                                 ` Miklos Szeredi
2010-09-20 18:25                                   ` Paul E. McKenney
2010-09-20 18:57                                     ` Paul E. McKenney
2010-09-20 20:26                                     ` Michael Cree
2010-09-20 20:40                                       ` Paul E. McKenney
2010-09-21 14:59                                         ` Paul E. McKenney
2010-09-22 18:41                                           ` Paul E. McKenney
2010-09-18  1:12                   ` Alan Cox
2010-09-16 16:50         ` Jamie Lokier
2010-09-16 16:18   ` Peter Zijlstra
2010-09-16 17:59   ` David Howells

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=1288419071.2680.648.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    /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®