qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paul Brook <paul@codesourcery.com>
To: qemu-devel@nongnu.org
Cc: Nathan Froyd <froydnj@codesourcery.com>
Subject: Re: [Qemu-devel] [PATCH 0/7] target-ppc/linux-user: NPTL support
Date: Sat, 6 Jun 2009 03:56:55 +0100	[thread overview]
Message-ID: <200906060356.56398.paul@codesourcery.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0906060302040.27655@linmac.oyster.ru>

On Saturday 06 June 2009, malc wrote:
> On Thu, 4 Jun 2009, Nathan Froyd wrote:
> > This patch series adds NPTL support in Linux user-mode emulation to
> > 32-bit PowerPC targets.
> >
> > The main complication comes from implementing atomic instructions
> > properly.  We chose to implement a simplistic model:
> >
> > - reserved loads record the value loaded;

An important point here is that the address/value pair is per thread/cpu.
A nice side-effect is that these loads reduce to a simple atomic load and some 
thread local bookkeeping. Conditional stores require somewhat more exotic 
atomic operations, but still don't need to go poking at system global state or 
other CPUs.
This sounds strange at first reading, but ll/sc semantics are deliberately 
designed to minimize contention between unrelated CPUs/resources in large 
systems.

> > - conditional stores check that the memory at the effective address
> >   contains the value loaded by the previous reserved load, in addition
> >   to all other checks.  if so, the store succeeds; otherwise, it fails.
>
> I think this will break code that relies on the fact that ll/sc is not
> affected by the ABA problem.

I'm not absolutely certain about PPC, but on other architectures (ARM, MIPS, 
Alpha) this implementation is sufficient.

The only questionable case is when a second thread overwrites and then 
restores the original value between a locked load and a conditional store. 
However limited coherency and memory ordering between CPUs make it impossible 
to know whether this modify+restore occurred before or after the initial load.

The worst that can happen here is that another thread gains and releases the 
lock[1] while the current thread is in the process of acquiring the lock.  
Even when this happens it is impossible for two threads to acquire the lock 
simultaneously. The only difference is the window between ll and sc. During 
this period we don't know whether we have the lock or not, so it's extremely 
unlikely that we will do anything that relies on no other thread having the 
lock. In practice ll/sc are always used as matching pairs with no intervening 
memory accesses, so this is never a problem.

I could probably come up with synthetic testcases where qemu behavior is 
observably different to real hardware. However I'm pretty certain this never 
occurs in real code, and it is questionable whether such behavior is 
architecturally defined.

If you still believe this is a problem you need come up with an actual 
testcase that demonstrates how this can introduce a race condition.

Paul

[1] Lock acquisition is the most obvious example, but the same applies to any 
atomic operation implemented on top of ll/sc. 

  reply	other threads:[~2009-06-06  2:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-04 18:51 [Qemu-devel] [PATCH 0/7] target-ppc/linux-user: NPTL support Nathan Froyd
2009-06-04 18:51 ` [Qemu-devel] [PATCH 1/7] linux-user: initialize mmap_mutex properly Nathan Froyd
2009-06-04 18:51 ` [Qemu-devel] [PATCH 2/7] target-ppc: fix cpu_clone_regs Nathan Froyd
2009-06-04 18:51 ` [Qemu-devel] [PATCH 3/7] target-ppc: add cpu_set_tls Nathan Froyd
2009-06-04 18:51 ` [Qemu-devel] [PATCH 4/7] target-ppc: retain l{w,d}arx loaded value Nathan Froyd
2009-06-10 15:59   ` Riku Voipio
2009-06-04 18:52 ` [Qemu-devel] [PATCH 5/7] target-ppc: add exceptions for conditional stores Nathan Froyd
2009-06-04 18:52 ` [Qemu-devel] [PATCH 6/7] linux-user: handle POWERPC_EXCP_STCX Nathan Froyd
2009-06-04 18:52 ` [Qemu-devel] [PATCH 7/7] enable NPTL for ppc-linux-user targets in configure Nathan Froyd
2009-06-05 23:04 ` [Qemu-devel] [PATCH 0/7] target-ppc/linux-user: NPTL support malc
2009-06-06  2:56   ` Paul Brook [this message]
2009-07-06 15:28   ` Nathan Froyd
2009-06-09 23:37 ` Miklos Vajna
2009-06-10  0:24   ` Daniel Jacobowitz
2009-06-10  0:30     ` Miklos Vajna
2009-06-10  2:49       ` Daniel Jacobowitz
2009-06-10  9:31         ` Miklos Vajna
2009-06-10  0:57   ` Laurent Vivier
2009-06-10  9:28     ` Miklos Vajna
  -- strict thread matches above, loose matches on Subject: below --
2009-06-10  9:36 Laurent Vivier
2009-06-10 10:15 ` Miklos Vajna
2009-06-10 10:44 Laurent Vivier
2009-06-10 10:50 ` Miklos Vajna
2009-06-10 10:54 Laurent Vivier
2009-06-10 11:10 ` Miklos Vajna

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=200906060356.56398.paul@codesourcery.com \
    --to=paul@codesourcery.com \
    --cc=froydnj@codesourcery.com \
    --cc=qemu-devel@nongnu.org \
    /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).