[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] tighten requirements on lXe_write() & Co.



This patch allows spotting incorrect use of lXe_write & Co in cases like

void test_pte_write_1(l1_pgentry_t *pl1e, l2_pgentry_t nl2e)
{
    l2e_write(pl1e, nl2e);
}

void test_pte_write_2(const l1_pgentry_t *pcl1e, l1_pgentry_t nl1e)
{
    l1e_write(pcl1e, nl1e);
}

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>

Index: 2006-12-11/xen/include/asm-x86/page.h
===================================================================
--- 2006-12-11.orig/xen/include/asm-x86/page.h  2006-12-12 14:56:46.000000000 
+0100
+++ 2006-12-11/xen/include/asm-x86/page.h       2006-12-12 15:06:51.000000000 
+0100
@@ -26,25 +26,25 @@
 #endif
 
 /* Read a pte atomically from memory. */
-#define l1e_read_atomic(l1ep) l1e_from_intpte(pte_read_atomic(l1ep))
-#define l2e_read_atomic(l2ep) l2e_from_intpte(pte_read_atomic(l2ep))
-#define l3e_read_atomic(l3ep) l3e_from_intpte(pte_read_atomic(l3ep))
-#define l4e_read_atomic(l4ep) l4e_from_intpte(pte_read_atomic(l4ep))
+#define l1e_read_atomic(l1ep) 
l1e_from_intpte(pte_read_atomic(&l1e_get_intpte(*(l1ep))))
+#define l2e_read_atomic(l2ep) 
l2e_from_intpte(pte_read_atomic(&l2e_get_intpte(*(l2ep))))
+#define l3e_read_atomic(l3ep) 
l3e_from_intpte(pte_read_atomic(&l3e_get_intpte(*(l3ep))))
+#define l4e_read_atomic(l4ep) 
l4e_from_intpte(pte_read_atomic(&l4e_get_intpte(*(l4ep))))
 
 /* Write a pte atomically to memory. */
-#define l1e_write_atomic(l1ep, l1e) pte_write_atomic(l1ep, l1e_get_intpte(l1e))
-#define l2e_write_atomic(l2ep, l2e) pte_write_atomic(l2ep, l2e_get_intpte(l2e))
-#define l3e_write_atomic(l3ep, l3e) pte_write_atomic(l3ep, l3e_get_intpte(l3e))
-#define l4e_write_atomic(l4ep, l4e) pte_write_atomic(l4ep, l4e_get_intpte(l4e))
+#define l1e_write_atomic(l1ep, l1e) pte_write_atomic(&l1e_get_intpte(*(l1ep)), 
l1e_get_intpte(l1e))
+#define l2e_write_atomic(l2ep, l2e) pte_write_atomic(&l2e_get_intpte(*(l2ep)), 
l2e_get_intpte(l2e))
+#define l3e_write_atomic(l3ep, l3e) pte_write_atomic(&l3e_get_intpte(*(l3ep)), 
l3e_get_intpte(l3e))
+#define l4e_write_atomic(l4ep, l4e) pte_write_atomic(&l4e_get_intpte(*(l4ep)), 
l4e_get_intpte(l4e))
 
 /*
  * Write a pte safely but non-atomically to memory.
  * The PTE may become temporarily not-present during the update.
  */
-#define l1e_write(l1ep, l1e) pte_write(l1ep, l1e_get_intpte(l1e))
-#define l2e_write(l2ep, l2e) pte_write(l2ep, l2e_get_intpte(l2e))
-#define l3e_write(l3ep, l3e) pte_write(l3ep, l3e_get_intpte(l3e))
-#define l4e_write(l4ep, l4e) pte_write(l4ep, l4e_get_intpte(l4e))
+#define l1e_write(l1ep, l1e) pte_write(&l1e_get_intpte(*(l1ep)), 
l1e_get_intpte(l1e))
+#define l2e_write(l2ep, l2e) pte_write(&l2e_get_intpte(*(l2ep)), 
l2e_get_intpte(l2e))
+#define l3e_write(l3ep, l3e) pte_write(&l3e_get_intpte(*(l3ep)), 
l3e_get_intpte(l3e))
+#define l4e_write(l4ep, l4e) pte_write(&l4e_get_intpte(*(l4ep)), 
l4e_get_intpte(l4e))
 
 /* Get direct integer representation of a pte's contents (intpte_t). */
 #define l1e_get_intpte(x)          ((x).l1)
Index: 2006-12-11/xen/include/asm-x86/x86_32/page-2level.h
===================================================================
--- 2006-12-11.orig/xen/include/asm-x86/x86_32/page-2level.h    2006-12-12 
14:56:46.000000000 +0100
+++ 2006-12-11/xen/include/asm-x86/x86_32/page-2level.h 2006-12-12 
15:06:51.000000000 +0100
@@ -28,9 +28,9 @@ typedef l2_pgentry_t root_pgentry_t;
 
 #endif /* !__ASSEMBLY__ */
 
-#define pte_read_atomic(ptep)       (*(intpte_t *)(ptep))
-#define pte_write_atomic(ptep, pte) ((*(intpte_t *)(ptep)) = (pte))
-#define pte_write(ptep, pte)        ((*(intpte_t *)(ptep)) = (pte))
+#define pte_read_atomic(ptep)       (*(ptep))
+#define pte_write_atomic(ptep, pte) (*(ptep) = (pte))
+#define pte_write(ptep, pte)        (*(ptep) = (pte))
 
 /* root table */
 #define root_get_pfn              l2e_get_pfn
Index: 2006-12-11/xen/include/asm-x86/x86_32/page-3level.h
===================================================================
--- 2006-12-11.orig/xen/include/asm-x86/x86_32/page-3level.h    2006-12-12 
14:56:46.000000000 +0100
+++ 2006-12-11/xen/include/asm-x86/x86_32/page-3level.h 2006-12-12 
15:27:19.000000000 +0100
@@ -38,22 +38,23 @@ typedef l3_pgentry_t root_pgentry_t;
 
 #endif /* !__ASSEMBLY__ */
 
-#define pte_read_atomic(ptep) ({                                            \
-    intpte_t __pte = *(intpte_t *)(ptep), __npte;                           \
-    while ( (__npte = cmpxchg((intpte_t *)(ptep), __pte, __pte)) != __pte ) \
-        __pte = __npte;                                                     \
+#define pte_read_atomic(ptep) ({                              \
+    intpte_t __pte = *(ptep), __npte;                         \
+    while ( (__npte = cmpxchg(ptep, __pte, __pte)) != __pte ) \
+        __pte = __npte;                                       \
     __pte; })
-#define pte_write_atomic(ptep, pte) do {                                    \
-    intpte_t __pte = *(intpte_t *)(ptep), __npte;                           \
-    while ( (__npte = cmpxchg((intpte_t *)(ptep), __pte, (pte))) != __pte ) \
-        __pte = __npte;                                                     \
+#define pte_write_atomic(ptep, pte) do {                      \
+    intpte_t __pte = *(ptep), __npte;                         \
+    while ( (__npte = cmpxchg(ptep, __pte, (pte))) != __pte ) \
+        __pte = __npte;                                       \
 } while ( 0 )
-#define pte_write(ptep, pte) do {               \
-    *((u32 *)(ptep)+0) = 0;                     \
-    wmb();                                      \
-    *((u32 *)(ptep)+1) = (pte) >> 32;           \
-    wmb();                                      \
-    *((u32 *)(ptep)+0) = (pte) >>  0;           \
+#define pte_write(ptep, pte) do {                             \
+    union { intpte_t *_ptep; u32 *parts; } __ptep = { ptep }; \
+    __ptep.parts[0] = 0;                                      \
+    wmb();                                                    \
+    __ptep.parts[1] = (pte) >> 32;                            \
+    wmb();                                                    \
+    __ptep.parts[0] = (pte) >>  0;                            \
 } while ( 0 )
 
 /* root table */
Index: 2006-12-11/xen/include/asm-x86/x86_64/page.h
===================================================================
--- 2006-12-11.orig/xen/include/asm-x86/x86_64/page.h   2006-12-12 
14:56:46.000000000 +0100
+++ 2006-12-11/xen/include/asm-x86/x86_64/page.h        2006-12-12 
15:06:51.000000000 +0100
@@ -43,9 +43,9 @@ typedef l4_pgentry_t root_pgentry_t;
 
 #endif /* !__ASSEMBLY__ */
 
-#define pte_read_atomic(ptep)       (*(intpte_t *)(ptep))
-#define pte_write_atomic(ptep, pte) ((*(intpte_t *)(ptep)) = (pte))
-#define pte_write(ptep, pte)        ((*(intpte_t *)(ptep)) = (pte))
+#define pte_read_atomic(ptep)       (*(ptep))
+#define pte_write_atomic(ptep, pte) (*(ptep) = (pte))
+#define pte_write(ptep, pte)        (*(ptep) = (pte))
 
 /* Given a virtual address, get an entry offset into a linear page table. */
 #define l1_linear_offset(_a) (((_a) & VADDR_MASK) >> L1_PAGETABLE_SHIFT)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.