[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations
From: |
Jamie Lokier |
Subject: |
Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations |
Date: |
Wed, 19 Sep 2012 14:32:01 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
liu ping fan wrote:
> >> +static inline void atomic_set(Atomic *v, int i)
> >> +{
> >> + v->counter = i;
> >> +}
Hi,
When running on ARM Linux kernels prior to 2.6.32, userspace
atomic_set() needs to use "clrex" or "strex" too.
See Linux commit 200b812d, "Clear the exclusive monitor when returning
from an exception".
You can see ARM's atomic_set() used to use "strex", and warns it's
important. The kernel patch allows atomic_set() to be simplified, and
that includes for userspace, by putting clrex/strex in the exception
return path instead.
However, someone may run QEMU on a kernel before 2.6.32, which isn't
that old. (E.g. my phone is running 2.6.28).
Otherwise you can have this situation:
Initially: a = 0.
Thread
atomic_inc(&a, 1)
= ldrex, add, [strex interrupted]
Interrupted by signal handler
atomic_set(&a, 3)
= str
Signal return
Resume thread
= strex (succeeds because CPU-local exclusive-flag still set)
Result: a = 1, should be impossible when the signal triggered, and
information about the signal is lost.
A more realistic example would use atomic_compare_exchange(), to
atomic-read-and-clear, atomic-read-and-dec-if-not-zero a variable set
in a signal handler, however I've used atomic_inc() to illustrate
because that's in your patch.
Best,
-- Jamie
- [Qemu-devel] [PATCH V3 0/10] prepare unplug out of protection of global lock, Liu Ping Fan, 2012/09/11
- [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Liu Ping Fan, 2012/09/11
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Avi Kivity, 2012/09/11
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, liu ping fan, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Avi Kivity, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Paolo Bonzini, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Avi Kivity, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Paolo Bonzini, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, liu ping fan, 2012/09/13
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Jamie Lokier, 2012/09/19
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations,
Jamie Lokier <=
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Peter Maydell, 2012/09/19
- Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Jamie Lokier, 2012/09/19
Re: [Qemu-devel] [PATCH V3 01/11] atomic: introduce atomic operations, Peter Maydell, 2012/09/11
[Qemu-devel] [PATCH V3 02/11] qom: apply atomic on object's refcount, Liu Ping Fan, 2012/09/11
[Qemu-devel] [PATCH V3 03/11] hotplug: introduce qdev_unplug_complete() to remove device from views, Liu Ping Fan, 2012/09/11
[Qemu-devel] [PATCH V3 04/11] pci: remove pci device from mem view when unplug, Liu Ping Fan, 2012/09/11
[Qemu-devel] [PATCH V3 05/11] memory: introduce ref, unref interface for MemoryRegionOps, Liu Ping Fan, 2012/09/11
[Qemu-devel] [PATCH V3 07/11] memory: implement e1000's MemoryRegionOps ref/unref, Liu Ping Fan, 2012/09/11