[PATCH][RFC] bios: mtrr: check MTRR default memory type

Colin Ian King colin.king at canonical.com
Fri Jul 15 07:45:20 UTC 2016


On 15/07/16 08:02, Alex Hung wrote:
> IA32_MTRR_DEF_TYPE MSR specifies default properties of memory ranges
> and it is checked by kernel during MTRR initialization. The result
> of kernel message is used as default value when checking MTRR setup.
> 
> Signed-off-by: Alex Hung <alex.hung at canonical.com>
> ---
>  src/bios/mtrr/mtrr.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/src/bios/mtrr/mtrr.c b/src/bios/mtrr/mtrr.c
> index 18e1a29..f685c1c 100644
> --- a/src/bios/mtrr/mtrr.c
> +++ b/src/bios/mtrr/mtrr.c
> @@ -49,6 +49,8 @@ static fwts_cpuinfo_x86 *fwts_cpuinfo;
>  #define DISABLED	0x0040
>  #define UNKNOWN		0x0080
>  
> +uint8_t mtrr_default = UNCACHED;
> +
>  struct mtrr_entry {
>  	uint8_t  reg;
>  	uint64_t start;
> @@ -198,6 +200,12 @@ restart:
>  	/* if there is no full coverage it's also uncached */
>  	if (start != end)
>  		type |= DEFAULT;
> +
> +	if ((type & DEFAULT) && mtrr_default != UNCACHED) {
> +		type &= ~DEFAULT;
> +		type |= mtrr_default;
> +	}
> +
>  	return type;
>  }
>  
> @@ -442,8 +450,33 @@ static void do_mtrr_resource(fwts_framework *fw)
>  	fwts_log_nl(fw);
>  }
>  
> +static void check_mtrr_default(fwts_framework *fw,
> +	char *line, int repeated, char *prevline, void *private, int *errors)
> +{
> +	FWTS_UNUSED(fw);
> +	FWTS_UNUSED(repeated);
> +	FWTS_UNUSED(prevline);
> +	FWTS_UNUSED(private);
> +	FWTS_UNUSED(errors);
> +
> +	if (strstr(line, "MTRR default type:")) {
> +		if (strstr(line, "write-back"))
> +			mtrr_default = WRITE_BACK;
> +		else if (strstr(line, "uncachable"))
> +			mtrr_default = UNCACHED;
> +		else if (strstr(line, "write-through"))
> +			mtrr_default = WRITE_THROUGH;
> +		else if (strstr(line, "write-combining"))
> +			mtrr_default = WRITE_COMBINING;
> +		else if (strstr(line, "write-protect"))
> +			mtrr_default = WRITE_PROTECT;
> +	}
> +}
> +
>  static int mtrr_init(fwts_framework *fw)
>  {
> +	int errors = 0;
> +
>  	if (get_mtrrs() != FWTS_OK) {
>  		fwts_log_error(fw, "Failed to read /proc/mtrr.");
>  		return FWTS_ERROR;
> @@ -464,6 +497,8 @@ static int mtrr_init(fwts_framework *fw)
>  
>  	do_mtrr_resource(fw);
>  
> +	fwts_klog_scan(fw, klog, check_mtrr_default, NULL, NULL, &errors);
> +
>  	return FWTS_OK;
>  }
>  
> 
We need to bullet-proof this code by sanity checking the times when the
kernel log does not have this message, e.g. the message may change in
the future and/or the message has rolled out of the klog buffer.

So if the message has not been found we need some way of either
informing the user in the test output.

Alternatively, if this test is being run as root we can probably read
the MSR using fwts_cpu_readmsr() which is probably easier ;-)

Colin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ubuntu.com/archives/fwts-devel/attachments/20160715/c42ae408/attachment-0001.pgp>


More information about the fwts-devel mailing list