diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 07e2037e9b..99588a330d 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -994,8 +994,21 @@ void free_init_memory(void) { 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); - memset(__init_begin, 0xcc, len); +#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; + for ( i = 0; i < nr; i++ ) + *(p + i) = insn; + 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); diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index 47b910d1eb..ddef59537b 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -221,3 +221,9 @@ SECTIONS * code running on the boot time identity map cannot cross a section boundary. */ ASSERT( _end_boot - start <= PAGE_SIZE, "Boot code is larger than 4K") +/* + * __init_[begin|end] MUST be at word size boundary otherwise we cannot + * write fault instructions in the space properly. + */ +ASSERT(IS_ALIGNED(__init_begin, 4), "__init_begin is misaligned") +ASSERT(IS_ALIGNED(__init_end, 4), "__init_end is misaligned")