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, Oct 28, 3:36 AM
Unknown Object (File)
Mon, Oct 21, 12:45 PM
Unknown Object (File)
Sun, Oct 20, 7:13 AM
Unknown Object (File)
Sun, Oct 20, 6:00 AM
Unknown Object (File)
Sep 28 2024, 7:55 AM
Unknown Object (File)
Sep 27 2024, 7:07 PM
Unknown Object (File)
Sep 27 2024, 12:47 PM
Unknown Object (File)
Sep 24 2024, 7:04 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