KVM ARM Archive on lore.kernel.org
 help / color / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: kvmarm@lists.cs.columbia.edu
Cc: kernel-team@android.com, Will Deacon <will@kernel.org>
Subject: [kvmtool][PATCH] arm64: Use default kernel offset when the image file can't be seeked
Date: Thu, 16 Jul 2020 13:08:01 +0100
Message-ID: <20200716120801.2996-1-maz@kernel.org> (raw)

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

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";
+	pr_warning("%s, assuming TEXT_OFFSET to be 0x80000", warn_str);
 	return 0x80000;

kvmarm mailing list

             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16 12:08 Marc Zyngier [this message]
2020-07-16 12:23 ` [PATCH] " Will Deacon

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200716120801.2996-1-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=kernel-team@android.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=will@kernel.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

KVM ARM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kvmarm/0 kvmarm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kvmarm kvmarm/ https://lore.kernel.org/kvmarm \
	public-inbox-index kvmarm

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git