From patchwork Mon Jul 13 16:50:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 494644 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 57B9D1402AE for ; Tue, 14 Jul 2015 02:51:23 +1000 (AEST) Received: from localhost ([::1]:55846 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEgwr-0007Ai-Ek for incoming@patchwork.ozlabs.org; Mon, 13 Jul 2015 12:51:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEgwZ-0006sR-Cr for qemu-devel@nongnu.org; Mon, 13 Jul 2015 12:51:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZEgwS-0005u6-H4 for qemu-devel@nongnu.org; Mon, 13 Jul 2015 12:51:03 -0400 Received: from cantor2.suse.de ([195.135.220.15]:50147 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEgwS-0005tm-Bi for qemu-devel@nongnu.org; Mon, 13 Jul 2015 12:50:56 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8995DAAF2; Mon, 13 Jul 2015 16:50:55 +0000 (UTC) From: Alexander Graf To: qemu-devel@nongnu.org Date: Mon, 13 Jul 2015 18:50:55 +0200 Message-Id: <1436806255-175781-1-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.7.12.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 Cc: Andreas Schwab , peter.maydell@linaro.org Subject: [Qemu-devel] [PATCH] hw/arm/boot: Increase fdt alignment X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- v1 -> v2: - Restrict new alignment to AArch64 guests --- 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); }