#1935 closed defect (fixed)

SMP: nested locking count variable overwritten

Reported by: Daniel Hellstrom Owned by: Joel Sherrill
Priority: normal Milestone: 4.11
Component: score Version: 4.11
Severity: normal Keywords:
Cc: jennifer.averett@…, jiri@… Blocked By:
Blocking:

Description

Hello,

Please see patch below, it tries to fix a problem when a nested lock is taken more than once (lock->count > 1) and another CPU not owning it tries to acquire it. What happens is that count is overwritten by SWAP with a value of 1, since it is used as the locking variable as well. This could have been made working if the CASA instruction was used.

To fix the problem I see no other solution than to add a locking variable, so I did, please see below.

Regards,
Daniel

Index: cpukit/score/src/smplock.c
===================================================================
RCS file: /usr1/CVS/rtems/cpukit/score/src/smplock.c,v
retrieving revision 1.4
diff -u -r1.4 smplock.c
--- cpukit/score/src/smplock.c 22 Aug 2011 18:26:08 -0000 1.4
+++ cpukit/score/src/smplock.c 11 Oct 2011 16:18:12 -0000
@@ -114,6 +114,7 @@

SMP_lock_spinlock_nested_Control *lock

)
{

+ lock->lock = 0;

lock->count = 0;
lock->cpu_id = -1;

}

@@ -143,8 +144,9 @@

if (lock->count == 1) {

lock->cpu_id = -1;
debug_logit( 'U', lock );

  • RTEMS_COMPILER_MEMORY_BARRIER();

lock->count = 0;

+ RTEMS_COMPILER_MEMORY_BARRIER();
+ lock->lock = 0;

} else {

debug_logit( 'u', lock );
lock->count--;

@@ -174,7 +176,7 @@

*/

while (1) {

RTEMS_COMPILER_MEMORY_BARRIER();

  • SMP_CPU_SWAP( &lock->count, value, previous );

+ SMP_CPU_SWAP( &lock->lock, value, previous );

RTEMS_COMPILER_MEMORY_BARRIER();
if ( previous == 0 ) {

/* was not locked */

@@ -190,6 +192,7 @@

}


lock->cpu_id = cpu_id;

+ lock->count = 1;

debug_logit( 'L', lock );


return level;

Index: cpukit/score/include/rtems/score/smplock.h
===================================================================
RCS file: /usr1/CVS/rtems/cpukit/score/include/rtems/score/smplock.h,v
retrieving revision 1.5
diff -u -r1.5 smplock.h
--- cpukit/score/include/rtems/score/smplock.h 1 Aug 2011 17:30:20 -0000 1.5
+++ cpukit/score/include/rtems/score/smplock.h 11 Oct 2011 16:18:12 -0000
@@ -50,6 +50,7 @@

  • times. */

typedef struct {

+ SMP_lock_spinlock_simple_Control lock;

uint32_t count;
int cpu_id;

} SMP_lock_spinlock_nested_Control;

Attachments (1)

smplock1.patch (1.7 KB) - added by Daniel Hellstrom on 10/11/11 at 15:28:25.
SMP Nested locks patch

Download all attachments as: .zip

Change History (4)

Changed on 10/11/11 at 15:28:25 by Daniel Hellstrom

Attachment: smplock1.patch added

SMP Nested locks patch

comment:1 Changed on 10/11/11 at 15:29:06 by Daniel Hellstrom

Cc: jennifer.averett@… jiri@… added

comment:2 Changed on 10/17/11 at 17:52:22 by Jennifer Averett

Resolution: fixed
Status: newclosed

Applied patch to head.

comment:3 Changed on 11/24/14 at 18:58:28 by Gedare Bloom

Version: HEAD4.11

Replace Version=HEAD with Version=4.11 for the tickets with Milestone >= 4.11

Note: See TracTickets for help on using tickets.