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

Pull kvm fixes from Paolo Bonzini:
"The largest part here is for KVM/PPC, where a NULL pointer dereference
was introduced in the 6.13 merge window and is now fixed.

There's some "holiday-induced lateness", as the s390 submaintainer put
it, but otherwise things looks fine.

s390:

- fix a latent bug when the kernel is compiled in debug mode

- two small UCONTROL fixes and their selftests

arm64:

- always check page state in hyp_ack_unshare()

- align set_id_regs selftest with the fact that ASIDBITS field is RO

- various vPMU fixes for bugs that only affect nested virt

PPC e500:

- Fix a mostly impossible (but just wrong) case where IRQs were never
re-enabled

- Observe host permissions instead of mapping readonly host pages as
guest-writable. This fixes a NULL-pointer dereference in 6.13

- Replace brittle VMA-based attempts at building huge shadow TLB
entries with PTE lookups"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
KVM: e500: perform hugepage check after looking up the PFN
KVM: e500: map readonly host pages for read
KVM: e500: track host-writability of pages
KVM: e500: use shadow TLB entry as witness for writability
KVM: e500: always restore irqs
KVM: s390: selftests: Add has device attr check to uc_attr_mem_limit selftest
KVM: s390: selftests: Add ucontrol gis routing test
KVM: s390: Reject KVM_SET_GSI_ROUTING on ucontrol VMs
KVM: s390: selftests: Add ucontrol flic attr selftests
KVM: s390: Reject setting flic pfault attributes on ucontrol VMs
KVM: s390: vsie: fix virtual/physical address in unpin_scb()
KVM: arm64: Only apply PMCR_EL0.P to the guest range of counters
KVM: arm64: nv: Reload PMU events upon MDCR_EL2.HPME change
KVM: arm64: Use KVM_REQ_RELOAD_PMU to handle PMCR_EL0.E change
KVM: arm64: Add unified helper for reprogramming counters by mask
KVM: arm64: Always check the state from hyp_ack_unshare()
KVM: arm64: Fix set_id_regs selftest for ASIDBITS becoming unwritable

Changed files
+333 -188
Documentation
virt
kvm
arch
arm64
powerpc
s390
include
kvm
tools
testing
selftests
kvm
+3
Documentation/virt/kvm/api.rst
··· 1914 1914 #define KVM_IRQ_ROUTING_HV_SINT 4 1915 1915 #define KVM_IRQ_ROUTING_XEN_EVTCHN 5 1916 1916 1917 + On s390, adding a KVM_IRQ_ROUTING_S390_ADAPTER is rejected on ucontrol VMs with 1918 + error -EINVAL. 1919 + 1917 1920 flags: 1918 1921 1919 1922 - KVM_MSI_VALID_DEVID: used along with KVM_IRQ_ROUTING_MSI routing entry
+4
Documentation/virt/kvm/devices/s390_flic.rst
··· 58 58 Enables async page faults for the guest. So in case of a major page fault 59 59 the host is allowed to handle this async and continues the guest. 60 60 61 + -EINVAL is returned when called on the FLIC of a ucontrol VM. 62 + 61 63 KVM_DEV_FLIC_APF_DISABLE_WAIT 62 64 Disables async page faults for the guest and waits until already pending 63 65 async page faults are done. This is necessary to trigger a completion interrupt 64 66 for every init interrupt before migrating the interrupt list. 67 + 68 + -EINVAL is returned when called on the FLIC of a ucontrol VM. 65 69 66 70 KVM_DEV_FLIC_ADAPTER_REGISTER 67 71 Register an I/O adapter interrupt source. Takes a kvm_s390_io_adapter
-3
arch/arm64/kvm/hyp/nvhe/mem_protect.c
··· 783 783 if (tx->initiator.id == PKVM_ID_HOST && hyp_page_count((void *)addr)) 784 784 return -EBUSY; 785 785 786 - if (__hyp_ack_skip_pgtable_check(tx)) 787 - return 0; 788 - 789 786 return __hyp_check_page_state_range(addr, size, 790 787 PKVM_PAGE_SHARED_BORROWED); 791 788 }
+36 -55
arch/arm64/kvm/pmu-emul.c
··· 24 24 25 25 static void kvm_pmu_create_perf_event(struct kvm_pmc *pmc); 26 26 static void kvm_pmu_release_perf_event(struct kvm_pmc *pmc); 27 + static bool kvm_pmu_counter_is_enabled(struct kvm_pmc *pmc); 27 28 28 29 static struct kvm_vcpu *kvm_pmc_to_vcpu(const struct kvm_pmc *pmc) 29 30 { ··· 328 327 return GENMASK(val - 1, 0) | BIT(ARMV8_PMU_CYCLE_IDX); 329 328 } 330 329 331 - /** 332 - * kvm_pmu_enable_counter_mask - enable selected PMU counters 333 - * @vcpu: The vcpu pointer 334 - * @val: the value guest writes to PMCNTENSET register 335 - * 336 - * Call perf_event_enable to start counting the perf event 337 - */ 338 - void kvm_pmu_enable_counter_mask(struct kvm_vcpu *vcpu, u64 val) 330 + static void kvm_pmc_enable_perf_event(struct kvm_pmc *pmc) 339 331 { 340 - int i; 341 - if (!kvm_vcpu_has_pmu(vcpu)) 332 + if (!pmc->perf_event) { 333 + kvm_pmu_create_perf_event(pmc); 342 334 return; 343 - 344 - if (!(kvm_vcpu_read_pmcr(vcpu) & ARMV8_PMU_PMCR_E) || !val) 345 - return; 346 - 347 - for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++) { 348 - struct kvm_pmc *pmc; 349 - 350 - if (!(val & BIT(i))) 351 - continue; 352 - 353 - pmc = kvm_vcpu_idx_to_pmc(vcpu, i); 354 - 355 - if (!pmc->perf_event) { 356 - kvm_pmu_create_perf_event(pmc); 357 - } else { 358 - perf_event_enable(pmc->perf_event); 359 - if (pmc->perf_event->state != PERF_EVENT_STATE_ACTIVE) 360 - kvm_debug("fail to enable perf event\n"); 361 - } 362 335 } 336 + 337 + perf_event_enable(pmc->perf_event); 338 + if (pmc->perf_event->state != PERF_EVENT_STATE_ACTIVE) 339 + kvm_debug("fail to enable perf event\n"); 363 340 } 364 341 365 - /** 366 - * kvm_pmu_disable_counter_mask - disable selected PMU counters 367 - * @vcpu: The vcpu pointer 368 - * @val: the value guest writes to PMCNTENCLR register 369 - * 370 - * Call perf_event_disable to stop counting the perf event 371 - */ 372 - void kvm_pmu_disable_counter_mask(struct kvm_vcpu *vcpu, u64 val) 342 + static void kvm_pmc_disable_perf_event(struct kvm_pmc *pmc) 343 + { 344 + if (pmc->perf_event) 345 + perf_event_disable(pmc->perf_event); 346 + } 347 + 348 + void kvm_pmu_reprogram_counter_mask(struct kvm_vcpu *vcpu, u64 val) 373 349 { 374 350 int i; 375 351 ··· 354 376 return; 355 377 356 378 for (i = 0; i < KVM_ARMV8_PMU_MAX_COUNTERS; i++) { 357 - struct kvm_pmc *pmc; 379 + struct kvm_pmc *pmc = kvm_vcpu_idx_to_pmc(vcpu, i); 358 380 359 381 if (!(val & BIT(i))) 360 382 continue; 361 383 362 - pmc = kvm_vcpu_idx_to_pmc(vcpu, i); 363 - 364 - if (pmc->perf_event) 365 - perf_event_disable(pmc->perf_event); 384 + if (kvm_pmu_counter_is_enabled(pmc)) 385 + kvm_pmc_enable_perf_event(pmc); 386 + else 387 + kvm_pmc_disable_perf_event(pmc); 366 388 } 389 + 390 + kvm_vcpu_pmu_restore_guest(vcpu); 367 391 } 368 392 369 393 /* ··· 606 626 if (!kvm_has_feat(vcpu->kvm, ID_AA64DFR0_EL1, PMUVer, V3P5)) 607 627 val &= ~ARMV8_PMU_PMCR_LP; 608 628 629 + /* Request a reload of the PMU to enable/disable affected counters */ 630 + if ((__vcpu_sys_reg(vcpu, PMCR_EL0) ^ val) & ARMV8_PMU_PMCR_E) 631 + kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu); 632 + 609 633 /* The reset bits don't indicate any state, and shouldn't be saved. */ 610 634 __vcpu_sys_reg(vcpu, PMCR_EL0) = val & ~(ARMV8_PMU_PMCR_C | ARMV8_PMU_PMCR_P); 611 - 612 - if (val & ARMV8_PMU_PMCR_E) { 613 - kvm_pmu_enable_counter_mask(vcpu, 614 - __vcpu_sys_reg(vcpu, PMCNTENSET_EL0)); 615 - } else { 616 - kvm_pmu_disable_counter_mask(vcpu, 617 - __vcpu_sys_reg(vcpu, PMCNTENSET_EL0)); 618 - } 619 635 620 636 if (val & ARMV8_PMU_PMCR_C) 621 637 kvm_pmu_set_counter_value(vcpu, ARMV8_PMU_CYCLE_IDX, 0); 622 638 623 639 if (val & ARMV8_PMU_PMCR_P) { 624 - unsigned long mask = kvm_pmu_accessible_counter_mask(vcpu); 625 - mask &= ~BIT(ARMV8_PMU_CYCLE_IDX); 640 + /* 641 + * Unlike other PMU sysregs, the controls in PMCR_EL0 always apply 642 + * to the 'guest' range of counters and never the 'hyp' range. 643 + */ 644 + unsigned long mask = kvm_pmu_implemented_counter_mask(vcpu) & 645 + ~kvm_pmu_hyp_counter_mask(vcpu) & 646 + ~BIT(ARMV8_PMU_CYCLE_IDX); 647 + 626 648 for_each_set_bit(i, &mask, 32) 627 649 kvm_pmu_set_pmc_value(kvm_vcpu_idx_to_pmc(vcpu, i), 0, true); 628 650 } 629 - kvm_vcpu_pmu_restore_guest(vcpu); 630 651 } 631 652 632 653 static bool kvm_pmu_counter_is_enabled(struct kvm_pmc *pmc) ··· 891 910 { 892 911 u64 mask = kvm_pmu_implemented_counter_mask(vcpu); 893 912 894 - kvm_pmu_handle_pmcr(vcpu, kvm_vcpu_read_pmcr(vcpu)); 895 - 896 913 __vcpu_sys_reg(vcpu, PMOVSSET_EL0) &= mask; 897 914 __vcpu_sys_reg(vcpu, PMINTENSET_EL1) &= mask; 898 915 __vcpu_sys_reg(vcpu, PMCNTENSET_EL0) &= mask; 916 + 917 + kvm_pmu_reprogram_counter_mask(vcpu, mask); 899 918 } 900 919 901 920 int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu)
+25 -7
arch/arm64/kvm/sys_regs.c
··· 1208 1208 mask = kvm_pmu_accessible_counter_mask(vcpu); 1209 1209 if (p->is_write) { 1210 1210 val = p->regval & mask; 1211 - if (r->Op2 & 0x1) { 1211 + if (r->Op2 & 0x1) 1212 1212 /* accessing PMCNTENSET_EL0 */ 1213 1213 __vcpu_sys_reg(vcpu, PMCNTENSET_EL0) |= val; 1214 - kvm_pmu_enable_counter_mask(vcpu, val); 1215 - kvm_vcpu_pmu_restore_guest(vcpu); 1216 - } else { 1214 + else 1217 1215 /* accessing PMCNTENCLR_EL0 */ 1218 1216 __vcpu_sys_reg(vcpu, PMCNTENSET_EL0) &= ~val; 1219 - kvm_pmu_disable_counter_mask(vcpu, val); 1220 - } 1217 + 1218 + kvm_pmu_reprogram_counter_mask(vcpu, val); 1221 1219 } else { 1222 1220 p->regval = __vcpu_sys_reg(vcpu, PMCNTENSET_EL0); 1223 1221 } ··· 2448 2450 return __el2_visibility(vcpu, rd, s1pie_visibility); 2449 2451 } 2450 2452 2453 + static bool access_mdcr(struct kvm_vcpu *vcpu, 2454 + struct sys_reg_params *p, 2455 + const struct sys_reg_desc *r) 2456 + { 2457 + u64 old = __vcpu_sys_reg(vcpu, MDCR_EL2); 2458 + 2459 + if (!access_rw(vcpu, p, r)) 2460 + return false; 2461 + 2462 + /* 2463 + * Request a reload of the PMU to enable/disable the counters affected 2464 + * by HPME. 2465 + */ 2466 + if ((old ^ __vcpu_sys_reg(vcpu, MDCR_EL2)) & MDCR_EL2_HPME) 2467 + kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu); 2468 + 2469 + return true; 2470 + } 2471 + 2472 + 2451 2473 /* 2452 2474 * Architected system registers. 2453 2475 * Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2 ··· 3001 2983 EL2_REG(SCTLR_EL2, access_rw, reset_val, SCTLR_EL2_RES1), 3002 2984 EL2_REG(ACTLR_EL2, access_rw, reset_val, 0), 3003 2985 EL2_REG_VNCR(HCR_EL2, reset_hcr, 0), 3004 - EL2_REG(MDCR_EL2, access_rw, reset_val, 0), 2986 + EL2_REG(MDCR_EL2, access_mdcr, reset_val, 0), 3005 2987 EL2_REG(CPTR_EL2, access_rw, reset_val, CPTR_NVHE_EL2_RES1), 3006 2988 EL2_REG_VNCR(HSTR_EL2, reset_val, 0), 3007 2989 EL2_REG_VNCR(HFGRTR_EL2, reset_val, 0),
+2
arch/powerpc/kvm/e500.h
··· 34 34 #define E500_TLB_BITMAP (1 << 30) 35 35 /* TLB1 entry is mapped by host TLB0 */ 36 36 #define E500_TLB_TLB0 (1 << 29) 37 + /* entry is writable on the host */ 38 + #define E500_TLB_WRITABLE (1 << 28) 37 39 /* bits [6-5] MAS2_X1 and MAS2_X0 and [4-0] bits for WIMGE */ 38 40 #define E500_TLB_MAS2_ATTR (0x7f) 39 41
+83 -116
arch/powerpc/kvm/e500_mmu_host.c
··· 45 45 return host_tlb_params[1].entries - tlbcam_index - 1; 46 46 } 47 47 48 - static inline u32 e500_shadow_mas3_attrib(u32 mas3, int usermode) 48 + static inline u32 e500_shadow_mas3_attrib(u32 mas3, bool writable, int usermode) 49 49 { 50 50 /* Mask off reserved bits. */ 51 51 mas3 &= MAS3_ATTRIB_MASK; 52 + 53 + if (!writable) 54 + mas3 &= ~(MAS3_UW|MAS3_SW); 52 55 53 56 #ifndef CONFIG_KVM_BOOKE_HV 54 57 if (!usermode) { ··· 245 242 return tlbe->mas7_3 & (MAS3_SW|MAS3_UW); 246 243 } 247 244 248 - static inline bool kvmppc_e500_ref_setup(struct tlbe_ref *ref, 245 + static inline void kvmppc_e500_ref_setup(struct tlbe_ref *ref, 249 246 struct kvm_book3e_206_tlb_entry *gtlbe, 250 - kvm_pfn_t pfn, unsigned int wimg) 247 + kvm_pfn_t pfn, unsigned int wimg, 248 + bool writable) 251 249 { 252 250 ref->pfn = pfn; 253 251 ref->flags = E500_TLB_VALID; 252 + if (writable) 253 + ref->flags |= E500_TLB_WRITABLE; 254 254 255 255 /* Use guest supplied MAS2_G and MAS2_E */ 256 256 ref->flags |= (gtlbe->mas2 & MAS2_ATTRIB_MASK) | wimg; 257 - 258 - return tlbe_is_writable(gtlbe); 259 257 } 260 258 261 259 static inline void kvmppc_e500_ref_release(struct tlbe_ref *ref) ··· 309 305 { 310 306 kvm_pfn_t pfn = ref->pfn; 311 307 u32 pr = vcpu->arch.shared->msr & MSR_PR; 308 + bool writable = !!(ref->flags & E500_TLB_WRITABLE); 312 309 313 310 BUG_ON(!(ref->flags & E500_TLB_VALID)); 314 311 ··· 317 312 stlbe->mas1 = MAS1_TSIZE(tsize) | get_tlb_sts(gtlbe) | MAS1_VALID; 318 313 stlbe->mas2 = (gvaddr & MAS2_EPN) | (ref->flags & E500_TLB_MAS2_ATTR); 319 314 stlbe->mas7_3 = ((u64)pfn << PAGE_SHIFT) | 320 - e500_shadow_mas3_attrib(gtlbe->mas7_3, pr); 315 + e500_shadow_mas3_attrib(gtlbe->mas7_3, writable, pr); 321 316 } 322 317 323 318 static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, ··· 326 321 struct tlbe_ref *ref) 327 322 { 328 323 struct kvm_memory_slot *slot; 329 - unsigned long pfn = 0; /* silence GCC warning */ 324 + unsigned int psize; 325 + unsigned long pfn; 330 326 struct page *page = NULL; 331 327 unsigned long hva; 332 - int pfnmap = 0; 333 328 int tsize = BOOK3E_PAGESZ_4K; 334 329 int ret = 0; 335 330 unsigned long mmu_seq; 336 331 struct kvm *kvm = vcpu_e500->vcpu.kvm; 337 - unsigned long tsize_pages = 0; 338 332 pte_t *ptep; 339 333 unsigned int wimg = 0; 340 334 pgd_t *pgdir; ··· 355 351 slot = gfn_to_memslot(vcpu_e500->vcpu.kvm, gfn); 356 352 hva = gfn_to_hva_memslot(slot, gfn); 357 353 358 - if (tlbsel == 1) { 359 - struct vm_area_struct *vma; 360 - mmap_read_lock(kvm->mm); 361 - 362 - vma = find_vma(kvm->mm, hva); 363 - if (vma && hva >= vma->vm_start && 364 - (vma->vm_flags & VM_PFNMAP)) { 365 - /* 366 - * This VMA is a physically contiguous region (e.g. 367 - * /dev/mem) that bypasses normal Linux page 368 - * management. Find the overlap between the 369 - * vma and the memslot. 370 - */ 371 - 372 - unsigned long start, end; 373 - unsigned long slot_start, slot_end; 374 - 375 - pfnmap = 1; 376 - 377 - start = vma->vm_pgoff; 378 - end = start + 379 - vma_pages(vma); 380 - 381 - pfn = start + ((hva - vma->vm_start) >> PAGE_SHIFT); 382 - 383 - slot_start = pfn - (gfn - slot->base_gfn); 384 - slot_end = slot_start + slot->npages; 385 - 386 - if (start < slot_start) 387 - start = slot_start; 388 - if (end > slot_end) 389 - end = slot_end; 390 - 391 - tsize = (gtlbe->mas1 & MAS1_TSIZE_MASK) >> 392 - MAS1_TSIZE_SHIFT; 393 - 394 - /* 395 - * e500 doesn't implement the lowest tsize bit, 396 - * or 1K pages. 397 - */ 398 - tsize = max(BOOK3E_PAGESZ_4K, tsize & ~1); 399 - 400 - /* 401 - * Now find the largest tsize (up to what the guest 402 - * requested) that will cover gfn, stay within the 403 - * range, and for which gfn and pfn are mutually 404 - * aligned. 405 - */ 406 - 407 - for (; tsize > BOOK3E_PAGESZ_4K; tsize -= 2) { 408 - unsigned long gfn_start, gfn_end; 409 - tsize_pages = 1UL << (tsize - 2); 410 - 411 - gfn_start = gfn & ~(tsize_pages - 1); 412 - gfn_end = gfn_start + tsize_pages; 413 - 414 - if (gfn_start + pfn - gfn < start) 415 - continue; 416 - if (gfn_end + pfn - gfn > end) 417 - continue; 418 - if ((gfn & (tsize_pages - 1)) != 419 - (pfn & (tsize_pages - 1))) 420 - continue; 421 - 422 - gvaddr &= ~((tsize_pages << PAGE_SHIFT) - 1); 423 - pfn &= ~(tsize_pages - 1); 424 - break; 425 - } 426 - } else if (vma && hva >= vma->vm_start && 427 - is_vm_hugetlb_page(vma)) { 428 - unsigned long psize = vma_kernel_pagesize(vma); 429 - 430 - tsize = (gtlbe->mas1 & MAS1_TSIZE_MASK) >> 431 - MAS1_TSIZE_SHIFT; 432 - 433 - /* 434 - * Take the largest page size that satisfies both host 435 - * and guest mapping 436 - */ 437 - tsize = min(__ilog2(psize) - 10, tsize); 438 - 439 - /* 440 - * e500 doesn't implement the lowest tsize bit, 441 - * or 1K pages. 442 - */ 443 - tsize = max(BOOK3E_PAGESZ_4K, tsize & ~1); 444 - } 445 - 446 - mmap_read_unlock(kvm->mm); 447 - } 448 - 449 - if (likely(!pfnmap)) { 450 - tsize_pages = 1UL << (tsize + 10 - PAGE_SHIFT); 451 - pfn = __kvm_faultin_pfn(slot, gfn, FOLL_WRITE, NULL, &page); 452 - if (is_error_noslot_pfn(pfn)) { 453 - if (printk_ratelimit()) 454 - pr_err("%s: real page not found for gfn %lx\n", 455 - __func__, (long)gfn); 456 - return -EINVAL; 457 - } 458 - 459 - /* Align guest and physical address to page map boundaries */ 460 - pfn &= ~(tsize_pages - 1); 461 - gvaddr &= ~((tsize_pages << PAGE_SHIFT) - 1); 354 + pfn = __kvm_faultin_pfn(slot, gfn, FOLL_WRITE, &writable, &page); 355 + if (is_error_noslot_pfn(pfn)) { 356 + if (printk_ratelimit()) 357 + pr_err("%s: real page not found for gfn %lx\n", 358 + __func__, (long)gfn); 359 + return -EINVAL; 462 360 } 463 361 464 362 spin_lock(&kvm->mmu_lock); ··· 378 472 * can't run hence pfn won't change. 379 473 */ 380 474 local_irq_save(flags); 381 - ptep = find_linux_pte(pgdir, hva, NULL, NULL); 475 + ptep = find_linux_pte(pgdir, hva, NULL, &psize); 382 476 if (ptep) { 383 477 pte_t pte = READ_ONCE(*ptep); 384 478 385 479 if (pte_present(pte)) { 386 480 wimg = (pte_val(pte) >> PTE_WIMGE_SHIFT) & 387 481 MAS2_WIMGE_MASK; 388 - local_irq_restore(flags); 389 482 } else { 390 483 local_irq_restore(flags); 391 484 pr_err_ratelimited("%s: pte not present: gfn %lx,pfn %lx\n", ··· 393 488 goto out; 394 489 } 395 490 } 396 - writable = kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg); 491 + local_irq_restore(flags); 397 492 493 + if (psize && tlbsel == 1) { 494 + unsigned long psize_pages, tsize_pages; 495 + unsigned long start, end; 496 + unsigned long slot_start, slot_end; 497 + 498 + psize_pages = 1UL << (psize - PAGE_SHIFT); 499 + start = pfn & ~(psize_pages - 1); 500 + end = start + psize_pages; 501 + 502 + slot_start = pfn - (gfn - slot->base_gfn); 503 + slot_end = slot_start + slot->npages; 504 + 505 + if (start < slot_start) 506 + start = slot_start; 507 + if (end > slot_end) 508 + end = slot_end; 509 + 510 + tsize = (gtlbe->mas1 & MAS1_TSIZE_MASK) >> 511 + MAS1_TSIZE_SHIFT; 512 + 513 + /* 514 + * Any page size that doesn't satisfy the host mapping 515 + * will fail the start and end tests. 516 + */ 517 + tsize = min(psize - PAGE_SHIFT + BOOK3E_PAGESZ_4K, tsize); 518 + 519 + /* 520 + * e500 doesn't implement the lowest tsize bit, 521 + * or 1K pages. 522 + */ 523 + tsize = max(BOOK3E_PAGESZ_4K, tsize & ~1); 524 + 525 + /* 526 + * Now find the largest tsize (up to what the guest 527 + * requested) that will cover gfn, stay within the 528 + * range, and for which gfn and pfn are mutually 529 + * aligned. 530 + */ 531 + 532 + for (; tsize > BOOK3E_PAGESZ_4K; tsize -= 2) { 533 + unsigned long gfn_start, gfn_end; 534 + tsize_pages = 1UL << (tsize - 2); 535 + 536 + gfn_start = gfn & ~(tsize_pages - 1); 537 + gfn_end = gfn_start + tsize_pages; 538 + 539 + if (gfn_start + pfn - gfn < start) 540 + continue; 541 + if (gfn_end + pfn - gfn > end) 542 + continue; 543 + if ((gfn & (tsize_pages - 1)) != 544 + (pfn & (tsize_pages - 1))) 545 + continue; 546 + 547 + gvaddr &= ~((tsize_pages << PAGE_SHIFT) - 1); 548 + pfn &= ~(tsize_pages - 1); 549 + break; 550 + } 551 + } 552 + 553 + kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg, writable); 398 554 kvmppc_e500_setup_stlbe(&vcpu_e500->vcpu, gtlbe, tsize, 399 555 ref, gvaddr, stlbe); 556 + writable = tlbe_is_writable(stlbe); 400 557 401 558 /* Clear i-cache for new pages */ 402 559 kvmppc_mmu_flush_icache(pfn);
+6
arch/s390/kvm/interrupt.c
··· 2678 2678 kvm_s390_clear_float_irqs(dev->kvm); 2679 2679 break; 2680 2680 case KVM_DEV_FLIC_APF_ENABLE: 2681 + if (kvm_is_ucontrol(dev->kvm)) 2682 + return -EINVAL; 2681 2683 dev->kvm->arch.gmap->pfault_enabled = 1; 2682 2684 break; 2683 2685 case KVM_DEV_FLIC_APF_DISABLE_WAIT: 2686 + if (kvm_is_ucontrol(dev->kvm)) 2687 + return -EINVAL; 2684 2688 dev->kvm->arch.gmap->pfault_enabled = 0; 2685 2689 /* 2686 2690 * Make sure no async faults are in transition when ··· 2898 2894 switch (ue->type) { 2899 2895 /* we store the userspace addresses instead of the guest addresses */ 2900 2896 case KVM_IRQ_ROUTING_S390_ADAPTER: 2897 + if (kvm_is_ucontrol(kvm)) 2898 + return -EINVAL; 2901 2899 e->set = set_adapter_int; 2902 2900 uaddr = gmap_translate(kvm->arch.gmap, ue->u.adapter.summary_addr); 2903 2901 if (uaddr == -EFAULT)
+1 -1
arch/s390/kvm/vsie.c
··· 854 854 static void unpin_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, 855 855 gpa_t gpa) 856 856 { 857 - hpa_t hpa = (hpa_t) vsie_page->scb_o; 857 + hpa_t hpa = virt_to_phys(vsie_page->scb_o); 858 858 859 859 if (hpa) 860 860 unpin_guest_page(vcpu->kvm, gpa, hpa);
+2 -4
include/kvm/arm_pmu.h
··· 53 53 void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu); 54 54 void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu); 55 55 void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu); 56 - void kvm_pmu_disable_counter_mask(struct kvm_vcpu *vcpu, u64 val); 57 - void kvm_pmu_enable_counter_mask(struct kvm_vcpu *vcpu, u64 val); 56 + void kvm_pmu_reprogram_counter_mask(struct kvm_vcpu *vcpu, u64 val); 58 57 void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu); 59 58 void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu); 60 59 bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu); ··· 126 127 static inline void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu) {} 127 128 static inline void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu) {} 128 129 static inline void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu) {} 129 - static inline void kvm_pmu_disable_counter_mask(struct kvm_vcpu *vcpu, u64 val) {} 130 - static inline void kvm_pmu_enable_counter_mask(struct kvm_vcpu *vcpu, u64 val) {} 130 + static inline void kvm_pmu_reprogram_counter_mask(struct kvm_vcpu *vcpu, u64 val) {} 131 131 static inline void kvm_pmu_flush_hwstate(struct kvm_vcpu *vcpu) {} 132 132 static inline void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu) {} 133 133 static inline bool kvm_pmu_should_notify_user(struct kvm_vcpu *vcpu)
-1
tools/testing/selftests/kvm/aarch64/set_id_regs.c
··· 152 152 REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64MMFR0_EL1, BIGENDEL0, 0), 153 153 REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64MMFR0_EL1, SNSMEM, 0), 154 154 REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64MMFR0_EL1, BIGEND, 0), 155 - REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64MMFR0_EL1, ASIDBITS, 0), 156 155 REG_FTR_BITS(FTR_LOWER_SAFE, ID_AA64MMFR0_EL1, PARANGE, 0), 157 156 REG_FTR_END, 158 157 };
+171 -1
tools/testing/selftests/kvm/s390x/ucontrol_test.c
··· 210 210 struct kvm_device_attr attr = { 211 211 .group = KVM_S390_VM_MEM_CTRL, 212 212 .attr = KVM_S390_VM_MEM_LIMIT_SIZE, 213 - .addr = (unsigned long)&limit, 213 + .addr = (u64)&limit, 214 214 }; 215 215 int rc; 216 + 217 + rc = ioctl(self->vm_fd, KVM_HAS_DEVICE_ATTR, &attr); 218 + EXPECT_EQ(0, rc); 216 219 217 220 rc = ioctl(self->vm_fd, KVM_GET_DEVICE_ATTR, &attr); 218 221 EXPECT_EQ(0, rc); ··· 636 633 ASSERT_EQ(skeyvalue & 0xfa, sync_regs->gprs[1]); 637 634 ASSERT_EQ(0, sync_regs->gprs[1] & 0x04); 638 635 uc_assert_diag44(self); 636 + } 637 + 638 + static char uc_flic_b[PAGE_SIZE]; 639 + static struct kvm_s390_io_adapter uc_flic_ioa = { .id = 0 }; 640 + static struct kvm_s390_io_adapter_req uc_flic_ioam = { .id = 0 }; 641 + static struct kvm_s390_ais_req uc_flic_asim = { .isc = 0 }; 642 + static struct kvm_s390_ais_all uc_flic_asima = { .simm = 0 }; 643 + static struct uc_flic_attr_test { 644 + char *name; 645 + struct kvm_device_attr a; 646 + int hasrc; 647 + int geterrno; 648 + int seterrno; 649 + } uc_flic_attr_tests[] = { 650 + { 651 + .name = "KVM_DEV_FLIC_GET_ALL_IRQS", 652 + .seterrno = EINVAL, 653 + .a = { 654 + .group = KVM_DEV_FLIC_GET_ALL_IRQS, 655 + .addr = (u64)&uc_flic_b, 656 + .attr = PAGE_SIZE, 657 + }, 658 + }, 659 + { 660 + .name = "KVM_DEV_FLIC_ENQUEUE", 661 + .geterrno = EINVAL, 662 + .a = { .group = KVM_DEV_FLIC_ENQUEUE, }, 663 + }, 664 + { 665 + .name = "KVM_DEV_FLIC_CLEAR_IRQS", 666 + .geterrno = EINVAL, 667 + .a = { .group = KVM_DEV_FLIC_CLEAR_IRQS, }, 668 + }, 669 + { 670 + .name = "KVM_DEV_FLIC_ADAPTER_REGISTER", 671 + .geterrno = EINVAL, 672 + .a = { 673 + .group = KVM_DEV_FLIC_ADAPTER_REGISTER, 674 + .addr = (u64)&uc_flic_ioa, 675 + }, 676 + }, 677 + { 678 + .name = "KVM_DEV_FLIC_ADAPTER_MODIFY", 679 + .geterrno = EINVAL, 680 + .seterrno = EINVAL, 681 + .a = { 682 + .group = KVM_DEV_FLIC_ADAPTER_MODIFY, 683 + .addr = (u64)&uc_flic_ioam, 684 + .attr = sizeof(uc_flic_ioam), 685 + }, 686 + }, 687 + { 688 + .name = "KVM_DEV_FLIC_CLEAR_IO_IRQ", 689 + .geterrno = EINVAL, 690 + .seterrno = EINVAL, 691 + .a = { 692 + .group = KVM_DEV_FLIC_CLEAR_IO_IRQ, 693 + .attr = 32, 694 + }, 695 + }, 696 + { 697 + .name = "KVM_DEV_FLIC_AISM", 698 + .geterrno = EINVAL, 699 + .seterrno = ENOTSUP, 700 + .a = { 701 + .group = KVM_DEV_FLIC_AISM, 702 + .addr = (u64)&uc_flic_asim, 703 + }, 704 + }, 705 + { 706 + .name = "KVM_DEV_FLIC_AIRQ_INJECT", 707 + .geterrno = EINVAL, 708 + .a = { .group = KVM_DEV_FLIC_AIRQ_INJECT, }, 709 + }, 710 + { 711 + .name = "KVM_DEV_FLIC_AISM_ALL", 712 + .geterrno = ENOTSUP, 713 + .seterrno = ENOTSUP, 714 + .a = { 715 + .group = KVM_DEV_FLIC_AISM_ALL, 716 + .addr = (u64)&uc_flic_asima, 717 + .attr = sizeof(uc_flic_asima), 718 + }, 719 + }, 720 + { 721 + .name = "KVM_DEV_FLIC_APF_ENABLE", 722 + .geterrno = EINVAL, 723 + .seterrno = EINVAL, 724 + .a = { .group = KVM_DEV_FLIC_APF_ENABLE, }, 725 + }, 726 + { 727 + .name = "KVM_DEV_FLIC_APF_DISABLE_WAIT", 728 + .geterrno = EINVAL, 729 + .seterrno = EINVAL, 730 + .a = { .group = KVM_DEV_FLIC_APF_DISABLE_WAIT, }, 731 + }, 732 + }; 733 + 734 + TEST_F(uc_kvm, uc_flic_attrs) 735 + { 736 + struct kvm_create_device cd = { .type = KVM_DEV_TYPE_FLIC }; 737 + struct kvm_device_attr attr; 738 + u64 value; 739 + int rc, i; 740 + 741 + rc = ioctl(self->vm_fd, KVM_CREATE_DEVICE, &cd); 742 + ASSERT_EQ(0, rc) TH_LOG("create device failed with err %s (%i)", 743 + strerror(errno), errno); 744 + 745 + for (i = 0; i < ARRAY_SIZE(uc_flic_attr_tests); i++) { 746 + TH_LOG("test %s", uc_flic_attr_tests[i].name); 747 + attr = (struct kvm_device_attr) { 748 + .group = uc_flic_attr_tests[i].a.group, 749 + .attr = uc_flic_attr_tests[i].a.attr, 750 + .addr = uc_flic_attr_tests[i].a.addr, 751 + }; 752 + if (attr.addr == 0) 753 + attr.addr = (u64)&value; 754 + 755 + rc = ioctl(cd.fd, KVM_HAS_DEVICE_ATTR, &attr); 756 + EXPECT_EQ(uc_flic_attr_tests[i].hasrc, !!rc) 757 + TH_LOG("expected dev attr missing %s", 758 + uc_flic_attr_tests[i].name); 759 + 760 + rc = ioctl(cd.fd, KVM_GET_DEVICE_ATTR, &attr); 761 + EXPECT_EQ(!!uc_flic_attr_tests[i].geterrno, !!rc) 762 + TH_LOG("get dev attr rc not expected on %s %s (%i)", 763 + uc_flic_attr_tests[i].name, 764 + strerror(errno), errno); 765 + if (uc_flic_attr_tests[i].geterrno) 766 + EXPECT_EQ(uc_flic_attr_tests[i].geterrno, errno) 767 + TH_LOG("get dev attr errno not expected on %s %s (%i)", 768 + uc_flic_attr_tests[i].name, 769 + strerror(errno), errno); 770 + 771 + rc = ioctl(cd.fd, KVM_SET_DEVICE_ATTR, &attr); 772 + EXPECT_EQ(!!uc_flic_attr_tests[i].seterrno, !!rc) 773 + TH_LOG("set sev attr rc not expected on %s %s (%i)", 774 + uc_flic_attr_tests[i].name, 775 + strerror(errno), errno); 776 + if (uc_flic_attr_tests[i].seterrno) 777 + EXPECT_EQ(uc_flic_attr_tests[i].seterrno, errno) 778 + TH_LOG("set dev attr errno not expected on %s %s (%i)", 779 + uc_flic_attr_tests[i].name, 780 + strerror(errno), errno); 781 + } 782 + 783 + close(cd.fd); 784 + } 785 + 786 + TEST_F(uc_kvm, uc_set_gsi_routing) 787 + { 788 + struct kvm_irq_routing *routing = kvm_gsi_routing_create(); 789 + struct kvm_irq_routing_entry ue = { 790 + .type = KVM_IRQ_ROUTING_S390_ADAPTER, 791 + .gsi = 1, 792 + .u.adapter = (struct kvm_irq_routing_s390_adapter) { 793 + .ind_addr = 0, 794 + }, 795 + }; 796 + int rc; 797 + 798 + routing->entries[0] = ue; 799 + routing->nr = 1; 800 + rc = ioctl(self->vm_fd, KVM_SET_GSI_ROUTING, routing); 801 + ASSERT_EQ(-1, rc) TH_LOG("err %s (%i)", strerror(errno), errno); 802 + ASSERT_EQ(EINVAL, errno) TH_LOG("err %s (%i)", strerror(errno), errno); 639 803 } 640 804 641 805 TEST_HARNESS_MAIN