Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp166133imj; Thu, 7 Feb 2019 02:19:17 -0800 (PST) X-Google-Smtp-Source: AHgI3IYz5FH9YUsZYH4cxDsvwSgIch6gUwSh/60Xm8Y/amxoNM/BuGrZ+/e27dErrin7aOTUBR+n X-Received: by 2002:a62:61c3:: with SMTP id v186mr15500950pfb.55.1549534757341; Thu, 07 Feb 2019 02:19:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549534757; cv=none; d=google.com; s=arc-20160816; b=f2Yn56Jpq6TNvXkwt0FY+xQPa2N47kVagNte9QPvzc351hKiZlUoi1ieK/Tt/V4FPd nNWV/XegVSFW3R9DeK0PKe6yO8QMJKCeqgPBfArdgOdzUKq1zHxfTx/Olh1wQqzijySZ EgLNU2TQLpve1esd4K7dgBAAzcv7zOFfYh8Qcp0fD4xuy838cDpPQF6tikXjHeW6HHds fj1lZT+AplYgJTSw6uGCOF+g+Gn85K8TlNKk2QvOJz2R/HGnT7WKzPhMCj+6bY/5GmVF ThDn3b5K7ti2Nv16gyJJ+iK/xxDSLZiqWEhKf+ttXy2LhNZ224uj4l69FK+qyxqsipko b4kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=zsBJCjqzCHb+jAJAJgavx5TZ6nri+z4/DkXqLVivWkc=; b=tRG6Dj71Z/vy+MXwPT7OhatO35+qbPSRHi3j6YHtd0K4D8bnZS2Fd7/X7FIqSQ4Kk+ 56Imk27AtGhHRZDMWirHA6asGezxdcaZSd+BwDkoEYecQTy5RnOBxLNQV4m1BrQj0y6f /bd2wLuJ2FZMk8cDYapSku01olWugFGcssHY5Nr5uQBcUSi3jHtX7PGAhVcnoWXsihVq 5fEI1FWphIkvzgqcj7wIJznM9e0OV9chfkqfhXVzzzxozF2dGyeo0r1YWaHp+L30xa7S tdp4GWge+zkDFwEuRf104Y+6A3sjRRTri90GPHz28mjedkG4X5aebNN8jcVipw7qxeIC qGcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=cWKXI3j6; 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 g5si6079337plt.273.2019.02.07.02.19.00; Thu, 07 Feb 2019 02:19:17 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=cWKXI3j6; 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 S1726708AbfBGKSw (ORCPT + 99 others); Thu, 7 Feb 2019 05:18:52 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:54974 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726186AbfBGKSw (ORCPT ); Thu, 7 Feb 2019 05:18:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zsBJCjqzCHb+jAJAJgavx5TZ6nri+z4/DkXqLVivWkc=; b=cWKXI3j6GsF42yHcIj45metbB TotxBY+ejoQJ8LpzmWOaPoXnhuIO7zbgz57T+6DasIh3kgsuQjDuw2+++H+85+xvpfnMxp9e4Mm4q gY6rfeAiShhfInb07evKMSWQ292sdJ+3lLgfQ2Tu6c63OJ/K9s5D1H2H+Bmhs0Xc/69dfdXJij2AA 9YsIpTTbaXoVvJgVfnbSutefwWAdxXvgJegE2Tr5fjkBu9HG/ksUvInYQwDDiaYy4ukteO/XFVaN0 5o3jBCCZgLbrHnK000VjOZNXLuh9TzwxMya28ZwYeIrPtRiSbcwbMGRM32opVOdxKPnJLdaiR/fwf IZUHfYdQg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1grglb-0005qs-KX; Thu, 07 Feb 2019 10:18:47 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 2281E201476F0; Thu, 7 Feb 2019 11:18:46 +0100 (CET) Date: Thu, 7 Feb 2019 11:18:46 +0100 From: Peter Zijlstra To: "Luck, Tony" Cc: Ingo Molnar , Linus Torvalds , linux-kernel@vger.kernel.org, Dave Hansen , Andy Lutomirski , Borislav Petkov , Thomas Gleixner , Rik van Riel Subject: Re: [GIT PULL] x86/mm changes for v4.21 Message-ID: <20190207101846.GB32511@hirez.programming.kicks-ass.net> References: <20181224231106.GA27438@gmail.com> <20190207001737.GA32096@agluck-desk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190207001737.GA32096@agluck-desk> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 06, 2019 at 04:17:42PM -0800, Luck, Tony wrote: > fe0937b24ff5 ("x86/mm/cpa: Fold cpa_flush_range() and cpa_flush_array() into a single cpa_flush() function") Boris pointed me at this gem: c7486104a5ce ("x86/mce: Fix set_mce_nospec() to avoid #GP fault") (can I just revel at the pure awesome grossness of that) But we then see my above commit having: @@ -1732,11 +1685,6 @@ static int change_page_attr_set_clr(unsigned long *addr, int numpages, */ WARN_ON_ONCE(1); } - /* - * Save address for cache flush. *addr is modified in the call - * to __change_page_attr_set_clr() below. - */ - baddr = make_addr_canonical_again(*addr); Where I clearly got distracted by that excellent comment.. So now the question is where to put it back in, I'm thinking this might want to be in __cpa_addr(). Something like so? diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c index 4f8972311a77..319b767484fb 100644 --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c @@ -230,6 +230,28 @@ static bool __cpa_pfn_in_highmap(unsigned long pfn) #endif +/* + * 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 unsigned long __cpa_addr(struct cpa_data *cpa, unsigned long idx) { if (cpa->flags & CPA_PAGES_ARRAY) { @@ -244,7 +266,7 @@ static unsigned long __cpa_addr(struct cpa_data *cpa, unsigned long idx) if (cpa->flags & CPA_ARRAY) return cpa->vaddr[idx]; - return *cpa->vaddr + idx * PAGE_SIZE; + return make_addr_canonical_again(*cpa->vaddr + idx * PAGE_SIZE); } /* @@ -1627,29 +1649,6 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias) 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,