Skip to content

refactor(uffd): add UFFD_EVENT_REMOVE constants and zero/wp/wake ioctls#2444

Open
ValentaTomas wants to merge 1 commit intomainfrom
refactor/uffd-add-remove-ioctl-constants
Open

refactor(uffd): add UFFD_EVENT_REMOVE constants and zero/wp/wake ioctls#2444
ValentaTomas wants to merge 1 commit intomainfrom
refactor/uffd-add-remove-ioctl-constants

Conversation

@ValentaTomas
Copy link
Copy Markdown
Member

@ValentaTomas ValentaTomas commented Apr 18, 2026

Purely additive cgo wiring extracted from #1896. No callers yet, no behaviour change — a reviewer only needs to confirm the new constants/structs/ioctls match linux/userfaultfd.h.

Adds:

  • Constants: UFFD_EVENT_REMOVE, UFFDIO_{ZEROPAGE,WRITEPROTECT,WAKE}, UFFDIO_WRITEPROTECT_MODE_WP, UFFDIO_ZEROPAGE_MODE_DONTWAKE, UFFD_PAGEFAULT_FLAG_{MINOR,WP}, UFFD_FEATURE_EVENT_REMOVE.
  • Types: UffdRemove (local mirror — kernel header doesn't expose the struct), UffdioZero.
  • (Fd).zero, (Fd).writeProtect, (Fd).wake — same shape as the existing (Fd).copy.

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 18, 2026

PR Summary

Low Risk
Additive cgo wiring and new ioctl helpers with no current callers; main risk is mismatched kernel constants/struct layouts causing failures once used.

Overview
Extends the userfaultfd cgo bindings to cover UFFD_EVENT_REMOVE and additional userfaultfd operations by adding missing constants/flags, a local uffd_remove struct mirror, and new Fd helpers for UFFDIO_ZEROPAGE, UFFDIO_WRITEPROTECT, and UFFDIO_WAKE (including basic page-alignment and return-size checking similar to existing copy).

Reviewed by Cursor Bugbot for commit e61c569. Bugbot is set up for automated code reviews on this repo. Configure here.

@ValentaTomas ValentaTomas changed the base branch from feat/firecracker-v1.14 to main April 18, 2026 21:54
@ValentaTomas ValentaTomas enabled auto-merge (squash) April 18, 2026 21:54
Comment thread packages/orchestrator/pkg/sandbox/uffd/userfaultfd/fd.go
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — purely additive cgo wiring with one cosmetic nit (see inline comment).

Extended reasoning...

Overview

Single-file change adding new constants, types, and methods to . All additions are mechanical mirrors of kernel macros from , following the exact same pattern as the existing implementation. No callers yet, no behaviour change.

Security Risks

None. This is low-level ioctl wiring with no auth, crypto, or permission logic. The new methods follow the same syscall pattern as the existing .

Level of Scrutiny

Low. The PR explicitly isolates kernel-header-mechanical work. The reviewer task is confirming constants/structs/ioctls match the kernel headers, which they do. All added code is dead code until a caller is wired up in a subsequent PR.

Other Factors

The one bug found (inline comment) is a cosmetic copy-paste artifact in an error string — "copied" instead of "zeroed" in . It has zero functional impact and no callers yet, so it does not warrant blocking the PR. Tests pass, linter clean.

Comment thread packages/orchestrator/pkg/sandbox/uffd/userfaultfd/fd.go
Purely additive cgo wiring extracted from #1896, in preparation for the
free-page-reporting feature work that will actually use these.

New constants:
- UFFD_EVENT_REMOVE
- UFFDIO_WRITEPROTECT_MODE_WP
- UFFDIO_ZEROPAGE_MODE_DONTWAKE
- UFFDIO_ZEROPAGE / UFFDIO_WRITEPROTECT / UFFDIO_WAKE
- UFFD_PAGEFAULT_FLAG_MINOR / UFFD_PAGEFAULT_FLAG_WP
- UFFD_FEATURE_EVENT_REMOVE

New types:
- UffdRemove (mirrors struct uffd_remove for events)
- UffdioZero (= C.struct_uffdio_zeropage)

New helper constructors and Fd methods:
- newUffdioZero, newUffdioWriteProtect
- (Fd).zero  - UFFDIO_ZEROPAGE ioctl
- (Fd).writeProtect - UFFDIO_WRITEPROTECT ioctl
- (Fd).wake  - UFFDIO_WAKE ioctl

No callers yet; this is intentionally a small, mechanically reviewable
diff against kernel headers (linux/userfaultfd.h, sys/ioctl.h). Behaviour
of existing code is unchanged.
@ValentaTomas ValentaTomas force-pushed the refactor/uffd-add-remove-ioctl-constants branch from 44b998c to e61c569 Compare April 18, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants