From patchwork Sun May 31 09:48:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 6515601 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9D703C0020 for ; Sun, 31 May 2015 09:48:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 08FB7206EC for ; Sun, 31 May 2015 09:48:23 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AE082205EA for ; Sun, 31 May 2015 09:48:12 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9963A18261C; Sun, 31 May 2015 02:48:12 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:120:8448::d00d]) by ml01.01.org (Postfix) with ESMTP id 0878118260F for ; Sun, 31 May 2015 02:48:11 -0700 (PDT) X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alien8.de; s=alien8; t=1433065690; bh=cm9/5pAgU6yaP5iKwHQ5nmb5w7gCK27DkeqKv/9i2uI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=D3zl +F9XEad62en7ouysFofNWFK4JFnU+sTx9Uv6HCNd3hcOEtSlyETn0dvTU+UCYyryWjC PQV4KZhovBxLcFi3HciKvlFxeFq7l8Og5v7nQyEu4a2ek+RQYpd988vma3Q+kmZsKUq kFlG1g/7ovMF9CM8mcEtX9j6JHAnOBw9I= Received: from mail.skyhub.de ([127.0.0.1]) by localhost (door.skyhub.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id RiHPWtnru5O9; Sun, 31 May 2015 11:48:09 +0200 (CEST) Received: from pd.tnic (p54AF42F0.dip0.t-ipconnect.de [84.175.66.240]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 0AEF01DA23A; Sun, 31 May 2015 11:48:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alien8.de; s=alien8; t=1433065689; bh=cm9/5pAgU6yaP5iKwHQ5nmb5w7gCK27DkeqKv/9i2uI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=T9sS F2/wTLd7Jj/4EV5GiuYPI5Qn46jqqUtotFn+8MTA60f+RbBAvQSzY3j1CT6R9JOQ2Zu rTHYB9fhBkNoxuvvvajAlJYQ3GPE7FGf6P1lihKZkNi6SgyTE8NFBpf8ramfSNlUexa eCcsDQf4/lXi1kK18tshS8d/F3vszsBaY= Received: by pd.tnic (Postfix, from userid 1000) id D5E5116035B; Sun, 31 May 2015 11:48:06 +0200 (CEST) From: Borislav Petkov To: LKML Subject: [PATCH 1/4] x86/pat: Untangle pat_init() Date: Sun, 31 May 2015 11:48:03 +0200 Message-Id: <1433065686-20922-1-git-send-email-bp@alien8.de> X-Mailer: git-send-email 2.3.5 In-Reply-To: <20150531094655.GA20440@pd.tnic> References: <20150531094655.GA20440@pd.tnic> Cc: jgross@suse.com, x86-ml , arnd@arndb.de, konrad.wilk@oracle.com, "Luis R. Rodriguez" , linux-nvdimm@lists.01.org, stefan.bader@canonical.com, Andy Lutomirski , linux-mm , Ingo Molnar , Thomas Gleixner , hmh@hmh.eng.br, "H. Peter Anvin" , Andrew Morton , hch@lst.de X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Borislav Petkov Split it into a BSP and AP version which makes the PAT initialization path actually readable again. Signed-off-by: Borislav Petkov Cc: Andrew Morton Cc: Andy Lutomirski Cc: arnd@arndb.de Cc: Elliott@hp.com Cc: hch@lst.de Cc: hmh@hmh.eng.br Cc: H. Peter Anvin Cc: Ingo Molnar Cc: jgross@suse.com Cc: konrad.wilk@oracle.com Cc: linux-mm Cc: linux-nvdimm@lists.01.org Cc: Luis R. Rodriguez Cc: stefan.bader@canonical.com Cc: Thomas Gleixner Cc: Toshi Kani Cc: x86-ml Cc: yigal@plexistor.com Reviewed-by: Toshi Kani --- arch/x86/mm/pat.c | 69 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c index a1c96544099d..476d0780560f 100644 --- a/arch/x86/mm/pat.c +++ b/arch/x86/mm/pat.c @@ -36,6 +36,8 @@ #undef pr_fmt #define pr_fmt(fmt) "" fmt +static bool boot_cpu_done; + static int __read_mostly __pat_enabled = IS_ENABLED(CONFIG_X86_PAT); static inline void pat_disable(const char *reason) @@ -194,31 +196,47 @@ void pat_init_cache_modes(void) #define PAT(x, y) ((u64)PAT_ ## y << ((x)*8)) -void pat_init(void) +static void pat_bsp_init(u64 pat) { - u64 pat; - bool boot_cpu = !boot_pat_state; + if (!cpu_has_pat) { + pat_disable("PAT not supported by CPU."); + return; + } - if (!pat_enabled()) + rdmsrl(MSR_IA32_CR_PAT, boot_pat_state); + if (!boot_pat_state) { + pat_disable("PAT MSR is 0, disabled."); return; + } + wrmsrl(MSR_IA32_CR_PAT, pat); + + pat_init_cache_modes(); +} + +static void pat_ap_init(u64 pat) +{ if (!cpu_has_pat) { - if (!boot_pat_state) { - pat_disable("PAT not supported by CPU."); - return; - } else { - /* - * If this happens we are on a secondary CPU, but - * switched to PAT on the boot CPU. We have no way to - * undo PAT. - */ - pr_err("x86/PAT: PAT enabled, but not supported by secondary CPU\n"); - BUG(); - } + /* + * If this happens we are on a secondary CPU, but switched to + * PAT on the boot CPU. We have no way to undo PAT. + */ + panic("x86/PAT: PAT enabled, but not supported by secondary CPU\n"); } - /* Set PWT to Write-Combining. All other bits stay the same */ + wrmsrl(MSR_IA32_CR_PAT, pat); +} + +void pat_init(void) +{ + u64 pat; + + if (!pat_enabled()) + return; + /* + * Set PWT to Write-Combining. All other bits stay the same: + * * PTE encoding used in Linux: * PAT * |PCD @@ -233,19 +251,12 @@ void pat_init(void) pat = PAT(0, WB) | PAT(1, WC) | PAT(2, UC_MINUS) | PAT(3, UC) | PAT(4, WB) | PAT(5, WC) | PAT(6, UC_MINUS) | PAT(7, UC); - /* Boot CPU check */ - if (!boot_pat_state) { - rdmsrl(MSR_IA32_CR_PAT, boot_pat_state); - if (!boot_pat_state) { - pat_disable("PAT read returns always zero, disabled."); - return; - } + if (!boot_cpu_done) { + pat_bsp_init(pat); + boot_cpu_done = true; + } else { + pat_ap_init(pat); } - - wrmsrl(MSR_IA32_CR_PAT, pat); - - if (boot_cpu) - pat_init_cache_modes(); } #undef PAT