All of lore.kernel.org
 help / color / mirror / Atom feed
* SPC-3 persistent reservations race condition
@ 2018-11-13 15:17 Martin Svec
  2018-11-20 18:31 ` David Disseldorp
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Martin Svec @ 2018-11-13 15:17 UTC (permalink / raw)
  To: target-devel

Hello,

during Hyper-V Cluster Validation tests, we hit a bug in SPC-3 persistent reservations
implementation where LIO iSCSI target started to loop indefinitely while freeing
a PR registration.

According to our investigation, there's the following race between pr_reg->pr_res_holders
reference counter and dev->dev_reservation_lock:

(1) Thread A enters core_scsi3_pro_preempt() and locks dev->dev_reservation_lock.

(2) Thread B enters core_scsi3_pro_preempt() and increments pr_reg->pr_res_holders
    by core_scsi3_locate_pr_reg().

(3) Thread B waits for dev->dev_reservation_lock which is held by thread A.

(4) Thread A goes through the registration list and calls __core_scsi3_free_registration()
    to remove all registrations.

(5) When __core_scsi3_free_registration() is called for pr_reg referenced by thread B
    in step 2, it ends up waiting for pr_reg->pr_res_holders = 0 indefinitely.

That is, thread A waits for thread B to decrease pr_res_holders and thread B waits
for thread A to release dev->dev_reservation_lock. 

We're able to reproduce this deadlock in LTS kernels 4.14.78 and 4.9.x but the bug
seems to be there from the beginning. I also guess that the same deadlock can occur in
core_scsi3_emulate_pro_clear() too.

Any ideas how to fix the locking?

Martin

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-11-29 13:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-13 15:17 SPC-3 persistent reservations race condition Martin Svec
2018-11-20 18:31 ` David Disseldorp
2018-11-21 13:16 ` Martin Svec
2018-11-21 13:33 ` David Disseldorp
2018-11-22 18:47 ` Martin Svec
2018-11-25 23:10 ` David Disseldorp
2018-11-29 13:40 ` Martin Svec
2018-11-29 13:57 ` David Disseldorp

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.