[PATCH kvmtool 13/15] arm/arm64: Allow standard size specifiers for firmware address

Alexandru Elisei alexandru.elisei at arm.com
Thu Apr 28 08:56:00 PDT 2022


The arm and arm64 permit the user to specify the load address, in RAM, for
the firmware image. Make it possible to use the standard size specifiers
(B/K/M/G/P/T) when doing so.

Signed-off-by: Alexandru Elisei <alexandru.elisei at arm.com>
---
 arm/include/arm-common/kvm-config-arch.h |  7 +++++--
 arm/kvm.c                                | 13 +++++++++++++
 builtin-run.c                            |  2 +-
 include/kvm/kvm.h                        |  1 +
 4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h
index cdcbf235ac4e..9306608cbe4e 100644
--- a/arm/include/arm-common/kvm-config-arch.h
+++ b/arm/include/arm-common/kvm-config-arch.h
@@ -17,6 +17,7 @@ struct kvm_config_arch {
 };
 
 int irqchip_parser(const struct option *opt, const char *arg, int unset);
+int fw_addr_parser(const struct option *opt, const char *arg, int unset);
 
 #define OPT_ARCH_RUN(pfx, cfg)							\
 	pfx,									\
@@ -34,7 +35,9 @@ int irqchip_parser(const struct option *opt, const char *arg, int unset);
 		     "[gicv2|gicv2m|gicv3|gicv3-its]",				\
 		     "Type of interrupt controller to emulate in the guest",	\
 		     irqchip_parser, NULL),					\
-	OPT_U64('\0', "firmware-address", &(cfg)->fw_addr,			\
-		"Address where firmware should be loaded"),
+	OPT_CALLBACK('\0', "firmware-address", NULL, "addr[BKMGTP]",		\
+		     "Address where firmware should be loaded. The default unit"\
+		     " of measurement is megabytes (M)",			\
+		     fw_addr_parser, kvm),
 
 #endif /* ARM_COMMON__KVM_CONFIG_ARCH_H */
diff --git a/arm/kvm.c b/arm/kvm.c
index d51cc15d8b1c..83df1c9a0cde 100644
--- a/arm/kvm.c
+++ b/arm/kvm.c
@@ -18,6 +18,19 @@ struct kvm_ext kvm_req_ext[] = {
 	{ 0, 0 },
 };
 
+int fw_addr_parser(const struct option *opt, const char *arg, int unset)
+{
+	struct kvm *kvm = opt->ptr;
+	char *next;
+
+	kvm->cfg.arch.fw_addr = parse_mem_option(arg, &next);
+
+	if (*next != '\0')
+		die("Invalid firmware address: %s", arg);
+
+	return 0;
+}
+
 bool kvm__arch_cpu_supports_vm(void)
 {
 	/* The KVM capability check is enough. */
diff --git a/builtin-run.c b/builtin-run.c
index 1eef1ffd0afc..710080f1831c 100644
--- a/builtin-run.c
+++ b/builtin-run.c
@@ -112,7 +112,7 @@ static int parse_mem_unit(char **next)
 	return shift;
 }
 
-static u64 parse_mem_option(const char *nptr, char **next)
+u64 parse_mem_option(const char *nptr, char **next)
 {
 	u64 shift;
 	u64 val;
diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h
index eb23e2f77310..af3441156725 100644
--- a/include/kvm/kvm.h
+++ b/include/kvm/kvm.h
@@ -211,6 +211,7 @@ static inline bool kvm__arch_has_cfg_ram_address(void)
 
 void *guest_flat_to_host(struct kvm *kvm, u64 offset);
 u64 host_to_guest_flat(struct kvm *kvm, void *ptr);
+u64 parse_mem_option(const char *nptr, char **next);
 
 bool kvm__arch_load_kernel_image(struct kvm *kvm, int fd_kernel, int fd_initrd,
 				 const char *kernel_cmdline);
-- 
2.36.0




More information about the linux-arm-kernel mailing list