Page MenuHomeFreeBSD

netmap: Tell the compiler to avoid reloading ring indices
ClosedPublic

Authored by markj on Jan 15 2023, 5:03 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 22, 2:36 AM
Unknown Object (File)
Sun, Apr 21, 10:27 PM
Unknown Object (File)
Mar 4 2024, 2:44 AM
Unknown Object (File)
Feb 16 2024, 10:28 PM
Unknown Object (File)
Dec 30 2023, 10:34 AM
Unknown Object (File)
Dec 22 2023, 11:55 PM
Unknown Object (File)
Dec 12 2023, 12:26 AM
Unknown Object (File)
Dec 8 2023, 2:49 PM
Subscribers

Details

Summary

Per the removed comments these fields should be loaded only once, since
they can in principle by modified concurrently. Use atomic(9) to
declare this intent to the compiler. No functional change intended.

Diff Detail

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

Event Timeline

markj requested review of this revision.Jan 15 2023, 5:03 PM

Keep in mind that if the user writes to cur and head while the syscall is executing, then the user is breaking the ABI and the result is undefined (but no harm can happen because of the checks of the prologue).

However, we have a NM_ACCESS_ONCE macro to be portable across Linux and FreeBSD. It looks like it is equivalent to atomic_load_32 on FreeBSD (right?)
If you feel, you could at most change the definition for NM_ACCESS_ONCE #ifdef FreeBSD.

Keep in mind that if the user writes to cur and head while the syscall is executing, then the user is breaking the ABI and the result is undefined (but no harm can happen because of the checks of the prologue).

Yes, that's true. Perhaps we should simply remove the (somewhat misleading) comments instead, since it looks like a bug but isn't.

However, we have a NM_ACCESS_ONCE macro to be portable across Linux and FreeBSD. It looks like it is equivalent to atomic_load_32 on FreeBSD (right?)
If you feel, you could at most change the definition for NM_ACCESS_ONCE #ifdef FreeBSD.

We don't have a generic atomic_load(), which is what we'd want there. Perhaps it's best to just drop this patch.

I'm not sure on what you mean about the generic atomic_load...
Anyway, the original meaning of the comment is "Load the variable(s) only once, in order to avoid TOCTOU issues". We may update it to make it more clear.

I'm not sure on what you mean about the generic atomic_load...

Sorry, I misunderstood your comment. I thought that NM_READ_ONCE() had a Linux-specific implementation, but we can use it on FreeBSD too.

Anyway, the original meaning of the comment is "Load the variable(s) only once, in order to avoid TOCTOU issues". We may update it to make it more clear.

I think that using NM_READ_ONCE() is fine. I'll update the diff.

Use NM_ACCESS_ONCE() instead.

This revision is now accepted and ready to land.Jan 18 2023, 10:17 PM