mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Dumazet <dada1@cosmosbay.com>
To: Oliver Neukum <oneukum@suse.de>
Cc: Greg KH <gregkh@suse.de>, linux-kernel@vger.kernel.org
Subject: Re: CPU ordering with respect to krefs
Date: Mon, 2 Apr 2007 16:33:54 +0200	[thread overview]
Message-ID: <20070402163354.ef741262.dada1@cosmosbay.com> (raw)
In-Reply-To: <200704021447.59476.oneukum@suse.de>

On Mon, 2 Apr 2007 14:47:59 +0200
Oliver Neukum <oneukum@suse.de> wrote:

> Hi,
> 
> some atomic operations are only atomic, not ordered. Thus a CPU is allowed
> to reorder memory references to an object to before the reference is
> obtained. This fixes it.
> 
> 	Regards
> 		Oliver
> Signed-off-by: Oliver Neukum <oneukum@suse.de>
> ------
> 
> --- a/lib/kref.c	2007-04-02 14:40:40.000000000 +0200
> +++ b/lib/kref.c	2007-04-02 14:40:50.000000000 +0200
> @@ -21,6 +21,7 @@
>  void kref_init(struct kref *kref)
>  {
>  	atomic_set(&kref->refcount,1);
> +	smp_mb();
>  }

I dont understand why smp_mb() is needed here, and not in spinlock_init() for example.

If you have ordering issues, then the caller of kref_init() should take care of it, not kref_init() itself.

Random example taken in drivers/usb/gadget/file_storage.c :

static int __init fsg_alloc(void)
{
...
kref_init(&fsg->ref);
init_completion(&fsg->thread_notifier);

the_fsg = fsg;
}

In this example, "the_fsg = fsg" memory write might be visible before the memory writes done in init_completion().
Doing a smp_mb() in kref_init() wont help.

AFAIK kref implementation doesnt need this extra smp_mb().


  reply	other threads:[~2007-04-02 14:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-02 12:47 Oliver Neukum
2007-04-02 14:33 ` Eric Dumazet [this message]
2007-04-12  6:27   ` Greg KH
2007-04-17  5:44     ` Oliver Neukum

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=20070402163354.ef741262.dada1@cosmosbay.com \
    --to=dada1@cosmosbay.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oneukum@suse.de \
    /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®