[Lguest] [PATCH] v2.6.26: x86: fix pte_flags() to only return flags, fix lguest (updated)

Rusty Russell rusty at rustcorp.com.au
Wed Jul 23 09:35:27 EST 2008


commit c2e3277f875b83e5adc34e96989d6d87ec5f80f7
Author: Rusty Russell <rusty at rustcorp.com.au>
Date:   Tue Jul 22 15:40:46 2008 +1000

    x86: fix pte_flags() to only return flags, fix lguest (updated)
    
    (Jeremy said:
    	rusty: use PTE_MASK
    	rusty: use PTE_MASK
    	rusty: use PTE_MASK
     When I asked:
    	jsgf: does that include the NX flag?
     He responded eloquently:
    	rusty: use PTE_MASK
    	rusty: use PTE_MASK
    	yes, it's the official constant of masking flags out of ptes
    )
    
    Change a15af1c9ea2750a9ff01e51615c45950bad8221b 'x86/paravirt: add
    pte_flags to just get pte flags' removed lguest's private pte_flags()
    in favor of a generic one.
    
    Unfortunately, the generic one doesn't filter out the non-flags bits:
    this results in lguest creating corrupt shadow page tables and blowing
    up host memory.
    
    Since noone is supposed to use the pfn part of pte_flags(), it seems
    safest to always do the filtering.
    
    Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
    Acked-by: Jeremy Fitzhardinge <jeremy at goop.org>
    Signed-off-and-morning-tea-spilled-by: Ingo Molnar <mingo at elte.hu>

diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
index 097d8a6..94da4d5 100644
--- a/arch/x86/kernel/paravirt.c
+++ b/arch/x86/kernel/paravirt.c
@@ -443,7 +443,7 @@ struct pv_mmu_ops pv_mmu_ops = {
 #endif /* PAGETABLE_LEVELS >= 3 */
 
 	.pte_val = native_pte_val,
-	.pte_flags = native_pte_val,
+	.pte_flags = native_pte_flags,
 	.pgd_val = native_pgd_val,
 
 	.make_pte = native_make_pte,
diff --git a/include/asm-x86/page.h b/include/asm-x86/page.h
index 28d7b45..05d9bea 100644
--- a/include/asm-x86/page.h
+++ b/include/asm-x86/page.h
@@ -144,6 +144,11 @@ static inline pteval_t native_pte_val(pte_t pte)
 	return pte.pte;
 }
 
+static inline pteval_t native_pte_flags(pte_t pte)
+{
+	return native_pte_val(pte) & ~PTE_MASK;
+}
+
 #define pgprot_val(x)	((x).pgprot)
 #define __pgprot(x)	((pgprot_t) { (x) } )
 
@@ -165,7 +170,7 @@ static inline pteval_t native_pte_val(pte_t pte)
 #endif
 
 #define pte_val(x)	native_pte_val(x)
-#define pte_flags(x)	native_pte_val(x)
+#define pte_flags(x)	native_pte_flags(x)
 #define __pte(x)	native_make_pte(x)
 
 #endif	/* CONFIG_PARAVIRT */
diff --git a/include/asm-x86/paravirt.h b/include/asm-x86/paravirt.h
index aec9767..5ca4639 100644
--- a/include/asm-x86/paravirt.h
+++ b/include/asm-x86/paravirt.h
@@ -1088,6 +1088,9 @@ static inline pteval_t pte_flags(pte_t pte)
 		ret = PVOP_CALL1(pteval_t, pv_mmu_ops.pte_flags,
 				 pte.pte);
 
+#ifdef CONFIG_PARAVIRT_DEBUG
+	BUG_ON(ret & PTE_MASK);
+#endif
 	return ret;
 }
 



More information about the Lguest mailing list