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 154809470011490.08185094725843; Mon, 21 Jan 2019 10:18:20 -0800 (PST) Received: from localhost ([127.0.0.1]:57507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gle9L-0005MC-1d for importer@patchew.org; Mon, 21 Jan 2019 13:18:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gldyF-0004VS-Nw for qemu-devel@nongnu.org; Mon, 21 Jan 2019 13:06:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gldyE-0004Ja-V0 for qemu-devel@nongnu.org; Mon, 21 Jan 2019 13:06:51 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:38429) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gldyE-0004Iz-O4 for qemu-devel@nongnu.org; Mon, 21 Jan 2019 13:06:50 -0500 Received: by mail-wr1-x444.google.com with SMTP id v13so24483603wrw.5 for ; Mon, 21 Jan 2019 10:06:50 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id 133sm56197732wme.9.2019.01.21.10.06.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 10:06:48 -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=c5zPj+nKiIci5idfYgiOSOfNgkRPCvh61Ln2BHSAz7o=; b=sl9BMqKk5w1S8RXdEH49ohK/E79gEuoyScWDpT8UHrm5aKXE8fIUTd1gdpwG8RZJ8a xIxs6IXeQGwTB9R344o+9kkVkA55GRfD9E7w09iDiH8HIvZKSIDvu9yGhgG15Wd75t1D is2ZqpUll/pv0tJzpxaljwvRC7UdJd7PEqMBuY3HAvq9JUMAp21xodnhm1PO9SLzpTjQ LOYFiaN9JgFuKViCBIn8w3qa6vBsyNIxkBqpoN546jrRO0xQ5zr9iHo8B4HLpEoGdgdB Xqr4fYQ+eYghnSkTX0hbiwYITO4hAH2ussuYgtZM7ki1muC1L4v0bPi6CxlSgxkKvA6b qGyg== 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=c5zPj+nKiIci5idfYgiOSOfNgkRPCvh61Ln2BHSAz7o=; b=ACoZQwfDwdciikglwopLsegCp6MXBA8+PFtVSLIv3ixsblT/ET9zrMjeig5HLKkvE9 WKcWArNlu0JEF6h10xeuXBdV9OWrmxODrBQlHn00Fkk/ygi9fy+iTb5nMIoDRbhsxoST L+g0aw7LMWJB2saWYcu8oIpkVwZZngz7ayI7BGp/YxNO1i+0XxTqSDGzrk1GtpGlRaxS o24WrLhUeWc25tWKgZM+ocQse5HIvWtP9ACZ/y+dz3KkLqFhbTl5FMMiwkj5ol5Teuss 39e5bbAT3dt56w52Kf1S00qcdAUHWNdUOjIDtNjUkYTSakm9SVB3t0zBUwC4MGa7O3lB UJaw== X-Gm-Message-State: AJcUukfTu9n6/M8f8t7KDIZIGalM69DAzqcJxMz2JksBVmM54q/2oKKk 97vtdk8aDuKzPh3+pK7aeNNUxkTD X-Google-Smtp-Source: ALg8bN7F3ykTAKNc6fuziD48rvLnp+h99MVC4QtLlyz9A40Zb7bCqDszo8tWkJQG8bs9qRe8O4QceQ== X-Received: by 2002:adf:ae1a:: with SMTP id x26mr28431118wrc.0.1548094009621; Mon, 21 Jan 2019 10:06:49 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 21 Jan 2019 19:05:58 +0100 Message-Id: <1548093980-43088-28-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::444 Subject: [Qemu-devel] [PULL 27/49] pvh: load initrd and expose it through fw_cfg 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: Stefano Garzarella 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: Stefano Garzarella When initrd is specified, load and expose it to the guest firmware through fw_cfg. The firmware will fill the hvm_start_info for the kernel. Signed-off-by: Stefano Garzarella Based-on: <1545422632-24444-5-git-send-email-liam.merwick@oracle.com> Signed-off-by: Liam Merwick Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 6d54995..9ed5063 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1213,25 +1213,45 @@ static void load_linux(PCMachineState *pcms, */ if (load_elfboot(kernel_filename, kernel_size, header, pvh_start_addr, fw_cfg)) { - struct hvm_modlist_entry ramdisk_mod =3D { 0 }; - fclose(f); =20 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline) + 1); fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline); =20 - assert(machine->device_memory !=3D NULL); - ramdisk_mod.paddr =3D machine->device_memory->base; - ramdisk_mod.size =3D - memory_region_size(&machine->device_memory->mr); - - fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, &ramdisk_mod, - sizeof(ramdisk_mod)); fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, sizeof(header)); fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, header, sizeof(header)); =20 + /* load initrd */ + if (initrd_filename) { + gsize initrd_size; + gchar *initrd_data; + GError *gerr =3D NULL; + + if (!g_file_get_contents(initrd_filename, &initrd_data, + &initrd_size, &gerr)) { + fprintf(stderr, "qemu: error reading initrd %s: %s\n", + initrd_filename, gerr->message); + exit(1); + } + + initrd_max =3D pcms->below_4g_mem_size - pcmc->acpi_data_s= ize - 1; + if (initrd_size >=3D initrd_max) { + fprintf(stderr, "qemu: initrd is too large, cannot sup= port." + "(max: %"PRIu32", need %"PRId64")\n", + initrd_max, (uint64_t)initrd_size); + exit(1); + } + + initrd_addr =3D (initrd_max - initrd_size) & ~4095; + + fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr); + fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); + fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, + initrd_size); + } + return; } /* This looks like a multiboot kernel. If it is, let's stop --=20 1.8.3.1