Commit a4316603 authored by Juergen Gross's avatar Juergen Gross Committed by Borislav Petkov (AMD)

x86/mtrr: Add mtrr=debug command line option

Add a new command line option "mtrr=debug" for getting debug output
after building the new cache mode map. The output will include MTRR
register values and the resulting map.
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Tested-by: default avatarMichael Kelley <mikelley@microsoft.com>
Link: https://lore.kernel.org/r/20230502120931.20719-13-jgross@suse.comSigned-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
parent 061b984a
...@@ -3423,6 +3423,10 @@ ...@@ -3423,6 +3423,10 @@
[HW] Make the MicroTouch USB driver use raw coordinates [HW] Make the MicroTouch USB driver use raw coordinates
('y', default) or cooked coordinates ('n') ('y', default) or cooked coordinates ('n')
mtrr=debug [X86]
Enable printing debug information related to MTRR
registers at boot time.
mtrr_chunk_size=nn[KMG] [X86] mtrr_chunk_size=nn[KMG] [X86]
used for mtrr cleanup. It is largest continuous chunk used for mtrr cleanup. It is largest continuous chunk
that could hold holes aka. UC entries. that could hold holes aka. UC entries.
......
...@@ -41,6 +41,23 @@ struct cache_map { ...@@ -41,6 +41,23 @@ struct cache_map {
u64 fixed:1; u64 fixed:1;
}; };
static bool mtrr_debug;
static int __init mtrr_param_setup(char *str)
{
int rc = 0;
if (!str)
return -EINVAL;
if (!strcmp(str, "debug"))
mtrr_debug = true;
else
rc = -EINVAL;
return rc;
}
early_param("mtrr", mtrr_param_setup);
/* /*
* CACHE_MAP_MAX is the maximum number of memory ranges in cache_map, where * CACHE_MAP_MAX is the maximum number of memory ranges in cache_map, where
* no 2 adjacent ranges have the same cache mode (those would be merged). * no 2 adjacent ranges have the same cache mode (those would be merged).
...@@ -515,6 +532,14 @@ void __init mtrr_build_map(void) ...@@ -515,6 +532,14 @@ void __init mtrr_build_map(void)
pr_info("MTRR map: %u entries (%u fixed + %u variable; max %u), built from %u variable MTRRs\n", pr_info("MTRR map: %u entries (%u fixed + %u variable; max %u), built from %u variable MTRRs\n",
cache_map_n, cache_map_fixed, cache_map_n - cache_map_fixed, cache_map_n, cache_map_fixed, cache_map_n - cache_map_fixed,
get_cache_map_size(), num_var_ranges + (mtrr_tom2 != 0)); get_cache_map_size(), num_var_ranges + (mtrr_tom2 != 0));
if (mtrr_debug) {
for (i = 0; i < cache_map_n; i++) {
pr_info("%3u: %016llx-%016llx %s\n", i,
cache_map[i].start, cache_map[i].end - 1,
mtrr_attrib_to_str(cache_map[i].type));
}
}
} }
/* Copy the cache_map from __initdata memory to dynamically allocated one. */ /* Copy the cache_map from __initdata memory to dynamically allocated one. */
...@@ -721,8 +746,8 @@ static void __init print_fixed_last(void) ...@@ -721,8 +746,8 @@ static void __init print_fixed_last(void)
if (!last_fixed_end) if (!last_fixed_end)
return; return;
pr_debug(" %05X-%05X %s\n", last_fixed_start, pr_info(" %05X-%05X %s\n", last_fixed_start,
last_fixed_end - 1, mtrr_attrib_to_str(last_fixed_type)); last_fixed_end - 1, mtrr_attrib_to_str(last_fixed_type));
last_fixed_end = 0; last_fixed_end = 0;
} }
...@@ -760,10 +785,10 @@ static void __init print_mtrr_state(void) ...@@ -760,10 +785,10 @@ static void __init print_mtrr_state(void)
unsigned int i; unsigned int i;
int high_width; int high_width;
pr_debug("MTRR default type: %s\n", pr_info("MTRR default type: %s\n",
mtrr_attrib_to_str(mtrr_state.def_type)); mtrr_attrib_to_str(mtrr_state.def_type));
if (mtrr_state.have_fixed) { if (mtrr_state.have_fixed) {
pr_debug("MTRR fixed ranges %sabled:\n", pr_info("MTRR fixed ranges %sabled:\n",
((mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED) && ((mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED) &&
(mtrr_state.enabled & MTRR_STATE_MTRR_FIXED_ENABLED)) ? (mtrr_state.enabled & MTRR_STATE_MTRR_FIXED_ENABLED)) ?
"en" : "dis"); "en" : "dis");
...@@ -778,27 +803,27 @@ static void __init print_mtrr_state(void) ...@@ -778,27 +803,27 @@ static void __init print_mtrr_state(void)
/* tail */ /* tail */
print_fixed_last(); print_fixed_last();
} }
pr_debug("MTRR variable ranges %sabled:\n", pr_info("MTRR variable ranges %sabled:\n",
mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED ? "en" : "dis"); mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED ? "en" : "dis");
high_width = (boot_cpu_data.x86_phys_bits - (32 - PAGE_SHIFT) + 3) / 4; high_width = (boot_cpu_data.x86_phys_bits - (32 - PAGE_SHIFT) + 3) / 4;
for (i = 0; i < num_var_ranges; ++i) { for (i = 0; i < num_var_ranges; ++i) {
if (mtrr_state.var_ranges[i].mask_lo & MTRR_PHYSMASK_V) if (mtrr_state.var_ranges[i].mask_lo & MTRR_PHYSMASK_V)
pr_debug(" %u base %0*X%05X000 mask %0*X%05X000 %s\n", pr_info(" %u base %0*X%05X000 mask %0*X%05X000 %s\n",
i, i,
high_width, high_width,
mtrr_state.var_ranges[i].base_hi, mtrr_state.var_ranges[i].base_hi,
mtrr_state.var_ranges[i].base_lo >> 12, mtrr_state.var_ranges[i].base_lo >> 12,
high_width, high_width,
mtrr_state.var_ranges[i].mask_hi, mtrr_state.var_ranges[i].mask_hi,
mtrr_state.var_ranges[i].mask_lo >> 12, mtrr_state.var_ranges[i].mask_lo >> 12,
mtrr_attrib_to_str(mtrr_state.var_ranges[i].base_lo & mtrr_attrib_to_str(mtrr_state.var_ranges[i].base_lo &
MTRR_PHYSBASE_TYPE)); MTRR_PHYSBASE_TYPE));
else else
pr_debug(" %u disabled\n", i); pr_info(" %u disabled\n", i);
} }
if (mtrr_tom2) if (mtrr_tom2)
pr_debug("TOM2: %016llx aka %lldM\n", mtrr_tom2, mtrr_tom2>>20); pr_info("TOM2: %016llx aka %lldM\n", mtrr_tom2, mtrr_tom2>>20);
} }
/* Grab all of the MTRR state for this CPU into *state */ /* Grab all of the MTRR state for this CPU into *state */
...@@ -833,7 +858,8 @@ bool __init get_mtrr_state(void) ...@@ -833,7 +858,8 @@ bool __init get_mtrr_state(void)
mtrr_tom2 &= 0xffffff800000ULL; mtrr_tom2 &= 0xffffff800000ULL;
} }
print_mtrr_state(); if (mtrr_debug)
print_mtrr_state();
mtrr_state_set = 1; mtrr_state_set = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment