-
Notifications
You must be signed in to change notification settings - Fork 182
Extract low level UFFD handler to a separate package #973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 18 commits
Commits
Show all changes
138 commits
Select commit
Hold shift + click to select a range
a929999
Wrap uffd fd in a struct with corresponding methods; Move the low lev…
ValentaTomas 58a4d41
Unify receiver name
ValentaTomas e3d6716
[WIP] Add uffd tests
ValentaTomas 56e43c8
Add disabled wp
ValentaTomas acc2d66
[WIP] WP
ValentaTomas 1c4b8ea
[WIP] Check multicopy
ValentaTomas 9d7f5e5
[WIP] Multicopy
ValentaTomas 66a1bbe
Remove experiments
ValentaTomas e774a92
Add the page alignment check (only in method)
ValentaTomas f240542
Remove commented out part
ValentaTomas f31cb47
Remove unused return field
ValentaTomas bfc5935
Cleanup
ValentaTomas f732d5a
Remove WP parts
ValentaTomas 855369b
Cleanup
ValentaTomas f981d76
Fix compile errors
ValentaTomas ccd8396
Cleanup
ValentaTomas fbf258a
Simplify offset check
ValentaTomas 67b1bfb
Clarify comment
ValentaTomas 28c48a7
Add test constant
ValentaTomas 1ecd0a1
Fix incorrect log
ValentaTomas 4fe40a0
Fix format
ValentaTomas bd8dc0b
Remove conversion
ValentaTomas f0d17ef
Make method public
ValentaTomas c4691b5
Add command context
ValentaTomas 9581305
Fix error formatting
ValentaTomas fa72b74
Fix error formatting
ValentaTomas 8230e4f
Improve error comparison
ValentaTomas 1454794
Fix error formatting
ValentaTomas ac484d2
Change process exit
ValentaTomas f2d01de
Enable unpriviledged uffd mode in GH PR tests
ValentaTomas d27b2d4
Trigger build
ValentaTomas 5e83359
Merge branch 'uffd-extract' of https://github.com/e2b-dev/infra into …
ValentaTomas 05ae2e9
Fix uffd unpriviledged enable
ValentaTomas 512fd04
Use 4k pages in uffd cross process test
ValentaTomas 1ecc810
Add access checks to tests
ValentaTomas fd77d22
Cleanup
ValentaTomas b1a6d53
Remove unused constants for now
ValentaTomas 2a329c8
Fix lint issue
ValentaTomas 44984ea
Clarify naming
ValentaTomas c5e55e3
Clarify comment
ValentaTomas b04e552
Remove yet non-relevant diagram
ValentaTomas 9607180
Remove comment
ValentaTomas 3cf3bec
Remove write protection field
ValentaTomas ac9bfdf
Add explicit mmap cleanup
ValentaTomas 3ab7848
Merge branch 'main' into uffd-extract
ValentaTomas 69954c5
Improve test names
ValentaTomas 4ce39ab
Fix test error message
ValentaTomas e8b9330
Cleanup tests
ValentaTomas e366753
Merge branch 'main' into uffd-extract
ValentaTomas 5ef4373
Fix lint error
ValentaTomas bb951ba
Add uffd write protect constants
ValentaTomas 8906575
Add UFFD write protection event diagram
ValentaTomas d89b81f
Add userfaultfd write protection methods
ValentaTomas f2a012a
Add tests todo
ValentaTomas e522612
[WIP] Add dirty tracking via WP
ValentaTomas 64e2b13
Clarify WP flow
ValentaTomas bd8988e
[WIP] Add WP to the serve loop
ValentaTomas 0dadb58
Wrap uffd fd in a struct with corresponding methods; Move the low lev…
ValentaTomas 34ccfc5
Unify receiver name
ValentaTomas 7312bca
[WIP] Add uffd tests
ValentaTomas 3c75576
Add disabled wp
ValentaTomas b67f0f2
[WIP] WP
ValentaTomas 9f1708c
[WIP] Check multicopy
ValentaTomas b07e13d
[WIP] Multicopy
ValentaTomas ff23f18
Remove experiments
ValentaTomas 389862e
Add the page alignment check (only in method)
ValentaTomas a8ec1bf
Remove commented out part
ValentaTomas 5632f63
Remove unused return field
ValentaTomas ef33099
Cleanup
ValentaTomas 5384bec
Remove WP parts
ValentaTomas f26cc5c
Cleanup
ValentaTomas 47e14b0
Fix compile errors
ValentaTomas 7ba06e7
Cleanup
ValentaTomas e91945f
Simplify offset check
ValentaTomas d4c2ea0
Clarify comment
ValentaTomas 091607e
Add test constant
ValentaTomas 7ae5f70
Fix incorrect log
ValentaTomas f9f95c5
Fix format
ValentaTomas 708d54b
Remove conversion
ValentaTomas 2aa9449
Make method public
ValentaTomas dc7dc60
Add command context
ValentaTomas 6331bd2
Fix error formatting
ValentaTomas 97ee756
Fix error formatting
ValentaTomas 03b0c46
Improve error comparison
ValentaTomas a331214
Fix error formatting
ValentaTomas 6855c56
Change process exit
ValentaTomas 359c17d
Trigger build
ValentaTomas 835a32d
Enable unpriviledged uffd mode in GH PR tests
ValentaTomas 76c3bf3
Fix uffd unpriviledged enable
ValentaTomas 0ba2a14
Use 4k pages in uffd cross process test
ValentaTomas 52d2fc7
Add access checks to tests
ValentaTomas f092687
Cleanup
ValentaTomas 3f7216a
Remove unused constants for now
ValentaTomas 7fb669e
Fix lint issue
ValentaTomas 052b09f
Clarify naming
ValentaTomas 1066947
Clarify comment
ValentaTomas d06985c
Remove yet non-relevant diagram
ValentaTomas 179ba74
Remove comment
ValentaTomas bacedce
Remove write protection field
ValentaTomas 5d4c576
Add explicit mmap cleanup
ValentaTomas fe1f562
Improve test names
ValentaTomas 70015bd
Fix test error message
ValentaTomas 6920876
Cleanup tests
ValentaTomas cb5cfdb
Fix lint error
ValentaTomas ac77fe5
Put back offset log on uffd panic
ValentaTomas c11e5ef
Fix lint errors
ValentaTomas dcea5f1
Merge branch 'main' into uffd-extract
djeebus 43f7daa
Merge branch 'main' into uffd-extract
ValentaTomas 6e6e073
Fix diagram flags
ValentaTomas 1ec8b01
Add uffd write handling
ValentaTomas f0247a0
Fix test errors
ValentaTomas 131b801
Merge branch 'uffd-extract' into use-uffd-wp-to-only-save-dirty-pages…
ValentaTomas c283d0c
Make offsetmap thread safe
ValentaTomas 7e78473
Fix merge problems; [WIP] Add triggerable uffd copy
ValentaTomas bc50b15
Fix refactor bug
ValentaTomas 96f546c
Fix compile error
ValentaTomas edb1c4c
[WIP] Refactor memory access
ValentaTomas ec4421f
Fix test after refactor
ValentaTomas f916358
Cleanup mapping
ValentaTomas 6838b66
Improve naming
ValentaTomas 0d4dc64
[WIP] Cleanup
ValentaTomas 65cf118
Fix test bugs
ValentaTomas 0505ab3
Add testing case
ValentaTomas a388c74
Cleanup
ValentaTomas 4f89a59
[WIP] Add overlay layer
ValentaTomas 2051bd6
Configure mise
ValentaTomas 8fc2164
Exclude mise tools from git
ValentaTomas 8995e6d
Extend tracker
ValentaTomas 7ac927b
[WIP] Add masked overlay
ValentaTomas 64be117
[WIP] Update masked overlay
ValentaTomas 20c0766
Remove files that will be added later
ValentaTomas ae57cb4
Cleanup
ValentaTomas 9783690
Remove files that will be added later
ValentaTomas aea1db4
Remove unnecessary change
ValentaTomas d9db61a
Cleanup
ValentaTomas 12911de
Remove files that will be added later
ValentaTomas 3b9249c
Add mapping tests
ValentaTomas 06a82ba
Add invalid event log
ValentaTomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 0 additions & 5 deletions
5
packages/orchestrator/internal/sandbox/uffd/mapping/mapping.go
This file was deleted.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package memory | ||
|
|
||
| type MemoryMap interface { | ||
| GetOffset(hostVirtAddr uintptr) (offset int64, pagesize uint64, err error) | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
packages/orchestrator/internal/sandbox/uffd/testutils/contiguous_map.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package testutils | ||
|
|
||
| // ContiguousMap is a mapping that is contiguous in the host virtual address space. | ||
| // This is used for testing purposes. | ||
| type ContiguousMap struct { | ||
| start uintptr | ||
| size uint64 | ||
| pagesize uint64 | ||
| } | ||
|
|
||
| func NewContiguousMap(start uintptr, size, pagesize uint64) *ContiguousMap { | ||
| return &ContiguousMap{ | ||
| start: start, | ||
| size: size, | ||
| pagesize: pagesize, | ||
| } | ||
| } | ||
|
|
||
| func (m *ContiguousMap) GetOffset(addr uintptr) (int64, uint64, error) { | ||
| offset := addr - m.start | ||
| pagesize := m.pagesize | ||
|
|
||
| return int64(offset), pagesize, nil | ||
| } |
48 changes: 48 additions & 0 deletions
48
packages/orchestrator/internal/sandbox/uffd/testutils/mmap.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package testutils | ||
|
|
||
| import ( | ||
| "context" | ||
| "math" | ||
| "syscall" | ||
| "unsafe" | ||
|
|
||
| "golang.org/x/sys/unix" | ||
|
|
||
| "github.com/e2b-dev/infra/packages/shared/pkg/storage/header" | ||
| ) | ||
|
|
||
| type mockSlicer struct { | ||
| content []byte | ||
| } | ||
|
|
||
| func newMockSlicer(content []byte) *mockSlicer { | ||
| return &mockSlicer{content: content} | ||
| } | ||
|
|
||
| func (s *mockSlicer) Slice(_ context.Context, offset, size int64) ([]byte, error) { | ||
| return s.content[offset : offset+size], nil | ||
| } | ||
|
|
||
| func New4KPageMmap(size uint64) ([]byte, uintptr) { | ||
| return newMockMmap(size, header.PageSize, 0) | ||
| } | ||
|
|
||
| func New2MPageMmap(size uint64) ([]byte, uintptr) { | ||
| return newMockMmap(size, header.HugepageSize, unix.MAP_HUGETLB|unix.MAP_HUGE_2MB) | ||
| } | ||
|
|
||
| func newMockMmap(size, pagesize uint64, flags int) ([]byte, uintptr) { | ||
| l := int(math.Ceil(float64(size)/float64(pagesize)) * float64(pagesize)) | ||
| b, err := syscall.Mmap( | ||
| -1, | ||
| 0, | ||
| l, | ||
| syscall.PROT_READ|syscall.PROT_WRITE, | ||
| syscall.MAP_PRIVATE|syscall.MAP_ANONYMOUS|flags, | ||
| ) | ||
| if err != nil { | ||
| return nil, 0 | ||
| } | ||
|
|
||
| return b, uintptr(unsafe.Pointer(&b[0])) | ||
| } |
31 changes: 31 additions & 0 deletions
31
packages/orchestrator/internal/sandbox/uffd/testutils/test_data.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package testutils | ||
|
|
||
| func repeatToSize(src []byte, size uint64) []byte { | ||
| if len(src) == 0 || size <= 0 { | ||
| return nil | ||
| } | ||
|
|
||
| dst := make([]byte, size) | ||
| for i := uint64(0); i < size; i += uint64(len(src)) { | ||
| end := i + uint64(len(src)) | ||
| if end > size { | ||
| end = size | ||
| } | ||
| copy(dst[i:end], src[:end-i]) | ||
| } | ||
|
|
||
| return dst | ||
| } | ||
|
|
||
| func PrepareTestData(pagesize, pagesInTestData uint64) (data *mockSlicer, size uint64) { | ||
| size = pagesize * pagesInTestData | ||
|
|
||
| data = newMockSlicer( | ||
| repeatToSize( | ||
| []byte("Hello from userfaultfd! This is our test content that should be readable after the page fault."), | ||
| size, | ||
| ), | ||
| ) | ||
|
|
||
| return data, size | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.