Skip to contentSkip to conversation

ARM: KVM: Initial skeleton to compile KVM support

PATCH Superseded Christoffer Dall 6 participants 58 messages Jun 3, 2011 – Jun 12, 2011 1 message not in the archive

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/8 ARM: KVM: Initial skeleton to compile KVM support

Targets KVM support for Cortex A-15 processors.

Contains no real functionality but all the framework components, make files, header files and some tracing functionality.

---
 arch/arm/Kconfig                   |    2 
 arch/arm/Makefile                  |    1 
 arch/arm/include/asm/kvm.h         |   65 +++++
 arch/arm/include/asm/kvm_asm.h     |   28 ++
 arch/arm/include/asm/kvm_emulate.h |   89 +++++++
 arch/arm/include/asm/kvm_host.h    |  114 +++++++++
 arch/arm/include/asm/kvm_para.h    |    9 +
 arch/arm/include/asm/unified.h     |   12 +
 arch/arm/kvm/Kconfig               |   44 ++++
 arch/arm/kvm/Makefile              |   13 +
 arch/arm/kvm/arm.c                 |  363 ++++++++++++++++++++++++++++++
 arch/arm/kvm/arm_emulate.c         |   70 ++++++
 arch/arm/kvm/arm_guest.c           |  142 ++++++++++++
 arch/arm/kvm/arm_interrupts.S      |   17 +
 arch/arm/kvm/arm_mmu.c             |    0 
 arch/arm/kvm/trace.c               |  436 ++++++++++++++++++++++++++++++++++++
 arch/arm/kvm/trace.h               |  108 +++++++++
 arch/arm/mach-vexpress/Kconfig     |    1 
 arch/arm/mm/Kconfig                |    7 +
 include/linux/kvm.h                |    1 
 20 files changed, 1522 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/include/asm/kvm.h
 create mode 100644 arch/arm/include/asm/kvm_asm.h
 create mode 100644 arch/arm/include/asm/kvm_emulate.h
 create mode 100644 arch/arm/include/asm/kvm_host.h
 create mode 100644 arch/arm/include/asm/kvm_para.h
 create mode 100644 arch/arm/kvm/Kconfig
 create mode 100644 arch/arm/kvm/Makefile
 create mode 100644 arch/arm/kvm/arm.c
 create mode 100644 arch/arm/kvm/arm_emulate.c
 create mode 100644 arch/arm/kvm/arm_guest.c
 create mode 100644 arch/arm/kvm/arm_interrupts.S
 create mode 100644 arch/arm/kvm/arm_mmu.c
 create mode 100644 arch/arm/kvm/trace.c
 create mode 100644 arch/arm/kvm/trace.h
arch/arm/Kconfig +2 -0
index b410049..b2a2b65 100644
@@ -1951,3 +1951,5 @@ source "security/Kconfig"
 source "crypto/Kconfig"
 
 source "lib/Kconfig"
+
+source "arch/arm/kvm/Kconfig"
arch/arm/Makefile +1 -0
index 6f7b292..72335fc 100644
@@ -254,6 +254,7 @@ core-$(CONFIG_VFP)		+= arch/arm/vfp/
 
 # If we have a machine-specific directory, then include it in the build.
 core-y				+= arch/arm/kernel/ arch/arm/mm/ arch/arm/common/
+core-$(CONFIG_KVM) 		+= arch/arm/kvm/
 core-y				+= $(machdirs) $(platdirs)
 
 drivers-$(CONFIG_OPROFILE)      += arch/arm/oprofile/
arch/arm/include/asm/kvm.h new file +65 -0

65 lines not on this page · raw message

arch/arm/include/asm/kvm_asm.h new file +28 -0
new file mode 100644
index 0000000..c3d4458
@@ -0,0 +1,28 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef __ARM_KVM_ASM_H__
+#define __ARM_KVM_ASM_H__
+
+#define ARM_EXCEPTION_RESET	  0
+#define ARM_EXCEPTION_UNDEFINED   1
+#define ARM_EXCEPTION_SOFTWARE    2
+#define ARM_EXCEPTION_PREF_ABORT  3
+#define ARM_EXCEPTION_DATA_ABORT  4
+#define ARM_EXCEPTION_IRQ	  5
+#define ARM_EXCEPTION_FIQ	  6
+
+#endif /* __ARM_KVM_ASM_H__ */
arch/arm/include/asm/kvm_emulate.h new file +89 -0

89 lines not on this page · raw message

arch/arm/include/asm/kvm_host.h new file +114 -0

114 lines not on this page · raw message

arch/arm/include/asm/kvm_para.h new file +9 -0
new file mode 100644
index 0000000..7ce5f1c
@@ -0,0 +1,9 @@
+#ifndef _ASM_X86_KVM_PARA_H
+#define _ASM_X86_KVM_PARA_H
+
+static inline unsigned int kvm_arch_para_features(void)
+{
+	return 0;
+}
+
+#endif /* _ASM_X86_KVM_PARA_H */
arch/arm/include/asm/unified.h +12 -0
index bc63116..14ad6bb 100644
@@ -54,6 +54,18 @@
 
 #endif	/* CONFIG_THUMB2_KERNEL */
 
+#ifdef CONFIG_KVM
+#ifdef __ASSEMBLY__
+.arch_extension sec
+.arch_extension virt
+#else
+__asm__(
+"	.arch_extension sec\n"
+"	.arch_extension virt\n"
+);
+#endif
+#endif
+
 #ifndef CONFIG_ARM_ASM_UNIFIED
 
 /*
arch/arm/kvm/Kconfig new file +44 -0

44 lines not on this page · raw message

arch/arm/kvm/Makefile new file +13 -0
new file mode 100644
index 0000000..4ff905d
@@ -0,0 +1,13 @@
+#
+# Makefile for Kernel-based Virtual Machine module
+#
+
+EXTRA_CFLAGS += -Ivirt/kvm -Iarch/arm/kvm
+AFLAGS_arm_interrupts.o := -I$(obj)
+
+kvm-arm-y += $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o)
+
+kvm-arm-y += arm.o arm_guest.o arm_interrupts.o arm_mmu.o arm_emulate.o \
+		trace.o
+
+obj-$(CONFIG_KVM) += kvm-arm.o
arch/arm/kvm/arm.c new file +363 -0

363 lines not on this page · raw message

arch/arm/kvm/arm_emulate.c new file +70 -0

70 lines not on this page · raw message

arch/arm/kvm/arm_guest.c new file +142 -0

142 lines not on this page · raw message

arch/arm/kvm/arm_interrupts.S new file +17 -0
new file mode 100644
index 0000000..073a494
@@ -0,0 +1,17 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+#include <asm/asm-offsets.h>
+#include <asm/kvm_asm.h>
arch/arm/kvm/arm_mmu.c new file +0 -0
new file mode 100644
index 0000000..e69de29
arch/arm/kvm/trace.c new file +436 -0

436 lines not on this page · raw message

arch/arm/kvm/trace.h new file +108 -0

108 lines not on this page · raw message

arch/arm/mach-vexpress/Kconfig +1 -0
index cfbc0f1..5b00905 100644
@@ -33,6 +33,7 @@ config ARCH_VEXPRESS_CA15X4
 	bool "Versatile Express Cortex-A15x4 tile"
 	depends on VEXPRESS_EXTENDED_MEMORY_MAP
 	select CPU_V7
+	select ARM_VIRT_EXT
 	select ARM_GIC
 	select HAVE_ARCH_TIMERS
 
arch/arm/mm/Kconfig +7 -0
index 04de742..ad77805 100644
@@ -628,6 +628,13 @@ config ARM_LPAE
 	  Say Y if you have an ARMv7 processor supporting the LPAE page table
 	  format and you would like to access memory beyond the 4GB limit.
 
+config ARM_VIRT_EXT
+	bool "Support for ARM Virtualization Extensions"
+	depends on ARM_LPAE
+	help
+	  Say Y if you have an ARMv7 processor supporting the ARM hardware
+	  Virtualization extensions.
+
 config ARCH_PHYS_ADDR_T_64BIT
 	def_bool ARM_LPAE
 
include/linux/kvm.h +1 -0
index ea2dc1a..d2ab07e 100644
@@ -310,6 +310,7 @@ struct kvm_translation {
 struct kvm_interrupt {
 	/* in */
 	__u32 irq;
+	__u8  raise;
 };
 
 /* for KVM_GET_DIRTY_LOG */
#1 lore raw

PATCH v3 2/8 ARM: KVM: Hypervisor identity mapping

Adds support in the identity mapping feature that allows KVM to setup identity mapping for the Hyp mode with the AP[1] bit set as required by the specification and also supports freeing created sub pmd's after finished use.

---
 arch/arm/include/asm/pgtable-3level-hwdef.h |    1 +
 arch/arm/include/asm/pgtable.h              |    5 +++
 arch/arm/mm/idmap.c                         |   47 ++++++++++++++++++++++++++-
 3 files changed, 52 insertions(+), 1 deletions(-)
arch/arm/include/asm/pgtable-3level-hwdef.h +1 -0
index 6c0fb9b..9142208 100644
@@ -48,6 +48,7 @@
 #endif
 #define PMD_SECT_AP_WRITE	(_AT(pmdval_t, 0))
 #define PMD_SECT_AP_READ	(_AT(pmdval_t, 0))
+#define PMD_SECT_AP1		(_AT(pmdval_t, 1) << 6)
 #define PMD_SECT_TEX(x)		(_AT(pmdval_t, 0))
 
 /*
arch/arm/include/asm/pgtable.h +5 -0
index 110f6f4..56081c0 100644
@@ -403,6 +403,11 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 void identity_mapping_add(pgd_t *, unsigned long, unsigned long);
 void identity_mapping_del(pgd_t *, unsigned long, unsigned long);
 
+#ifdef CONFIG_KVM
+void hyp_identity_mapping_add(pgd_t *, unsigned long, unsigned long);
+void hyp_identity_mapping_del(pgd_t *pgd, unsigned long addr, unsigned long end);
+#endif
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* CONFIG_MMU */
arch/arm/mm/idmap.c +46 -1

69 lines not on this page · raw message

#2 lore raw

PATCH v3 3/8 ARM: KVM: Add hypervisor inititalization

In reply to Christoffer Dall

Sets up the required registers to run code in HYP-mode from the kernel. No major controversies, but we should consider how to deal with SMP support for hypervisor stack page.

Works by setting the HVBAR the kernel can execute code in Hyp-mode with the MMU disabled which initializes other registers and enables the MMU for Hyp-mode.

Also provides memory mapping code to map required code pages and data structures accessed in Hyp mode at the same virtual address as the host kernel virtual addresses, but which conforms to the architectural requirements for translations in Hyp mode.

---
 arch/arm/include/asm/kvm_arm.h              |  103 +++++++++++
 arch/arm/include/asm/kvm_asm.h              |   12 +
 arch/arm/include/asm/kvm_host.h             |    1 
 arch/arm/include/asm/kvm_mmu.h              |   40 ++++
 arch/arm/include/asm/pgtable-3level-hwdef.h |    5 +
 arch/arm/include/asm/pgtable.h              |    5 +
 arch/arm/kvm/arm.c                          |  163 +++++++++++++++++
 arch/arm/kvm/arm_interrupts.S               |  124 +++++++++++++
 arch/arm/kvm/arm_mmu.c                      |  255 +++++++++++++++++++++++++++
 9 files changed, 708 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/include/asm/kvm_arm.h
 create mode 100644 arch/arm/include/asm/kvm_mmu.h
arch/arm/include/asm/kvm_arm.h new file +103 -0
new file mode 100644
index 0000000..835abd1
@@ -0,0 +1,103 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef __KVM_ARM_H__
+#define __KVM_ARM_H__
+
+#include <asm/types.h>
+
+/* Hyp Configuration Register (HCR) bits */
+#define HCR_TGE		(1 << 27)
+#define HCR_TVM		(1 << 26)
+#define HCR_TTLB	(1 << 25)
+#define HCR_TPU		(1 << 24)
+#define HCR_TPC		(1 << 23)
+#define HCR_TSW		(1 << 22)
+#define HCR_TAC		(1 << 21)
+#define HCR_TIDCP	(1 << 20)
+#define HCR_TSC		(1 << 19)
+#define HCR_TID3	(1 << 18)
+#define HCR_TID2	(1 << 17)
+#define HCR_TID1	(1 << 16)
+#define HCR_TID0	(1 << 15)
+#define HCR_TWE		(1 << 14)
+#define HCR_TWI		(1 << 13)
+#define HCR_DC		(1 << 12)
+#define HCR_BSU		(3 << 10)
+#define HCR_FB		(1 << 9)
+#define HCR_VA		(1 << 8)
+#define HCR_VI		(1 << 7)
+#define HCR_VF		(1 << 6)
+#define HCR_AMO		(1 << 5)
+#define HCR_IMO		(1 << 4)
+#define HCR_FMO		(1 << 3)
+#define HCR_PTW		(1 << 2)
+#define HCR_SWIO	(1 << 1)
+#define HCR_VM		1
+#define HCR_GUEST_MASK (HCR_TSC | HCR_TWE | HCR_TWI | HCR_VM | HCR_AMO | \
+			HCR_AMO | HCR_IMO | HCR_FMO | HCR_SWIO)
+
+/* Hyp System Control Register (HSCTLR) bits */
+#define HSCTLR_TE	(1 << 30)
+#define HSCTLR_EE	(1 << 25)
+#define HSCTLR_FI	(1 << 21)
+#define HSCTLR_WXN	(1 << 19)
+#define HSCTLR_I	(1 << 12)
+#define HSCTLR_C	(1 << 2)
+#define HSCTLR_A	(1 << 1)
+#define HSCTLR_M	1
+#define HSCTLR_MASK	(HSCTLR_M | HSCTLR_A | HSCTLR_C | HSCTLR_I | \
+			 HSCTLR_WXN | HSCTLR_FI | HSCTLR_EE | HSCTLR_TE)
+
+/* TTBCR and HTCR Registers bits */
+#define TTBCR_EAE	(1 << 31)
+#define TTBCR_IMP	(1 << 30)
+#define TTBCR_SH1	(3 << 28)
+#define TTBCR_ORGN1	(3 << 26)
+#define TTBCR_IRGN1	(3 << 24)
+#define TTBCR_EPD1	(1 << 23)
+#define TTBCR_A1	(1 << 22)
+#define TTBCR_T1SZ	(3 << 16)
+#define TTBCR_SH0	(3 << 12)
+#define TTBCR_ORGN0	(3 << 10)
+#define TTBCR_IRGN0	(3 << 8)
+#define TTBCR_EPD0	(1 << 7)
+#define TTBCR_T0SZ	3
+#define HTCR_MASK	(TTBCR_T0SZ | TTBCR_IRGN0 | TTBCR_ORGN0 | TTBCR_SH0)
+
+
+/* Virtualization Translation Control Register (VTCR) bits */
+#define VTCR_SH0	(3 << 12)
+#define VTCR_ORGN0	(3 << 10)
+#define VTCR_IRGN0	(3 << 8)
+#define VTCR_SL0	(3 << 6)
+#define VTCR_S		(1 << 4)
+#define VTCR_T0SZ	3
+#define VTCR_MASK	(VTCR_SH0 | VTCR_ORGN0 | VTCR_IRGN0 | VTCR_SL0 | \
+			 VTCR_S | VTCR_T0SZ | VTCR_MASK)
+#define VTCR_HTCR_SH	(VTCR_SH0 | VTCR_ORGN0 | VTCR_IRGN0)
+#define VTCR_SL_L2	0		/* Starting-level: 2 */
+#define VTCR_SL_L1	(1 << 6)	/* Starting-level: 1 */
+#define VTCR_GUEST_SL	VTCR_SL_L1
+#define VTCR_GUEST_T0SZ	0
+#if VTCR_GUEST_SL == 0
+#define VTTBR_X		(14 - VTCR_GUEST_T0SZ)
+#else
+#define VTTBR_X		(5 - VTCR_GUEST_T0SZ)
+#endif
+
+
+#endif /* __KVM_ARM_H__ */
arch/arm/include/asm/kvm_asm.h +12 -0
index c3d4458..99991b4 100644
@@ -24,5 +24,17 @@
 #define ARM_EXCEPTION_DATA_ABORT  4
 #define ARM_EXCEPTION_IRQ	  5
 #define ARM_EXCEPTION_FIQ	  6
+#define ARM_EXCEPTION_HVC	  7
+
+/*
+ * SMC Hypervisor API call numbers
+ */
+#ifdef __ASSEMBLY__
+#define SMC_HYP_CALL(n, x) .equ n, x
+#else /* !__ASSEMBLY__ */
+#define SMC_HYP_CALL(n, x) asm(".equ " #n ", " #x);
+#endif /* __ASSEMBLY__ */
+
+SMC_HYP_CALL(SMCHYP_HVBAR_W  , 0xfffffff0)
 
 #endif /* __ARM_KVM_ASM_H__ */
arch/arm/include/asm/kvm_host.h +1 -0
index 6e8a08d..9fa9b20 100644
@@ -31,6 +31,7 @@ struct kvm_vcpu;
 u32* kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode);
 
 struct kvm_arch {
+	pgd_t *pgd;     /* 1-level 2nd stage table */
 };
 
 #define EXCEPTION_NONE      0
arch/arm/include/asm/kvm_mmu.h new file +40 -0
new file mode 100644
index 0000000..d22aad0
@@ -0,0 +1,40 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef __ARM_KVM_MMU_H__
+#define __ARM_KVM_MMU_H__
+
+/*
+ * The architecture supports 40-bit IPA as input to the 2nd stage translations
+ * and PTRS_PER_PGD2 could therefore be 1024.
+ *
+ * To save a bit of memory and to avoid alignment issues we assume 39-bit IPA
+ * for now, but remember that the level-1 table must be aligned to its size.
+ */
+#define PTRS_PER_PGD2	512
+#define PGD2_ORDER	get_order(PTRS_PER_PGD2 * sizeof(pgd_t))
+
+extern pgd_t *kvm_hyp_pgd;
+
+int create_hyp_mappings(pgd_t *hyp_pgd,
+			unsigned long start,
+			unsigned long end);
+void remove_hyp_mappings(pgd_t *hyp_pgd,
+			 unsigned long start,
+			 unsigned long end);
+void free_hyp_pmds(pgd_t *hyp_pgd);
+
+#endif /* __ARM_KVM_MMU_H__ */
arch/arm/include/asm/pgtable-3level-hwdef.h +5 -0
index 9142208..6cfe57c 100644
@@ -31,6 +31,9 @@
 #define PMD_TYPE_SECT		(_AT(pmdval_t, 1) << 0)
 #define PMD_BIT4		(_AT(pmdval_t, 0))
 #define PMD_DOMAIN(x)		(_AT(pmdval_t, 0))
+#define PMD_APTABLE_SHIFT	(61)
+#define PMD_APTABLE		(_AT(pgdval_t, 3) << PGD_APTABLE_SHIFT)
+#define PMD_PXNTABLE		(_AT(pgdval_t, 1) << 59)
 
 /*
  *   - section
@@ -43,8 +46,10 @@
 #ifdef __ASSEMBLY__
 /* avoid 'shift count out of range' warning */
 #define PMD_SECT_XN		(0)
+#define PMD_SECT_PXN		(0)
 #else
 #define PMD_SECT_XN		((pmdval_t)1 << 54)
+#define PMD_SECT_PXN		((pmdval_t)1 << 53)
 #endif
 #define PMD_SECT_AP_WRITE	(_AT(pmdval_t, 0))
 #define PMD_SECT_AP_READ	(_AT(pmdval_t, 0))
arch/arm/include/asm/pgtable.h +5 -0
index 56081c0..2906f35 100644
@@ -87,6 +87,7 @@ extern pgprot_t		pgprot_kernel;
 #define PAGE_READONLY_EXEC	_MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY)
 #define PAGE_KERNEL		_MOD_PROT(pgprot_kernel, L_PTE_XN)
 #define PAGE_KERNEL_EXEC	pgprot_kernel
+#define PAGE_HYP		_MOD_PROT(pgprot_kernel, L_PTE_USER)
 
 #define __PAGE_NONE		__pgprot(_L_PTE_DEFAULT | L_PTE_RDONLY | L_PTE_XN)
 #define __PAGE_SHARED		__pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_XN)
@@ -217,6 +218,10 @@ static inline pmd_t *pgd_page_vaddr(pgd_t pgd)
 #ifdef CONFIG_ARM_LPAE
 
 #define pmd_bad(pmd)		(!(pmd_val(pmd) & 2))
+#define pmd_table(pmd)		((pmd_val(pmd) & PMD_TYPE_MASK) == \
+						 PMD_TYPE_TABLE)
+#define pmd_sect(pmd)		((pmd_val(pmd) & PMD_TYPE_MASK) == \
+						 PMD_TYPE_SECT)
 
 #define copy_pmd(pmdpd,pmdps)		\
 	do {				\
arch/arm/kvm/arm.c +163 -0

195 lines not on this page · raw message

arch/arm/kvm/arm_interrupts.S +124 -0

129 lines not on this page · raw message

arch/arm/kvm/arm_mmu.c +255 -0

255 lines not on this page · raw message

#3 lore raw

PATCH v3 4/8 ARM: KVM: Memory virtualization setup

In reply to Christoffer Dall

Initializes a blank level-1 translation table for the second stage translation and handles freeing it as well.

---
 arch/arm/include/asm/kvm_host.h |    4 ++-
 arch/arm/include/asm/kvm_mmu.h  |    5 ++++
 arch/arm/kvm/arm.c              |   54 ++++++++++++++++++++++++++++++++++++++-
 3 files changed, 61 insertions(+), 2 deletions(-)
arch/arm/include/asm/kvm_host.h +3 -1
index 9fa9b20..5955ff4 100644
@@ -31,7 +31,9 @@ struct kvm_vcpu;
 u32* kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode);
 
 struct kvm_arch {
-	pgd_t *pgd;     /* 1-level 2nd stage table */
+	u32    vmid;	/* The VMID used for the virt. memory system */
+	pgd_t *pgd;	/* 1-level 2nd stage table */
+	u64    vttbr;	/* VTTBR value associated with above pgd and vmid */
 };
 
 #define EXCEPTION_NONE      0
arch/arm/include/asm/kvm_mmu.h +5 -0
index d22aad0..a64ab2d 100644
@@ -37,4 +37,9 @@ void remove_hyp_mappings(pgd_t *hyp_pgd,
 			 unsigned long end);
 void free_hyp_pmds(pgd_t *hyp_pgd);
 
+int kvm_alloc_stage2_pgd(struct kvm *kvm);
+void kvm_free_stage2_pgd(struct kvm *kvm);
+
+int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run);
+
 #endif /* __ARM_KVM_MMU_H__ */
arch/arm/kvm/arm.c +53 -1

79 lines not on this page · raw message

#4 lore raw

Re: [PATCH v3 4/8] ARM: KVM: Memory virtualization setup

arch/arm/kvm/arm.c void kvm_arch_sync_events(struct kvm *kvm) · line 106

Quoted 6 lines · Christoffer Dall

Initializes a blank level-1 translation table for the second stage translation and handles freeing it as well.

arch/arm/kvm/arm.c +3 -0
+	start = (unsigned long)kvm,
+	end = start + sizeof(struct kvm);
+	ret = create_hyp_mappings(kvm_hyp_pgd, start, end);

Why not map all GFP_KERNEL memory?

Signature · 1 line
error compiling committee.c: too many arguments to function
#5 lore raw

Re: [PATCH v3 4/8] ARM: KVM: Memory virtualization setup

Quoted 11 lines · Avi Kivity
Quoted 7 lines · Christoffer Dall

Initializes a blank level-1 translation table for the second stage translation and handles freeing it as well.

+       start = (unsigned long)kvm,
+       end = start + sizeof(struct kvm);
+       ret = create_hyp_mappings(kvm_hyp_pgd, start, end);

Why not map all GFP_KERNEL memory?

I wanted to only map things I was sure would be there and stay there so no assumptions were made about existing pages which could have been removed, since I don't handle aborts taken in the hypervisor itself. But, if it would be as safe to map all GFP_KERNEL memory and that also maps the necessary code segments, then we could do that. Do you feel it would me simpler/faster/easier?

Quoted 4 lines

--
error compiling committee.c: too many arguments to function

#6 lore raw

Re: [PATCH v3 4/8] ARM: KVM: Memory virtualization setup

Quoted 10 lines · Christoffer Dall
Quoted 9 lines · Avi Kivity
Quoted 7 lines · Christoffer Dall

Initializes a blank level-1 translation table for the second stage translation and handles freeing it as well.

 +       start = (unsigned long)kvm,
 +       end = start + sizeof(struct kvm);
 +       ret = create_hyp_mappings(kvm_hyp_pgd, start, end);
Quoted 8 lines
Quoted 2 lines

Why not map all GFP_KERNEL memory?

I wanted to only map things I was sure would be there and stay there so no assumptions were made about existing pages which could have been removed, since I don't handle aborts taken in the hypervisor itself. But, if it would be as safe to map all GFP_KERNEL memory and that also maps the necessary code segments, then we could do that. Do you feel it would me simpler/faster/easier?

I think so - you wouldn't have to worry about dereferencing pointers within the vcpu structure.

Of course, it's up to you, I don't really have a enough understanding of the architecture.

Signature · 1 line
error compiling committee.c: too many arguments to function
#7 lore raw

Re: [PATCH v3 4/8] ARM: KVM: Memory virtualization setup

Quoted 13 lines · Avi Kivity
Quoted 12 lines · Christoffer Dall
Quoted 11 lines · Avi Kivity
Quoted 7 lines · Christoffer Dall

Initializes a blank level-1 translation table for the second stage translation and handles freeing it as well.

 +       start = (unsigned long)kvm,
 +       end = start + sizeof(struct kvm);
 +       ret = create_hyp_mappings(kvm_hyp_pgd, start, end);

Why not map all GFP_KERNEL memory?

Quoted 8 lines
Quoted 6 lines

I wanted to only map things I was sure would be there and stay there so no assumptions were made about existing pages which could have been removed, since I don't handle aborts taken in the hypervisor itself. But, if it would be as safe to map all GFP_KERNEL memory and that also maps the necessary code segments, then we could do that. Do you feel it would me simpler/faster/easier?

I think so - you wouldn't have to worry about dereferencing pointers within the vcpu structure.

Also, you could use huge pages for the mapping, yes? that should improve switching performance a bit.

Can you run the host kernel in hypervisor mode? That may reduce switching time even further.

Signature · 1 line
error compiling committee.c: too many arguments to function
#8 lore raw

Re: [PATCH v3 4/8] ARM: KVM: Memory virtualization setup

Quoted 23 lines · Avi Kivity
Quoted 22 lines · Avi Kivity
Quoted 19 lines · Christoffer Dall
Quoted 11 lines · Avi Kivity
Quoted 7 lines · Christoffer Dall

 Initializes a blank level-1 translation table for the second stage translation and handles freeing it as well.

 +       start = (unsigned long)kvm,
 +       end = start + sizeof(struct kvm);
 +       ret = create_hyp_mappings(kvm_hyp_pgd, start, end);

 Why not map all GFP_KERNEL memory?

I wanted to only map things I was sure would be there and stay there so no assumptions were made about existing pages which could have been removed, since I don't handle aborts taken in the hypervisor itself. But, if it would be as safe to map all GFP_KERNEL memory and that also maps the necessary code segments, then we could do that. Do you feel it would me simpler/faster/easier?

Quoted 5 lines
Quoted 2 lines

I think so - you wouldn't have to worry about dereferencing pointers within the vcpu structure.

Also, you could use huge pages for the mapping, yes?  that should improve switching performance a bit.

well, the only advantage here would be to save a few entries in the TLB right? So really it would only be the case if the data and the code and such accessed during switches lie within the same sections, which could happen, but could also not happen. I don't see a big performance gain here, but slightly more complicated code. For instance, if the VCPU struct is mapped using a page, not a section mapping, I cannot use section mappings since I would map weird things. So I would have to support both for allocating and freeing.

I suggest keeping this in place for now and experiment with performance later on to see if there's a gain. Allocating all of GFP_KERNEL memory could be good to prevent bugs, but I would like to clear this with the ARM memory experts that it is in fact a good idea.

Quoted 3 lines

Can you run the host kernel in hypervisor mode?  That may reduce switching time even further.

No, I think the implications would be way too widespread all over the kernel.

Quoted 5 lines

--
error compiling committee.c: too many arguments to function

#9 lore raw

Re: [PATCH v3 4/8] ARM: KVM: Memory virtualization setup

Quoted 39 lines · Christoffer Dall
Quoted 23 lines · Avi Kivity
Quoted 22 lines · Avi Kivity
Quoted 19 lines · Christoffer Dall
Quoted 11 lines · Avi Kivity
Quoted 7 lines · Christoffer Dall

Initializes a blank level-1 translation table for the second stage translation and handles freeing it as well.

   +       start = (unsigned long)kvm,
   +       end = start + sizeof(struct kvm);
   +       ret = create_hyp_mappings(kvm_hyp_pgd, start, end);

Why not map all GFP_KERNEL memory?

I wanted to only map things I was sure would be there and stay there so no assumptions were made about existing pages which could have been removed, since I don't handle aborts taken in the hypervisor itself. But, if it would be as safe to map all GFP_KERNEL memory and that also maps the necessary code segments, then we could do that. Do you feel it would me simpler/faster/easier?

Quoted 5 lines
Quoted 2 lines

I think so - you wouldn't have to worry about dereferencing pointers within the vcpu structure.

Also, you could use huge pages for the mapping, yes? that should improve switching performance a bit.

well, the only advantage here would be to save a few entries in the TLB right? So really it would only be the case if the data and the code and such accessed during switches lie within the same sections, which could happen, but could also not happen. I don't see a big performance gain here, but slightly more complicated code. For instance, if the VCPU struct is mapped using a page, not a section mapping, I cannot use section mappings since I would map weird things. So I would have to support both for allocating and freeing.

Quoted 4 lines

I suggest keeping this in place for now and experiment with performance later on to see if there's a gain. Allocating all of GFP_KERNEL memory could be good to prevent bugs, but I would like to clear this with the ARM memory experts that it is in fact a good idea.

Sure. All of my arch related comments are made from ignorance anyway, feel free to ignore or use them as you like. The only important ones are those related to the API.

Quoted 5 lines
Quoted 3 lines

Can you run the host kernel in hypervisor mode? That may reduce switching time even further.

No, I think the implications would be way too widespread all over the kernel.

Okay.

Signature · 1 line
error compiling committee.c: too many arguments to function
#10 lore raw

PATCH v3 5/8 ARM: KVM: World-switch implementation

In reply to Christoffer Dall

Provides complete world-switch implementation to switch to other guests runinng in non-secure modes. Includes Hyp exception handlers that captures necessary exception information and stores the information on the VCPU and KVM structures.

Only controversy may be the back-door call to __irq_svc (the host kernel's own physical IRQ handler) which is called when a physical IRQ exception is taken in Hyp mode while running in the guest.

---
 arch/arm/include/asm/kvm_arm.h  |   24 +++
 arch/arm/include/asm/kvm_host.h |    2 
 arch/arm/kernel/asm-offsets.c   |   23 ++
 arch/arm/kernel/entry-armv.S    |    1 
 arch/arm/kvm/arm.c              |   20 ++
 arch/arm/kvm/arm_interrupts.S   |  373 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 439 insertions(+), 4 deletions(-)
arch/arm/include/asm/kvm_arm.h +24 -0
index 835abd1..505a1a5 100644
@@ -99,5 +99,29 @@
 #define VTTBR_X		(5 - VTCR_GUEST_T0SZ)
 #endif
 
+/* Hyp Syndrome Register (HSR) bits */
+#define HSR_EC_SHIFT	(26)
+#define HSR_EC		(0x3fU << HSR_EC_SHIFT)
+#define HSR_IL		(1U << 25)
+#define HSR_ISS		(HSR_IL - 1)
+
+#define HSR_EC_UNKNOWN	(0x00)
+#define HSR_EC_WFI	(0x01)
+#define HSR_EC_CP15_32	(0x03)
+#define HSR_EC_CP15_64	(0x04)
+#define HSR_EC_CP14_MR	(0x05)
+#define HSR_EC_CP14_LS	(0x06)
+#define HSR_EC_CP_0_13	(0x07)
+#define HSR_EC_CP10_ID	(0x08)
+#define HSR_EC_JAZELLE	(0x09)
+#define HSR_EC_BXJ	(0x0A)
+#define HSR_EC_CP14_64	(0x0C)
+#define HSR_EC_SVC_HYP	(0x11)
+#define HSR_EC_HVC	(0x12)
+#define HSR_EC_SMC	(0x13)
+#define HSR_EC_IABT	(0x20)
+#define HSR_EC_IABT_HYP	(0x21)
+#define HSR_EC_DABT	(0x24)
+#define HSR_EC_DABT_HYP	(0x25)
 
 #endif /* __KVM_ARM_H__ */
arch/arm/include/asm/kvm_host.h +2 -0
index 5955ff4..7f96974 100644
@@ -73,6 +73,8 @@ struct kvm_vcpu_arch {
 		u64 c2_TTBR1;		/* Translation Table Base Register 1 */
 		u32 c2_TTBCR;		/* Translation Table Base Control Register */
 		u32 c3_DACR;		/* Domain Access Control Register */
+		u32 c10_PRRR;		/* Primary Region Remap Register */
+		u32 c10_NMRR;		/* Normal Memory Remap Register */
 	} cp15;
 
 	u32 exception_pending;  	/* Exception to raise after emulation */
arch/arm/kernel/asm-offsets.c +23 -0
index 82da661..769fa97 100644
@@ -13,6 +13,7 @@
 #include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/dma-mapping.h>
+#include <linux/kvm_host.h>
 #include <asm/mach/arch.h>
 #include <asm/thread_info.h>
 #include <asm/memory.h>
@@ -118,5 +119,27 @@ int main(void)
   DEFINE(DMA_BIDIRECTIONAL,	DMA_BIDIRECTIONAL);
   DEFINE(DMA_TO_DEVICE,		DMA_TO_DEVICE);
   DEFINE(DMA_FROM_DEVICE,	DMA_FROM_DEVICE);
+#ifdef CONFIG_KVM
+  DEFINE(VCPU_KVM,		offsetof(struct kvm_vcpu, kvm));
+  DEFINE(VCPU_SCTLR,		offsetof(struct kvm_vcpu, arch.cp15.c1_SCTLR));
+  DEFINE(VCPU_CPACR,		offsetof(struct kvm_vcpu, arch.cp15.c1_CPACR));
+  DEFINE(VCPU_TTBR0,		offsetof(struct kvm_vcpu, arch.cp15.c2_TTBR0));
+  DEFINE(VCPU_TTBR1,		offsetof(struct kvm_vcpu, arch.cp15.c2_TTBR1));
+  DEFINE(VCPU_TTBCR,		offsetof(struct kvm_vcpu, arch.cp15.c2_TTBCR));
+  DEFINE(VCPU_DACR,		offsetof(struct kvm_vcpu, arch.cp15.c3_DACR));
+  DEFINE(VCPU_PRRR,		offsetof(struct kvm_vcpu, arch.cp15.c10_PRRR));
+  DEFINE(VCPU_NMRR,		offsetof(struct kvm_vcpu, arch.cp15.c10_NMRR));
+  DEFINE(VCPU_REGS,		offsetof(struct kvm_vcpu, arch.regs));
+  DEFINE(VCPU_USR_REGS,		offsetof(struct kvm_vcpu, arch.regs.usr_regs));
+  DEFINE(VCPU_SVC_REGS,		offsetof(struct kvm_vcpu, arch.regs.svc_regs));
+  DEFINE(VCPU_ABT_REGS,		offsetof(struct kvm_vcpu, arch.regs.abt_regs));
+  DEFINE(VCPU_UND_REGS,		offsetof(struct kvm_vcpu, arch.regs.und_regs));
+  DEFINE(VCPU_IRQ_REGS,		offsetof(struct kvm_vcpu, arch.regs.irq_regs));
+  DEFINE(VCPU_FIQ_REGS,		offsetof(struct kvm_vcpu, arch.regs.fiq_regs));
+  DEFINE(VCPU_PC,		offsetof(struct kvm_vcpu, arch.regs.pc));
+  DEFINE(VCPU_CPSR,		offsetof(struct kvm_vcpu, arch.regs.cpsr));
+  DEFINE(VCPU_HSR,		offsetof(struct kvm_vcpu, arch.hsr));
+  DEFINE(KVM_VTTBR,		offsetof(struct kvm, arch.vttbr));
+#endif
   return 0; 
 }
arch/arm/kernel/entry-armv.S +1 -0
index 2b46fea..9cdc65e 100644
@@ -197,6 +197,7 @@ __dabt_svc:
 ENDPROC(__dabt_svc)
 
 	.align	5
+	.globl __irq_svc
 __irq_svc:
 	svc_entry
 
arch/arm/kvm/arm.c +19 -1
index 714f415..1a9f168 100644
@@ -245,7 +245,19 @@ int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
 
 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
 {
-	KVMARM_NOT_IMPLEMENTED();
+	unsigned long cpsr;
+	unsigned long sctlr;
+
+	/* Init execution CPSR */
+	asm volatile ("mrs	%[cpsr], cpsr": [cpsr] "=r" (cpsr));
+	vcpu->arch.regs.cpsr = SVC_MODE | PSR_I_BIT | PSR_F_BIT | PSR_A_BIT |
+				(cpsr & PSR_E_BIT);
+
+	/* Init SCTLR with MMU disabled */
+	asm volatile ("mrc	p15, 0, %[sctlr], c1, c0, 0":
+			[sctlr] "=r" (sctlr));
+	vcpu->arch.cp15.c1_SCTLR = sctlr & ~1U;
+
 	return 0;
 }
 
@@ -287,6 +299,12 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 
 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
 {
+	unsigned long flags;
+
+	local_irq_save(flags);
+	__kvm_vcpu_run(vcpu);
+	local_irq_restore(flags);
+
 	KVMARM_NOT_IMPLEMENTED();
 	return -EINVAL;
 }
arch/arm/kvm/arm_interrupts.S +370 -3

393 lines not on this page · raw message

#11 lore raw

PATCH v3 6/8 ARM: KVM: Emulation framework and CP15 emulation

In reply to Christoffer Dall

A few stub functions and support for emulating access to memory remap registers PRRR and NMRR.

Provides some framework for handling trapped CP15 accesses in general.

---
 arch/arm/include/asm/kvm_emulate.h |    7 ++
 arch/arm/kvm/arm.c                 |   73 +++++++++++++++-
 arch/arm/kvm/arm_emulate.c         |  166 ++++++++++++++++++++++++++++++++++++
 3 files changed, 241 insertions(+), 5 deletions(-)
arch/arm/include/asm/kvm_emulate.h +7 -0
index 8eed752..6483b2a 100644
@@ -40,6 +40,13 @@ static inline unsigned char vcpu_mode(struct kvm_vcpu *vcpu)
 	return modes_table[vcpu->arch.regs.cpsr & 0xf];
 }
 
+int kvm_handle_cp10_id(struct kvm_vcpu *vcpu, struct kvm_run *run);
+int kvm_handle_cp_0_13_access(struct kvm_vcpu *vcpu, struct kvm_run *run);
+int kvm_handle_cp14_load_store(struct kvm_vcpu *vcpu, struct kvm_run *run);
+int kvm_handle_cp14_access(struct kvm_vcpu *vcpu, struct kvm_run *run);
+int kvm_handle_cp15_access(struct kvm_vcpu *vcpu, struct kvm_run *run);
+int kvm_handle_wfi(struct kvm_vcpu *vcpu, struct kvm_run *run);
+
 /*
  * Return the SPSR for the specified mode of the virtual CPU.
  */
arch/arm/kvm/arm.c +68 -5

90 lines not on this page · raw message

arch/arm/kvm/arm_emulate.c +166 -0

177 lines not on this page · raw message

#12 lore raw

PATCH v3 7/8 ARM: KVM: Handle guest faults in KVM

In reply to Christoffer Dall

Handles the guest faults in KVM by mapping in corresponding user pages in the 2nd stage page tables.

Introduces new ARM-specific kernel memory types, PAGE_KVM_GUEST and pgprot_guest variables used to map 2nd stage memory for KVM guests.

---
 arch/arm/include/asm/pgtable-3level.h |    9 +++
 arch/arm/include/asm/pgtable.h        |    4 ++
 arch/arm/kernel/asm-offsets.c         |    3 +
 arch/arm/kvm/arm_interrupts.S         |   14 +++++
 arch/arm/kvm/arm_mmu.c                |   86 +++++++++++++++++++++++++++++++++
 arch/arm/mm/mmu.c                     |    3 +
 6 files changed, 118 insertions(+), 1 deletions(-)
arch/arm/include/asm/pgtable-3level.h +9 -0
index 14a3e28..f90d120 100644
@@ -103,4 +103,13 @@
  */
 #define L_PGD_SWAPPER		(_AT(pgdval_t, 1) << 55)	/* swapper_pg_dir entry */
 
+/*
+ * 2-nd stage PTE definitions for LPAE.
+ */
+#define L_PTE2_READ		(_AT(pteval_t, 1) << 6)		/* HAP[0] */
+#define L_PTE2_WRITE		(_AT(pteval_t, 1) << 7)		/* HAP[1] */
+#define L_PTE2_NORM_WB		(_AT(pteval_t, 3) << 4)		/* MemAttr[3:2] */
+#define L_PTE2_INNER_WB		(_AT(pteval_t, 3) << 2)		/* MemAttr[1:0] */
+
+
 #endif /* _ASM_PGTABLE_3LEVEL_H */
arch/arm/include/asm/pgtable.h +4 -0
index 2906f35..c4e71ff 100644
@@ -75,6 +75,7 @@ extern void __pgd_error(const char *file, int line, pgd_t);
 
 extern pgprot_t		pgprot_user;
 extern pgprot_t		pgprot_kernel;
+extern pgprot_t		pgprot_guest;
 
 #define _MOD_PROT(p, b)	__pgprot(pgprot_val(p) | (b))
 
@@ -88,6 +89,9 @@ extern pgprot_t		pgprot_kernel;
 #define PAGE_KERNEL		_MOD_PROT(pgprot_kernel, L_PTE_XN)
 #define PAGE_KERNEL_EXEC	pgprot_kernel
 #define PAGE_HYP		_MOD_PROT(pgprot_kernel, L_PTE_USER)
+#define PAGE_KVM_GUEST		_MOD_PROT(pgprot_guest, L_PTE2_READ | \
+					  L_PTE2_WRITE | L_PTE2_NORM_WB | \
+					  L_PTE2_INNER_WB)
 
 #define __PAGE_NONE		__pgprot(_L_PTE_DEFAULT | L_PTE_RDONLY | L_PTE_XN)
 #define __PAGE_SHARED		__pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_XN)
arch/arm/kernel/asm-offsets.c +3 -0
index 769fa97..9f485aa 100644
@@ -139,6 +139,9 @@ int main(void)
   DEFINE(VCPU_PC,		offsetof(struct kvm_vcpu, arch.regs.pc));
   DEFINE(VCPU_CPSR,		offsetof(struct kvm_vcpu, arch.regs.cpsr));
   DEFINE(VCPU_HSR,		offsetof(struct kvm_vcpu, arch.hsr));
+  DEFINE(VCPU_HDFAR,		offsetof(struct kvm_vcpu, arch.hdfar));
+  DEFINE(VCPU_HIFAR,		offsetof(struct kvm_vcpu, arch.hifar));
+  DEFINE(VCPU_HPFAR,		offsetof(struct kvm_vcpu, arch.hpfar));
   DEFINE(KVM_VTTBR,		offsetof(struct kvm, arch.vttbr));
 #endif
   return 0; 
arch/arm/kvm/arm_interrupts.S +13 -1
index 6d3044c..689b337 100644
@@ -483,7 +483,19 @@ guest_trap:
 	stmia	r1, {r3, r4, r5}
 	sub	r1, r1, #VCPU_USR_REG(0)
 
-	mov	r0, #ARM_EXCEPTION_HVC
+	@ Check if we need the fault information
+	lsr	r0, r0, #HSR_EC_SHIFT
+	cmp	r0, #HSR_EC_IABT
+	beq	2f
+	cmp	r0, #HSR_EC_DABT
+	beq	2f
+	b	1f
+2:	mrc	p15, 4, r2, c6, c0, 0	@ HDFAR
+	mrc	p15, 4, r3, c6, c0, 2	@ HIFAR
+	mrc	p15, 4, r4, c6, c0, 4	@ HPFAR
+	add	r5, r1, #VCPU_HDFAR
+	stmia	r5, {r2, r3, r4}
+1:	mov	r0, #ARM_EXCEPTION_HVC
 	b	__kvm_vcpu_return
 
 	.align
arch/arm/kvm/arm_mmu.c +86 -0

94 lines not on this page · raw message

arch/arm/mm/mmu.c +3 -0
index d1da559..c5cbcd3 100644
@@ -55,9 +55,11 @@ static unsigned int cachepolicy __initdata = CPOLICY_WRITEBACK;
 static unsigned int ecc_mask __initdata = 0;
 pgprot_t pgprot_user;
 pgprot_t pgprot_kernel;
+pgprot_t pgprot_guest;
 
 EXPORT_SYMBOL(pgprot_user);
 EXPORT_SYMBOL(pgprot_kernel);
+EXPORT_SYMBOL(pgprot_guest);
 
 struct cachepolicy {
 	const char	policy[16];
@@ -497,6 +499,7 @@ static void __init build_mem_type_table(void)
 	pgprot_user   = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | user_pgprot);
 	pgprot_kernel = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG |
 				 L_PTE_DIRTY | kern_pgprot);
+	pgprot_guest  = __pgprot(L_PTE_PRESENT | L_PTE_YOUNG);
 
 	mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
 	mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
#13 lore raw

Re: [PATCH v3 7/8] ARM: KVM: Handle guest faults in KVM

Quoted 75 lines · Christoffer Dall

Handles the guest faults in KVM by mapping in corresponding user pages in the 2nd stage page tables.

arch/arm/kvm/arm_mmu.c +68 -0
+static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
+			  gfn_t gfn, struct kvm_memory_slot *memslot)
+{
+	pfn_t pfn;
+	pgd_t *pgd;
+	pmd_t *pmd;
+	pte_t *pte, new_pte;
+
+	pfn = gfn_to_pfn(vcpu->kvm, gfn);
+
+	if (is_error_pfn(pfn)) {
+		kvm_err(-EFAULT, "Guest gfn %u (0x%08lx) does not have "
+				"corresponding host mapping",
+				gfn, gfn<<  PAGE_SHIFT);
+		return -EFAULT;
+	}
+
+	/* Create 2nd stage page table mapping - Level 1 */
+	pgd = vcpu->kvm->arch.pgd + pgd_index(fault_ipa);
+	if (pgd_none(*pgd)) {
+		pmd = pmd_alloc_one(NULL, fault_ipa);
+		if (!pmd) {
+			kvm_err(-ENOMEM, "Cannot allocate 2nd stage pmd");
+			return -ENOMEM;
+		}
+		pgd_populate(NULL, pgd, pmd);
+		pmd += pmd_index(fault_ipa);
+	} else
+		pmd = pmd_offset(pgd, fault_ipa);
+
+	/* Create 2nd stage page table mapping - Level 2 */
+	if (pmd_none(*pmd)) {
+		pte = pte_alloc_one_kernel(NULL, fault_ipa);
+		if (!pte) {
+			kvm_err(-ENOMEM, "Cannot allocate 2nd stage pte");
+			return -ENOMEM;
+		}
+		pmd_populate_kernel(NULL, pmd, pte);
+		pte += pte_index(fault_ipa);
+	} else
+		pte = pte_offset_kernel(pmd, fault_ipa);
+
+	/* Create 2nd stage page table mapping - Level 3 */
+	new_pte = pfn_pte(pfn, PAGE_KVM_GUEST);
+	set_pte_ext(pte, new_pte, 0);
+
+	return 0;
+}
+
+#define HSR_ABT_FS	(0x3f)
+#define HPFAR_MASK	(~0xf)
  int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run)
  {
+	unsigned long hsr_ec;
+	unsigned long fault_status;
+	phys_addr_t fault_ipa;
+	struct kvm_memory_slot *memslot = NULL;
+	bool is_iabt;
+	gfn_t gfn;
+
+	hsr_ec = vcpu->arch.hsr>>  HSR_EC_SHIFT;
+	is_iabt = (hsr_ec == HSR_EC_IABT);
+
+	/* Check that the second stage fault is a translation fault */
+	fault_status = vcpu->arch.hsr&  HSR_ABT_FS;
+	if ((fault_status&  0x3c) != 0x4) {
+		kvm_err(-EFAULT, "Unsupported fault status: %x",
+				fault_status&  0x3c);
+		return -EFAULT;
+	}

arch/arm/kvm/arm_mmu.c void kvm_free_stage2_pgd(struct kvm *kvm) · line 330

Quoted 10 lines
arch/arm/kvm/arm_mmu.c +10 -0
+
+	fault_ipa = ((phys_addr_t)vcpu->arch.hpfar&  HPFAR_MASK)<<  8;
+
+	gfn = fault_ipa>>  PAGE_SHIFT;
+	if (!kvm_is_visible_gfn(vcpu->kvm, gfn))
+		goto io_mem_abort;
+
+	memslot = gfn_to_memslot(vcpu->kvm, gfn);
+	if (memslot->user_alloc)
+		return user_mem_abort(vcpu, fault_ipa, gfn, memslot);

Non-user_alloc should not exist for ARM (and are not supported for x86 these days, except for a few implementation internal slots).

arch/arm/kvm/arm_mmu.c void kvm_free_stage2_pgd(struct kvm *kvm) · line 341

Quoted 11 lines
arch/arm/kvm/arm_mmu.c +8 -0
+
+io_mem_abort:
+	if (is_iabt) {
+		kvm_err(-EFAULT, "Inst. abort on I/O address");
+		return -EFAULT;
+	}
+
+	kvm_msg("I/O address abort...");
  	KVMARM_NOT_IMPLEMENTED();
  	return -EINVAL;
  }

Okay, this is about a zillion times simpler than x86. Congratulations.

What are your thoughts about mmu notifier support?

Signature · 1 line
error compiling committee.c: too many arguments to function
#14 lore raw

Re: [PATCH v3 7/8] ARM: KVM: Handle guest faults in KVM

Quoted 82 lines · Avi Kivity
Quoted 81 lines · Christoffer Dall

Handles the guest faults in KVM by mapping in corresponding user pages in the 2nd stage page tables.

arch/arm/kvm/arm_mmu.c +51 -0
+static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
+                         gfn_t gfn, struct kvm_memory_slot *memslot)
+{
+       pfn_t pfn;
+       pgd_t *pgd;
+       pmd_t *pmd;
+       pte_t *pte, new_pte;
+
+       pfn = gfn_to_pfn(vcpu->kvm, gfn);
+
+       if (is_error_pfn(pfn)) {
+               kvm_err(-EFAULT, "Guest gfn %u (0x%08lx) does not have "
+                               "corresponding host mapping",
+                               gfn, gfn<<  PAGE_SHIFT);
+               return -EFAULT;
+       }
+
+       /* Create 2nd stage page table mapping - Level 1 */
+       pgd = vcpu->kvm->arch.pgd + pgd_index(fault_ipa);
+       if (pgd_none(*pgd)) {
+               pmd = pmd_alloc_one(NULL, fault_ipa);
+               if (!pmd) {
+                       kvm_err(-ENOMEM, "Cannot allocate 2nd stage pmd");
+                       return -ENOMEM;
+               }
+               pgd_populate(NULL, pgd, pmd);
+               pmd += pmd_index(fault_ipa);
+       } else
+               pmd = pmd_offset(pgd, fault_ipa);
+
+       /* Create 2nd stage page table mapping - Level 2 */
+       if (pmd_none(*pmd)) {
+               pte = pte_alloc_one_kernel(NULL, fault_ipa);
+               if (!pte) {
+                       kvm_err(-ENOMEM, "Cannot allocate 2nd stage pte");
+                       return -ENOMEM;
+               }
+               pmd_populate_kernel(NULL, pmd, pte);
+               pte += pte_index(fault_ipa);
+       } else
+               pte = pte_offset_kernel(pmd, fault_ipa);
+
+       /* Create 2nd stage page table mapping - Level 3 */
+       new_pte = pfn_pte(pfn, PAGE_KVM_GUEST);
+       set_pte_ext(pte, new_pte, 0);
+
+       return 0;
+}
+
+#define HSR_ABT_FS     (0x3f)
+#define HPFAR_MASK     (~0xf)

 int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) {
+       unsigned long hsr_ec;
+       unsigned long fault_status;
+       phys_addr_t fault_ipa;
+       struct kvm_memory_slot *memslot = NULL;
+       bool is_iabt;
+       gfn_t gfn;

arch/arm/kvm/arm_mmu.c +16 -0
+
+       hsr_ec = vcpu->arch.hsr>>  HSR_EC_SHIFT;
+       is_iabt = (hsr_ec == HSR_EC_IABT);
+
+       /* Check that the second stage fault is a translation fault */
+       fault_status = vcpu->arch.hsr&  HSR_ABT_FS;
+       if ((fault_status&  0x3c) != 0x4) {
+               kvm_err(-EFAULT, "Unsupported fault status: %x",
+                               fault_status&  0x3c);
+               return -EFAULT;
+       }
+
+       fault_ipa = ((phys_addr_t)vcpu->arch.hpfar&  HPFAR_MASK)<<  8;
+
+       gfn = fault_ipa>>  PAGE_SHIFT;
+       if (!kvm_is_visible_gfn(vcpu->kvm, gfn))
Quoted 8 lines
Quoted 5 lines

+               goto io_mem_abort;
+
+       memslot = gfn_to_memslot(vcpu->kvm, gfn);
+       if (memslot->user_alloc)
+               return user_mem_abort(vcpu, fault_ipa, gfn, memslot);

Non-user_alloc should not exist for ARM (and are not supported for x86 these days, except for a few implementation internal slots).

ok, I raise an error in when (!memslot->user_alloc) instead now. thanks.

Quoted 14 lines
Quoted 9 lines
arch/arm/kvm/arm_mmu.c +8 -0
+
+io_mem_abort:
+       if (is_iabt) {
+               kvm_err(-EFAULT, "Inst. abort on I/O address");
+               return -EFAULT;
+       }
+
+       kvm_msg("I/O address abort...");
Quoted 3 lines

       KVMARM_NOT_IMPLEMENTED();
       return -EINVAL;
 }

Okay, this is about a zillion times simpler than x86.  Congratulations.

Well, I need to handle the I/O aborts, but it's quite simple. What makes it much more complicated on x86?

Quoted 2 lines

What are your thoughts about mmu notifier support?

For what purpose? There is no swapping on ARM, so only case that jumps to my mind is for KSM. And I'm not quite there yet :)

#15 lore raw

Re: [PATCH v3 7/8] ARM: KVM: Handle guest faults in KVM

Quoted 5 lines · Christoffer Dall
Quoted 2 lines

Okay, this is about a zillion times simpler than x86. Congratulations.

Well, I need to handle the I/O aborts, but it's quite simple. What makes it much more complicated on x86?

- lack of nested paging on earlier processors
- 97 different paging modes
- lots of extra bits bringing in wierd functionality
- lots of optimizations

Quoted 5 lines
Quoted 2 lines

What are your thoughts about mmu notifier support?

For what purpose? There is no swapping on ARM, so only case that jumps to my mind is for KSM. And I'm not quite there yet :)

Really? I imaging swapping will be needed for server workloads. mmu notifiers are also useful for transparent hugepages and page migrations. I imagine these will all follow if ARM servers take off.

Signature · 1 line
error compiling committee.c: too many arguments to function
#16 lore raw

Re: [PATCH v3 7/8] ARM: KVM: Handle guest faults in KVM

Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

 What are your thoughts about mmu notifier support?

For what purpose? There is no swapping on ARM, so only case that jumps to my mind is for KSM. And I'm not quite there yet :)

Really?  I imaging swapping will be needed for server workloads.  mmu notifiers are also useful for transparent hugepages and page migrations.  I imagine these will all follow if ARM servers take off.

You may be right, but I guess it depends how ARM servers are going to be used. I agree though, swapping could very well be useful in an ARM server scenario and at that time mmu notifier integration should be looked into, but it's not in my critical path yet.

Thanks for the input.

#17 lore raw

PATCH v3 8/8 ARM: KVM: Handle I/O aborts

In reply to Christoffer Dall

When the guest accesses I/O memory this will create data abort exceptions and they are handled by decoding the HSR information (physical address, read/write, length, register) and forwarding reads and writes to QEMU which performs the device emulation.

This requires changing the general flow somewhat since new calls to run the VCPU must check if there's a pending MMIO load and perform the write after QEMU has made the data available.

---
 arch/arm/include/asm/kvm_host.h |    1 
 arch/arm/include/asm/kvm_mmu.h  |    1 
 arch/arm/kvm/arm.c              |   11 ++++
 arch/arm/kvm/arm_mmu.c          |  106 ++++++++++++++++++++++++++++++++++++++-
 4 files changed, 115 insertions(+), 4 deletions(-)
arch/arm/include/asm/kvm_host.h +1 -0
index 7f96974..5393e25 100644
@@ -86,6 +86,7 @@ struct kvm_vcpu_arch {
 	u32 hpfar;		/* Hyp IPA Fault Address Register */
 
 	/* IO related fields */
+	bool mmio_sign_extend;	/* for byte/halfword loads */
 	u32 mmio_rd;
 
 	/* Misc. fields */
arch/arm/include/asm/kvm_mmu.h +1 -0
index a64ab2d..f06f42d 100644
@@ -40,6 +40,7 @@ void free_hyp_pmds(pgd_t *hyp_pgd);
 int kvm_alloc_stage2_pgd(struct kvm *kvm);
 void kvm_free_stage2_pgd(struct kvm *kvm);
 
+int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
 int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run);
 
 #endif /* __ARM_KVM_MMU_H__ */
arch/arm/kvm/arm.c +11 -0
index abed683..d01f234 100644
@@ -349,6 +349,12 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
 	int ret;
 
 	for (;;) {
+		if (run->exit_reason == KVM_EXIT_MMIO) {
+			ret = kvm_handle_mmio_return(vcpu, vcpu->run);
+			if (ret)
+				break;
+		}
+
 		local_irq_save(flags);
 		ret = __kvm_vcpu_run(vcpu);
 		local_irq_restore(flags);
@@ -367,8 +373,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
 			kvm_err(ret, "Error in handle_exit");
 			break;
 		}
+
+		if (run->exit_reason == KVM_EXIT_MMIO)
+			break;
 	}
 
+	if (ret < 0)
+		run->exit_reason = KVM_EXIT_EXCEPTION;
 	return ret;
 }
 
arch/arm/kvm/arm_mmu.c +102 -4

124 lines not on this page · raw message

#18 lore raw
In reply to Christoffer Dall
Quoted 5 lines · Christoffer Dall

Targets KVM support for Cortex A-15 processors.

Contains no real functionality but all the framework components, make files, header files and some tracing functionality.
---

...

include/linux/kvm.h struct kvm_translation { · line 314

Quoted 10 lines
include/linux/kvm.h +1 -0
index ea2dc1a..d2ab07e 100644
@@ -310,6 +310,7 @@ struct kvm_translation {
 struct kvm_interrupt {
 	/* in */
 	__u32 irq;
+	__u8  raise;
 };

This touches an existing ABI and corrupts the definition of KVM_INTERRUPT IOCTL. The might exist jurisdictions considering this a capital crime. :)

You rather have to define a new CPU IRQ injection interface that supports both raising and lowering and declare its availability via a KVM_CAP. Don't forget to make it extensible (flags field) so that future requirements can be added without breaking existing users.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#19 lore raw
Quoted 24 lines · Jan Kiszka
Quoted 5 lines · Christoffer Dall

Targets KVM support for Cortex A-15 processors.

Contains no real functionality but all the framework components, make files, header files and some tracing functionality.
---

...

include/linux/kvm.h struct kvm_translation { · line 314

Quoted 10 lines
include/linux/kvm.h +1 -0
index ea2dc1a..d2ab07e 100644
@@ -310,6 +310,7 @@ struct kvm_translation {
 struct kvm_interrupt {
 	/* in */
 	__u32 irq;
+	__u8  raise;
 };

This touches an existing ABI and corrupts the definition of KVM_INTERRUPT IOCTL. The might exist jurisdictions considering this a capital crime. :)

Quoted 4 lines

You rather have to define a new CPU IRQ injection interface that supports both raising and lowering and declare its availability via a KVM_CAP. Don't forget to make it extensible (flags field) so that future requirements can be added without breaking existing users.

Or much easier (this is what PowerPC is doing): Define irq values in a way that they include a raise/lower flag.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#20 lore raw

thanks, I will fix this for next version.

Quoted 39 lines · Jan Kiszka
Quoted 24 lines · Jan Kiszka
Quoted 5 lines · Christoffer Dall

Targets KVM support for Cortex A-15 processors.

Contains no real functionality but all the framework components, make files, header files and some tracing functionality.
---

...

include/linux/kvm.h struct kvm_translation { · line 314

Quoted 10 lines
include/linux/kvm.h +1 -0
index ea2dc1a..d2ab07e 100644
@@ -310,6 +310,7 @@ struct kvm_translation {
  struct kvm_interrupt {
      /* in */
      __u32 irq;
+    __u8  raise;
  };

This touches an existing ABI and corrupts the definition of KVM_INTERRUPT IOCTL. The might exist jurisdictions considering this a capital crime. :)

Quoted 4 lines

You rather have to define a new CPU IRQ injection interface that supports both raising and lowering and declare its availability via a KVM_CAP. Don't forget to make it extensible (flags field) so that future requirements can be added without breaking existing users.

Or much easier (this is what PowerPC is doing): Define irq values in a way that they include a raise/lower flag.

Jan

--
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux

#21 lore raw
Quoted 1 line · Christoffer Dall

thanks, I will fix this for next version.

Please be prepared that we might want to model the API as well, so I'd propose you send out an RFC that patches Documentation/kvm with the respective API documentation so we can have some constructive influence :).

Currently, on book3s at least, PPC simply uses the irq field to indicate raise/lower since there's only a single "external interrupt" line that the CPU sees. All other dispatching happens in user space. I don't know if you could use the same model or of you need specific table offsets for different external interrupt vectors.

Alex

#22 lore raw
In reply to Jan Kiszka
Quoted 25 lines · Jan Kiszka
Quoted 24 lines · Jan Kiszka
Quoted 5 lines · Christoffer Dall

Targets KVM support for Cortex A-15 processors.

Contains no real functionality but all the framework components, make files, header files and some tracing functionality.
---

...

include/linux/kvm.h struct kvm_translation { · line 314

Quoted 10 lines
include/linux/kvm.h +1 -0
index ea2dc1a..d2ab07e 100644
@@ -310,6 +310,7 @@ struct kvm_translation {
 struct kvm_interrupt {
 	/* in */
 	__u32 irq;
+	__u8  raise;
 };

This touches an existing ABI and corrupts the definition of KVM_INTERRUPT IOCTL. The might exist jurisdictions considering this a capital crime. :)

Quoted 7 lines
Quoted 4 lines

You rather have to define a new CPU IRQ injection interface that supports both raising and lowering and declare its availability via a KVM_CAP. Don't forget to make it extensible (flags field) so that future requirements can be added without breaking existing users.

Or much easier (this is what PowerPC is doing): Define irq values in a way that they include a raise/lower flag.

It's not quite what PPC does. On PPC we have constant magic values for "irq" that mean "raise external interrupt" and "lower external interrupt". I like the idea with the mask though. It allows you to still have 31 bits of irq number information :)

Alex

#23 lore raw
In reply to Jan Kiszka
Quoted 7 lines · Jan Kiszka
Quoted 7 lines
Quoted 6 lines

@@ -310,6 +310,7 @@ struct kvm_translation {
struct kvm_interrupt {
/* in */
__u32 irq;
+ __u8 raise;
};

Quoted 6 lines
Quoted 6 lines

This touches an existing ABI and corrupts the definition of KVM_INTERRUPT IOCTL. The might exist jurisdictions considering this a capital crime. :)

You rather have to define a new CPU IRQ injection interface that supports both raising and lowering

This is KVM_IRQ_LINE:

Quoted 6 lines

and declare its availability via a

Quoted 2 lines

KVM_CAP. Don't forget to make it extensible (flags field) so that future requirements can be added without breaking existing users.

Or much easier (this is what PowerPC is doing): Define irq values in a way that they include a raise/lower flag.

Much easier and much horribler.

Signature · 1 line
error compiling committee.c: too many arguments to function
#24 lore raw
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Jan Kiszka
Quoted 7 lines
Quoted 6 lines

@@ -310,6 +310,7 @@ struct kvm_translation {

  struct kvm_interrupt {
      /* in */
      __u32 irq;

+ __u8 raise;
};

Quoted 9 lines
Quoted 6 lines
Quoted 6 lines

This touches an existing ABI and corrupts the definition of KVM_INTERRUPT IOCTL. The might exist jurisdictions considering this a capital crime. :)

You rather have to define a new CPU IRQ injection interface that supports both raising and lowering

This is KVM_IRQ_LINE:

It's so far associated with in-kernel irqchip input pins, not with raising CPU IRQs.

Quoted 12 lines
Quoted 9 lines

and declare its availability via a

Quoted 1 line

KVM_CAP. Don't forget to make it extensible (flags field) so that

future

Quoted 1 line

requirements can be added without breaking existing users.

Or much easier (this is what PowerPC is doing): Define irq values in a way that they include a raise/lower flag.

Much easier and much horribler.

Less horrible than overloading KVM_IRQ_LINE IMHO. The semantics of kvm_interrupt::irq are in arch hands anyway.

Jan

#25 lore raw
Quoted 13 lines · Jan Kiszka
Quoted 12 lines · Avi Kivity
Quoted 11 lines · Jan Kiszka
Quoted 11 lines
Quoted 6 lines
  @@ -310,6 +310,7 @@ struct kvm_translation {
   struct kvm_interrupt {
       /* in */
       __u32 irq;
  +    __u8  raise;
   };

This touches an existing ABI and corrupts the definition of KVM_INTERRUPT IOCTL. The might exist jurisdictions considering this a capital crime. :)

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

You rather have to define a new CPU IRQ injection interface that supports both raising and lowering

This is KVM_IRQ_LINE:

It's so far associated with in-kernel irqchip input pins, not with raising CPU IRQs.

It's up to the architecture to define what it's connected to.

Note that with KVM_SET_GSI_ROUTING (bad name for ARM...) we can even choose if an irq line is connected to a kernel-emulated interrupt controller or to the core's irq input.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

and declare its availability via a

Quoted 1 line

KVM_CAP. Don't forget to make it extensible (flags field) so that

future

Quoted 1 line

requirements can be added without breaking existing users.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Or much easier (this is what PowerPC is doing): Define irq values in a way that they include a raise/lower flag.

Much easier and much horribler.

Less horrible than overloading KVM_IRQ_LINE IMHO. The semantics of kvm_interrupt::irq are in arch hands anyway.

Something that can be raised or lowered is an irq line.

Signature · 1 line
error compiling committee.c: too many arguments to function
#26 lore raw
Quoted 21 lines · Avi Kivity
Quoted 20 lines · Jan Kiszka
Quoted 10 lines · Avi Kivity
Quoted 9 lines · Jan Kiszka
Quoted 9 lines
Quoted 6 lines
  @@ -310,6 +310,7 @@ struct kvm_translation {
   struct kvm_interrupt {
       /* in */
       __u32 irq;
  +    __u8  raise;
   };

This touches an existing ABI and corrupts the definition of KVM_INTERRUPT IOCTL. The might exist jurisdictions considering

this a

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

capital crime. :)

You rather have to define a new CPU IRQ injection interface that supports both raising and lowering

This is KVM_IRQ_LINE:

Quoted 8 lines
Quoted 2 lines

It's so far associated with in-kernel irqchip input pins, not with raising CPU IRQs.

It's up to the architecture to define what it's connected to.

Note that with KVM_SET_GSI_ROUTING (bad name for ARM...) we can even choose if an irq line is connected to a kernel-emulated interrupt controller or to the core's irq input.

Makes some sense: Add KVM_IRQ_ROUTING_CPU, and kvm_irq_routing_entry's union would require some struct kvm_irq_routing_cpu containing the target identifier.

However, I would recommend to carefully check the generic irq routing bits before use - if they still contain some x86/ia64 specifics or unwanted irqchip_in_kernel().

Jan

#27 lore raw
Quoted 8 lines · Jan Kiszka
Quoted 4 lines

Note that with KVM_SET_GSI_ROUTING (bad name for ARM...) we can even choose if an irq line is connected to a kernel-emulated interrupt controller or to the core's irq input.

Makes some sense: Add KVM_IRQ_ROUTING_CPU, and kvm_irq_routing_entry's union would require some struct kvm_irq_routing_cpu containing the target identifier.

Right. Note it would be the default, so no need to implement KVM_SET_GSI_ROUTING just yet.

An additional advantage is that this is a vm ioctl, not a vcpu ioctl, so no need to interrupt the vcpu thread in userspace in order to queue an interrupt. Of course, it still happens in the kernel, but it's easier for userspace to implement its device model this way.

Quoted 3 lines

However, I would recommend to carefully check the generic irq routing bits before use - if they still contain some x86/ia64 specifics or unwanted irqchip_in_kernel().

Most likely yes.

Signature · 1 line
error compiling committee.c: too many arguments to function
#28 lore raw
Quoted 10 lines · Avi Kivity
Quoted 8 lines · Jan Kiszka
Quoted 4 lines

Note that with KVM_SET_GSI_ROUTING (bad name for ARM...) we can even choose if an irq line is connected to a kernel-emulated interrupt controller or to the core's irq input.

Makes some sense: Add KVM_IRQ_ROUTING_CPU, and kvm_irq_routing_entry's union would require some struct kvm_irq_routing_cpu containing the target identifier.

Quoted 7 lines

Right. Note it would be the default, so no need to implement KVM_SET_GSI_ROUTING just yet.

An additional advantage is that this is a vm ioctl, not a vcpu ioctl, so no need to interrupt the vcpu thread in userspace in order to queue an interrupt. Of course, it still happens in the kernel, but it's easier for userspace to implement its device model this way.

So supporting this over existing archs would have some benefits as well, though a bit smaller if in-kernel irqchip is already implemented.

Jan

#29 lore raw
Quoted 7 lines · Jan Kiszka
Quoted 4 lines

An additional advantage is that this is a vm ioctl, not a vcpu ioctl, so no need to interrupt the vcpu thread in userspace in order to queue an interrupt. Of course, it still happens in the kernel, but it's easier for userspace to implement its device model this way.

So supporting this over existing archs would have some benefits as well, though a bit smaller if in-kernel irqchip is already implemented.

Yes, except for s390, of course.

Signature · 1 line
error compiling committee.c: too many arguments to function
#30 lore raw
In reply to Jan Kiszka
Quoted 14 lines · Jan Kiszka
Quoted 13 lines · Avi Kivity
Quoted 8 lines · Jan Kiszka
Quoted 4 lines

 Note that with KVM_SET_GSI_ROUTING (bad name for ARM...) we can even choose if an irq line is connected to a kernel-emulated interrupt controller or to the core's irq input.

Makes some sense: Add KVM_IRQ_ROUTING_CPU, and kvm_irq_routing_entry's union would require some struct kvm_irq_routing_cpu containing the target identifier.

Right.  Note it would be the default, so no need to implement KVM_SET_GSI_ROUTING just yet.

Quoted 8 lines
Quoted 4 lines

An additional advantage is that this is a vm ioctl, not a vcpu ioctl, so no need to interrupt the vcpu thread in userspace in order to queue an interrupt.  Of course, it still happens in the kernel, but it's easier for userspace to implement its device model this way.

So supporting this over existing archs would have some benefits as well, though a bit smaller if in-kernel irqchip is already implemented.

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

#31 lore raw
Quoted 6 lines · Christoffer Dall
Quoted 6 lines
Quoted 5 lines

An additional advantage is that this is a vm ioctl, not a vcpu ioctl, so no need to interrupt the vcpu thread in userspace in order to queue an interrupt. Of course, it still happens in the kernel, but it's easier for userspace to implement its device model this way.

Quoted 6 lines
Quoted 3 lines

So supporting this over existing archs would have some benefits as well, though a bit smaller if in-kernel irqchip is already implemented.

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

Signature · 1 line
error compiling committee.c: too many arguments to function
#32 lore raw
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Christoffer Dall
Quoted 6 lines
Quoted 5 lines

An additional advantage is that this is a vm ioctl, not a vcpu ioctl, so no need to interrupt the vcpu thread in userspace in order to queue an interrupt. Of course, it still happens in the kernel, but it's easier for userspace to implement its device model this way.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

So supporting this over existing archs would have some benefits as well, though a bit smaller if in-kernel irqchip is already implemented.

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

An in-kernel MPIC implementation is coming for PPC, so I don't see any reason to switch from something that works now.

Alex

#33 lore raw
Quoted 7 lines · Alexander Graf
Quoted 5 lines
Quoted 3 lines

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

An in-kernel MPIC implementation is coming for PPC, so I don't see any reason to switch from something that works now.

Right, this is spilled milk.

Does the ppc qemu implementation raise KVM_INTERRUPT solely from the vcpu thread?

Signature · 1 line
error compiling committee.c: too many arguments to function
#34 lore raw
Quoted 5 lines · Avi Kivity
Quoted 4 lines · Alexander Graf
Quoted 4 lines
Quoted 3 lines

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

An in-kernel MPIC implementation is coming for PPC, so I don't see any reason to switch from something that works now.

Right, this is spilled milk.

Does the ppc qemu implementation raise KVM_INTERRUPT solely from the vcpu thread?

Well, without iothread it used to obviously. Now that we have an iothread, it calls ioctl(KVM_INTERRUPT) from a separate thread. The code also doesn't forcefully wake up the vcpu thread, so yes, I think here's a chance for at least delaying interrupt delivery. Chances are pretty slim we don't get out of the vcpu thread at all :).

Alex

#35 lore raw
Quoted 10 lines · Alexander Graf
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Alexander Graf
Quoted 5 lines
Quoted 3 lines

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

An in-kernel MPIC implementation is coming for PPC, so I don't see any reason to switch from something that works now.

Right, this is spilled milk.

Does the ppc qemu implementation raise KVM_INTERRUPT solely from the vcpu thread?

Well, without iothread it used to obviously. Now that we have an iothread, it calls ioctl(KVM_INTERRUPT) from a separate thread. The code also doesn't forcefully wake up the vcpu thread, so yes, I think here's a chance for at least delaying interrupt delivery. Chances are pretty slim we don't get out of the vcpu thread at all :).

There are good chances to run into a deadlock when calling a per-vcpu IOCTL over a foreign context: calling thread holds qemu_mutex and blocks on kvm_mutex inside the kernel, target vcpu is running endless guest loop, holding kvm_mutex, all other qemu threads will sooner or later block on the global lock. That's at least one pattern you can get on x86 (we had a few of such bugs in the past).

Jan

#36 lore raw
Quoted 17 lines · Jan Kiszka
Quoted 16 lines · Alexander Graf
Quoted 12 lines · Avi Kivity
Quoted 7 lines · Alexander Graf
Quoted 5 lines
Quoted 3 lines

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

An in-kernel MPIC implementation is coming for PPC, so I don't see any reason to switch from something that works now.

Right, this is spilled milk.

Does the ppc qemu implementation raise KVM_INTERRUPT solely from the vcpu thread?

Quoted 8 lines
Quoted 1 line

Well, without iothread it used to obviously. Now that we have an iothread, it calls ioctl(KVM_INTERRUPT) from a separate thread. The code also doesn't forcefully wake up the vcpu thread, so yes, I think here's a chance for at least delaying interrupt delivery. Chances are pretty slim we don't get out of the vcpu thread at all :).

There are good chances to run into a deadlock when calling a per-vcpu IOCTL over a foreign context: calling thread holds qemu_mutex and blocks on kvm_mutex inside the kernel, target vcpu is running endless guest loop, holding kvm_mutex, all other qemu threads will sooner or later block on the global lock. That's at least one pattern you can get on x86 (we had a few of such bugs in the past).

Any recommendations? Should we just signal the main thread when we want to inject an interrupt?

Alex

#37 lore raw
Quoted 22 lines · Alexander Graf
Quoted 19 lines · Jan Kiszka
Quoted 17 lines · Alexander Graf
Quoted 5 lines · Avi Kivity
Quoted 4 lines · Alexander Graf
Quoted 4 lines
Quoted 3 lines

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

An in-kernel MPIC implementation is coming for PPC, so I don't see any reason to switch from something that works now.

Right, this is spilled milk.

Does the ppc qemu implementation raise KVM_INTERRUPT solely from the vcpu thread?

Well, without iothread it used to obviously. Now that we have an iothread, it calls ioctl(KVM_INTERRUPT) from a separate thread. The code also doesn't forcefully wake up the vcpu thread, so yes, I think here's a chance for at least delaying interrupt delivery. Chances are pretty slim we don't get out of the vcpu thread at all :).

Quoted 8 lines
Quoted 6 lines

There are good chances to run into a deadlock when calling a per-vcpu IOCTL over a foreign context: calling thread holds qemu_mutex and blocks on kvm_mutex inside the kernel, target vcpu is running endless guest loop, holding kvm_mutex, all other qemu threads will sooner or later block on the global lock. That's at least one pattern you can get on x86 (we had a few of such bugs in the past).

Any recommendations? Should we just signal the main thread when we want to inject an interrupt?

Yep. That's also what x86 does (when using user space irqchips).

Jan

#38 lore raw
Quoted 30 lines · Jan Kiszka
Quoted 29 lines · Alexander Graf
Quoted 25 lines · Jan Kiszka
Quoted 10 lines · Alexander Graf
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Alexander Graf
Quoted 5 lines
Quoted 3 lines

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

An in-kernel MPIC implementation is coming for PPC, so I don't see any reason to switch from something that works now.

Right, this is spilled milk.

Does the ppc qemu implementation raise KVM_INTERRUPT solely from the vcpu thread?

Well, without iothread it used to obviously. Now that we have an iothread, it calls ioctl(KVM_INTERRUPT) from a separate thread. The code also doesn't forcefully wake up the vcpu thread, so yes, I think here's a chance for at least delaying interrupt delivery. Chances are pretty slim we don't get out of the vcpu thread at all :).

There are good chances to run into a deadlock when calling a per-vcpu IOCTL over a foreign context: calling thread holds qemu_mutex and blocks on kvm_mutex inside the kernel, target vcpu is running endless guest loop, holding kvm_mutex, all other qemu threads will sooner or later block on the global lock. That's at least one pattern you can get on x86 (we had a few of such bugs in the past).

Quoted 3 lines
Quoted 1 line

Any recommendations? Should we just signal the main thread when we want to inject an interrupt?

Yep. That's also what x86 does (when using user space irqchips).

Hrm, ok :). I guess the main reason we don't see major issues is that

1) people don't use iothread too often yet - is it even enabled by default?
2) the decrementor interrupt happens in-kernel, so timer interrupts still arrive properly

Alex

#39 lore raw
Quoted 33 lines · Alexander Graf
Quoted 30 lines · Jan Kiszka
Quoted 29 lines · Alexander Graf
Quoted 25 lines · Jan Kiszka
Quoted 10 lines · Alexander Graf
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Alexander Graf
Quoted 5 lines
Quoted 3 lines

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

An in-kernel MPIC implementation is coming for PPC, so I don't see any reason to switch from something that works now.

Right, this is spilled milk.

Does the ppc qemu implementation raise KVM_INTERRUPT solely from the vcpu thread?

Well, without iothread it used to obviously. Now that we have an iothread, it calls ioctl(KVM_INTERRUPT) from a separate thread. The code also doesn't forcefully wake up the vcpu thread, so yes, I think here's a chance for at least delaying interrupt delivery. Chances are pretty slim we don't get out of the vcpu thread at all :).

There are good chances to run into a deadlock when calling a per-vcpu IOCTL over a foreign context: calling thread holds qemu_mutex and blocks on kvm_mutex inside the kernel, target vcpu is running endless guest loop, holding kvm_mutex, all other qemu threads will sooner or later block on the global lock. That's at least one pattern you can get on x86 (we had a few of such bugs in the past).

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Any recommendations? Should we just signal the main thread when we want to inject an interrupt?

Yep. That's also what x86 does (when using user space irqchips).

Hrm, ok :). I guess the main reason we don't see major issues is that

1) people don't use iothread too often yet - is it even enabled by default?

Nope (unless you use qemu-kvm.git next).

Quoted 1 line

2) the decrementor interrupt happens in-kernel, so timer interrupts still arrive properly

Means PPC periodically returns to user space?

Jan

#40 lore raw
Quoted 36 lines · Jan Kiszka
Quoted 35 lines · Alexander Graf
Quoted 32 lines · Jan Kiszka
Quoted 30 lines · Alexander Graf
Quoted 17 lines · Jan Kiszka
Quoted 16 lines · Alexander Graf
Quoted 12 lines · Avi Kivity
Quoted 7 lines · Alexander Graf
Quoted 5 lines
Quoted 3 lines

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

An in-kernel MPIC implementation is coming for PPC, so I don't see any reason to switch from something that works now.

Right, this is spilled milk.

Does the ppc qemu implementation raise KVM_INTERRUPT solely from the vcpu thread?

Quoted 8 lines
Quoted 1 line

Well, without iothread it used to obviously. Now that we have an iothread, it calls ioctl(KVM_INTERRUPT) from a separate thread. The code also doesn't forcefully wake up the vcpu thread, so yes, I think here's a chance for at least delaying interrupt delivery. Chances are pretty slim we don't get out of the vcpu thread at all :).

There are good chances to run into a deadlock when calling a per-vcpu IOCTL over a foreign context: calling thread holds qemu_mutex and blocks on kvm_mutex inside the kernel, target vcpu is running endless guest loop, holding kvm_mutex, all other qemu threads will sooner or later block on the global lock. That's at least one pattern you can get on x86 (we had a few of such bugs in the past).

Any recommendations? Should we just signal the main thread when we want to inject an interrupt?

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Yep. That's also what x86 does (when using user space irqchips).

Hrm, ok :). I guess the main reason we don't see major issues is that

1) people don't use iothread too often yet - is it even enabled by default?

Nope (unless you use qemu-kvm.git next).

Any plans on finally doing that step? Code that isn't enabled by default is pretty prone to not be tested ;). It's a good way to slowly move code upstream, stabilize it there and then finally have it enabled by default. But I don't think this process should last more than 1/2 year. And IIRC with iothread, we're way past that point.

Quoted 3 lines
Quoted 1 line

2) the decrementor interrupt happens in-kernel, so timer interrupts still arrive properly

Means PPC periodically returns to user space?

Hrm. No. It stays in kernel space even more. But at least it continues to live without the need for a timer interrupt from user space, so an endless loop doesn't completely stall the guest. I see your point though.

With VGA we're good thanks to the dirty bitmap update. So we get quite a good number of exits from guest context. -nographic might be problematic though. I don't see how a new key event or a new packet on the network could easily arrive inside the guest there. Sigh.

I'll take a look at it when I get my head around it. Thanks a lot for the insight :).

Alex

#41 lore raw
Quoted 41 lines · Alexander Graf
Quoted 38 lines · Jan Kiszka
Quoted 37 lines · Alexander Graf
Quoted 33 lines · Jan Kiszka
Quoted 22 lines · Alexander Graf
Quoted 19 lines · Jan Kiszka
Quoted 17 lines · Alexander Graf
Quoted 5 lines · Avi Kivity
Quoted 4 lines · Alexander Graf
Quoted 4 lines
Quoted 3 lines

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

An in-kernel MPIC implementation is coming for PPC, so I don't see any reason to switch from something that works now.

Right, this is spilled milk.

Does the ppc qemu implementation raise KVM_INTERRUPT solely from the vcpu thread?

Well, without iothread it used to obviously. Now that we have an iothread, it calls ioctl(KVM_INTERRUPT) from a separate thread. The code also doesn't forcefully wake up the vcpu thread, so yes, I think here's a chance for at least delaying interrupt delivery. Chances are pretty slim we don't get out of the vcpu thread at all :).

Quoted 8 lines
Quoted 6 lines

There are good chances to run into a deadlock when calling a per-vcpu IOCTL over a foreign context: calling thread holds qemu_mutex and blocks on kvm_mutex inside the kernel, target vcpu is running endless guest loop, holding kvm_mutex, all other qemu threads will sooner or later block on the global lock. That's at least one pattern you can get on x86 (we had a few of such bugs in the past).

Any recommendations? Should we just signal the main thread when we want to inject an interrupt?

Yep. That's also what x86 does (when using user space irqchips).

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Hrm, ok :). I guess the main reason we don't see major issues is that

1) people don't use iothread too often yet - is it even enabled by default?

Nope (unless you use qemu-kvm.git next).

Any plans on finally doing that step? Code that isn't enabled by default is pretty prone to not be tested ;). It's a good way to slowly move code upstream, stabilize it there and then finally have it enabled by default. But I don't think this process should last more than 1/2 year. And IIRC with iothread, we're way past that point.

That's getting a bit off-topic for this thread now:

The good news is that 'next' will become 'master' fairly soon (unless some regression is found), and then we are using QEMU upstream's iothread code in qemu-kvm. By default.

For upstream, we are still facing TCG performance regressions in iothread mode, thus it's still default off. $Someone would have to sort them out, and then we could flip defaults there as well.

Jan

#42 lore raw
In reply to Alexander Graf
Quoted 21 lines · Alexander Graf
Quoted 19 lines · Jan Kiszka
Quoted 17 lines · Alexander Graf
Quoted 5 lines · Avi Kivity
Quoted 4 lines · Alexander Graf
Quoted 4 lines
Quoted 3 lines

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

An in-kernel MPIC implementation is coming for PPC, so I don't see any reason to switch from something that works now.

Right, this is spilled milk.

Does the ppc qemu implementation raise KVM_INTERRUPT solely from the vcpu thread?

Well, without iothread it used to obviously. Now that we have an iothread, it calls ioctl(KVM_INTERRUPT) from a separate thread. The code also doesn't forcefully wake up the vcpu thread, so yes, I think here's a chance for at least delaying interrupt delivery. Chances are pretty slim we don't get out of the vcpu thread at all :).

Quoted 9 lines
Quoted 6 lines

There are good chances to run into a deadlock when calling a per-vcpu IOCTL over a foreign context: calling thread holds qemu_mutex and blocks on kvm_mutex inside the kernel, target vcpu is running endless guest loop, holding kvm_mutex, all other qemu threads will sooner or later block on the global lock. That's at least one pattern you can get on x86 (we had a few of such bugs in the past).

Any recommendations? Should we just signal the main thread when we want to inject an interrupt?

Signal the vcpu thread, of course. There's on_vcpu (or on_cpu, don't know how it's called today) for that.

Signature · 1 line
error compiling committee.c: too many arguments to function
#43 lore raw
In reply to Alexander Graf
Quoted 9 lines · Alexander Graf
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Alexander Graf
Quoted 5 lines
Quoted 3 lines

Could you elaborate what you mean here? I'm not really following. Are you suggesting a new arch-generic interface? (Pardon my ignorance).

Using KVM_IRQ_LINE everywhere except s390, not just in x86 and ARM.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

An in-kernel MPIC implementation is coming for PPC, so I don't see any reason to switch from something that works now.

Right, this is spilled milk.

Does the ppc qemu implementation raise KVM_INTERRUPT solely from the vcpu thread?

Well, without iothread it used to obviously. Now that we have an iothread, it calls ioctl(KVM_INTERRUPT) from a separate thread.

That's 100% broken, as api.txt states. Besides consistency, this is to allow an eventual move to a syscall interface where the vcpu is derived from current rather than an fd parameter.

Quoted 1 line

The code also doesn't forcefully wake up the vcpu thread, so yes, I think here's a chance for at least delaying interrupt delivery. Chances are pretty slim we don't get out of the vcpu thread at all :).

Maybe slim, but still a major bug.

Signature · 1 line
error compiling committee.c: too many arguments to function
#44 lore raw
In reply to Jan Kiszka
Quoted 31 lines · Jan Kiszka
Quoted 21 lines · Avi Kivity
Quoted 20 lines · Jan Kiszka
Quoted 10 lines · Avi Kivity
Quoted 9 lines · Jan Kiszka

 >>   @@ -310,6 +310,7 @@ struct kvm_translation {
 >>    struct kvm_interrupt {
 >>        /* in */
 >>        __u32 irq;
 >>   +    __u8  raise;
 >>    };
 >
 >   This touches an existing ABI and corrupts the definition of >   KVM_INTERRUPT IOCTL. The might exist jurisdictions considering

this a

Quoted 7 lines
Quoted 4 lines

 >   capital crime. :)
 >
 >   You rather have to define a new CPU IRQ injection interface that >   supports both raising and lowering

 This is KVM_IRQ_LINE:

Quoted 8 lines
Quoted 2 lines

It's so far associated with in-kernel irqchip input pins, not with raising CPU IRQs.

It's up to the architecture to define what it's connected to.

Note that with KVM_SET_GSI_ROUTING (bad name for ARM...) we can even choose if an irq line is connected to a kernel-emulated interrupt controller or to the core's irq input.

Quoted 8 lines

Makes some sense: Add KVM_IRQ_ROUTING_CPU, and kvm_irq_routing_entry's union would require some struct kvm_irq_routing_cpu containing the target identifier.

However, I would recommend to carefully check the generic irq routing bits before use - if they still contain some x86/ia64 specifics or unwanted irqchip_in_kernel().

OK, so let me try to get this straight.

We all agree that ruining the ABI is crazy - sorry about even putting that out there.

On ARM, we are talking about IRQs and FIQs, both of which can be lowered and raised. In other words, four values.

But instead of this, you want to use KVM_IRQ_LINE and just assume one CPU to begin with and always assert/deassert the interrupts on that CPU and later, with SMP support, you want to use KVM_SET_GSI_ROUTING to control which CPU gets the interrupt - even though GSI is a non-existing concept for ARM? (Also, I could not seem to find any use of GSI_ROUTING in current upstream QEMU, but I may be missing something here?).

I suggest I simply use a flag in the irq field on the kvm_interrupt struct as suggested by Jan, for now, and if we start emulating GICs inside the kernel for ARM we can go the extra mile at that point. IMHO, I think the semantics of actually raising an interrup line on the VCPU, as opposed to the VM, when it's CPU interrupt we are talking about is equally important.

#45 lore raw
Quoted 2 lines · Christoffer Dall

On ARM, we are talking about IRQs and FIQs, both of which can be lowered and raised. In other words, four values.

Two lines per cpu, each of which can be raised or lowered.

Quoted 7 lines

But instead of this, you want to use KVM_IRQ_LINE and just assume one CPU to begin with and always assert/deassert the interrupts on that CPU and later, with SMP support, you want to use KVM_SET_GSI_ROUTING to control which CPU gets the interrupt - even though GSI is a non-existing concept for ARM? (Also, I could not seem to find any use of GSI_ROUTING in current upstream QEMU, but I may be missing something here?).

Almost. vcpu N's IRQ -> KVM_IRQ_LINE(N*2, level). vcpu N's FIQ -> KVM_IRQ_LINE(N*2+1, level), + documentation somewhere.

Quoted 6 lines

I suggest I simply use a flag in the irq field on the kvm_interrupt struct as suggested by Jan, for now, and if we start emulating GICs inside the kernel for ARM we can go the extra mile at that point. IMHO, I think the semantics of actually raising an interrup line on the VCPU, as opposed to the VM, when it's CPU interrupt we are talking about is equally important.

When you implement an interrupt controller, you can use KVM_SET_GSI_ROUTING to change the meaning of the parameter to KVM_IRQ_LINE to point to the interrupt controllers.

Signature · 1 line
error compiling committee.c: too many arguments to function
#46 lore raw
In reply to Christoffer Dall
Quoted 24 lines · Christoffer Dall

Targets KVM support for Cortex A-15 processors.

Contains no real functionality but all the framework components, make files, header files and some tracing functionality.

arch/arm/include/asm/kvm.h new file +19 -0
+
+struct kvm_regs {
+	__u32 regs0_7[8];	/* Unbanked regs. (r0 - r7)	   */
+	__u32 fiq_regs8_12[5];	/* Banked fiq regs. (r8 - r12)	   */
+	__u32 usr_regs8_12[5];	/* Banked usr registers (r8 - r12) */
+	__u32 reg13[6];		/* Banked r13, indexed by MODE_	   */
+	__u32 reg14[6];		/* Banked r13, indexed by MODE_	   */
+	__u32 reg15;
+	__u32 cpsr;
+	__u32 spsr[5];		/* Banked SPSR,  indexed by MODE_  */
+	struct {
+		__u32 c2_base0;
+		__u32 c2_base1;
+		__u32 c3_dacr;
+	} cp15;
+
+};
+
+struct kvm_sregs {

arch/arm/include/asm/kvm.h line 63

Quoted 10 lines
arch/arm/include/asm/kvm.h new file +10 -0
+};
+
+struct kvm_fpu {
+};
+
+struct kvm_guest_debug_arch {
+};
+
+struct kvm_debug_exit_arch {
+};

Presumably, to be filled in later?

Quoted 15 lines
arch/arm/include/asm/kvm_emulate.h new file +15 -0
+
+/* Get vcpu register for current mode */
+#define vcpu_reg(_vcpu, _reg_num) \
+	(*kvm_vcpu_reg((_vcpu), _reg_num, vcpu_mode(_vcpu)))
+
+/* Get vcpu register for specific mode */
+#define vcpu_reg_m(_vcpu, _reg_num, _mode) \
+	(*kvm_vcpu_reg(_vcpu, _reg_num, _mode))
+
+#define vcpu_cpsr(_vcpu) \
+	(_vcpu->arch.regs.cpsr)
+
+/* Get vcpu SPSR for current mode */
+#define vcpu_spsr(_vcpu) \
+	kvm_vcpu_spsr(_vcpu, vcpu_mode(_vcpu))

arch/arm/include/asm/kvm_emulate.h line 87

Quoted 10 lines
arch/arm/include/asm/kvm_emulate.h new file +10 -0
+
+/* Get vcpu SPSR for specific mode */
+#define vcpu_spsr_m(_vcpu, _mode) \
+	kvm_vcpu_spsr(_vcpu, _mode)
+
+#define MODE_HAS_SPSR(_vcpu) \
+	 ((vcpu_mode(_vcpu))<  MODE_USR)
+
+#define VCPU_MODE_PRIV(_vcpu) \
+	(((vcpu_mode(_vcpu)) == MODE_USR) ? 0 : 1)

Please use static inlines. Yes, you'll need more helpers to set registers, but it's worth it, especially as some macros evaluate an argument multiple times.

Quoted 6 lines
arch/arm/kvm/Kconfig new file +6 -0
+if VIRTUALIZATION
+
+config KVM
+	bool "Kernel-based Virtual Machine (KVM) support"
+	select PREEMPT_NOTIFIERS
+	select ANON_INODES

arch/arm/kvm/Kconfig line 32

Quoted 10 lines
arch/arm/kvm/Kconfig new file +10 -0
+	select KVM_ARM_HOST
+	select KVM_MMIO
+	---help---
+	  Support hosting virtualized guest machines. You will also
+	  need to select one or more of the processor modules below.
+
+	  This module provides access to the hardware capabilities through
+	  a character device node named /dev/kvm.
+
+	  If unsure, say N.

I see you can't support a modular build, which is a pity.

Quoted 38 lines
arch/arm/kvm/arm.c new file +38 -0
+
+static int k_show(struct seq_file *m, void *v)
+{
+	print_kvm_debug_info(&seq_printf, m);
+	return 0;
+}
+
+static void *k_start(struct seq_file *m, loff_t *pos)
+{
+	return *pos<  1 ? (void *)1 : NULL;
+}
+
+static void *k_next(struct seq_file *m, void *v, loff_t *pos)
+{
+	++*pos;
+	return NULL;
+}
+
+static void k_stop(struct seq_file *m, void *v)
+{
+}
+
+static const struct seq_operations kvmproc_op = {
+	.start	= k_start,
+	.next	= k_next,
+	.stop	= k_stop,
+	.show	= k_show
+};
+
+static int kvm_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file,&kvmproc_op);
+}
+
+static const struct file_operations proc_kvm_operations = {
+	.open		= kvm_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,

arch/arm/kvm/arm.c line 355

Quoted 10 lines
arch/arm/kvm/arm.c new file +10 -0
+	.release	= seq_release,
+};
+
+static int arm_init(void)
+{
+	int rc = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE);
+	if (rc == 0)
+		proc_create("kvm", 0, NULL,&proc_kvm_operations);
+	return rc;
+}

/proc is frowned upon these days. Is there no better place for this?+

Quoted 38 lines
arch/arm/kvm/arm_emulate.c new file +38 -0
+/*
+ * Return a pointer to the register number valid in the specified mode of
+ * the virtual CPU.
+ */
+u32* kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode)
+{
+	struct kvm_vcpu_regs *regs;
+	u8 reg_idx;
+	BUG_ON(reg_num>  15);
+
+	regs =&vcpu->arch.regs;
+
+	/* The PC is trivial */
+	if (reg_num == 15)
+		return&(regs->pc);
+
+	/* Non-banked registers */
+	if (reg_num<  8)
+		return&(regs->usr_regs[reg_num]);
+
+	/* Banked registers r13 and r14 */
+	if (reg_num>= 13) {
+		reg_idx = reg_num - 13; /* 0=r13 and 1=r14 */
+		switch (mode) {
+		case MODE_FIQ:
+			return&(regs->fiq_regs[reg_idx + 5]);
+		case MODE_IRQ:
+			return&(regs->irq_regs[reg_idx]);
+		case MODE_SVC:
+			return&(regs->svc_regs[reg_idx]);
+		case MODE_ABT:
+			return&(regs->abt_regs[reg_idx]);
+		case MODE_UND:
+			return&(regs->und_regs[reg_idx]);
+		case MODE_USR:
+		case MODE_SYS:
+			return&(regs->usr_regs[reg_idx]);
+		}

arch/arm/kvm/arm_emulate.c line 66

Quoted 10 lines
arch/arm/kvm/arm_emulate.c new file +10 -0
+	}
+
+	/* Banked FIQ registers r8-r12 */
+	if (reg_num>= 8&&  reg_num<= 12) {
+		if (mode == MODE_FIQ) {
+			reg_idx = reg_num - 8; /* 0=r8, ..., 4=r12 */
+			return&(regs->fiq_regs[reg_idx]);
+		} else
+			return&(regs->usr_regs[reg_num]);
+	}

You could have a static 2D array indexed by mode and register number, returning an offsetof() into the vcpu structure.

Quoted 83 lines
arch/arm/kvm/arm_emulate.c new file +4 -0
+
+	BUG();
+	return NULL;
+}
arch/arm/kvm/trace.c new file +72 -0
new file mode 100644
index 0000000..8ea1155
@@ -0,0 +1,436 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+#include<linux/types.h>
+#include<linux/kvm_types.h>
+#include<linux/kvm_host.h>
+
+#include<asm/kvm_emulate.h>
+#include "trace.h"
+
+
+/******************************************************************************
+ * Simple event counting
+ */
+
+struct kvm_event {
+	unsigned long long cnt;
+	char *descr;
+};
+
+static struct kvm_event kvm_eventc_log[KVM_EVENTC_ITEMS] =
+{
+	{ 0, "switch to guest" },
+	{ 0, "exit from guest" },
+	{ 0, "Block VCPU" },
+	{ 0, "Exit to QEMU for IRQ window" },
+	{ 0, "Switch VCPU mode" },
+	{ 0, "VCPU IRQs on" },
+	{ 0, "VCPU IRQs off" },
+	{ 0, "Wait-for-interrupts" },
+	{ 0, "Flush shadow page table" },
+	{ 0, "Virtual TTBR change" },
+	{ 0, "Read guest page table entry" },
+	{ 0, "Map GVA to GFN" },
+	{ 0, "Virtual DACR change" },
+	{ 0, "VCPU switch to privileged mode" },
+	{ 0, "VCPU switch from privileged mode" },
+	{ 0, "VCPU process ID registers change" },
+	{ 0, "Emulate Load/Store with translation" },
+	{ 0, "Emulate MRS" },
+	{ 0, "Emulate MSR" },
+	{ 0, "Emulate CPS" },
+	{ 0, "Need reschedule in execution loop" },
+	{ 0, "MCR 7,  5, 0 - Invalidate entire I-cache" },
+	{ 0, "MCR 7,  5, 1 - Invalidate line in I-cache MVA" },
+	{ 0, "MCR 7,  5, 2 - Invalidate line in I-cache set/way" },
+	{ 0, "MCR 7,  5, 7 - Flush branch target cache - MVA" },
+	{ 0, "MCR 7,  6, 0 - Invalidate entire data cache" },
+	{ 0, "MCR 7,  6, 1 - Invalidate data cache line - MVA" },
+	{ 0, "MCR 7,  6, 2 - Invalidate data cache line - set/way" },
+	{ 0, "MCR 7,  7, 0 - Invalidate D- and I-cache" },
+	{ 0, "MCR 7, 10, 0 - Clean entire data cache" },
+	{ 0, "MCR 7, 10, 1 - Clean data cache line - MVA" },
+	{ 0, "MCR 7, 10, 4 - Data Synchronization Barrier (DSB)" },
+	{ 0, "MCR 7, 14, 0 - Clean and invalidate entire D-cache" },
+	{ 0, "MCR 7, 14, 1 - Clean and invalidate D-cache line - MVA" },
+	{ 0, "MCR 7, 15, 0 - Clean and invalidate unified cache" },
+	{ 0, "MCR 8,  5, 0 - Invalidate instruction TLB" },
+	{ 0, "MCR 8,  6, 0 - Invalidate data TLB" },
+	{ 0, "MCR 8,  7, 0 - Invalidate unified TLB" },

arch/arm/kvm/trace.c line 82

Quoted 10 lines
arch/arm/kvm/trace.c new file +10 -0
+	{ 0, "Emulate Load-Store multiple" },
+};
+
+void kvm_arm_count_event(unsigned int event)
+{
+	if (event>= KVM_EVENTC_ITEMS)
+		return;
+
+	kvm_eventc_log[event].cnt++;
+}

We've switched to ftrace for this sort of thing. Simply add a tracepoint for each interesting event, and the kernel can provide you with

- a count of events ('perf stat')
- a log of events ('trace-cmd record/report'), possibly with other kernel events interspersed
- a running histogram ('kvm_stat')

with near-zero impact when disabled.

See include/trace/events/kvm.h, arch/x86/kvm/trace.h.

Signature · 1 line
error compiling committee.c: too many arguments to function
#47 lore raw
Quoted 30 lines · Avi Kivity
Quoted 29 lines · Christoffer Dall

Targets KVM support for Cortex A-15 processors.

Contains no real functionality but all the framework components, make files, header files and some tracing functionality.

arch/arm/include/asm/kvm.h new file +23 -0
+
+struct kvm_regs {
+       __u32 regs0_7[8];       /* Unbanked regs. (r0 - r7)        */
+       __u32 fiq_regs8_12[5];  /* Banked fiq regs. (r8 - r12)     */
+       __u32 usr_regs8_12[5];  /* Banked usr registers (r8 - r12) */
+       __u32 reg13[6];         /* Banked r13, indexed by MODE_    */
+       __u32 reg14[6];         /* Banked r13, indexed by MODE_    */
+       __u32 reg15;
+       __u32 cpsr;
+       __u32 spsr[5];          /* Banked SPSR,  indexed by MODE_  */
+       struct {
+               __u32 c2_base0;
+               __u32 c2_base1;
+               __u32 c3_dacr;
+       } cp15;
+
+};
+
+struct kvm_sregs {
+};
+
+struct kvm_fpu {
+};
Quoted 9 lines

arch/arm/include/asm/kvm.h line 63

Quoted 6 lines
arch/arm/include/asm/kvm.h new file +6 -0
+
+struct kvm_guest_debug_arch {
+};
+
+struct kvm_debug_exit_arch {
+};

Presumably, to be filled in later?

I simply didn't look at these yet and didn't need them yet. I will look into this later on.

Quoted 21 lines
Quoted 21 lines
arch/arm/include/asm/kvm_emulate.h new file +21 -0
+
+/* Get vcpu register for current mode */
+#define vcpu_reg(_vcpu, _reg_num) \
+       (*kvm_vcpu_reg((_vcpu), _reg_num, vcpu_mode(_vcpu)))
+
+/* Get vcpu register for specific mode */
+#define vcpu_reg_m(_vcpu, _reg_num, _mode) \
+       (*kvm_vcpu_reg(_vcpu, _reg_num, _mode))
+
+#define vcpu_cpsr(_vcpu) \
+       (_vcpu->arch.regs.cpsr)
+
+/* Get vcpu SPSR for current mode */
+#define vcpu_spsr(_vcpu) \
+       kvm_vcpu_spsr(_vcpu, vcpu_mode(_vcpu))
+
+/* Get vcpu SPSR for specific mode */
+#define vcpu_spsr_m(_vcpu, _mode) \
+       kvm_vcpu_spsr(_vcpu, _mode)
+
+#define MODE_HAS_SPSR(_vcpu) \
Quoted 8 lines

arch/arm/include/asm/kvm_emulate.h line 87

Quoted 4 lines

+        ((vcpu_mode(_vcpu))<  MODE_USR)

arch/arm/include/asm/kvm_emulate.h new file +3 -0
+
+#define VCPU_MODE_PRIV(_vcpu) \
+       (((vcpu_mode(_vcpu)) == MODE_USR) ? 0 : 1)

Please use static inlines.  Yes, you'll need more helpers to set registers, but it's worth it, especially as some macros evaluate an argument multiple times.

ok.

Quoted 11 lines
Quoted 11 lines
arch/arm/kvm/Kconfig new file +10 -0
+if VIRTUALIZATION
+
+config KVM
+       bool "Kernel-based Virtual Machine (KVM) support"
+       select PREEMPT_NOTIFIERS
+       select ANON_INODES
+       select KVM_ARM_HOST
+       select KVM_MMIO
+       ---help---
+         Support hosting virtualized guest machines. You will also
Quoted 9 lines

arch/arm/kvm/Kconfig line 32

Quoted 6 lines

+         need to select one or more of the processor modules below.

arch/arm/kvm/Kconfig new file +5 -0
+
+         This module provides access to the hardware capabilities through
+         a character device node named /dev/kvm.
+
+         If unsure, say N.

I see you can't support a modular build, which is a pity.

My concern is that I map in code that needs to be in place for running in Hyp mode. Of course I just need to pin these, so it should be possible. I'll look into this as well.

Quoted 42 lines
Quoted 42 lines
arch/arm/kvm/arm.c new file +42 -0
+
+static int k_show(struct seq_file *m, void *v)
+{
+       print_kvm_debug_info(&seq_printf, m);
+       return 0;
+}
+
+static void *k_start(struct seq_file *m, loff_t *pos)
+{
+       return *pos<  1 ? (void *)1 : NULL;
+}
+
+static void *k_next(struct seq_file *m, void *v, loff_t *pos)
+{
+       ++*pos;
+       return NULL;
+}
+
+static void k_stop(struct seq_file *m, void *v)
+{
+}
+
+static const struct seq_operations kvmproc_op = {
+       .start  = k_start,
+       .next   = k_next,
+       .stop   = k_stop,
+       .show   = k_show
+};
+
+static int kvm_open(struct inode *inode, struct file *file)
+{
+       return seq_open(file,&kvmproc_op);
+}
+
+static const struct file_operations proc_kvm_operations = {
+       .open           = kvm_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = seq_release,
+};
+
+static int arm_init(void)
Quoted 9 lines

arch/arm/kvm/arm.c line 355

Quoted 6 lines
arch/arm/kvm/arm.c new file +6 -0
+{
+       int rc = kvm_init(NULL, sizeof(struct kvm_vcpu), 0, THIS_MODULE);
+       if (rc == 0)
+               proc_create("kvm", 0, NULL,&proc_kvm_operations);
+       return rc;
+}

/proc is frowned upon these days.  Is there no better place for this?+

Quoted 1 line

Yeah, this is actually quite legacy and probably shouldn't have been included. I will give this a thorough overhaul before next patch series.

Quoted 43 lines
Quoted 43 lines
arch/arm/kvm/arm_emulate.c new file +43 -0
+/*
+ * Return a pointer to the register number valid in the specified mode of
+ * the virtual CPU.
+ */
+u32* kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode)
+{
+       struct kvm_vcpu_regs *regs;
+       u8 reg_idx;
+       BUG_ON(reg_num>  15);
+
+       regs =&vcpu->arch.regs;
+
+       /* The PC is trivial */
+       if (reg_num == 15)
+               return&(regs->pc);
+
+       /* Non-banked registers */
+       if (reg_num<  8)
+               return&(regs->usr_regs[reg_num]);
+
+       /* Banked registers r13 and r14 */
+       if (reg_num>= 13) {
+               reg_idx = reg_num - 13; /* 0=r13 and 1=r14 */
+               switch (mode) {
+               case MODE_FIQ:
+                       return&(regs->fiq_regs[reg_idx + 5]);
+               case MODE_IRQ:
+                       return&(regs->irq_regs[reg_idx]);
+               case MODE_SVC:
+                       return&(regs->svc_regs[reg_idx]);
+               case MODE_ABT:
+                       return&(regs->abt_regs[reg_idx]);
+               case MODE_UND:
+                       return&(regs->und_regs[reg_idx]);
+               case MODE_USR:
+               case MODE_SYS:
+                       return&(regs->usr_regs[reg_idx]);
+               }
+       }
+
+       /* Banked FIQ registers r8-r12 */
+       if (reg_num>= 8&&  reg_num<= 12) {
+               if (mode == MODE_FIQ) {
Quoted 8 lines
Quoted 5 lines

+                       reg_idx = reg_num - 8; /* 0=r8, ..., 4=r12 */
+                       return&(regs->fiq_regs[reg_idx]);
+               } else
+                       return&(regs->usr_regs[reg_num]);
+       }

You could have a static 2D array indexed by mode and register number, returning an offsetof() into the vcpu structure.

You think it's simpler or faster? I don't quite see the incentive. It's not going to be called a whole lot given the Virt. Extensions.

Quoted 9 lines
Quoted 9 lines
arch/arm/kvm/arm_emulate.c new file +4 -0
+
+       BUG();
+       return NULL;
+}
arch/arm/kvm/trace.c new file +0 -0
new file mode 100644
index 0000000..8ea1155

[snip]

Quoted 12 lines

arch/arm/kvm/trace.c line 82

Quoted 8 lines
arch/arm/kvm/trace.c new file +8 -0
+
+void kvm_arm_count_event(unsigned int event)
+{
+       if (event>= KVM_EVENTC_ITEMS)
+               return;
+
+       kvm_eventc_log[event].cnt++;
+}

We've switched to ftrace for this sort of thing.  Simply add a tracepoint for each interesting event, and the kernel can provide you with

Quoted 8 lines

- a count of events ('perf stat')
- a log of events ('trace-cmd record/report'), possibly with other kernel events interspersed
- a running histogram ('kvm_stat')

with near-zero impact when disabled.

See include/trace/events/kvm.h, arch/x86/kvm/trace.h.

Will do, thanks.

Quoted 5 lines

--
error compiling committee.c: too many arguments to function

#48 lore raw
Quoted 10 lines · Christoffer Dall
Quoted 10 lines
Quoted 9 lines

+
+ /* Banked FIQ registers r8-r12 */
+ if (reg_num>= 8&& reg_num<= 12) {
+ if (mode == MODE_FIQ) {
+ reg_idx = reg_num - 8; /* 0=r8, ..., 4=r12 */
+ return&(regs->fiq_regs[reg_idx]);
+ } else
+ return&(regs->usr_regs[reg_num]);
+ }

Quoted 5 lines
Quoted 2 lines

You could have a static 2D array indexed by mode and register number, returning an offsetof() into the vcpu structure.

You think it's simpler or faster? I don't quite see the incentive. It's not going to be called a whole lot given the Virt. Extensions.

Yes (those are mostly unpredictable branches), and clearer as well. But I agree it's a rare-enough path that doesn't need optimizing, certainly not prematurely.

Signature · 1 line
error compiling committee.c: too many arguments to function

A message that is not in the archive (sent off-list or not yet received): [email protected]

#50 lore raw
Quoted 45 lines · Alexander Graf

On 05.06.2011, at 18:03, Christoffer Dall wrote:

On Sun, Jun 5, 2011 at 2:36 PM, Avi Kivity <[email protected]> wrote:

On 06/03/2011 06:03 PM, Christoffer Dall wrote:

[...]

arch/arm/kvm/Kconfig new file +16 -0
+if VIRTUALIZATION
 
+
 
+config KVM
 
+       bool "Kernel-based Virtual Machine (KVM) support"
 
+       select PREEMPT_NOTIFIERS
 
+       select ANON_INODES
 
+       select KVM_ARM_HOST
 
+       select KVM_MMIO
 
+       ---help---
 
+         Support hosting virtualized guest machines. You will also
 
+         need to select one or more of the processor modules below.
 
+
 
+         This module provides access to the hardware capabilities through
 
+         a character device node named /dev/kvm.
 
+
 
+         If unsure, say N.

I see you can't support a modular build, which is a pity.

Quoted 8 lines

My concern is that I map in code that needs to be in place for running in Hyp mode. Of course I just need to pin these, so it should be possible. I'll look into this as well.

We have similar requirements for PPC, so feel free to check how we did it there :). On =M we still include reasonably small parts of the code in the kernel as =Y, but keep the big chunks outside as module.

OK, so I looked into compiling KVM/ARM as a module and there are a few obstacles:

I need to export several symbols (identitiy_mapping_add, pgd_clear_bad, __irq_svc). __irq_svc is tricky because it's in the entry-armv.S assembly file, so it's not obvious where to export it from. Recommendations? (dedicated KVM export file as in PPC or simply adding EXPORT_SYMBOL_GPL(...) or alternative?

Also, iirc, modules are loaded using vmalloc, wouldn't that make it impossible for me to use virt_to_phys, which I need to do on some of the code pages for Hypervisor initialization? If any of the ARM people could give an advise here, it would be much appreciated - of course I can kmalloc a page and relocate the init code, but I really would like to avoid this.

Thanks!
-Christoffer

#51 lore raw
Quoted 8 lines · Christoffer Dall

OK, so I looked into compiling KVM/ARM as a module and there are a few obstacles:

I need to export several symbols (identitiy_mapping_add, pgd_clear_bad, __irq_svc). __irq_svc is tricky because it's in the entry-armv.S assembly file, so it's not obvious where to export it from. Recommendations? (dedicated KVM export file as in PPC or simply adding EXPORT_SYMBOL_GPL(...) or alternative?

There is arch/arm/kernel/armksyms.c where we export extra symbols coming from .S files. I haven't looked at the code yet, maybe some of the symbols could be avoided.

Quoted 6 lines

Also, iirc, modules are loaded using vmalloc, wouldn't that make it impossible for me to use virt_to_phys, which I need to do on some of the code pages for Hypervisor initialization? If any of the ARM people could give an advise here, it would be much appreciated - of course I can kmalloc a page and relocate the init code, but I really would like to avoid this.

You could alloc a page (or a few) an copy the hypervisor code in there. Just make sure that it is position independent (which is not difficult with hand-written assembly).

Alternatively, you could set up the Hyp translation tables to also include the modules area (pretty much duplicating the corresponding swapper_pg_dir entries, with some attributes changed).

But for now you can probably ignore this issue and get back to it once everything else is working.

Signature · 1 line
Catalin
#52 lore raw

Am 10.06.2011 um 11:23 schrieb Catalin Marinas <[email protected]>:

Quoted 21 lines · Christoffer Dall
Quoted 8 lines

OK, so I looked into compiling KVM/ARM as a module and there are a few obstacles:

I need to export several symbols (identitiy_mapping_add, pgd_clear_bad, __irq_svc). __irq_svc is tricky because it's in the entry-armv.S assembly file, so it's not obvious where to export it from. Recommendations? (dedicated KVM export file as in PPC or simply adding EXPORT_SYMBOL_GPL(...) or alternative?

There is arch/arm/kernel/armksyms.c where we export extra symbols coming from .S files. I haven't looked at the code yet, maybe some of the symbols could be avoided.

Quoted 6 lines

Also, iirc, modules are loaded using vmalloc, wouldn't that make it impossible for me to use virt_to_phys, which I need to do on some of the code pages for Hypervisor initialization? If any of the ARM people could give an advise here, it would be much appreciated - of course I can kmalloc a page and relocate the init code, but I really would like to avoid this.

Quoted 3 lines

You could alloc a page (or a few) an copy the hypervisor code in there. Just make sure that it is position independent (which is not difficult with hand-written assembly).

What we do on ppc is to select another kernel option =Y when we set kvm=M. Based on that other option, we then add the code that need to run in real mode (linear map) to the main kernel binary.

That way, the guest entry/exit code for example is always in the kernel, while the logic that dispatches what to do on a specific guest exit can stay as module, making development a lot easier.

Alex

Quoted 1 line
#53 lore raw
Quoted 26 lines · Alexander Graf

Am 10.06.2011 um 11:23 schrieb Catalin Marinas <[email protected]>:

Quoted 21 lines · Christoffer Dall
Quoted 8 lines

OK, so I looked into compiling KVM/ARM as a module and there are a few obstacles:

I need to export several symbols (identitiy_mapping_add, pgd_clear_bad, __irq_svc). __irq_svc is tricky because it's in the entry-armv.S assembly file, so it's not obvious where to export it from. Recommendations? (dedicated KVM export file as in PPC or simply adding EXPORT_SYMBOL_GPL(...) or alternative?

There is arch/arm/kernel/armksyms.c where we export extra symbols coming from .S files. I haven't looked at the code yet, maybe some of the symbols could be avoided.

Quoted 6 lines

Also, iirc, modules are loaded using vmalloc, wouldn't that make it impossible for me to use virt_to_phys, which I need to do on some of the code pages for Hypervisor initialization? If any of the ARM people could give an advise here, it would be much appreciated - of course I can kmalloc a page and relocate the init code, but I really would like to avoid this.

Quoted 3 lines

You could alloc a page (or a few) an copy the hypervisor code in there. Just make sure that it is position independent (which is not difficult with hand-written assembly).

Quoted 7 lines

What we do on ppc is to select another kernel option =Y when we set kvm=M. Based on that other option, we then add the code that need to run in real mode (linear map) to the main kernel binary.

That way, the guest entry/exit code for example is always in the kernel, while the logic that dispatches what to do on a specific guest exit can stay as module, making development a lot easier.

Good point. We could do the same on ARM.

Thanks.

Signature · 1 line
Catalin
#54 lore raw
Quoted 31 lines · Catalin Marinas
Quoted 30 lines · Alexander Graf

Am 10.06.2011 um 11:23 schrieb Catalin Marinas <[email protected]>:

Quoted 21 lines · Christoffer Dall
Quoted 8 lines

OK, so I looked into compiling KVM/ARM as a module and there are a few obstacles:

I need to export several symbols (identitiy_mapping_add, pgd_clear_bad, __irq_svc). __irq_svc is tricky because it's in the entry-armv.S assembly file, so it's not obvious where to export it from. Recommendations? (dedicated KVM export file as in PPC or simply adding EXPORT_SYMBOL_GPL(...) or alternative?

There is arch/arm/kernel/armksyms.c where we export extra symbols coming from .S files. I haven't looked at the code yet, maybe some of the symbols could be avoided.

Quoted 6 lines

Also, iirc, modules are loaded using vmalloc, wouldn't that make it impossible for me to use virt_to_phys, which I need to do on some of the code pages for Hypervisor initialization? If any of the ARM people could give an advise here, it would be much appreciated - of course I can kmalloc a page and relocate the init code, but I really would like to avoid this.

Quoted 3 lines

You could alloc a page (or a few) an copy the hypervisor code in there. Just make sure that it is position independent (which is not difficult with hand-written assembly).

What we do on ppc is to select another kernel option =Y when we set kvm=M. Based on that other option, we then add the code that need to run in real mode (linear map) to the main kernel binary.

Quoted 5 lines
Quoted 3 lines

That way, the guest entry/exit code for example is always in the kernel, while the logic that dispatches what to do on a specific guest exit can stay as module, making development a lot easier.

Good point. We could do the same on ARM.

Thanks, I will follow your suggestions for next patch series.

#55 lore raw
In reply to Christoffer Dall
Quoted 4 lines · Christoffer Dall

Targets KVM support for Cortex A-15 processors.

Contains no real functionality but all the framework components, make files, header files and some tracing functionality.

(series review - please have a cover letter in the future for this stuff)

Looks good in general. Of course I can't say much about technical correctness and will rely on the ARM maintainers for that.

Please document which ioctls are supported in Documentation/virtual/kvm/api.txt, and make sure that any ARM-specific ioctls (if you ever have any) are documented there.

Signature · 1 line
error compiling committee.c: too many arguments to function
#56 lore raw
Quoted 3 lines · Avi Kivity

(series review - please have a cover letter in the future for this stuff)

Oh - you did - but in a separate thread. Oh well.

Signature · 1 line
error compiling committee.c: too many arguments to function
#57 lore raw
Quoted 6 lines · Avi Kivity
Quoted 3 lines · Avi Kivity

(series review - please have a cover letter in the future for this stuff)

Oh - you did - but in a separate thread.  Oh well.

My internet router decided to reset immediately after sending the cover letter, when it was backup stgit gave up on sending the rest of the patches, and I didn't think about putting the rest in the same thread. Sorry about that.

Quoted 5 lines

--
error compiling committee.c: too many arguments to function

#58 lore raw
Quoted 6 lines · Christoffer Dall
Quoted 5 lines · Avi Kivity
Quoted 3 lines · Avi Kivity

(series review - please have a cover letter in the future for this stuff)

Quoted 6 lines
Quoted 1 line

Oh - you did - but in a separate thread. Oh well.

My internet router decided to reset immediately after sending the cover letter, when it was backup stgit gave up on sending the rest of the patches, and I didn't think about putting the rest in the same thread. Sorry about that.

No problem.

Signature · 1 line
error compiling committee.c: too many arguments to function