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

Merge tag 'kvm-s390-next-20150209' of git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD

KVM: s390: fixes and features for kvm/next (3.20)

1. Fixes
- Fix user triggerable endless loop
- reenable LPP facility
- disable KVM compat ioctl on s390 (untested and broken)

2. cpu models for s390
- provide facilities and instruction blocking per VM
- add s390 specific vm attributes for setting values

3. crypto
- toleration patch for z13 support

4. add uuid and long name to /proc/sysinfo (stsi 322)
- patch Acked by Heiko Carstens (touches non-kvm s390 code)

+397 -56
+45
Documentation/virtual/kvm/devices/vm.txt
··· 38 38 the maximum guest memory size. The limit will be rounded up to 39 39 2048 MB, 4096 GB, 8192 TB respectively, as this limit is governed by 40 40 the number of page table levels. 41 + 42 + 2. GROUP: KVM_S390_VM_CPU_MODEL 43 + Architectures: s390 44 + 45 + 2.1. ATTRIBUTE: KVM_S390_VM_CPU_MACHINE (r/o) 46 + 47 + Allows user space to retrieve machine and kvm specific cpu related information: 48 + 49 + struct kvm_s390_vm_cpu_machine { 50 + __u64 cpuid; # CPUID of host 51 + __u32 ibc; # IBC level range offered by host 52 + __u8 pad[4]; 53 + __u64 fac_mask[256]; # set of cpu facilities enabled by KVM 54 + __u64 fac_list[256]; # set of cpu facilities offered by host 55 + } 56 + 57 + Parameters: address of buffer to store the machine related cpu data 58 + of type struct kvm_s390_vm_cpu_machine* 59 + Returns: -EFAULT if the given address is not accessible from kernel space 60 + -ENOMEM if not enough memory is available to process the ioctl 61 + 0 in case of success 62 + 63 + 2.2. ATTRIBUTE: KVM_S390_VM_CPU_PROCESSOR (r/w) 64 + 65 + Allows user space to retrieve or request to change cpu related information for a vcpu: 66 + 67 + struct kvm_s390_vm_cpu_processor { 68 + __u64 cpuid; # CPUID currently (to be) used by this vcpu 69 + __u16 ibc; # IBC level currently (to be) used by this vcpu 70 + __u8 pad[6]; 71 + __u64 fac_list[256]; # set of cpu facilities currently (to be) used 72 + # by this vcpu 73 + } 74 + 75 + KVM does not enforce or limit the cpu model data in any form. Take the information 76 + retrieved by means of KVM_S390_VM_CPU_MACHINE as hint for reasonable configuration 77 + setups. Instruction interceptions triggered by additionally set facilitiy bits that 78 + are not handled by KVM need to by imlemented in the VM driver code. 79 + 80 + Parameters: address of buffer to store/set the processor related cpu 81 + data of type struct kvm_s390_vm_cpu_processor*. 82 + Returns: -EBUSY in case 1 or more vcpus are already activated (only in write case) 83 + -EFAULT if the given address is not accessible from kernel space 84 + -ENOMEM if not enough memory is available to process the ioctl 85 + 0 in case of success
+26 -1
arch/s390/include/asm/kvm_host.h
··· 89 89 atomic_t cpuflags; /* 0x0000 */ 90 90 __u32 : 1; /* 0x0004 */ 91 91 __u32 prefix : 18; 92 - __u32 : 13; 92 + __u32 : 1; 93 + __u32 ibc : 12; 93 94 __u8 reserved08[4]; /* 0x0008 */ 94 95 #define PROG_IN_SIE (1<<0) 95 96 __u32 prog0c; /* 0x000c */ ··· 164 163 __u64 tecmc; /* 0x00e8 */ 165 164 __u8 reservedf0[12]; /* 0x00f0 */ 166 165 #define CRYCB_FORMAT1 0x00000001 166 + #define CRYCB_FORMAT2 0x00000003 167 167 __u32 crycbd; /* 0x00fc */ 168 168 __u64 gcr[16]; /* 0x0100 */ 169 169 __u64 gbea; /* 0x0180 */ ··· 507 505 #define MAX_S390_IO_ADAPTERS ((MAX_ISC + 1) * 8) 508 506 #define MAX_S390_ADAPTER_MAPS 256 509 507 508 + /* maximum size of facilities and facility mask is 2k bytes */ 509 + #define S390_ARCH_FAC_LIST_SIZE_BYTE (1<<11) 510 + #define S390_ARCH_FAC_LIST_SIZE_U64 \ 511 + (S390_ARCH_FAC_LIST_SIZE_BYTE / sizeof(u64)) 512 + #define S390_ARCH_FAC_MASK_SIZE_BYTE S390_ARCH_FAC_LIST_SIZE_BYTE 513 + #define S390_ARCH_FAC_MASK_SIZE_U64 \ 514 + (S390_ARCH_FAC_MASK_SIZE_BYTE / sizeof(u64)) 515 + 516 + struct s390_model_fac { 517 + /* facilities used in SIE context */ 518 + __u64 sie[S390_ARCH_FAC_LIST_SIZE_U64]; 519 + /* subset enabled by kvm */ 520 + __u64 kvm[S390_ARCH_FAC_LIST_SIZE_U64]; 521 + }; 522 + 523 + struct kvm_s390_cpu_model { 524 + struct s390_model_fac *fac; 525 + struct cpuid cpu_id; 526 + unsigned short ibc; 527 + }; 528 + 510 529 struct kvm_s390_crypto { 511 530 struct kvm_s390_crypto_cb *crycb; 512 531 __u32 crycbd; ··· 539 516 __u8 reserved00[72]; /* 0x0000 */ 540 517 __u8 dea_wrapping_key_mask[24]; /* 0x0048 */ 541 518 __u8 aes_wrapping_key_mask[32]; /* 0x0060 */ 519 + __u8 reserved80[128]; /* 0x0080 */ 542 520 }; 543 521 544 522 struct kvm_arch{ ··· 558 534 int ipte_lock_count; 559 535 struct mutex ipte_mutex; 560 536 spinlock_t start_stop_lock; 537 + struct kvm_s390_cpu_model model; 561 538 struct kvm_s390_crypto crypto; 562 539 u64 epoch; 563 540 };
+7 -3
arch/s390/include/asm/sysinfo.h
··· 15 15 #define __ASM_S390_SYSINFO_H 16 16 17 17 #include <asm/bitsperlong.h> 18 + #include <linux/uuid.h> 18 19 19 20 struct sysinfo_1_1_1 { 20 21 unsigned char p:1; ··· 113 112 char name[8]; 114 113 unsigned int caf; 115 114 char cpi[16]; 116 - char reserved_1[24]; 117 - 115 + char reserved_1[3]; 116 + char ext_name_encoding; 117 + unsigned int reserved_2; 118 + uuid_be uuid; 118 119 } vm[8]; 119 - char reserved_544[3552]; 120 + char reserved_3[1504]; 121 + char ext_names[8][256]; 120 122 }; 121 123 122 124 extern int topology_max_mnest;
+21
arch/s390/include/uapi/asm/kvm.h
··· 59 59 #define KVM_S390_VM_MEM_CTRL 0 60 60 #define KVM_S390_VM_TOD 1 61 61 #define KVM_S390_VM_CRYPTO 2 62 + #define KVM_S390_VM_CPU_MODEL 3 62 63 63 64 /* kvm attributes for mem_ctrl */ 64 65 #define KVM_S390_VM_MEM_ENABLE_CMMA 0 ··· 69 68 /* kvm attributes for KVM_S390_VM_TOD */ 70 69 #define KVM_S390_VM_TOD_LOW 0 71 70 #define KVM_S390_VM_TOD_HIGH 1 71 + 72 + /* kvm attributes for KVM_S390_VM_CPU_MODEL */ 73 + /* processor related attributes are r/w */ 74 + #define KVM_S390_VM_CPU_PROCESSOR 0 75 + struct kvm_s390_vm_cpu_processor { 76 + __u64 cpuid; 77 + __u16 ibc; 78 + __u8 pad[6]; 79 + __u64 fac_list[256]; 80 + }; 81 + 82 + /* machine related attributes are r/o */ 83 + #define KVM_S390_VM_CPU_MACHINE 1 84 + struct kvm_s390_vm_cpu_machine { 85 + __u64 cpuid; 86 + __u32 ibc; 87 + __u8 pad[4]; 88 + __u64 fac_mask[256]; 89 + __u64 fac_list[256]; 90 + }; 72 91 73 92 /* kvm attributes for crypto */ 74 93 #define KVM_S390_VM_CRYPTO_ENABLE_AES_KW 0
+29
arch/s390/kernel/sysinfo.c
··· 196 196 seq_printf(m, "LPAR CPUs Shared: %d\n", info->cpus_shared); 197 197 } 198 198 199 + static void print_ext_name(struct seq_file *m, int lvl, 200 + struct sysinfo_3_2_2 *info) 201 + { 202 + if (info->vm[lvl].ext_name_encoding == 0) 203 + return; 204 + if (info->ext_names[lvl][0] == 0) 205 + return; 206 + switch (info->vm[lvl].ext_name_encoding) { 207 + case 1: /* EBCDIC */ 208 + EBCASC(info->ext_names[lvl], sizeof(info->ext_names[lvl])); 209 + break; 210 + case 2: /* UTF-8 */ 211 + break; 212 + default: 213 + return; 214 + } 215 + seq_printf(m, "VM%02d Extended Name: %-.256s\n", lvl, 216 + info->ext_names[lvl]); 217 + } 218 + 219 + static void print_uuid(struct seq_file *m, int i, struct sysinfo_3_2_2 *info) 220 + { 221 + if (!memcmp(&info->vm[i].uuid, &NULL_UUID_BE, sizeof(uuid_be))) 222 + return; 223 + seq_printf(m, "VM%02d UUID: %pUb\n", i, &info->vm[i].uuid); 224 + } 225 + 199 226 static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info) 200 227 { 201 228 int i; ··· 240 213 seq_printf(m, "VM%02d CPUs Configured: %d\n", i, info->vm[i].cpus_configured); 241 214 seq_printf(m, "VM%02d CPUs Standby: %d\n", i, info->vm[i].cpus_standby); 242 215 seq_printf(m, "VM%02d CPUs Reserved: %d\n", i, info->vm[i].cpus_reserved); 216 + print_ext_name(m, i, info); 217 + print_uuid(m, i, info); 243 218 } 244 219 } 245 220
+2 -2
arch/s390/kvm/gaccess.c
··· 357 357 union asce asce; 358 358 359 359 ctlreg0.val = vcpu->arch.sie_block->gcr[0]; 360 - edat1 = ctlreg0.edat && test_vfacility(8); 361 - edat2 = edat1 && test_vfacility(78); 360 + edat1 = ctlreg0.edat && test_kvm_facility(vcpu->kvm, 8); 361 + edat2 = edat1 && test_kvm_facility(vcpu->kvm, 78); 362 362 asce.val = get_vcpu_asce(vcpu); 363 363 if (asce.r) 364 364 goto real_address;
+2
arch/s390/kvm/interrupt.c
··· 1244 1244 list_add_tail(&inti->list, &iter->list); 1245 1245 } 1246 1246 atomic_set(&fi->active, 1); 1247 + if (atomic_read(&kvm->online_vcpus) == 0) 1248 + goto unlock_fi; 1247 1249 sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS); 1248 1250 if (sigcpu == KVM_MAX_VCPUS) { 1249 1251 do {
+237 -36
arch/s390/kvm/kvm-s390.c
··· 30 30 #include <asm/pgtable.h> 31 31 #include <asm/nmi.h> 32 32 #include <asm/switch_to.h> 33 - #include <asm/facility.h> 34 33 #include <asm/sclp.h> 35 34 #include "kvm-s390.h" 36 35 #include "gaccess.h" ··· 99 100 { NULL } 100 101 }; 101 102 102 - unsigned long *vfacilities; 103 - static struct gmap_notifier gmap_notifier; 103 + /* upper facilities limit for kvm */ 104 + unsigned long kvm_s390_fac_list_mask[] = { 105 + 0xff82fffbf4fc2000UL, 106 + 0x005c000000000000UL, 107 + }; 104 108 105 - /* test availability of vfacility */ 106 - int test_vfacility(unsigned long nr) 109 + unsigned long kvm_s390_fac_list_mask_size(void) 107 110 { 108 - return __test_facility(nr, (void *) vfacilities); 111 + BUILD_BUG_ON(ARRAY_SIZE(kvm_s390_fac_list_mask) > S390_ARCH_FAC_MASK_SIZE_U64); 112 + return ARRAY_SIZE(kvm_s390_fac_list_mask); 109 113 } 114 + 115 + static struct gmap_notifier gmap_notifier; 110 116 111 117 /* Section: not file related */ 112 118 int kvm_arch_hardware_enable(void) ··· 355 351 struct kvm_vcpu *vcpu; 356 352 int i; 357 353 358 - if (!test_vfacility(76)) 354 + if (!test_kvm_facility(kvm, 76)) 359 355 return -EINVAL; 360 356 361 357 mutex_lock(&kvm->lock); ··· 502 498 return ret; 503 499 } 504 500 501 + static int kvm_s390_set_processor(struct kvm *kvm, struct kvm_device_attr *attr) 502 + { 503 + struct kvm_s390_vm_cpu_processor *proc; 504 + int ret = 0; 505 + 506 + mutex_lock(&kvm->lock); 507 + if (atomic_read(&kvm->online_vcpus)) { 508 + ret = -EBUSY; 509 + goto out; 510 + } 511 + proc = kzalloc(sizeof(*proc), GFP_KERNEL); 512 + if (!proc) { 513 + ret = -ENOMEM; 514 + goto out; 515 + } 516 + if (!copy_from_user(proc, (void __user *)attr->addr, 517 + sizeof(*proc))) { 518 + memcpy(&kvm->arch.model.cpu_id, &proc->cpuid, 519 + sizeof(struct cpuid)); 520 + kvm->arch.model.ibc = proc->ibc; 521 + memcpy(kvm->arch.model.fac->kvm, proc->fac_list, 522 + S390_ARCH_FAC_LIST_SIZE_BYTE); 523 + } else 524 + ret = -EFAULT; 525 + kfree(proc); 526 + out: 527 + mutex_unlock(&kvm->lock); 528 + return ret; 529 + } 530 + 531 + static int kvm_s390_set_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr) 532 + { 533 + int ret = -ENXIO; 534 + 535 + switch (attr->attr) { 536 + case KVM_S390_VM_CPU_PROCESSOR: 537 + ret = kvm_s390_set_processor(kvm, attr); 538 + break; 539 + } 540 + return ret; 541 + } 542 + 543 + static int kvm_s390_get_processor(struct kvm *kvm, struct kvm_device_attr *attr) 544 + { 545 + struct kvm_s390_vm_cpu_processor *proc; 546 + int ret = 0; 547 + 548 + proc = kzalloc(sizeof(*proc), GFP_KERNEL); 549 + if (!proc) { 550 + ret = -ENOMEM; 551 + goto out; 552 + } 553 + memcpy(&proc->cpuid, &kvm->arch.model.cpu_id, sizeof(struct cpuid)); 554 + proc->ibc = kvm->arch.model.ibc; 555 + memcpy(&proc->fac_list, kvm->arch.model.fac->kvm, S390_ARCH_FAC_LIST_SIZE_BYTE); 556 + if (copy_to_user((void __user *)attr->addr, proc, sizeof(*proc))) 557 + ret = -EFAULT; 558 + kfree(proc); 559 + out: 560 + return ret; 561 + } 562 + 563 + static int kvm_s390_get_machine(struct kvm *kvm, struct kvm_device_attr *attr) 564 + { 565 + struct kvm_s390_vm_cpu_machine *mach; 566 + int ret = 0; 567 + 568 + mach = kzalloc(sizeof(*mach), GFP_KERNEL); 569 + if (!mach) { 570 + ret = -ENOMEM; 571 + goto out; 572 + } 573 + get_cpu_id((struct cpuid *) &mach->cpuid); 574 + mach->ibc = sclp_get_ibc(); 575 + memcpy(&mach->fac_mask, kvm_s390_fac_list_mask, 576 + kvm_s390_fac_list_mask_size() * sizeof(u64)); 577 + memcpy((unsigned long *)&mach->fac_list, S390_lowcore.stfle_fac_list, 578 + S390_ARCH_FAC_LIST_SIZE_U64); 579 + if (copy_to_user((void __user *)attr->addr, mach, sizeof(*mach))) 580 + ret = -EFAULT; 581 + kfree(mach); 582 + out: 583 + return ret; 584 + } 585 + 586 + static int kvm_s390_get_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr) 587 + { 588 + int ret = -ENXIO; 589 + 590 + switch (attr->attr) { 591 + case KVM_S390_VM_CPU_PROCESSOR: 592 + ret = kvm_s390_get_processor(kvm, attr); 593 + break; 594 + case KVM_S390_VM_CPU_MACHINE: 595 + ret = kvm_s390_get_machine(kvm, attr); 596 + break; 597 + } 598 + return ret; 599 + } 600 + 505 601 static int kvm_s390_vm_set_attr(struct kvm *kvm, struct kvm_device_attr *attr) 506 602 { 507 603 int ret; ··· 612 508 break; 613 509 case KVM_S390_VM_TOD: 614 510 ret = kvm_s390_set_tod(kvm, attr); 511 + break; 512 + case KVM_S390_VM_CPU_MODEL: 513 + ret = kvm_s390_set_cpu_model(kvm, attr); 615 514 break; 616 515 case KVM_S390_VM_CRYPTO: 617 516 ret = kvm_s390_vm_set_crypto(kvm, attr); ··· 637 530 break; 638 531 case KVM_S390_VM_TOD: 639 532 ret = kvm_s390_get_tod(kvm, attr); 533 + break; 534 + case KVM_S390_VM_CPU_MODEL: 535 + ret = kvm_s390_get_cpu_model(kvm, attr); 640 536 break; 641 537 default: 642 538 ret = -ENXIO; ··· 670 560 switch (attr->attr) { 671 561 case KVM_S390_VM_TOD_LOW: 672 562 case KVM_S390_VM_TOD_HIGH: 563 + ret = 0; 564 + break; 565 + default: 566 + ret = -ENXIO; 567 + break; 568 + } 569 + break; 570 + case KVM_S390_VM_CPU_MODEL: 571 + switch (attr->attr) { 572 + case KVM_S390_VM_CPU_PROCESSOR: 573 + case KVM_S390_VM_CPU_MACHINE: 673 574 ret = 0; 674 575 break; 675 576 default: ··· 775 654 return r; 776 655 } 777 656 657 + static int kvm_s390_query_ap_config(u8 *config) 658 + { 659 + u32 fcn_code = 0x04000000UL; 660 + u32 cc; 661 + 662 + asm volatile( 663 + "lgr 0,%1\n" 664 + "lgr 2,%2\n" 665 + ".long 0xb2af0000\n" /* PQAP(QCI) */ 666 + "ipm %0\n" 667 + "srl %0,28\n" 668 + : "=r" (cc) 669 + : "r" (fcn_code), "r" (config) 670 + : "cc", "0", "2", "memory" 671 + ); 672 + 673 + return cc; 674 + } 675 + 676 + static int kvm_s390_apxa_installed(void) 677 + { 678 + u8 config[128]; 679 + int cc; 680 + 681 + if (test_facility(2) && test_facility(12)) { 682 + cc = kvm_s390_query_ap_config(config); 683 + 684 + if (cc) 685 + pr_err("PQAP(QCI) failed with cc=%d", cc); 686 + else 687 + return config[0] & 0x40; 688 + } 689 + 690 + return 0; 691 + } 692 + 693 + static void kvm_s390_set_crycb_format(struct kvm *kvm) 694 + { 695 + kvm->arch.crypto.crycbd = (__u32)(unsigned long) kvm->arch.crypto.crycb; 696 + 697 + if (kvm_s390_apxa_installed()) 698 + kvm->arch.crypto.crycbd |= CRYCB_FORMAT2; 699 + else 700 + kvm->arch.crypto.crycbd |= CRYCB_FORMAT1; 701 + } 702 + 703 + static void kvm_s390_get_cpu_id(struct cpuid *cpu_id) 704 + { 705 + get_cpu_id(cpu_id); 706 + cpu_id->version = 0xff; 707 + } 708 + 778 709 static int kvm_s390_crypto_init(struct kvm *kvm) 779 710 { 780 - if (!test_vfacility(76)) 711 + if (!test_kvm_facility(kvm, 76)) 781 712 return 0; 782 713 783 714 kvm->arch.crypto.crycb = kzalloc(sizeof(*kvm->arch.crypto.crycb), ··· 837 664 if (!kvm->arch.crypto.crycb) 838 665 return -ENOMEM; 839 666 840 - kvm->arch.crypto.crycbd = (__u32) (unsigned long) kvm->arch.crypto.crycb | 841 - CRYCB_FORMAT1; 667 + kvm_s390_set_crycb_format(kvm); 842 668 843 669 /* Disable AES/DEA protected key functions by default */ 844 670 kvm->arch.crypto.aes_kw = 0; ··· 848 676 849 677 int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) 850 678 { 851 - int rc; 679 + int i, rc; 852 680 char debug_name[16]; 853 681 static unsigned long sca_offset; 854 682 ··· 883 711 if (!kvm->arch.dbf) 884 712 goto out_nodbf; 885 713 714 + /* 715 + * The architectural maximum amount of facilities is 16 kbit. To store 716 + * this amount, 2 kbyte of memory is required. Thus we need a full 717 + * page to hold the active copy (arch.model.fac->sie) and the current 718 + * facilities set (arch.model.fac->kvm). Its address size has to be 719 + * 31 bits and word aligned. 720 + */ 721 + kvm->arch.model.fac = 722 + (struct s390_model_fac *) get_zeroed_page(GFP_KERNEL | GFP_DMA); 723 + if (!kvm->arch.model.fac) 724 + goto out_nofac; 725 + 726 + memcpy(kvm->arch.model.fac->kvm, S390_lowcore.stfle_fac_list, 727 + S390_ARCH_FAC_LIST_SIZE_U64); 728 + 729 + /* 730 + * If this KVM host runs *not* in a LPAR, relax the facility bits 731 + * of the kvm facility mask by all missing facilities. This will allow 732 + * to determine the right CPU model by means of the remaining facilities. 733 + * Live guest migration must prohibit the migration of KVMs running in 734 + * a LPAR to non LPAR hosts. 735 + */ 736 + if (!MACHINE_IS_LPAR) 737 + for (i = 0; i < kvm_s390_fac_list_mask_size(); i++) 738 + kvm_s390_fac_list_mask[i] &= kvm->arch.model.fac->kvm[i]; 739 + 740 + /* 741 + * Apply the kvm facility mask to limit the kvm supported/tolerated 742 + * facility list. 743 + */ 744 + for (i = 0; i < S390_ARCH_FAC_LIST_SIZE_U64; i++) { 745 + if (i < kvm_s390_fac_list_mask_size()) 746 + kvm->arch.model.fac->kvm[i] &= kvm_s390_fac_list_mask[i]; 747 + else 748 + kvm->arch.model.fac->kvm[i] = 0UL; 749 + } 750 + 751 + kvm_s390_get_cpu_id(&kvm->arch.model.cpu_id); 752 + kvm->arch.model.ibc = sclp_get_ibc() & 0x0fff; 753 + 886 754 if (kvm_s390_crypto_init(kvm) < 0) 887 755 goto out_crypto; 888 756 ··· 954 742 out_nogmap: 955 743 kfree(kvm->arch.crypto.crycb); 956 744 out_crypto: 745 + free_page((unsigned long)kvm->arch.model.fac); 746 + out_nofac: 957 747 debug_unregister(kvm->arch.dbf); 958 748 out_nodbf: 959 749 free_page((unsigned long)(kvm->arch.sca)); ··· 1008 794 void kvm_arch_destroy_vm(struct kvm *kvm) 1009 795 { 1010 796 kvm_free_vcpus(kvm); 797 + free_page((unsigned long)kvm->arch.model.fac); 1011 798 free_page((unsigned long)(kvm->arch.sca)); 1012 799 debug_unregister(kvm->arch.dbf); 1013 800 kfree(kvm->arch.crypto.crycb); ··· 1104 889 1105 890 static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu) 1106 891 { 1107 - if (!test_vfacility(76)) 892 + if (!test_kvm_facility(vcpu->kvm, 76)) 1108 893 return; 1109 894 1110 895 vcpu->arch.sie_block->ecb3 &= ~(ECB3_AES | ECB3_DEA); ··· 1143 928 CPUSTAT_STOPPED | 1144 929 CPUSTAT_GED); 1145 930 vcpu->arch.sie_block->ecb = 6; 1146 - if (test_vfacility(50) && test_vfacility(73)) 931 + if (test_kvm_facility(vcpu->kvm, 50) && test_kvm_facility(vcpu->kvm, 73)) 1147 932 vcpu->arch.sie_block->ecb |= 0x10; 1148 933 1149 934 vcpu->arch.sie_block->ecb2 = 8; ··· 1152 937 vcpu->arch.sie_block->eca |= 1; 1153 938 if (sclp_has_sigpif()) 1154 939 vcpu->arch.sie_block->eca |= 0x10000000U; 1155 - vcpu->arch.sie_block->fac = (int) (long) vfacilities; 1156 940 vcpu->arch.sie_block->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE | 1157 941 ICTL_TPROT; 1158 942 ··· 1162 948 } 1163 949 hrtimer_init(&vcpu->arch.ckc_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 1164 950 vcpu->arch.ckc_timer.function = kvm_s390_idle_wakeup; 1165 - get_cpu_id(&vcpu->arch.cpu_id); 1166 - vcpu->arch.cpu_id.version = 0xff; 951 + 952 + mutex_lock(&vcpu->kvm->lock); 953 + vcpu->arch.cpu_id = vcpu->kvm->arch.model.cpu_id; 954 + memcpy(vcpu->kvm->arch.model.fac->sie, vcpu->kvm->arch.model.fac->kvm, 955 + S390_ARCH_FAC_LIST_SIZE_BYTE); 956 + vcpu->arch.sie_block->ibc = vcpu->kvm->arch.model.ibc; 957 + mutex_unlock(&vcpu->kvm->lock); 1167 958 1168 959 kvm_s390_vcpu_crypto_setup(vcpu); 1169 960 ··· 1212 993 vcpu->arch.sie_block->scaol = (__u32)(__u64)kvm->arch.sca; 1213 994 set_bit(63 - id, (unsigned long *) &kvm->arch.sca->mcn); 1214 995 } 996 + vcpu->arch.sie_block->fac = (int) (long) kvm->arch.model.fac->sie; 1215 997 1216 998 spin_lock_init(&vcpu->arch.local_int.lock); 1217 999 vcpu->arch.local_int.float_int = &kvm->arch.float_int; ··· 2278 2058 2279 2059 static int __init kvm_s390_init(void) 2280 2060 { 2281 - int ret; 2282 - ret = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE); 2283 - if (ret) 2284 - return ret; 2285 - 2286 - /* 2287 - * guests can ask for up to 255+1 double words, we need a full page 2288 - * to hold the maximum amount of facilities. On the other hand, we 2289 - * only set facilities that are known to work in KVM. 2290 - */ 2291 - vfacilities = (unsigned long *) get_zeroed_page(GFP_KERNEL|GFP_DMA); 2292 - if (!vfacilities) { 2293 - kvm_exit(); 2294 - return -ENOMEM; 2295 - } 2296 - memcpy(vfacilities, S390_lowcore.stfle_fac_list, 16); 2297 - vfacilities[0] &= 0xff82fffbf47c2000UL; 2298 - vfacilities[1] &= 0x005c000000000000UL; 2299 - return 0; 2061 + return kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE); 2300 2062 } 2301 2063 2302 2064 static void __exit kvm_s390_exit(void) 2303 2065 { 2304 - free_page((unsigned long) vfacilities); 2305 2066 kvm_exit(); 2306 2067 } 2307 2068
+9 -4
arch/s390/kvm/kvm-s390.h
··· 18 18 #include <linux/hrtimer.h> 19 19 #include <linux/kvm.h> 20 20 #include <linux/kvm_host.h> 21 + #include <asm/facility.h> 21 22 22 23 typedef int (*intercept_handler_t)(struct kvm_vcpu *vcpu); 23 - 24 - /* declare vfacilities extern */ 25 - extern unsigned long *vfacilities; 26 24 27 25 /* Transactional Memory Execution related macros */ 28 26 #define IS_TE_ENABLED(vcpu) ((vcpu->arch.sie_block->ecb & 0x10)) ··· 125 127 vcpu->arch.sie_block->gpsw.mask |= cc << 44; 126 128 } 127 129 130 + /* test availability of facility in a kvm intance */ 131 + static inline int test_kvm_facility(struct kvm *kvm, unsigned long nr) 132 + { 133 + return __test_facility(nr, kvm->arch.model.fac->kvm); 134 + } 135 + 128 136 /* are cpu states controlled by user space */ 129 137 static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm) 130 138 { ··· 187 183 void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu); 188 184 /* is cmma enabled */ 189 185 bool kvm_s390_cmma_enabled(struct kvm *kvm); 190 - int test_vfacility(unsigned long nr); 186 + unsigned long kvm_s390_fac_list_mask_size(void); 187 + extern unsigned long kvm_s390_fac_list_mask[]; 191 188 192 189 /* implemented in diag.c */ 193 190 int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
+9 -4
arch/s390/kvm/priv.c
··· 337 337 static int handle_stfl(struct kvm_vcpu *vcpu) 338 338 { 339 339 int rc; 340 + unsigned int fac; 340 341 341 342 vcpu->stat.instruction_stfl++; 342 343 343 344 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) 344 345 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); 345 346 347 + /* 348 + * We need to shift the lower 32 facility bits (bit 0-31) from a u64 349 + * into a u32 memory representation. They will remain bits 0-31. 350 + */ 351 + fac = *vcpu->kvm->arch.model.fac->sie >> 32; 346 352 rc = write_guest_lc(vcpu, offsetof(struct _lowcore, stfl_fac_list), 347 - vfacilities, 4); 353 + &fac, sizeof(fac)); 348 354 if (rc) 349 355 return rc; 350 - VCPU_EVENT(vcpu, 5, "store facility list value %x", 351 - *(unsigned int *) vfacilities); 352 - trace_kvm_s390_handle_stfl(vcpu, *(unsigned int *) vfacilities); 356 + VCPU_EVENT(vcpu, 5, "store facility list value %x", fac); 357 + trace_kvm_s390_handle_stfl(vcpu, fac); 353 358 return 0; 354 359 } 355 360
+4
virt/kvm/Kconfig
··· 43 43 44 44 config KVM_GENERIC_DIRTYLOG_READ_PROTECT 45 45 bool 46 + 47 + config KVM_COMPAT 48 + def_bool y 49 + depends on COMPAT && !S390
+6 -6
virt/kvm/kvm_main.c
··· 92 92 93 93 static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl, 94 94 unsigned long arg); 95 - #ifdef CONFIG_COMPAT 95 + #ifdef CONFIG_KVM_COMPAT 96 96 static long kvm_vcpu_compat_ioctl(struct file *file, unsigned int ioctl, 97 97 unsigned long arg); 98 98 #endif ··· 2052 2052 static struct file_operations kvm_vcpu_fops = { 2053 2053 .release = kvm_vcpu_release, 2054 2054 .unlocked_ioctl = kvm_vcpu_ioctl, 2055 - #ifdef CONFIG_COMPAT 2055 + #ifdef CONFIG_KVM_COMPAT 2056 2056 .compat_ioctl = kvm_vcpu_compat_ioctl, 2057 2057 #endif 2058 2058 .mmap = kvm_vcpu_mmap, ··· 2342 2342 return r; 2343 2343 } 2344 2344 2345 - #ifdef CONFIG_COMPAT 2345 + #ifdef CONFIG_KVM_COMPAT 2346 2346 static long kvm_vcpu_compat_ioctl(struct file *filp, 2347 2347 unsigned int ioctl, unsigned long arg) 2348 2348 { ··· 2434 2434 2435 2435 static const struct file_operations kvm_device_fops = { 2436 2436 .unlocked_ioctl = kvm_device_ioctl, 2437 - #ifdef CONFIG_COMPAT 2437 + #ifdef CONFIG_KVM_COMPAT 2438 2438 .compat_ioctl = kvm_device_ioctl, 2439 2439 #endif 2440 2440 .release = kvm_device_release, ··· 2721 2721 return r; 2722 2722 } 2723 2723 2724 - #ifdef CONFIG_COMPAT 2724 + #ifdef CONFIG_KVM_COMPAT 2725 2725 struct compat_kvm_dirty_log { 2726 2726 __u32 slot; 2727 2727 __u32 padding1; ··· 2768 2768 static struct file_operations kvm_vm_fops = { 2769 2769 .release = kvm_vm_release, 2770 2770 .unlocked_ioctl = kvm_vm_ioctl, 2771 - #ifdef CONFIG_COMPAT 2771 + #ifdef CONFIG_KVM_COMPAT 2772 2772 .compat_ioctl = kvm_vm_compat_ioctl, 2773 2773 #endif 2774 2774 .llseek = noop_llseek,