WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

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

To: <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] tighten requirements on lXe_write() & Co.
From: "Jan Beulich" <jbeulich@xxxxxxxxxx>
Date: Tue, 12 Dec 2006 16:24:37 +0000
Delivery-date: Tue, 12 Dec 2006 08:29:30 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] tighten requirements on lXe_write() & Co., Jan Beulich <=