[coreboot-gerrit] Patch set updated for coreboot: cpu/x86/mtrr: correct variable MTRR calculation around 1MiB boundary

Aaron Durbin (adurbin@chromium.org) gerrit at coreboot.org
Thu Jul 21 21:39:50 CEST 2016


Aaron Durbin (adurbin at chromium.org) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/15780

-gerrit

commit 2f278dc63de7b5f72e4125845ed271be6edf8bf8
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Thu Jul 21 14:26:34 2016 -0500

    cpu/x86/mtrr: correct variable MTRR calculation around 1MiB boundary
    
    The fixed MTRs cover the range [0:1MiB). While calculating the
    variable MTRR usage the 1MiB boundary is checked such that
    an excessive number of MTRRs aren't used because of unnatural
    alignment at the low end of the physical address space. Howevever,
    those checks weren't inclusive of the 1MiB boundary. As such a
    variable MTRR could be used for a range which is actually covered
    by the fixed MTRRs when the end address is equal to 1MiB. Likewise,
    if the starting address of the range lands on the 1MiB boundary
    then more variable MTRRs are calculated in order to meet natural
    alignment requirements.
    
    Before:
    MTRR: Physical address space:
    0x0000000000000000 - 0x00000000000a0000 size 0x000a0000 type 6
    0x00000000000a0000 - 0x0000000000100000 size 0x00060000 type 0
    0x0000000000100000 - 0x000000007b800000 size 0x7b700000 type 6
    0x000000007b800000 - 0x00000000b0000000 size 0x34800000 type 0
    0x00000000b0000000 - 0x00000000c0000000 size 0x10000000 type 1
    0x00000000c0000000 - 0x0000000100000000 size 0x40000000 type 0
    0x0000000100000000 - 0x0000000180000000 size 0x80000000 type 6
    CPU physical address size: 39 bits
    MTRR: default type WB/UC MTRR counts: 7/17.
    MTRR: WB selected as default type.
    MTRR: 0 base 0x0000000000000000 mask 0x0000007ffff00000 type 0
    MTRR: 1 base 0x000000007b800000 mask 0x0000007fff800000 type 0
    MTRR: 2 base 0x000000007c000000 mask 0x0000007ffc000000 type 0
    MTRR: 3 base 0x0000000080000000 mask 0x0000007fe0000000 type 0
    MTRR: 4 base 0x00000000a0000000 mask 0x0000007ff0000000 type 0
    MTRR: 5 base 0x00000000b0000000 mask 0x0000007ff0000000 type 1
    MTRR: 6 base 0x00000000c0000000 mask 0x0000007fc0000000 type 0
    
    After:
    MTRR: Physical address space:
    0x0000000000000000 - 0x00000000000a0000 size 0x000a0000 type 6
    0x00000000000a0000 - 0x0000000000100000 size 0x00060000 type 0
    0x0000000000100000 - 0x000000007b800000 size 0x7b700000 type 6
    0x000000007b800000 - 0x00000000b0000000 size 0x34800000 type 0
    0x00000000b0000000 - 0x00000000c0000000 size 0x10000000 type 1
    0x00000000c0000000 - 0x0000000100000000 size 0x40000000 type 0
    0x0000000100000000 - 0x0000000180000000 size 0x80000000 type 6
    CPU physical address size: 39 bits
    MTRR: default type WB/UC MTRR counts: 6/8.
    MTRR: WB selected as default type.
    MTRR: 0 base 0x000000007b800000 mask 0x0000007fff800000 type 0
    MTRR: 1 base 0x000000007c000000 mask 0x0000007ffc000000 type 0
    MTRR: 2 base 0x0000000080000000 mask 0x0000007fe0000000 type 0
    MTRR: 3 base 0x00000000a0000000 mask 0x0000007ff0000000 type 0
    MTRR: 4 base 0x00000000b0000000 mask 0x0000007ff0000000 type 1
    MTRR: 5 base 0x00000000c0000000 mask 0x0000007fc0000000 type 0
    
    BUG=chrome-os-partner:55504
    
    Change-Id: I7feab38dfe135f5e596c9e67520378a406aa6866
    Signed-off-by: Aaron Durbin <adurbin at chromium.org>
---
 src/cpu/x86/mtrr/mtrr.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/cpu/x86/mtrr/mtrr.c b/src/cpu/x86/mtrr/mtrr.c
index 794df99..8bdc511 100644
--- a/src/cpu/x86/mtrr/mtrr.c
+++ b/src/cpu/x86/mtrr/mtrr.c
@@ -505,15 +505,15 @@ static void calc_var_mtrrs_with_hole(struct var_mtrr_state *var_state,
 	a1 = range_entry_base_mtrr_addr(r);
 	a2 = range_entry_end_mtrr_addr(r);
 
-	/* The end address is under 1MiB. The fixed MTRRs take
+	/* The end address is within the first 1MiB. The fixed MTRRs take
 	 * precedence over the variable ones. Therefore this range
 	 * can be ignored. */
-	if (a2 < RANGE_1MB)
+	if (a2 <= RANGE_1MB)
 		return;
 
 	/* Again, the fixed MTRRs take precedence so the beginning
-	 * of the range can be set to 0 if it starts below 1MiB. */
-	if (a1 < RANGE_1MB)
+	 * of the range can be set to 0 if it starts at or below 1MiB. */
+	if (a1 <= RANGE_1MB)
 		a1 = 0;
 
 	/* If the range starts above 4GiB the processing is done. */
@@ -585,15 +585,15 @@ static void calc_var_mtrrs_without_hole(struct var_mtrr_state *var_state,
 	a1 = range_entry_base_mtrr_addr(r);
 	c2 = range_entry_end_mtrr_addr(r);
 
-	/* The end address is under 1MiB. The fixed MTRRs take
+	/* The end address is within the first 1MiB. The fixed MTRRs take
 	 * precedence over the variable ones. Therefore this range
 	 * can be ignored. */
-	if (c2 < RANGE_1MB)
+	if (c2 <= RANGE_1MB)
 		return;
 
 	/* Again, the fixed MTRRs take precedence so the beginning
-	 * of the range can be set to 0 if it starts below 1MiB. */
-	if (a1 < RANGE_1MB)
+	 * of the range can be set to 0 if it starts at or below 1MiB. */
+	if (a1 <= RANGE_1MB)
 		a1 = 0;
 
 	/* If the range starts above 4GiB the processing is done. */



More information about the coreboot-gerrit mailing list