xen: use start_, end_, and more
A message that is not in the archive (sent off-list or not yet received): wt35AlsJdPHayD9a
PATCH v8 1/7 xen: add assembly variables corresponding to linker symbols
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.
---
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
xen/arch/arm/arm32/Makefile +1 -0
@@ -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
xen/arch/arm/arm32/var.S new file +72 -0
72 lines not on this page · raw message
xen/arch/arm/arm64/Makefile +1 -0
@@ -13,3 +13,4 @@ obj-y += smpboot.o obj-y += traps.o obj-y += vfp.o obj-y += vsysreg.o +obj-y += var.o
xen/arch/arm/arm64/var.S new file +72 -0
72 lines not on this page · raw message
xen/arch/x86/x86_64/Makefile +1 -0
@@ -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
xen/arch/x86/x86_64/var.S new file +92 -0
92 lines not on this page · raw message
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v8 1/7] xen: add assembly variables corresponding to linker symbols
xen/arch/x86/x86_64/var.S line 2
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 16.01.19 at 00:35, <[email protected]> wrote:
xen/arch/x86/x86_64/var.S new file +2
-0@@ -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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v8 2/7 xen: use start_, end_, and more
In reply to a message not in the archiveStart 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).
---
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(-)
xen/arch/arm/alternative.c +3 -3
@@ -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 (®ion, xenmap - (void *)_start); + ret =__apply_alternatives (®ion, (uintptr_t )xenmap - start_);/* The patching is not expected to fail during boot. */ BUG_ON (ret !=0 );
xen/arch/arm/arm32/livepatch.c +2 -1
@@ -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! */
xen/arch/arm/arm64/livepatch.c +2 -1
@@ -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! */
xen/arch/arm/domain_build.c +1 -1
@@ -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
xen/arch/arm/livepatch.c +3 -2
@@ -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);
xen/arch/arm/setup.c +3 -2
@@ -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);
xen/arch/x86/setup.c +8 -9
@@ -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);
xen/arch/x86/smpboot.c +4 -3
@@ -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 )
xen/arch/x86/tboot.c +2 -2
@@ -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) -
xen/arch/x86/x86_64/machine_kexec.c +2 -2
@@ -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 ; }
xen/common/symbols.c +1 -2
@@ -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);
xen/common/virtual_region.c +5 -4
@@ -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;
xen/include/asm-arm/grant_table.h +1 -1
@@ -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) \ ({ \
xen/include/asm-arm/mm.h +2 -2
@@ -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))
xen/include/asm-x86/mm.h +1 -1
@@ -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 */
xen/include/xen/kernel.h +16 -16
@@ -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 {
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
xen/arch/arm/alternative.c static int __apply_alternatives_multi_stop(void *unused) · line 191
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 16.01.19 at 00:35, <[email protected]> wrote:
xen/arch/arm/alternative.c +2
-2@@ -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
xen/arch/arm/alternative.c int __hwdom_init xen_in_range(unsigned long mfn) · line 1876
Quoted 9 lines
xen/arch/arm/alternative.c +1
-1@@ -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.
Quoted 4 lines
xen/arch/x86/tboot.c +0
-0@@ -373,9 +373,9 @@ void tboot_shutdown(uint32_t shutdown_type) g_tboot_shared->mac_regions[0].size = bootsym_phys(trampoline_end) -
xen/arch/x86/tboot.c void tboot_shutdown(uint32_t shutdown_type) · line 381
Quoted 10 lines
xen/arch/x86/tboot.c +2
-2bootsym_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.
xen/arch/x86/tboot.c void __init setup_virtual_regions(const struct exception_table_entry *start, · line 116
Quoted 8 lines
xen/arch/x86/tboot.c +4
-0@@ -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?
xen/include/xen/kernel.h line 70
Quoted 13 lines
xen/include/xen/kernel.h +3
-4@@ -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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v8 3/7 xen/x86: use rodata_start_2M_, init_start_2M_, and more
In reply to a message not in the archiveStart 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.
---
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(-)
xen/arch/x86/setup.c +30 -30
@@ -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 ;
xen/arch/x86/tboot.c +4 -4
@@ -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
xen/include/asm-x86/mm.h +1 -1
@@ -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 */
xen/include/asm-x86/setup.h +4 -4
@@ -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;
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v8 4/7 xen: use initcall_start_, ctors_start_, and more
In reply to a message not in the archiveStart 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.
---
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(-)
xen/common/kernel.c +7 -4
@@ -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)(); }
xen/common/lib.c +5 -2
@@ -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. */
xen/common/schedule.c +4 -3
@@ -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;
xen/common/spinlock.c +5 -3
@@ -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;
xen/common/version.c +5 -5
@@ -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_pdb70static 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);
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v8 4/7] xen: use initcall_start_, ctors_start_, and more
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 16.01.19 at 00:35, <[email protected]> wrote:
xen/common/kernel.c +0
-0@@ -306,20 +306,23 @@ void add_taint(unsigned int flag) tainted |= flag; }
xen/common/kernel.c void add_taint(unsigned int flag) · line 315
Quoted 10 lines
xen/common/kernel.c +3
-3-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.
xen/common/schedule.c DEFINE_PER_CPU(struct scheduler *, scheduler); · line 72
Quoted 12 lines
xen/common/schedule.c +3
-3@@ -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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v8 5/7 xen: use per_cpu_start_, start_bug_frames_, and more
In reply to a message not in the archiveStart 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.
---
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(-)
xen/arch/arm/percpu.c +6 -5
@@ -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 ; }
xen/arch/x86/percpu.c +5 -5
@@ -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 ;
xen/common/virtual_region.c +9 -9
@@ -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;
xen/include/asm-arm/bug.h +4 -4
@@ -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__ */ /*
xen/include/asm-arm/percpu.h +1 -1
@@ -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 );
xen/include/asm-x86/bug.h +5 -5
@@ -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__ */
xen/include/asm-x86/percpu.h +3 -1
@@ -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
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v8 6/7 xen/arm: use alt_instructions_, sdevice_, and more
In reply to a message not in the archiveStart 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.
---
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(-)
xen/arch/arm/alternative.c +3 -3
@@ -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 (®ion, (uintptr_t )xenmap - start_);/* The patching is not expected to fail during boot. */
xen/arch/arm/device.c +11 -5
@@ -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;
xen/arch/arm/mm.c +13 -10
@@ -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 )
xen/arch/arm/platform.c +5 -3
@@ -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" );
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v8 7/7 xen/arm: use alt_instructions_, trampoline_rel_start_, start_vpci_array_, and more
In reply to a message not in the archiveStart 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.
---
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(-)
xen/arch/x86/alternative.c +3 -2
@@ -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);
xen/arch/x86/efi/efi-boot.h +6 -6
@@ -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 ; }
xen/arch/x86/setup.c +4 -4
@@ -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);
xen/drivers/vpci/vpci.c +7 -4
@@ -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 ; }
Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v8 7/7] xen/arm: use alt_instructions_, trampoline_rel_start_, start_vpci_array_, and more
xen/arch/x86/alternative.c static int __init nmi_apply_alternatives(const struct cpu_user_regs *regs, · line 277
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 16.01.19 at 00:35, <[email protected]> wrote:
xen/arch/x86/alternative.c +2
-1@@ -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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel