Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4807470ooa; Tue, 14 Aug 2018 10:49:42 -0700 (PDT) X-Google-Smtp-Source: AA+uWPy/LcYaIZpB85RRoH210Qj0hkE+hqVRxXtvSz+AKRfK3U1vgDhJ3TI72AmVh1xNAqF1byPU X-Received: by 2002:a17:902:a50a:: with SMTP id s10-v6mr21002954plq.147.1534268982858; Tue, 14 Aug 2018 10:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534268982; cv=none; d=google.com; s=arc-20160816; b=Nup9MchSJdk2YGJBBUbLH92bCxaT2Wj4H94F5QTILXvucUlo2+EtDg6abjuFwo7R0t uE9ZM5nb3Lxxm4XphlSmnC+Cy/MhTZqQg0OkdZll2OXhiuK+7fZ86Jg/lOZUqoRELKXQ CMJ/svFqlF27XImoVRScljUjVVp1dKntpUfRi+fxaHHmyIgQX5UMjBXakDCLEKzaDoBl d1T8NGDP9RFxy4eMSXn1UAdXuOCmXgcn+ag1MGGoPbOwVJMY4k1sDOgQy48ykcLzGb46 WLFUY+FMhVfSKIpiu/r+/wnWI91JLePgdd1xbM7HgpqqyQHa+IStjqLilw9fgLQrzhAi cD/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=XXJbIXSOx19xJo3xamBW+4EU2x7gak18heXlMLv6Gu0=; b=yYBlqKCgo54/ubIF1e4dBST1ysNwCGXqAmpITg35Hq3vNj+lTKPeTHGWd3Is1eLLO0 /CMIojx6pvYb1HjmTmsNqQnULWDc4HXvSMZln7VX+peora+3TDFCoooN/Q1HajkDYXZ/ fJf+RA1Lt9uBnjkV4NUMDgicg5R+XJ2VKZVZ3cvC2XHJJJ2aqF0fTThwrvonArIsaIvE tCrA2KMkb4vpVYOz4KNJ+3zz8Te6GQRH05v78e9LYo8qQ+lZ/nEnWe0UtBIXpWn/koqJ T5nPvFRAsi9BoKSkp6maENFiuTnORwDWyU7pChF4AbDTT67eYrwgZXpZw4Yji12DJTIg kwEA== 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 r15-v6si18454429pgf.403.2018.08.14.10.49.27; Tue, 14 Aug 2018 10:49:42 -0700 (PDT) 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 S2391315AbeHNUg2 (ORCPT + 99 others); Tue, 14 Aug 2018 16:36:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:32956 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390418AbeHNUg2 (ORCPT ); Tue, 14 Aug 2018 16:36:28 -0400 Received: from localhost (unknown [194.244.16.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5F495CB5; Tue, 14 Aug 2018 17:48:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andi Kleen , Thomas Gleixner , David Woodhouse , Guenter Roeck Subject: [PATCH 4.4 41/43] x86/mm/pat: Make set_memory_np() L1TF safe Date: Tue, 14 Aug 2018 19:18:17 +0200 Message-Id: <20180814171519.769320295@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180814171517.014285600@linuxfoundation.org> References: <20180814171517.014285600@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andi Kleen commit 958f79b9ee55dfaf00c8106ed1c22a2919e0028b upstream set_memory_np() is used to mark kernel mappings not present, but it has it's own open coded mechanism which does not have the L1TF protection of inverting the address bits. Replace the open coded PTE manipulation with the L1TF protecting low level PTE routines. Passes the CPA self test. Signed-off-by: Andi Kleen Signed-off-by: Thomas Gleixner [ dwmw2: Pull in pud_mkhuge() from commit a00cc7d9dd, and pfn_pud() ] Signed-off-by: David Woodhouse [groeck: port to 4.4] Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/pgtable.h | 27 +++++++++++++++++++++++++++ arch/x86/mm/pageattr.c | 8 ++++---- 2 files changed, 31 insertions(+), 4 deletions(-) --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -378,12 +378,39 @@ static inline pmd_t pfn_pmd(unsigned lon return __pmd(pfn | massage_pgprot(pgprot)); } +static inline pud_t pfn_pud(unsigned long page_nr, pgprot_t pgprot) +{ + phys_addr_t pfn = page_nr << PAGE_SHIFT; + pfn ^= protnone_mask(pgprot_val(pgprot)); + pfn &= PHYSICAL_PUD_PAGE_MASK; + return __pud(pfn | massage_pgprot(pgprot)); +} + static inline pmd_t pmd_mknotpresent(pmd_t pmd) { return pfn_pmd(pmd_pfn(pmd), __pgprot(pmd_flags(pmd) & ~(_PAGE_PRESENT|_PAGE_PROTNONE))); } +static inline pud_t pud_set_flags(pud_t pud, pudval_t set) +{ + pudval_t v = native_pud_val(pud); + + return __pud(v | set); +} + +static inline pud_t pud_clear_flags(pud_t pud, pudval_t clear) +{ + pudval_t v = native_pud_val(pud); + + return __pud(v & ~clear); +} + +static inline pud_t pud_mkhuge(pud_t pud) +{ + return pud_set_flags(pud, _PAGE_PSE); +} + static inline u64 flip_protnone_guard(u64 oldval, u64 val, u64 mask); static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c @@ -1006,8 +1006,8 @@ static int populate_pmd(struct cpa_data pmd = pmd_offset(pud, start); - set_pmd(pmd, __pmd(cpa->pfn | _PAGE_PSE | - massage_pgprot(pmd_pgprot))); + set_pmd(pmd, pmd_mkhuge(pfn_pmd(cpa->pfn, + canon_pgprot(pmd_pgprot)))); start += PMD_SIZE; cpa->pfn += PMD_SIZE; @@ -1079,8 +1079,8 @@ static int populate_pud(struct cpa_data * Map everything starting from the Gb boundary, possibly with 1G pages */ while (end - start >= PUD_SIZE) { - set_pud(pud, __pud(cpa->pfn | _PAGE_PSE | - massage_pgprot(pud_pgprot))); + set_pud(pud, pud_mkhuge(pfn_pud(cpa->pfn, + canon_pgprot(pud_pgprot)))); start += PUD_SIZE; cpa->pfn += PUD_SIZE;