This is an archive of the discontinued LLVM Phabricator instance.

[libc][rpc] Fix the memory ordering in lock.
ClosedPublic

Authored by JonChesterfield on May 3 2023, 2:57 PM.

Details

Summary

Prevent operation reordering with fence instead of a comment.

The mailboxes are in shared memory and the locks structure in device memory.
If the mailboxes are read and then the lock taken, the lock says nothing
about the current or future state of those mail boxes. The relaxed atomic
fetch_or can be reordered before the relaxed atomic loads of unrelated
variables unless there is a fence preventing this.

Patches both Client::try_open and Server::try_open, one of which is missing
an optimisation and the other is missing the comment, but which otherwise
could be Process::try_open followed by buffer->opcode = opcode in Client.

Diff Detail

Event Timeline

JonChesterfield created this revision.May 3 2023, 2:57 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 3 2023, 2:57 PM
JonChesterfield requested review of this revision.May 3 2023, 2:57 PM
jhuber6 accepted this revision.May 3 2023, 3:04 PM

Thanks, I forgot about the potential ordering hazard here.

This revision is now accepted and ready to land.May 3 2023, 3:04 PM
This revision was automatically updated to reflect the committed changes.