From patchwork Thu Jan 10 14:20:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Thierry X-Patchwork-Id: 10755921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D6FE6C2 for ; Thu, 10 Jan 2019 14:21:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CF9B29964 for ; Thu, 10 Jan 2019 14:21:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40E5B2996B; Thu, 10 Jan 2019 14:21:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BD172995D for ; Thu, 10 Jan 2019 14:21:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728774AbfAJOVE (ORCPT ); Thu, 10 Jan 2019 09:21:04 -0500 Received: from foss.arm.com ([217.140.101.70]:36852 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728750AbfAJOVD (ORCPT ); Thu, 10 Jan 2019 09:21:03 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1BA8B1596; Thu, 10 Jan 2019 06:21:03 -0800 (PST) Received: from e112298-lin.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DA1993F5AF; Thu, 10 Jan 2019 06:21:01 -0800 (PST) From: Julien Thierry To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: will.deacon@arm.com, Sami.Mujawar@arm.com, Mark.Rutland@arm.com, andre.przywara@arm.com, Julien Thierry Subject: [PATCH kvmtool v2 6/6] arm: Support non-volatile memory Date: Thu, 10 Jan 2019 14:20:46 +0000 Message-Id: <1547130046-14729-7-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1547130046-14729-1-git-send-email-julien.thierry@arm.com> References: <1547130046-14729-1-git-send-email-julien.thierry@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add an option to let user load files as non-volatile memory. An additional range of addresses is reserved for nv memory. Loaded files must be a multiple of the system page size. Users can chose whether the data written by the guest modifies the original file. Signed-off-by: Julien Thierry --- arm/fdt.c | 34 ++++++++ arm/include/arm-common/kvm-arch.h | 5 +- arm/include/arm-common/kvm-config-arch.h | 18 ++++- arm/kvm.c | 134 +++++++++++++++++++++++++++++++ 4 files changed, 189 insertions(+), 2 deletions(-) diff --git a/arm/fdt.c b/arm/fdt.c index 2936986..e3a7a64 100644 --- a/arm/fdt.c +++ b/arm/fdt.c @@ -72,6 +72,37 @@ static void generate_irq_prop(void *fdt, u8 irq, enum irq_type irq_type) _FDT(fdt_property(fdt, "interrupts", irq_prop, sizeof(irq_prop))); } +static void generate_nvmem_node(void *fdt, struct kvm_nv_mem *nvmem) +{ + char buf[22]; // 22 >= len("flash@" + 16 hex char + '\0') + const u64 reg_prop[] = { + cpu_to_fdt64(nvmem->map_addr), + cpu_to_fdt64(nvmem->size) + }; + + snprintf(buf, sizeof(buf), "flash@%llx", nvmem->map_addr); + _FDT(fdt_begin_node(fdt, buf)); + + _FDT(fdt_property_string(fdt, "compatible", "kvmtool,flash")); + + _FDT(fdt_property(fdt, "reg", reg_prop, sizeof(reg_prop))); + + _FDT(fdt_property_string(fdt, "label", nvmem->name)); + + _FDT(fdt_end_node(fdt)); +} + +static void generate_nvmem_nodes(void *fdt, struct kvm *kvm) +{ + struct list_head *nvmem_node; + + list_for_each(nvmem_node, &kvm->cfg.arch.nvmem_list) + generate_nvmem_node(fdt, + container_of(nvmem_node, + struct kvm_nv_mem, + node)); +} + struct psci_fns { u32 cpu_suspend; u32 cpu_off; @@ -210,6 +241,9 @@ static int setup_fdt(struct kvm *kvm) _FDT(fdt_property_cell(fdt, "migrate", fns->migrate)); _FDT(fdt_end_node(fdt)); + /* Non volatile memories */ + generate_nvmem_nodes(fdt, kvm); + /* Finalise. */ _FDT(fdt_end_node(fdt)); _FDT(fdt_finish(fdt)); diff --git a/arm/include/arm-common/kvm-arch.h b/arm/include/arm-common/kvm-arch.h index b9d486d..f425d86 100644 --- a/arm/include/arm-common/kvm-arch.h +++ b/arm/include/arm-common/kvm-arch.h @@ -10,6 +10,7 @@ #define ARM_IOPORT_AREA _AC(0x0000000000000000, UL) #define ARM_MMIO_AREA _AC(0x0000000000010000, UL) #define ARM_AXI_AREA _AC(0x0000000040000000, UL) +#define ARM_NVRAM_AREA _AC(0x000000007f000000, UL) #define ARM_MEMORY_AREA _AC(0x0000000080000000, UL) #define ARM_LOMAP_MAX_MEMORY ((1ULL << 32) - ARM_MEMORY_AREA) @@ -24,9 +25,11 @@ #define ARM_IOPORT_SIZE (ARM_MMIO_AREA - ARM_IOPORT_AREA) #define ARM_VIRTIO_MMIO_SIZE (ARM_AXI_AREA - (ARM_MMIO_AREA + ARM_GIC_SIZE)) #define ARM_PCI_CFG_SIZE (1ULL << 24) -#define ARM_PCI_MMIO_SIZE (ARM_MEMORY_AREA - \ +#define ARM_PCI_MMIO_SIZE (ARM_NVRAM_AREA - \ (ARM_AXI_AREA + ARM_PCI_CFG_SIZE)) +#define ARM_NVRAM_SIZE (ARM_MEMORY_AREA - ARM_NVRAM_AREA) + #define KVM_IOPORT_AREA ARM_IOPORT_AREA #define KVM_PCI_CFG_AREA ARM_AXI_AREA #define KVM_PCI_MMIO_AREA (KVM_PCI_CFG_AREA + ARM_PCI_CFG_SIZE) diff --git a/arm/include/arm-common/kvm-config-arch.h b/arm/include/arm-common/kvm-config-arch.h index 5734c46..0f1fa11 100644 --- a/arm/include/arm-common/kvm-config-arch.h +++ b/arm/include/arm-common/kvm-config-arch.h @@ -1,8 +1,18 @@ #ifndef ARM_COMMON__KVM_CONFIG_ARCH_H #define ARM_COMMON__KVM_CONFIG_ARCH_H +#include #include "kvm/parse-options.h" +struct kvm_nv_mem { + char *data_file; + char *name; + ssize_t size; + u64 map_addr; + bool write_back; + struct list_head node; +}; + struct kvm_config_arch { const char *dump_dtb_filename; unsigned int force_cntfrq; @@ -12,9 +22,11 @@ struct kvm_config_arch { u64 kaslr_seed; enum irqchip_type irqchip; u64 fw_addr; + struct list_head nvmem_list; }; int irqchip_parser(const struct option *opt, const char *arg, int unset); +int nvmem_parser(const struct option *opt, const char *arg, int unset); #define OPT_ARCH_RUN(pfx, cfg) \ pfx, \ @@ -33,6 +45,10 @@ int irqchip_parser(const struct option *opt, const char *arg, int unset); "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"), + "Address where firmware should be loaded"), \ + OPT_CALLBACK('\0', "nvmem", NULL, \ + ",