-
Notifications
You must be signed in to change notification settings - Fork 176
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
Open
ValentaTomas
wants to merge
51
commits into
main
Choose a base branch
from
uffd-extract
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
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 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
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
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) | ||
} | ||
17 changes: 17 additions & 0 deletions
17
packages/orchestrator/internal/sandbox/uffd/testutils/content_slicer.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,17 @@ | ||
package testutils | ||
|
||
import "context" | ||
|
||
// contentSlicer exposes byte slice via the Slicer interface. | ||
// This is used for testing purposes. | ||
type contentSlicer struct { | ||
content []byte | ||
} | ||
|
||
func newContentSlicer(content []byte) *contentSlicer { | ||
return &contentSlicer{content: content} | ||
} | ||
|
||
func (s *contentSlicer) Slice(_ context.Context, offset, size int64) ([]byte, error) { | ||
return s.content[offset : offset+size], nil | ||
} |
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
package testutils | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/e2b-dev/infra/packages/shared/pkg/utils" | ||
) | ||
|
||
// 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 | ||
|
||
accessedOffsets map[uint64]struct{} | ||
mu sync.RWMutex | ||
} | ||
|
||
func NewContiguousMap(start uintptr, size, pagesize uint64) *ContiguousMap { | ||
return &ContiguousMap{ | ||
start: start, | ||
size: size, | ||
pagesize: pagesize, | ||
accessedOffsets: make(map[uint64]struct{}), | ||
} | ||
} | ||
|
||
func (m *ContiguousMap) GetOffset(addr uintptr) (int64, uint64, error) { | ||
offset := addr - m.start | ||
pagesize := m.pagesize | ||
|
||
m.mu.Lock() | ||
m.accessedOffsets[uint64(offset)] = struct{}{} | ||
m.mu.Unlock() | ||
|
||
return int64(offset), pagesize, nil | ||
} | ||
|
||
func (m *ContiguousMap) Map() map[uint64]struct{} { | ||
return m.accessedOffsets | ||
} | ||
|
||
func (m *ContiguousMap) Keys() []uint64 { | ||
return utils.MapKeys(m.accessedOffsets) | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/orchestrator/internal/sandbox/uffd/testutils/page_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,44 @@ | ||
package testutils | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"syscall" | ||
"unsafe" | ||
|
||
"golang.org/x/sys/unix" | ||
|
||
"github.com/e2b-dev/infra/packages/shared/pkg/storage/header" | ||
) | ||
|
||
func NewPageMmap(size, pagesize uint64) ([]byte, uintptr, func() error, error) { | ||
if pagesize == header.PageSize { | ||
return newMmap(size, header.PageSize, 0) | ||
} | ||
|
||
if pagesize == header.HugepageSize { | ||
return newMmap(size, header.HugepageSize, unix.MAP_HUGETLB|unix.MAP_HUGE_2MB) | ||
} | ||
|
||
return nil, 0, nil, fmt.Errorf("unsupported page size: %d", pagesize) | ||
} | ||
|
||
func newMmap(size, pagesize uint64, flags int) ([]byte, uintptr, func() error, error) { | ||
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, nil, err | ||
} | ||
|
||
closeMmap := func() error { | ||
return syscall.Munmap(b) | ||
} | ||
|
||
return b, uintptr(unsafe.Pointer(&b[0])), closeMmap, nil | ||
} |
41 changes: 41 additions & 0 deletions
41
packages/orchestrator/internal/sandbox/uffd/testutils/random_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,41 @@ | ||
package testutils | ||
|
||
import ( | ||
"crypto/rand" | ||
) | ||
|
||
func RandomPages(pagesize, numberOfPages uint64) (data *contentSlicer, size uint64) { | ||
size = pagesize * numberOfPages | ||
|
||
n := int(size) | ||
buf := make([]byte, n) | ||
if _, err := rand.Read(buf); err != nil { | ||
panic(err) | ||
} | ||
|
||
data = newContentSlicer(buf) | ||
|
||
return data, size | ||
} | ||
|
||
// DiffByte returns the first byte index where a and b differ. | ||
// It also returns the differing byte values (want, got). | ||
// If slices are identical, it returns -1. | ||
func DiffByte(a, b []byte) (idx int, want, got byte) { | ||
minLen := len(a) | ||
if len(b) < minLen { | ||
minLen = len(b) | ||
} | ||
|
||
for i := range minLen { | ||
if a[i] != b[i] { | ||
return i, b[i], a[i] | ||
} | ||
} | ||
|
||
if len(a) != len(b) { | ||
return minLen, 0, 0 | ||
} | ||
|
||
return -1, 0, 0 | ||
} |
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.
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.