• Sean Christopherson's avatar
    KVM: x86: "Reset" vcpu->run->exit_reason early in KVM_RUN · ee605e31
    Sean Christopherson authored
    Initialize run->exit_reason to KVM_EXIT_UNKNOWN early in KVM_RUN to reduce
    the probability of exiting to userspace with a stale run->exit_reason that
    *appears* to be valid.
    
    To support fd-based guest memory (guest memory without a corresponding
    userspace virtual address), KVM will exit to userspace for various memory
    related errors, which userspace *may* be able to resolve, instead of using
    e.g. BUS_MCEERR_AR.  And in the more distant future, KVM will also likely
    utilize the same functionality to let userspace "intercept" and handle
    memory faults when the userspace mapping is missing, i.e. when fast gup()
    fails.
    
    Because many of KVM's internal APIs related to guest memory use '0' to
    indicate "success, continue on" and not "exit to userspace", reporting
    memory faults/errors to userspace will set run->exit_reason and
    corresponding fields in the run structure fields in conjunction with a
    a non-zero, negative return code, e.g. -EFAULT or -EHWPOISON.  And because
    KVM already returns  -EFAULT in many paths, there's a relatively high
    probability that KVM could return -EFAULT without setting run->exit_reason,
    in which case reporting KVM_EXIT_UNKNOWN is much better than reporting
    whatever exit reason happened to be in the run structure.
    
    Note, KVM must wait until after run->immediate_exit is serviced to
    sanitize run->exit_reason as KVM's ABI is that run->exit_reason is
    preserved across KVM_RUN when run->immediate_exit is true.
    
    Link: https://lore.kernel.org/all/20230908222905.1321305-1-amoorthy@google.com
    Link: https://lore.kernel.org/all/ZFFbwOXZ5uI%2Fgdaf@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
    Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    Reviewed-by: default avatarFuad Tabba <tabba@google.com>
    Tested-by: default avatarFuad Tabba <tabba@google.com>
    Message-Id: <20231027182217.3615211-19-seanjc@google.com>
    Reviewed-by: default avatarXiaoyao Li <xiaoyao.li@intel.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    ee605e31
x86.c 368 KB