From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751378AbcGWTRE (ORCPT ); Sat, 23 Jul 2016 15:17:04 -0400 Received: from terminus.zytor.com ([198.137.202.10]:53034 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751234AbcGWTRB (ORCPT ); Sat, 23 Jul 2016 15:17:01 -0400 Date: Sat, 23 Jul 2016 12:15:54 -0700 From: tip-bot for Andy Lutomirski Message-ID: Cc: tglx@linutronix.de, bp@alien8.de, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Valdis.Kletnieks@vt.edu, brgerst@gmail.com, jpoimboe@redhat.com, mcgrof@suse.com, torvalds@linux-foundation.org, hpa@zytor.com, luto@kernel.org, mingo@kernel.org, toshi.kani@hp.com, krinkin.m.u@gmail.com, dvlasenk@redhat.com, peterz@infradead.org Reply-To: mingo@kernel.org, peterz@infradead.org, dvlasenk@redhat.com, krinkin.m.u@gmail.com, toshi.kani@hp.com, mcgrof@suse.com, jpoimboe@redhat.com, linux-kernel@vger.kernel.org, Valdis.Kletnieks@vt.edu, brgerst@gmail.com, tglx@linutronix.de, akpm@linux-foundation.org, bp@alien8.de, luto@kernel.org, hpa@zytor.com, torvalds@linux-foundation.org In-Reply-To: <21cbc2822aa18aa812c0215f4231dbf5f65afa7f.1469249789.git.luto@kernel.org> References: <21cbc2822aa18aa812c0215f4231dbf5f65afa7f.1469249789.git.luto@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/mm/cpa: Fix populate_pgd(): Stop trying to deallocate failed PUDs Git-Commit-ID: 530dd8d4b9daf77e3e5d145a26210d91ced954c7 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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 530dd8d4b9daf77e3e5d145a26210d91ced954c7 Gitweb: http://git.kernel.org/tip/530dd8d4b9daf77e3e5d145a26210d91ced954c7 Author: Andy Lutomirski AuthorDate: Fri, 22 Jul 2016 21:58:08 -0700 Committer: Ingo Molnar CommitDate: Sat, 23 Jul 2016 21:13:25 +0200 x86/mm/cpa: Fix populate_pgd(): Stop trying to deallocate failed PUDs Valdis Kletnieks bisected a boot failure back to this recent commit: 360cb4d15567 ("x86/mm/cpa: In populate_pgd(), don't set the PGD entry until it's populated") I broke the case where a PUD table got allocated -- populate_pud() would wander off a pgd_none entry and get lost. I'm not sure how this survived my testing. Fix the original issue in a much simpler way. The problem was that, if we allocated a PUD table, failed to populate it, and freed it, another CPU could potentially keep using the PGD entry we installed (either by copying it via vmalloc_fault or by speculatively caching it). There's a straightforward fix: simply leave the top-level entry in place if this happens. This can't waste any significant amount of memory -- there are at most 256 entries like this systemwide and, as a practical matter, if we hit this failure path repeatedly, we're likely to reuse the same page anyway. For context, this is a reversion with this hunk added in: if (ret < 0) { + /* + * Leave the PUD page in place in case some other CPU or thread + * already found it, but remove any useless entries we just + * added to it. + */ - unmap_pgd_range(cpa->pgd, addr, + unmap_pud_range(pgd_entry, addr, addr + (cpa->numpages << PAGE_SHIFT)); return ret; } This effectively open-codes what the now-deleted unmap_pgd_range() function used to do except that unmap_pgd_range() used to try to free the page as well. Reported-by: Valdis Kletnieks Signed-off-by: Andy Lutomirski Cc: Andrew Morton Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Luis R. Rodriguez Cc: Mike Krinkin Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Toshi Kani Link: http://lkml.kernel.org/r/21cbc2822aa18aa812c0215f4231dbf5f65afa7f.1469249789.git.luto@kernel.org Signed-off-by: Ingo Molnar --- arch/x86/mm/pageattr.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c index 26c93c6..2bc6ea1 100644 --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c @@ -1082,6 +1082,8 @@ static int populate_pgd(struct cpa_data *cpa, unsigned long addr) pud = (pud_t *)get_zeroed_page(GFP_KERNEL | __GFP_NOTRACK); if (!pud) return -1; + + set_pgd(pgd_entry, __pgd(__pa(pud) | _KERNPG_TABLE)); } pgprot_val(pgprot) &= ~pgprot_val(cpa->mask_clr); @@ -1089,16 +1091,11 @@ static int populate_pgd(struct cpa_data *cpa, unsigned long addr) ret = populate_pud(cpa, addr, pgd_entry, pgprot); if (ret < 0) { - if (pud) - free_page((unsigned long)pud); unmap_pud_range(pgd_entry, addr, addr + (cpa->numpages << PAGE_SHIFT)); return ret; } - if (pud) - set_pgd(pgd_entry, __pgd(__pa(pud) | _KERNPG_TABLE)); - cpa->numpages = ret; return 0; }