Patch "x86/pgtable: Don't set huge PUD/PMD on non-leaf entries" has been added to the 4.16-stable tree
diff mbox

Message ID
State New
Headers show

Commit Message

Greg Kroah-Hartman May 1, 2018, 10:33 p.m. UTC
This is a note to let you know that I've just added the patch titled

    x86/pgtable: Don't set huge PUD/PMD on non-leaf entries

to the 4.16-stable tree which can be found at:;a=summary

The filename of the patch is:
and it can be found in the queue-4.16 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <> know about it.

From foo@baz Tue May  1 14:59:17 PDT 2018
From: Joerg Roedel <>
Date: Wed, 11 Apr 2018 17:24:38 +0200
Subject: x86/pgtable: Don't set huge PUD/PMD on non-leaf entries

From: Joerg Roedel <>

[ Upstream commit e3e288121408c3abeed5af60b87b95c847143845 ]

The pmd_set_huge() and pud_set_huge() functions are used from
the generic ioremap() code to establish large mappings where this
is possible.

But the generic ioremap() code does not check whether the
PMD/PUD entries are already populated with a non-leaf entry,
so that any page-table pages these entries point to will be

Further, on x86-32 with SHARED_KERNEL_PMD=0, this causes a
BUG_ON() in vmalloc_sync_one() when PMD entries are synced
from swapper_pg_dir to the current page-table. This happens
because the PMD entry from swapper_pg_dir was promoted to a
huge-page entry while the current PGD still contains the
non-leaf entry. Because both entries are present and point
to a different page, the BUG_ON() triggers.

This was actually triggered with pti-x32 enabled in a KVM
virtual machine by the graphics driver.

A real and better fix for that would be to improve the
page-table handling in the generic ioremap() code. But that is
out-of-scope for this patch-set and left for later work.

Reported-by: David H. Gutteridge <>
Signed-off-by: Joerg Roedel <>
Reviewed-by: Thomas Gleixner <>
Cc: Andrea Arcangeli <>
Cc: Andy Lutomirski <>
Cc: Boris Ostrovsky <>
Cc: Borislav Petkov <>
Cc: Brian Gerst <>
Cc: Dave Hansen <>
Cc: David Laight <>
Cc: Denys Vlasenko <>
Cc: Eduardo Valentin <>
Cc: Greg KH <>
Cc: Jiri Kosina <>
Cc: Josh Poimboeuf <>
Cc: Juergen Gross <>
Cc: Linus Torvalds <>
Cc: Pavel Machek <>
Cc: Peter Zijlstra <>
Cc: Waiman Long <>
Cc: Will Deacon <>
Signed-off-by: Ingo Molnar <>
Signed-off-by: Sasha Levin <>
Signed-off-by: Greg Kroah-Hartman <>
 arch/x86/mm/pgtable.c |    9 +++++++++
 1 file changed, 9 insertions(+)

Patches currently in stable-queue which might be from are


diff mbox

--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -1,6 +1,7 @@ 
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/mm.h>
 #include <linux/gfp.h>
+#include <linux/hugetlb.h>
 #include <asm/pgalloc.h>
 #include <asm/pgtable.h>
 #include <asm/tlb.h>
@@ -636,6 +637,10 @@  int pud_set_huge(pud_t *pud, phys_addr_t
 	    (mtrr != MTRR_TYPE_WRBACK))
 		return 0;
+	/* Bail out if we are we on a populated non-leaf entry: */
+	if (pud_present(*pud) && !pud_huge(*pud))
+		return 0;
 	prot = pgprot_4k_2_large(prot);
 	set_pte((pte_t *)pud, pfn_pte(
@@ -664,6 +669,10 @@  int pmd_set_huge(pmd_t *pmd, phys_addr_t
 		return 0;
+	/* Bail out if we are we on a populated non-leaf entry: */
+	if (pmd_present(*pmd) && !pmd_huge(*pmd))
+		return 0;
 	prot = pgprot_4k_2_large(prot);
 	set_pte((pte_t *)pmd, pfn_pte(