Skip to contentSkip to conversation

double incrementing l2tab

PATCH In review Scott Parish 2 participants 2 messages May 12, 2005 – May 13, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 double incrementing l2tab

For PAE, l2e_get_phys() will look something like this:

  #define l2e_get_phys(_x)          ((((u64)(_x).l2_hi & 0x0f) << 32)  |\ 
                                      ((u64)(_x).l2_lo & PAGE_MASK)) 

Thus l2e_get_phys(++foo) is not safe, as the increment will be evaluated multiple times and at undefined times.

sRp

Signature · 2 lines
Scott Parish
Signed-off-by: [email protected]
xen/arch/x86/domain_build.c +4 -1
@@ -330,7 +330,10 @@ int construct_dom0(struct domain *d,
             get_page(page, d); /* an extra ref because of readable mapping */
         }
         if ( !((unsigned long)++l1tab & (PAGE_SIZE - 1)) )
-            l1start = l1tab = (l1_pgentry_t *)l2e_get_phys(*++l2tab);
+        {
+            l2tab++;
+            l1start = l1tab = (l1_pgentry_t *)l2e_get_phys(*l2tab);
+        }
     }
 
 #elif defined(__x86_64__)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 8 lines · Scott Parish

For PAE, l2e_get_phys() will look something like this:

#define l2e_get_phys(_x) ((((u64)(_x).l2_hi & 0x0f) << 32)

|\
                                      ((u64)(_x).l2_lo & PAGE_MASK))

Thus l2e_get_phys(++foo) is not safe, as the increment will be evaluated multiple times and at undefined times.

This leaves the macro to bite you in future. Either make l2e_get_phys() a static inline function, or do something like:

#define l2e_get_phys(_x) ({ \
    u64 __x = (_x); \
    <your macro here but _x -> __x>; \
})

-- Keir