shim-sgx: batch page commits and tolerate EPCM permission races - #27
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20. The composed case from #16 (gcc + IMFS grate + SGX) now compiles hello.c end to end.
What was hanging
The shim commits enclave memory one page per page fault, and each commit is its own mmap of
/dev/sgx_enclave. Device mappings never merge, so every touched page stays a VMA. gcc through the IMFS grate touches about 4 GiB, about 1M pages, andvm.max_map_counton lind-server-3 is 1,048,576. At the capmmap_hostreturns ENOMEM, the handler panics, and a shim panic isloop {}holding the HEAP lock. Every other thread that faults then spins too, which is the "three threads at 100% CPU, no output, always at the same point" signature we had been chasing.Live measurement on the wedged process: 1,048,578 VMAs, 1,048,100 of them
/dev/sgx_enclave.Change
handle_page_faultcommits up to 64 pages per fault, limited to the rest of the ledger record containing the faulting page, and only when that record has the same access and is not yet MMAPPED. NewHeap::record_at()exposes that record.Ledger::contains()cannot be used for this check because it ANDs access bits across records and would make a mixed committed/uncommitted window look uniform (a first version did this and re-EACCEPTed committed pages).PROTECTION_VIOLATION|SGXfaults on already committed pages with ledger-granted access are repaired (accept pending restrict, extend to the ledger's permissions) and retried, instead of being rejected. We hit this race once in an earlier run.