From patchwork Mon Jun 17 14:33:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 167063 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2983525ilk; Mon, 17 Jun 2019 08:10:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZgywBS1Q1/yhZRJD8CpjdeNn1xH0QzAk9HwU+Ci2MOfkpYjxXLZuHD+H/bBvZXbbRo66h X-Received: by 2002:a50:ba19:: with SMTP id g25mr36179516edc.123.1560784219018; Mon, 17 Jun 2019 08:10:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560784219; cv=none; d=google.com; s=arc-20160816; b=zOdQvXq0Z04JhD94LAxyDyfV/pEzy8ssOjL+qa0pLIcS3K2sRu+SwMMejNXHcSlY13 saXzHEbrfHhg5Zj8jn9DOKCtz6TNbuJ3CfKKFYf3epFxFZkn9wnMXVHdYZP61u9j9qdh deD/dTJuQ39+IzbquCqpitM+F8Slg5CzBZJCw4BQlkdV4zksX9zhS4wy4yDPDhz14z7V jmMbzwl8vx/FIG7TAPLKExjokiTyKO/zp/wLCgBIvbN2AVgKIp+Cs8WdZzcOknqLIHmW s+C5ESRFwqWmPy8HNSC3HnwzBwL6XofPpYh8mfdbBhT/44bkjzccnFKkdpGzZ80XvKCJ wG5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=OwEVsvj6AmcZtJrR0oDBzLmj1hc9aGGjVH7CWfs5T2E=; b=imOuP/UNk5udvJt15lC/T94+bAJt0qT75cyIc+JYjPAyJriCO4XIhuCBTxtFxB4UKt D/sH1kt/PsAegTmk8uspbM9XeakiVR4UxpQblgB0dkjko0lYiwDwVgRtuwChIhgxmfiN j1q3zRl4Hqa0edKJte1VrKKusSSnmJwxe0YJ7cizmI9U5QbYcAr2819NvJFP4ybWtF6t 5SF/gswcEtw7OTs8yrsRg/VH3lv6gS2j6AV2Hju/2F2SJOkw2ob8SgRTl0sQQCXM8f86 g7AH4sp6lvlAzRiAASzo2FHc+ko5X60bwC7/vohGLFF6QGaFxnO023Sbj43IF7KooeAl Uosg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wegP1t44; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o3si7196914ejj.191.2019.06.17.08.10.18 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 Jun 2019 08:10:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wegP1t44; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hctGz-0002mS-Bg for patch@linaro.org; Mon, 17 Jun 2019 11:10:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46579) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hcsiF-0003RW-Ms for qemu-devel@nongnu.org; Mon, 17 Jun 2019 10:34:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hcsiE-0007zt-9R for qemu-devel@nongnu.org; Mon, 17 Jun 2019 10:34:23 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:33072) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hcsiD-0007xa-UH for qemu-devel@nongnu.org; Mon, 17 Jun 2019 10:34:22 -0400 Received: by mail-wm1-x344.google.com with SMTP id h19so117900wme.0 for ; Mon, 17 Jun 2019 07:34:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OwEVsvj6AmcZtJrR0oDBzLmj1hc9aGGjVH7CWfs5T2E=; b=wegP1t44P2f0nUSY72d/uE57QLjqjC37ewmdo3sooKaNpoK8SLdF3qf6xqGtYIHie8 SpRfUgYlqvQ5pJC/5K0Up6Dy0UaOSSr/JLYwjoagiNC7m+sdTVnHJC3dyD2PIUpM2J4V vYTRs974RysUekh/crvCRYKuf1phnSqYQ959ZXXUEj9RHYAs1yOEL6BWkyqjX3e+KNUv 8Ccwrqe3tPfeKPuBM7YsYhTMEKtPS36/ZJBjrP1kfj2sLn4wJd3UB5OOqXqqVqHnwiHB AjT6T4AArSH99Gf3ltwRNBPYMicBqlIenD21KdKINhmGrHwn1/44CBy1WJp1aNhEMSY8 6OzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OwEVsvj6AmcZtJrR0oDBzLmj1hc9aGGjVH7CWfs5T2E=; b=eucoFsnKLqUugIn/uNS4hkqOqpAc+exzo/eBvoGyisP9Eb/Sk7glbS62yqNgwuwJXf S/Y6ZnIGFb+uhfRnT/ea01PPi0lEVYcIvcjQfDzKCYPPRpUUL3rlLjwDtVc+haWdEdoo L4jVTAZ5G7UX9FzKzQC1f0AtrN0yzNRNX6N/gOUNIOOetSJTmq0tkDqpOfdZZWQDZiGV JkNYZ/CmDBiORe/ySgTluY8K1T+CBmo2NH6jyB3b5n2/47YvGn3S4pTni6F87JAvvueK YD0rg/U5w7dsddECrQwJNjYHXOLok4d/tkQkP96xUK9r+Fy8UKz824WaV/B324q7eD3w aG9w== X-Gm-Message-State: APjAAAVthE94w9V91eZGvb/iBOYQ4lw2spMgz64i6T/UkEW/d2JQuq+a /VbsdAPoT7jLXzoguudZQnCU1hHQN8NeCg== X-Received: by 2002:a1c:9d86:: with SMTP id g128mr20844483wme.51.1560782058298; Mon, 17 Jun 2019 07:34:18 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a67sm13819985wmh.40.2019.06.17.07.34.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jun 2019 07:34:17 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jun 2019 15:33:51 +0100 Message-Id: <20190617143412.5734-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190617143412.5734-1-peter.maydell@linaro.org> References: <20190617143412.5734-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 Subject: [Qemu-devel] [PULL 03/24] hw/arm/boot: Avoid placing the initrd on top of the kernel X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We currently put the initrd at the smaller of: * 128MB into RAM * halfway into the RAM (with the dtb following it). However for large kernels this might mean that the kernel overlaps the initrd. For some kinds of kernel (self-decompressing 32-bit kernels, and ELF images with a BSS section at the end) we don't know the exact size, but even there we have a minimum size. Put the initrd at least further into RAM than that. For image formats that can give us an exact kernel size, this will mean that we definitely avoid overlaying kernel and initrd. Signed-off-by: Peter Maydell Reviewed-by: Alex Bennée Tested-by: Mark Rutland Message-id: 20190516144733.32399-4-peter.maydell@linaro.org --- hw/arm/boot.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) -- 2.20.1 diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 5ddba727d45..a0e1110719e 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -1000,20 +1000,6 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu, if (info->nb_cpus == 0) info->nb_cpus = 1; - /* - * We want to put the initrd far enough into RAM that when the - * kernel is uncompressed it will not clobber the initrd. However - * on boards without much RAM we must ensure that we still leave - * enough room for a decent sized initrd, and on boards with large - * amounts of RAM we must avoid the initrd being so far up in RAM - * that it is outside lowmem and inaccessible to the kernel. - * So for boards with less than 256MB of RAM we put the initrd - * halfway into RAM, and for boards with 256MB of RAM or more we put - * the initrd at 128MB. - */ - info->initrd_start = info->loader_start + - MIN(info->ram_size / 2, 128 * 1024 * 1024); - /* Assume that raw images are linux kernels, and ELF images are not. */ kernel_size = arm_load_elf(info, &elf_entry, &elf_low_addr, &elf_high_addr, elf_machine, as); @@ -1065,6 +1051,26 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu, } info->entry = entry; + + /* + * We want to put the initrd far enough into RAM that when the + * kernel is uncompressed it will not clobber the initrd. However + * on boards without much RAM we must ensure that we still leave + * enough room for a decent sized initrd, and on boards with large + * amounts of RAM we must avoid the initrd being so far up in RAM + * that it is outside lowmem and inaccessible to the kernel. + * So for boards with less than 256MB of RAM we put the initrd + * halfway into RAM, and for boards with 256MB of RAM or more we put + * the initrd at 128MB. + * We also refuse to put the initrd somewhere that will definitely + * overlay the kernel we just loaded, though for kernel formats which + * don't tell us their exact size (eg self-decompressing 32-bit kernels) + * we might still make a bad choice here. + */ + info->initrd_start = info->loader_start + + MAX(MIN(info->ram_size / 2, 128 * 1024 * 1024), kernel_size); + info->initrd_start = TARGET_PAGE_ALIGN(info->initrd_start); + if (is_linux) { uint32_t fixupcontext[FIXUP_MAX];