Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull KVM fixes from Paolo Bonzini:
"s390 and POWER bug fixes, plus enabling the KVM-VFIO interface on
s390"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
KVM doc: Fix KVM_SMI chapter number
KVM: s390: fix memory overwrites when vx is disabled
KVM: s390: Enable the KVM-VFIO device
KVM: s390: fix guest fprs memory leak
KVM: PPC: Fix ONE_REG AltiVec support
KVM: PPC: Increase memslots to 512
KVM: PPC: Book3S PR: Remove unused variable 'vcpu_book3s'
KVM: PPC: Fix emulation of H_SET_DABR/X on POWER8
KVM: PPC: Book3S HV: Handle unexpected traps in guest entry/exit code better

+77 -98
+1 -1
Documentation/virtual/kvm/api.txt
··· 3025 3025 and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq), 3026 3026 which is the maximum number of possibly pending cpu-local interrupts. 3027 3027 3028 - 4.90 KVM_SMI 3028 + 4.96 KVM_SMI 3029 3029 3030 3030 Capability: KVM_CAP_X86_SMM 3031 3031 Architectures: x86
+1 -2
arch/powerpc/include/asm/kvm_host.h
··· 38 38 39 39 #define KVM_MAX_VCPUS NR_CPUS 40 40 #define KVM_MAX_VCORES NR_CPUS 41 - #define KVM_USER_MEM_SLOTS 32 42 - #define KVM_MEM_SLOTS_NUM KVM_USER_MEM_SLOTS 41 + #define KVM_USER_MEM_SLOTS 512 43 42 44 43 #ifdef CONFIG_KVM_MMIO 45 44 #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
-3
arch/powerpc/kvm/book3s_64_mmu.c
··· 377 377 378 378 static void kvmppc_mmu_book3s_64_slbmte(struct kvm_vcpu *vcpu, u64 rs, u64 rb) 379 379 { 380 - struct kvmppc_vcpu_book3s *vcpu_book3s; 381 380 u64 esid, esid_1t; 382 381 int slb_nr; 383 382 struct kvmppc_slb *slbe; 384 383 385 384 dprintk("KVM MMU: slbmte(0x%llx, 0x%llx)\n", rs, rb); 386 - 387 - vcpu_book3s = to_book3s(vcpu); 388 385 389 386 esid = GET_ESID(rb); 390 387 esid_1t = GET_ESID_1T(rb);
+18
arch/powerpc/kvm/book3s_hv.c
··· 833 833 834 834 vcpu->stat.sum_exits++; 835 835 836 + /* 837 + * This can happen if an interrupt occurs in the last stages 838 + * of guest entry or the first stages of guest exit (i.e. after 839 + * setting paca->kvm_hstate.in_guest to KVM_GUEST_MODE_GUEST_HV 840 + * and before setting it to KVM_GUEST_MODE_HOST_HV). 841 + * That can happen due to a bug, or due to a machine check 842 + * occurring at just the wrong time. 843 + */ 844 + if (vcpu->arch.shregs.msr & MSR_HV) { 845 + printk(KERN_EMERG "KVM trap in HV mode!\n"); 846 + printk(KERN_EMERG "trap=0x%x | pc=0x%lx | msr=0x%llx\n", 847 + vcpu->arch.trap, kvmppc_get_pc(vcpu), 848 + vcpu->arch.shregs.msr); 849 + kvmppc_dump_regs(vcpu); 850 + run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 851 + run->hw.hardware_exit_reason = vcpu->arch.trap; 852 + return RESUME_HOST; 853 + } 836 854 run->exit_reason = KVM_EXIT_UNKNOWN; 837 855 run->ready_for_interrupt_injection = 1; 838 856 switch (vcpu->arch.trap) {
+3 -1
arch/powerpc/kvm/book3s_hv_rmhandlers.S
··· 2153 2153 2154 2154 /* Emulate H_SET_DABR/X on P8 for the sake of compat mode guests */ 2155 2155 2: rlwimi r5, r4, 5, DAWRX_DR | DAWRX_DW 2156 - rlwimi r5, r4, 1, DAWRX_WT 2156 + rlwimi r5, r4, 2, DAWRX_WT 2157 2157 clrrdi r4, r4, 3 2158 2158 std r4, VCPU_DAWR(r3) 2159 2159 std r5, VCPU_DAWRX(r3) ··· 2404 2404 * guest as machine check causing guest to crash. 2405 2405 */ 2406 2406 ld r11, VCPU_MSR(r9) 2407 + rldicl. r0, r11, 64-MSR_HV_LG, 63 /* check if it happened in HV mode */ 2408 + bne mc_cont /* if so, exit to host */ 2407 2409 andi. r10, r11, MSR_RI /* check for unrecoverable exception */ 2408 2410 beq 1f /* Deliver a machine check to guest */ 2409 2411 ld r10, VCPU_PC(r9)
+10 -10
arch/powerpc/kvm/powerpc.c
··· 919 919 r = -ENXIO; 920 920 break; 921 921 } 922 - vcpu->arch.vr.vr[reg->id - KVM_REG_PPC_VR0] = val.vval; 922 + val.vval = vcpu->arch.vr.vr[reg->id - KVM_REG_PPC_VR0]; 923 923 break; 924 924 case KVM_REG_PPC_VSCR: 925 925 if (!cpu_has_feature(CPU_FTR_ALTIVEC)) { 926 926 r = -ENXIO; 927 927 break; 928 928 } 929 - vcpu->arch.vr.vscr.u[3] = set_reg_val(reg->id, val); 929 + val = get_reg_val(reg->id, vcpu->arch.vr.vscr.u[3]); 930 930 break; 931 931 case KVM_REG_PPC_VRSAVE: 932 - if (!cpu_has_feature(CPU_FTR_ALTIVEC)) { 933 - r = -ENXIO; 934 - break; 935 - } 936 - vcpu->arch.vrsave = set_reg_val(reg->id, val); 932 + val = get_reg_val(reg->id, vcpu->arch.vrsave); 937 933 break; 938 934 #endif /* CONFIG_ALTIVEC */ 939 935 default: ··· 970 974 r = -ENXIO; 971 975 break; 972 976 } 973 - val.vval = vcpu->arch.vr.vr[reg->id - KVM_REG_PPC_VR0]; 977 + vcpu->arch.vr.vr[reg->id - KVM_REG_PPC_VR0] = val.vval; 974 978 break; 975 979 case KVM_REG_PPC_VSCR: 976 980 if (!cpu_has_feature(CPU_FTR_ALTIVEC)) { 977 981 r = -ENXIO; 978 982 break; 979 983 } 980 - val = get_reg_val(reg->id, vcpu->arch.vr.vscr.u[3]); 984 + vcpu->arch.vr.vscr.u[3] = set_reg_val(reg->id, val); 981 985 break; 982 986 case KVM_REG_PPC_VRSAVE: 983 - val = get_reg_val(reg->id, vcpu->arch.vrsave); 987 + if (!cpu_has_feature(CPU_FTR_ALTIVEC)) { 988 + r = -ENXIO; 989 + break; 990 + } 991 + vcpu->arch.vrsave = set_reg_val(reg->id, val); 984 992 break; 985 993 #endif /* CONFIG_ALTIVEC */ 986 994 default:
-1
arch/s390/include/asm/kvm_host.h
··· 546 546 struct kvm_s390_sie_block *sie_block; 547 547 unsigned int host_acrs[NUM_ACRS]; 548 548 struct fpu host_fpregs; 549 - struct fpu guest_fpregs; 550 549 struct kvm_s390_local_interrupt local_int; 551 550 struct hrtimer ckc_timer; 552 551 struct kvm_s390_pgm_info pgm;
+1
arch/s390/kvm/Kconfig
··· 29 29 select HAVE_KVM_IRQFD 30 30 select HAVE_KVM_IRQ_ROUTING 31 31 select SRCU 32 + select KVM_VFIO 32 33 ---help--- 33 34 Support hosting paravirtualized guest machines using the SIE 34 35 virtualization capability on the mainframe. This should work
+1 -1
arch/s390/kvm/Makefile
··· 7 7 # as published by the Free Software Foundation. 8 8 9 9 KVM := ../../../virt/kvm 10 - common-objs = $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/async_pf.o $(KVM)/irqchip.o 10 + common-objs = $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/async_pf.o $(KVM)/irqchip.o $(KVM)/vfio.o 11 11 12 12 ccflags-y := -Ivirt/kvm -Iarch/s390/kvm 13 13
+42 -79
arch/s390/kvm/kvm-s390.c
··· 1423 1423 return 0; 1424 1424 } 1425 1425 1426 - /* 1427 - * Backs up the current FP/VX register save area on a particular 1428 - * destination. Used to switch between different register save 1429 - * areas. 1430 - */ 1431 - static inline void save_fpu_to(struct fpu *dst) 1432 - { 1433 - dst->fpc = current->thread.fpu.fpc; 1434 - dst->regs = current->thread.fpu.regs; 1435 - } 1436 - 1437 - /* 1438 - * Switches the FP/VX register save area from which to lazy 1439 - * restore register contents. 1440 - */ 1441 - static inline void load_fpu_from(struct fpu *from) 1442 - { 1443 - current->thread.fpu.fpc = from->fpc; 1444 - current->thread.fpu.regs = from->regs; 1445 - } 1446 - 1447 1426 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 1448 1427 { 1449 1428 /* Save host register state */ 1450 1429 save_fpu_regs(); 1451 - save_fpu_to(&vcpu->arch.host_fpregs); 1430 + vcpu->arch.host_fpregs.fpc = current->thread.fpu.fpc; 1431 + vcpu->arch.host_fpregs.regs = current->thread.fpu.regs; 1452 1432 1453 - if (test_kvm_facility(vcpu->kvm, 129)) { 1454 - current->thread.fpu.fpc = vcpu->run->s.regs.fpc; 1455 - /* 1456 - * Use the register save area in the SIE-control block 1457 - * for register restore and save in kvm_arch_vcpu_put() 1458 - */ 1459 - current->thread.fpu.vxrs = 1460 - (__vector128 *)&vcpu->run->s.regs.vrs; 1461 - } else 1462 - load_fpu_from(&vcpu->arch.guest_fpregs); 1463 - 1433 + /* Depending on MACHINE_HAS_VX, data stored to vrs either 1434 + * has vector register or floating point register format. 1435 + */ 1436 + current->thread.fpu.regs = vcpu->run->s.regs.vrs; 1437 + current->thread.fpu.fpc = vcpu->run->s.regs.fpc; 1464 1438 if (test_fp_ctl(current->thread.fpu.fpc)) 1465 1439 /* User space provided an invalid FPC, let's clear it */ 1466 1440 current->thread.fpu.fpc = 0; ··· 1450 1476 atomic_andnot(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags); 1451 1477 gmap_disable(vcpu->arch.gmap); 1452 1478 1479 + /* Save guest register state */ 1453 1480 save_fpu_regs(); 1481 + vcpu->run->s.regs.fpc = current->thread.fpu.fpc; 1454 1482 1455 - if (test_kvm_facility(vcpu->kvm, 129)) 1456 - /* 1457 - * kvm_arch_vcpu_load() set up the register save area to 1458 - * the &vcpu->run->s.regs.vrs and, thus, the vector registers 1459 - * are already saved. Only the floating-point control must be 1460 - * copied. 1461 - */ 1462 - vcpu->run->s.regs.fpc = current->thread.fpu.fpc; 1463 - else 1464 - save_fpu_to(&vcpu->arch.guest_fpregs); 1465 - load_fpu_from(&vcpu->arch.host_fpregs); 1483 + /* Restore host register state */ 1484 + current->thread.fpu.fpc = vcpu->arch.host_fpregs.fpc; 1485 + current->thread.fpu.regs = vcpu->arch.host_fpregs.regs; 1466 1486 1467 1487 save_access_regs(vcpu->run->s.regs.acrs); 1468 1488 restore_access_regs(vcpu->arch.host_acrs); ··· 1474 1506 memset(vcpu->arch.sie_block->gcr, 0, 16 * sizeof(__u64)); 1475 1507 vcpu->arch.sie_block->gcr[0] = 0xE0UL; 1476 1508 vcpu->arch.sie_block->gcr[14] = 0xC2000000UL; 1477 - vcpu->arch.guest_fpregs.fpc = 0; 1478 - asm volatile("lfpc %0" : : "Q" (vcpu->arch.guest_fpregs.fpc)); 1509 + /* make sure the new fpc will be lazily loaded */ 1510 + save_fpu_regs(); 1511 + current->thread.fpu.fpc = 0; 1479 1512 vcpu->arch.sie_block->gbea = 1; 1480 1513 vcpu->arch.sie_block->pp = 0; 1481 1514 vcpu->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID; ··· 1616 1647 vcpu->arch.local_int.float_int = &kvm->arch.float_int; 1617 1648 vcpu->arch.local_int.wq = &vcpu->wq; 1618 1649 vcpu->arch.local_int.cpuflags = &vcpu->arch.sie_block->cpuflags; 1619 - 1620 - /* 1621 - * Allocate a save area for floating-point registers. If the vector 1622 - * extension is available, register contents are saved in the SIE 1623 - * control block. The allocated save area is still required in 1624 - * particular places, for example, in kvm_s390_vcpu_store_status(). 1625 - */ 1626 - vcpu->arch.guest_fpregs.fprs = kzalloc(sizeof(freg_t) * __NUM_FPRS, 1627 - GFP_KERNEL); 1628 - if (!vcpu->arch.guest_fpregs.fprs) 1629 - goto out_free_sie_block; 1630 1650 1631 1651 rc = kvm_vcpu_init(vcpu, kvm, id); 1632 1652 if (rc) ··· 1837 1879 1838 1880 int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) 1839 1881 { 1882 + /* make sure the new values will be lazily loaded */ 1883 + save_fpu_regs(); 1840 1884 if (test_fp_ctl(fpu->fpc)) 1841 1885 return -EINVAL; 1842 - memcpy(vcpu->arch.guest_fpregs.fprs, &fpu->fprs, sizeof(fpu->fprs)); 1843 - vcpu->arch.guest_fpregs.fpc = fpu->fpc; 1844 - save_fpu_regs(); 1845 - load_fpu_from(&vcpu->arch.guest_fpregs); 1886 + current->thread.fpu.fpc = fpu->fpc; 1887 + if (MACHINE_HAS_VX) 1888 + convert_fp_to_vx(current->thread.fpu.vxrs, (freg_t *)fpu->fprs); 1889 + else 1890 + memcpy(current->thread.fpu.fprs, &fpu->fprs, sizeof(fpu->fprs)); 1846 1891 return 0; 1847 1892 } 1848 1893 1849 1894 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) 1850 1895 { 1851 - memcpy(&fpu->fprs, vcpu->arch.guest_fpregs.fprs, sizeof(fpu->fprs)); 1852 - fpu->fpc = vcpu->arch.guest_fpregs.fpc; 1896 + /* make sure we have the latest values */ 1897 + save_fpu_regs(); 1898 + if (MACHINE_HAS_VX) 1899 + convert_vx_to_fp((freg_t *)fpu->fprs, current->thread.fpu.vxrs); 1900 + else 1901 + memcpy(fpu->fprs, current->thread.fpu.fprs, sizeof(fpu->fprs)); 1902 + fpu->fpc = current->thread.fpu.fpc; 1853 1903 return 0; 1854 1904 } 1855 1905 ··· 2362 2396 int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long gpa) 2363 2397 { 2364 2398 unsigned char archmode = 1; 2399 + freg_t fprs[NUM_FPRS]; 2365 2400 unsigned int px; 2366 2401 u64 clkcomp; 2367 2402 int rc; ··· 2378 2411 gpa = px; 2379 2412 } else 2380 2413 gpa -= __LC_FPREGS_SAVE_AREA; 2381 - rc = write_guest_abs(vcpu, gpa + __LC_FPREGS_SAVE_AREA, 2382 - vcpu->arch.guest_fpregs.fprs, 128); 2414 + 2415 + /* manually convert vector registers if necessary */ 2416 + if (MACHINE_HAS_VX) { 2417 + convert_vx_to_fp(fprs, current->thread.fpu.vxrs); 2418 + rc = write_guest_abs(vcpu, gpa + __LC_FPREGS_SAVE_AREA, 2419 + fprs, 128); 2420 + } else { 2421 + rc = write_guest_abs(vcpu, gpa + __LC_FPREGS_SAVE_AREA, 2422 + vcpu->run->s.regs.vrs, 128); 2423 + } 2383 2424 rc |= write_guest_abs(vcpu, gpa + __LC_GPREGS_SAVE_AREA, 2384 2425 vcpu->run->s.regs.gprs, 128); 2385 2426 rc |= write_guest_abs(vcpu, gpa + __LC_PSW_SAVE_AREA, ··· 2395 2420 rc |= write_guest_abs(vcpu, gpa + __LC_PREFIX_SAVE_AREA, 2396 2421 &px, 4); 2397 2422 rc |= write_guest_abs(vcpu, gpa + __LC_FP_CREG_SAVE_AREA, 2398 - &vcpu->arch.guest_fpregs.fpc, 4); 2423 + &vcpu->run->s.regs.fpc, 4); 2399 2424 rc |= write_guest_abs(vcpu, gpa + __LC_TOD_PROGREG_SAVE_AREA, 2400 2425 &vcpu->arch.sie_block->todpr, 4); 2401 2426 rc |= write_guest_abs(vcpu, gpa + __LC_CPU_TIMER_SAVE_AREA, ··· 2418 2443 * it into the save area 2419 2444 */ 2420 2445 save_fpu_regs(); 2421 - if (test_kvm_facility(vcpu->kvm, 129)) { 2422 - /* 2423 - * If the vector extension is available, the vector registers 2424 - * which overlaps with floating-point registers are saved in 2425 - * the SIE-control block. Hence, extract the floating-point 2426 - * registers and the FPC value and store them in the 2427 - * guest_fpregs structure. 2428 - */ 2429 - vcpu->arch.guest_fpregs.fpc = current->thread.fpu.fpc; 2430 - convert_vx_to_fp(vcpu->arch.guest_fpregs.fprs, 2431 - current->thread.fpu.vxrs); 2432 - } else 2433 - save_fpu_to(&vcpu->arch.guest_fpregs); 2446 + vcpu->run->s.regs.fpc = current->thread.fpu.fpc; 2434 2447 save_access_regs(vcpu->run->s.regs.acrs); 2435 2448 2436 2449 return kvm_s390_store_status_unloaded(vcpu, addr);