[03/14] x86: allow pipes for bzImage kernel images

Message ID 1438253551-2378-4-git-send-email-andre.przywara@arm.com
State Not Applicable, archived
Headers show

Commit Message

Andre Przywara July 30, 2015, 10:52 a.m.
Streamline the x86 kernel loading implementation by removing unneeded
seeks and thus allow an x86 bzImage to be loaded from a pipe.
"Flat binaries" are taken care of in a separate patch.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 x86/kvm.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

Patch

diff --git a/x86/kvm.c b/x86/kvm.c
index a0204b8..8fe5585 100644
--- a/x86/kvm.c
+++ b/x86/kvm.c
@@ -245,9 +245,6 @@  static bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd,
 	 * memory layout.
 	 */
 
-	if (lseek(fd_kernel, 0, SEEK_SET) < 0)
-		die_perror("lseek");
-
 	if (read(fd_kernel, &boot, sizeof(boot)) != sizeof(boot))
 		return false;
 
@@ -257,9 +254,6 @@  static bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd,
 	if (boot.hdr.version < BOOT_PROTOCOL_REQUIRED)
 		die("Too old kernel");
 
-	if (lseek(fd_kernel, 0, SEEK_SET) < 0)
-		die_perror("lseek");
-
 	if (!boot.hdr.setup_sects)
 		boot.hdr.setup_sects = BZ_DEFAULT_SETUP_SECTS;
 	setup_sects = boot.hdr.setup_sects + 1;
@@ -267,7 +261,10 @@  static bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd,
 	setup_size = setup_sects << 9;
 	p = guest_real_to_host(kvm, BOOT_LOADER_SELECTOR, BOOT_LOADER_IP);
 
-	/* copy setup.bin to mem*/
+	/* copy setup.bin to mem */
+	memcpy(p, &boot, sizeof(boot));
+	p += sizeof(boot);
+	setup_size -= sizeof(boot);
 	if (read(fd_kernel, p, setup_size) != setup_size)
 		die_perror("read");