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

KVM: MTRR: fix memory type handling if MTRR is completely disabled

Currently code uses default memory type if MTRR is fully disabled,
fix it by using UC instead.

Signed-off-by: Xiao Guangrong <guangrong.xiao@intel.com>
Tested-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Xiao Guangrong and committed by
Paolo Bonzini
10dc331f c5dfd654

+20 -1
+20 -1
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 659 + if (iter.mtrr_disabled) 660 + return mtrr_disabled_type(); 661 + 672 662 /* It is not covered by MTRRs. */ 673 663 if (iter.partial_map) { 674 664 /* ··· 704 688 if (type != iter.mem_type) 705 689 return false; 706 690 } 691 + 692 + if (iter.mtrr_disabled) 693 + return true; 707 694 708 695 if (!iter.partial_map) 709 696 return true;