From: ben@skyportsystems.com
To: qemu-devel@nongnu.org
Cc: Ben Warren <ben@skyportsystems.com>
Subject: [Qemu-devel] [PATCH v4 2/9] linker-loader: Add new 'allocate and return address' cmd
Date: Tue, 24 Jan 2017 17:43:21 -0800 [thread overview]
Message-ID: <01f010147f8faaf7bd7c4ea94a364a584f323b0a.1485308342.git.ben@skyportsystems.com> (raw)
In-Reply-To: <cover.1485308342.git.ben@skyportsystems.com>
In-Reply-To: <cover.1485308342.git.ben@skyportsystems.com>
From: Ben Warren <ben@skyportsystems.com>
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 <ben@skyportsystems.com>
---
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
--
2.7.4
next prev parent reply other threads:[~2017-01-25 1:44 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-25 1:43 [Qemu-devel] [PATCH v4 0/9] Add support for VM Generation ID ben
2017-01-25 1:43 ` [Qemu-devel] [PATCH v4 1/9] ACPI: Add a function for building named qword entries ben
2017-01-25 3:55 ` Laszlo Ersek
2017-01-25 17:36 ` Ben Warren
2017-01-25 18:35 ` Michael S. Tsirkin
2017-01-26 0:48 ` Laszlo Ersek
2017-01-26 5:35 ` Ben Warren
2017-01-26 8:21 ` Laszlo Ersek
2017-01-26 15:20 ` Michael S. Tsirkin
2017-01-26 17:43 ` Laszlo Ersek
2017-01-26 18:15 ` Michael S. Tsirkin
2017-01-26 18:25 ` Laszlo Ersek
2017-01-26 18:59 ` Michael S. Tsirkin
2017-01-27 3:20 ` Laszlo Ersek
2017-01-27 14:18 ` Kevin O'Connor
2017-01-27 14:46 ` Laszlo Ersek
2017-01-27 15:43 ` Kevin O'Connor
2017-01-27 16:12 ` Laszlo Ersek
2017-01-27 18:19 ` Ben Warren
2017-01-30 12:07 ` Laszlo Ersek
2017-01-30 20:28 ` Michael S. Tsirkin
2017-01-31 9:51 ` Igor Mammedov
2017-01-31 21:39 ` Michael S. Tsirkin
2017-02-01 11:46 ` Igor Mammedov
2017-02-01 17:55 ` Michael S. Tsirkin
2017-01-25 1:43 ` ben [this message]
2017-01-25 4:30 ` [Qemu-devel] [PATCH v4 2/9] linker-loader: Add new 'allocate and return address' cmd Laszlo Ersek
2017-01-25 13:03 ` Laszlo Ersek
2017-01-25 1:43 ` [Qemu-devel] [PATCH v4 3/9] docs: VM Generation ID device description ben
2017-01-25 5:29 ` Laszlo Ersek
2017-01-25 1:43 ` [Qemu-devel] [PATCH v4 4/9] ACPI: Add Virtual Machine Generation ID support ben
2017-01-25 10:04 ` Laszlo Ersek
2017-01-25 14:00 ` Laszlo Ersek
2017-01-25 1:43 ` [Qemu-devel] [PATCH v4 5/9] qmp/hmp: add query-vm-generation-id and 'info vm-generation-id' commands ben
2017-01-25 1:43 ` [Qemu-devel] [PATCH v4 6/9] qmp/hmp: add set-vm-generation-id commands ben
2017-01-25 1:43 ` [Qemu-devel] [PATCH v4 7/9] PC: Support dynamic sysbus on pc_i440fx ben
2017-01-25 10:09 ` Laszlo Ersek
2017-01-25 1:43 ` [Qemu-devel] [PATCH v4 8/9] tests: Move reusable ACPI macros into a new header file ben
2017-01-25 1:43 ` [Qemu-devel] [PATCH v4 9/9] tests: Add unit tests for the VM Generation ID feature ben
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=01f010147f8faaf7bd7c4ea94a364a584f323b0a.1485308342.git.ben@skyportsystems.com \
--to=ben@skyportsystems.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).