Page MenuHomeFreeBSD

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

Authored by chandrakanth.patil_broadcom.com on May 3 2025, 9:01 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, May 15, 2:17 PM
Unknown Object (File)
Fri, May 15, 8:22 AM
Unknown Object (File)
Fri, May 15, 8:22 AM
Unknown Object (File)
Tue, May 12, 3:40 PM
Unknown Object (File)
Mon, Apr 27, 11:12 AM
Unknown Object (File)
Apr 20 2026, 4:10 AM
Unknown Object (File)
Apr 13 2026, 5:20 PM
Unknown Object (File)
Apr 6 2026, 2:50 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.May 7 2025, 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().