All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: xen-devel@lists.xenproject.org
Cc: andrew.cooper3@citrix.com, julien.grall@arm.com,
	sstabellini@kernel.org, JBeulich@suse.com,
	Stefano Stabellini <stefanos@xilinx.com>
Subject: [PATCH v8 2/7] xen: use start_, end_, and more
Date: Tue, 15 Jan 2019 15:35:53 -0800	[thread overview]
Message-ID: <1547595358-16379-2-git-send-email-sstabellini@kernel.org> (raw)
In-Reply-To: <wt35AlsJdPHayD9a>

Start making use of the following uintptr_t variables:

start_, end_, stext_, etext_, stextentry_, etextentry_,
srodata_, erodata_, _sinittext, _einittext

Replacing the corresponding linker symbols. It is done to avoid
comparing and subtracting pointers pointing to different objects.

This patch carries one functional change: core.start/end and
core_init.start/end are now initialized in setup_virtual_regions,
because stext_ & friends are not constant anymore (initializer element
is not constant).

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
---
Changes in v8:
- remove SYMBOL_HIDE
- use new symbol names
- changes are split differently across the patches
---
 xen/arch/arm/alternative.c          |  6 +++---
 xen/arch/arm/arm32/livepatch.c      |  3 ++-
 xen/arch/arm/arm64/livepatch.c      |  3 ++-
 xen/arch/arm/domain_build.c         |  2 +-
 xen/arch/arm/livepatch.c            |  5 +++--
 xen/arch/arm/setup.c                |  5 +++--
 xen/arch/x86/setup.c                | 17 ++++++++---------
 xen/arch/x86/smpboot.c              |  7 ++++---
 xen/arch/x86/tboot.c                |  4 ++--
 xen/arch/x86/x86_64/machine_kexec.c |  4 ++--
 xen/common/symbols.c                |  3 +--
 xen/common/virtual_region.c         |  9 +++++----
 xen/include/asm-arm/grant_table.h   |  2 +-
 xen/include/asm-arm/mm.h            |  4 ++--
 xen/include/asm-x86/mm.h            |  2 +-
 xen/include/xen/kernel.h            | 32 ++++++++++++++++----------------
 16 files changed, 56 insertions(+), 52 deletions(-)

diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c
index 52ed7ed..b79536d 100644
--- a/xen/arch/arm/alternative.c
+++ b/xen/arch/arm/alternative.c
@@ -187,8 +187,8 @@ static int __apply_alternatives_multi_stop(void *unused)
     {
         int ret;
         struct alt_region region;
-        mfn_t xen_mfn = virt_to_mfn(_start);
-        paddr_t xen_size = _end - _start;
+        mfn_t xen_mfn = virt_to_mfn(start_);
+        paddr_t xen_size = end_ - start_;
         unsigned int xen_order = get_order_from_bytes(xen_size);
         void *xenmap;
 
@@ -206,7 +206,7 @@ static int __apply_alternatives_multi_stop(void *unused)
         region.begin = __alt_instructions;
         region.end = __alt_instructions_end;
 
-        ret = __apply_alternatives(&region, xenmap - (void *)_start);
+        ret = __apply_alternatives(&region, (uintptr_t)xenmap - start_);
         /* The patching is not expected to fail during boot. */
         BUG_ON(ret != 0);
 
diff --git a/xen/arch/arm/arm32/livepatch.c b/xen/arch/arm/arm32/livepatch.c
index 41378a5..db9a3f4 100644
--- a/xen/arch/arm/arm32/livepatch.c
+++ b/xen/arch/arm/arm32/livepatch.c
@@ -56,7 +56,8 @@ void arch_livepatch_apply(struct livepatch_func *func)
     else
         insn = 0xe1a00000; /* mov r0, r0 */
 
-    new_ptr = func->old_addr - (void *)_start + vmap_of_xen_text;
+    new_ptr = (uint32_t *)((uintptr_t)func->old_addr -
+              start_ + (uintptr_t)vmap_of_xen_text);
     len = len / sizeof(uint32_t);
 
     /* PATCH! */
diff --git a/xen/arch/arm/arm64/livepatch.c b/xen/arch/arm/arm64/livepatch.c
index 2247b92..a18d25d 100644
--- a/xen/arch/arm/arm64/livepatch.c
+++ b/xen/arch/arm/arm64/livepatch.c
@@ -43,7 +43,8 @@ void arch_livepatch_apply(struct livepatch_func *func)
     /* Verified in livepatch_verify_distance. */
     ASSERT(insn != AARCH64_BREAK_FAULT);
 
-    new_ptr = func->old_addr - (void *)_start + vmap_of_xen_text;
+    new_ptr = (uint32_t *)((uintptr_t)func->old_addr -
+              start_ + (uintptr_t)vmap_of_xen_text);
     len = len / sizeof(uint32_t);
 
     /* PATCH! */
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index d2c63a8..455b0f2 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -1904,7 +1904,7 @@ static void __init find_gnttab_region(struct domain *d,
      * Only use the text section as it's always present and will contain
      * enough space for a large grant table
      */
-    kinfo->gnttab_start = __pa(_stext);
+    kinfo->gnttab_start = __pa(stext_);
     kinfo->gnttab_size = gnttab_dom0_frames() << PAGE_SHIFT;
 
 #ifdef CONFIG_ARM_32
diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c
index 279d52c..3f12c8e 100644
--- a/xen/arch/arm/livepatch.c
+++ b/xen/arch/arm/livepatch.c
@@ -27,7 +27,7 @@ int arch_livepatch_quiesce(void)
         return -EINVAL;
 
     text_mfn = virt_to_mfn(_start);
-    text_order = get_order_from_bytes(_end - _start);
+    text_order = get_order_from_bytes(end_ - start_);
 
     /*
      * The text section is read-only. So re-map Xen to be able to patch
@@ -78,7 +78,8 @@ void arch_livepatch_revert(const struct livepatch_func *func)
     uint32_t *new_ptr;
     unsigned int len;
 
-    new_ptr = func->old_addr - (void *)_start + vmap_of_xen_text;
+    new_ptr = (uint32_t *)((uintptr_t)func->old_addr -
+              start_ + (uintptr_t)vmap_of_xen_text);
 
     len = livepatch_insn_len(func);
     memcpy(new_ptr, func->opaque, len);
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 444857a..83e29ff 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -772,8 +772,9 @@ void __init start_xen(unsigned long boot_phys_offset,
 
     /* Register Xen's load address as a boot module. */
     xen_bootmodule = add_boot_module(BOOTMOD_XEN,
-                             (paddr_t)(uintptr_t)(_start + boot_phys_offset),
-                             (paddr_t)(uintptr_t)(_end - _start + 1), false);
+                                     start_ + boot_phys_offset,
+                                     end_ - start_ + 1,
+                                     false);
     BUG_ON(!xen_bootmodule);
 
     setup_pagetables(boot_phys_offset);
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 06eb483..34949fc4 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -971,8 +971,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
          * This needs to remain in sync with xen_in_range() and the
          * respective reserve_e820_ram() invocation below.
          */
-        mod[mbi->mods_count].mod_start = virt_to_mfn(_stext);
-        mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext;
+        mod[mbi->mods_count].mod_start = virt_to_mfn(stext_);
+        mod[mbi->mods_count].mod_end = (uintptr_t)__2M_rwdata_end - stext_;
     }
 
     modules_headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end);
@@ -1039,7 +1039,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
          * Is the region size greater than zero and does it begin
          * at or above the end of current Xen image placement?
          */
-        if ( (end > s) && (end - reloc_size + XEN_IMG_OFFSET >= __pa(_end)) )
+        if ( (end > s) && (end - reloc_size + XEN_IMG_OFFSET >= __pa(end_)) )
         {
             l4_pgentry_t *pl4e;
             l3_pgentry_t *pl3e;
@@ -1067,7 +1067,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
              * data until after we have switched to the relocated pagetables!
              */
             barrier();
-            move_memory(e + XEN_IMG_OFFSET, XEN_IMG_OFFSET, _end - _start, 1);
+            move_memory(e + XEN_IMG_OFFSET, XEN_IMG_OFFSET, end_ - start_, 1);
 
             /* Walk initial pagetables, relocating page directory entries. */
             pl4e = __va(__pa(idle_pg_table));
@@ -1108,8 +1108,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
              * is contained in this PTE.
              */
             BUG_ON(using_2M_mapping() &&
-                   l2_table_offset((unsigned long)_erodata) ==
-                   l2_table_offset((unsigned long)_stext));
+                   l2_table_offset(erodata_) == l2_table_offset(stext_));
             *pl2e++ = l2e_from_pfn(xen_phys_start >> PAGE_SHIFT,
                                    PAGE_HYPERVISOR_RX | _PAGE_PSE);
             for ( i = 1; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
@@ -1239,7 +1238,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         panic("Not enough memory to relocate Xen\n");
 
     /* This needs to remain in sync with xen_in_range(). */
-    reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end));
+    reserve_e820_ram(&boot_e820, __pa(stext_), __pa(__2M_rwdata_end));
 
     /* Late kexec reservation (dynamic start address). */
     kexec_reserve_area(&boot_e820);
@@ -1382,7 +1381,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     }
 #endif
 
-    xen_virt_end = ((unsigned long)_end + (1UL << L2_PAGETABLE_SHIFT) - 1) &
+    xen_virt_end = (end_ + (1UL << L2_PAGETABLE_SHIFT) - 1) &
                    ~((1UL << L2_PAGETABLE_SHIFT) - 1);
     destroy_xen_mappings(xen_virt_end, XEN_VIRT_START + BOOTSTRAP_MAP_BASE);
 
@@ -1871,7 +1870,7 @@ int __hwdom_init xen_in_range(unsigned long mfn)
          */
 
         /* hypervisor .text + .rodata */
-        xen_regions[region_ro].s = __pa(&_stext);
+        xen_regions[region_ro].s = __pa(stext_);
         xen_regions[region_ro].e = __pa(&__2M_rodata_end);
         /* hypervisor .data + .bss */
         xen_regions[region_rw].s = __pa(&__2M_rwdata_start);
diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c
index 7d1226d..44fae91 100644
--- a/xen/arch/x86/smpboot.c
+++ b/xen/arch/x86/smpboot.c
@@ -782,7 +782,7 @@ DEFINE_PER_CPU(root_pgentry_t *, root_pgt);
 
 static root_pgentry_t common_pgt;
 
-extern const char _stextentry[], _etextentry[];
+extern uintptr_t stextentry_, etextentry_;
 
 static int setup_cpu_root_pgt(unsigned int cpu)
 {
@@ -810,8 +810,9 @@ static int setup_cpu_root_pgt(unsigned int cpu)
     {
         const char *ptr;
 
-        for ( rc = 0, ptr = _stextentry;
-              !rc && ptr < _etextentry; ptr += PAGE_SIZE )
+        for ( rc = 0, ptr = (const char *)stextentry_;
+              !rc && (uintptr_t)ptr < etextentry_;
+              ptr += PAGE_SIZE )
             rc = clone_mapping(ptr, rpt);
 
         if ( rc )
diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c
index f3fdee4..620303e 100644
--- a/xen/arch/x86/tboot.c
+++ b/xen/arch/x86/tboot.c
@@ -373,9 +373,9 @@ void tboot_shutdown(uint32_t shutdown_type)
         g_tboot_shared->mac_regions[0].size = bootsym_phys(trampoline_end) -
                                               bootsym_phys(trampoline_start);
         /* hypervisor .text + .rodata */
-        g_tboot_shared->mac_regions[1].start = (uint64_t)__pa(&_stext);
+        g_tboot_shared->mac_regions[1].start = (uint64_t)__pa(stext_);
         g_tboot_shared->mac_regions[1].size = __pa(&__2M_rodata_end) -
-                                              __pa(&_stext);
+                                              __pa(stext_);
         /* hypervisor .data + .bss */
         g_tboot_shared->mac_regions[2].start = (uint64_t)__pa(&__2M_rwdata_start);
         g_tboot_shared->mac_regions[2].size = __pa(&__2M_rwdata_end) -
diff --git a/xen/arch/x86/x86_64/machine_kexec.c b/xen/arch/x86/x86_64/machine_kexec.c
index f4a005c..cf435ac 100644
--- a/xen/arch/x86/x86_64/machine_kexec.c
+++ b/xen/arch/x86/x86_64/machine_kexec.c
@@ -13,8 +13,8 @@
 
 int machine_kexec_get_xen(xen_kexec_range_t *range)
 {
-        range->start = virt_to_maddr(_start);
-        range->size = virt_to_maddr(_end) - (unsigned long)range->start;
+        range->start = virt_to_maddr(start_);
+        range->size = virt_to_maddr(end_) - (unsigned long)range->start;
         return 0;
 }
 
diff --git a/xen/common/symbols.c b/xen/common/symbols.c
index 9377f41..b6cf0dd 100644
--- a/xen/common/symbols.c
+++ b/xen/common/symbols.c
@@ -149,8 +149,7 @@ const char *symbols_lookup(unsigned long addr,
 
     /* if we found no next symbol, we use the end of the section */
     if (!symbol_end)
-        symbol_end = is_kernel_inittext(addr) ?
-            (unsigned long)_einittext : (unsigned long)_etext;
+        symbol_end = is_kernel_inittext(addr) ? einittext_ : etext_;
 
     *symbolsize = symbol_end - symbols_address(low);
     *offset = addr - symbols_address(low);
diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c
index aa23918..1637453 100644
--- a/xen/common/virtual_region.c
+++ b/xen/common/virtual_region.c
@@ -10,15 +10,11 @@
 
 static struct virtual_region core = {
     .list = LIST_HEAD_INIT(core.list),
-    .start = _stext,
-    .end = _etext,
 };
 
 /* Becomes irrelevant when __init sections are cleared. */
 static struct virtual_region core_init __initdata = {
     .list = LIST_HEAD_INIT(core_init.list),
-    .start = _sinittext,
-    .end = _einittext,
 };
 
 /*
@@ -114,6 +110,11 @@ void __init setup_virtual_regions(const struct exception_table_entry *start,
         NULL
     };
 
+    core.start = (char *)start_;
+    core.end = (char *)end_;
+    core_init.start = (char *)sinittext_;
+    core_init.end = (char *)einittext_;
+
     for ( i = 1; bug_frames[i]; i++ )
     {
         const struct bug_frame *s;
diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_table.h
index 816e3c6..74a8ef4 100644
--- a/xen/include/asm-arm/grant_table.h
+++ b/xen/include/asm-arm/grant_table.h
@@ -31,7 +31,7 @@ void gnttab_mark_dirty(struct domain *d, mfn_t mfn);
  * enough space for a large grant table
  */
 #define gnttab_dom0_frames()                                             \
-    min_t(unsigned int, opt_max_grant_frames, PFN_DOWN(_etext - _stext))
+    min_t(unsigned int, opt_max_grant_frames, PFN_DOWN(etext_ - stext_))
 
 #define gnttab_init_arch(gt)                                             \
 ({                                                                       \
diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h
index eafa26f..e72ffb2 100644
--- a/xen/include/asm-arm/mm.h
+++ b/xen/include/asm-arm/mm.h
@@ -151,8 +151,8 @@ extern vaddr_t xenheap_virt_start;
 #endif
 
 #define is_xen_fixed_mfn(mfn)                                   \
-    ((pfn_to_paddr(mfn) >= virt_to_maddr(&_start)) &&       \
-     (pfn_to_paddr(mfn) <= virt_to_maddr(&_end)))
+    ((pfn_to_paddr(mfn) >= virt_to_maddr(&start_)) &&       \
+     (pfn_to_paddr(mfn) <= virt_to_maddr(&end_)))
 
 #define page_get_owner(_p)    (_p)->v.inuse.domain
 #define page_set_owner(_p,_d) ((_p)->v.inuse.domain = (_d))
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index 6faa563..3b07d12 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -280,7 +280,7 @@ struct page_info
 #define is_xen_heap_mfn(mfn) \
     (__mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(_mfn(mfn))))
 #define is_xen_fixed_mfn(mfn)                     \
-    ((((mfn) << PAGE_SHIFT) >= __pa(&_stext)) &&  \
+    ((((mfn) << PAGE_SHIFT) >= __pa(stext_)) &&  \
      (((mfn) << PAGE_SHIFT) <= __pa(&__2M_rwdata_end)))
 
 #define PRtype_info "016lx"/* should only be used for printk's */
diff --git a/xen/include/xen/kernel.h b/xen/include/xen/kernel.h
index 548b64d..78643a9 100644
--- a/xen/include/xen/kernel.h
+++ b/xen/include/xen/kernel.h
@@ -65,28 +65,28 @@
 	1;                                      \
 })
 
-extern char _start[], _end[], start[];
-#define is_kernel(p) ({                         \
-    char *__p = (char *)(unsigned long)(p);     \
-    (__p >= _start) && (__p < _end);            \
+extern uintptr_t start_, end_;
+#define is_kernel(p) ({                                             \
+    const uintptr_t p__ = (const uintptr_t)(p);                     \
+    (p__ >= start_) && (p__ < end_);      \
 })
 
-extern char _stext[], _etext[];
-#define is_kernel_text(p) ({                    \
-    char *__p = (char *)(unsigned long)(p);     \
-    (__p >= _stext) && (__p < _etext);          \
+extern uintptr_t stext_, etext_;
+#define is_kernel_text(p) ({                                        \
+    const uintptr_t p__ = (const uintptr_t)(p);                     \
+    (p__ >= stext_) && (p__ < etext_);                              \
 })
 
-extern const char _srodata[], _erodata[];
-#define is_kernel_rodata(p) ({                  \
-    const char *__p = (const char *)(unsigned long)(p);     \
-    (__p >= _srodata) && (__p < _erodata);      \
+extern uintptr_t srodata_, erodata_;
+#define is_kernel_rodata(p) ({                                      \
+    const uintptr_t p__ = (const uintptr_t)(p);                     \
+    (p__ >= srodata_) && (p__ < erodata_);                          \
 })
 
-extern char _sinittext[], _einittext[];
-#define is_kernel_inittext(p) ({                \
-    char *__p = (char *)(unsigned long)(p);     \
-    (__p >= _sinittext) && (__p < _einittext);  \
+extern uintptr_t sinittext_, einittext_;
+#define is_kernel_inittext(p) ({                                         \
+    const uintptr_t p__ = (const uintptr_t)(p);                          \
+    (p__ >= sinittext_) && (p__ < einittext_);                           \
 })
 
 extern enum system_state {
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-01-15 23:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <wt35AlsJdPHayD9a>
2019-01-15 23:35 ` [PATCH v8 1/7] xen: add assembly variables corresponding to linker symbols Stefano Stabellini
2019-01-17 16:12   ` Jan Beulich
2019-01-15 23:35 ` Stefano Stabellini [this message]
2019-01-17 16:24   ` [PATCH v8 2/7] xen: use start_, end_, and more Jan Beulich
2019-01-15 23:35 ` [PATCH v8 3/7] xen/x86: use rodata_start_2M_, init_start_2M_, " Stefano Stabellini
2019-01-15 23:35 ` [PATCH v8 4/7] xen: use initcall_start_, ctors_start_, " Stefano Stabellini
2019-01-17 16:07   ` Jan Beulich
2019-01-15 23:35 ` [PATCH v8 5/7] xen: use per_cpu_start_, start_bug_frames_, " Stefano Stabellini
2019-01-15 23:35 ` [PATCH v8 6/7] xen/arm: use alt_instructions_, sdevice_, " Stefano Stabellini
2019-01-15 23:35 ` [PATCH v8 7/7] xen/arm: use alt_instructions_, trampoline_rel_start_, start_vpci_array_, " Stefano Stabellini
2019-01-17 15:58   ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1547595358-16379-2-git-send-email-sstabellini@kernel.org \
    --to=sstabellini@kernel.org \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=julien.grall@arm.com \
    --cc=stefanos@xilinx.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.