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

[Xen-changelog] [xen master] x86: refine link time stub area related assertion



commit 3c4b2eef4941c8a81d04337c6df31175a881635f
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Fri Jan 17 16:15:28 2020 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Fri Jan 17 16:15:28 2020 +0100

    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.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/arch/x86/xen.lds.S          |  5 +++--
 xen/include/asm-x86/config.h    |  1 +
 xen/include/asm-x86/processor.h |  2 --
 xen/include/xen/lib.h           | 28 ++++++++++++++++------------
 4 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index 7f82f64078..29ef507432 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -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
diff --git a/xen/include/asm-x86/config.h b/xen/include/asm-x86/config.h
index dab7d7bade..d0cfbb70a8 100644
--- a/xen/include/asm-x86/config.h
+++ b/xen/include/asm-x86/config.h
@@ -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)
diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processor.h
index 19328f481a..b2b19a02cd 100644
--- a/xen/include/asm-x86/processor.h
+++ b/xen/include/asm-x86/processor.h
@@ -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);
diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
index 8fbe84032d..5d718bbdba 100644
--- a/xen/include/xen/lib.h
+++ b/xen/include/xen/lib.h
@@ -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__ */
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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