lkml.org 
[lkml]   [2018]   [Aug]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v3 5/5] x86/mm: add WARN_ON_ONCE() for wrong large page mapping
Date
If there is a large page which contains an area which requires a
different mapping that the one which the large page provides,
then something went wrong _before_ this code is called.

Here we can catch a case where the existing mapping is wrong
already.

Inspired-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Bin Yang <bin.yang@intel.com>
---
arch/x86/mm/pageattr.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index fd90c5b..91a250c 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -625,6 +625,7 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,

psize = page_level_size(level);
pmask = page_level_mask(level);
+ addr = address & pmask;

/*
* Calculate the number of pages, which fit into this large
@@ -636,6 +637,12 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,
cpa->numpages = numpages;

/*
+ * The old pgprot should not have any protection bit. Otherwise,
+ * the existing mapping is wrong already.
+ */
+ WARN_ON_ONCE(needs_static_protections(old_prot, addr, psize, old_pfn));
+
+ /*
* We are safe now. Check whether the new pgprot is the same:
* Convert protection attributes to 4k-format, as cpa->mask* are set
* up accordingly.
@@ -690,7 +697,6 @@ try_preserve_large_page(pte_t *kpte, unsigned long address,
* would anyway result in a split after doing all the check work
* for nothing.
*/
- addr = address & pmask;
if (address != addr || cpa->numpages != numpages)
goto out_unlock;

--
2.7.4
\
 
 \ /
  Last update: 2018-08-21 03:17    [W:1.041 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site