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

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull KVM fixes from Paolo Bonzini:
"Everything related to the new quirks and memory type features:

- small improvements to the quirks API

- extending one of the quirks from just AMD to Intel as well, because
4.2 can show the same problem with problematic firmware on Intel
too"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm:
KVM: x86: rename quirk constants to KVM_X86_QUIRK_*
KVM: vmx: obey KVM_QUIRK_CD_NW_CLEARED
KVM: x86: introduce kvm_check_has_quirk
KVM: MTRR: simplify kvm_mtrr_get_guest_memory_type
KVM: MTRR: fix memory type handling if MTRR is completely disabled

+43 -15
+2 -2
arch/x86/include/uapi/asm/kvm.h
··· 354 354 struct kvm_sync_regs { 355 355 }; 356 356 357 - #define KVM_QUIRK_LINT0_REENABLED (1 << 0) 358 - #define KVM_QUIRK_CD_NW_CLEARED (1 << 1) 357 + #define KVM_X86_QUIRK_LINT0_REENABLED (1 << 0) 358 + #define KVM_X86_QUIRK_CD_NW_CLEARED (1 << 1) 359 359 360 360 #endif /* _ASM_X86_KVM_H */
+1 -1
arch/x86/kvm/lapic.c
··· 1595 1595 for (i = 0; i < APIC_LVT_NUM; i++) 1596 1596 apic_set_reg(apic, APIC_LVTT + 0x10 * i, APIC_LVT_MASKED); 1597 1597 apic_update_lvtt(apic); 1598 - if (!(vcpu->kvm->arch.disabled_quirks & KVM_QUIRK_LINT0_REENABLED)) 1598 + if (kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_LINT0_REENABLED)) 1599 1599 apic_set_reg(apic, APIC_LVT0, 1600 1600 SET_APIC_DELIVERY_MODE(0, APIC_MODE_EXTINT)); 1601 1601 apic_manage_nmi_watchdog(apic, kvm_apic_get_reg(apic, APIC_LVT0));
+30 -10
arch/x86/kvm/mtrr.c
··· 120 120 return mtrr_state->deftype & IA32_MTRR_DEF_TYPE_TYPE_MASK; 121 121 } 122 122 123 + static u8 mtrr_disabled_type(void) 124 + { 125 + /* 126 + * Intel SDM 11.11.2.2: all MTRRs are disabled when 127 + * IA32_MTRR_DEF_TYPE.E bit is cleared, and the UC 128 + * memory type is applied to all of physical memory. 129 + */ 130 + return MTRR_TYPE_UNCACHABLE; 131 + } 132 + 123 133 /* 124 134 * Three terms are used in the following code: 125 135 * - segment, it indicates the address segments covered by fixed MTRRs. ··· 444 434 445 435 /* output fields. */ 446 436 int mem_type; 437 + /* mtrr is completely disabled? */ 438 + bool mtrr_disabled; 447 439 /* [start, end) is not fully covered in MTRRs? */ 448 440 bool partial_map; 449 441 ··· 561 549 static void mtrr_lookup_start(struct mtrr_iter *iter) 562 550 { 563 551 if (!mtrr_is_enabled(iter->mtrr_state)) { 564 - iter->partial_map = true; 552 + iter->mtrr_disabled = true; 565 553 return; 566 554 } 567 555 ··· 575 563 iter->mtrr_state = mtrr_state; 576 564 iter->start = start; 577 565 iter->end = end; 566 + iter->mtrr_disabled = false; 578 567 iter->partial_map = false; 579 568 iter->fixed = false; 580 569 iter->range = NULL; ··· 669 656 return MTRR_TYPE_WRBACK; 670 657 } 671 658 672 - /* It is not covered by MTRRs. */ 673 - if (iter.partial_map) { 674 - /* 675 - * We just check one page, partially covered by MTRRs is 676 - * impossible. 677 - */ 678 - WARN_ON(type != -1); 679 - type = mtrr_default_type(mtrr_state); 680 - } 659 + if (iter.mtrr_disabled) 660 + return mtrr_disabled_type(); 661 + 662 + /* 663 + * We just check one page, partially covered by MTRRs is 664 + * impossible. 665 + */ 666 + WARN_ON(iter.partial_map); 667 + 668 + /* not contained in any MTRRs. */ 669 + if (type == -1) 670 + return mtrr_default_type(mtrr_state); 671 + 681 672 return type; 682 673 } 683 674 EXPORT_SYMBOL_GPL(kvm_mtrr_get_guest_memory_type); ··· 705 688 if (type != iter.mem_type) 706 689 return false; 707 690 } 691 + 692 + if (iter.mtrr_disabled) 693 + return true; 708 694 709 695 if (!iter.partial_map) 710 696 return true;
+1 -1
arch/x86/kvm/svm.c
··· 1672 1672 * does not do it - this results in some delay at 1673 1673 * reboot 1674 1674 */ 1675 - if (!(vcpu->kvm->arch.disabled_quirks & KVM_QUIRK_CD_NW_CLEARED)) 1675 + if (kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED)) 1676 1676 cr0 &= ~(X86_CR0_CD | X86_CR0_NW); 1677 1677 svm->vmcb->save.cr0 = cr0; 1678 1678 mark_dirty(svm->vmcb, VMCB_CR);
+4 -1
arch/x86/kvm/vmx.c
··· 8650 8650 8651 8651 if (kvm_read_cr0(vcpu) & X86_CR0_CD) { 8652 8652 ipat = VMX_EPT_IPAT_BIT; 8653 - cache = MTRR_TYPE_UNCACHABLE; 8653 + if (kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED)) 8654 + cache = MTRR_TYPE_WRBACK; 8655 + else 8656 + cache = MTRR_TYPE_UNCACHABLE; 8654 8657 goto exit; 8655 8658 } 8656 8659
+5
arch/x86/kvm/x86.h
··· 147 147 return kvm_register_write(vcpu, reg, val); 148 148 } 149 149 150 + static inline bool kvm_check_has_quirk(struct kvm *kvm, u64 quirk) 151 + { 152 + return !(kvm->arch.disabled_quirks & quirk); 153 + } 154 + 150 155 void kvm_before_handle_nmi(struct kvm_vcpu *vcpu); 151 156 void kvm_after_handle_nmi(struct kvm_vcpu *vcpu); 152 157 void kvm_set_pending_timer(struct kvm_vcpu *vcpu);