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)
Wed, Oct 8, 6:50 AM
Unknown Object (File)
Fri, Sep 19, 10:13 AM
Unknown Object (File)
Sep 13 2025, 11:42 AM
Unknown Object (File)
Sep 12 2025, 6:16 PM
Unknown Object (File)
Sep 6 2025, 6:45 PM
Unknown Object (File)
Sep 1 2025, 10:03 AM
Unknown Object (File)
Aug 30 2025, 6:00 AM
Unknown Object (File)
Aug 26 2025, 5:28 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().