kvmarm.lists.cs.columbia.edu archive mirror
 help / color / mirror / Atom feed
* [kvmtool][PATCH] arm64: Use default kernel offset when the image file can't be seeked
@ 2020-07-16 12:08 Marc Zyngier
  2020-07-16 12:23 ` [PATCH] " Will Deacon
  0 siblings, 1 reply; 2+ messages in thread
From: Marc Zyngier @ 2020-07-16 12:08 UTC (permalink / raw)
  To: kvmarm; +Cc: kernel-team, Will Deacon

While introducing new code to extract the kernel offset from the
image, commit fd0a05b ("arm64: Obtain text offset from kernel image")
introduced a regression where something such as:

  ./lkvm run -c 8 -p earlycon <(zcat /boot/vmlinuz-5.8.0-rc5-00172-ga161216e31ba)

now fails to load the kernel, as the file descriptor cannot be
seeked.

Let's assume the good old 0x80000 offset when the seek syscall fails,
with a warning for a good measure.

Fixes: fd0a05b ("arm64: Obtain text offset from kernel image")
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arm/aarch64/kvm.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c
index a46d438..49e1dd3 100644
--- a/arm/aarch64/kvm.c
+++ b/arm/aarch64/kvm.c
@@ -15,6 +15,7 @@ unsigned long long kvm__arch_get_kern_offset(struct kvm *kvm, int fd)
 	struct arm64_image_header header;
 	off_t cur_offset;
 	ssize_t size;
+	const char *warn_str;
 
 	/* the 32bit kernel offset is a well known value */
 	if (kvm->cfg.arch.aarch32_guest)
@@ -22,8 +23,10 @@ unsigned long long kvm__arch_get_kern_offset(struct kvm *kvm, int fd)
 
 	cur_offset = lseek(fd, 0, SEEK_CUR);
 	if (cur_offset == (off_t)-1 ||
-	    lseek(fd, 0, SEEK_SET) == (off_t)-1)
-		die("Failed to seek in image file");
+	    lseek(fd, 0, SEEK_SET) == (off_t)-1) {
+		warn_str = "Failed to seek in kernel image file";
+		goto fail;
+	}
 
 	size = xread(fd, &header, sizeof(header));
 	if (size < 0 || (size_t)size < sizeof(header))
@@ -37,7 +40,9 @@ unsigned long long kvm__arch_get_kern_offset(struct kvm *kvm, int fd)
 	if (le64_to_cpu(header.image_size))
 		return le64_to_cpu(header.text_offset);
 
-	pr_warning("Image size is 0, assuming TEXT_OFFSET to be 0x80000");
+	warn_str = "Image size is 0";
+fail:
+	pr_warning("%s, assuming TEXT_OFFSET to be 0x80000", warn_str);
 	return 0x80000;
 }
 
-- 
2.27.0

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-16 12:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16 12:08 [kvmtool][PATCH] arm64: Use default kernel offset when the image file can't be seeked Marc Zyngier
2020-07-16 12:23 ` [PATCH] " Will Deacon

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).