lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 22 Mar 2016 17:57:26 +0100
From:	Borislav Petkov <bp@...e.de>
To:	Toshi Kani <toshi.kani@....com>
Cc:	mingo@...nel.org, hpa@...or.com, tglx@...utronix.de,
	mcgrof@...e.com, jgross@...e.com, paul.gortmaker@...driver.com,
	konrad.wilk@...cle.com, elliott@....com, x86@...nel.org,
	xen-devel@...ts.xenproject.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/6] x86/mm/pat: Change PAT to support non-default PAT
 MSR

$Subject is misleading - there's no non-default PAT MSR - the setting is
non-default.

On Wed, Mar 16, 2016 at 06:44:57PM -0600, Toshi Kani wrote:
> In preparation to fix a regression caused by 'commit 9cd25aac1f44
> ("x86/mm/pat: Emulate PAT when it is disabled")', PAT needs to
> support a case that PAT MSR is initialized with a non-default
> value.
> 
> When pat_init() is called in PAT disable state, it initializes

		  is called and PAT is disabled

> PAT table with the BIOS default value. Xen, however, sets PAT MSR
> with a non-default value to enable WC. This causes inconsistency
> between PAT table and PAT MSR when PAT is set to disable on Xen.
> 
> Change pat_init() to handle the PAT disable cases properly.  Add
> pat_keep_handoff_state() to handle two cases when PAT is set to
> disable.
>  1. CPU supports PAT: Set PAT table to be consistent with PAT MSR.
>  2. CPU does not support PAT: Set PAT table to be consistent with
>     PWT and PCD bits in a PTE.
> 
> Signed-off-by: Toshi Kani <toshi.kani@....com>
> Cc: Borislav Petkov <bp@...e.de>
> Cc: Luis R. Rodriguez <mcgrof@...e.com>
> Cc: Juergen Gross <jgross@...e.com>
> Cc: Ingo Molnar <mingo@...nel.org>
> Cc: H. Peter Anvin <hpa@...or.com>
> Cc: Thomas Gleixner <tglx@...utronix.de>
> ---
>  arch/x86/mm/pat.c |   80 +++++++++++++++++++++++++++++++++++++++++------------
>  1 file changed, 62 insertions(+), 18 deletions(-)
> 
> diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
> index 04e2e71..e0a34b0 100644
> --- a/arch/x86/mm/pat.c
> +++ b/arch/x86/mm/pat.c
> @@ -207,9 +207,6 @@ static void pat_bsp_init(u64 pat)
>  		return;
>  	}
>  
> -	if (!pat_enabled())
> -		goto done;
> -
>  	rdmsrl(MSR_IA32_CR_PAT, tmp_pat);
>  	if (!tmp_pat) {
>  		pat_disable("PAT MSR is 0, disabled.");
> @@ -218,15 +215,11 @@ static void pat_bsp_init(u64 pat)
>  
>  	wrmsrl(MSR_IA32_CR_PAT, pat);
>  
> -done:
>  	pat_init_cache_modes(pat);
>  }
>  
>  static void pat_ap_init(u64 pat)
>  {
> -	if (!pat_enabled())
> -		return;
> -
>  	if (!cpu_has_pat) {
>  		/*
>  		 * If this happens we are on a secondary CPU, but switched to
> @@ -238,18 +231,43 @@ static void pat_ap_init(u64 pat)
>  	wrmsrl(MSR_IA32_CR_PAT, pat);
>  }
>  
> -void pat_init(void)
> +/**
> + * pat_keep_handoff_state - Set PAT table to the handoff state
> + *
> + * This function keeps PAT in the BIOS handoff state. When CPU supports
> + * PAT, it sets PAT table to be consistent with PAT MSR. When CPU does not
> + * support PAT, it emulates PAT by setting PAT table consistent with PWT
> + * and PCD bits in a PTE.
> + *
> + * The PAT table is global to all CPUs, which is initialized once at
> + * boot-time. Any subsequent calls to this function have no effect.
> + */
> +static void pat_keep_handoff_state(void)

Static function, no need for "pat_" prefix. Also, no need for the
kernel-doc comment.

Also, no need for all that handoff nomenclature etc, just call it
setup_pat(). Because it does exactly that - it sets up the PAT bits
unconditionally, regardless of enabled or not.

>  {
> -	u64 pat;
> -	struct cpuinfo_x86 *c = &boot_cpu_data;
> +	u64 pat = 0;
> +	static int set_handoff_done;

s/set_handoff_done/pat_setup_done/

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ