Skip to contentSkip to conversation

x86: refine link time stub area related assertion

PATCH In review Jan Beulich 2 participants 2 messages Jan 16, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86: refine link time stub area related assertion

While it has been me to introduce this, the use of | there has become (and perhaps was from the very beginning) misleading. Rather than avoiding the right side of it when linking the xen.efi intermediate file at a different base address, make the expression cope with that case, thus verifying placement on every step.

Furthermore the original check was too strict: We don't use one page per CPU, so account for this as well. This involves moving the STUBS_PER_PAGE definition and making DIV_ROUND_UP() accessible from assembly (and hence the linker script); move a few other potentially generally useful definitions along with it.

---
v2: Account for STUBS_PER_PAGE as well.

xen/arch/x86/xen.lds.S +3 -2
@@ -2,6 +2,7 @@
 /* Modified for i386/x86-64 Xen by Keir Fraser */
 
 #include <xen/cache.h>
+#include <xen/lib.h>
 #include <asm/page.h>
 #undef ENTRY
 #undef ALIGN
@@ -351,8 +352,8 @@ SECTIONS
   .comment 0 : { *(.comment) }
 }
 
-ASSERT(__image_base__ > XEN_VIRT_START |
-       __2M_rwdata_end <= XEN_VIRT_END - NR_CPUS * PAGE_SIZE,
+ASSERT(__2M_rwdata_end <= XEN_VIRT_END - XEN_VIRT_START + __XEN_VIRT_START -
+                          DIV_ROUND_UP(NR_CPUS, STUBS_PER_PAGE) * PAGE_SIZE,
        "Xen image overlaps stubs area")
 
 #ifdef CONFIG_KEXEC
xen/include/asm-x86/config.h +1 -0
@@ -78,6 +78,7 @@
 /* Total size of syscall and emulation stubs. */
 #define STUB_BUF_SHIFT (L1_CACHE_SHIFT > 7 ? L1_CACHE_SHIFT : 7)
 #define STUB_BUF_SIZE  (1 << STUB_BUF_SHIFT)
+#define STUBS_PER_PAGE (PAGE_SIZE / STUB_BUF_SIZE)
 
 /* Return value for zero-size _xmalloc(), distinguished from NULL. */
 #define ZERO_BLOCK_PTR ((void *)0xBAD0BAD0BAD0BAD0UL)
xen/include/asm-x86/processor.h +0 -2
@@ -563,8 +563,6 @@ void sysenter_entry(void);
 void sysenter_eflags_saved(void);
 void int80_direct_trap(void);
 
-#define STUBS_PER_PAGE (PAGE_SIZE / STUB_BUF_SIZE)
-
 struct stubs {
     union {
         void(*func)(void);
xen/include/xen/lib.h +16 -12
@@ -1,6 +1,20 @@
 #ifndef __LIB_H__
 #define __LIB_H__
 
+#define ROUNDUP(x, a) (((x) + (a) - 1) & ~((a) - 1))
+
+#define DIV_ROUND(n, d) (((n) + (d) / 2) / (d))
+#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+
+#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
+#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))
+
+#define count_args_(dot, a1, a2, a3, a4, a5, a6, a7, a8, x, ...) x
+#define count_args(args...) \
+    count_args_(., ## args, 8, 7, 6, 5, 4, 3, 2, 1, 0)
+
+#ifndef __ASSEMBLY__
+
 #include <xen/inttypes.h>
 #include <xen/stdarg.h>
 #include <xen/types.h>
@@ -51,9 +65,6 @@
 #define SWAP(_a, _b) \
    do { typeof(_a) _t = (_a); (_a) = (_b); (_b) = _t; } while ( 0 )
 
-#define DIV_ROUND(n, d) (((n) + (d) / 2) / (d))
-#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
-
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x))
 
 #define __ACCESS_ONCE(x) ({                             \
@@ -61,15 +72,6 @@
             (volatile typeof(x) *)&(x); })
 #define ACCESS_ONCE(x) (*__ACCESS_ONCE(x))
 
-#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
-#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))
-
-#define ROUNDUP(x, a) (((x) + (a) - 1) & ~((a) - 1))
-
-#define count_args_(dot, a1, a2, a3, a4, a5, a6, a7, a8, x, ...) x
-#define count_args(args...) \
-    count_args_(., ## args, 8, 7, 6, 5, 4, 3, 2, 1, 0)
-
 struct domain;
 
 void cmdline_parse(const char *cmdline);
@@ -194,4 +196,6 @@ void init_constructors(void);
 void *bsearch(const void *key, const void *base, size_t num, size_t size,
               int (*cmp)(const void *key, const void *elt));
 
+#endif /* __ASSEMBLY__ */
+
 #endif /* __LIB_H__ */

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Jan Beulich

While it has been me to introduce this, the use of | there has become (and perhaps was from the very beginning) misleading. Rather than avoiding the right side of it when linking the xen.efi intermediate file at a different base address, make the expression cope with that case, thus verifying placement on every step.

Quoted 7 lines

Furthermore the original check was too strict: We don't use one page per CPU, so account for this as well. This involves moving the STUBS_PER_PAGE definition and making DIV_ROUND_UP() accessible from assembly (and hence the linker script); move a few other potentially generally useful definitions along with it.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel