Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1677318imj; Fri, 8 Feb 2019 05:38:46 -0800 (PST) X-Google-Smtp-Source: AHgI3IYDdJ7I3Q4f8ViVJFGGGReQ8RYDLvKbdqj22F6LOf/rxQX9kL2Kmf0C0yL52nzdOxr2VtMD X-Received: by 2002:a62:6f88:: with SMTP id k130mr22060686pfc.234.1549633126265; Fri, 08 Feb 2019 05:38:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549633126; cv=none; d=google.com; s=arc-20160816; b=DGw6woA9MDgVzjNJutwTonKP8zKykBPCQd72tPjD0AkMBtq9V+M/tF+IiCGFKiQ/N+ 0zOLjnLRHqC1Agd05+VMOkqqsNMFABooU2pEY7+h1R27iOLniHRLSFnxMMnlJdxvi8In /pOkyS+DGspyAiDnxfswW9LV9ymj9nN9/bt5K1eTvb2y9/D+LIXL4zG2IyAWAIQa9opa J5Usue/DUcYDYJ/NPw8dG36AcF8XOdknLB00XyOkU79T/Fj58gZQ3M/ppaubG2LGrRSl QdVA2vPaFxrIVzQPw6qfLZAY9Rjy+iA1k7u6JM6xi/iMqhQn1rsOEvcM+C49227m27yq WOqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=mvQM4e9xsgtqidR959/xzD2Bp7PcC+cE6aWmWssx8xw=; b=IDj9cuKOzBJaWiU1VervbTJRVe0/U/Ep9loLWqe2TmZcZZ9u0WuI6ibcDsYPZN3/ZK NDSvLhFcLbSn0Za7BAke5xX2rIhdvr3BskbiG3ilsYEj/xK//ZbxfP+tkdBB3V9GrXqS uRFuuyE+dsRiBNEFbLL9GGBlNAnRwHAMlCQJhi1inEHh5R68jZjWyVT1+iyUaaoTbgY4 l/7Ic0eZlqQBV9Ze+cWozNqFMPvpxlXGYlO0lO72fVuM5Bn7AEgoA4Mpo8WJn9nKWM5m PMHEUaAR2x1Ado4qQkzjctOfBKnkGUPiXhkDXa9XhUNcU5gpLs/G7TZ2DyuEd49/8WId mHAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w23si2300439plq.198.2019.02.08.05.38.29; Fri, 08 Feb 2019 05:38:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726813AbfBHNhq (ORCPT + 99 others); Fri, 8 Feb 2019 08:37:46 -0500 Received: from terminus.zytor.com ([198.137.202.136]:49341 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726456AbfBHNhp (ORCPT ); Fri, 8 Feb 2019 08:37:45 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x18DbF7n2188684 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 8 Feb 2019 05:37:15 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x18DbFDd2188680; Fri, 8 Feb 2019 05:37:15 -0800 Date: Fri, 8 Feb 2019 05:37:15 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Peter Zijlstra Message-ID: Cc: torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, dan.j.williams@intel.com, luto@kernel.org, peterz@infradead.org, bp@alien8.de, hpa@zytor.com, tony.luck@intel.com, dave.hansen@linux.intel.com, mingo@kernel.org, tglx@linutronix.de, riel@surriel.com Reply-To: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, dan.j.williams@intel.com, peterz@infradead.org, luto@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, tony.luck@intel.com, hpa@zytor.com, tglx@linutronix.de, mingo@kernel.org, riel@surriel.com In-Reply-To: <20190208120859.GH32511@hirez.programming.kicks-ass.net> References: <20190208120859.GH32511@hirez.programming.kicks-ass.net> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] x86/mm/cpa: Fix set_mce_nospec() Git-Commit-ID: 0521e8be211cd20d547bff9da2534b7ed6f2c1b9 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 0521e8be211cd20d547bff9da2534b7ed6f2c1b9 Gitweb: https://git.kernel.org/tip/0521e8be211cd20d547bff9da2534b7ed6f2c1b9 Author: Peter Zijlstra AuthorDate: Fri, 8 Feb 2019 13:08:59 +0100 Committer: Thomas Gleixner CommitDate: Fri, 8 Feb 2019 14:31:56 +0100 x86/mm/cpa: Fix set_mce_nospec() The recent commit fe0937b24ff5 ("x86/mm/cpa: Fold cpa_flush_range() and cpa_flush_array() into a single cpa_flush() function") accidentally made the call to make_addr_canonical_again() go away, which breaks set_mce_nospec(). Re-instate the call to convert the address back into canonical form right before invoking either CLFLUSH or INVLPG. Rename the function while at it to be shorter (and less MAGA). Fixes: fe0937b24ff5 ("x86/mm/cpa: Fold cpa_flush_range() and cpa_flush_array() into a single cpa_flush() function") Reported-by: Tony Luck Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Thomas Gleixner Tested-by: Tony Luck Cc: Linus Torvalds Cc: Dan Williams Cc: Dave Hansen Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Rik van Riel Link: https://lkml.kernel.org/r/20190208120859.GH32511@hirez.programming.kicks-ass.net --- arch/x86/mm/pageattr.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c index 4f8972311a77..14e6119838a6 100644 --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c @@ -230,6 +230,29 @@ static bool __cpa_pfn_in_highmap(unsigned long pfn) #endif +/* + * See set_mce_nospec(). + * + * Machine check recovery code needs to change cache mode of poisoned pages to + * UC to avoid speculative access logging another error. But passing the + * address of the 1:1 mapping to set_memory_uc() is a fine way to encourage a + * speculative access. So we cheat and flip the top bit of the address. This + * works fine for the code that updates the page tables. But at the end of the + * process we need to flush the TLB and cache and the non-canonical address + * causes a #GP fault when used by the INVLPG and CLFLUSH instructions. + * + * But in the common case we already have a canonical address. This code + * will fix the top bit if needed and is a no-op otherwise. + */ +static inline unsigned long fix_addr(unsigned long addr) +{ +#ifdef CONFIG_X86_64 + return (long)(addr << 1) >> 1; +#else + return addr; +#endif +} + static unsigned long __cpa_addr(struct cpa_data *cpa, unsigned long idx) { if (cpa->flags & CPA_PAGES_ARRAY) { @@ -313,7 +336,7 @@ void __cpa_flush_tlb(void *data) unsigned int i; for (i = 0; i < cpa->numpages; i++) - __flush_tlb_one_kernel(__cpa_addr(cpa, i)); + __flush_tlb_one_kernel(fix_addr(__cpa_addr(cpa, i))); } static void cpa_flush(struct cpa_data *data, int cache) @@ -347,7 +370,7 @@ static void cpa_flush(struct cpa_data *data, int cache) * Only flush present addresses: */ if (pte && (pte_val(*pte) & _PAGE_PRESENT)) - clflush_cache_range_opt((void *)addr, PAGE_SIZE); + clflush_cache_range_opt((void *)fix_addr(addr), PAGE_SIZE); } mb(); } @@ -1627,29 +1650,6 @@ out: return ret; } -/* - * Machine check recovery code needs to change cache mode of poisoned - * pages to UC to avoid speculative access logging another error. But - * passing the address of the 1:1 mapping to set_memory_uc() is a fine - * way to encourage a speculative access. So we cheat and flip the top - * bit of the address. This works fine for the code that updates the - * page tables. But at the end of the process we need to flush the cache - * and the non-canonical address causes a #GP fault when used by the - * CLFLUSH instruction. - * - * But in the common case we already have a canonical address. This code - * will fix the top bit if needed and is a no-op otherwise. - */ -static inline unsigned long make_addr_canonical_again(unsigned long addr) -{ -#ifdef CONFIG_X86_64 - return (long)(addr << 1) >> 1; -#else - return addr; -#endif -} - - static int change_page_attr_set_clr(unsigned long *addr, int numpages, pgprot_t mask_set, pgprot_t mask_clr, int force_split, int in_flag,