Skip to content

virt_support_x86emu: inject descriptor operand faults into the guest - #5239

Open
Sunil Muthuswamy (sunilmut) wants to merge 2 commits into
microsoft:mainfrom
sunilmut:user/sunilmut/tdx-descriptor-fault-repro
Open

Sunil Muthuswamy (sunilmut) wants to merge 2 commits into
microsoft:mainfrom
sunilmut:user/sunilmut/tdx-descriptor-fault-repro

Conversation

@sunilmut

Copy link
Copy Markdown
Member

emulate_insn_memory_op, the memory-only emulation helper used by TDX
descriptor-table instructions, passed every error to fatal_error. An
ordinary guest fault on an SGDT/SIDT/LGDT/LIDT/SLDT/STR/LLDT/LTR operand (for
example a non-present page) therefore stopped OpenHCL instead of delivering
the architectural exception to the guest. The full instruction emulation path
already injects these.

This change:

  • Makes the helper return a #[must_use] MemoryOpOutcome: Completed, or
    FaultInjected when the access faulted and the exception was injected.
  • Injects InstructionException errors (segmentation, canonical, alignment)
    and MemoryAccess errors through inject_memory_access_fault, matching the
    full emulation path. Failures with no guest event, such as host-side memory
    errors, remain fatal.
  • Makes the four TDX callers return before updating registers or advancing
    RIP on FaultInjected, so the guest re-executes the instruction after
    handling the fault. This matches their existing CPL/UMIP #GP early returns.

On TDX, check_vtl_access always succeeds and translation errors are #PF or
#GP, so only exception events reach TDX's inject_pending_event.

Test changes:

  • A non-present operand page injects #PF with the correct error code and
    address, leaving memory and RIP unchanged (fatal TripleFault before).
  • A non-canonical operand address injects #GP.
  • A translated address outside guest memory remains fatal.
  • A mapped operand still reads and writes correctly.

@sunilmut
Sunil Muthuswamy (sunilmut) requested a review from a team as a code owner November 23, 2026 00:44
Copilot AI balanced review requested due to automatic review settings November 23, 2026 00:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical descriptor-operand page-fault path drops the fault address in TDX, leaving CR2 stale and risking incorrect or repeated guest faults; CR2 propagation and a regression check are needed.

1 open issue
What changed in this PR

This PR changes OpenHCL’s TDX descriptor-operand emulation to inject guest exceptions instead of treating ordinary access faults as fatal errors.

Changes:

  • Adds MemoryOpOutcome to distinguish completed accesses from injected faults while preserving fatal host-side errors.
  • Updates all four TDX callers to stop before changing registers or advancing RIP after a fault.
  • Adds tests for page faults, non-canonical addresses, successful accesses, and fatal host-memory failures.
File Description
vmm_core/​virt_support_x86emu/​tests/​tests/​translate.rs Adds memory-only emulation success and fault regression tests.
vmm_core/​virt_support_x86emu/​src/​emulate.rs Injects operand exceptions and returns an explicit completion outcome.
openhcl/​virt_mshv_vtl/​src/​processor/​tdx/​mod.rs Stops descriptor-instruction completion when an operand fault is injected.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The TDX/VTL0 exception-delivery changes need domain-owner review and hardware-backed validation of CR2 updates, instruction restart, and register preservation beyond the mock tests.

1 open issue

Review effort: Balanced

The memory-only emulation helper used by TDX descriptor-table
instructions treated every error as fatal, so an ordinary guest page
fault on an SGDT/SIDT/LGDT/LIDT/SLDT/STR/LLDT/LTR operand stopped
OpenHCL. Inject architectural exceptions into the guest instead and
report the outcome, so TDX callers skip state updates and leave RIP
on the faulting instruction. Host-side memory failures remain fatal.

Test changes:
- Verify a non-present operand page injects #PF, not a fatal error.
- Verify a non-canonical operand address injects #GP.
- Verify host-side memory failures remain fatal.
- Verify mapped operands still read and write correctly.
Copy the pending exception's fault address to the runner's shared CR2
state before injecting a page fault. Leave CR2 unchanged for other
exceptions so descriptor operand faults reach the guest with the correct
faulting linear address.
@sunilmut
Sunil Muthuswamy (sunilmut) force-pushed the user/sunilmut/tdx-descriptor-fault-repro branch from fcb4b3d to fd88dcb Compare November 26, 2026 22:41
Copilot AI balanced review requested due to automatic review settings November 26, 2026 22:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The change affects TDX exception delivery and CR2 state across the OpenHCL/VTL0 trust boundary, while mock tests leave VM-entry delivery and instruction retry unverified, requiring hardware-backed validation and domain review.

1 open issue

Review effort: Balanced

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.

3 participants