Pull kvm fixes from Paolo Bonzini: "s390: - Fix S390_USER_OPEREXEC so it can now be enabled regardless of other unrelated capabilities - Fix handling of the _PAGE_UNUSED pte bit that could lead to guest memory corruption in some scenarios - A bunch of misc gmap fixes (locking, behaviour under memory pressure) - Fix CMMA dirty tracking x86: - Tidy up some WARN_ON() and BUG_ON(), replacing them with WARN_ON_ONCE() or KVM_BUG_ON(). All of these have obviously never triggered, or somebody would have been annoyed earlier, but still... - Fix missing interrupt due to stale CR8 intercept - Add a statistic that can come in handy to debug leaks as well as the vulnerability to a class of recently-discovered issues - Do not ask arch/x86/kernel to export default_cpu_present_to_apicid() just for KVM" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (22 commits) x86/apic: KVM: Use cpu_physical_id() to get APIC ID of running vCPU for AVIC KVM: x86/mmu: Expose number of shadow MMU shadow pages as a stat KVM: x86: Unconditionally recompute CR8 intercept on PPR update KVM: VMX: Grab vmcs12 on CR8 interception update iff vCPU is in guest mode KVM: x86: WARN (once) if RTC pending EOI tracking goes off the rails KVM: x86: WARN and fail kvm_set_irq() if a PIC or I/O APIC vector is invalid KVM: x86: Bug the VM, not the kernel, if the ISR count {under,over}flows KVM: x86/mmu: Bug the VM, not the host kernel, if KVM write-protects upper SPTEs KVM: x86: Replace BUG_ON() with WARN_ON_ONCE() on "bad" nested GPA translation KVM: Replace guest-triggerable BUG_ON() in ioeventfd datamatch with get_unaligned() KVM: s390: Return failure in case of failure in kvm_s390_set_cmma_bits() KVM: s390: selftests: Fix cmma selftest KVM: s390: Fix cmma dirty tracking KVM: s390: Fix locking in kvm_s390_set_mem_control() KVM: s390: Fix handle_{sske,pfmf} under memory pressure KVM: s390: Fix code typo in gmap_protect_asce_top_level() KVM: s390: Do not set special large pages dirty KVM: s390: Fix dat_peek_cmma() overflow s390/mm: Fix handling of _PAGE_UNUSED pte bit KVM: s390: Fix typo in UCONTROL documentation ...
Showing the changes to tools/testing (3 of 25 files). Show all
Unified · Split
| @@ -11,6 +11,7 @@ · 10 unmodified lines | |||
| 11 | #ifndef SELFTEST_KVM_FACILITY_H | 11 | #ifndef SELFTEST_KVM_FACILITY_H |
| 12 | #define SELFTEST_KVM_FACILITY_H | 12 | #define SELFTEST_KVM_FACILITY_H |
| 13 | 13 | ||
| 14 | #include <linux/atomic.h> | ||
| 14 | #include <linux/bitops.h> | 15 | #include <linux/bitops.h> |
| 15 | 16 | ||
| 16 | /* alt_stfle_fac_list[16] + stfle_fac_list[16] */ | 17 | /* alt_stfle_fac_list[16] + stfle_fac_list[16] */ |
| @@ -19,6 +20,11 @@ · 2 unmodified lines | |||
| 19 | extern u64 stfl_doublewords[NB_STFL_DOUBLEWORDS]; | 20 | extern u64 stfl_doublewords[NB_STFL_DOUBLEWORDS]; |
| 20 | extern bool stfle_flag; | 21 | extern bool stfle_flag; |
| 21 | 22 | ||
| 23 | static inline bool clear_bit_inv(unsigned long nr, unsigned long *ptr) | ||
| 24 | { | ||
| 25 | return clear_bit(nr ^ (BITS_PER_LONG - 1), ptr); | ||
| 26 | } | ||
| 27 | |||
| 22 | static inline bool test_bit_inv(unsigned long nr, const unsigned long *ptr) | 28 | static inline bool test_bit_inv(unsigned long nr, const unsigned long *ptr) |
| 23 | { | 29 | { |
| 24 | return test_bit(nr ^ (BITS_PER_LONG - 1), ptr); | 30 | return test_bit(nr ^ (BITS_PER_LONG - 1), ptr); |
| @@ -34,16 +34,22 @@ static char cmma_value_buf[MAIN_PAGE_COUNT + TEST_DATA_PAGE_COUNT]; · 33 unmodified lines | |||
| 34 | /** | 34 | /** |
| 35 | * Dirty CMMA attributes of exactly one page in the TEST_DATA memslot, | 35 | * Dirty CMMA attributes of exactly one page in the TEST_DATA memslot, |
| 36 | * so use_cmma goes on and the CMMA related ioctls do something. | 36 | * so use_cmma goes on and the CMMA related ioctls do something. |
| 37 | * Touch the page at offset 1M inside TEST_DATA to make sure its page | ||
| 38 | * tables are allocated in the host. | ||
| 37 | */ | 39 | */ |
| 38 | static void guest_do_one_essa(void) | 40 | static void guest_do_one_essa(void) |
| 39 | { | 41 | { |
| 40 | asm volatile( | 42 | asm volatile( |
| 41 | /* load TEST_DATA_START_GFN into r1 */ | 43 | /* load TEST_DATA_START_GFN into r1 */ |
| 44 | " xgr 1,1\n" | ||
| 42 | " llilf 1,%[start_gfn]\n" | 45 | " llilf 1,%[start_gfn]\n" |
| 43 | /* calculate the address from the gfn */ | 46 | /* calculate the address from the gfn */ |
| 44 | " sllg 1,1,12(0)\n" | 47 | " sllg 1,1,12(0)\n" |
| 45 | /* set the first page in TEST_DATA memslot to STABLE */ | 48 | /* set the first page in TEST_DATA memslot to STABLE */ |
| 46 | " .insn rrf,0xb9ab0000,2,1,1,0\n" | 49 | " .insn rrf,0xb9ab0000,2,1,1,0\n" |
| 50 | " agfi 1,0x100000\n" | ||
| 51 | /* also touch the first page of the second MB of TEST_DATA */ | ||
| 52 | " .insn rrf,0xb9ab0000,2,1,1,0\n" | ||
| 47 | /* hypercall */ | 53 | /* hypercall */ |
| 48 | " diag 0,0,0x501\n" | 54 | " diag 0,0,0x501\n" |
| 49 | "0: j 0b" | 55 | "0: j 0b" |
| @@ -6,6 +6,7 @@ · 5 unmodified lines | |||
| 6 | * Authors: | 6 | * Authors: |
| 7 | * Janosch Frank <frankja@linux.ibm.com> | 7 | * Janosch Frank <frankja@linux.ibm.com> |
| 8 | */ | 8 | */ |
| 9 | #include "facility.h" | ||
| 9 | #include "kselftest.h" | 10 | #include "kselftest.h" |
| 10 | #include "kvm_util.h" | 11 | #include "kvm_util.h" |
| 11 | #include "test_util.h" | 12 | #include "test_util.h" |
| @@ -109,6 +110,111 @@ static void test_user_operexec_combined(void) · 97 unmodified lines | |||
| 109 | kvm_vm_free(vm); | 110 | kvm_vm_free(vm); |
| 110 | } | 111 | } |
| 111 | 112 | ||
| 113 | static struct kvm_vm *create_vm_without_sthyi(void) | ||
| 114 | { | ||
| 115 | struct kvm_s390_vm_cpu_processor info; | ||
| 116 | struct kvm_vm *vm; | ||
| 117 | |||
| 118 | vm = vm_create(1); | ||
| 119 | |||
| 120 | kvm_device_attr_get(vm->fd, KVM_S390_VM_CPU_MODEL, | ||
| 121 | KVM_S390_VM_CPU_PROCESSOR, &info); | ||
| 122 | |||
| 123 | clear_bit_inv(74, (unsigned long *)&info.fac_list); | ||
| 124 | kvm_device_attr_set(vm->fd, KVM_S390_VM_CPU_MODEL, | ||
| 125 | KVM_S390_VM_CPU_PROCESSOR, &info); | ||
| 126 | |||
| 127 | return vm; | ||
| 128 | } | ||
| 129 | |||
| 130 | static void test_user_instr0_no_stfle_74(void) | ||
| 131 | { | ||
| 132 | struct kvm_vcpu *vcpu; | ||
| 133 | struct kvm_vm *vm; | ||
| 134 | int rc; | ||
| 135 | |||
| 136 | vm = create_vm_without_sthyi(); | ||
| 137 | |||
| 138 | rc = __vm_enable_cap(vm, KVM_CAP_S390_USER_INSTR0, 0); | ||
| 139 | TEST_ASSERT_EQ(0, rc); | ||
| 140 | |||
| 141 | vcpu = vm_vcpu_add(vm, 0, guest_code_instr0); | ||
| 142 | |||
| 143 | vcpu_run(vcpu); | ||
| 144 | TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC); | ||
| 145 | TEST_ASSERT_EQ(vcpu->run->s390_sieic.icptcode, ICPT_OPEREXC); | ||
| 146 | TEST_ASSERT_EQ(vcpu->run->s390_sieic.ipa, 0x0000); | ||
| 147 | |||
| 148 | kvm_vm_free(vm); | ||
| 149 | } | ||
| 150 | |||
| 151 | static void test_user_operexec_no_stfle_74(void) | ||
| 152 | { | ||
| 153 | struct kvm_vcpu *vcpu; | ||
| 154 | struct kvm_vm *vm; | ||
| 155 | int rc; | ||
| 156 | |||
| 157 | vm = create_vm_without_sthyi(); | ||
| 158 | |||
| 159 | rc = __vm_enable_cap(vm, KVM_CAP_S390_USER_OPEREXEC, 0); | ||
| 160 | TEST_ASSERT_EQ(0, rc); | ||
| 161 | |||
| 162 | vcpu = vm_vcpu_add(vm, 0, guest_code_user_operexec); | ||
| 163 | |||
| 164 | vcpu_run(vcpu); | ||
| 165 | TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC); | ||
| 166 | TEST_ASSERT_EQ(vcpu->run->s390_sieic.icptcode, ICPT_OPEREXC); | ||
| 167 | TEST_ASSERT_EQ(vcpu->run->s390_sieic.ipa, 0x0807); | ||
| 168 | |||
| 169 | kvm_vm_free(vm); | ||
| 170 | } | ||
| 171 | |||
| 172 | static void test_instr0_combined_no_stfle_74(void) | ||
| 173 | { | ||
| 174 | struct kvm_vcpu *vcpu; | ||
| 175 | struct kvm_vm *vm; | ||
| 176 | int rc; | ||
| 177 | |||
| 178 | vm = create_vm_without_sthyi(); | ||
| 179 | |||
| 180 | rc = __vm_enable_cap(vm, KVM_CAP_S390_USER_INSTR0, 0); | ||
| 181 | TEST_ASSERT_EQ(0, rc); | ||
| 182 | rc = __vm_enable_cap(vm, KVM_CAP_S390_USER_OPEREXEC, 0); | ||
| 183 | TEST_ASSERT_EQ(0, rc); | ||
| 184 | |||
| 185 | vcpu = vm_vcpu_add(vm, 0, guest_code_instr0); | ||
| 186 | |||
| 187 | vcpu_run(vcpu); | ||
| 188 | TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC); | ||
| 189 | TEST_ASSERT_EQ(vcpu->run->s390_sieic.icptcode, ICPT_OPEREXC); | ||
| 190 | TEST_ASSERT_EQ(vcpu->run->s390_sieic.ipa, 0x0000); | ||
| 191 | |||
| 192 | kvm_vm_free(vm); | ||
| 193 | } | ||
| 194 | |||
| 195 | static void test_operexec_combined_no_stfle_74(void) | ||
| 196 | { | ||
| 197 | struct kvm_vcpu *vcpu; | ||
| 198 | struct kvm_vm *vm; | ||
| 199 | int rc; | ||
| 200 | |||
| 201 | vm = create_vm_without_sthyi(); | ||
| 202 | |||
| 203 | rc = __vm_enable_cap(vm, KVM_CAP_S390_USER_INSTR0, 0); | ||
| 204 | TEST_ASSERT_EQ(0, rc); | ||
| 205 | rc = __vm_enable_cap(vm, KVM_CAP_S390_USER_OPEREXEC, 0); | ||
| 206 | TEST_ASSERT_EQ(0, rc); | ||
| 207 | |||
| 208 | vcpu = vm_vcpu_add(vm, 0, guest_code_user_operexec); | ||
| 209 | |||
| 210 | vcpu_run(vcpu); | ||
| 211 | TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC); | ||
| 212 | TEST_ASSERT_EQ(vcpu->run->s390_sieic.icptcode, ICPT_OPEREXC); | ||
| 213 | TEST_ASSERT_EQ(vcpu->run->s390_sieic.ipa, 0x0807); | ||
| 214 | |||
| 215 | kvm_vm_free(vm); | ||
| 216 | } | ||
| 217 | |||
| 112 | /* | 218 | /* |
| 113 | * Run all tests above. | 219 | * Run all tests above. |
| 114 | * | 220 | * |
| @@ -122,6 +228,10 @@ static struct testdef { · 7 unmodified lines | |||
| 122 | { "instr0", test_user_instr0 }, | 228 | { "instr0", test_user_instr0 }, |
| 123 | { "operexec", test_user_operexec }, | 229 | { "operexec", test_user_operexec }, |
| 124 | { "operexec_combined", test_user_operexec_combined}, | 230 | { "operexec_combined", test_user_operexec_combined}, |
| 231 | { "instr0_no_stfle_74", test_user_instr0_no_stfle_74 }, | ||
| 232 | { "instr0_combined_no_stfle_74", test_instr0_combined_no_stfle_74 }, | ||
| 233 | { "operexec_combined_no_stfle_74", test_operexec_combined_no_stfle_74 }, | ||
| 234 | { "operexec_no_stfle_74", test_user_operexec_no_stfle_74 }, | ||
| 125 | }; | 235 | }; |
| 126 | 236 | ||
| 127 | int main(int argc, char *argv[]) | 237 | int main(int argc, char *argv[]) |