Page MenuHomeFreeBSD

ipsec: replace SECASVAR mtx by rmlock
ClosedPublic

Authored by kp on Jul 10 2022, 11:26 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 14 2024, 6:22 AM
Unknown Object (File)
Mar 14 2024, 6:22 AM
Unknown Object (File)
Mar 14 2024, 6:22 AM
Unknown Object (File)
Mar 14 2024, 6:22 AM
Unknown Object (File)
Mar 10 2024, 10:29 PM
Unknown Object (File)
Jan 12 2024, 6:58 AM
Unknown Object (File)
Jan 6 2024, 10:33 AM
Unknown Object (File)
Jan 6 2024, 10:33 AM

Details

Summary

This mutex is a significant point of contention in the ipsec code, and
can be relatively trivially replaced by a read-mostly lock.
It does require a separate lock for the replay protection, which we do
here by adding a separate mutex.

This improves throughput (without replay protection) by 10-15%.

Sponsored by: Orange Business Services

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kp requested review of this revision.Jul 10 2022, 11:26 AM

This is a largely mechanical substitution, there's going to be room for further improvement, but it's a somewhat significant gain already so it's worth doing anyway.

There are some places where the current locking looks odd to me, but I've not yet been able to dig further. This change doesn't improve that, but also doesn't make it any worse.

mjg added inline comments.
sys/netipsec/xform_ah.c
968

this is an example why the patch in the current form does not work: replay count gets bumped without the lock by many cpus at the same time. all places of the sort will need to be coverted to use atomics. Specifically this one will unfortunately need to be a fcmpset loop to make sure you don't bump across the limit.

i was looking at replacing this lock myself and my general idea was to use sequence counters. it would avoid degeneration from IPIs on write locking (although I don't know how frequently that's needed) and be faster single-threaded at least on amd64. However, it may happen to be slower on arm64 as it requires 2 load fences.

Ensure that all uses of 'replay' are protected by the replay mutex.

This revision was not accepted when it landed; it landed in state Needs Review.Jul 19 2022, 3:28 AM
This revision was automatically updated to reflect the committed changes.