From nobody Tue Feb 10 02:43:49 2026 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549307526142895.8703198585073; Mon, 4 Feb 2019 11:12:06 -0800 (PST) Received: from localhost ([127.0.0.1]:47782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqjey-0000XO-3e for importer@patchew.org; Mon, 04 Feb 2019 14:12:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59703) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqj7C-0005N3-9Z for qemu-devel@nongnu.org; Mon, 04 Feb 2019 13:37:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqj78-0003kS-UN for qemu-devel@nongnu.org; Mon, 04 Feb 2019 13:37:04 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:51631) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gqj78-0003ie-MK for qemu-devel@nongnu.org; Mon, 04 Feb 2019 13:37:02 -0500 Received: by mail-wm1-x344.google.com with SMTP id b11so979355wmj.1 for ; Mon, 04 Feb 2019 10:37:00 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id s132sm8836236wmf.28.2019.02.04.10.36.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Feb 2019 10:36:58 -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=2ZmDsNTvSqq9wAUp4eF9ynOF4kD3WulPOABTzSsTzHQ=; b=HdMuSPohFZDSJ+yv6zKtn+QVG6mcY1mAAi7q7rnpqTsMtrL4E/jLEsx+NqcFm+xZpy q2WsU3gc6g2JWmpFUiae4jb8zC41t39eL6b+yPesDxEkg83c5/846YlZF8g9wOxUZoJE YJH+JT7zJl1jiQS22xm4pd603L5OsbVMr6SZfTDUZePKJGpzE3CdwXkBJNC9pSZhXflr PfRKijmv1KVy3GwrVYLQvnEZZ3uI8l3rRiIdVQ/yoFwWgjDvQk8y+fe/dThbs9XpJpu9 HwSK4Ul+mwoH1qBxJFQulfP+foeiGeOoJ37+gdryRCgD5ZdBwkk2Ru5+zToLKyVG3zyy AbrA== 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=2ZmDsNTvSqq9wAUp4eF9ynOF4kD3WulPOABTzSsTzHQ=; b=VBor+EuHxScgygoPdLpRC+DXjw8qRNTt9ZUdz7/MU79Kf+a2OCN4N06Qp6pQsBDL2G byu7fEwq5nvmj+fK6cJ7WpDzei4yyhIn8ttc8TLfIun37SJm4PNw2s+olPJpQL3fCIMQ 66jmferjRr41TqizKrhXSIHWvbXz6atlX7dP7vy9EitIbKdgZ9U6vtNVo6q/RWam+Ugv hkRfBvJV1/wx/WOBrid5M+QLPL2m5E2h6E2QT2Ptv8jIkQvrfHk71MRDdMwOqUSylSmv 28LmJRjZfPqvvPW8Avyo7gYsE8Kj25XXZISLr1asbYiMyjSop2/e/KxJBRdjRs+GiUWw /gdQ== X-Gm-Message-State: AHQUAubGaeUkdi8L+3mcdrXq7qrcg2fsRQ+nVKiJMSK+loNvACji1JCl ZsCiXz/R6x46V8zt52ll4+i5N9Gc X-Google-Smtp-Source: AHgI3IYfoJT3uNM1HLBdS9g2mP9wlnL/OKdVMl6lXuD8wJKvIS1PYlhhWOF5cVUd98QQHdg3wm7gSg== X-Received: by 2002:a1c:6e06:: with SMTP id j6mr582935wmc.3.1549305419637; Mon, 04 Feb 2019 10:36:59 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2019 19:35:41 +0100 Message-Id: <1549305379-51117-40-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1549305379-51117-1-git-send-email-pbonzini@redhat.com> References: <1549305379-51117-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::344 Subject: [Qemu-devel] [PULL 39/77] 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 9664822..7d8f351 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1299,7 +1299,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