Commit ac4bc0e
committed
feat: enable write-protection on guest memory
UFFD provides an API to enable write-protection for memory ranges
tracked by a userfault file descriptor. Detailed information can be
found here: https://docs.kernel.org/admin-guide/mm/userfaultfd.html.
To use the feature, users need to register the memory region with
UFFDIO_REGISTER_MODE_WP. Then, users need to enable explicitly
write-protection for sub-ranges of the registered region.
Writes in pages within write-protected memory ranges can be handled in
one of two ways. In synchronous mode, writes in a protected page will
cause kernel to send a write protection event over the userfaultfd.
In asynchronous mode, the kernel will automatically handle writes to
protected pages by clearing the write-protection bit. Userspace can
later observe the write protection bit by looking into the corresponding
entry of /proc/<pid>/pagemap.
This commit, uncoditionally, enables write protection for guest memory
using the asynchronous mode.
!NOTE!: asynchronous write protection requires (host) kernel version 6.7
or later).
Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>1 parent 7eaafb6 commit ac4bc0e
4 files changed
Lines changed: 58 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
513 | 513 | | |
514 | 514 | | |
515 | 515 | | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
516 | 520 | | |
517 | 521 | | |
518 | 522 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
| 539 | + | |
| 540 | + | |
539 | 541 | | |
540 | 542 | | |
541 | 543 | | |
| |||
560 | 562 | | |
561 | 563 | | |
562 | 564 | | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
563 | 569 | | |
564 | 570 | | |
565 | 571 | | |
| |||
568 | 574 | | |
569 | 575 | | |
570 | 576 | | |
571 | | - | |
572 | | - | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
573 | 593 | | |
574 | 594 | | |
575 | 595 | | |
| |||
0 commit comments