From nobody Fri Nov 7 14:34:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548096479853863.2917048634712; Mon, 21 Jan 2019 10:47:59 -0800 (PST) Received: from localhost ([127.0.0.1]:57981 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1glec2-0005zo-SU for importer@patchew.org; Mon, 21 Jan 2019 13:47:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gldz3-0005DA-GH for qemu-devel@nongnu.org; Mon, 21 Jan 2019 13:07:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gldz2-000526-Es for qemu-devel@nongnu.org; Mon, 21 Jan 2019 13:07:41 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:46996) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gldz2-0004h9-6Q for qemu-devel@nongnu.org; Mon, 21 Jan 2019 13:07:40 -0500 Received: by mail-wr1-x442.google.com with SMTP id l9so24410492wrt.13 for ; Mon, 21 Jan 2019 10:07:11 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id 133sm56197732wme.9.2019.01.21.10.07.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 10:07:09 -0800 (PST) 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=UyOO/3qIIIuGKtRlQ6sy6c1ESLrovs2uE9nyiP4gaxg=; b=ao5kPbbYb4hvbwGZIOP4qS03qtS5EW7Jl7yO/bmW9XyhF2Lzxx5E9MYxZqXzW8ePfH 6NUe2pWzqy3FHRM0Bv2MQ9ylKdQDnK2Gr1P/IxtZ3rVeWhxlQe6W7dGw/OMmSsUDrGpR V5sbIdg3yvNJcUNpHOOe8ZI3mpkTvy3JFCaSrnvMKaUmyFRZ0ToZsa5WCvxuSCnLpYXG mKSW6jmWVL0hT0xfwk4wvsKXs98x46myKtThJ+W2qYbrFhsdEPuS0qjM2SBph9e+zJuQ 0fGhzmzi00fInKGti12bLAr1IbeO6mnqNiCFt4QZR2rY8EFAyWIkUJv/4yXNTRFmaOjX i3rA== 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=UyOO/3qIIIuGKtRlQ6sy6c1ESLrovs2uE9nyiP4gaxg=; b=jlHt+maIhyK/pcUf4CZRO8Ox/pxle+orNHyXHONKWx2YirnxT6hctWq4z/BXi0Dqeo X2RBNazUGKRJPhzDAQ9ZikFijmdXXfOH84MCd37DkKbN2kkwVigNqPTK1Lw/UytmdON7 fcgdrNryO8ohpMhZYy7xOrjMAS+oJoO4J3laB0GzML+WVJ9imIk3ijgBSBdYvp7Q9gsP hKwfqOL2b30o3PoEWzhXRORR37j2F9bk18Zq2ZRILnm/pA+BXGXWBMcZdAoMlpMzHB0J jrnZZoRYTD/H7FR32XLUOOrXe3zX4KHWehki3IS6DGIIoMeunkeINqUAlTyw/7DWD9zy uYxA== X-Gm-Message-State: AJcUukfC08VJ7SF2niPhViYb9MBQf4XEK0/blsBoPevmwgTjvY/teX/n Ceq2B4Z67Iwk70w1Fvkrei0PzmOe X-Google-Smtp-Source: ALg8bN4lTH2O8WgZzTvfcR5LIUFoL4wCcyXiEdsHKFypAoojOdn0LysDIWZCLFKvr4tQMNkOIwBWxg== X-Received: by 2002:adf:e407:: with SMTP id g7mr18601677wrm.277.1548094030519; Mon, 21 Jan 2019 10:07:10 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 21 Jan 2019 19:06:19 +0100 Message-Id: <1548093980-43088-49-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1548093980-43088-1-git-send-email-pbonzini@redhat.com> References: <1548093980-43088-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::442 Subject: [Qemu-devel] [PULL 48/49] i386: allow to load initrd below 4 GB for recent linux 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: "Michael S. Tsirkin" , Eduardo Habkost , Li Zhijian , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Li Zhijian Since linux commit: cf8fa920cb42 ("i386: handle an initrd in highmem (versi= on 2)") linux has supported initrd up to 4 GB, but the header field ramdisk_max is still set to 2 GB to avoid "possible bootloader bugs". When use '-kernel vmlinux -initrd initrd.cgz' to launch a VM, the firmware(it could be linuxboot_dma.bin) helps to read initrd contents into guest memory(below ramdisk_max) and jump to kernel. that's similar with what bootloader does, like grub. In addition, initrd_max is uint32_t simply because QEMU doesn't support the 64-bit boot protocol (specifically the ext_ramdisk_image field). Therefore here just limit initrd_max to UINT32_MAX simply as well to allow initrd to be loaded below 4 GB. NOTE: it's possible that linux protocol within [0x208, 0x20c] supports up to 4 GB initrd as well. CC: Paolo Bonzini CC: Richard Henderson CC: Eduardo Habkost CC: "Michael S. Tsirkin" CC: Marcel Apfelbaum Signed-off-by: Li Zhijian Reviewed-by: Eduardo Habkost Reviewed-by: Stefano Garzarella Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 90e684d..3d66f81 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1289,7 +1289,26 @@ static void load_linux(PCMachineState *pcms, #endif =20 /* highest address for loading the initrd */ - if (protocol >=3D 0x203) { + if (protocol >=3D 0x20c && + lduw_p(header+0x236) & XLF_CAN_BE_LOADED_ABOVE_4G) { + /* + * Linux has supported initrd up to 4 GB for a very long time (200= 7, + * long before XLF_CAN_BE_LOADED_ABOVE_4G which was added in 2013), + * though it only sets initrd_max to 2 GB to "work around bootload= er + * bugs". Luckily, QEMU firmware(which does something like bootloa= der) + * has supported this. + * + * It's believed that if XLF_CAN_BE_LOADED_ABOVE_4G is set, initrd= can + * be loaded into any address. + * + * In addition, initrd_max is uint32_t simply because QEMU doesn't + * support the 64-bit boot protocol (specifically the ext_ramdisk_= image + * field). + * + * Therefore here just limit initrd_max to UINT32_MAX simply as we= ll. + */ + initrd_max =3D UINT32_MAX; + } else if (protocol >=3D 0x203) { initrd_max =3D ldl_p(header+0x22c); } else { initrd_max =3D 0x37ffffff; --=20 1.8.3.1