From patchwork Sun Aug 14 20:37:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 9280069 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E4B9160231 for ; Sun, 14 Aug 2016 20:46:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D641A289A7 for ; Sun, 14 Aug 2016 20:46:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA3D328A1A; Sun, 14 Aug 2016 20:46:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 87EB2289A7 for ; Sun, 14 Aug 2016 20:46:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZ2GR-0008L5-N8; Sun, 14 Aug 2016 20:44:11 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZ2GQ-0008Kt-MK for xen-devel@lists.xenproject.org; Sun, 14 Aug 2016 20:44:10 +0000 Received: from [85.158.137.68] by server-2.bemta-3.messagelabs.com id 09/32-01945-918D0B75; Sun, 14 Aug 2016 20:44:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmkeJIrShJLcpLzFFi42LpubySR1fyxoZ wg7nnBCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxt2xqYC65IVvS1L2dvYOwW62Lk4hAS2MYo MXv3H6YuRg4ONgFTiRn/VboYOTlEBBQkNvc+YwWpYRZ4yirxZ8ImJpCEsECARMekfjYQm0VAV eJ4z1dGEJtXwEpixuuDYHEJATmJS9u+MIPYnALWEjPvtYL1CgHVXD3cBxYXFRCT2Ny2ixWiV1 Di5MwnLCA3MAuoS6yfJzSBkXcWkswshMwCRqZVjOrFqUVlqUW6FnpJRZnpGSW5iZk5uoYGxnq 5qcXFiempOYlJxXrJ+bmbGIGBwwAEOxgvtDsfYpTkYFIS5dUxXxcuxJeUn1KZkVicEV9UmpNa fIhRhoNDSYL31LUN4UKCRanpqRVpmTnAEIZJS3DwKInwPgdJ8xYXJOYWZ6ZDpE4xKkqJ8z4CS QiAJDJK8+DaYHFziVFWSpiXEegQIZ6C1KLczBJU+VeM4hyMSsK820Gm8GTmlcBNfwW0mAlosb 402OKSRISUVAOjrOsRh4LKmyJLt1iseO925oLqu/xlTza67fCK6VDc5dYTtsGBZe0fSzlmhUn BM2fcmCG/fsOMkiV9KQZPPevitnvX5+Q7nOQzN1389+WD6dtadctOi3i6Hl79NCw+dOf5u45v Go1yvVL+tn2Xml2lGDvrwAlxPctza7qYH6YuYlfpW60UcTxfiaU4I9FQi7moOBEAftF4vZYCA AA= X-Env-Sender: gregkh@linuxfoundation.org X-Msg-Ref: server-13.tower-31.messagelabs.com!1471207447!54930955!1 X-Originating-IP: [140.211.169.12] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 41596 invoked from network); 14 Aug 2016 20:44:08 -0000 Received: from mail.linuxfoundation.org (HELO mail.linuxfoundation.org) (140.211.169.12) by server-13.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 14 Aug 2016 20:44:08 -0000 Received: from localhost (pes75-3-78-192-101-3.fbxo.proxad.net [78.192.101.3]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1166A26C; Sun, 14 Aug 2016 20:44:06 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Date: Sun, 14 Aug 2016 22:37:31 +0200 Message-Id: <20160814202506.044190475@linuxfoundation.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160814202504.908694181@linuxfoundation.org> References: <20160814202504.908694181@linuxfoundation.org> User-Agent: quilt/0.64 MIME-Version: 1.0 Cc: Juergen Gross , Denys Vlasenko , xen-devel@lists.xenproject.org, Toshi Kani , Peter Zijlstra , Greg Kroah-Hartman , "Luis R. Rodriguez" , "H. Peter Anvin" , stable@vger.kernel.org, Andy Lutomirski , paul.gortmaker@windriver.com, Ingo Molnar , Borislav Petkov , Brian Gerst , Toshi Kani , Andrew Morton , Borislav Petkov , Linus Torvalds , Thomas Gleixner , elliott@hpe.com Subject: [Xen-devel] [PATCH 4.6 27/56] x86/mtrr: Fix PAT init handling when MTRR is disabled X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 4.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Toshi Kani commit ad025a73f0e9344ac73ffe1b74c184033e08e7d5 upstream. get_mtrr_state() calls pat_init() on BSP even if MTRR is disabled. This results in calling pat_init() on BSP only since APs do not call pat_init() when MTRR is disabled. This inconsistency between BSP and APs leads to undefined behavior. Make BSP's calling condition to pat_init() consistent with AP's, mtrr_ap_init() and mtrr_aps_init(). Signed-off-by: Toshi Kani Reviewed-by: Thomas Gleixner Cc: Andrew Morton Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Juergen Gross Cc: Linus Torvalds Cc: Luis R. Rodriguez Cc: Peter Zijlstra Cc: Toshi Kani Cc: elliott@hpe.com Cc: konrad.wilk@oracle.com Cc: paul.gortmaker@windriver.com Cc: xen-devel@lists.xenproject.org Link: http://lkml.kernel.org/r/1458769323-24491-6-git-send-email-toshi.kani@hpe.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/mtrr/generic.c | 24 ++++++++++++++---------- arch/x86/kernel/cpu/mtrr/main.c | 3 +++ arch/x86/kernel/cpu/mtrr/mtrr.h | 1 + 3 files changed, 18 insertions(+), 10 deletions(-) --- a/arch/x86/kernel/cpu/mtrr/generic.c +++ b/arch/x86/kernel/cpu/mtrr/generic.c @@ -444,11 +444,24 @@ static void __init print_mtrr_state(void pr_debug("TOM2: %016llx aka %lldM\n", mtrr_tom2, mtrr_tom2>>20); } +/* PAT setup for BP. We need to go through sync steps here */ +void __init mtrr_bp_pat_init(void) +{ + unsigned long flags; + + local_irq_save(flags); + prepare_set(); + + pat_init(); + + post_set(); + local_irq_restore(flags); +} + /* Grab all of the MTRR state for this CPU into *state */ bool __init get_mtrr_state(void) { struct mtrr_var_range *vrs; - unsigned long flags; unsigned lo, dummy; unsigned int i; @@ -481,15 +494,6 @@ bool __init get_mtrr_state(void) mtrr_state_set = 1; - /* PAT setup for BP. We need to go through sync steps here */ - local_irq_save(flags); - prepare_set(); - - pat_init(); - - post_set(); - local_irq_restore(flags); - return !!(mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED); } --- a/arch/x86/kernel/cpu/mtrr/main.c +++ b/arch/x86/kernel/cpu/mtrr/main.c @@ -752,6 +752,9 @@ void __init mtrr_bp_init(void) /* BIOS may override */ __mtrr_enabled = get_mtrr_state(); + if (mtrr_enabled()) + mtrr_bp_pat_init(); + if (mtrr_cleanup(phys_addr)) { changed_by_mtrr_cleanup = 1; mtrr_if->set_all(); --- a/arch/x86/kernel/cpu/mtrr/mtrr.h +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h @@ -52,6 +52,7 @@ void set_mtrr_prepare_save(struct set_mt void fill_mtrr_var_range(unsigned int index, u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi); bool get_mtrr_state(void); +void mtrr_bp_pat_init(void); extern void set_mtrr_ops(const struct mtrr_ops *ops);