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

[Xen-devel] [PATCH v4 23/34] xsplice: Add support for exception tables.



From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>

Add support for exception tables contained within xSplice payloads. If an
exception occurs search either the main exception table or a particular
active payload's exception table depending on the instruction pointer.

Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>

---
Cc: Keir Fraser <keir@xxxxxxx>
Cc: Jan Beulich <jbeulich@xxxxxxxx>
Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>

v2:
 - s/module/payload/
 - sanity checks.
 - Move code around.
 - s/module/payload/
v3: Use 'struct virtual_region'
---
 xen/arch/x86/extable.c        | 30 +++++++++++++++++-------------
 xen/common/xsplice.c          | 19 +++++++++++++++++++
 xen/include/asm-x86/uaccess.h |  5 +++++
 3 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/xen/arch/x86/extable.c b/xen/arch/x86/extable.c
index 6e083a8..4a9016b 100644
--- a/xen/arch/x86/extable.c
+++ b/xen/arch/x86/extable.c
@@ -20,7 +20,7 @@ static inline unsigned long ex_cont(const struct 
exception_table_entry *x)
        return EX_FIELD(x, cont);
 }
 
-static int __init cmp_ex(const void *a, const void *b)
+static int cmp_ex(const void *a, const void *b)
 {
        const struct exception_table_entry *l = a, *r = b;
        unsigned long lip = ex_addr(l);
@@ -35,7 +35,7 @@ static int __init cmp_ex(const void *a, const void *b)
 }
 
 #ifndef swap_ex
-static void __init swap_ex(void *a, void *b, int size)
+static void swap_ex(void *a, void *b, int size)
 {
        struct exception_table_entry *l = a, *r = b, tmp;
        long delta = b - a;
@@ -48,19 +48,23 @@ static void __init swap_ex(void *a, void *b, int size)
 }
 #endif
 
-void __init sort_exception_tables(void)
+void sort_exception_table(struct exception_table_entry *start,
+                          struct exception_table_entry *stop)
 {
-    sort(__start___ex_table, __stop___ex_table - __start___ex_table,
-         sizeof(struct exception_table_entry), cmp_ex, swap_ex);
-    sort(__start___pre_ex_table,
-         __stop___pre_ex_table - __start___pre_ex_table,
+    sort(start, stop - start,
          sizeof(struct exception_table_entry), cmp_ex, swap_ex);
 }
 
-static inline unsigned long
-search_one_table(const struct exception_table_entry *first,
-                 const struct exception_table_entry *last,
-                 unsigned long value)
+void __init sort_exception_tables(void)
+{
+    sort_exception_table(__start___ex_table, __stop___ex_table);
+    sort_exception_table(__start___pre_ex_table, __stop___pre_ex_table);
+}
+
+unsigned long
+search_one_extable(const struct exception_table_entry *first,
+                   const struct exception_table_entry *last,
+                   unsigned long value)
 {
     const struct exception_table_entry *mid;
     long diff;
@@ -90,7 +94,7 @@ search_exception_table(unsigned long addr)
             continue;
 
         if ( (addr >= region->start) && (addr < region->end) )
-            return search_one_table(region->ex, region->ex_end-1, addr);
+            return search_one_extable(region->ex, region->ex_end-1, addr);
     }
 
     return 0;
@@ -100,7 +104,7 @@ unsigned long
 search_pre_exception_table(struct cpu_user_regs *regs)
 {
     unsigned long addr = (unsigned long)regs->eip;
-    unsigned long fixup = search_one_table(
+    unsigned long fixup = search_one_extable(
         __start___pre_ex_table, __stop___pre_ex_table-1, addr);
     if ( fixup )
     {
diff --git a/xen/common/xsplice.c b/xen/common/xsplice.c
index 49f0d6e..834fda3 100644
--- a/xen/common/xsplice.c
+++ b/xen/common/xsplice.c
@@ -510,6 +510,25 @@ static int prepare_payload(struct payload *payload,
         if ( !(region->priv & CHECKING_BUG_FRAME) )
             region->priv |= CHECKING_BUG_FRAME;
     }
+#ifdef CONFIG_X86
+    sec = xsplice_elf_sec_by_name(elf, ".ex_table");
+    if ( sec )
+    {
+        if ( !sec->sec->sh_size ||
+             (sec->sec->sh_size % sizeof (struct exception_table_entry)) )
+        {
+            dprintk(XENLOG_DEBUG, "%s%s: Wrong size of .ex_table (exp:%lu vs 
%lu)!\n",
+                    XSPLICE, elf->name, sizeof (struct exception_table_entry),
+                    sec->sec->sh_size);
+            return -EINVAL;
+        }
+        region->ex = (struct exception_table_entry *)sec->load_addr;
+        region->ex_end = (struct exception_table_entry *)(sec->load_addr + 
sec->sec->sh_size);
+
+        sort_exception_table(region->ex, region->ex_end);
+        region->priv |= CHECKING_EXCEPTION;
+    }
+#endif
     return 0;
 }
 
diff --git a/xen/include/asm-x86/uaccess.h b/xen/include/asm-x86/uaccess.h
index 947470d..9e67bf0 100644
--- a/xen/include/asm-x86/uaccess.h
+++ b/xen/include/asm-x86/uaccess.h
@@ -276,6 +276,11 @@ extern struct exception_table_entry 
__start___pre_ex_table[];
 extern struct exception_table_entry __stop___pre_ex_table[];
 
 extern unsigned long search_exception_table(unsigned long);
+extern unsigned long search_one_extable(const struct exception_table_entry 
*first,
+                                        const struct exception_table_entry 
*last,
+                                        unsigned long value);
 extern void sort_exception_tables(void);
+extern void sort_exception_table(struct exception_table_entry *start,
+                                 struct exception_table_entry *stop);
 
 #endif /* __X86_UACCESS_H__ */
-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

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