All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v8 1/7] xen: add assembly variables corresponding to linker symbols
       [not found] <wt35AlsJdPHayD9a>
@ 2019-01-15 23:35 ` Stefano Stabellini
  2019-01-17 16:12   ` Jan Beulich
  2019-01-15 23:35 ` [PATCH v8 2/7] xen: use start_, end_, and more Stefano Stabellini
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Stefano Stabellini @ 2019-01-15 23:35 UTC (permalink / raw)
  To: xen-devel
  Cc: andrew.cooper3, julien.grall, sstabellini, JBeulich, Stefano Stabellini

Allocate one assembly variable for each linker symbol to be used from C.
Next patches will make use of these variables, by replacing the usage of
the corresponding linker symbols group by group.

The new variables are intended to be integer types (uintptr_t), not
pointers, to avoid comparisons and subtractions between pointers
pointing to different objects.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
---
Changes in v8:
- new patch
---
 xen/arch/arm/arm32/Makefile  |  1 +
 xen/arch/arm/arm32/var.S     | 72 ++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile  |  1 +
 xen/arch/arm/arm64/var.S     | 72 ++++++++++++++++++++++++++++++++++
 xen/arch/x86/x86_64/Makefile |  1 +
 xen/arch/x86/x86_64/var.S    | 92 ++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 239 insertions(+)
 create mode 100644 xen/arch/arm/arm32/var.S
 create mode 100644 xen/arch/arm/arm64/var.S
 create mode 100644 xen/arch/x86/x86_64/var.S

diff --git a/xen/arch/arm/arm32/Makefile b/xen/arch/arm/arm32/Makefile
index 0ac254f..983fb82 100644
--- a/xen/arch/arm/arm32/Makefile
+++ b/xen/arch/arm/arm32/Makefile
@@ -10,4 +10,5 @@ obj-y += proc-v7.o proc-caxx.o
 obj-y += smpboot.o
 obj-y += traps.o
 obj-y += vfp.o
+obj-y += var.o
 
diff --git a/xen/arch/arm/arm32/var.S b/xen/arch/arm/arm32/var.S
new file mode 100644
index 0000000..69e5b04
--- /dev/null
+++ b/xen/arch/arm/arm32/var.S
@@ -0,0 +1,72 @@
+GLOBAL(start_)
+  .long  _start
+GLOBAL(end_)
+  .long  _end
+GLOBAL(init_begin_)
+  .long __init_begin
+GLOBAL(init_end_)
+  .long __init_end
+GLOBAL(stext_)
+  .long _stext
+GLOBAL(etext_)
+  .long _etext
+GLOBAL(alt_instructions_)
+  .long __alt_instructions
+GLOBAL(alt_instructions_end_)
+  .long __alt_instructions_end
+GLOBAL(per_cpu_start_)
+  .long __per_cpu_start
+GLOBAL(per_cpu_data_end_)
+  .long __per_cpu_data_end
+GLOBAL(splatform_)
+  .long _splatform
+GLOBAL(eplatform_)
+  .long _eplatform
+GLOBAL(sdevice_)
+  .long _sdevice
+GLOBAL(edevice_)
+  .long _edevice
+GLOBAL(asdevice_)
+  .long _asdevice
+GLOBAL(aedevice_)
+  .long _aedevice
+GLOBAL(srodata_)
+  .long _srodata
+GLOBAL(erodata_)
+  .long _erodata
+GLOBAL(sinittext_)
+  .long _sinittext
+GLOBAL(einittext_)
+  .long _einittext
+GLOBAL(note_gnu_build_id_start_)
+  .long __note_gnu_build_id_start
+GLOBAL(note_gnu_build_id_end_)
+  .long __note_gnu_build_id_end
+#ifdef CONFIG_LOCK_PROFILE
+GLOBAL(lock_profile_start_)
+  .long __lock_profile_start
+GLOBAL(lock_profile_end_)
+  .long __lock_profile_end
+#endif
+GLOBAL(initcall_start_)
+  .long __initcall_start
+GLOBAL(initcall_end_)
+  .long __initcall_end
+GLOBAL(presmp_initcall_end_)
+  .long __presmp_initcall_end
+GLOBAL(ctors_start_)
+  .long __ctors_start
+GLOBAL(ctors_end_)
+  .long __ctors_end
+GLOBAL(end_schedulers_array_)
+  .long __end_schedulers_array
+GLOBAL(start_schedulers_array_)
+  .long __start_schedulers_array
+GLOBAL(start_bug_frames_)
+  .long __start_bug_frames
+GLOBAL(stop_bug_frames_0_)
+  .long __stop_bug_frames_0
+GLOBAL(stop_bug_frames_1_)
+  .long __stop_bug_frames_1
+GLOBAL(stop_bug_frames_2_)
+  .long __stop_bug_frames_2
diff --git a/xen/arch/arm/arm64/Makefile b/xen/arch/arm/arm64/Makefile
index c4f3a28..a5d9558 100644
--- a/xen/arch/arm/arm64/Makefile
+++ b/xen/arch/arm/arm64/Makefile
@@ -13,3 +13,4 @@ obj-y += smpboot.o
 obj-y += traps.o
 obj-y += vfp.o
 obj-y += vsysreg.o
+obj-y += var.o
diff --git a/xen/arch/arm/arm64/var.S b/xen/arch/arm/arm64/var.S
new file mode 100644
index 0000000..30ef0c2
--- /dev/null
+++ b/xen/arch/arm/arm64/var.S
@@ -0,0 +1,72 @@
+GLOBAL(start_)
+  .quad  _start
+GLOBAL(end_)
+  .quad  _end
+GLOBAL(init_begin_)
+  .quad __init_begin
+GLOBAL(init_end_)
+  .quad __init_end
+GLOBAL(stext_)
+  .quad _stext
+GLOBAL(etext_)
+  .quad _etext
+GLOBAL(alt_instructions_)
+  .quad __alt_instructions
+GLOBAL(alt_instructions_end_)
+  .quad __alt_instructions_end
+GLOBAL(per_cpu_start_)
+  .quad __per_cpu_start
+GLOBAL(per_cpu_data_end_)
+  .quad __per_cpu_data_end
+GLOBAL(splatform_)
+  .quad _splatform
+GLOBAL(eplatform_)
+  .quad _eplatform
+GLOBAL(sdevice_)
+  .quad _sdevice
+GLOBAL(edevice_)
+  .quad _edevice
+GLOBAL(asdevice_)
+  .quad _asdevice
+GLOBAL(aedevice_)
+  .quad _aedevice
+GLOBAL(srodata_)
+  .quad _srodata
+GLOBAL(erodata_)
+  .quad _erodata
+GLOBAL(sinittext_)
+  .quad _sinittext
+GLOBAL(einittext_)
+  .quad _einittext
+GLOBAL(note_gnu_build_id_start_)
+  .quad __note_gnu_build_id_start
+GLOBAL(note_gnu_build_id_end_)
+  .quad __note_gnu_build_id_end
+#ifdef CONFIG_LOCK_PROFILE
+GLOBAL(lock_profile_start_)
+  .quad __lock_profile_start
+GLOBAL(lock_profile_end_)
+  .quad __lock_profile_end
+#endif
+GLOBAL(initcall_start_)
+  .quad __initcall_start
+GLOBAL(initcall_end_)
+  .quad __initcall_end
+GLOBAL(presmp_initcall_end_)
+  .quad __presmp_initcall_end
+GLOBAL(ctors_start_)
+  .quad __ctors_start
+GLOBAL(ctors_end_)
+  .quad __ctors_end
+GLOBAL(end_schedulers_array_)
+  .quad __end_schedulers_array
+GLOBAL(start_schedulers_array_)
+  .quad __start_schedulers_array
+GLOBAL(start_bug_frames_)
+  .quad __start_bug_frames
+GLOBAL(stop_bug_frames_0_)
+  .quad __stop_bug_frames_0
+GLOBAL(stop_bug_frames_1_)
+  .quad __stop_bug_frames_1
+GLOBAL(stop_bug_frames_2_)
+  .quad __stop_bug_frames_2
diff --git a/xen/arch/x86/x86_64/Makefile b/xen/arch/x86/x86_64/Makefile
index 4bfa148..e9a94cb 100644
--- a/xen/arch/x86/x86_64/Makefile
+++ b/xen/arch/x86/x86_64/Makefile
@@ -1,6 +1,7 @@
 subdir-$(CONFIG_PV) += compat
 
 obj-bin-y += entry.o
+obj-bin-y += var.o
 obj-y += traps.o
 obj-$(CONFIG_KEXEC) += machine_kexec.o
 obj-y += pci.o
diff --git a/xen/arch/x86/x86_64/var.S b/xen/arch/x86/x86_64/var.S
new file mode 100644
index 0000000..6da54a5
--- /dev/null
+++ b/xen/arch/x86/x86_64/var.S
@@ -0,0 +1,92 @@
+GLOBAL(start_)
+  .quad  _start
+GLOBAL(end_)
+  .quad  _end
+GLOBAL(rwdata_start_2M_)
+  .quad __2M_rwdata_start
+GLOBAL(rwdata_end_2M_)
+  .quad __2M_rwdata_end 
+GLOBAL(rodata_start_2M_)
+  .quad __2M_rodata_start
+GLOBAL(rodata_end_2M_)
+  .quad __2M_rodata_end 
+GLOBAL(text_end_2M_)
+  .quad __2M_text_end 
+GLOBAL(init_start_2M_)
+  .quad __2M_init_start
+GLOBAL(init_end_2M_)
+  .quad __2M_init_end 
+GLOBAL(init_begin_)
+  .quad __init_begin
+GLOBAL(init_end_)
+  .quad __init_end
+GLOBAL(stext_)
+  .quad _stext
+GLOBAL(etext_)
+  .quad _etext
+GLOBAL(alt_instructions_)
+  .quad __alt_instructions
+GLOBAL(alt_instructions_end_)
+  .quad __alt_instructions_end
+GLOBAL(end_vpci_array_)
+  .quad __end_vpci_array
+GLOBAL(start_vpci_array_)
+  .quad __start_vpci_array
+GLOBAL(stextentry_)
+  .quad _stextentry 
+GLOBAL(etextentry_)
+  .quad _etextentry 
+GLOBAL(trampoline_rel_start_)
+  .quad __trampoline_rel_start 
+GLOBAL(trampoline_rel_stop_)
+  .quad __trampoline_rel_stop 
+GLOBAL(trampoline_seg_start_)
+  .quad __trampoline_seg_start 
+GLOBAL(trampoline_seg_stop_)
+  .quad __trampoline_seg_stop 
+GLOBAL(per_cpu_start_)
+  .quad __per_cpu_start
+GLOBAL(per_cpu_data_end_)
+  .quad __per_cpu_data_end
+GLOBAL(srodata_)
+  .quad _srodata
+GLOBAL(erodata_)
+  .quad _erodata
+GLOBAL(sinittext_)
+  .quad _sinittext
+GLOBAL(einittext_)
+  .quad _einittext
+GLOBAL(note_gnu_build_id_start_)
+  .quad __note_gnu_build_id_start
+GLOBAL(note_gnu_build_id_end_)
+  .quad __note_gnu_build_id_end
+#ifdef CONFIG_LOCK_PROFILE
+GLOBAL(lock_profile_start_)
+  .quad __lock_profile_start
+GLOBAL(lock_profile_end_)
+  .quad __lock_profile_end
+#endif
+GLOBAL(initcall_start_)
+  .quad __initcall_start
+GLOBAL(initcall_end_)
+  .quad __initcall_end
+GLOBAL(presmp_initcall_end_)
+  .quad __presmp_initcall_end
+GLOBAL(ctors_start_)
+  .quad __ctors_start
+GLOBAL(ctors_end_)
+  .quad __ctors_end
+GLOBAL(end_schedulers_array_)
+  .quad __end_schedulers_array
+GLOBAL(start_schedulers_array_)
+  .quad __start_schedulers_array
+GLOBAL(start_bug_frames_)
+  .quad __start_bug_frames
+GLOBAL(stop_bug_frames_0_)
+  .quad __stop_bug_frames_0
+GLOBAL(stop_bug_frames_1_)
+  .quad __stop_bug_frames_1
+GLOBAL(stop_bug_frames_2_)
+  .quad __stop_bug_frames_2
+GLOBAL(stop_bug_frames_3_)
+  .quad __stop_bug_frames_3
-- 
1.9.1


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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v8 2/7] xen: use start_, end_, and more
       [not found] <wt35AlsJdPHayD9a>
  2019-01-15 23:35 ` [PATCH v8 1/7] xen: add assembly variables corresponding to linker symbols Stefano Stabellini
@ 2019-01-15 23:35 ` Stefano Stabellini
  2019-01-17 16:24   ` Jan Beulich
  2019-01-15 23:35 ` [PATCH v8 3/7] xen/x86: use rodata_start_2M_, init_start_2M_, " Stefano Stabellini
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Stefano Stabellini @ 2019-01-15 23:35 UTC (permalink / raw)
  To: xen-devel
  Cc: andrew.cooper3, julien.grall, sstabellini, JBeulich, Stefano Stabellini

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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v8 3/7] xen/x86: use rodata_start_2M_, init_start_2M_, and more
       [not found] <wt35AlsJdPHayD9a>
  2019-01-15 23:35 ` [PATCH v8 1/7] xen: add assembly variables corresponding to linker symbols Stefano Stabellini
  2019-01-15 23:35 ` [PATCH v8 2/7] xen: use start_, end_, and more Stefano Stabellini
@ 2019-01-15 23:35 ` Stefano Stabellini
  2019-01-15 23:35 ` [PATCH v8 4/7] xen: use initcall_start_, ctors_start_, " Stefano Stabellini
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Stefano Stabellini @ 2019-01-15 23:35 UTC (permalink / raw)
  To: xen-devel
  Cc: andrew.cooper3, julien.grall, sstabellini, JBeulich, Stefano Stabellini

Start making use of the following uintptr_t variables:

text_start_2M_, text_end_2M_, rodata_start_2M_, rodata_end_2M_,
init_start_2M_, init_end_2M_, rwdata_start_2M_, rwdata_end_2M_

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

These symbols are all x86 specific symbols.

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/x86/setup.c        | 60 ++++++++++++++++++++++-----------------------
 xen/arch/x86/tboot.c        |  8 +++---
 xen/include/asm-x86/mm.h    |  2 +-
 xen/include/asm-x86/setup.h |  8 +++---
 4 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 34949fc4..3a2aa4c 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -578,13 +578,13 @@ static void __init kexec_reserve_area(struct e820map *e820)
 
 static inline bool using_2M_mapping(void)
 {
-    return !l1_table_offset((unsigned long)__2M_text_end) &&
-           !l1_table_offset((unsigned long)__2M_rodata_start) &&
-           !l1_table_offset((unsigned long)__2M_rodata_end) &&
-           !l1_table_offset((unsigned long)__2M_init_start) &&
-           !l1_table_offset((unsigned long)__2M_init_end) &&
-           !l1_table_offset((unsigned long)__2M_rwdata_start) &&
-           !l1_table_offset((unsigned long)__2M_rwdata_end);
+    return !l1_table_offset(text_end_2M_) &&
+           !l1_table_offset(rodata_start_2M_) &&
+           !l1_table_offset(rodata_end_2M_) &&
+           !l1_table_offset(init_start_2M_) &&
+           !l1_table_offset(init_end_2M_) &&
+           !l1_table_offset(rwdata_start_2M_) &&
+           !l1_table_offset(rwdata_end_2M_);
 }
 
 static void noinline init_done(void)
@@ -606,8 +606,8 @@ static void noinline init_done(void)
     /* Destroy Xen's mappings, and reuse the pages. */
     if ( using_2M_mapping() )
     {
-        start = (unsigned long)&__2M_init_start,
-        end   = (unsigned long)&__2M_init_end;
+        start = init_start_2M_,
+        end   = init_end_2M_;
     }
     else
     {
@@ -972,7 +972,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
          * respective reserve_e820_ram() invocation below.
          */
         mod[mbi->mods_count].mod_start = virt_to_mfn(stext_);
-        mod[mbi->mods_count].mod_end = (uintptr_t)__2M_rwdata_end - stext_;
+        mod[mbi->mods_count].mod_end = rwdata_end_2M_ - stext_;
     }
 
     modules_headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end);
@@ -1023,7 +1023,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                      1UL << (PAGE_SHIFT + 32)) )
             e = min(HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START,
                     1UL << (PAGE_SHIFT + 32));
-#define reloc_size ((__pa(__2M_rwdata_end) + mask) & ~mask)
+#define reloc_size ((__pa(rwdata_end_2M_) + mask) & ~mask)
         /* Is the region suitable for relocating Xen? */
         if ( !xen_phys_start && e <= limit )
         {
@@ -1104,7 +1104,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
             /* The only data mappings to be relocated are in the Xen area. */
             pl2e = __va(__pa(l2_xenmap));
             /*
-             * Undo the temporary-hooking of the l1_identmap.  __2M_text_start
+             * Undo the temporary-hooking of the l1_identmap.  text_start_2M_
              * is contained in this PTE.
              */
             BUG_ON(using_2M_mapping() &&
@@ -1126,22 +1126,22 @@ void __init noreturn __start_xen(unsigned long mbi_p)
                     continue;
                 }
 
-                if ( i < l2_table_offset((unsigned long)&__2M_text_end) )
+                if ( i < l2_table_offset(text_end_2M_) )
                 {
                     flags = PAGE_HYPERVISOR_RX | _PAGE_PSE;
                 }
-                else if ( i >= l2_table_offset((unsigned long)&__2M_rodata_start) &&
-                          i <  l2_table_offset((unsigned long)&__2M_rodata_end) )
+                else if ( i >= l2_table_offset(rodata_start_2M_) &&
+                          i <  l2_table_offset(rodata_end_2M_) )
                 {
                     flags = PAGE_HYPERVISOR_RO | _PAGE_PSE;
                 }
-                else if ( i >= l2_table_offset((unsigned long)&__2M_init_start) &&
-                          i <  l2_table_offset((unsigned long)&__2M_init_end) )
+                else if ( i >= l2_table_offset(init_start_2M_) &&
+                          i <  l2_table_offset(init_end_2M_) )
                 {
                     flags = PAGE_HYPERVISOR_RWX | _PAGE_PSE;
                 }
-                else if ( (i >= l2_table_offset((unsigned long)&__2M_rwdata_start) &&
-                           i <  l2_table_offset((unsigned long)&__2M_rwdata_end)) )
+                else if ( (i >= l2_table_offset(rwdata_start_2M_) &&
+                           i <  l2_table_offset(rwdata_end_2M_)) )
                 {
                     flags = PAGE_HYPERVISOR_RW | _PAGE_PSE;
                 }
@@ -1238,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(rwdata_end_2M_));
 
     /* Late kexec reservation (dynamic start address). */
     kexec_reserve_area(&boot_e820);
@@ -1394,22 +1394,22 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     {
         /* Mark .text as RX (avoiding the first 2M superpage). */
         modify_xen_mappings(XEN_VIRT_START + MB(2),
-                            (unsigned long)&__2M_text_end,
+                            text_end_2M_,
                             PAGE_HYPERVISOR_RX);
 
         /* Mark .rodata as RO. */
-        modify_xen_mappings((unsigned long)&__2M_rodata_start,
-                            (unsigned long)&__2M_rodata_end,
+        modify_xen_mappings(rodata_start_2M_,
+                            rodata_end_2M_,
                             PAGE_HYPERVISOR_RO);
 
         /* Mark .data and .bss as RW. */
-        modify_xen_mappings((unsigned long)&__2M_rwdata_start,
-                            (unsigned long)&__2M_rwdata_end,
+        modify_xen_mappings(rwdata_start_2M_,
+                            rwdata_end_2M_,
                             PAGE_HYPERVISOR_RW);
 
         /* Drop the remaining mappings in the shattered superpage. */
-        destroy_xen_mappings((unsigned long)&__2M_rwdata_end,
-                             ROUNDUP((unsigned long)&__2M_rwdata_end, MB(2)));
+        destroy_xen_mappings(rwdata_end_2M_,
+                             ROUNDUP(rwdata_end_2M_, MB(2)));
     }
 
     nr_pages = 0;
@@ -1871,10 +1871,10 @@ int __hwdom_init xen_in_range(unsigned long mfn)
 
         /* hypervisor .text + .rodata */
         xen_regions[region_ro].s = __pa(stext_);
-        xen_regions[region_ro].e = __pa(&__2M_rodata_end);
+        xen_regions[region_ro].e = __pa(rodata_end_2M_);
         /* hypervisor .data + .bss */
-        xen_regions[region_rw].s = __pa(&__2M_rwdata_start);
-        xen_regions[region_rw].e = __pa(&__2M_rwdata_end);
+        xen_regions[region_rw].s = __pa(rwdata_start_2M_);
+        xen_regions[region_rw].e = __pa(rwdata_end_2M_);
     }
 
     start = (paddr_t)mfn << PAGE_SHIFT;
diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c
index 620303e..7c11cdb 100644
--- a/xen/arch/x86/tboot.c
+++ b/xen/arch/x86/tboot.c
@@ -374,12 +374,12 @@ void tboot_shutdown(uint32_t shutdown_type)
                                               bootsym_phys(trampoline_start);
         /* hypervisor .text + .rodata */
         g_tboot_shared->mac_regions[1].start = (uint64_t)__pa(stext_);
-        g_tboot_shared->mac_regions[1].size = __pa(&__2M_rodata_end) -
+        g_tboot_shared->mac_regions[1].size = __pa(rodata_end_2M_) -
                                               __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) -
-                                              __pa(&__2M_rwdata_start);
+        g_tboot_shared->mac_regions[2].start = (uint64_t)__pa(rwdata_start_2M_);
+        g_tboot_shared->mac_regions[2].size = __pa(rwdata_end_2M_) -
+                                              __pa(rwdata_start_2M_);
 
         /*
          * MAC domains and other Xen memory
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index 3b07d12..904e84b 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -281,7 +281,7 @@ struct page_info
     (__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(&__2M_rwdata_end)))
+     (((mfn) << PAGE_SHIFT) <= __pa(rwdata_end_2M_)))
 
 #define PRtype_info "016lx"/* should only be used for printk's */
 
diff --git a/xen/include/asm-x86/setup.h b/xen/include/asm-x86/setup.h
index bb4c385..d52bee2 100644
--- a/xen/include/asm-x86/setup.h
+++ b/xen/include/asm-x86/setup.h
@@ -7,10 +7,10 @@
 /* vCPU pointer used prior to there being a valid one around */
 #define INVALID_VCPU ((struct vcpu *)0xccccccccccccc000UL)
 
-extern const char __2M_text_start[], __2M_text_end[];
-extern const char __2M_rodata_start[], __2M_rodata_end[];
-extern char __2M_init_start[], __2M_init_end[];
-extern char __2M_rwdata_start[], __2M_rwdata_end[];
+extern uintptr_t text_start_2M_, text_end_2M_;
+extern uintptr_t rodata_start_2M_, rodata_end_2M_;
+extern uintptr_t init_start_2M_, init_end_2M_;
+extern uintptr_t rwdata_start_2M_, rwdata_end_2M_;
 
 extern unsigned long xenheap_initial_phys_start;
 
-- 
1.9.1


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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v8 4/7] xen: use initcall_start_, ctors_start_, and more
       [not found] <wt35AlsJdPHayD9a>
                   ` (2 preceding siblings ...)
  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 ` 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
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Stefano Stabellini @ 2019-01-15 23:35 UTC (permalink / raw)
  To: xen-devel
  Cc: andrew.cooper3, julien.grall, sstabellini, JBeulich, Stefano Stabellini

Start making use of the following uintptr_t variables:

initcall_start_, presmp_initcall_end_, initcall_end_, ctors_start_,
ctors_end_, start_schedulers_array_, end_schedulers_array_,
lock_profile_start_, lock_profile_end_, note_gnu_build_id_start_,
note_gnu_build_id_end_

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

The separation is a bit arbitrary, but all these symbols are used only
within the C source file where they are declared.

One meaningful change is in the calculation of NUM_SCHEDULERS.

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/common/kernel.c   | 11 +++++++----
 xen/common/lib.c      |  7 +++++--
 xen/common/schedule.c |  7 ++++---
 xen/common/spinlock.c |  8 +++++---
 xen/common/version.c  | 10 +++++-----
 5 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 5766a0f..7eea266 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -306,20 +306,23 @@ void add_taint(unsigned int flag)
     tainted |= flag;
 }
 
-extern const initcall_t __initcall_start[], __presmp_initcall_end[],
-    __initcall_end[];
+extern uintptr_t initcall_start_, presmp_initcall_end_, initcall_end_;
 
 void __init do_presmp_initcalls(void)
 {
     const initcall_t *call;
-    for ( call = __initcall_start; call < __presmp_initcall_end; call++ )
+    for ( call = (const initcall_t *)initcall_start_;
+          (uintptr_t)call < presmp_initcall_end_;
+          call++ )
         (*call)();
 }
 
 void __init do_initcalls(void)
 {
     const initcall_t *call;
-    for ( call = __presmp_initcall_end; call < __initcall_end; call++ )
+    for ( call = (const initcall_t *)presmp_initcall_end_;
+          (uintptr_t)call < initcall_end_;
+          call++ )
         (*call)();
 }
 
diff --git a/xen/common/lib.c b/xen/common/lib.c
index 8ebec81..e228b18 100644
--- a/xen/common/lib.c
+++ b/xen/common/lib.c
@@ -492,12 +492,15 @@ unsigned long long parse_size_and_unit(const char *s, const char **ps)
 }
 
 typedef void (*ctor_func_t)(void);
-extern const ctor_func_t __ctors_start[], __ctors_end[];
+extern uintptr_t ctors_start_, ctors_end_;
 
 void __init init_constructors(void)
 {
     const ctor_func_t *f;
-    for ( f = __ctors_start; f < __ctors_end; ++f )
+
+    for ( f = (const ctor_func_t *)ctors_start_;
+          (uintptr_t)f < ctors_end_;
+          ++f )
         (*f)();
 
     /* Putting this here seems as good (or bad) as any other place. */
diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index a957c5e..13b9558 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -67,9 +67,10 @@ DEFINE_PER_CPU(struct scheduler *, scheduler);
 /* Scratch space for cpumasks. */
 DEFINE_PER_CPU(cpumask_t, cpumask_scratch);
 
-extern const struct scheduler *__start_schedulers_array[], *__end_schedulers_array[];
-#define NUM_SCHEDULERS (__end_schedulers_array - __start_schedulers_array)
-#define schedulers __start_schedulers_array
+extern uintptr_t start_schedulers_array_, end_schedulers_array_;
+#define NUM_SCHEDULERS ((end_schedulers_array_ - start_schedulers_array_) \
+                        / sizeof(const struct scheduler *))
+#define schedulers ((struct scheduler **)start_schedulers_array_)
 
 static struct scheduler __read_mostly ops;
 
diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c
index 6bc52d7..766cdc1 100644
--- a/xen/common/spinlock.c
+++ b/xen/common/spinlock.c
@@ -318,8 +318,8 @@ struct lock_profile_anc {
 typedef void lock_profile_subfunc(
     struct lock_profile *, int32_t, int32_t, void *);
 
-extern struct lock_profile *__lock_profile_start;
-extern struct lock_profile *__lock_profile_end;
+extern uintptr_t lock_profile_start_;
+extern uintptr_t lock_profile_end_;
 
 static s_time_t lock_profile_start;
 static struct lock_profile_anc lock_profile_ancs[LOCKPROF_TYPE_N];
@@ -474,7 +474,9 @@ static int __init lock_prof_init(void)
 {
     struct lock_profile **q;
 
-    for ( q = &__lock_profile_start; q < &__lock_profile_end; q++ )
+    for ( q = (struct lock_profile **)lock_profile_start_;
+          (uintptr_t)q < lock_profile_end_;
+          q++ )
     {
         (*q)->next = lock_profile_glb_q.elem_q;
         lock_profile_glb_q.elem_q = *q;
diff --git a/xen/common/version.c b/xen/common/version.c
index 223cb52..246c96b 100644
--- a/xen/common/version.c
+++ b/xen/common/version.c
@@ -86,7 +86,7 @@ int xen_build_id(const void **p, unsigned int *len)
 
 #ifdef BUILD_ID
 /* Defined in linker script. */
-extern const Elf_Note __note_gnu_build_id_start[], __note_gnu_build_id_end[];
+extern uintptr_t note_gnu_build_id_start_, note_gnu_build_id_end_;
 
 int xen_build_id_check(const Elf_Note *n, unsigned int n_sz,
                        const void **p, unsigned int *len)
@@ -142,19 +142,19 @@ struct cv_info_pdb70
 
 static int __init xen_build_init(void)
 {
-    const Elf_Note *n = __note_gnu_build_id_start;
+    const Elf_Note *n = (const Elf_Note *)note_gnu_build_id_start_;
     unsigned int sz;
     int rc;
 
     /* --build-id invoked with wrong parameters. */
-    if ( __note_gnu_build_id_end <= &n[0] )
+    if ( note_gnu_build_id_end_ <= (uintptr_t)&n[0] )
         return -ENODATA;
 
     /* Check for full Note header. */
-    if ( &n[1] >= __note_gnu_build_id_end )
+    if ( (uintptr_t)&n[1] >= note_gnu_build_id_end_ )
         return -ENODATA;
 
-    sz = (void *)__note_gnu_build_id_end - (void *)n;
+    sz = note_gnu_build_id_end_ - (uintptr_t)n;
 
     rc = xen_build_id_check(n, sz, &build_id_p, &build_id_len);
 
-- 
1.9.1


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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v8 5/7] xen: use per_cpu_start_, start_bug_frames_, and more
       [not found] <wt35AlsJdPHayD9a>
                   ` (3 preceding siblings ...)
  2019-01-15 23:35 ` [PATCH v8 4/7] xen: use initcall_start_, ctors_start_, " Stefano Stabellini
@ 2019-01-15 23:35 ` 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
  6 siblings, 0 replies; 11+ messages in thread
From: Stefano Stabellini @ 2019-01-15 23:35 UTC (permalink / raw)
  To: xen-devel
  Cc: andrew.cooper3, julien.grall, sstabellini, JBeulich, Stefano Stabellini

Start making use of the following uintptr_t variables:

per_cpu_start_, per_cpu_data_end_, per_cpu_data_end_,
start_bug_frames_, stop_bug_frames_0_, stop_bug_frames_1_,
stop_bug_frames_2_, stop_bug_frames_3_

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

The separation is a bit arbitrary, but all these symbols are declared in
asm files.

One meaningful change is in the size calculation (sz variable) in
setup_virtual_regions, now it needs to take into account the size of the
struct pointer.

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/percpu.c        | 11 ++++++-----
 xen/arch/x86/percpu.c        | 10 +++++-----
 xen/common/virtual_region.c  | 18 +++++++++---------
 xen/include/asm-arm/bug.h    |  8 ++++----
 xen/include/asm-arm/percpu.h |  2 +-
 xen/include/asm-x86/bug.h    | 10 +++++-----
 xen/include/asm-x86/percpu.h |  4 +++-
 7 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/xen/arch/arm/percpu.c b/xen/arch/arm/percpu.c
index 25442c4..91f5ae9 100644
--- a/xen/arch/arm/percpu.c
+++ b/xen/arch/arm/percpu.c
@@ -5,8 +5,8 @@
 #include <xen/rcupdate.h>
 
 unsigned long __per_cpu_offset[NR_CPUS];
-#define INVALID_PERCPU_AREA (-(long)__per_cpu_start)
-#define PERCPU_ORDER (get_order_from_bytes(__per_cpu_data_end-__per_cpu_start))
+#define INVALID_PERCPU_AREA (-(long)per_cpu_start_)
+#define PERCPU_ORDER (get_order_from_bytes(per_cpu_data_end_ - per_cpu_start_))
 
 void __init percpu_init_areas(void)
 {
@@ -22,8 +22,8 @@ static int init_percpu_area(unsigned int cpu)
         return -EBUSY;
     if ( (p = alloc_xenheap_pages(PERCPU_ORDER, 0)) == NULL )
         return -ENOMEM;
-    memset(p, 0, __per_cpu_data_end - __per_cpu_start);
-    __per_cpu_offset[cpu] = p - __per_cpu_start;
+    memset(p, 0, per_cpu_data_end_ - per_cpu_start_);
+    __per_cpu_offset[cpu] = (uintptr_t)p - per_cpu_start_;
     return 0;
 }
 
@@ -37,7 +37,8 @@ static void _free_percpu_area(struct rcu_head *head)
 {
     struct free_info *info = container_of(head, struct free_info, rcu);
     unsigned int cpu = info->cpu;
-    char *p = __per_cpu_start + __per_cpu_offset[cpu];
+    char *p = (char *)(per_cpu_start_ + __per_cpu_offset[cpu]);
+
     free_xenheap_pages(p, PERCPU_ORDER);
     __per_cpu_offset[cpu] = INVALID_PERCPU_AREA;
 }
diff --git a/xen/arch/x86/percpu.c b/xen/arch/x86/percpu.c
index 8be4ebd..58624a3 100644
--- a/xen/arch/x86/percpu.c
+++ b/xen/arch/x86/percpu.c
@@ -12,8 +12,8 @@ unsigned long __per_cpu_offset[NR_CPUS];
  * possible #PF at (NULL + a little) which has security implications in the
  * context of PV guests.
  */
-#define INVALID_PERCPU_AREA (0x8000000000000000L - (long)__per_cpu_start)
-#define PERCPU_ORDER get_order_from_bytes(__per_cpu_data_end - __per_cpu_start)
+#define INVALID_PERCPU_AREA (0x8000000000000000L - (long)per_cpu_start_)
+#define PERCPU_ORDER get_order_from_bytes(per_cpu_data_end_ - per_cpu_start_)
 
 void __init percpu_init_areas(void)
 {
@@ -33,8 +33,8 @@ static int init_percpu_area(unsigned int cpu)
     if ( (p = alloc_xenheap_pages(PERCPU_ORDER, 0)) == NULL )
         return -ENOMEM;
 
-    memset(p, 0, __per_cpu_data_end - __per_cpu_start);
-    __per_cpu_offset[cpu] = p - __per_cpu_start;
+    memset(p, 0, per_cpu_data_end_ - per_cpu_start_);
+    __per_cpu_offset[cpu] = (uintptr_t)p - per_cpu_start_;
 
     return 0;
 }
@@ -49,7 +49,7 @@ static void _free_percpu_area(struct rcu_head *head)
 {
     struct free_info *info = container_of(head, struct free_info, rcu);
     unsigned int cpu = info->cpu;
-    char *p = __per_cpu_start + __per_cpu_offset[cpu];
+    char *p = (char *)(per_cpu_start_ + __per_cpu_offset[cpu]);
 
     free_xenheap_pages(p, PERCPU_ORDER);
     __per_cpu_offset[cpu] = INVALID_PERCPU_AREA;
diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c
index 1637453..d048016 100644
--- a/xen/common/virtual_region.c
+++ b/xen/common/virtual_region.c
@@ -99,15 +99,15 @@ void __init setup_virtual_regions(const struct exception_table_entry *start,
 {
     size_t sz;
     unsigned int i;
-    static const struct bug_frame *const __initconstrel bug_frames[] = {
-        __start_bug_frames,
-        __stop_bug_frames_0,
-        __stop_bug_frames_1,
-        __stop_bug_frames_2,
+    const uintptr_t bug_frames[] = {
+        start_bug_frames_,
+        stop_bug_frames_0_,
+        stop_bug_frames_1_,
+        stop_bug_frames_2_,
 #ifdef CONFIG_X86
-        __stop_bug_frames_3,
+        stop_bug_frames_3_,
 #endif
-        NULL
+        0
     };
 
     core.start = (char *)start_;
@@ -119,8 +119,8 @@ void __init setup_virtual_regions(const struct exception_table_entry *start,
     {
         const struct bug_frame *s;
 
-        s = bug_frames[i - 1];
-        sz = bug_frames[i] - s;
+        s = (struct bug_frame *)bug_frames[i - 1];
+        sz = (bug_frames[i] - bug_frames[i - 1]) / sizeof(struct bug_frame *);
 
         core.frame[i - 1].n_bugs = sz;
         core.frame[i - 1].bugs = s;
diff --git a/xen/include/asm-arm/bug.h b/xen/include/asm-arm/bug.h
index 36c8033..8720241 100644
--- a/xen/include/asm-arm/bug.h
+++ b/xen/include/asm-arm/bug.h
@@ -70,10 +70,10 @@ struct bug_frame {
     unreachable();                                              \
 } while (0)
 
-extern const struct bug_frame __start_bug_frames[],
-                              __stop_bug_frames_0[],
-                              __stop_bug_frames_1[],
-                              __stop_bug_frames_2[];
+extern uintptr_t start_bug_frames_,
+                 stop_bug_frames_0_,
+                 stop_bug_frames_1_,
+                 stop_bug_frames_2_;
 
 #endif /* __ARM_BUG_H__ */
 /*
diff --git a/xen/include/asm-arm/percpu.h b/xen/include/asm-arm/percpu.h
index 6263e77..2cb50ed 100644
--- a/xen/include/asm-arm/percpu.h
+++ b/xen/include/asm-arm/percpu.h
@@ -6,7 +6,7 @@
 #include <xen/types.h>
 #include <asm/sysregs.h>
 
-extern char __per_cpu_start[], __per_cpu_data_end[];
+extern uintptr_t per_cpu_start_, per_cpu_data_end_;
 extern unsigned long __per_cpu_offset[NR_CPUS];
 void percpu_init_areas(void);
 
diff --git a/xen/include/asm-x86/bug.h b/xen/include/asm-x86/bug.h
index 9bb4a19..32cd2c4 100644
--- a/xen/include/asm-x86/bug.h
+++ b/xen/include/asm-x86/bug.h
@@ -72,11 +72,11 @@ struct bug_frame {
     unreachable();                                              \
 } while (0)
 
-extern const struct bug_frame __start_bug_frames[],
-                              __stop_bug_frames_0[],
-                              __stop_bug_frames_1[],
-                              __stop_bug_frames_2[],
-                              __stop_bug_frames_3[];
+extern uintptr_t start_bug_frames_,
+                 stop_bug_frames_0_,
+                 stop_bug_frames_1_,
+                 stop_bug_frames_2_,
+                 stop_bug_frames_3_;
 
 #else  /* !__ASSEMBLY__ */
 
diff --git a/xen/include/asm-x86/percpu.h b/xen/include/asm-x86/percpu.h
index 51562b9..a1e1569 100644
--- a/xen/include/asm-x86/percpu.h
+++ b/xen/include/asm-x86/percpu.h
@@ -2,7 +2,9 @@
 #define __X86_PERCPU_H__
 
 #ifndef __ASSEMBLY__
-extern char __per_cpu_start[], __per_cpu_data_end[];
+#include <xen/types.h>
+
+extern uintptr_t per_cpu_start_, per_cpu_data_end_;
 extern unsigned long __per_cpu_offset[NR_CPUS];
 void percpu_init_areas(void);
 #endif
-- 
1.9.1


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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v8 6/7] xen/arm: use alt_instructions_, sdevice_, and more
       [not found] <wt35AlsJdPHayD9a>
                   ` (4 preceding siblings ...)
  2019-01-15 23:35 ` [PATCH v8 5/7] xen: use per_cpu_start_, start_bug_frames_, " Stefano Stabellini
@ 2019-01-15 23:35 ` Stefano Stabellini
  2019-01-15 23:35 ` [PATCH v8 7/7] xen/arm: use alt_instructions_, trampoline_rel_start_, start_vpci_array_, " Stefano Stabellini
  6 siblings, 0 replies; 11+ messages in thread
From: Stefano Stabellini @ 2019-01-15 23:35 UTC (permalink / raw)
  To: xen-devel
  Cc: andrew.cooper3, julien.grall, sstabellini, JBeulich, Stefano Stabellini

Start making use of the following arm specific uintptr_t variables:

alt_instructions_, alt_instructions_end_, sdevice_, edevice_,
asdevice_, aedevice_, init_begin_, init_end_, splatform_, eplatform_,

Replacing the corresponding linker symbols. These are all arm specific
changes. It is done to avoid comparing and subtracting pointers pointing
to different objects.

One thing to note is that ideally we would avoid converting
alt_instructions_ and alt_instructions_end_ to pointers as done in
alternative.c because it can lead to comparisions/subtractions between
pointers to different objects. It is not difficult to fix by reworking
the code slightly but out of scope for this patch.

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/device.c      | 16 +++++++++++-----
 xen/arch/arm/mm.c          | 23 +++++++++++++----------
 xen/arch/arm/platform.c    |  8 +++++---
 4 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c
index b79536d..7c3f32d 100644
--- a/xen/arch/arm/alternative.c
+++ b/xen/arch/arm/alternative.c
@@ -38,7 +38,7 @@
 #undef virt_to_mfn
 #define virt_to_mfn(va) _mfn(__virt_to_mfn(va))
 
-extern const struct alt_instr __alt_instructions[], __alt_instructions_end[];
+extern uintptr_t alt_instructions_, alt_instructions_end_;
 
 struct alt_region {
     const struct alt_instr *begin;
@@ -203,8 +203,8 @@ static int __apply_alternatives_multi_stop(void *unused)
         /* Re-mapping Xen is not expected to fail during boot. */
         BUG_ON(!xenmap);
 
-        region.begin = __alt_instructions;
-        region.end = __alt_instructions_end;
+        region.begin = (const struct alt_instr *)alt_instructions_;
+        region.end = (const struct alt_instr *)alt_instructions_end_;
 
         ret = __apply_alternatives(&region, (uintptr_t)xenmap - start_);
         /* The patching is not expected to fail during boot. */
diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c
index 70cd6c1..3e2d759 100644
--- a/xen/arch/arm/device.c
+++ b/xen/arch/arm/device.c
@@ -22,8 +22,8 @@
 #include <xen/init.h>
 #include <xen/lib.h>
 
-extern const struct device_desc _sdevice[], _edevice[];
-extern const struct acpi_device_desc _asdevice[], _aedevice[];
+extern uintptr_t sdevice_, edevice_;
+extern uintptr_t asdevice_, aedevice_;
 
 int __init device_init(struct dt_device_node *dev, enum device_class class,
                        const void *data)
@@ -35,7 +35,9 @@ int __init device_init(struct dt_device_node *dev, enum device_class class,
     if ( !dt_device_is_available(dev) || dt_device_for_passthrough(dev) )
         return  -ENODEV;
 
-    for ( desc = _sdevice; desc != _edevice; desc++ )
+    for ( desc = (struct device_desc *)sdevice_;
+          (uintptr_t)desc != edevice_;
+          desc++ )
     {
         if ( desc->class != class )
             continue;
@@ -56,7 +58,9 @@ int __init acpi_device_init(enum device_class class, const void *data, int class
 {
     const struct acpi_device_desc *desc;
 
-    for ( desc = _asdevice; desc != _aedevice; desc++ )
+    for ( desc = (struct acpi_device_desc *)asdevice_;
+          (uintptr_t)desc != aedevice_;
+          desc++ )
     {
         if ( ( desc->class != class ) || ( desc->class_type != class_type ) )
             continue;
@@ -75,7 +79,9 @@ enum device_class device_get_class(const struct dt_device_node *dev)
 
     ASSERT(dev != NULL);
 
-    for ( desc = _sdevice; desc != _edevice; desc++ )
+    for ( desc = (struct device_desc *)sdevice_;
+          (uintptr_t)desc != edevice_;
+          desc++ )
     {
         if ( dt_match_node(desc->dt_match, dev) )
             return desc->class;
diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 01ae2cc..9c80e03 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -157,7 +157,7 @@ unsigned long frametable_virt_end __read_mostly;
 unsigned long max_page;
 unsigned long total_pages;
 
-extern char __init_begin[], __init_end[];
+extern uintptr_t init_begin_, init_end_;
 
 /* Checking VA memory layout alignment. */
 static inline void check_memory_layout_alignment_constraints(void) {
@@ -1073,7 +1073,9 @@ int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags)
 }
 
 enum mg { mg_clear, mg_ro, mg_rw, mg_rx };
-static void set_pte_flags_on_range(const char *p, unsigned long l, enum mg mg)
+static void set_pte_flags_on_range(const uintptr_t p,
+                                   unsigned long l,
+                                   enum mg mg)
 {
     lpae_t pte;
     int i;
@@ -1084,8 +1086,8 @@ static void set_pte_flags_on_range(const char *p, unsigned long l, enum mg mg)
     ASSERT(!((unsigned long) p & ~PAGE_MASK));
     ASSERT(!(l & ~PAGE_MASK));
 
-    for ( i = (p - _start) / PAGE_SIZE; 
-          i < (p + l - _start) / PAGE_SIZE; 
+    for ( i = (p - start_) / PAGE_SIZE;
+          i < (p + l - start_) / PAGE_SIZE;
           i++ )
     {
         pte = xen_xenmap[i];
@@ -1121,26 +1123,27 @@ static void set_pte_flags_on_range(const char *p, unsigned long l, enum mg mg)
 /* Release all __init and __initdata ranges to be reused */
 void free_init_memory(void)
 {
-    paddr_t pa = virt_to_maddr(__init_begin);
-    unsigned long len = __init_end - __init_begin;
+    paddr_t pa = virt_to_maddr(init_begin_);
+    unsigned long len = init_end_ - init_begin_;
     uint32_t insn;
     unsigned int i, nr = len / sizeof(insn);
     uint32_t *p;
 
-    set_pte_flags_on_range(__init_begin, len, mg_rw);
+    set_pte_flags_on_range(init_begin_, len, mg_rw);
 #ifdef CONFIG_ARM_32
     /* udf instruction i.e (see A8.8.247 in ARM DDI 0406C.c) */
     insn = 0xe7f000f0;
 #else
     insn = AARCH64_BREAK_FAULT;
 #endif
-    p = (uint32_t *)__init_begin;
+    p = (uint32_t *)init_begin_;
     for ( i = 0; i < nr; i++ )
         *(p + i) = insn;
 
-    set_pte_flags_on_range(__init_begin, len, mg_clear);
+    set_pte_flags_on_range(init_begin_, len, mg_clear);
     init_domheap_pages(pa, pa + len);
-    printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10);
+    printk("Freed %"PRIxPTR"kB init memory.\n",
+           (init_end_ - init_begin_) >> 10);
 }
 
 void arch_dump_shared_mem_info(void)
diff --git a/xen/arch/arm/platform.c b/xen/arch/arm/platform.c
index 8eb0b6e..a79eb53 100644
--- a/xen/arch/arm/platform.c
+++ b/xen/arch/arm/platform.c
@@ -22,7 +22,7 @@
 #include <xen/init.h>
 #include <asm/psci.h>
 
-extern const struct platform_desc _splatform[], _eplatform[];
+extern uintptr_t splatform_, eplatform_;
 
 /* Pointer to the current platform description */
 static const struct platform_desc *platform;
@@ -51,14 +51,16 @@ void __init platform_init(void)
     ASSERT(platform == NULL);
 
     /* Looking for the platform description */
-    for ( platform = _splatform; platform != _eplatform; platform++ )
+    for ( platform = (struct platform_desc *)splatform_;
+          (uintptr_t)platform != eplatform_;
+          platform++ )
     {
         if ( platform_is_compatible(platform) )
             break;
     }
 
     /* We don't have specific operations for this platform */
-    if ( platform == _eplatform )
+    if ( (uintptr_t)platform == eplatform_ )
     {
         /* TODO: dump DT machine compatible node */
         printk(XENLOG_INFO "Platform: Generic System\n");
-- 
1.9.1


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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v8 7/7] xen/arm: use alt_instructions_, trampoline_rel_start_, start_vpci_array_, and more
       [not found] <wt35AlsJdPHayD9a>
                   ` (5 preceding siblings ...)
  2019-01-15 23:35 ` [PATCH v8 6/7] xen/arm: use alt_instructions_, sdevice_, " Stefano Stabellini
@ 2019-01-15 23:35 ` Stefano Stabellini
  2019-01-17 15:58   ` Jan Beulich
  6 siblings, 1 reply; 11+ messages in thread
From: Stefano Stabellini @ 2019-01-15 23:35 UTC (permalink / raw)
  To: xen-devel
  Cc: andrew.cooper3, julien.grall, sstabellini, JBeulich, Stefano Stabellini

Start making use of the following x86 specific uintptr_t variables:

alt_instructions_, alt_instructions_end_, trampoline_rel_start_,
trampoline_rel_stop_, trampoline_seg_start_, trampoline_seg_stop_,
init_begin_, init_end_, start_vpci_array_, end_vpci_array_

Replacing the corresponding linker symbols. These are all x86 specific
changes. It is done to avoid comparing and subtracting pointers pointing
to different objects.

bss_start_, bss_end_ have been removed because they are not used.
Another meaningful change is in the calculation of NUM_VPCI_INIT: now it
needs to take into account the size of the struct pointer.

One thing to note is that ideally we would avoid converting
alt_instructions_ and alt_instructions_end_ to pointers as done in
alternative.c because it can lead to comparisions/subtractions between
pointers to different objects. It is not difficult to fix by reworking
the code slightly but out of scope for this patch.

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/x86/alternative.c  |  5 +++--
 xen/arch/x86/efi/efi-boot.h | 12 ++++++------
 xen/arch/x86/setup.c        |  8 ++++----
 xen/drivers/vpci/vpci.c     | 11 +++++++----
 4 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c
index b8c819a..bdbb9bd 100644
--- a/xen/arch/x86/alternative.c
+++ b/xen/arch/x86/alternative.c
@@ -29,7 +29,7 @@
 
 #define MAX_PATCH_LEN (255-1)
 
-extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
+extern uintptr_t alt_instructions_, alt_instructions_end_;
 
 #ifdef K8_NOP1
 static const unsigned char k8nops[] init_or_livepatch_const = {
@@ -273,7 +273,8 @@ static int __init nmi_apply_alternatives(const struct cpu_user_regs *regs,
         /* Disable WP to allow patching read-only pages. */
         write_cr0(cr0 & ~X86_CR0_WP);
 
-        apply_alternatives(__alt_instructions, __alt_instructions_end);
+        apply_alternatives((struct alt_instr *)alt_instructions_,
+                           (struct alt_instr *)alt_instructions_end_);
 
         write_cr0(cr0);
 
diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h
index 5789d2c..33e39bd 100644
--- a/xen/arch/x86/efi/efi-boot.h
+++ b/xen/arch/x86/efi/efi-boot.h
@@ -98,8 +98,8 @@ static void __init efi_arch_relocate_image(unsigned long delta)
     }
 }
 
-extern const s32 __trampoline_rel_start[], __trampoline_rel_stop[];
-extern const s32 __trampoline_seg_start[], __trampoline_seg_stop[];
+extern uintptr_t trampoline_rel_start_, trampoline_rel_stop_;
+extern uintptr_t trampoline_seg_start_, trampoline_seg_stop_;
 
 static void __init relocate_trampoline(unsigned long phys)
 {
@@ -111,12 +111,12 @@ static void __init relocate_trampoline(unsigned long phys)
         return;
 
     /* Apply relocations to trampoline. */
-    for ( trampoline_ptr = __trampoline_rel_start;
-          trampoline_ptr < __trampoline_rel_stop;
+    for ( trampoline_ptr = (const s32 *)trampoline_rel_start_;
+          (uintptr_t)trampoline_ptr < trampoline_rel_stop_;
           ++trampoline_ptr )
         *(u32 *)(*trampoline_ptr + (long)trampoline_ptr) += phys;
-    for ( trampoline_ptr = __trampoline_seg_start;
-          trampoline_ptr < __trampoline_seg_stop;
+    for ( trampoline_ptr = (const s32 *)trampoline_seg_start_;
+          (uintptr_t)trampoline_ptr < trampoline_seg_stop_;
           ++trampoline_ptr )
         *(u16 *)(*trampoline_ptr + (long)trampoline_ptr) = phys >> 4;
 }
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 3a2aa4c..3f0d597 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -252,7 +252,7 @@ void __init discard_initial_images(void)
     initial_images = NULL;
 }
 
-extern char __init_begin[], __init_end[], __bss_start[], __bss_end[];
+extern uintptr_t init_begin_, init_end_;
 
 static void __init init_idle_domain(void)
 {
@@ -600,7 +600,7 @@ static void noinline init_done(void)
     unregister_init_virtual_region();
 
     /* Zero the .init code and data. */
-    for ( va = __init_begin; va < _p(__init_end); va += PAGE_SIZE )
+    for ( va = (void *)init_begin_; (uintptr_t)va < init_end_; va += PAGE_SIZE )
         clear_page(va);
 
     /* Destroy Xen's mappings, and reuse the pages. */
@@ -611,8 +611,8 @@ static void noinline init_done(void)
     }
     else
     {
-        start = (unsigned long)&__init_begin;
-        end   = (unsigned long)&__init_end;
+        start = init_begin_;
+        end   = init_end_;
     }
 
     destroy_xen_mappings(start, end);
diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c
index 82607bd..6eafd00 100644
--- a/xen/drivers/vpci/vpci.c
+++ b/xen/drivers/vpci/vpci.c
@@ -31,9 +31,10 @@ struct vpci_register {
 };
 
 #ifdef __XEN__
-extern vpci_register_init_t *const __start_vpci_array[];
-extern vpci_register_init_t *const __end_vpci_array[];
-#define NUM_VPCI_INIT (__end_vpci_array - __start_vpci_array)
+extern uintptr_t start_vpci_array_;
+extern uintptr_t end_vpci_array_;
+#define NUM_VPCI_INIT ((end_vpci_array_ - start_vpci_array_) / \
+                       (sizeof(vpci_register_init_t *)))
 
 void vpci_remove_device(struct pci_dev *pdev)
 {
@@ -58,6 +59,8 @@ int __hwdom_init vpci_add_handlers(struct pci_dev *pdev)
 {
     unsigned int i;
     int rc = 0;
+    vpci_register_init_t **start_vpci_array = (vpci_register_init_t **)
+                                              start_vpci_array_;
 
     if ( !has_vpci(pdev->domain) )
         return 0;
@@ -71,7 +74,7 @@ int __hwdom_init vpci_add_handlers(struct pci_dev *pdev)
 
     for ( i = 0; i < NUM_VPCI_INIT; i++ )
     {
-        rc = __start_vpci_array[i](pdev);
+        rc = start_vpci_array[i](pdev);
         if ( rc )
             break;
     }
-- 
1.9.1


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

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v8 7/7] xen/arm: use alt_instructions_, trampoline_rel_start_, start_vpci_array_, and more
  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
  0 siblings, 0 replies; 11+ messages in thread
From: Jan Beulich @ 2019-01-17 15:58 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, xen-devel

>>> On 16.01.19 at 00:35, <sstabellini@kernel.org> wrote:
> @@ -273,7 +273,8 @@ static int __init nmi_apply_alternatives(const struct cpu_user_regs *regs,
>          /* Disable WP to allow patching read-only pages. */
>          write_cr0(cr0 & ~X86_CR0_WP);
>  
> -        apply_alternatives(__alt_instructions, __alt_instructions_end);
> +        apply_alternatives((struct alt_instr *)alt_instructions_,
> +                           (struct alt_instr *)alt_instructions_end_);

Such addition of casts is exactly what I'd like to avoid.

As an aside - the title surely was meant to start with "xen/x86:"?

Jan



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v8 4/7] xen: use initcall_start_, ctors_start_, and more
  2019-01-15 23:35 ` [PATCH v8 4/7] xen: use initcall_start_, ctors_start_, " Stefano Stabellini
@ 2019-01-17 16:07   ` Jan Beulich
  0 siblings, 0 replies; 11+ messages in thread
From: Jan Beulich @ 2019-01-17 16:07 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, xen-devel

>>> On 16.01.19 at 00:35, <sstabellini@kernel.org> wrote:
> --- a/xen/common/kernel.c
> +++ b/xen/common/kernel.c
> @@ -306,20 +306,23 @@ void add_taint(unsigned int flag)
>      tainted |= flag;
>  }
>  
> -extern const initcall_t __initcall_start[], __presmp_initcall_end[],
> -    __initcall_end[];
> +extern uintptr_t initcall_start_, presmp_initcall_end_, initcall_end_;
>  
>  void __init do_presmp_initcalls(void)
>  {
>      const initcall_t *call;
> -    for ( call = __initcall_start; call < __presmp_initcall_end; call++ )
> +    for ( call = (const initcall_t *)initcall_start_;
> +          (uintptr_t)call < presmp_initcall_end_;

This (just taken as an example) is at best marginally better
than using casts to an arithmetic type without intermediate
variables.

> --- a/xen/common/schedule.c
> +++ b/xen/common/schedule.c
> @@ -67,9 +67,10 @@ DEFINE_PER_CPU(struct scheduler *, scheduler);
>  /* Scratch space for cpumasks. */
>  DEFINE_PER_CPU(cpumask_t, cpumask_scratch);
>  
> -extern const struct scheduler *__start_schedulers_array[], *__end_schedulers_array[];
> -#define NUM_SCHEDULERS (__end_schedulers_array - __start_schedulers_array)
> -#define schedulers __start_schedulers_array
> +extern uintptr_t start_schedulers_array_, end_schedulers_array_;
> +#define NUM_SCHEDULERS ((end_schedulers_array_ - start_schedulers_array_) \
> +                        / sizeof(const struct scheduler *))

Despite not being a cast, this is another example of a hidden
type dependency which would better not be introduced. At
the very least this should use an expression rather than a
type name, such that the type of the expression changing
also affects the calculation here. Granted it's a pointer here,
so e.g. renaming struct scheduler wouldn't have bad
consequences, but other (future) places may clone this code
and use other than a pointer.

As another general remark - I'm also not really happy about
the trailing underscores. Yes, this is a means to avoid leading
ones, and hence to avoid name space violations. But we use
trailing underscores in macros a lot, so this opens up new
conflict potential. Anyway, I still hope we can get away either
without any intermediate variables, or ones replacing (rather
than amending) the current ones.

Jan



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v8 1/7] xen: add assembly variables corresponding to linker symbols
  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
  0 siblings, 0 replies; 11+ messages in thread
From: Jan Beulich @ 2019-01-17 16:12 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, xen-devel

>>> On 16.01.19 at 00:35, <sstabellini@kernel.org> wrote:
> --- /dev/null
> +++ b/xen/arch/x86/x86_64/var.S
> @@ -0,0 +1,92 @@
> +GLOBAL(start_)
> +  .quad  _start

First of all I think it would be better if there was an abstracting macro
requiring exactly one line per symbol.

Next I don't think you want these symbols to end up in .text, in
which case you need to a .section directive.

And then, specific to this x86 instance - if we really need to go with
this, please move this up one level in the directory hierarchy.

Jan



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v8 2/7] xen: use start_, end_, and more
  2019-01-15 23:35 ` [PATCH v8 2/7] xen: use start_, end_, and more Stefano Stabellini
@ 2019-01-17 16:24   ` Jan Beulich
  0 siblings, 0 replies; 11+ messages in thread
From: Jan Beulich @ 2019-01-17 16:24 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, xen-devel

>>> On 16.01.19 at 00:35, <sstabellini@kernel.org> wrote:
> --- 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_;

I can see why you want to replace the latter, but why also the former?
There are more similar cases elsewhere. One particularly funny one is

> @@ -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);

... this: You replace one both not the other two visible here.

> --- 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) -

Same here.

> @@ -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_;

Not sure why it occurred to me when looking at this code, but I
can't resist quoting the standard here:

"An integer may be converted to any pointer type. Except as previously
 specified, the result is implementation-defined, might not be correctly
 aligned, might not point to an entity of the referenced type, and might
 be a trap representation.

 Any pointer type may be converted to an integer type. Except as
 previously specified, the result is implementation-defined. If the result
 cannot be represented in the integer type, the behavior is undefined.
 The result need not be in the range of values of any integer type."

Is this not concerning to MISRA?

> --- 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);                     \

Without it being a pointer the const in the cast is now pointless.

Jan



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-01-17 16:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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 ` [PATCH v8 2/7] xen: use start_, end_, and more Stefano Stabellini
2019-01-17 16:24   ` 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

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.