In mpt3sas_base_clear_st() function smid value is reset in wrong line, i.e. driver should reset smid value to zero after decrementing chain_offset counter in chain_lookup table but in current code, driver is resetting smid value before decrementing the chain_offset counter. Which we are correcting with this patch. v1 changelog: Added memory barriers before & after atomic_set() API. v2 changelog: Added proper comments to describe the need of using smp_mb__before_atomic() & smp_mb__after_atomic() APIs in the driver before calling these APIs. v3 changelog: Replaced smp_mb__before_atomic() & smp_mb__after_atomic() APIs with smp_mb() APIs. Used smp_mb() API in mpt3sas_base_clear_st() to make sure that smid is reset to zero only after corresponding smid pool's chain_offset in chain lookup table is reset to zero. Used smp_mb() API in _base_get_chain_buffer_tracker() to make sure that proper chain tracker is retrieved from the corresponding smid's pool from chain table before incrementing smid pool's chain offset value. Signed-off-by: Sreekanth Reddy <sreekanth.reddy@xxxxxxxxxxxx> --- drivers/scsi/mpt3sas/mpt3sas_base.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index 902610d..2c5a5b4 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -1702,6 +1702,13 @@ static int mpt3sas_remove_dead_ioc_func(void *arg) return NULL; chain_req = &ioc->chain_lookup[smid - 1].chains_per_smid[chain_offset]; + + /* + * Added memory barrier to make sure that correct chain tracker + * is retrieved before incrementing the smid pool's chain_offset + * value in chain lookup table. + */ + smp_mb(); atomic_inc(&ioc->chain_lookup[smid - 1].chain_offset); return chain_req; } @@ -3283,8 +3290,15 @@ void mpt3sas_base_clear_st(struct MPT3SAS_ADAPTER *ioc, return; st->cb_idx = 0xFF; st->direct_io = 0; - st->smid = 0; atomic_set(&ioc->chain_lookup[st->smid - 1].chain_offset, 0); + + /* + * Added memory barrier to make sure that smid is set to zero + * only after resetting corresponding smid pool's chain_offset to zero + * in chain lookup table. + */ + smp_mb(); + st->smid = 0; } /** -- 1.8.3.1