Page MenuHomeFreeBSD

mpi3mr: Add atomic decrement-if-not-zero helper
AcceptedPublic

Authored by chandrakanth.patil_broadcom.com on Sat, May 3, 9:01 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, May 31, 5:49 AM
Unknown Object (File)
Fri, May 16, 10:25 AM
Unknown Object (File)
Wed, May 14, 4:57 PM
Unknown Object (File)
Fri, May 9, 9:17 AM
Unknown Object (File)
Tue, May 6, 2:11 AM
Unknown Object (File)
Mon, May 5, 1:44 PM
Unknown Object (File)
Mon, May 5, 7:49 AM
Subscribers
None

Details

Summary

Added a generic inline helper function mpi3mr_atomic_dec_if_not_zero() that performs
a safe atomic decrement only if the current value is non-zero.

This wrapper uses atomic_fcmpset_int() to ensure lockless and thread-safe modification of
mpi3mr_atomic_t counters. It replaces non-atomic read-and-decrement patterns in the driver,
which are prone to race conditions and possible underflow under concurrent access.

Suggested by: chs

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

Hi Chs,

Thank you for reviewing and suggesting the code.

  • This patch fixes the issue for patch https://reviews.freebsd.org/D49749.
  • I will submit the other patch soon which would take care of all remaining atomic check and decrement instances in the other code path.

I think this is good...

This revision is now accepted and ready to land.Wed, May 7, 7:17 PM
In D50134#1145957, @imp wrote:

I think this is good...

Thank you for reviewing and approving it!!

this is fine as far as it goes, but the other places that already do "mpi3mr_atomic_dec(&tgtdev->block_io)" should also be converted to use the new mpi3mr_atomic_dec_if_not_zero().