Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756401AbcCVQ5j (ORCPT ); Tue, 22 Mar 2016 12:57:39 -0400 Received: from mx2.suse.de ([195.135.220.15]:58791 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751242AbcCVQ5b (ORCPT ); Tue, 22 Mar 2016 12:57:31 -0400 Date: Tue, 22 Mar 2016 17:57:26 +0100 From: Borislav Petkov To: Toshi Kani Cc: mingo@kernel.org, hpa@zytor.com, tglx@linutronix.de, mcgrof@suse.com, jgross@suse.com, paul.gortmaker@windriver.com, konrad.wilk@oracle.com, elliott@hpe.com, x86@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/6] x86/mm/pat: Change PAT to support non-default PAT MSR Message-ID: <20160322165725.GB5656@pd.tnic> References: <1458175502-31936-1-git-send-email-toshi.kani@hpe.com> <1458175502-31936-2-git-send-email-toshi.kani@hpe.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1458175502-31936-2-git-send-email-toshi.kani@hpe.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3307 Lines: 104 $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 > Cc: Borislav Petkov > Cc: Luis R. Rodriguez > Cc: Juergen Gross > Cc: Ingo Molnar > Cc: H. Peter Anvin > Cc: Thomas Gleixner > --- > 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) --