From patchwork Sun Sep 30 08:12:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 976809 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oMSoP7/B"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42NJX75v1Tz9s7T for ; Sun, 30 Sep 2018 18:30:47 +1000 (AEST) Received: from localhost ([::1]:54293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6X7l-0000pS-AZ for incoming@patchwork.ozlabs.org; Sun, 30 Sep 2018 04:30:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6WrJ-0002Is-9j for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g6WrH-0000OA-1u for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:45 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:45396) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g6WrG-0000MM-Nj for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:42 -0400 Received: by mail-wr1-x441.google.com with SMTP id q5-v6so4000076wrw.12 for ; Sun, 30 Sep 2018 01:13:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ANHlB8aU+xWVwM8nd/m8EmfKJLiOcjsLsRHbYgach0s=; b=oMSoP7/B7d2ZeVJfkjABgzD1Uuudvs8yGMH427lWgO/wZ0lRZj1vLuotL9hQLkMLoJ /B5ljGjgXM/tBbOJbFXHIA+AVQvHmt+l12NWtrRcH7QZu8EqB/ZHc5GpGYRAdaF+fh/u k8p9a7jm5alwTngO6fzTe8DfW8mYjuC5p7SyxF5EbnLivBFe58u10XvA+7L3Ehq7TrGv I/L7cGP75ByhoR1RbOoWaFvMuEDmK2qlgroTViF6dmBMHQhzG9gTUp1mMCK5BltEXf80 vr7p0SHjZ1QQN+eqQcyeW0NxXTvebTrnyk2mIfL30rgzlSA8HnbctjyVETdDl83wiyGi 9Y2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ANHlB8aU+xWVwM8nd/m8EmfKJLiOcjsLsRHbYgach0s=; b=EPPACBLaAOmHA+5cEPoY08xO+7Jt2UNMYYkbb1OIXlTiGszZ5KmxVVxPqf0+9fEXAy UkgebxGje09eSqvzIQ6eyFPhYdUr6uZ6NJkThd5UiZ5kmjqGcbxtKQzYDjyHN3KmmXvQ B5bQKqA37baD3+SWJQpn828KToOtu72IlncmFg9qUHKkVlM7G/EG2FW/jAtcYmr2riO+ 5tj6WkJePRMnDxHmEQRTj7eZJzeXgGxGr6TRBsMyrgg0IXqkpYNYQASAtIc4YepCsFO6 dbgjDfH894zSC/PEaeYTgr1h9uXyIns4FzCY6lfPnQ7fMzoEbBv82pm02W9V7JppW3Vv KdXg== X-Gm-Message-State: ABuFfogLyjZinjra6dv8veyOcayE5GVpn+k4T0o3G7IFyszsQTGx87pZ 6iI6TE4umi7JIp+Y1Vp4eSFjAgiv X-Google-Smtp-Source: ACcGV62Kr4vY1snE4Ller1YoR5XqEv6unaQ0rTAWKw3SePbyhyL33Ox2n6kS4BywsDAoHJQCU6a8JA== X-Received: by 2002:adf:94c2:: with SMTP id 60-v6mr3609318wrr.247.1538295221492; Sun, 30 Sep 2018 01:13:41 -0700 (PDT) Received: from 640k.lan (94-36-187-248.adsl-ull.clienti.tiscali.it. [94.36.187.248]) by smtp.gmail.com with ESMTPSA id u76-v6sm11369194wmd.10.2018.09.30.01.13.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 01:13:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sun, 30 Sep 2018 10:12:22 +0200 Message-Id: <1538295197-23704-25-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> References: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PULL 24/79] change get_image_size return type to int64_t X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Zhijian Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Li Zhijian Previously, if the size of initrd >=2G, qemu exits with error: root@haswell-OptiPlex-9020:/home/lizj# /home/lizhijian/lkp/qemu-colo/x86_64-softmmu/qemu-system-x86_64 -kernel ./vmlinuz-4.16.0-rc4 -initrd large.cgz -nographic qemu: error reading initrd large.cgz: No such file or directory root@haswell-OptiPlex-9020:/home/lizj# du -sh large.cgz 2.5G large.cgz this patch changes the caller side that use this function to calculate size of initrd file as well. v2: update error message and int64_t printing format Signed-off-by: Li Zhijian Message-Id: <1536833233-14121-1-git-send-email-lizhijian@cn.fujitsu.com> Signed-off-by: Paolo Bonzini --- hw/alpha/dp264.c | 3 ++- hw/core/loader.c | 5 +++-- hw/hppa/machine.c | 2 +- hw/i386/pc.c | 7 ++++++- hw/mips/mips_fulong2e.c | 4 ++-- hw/mips/mips_malta.c | 4 ++-- hw/mips/mips_mipssim.c | 3 +-- hw/mips/mips_r4k.c | 4 ++-- hw/moxie/moxiesim.c | 2 +- include/hw/loader.h | 2 +- 10 files changed, 21 insertions(+), 15 deletions(-) diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c index 80b987f..dd62f2a 100644 --- a/hw/alpha/dp264.c +++ b/hw/alpha/dp264.c @@ -150,7 +150,8 @@ static void clipper_init(MachineState *machine) } if (initrd_filename) { - long initrd_base, initrd_size; + long initrd_base; + int64_t initrd_size; initrd_size = get_image_size(initrd_filename); if (initrd_size < 0) { diff --git a/hw/core/loader.c b/hw/core/loader.c index 390987a..aa0b3fc 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -61,9 +61,10 @@ static int roms_loaded; /* return the size or -1 if error */ -int get_image_size(const char *filename) +int64_t get_image_size(const char *filename) { - int fd, size; + int fd; + int64_t size; fd = open(filename, O_RDONLY | O_BINARY); if (fd < 0) return -1; diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c index 0fb8fb8..ac6dd7f 100644 --- a/hw/hppa/machine.c +++ b/hw/hppa/machine.c @@ -191,7 +191,7 @@ static void machine_hppa_init(MachineState *machine) if (initrd_filename) { ram_addr_t initrd_base; - long initrd_size; + int64_t initrd_size; initrd_size = get_image_size(initrd_filename); if (initrd_size < 0) { diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 0314845..cd5029c 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -838,7 +838,8 @@ static void load_linux(PCMachineState *pcms, FWCfgState *fw_cfg) { uint16_t protocol; - int setup_size, kernel_size, initrd_size = 0, cmdline_size; + int setup_size, kernel_size, cmdline_size; + int64_t initrd_size = 0; int dtb_size, setup_data_offset; uint32_t initrd_max; uint8_t header[8192], *setup, *kernel, *initrd_data; @@ -974,6 +975,10 @@ static void load_linux(PCMachineState *pcms, fprintf(stderr, "qemu: error reading initrd %s: %s\n", initrd_filename, strerror(errno)); exit(1); + } else if (initrd_size >= initrd_max) { + fprintf(stderr, "qemu: initrd is too large, cannot support." + "(max: %"PRIu32", need %"PRId64")\n", initrd_max, initrd_size); + exit(1); } initrd_addr = (initrd_max-initrd_size) & ~4095; diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c index c1694c8..91655ea 100644 --- a/hw/mips/mips_fulong2e.c +++ b/hw/mips/mips_fulong2e.c @@ -104,9 +104,9 @@ static void GCC_FMT_ATTR(3, 4) prom_set(uint32_t* prom_buf, int index, static int64_t load_kernel (CPUMIPSState *env) { - int64_t kernel_entry, kernel_low, kernel_high; + int64_t kernel_entry, kernel_low, kernel_high, initrd_size; int index = 0; - long kernel_size, initrd_size; + long kernel_size; ram_addr_t initrd_offset; uint32_t *prom_buf; long prom_size; diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c index 40041d5..64ab5d1 100644 --- a/hw/mips/mips_malta.c +++ b/hw/mips/mips_malta.c @@ -995,8 +995,8 @@ static void GCC_FMT_ATTR(3, 4) prom_set(uint32_t* prom_buf, int index, /* Kernel */ static int64_t load_kernel (void) { - int64_t kernel_entry, kernel_high; - long kernel_size, initrd_size; + int64_t kernel_entry, kernel_high, initrd_size; + long kernel_size; ram_addr_t initrd_offset; int big_endian; uint32_t *prom_buf; diff --git a/hw/mips/mips_mipssim.c b/hw/mips/mips_mipssim.c index 241faa1..f665752 100644 --- a/hw/mips/mips_mipssim.c +++ b/hw/mips/mips_mipssim.c @@ -58,9 +58,8 @@ typedef struct ResetData { static int64_t load_kernel(void) { - int64_t entry, kernel_high; + int64_t entry, kernel_high, initrd_size; long kernel_size; - long initrd_size; ram_addr_t initrd_offset; int big_endian; diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c index d5725d0..ef6b810 100644 --- a/hw/mips/mips_r4k.c +++ b/hw/mips/mips_r4k.c @@ -81,8 +81,8 @@ typedef struct ResetData { static int64_t load_kernel(void) { const size_t params_size = 264; - int64_t entry, kernel_high; - long kernel_size, initrd_size; + int64_t entry, kernel_high, initrd_size; + long kernel_size; ram_addr_t initrd_offset; uint32_t *params_buf; int big_endian; diff --git a/hw/moxie/moxiesim.c b/hw/moxie/moxiesim.c index d41247d..4b0ce09 100644 --- a/hw/moxie/moxiesim.c +++ b/hw/moxie/moxiesim.c @@ -54,8 +54,8 @@ typedef struct { static void load_kernel(MoxieCPU *cpu, LoaderParams *loader_params) { uint64_t entry, kernel_low, kernel_high; + int64_t initrd_size; long kernel_size; - long initrd_size; ram_addr_t initrd_offset; kernel_size = load_elf(loader_params->kernel_filename, NULL, NULL, diff --git a/include/hw/loader.h b/include/hw/loader.h index 3c11297..67a0af8 100644 --- a/include/hw/loader.h +++ b/include/hw/loader.h @@ -10,7 +10,7 @@ * Returns the size of the image file on success, -1 otherwise. * On error, errno is also set as appropriate. */ -int get_image_size(const char *filename); +int64_t get_image_size(const char *filename); int load_image(const char *filename, uint8_t *addr); /* deprecated */ ssize_t load_image_size(const char *filename, void *addr, size_t size);