All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] misc safety certification fixes
@ 2018-10-17 14:30 Stefano Stabellini
  2018-10-17 14:31 ` [PATCH v2 1/4] xen/arm: initialize target Stefano Stabellini
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Stefano Stabellini @ 2018-10-17 14:30 UTC (permalink / raw)
  To: xen-devel; +Cc: andrew.cooper3, julien.grall, sstabellini, JBeulich

Hi all,

This short patch series fixes a few issues discovered by the safety
certifications code scanner. The first two patches address simple
variable initializations concerns. The third patch introduces a new
macro that is used throughout the code in patch #4 to access _stext,
_etext pointers and friends.


Jan, Andrew, as you know my goal is to fix arm and common code. I think
it would be best to do the same for the x86 code as well, but let me
know if you think otherwise.


Cheers,

Stefano


Stefano Stabellini (4):
      xen/arm: initialize target
      xen/arm: initialize access
      xen: introduce __symbol
      xen: use __symbol everywhere

 xen/arch/arm/alternative.c          |  6 +--
 xen/arch/arm/arm32/livepatch.c      |  2 +-
 xen/arch/arm/arm64/livepatch.c      |  2 +-
 xen/arch/arm/domain_build.c         |  2 +-
 xen/arch/arm/livepatch.c            |  6 +--
 xen/arch/arm/mem_access.c           |  1 +
 xen/arch/arm/mm.c                   | 17 ++++----
 xen/arch/arm/setup.c                |  8 ++--
 xen/arch/arm/vgic-v2.c              |  2 +-
 xen/arch/arm/vgic-v3.c              |  2 +-
 xen/arch/x86/setup.c                | 79 +++++++++++++++++++------------------
 xen/arch/x86/tboot.c                | 12 +++---
 xen/arch/x86/x86_64/machine_kexec.c |  4 +-
 xen/include/asm-arm/grant_table.h   |  3 +-
 xen/include/asm-arm/mm.h            |  4 +-
 xen/include/asm-x86/mm.h            |  4 +-
 xen/include/xen/compiler.h          |  6 +++
 xen/include/xen/kernel.h            | 24 +++++------
 18 files changed, 99 insertions(+), 85 deletions(-)

_______________________________________________
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

* [PATCH v2 1/4] xen/arm: initialize target
  2018-10-17 14:30 [PATCH v2 0/4] misc safety certification fixes Stefano Stabellini
@ 2018-10-17 14:31 ` Stefano Stabellini
  2018-10-17 14:40   ` Julien Grall
  2018-10-17 14:31 ` [PATCH v2 2/4] xen/arm: initialize access Stefano Stabellini
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Stefano Stabellini @ 2018-10-17 14:31 UTC (permalink / raw)
  To: xen-devel; +Cc: Stefano Stabellini, julien.grall, sstabellini

Initialize variable target before passing it as a parameter.
It makes the code a bit nicer and it is a safety certification
requirement.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
---
Changes in v2:
- improve comment
---
 xen/arch/arm/vgic-v2.c | 2 +-
 xen/arch/arm/vgic-v3.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/arch/arm/vgic-v2.c b/xen/arch/arm/vgic-v2.c
index f6c11f1..0099fcf 100644
--- a/xen/arch/arm/vgic-v2.c
+++ b/xen/arch/arm/vgic-v2.c
@@ -379,6 +379,7 @@ static bool vgic_v2_to_sgi(struct vcpu *v, register_t sgir)
     enum gic_sgi_mode sgi_mode;
     struct sgi_target target;
 
+    sgi_target_init(&target);
     irqmode = (sgir & GICD_SGI_TARGET_LIST_MASK) >> GICD_SGI_TARGET_LIST_SHIFT;
     virq = (sgir & GICD_SGI_INTID_MASK);
 
@@ -386,7 +387,6 @@ static bool vgic_v2_to_sgi(struct vcpu *v, register_t sgir)
     switch ( irqmode )
     {
     case GICD_SGI_TARGET_LIST_VAL:
-        sgi_target_init(&target);
         target.list = (sgir & GICD_SGI_TARGET_MASK) >> GICD_SGI_TARGET_SHIFT;
         sgi_mode = SGI_TARGET_LIST;
         break;
diff --git a/xen/arch/arm/vgic-v3.c b/xen/arch/arm/vgic-v3.c
index efe824c..c14bcd8 100644
--- a/xen/arch/arm/vgic-v3.c
+++ b/xen/arch/arm/vgic-v3.c
@@ -1474,6 +1474,7 @@ static bool vgic_v3_to_sgi(struct vcpu *v, register_t sgir)
     enum gic_sgi_mode sgi_mode;
     struct sgi_target target;
 
+    sgi_target_init(&target);
     irqmode = (sgir >> ICH_SGI_IRQMODE_SHIFT) & ICH_SGI_IRQMODE_MASK;
     virq = (sgir >> ICH_SGI_IRQ_SHIFT ) & ICH_SGI_IRQ_MASK;
 
@@ -1481,7 +1482,6 @@ static bool vgic_v3_to_sgi(struct vcpu *v, register_t sgir)
     switch ( irqmode )
     {
     case ICH_SGI_TARGET_LIST:
-        sgi_target_init(&target);
         /* We assume that only AFF1 is used in ICC_SGI1R_EL1. */
         target.aff1 = (sgir >> ICH_SGI_AFFINITY_LEVEL(1)) & ICH_SGI_AFFx_MASK;
         target.list = sgir & ICH_SGI_TARGETLIST_MASK;
-- 
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 v2 2/4] xen/arm: initialize access
  2018-10-17 14:30 [PATCH v2 0/4] misc safety certification fixes Stefano Stabellini
  2018-10-17 14:31 ` [PATCH v2 1/4] xen/arm: initialize target Stefano Stabellini
@ 2018-10-17 14:31 ` Stefano Stabellini
  2018-10-17 14:33   ` Razvan Cojocaru
  2018-10-17 14:40   ` Julien Grall
  2018-10-17 14:31 ` [PATCH v2 3/4] xen: introduce __symbol Stefano Stabellini
  2018-10-17 14:31 ` [PATCH v2 4/4] xen: use __symbol everywhere Stefano Stabellini
  3 siblings, 2 replies; 11+ messages in thread
From: Stefano Stabellini @ 2018-10-17 14:31 UTC (permalink / raw)
  To: xen-devel
  Cc: Stefano Stabellini, julien.grall, sstabellini, Tamas K Lengyel,
	rcojocaru

Initialize variable *access before returning it back to the caller.
It makes the code a bit nicer and it is a safety certification
requirement.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
CC: rcojocaru@bitdefender.com
CC: Tamas K Lengyel <tamas@tklengyel.com>
---
Changes in v2:
- improve comment
- use p2m->default_access
---
 xen/arch/arm/mem_access.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/xen/arch/arm/mem_access.c b/xen/arch/arm/mem_access.c
index ba4ec78..86f0882 100644
--- a/xen/arch/arm/mem_access.c
+++ b/xen/arch/arm/mem_access.c
@@ -47,6 +47,7 @@ static int __p2m_get_mem_access(struct domain *d, gfn_t gfn,
     };
 
     ASSERT(p2m_is_locked(p2m));
+    *access = p2m->default_access;
 
     /* If no setting was ever set, just return rwx. */
     if ( !p2m->mem_access_enabled )
-- 
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 v2 3/4] xen: introduce __symbol
  2018-10-17 14:30 [PATCH v2 0/4] misc safety certification fixes Stefano Stabellini
  2018-10-17 14:31 ` [PATCH v2 1/4] xen/arm: initialize target Stefano Stabellini
  2018-10-17 14:31 ` [PATCH v2 2/4] xen/arm: initialize access Stefano Stabellini
@ 2018-10-17 14:31 ` Stefano Stabellini
  2018-10-17 14:48   ` Julien Grall
  2018-10-17 14:31 ` [PATCH v2 4/4] xen: use __symbol everywhere Stefano Stabellini
  3 siblings, 1 reply; 11+ messages in thread
From: Stefano Stabellini @ 2018-10-17 14:31 UTC (permalink / raw)
  To: xen-devel
  Cc: Stefano Stabellini, sstabellini, wei.liu2, andrew.cooper3,
	julien.grall, JBeulich

Introduce a macro, __symbol, which is a simple wrapper around RELOC_HIDE
to be used everywhere symbols such as _stext and _etext are used in the
code.

RELOC_HIDE is needed when accessing symbols such as _stext and _etext
because the C standard forbids comparisons between pointers pointing to
different objects. _stext, _etext, etc. are all pointers to different
objects from ANCI C point of view.

To work around potential C compiler issues (which have actually
been found, see the comment on top of RELOC_HIDE in Linux), and to help
with certifications, let's introduce some syntactic sugar to be used in
following patches.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
CC: JBeulich@suse.com
CC: andrew.cooper3@citrix.com
CC: wei.liu2@citrix.com
---
Changes in v2:
- do not cast return to char*
- move to common header
---
 xen/include/xen/compiler.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h
index ff6c0f5..850b0d0 100644
--- a/xen/include/xen/compiler.h
+++ b/xen/include/xen/compiler.h
@@ -99,6 +99,12 @@
     __asm__ ("" : "=r"(__ptr) : "0"(ptr));      \
     (typeof(ptr)) (__ptr + (off)); })
 
+/*
+ * Use RELOC_HIDE with symbols such as _stext and _etext to avoid errors
+ * on comparing pointers to different objects
+ */
+#define __symbol(x)         (RELOC_HIDE((unsigned long)(x), 0))
+
 #ifdef __GCC_ASM_FLAG_OUTPUTS__
 # define ASM_FLAG_OUT(yes, no) yes
 #else
-- 
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 v2 4/4] xen: use __symbol everywhere
  2018-10-17 14:30 [PATCH v2 0/4] misc safety certification fixes Stefano Stabellini
                   ` (2 preceding siblings ...)
  2018-10-17 14:31 ` [PATCH v2 3/4] xen: introduce __symbol Stefano Stabellini
@ 2018-10-17 14:31 ` Stefano Stabellini
  2018-10-17 14:59   ` Julien Grall
  3 siblings, 1 reply; 11+ messages in thread
From: Stefano Stabellini @ 2018-10-17 14:31 UTC (permalink / raw)
  To: xen-devel
  Cc: Stefano Stabellini, julien.grall, sstabellini, JBeulich,
	andrew.cooper3

Use __symbol everywhere _stext, _etext, etc. are used. Technically, it
is only required when comparing pointers, but use it everywhere to avoid
confusion.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
CC: JBeulich@suse.com
CC: andrew.cooper3@citrix.com
---
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          |  6 +--
 xen/arch/arm/arm32/livepatch.c      |  2 +-
 xen/arch/arm/arm64/livepatch.c      |  2 +-
 xen/arch/arm/domain_build.c         |  2 +-
 xen/arch/arm/livepatch.c            |  6 +--
 xen/arch/arm/mm.c                   | 17 ++++----
 xen/arch/arm/setup.c                |  8 ++--
 xen/arch/x86/setup.c                | 79 +++++++++++++++++++------------------
 xen/arch/x86/tboot.c                | 12 +++---
 xen/arch/x86/x86_64/machine_kexec.c |  4 +-
 xen/include/asm-arm/grant_table.h   |  3 +-
 xen/include/asm-arm/mm.h            |  4 +-
 xen/include/asm-x86/mm.h            |  4 +-
 xen/include/xen/kernel.h            | 24 +++++------
 14 files changed, 90 insertions(+), 83 deletions(-)

diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c
index 52ed7ed..305b337 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(__symbol(_start));
+        paddr_t xen_size = __symbol(_end) - __symbol(_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, xenmap - (void *)__symbol(_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..e71764c 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(_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..4a31026 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(_start) + 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 f552154..40968d0 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2090,7 +2090,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(__symbol(_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..006dff8 100644
--- a/xen/arch/arm/livepatch.c
+++ b/xen/arch/arm/livepatch.c
@@ -26,8 +26,8 @@ int arch_livepatch_quiesce(void)
     if ( vmap_of_xen_text )
         return -EINVAL;
 
-    text_mfn = virt_to_mfn(_start);
-    text_order = get_order_from_bytes(_end - _start);
+    text_mfn = virt_to_mfn(__symbol(_start));
+    text_order = get_order_from_bytes(__symbol(_end) - __symbol(_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(_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 7a06a33..d9d3948 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -620,7 +620,7 @@ void __init setup_pagetables(unsigned long boot_phys_offset, paddr_t xen_paddr)
     int i;
 
     /* Calculate virt-to-phys offset for the new location */
-    phys_offset = xen_paddr - (unsigned long) _start;
+    phys_offset = xen_paddr - (unsigned long) __symbol(_start);
 
 #ifdef CONFIG_ARM_64
     p = (void *) xen_pgtable;
@@ -681,7 +681,8 @@ void __init setup_pagetables(unsigned long boot_phys_offset, paddr_t xen_paddr)
     ttbr = (uintptr_t) cpu0_pgtable + phys_offset;
 #endif
 
-    relocate_xen(ttbr, _start, (void*)dest_va, _end - _start);
+    relocate_xen(ttbr, (void*)__symbol(_start), (void*)dest_va,
+			     __symbol(_end) - __symbol(_start));
 
     /* Clear the copy of the boot pagetables. Each secondary CPU
      * rebuilds these itself (see head.S) */
@@ -1089,7 +1090,7 @@ 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 unsigned long p, unsigned long l, enum mg mg)
 {
     lpae_t pte;
     int i;
@@ -1100,8 +1101,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(_start)) / PAGE_SIZE; 
+          i < (p + l - __symbol(_start)) / PAGE_SIZE; 
           i++ )
     {
         pte = xen_xenmap[i];
@@ -1138,12 +1139,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(__init_end) - __symbol(__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(__init_begin), len, mg_rw);
 #ifdef CONFIG_ARM_32
     /* udf instruction i.e (see A8.8.247 in ARM DDI 0406C.c) */
     insn = 0xe7f000f0;
@@ -1154,7 +1155,7 @@ 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(__init_begin), len, mg_clear);
     init_domheap_pages(pa, pa + len);
     printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10);
 }
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index ea2495a..9d0b915 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -394,7 +394,8 @@ static paddr_t __init get_xen_paddr(void)
     paddr_t paddr = 0;
     int i;
 
-    min_size = (_end - _start + (XEN_PADDR_ALIGN-1)) & ~(XEN_PADDR_ALIGN-1);
+    min_size = (__symbol(_end) - __symbol(_start) +
+			   (XEN_PADDR_ALIGN-1)) & ~(XEN_PADDR_ALIGN-1);
 
     /* Find the highest bank with enough space. */
     for ( i = 0; i < mi->nr_banks; i++ )
@@ -727,8 +728,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), NULL);
+                             (paddr_t)(uintptr_t)(__symbol(_start) + boot_phys_offset),
+                             (paddr_t)(uintptr_t)(__symbol(_end) -
+								                  __symbol(_start) + 1), NULL);
     BUG_ON(!xen_bootmodule);
 
     xen_paddr = get_xen_paddr();
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index 93b79c7..0a7d6c0 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((unsigned long)__symbol(__2M_text_end)) &&
+           !l1_table_offset((unsigned long)__symbol(__2M_rodata_start)) &&
+           !l1_table_offset((unsigned long)__symbol(__2M_rodata_end)) &&
+           !l1_table_offset((unsigned long)__symbol(__2M_init_start)) &&
+           !l1_table_offset((unsigned long)__symbol(__2M_init_end)) &&
+           !l1_table_offset((unsigned long)__symbol(__2M_rwdata_start)) &&
+           !l1_table_offset((unsigned long)__symbol(__2M_rwdata_end));
 }
 
 static void noinline init_done(void)
@@ -606,13 +606,13 @@ 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 = (unsigned long)__symbol(&__2M_init_start),
+        end   = (unsigned long)__symbol(&__2M_init_end);
     }
     else
     {
-        start = (unsigned long)&__init_begin;
-        end   = (unsigned long)&__init_end;
+        start = (unsigned long)__symbol(&__init_begin);
+        end   = (unsigned long)__symbol(&__init_end);
     }
 
     destroy_xen_mappings(start, end);
@@ -966,8 +966,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(__symbol(_stext));
+        mod[mbi->mods_count].mod_end = __symbol(__2M_rwdata_end) - __symbol(_stext);
     }
 
     modules_headroom = bzimage_headroom(bootstrap_map(mod), mod->mod_end);
@@ -1018,7 +1018,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(__symbol(__2M_rwdata_end)) + mask) & ~mask)
         /* Is the region suitable for relocating Xen? */
         if ( !xen_phys_start && e <= limit )
         {
@@ -1034,7 +1034,8 @@ 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(__symbol(_end))) )
         {
             l4_pgentry_t *pl4e;
             l3_pgentry_t *pl3e;
@@ -1062,7 +1063,8 @@ 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,
+					    __symbol(_end) - __symbol(_start), 1);
 
             /* Walk initial pagetables, relocating page directory entries. */
             pl4e = __va(__pa(idle_pg_table));
@@ -1103,8 +1105,8 @@ 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((unsigned long)__symbol(_erodata)) ==
+                   l2_table_offset((unsigned long)__symbol(_stext)));
             *pl2e++ = l2e_from_pfn(xen_phys_start >> PAGE_SHIFT,
                                    PAGE_HYPERVISOR_RX | _PAGE_PSE);
             for ( i = 1; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
@@ -1122,22 +1124,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((unsigned long)__symbol(&__2M_text_end)) )
                 {
                     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((unsigned long)__symbol(&__2M_rodata_start)) &&
+                          i <  l2_table_offset((unsigned long)__symbol(&__2M_rodata_end)) )
                 {
                     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((unsigned long)__symbol(&__2M_init_start)) &&
+                          i <  l2_table_offset((unsigned long)__symbol(&__2M_init_end)) )
                 {
                     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((unsigned long)__symbol(&__2M_rwdata_start)) &&
+                           i <  l2_table_offset((unsigned long)__symbol(&__2M_rwdata_end))) )
                 {
                     flags = PAGE_HYPERVISOR_RW | _PAGE_PSE;
                 }
@@ -1234,7 +1236,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(__symbol(_stext)), __pa(__symbol(__2M_rwdata_end)));
 
     /* Late kexec reservation (dynamic start address). */
     kexec_reserve_area(&boot_e820);
@@ -1377,7 +1379,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     }
 #endif
 
-    xen_virt_end = ((unsigned long)_end + (1UL << L2_PAGETABLE_SHIFT) - 1) &
+    xen_virt_end = ((unsigned long)__symbol(_end) +
+			       (1UL << L2_PAGETABLE_SHIFT) - 1) &
                    ~((1UL << L2_PAGETABLE_SHIFT) - 1);
     destroy_xen_mappings(xen_virt_end, XEN_VIRT_START + BOOTSTRAP_MAP_BASE);
 
@@ -1390,22 +1393,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,
+                            (unsigned long)__symbol(&__2M_text_end),
                             PAGE_HYPERVISOR_RX);
 
         /* Mark .rodata as RO. */
-        modify_xen_mappings((unsigned long)&__2M_rodata_start,
-                            (unsigned long)&__2M_rodata_end,
+        modify_xen_mappings((unsigned long)__symbol(&__2M_rodata_start),
+                            (unsigned long)__symbol(&__2M_rodata_end),
                             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((unsigned long)__symbol(&__2M_rwdata_start),
+                            (unsigned long)__symbol(&__2M_rwdata_end),
                             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((unsigned long)__symbol(&__2M_rwdata_end),
+                             ROUNDUP((unsigned long)__symbol(&__2M_rwdata_end), MB(2)));
     }
 
     nr_pages = 0;
@@ -1860,11 +1863,11 @@ 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].s = __pa(__symbol(&_stext));
+        xen_regions[region_ro].e = __pa(__symbol(&__2M_rodata_end));
         /* 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(__symbol(&__2M_rwdata_start));
+        xen_regions[region_rw].e = __pa(__symbol(&__2M_rwdata_end));
     }
 
     start = (paddr_t)mfn << PAGE_SHIFT;
diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c
index f3fdee4..032bf8e 100644
--- a/xen/arch/x86/tboot.c
+++ b/xen/arch/x86/tboot.c
@@ -373,13 +373,13 @@ 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].size = __pa(&__2M_rodata_end) -
-                                              __pa(&_stext);
+        g_tboot_shared->mac_regions[1].start = (uint64_t)__pa(__symbol(&_stext));
+        g_tboot_shared->mac_regions[1].size = __pa(__symbol(&__2M_rodata_end)) -
+                                              __pa(__symbol(&_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(__symbol(&__2M_rwdata_start));
+        g_tboot_shared->mac_regions[2].size = __pa(__symbol(&__2M_rwdata_end)) -
+                                              __pa(__symbol(&__2M_rwdata_start));
 
         /*
          * MAC domains and other Xen memory
diff --git a/xen/arch/x86/x86_64/machine_kexec.c b/xen/arch/x86/x86_64/machine_kexec.c
index f4a005c..7840761 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(__symbol(_start));
+        range->size = virt_to_maddr(__symbol(_end)) - (unsigned long)range->start;
         return 0;
 }
 
diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_table.h
index 37415b7..865a073 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(_etext) - __symbol(_stext)))
 
 #define gnttab_init_arch(gt)                                             \
 ({                                                                       \
diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h
index 940b74b..b00a17c 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(__symbol(&_start))) && \
+     (pfn_to_paddr(mfn) <= virt_to_maddr(__symbol(&_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 6e45651..b49d00c 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -273,8 +273,8 @@ 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(&__2M_rwdata_end)))
+    ((((mfn) << PAGE_SHIFT) >= __pa(__symbol(&_stext))) &&  \
+     (((mfn) << PAGE_SHIFT) <= __pa(__symbol(&__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..7600a7f 100644
--- a/xen/include/xen/kernel.h
+++ b/xen/include/xen/kernel.h
@@ -66,27 +66,27 @@
 })
 
 extern char _start[], _end[], start[];
-#define is_kernel(p) ({                         \
-    char *__p = (char *)(unsigned long)(p);     \
-    (__p >= _start) && (__p < _end);            \
+#define is_kernel(p) ({                                             \
+    const unsigned long __p = (unsigned long)(p);                   \
+    (__p >= __symbol(_start)) && (__p < __symbol(_end));            \
 })
 
 extern char _stext[], _etext[];
-#define is_kernel_text(p) ({                    \
-    char *__p = (char *)(unsigned long)(p);     \
-    (__p >= _stext) && (__p < _etext);          \
+#define is_kernel_text(p) ({                                        \
+    const unsigned long __p = (unsigned long)(p);                   \
+    (__p >= __symbol(_stext)) && (__p < __symbol(_etext));          \
 })
 
 extern const char _srodata[], _erodata[];
-#define is_kernel_rodata(p) ({                  \
-    const char *__p = (const char *)(unsigned long)(p);     \
-    (__p >= _srodata) && (__p < _erodata);      \
+#define is_kernel_rodata(p) ({                                      \
+    const unsigned long __p = (unsigned long)(p);                   \
+    (__p >= __symbol(_srodata)) && (__p < __symbol(_erodata));      \
 })
 
 extern char _sinittext[], _einittext[];
-#define is_kernel_inittext(p) ({                \
-    char *__p = (char *)(unsigned long)(p);     \
-    (__p >= _sinittext) && (__p < _einittext);  \
+#define is_kernel_inittext(p) ({                                    \
+    const unsigned long __p = (unsigned long)(p);                   \
+    (__p >= __symbol(_sinittext)) && (__p < __symbol(_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

* Re: [PATCH v2 2/4] xen/arm: initialize access
  2018-10-17 14:31 ` [PATCH v2 2/4] xen/arm: initialize access Stefano Stabellini
@ 2018-10-17 14:33   ` Razvan Cojocaru
  2018-10-17 14:40   ` Julien Grall
  1 sibling, 0 replies; 11+ messages in thread
From: Razvan Cojocaru @ 2018-10-17 14:33 UTC (permalink / raw)
  To: Stefano Stabellini, xen-devel
  Cc: Stefano Stabellini, julien.grall, Tamas K Lengyel

On 10/17/18 5:31 PM, Stefano Stabellini wrote:
> Initialize variable *access before returning it back to the caller.
> It makes the code a bit nicer and it is a safety certification
> requirement.
> 
> Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> CC: rcojocaru@bitdefender.com
> CC: Tamas K Lengyel <tamas@tklengyel.com>

Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>


Thanks,
Razvan

_______________________________________________
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 v2 1/4] xen/arm: initialize target
  2018-10-17 14:31 ` [PATCH v2 1/4] xen/arm: initialize target Stefano Stabellini
@ 2018-10-17 14:40   ` Julien Grall
  0 siblings, 0 replies; 11+ messages in thread
From: Julien Grall @ 2018-10-17 14:40 UTC (permalink / raw)
  To: Stefano Stabellini, xen-devel; +Cc: Stefano Stabellini

Hi,

On 17/10/2018 15:31, Stefano Stabellini wrote:
> Initialize variable target before passing it as a parameter.
> It makes the code a bit nicer and it is a safety certification
> requirement.

While I know why this is a certification requirement, it may not be the 
case for other on the mailing list. Please write down at least the rule 
number.

Also, it might also be good to start using a tag similar to coverity (I 
am assuming the bug ID are uniq) for tracking what has been fixed.

Cheers,

> 
> Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> ---
> Changes in v2:
> - improve comment
> ---
>   xen/arch/arm/vgic-v2.c | 2 +-
>   xen/arch/arm/vgic-v3.c | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/arch/arm/vgic-v2.c b/xen/arch/arm/vgic-v2.c
> index f6c11f1..0099fcf 100644
> --- a/xen/arch/arm/vgic-v2.c
> +++ b/xen/arch/arm/vgic-v2.c
> @@ -379,6 +379,7 @@ static bool vgic_v2_to_sgi(struct vcpu *v, register_t sgir)
>       enum gic_sgi_mode sgi_mode;
>       struct sgi_target target;
>   
> +    sgi_target_init(&target);
>       irqmode = (sgir & GICD_SGI_TARGET_LIST_MASK) >> GICD_SGI_TARGET_LIST_SHIFT;
>       virq = (sgir & GICD_SGI_INTID_MASK);
>   
> @@ -386,7 +387,6 @@ static bool vgic_v2_to_sgi(struct vcpu *v, register_t sgir)
>       switch ( irqmode )
>       {
>       case GICD_SGI_TARGET_LIST_VAL:
> -        sgi_target_init(&target);
>           target.list = (sgir & GICD_SGI_TARGET_MASK) >> GICD_SGI_TARGET_SHIFT;
>           sgi_mode = SGI_TARGET_LIST;
>           break;
> diff --git a/xen/arch/arm/vgic-v3.c b/xen/arch/arm/vgic-v3.c
> index efe824c..c14bcd8 100644
> --- a/xen/arch/arm/vgic-v3.c
> +++ b/xen/arch/arm/vgic-v3.c
> @@ -1474,6 +1474,7 @@ static bool vgic_v3_to_sgi(struct vcpu *v, register_t sgir)
>       enum gic_sgi_mode sgi_mode;
>       struct sgi_target target;
>   
> +    sgi_target_init(&target);
>       irqmode = (sgir >> ICH_SGI_IRQMODE_SHIFT) & ICH_SGI_IRQMODE_MASK;
>       virq = (sgir >> ICH_SGI_IRQ_SHIFT ) & ICH_SGI_IRQ_MASK;
>   
> @@ -1481,7 +1482,6 @@ static bool vgic_v3_to_sgi(struct vcpu *v, register_t sgir)
>       switch ( irqmode )
>       {
>       case ICH_SGI_TARGET_LIST:
> -        sgi_target_init(&target);
>           /* We assume that only AFF1 is used in ICC_SGI1R_EL1. */
>           target.aff1 = (sgir >> ICH_SGI_AFFINITY_LEVEL(1)) & ICH_SGI_AFFx_MASK;
>           target.list = sgir & ICH_SGI_TARGETLIST_MASK;
> 

-- 
Julien Grall

_______________________________________________
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 v2 2/4] xen/arm: initialize access
  2018-10-17 14:31 ` [PATCH v2 2/4] xen/arm: initialize access Stefano Stabellini
  2018-10-17 14:33   ` Razvan Cojocaru
@ 2018-10-17 14:40   ` Julien Grall
  1 sibling, 0 replies; 11+ messages in thread
From: Julien Grall @ 2018-10-17 14:40 UTC (permalink / raw)
  To: Stefano Stabellini, xen-devel
  Cc: Stefano Stabellini, Tamas K Lengyel, rcojocaru



On 17/10/2018 15:31, Stefano Stabellini wrote:
> Initialize variable *access before returning it back to the caller.
> It makes the code a bit nicer and it is a safety certification
> requirement.

Same as previous patch.

> 
> Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> CC: rcojocaru@bitdefender.com
> CC: Tamas K Lengyel <tamas@tklengyel.com>
> ---
> Changes in v2:
> - improve comment
> - use p2m->default_access
> ---
>   xen/arch/arm/mem_access.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/xen/arch/arm/mem_access.c b/xen/arch/arm/mem_access.c
> index ba4ec78..86f0882 100644
> --- a/xen/arch/arm/mem_access.c
> +++ b/xen/arch/arm/mem_access.c
> @@ -47,6 +47,7 @@ static int __p2m_get_mem_access(struct domain *d, gfn_t gfn,
>       };
>   
>       ASSERT(p2m_is_locked(p2m));
> +    *access = p2m->default_access;
>   
>       /* If no setting was ever set, just return rwx. */
>       if ( !p2m->mem_access_enabled )
> 

-- 
Julien Grall

_______________________________________________
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 v2 3/4] xen: introduce __symbol
  2018-10-17 14:31 ` [PATCH v2 3/4] xen: introduce __symbol Stefano Stabellini
@ 2018-10-17 14:48   ` Julien Grall
  0 siblings, 0 replies; 11+ messages in thread
From: Julien Grall @ 2018-10-17 14:48 UTC (permalink / raw)
  To: Stefano Stabellini, xen-devel
  Cc: Stefano Stabellini, wei.liu2, JBeulich, andrew.cooper3



On 17/10/2018 15:31, Stefano Stabellini wrote:
> Introduce a macro, __symbol, which is a simple wrapper around RELOC_HIDE
> to be used everywhere symbols such as _stext and _etext are used in the
> code.
> 
> RELOC_HIDE is needed when accessing symbols such as _stext and _etext
> because the C standard forbids comparisons between pointers pointing to
> different objects.

The C standard forbids for both comparisons and substraction (see C 
Standard, 6.5.6 [ISO/IEC 9899:2011] and [1]). Also, it is probably worth 
to give a pointer to the paragraph in the standard to help finding more 
details.

Cheers,

[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

> _stext, _etext, etc. are all pointers to different
> objects from ANCI C point of view.
> 
> To work around potential C compiler issues (which have actually
> been found, see the comment on top of RELOC_HIDE in Linux), and to help
> with certifications, let's introduce some syntactic sugar to be used in
> following patches.
> 
> Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> CC: JBeulich@suse.com
> CC: andrew.cooper3@citrix.com
> CC: wei.liu2@citrix.com
> ---
> Changes in v2:
> - do not cast return to char*
> - move to common header
> ---
>   xen/include/xen/compiler.h | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h
> index ff6c0f5..850b0d0 100644
> --- a/xen/include/xen/compiler.h
> +++ b/xen/include/xen/compiler.h
> @@ -99,6 +99,12 @@
>       __asm__ ("" : "=r"(__ptr) : "0"(ptr));      \
>       (typeof(ptr)) (__ptr + (off)); })
>   
> +/*
> + * Use RELOC_HIDE with symbols such as _stext and _etext to avoid errors
> + * on comparing pointers to different objects
> + */
> +#define __symbol(x)         (RELOC_HIDE((unsigned long)(x), 0))
> +
>   #ifdef __GCC_ASM_FLAG_OUTPUTS__
>   # define ASM_FLAG_OUT(yes, no) yes
>   #else
> 

-- 
Julien Grall

_______________________________________________
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 v2 4/4] xen: use __symbol everywhere
  2018-10-17 14:31 ` [PATCH v2 4/4] xen: use __symbol everywhere Stefano Stabellini
@ 2018-10-17 14:59   ` Julien Grall
  2018-11-06 22:01     ` Stefano Stabellini
  0 siblings, 1 reply; 11+ messages in thread
From: Julien Grall @ 2018-10-17 14:59 UTC (permalink / raw)
  To: Stefano Stabellini, xen-devel
  Cc: Stefano Stabellini, JBeulich, andrew.cooper3

Hi,

On 17/10/2018 15:31, Stefano Stabellini wrote:
> Use __symbol everywhere _stext, _etext, etc. are used. Technically, it
> is only required when comparing pointers, but use it everywhere to avoid

Well no. It is also required when substracting pointers (see [1]).

> confusion.

[...]

> diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c
> index 52ed7ed..305b337 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(__symbol(_start));
> +        paddr_t xen_size = __symbol(_end) - __symbol(_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, xenmap - (void *)__symbol(_start));

For instance, I think this line would be contain undefined behavior. 
There are probably others below.

[...]

> diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
> index 7a06a33..d9d3948 100644
> --- a/xen/arch/arm/mm.c
> +++ b/xen/arch/arm/mm.c
> @@ -620,7 +620,7 @@ void __init setup_pagetables(unsigned long boot_phys_offset, paddr_t xen_paddr)
>       int i;
>   
>       /* Calculate virt-to-phys offset for the new location */
> -    phys_offset = xen_paddr - (unsigned long) _start;
> +    phys_offset = xen_paddr - (unsigned long) __symbol(_start);
>   
>   #ifdef CONFIG_ARM_64
>       p = (void *) xen_pgtable;
> @@ -681,7 +681,8 @@ void __init setup_pagetables(unsigned long boot_phys_offset, paddr_t xen_paddr)
>       ttbr = (uintptr_t) cpu0_pgtable + phys_offset;
>   #endif
>   
> -    relocate_xen(ttbr, _start, (void*)dest_va, _end - _start);
> +    relocate_xen(ttbr, (void*)__symbol(_start), (void*)dest_va,
> +			     __symbol(_end) - __symbol(_start));

No hard tab.

[...]

> diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
> index ea2495a..9d0b915 100644
> --- a/xen/arch/arm/setup.c
> +++ b/xen/arch/arm/setup.c
> @@ -394,7 +394,8 @@ static paddr_t __init get_xen_paddr(void)
>       paddr_t paddr = 0;
>       int i;
>   
> -    min_size = (_end - _start + (XEN_PADDR_ALIGN-1)) & ~(XEN_PADDR_ALIGN-1);
> +    min_size = (__symbol(_end) - __symbol(_start) +
> +			   (XEN_PADDR_ALIGN-1)) & ~(XEN_PADDR_ALIGN-1);
>   
>       /* Find the highest bank with enough space. */
>       for ( i = 0; i < mi->nr_banks; i++ )
> @@ -727,8 +728,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), NULL);
> +                             (paddr_t)(uintptr_t)(__symbol(_start) + boot_phys_offset),
> +                             (paddr_t)(uintptr_t)(__symbol(_end) -
> +								                  __symbol(_start) + 1), NULL);

No hard tab.

>       BUG_ON(!xen_bootmodule);
>   
>       xen_paddr = get_xen_paddr();
> diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
> index 93b79c7..0a7d6c0 100644
> --- a/xen/arch/x86/setup.c
> +++ b/xen/arch/x86/setup.c

[...]

> @@ -1390,22 +1393,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,
> +                            (unsigned long)__symbol(&__2M_text_end),
>                               PAGE_HYPERVISOR_RX);
>   
>           /* Mark .rodata as RO. */
> -        modify_xen_mappings((unsigned long)&__2M_rodata_start,
> -                            (unsigned long)&__2M_rodata_end,
> +        modify_xen_mappings((unsigned long)__symbol(&__2M_rodata_start),
> +                            (unsigned long)__symbol(&__2M_rodata_end),

AFAICT the return of __symbol should be unsigned long, right? If so, the 
cast could be removed.

Cheers,

[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

-- 
Julien Grall

_______________________________________________
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 v2 4/4] xen: use __symbol everywhere
  2018-10-17 14:59   ` Julien Grall
@ 2018-11-06 22:01     ` Stefano Stabellini
  0 siblings, 0 replies; 11+ messages in thread
From: Stefano Stabellini @ 2018-11-06 22:01 UTC (permalink / raw)
  To: Julien Grall
  Cc: xen-devel, Stefano Stabellini, andrew.cooper3, JBeulich,
	Stefano Stabellini

On Wed, 17 Oct 2018, Julien Grall wrote:
> Hi,
> 
> On 17/10/2018 15:31, Stefano Stabellini wrote:
> > Use __symbol everywhere _stext, _etext, etc. are used. Technically, it
> > is only required when comparing pointers, but use it everywhere to avoid
> 
> Well no. It is also required when substracting pointers (see [1]).
> 
> > confusion.
> 
> [...]
> 
> > diff --git a/xen/arch/arm/alternative.c b/xen/arch/arm/alternative.c
> > index 52ed7ed..305b337 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(__symbol(_start));
> > +        paddr_t xen_size = __symbol(_end) - __symbol(_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, xenmap - (void
> > *)__symbol(_start));
> 
> For instance, I think this line would be contain undefined behavior. There are
> probably others below.

I'll fix


> [...]
> 
> > diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
> > index 7a06a33..d9d3948 100644
> > --- a/xen/arch/arm/mm.c
> > +++ b/xen/arch/arm/mm.c
> > @@ -620,7 +620,7 @@ void __init setup_pagetables(unsigned long
> > boot_phys_offset, paddr_t xen_paddr)
> >       int i;
> >         /* Calculate virt-to-phys offset for the new location */
> > -    phys_offset = xen_paddr - (unsigned long) _start;
> > +    phys_offset = xen_paddr - (unsigned long) __symbol(_start);
> >     #ifdef CONFIG_ARM_64
> >       p = (void *) xen_pgtable;
> > @@ -681,7 +681,8 @@ void __init setup_pagetables(unsigned long
> > boot_phys_offset, paddr_t xen_paddr)
> >       ttbr = (uintptr_t) cpu0_pgtable + phys_offset;
> >   #endif
> >   -    relocate_xen(ttbr, _start, (void*)dest_va, _end - _start);
> > +    relocate_xen(ttbr, (void*)__symbol(_start), (void*)dest_va,
> > +			     __symbol(_end) - __symbol(_start));
> 
> No hard tab.
> 
> [...]
> 
> > diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
> > index ea2495a..9d0b915 100644
> > --- a/xen/arch/arm/setup.c
> > +++ b/xen/arch/arm/setup.c
> > @@ -394,7 +394,8 @@ static paddr_t __init get_xen_paddr(void)
> >       paddr_t paddr = 0;
> >       int i;
> >   -    min_size = (_end - _start + (XEN_PADDR_ALIGN-1)) &
> > ~(XEN_PADDR_ALIGN-1);
> > +    min_size = (__symbol(_end) - __symbol(_start) +
> > +			   (XEN_PADDR_ALIGN-1)) & ~(XEN_PADDR_ALIGN-1);
> >         /* Find the highest bank with enough space. */
> >       for ( i = 0; i < mi->nr_banks; i++ )
> > @@ -727,8 +728,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),
> > NULL);
> > +                             (paddr_t)(uintptr_t)(__symbol(_start) +
> > boot_phys_offset),
> > +                             (paddr_t)(uintptr_t)(__symbol(_end) -
> > +
> > __symbol(_start) + 1), NULL);
> 
> No hard tab.
> 
> >       BUG_ON(!xen_bootmodule);
> >         xen_paddr = get_xen_paddr();
> > diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
> > index 93b79c7..0a7d6c0 100644
> > --- a/xen/arch/x86/setup.c
> > +++ b/xen/arch/x86/setup.c
> 
> [...]
> 
> > @@ -1390,22 +1393,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,
> > +                            (unsigned long)__symbol(&__2M_text_end),
> >                               PAGE_HYPERVISOR_RX);
> >             /* Mark .rodata as RO. */
> > -        modify_xen_mappings((unsigned long)&__2M_rodata_start,
> > -                            (unsigned long)&__2M_rodata_end,
> > +        modify_xen_mappings((unsigned long)__symbol(&__2M_rodata_start),
> > +                            (unsigned long)__symbol(&__2M_rodata_end),
> 
> AFAICT the return of __symbol should be unsigned long, right? If so, the cast
> could be removed.

I'll fix


> Cheers,
> 
> [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
> 
> -- 
> Julien Grall
> 

_______________________________________________
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:[~2018-11-06 22:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-17 14:30 [PATCH v2 0/4] misc safety certification fixes Stefano Stabellini
2018-10-17 14:31 ` [PATCH v2 1/4] xen/arm: initialize target Stefano Stabellini
2018-10-17 14:40   ` Julien Grall
2018-10-17 14:31 ` [PATCH v2 2/4] xen/arm: initialize access Stefano Stabellini
2018-10-17 14:33   ` Razvan Cojocaru
2018-10-17 14:40   ` Julien Grall
2018-10-17 14:31 ` [PATCH v2 3/4] xen: introduce __symbol Stefano Stabellini
2018-10-17 14:48   ` Julien Grall
2018-10-17 14:31 ` [PATCH v2 4/4] xen: use __symbol everywhere Stefano Stabellini
2018-10-17 14:59   ` Julien Grall
2018-11-06 22:01     ` Stefano Stabellini

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.