// SPDX-License-Identifier: GPL-2.0-only /* * Test for x86 KVM_CAP_SYNC_REGS * * Copyright (C) 2018, Google LLC. * * Verifies expected behavior of x86 KVM_CAP_SYNC_REGS functionality, * including requesting an invalid register set, updates to/from values * in kvm_run.s.regs when kvm_valid_regs and kvm_dirty_regs are toggled.
*/ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <pthread.h>
/* * ucall is embedded here to protect against compiler reshuffling registers * before calling a function. In this test we only need to get KVM_EXIT_IO * vmexit and preserve RBX, no additional information is needed.
*/ void guest_code(void)
{ asmvolatile("1: in %[port], %%al\n" "add $0x1, %%rbx\n" "jmp 1b"
: : [port] "d" (UCALL_PIO_PORT), "D" (&uc_none)
: "rax", "rbx");
}
/* * Set an exception as pending *and* injected while KVM is processing events. * KVM is supposed to ignore/drop pending exceptions if userspace is also * requesting that an exception be injected.
*/ staticvoid *race_events_inj_pen(void *arg)
{ struct kvm_run *run = (struct kvm_run *)arg; struct kvm_vcpu_events *events = &run->s.regs.events;
/* * Set an invalid exception vector while KVM is processing events. KVM is * supposed to reject any vector >= 32, as well as NMIs (vector 2).
*/ staticvoid *race_events_exc(void *arg)
{ struct kvm_run *run = (struct kvm_run *)arg; struct kvm_vcpu_events *events = &run->s.regs.events;
/* Save state *before* spawning the thread that mucks with vCPU state. */
state = vcpu_save_state(vcpu);
/* * Selftests run 64-bit guests by default, both EFER.LME and CR4.PAE * should already be set in guest state.
*/
TEST_ASSERT((run->s.regs.sregs.cr4 & X86_CR4_PAE) &&
(run->s.regs.sregs.efer & EFER_LME), "vCPU should be in long mode, CR4.PAE=%d, EFER.LME=%d",
!!(run->s.regs.sregs.cr4 & X86_CR4_PAE),
!!(run->s.regs.sregs.efer & EFER_LME));
for (t = time(NULL) + TIMEOUT; time(NULL) < t;) { /* * Reload known good state if the vCPU triple faults, e.g. due * to the unhandled #GPs being injected. VMX preserves state * on shutdown, but SVM synthesizes an INIT as the VMCB state * is architecturally undefined on triple fault.
*/ if (!__vcpu_run(vcpu) && run->exit_reason == KVM_EXIT_SHUTDOWN)
vcpu_load_state(vcpu, state);
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.1Bemerkung:
(vorverarbeitet am 2026-06-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.