xen/spinlock: move debug helpers inside the locked regions
PATCH 1/1 xen/spinlock: move debug helpers inside the locked regions
Debug helpers such as lock profiling or the invariant pCPU assertions must strictly be performed inside the exclusive locked region, or else races might happen.
Note the issue was not strictly introduced by the pointed commit in the Fixes tag, since lock stats where already incremented before the barrier, but that commit made it more apparent as manipulating the cpu field could happen outside of the locked regions and thus trigger the BUG_ON. This is only enabled on debug builds, and thus releases are not affected.
--- xen/common/spinlock.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
xen/common/spinlock.c +6 -6
@@ -170,9 +170,9 @@ void inline _spin_lock_cb(spinlock_t *lock, void (*cb)(void *), void *data)cb (data);arch_lock_relax (); } +arch_lock_acquire_barrier ();got_lock (&lock->debug);LOCK_PROFILE_GOT ; -arch_lock_acquire_barrier (); }void _spin_lock (spinlock_t *lock)
@@ -198,9 +198,9 @@ unsigned long _spin_lock_irqsave(spinlock_t *lock)void _spin_unlock (spinlock_t *lock) { -arch_lock_release_barrier ();LOCK_PROFILE_REL ;rel_lock (&lock->debug); +arch_lock_release_barrier ();add_sized (&lock->tickets.head,1 );arch_lock_signal ();preempt_enable ();
@@ -249,15 +249,15 @@ int _spin_trylock(spinlock_t *lock)preempt_enable ();return 0 ; } +/* +* cmpxchg() is a full barrier so no need for an +* arch_lock_acquire_barrier(). +*/ got_lock (&lock->debug);#ifdef CONFIG_DEBUG_LOCK_PROFILE if (lock->profile) lock->profile->time_locked =NOW ();#endif -/* -* cmpxchg() is a full barrier so no need for an -* arch_lock_acquire_barrier(). -*/ return 1 ; }
Signature · 1 line
2.27.0
Hi Roger,
Quoted 9 lines · Roger Pau Monne
Debug helpers such as lock profiling or the invariant pCPU assertions must strictly be performed inside the exclusive locked region, or else races might happen.
Note the issue was not strictly introduced by the pointed commit in the Fixes tag, since lock stats where already incremented before the barrier, but that commit made it more apparent as manipulating the cpu field could happen outside of the locked regions and thus trigger the
BUG_ON.
From the wording, it is not entirely clear which BUG_ON() you are referring to. I am guessing, it is the one in rel_lock(). Am I correct?
Otherwise, the change looks good to me.
Cheers,
Quoted 57 lines
This is only enabled on debug builds, and thus releases are not affected.
Fixes 80cba391a35 ('spinlocks: in debug builds store cpu holding the lock')Reported-by Igor Druzhinin <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>--- xen/common/spinlock.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)xen/common/spinlock.c +6
-6@@ -170,9 +170,9 @@ void inline _spin_lock_cb(spinlock_t *lock, void (*cb)(void *), void *data)cb (data);arch_lock_relax (); } +arch_lock_acquire_barrier ();got_lock (&lock->debug);LOCK_PROFILE_GOT ; -arch_lock_acquire_barrier (); }void _spin_lock (spinlock_t *lock)@@ -198,9 +198,9 @@ unsigned long _spin_lock_irqsave(spinlock_t *lock)void _spin_unlock (spinlock_t *lock) { -arch_lock_release_barrier ();LOCK_PROFILE_REL ;rel_lock (&lock->debug); +arch_lock_release_barrier ();add_sized (&lock->tickets.head,1 );arch_lock_signal ();preempt_enable ();@@ -249,15 +249,15 @@ int _spin_trylock(spinlock_t *lock)preempt_enable ();return 0 ; } +/* +* cmpxchg() is a full barrier so no need for an +* arch_lock_acquire_barrier(). +*/ got_lock (&lock->debug);#ifdef CONFIG_DEBUG_LOCK_PROFILE if (lock->profile) lock->profile->time_locked =NOW ();#endif -/* -* cmpxchg() is a full barrier so no need for an -* arch_lock_acquire_barrier(). -*/ return 1 ; }
Signature · 1 line
Julien Grall
Quoted 7 lines · Julien Grall
Hi Roger,
Quoted 4 lines · Roger Pau Monne
Debug helpers such as lock profiling or the invariant pCPU assertions must strictly be performed inside the exclusive locked region, or else races might happen.
Quoted 8 lines
Quoted 5 lines
Note the issue was not strictly introduced by the pointed commit in the Fixes tag, since lock stats where already incremented before the barrier, but that commit made it more apparent as manipulating the cpu field could happen outside of the locked regions and thus trigger the
BUG_ON.From the wording, it is not entirely clear which
BUG_ON()you are referring to. I am guessing, it is the one inrel_lock(). Am I correct?
Yes, that's right. Expanding to:
"... and thus trigger the BUG_ON in rel_lock()." would be better.
Quoted 1 line
Otherwise, the change looks good to me.
Thanks.
Julien Grall
Reviewed-byHi Roger,
Quoted 14 lines · Roger Pau Monné
Quoted 13 lines · Julien Grall
Hi Roger,
Quoted 9 lines · Roger Pau Monne
Debug helpers such as lock profiling or the invariant pCPU assertions must strictly be performed inside the exclusive locked region, or else races might happen.
Note the issue was not strictly introduced by the pointed commit in the Fixes tag, since lock stats where already incremented before the barrier, but that commit made it more apparent as manipulating the cpu field could happen outside of the locked regions and thus trigger the
BUG_ON.
Quoted 6 lines
Quoted 2 lines
From the wording, it is not entirely clear which
BUG_ON()you are referring
to. I am guessing, it is the one inrel_lock(). Am I correct?Yes, that's right. Expanding to:
"... and thus trigger the
BUG_ONinrel_lock()." would be better.
Looks good to me. With that:
I am happy to do the update on commit if there is no more comments.
Cheers,
Signature · 1 line
Julien Grall
Quoted 22 lines · Julien Grall
Hi Roger,
Quoted 19 lines · Roger Pau Monné
Quoted 7 lines · Julien Grall
Hi Roger,
Quoted 4 lines · Roger Pau Monne
Debug helpers such as lock profiling or the invariant pCPU assertions must strictly be performed inside the exclusive locked region, or else races might happen.
Quoted 8 lines
Quoted 5 lines
Note the issue was not strictly introduced by the pointed commit in the Fixes tag, since lock stats where already incremented before the barrier, but that commit made it more apparent as manipulating the cpu field could happen outside of the locked regions and thus trigger the
BUG_ON.From the wording, it is not entirely clear which
BUG_ON()you are referring to. I am guessing, it is the one inrel_lock(). Am I correct?Yes, that's right. Expanding to:
Quoted 7 lines
Quoted 1 line
"... and thus trigger the
BUG_ONinrel_lock()." would be better.Looks good to me. With that:
Reviewed-by Julien Grall <[email protected]>I am happy to do the update on commit if there is no more comments.
Committed.
Thank you!
Cheers,
Signature · 1 line
Julien Grall