kvm tools: add support for ARMv7 processors
cover kvm tools: add support for ARMv7 processors
Hello,
This patch series adds support for ARMv7 processors (Cortex-A15) to kvm tool. The majority of the series consists of small changes in preparation for ARM support, which is added by the final patch. I can try to split this up further, but given that there is no current support for ARM, the sub-patches wouldn't be especially meaningful.
To boot a guest, you will need:
- A Cortex-A15 platform with a kvm-capable bootloader
- The latest kvm-arm patches:
git://github.com/virtualopensystems/linux-kvm-arm.git kvm-arm-master
- A guest kernel configured for our virtual target:
git://git.kernel.org/pub/scm/linux/kernel/git/will/kvmtool.git kvm/mach-virt
I'm also working on an ARMv8 (AArch64) port which fits neatly into the code presented here.
All feedback welcome,
Will
Will Deacon (16):
kvm tools: include arch uapi/asm directories in include path kvm tools: only enable LTO if supported by GCC
kvm tools: avoid linking dynamically against libbfd
kvm tools: specify compiler by name when overriding make default kvm tools: don't bother including linux/compiler.h
kvm tools: don't pass -Wcast-align to the compiler
kvm tools: die if init_list__init returns failure
kvm tools: add generic device registration mechanism
kvm tools: make _FDT macro usable by other architectures kvm tools: virtio-mmio: use subsys_id instead of pci device ID kvm tools: virtio: add dummy set_size_vq implementations kvm tools: allow arch to specify default virtio transport kvm tools: keep track of registered memory banks in struct kvm kvm tools: teach guest_flat_to_host about memory banks starting above
0
kvm tools: provide a mechanism for translating host to guest
addresses
kvm tools: add support for ARMv7 processors
tools/kvm/Makefile | 38 +++- tools/kvm/arm/aarch32/cortex-a15.c | 98 ++++++++++ tools/kvm/arm/aarch32/include/kvm/barrier.h | 10 + tools/kvm/arm/aarch32/include/kvm/kvm-arch.h | 28 +++ tools/kvm/arm/aarch32/kvm-cpu.c | 111 +++++++++++ tools/kvm/arm/aarch32/smp-pen.S | 14 ++ tools/kvm/arm/fdt.c | 269 ++++++++++++++++++++++++++ tools/kvm/arm/gic.c | 86 ++++++++ tools/kvm/arm/include/arm-common/gic.h | 29 +++ tools/kvm/arm/include/arm-common/kvm-arch.h | 31 +++ tools/kvm/arm/include/arm-common/smp.h | 7 + tools/kvm/arm/include/kvm/kvm-cpu-arch.h | 47 +++++ tools/kvm/arm/ioport.c | 5 + tools/kvm/arm/irq.c | 25 +++ tools/kvm/arm/kvm-cpu.c | 112 +++++++++++ tools/kvm/arm/kvm.c | 69 +++++++ tools/kvm/arm/smp.c | 13 ++ tools/kvm/builtin-run.c | 3 +- tools/kvm/devices.c | 24 +++ tools/kvm/hw/pci-shmem.c | 8 +- tools/kvm/hw/vesa.c | 8 +- tools/kvm/include/kvm/devices.h | 21 ++ tools/kvm/include/kvm/fdt.h | 26 +++ tools/kvm/include/kvm/kvm.h | 16 +- tools/kvm/include/kvm/pci.h | 2 - tools/kvm/include/kvm/virtio-mmio.h | 1 + tools/kvm/include/kvm/virtio-pci.h | 2 + tools/kvm/include/linux/stddef.h | 6 - tools/kvm/kvm.c | 55 +++++- tools/kvm/pci.c | 40 ++--- tools/kvm/powerpc/include/kvm/kvm-arch.h | 13 +- tools/kvm/powerpc/irq.c | 3 +- tools/kvm/powerpc/kvm.c | 2 +- tools/kvm/powerpc/spapr_pci.c | 4 +- tools/kvm/virtio/9p.c | 10 +- tools/kvm/virtio/balloon.c | 3 +- tools/kvm/virtio/blk.c | 3 +- tools/kvm/virtio/console.c | 10 +- tools/kvm/virtio/mmio.c | 9 +- tools/kvm/virtio/pci.c | 7 +- tools/kvm/virtio/rng.c | 10 +- tools/kvm/virtio/scsi.c | 3 +- tools/kvm/x86/include/kvm/kvm-arch.h | 11 +- tools/kvm/x86/kvm.c | 7 + 44 files changed, 1214 insertions(+), 85 deletions(-) create mode 100644 tools/kvm/arm/aarch32/cortex-a15.c create mode 100644 tools/kvm/arm/aarch32/include/kvm/barrier.h create mode 100644 tools/kvm/arm/aarch32/include/kvm/kvm-arch.h create mode 100644 tools/kvm/arm/aarch32/kvm-cpu.c create mode 100644 tools/kvm/arm/aarch32/smp-pen.S create mode 100644 tools/kvm/arm/fdt.c create mode 100644 tools/kvm/arm/gic.c create mode 100644 tools/kvm/arm/include/arm-common/gic.h create mode 100644 tools/kvm/arm/include/arm-common/kvm-arch.h create mode 100644 tools/kvm/arm/include/arm-common/smp.h create mode 100644 tools/kvm/arm/include/kvm/kvm-cpu-arch.h create mode 100644 tools/kvm/arm/ioport.c create mode 100644 tools/kvm/arm/irq.c create mode 100644 tools/kvm/arm/kvm-cpu.c create mode 100644 tools/kvm/arm/kvm.c create mode 100644 tools/kvm/arm/smp.c create mode 100644 tools/kvm/devices.c create mode 100644 tools/kvm/include/kvm/devices.h create mode 100644 tools/kvm/include/kvm/fdt.h
Signature · 1 line
1.7.4.1
RFC PATCH 1/16 kvm tools: include arch uapi/asm directories in include path
Architectures such as ARM and powerpc place asm/kvm.h under arch/$ARCH/include/uapi/asm, so ensure that this is part of the C include path.
--- tools/kvm/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/kvm/Makefile +1 -1
@@ -244,7 +244,7 @@ DEFINES += -DKVMTOOLS_VERSION='"$(KVMTOOLS_VERSION)"' DEFINES += -DBUILD_ARCH='"$(ARCH)"' KVM_INCLUDE := include -CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) -I$(KINCL_PATH)/include/uapi -I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/ -O2 -fno-strict-aliasing -g -flto +CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) -I$(KINCL_PATH)/include/uapi -I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/uapi -I$(KINCL_PATH)/arch/$(ARCH)/include/ -O2 -fno-strict-aliasing -g -flto WARNINGS += -Wall WARNINGS += -Wcast-align
Signature · 1 line
1.7.4.1
RFC PATCH 2/16 kvm tools: only enable LTO if supported by GCC
In reply to Will DeaconCommit 99423f12db2a ("kvm tools: enable LTO") unconditionally enabled link-time-optimisations when building kvmtool. Unfortunately, passing -flto to a GCC without support for the option, results in a fatal build error:
cc1: error: LTO support has not been enabled in this configuration
This patch adds a check to the kvm tools Makefile so that LTO is only enabled if the host compiler supports it.
--- tools/kvm/Makefile | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
tools/kvm/Makefile +6 -1
@@ -226,6 +226,11 @@ ifeq ($(call try-cc,$(SOURCE_AIO),$(FLAGS_AIO) -static),y) LIBS_STATOPT += -laio endif +FLAGS_LTO := -flto +ifeq ($(call try-cc,$(SOURCE_HELLO),$(FLAGS_LTO)),y) + CFLAGS += $(FLAGS_LTO) +endif + ifneq ($(call try-build,$(SOURCE_STATIC),-static,),y) $(error No static libc found. Please install glibc-static package.) endif
@@ -244,7 +249,7 @@ DEFINES += -DKVMTOOLS_VERSION='"$(KVMTOOLS_VERSION)"' DEFINES += -DBUILD_ARCH='"$(ARCH)"' KVM_INCLUDE := include -CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) -I$(KINCL_PATH)/include/uapi -I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/uapi -I$(KINCL_PATH)/arch/$(ARCH)/include/ -O2 -fno-strict-aliasing -g -flto +CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) -I$(KINCL_PATH)/include/uapi -I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/uapi -I$(KINCL_PATH)/arch/$(ARCH)/include/ -O2 -fno-strict-aliasing -g WARNINGS += -Wall WARNINGS += -Wcast-align
Signature · 1 line
1.7.4.1
RFC PATCH 3/16 kvm tools: avoid linking dynamically against libbfd
In reply to Will DeaconLinking dynamically against libbfd results in a non-portable application binary and is generally frowned upon by distributions: Debian forbids it explicitly and on Gentoo, it results in a failure at run-time:
./lkvm: error while loading shared libraries: libbfd-2.22.so: cannot open shared object file: No such file or directory
Avoid these problems by linking statically instead.
--- tools/kvm/Makefile | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
tools/kvm/Makefile +0 -5
@@ -171,11 +171,6 @@ endif # both and only build those that link! FLAGS_BFD := $(CFLAGS) -lbfd -ifeq ($(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD)),y) - CFLAGS_DYNOPT += -DCONFIG_HAS_BFD - OBJS_DYNOPT += symbol.o - LIBS_DYNOPT += -lbfd -endif ifeq ($(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD) -static),y) CFLAGS_STATOPT += -DCONFIG_HAS_BFD OBJS_STATOPT += symbol.o
Signature · 1 line
1.7.4.1
RFC PATCH 4/16 kvm tools: specify compiler by name when overriding make default
In reply to Will DeaconGNU make defaults "$(CC)" to "cc", which breaks compilation when we try to execute $(CROSS_COMPILE)-cc.
This patch copies what the top-level kernel Makefile does, by specifying "gcc" directly when overriding the $CC environment variable.
--- tools/kvm/Makefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
tools/kvm/Makefile +2 -2
@@ -19,8 +19,8 @@ export E Q KINCL_PATH include config/utilities.mak include config/feature-tests.mak -CC := $(CROSS_COMPILE)$(CC) -LD := $(CROSS_COMPILE)$(LD) +CC := $(CROSS_COMPILE)gcc +LD := $(CROSS_COMPILE)ld FIND := find CSCOPE := cscope
Signature · 1 line
1.7.4.1
RFC PATCH 5/16 kvm tools: don't bother including linux/compiler.h
In reply to Will Deaconlinux/compiler.h will never give us a definition for __compiler_offsetof because __KERNEL__ isn't defined, so just use the simple definition that we have already.
This patch removes the redundant code.
--- tools/kvm/include/linux/stddef.h | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
tools/kvm/include/linux/stddef.h +0 -6
@@ -1,16 +1,10 @@#ifndef _LINUX_STDDEF_H#define _LINUX_STDDEF_H -#include <linux/compiler.h> -#undef NULL#define NULL ((void *)0)#undef offsetof -#ifdef __compiler_offsetof -#define offsetof (TYPE ,MEMBER ) __compiler_offsetof(TYPE,MEMBER) -#else #define offsetof (TYPE ,MEMBER ) ((size_t) &((TYPE *)0)->MEMBER) -#endif #endif
Signature · 1 line
1.7.4.1
Re: [RFC PATCH 05/16] kvm tools: don't bother including linux/compiler.h
Quoted 22 lines · Will Deacon
linux/compiler.hwill never give us a definition for__compiler_offsetofbecause__KERNEL__isn't defined, so just use the simple definition that we have already.This patch removes the redundant code.
Signed-off-by Will Deacon <[email protected]>--- tools/kvm/include/linux/stddef.h | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)tools/kvm/include/linux/stddef.h +0
-2@@ -1,16 +1,10 @@#ifndef _LINUX_STDDEF_H#define _LINUX_STDDEF_H -#include <linux/compiler.h> -#undef NULL
tools/kvm/include/linux/stddef.h line 10
Quoted 10 lines
tools/kvm/include/linux/stddef.h +0
-4#define NULL ((void *)0)#undef offsetof -#ifdef __compiler_offsetof -#define offsetof (TYPE ,MEMBER ) __compiler_offsetof(TYPE,MEMBER) -#else #define offsetof (TYPE ,MEMBER ) ((size_t) &((TYPE *)0)->MEMBER) -#endif #endif
I'm seeing the following breakage with this patch applied:
[penberg@tux kvm]$ make
CC hw/rtc.o
CC ioport.o
CC kvm-cpu.o
CC kvm.o
In file included from include/kvm/rbtree-interval.h:4:0,
from include/kvm/ioport.h:4,
from hw/rtc.c:3:../../include/linux/rbtree_augmented.h:125:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ In file included from include/kvm/rbtree-interval.h:4:0,
from include/kvm/ioport.h:4,
from ioport.c:1:../../include/linux/rbtree_augmented.h:125:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
make: *** [hw/rtc.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [ioport.o] Error 1
Re: [RFC PATCH 05/16] kvm tools: don't bother including linux/compiler.h
[ apologies if you receive this twice -- my email is playing up ]
Hi Pekka,
Quoted 33 lines · Pekka Enberg
Quoted 11 lines · Will Deacon
tools/kvm/include/linux/stddef.h +0
-2@@ -1,16 +1,10 @@#ifndef _LINUX_STDDEF_H#define _LINUX_STDDEF_H -#include <linux/compiler.h> -#undef NULLtools/kvm/include/linux/stddef.h line 10
Quoted 10 lines
tools/kvm/include/linux/stddef.h +0
-4#define NULL ((void *)0)#undef offsetof -#ifdef __compiler_offsetof -#define offsetof (TYPE ,MEMBER ) __compiler_offsetof(TYPE,MEMBER) -#else #define offsetof (TYPE ,MEMBER ) ((size_t) &((TYPE *)0)->MEMBER) -#endif #endif I'm seeing the following breakage with this patch applied:
[penberg@tux kvm]$ make
CC hw/rtc.o CC ioport.o CC kvm-cpu.o CC kvm.o In file included from include/kvm/rbtree-interval.h:4:0, from include/kvm/ioport.h:4, from hw/rtc.c:3:
Quoted 8 lines
../../include/linux/rbtree_augmented.h:125:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ In file included frominclude/kvm/rbtree-interval.h:4:0,
frominclude/kvm/ioport.h:4,
from ioport.c:1:../../include/linux/rbtree_augmented.h:125:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
make: *** [hw/rtc.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [ioport.o] Error 1
I'm struggling to reproduce this with my tree. Can you confirm whether or not you have commit 29fc7c5a4f51 ("rbtree: include linux/compiler.h for definition of __always_inline") in your *kernel* sources please?
Cheers,
Will
Re: [RFC PATCH 05/16] kvm tools: don't bother including linux/compiler.h
Quoted 19 lines · Will Deacon
Quoted 10 lines
I'm seeing the following breakage with this patch applied:
[penberg@tux kvm]$ make
CC hw/rtc.o CC ioport.o CC kvm-cpu.o CC kvm.o In file included from include/kvm/rbtree-interval.h:4:0, from include/kvm/ioport.h:4, from hw/rtc.c:3:Quoted 8 lines
../../include/linux/rbtree_augmented.h:125:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ In file included frominclude/kvm/rbtree-interval.h:4:0,
frominclude/kvm/ioport.h:4,
from ioport.c:1:../../include/linux/rbtree_augmented.h:125:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
make: *** [hw/rtc.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [ioport.o] Error 1
Quoted 3 lines
I'm struggling to reproduce this with my tree. Can you confirm whether or not you have commit
29fc7c5a4f51("rbtree: includelinux/compiler.hfor definition of__always_inline") in your *kernel* sources please?
No, I don't. I can cherry-pick that to my tree if necessary.
Pekka
Re: [RFC PATCH 05/16] kvm tools: don't bother including linux/compiler.h
Quoted 20 lines · Pekka Enberg
Quoted 19 lines · Will Deacon
Quoted 18 lines
I'm seeing the following breakage with this patch applied:
[penberg@tux kvm]$ make
CC hw/rtc.o CC ioport.o CC kvm-cpu.o CC kvm.o In file included from include/kvm/rbtree-interval.h:4:0, from include/kvm/ioport.h:4, from hw/rtc.c:3:
../../include/linux/rbtree_augmented.h:125:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’ In file included frominclude/kvm/rbtree-interval.h:4:0,
frominclude/kvm/ioport.h:4,
from ioport.c:1:../../include/linux/rbtree_augmented.h:125:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
make: *** [hw/rtc.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [ioport.o] Error 1
Quoted 5 lines
Quoted 3 lines
I'm struggling to reproduce this with my tree. Can you confirm whether or not you have commit
29fc7c5a4f51("rbtree: includelinux/compiler.hfor definition of__always_inline") in your *kernel* sources please?No, I don't. I can cherry-pick that to my tree if necessary.
Aha, that's probably the issue then since you won't have a definition of __always_inline from linux/compiler.h. If you cherry-pick that patch, then this one should work as intended. If you prefer, I can include that patch in v2 of my series.
Cheers,
Will
Re: [RFC PATCH 05/16] kvm tools: don't bother including linux/compiler.h
Hi Will,
Quoted 10 lines · Will Deacon
Quoted 5 lines
Quoted 3 lines
I'm struggling to reproduce this with my tree. Can you confirm whether or not you have commit
29fc7c5a4f51("rbtree: includelinux/compiler.hfor definition of__always_inline") in your *kernel* sources please?No, I don't. I can cherry-pick that to my tree if necessary.
Aha, that's probably the issue then since you won't have a definition of
__always_inlinefromlinux/compiler.h. If you cherry-pick that patch, then this one should work as intended. If you prefer, I can include that patch in v2 of my series.
Please just include the patch in your series.
Pekka
RFC PATCH 6/16 kvm tools: don't pass -Wcast-align to the compiler
In reply to Will DeaconGCC 4.7 with -Wcast-align will warn for code like the following:
bar = (struct foo *)(char *)(0);
which is exactly the sort of code generated by container_of. In combination with -Werror, this breaks the build.
This patch removes the option from the kvmtool Makefile.
--- tools/kvm/Makefile | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
tools/kvm/Makefile +0 -1
@@ -247,7 +247,6 @@ KVM_INCLUDE := include CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) -I$(KINCL_PATH)/include/uapi -I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/uapi -I$(KINCL_PATH)/arch/$(ARCH)/include/ -O2 -fno-strict-aliasing -g WARNINGS += -Wall -WARNINGS += -Wcast-align WARNINGS += -Wformat=2 WARNINGS += -Winit-self WARNINGS += -Wmissing-declarations
Signature · 1 line
1.7.4.1
RFC PATCH 7/16 kvm tools: die if init_list__init returns failure
In reply to Will DeaconIf init_list__init returns failure when initialising kvm tool, we can't rely on our structures being fully initialised, so die rather than try to continue and fail gracefully later on.
This prevents a SEGV when kvm is not available on the host:
Error: '/dev/kvm' not found. Please make sure your kernel has CONFIG_KVM enabled and that the KVM modules are loaded.
Warning: Failed init: kvm__init
Segmentation fault
--- tools/kvm/builtin-run.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
tools/kvm/builtin-run.c +2 -1
@@ -665,7 +665,8 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv)printf (" # %s run -k %s -m %Lu -c %d --name %s\n" ,KVM_BINARY_NAME , kvm->cfg.kernel_filename, kvm->cfg.ram_size /1024 /1024 , kvm->cfg.nrcpus, kvm->cfg.guest_name); -init_list__init (kvm); +if (init_list__init (kvm) <0 ) +die ("Initialisation failed" );return kvm; }
Signature · 1 line
1.7.4.1
RFC PATCH 8/16 kvm tools: add generic device registration mechanism
In reply to Will DeaconPCI devices are currently registered into the pci_devices array via the pci__register function, which can then be indexed later by architecture code to construct device tree nodes. For MMIO devices, there is no such utility.
Rather than invent a similar mechanism for MMIO, this patch creates a global device registration mechanism, which allows the device type to be specified when registered or indexing a device. Current users of the pci registration code are migrated to the new infrastructure and virtio MMIO devices are registered at init time.
--- tools/kvm/Makefile | 1 + tools/kvm/devices.c | 24 +++++++++++++++++++++ tools/kvm/hw/pci-shmem.c | 8 ++++++- tools/kvm/hw/vesa.c | 8 ++++++- tools/kvm/include/kvm/devices.h | 21 ++++++++++++++++++ tools/kvm/include/kvm/pci.h | 2 - tools/kvm/include/kvm/virtio-mmio.h | 1 + tools/kvm/include/kvm/virtio-pci.h | 2 + tools/kvm/pci.c | 40 ++++++++++++---------------------- tools/kvm/powerpc/irq.c | 3 +- tools/kvm/powerpc/spapr_pci.c | 2 +- tools/kvm/virtio/mmio.c | 7 ++++++ tools/kvm/virtio/pci.c | 7 +++++- 13 files changed, 93 insertions(+), 33 deletions(-) create mode 100644 tools/kvm/devices.c create mode 100644 tools/kvm/include/kvm/devices.h
tools/kvm/Makefile +1 -0
@@ -50,6 +50,7 @@ OBJS += builtin-run.o OBJS += builtin-setup.o OBJS += builtin-stop.o OBJS += builtin-version.o +OBJS += devices.o OBJS += disk/core.o OBJS += framebuffer.o OBJS += guest_compat.o
tools/kvm/devices.c new file +24 -0
@@ -0,0 +1,24 @@ +#include "kvm/devices.h" +#include "kvm/kvm.h" + +#include <linux/err.h> + +static struct device_header *devices[KVM_MAX_DEVICES ]; + +int device__register (struct device_header *dev,u8 dev_num) +{ +if (dev_num >=KVM_MAX_DEVICES ) +return -ENOSPC ; + + devices[dev_num] = dev; + +return 0 ; +} + +struct device_header *device__find_dev (u8 dev_num) +{ +if (dev_num >=KVM_MAX_DEVICES ) +return ERR_PTR (-EOVERFLOW ); + +return devices[dev_num]; +}
tools/kvm/hw/pci-shmem.c +7 -1
@@ -1,3 +1,4 @@ +#include "kvm/devices.h" #include "kvm/pci-shmem.h" #include "kvm/virtio-pci-dev.h" #include "kvm/irq.h"
@@ -30,6 +31,11 @@ static struct pci_device_header pci_shmem_pci_device = { .msix.pba_offset = cpu_to_le32(0x1001), /* Use BAR 1 */ }; +static struct device_header pci_shmem_device = { + .bus_type =DEVICE_BUS_PCI , + .data = &pci_shmem_pci_device, +}; +/* registers for the Inter-VM shared memory device */ enum ivshmem_registers {INTRMASK =0 ,
@@ -384,7 +390,7 @@ int pci_shmem__init(struct kvm *kvm) pci_shmem_pci_device.bar[2 ] =cpu_to_le32 (shmem_region->phys_addr |PCI_BASE_ADDRESS_SPACE_MEMORY ); pci_shmem_pci_device.bar_size[2 ] = shmem_region->size; -pci__register (&pci_shmem_pci_device, dev); +device__register (&pci_shmem_device, dev);/* Open shared memory and plug it into the guest */ mem = setup_shmem(shmem_region->handle, shmem_region->size,
tools/kvm/hw/vesa.c +7 -1
@@ -1,5 +1,6 @@#include "kvm/vesa.h" +#include "kvm/devices.h" #include "kvm/virtio-pci-dev.h" #include "kvm/framebuffer.h" #include "kvm/kvm-cpu.h"
@@ -44,6 +45,11 @@ static struct pci_device_header vesa_pci_device = { .bar_size[1] = VESA_MEM_SIZE, }; +static struct device_header vesa_device = { + .bus_type =DEVICE_BUS_PCI , + .data = &vesa_pci_device, +}; +static struct framebuffer vesafb;struct framebuffer *vesa__init (struct kvm *kvm)
@@ -68,7 +74,7 @@ struct framebuffer *vesa__init(struct kvm *kvm) vesa_pci_device.irq_line = line; vesa_base_addr = (u16 )r; vesa_pci_device.bar[0 ] =cpu_to_le32 (vesa_base_addr |PCI_BASE_ADDRESS_SPACE_IO ); -pci__register (&vesa_pci_device, dev); +device__register (&vesa_device, dev); mem =mmap (NULL ,VESA_MEM_SIZE ,PROT_RW ,MAP_ANON_NORESERVE ,-1 ,0 );if (mem ==MAP_FAILED )
tools/kvm/include/kvm/devices.h new file +21 -0
@@ -0,0 +1,21 @@ +#ifndef KVM__DEVICES_H +#define KVM__DEVICES_H + +#include <linux/types.h> + +#define KVM_MAX_DEVICES 256 + +enum device_bus_type { +DEVICE_BUS_PCI , +DEVICE_BUS_MMIO , +}; + +struct device_header { +enum device_bus_type bus_type; +void *data; +}; + +int device__register (struct device_header *dev,u8 dev_num); +struct device_header *device__find_dev (u8 dev_num); + +#endif /* KVM__DEVICES_H */
tools/kvm/include/kvm/pci.h +0 -2
@@ -9,7 +9,6 @@#include "kvm/kvm.h" #include "kvm/msi.h" -#define PCI_MAX_DEVICES 256/* * PCI Configuration Mechanism #1 I/O ports. See Section 3.7.4.1. * ("Configuration Mechanism #1") of the PCI Local Bus Specification 2.1 for
@@ -86,7 +85,6 @@ struct pci_device_header {int pci__init (struct kvm *kvm);int pci__exit (struct kvm *kvm); -int pci__register (struct pci_device_header *dev,u8 dev_num);struct pci_device_header *pci__find_dev (u8 dev_num);u32 pci_get_io_space_block (u32 size);void pci__config_wr (struct kvm *kvm,union pci_config_address addr,void *data,int size);
tools/kvm/include/kvm/virtio-mmio.h +1 -0
@@ -47,6 +47,7 @@ struct virtio_mmio {struct kvm *kvm;u8 irq;struct virtio_mmio_hdr hdr; +struct device_header dev_hdr;struct virtio_mmio_ioevent_param ioeventfds[VIRTIO_MMIO_MAX_VQ ]; };
tools/kvm/include/kvm/virtio-pci.h +2 -0
@@ -1,6 +1,7 @@#ifndef KVM__VIRTIO_PCI_H #define KVM__VIRTIO_PCI_H +#include "kvm/devices.h" #include "kvm/pci.h" #include <linux/types.h>
@@ -19,6 +20,7 @@ struct virtio_pci_ioevent_param {struct virtio_pci {struct pci_device_header pci_hdr; +struct device_header dev_hdr;void *dev;u16 base_addr;
tools/kvm/pci.c +14 -26
@@ -1,3 +1,4 @@ +#include "kvm/devices.h" #include "kvm/pci.h" #include "kvm/ioport.h" #include "kvm/util.h"
@@ -8,8 +9,6 @@#define PCI_BAR_OFFSET (b) (offsetof(struct pci_device_header, bar[b])) -static struct pci_device_header *pci_devices[PCI_MAX_DEVICES ]; -static union pci_config_address pci_config_address;/* This is within our PCI gap - in an unused area.
@@ -63,7 +62,7 @@ static struct ioport_operations pci_config_address_ops = {static bool pci_device_exists (u8 bus_number,u8 device_number,u8 function_number) { -struct pci_device_header *dev; +struct device_header *dev;if (pci_config_address.bus_number != bus_number)return false;
@@ -71,12 +70,8 @@ static bool pci_device_exists(u8 bus_number, u8 device_number, u8 function_numbeif (pci_config_address.function_number != function_number)return false; -if (device_number >=PCI_MAX_DEVICES ) -return false; - - dev = pci_devices[device_number]; - -return dev !=NULL ; + dev =device__find_dev (device_number); +return !IS_ERR_OR_NULL (dev) && dev->bus_type ==DEVICE_BUS_PCI ; }static bool pci_config_data_out (struct ioport *ioport,struct kvm *kvm,u16 port,void *data,int size)
@@ -121,12 +116,13 @@ void pci__config_wr(struct kvm *kvm, union pci_config_address addr, void *data, offset = addr.w &0xff ;if (offset <sizeof (struct pci_device_header )) { -void *p = pci_devices[dev_num]; +void *p =device__find_dev (dev_num)->data; +struct pci_device_header *hdr = p;u8 bar = (offset -PCI_BAR_OFFSET (0 )) / (sizeof (u32));u32 sz =PCI_IO_SIZE ; -if (bar <6 && pci_devices[dev_num]->bar_size[bar]) - sz = pci_devices[dev_num]->bar_size[bar]; +if (bar <6 && hdr->bar_size[bar]) + sz = hdr->bar_size[bar];/* * If the kernel masks the BAR it would expect to find the
@@ -158,7 +154,7 @@ void pci__config_rd(struct kvm *kvm, union pci_config_address addr, void *data, offset = addr.w &0xff ;if (offset <sizeof (struct pci_device_header )) { -void *p = pci_devices[dev_num]; +void *p =device__find_dev (dev_num)->data;memcpy (data, p + offset, size); }else {
@@ -169,22 +165,14 @@ void pci__config_rd(struct kvm *kvm, union pci_config_address addr, void *data, } } -int pci__register (struct pci_device_header *dev,u8 dev_num) -{ -if (dev_num >=PCI_MAX_DEVICES ) -return -ENOSPC ; - - pci_devices[dev_num] = dev; - -return 0 ; -} -struct pci_device_header *pci__find_dev (u8 dev_num) { -if (dev_num >=PCI_MAX_DEVICES ) -return ERR_PTR (-EOVERFLOW ); +struct device_header *hdr =device__find_dev (dev_num); + +if (IS_ERR (hdr) || hdr->bus_type !=DEVICE_BUS_PCI ) +return NULL ; -return pci_devices[dev_num]; +return hdr->data; }int pci__init (struct kvm *kvm)
tools/kvm/powerpc/irq.c +2 -1
@@ -8,6 +8,7 @@* by the Free Software Foundation. */ +#include "kvm/devices.h" #include "kvm/irq.h" #include "kvm/kvm.h" #include "kvm/util.h"
@@ -35,7 +36,7 @@ static int pci_devs = 0;int irq__register_device (u32 dev,u8 *num,u8 *pin,u8 *line) { -if (pci_devs >=PCI_MAX_DEVICES ) +if (pci_devs >=KVM_MAX_DEVICES )die ("Hit PCI device limit!\n" ); *num = pci_devs++;
tools/kvm/powerpc/spapr_pci.c +1 -1
@@ -302,7 +302,7 @@ int spapr_populate_pci_devices(struct kvm *kvm,/* Populate PCI devices and allocate IRQs */ devices =0 ; -for (devid =0 ; devid <PCI_MAX_DEVICES ; devid++) { +for (devid =0 ; devid <KVM_MAX_DEVICES ; devid++) {uint32_t *irqmap = interrupt_map[devices];struct pci_device_header *hdr =pci__find_dev (devid);
tools/kvm/virtio/mmio.c +7 -0
@@ -1,3 +1,4 @@ +#include "kvm/devices.h" #include "kvm/virtio-mmio.h" #include "kvm/ioeventfd.h" #include "kvm/ioport.h"
@@ -238,6 +239,12 @@ int virtio_mmio_init(struct kvm *kvm, void *dev, struct virtio_device *vdev,if (irq__register_device (subsys_id, &device, &pin, &line) <0 )return -1 ; vmmio->irq = line; + vmmio->dev_hdr = (struct device_header ) { + .bus_type =DEVICE_BUS_MMIO , + .data = vmmio, + }; + +device__register (&vmmio->dev_hdr, device);/* * Instantiate guest virtio-mmio devices using kernel command line
tools/kvm/virtio/pci.c +6 -1
@@ -343,6 +343,11 @@ int virtio_pci__init(struct kvm *kvm, void *dev, struct virtio_device *vdev, .bar_size[3] = PCI_IO_SIZE, }; + vpci->dev_hdr = (struct device_header ) { + .bus_type =DEVICE_BUS_PCI , + .data = &vpci->pci_hdr, + }; + vpci->pci_hdr.msix.cap =PCI_CAP_ID_MSIX ; vpci->pci_hdr.msix.next =0 ;/*
@@ -375,7 +380,7 @@ int virtio_pci__init(struct kvm *kvm, void *dev, struct virtio_device *vdev, vpci->pci_hdr.irq_pin = pin; vpci->pci_hdr.irq_line = line; - r =pci__register (&vpci->pci_hdr, ndev); + r =device__register (&vpci->dev_hdr, ndev);if (r <0 ) goto free_ioport;
Signature · 1 line
1.7.4.1
Re: [RFC PATCH 08/16] kvm tools: add generic device registration mechanism
Quoted 48 lines · Will Deacon
PCI devices are currently registered into the
pci_devicesarray via thepci__registerfunction, which can then be indexed later by architecture code to construct device tree nodes. For MMIO devices, there is no such utility.Rather than invent a similar mechanism for MMIO, this patch creates a global device registration mechanism, which allows the device type to be specified when registered or indexing a device. Current users of the pci registration code are migrated to the new infrastructure and virtio MMIO devices are registered at init time.
Signed-off-by Will Deacon <[email protected]>--- tools/kvm/Makefile | 1 + tools/kvm/devices.c | 24 +++++++++++++++++++++ tools/kvm/hw/pci-shmem.c | 8 ++++++- tools/kvm/hw/vesa.c | 8 ++++++- tools/kvm/include/kvm/devices.h | 21 ++++++++++++++++++ tools/kvm/include/kvm/pci.h | 2 - tools/kvm/include/kvm/virtio-mmio.h | 1 + tools/kvm/include/kvm/virtio-pci.h | 2 + tools/kvm/pci.c | 40 ++++++++++++---------------------- tools/kvm/powerpc/irq.c | 3 +- tools/kvm/powerpc/spapr_pci.c | 2 +- tools/kvm/virtio/mmio.c | 7 ++++++ tools/kvm/virtio/pci.c | 7 +++++- 13 files changed, 93 insertions(+), 33 deletions(-) create mode 100644 tools/kvm/devices.c create mode 100644 tools/kvm/include/kvm/devices.htools/kvm/Makefile +1
-0@@ -50,6 +50,7 @@ OBJS += builtin-run.o OBJS += builtin-setup.o OBJS += builtin-stop.o OBJS += builtin-version.o +OBJS += devices.o OBJS += disk/core.o OBJS += framebuffer.o OBJS += guest_compat.otools/kvm/devices.c new file +0
-0
tools/kvm/devices.c line 6
Quoted 6 lines
tools/kvm/devices.c new file +6
-0@@ -0,0 +1,24 @@ +#include "kvm/devices.h" +#include "kvm/kvm.h" + +#include <linux/err.h> + +static struct device_header *devices[KVM_MAX_DEVICES ];
Does it really have a hard limit at KVM_MAX_DEVICES? Or can we turn it into something more dynamic (list/tree/whatever)?
Thanks,
Sasha
Re: [RFC PATCH 08/16] kvm tools: add generic device registration mechanism
Hi Sasha,
Quoted 16 lines · Sasha Levin
tools/kvm/devices.c line 6
Quoted 12 lines · Will Deacon
tools/kvm/devices.c new file +6
-0@@ -0,0 +1,24 @@ +#include "kvm/devices.h" +#include "kvm/kvm.h" + +#include <linux/err.h> + +static struct device_header *devices[KVM_MAX_DEVICES ];Does it really have a hard limit at
KVM_MAX_DEVICES? Or can we turn it into something more dynamic (list/tree/whatever)?
Sure, I'm happy to change the datatype to something more appropriate. Matt also suggested trying to split up PCI devices from MMIO devices so that they have their own ID namespaces, so I'll need to have a play.
Cheers,
Will
RFC PATCH 9/16 kvm tools: make _FDT macro usable by other architectures
In reply to Will DeaconThe _FDT macro is useful when generating device trees for a guest, so make it available to other architectures.
--- tools/kvm/include/kvm/fdt.h | 26 ++++++++++++++++++++++++++ tools/kvm/powerpc/include/kvm/kvm-arch.h | 11 ----------- tools/kvm/powerpc/kvm.c | 2 +- tools/kvm/powerpc/spapr_pci.c | 2 +- 4 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 tools/kvm/include/kvm/fdt.h
tools/kvm/include/kvm/fdt.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef KVM__FDT_H +#define KVM__FDT_H + +#include "libfdt.h" + +#include <linux/types.h> + +#define FDT_MAX_SIZE 0x10000 + +/* Helper for the various bits of code that generate FDT nodes */ +#define _FDT (exp) \ + do { \ + int ret = (exp); \ + if (ret < 0) { \ + die("Error creating device tree: %s: %s\n", \ + #exp, fdt_strerror(ret)); \ + } \ + } while (0) + +static inline u32 fdt__alloc_phandle (void ) +{ +static u32 phandle =0 ; +return ++phandle; +} + +#endif /* KVM__FDT_H */
tools/kvm/powerpc/include/kvm/kvm-arch.h +0 -11
@@ -27,7 +27,6 @@#define KERNEL_SECONDARY_START_ADDR 0x0000000000000060#define INITRD_LOAD_ADDR 0x0000000002800000 -#define FDT_MAX_SIZE 0x10000#define RTAS_MAX_SIZE 0x10000#define TIMEBASE_FREQ 512000000ULL
@@ -55,14 +54,4 @@ struct kvm_arch { struct spapr_phb *phb; }; -/* Helper for the various bits of code that generate FDT nodes */ -#define _FDT (exp) \ - do { \ - int ret = (exp); \ - if (ret < 0) { \ - die("Error creating device tree: %s: %s\n", \ - #exp, fdt_strerror(ret)); \ - } \ - } while (0) -#endif /* KVM__KVM_ARCH_H */
tools/kvm/powerpc/kvm.c +1 -1
@@ -11,9 +11,9 @@* by the Free Software Foundation. */ +#include "kvm/fdt.h" #include "kvm/kvm.h" #include "kvm/util.h" -#include "libfdt.h" #include "cpu_info.h" #include "spapr.h"
tools/kvm/powerpc/spapr_pci.c +1 -1
@@ -15,9 +15,9 @@#include "spapr.h" #include "spapr_pci.h" +#include "kvm/fdt.h" #include "kvm/util.h" #include "kvm/pci.h" -#include "libfdt.h" #include <linux/pci_regs.h> #include <linux/byteorder.h>
Signature · 1 line
1.7.4.1
RFC PATCH 10/16 kvm tools: virtio-mmio: use subsys_id instead of pci device ID
In reply to Will DeaconThe virtio MMIO code attempts to map PCI device IDs to virtio MMIO device IDs by subtracting 0x1000 and adding 1, however this conversion only works for NET and BLK devices.
This patch uses the subsys_id (which is actually the virtio device ID for virtio-mmio devices) instead of the PCI device ID when populating the mmio device header.
--- tools/kvm/virtio/mmio.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/kvm/virtio/mmio.c +1 -1
@@ -231,7 +231,7 @@ int virtio_mmio_init(struct kvm *kvm, void *dev, struct virtio_device *vdev, vmmio->hdr = (struct virtio_mmio_hdr ) { .magic = {'v' ,'i' ,'r' ,'t' }, .version =1 , - .device_id = device_id -0x1000 +1 , + .device_id = subsys_id, .vendor_id =0x4d564b4c ,/* 'LKVM' */ .queue_num_max =256 , };
Signature · 1 line
1.7.4.1
RFC PATCH 11/16 kvm tools: virtio: add dummy set_size_vq implementations
In reply to Will DeaconWhen a guest kernel initialises a virtio device using an MMIO transport, it attempts to set the size of the virtual queue. For devices that expect a PCI transport, this is not the case and, as such, our console, 9p and rng virtio devices do not set a pointer for this function and subsequently SEGV.
This patch adds a dummy implementation of the function to avoid the fatal signal.
--- tools/kvm/virtio/9p.c | 7 +++++++ tools/kvm/virtio/console.c | 7 +++++++ tools/kvm/virtio/rng.c | 7 +++++++ 3 files changed, 21 insertions(+), 0 deletions(-)
tools/kvm/virtio/9p.c +7 -0
@@ -1300,6 +1300,12 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq)return VIRTQUEUE_NUM ; } +static int set_size_vq (struct kvm *kvm,void *dev,u32 vq,int size) +{ +/* FIXME: dynamic */ +return size; +} +struct virtio_ops p9_dev_virtio_ops = (struct virtio_ops ) { .get_config = get_config, .get_host_features = get_host_features,
@@ -1308,6 +1314,7 @@ struct virtio_ops p9_dev_virtio_ops = (struct virtio_ops) { .notify_vq = notify_vq, .get_pfn_vq = get_pfn_vq, .get_size_vq = get_size_vq, + .set_size_vq = set_size_vq, };int virtio_9p_rootdir_parser (const struct option *opt,const char *arg,int unset)
tools/kvm/virtio/console.c +7 -0
@@ -172,6 +172,12 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq)return VIRTIO_CONSOLE_QUEUE_SIZE ; } +static int set_size_vq (struct kvm *kvm,void *dev,u32 vq,int size) +{ +/* FIXME: dynamic */ +return size; +} +static struct virtio_ops con_dev_virtio_ops = (struct virtio_ops ) { .get_config = get_config, .get_host_features = get_host_features,
@@ -180,6 +186,7 @@ static struct virtio_ops con_dev_virtio_ops = (struct virtio_ops) { .notify_vq = notify_vq, .get_pfn_vq = get_pfn_vq, .get_size_vq = get_size_vq, + .set_size_vq = set_size_vq, };int virtio_console__init (struct kvm *kvm)
tools/kvm/virtio/rng.c +7 -0
@@ -132,6 +132,12 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq)return VIRTIO_RNG_QUEUE_SIZE ; } +static int set_size_vq (struct kvm *kvm,void *dev,u32 vq,int size) +{ +/* FIXME: dynamic */ +return size; +} +static struct virtio_ops rng_dev_virtio_ops = (struct virtio_ops ) { .get_config = get_config, .get_host_features = get_host_features,
@@ -140,6 +146,7 @@ static struct virtio_ops rng_dev_virtio_ops = (struct virtio_ops) { .notify_vq = notify_vq, .get_pfn_vq = get_pfn_vq, .get_size_vq = get_size_vq, + .set_size_vq = set_size_vq, };int virtio_rng__init (struct kvm *kvm)
Signature · 1 line
1.7.4.1
RFC PATCH 12/16 kvm tools: allow arch to specify default virtio transport
In reply to Will DeaconSome architectures may provide only a restricted PCI implementation and therefore prefer MMIO as the transport for virtio devices.
This patch allows the arch backend to specify the default virtio transport. Some devices (e.g. net) allow the transport to be overriden by the user and are left alone by this change.
--- tools/kvm/powerpc/include/kvm/kvm-arch.h | 2 ++ tools/kvm/virtio/9p.c | 3 ++- tools/kvm/virtio/balloon.c | 3 ++- tools/kvm/virtio/blk.c | 3 ++- tools/kvm/virtio/console.c | 3 ++- tools/kvm/virtio/rng.c | 3 ++- tools/kvm/virtio/scsi.c | 3 ++- tools/kvm/x86/include/kvm/kvm-arch.h | 2 ++ 8 files changed, 16 insertions(+), 6 deletions(-)
tools/kvm/powerpc/include/kvm/kvm-arch.h +2 -0
@@ -40,6 +40,8 @@#define KVM_PCI_MMIO_AREA 0x1000000#define KVM_VIRTIO_MMIO_AREA 0x2000000 +#define VIRTIO_DEFAULT_TRANS VIRTIO_PCI +struct spapr_phb ;struct kvm_arch {
tools/kvm/virtio/9p.c +2 -1
@@ -1390,7 +1390,8 @@ int virtio_9p__init(struct kvm *kvm)list_for_each_entry (p9dev, &devs, list) {virtio_init (kvm, p9dev, &p9dev->vdev, &p9_dev_virtio_ops, -VIRTIO_PCI ,PCI_DEVICE_ID_VIRTIO_9P ,VIRTIO_ID_9P ,PCI_CLASS_9P ); +VIRTIO_DEFAULT_TRANS ,PCI_DEVICE_ID_VIRTIO_9P , +VIRTIO_ID_9P ,PCI_CLASS_9P ); }return 0 ;
tools/kvm/virtio/balloon.c +2 -1
@@ -254,7 +254,8 @@ int virtio_bln__init(struct kvm *kvm)memset (&bdev.config,0 ,sizeof (struct virtio_balloon_config ));virtio_init (kvm, &bdev, &bdev.vdev, &bln_dev_virtio_ops, -VIRTIO_PCI ,PCI_DEVICE_ID_VIRTIO_BLN ,VIRTIO_ID_BALLOON ,PCI_CLASS_BLN ); +VIRTIO_DEFAULT_TRANS ,PCI_DEVICE_ID_VIRTIO_BLN , +VIRTIO_ID_BALLOON ,PCI_CLASS_BLN );if (compat_id ==-1 ) compat_id =virtio_compat_add_message ("virtio-balloon" ,"CONFIG_VIRTIO_BALLOON" );
tools/kvm/virtio/blk.c +2 -1
@@ -259,7 +259,8 @@ static int virtio_blk__init_one(struct kvm *kvm, struct disk_image *disk) };virtio_init (kvm, bdev, &bdev->vdev, &blk_dev_virtio_ops, -VIRTIO_PCI ,PCI_DEVICE_ID_VIRTIO_BLK ,VIRTIO_ID_BLOCK ,PCI_CLASS_BLK ); +VIRTIO_DEFAULT_TRANS ,PCI_DEVICE_ID_VIRTIO_BLK , +VIRTIO_ID_BLOCK ,PCI_CLASS_BLK );list_add_tail (&bdev->list, &bdevs);
tools/kvm/virtio/console.c +2 -1
@@ -195,7 +195,8 @@ int virtio_console__init(struct kvm *kvm)return 0 ;virtio_init (kvm, &cdev, &cdev.vdev, &con_dev_virtio_ops, -VIRTIO_PCI ,PCI_DEVICE_ID_VIRTIO_CONSOLE ,VIRTIO_ID_CONSOLE ,PCI_CLASS_CONSOLE ); +VIRTIO_DEFAULT_TRANS ,PCI_DEVICE_ID_VIRTIO_CONSOLE , +VIRTIO_ID_CONSOLE ,PCI_CLASS_CONSOLE );if (compat_id ==-1 ) compat_id =virtio_compat_add_message ("virtio-console" ,"CONFIG_VIRTIO_CONSOLE" );
tools/kvm/virtio/rng.c +2 -1
@@ -168,7 +168,8 @@ int virtio_rng__init(struct kvm *kvm) } r =virtio_init (kvm, rdev, &rdev->vdev, &rng_dev_virtio_ops, -VIRTIO_PCI ,PCI_DEVICE_ID_VIRTIO_RNG ,VIRTIO_ID_RNG ,PCI_CLASS_RNG ); +VIRTIO_DEFAULT_TRANS ,PCI_DEVICE_ID_VIRTIO_RNG , +VIRTIO_ID_RNG ,PCI_CLASS_RNG );if (r <0 ) goto cleanup;
tools/kvm/virtio/scsi.c +2 -1
@@ -251,7 +251,8 @@ static int virtio_scsi_init_one(struct kvm *kvm, struct disk_image *disk) sdev->target.vhost_tpgt =strtol (disk->tpgt,NULL ,0 );virtio_init (kvm, sdev, &sdev->vdev, &scsi_dev_virtio_ops, -VIRTIO_PCI ,PCI_DEVICE_ID_VIRTIO_SCSI ,VIRTIO_ID_SCSI ,PCI_CLASS_BLK ); +VIRTIO_DEFAULT_TRANS ,PCI_DEVICE_ID_VIRTIO_SCSI , +VIRTIO_ID_SCSI ,PCI_CLASS_BLK );list_add_tail (&sdev->list, &sdevs);
tools/kvm/x86/include/kvm/kvm-arch.h +2 -0
@@ -23,6 +23,8 @@#define KVM_PCI_MMIO_AREA (KVM_MMIO_START + 0x1000000)#define KVM_VIRTIO_MMIO_AREA (KVM_MMIO_START + 0x2000000) +#define VIRTIO_DEFAULT_TRANS VIRTIO_PCI +struct kvm_arch {u16 boot_selector;u16 boot_ip;
Signature · 1 line
1.7.4.1
RFC PATCH 13/16 kvm tools: keep track of registered memory banks in struct kvm
In reply to Will DeaconWhen registering memory banks for a guest, it is useful to keep the range information around for translating between guest and host address spaces.
This patch adds a list of kvm_mem_bank structures to struct kvm, which is updated when a new bank is registered.
--- tools/kvm/include/kvm/kvm.h | 8 ++++++++ tools/kvm/kvm.c | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletions(-)
tools/kvm/include/kvm/kvm.h +8 -0
@@ -35,6 +35,13 @@ struct kvm_ext {int code; }; +struct kvm_mem_bank { +struct list_head list; +unsigned long guest_phys_addr; +void *host_addr; +unsigned long size; +}; +struct kvm {struct kvm_arch arch;struct kvm_config cfg;
@@ -49,6 +56,7 @@ struct kvm {u64 ram_size;void *ram_start;u64 ram_pagesize; +struct list_head mem_banks;bool nmi_disabled;
tools/kvm/kvm.c +22 -1
@@ -6,7 +6,9 @@#include "kvm/kvm-cpu.h" #include "kvm/kvm-ipc.h" +#include <linux/kernel.h> #include <linux/kvm.h> +#include <linux/list.h> #include <linux/err.h> #include <sys/un.h>
@@ -133,9 +135,16 @@ struct kvm *kvm__new(void)int kvm__exit (struct kvm *kvm) { +struct kvm_mem_bank *bank, *tmp; +kvm__arch_delete_ram (kvm); -free (kvm); +list_for_each_entry_safe (bank, tmp, &kvm->mem_banks, list) { +list_del (&bank->list); +free (bank); + } + +free (kvm);return 0 ; }core_exit (kvm__exit);
@@ -148,8 +157,18 @@ core_exit(kvm__exit);int kvm__register_mem (struct kvm *kvm,u64 guest_phys,u64 size,void *userspace_addr) {struct kvm_userspace_memory_region mem; +struct kvm_mem_bank *bank;int ret; + bank =malloc (sizeof (*bank)); +if (!bank) +return -ENOMEM ; + +INIT_LIST_HEAD (&bank->list); + bank->guest_phys_addr = guest_phys; + bank->host_addr = userspace_addr; + bank->size = size; + mem = (struct kvm_userspace_memory_region ) { .slot = kvm->mem_slots++, .guest_phys_addr = guest_phys,
@@ -161,6 +180,7 @@ int kvm__register_mem(struct kvm *kvm, u64 guest_phys, u64 size, void *userspaceif (ret <0 )return -errno; +list_add (&bank->list, &kvm->mem_banks);return 0 ; }
@@ -245,6 +265,7 @@ int kvm__init(struct kvm *kvm)kvm__arch_init (kvm, kvm->cfg.hugetlbfs_path, kvm->cfg.ram_size); +INIT_LIST_HEAD (&kvm->mem_banks);kvm__init_ram (kvm);if (!kvm->cfg.firmware_filename) {
Signature · 1 line
1.7.4.1
Re: [RFC PATCH 13/16] kvm tools: keep track of registered memory banks in struct kvm
Quoted 18 lines · Will Deacon
When registering memory banks for a guest, it is useful to keep the range information around for translating between guest and host address spaces.
This patch adds a list of
kvm_mem_bankstructures to struct kvm, which is updated when a new bank is registered.Signed-off-by Will Deacon <[email protected]>--- tools/kvm/include/kvm/kvm.h | 8 ++++++++ tools/kvm/kvm.c | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletions(-)tools/kvm/include/kvm/kvm.h +0
-0
tools/kvm/include/kvm/kvm.h struct kvm_ext { · line 43
Quoted 9 lines
tools/kvm/include/kvm/kvm.h +6
-0@@ -35,6 +35,13 @@ struct kvm_ext {int code; }; +struct kvm_mem_bank { +struct list_head list; +unsigned long guest_phys_addr; +void *host_addr; +unsigned long size; +};
Can we just reuse struct kvm_userspace_memory_region here? We're also using different data types for guest_phys_addr and size than whats in kvm_userspace_memory_region - that can't be good.
tools/kvm/include/kvm/kvm.h struct kvm { · line 59
Quoted 8 lines
tools/kvm/include/kvm/kvm.h +1
-0struct kvm {struct kvm_arch arch;struct kvm_config cfg;@@ -49,6 +56,7 @@ struct kvm {u64 ram_size;void *ram_start;u64 ram_pagesize; +struct list_head mem_banks;
These memory banks actually look like a perfect example to use our augmented interval rb-tree, can we switch them to use it, or is it a list on purpose?
Thanks,
Sasha
Re: [RFC PATCH 13/16] kvm tools: keep track of registered memory banks in struct kvm
Quoted 11 lines · Sasha Levin
tools/kvm/include/kvm/kvm.h struct kvm_ext { · line 43
Quoted 6 lines · Will Deacon
tools/kvm/include/kvm/kvm.h +6
-0+struct kvm_mem_bank { +struct list_head list; +unsigned long guest_phys_addr; +void *host_addr; +unsigned long size; +};Can we just reuse struct
kvm_userspace_memory_regionhere? We're also using different data types forguest_phys_addrand size than whats inkvm_userspace_memory_region- that can't be good.
I looked briefly at doing that when I wrote the multi-bank stuff, but I hit a couple of issues:
- kvmtool itself tends to use void * for host addresses, rather than the __u64 userspace_addr in kvm_userspace_memory_region
- kvm_userspace_memory_region is a superset of what we need (not the end of the world I guess)
so you end up casting address types a fair amount. Still, I'll revisit it and see if I can come up with something cleaner.
Quoted 11 lines
tools/kvm/include/kvm/kvm.h struct kvm { · line 59
Quoted 8 lines
struct kvm {
tools/kvm/include/kvm/kvm.h +1
-0struct kvm_arch arch;struct kvm_config cfg;@@ -49,6 +56,7 @@ struct kvm {u64 ram_size;void *ram_start;u64 ram_pagesize; +struct list_head mem_banks;These memory banks actually look like a perfect example to use our augmented interval rb-tree, can we switch them to use it, or is it a list on purpose?
Well, the usual case is one memory bank but that doesn't swing the argument either way. I'll update to use the fancy new tree.
Thanks for the comments,
Will
Re: [RFC PATCH 13/16] kvm tools: keep track of registered memory banks in struct kvm
Quoted 16 lines · Will Deacon
Quoted 11 lines · Sasha Levin
tools/kvm/include/kvm/kvm.h struct kvm_ext { · line 43
Quoted 6 lines · Will Deacon
tools/kvm/include/kvm/kvm.h +6
-0+struct kvm_mem_bank { +struct list_head list; +unsigned long guest_phys_addr; +void *host_addr; +unsigned long size; +};Can we just reuse struct
kvm_userspace_memory_regionhere? We're also using different data types forguest_phys_addrand size than whats inkvm_userspace_memory_region- that can't be good.I looked briefly at doing that when I wrote the multi-bank stuff, but I hit a couple of issues:
Quoted 8 lines
- kvmtool itself tends to use void * for host addresses, rather than the
__u64userspace_addrinkvm_userspace_memory_region-
kvm_userspace_memory_regionis a superset of what we need (not the end of the world I guess)so you end up casting address types a fair amount. Still, I'll revisit it and see if I can come up with something cleaner.
That's a good point. We used void* while the kernel side is using u64, which looks odd.
In that case, let's get everything moved to u64 (obviously not in the scope of this patch series).
Thanks,
Sasha
Re: [RFC PATCH 13/16] kvm tools: keep track of registered memory banks in struct kvm
Quoted 23 lines · Sasha Levin
Quoted 22 lines · Will Deacon
Quoted 11 lines · Sasha Levin
tools/kvm/include/kvm/kvm.h struct kvm_ext { · line 43
Quoted 6 lines · Will Deacon
tools/kvm/include/kvm/kvm.h +6
-0+struct kvm_mem_bank { +struct list_head list; +unsigned long guest_phys_addr; +void *host_addr; +unsigned long size; +};Can we just reuse struct
kvm_userspace_memory_regionhere? We're also using different data types forguest_phys_addrand size than whats inkvm_userspace_memory_region- that can't be good.I looked briefly at doing that when I wrote the multi-bank stuff, but I hit a couple of issues:
- kvmtool itself tends to use void * for host addresses, rather than the
__u64userspace_addrinkvm_userspace_memory_region-
kvm_userspace_memory_regionis a superset of what we need (not the end of the world I guess)
Quoted 8 lines
Quoted 2 lines
so you end up casting address types a fair amount. Still, I'll revisit it and see if I can come up with something cleaner.
That's a good point. We used void* while the kernel side is using u64, which looks odd.
In that case, let's get everything moved to u64 (obviously not in the scope of this patch series).
Ok, I'll update the size field to match in this patch series, then we can tackle the address discrepancy separately.
Cheers,
Will
Re: [RFC PATCH 13/16] kvm tools: keep track of registered memory banks in struct kvm
In reply to Sasha LevinHi Sasha,
Quoted 12 lines · Sasha Levin
tools/kvm/include/kvm/kvm.h struct kvm { · line 59
Quoted 8 lines · Will Deacon
struct kvm {
tools/kvm/include/kvm/kvm.h +1
-0struct kvm_arch arch;struct kvm_config cfg;@@ -49,6 +56,7 @@ struct kvm {u64 ram_size;void *ram_start;u64 ram_pagesize; +struct list_head mem_banks;These memory banks actually look like a perfect example to use our augmented interval rb-tree, can we switch them to use it, or is it a list on purpose?
I found some time to look at this today but unfortunately they're not as ideally suited to the interval tree as they look: the problem being that we need to search for banks by both host virtual address *and* guest physical address depending on the translation that we're doing.
We could have two separate tress, but that seems like overkill given the likely number of banks.
Will
Re: [RFC PATCH 13/16] kvm tools: keep track of registered memory banks in struct kvm
Quoted 16 lines · Will Deacon
Hi Sasha,
Quoted 12 lines · Sasha Levin
tools/kvm/include/kvm/kvm.h struct kvm { · line 59
Quoted 8 lines · Will Deacon
struct kvm {
tools/kvm/include/kvm/kvm.h +1
-0struct kvm_arch arch;struct kvm_config cfg;@@ -49,6 +56,7 @@ struct kvm {u64 ram_size;void *ram_start;u64 ram_pagesize; +struct list_head mem_banks;These memory banks actually look like a perfect example to use our augmented interval rb-tree, can we switch them to use it, or is it a list on purpose?
Quoted 7 lines
I found some time to look at this today but unfortunately they're not as ideally suited to the interval tree as they look: the problem being that we need to search for banks by both host virtual address *and* guest physical address depending on the translation that we're doing.
We could have two separate tress, but that seems like overkill given the likely number of banks.
Makes sense. We can convert it later if we need to as well.
Thanks,
Sasha
RFC PATCH 14/16 kvm tools: teach guest_flat_to_host about memory banks starting above 0
In reply to Will DeaconRunning a guest with multiple banks of memory based above 0 causes the guest_flat_to_host address conversion to fail, as it is assumed that guest memory addresses are offset linearly from 0.
This patch changes the translation function so that the kvm_mem_bank structures registered by kvm__register_mem are used to translate guest addresses, rather than use an offset from the start of host memory.
--- tools/kvm/include/kvm/kvm.h | 7 ++----- tools/kvm/kvm.c | 16 ++++++++++++++++ tools/kvm/x86/include/kvm/kvm-arch.h | 9 --------- tools/kvm/x86/kvm.c | 7 +++++++ 4 files changed, 25 insertions(+), 14 deletions(-)
tools/kvm/include/kvm/kvm.h +2 -5
@@ -105,6 +105,8 @@ int kvm__arch_free_firmware(struct kvm *kvm);bool kvm__arch_cpu_supports_vm (void );void kvm__arch_periodic_poll (struct kvm *kvm); +void *guest_flat_to_host (struct kvm *kvm,unsigned long offset); +int load_flat_binary (struct kvm *kvm,int fd_kernel,int fd_initrd,const char *kernel_cmdline);bool load_bzimage (struct kvm *kvm,int fd_kernel,int fd_initrd,const char *kernel_cmdline,u16 vidmode);
@@ -120,11 +122,6 @@ static inline bool host_ptr_in_ram(struct kvm *kvm, void *p)return kvm->ram_start <= p && p < (kvm->ram_start + kvm->ram_size); } -static inline void *guest_flat_to_host (struct kvm *kvm,unsigned long offset) -{ -return kvm->ram_start + offset; -} -bool kvm__supports_extension (struct kvm *kvm,unsigned int extension);static inline void kvm__set_thread_name (const char *name)
tools/kvm/kvm.c +16 -0
@@ -184,6 +184,22 @@ int kvm__register_mem(struct kvm *kvm, u64 guest_phys, u64 size, void *userspacereturn 0 ; } +void *guest_flat_to_host (struct kvm *kvm,unsigned long offset) +{ +struct kvm_mem_bank *bank; + +list_for_each_entry (bank, &kvm->mem_banks, list) { +unsigned long bank_start = bank->guest_phys_addr; +unsigned long bank_end = bank_start + bank->size; + +if (offset >= bank_start && offset < bank_end) +return bank->host_addr + (offset - bank_start); + } + +pr_warning ("unable to translate guest address 0x%lx to host" , offset); +return NULL ; +} +int kvm__recommended_cpus (struct kvm *kvm) {int ret;
tools/kvm/x86/include/kvm/kvm-arch.h +0 -9
@@ -33,13 +33,4 @@ struct kvm_arch { struct interrupt_table interrupt_table; }; -static inline void *guest_flat_to_host (struct kvm *kvm,unsigned long offset);/* In kvm.h */ - -static inline void *guest_real_to_host (struct kvm *kvm,u16 selector,u16 offset) -{ -unsigned long flat =segment_to_flat (selector, offset); - -return guest_flat_to_host (kvm, flat); -} -#endif /* KVM__KVM_ARCH_H */
tools/kvm/x86/kvm.c +7 -0
@@ -199,6 +199,13 @@ void kvm__irq_trigger(struct kvm *kvm, int irq)#define BOOT_PROTOCOL_REQUIRED 0x206#define LOAD_HIGH 0x01 +static inline void *guest_real_to_host (struct kvm *kvm,u16 selector,u16 offset) +{ +unsigned long flat =segment_to_flat (selector, offset); + +return guest_flat_to_host (kvm, flat); +} +int load_flat_binary (struct kvm *kvm,int fd_kernel,int fd_initrd,const char *kernel_cmdline) {void *p;
Signature · 1 line
1.7.4.1
Re: [RFC PATCH 14/16] kvm tools: teach guest_flat_to_host about memory banks starting above 0
Quoted 10 lines · Will Deacon
Running a guest with multiple banks of memory based above 0 causes the
guest_flat_to_hostaddress conversion to fail, as it is assumed that guest memory addresses are offset linearly from 0.This patch changes the translation function so that the
kvm_mem_bankstructures registered bykvm__register_memare used to translate guest addresses, rather than use an offset from the start of host memory.Signed-off-by Will Deacon <[email protected]>---
Hmm... we probably need something to teach E820 about this new memory layout thingie if we start mapping multiple memory banks.
Not urgent for now though - I guess.
Thanks,
Sasha
RFC PATCH 15/16 kvm tools: provide a mechanism for translating host to guest addresses
In reply to Will DeaconWhen generating a device tree for a guest, it is useful to have a helper for converting host addresses to guest addresses in order to populate the device nodes correctly.
This patch adds such a helper, following a similar implementation to the reverse translation function that already exists.
--- tools/kvm/include/kvm/kvm.h | 1 + tools/kvm/kvm.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-)
tools/kvm/include/kvm/kvm.h +1 -0
@@ -106,6 +106,7 @@ bool kvm__arch_cpu_supports_vm(void);void kvm__arch_periodic_poll (struct kvm *kvm);void *guest_flat_to_host (struct kvm *kvm,unsigned long offset); +unsigned long host_to_guest_flat (struct kvm *kvm,void *ptr);int load_flat_binary (struct kvm *kvm,int fd_kernel,int fd_initrd,const char *kernel_cmdline);bool load_bzimage (struct kvm *kvm,int fd_kernel,int fd_initrd,const char *kernel_cmdline,u16 vidmode);
tools/kvm/kvm.c +16 -0
@@ -200,6 +200,22 @@ void *guest_flat_to_host(struct kvm *kvm, unsigned long offset)return NULL ; } +unsigned long host_to_guest_flat (struct kvm *kvm,void *ptr) +{ +struct kvm_mem_bank *bank; + +list_for_each_entry (bank, &kvm->mem_banks, list) { +void *bank_start = bank->host_addr; +void *bank_end = bank_start + bank->size; + +if (ptr >= bank_start && ptr < bank_end) +return bank->guest_phys_addr + (ptr - bank_start); + } + +pr_warning ("unable to translate host address %p to guest" , ptr); +return 0 ; +} +int kvm__recommended_cpus (struct kvm *kvm) {int ret;
Signature · 1 line
1.7.4.1
RFC PATCH 16/16 kvm tools: add support for ARMv7 processors
In reply to Will DeaconThis patch adds initial support for ARMv7 processors (more specifically, Cortex-A15) to kvmtool.
Everything is driven by FDT, including dynamic generation of virtio nodes for MMIO devices (PCI is not used due to lack of a suitable host-bridge).
The virtual timers and virtual interrupt controller (VGIC) are provided by the kernel and require very little in terms of userspace code.
--- tools/kvm/Makefile | 20 ++- tools/kvm/arm/aarch32/cortex-a15.c | 98 ++++++++++ tools/kvm/arm/aarch32/include/kvm/barrier.h | 10 + tools/kvm/arm/aarch32/include/kvm/kvm-arch.h | 28 +++ tools/kvm/arm/aarch32/kvm-cpu.c | 111 +++++++++++ tools/kvm/arm/aarch32/smp-pen.S | 14 ++ tools/kvm/arm/fdt.c | 269 ++++++++++++++++++++++++++ tools/kvm/arm/gic.c | 86 ++++++++ tools/kvm/arm/include/arm-common/gic.h | 29 +++ tools/kvm/arm/include/arm-common/kvm-arch.h | 31 +++ tools/kvm/arm/include/arm-common/smp.h | 7 + tools/kvm/arm/include/kvm/kvm-cpu-arch.h | 47 +++++ tools/kvm/arm/ioport.c | 5 + tools/kvm/arm/irq.c | 25 +++ tools/kvm/arm/kvm-cpu.c | 112 +++++++++++ tools/kvm/arm/kvm.c | 69 +++++++ tools/kvm/arm/smp.c | 13 ++ 17 files changed, 973 insertions(+), 1 deletions(-) create mode 100644 tools/kvm/arm/aarch32/cortex-a15.c create mode 100644 tools/kvm/arm/aarch32/include/kvm/barrier.h create mode 100644 tools/kvm/arm/aarch32/include/kvm/kvm-arch.h create mode 100644 tools/kvm/arm/aarch32/kvm-cpu.c create mode 100644 tools/kvm/arm/aarch32/smp-pen.S create mode 100644 tools/kvm/arm/fdt.c create mode 100644 tools/kvm/arm/gic.c create mode 100644 tools/kvm/arm/include/arm-common/gic.h create mode 100644 tools/kvm/arm/include/arm-common/kvm-arch.h create mode 100644 tools/kvm/arm/include/arm-common/smp.h create mode 100644 tools/kvm/arm/include/kvm/kvm-cpu-arch.h create mode 100644 tools/kvm/arm/ioport.c create mode 100644 tools/kvm/arm/irq.c create mode 100644 tools/kvm/arm/kvm-cpu.c create mode 100644 tools/kvm/arm/kvm.c create mode 100644 tools/kvm/arm/smp.c
tools/kvm/Makefile +19 -1
@@ -102,7 +102,8 @@ OBJS += builtin-sandbox.o OBJS += virtio/mmio.o # Translate uname -m into ARCH string -ARCH ?= $(shell uname -m | sed -e s/i.86/i386/ -e s/ppc.*/powerpc/) +ARCH ?= $(shell uname -m | sed -e s/i.86/i386/ -e s/ppc.*/powerpc/ \ + -e s/armv7.*/arm/) ifeq ($(ARCH),i386) ARCH := x86
@@ -157,6 +158,23 @@ ifeq ($(ARCH), powerpc) CFLAGS += -m64 endif +# ARM +OBJS_ARM_COMMON := arm/fdt.o arm/gic.o arm/ioport.o arm/irq.o \ + arm/kvm.o arm/kvm-cpu.o arm/smp.o +HDRS_ARM_COMMON := arm/include +ifeq ($(ARCH), arm) + DEFINES += -DCONFIG_ARM + OBJS += $(OBJS_ARM_COMMON) + OBJS += arm/aarch32/cortex-a15.o + OBJS += arm/aarch32/kvm-cpu.o + OTHEROBJS += arm/aarch32/smp-pen.o + ARCH_INCLUDE := $(HDRS_ARM_COMMON) + ARCH_INCLUDE += -Iarm/aarch32/include + CFLAGS += -march=armv7-a + CFLAGS += -I../../scripts/dtc/libfdt + OTHEROBJS += $(LIBFDT_OBJS) +endif + ### ifeq (,$(ARCH_INCLUDE))
tools/kvm/arm/aarch32/cortex-a15.c new file +98 -0
98 lines not on this page · raw message
tools/kvm/arm/aarch32/include/kvm/barrier.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef KVM__KVM_BARRIER_H +#define KVM__KVM_BARRIER_H + +#define dmb () asm volatile ("dmb" : : : "memory") + +#define mb () dmb() +#define rmb () dmb() +#define wmb () dmb() + +#endif
tools/kvm/arm/aarch32/include/kvm/kvm-arch.h new file +28 -0
@@ -0,0 +1,28 @@ +#ifndef KVM__KVM_ARCH_H +#define KVM__KVM_ARCH_H + +#define ARM_LOMAP_MMIO_AREA 0x00000000UL +#define ARM_LOMAP_AXI_AREA 0x40000000UL +#define ARM_LOMAP_MEMORY_AREA 0x80000000UL +#define ARM_LOMAP_MAX_MEMORY 0x7ffff000UL + +#define ARM_GIC_DIST_SIZE 0x1000 +#define ARM_GIC_DIST_BASE (ARM_LOMAP_AXI_AREA - ARM_GIC_DIST_SIZE) +#define ARM_GIC_CPUI_SIZE 0x2000 +#define ARM_GIC_CPUI_BASE (ARM_GIC_DIST_BASE - ARM_GIC_CPUI_SIZE) + +#define ARM_KERN_OFFSET 0x8000 + +#define ARM_SMP_PEN_SIZE PAGE_SIZE +#define ARM_VIRTIO_MMIO_SIZE (ARM_GIC_DIST_BASE - ARM_LOMAP_MMIO_AREA) +#define ARM_PCI_MMIO_SIZE (ARM_LOMAP_MEMORY_AREA - ARM_LOMAP_AXI_AREA) + +#define ARM_MEMORY_AREA ARM_LOMAP_MEMORY_AREA +#define ARM_MAX_MEMORY ARM_LOMAP_MAX_MEMORY + +#define KVM_PCI_MMIO_AREA ARM_LOMAP_AXI_AREA +#define KVM_VIRTIO_MMIO_AREA ARM_LOMAP_MMIO_AREA + +#include "arm-common/kvm-arch.h" + +#endif
tools/kvm/arm/aarch32/kvm-cpu.c new file +111 -0
111 lines not on this page · raw message
tools/kvm/arm/aarch32/smp-pen.S new file +14 -0
@@ -0,0 +1,14 @@ + .arm + .globl smp_pen_start + .globl smp_pen_end + .globl smp_jump_addr + .align +smp_pen_start: + adr r0, smp_jump_addr + wfi + ldr r1, [r0] + mov pc, r1 + .align +smp_jump_addr: + .long 0xdeadc0de +smp_pen_end:
tools/kvm/arm/fdt.c new file +269 -0
269 lines not on this page · raw message
tools/kvm/arm/gic.c new file +86 -0
86 lines not on this page · raw message
tools/kvm/arm/include/arm-common/gic.h new file +29 -0
@@ -0,0 +1,29 @@ +#ifndef ARM_COMMON__GIC_H +#define ARM_COMMON__GIC_H + +#define GIC_SGI_IRQ_BASE 0 +#define GIC_PPI_IRQ_BASE 16 +#define GIC_SPI_IRQ_BASE 32 + +#define GIC_FDT_IRQ_NUM_CELLS 3 + +#define GIC_FDT_IRQ_TYPE_SPI 0 +#define GIC_FDT_IRQ_TYPE_PPI 1 + +#define GIC_FDT_IRQ_FLAGS_EDGE_LO_HI 1 +#define GIC_FDT_IRQ_FLAGS_EDGE_HI_LO 2 +#define GIC_FDT_IRQ_FLAGS_LEVEL_HI 4 +#define GIC_FDT_IRQ_FLAGS_LEVEL_LO 8 + +#define GIC_FDT_IRQ_PPI_CPU_SHIFT 8 +#define GIC_FDT_IRQ_PPI_CPU_MASK (0xff << GIC_FDT_IRQ_PPI_CPU_SHIFT) + +#define KVM_MAX_IRQ 255 + +struct kvm ; + +int gic__alloc_irqnum (void ); +int gic__init_irqchip (struct kvm *kvm); +void gic__generate_fdt_nodes (void *fdt,u32 phandle); + +#endif /* ARM_COMMON__GIC_H */
tools/kvm/arm/include/arm-common/kvm-arch.h new file +31 -0
@@ -0,0 +1,31 @@ +#ifndef ARM_COMMON__KVM_ARCH_H +#define ARM_COMMON__KVM_ARCH_H + +#include <stdbool.h> +#include <linux/types.h> + +#define VIRTIO_DEFAULT_TRANS VIRTIO_MMIO + +static inline bool arm_addr_in_virtio_mmio_region (u64 phys_addr) +{ +u64 limit =KVM_VIRTIO_MMIO_AREA +ARM_VIRTIO_MMIO_SIZE ; +return phys_addr >=KVM_VIRTIO_MMIO_AREA && phys_addr < limit; +} + +static inline bool arm_addr_in_pci_mmio_region (u64 phys_addr) +{ +u64 limit =KVM_PCI_MMIO_AREA +ARM_PCI_MMIO_SIZE ; +return phys_addr >=KVM_PCI_MMIO_AREA && phys_addr < limit; +} + +struct kvm_arch { +unsigned long memory_guest_start; +unsigned long kern_guest_start; +unsigned long initrd_guest_start; +unsigned long initrd_size; +unsigned long dtb_guest_start; +unsigned long smp_pen_guest_start; +unsigned long smp_jump_guest_start; +}; + +#endif /* ARM_COMMON__KVM_ARCH_H */
tools/kvm/arm/include/arm-common/smp.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef ARM_COMMON__SMP_H +#define ARM_COMMON__SMP_H + +extern u8 smp_pen_start, smp_pen_end, smp_jump_addr; +void smp_pen_init (struct kvm *kvm); + +#endif /* ARM_COMMON__SMP_H */
tools/kvm/arm/include/kvm/kvm-cpu-arch.h new file +47 -0
47 lines not on this page · raw message
tools/kvm/arm/ioport.c new file +5 -0
@@ -0,0 +1,5 @@ +#include "kvm/ioport.h" + +void ioport__setup_arch (struct kvm *kvm) +{ +}
tools/kvm/arm/irq.c new file +25 -0
@@ -0,0 +1,25 @@ +#include "kvm/devices.h" +#include "kvm/irq.h" +#include "kvm/kvm.h" +#include "kvm/util.h" + +#include "arm-common/gic.h" + +static int device_ids; + +int irq__register_device (u32 dev,u8 *num,u8 *pin,u8 *line) +{ +if (device_ids >=KVM_MAX_DEVICES ) +die ("Device limit %d reached!" ,KVM_MAX_DEVICES ); + + *num = device_ids++; + *line =gic__alloc_irqnum (); + +return 0 ; +} + +int irq__add_msix_route (struct kvm *kvm,struct msi_msg *msg) +{ +die (__FUNCTION__); +return 0 ; +}
tools/kvm/arm/kvm-cpu.c new file +112 -0
112 lines not on this page · raw message
tools/kvm/arm/kvm.c new file +69 -0
69 lines not on this page · raw message
tools/kvm/arm/smp.c new file +13 -0
@@ -0,0 +1,13 @@ +#include "kvm/kvm.h" + +#include "arm-common/smp.h" + +void smp_pen_init (struct kvm *kvm) +{ +unsigned long pen_size = &smp_pen_end - &smp_pen_start; +unsigned long pen_start = kvm->arch.smp_pen_guest_start; +unsigned long jump_offset = &smp_jump_addr - &smp_pen_start; + + kvm->arch.smp_jump_guest_start = pen_start + jump_offset; +memcpy (guest_flat_to_host (kvm, pen_start), &smp_pen_start, pen_size); +}
Signature · 1 line
1.7.4.1
Quoted 10 lines · Will Deacon
This patch adds initial support for ARMv7 processors (more specifically, Cortex-A15) to kvmtool.
Everything is driven by FDT, including dynamic generation of virtio nodes for MMIO devices (PCI is not used due to lack of a suitable host-bridge).
The virtual timers and virtual interrupt controller (VGIC) are provided by the kernel and require very little in terms of userspace code.
Signed-off-by Will Deacon <[email protected]>
I'm happy with this but I'm not really an ARM guy. Is there anyone in the ARM/KVM community who is interested in reviewing this?
Pekka
Matt Evans
Acked-byHi Pekka,
Quoted 11 lines · On 13 November 2012 07:40 Pekka Enberg wrote:
Quoted 1 line · Will Deacon
This patch adds initial support for ARMv7 processors (more
specifically,
Quoted 3 lines
Cortex-A15) to kvmtool.
Everything is driven by FDT, including dynamic generation of virtio
nodes
Quoted 1 line
for MMIO devices (PCI is not used due to lack of a suitable host-
bridge).
Quoted 2 lines
The virtual timers and virtual interrupt controller (VGIC) are
Quoted 8 lines
provided
Quoted 3 lines
by the kernel and require very little in terms of userspace code.
Signed-off-by Will Deacon <[email protected]>I'm happy with this but I'm not really an ARM guy. Is there anyone in the
ARM/KVM community who is interested in reviewing this?
For the sake of transparency, I sent some minor feedback to Will off-list so that my (Outlook >:( ) broken linewraps & legal autoappend signature (see above and below) wouldn't pollute the thread on-list. He'll use my IMAP address next time. ;-)
I *think* Will was going to make some small changes, if you've already merged it then a follow-up set perhaps?
(Modulo minor changes,
)
Cheers,
Matt
-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Quoted 1 line · Matt Evans
I *think* Will was going to make some small changes, if you've already merged it then a follow-up set perhaps?
I only merged the non-ARM specific changes which looked good to me. But sure, please send an incremental patch if you need to fix them up, Will.
Quoted 6 lines · Pekka Enberg
Quoted 1 line · Matt Evans
I *think* Will was going to make some small changes, if you've already merged it then a follow-up set perhaps?
I only merged the non-ARM specific changes which looked good to me. But sure, please send an incremental patch if you need to fix them up, Will.
Thanks Pekka! The patches you merged are all fine, so I'll send a v2 against kvmtool master when I've updated the remaining patches to incorporate comments from Sasha and Matt. I also need to investigate the build failure you saw, because I've not managed to reproduce it myself.
Will
Quoted 7 lines · Will Deacon
Hello,
This patch series adds support for ARMv7 processors (Cortex-A15) to kvm tool. The majority of the series consists of small changes in preparation for ARM support, which is added by the final patch. I can try to split this up further, but given that there is no current support for ARM, the sub-patches wouldn't be especially meaningful.
Very cool, looking forward to trying it out!
Would have been very nice if you had sent it to
[email protected] as well.
Quoted 8 lines
To boot a guest, you will need:
- A Cortex-A15 platform with a kvm-capable bootloader
- The latest kvm-arm patches:
git://github.com/virtualopensystems/linux-kvm-arm.gitkvm-arm-master
- A guest kernel configured for our virtual target:
git://git.kernel.org/pub/scm/linux/kernel/git/will/kvmtool.gitkvm/mach-virt
newest as in v4 from this weekend or before the weekend? There were some (hopefully final) API breakage in there.
Quoted 97 lines
I'm also working on an ARMv8 (AArch64) port which fits neatly into the code presented here.
All feedback welcome,
Will
Will Deacon (16):
kvm tools: include arch uapi/asm directories in include path kvm tools: only enable LTO if supported by GCC
kvm tools: avoid linking dynamically against libbfd
kvm tools: specify compiler by name when overriding make default kvm tools: don't bother includinglinux/compiler.h
kvm tools: don't pass -Wcast-align to the compiler
kvm tools: die ifinit_list__initreturns failure
kvm tools: add generic device registration mechanism
kvm tools: make_FDTmacro usable by other architectures kvm tools: virtio-mmio: usesubsys_idinstead of pci device ID kvm tools: virtio: add dummyset_size_vqimplementations kvm tools: allow arch to specify default virtio transport kvm tools: keep track of registered memory banks in struct kvm kvm tools: teachguest_flat_to_hostabout memory banks starting above0kvm tools: provide a mechanism for translating host to guest
addresses
kvm tools: add support for ARMv7 processorstools/kvm/Makefile | 38 +++- tools/kvm/arm/aarch32/cortex-a15.c | 98 ++++++++++ tools/kvm/arm/aarch32/include/kvm/barrier.h | 10 + tools/kvm/arm/aarch32/include/kvm/kvm-arch.h | 28 +++ tools/kvm/arm/aarch32/kvm-cpu.c | 111 +++++++++++ tools/kvm/arm/aarch32/smp-pen.S | 14 ++ tools/kvm/arm/fdt.c | 269 ++++++++++++++++++++++++++ tools/kvm/arm/gic.c | 86 ++++++++ tools/kvm/arm/include/arm-common/gic.h | 29 +++ tools/kvm/arm/include/arm-common/kvm-arch.h | 31 +++ tools/kvm/arm/include/arm-common/smp.h | 7 + tools/kvm/arm/include/kvm/kvm-cpu-arch.h | 47 +++++ tools/kvm/arm/ioport.c | 5 + tools/kvm/arm/irq.c | 25 +++ tools/kvm/arm/kvm-cpu.c | 112 +++++++++++ tools/kvm/arm/kvm.c | 69 +++++++ tools/kvm/arm/smp.c | 13 ++ tools/kvm/builtin-run.c | 3 +- tools/kvm/devices.c | 24 +++ tools/kvm/hw/pci-shmem.c | 8 +- tools/kvm/hw/vesa.c | 8 +- tools/kvm/include/kvm/devices.h | 21 ++ tools/kvm/include/kvm/fdt.h | 26 +++ tools/kvm/include/kvm/kvm.h | 16 +- tools/kvm/include/kvm/pci.h | 2 - tools/kvm/include/kvm/virtio-mmio.h | 1 + tools/kvm/include/kvm/virtio-pci.h | 2 + tools/kvm/include/linux/stddef.h | 6 - tools/kvm/kvm.c | 55 +++++- tools/kvm/pci.c | 40 ++--- tools/kvm/powerpc/include/kvm/kvm-arch.h | 13 +- tools/kvm/powerpc/irq.c | 3 +- tools/kvm/powerpc/kvm.c | 2 +- tools/kvm/powerpc/spapr_pci.c | 4 +- tools/kvm/virtio/9p.c | 10 +- tools/kvm/virtio/balloon.c | 3 +- tools/kvm/virtio/blk.c | 3 +- tools/kvm/virtio/console.c | 10 +- tools/kvm/virtio/mmio.c | 9 +- tools/kvm/virtio/pci.c | 7 +- tools/kvm/virtio/rng.c | 10 +- tools/kvm/virtio/scsi.c | 3 +- tools/kvm/x86/include/kvm/kvm-arch.h | 11 +- tools/kvm/x86/kvm.c | 7 + 44 files changed, 1214 insertions(+), 85 deletions(-) create mode 100644 tools/kvm/arm/aarch32/cortex-a15.c create mode 100644 tools/kvm/arm/aarch32/include/kvm/barrier.h create mode 100644 tools/kvm/arm/aarch32/include/kvm/kvm-arch.h create mode 100644 tools/kvm/arm/aarch32/kvm-cpu.c create mode 100644 tools/kvm/arm/aarch32/smp-pen.S create mode 100644 tools/kvm/arm/fdt.c create mode 100644 tools/kvm/arm/gic.c create mode 100644 tools/kvm/arm/include/arm-common/gic.h create mode 100644 tools/kvm/arm/include/arm-common/kvm-arch.h create mode 100644 tools/kvm/arm/include/arm-common/smp.h create mode 100644 tools/kvm/arm/include/kvm/kvm-cpu-arch.h create mode 100644 tools/kvm/arm/ioport.c create mode 100644 tools/kvm/arm/irq.c create mode 100644 tools/kvm/arm/kvm-cpu.c create mode 100644 tools/kvm/arm/kvm.c create mode 100644 tools/kvm/arm/smp.c create mode 100644 tools/kvm/devices.c create mode 100644 tools/kvm/include/kvm/devices.h create mode 100644 tools/kvm/include/kvm/fdt.h--
1.7.4.1
Hi Christoffer,
Quoted 10 lines · Christoffer Dall
Quoted 7 lines · Will Deacon
Hello,
This patch series adds support for ARMv7 processors (Cortex-A15) to kvm tool. The majority of the series consists of small changes in preparation for ARM support, which is added by the final patch. I can try to split this up further, but given that there is no current support for ARM, the sub-patches wouldn't be especially meaningful.
Very cool, looking forward to trying it out!
Great -- please let me know if/when it explodes...
Quoted 2 lines
Would have been very nice if you had sent it to
[email protected] as well.
Sorry, will include that on CC for future submissions (obviously didn't appear in the get_maintainers.pl output).
Quoted 11 lines
Quoted 8 lines
To boot a guest, you will need:
- A Cortex-A15 platform with a kvm-capable bootloader
- The latest kvm-arm patches:
git://github.com/virtualopensystems/linux-kvm-arm.gitkvm-arm-master
- A guest kernel configured for our virtual target:
git://git.kernel.org/pub/scm/linux/kernel/git/will/kvmtool.gitkvm/mach-virtnewest as in v4 from this weekend or before the weekend? There were some (hopefully final) API breakage in there.
That's the GIC device ID type change right? I think that just requires a recompile on my part, with no changes to the code. I've been working off kvm-arm-master and updating fairly frequently (current HEAD a73616f165).
I see you posted v14 of the kernel patches too, so I'll try and get round to looking at those this week.
Cheers,
Will
Quoted 31 lines · Will Deacon
Hi Christoffer,
Quoted 10 lines · Christoffer Dall
Quoted 7 lines · Will Deacon
Hello,
This patch series adds support for ARMv7 processors (Cortex-A15) to kvm tool. The majority of the series consists of small changes in preparation for ARM support, which is added by the final patch. I can try to split this up further, but given that there is no current support for ARM, the sub-patches wouldn't be especially meaningful.
Very cool, looking forward to trying it out!
Great -- please let me know if/when it explodes...
Quoted 2 lines
Would have been very nice if you had sent it to
[email protected] as well.Sorry, will include that on CC for future submissions (obviously didn't appear in the get_maintainers.pl output).
Quoted 9 lines
Quoted 8 lines
To boot a guest, you will need:
- A Cortex-A15 platform with a kvm-capable bootloader
- The latest kvm-arm patches:
git://github.com/virtualopensystems/linux-kvm-arm.gitkvm-arm-master
- A guest kernel configured for our virtual target:
git://git.kernel.org/pub/scm/linux/kernel/git/will/kvmtool.gitkvm/mach-virt
Quoted 7 lines
Quoted 2 lines
newest as in v4 from this weekend or before the weekend? There were some (hopefully final) API breakage in there.
That's the GIC device ID type change right? I think that just requires a recompile on my part, with no changes to the code. I've been working off kvm-arm-master and updating fairly frequently (current HEAD
a73616f165).
between v3 and v4 we also changed the struct kvm_regs to use pt_regs, but that's all included in a73616f165.
thanks
Quoted 13 lines · Christoffer Dall
Quoted 12 lines · Will Deacon
Hi Christoffer,
Quoted 9 lines · Christoffer Dall
Quoted 7 lines · Will Deacon
Hello,
This patch series adds support for ARMv7 processors (Cortex-A15) to kvm tool. The majority of the series consists of small changes in preparation for ARM support, which is added by the final patch. I can try to split this up further, but given that there is no current support for ARM, the sub-patches wouldn't be especially meaningful.
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Very cool, looking forward to trying it out!
Great -- please let me know if/when it explodes...
just to make sure, this patch series is also the one that can be found here (HEAD~1):git://git.kernel.org/pub/scm/linux/kernel/git/will/kvmtool.git kvmtool/arm
???
-Christoffer
Quoted 15 lines · Christoffer Dall
Quoted 13 lines · Christoffer Dall
Quoted 12 lines · Will Deacon
Hi Christoffer,
Quoted 9 lines · Christoffer Dall
Quoted 7 lines · Will Deacon
Hello,
This patch series adds support for ARMv7 processors (Cortex-A15) to kvm tool. The majority of the series consists of small changes in preparation for ARM support, which is added by the final patch. I can try to split this up further, but given that there is no current support for ARM, the sub-patches wouldn't be especially meaningful.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Very cool, looking forward to trying it out!
Great -- please let me know if/when it explodes...
just to make sure, this patch series is also the one that can be found here (HEAD~1):
git://git.kernel.org/pub/scm/linux/kernel/git/will/kvmtool.gitkvmtool/arm
Currently, yes, but that is my development branch and will rebase as and when I make changes in preparation for v2. There's also a patch there for AArch64 support, but the kernel side needs to settle down before that's ready for posting.
Cheers,
Will
Quoted 5 lines · Will Deacon
This patch series adds support for ARMv7 processors (Cortex-A15) to kvm tool. The majority of the series consists of small changes in preparation for ARM support, which is added by the final patch. I can try to split this up further, but given that there is no current support for ARM, the sub-patches wouldn't be especially meaningful.
I cherry-picked the easy ones from this series and merged them. Thanks a lot, Will!
Pekka