From patchwork Thu Apr 28 15:56:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 12830988 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CEEEFC433F5 for ; Thu, 28 Apr 2022 16:02:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Z/79S28Ayol5vCkmDuyvfHe4LTTD2/RfjAdnTrH4WY8=; b=tS51J8WPobOqb7 MbxAV5BaFUh/lDKt1v3BItRYBQCJ2cNagAWl/0EExgNaTnyBY714mlUPDR6VFOpM0pfFyYP+db1hm QQbQuNChjXBYF73lOYhewnB3NB4KLA6z6LZtaodDBR6+Jnk/WHD0F4q/wl1VqG85FMlTw0ficZE2P AtrMZHPSZ0jjATnKmshywJIZVDAdNn9IEfmsVBOHNgAEdilz4WShbqURQxyGl4Ir62MvKDBitIwuX wjjP76ElqP7bp3cfvmKrPPQgtQvdsZENhpw+sxt2qcrM7ouTACflijR0HETDp0hklX7Jihkqw1/bO uNHuy8iWC2Gzf8yOAptw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk6Zd-007mXj-TD; Thu, 28 Apr 2022 16:00:57 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk6VJ-007kK7-29 for linux-arm-kernel@lists.infradead.org; Thu, 28 Apr 2022 15:56:30 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9A27E1477; Thu, 28 Apr 2022 08:56:28 -0700 (PDT) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3884A3F774; Thu, 28 Apr 2022 08:56:27 -0700 (PDT) From: Alexandru Elisei To: julien.thierry.kdev@gmail.com, will@kernel.org, maz@kernel.org, suzuki.poulose@arm.com, julien@xen.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, james.morse@arm.com Subject: [PATCH kvmtool 13/15] arm/arm64: Allow standard size specifiers for firmware address Date: Thu, 28 Apr 2022 16:56:00 +0100 Message-Id: <20220428155602.29445-14-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220428155602.29445-1-alexandru.elisei@arm.com> References: <20220428155602.29445-1-alexandru.elisei@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220428_085629_223307_10A94F88 X-CRM114-Status: GOOD ( 13.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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);