Skip to content

Commit 1051e29

Browse files
committed
KVM: selftests: Drop superfluous switch() on vm->mode in vcpu_init_sregs()
Replace the switch statement on vm->mode in x86's vcpu_init_sregs()'s with a simple assert that the VM has a 48-bit virtual address space. A switch statement is both overkill and misleading, as the existing code incorrectly implies that VMs with LA57 would need different to configuration for the LDT, TSS, and flat segments. In all likelihood, the only difference that would be needed for selftests is CR4.LA57 itself. Reviewed-by: Ackerley Tng <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 2a511ca commit 1051e29

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

tools/testing/selftests/kvm/lib/x86_64/processor.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -556,29 +556,24 @@ static void vcpu_init_sregs(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
556556
{
557557
struct kvm_sregs sregs;
558558

559+
TEST_ASSERT_EQ(vm->mode, VM_MODE_PXXV48_4K);
560+
559561
/* Set mode specific system register values. */
560562
vcpu_sregs_get(vcpu, &sregs);
561563

562564
sregs.idt.limit = 0;
563565

564566
kvm_setup_gdt(vm, &sregs.gdt);
565567

566-
switch (vm->mode) {
567-
case VM_MODE_PXXV48_4K:
568-
sregs.cr0 = X86_CR0_PE | X86_CR0_NE | X86_CR0_PG;
569-
sregs.cr4 |= X86_CR4_PAE | X86_CR4_OSFXSR;
570-
sregs.efer |= (EFER_LME | EFER_LMA | EFER_NX);
571-
572-
kvm_seg_set_unusable(&sregs.ldt);
573-
kvm_seg_set_kernel_code_64bit(vm, DEFAULT_CODE_SELECTOR, &sregs.cs);
574-
kvm_seg_set_kernel_data_64bit(vm, DEFAULT_DATA_SELECTOR, &sregs.ds);
575-
kvm_seg_set_kernel_data_64bit(vm, DEFAULT_DATA_SELECTOR, &sregs.es);
576-
kvm_setup_tss_64bit(vm, &sregs.tr, 0x18);
577-
break;
578-
579-
default:
580-
TEST_FAIL("Unknown guest mode, mode: 0x%x", vm->mode);
581-
}
568+
sregs.cr0 = X86_CR0_PE | X86_CR0_NE | X86_CR0_PG;
569+
sregs.cr4 |= X86_CR4_PAE | X86_CR4_OSFXSR;
570+
sregs.efer |= (EFER_LME | EFER_LMA | EFER_NX);
571+
572+
kvm_seg_set_unusable(&sregs.ldt);
573+
kvm_seg_set_kernel_code_64bit(vm, DEFAULT_CODE_SELECTOR, &sregs.cs);
574+
kvm_seg_set_kernel_data_64bit(vm, DEFAULT_DATA_SELECTOR, &sregs.ds);
575+
kvm_seg_set_kernel_data_64bit(vm, DEFAULT_DATA_SELECTOR, &sregs.es);
576+
kvm_setup_tss_64bit(vm, &sregs.tr, 0x18);
582577

583578
sregs.cr3 = vm->pgd;
584579
vcpu_sregs_set(vcpu, &sregs);

0 commit comments

Comments
 (0)