All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Elisei <alexandru.elisei@arm.com>
To: will@kernel.org, julien.thierry.kdev@gmail.com, kvm@vger.kernel.org
Cc: christoffer.dall@arm.com, vivek.gautam@arm.com
Subject: [PATCH kvmtool 10/10] arm64: Be more permissive when parsing the kernel header
Date: Thu, 23 Sep 2021 15:45:05 +0100	[thread overview]
Message-ID: <20210923144505.60776-11-alexandru.elisei@arm.com> (raw)
In-Reply-To: <20210923144505.60776-1-alexandru.elisei@arm.com>

kvmtool complains loudly when it parses the kernel header and doesn't find
what it expects, but unless it outright fails to read the kernel image, it
will copy the image in the guest memory at the default offset of 0x80000.

There's no technical reason to stop the user from loading payloads other
than a Linux kernel with the --kernel option. These payloads can behave
just like a kernel and can use an initrd (which is not possible with
--firmware), but don't have the kernel header (like kvm-unit-tests), and
the warnings kvmtool emites can be confusing for this type of payloads.

Change the warnings to debug statements, which can be enabled via the
--debug kvmtool command line option, to make them disappear for these cases
where they aren't really relevant.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arm/aarch64/kvm.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c
index b38365fb7156..56a0aedc263d 100644
--- a/arm/aarch64/kvm.c
+++ b/arm/aarch64/kvm.c
@@ -16,7 +16,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;
+	const char *debug_str;
 
 	/* the 32bit kernel offset is a well known value */
 	if (kvm->cfg.arch.aarch32_guest)
@@ -25,8 +25,8 @@ 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) {
-		warn_str = "Failed to seek in kernel image file";
-		goto fail;
+		debug_str = "Failed to seek in kernel image file";
+		goto default_offset;
 	}
 
 	size = xread(fd, &header, sizeof(header));
@@ -36,16 +36,16 @@ unsigned long long kvm__arch_get_kern_offset(struct kvm *kvm, int fd)
 	lseek(fd, cur_offset, SEEK_SET);
 
 	if (memcmp(&header.magic, ARM64_IMAGE_MAGIC, sizeof(header.magic))) {
-		warn_str = "Kernel image magic not matching";
-		goto fail;
+		debug_str = "Kernel image magic not matching";
+		goto default_offset;
 	}
 
 	if (le64_to_cpu(header.image_size))
 		return le64_to_cpu(header.text_offset);
 
-	warn_str = "Image size is 0";
-fail:
-	pr_warning("%s, assuming TEXT_OFFSET to be 0x80000", warn_str);
+	debug_str = "Image size is 0";
+default_offset:
+	pr_debug("%s, assuming TEXT_OFFSET to be 0x80000", debug_str);
 	return 0x80000;
 }
 
-- 
2.31.1


  parent reply	other threads:[~2021-09-23 14:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-23 14:44 [PATCH kvmtool 00/10] Run kvm-unit-tests with --kernel Alexandru Elisei
2021-09-23 14:44 ` [PATCH kvmtool 01/10] builtin-run: Treat specifying both --kernel and --firmware as an error Alexandru Elisei
2021-09-23 14:44 ` [PATCH kvmtool 02/10] builtin-run: Warn when ignoring initrd because --firmware was specified Alexandru Elisei
2021-09-23 14:44 ` [PATCH kvmtool 03/10] builtin-run: Do not attempt to find vmlinux if --firmware Alexandru Elisei
2021-09-23 14:44 ` [PATCH kvmtool 04/10] builtin-run: Abstract argument validation into a separate function Alexandru Elisei
2021-09-23 14:45 ` [PATCH kvmtool 05/10] Use kvm->nr_disks instead of kvm->cfg.image_count Alexandru Elisei
2021-09-23 14:45 ` [PATCH kvmtool 06/10] builtin-run: Move kernel command line generation to a separate function Alexandru Elisei
2021-09-23 14:45 ` [PATCH kvmtool 07/10] Add --nodefaults command line argument Alexandru Elisei
2021-09-23 14:45 ` [PATCH kvmtool 08/10] Add --nocompat option to disable compat warnings Alexandru Elisei
2021-10-12  8:34   ` Will Deacon
2021-10-12 14:24     ` Alexandru Elisei
2021-09-23 14:45 ` [PATCH kvmtool 09/10] arm64: Use the default offset when the kernel image magic is not found Alexandru Elisei
2021-09-23 14:45 ` Alexandru Elisei [this message]
2021-10-12  8:46 ` [PATCH kvmtool 00/10] Run kvm-unit-tests with --kernel 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:
  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=20210923144505.60776-11-alexandru.elisei@arm.com \
    --to=alexandru.elisei@arm.com \
    --cc=christoffer.dall@arm.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=vivek.gautam@arm.com \
    --cc=will@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.