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
F166615990: D50134.id154740.diff
Fri, Aug 14, 9:35 PM
F166615989: D50134.id.diff
Fri, Aug 14, 9:35 PM
F166615912: D50134.diff
Fri, Aug 14, 9:35 PM
Unknown Object (File)
Wed, Aug 12, 7:13 PM
Unknown Object (File)
Tue, Aug 4, 4:55 PM
Unknown Object (File)
Sat, Aug 1, 4:12 AM
Unknown Object (File)
Thu, Jul 30, 5:10 AM
Unknown Object (File)
Thu, Jul 30, 3:00 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().