From patchwork Wed Dec 5 22:37:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10715007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2B7D318B8 for ; Wed, 5 Dec 2018 22:39:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 193222DD04 for ; Wed, 5 Dec 2018 22:39:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0BCBF2E370; Wed, 5 Dec 2018 22:39:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 802EE2DD04 for ; Wed, 5 Dec 2018 22:39:38 +0000 (UTC) Received: from localhost ([::1]:37313 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUfpR-0008Uz-Kl for patchwork-qemu-devel@patchwork.kernel.org; Wed, 05 Dec 2018 17:39:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUfny-0005ek-8c for qemu-devel@nongnu.org; Wed, 05 Dec 2018 17:38:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUfnt-00021o-GN for qemu-devel@nongnu.org; Wed, 05 Dec 2018 17:38:06 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:53382) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gUfnt-0001z5-7V for qemu-devel@nongnu.org; Wed, 05 Dec 2018 17:38:01 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wB5MYj2X124820; Wed, 5 Dec 2018 22:37:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=3I7cO5yTJq4Q8lR7O3K2ZfQ5K3C6n1RVrlRqSm2X0E8=; b=JQwVdmpumE70zoOyAeb/Zj6s3gslr8IWD+7nMBEoYc/pNhNIr514LVGZL0YVfB/abZxc CGiNUxTwtLdV7m7InZCYuuSgrDIBL7yGJ4idEJJ8m5Cp4ryXpmDgQQmw90bC2yxDIWJY cbaeExHu7hTG1yfmkJzcFeyiU+lEtpbz4mwx1b5p+Ue/bM9ZgevPRUY093SP83lxZyvw NYYPcR07vLy8w5zkJqYBgHaDZxd/mmovIFUPBJXVDSXgBp32G/BwBus0bdqllm6ruu+H ZRfC032dG8UXc1YrYZxaDBV4S2E/UXFBe4U/WA5zy/drAsXZ1+c46ALoe14MSC9qao+u kQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2p3hqu593g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Dec 2018 22:37:59 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wB5MbvqT017354 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 5 Dec 2018 22:37:58 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wB5MbvIV011088; Wed, 5 Dec 2018 22:37:57 GMT Received: from ol7.uk.oracle.com (/10.175.200.102) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 05 Dec 2018 22:37:56 +0000 From: Liam Merwick To: qemu-devel@nongnu.org Date: Wed, 5 Dec 2018 22:37:26 +0000 Message-Id: <1544049446-6359-4-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1544049446-6359-1-git-send-email-liam.merwick@oracle.com> References: <1544049446-6359-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9098 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=807 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812050197 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [RFC 3/3] pvh: Boot uncompressed kernel using direct boot ABI 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: ehabkost@redhat.com, mst@redhat.com, maran.wilson@oracle.com, stefanha@redhat.com, xen-devel@lists.xenproject.org, pbonzini@redhat.com, rth@twiddle.net, sgarzare@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP These changes (along with corresponding qboot and Linux kernel changes) enable a guest to be booted using the x86/HVM direct boot ABI. This commit adds a load_elfboot() routine to pass the size and location of the kernel entry point to qboot (which will fill in the start_info struct information needed to to boot the guest). Having loaded the ELF binary, load_linux() will run qboot which continues the boot. The address for the kernel entry point has already been read from an ELF Note in the uncompressed kernel binary earlier in pc_memory_init(). Signed-off-by: George Kennedy Signed-off-by: Liam Merwick --- hw/i386/pc.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 056aa46d99b9..d3012cbd8597 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -54,6 +54,7 @@ #include "sysemu/qtest.h" #include "kvm_i386.h" #include "hw/xen/xen.h" +#include "hw/xen/start_info.h" #include "ui/qemu-spice.h" #include "exec/memory.h" #include "exec/address-spaces.h" @@ -1098,6 +1099,50 @@ done: return pvh_start_addr != 0; } +static bool load_elfboot(const char *kernel_filename, + int kernel_file_size, + uint8_t *header, + size_t pvh_xen_start_addr, + FWCfgState *fw_cfg) +{ + uint32_t flags = 0; + uint32_t mh_load_addr = 0; + uint32_t elf_kernel_size = 0; + uint64_t elf_entry; + uint64_t elf_low, elf_high; + int kernel_size; + + if (ldl_p(header) != 0x464c457f) { + return false; /* no elfboot */ + } + + bool elf_is64 = header[EI_CLASS] == ELFCLASS64; + flags = elf_is64 ? + ((Elf64_Ehdr *)header)->e_flags : ((Elf32_Ehdr *)header)->e_flags; + + if (flags & 0x00010004) { /* LOAD_ELF_HEADER_HAS_ADDR */ + error_report("elfboot unsupported flags = %x", flags); + exit(1); + } + + kernel_size = load_elf(kernel_filename, NULL, NULL, &elf_entry, + &elf_low, &elf_high, 0, I386_ELF_MACHINE, + 0, 0); + + if (kernel_size < 0) { + error_report("Error while loading elf kernel"); + exit(1); + } + mh_load_addr = elf_low; + elf_kernel_size = elf_high - elf_low; + + fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ENTRY, pvh_xen_start_addr); + fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, mh_load_addr); + fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, elf_kernel_size); + + return true; +} + static void load_linux(PCMachineState *pcms, FWCfgState *fw_cfg) { @@ -1138,6 +1183,33 @@ static void load_linux(PCMachineState *pcms, if (ldl_p(header+0x202) == 0x53726448) { protocol = lduw_p(header+0x206); } else { + /* If the kernel address for using the x86/HVM direct boot ABI has + * been saved then proceed with booting the uncompressed kernel */ + if (pvh_start_addr) { + if (load_elfboot(kernel_filename, kernel_size, + header, pvh_start_addr, fw_cfg)) { + struct hvm_modlist_entry ramdisk_mod = { 0 }; + + fclose(f); + + 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); + + assert(machine->device_memory != NULL); + ramdisk_mod.paddr = machine->device_memory->base; + ramdisk_mod.size = + 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)); + + return; + } + } /* This looks like a multiboot kernel. If it is, let's stop treating it like a Linux kernel. */ if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,