From patchwork Mon Jan 23 07:32:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ben@skyportsystems.com X-Patchwork-Id: 9531843 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A7B3760434 for ; Mon, 23 Jan 2017 07:37:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9906427D76 for ; Mon, 23 Jan 2017 07:37:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DE8727EED; Mon, 23 Jan 2017 07:37:59 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 023D427D76 for ; Mon, 23 Jan 2017 07:37:58 +0000 (UTC) Received: from localhost ([::1]:39549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVZCP-00005J-Op for patchwork-qemu-devel@patchwork.kernel.org; Mon, 23 Jan 2017 02:37:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVZ86-00053y-Q1 for qemu-devel@nongnu.org; Mon, 23 Jan 2017 02:33:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cVZ81-0006gU-Tz for qemu-devel@nongnu.org; Mon, 23 Jan 2017 02:33:30 -0500 Received: from mail-pf0-x22e.google.com ([2607:f8b0:400e:c00::22e]:33774) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cVZ81-0006gB-Lm for qemu-devel@nongnu.org; Mon, 23 Jan 2017 02:33:25 -0500 Received: by mail-pf0-x22e.google.com with SMTP id y143so39244673pfb.0 for ; Sun, 22 Jan 2017 23:33:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=e3SqrgIlpvIYt+Ev698oSAsYFSvqsC7tgp8/DBzIxew=; b=bmHMrPoweuo+KUgvIuySoQiesVaufgXq34DTSPiG4vq3IM4FUtg855b9Shxs1uM8sg icGb8HVfqAd+oDIbHw8WD4ldWubO0cN6Tcq+e5RFKkFlpUUs3d5fAymdjqvWD7k7A22Z +rBFunOGY5Sle3jVuz4OFgBMNH4MeK8ad5qe4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=e3SqrgIlpvIYt+Ev698oSAsYFSvqsC7tgp8/DBzIxew=; b=UzaJU8rQsJKnqYhikJBb2WgGVsV5Ms9igGZqtIUiyRkzELZ1bW9A7Dv5rtrAKYAtD4 rQA+6BE+I7Akwi8e4+KI8oVS62ax/UZVqtu+c447w5vsz0DGtkkyEa4/mY1jgKjhP8AK r8t++xEwslYkcvkJditckBqxYelO+m/JdFSJ1gPlY6K08eC1W86rADpGUFzJ8Q5Ov+TD XDvZV4VA0TdhWBJjEjvK2GnK73KjIQuBDuhOEbLByOEY5sSJhl2v4AfMVIPObGvV2GGF Vwre3UJ5Pde9OarZNOmTI+CIU4PJ2c8WLbVbvzIh74cLekWX57ORBzgPRaFcgVtrxlWR VmkQ== X-Gm-Message-State: AIkVDXK4bden3oFLJ0LAMdPytcS9CufrYMBM8f+rAZo+t6lJNh6795ZjZ17ZuCfDjSQurbTC X-Received: by 10.84.216.24 with SMTP id m24mr41419232pli.22.1485156804579; Sun, 22 Jan 2017 23:33:24 -0800 (PST) Received: from Arrow.corp.skyportsystems.com (162-199-88-38.lightspeed.sntcca.sbcglobal.net. [162.199.88.38]) by smtp.gmail.com with ESMTPSA id d78sm34155810pfb.43.2017.01.22.23.33.23 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 22 Jan 2017 23:33:24 -0800 (PST) From: ben@skyportsystems.com To: qemu-devel@nongnu.org Date: Sun, 22 Jan 2017 23:32:48 -0800 Message-Id: <59d78a9d2a1a550a883449b86a7e90ab0bcd613a.1485155611.git.ben@skyportsystems.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::22e Subject: [Qemu-devel] [PATCH v3 2/6] linker-loader: add new 'allocate and return address' cmd 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: Ben Warren Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Ben Warren This adds a new linker-loader command to instruct the guest to allocate memory for a fw_cfg file and write the address back into another writeable fw_cfg file. Knowing this address, QEMU can then write into guest memory at runtime. Signed-off-by: Ben Warren --- hw/acpi/bios-linker-loader.c | 71 ++++++++++++++++++++++++++++++++++-- include/hw/acpi/bios-linker-loader.h | 7 ++++ 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/hw/acpi/bios-linker-loader.c b/hw/acpi/bios-linker-loader.c index d963ebe..1d991ba 100644 --- a/hw/acpi/bios-linker-loader.c +++ b/hw/acpi/bios-linker-loader.c @@ -78,6 +78,22 @@ struct BiosLinkerLoaderEntry { uint32_t length; } cksum; + /* + * COMMAND_ALLOCATE_RETURN_ADDR - allocate a table from @alloc_ret_file + * subject to @alloc_ret_align alignment (must be power of 2) + * and @alloc_ret_zone (can be HIGH or FSEG) requirements. + * Additionally, return the address of the allocation in + * @addr_file. + * + * This may be used instead of COMMAND_ALLOCATE + */ + struct { + char alloc_ret_file[BIOS_LINKER_LOADER_FILESZ]; + uint32_t alloc_ret_align; + uint8_t alloc_ret_zone; + char alloc_ret_addr_file[BIOS_LINKER_LOADER_FILESZ]; + }; + /* padding */ char pad[124]; }; @@ -85,9 +101,10 @@ struct BiosLinkerLoaderEntry { typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry; enum { - BIOS_LINKER_LOADER_COMMAND_ALLOCATE = 0x1, - BIOS_LINKER_LOADER_COMMAND_ADD_POINTER = 0x2, - BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3, + BIOS_LINKER_LOADER_COMMAND_ALLOCATE = 0x1, + BIOS_LINKER_LOADER_COMMAND_ADD_POINTER = 0x2, + BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3, + BIOS_LINKER_LOADER_COMMAND_ALLOCATE_RET_ADDR = 0x4, }; enum { @@ -278,3 +295,51 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker, g_array_append_vals(linker->cmd_blob, &entry, sizeof entry); } + +/* + * bios_linker_loader_alloc_ret_addr: ask guest to load file into guest memory + * and patch the address in another file + * + * @linker: linker object instance + * @data_file: name of the file blob to be loaded + * @file_blob: pointer to blob corresponding to @file_name + * @alloc_align: required minimal alignment in bytes. Must be a power of 2. + * @alloc_fseg: request allocation in FSEG zone (useful for the RSDP ACPI table) + * @addr_file: destination file that will contain the address. + * This must already exist + * + * Note: this command must precede any other linker command that uses + * the data file. + */ +void bios_linker_loader_alloc_ret_addr(BIOSLinker *linker, + const char *data_file, + GArray *file_blob, + uint32_t alloc_align, + bool alloc_fseg, + const char *addr_file) +{ + BiosLinkerLoaderEntry entry; + BiosLinkerFileEntry d_file = { g_strdup(data_file), file_blob}; + + /* Address file is expected to already be loaded */ + const BiosLinkerFileEntry *a_file = + bios_linker_find_file(linker, addr_file); + + assert(!(alloc_align & (alloc_align - 1))); + assert(a_file); + + g_array_append_val(linker->file_list, d_file); + + memset(&entry, 0, sizeof entry); + strncpy(entry.alloc_ret_file, data_file, + sizeof entry.alloc_ret_file - 1); + strncpy(entry.alloc_ret_addr_file, addr_file, + sizeof entry.alloc_ret_addr_file - 1); + entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE_RET_ADDR); + entry.alloc.align = cpu_to_le32(alloc_align); + entry.alloc.zone = alloc_fseg ? BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG : + BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH; + + /* Alloc entries must come first, so prepend them */ + g_array_append_vals(linker->cmd_blob, &entry, sizeof entry); +} diff --git a/include/hw/acpi/bios-linker-loader.h b/include/hw/acpi/bios-linker-loader.h index fa1e5d1..69953e6 100644 --- a/include/hw/acpi/bios-linker-loader.h +++ b/include/hw/acpi/bios-linker-loader.h @@ -26,5 +26,12 @@ void bios_linker_loader_add_pointer(BIOSLinker *linker, const char *src_file, uint32_t src_offset); +void bios_linker_loader_alloc_ret_addr(BIOSLinker *linker, + const char *data_file, + GArray *file_blob, + uint32_t alloc_align, + bool alloc_fseg, + const char *addr_file); + void bios_linker_loader_cleanup(BIOSLinker *linker); #endif