[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v7 2/4] xen/arm: use SYMBOL_HIDE when required
Use SYMBOL_HIDE in cases of comparisons and subtractions of: _start, _end, __init_begin, __init_end, _stext, _etext, __alt_instructions, __alt_instructions_end, __per_cpu_start, __per_cpu_data_end, _splatform, _eplatform, _sdevice, _edevice, _asdevice, _aedevice. as by the C standard [1]. M3CM: Rule-18.2: Subtraction between pointers shall only be applied to pointers that address elements of the same array [1] https://wiki.sei.cmu.edu/confluence/display/c/ARR36-C.+Do+not+subtract+or+compare+two+pointers+that+do+not+refer+to+the+same+array QAVerify: 2761 Signed-off-by: Stefano Stabellini <stefanos@xxxxxxxxxx> CC: JBeulich@xxxxxxxx CC: andrew.cooper3@xxxxxxxxxx --- Changes in v7: - code style Changes in v6: - more accurate commit message - use new SYMBOL macro that returns the native type Changes in v5: - remove two spurious changes - split into three patches - remove SYMBOL() from derived variables Changes in v4: - only use SYMBOL where necessary, not "everywhere": comparisons and subtractions - improve commit message - remove some unnecessary casts - fix some still unsafe casts - extend checks to all symbols in xen/arch/x86/xen.lds.S and xen/arch/arm/xen.lds.S Changes in v3: - improve commit message - no hard tabs - rename __symbol to SYMBOL - fix __end_vpci_array and __start_vpci_array - avoid all comparisons between pointers: including (void *) casted returns from SYMBOL() - remove useless casts to (unsigned long) Changes in v2: - cast return of SYMBOL to char* when required - define __pa as unsigned long in is_kernel* functions --- xen/arch/arm/alternative.c | 5 +++-- xen/arch/arm/arm32/livepatch.c | 2 +- xen/arch/arm/arm64/livepatch.c | 2 +- xen/arch/arm/device.c | 8 +++++--- xen/arch/arm/livepatch.c | 4 ++-- xen/arch/arm/mm.c | 13 +++++++------ xen/arch/arm/percpu.c | 11 +++++++---- xen/arch/arm/platform.c | 6 ++++-- xen/arch/arm/setup.c | 7 +++++-- xen/include/asm-arm/grant_table.h | 3 ++- 10 files changed, 37 insertions(+), 24 deletions(-) diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c index 52ed7ed..d3391a7 100644 --- a/xen/arch/arm/alternative.c +++ b/xen/arch/arm/alternative.c @@ -188,7 +188,7 @@ 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; + paddr_t xen_size = SYMBOL_HIDE(_end) - SYMBOL_HIDE(_start); unsigned int xen_order = get_order_from_bytes(xen_size); void *xenmap; @@ -206,7 +206,8 @@ 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, + xenmap - (void *)SYMBOL_HIDE(_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..183300d 100644 --- a/xen/arch/arm/arm32/livepatch.c +++ b/xen/arch/arm/arm32/livepatch.c @@ -56,7 +56,7 @@ 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 = func->old_addr - (void *)SYMBOL_HIDE(_start) + 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..533debe 100644 --- a/xen/arch/arm/arm64/livepatch.c +++ b/xen/arch/arm/arm64/livepatch.c @@ -43,7 +43,7 @@ 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 = func->old_addr - (void *)SYMBOL_HIDE(_start) + vmap_of_xen_text; len = len / sizeof(uint32_t); /* PATCH! */ diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index 70cd6c1..6ecde1a 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -35,7 +35,7 @@ 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 = SYMBOL_HIDE(_sdevice); desc != SYMBOL_HIDE(_edevice); desc++ ) { if ( desc->class != class ) continue; @@ -56,7 +56,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 = SYMBOL_HIDE(_asdevice); + desc != SYMBOL_HIDE(_aedevice); + desc++ ) { if ( ( desc->class != class ) || ( desc->class_type != class_type ) ) continue; @@ -75,7 +77,7 @@ enum device_class device_get_class(const struct dt_device_node *dev) ASSERT(dev != NULL); - for ( desc = _sdevice; desc != _edevice; desc++ ) + for ( desc = SYMBOL_HIDE(_sdevice); desc != SYMBOL_HIDE(_edevice); desc++ ) { if ( dt_match_node(desc->dt_match, dev) ) return desc->class; diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c index 279d52c..d1a88b4 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(SYMBOL_HIDE(_end) - SYMBOL_HIDE(_start)); /* * The text section is read-only. So re-map Xen to be able to patch @@ -78,7 +78,7 @@ 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 = func->old_addr - (void *)SYMBOL_HIDE(_start) + vmap_of_xen_text; len = livepatch_insn_len(func); memcpy(new_ptr, func->opaque, len); diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 01ae2cc..cf0805b 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1084,8 +1084,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 - SYMBOL_HIDE(_start)) / PAGE_SIZE; + i < (p + l - SYMBOL_HIDE(_start)) / PAGE_SIZE; i++ ) { pte = xen_xenmap[i]; @@ -1122,12 +1122,12 @@ static void set_pte_flags_on_range(const char *p, unsigned long l, enum mg mg) void free_init_memory(void) { paddr_t pa = virt_to_maddr(__init_begin); - unsigned long len = __init_end - __init_begin; + unsigned long len = SYMBOL_HIDE(__init_end) - SYMBOL_HIDE(__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(SYMBOL_HIDE(__init_begin), len, mg_rw); #ifdef CONFIG_ARM_32 /* udf instruction i.e (see A8.8.247 in ARM DDI 0406C.c) */ insn = 0xe7f000f0; @@ -1138,9 +1138,10 @@ void free_init_memory(void) for ( i = 0; i < nr; i++ ) *(p + i) = insn; - set_pte_flags_on_range(__init_begin, len, mg_clear); + set_pte_flags_on_range(SYMBOL_HIDE(__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 %ldkB init memory.\n", + (long)(SYMBOL_HIDE(__init_end) - SYMBOL_HIDE(__init_begin)) >> 10); } void arch_dump_shared_mem_info(void) diff --git a/xen/arch/arm/percpu.c b/xen/arch/arm/percpu.c index 25442c4..7cde0f6 100644 --- a/xen/arch/arm/percpu.c +++ b/xen/arch/arm/percpu.c @@ -6,7 +6,8 @@ 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 PERCPU_ORDER (get_order_from_bytes(SYMBOL_HIDE(__per_cpu_data_end) - \ + SYMBOL_HIDE(__per_cpu_start))) void __init percpu_init_areas(void) { @@ -22,8 +23,9 @@ 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, SYMBOL_HIDE(__per_cpu_data_end) - + SYMBOL_HIDE(__per_cpu_start)); + __per_cpu_offset[cpu] = p - SYMBOL_HIDE(__per_cpu_start); return 0; } @@ -37,7 +39,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 = SYMBOL_HIDE(__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/arm/platform.c b/xen/arch/arm/platform.c index 8eb0b6e..395bf17 100644 --- a/xen/arch/arm/platform.c +++ b/xen/arch/arm/platform.c @@ -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 = SYMBOL_HIDE(_splatform); + platform != SYMBOL_HIDE(_eplatform); + platform++ ) { if ( platform_is_compatible(platform) ) break; } /* We don't have specific operations for this platform */ - if ( platform == _eplatform ) + if ( platform == SYMBOL_HIDE(_eplatform) ) { /* TODO: dump DT machine compatible node */ printk(XENLOG_INFO "Platform: Generic System\n"); diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 444857a..083f293 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -772,8 +772,11 @@ 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); + (paddr_t)(uintptr_t)(SYMBOL_HIDE(_start) + + boot_phys_offset), + (paddr_t)(uintptr_t)(SYMBOL_HIDE(_end) - + SYMBOL_HIDE(_start) + 1), + false); BUG_ON(!xen_bootmodule); setup_pagetables(boot_phys_offset); diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_table.h index 816e3c6..b829813 100644 --- a/xen/include/asm-arm/grant_table.h +++ b/xen/include/asm-arm/grant_table.h @@ -31,7 +31,8 @@ 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(SYMBOL_HIDE(_etext) - SYMBOL_HIDE(_stext))) #define gnttab_init_arch(gt) \ ({ \ -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |