From patchwork Mon Jun 17 14:33:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 167045 Delivered-To: patch@linaro.org Received: by 2002:ac9:6410:0:0:0:0:0 with SMTP id r16csp1094938ock; Mon, 17 Jun 2019 07:48:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNVo4mWeyJtHQU4xF0QlQ5IAnD8qsd6KyTr4k6sVGyx1WTkBokPa//UvQfmXodnwMsNftC X-Received: by 2002:a17:906:401a:: with SMTP id v26mr79068480ejj.62.1560782901307; Mon, 17 Jun 2019 07:48:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560782901; cv=none; d=google.com; s=arc-20160816; b=YQKfhowPJb6/JIx2/Q8HTmBqZeijGR8yjIfhAhDJQMjuJZEZU/wia/9oOSLLCOcXJU FcaY+TJfLO4Kj93d6rUezUldVBygvxjxtkTGiVfdIB8Lg0ADElIgkQcmpMXFXYhoi/Ss 4xxDS8KubxUMVxtwKoJiLRQQzPQcBuCe/sR4PeiI9oke4csDmUvsO1CLJ5Qj/pPR7vru hvUY5eZhcwEpFG9OA1NF/SWV6P9W44wUi3YMFjGvtKmiiRxfCdDEPPwoCrtf398PY4CN RbFmcmC8rCisR0FZCHivPgCNw/TlJzkq7MgDyOGD3Od7GEPaE6+PzCn/rZDnR+slboPn DslQ== 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=DxzFr+PxhxGUlwpP3ZW+DROYq2bJOJKyGjaM0kFUnOU=; b=sMVyQQm/mMh1O2gMn9nU9kFRXpxihtHCQecWikSqzcvYI+hsNyrp7OKSu409TKJGNC IddyOP2ywiFFuyD9aonWDIWELcSW7PlufHyC0FsPNSbf2bE4XI8ykRhAvAGDjuXK8ZeW ONjGlcPXHntXBk4EqEtudoeQk2GFD8Bd4MdrTKkvAa/tlQT1pXYs3ARBZ9LHN5gw6J3N uqemHUpEAXU7zdXJU9YlZd2m+quoGUb33Ax08iVqbjfToJa4sXhEwrIxY1vscV2DH7Bd NSWNhZ46SUxMi6+ARz5XpjMo+1kXHlhBRhbbUgXHzQBihBnoW18gRWXLho+orjFzq3E7 UNSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=aqmm+rB2; 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 v6si7217490ejh.395.2019.06.17.07.48.21 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 Jun 2019 07:48:21 -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=aqmm+rB2; 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]:48156 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hcsvk-0008RD-7r for patch@linaro.org; Mon, 17 Jun 2019 10:48:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46593) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hcsiG-0003S9-1g for qemu-devel@nongnu.org; Mon, 17 Jun 2019 10:34:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hcsiE-00080D-Cw for qemu-devel@nongnu.org; Mon, 17 Jun 2019 10:34:23 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:37309) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hcsiE-0007yK-4G for qemu-devel@nongnu.org; Mon, 17 Jun 2019 10:34:22 -0400 Received: by mail-wm1-x342.google.com with SMTP id f17so6864258wme.2 for ; Mon, 17 Jun 2019 07:34:20 -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=DxzFr+PxhxGUlwpP3ZW+DROYq2bJOJKyGjaM0kFUnOU=; b=aqmm+rB2hNupjoWQ41jh5K3g53Yk+UP4Uifqa6F3MA6r5aWXX98PfSZs337HqQfsJe NKOsFpZ6gN5fj93bfHfbvkE6KDKOnq8owxPhqBQOmjoSD/atUUpwEkPd3ZM0mho1/aYl 7BEDbRlYEuXr2QrTpr07C9QYMLKnsFlHcrsOIYhAFafqSG7oDoX+HJ8zfue0+puiGIgD 8so2i+XEk5NSocR6wnuuW4SsngiBu+Evny+/XvBRJ1Fczb3yALg7fczmN5RwbGBfN73b +DNJR4qc+4Q8XtQg4qwecYR93Be9SLQFoPdVM309TjHn0iofp2WzIvmBAkopQJQUALJ8 xZAQ== 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=DxzFr+PxhxGUlwpP3ZW+DROYq2bJOJKyGjaM0kFUnOU=; b=SPWJlUQqSPvFtQhFBD/prRVkAYBXA2SWPiqcpjtkTAJpEoFShkcG4v7ed7pqunXgFM VHUmyxvNXDqwDVieGrzGWEyNF8hxVrhnXj8bzCbgq2p8qZZyrraFCIGcL81NC6rb3a1C N4bNe16PRZuRKJKcizlbRVKlPkIi5k3it4VHz9FE0Zj0Cay41GR8+I/2I1kXR0E4WGL+ Tao0l+K8fcmhTqo6/IDlqzgqhwEkIdIgV6PfPlC/gB25VGnzagWoBy2MXaB63brQRAsQ c5x91//VqLKOCsLw1gcxMEcxNkaFsv2Pf8exykPUwNwiERbOXy5DB+1kE3qH6fLxZ92f R0QA== X-Gm-Message-State: APjAAAV3/aBNbJnis6qIfOlcJqwwZJ4A1lFLMJJ/u5qAM9FVgGseutAl UFh7FKXJALgoZ3HjK/1be/zI8WQ35SCjYQ== X-Received: by 2002:a1c:f515:: with SMTP id t21mr20392549wmh.39.1560782059272; Mon, 17 Jun 2019 07:34:19 -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.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jun 2019 07:34:18 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 17 Jun 2019 15:33:52 +0100 Message-Id: <20190617143412.5734-5-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::342 Subject: [Qemu-devel] [PULL 04/24] hw/arm/boot: Honour image size field in AArch64 Image format kernels 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" Since Linux v3.17, the kernel's Image header includes a field image_size, which gives the total size of the kernel including unpopulated data sections such as the BSS). If this is present, then return it from load_aarch64_image() as the true size of the kernel rather than just using the size of the Image file itself. This allows the code which calculates where to put the initrd to avoid putting it in the kernel's BSS area. This means that we should be able to reliably load kernel images which are larger than 128MB without accidentally putting the initrd or dtb in locations that clash with the kernel itself. Fixes: https://bugs.launchpad.net/qemu/+bug/1823998 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Tested-by: Mark Rutland Message-id: 20190516144733.32399-5-peter.maydell@linaro.org --- hw/arm/boot.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/hw/arm/boot.c b/hw/arm/boot.c index a0e1110719e..b2f93f6beff 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -911,6 +911,7 @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base, hwaddr *entry, AddressSpace *as) { hwaddr kernel_load_offset = KERNEL64_LOAD_ADDR; + uint64_t kernel_size = 0; uint8_t *buffer; int size; @@ -938,7 +939,10 @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base, * is only valid if the image_size is non-zero. */ memcpy(&hdrvals, buffer + ARM64_TEXT_OFFSET_OFFSET, sizeof(hdrvals)); - if (hdrvals[1] != 0) { + + kernel_size = le64_to_cpu(hdrvals[1]); + + if (kernel_size != 0) { kernel_load_offset = le64_to_cpu(hdrvals[0]); /* @@ -956,12 +960,21 @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base, } } + /* + * Kernels before v3.17 don't populate the image_size field, and + * raw images have no header. For those our best guess at the size + * is the size of the Image file itself. + */ + if (kernel_size == 0) { + kernel_size = size; + } + *entry = mem_base + kernel_load_offset; rom_add_blob_fixed_as(filename, buffer, size, *entry, as); g_free(buffer); - return size; + return kernel_size; } static void arm_setup_direct_kernel_boot(ARMCPU *cpu,