Remove the need to rewind the kernel image file if loading it as a
flat binary by re-using the already read portion of the file passed
in as a buffer.
This allows the MIPS flat binary kernel image to be read from a pipe.

Signed-off-by: Andre Przywara <andre.przyw...@arm.com>
---
 mips/kvm.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/mips/kvm.c b/mips/kvm.c
index ed81a02..d970ee0 100644
--- a/mips/kvm.c
+++ b/mips/kvm.c
@@ -164,24 +164,26 @@ static void kvm__mips_install_cmdline(struct kvm *kvm)
 /* Load at the 1M point. */
 #define KERNEL_LOAD_ADDR 0x1000000
 
-static bool load_flat_binary(struct kvm *kvm, int fd_kernel)
+static bool load_flat_binary(struct kvm *kvm, int fd_kernel, const void *buf,
+                            int buflen)
 {
        void *p;
        void *k_start;
        int nr;
 
-       if (lseek(fd_kernel, 0, SEEK_SET) < 0)
-               die_perror("lseek");
-
        p = k_start = guest_flat_to_host(kvm, KERNEL_LOAD_ADDR);
 
+       memcpy(p, buf, buflen);
+       p += buflen;
+
        while ((nr = read(fd_kernel, p, 65536)) > 0)
                p += nr;
 
        kvm->arch.is64bit = true;
        kvm->arch.entry_point = 0xffffffff81000000ull;
 
-       pr_info("Loaded kernel to 0x%x (%ld bytes)", KERNEL_LOAD_ADDR, (long 
int)(p - k_start));
+       pr_info("Loaded kernel to 0x%x (%ld bytes)", KERNEL_LOAD_ADDR,
+               (long int)(p - k_start));
 
        return true;
 }
@@ -357,7 +359,7 @@ bool kvm__arch_load_kernel_image(struct kvm *kvm, int 
fd_kernel, int fd_initrd,
                return true;
        }
 
-       return load_flat_binary(kvm, fd_kernel);
+       return load_flat_binary(kvm, fd_kernel, &eh, sizeof(eh));
 }
 
 void ioport__map_irq(u8 *irq)
-- 
2.3.5

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to