Skip to content

Make sure guest spans are setup as late as possible to avoid human error #1076

Closed

Description

@ludfjig

with #924 merging, guest span is setup before calling run_vcpu. In the future, if any spans are created in run_vcpu method, then the spans will be malformed. We should change the api to make sure this cannot happen

Activity

  1. added
    lifecycle/confirmedBug is verified or proposal seems reasonable
    and removed on Dec 17, 2025
  2. added this to the v0.13.0 milestone on Dec 17, 2025
  3. ludfjig commented on Jan 7, 2026

    @ludfjig
    ContributorAuthor

    Before #924, the guest span was set up immediately before entering the guest

    tc.setup_guest_trace(Span::current().context());
    let exit_reason = self.vcpu_fd.run();

    After #924, the span is setup in a different functions compared to where we enter the guest (note that run_vcpu does not immediately enter the guest, depending on which hv driver we use):

    tc.setup_guest_trace(Span::current().context());
    // ==== KILL() TIMING POINT 3: Before calling run() ====
    // If kill() is called and ran to completion BEFORE this line executes:
    // - Will still do a VM entry, but signals will be sent until VM exits
    let result = self.vm.run_vcpu();

    and in mshv (also see kvm and whp)

    fn run_vcpu(&mut self) -> Result<VmExit> {
    const HALT_MESSAGE: hv_message_type = hv_message_type_HVMSG_X64_HALT;
    const IO_PORT_INTERCEPT_MESSAGE: hv_message_type =
    hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT;
    const UNMAPPED_GPA_MESSAGE: hv_message_type = hv_message_type_HVMSG_UNMAPPED_GPA;
    const INVALID_GPA_ACCESS_MESSAGE: hv_message_type = hv_message_type_HVMSG_GPA_INTERCEPT;
    #[cfg(gdb)]
    const EXCEPTION_INTERCEPT: hv_message_type = hv_message_type_HVMSG_X64_EXCEPTION_INTERCEPT;
    let exit_reason = self.vcpu_fd.run();

    This means that if a developer in the future changes code so that it emits an event in between these two places (because they forgot you're not supposed to), for example at the top of run_vcpu, the event emitted on the host side will be inside the guest span (incorrect!). The fix should be to move these two places right next to each other so that it's impossible for us (developers) to forget about this in the future. Probably by passing in the tracing context to run_vcpu, and then calling setup_guest_trace right before run_vcpu

  4. added 11 commits that reference this issue on Jan 21, 2026
    6fd7f0a
    06c7c7a
    1fdf124
    20455e4
    1d620ce
    45f05bf
    7c4c7e5
    3a2f9bd
    3ec2a45
    c7586a1
    0251788
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions