From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFPVQ-0007tU-RE for qemu-devel@nongnu.org; Wed, 15 Jul 2015 12:26:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFPVP-0002oj-LX for qemu-devel@nongnu.org; Wed, 15 Jul 2015 12:26:00 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:34614) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFPVP-0002lZ-2S for qemu-devel@nongnu.org; Wed, 15 Jul 2015 12:25:59 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1ZFPVG-00084E-MQ for qemu-devel@nongnu.org; Wed, 15 Jul 2015 17:25:50 +0100 From: Peter Maydell Date: Wed, 15 Jul 2015 17:25:50 +0100 Message-Id: <1436977550-30977-3-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1436977550-30977-1-git-send-email-peter.maydell@linaro.org> References: <1436977550-30977-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PULL 2/2] hw/arm/boot: Increase fdt alignment List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Alexander Graf The Linux kernel on aarch64 creates a page table entry at early bootup that spans the 2MB range on memory spanning the fdt start address: [ ALIGN_DOWN(fdt, 2MB) ... ALIGN_DOWN(fdt, 2MB) + 2MB ] This means that when our current 4k alignment happens to fall at the end of the aligned region, Linux tries to access memory that is not mapped. The easy fix is to instead increase the alignment to 2MB, making Linux's logic always succeed. We leave the existing 4k alignment for 32bit kernels to not cause any regressions due to space constraints. Reported-by: Andreas Schwab Signed-off-by: Alexander Graf Signed-off-by: Peter Maydell --- hw/arm/boot.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index f48ed2d..5b969cd 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -735,12 +735,28 @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) * we point to the kernel args. */ if (have_dtb(info)) { - /* Place the DTB after the initrd in memory. Note that some - * kernels will trash anything in the 4K page the initrd - * ends in, so make sure the DTB isn't caught up in that. - */ - hwaddr dtb_start = QEMU_ALIGN_UP(info->initrd_start + initrd_size, - 4096); + hwaddr align; + hwaddr dtb_start; + + if (elf_machine == EM_AARCH64) { + /* + * Some AArch64 kernels on early bootup map the fdt region as + * + * [ ALIGN_DOWN(fdt, 2MB) ... ALIGN_DOWN(fdt, 2MB) + 2MB ] + * + * Let's play safe and prealign it to 2MB to give us some space. + */ + align = 2 * 1024 * 1024; + } else { + /* + * Some 32bit kernels will trash anything in the 4K page the + * initrd ends in, so make sure the DTB isn't caught up in that. + */ + align = 4096; + } + + /* Place the DTB after the initrd in memory with alignment. */ + dtb_start = QEMU_ALIGN_UP(info->initrd_start + initrd_size, align); if (load_dtb(dtb_start, info, 0) < 0) { exit(1); } -- 1.9.1