* locking problems with mips atomicity ?
@ 2004-04-20 22:44 Harm Verhagen
2004-04-20 22:49 ` Daniel Jacobowitz
0 siblings, 1 reply; 5+ messages in thread
From: Harm Verhagen @ 2004-04-20 22:44 UTC (permalink / raw)
To: linux-mips
Hi folks,
I noticed the following thread "locking problem with mips atomicity" on
the GCC mailing list, and I started to wonder if the linux kernel has
the same problem.
http://gcc.gnu.org/ml/gcc/2004-03/threads.html#01061
It about the problem that gcc can generate loads (using AT) in between
the ll and sc instructions (which is not legal according to the MIPS
spec) This can happen when incorrect constraints are used with the
inline assembly, and the inline assembly happens to be in an inline
functions.
The code from linux 2.4.26 arch-mips/atomic.h looks _very_ similar to
the code described in the thread that has a BUG.
static __inline__ void atomic_add(int i, atomic_t * v)
{
unsigned long temp;
__asm__ __volatile__(
"1: ll %0, %1 # atomic_add\n"
" addu %0, %2 \n"
" sc %0, %1 \n"
" beqz %0, 1b \n"
: "=&r" (temp), "=m" (v->counter)
: "Ir" (i), "m" (v->counter));
}
So I wonder if there is a bug here.
Can some MIPS guru check ? :)
Please copy me on replies as I'm not subscribed
Kind regards,
Harm Verhagen
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: locking problems with mips atomicity ?
2004-04-20 22:44 locking problems with mips atomicity ? Harm Verhagen
@ 2004-04-20 22:49 ` Daniel Jacobowitz
2004-04-20 22:53 ` Harm Verhagen
2004-04-21 12:43 ` Maciej W. Rozycki
0 siblings, 2 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2004-04-20 22:49 UTC (permalink / raw)
To: Harm Verhagen; +Cc: linux-mips
On Wed, Apr 21, 2004 at 12:44:34AM +0200, Harm Verhagen wrote:
> The code from linux 2.4.26 arch-mips/atomic.h looks _very_ similar to
> the code described in the thread that has a BUG.
>
> static __inline__ void atomic_add(int i, atomic_t * v)
> {
> unsigned long temp;
>
> __asm__ __volatile__(
> "1: ll %0, %1 # atomic_add\n"
> " addu %0, %2 \n"
> " sc %0, %1 \n"
> " beqz %0, 1b \n"
> : "=&r" (temp), "=m" (v->counter)
> : "Ir" (i), "m" (v->counter));
> }
>
> So I wonder if there is a bug here.
> Can some MIPS guru check ? :)
It won't be a problem in the kernel. The problem only happens when the
assembler expands a macro to multiple instructions including a load,
and that only happens for position-independent code; the kernel is not
PIC.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: locking problems with mips atomicity ?
2004-04-20 22:49 ` Daniel Jacobowitz
@ 2004-04-20 22:53 ` Harm Verhagen
2004-04-20 22:56 ` Daniel Jacobowitz
2004-04-21 12:43 ` Maciej W. Rozycki
1 sibling, 1 reply; 5+ messages in thread
From: Harm Verhagen @ 2004-04-20 22:53 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: linux-mips
On Wed, 2004-04-21 at 00:49, Daniel Jacobowitz wrote:
> On Wed, Apr 21, 2004 at 12:44:34AM +0200, Harm Verhagen wrote:
> > The code from linux 2.4.26 arch-mips/atomic.h looks _very_ similar to
> > the code described in the thread that has a BUG.
> >
> > static __inline__ void atomic_add(int i, atomic_t * v)
> > {
> > unsigned long temp;
> >
> > __asm__ __volatile__(
> > "1: ll %0, %1 # atomic_add\n"
> > " addu %0, %2 \n"
> > " sc %0, %1 \n"
> > " beqz %0, 1b \n"
> > : "=&r" (temp), "=m" (v->counter)
> > : "Ir" (i), "m" (v->counter));
> > }
> >
> > So I wonder if there is a bug here.
> > Can some MIPS guru check ? :)
>
> It won't be a problem in the kernel. The problem only happens when the
> assembler expands a macro to multiple instructions including a load,
> and that only happens for position-independent code; the kernel is not
> PIC.
Sorry for not understanding completely. What makes the gcc code PIC
then? The code looks similar, an inline function with inline assembly.
Could you elaborate ?
Kind regards,
Harm
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: locking problems with mips atomicity ?
2004-04-20 22:53 ` Harm Verhagen
@ 2004-04-20 22:56 ` Daniel Jacobowitz
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2004-04-20 22:56 UTC (permalink / raw)
To: Harm Verhagen; +Cc: linux-mips
On Wed, Apr 21, 2004 at 12:53:56AM +0200, Harm Verhagen wrote:
> On Wed, 2004-04-21 at 00:49, Daniel Jacobowitz wrote:
> > On Wed, Apr 21, 2004 at 12:44:34AM +0200, Harm Verhagen wrote:
> > > The code from linux 2.4.26 arch-mips/atomic.h looks _very_ similar to
> > > the code described in the thread that has a BUG.
> > >
> > > static __inline__ void atomic_add(int i, atomic_t * v)
> > > {
> > > unsigned long temp;
> > >
> > > __asm__ __volatile__(
> > > "1: ll %0, %1 # atomic_add\n"
> > > " addu %0, %2 \n"
> > > " sc %0, %1 \n"
> > > " beqz %0, 1b \n"
> > > : "=&r" (temp), "=m" (v->counter)
> > > : "Ir" (i), "m" (v->counter));
> > > }
> > >
> > > So I wonder if there is a bug here.
> > > Can some MIPS guru check ? :)
> >
> > It won't be a problem in the kernel. The problem only happens when the
> > assembler expands a macro to multiple instructions including a load,
> > and that only happens for position-independent code; the kernel is not
> > PIC.
> Sorry for not understanding completely. What makes the gcc code PIC
> then? The code looks similar, an inline function with inline assembly.
> Could you elaborate ?
You may want to look for documentation describing the MIPS PIC
conventions. Good luck; they're bizarre.
The problem is that in userspace "ll $2, symbol_name" may expand to a
load of the address of symbol_name from the GOT (global offset table).
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: locking problems with mips atomicity ?
2004-04-20 22:49 ` Daniel Jacobowitz
2004-04-20 22:53 ` Harm Verhagen
@ 2004-04-21 12:43 ` Maciej W. Rozycki
1 sibling, 0 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2004-04-21 12:43 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: Harm Verhagen, linux-mips
On Tue, 20 Apr 2004, Daniel Jacobowitz wrote:
> > static __inline__ void atomic_add(int i, atomic_t * v)
> > {
> > unsigned long temp;
> >
> > __asm__ __volatile__(
> > "1: ll %0, %1 # atomic_add\n"
> > " addu %0, %2 \n"
> > " sc %0, %1 \n"
> > " beqz %0, 1b \n"
> > : "=&r" (temp), "=m" (v->counter)
> > : "Ir" (i), "m" (v->counter));
> > }
> >
> > So I wonder if there is a bug here.
> > Can some MIPS guru check ? :)
>
> It won't be a problem in the kernel. The problem only happens when the
> assembler expands a macro to multiple instructions including a load,
> and that only happens for position-independent code; the kernel is not
> PIC.
And if using a function like the above is to be PIC, the solution is to
use the "R" constraint for the ll/sc memory operand to assure it's passed
to gas as a machine-expressible address, although I'm not sure if that's
currently handled by gcc correctly (2.95.x definitely has problems with
it; I'm going to look into it for 3.5.0 soon).
--
+ Maciej W. Rozycki, Technical University of Gdansk, Poland +
+--------------------------------------------------------------+
+ e-mail: macro@ds2.pg.gda.pl, PGP key available +
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-04-21 12:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-20 22:44 locking problems with mips atomicity ? Harm Verhagen
2004-04-20 22:49 ` Daniel Jacobowitz
2004-04-20 22:53 ` Harm Verhagen
2004-04-20 22:56 ` Daniel Jacobowitz
2004-04-21 12:43 ` Maciej W. Rozycki
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.