Skip to contentSkip to conversation

Added aarch64 configure support and default configuration

PATCH In review Mian M. Hamayun 4 participants 20 messages Jun 28, 2013 – Jul 1, 2013 Arm/versatile express platform

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 Added aarch64 configure support and default configuration

From: "Mian M. Hamayun" <[email protected]>

---
 configure                           |    3 +-
 default-configs/aarch64-softmmu.mak |   83 +++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 1 deletion(-)
 create mode 100644 default-configs/aarch64-softmmu.mak
configure +2 -1
index b247e5b..ddec40d 100755
@@ -4293,10 +4293,11 @@ case "$target_name" in
   *)
 esac
 case "$target_name" in
-  arm|i386|x86_64|ppcemb|ppc|ppc64|s390x)
+  arm|aarch64|i386|x86_64|ppcemb|ppc|ppc64|s390x)
     # Make sure the target and host cpus are compatible
     if test "$kvm" = "yes" -a "$target_softmmu" = "yes" -a \
       \( "$target_name" = "$cpu" -o \
+      \( "$target_name" = "arm"    -a "$cpu" = "aarch64"   \) -o \
       \( "$target_name" = "ppcemb" -a "$cpu" = "ppc" \) -o \
       \( "$target_name" = "ppc64"  -a "$cpu" = "ppc" \) -o \
       \( "$target_name" = "ppc"    -a "$cpu" = "ppc64" \) -o \
default-configs/aarch64-softmmu.mak new file +83 -0

83 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/6 Added KVM Headers from KVM Tool

From: "Mian M. Hamayun" <[email protected]>

---
 linux-headers/asm-arm64/kvm.h      |  168 ++++++++++++++++++++++++++++++++++++
 linux-headers/asm-arm64/kvm_para.h |    1 +
 2 files changed, 169 insertions(+)
 create mode 100644 linux-headers/asm-arm64/kvm.h
 create mode 100644 linux-headers/asm-arm64/kvm_para.h
linux-headers/asm-arm64/kvm.h new file +168 -0
new file mode 100644
index 0000000..5031f42
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2012,2013 - ARM Ltd
+ * Author: Marc Zyngier <[email protected]>
+ *
+ * Derived from arch/arm/include/uapi/asm/kvm.h:
+ * Copyright (C) 2012 - Virtual Open Systems and Columbia University
+ * Author: Christoffer Dall <[email protected]>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ARM_KVM_H__
+#define __ARM_KVM_H__
+
+#define KVM_SPSR_EL1	0
+#define KVM_SPSR_SVC	KVM_SPSR_EL1
+#define KVM_SPSR_ABT	1
+#define KVM_SPSR_UND	2
+#define KVM_SPSR_IRQ	3
+#define KVM_SPSR_FIQ	4
+#define KVM_NR_SPSR	5
+
+#ifndef __ASSEMBLY__
+#include <asm/types.h>
+#include <asm/ptrace.h>
+
+#define __KVM_HAVE_GUEST_DEBUG
+#define __KVM_HAVE_IRQ_LINE
+
+#define KVM_REG_SIZE(id)						\
+	(1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
+
+struct kvm_regs {
+	struct user_pt_regs regs;	/* sp = sp_el0 */
+
+	__u64	sp_el1;
+	__u64	elr_el1;
+
+	__u64	spsr[KVM_NR_SPSR];
+
+	struct user_fpsimd_state fp_regs;
+};
+
+/* Supported Processor Types */
+#define KVM_ARM_TARGET_AEM_V8		0
+#define KVM_ARM_TARGET_FOUNDATION_V8	1
+#define KVM_ARM_TARGET_CORTEX_A57	2
+
+#define KVM_ARM_NUM_TARGETS		3
+
+/* KVM_ARM_SET_DEVICE_ADDR ioctl id encoding */
+#define KVM_ARM_DEVICE_TYPE_SHIFT	0
+#define KVM_ARM_DEVICE_TYPE_MASK	(0xffff << KVM_ARM_DEVICE_TYPE_SHIFT)
+#define KVM_ARM_DEVICE_ID_SHIFT		16
+#define KVM_ARM_DEVICE_ID_MASK		(0xffff << KVM_ARM_DEVICE_ID_SHIFT)
+
+/* Supported device IDs */
+#define KVM_ARM_DEVICE_VGIC_V2		0
+
+/* Supported VGIC address types  */
+#define KVM_VGIC_V2_ADDR_TYPE_DIST	0
+#define KVM_VGIC_V2_ADDR_TYPE_CPU	1
+
+#define KVM_VGIC_V2_DIST_SIZE		0x1000
+#define KVM_VGIC_V2_CPU_SIZE		0x2000
+
+#define KVM_ARM_VCPU_POWER_OFF		0 /* CPU is started in OFF state */
+#define KVM_ARM_VCPU_EL1_32BIT		1 /* CPU running a 32bit VM */
+
+struct kvm_vcpu_init {
+	__u32 target;
+	__u32 features[7];
+};
+
+struct kvm_sregs {
+};
+
+struct kvm_fpu {
+};
+
+struct kvm_guest_debug_arch {
+};
+
+struct kvm_debug_exit_arch {
+};
+
+struct kvm_sync_regs {
+};
+
+struct kvm_arch_memory_slot {
+};
+
+/* If you need to interpret the index values, here is the key: */
+#define KVM_REG_ARM_COPROC_MASK		0x000000000FFF0000
+#define KVM_REG_ARM_COPROC_SHIFT	16
+
+/* Normal registers are mapped as coprocessor 16. */
+#define KVM_REG_ARM_CORE		(0x0010 << KVM_REG_ARM_COPROC_SHIFT)
+#define KVM_REG_ARM_CORE_REG(name)	(offsetof(struct kvm_regs, name) / sizeof(__u32))
+
+/* Some registers need more space to represent values. */
+#define KVM_REG_ARM_DEMUX		(0x0011 << KVM_REG_ARM_COPROC_SHIFT)
+#define KVM_REG_ARM_DEMUX_ID_MASK	0x000000000000FF00
+#define KVM_REG_ARM_DEMUX_ID_SHIFT	8
+#define KVM_REG_ARM_DEMUX_ID_CCSIDR	(0x00 << KVM_REG_ARM_DEMUX_ID_SHIFT)
+#define KVM_REG_ARM_DEMUX_VAL_MASK	0x00000000000000FF
+#define KVM_REG_ARM_DEMUX_VAL_SHIFT	0
+
+/* AArch64 system registers */
+#define KVM_REG_ARM64_SYSREG		(0x0013 << KVM_REG_ARM_COPROC_SHIFT)
+#define KVM_REG_ARM64_SYSREG_OP0_MASK	0x000000000000c000
+#define KVM_REG_ARM64_SYSREG_OP0_SHIFT	14
+#define KVM_REG_ARM64_SYSREG_OP1_MASK	0x0000000000003800
+#define KVM_REG_ARM64_SYSREG_OP1_SHIFT	11
+#define KVM_REG_ARM64_SYSREG_CRN_MASK	0x0000000000000780
+#define KVM_REG_ARM64_SYSREG_CRN_SHIFT	7
+#define KVM_REG_ARM64_SYSREG_CRM_MASK	0x0000000000000078
+#define KVM_REG_ARM64_SYSREG_CRM_SHIFT	3
+#define KVM_REG_ARM64_SYSREG_OP2_MASK	0x0000000000000007
+#define KVM_REG_ARM64_SYSREG_OP2_SHIFT	0
+
+/* KVM_IRQ_LINE irq field index values */
+#define KVM_ARM_IRQ_TYPE_SHIFT		24
+#define KVM_ARM_IRQ_TYPE_MASK		0xff
+#define KVM_ARM_IRQ_VCPU_SHIFT		16
+#define KVM_ARM_IRQ_VCPU_MASK		0xff
+#define KVM_ARM_IRQ_NUM_SHIFT		0
+#define KVM_ARM_IRQ_NUM_MASK		0xffff
+
+/* irq_type field */
+#define KVM_ARM_IRQ_TYPE_CPU		0
+#define KVM_ARM_IRQ_TYPE_SPI		1
+#define KVM_ARM_IRQ_TYPE_PPI		2
+
+/* out-of-kernel GIC cpu interrupt injection irq_number field */
+#define KVM_ARM_IRQ_CPU_IRQ		0
+#define KVM_ARM_IRQ_CPU_FIQ		1
+
+/* Highest supported SPI, from VGIC_NR_IRQS */
+#define KVM_ARM_IRQ_GIC_MAX		127
+
+/* PSCI interface */
+#define KVM_PSCI_FN_BASE		0x95c1ba5e
+#define KVM_PSCI_FN(n)			(KVM_PSCI_FN_BASE + (n))
+
+#define KVM_PSCI_FN_CPU_SUSPEND		KVM_PSCI_FN(0)
+#define KVM_PSCI_FN_CPU_OFF		KVM_PSCI_FN(1)
+#define KVM_PSCI_FN_CPU_ON		KVM_PSCI_FN(2)
+#define KVM_PSCI_FN_MIGRATE		KVM_PSCI_FN(3)
+
+#define KVM_PSCI_RET_SUCCESS		0
+#define KVM_PSCI_RET_NI			((unsigned long)-1)
+#define KVM_PSCI_RET_INVAL		((unsigned long)-2)
+#define KVM_PSCI_RET_DENIED		((unsigned long)-3)
+
+#endif
+
+#endif /* __ARM_KVM_H__ */
linux-headers/asm-arm64/kvm_para.h new file +1 -0
new file mode 100644
index 0000000..14fab8f
@@ -0,0 +1 @@
+#include <asm-generic/kvm_para.h>
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 3/6 Added Aarch64 CPU Initialization, Get and Put Registers Support.

In reply to Mian M. Hamayun

From: "Mian M. Hamayun" <[email protected]>

The init function tries to initialize with Foundation models first and on failure retries initializing on Fast Models.

Get and Put Registers deal with the basic state of Aarch64 CPUs for the moment.

---
 linux-headers/linux/kvm.h |    1 +
 target-arm/cpu.c          |    8 +++
 target-arm/cpu.h          |    1 +
 target-arm/kvm.c          |  120 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 130 insertions(+)
linux-headers/linux/kvm.h +1 -0
index c614070..4df5292 100644
@@ -783,6 +783,7 @@ struct kvm_dirty_tlb {
 #define KVM_REG_IA64		0x3000000000000000ULL
 #define KVM_REG_ARM		0x4000000000000000ULL
 #define KVM_REG_S390		0x5000000000000000ULL
+#define KVM_REG_ARM64          0x6000000000000000ULL
 
 #define KVM_REG_SIZE_SHIFT	52
 #define KVM_REG_SIZE_MASK	0x00f0000000000000ULL
target-arm/cpu.c +8 -0
index 496a59f..34eba77 100644
@@ -601,6 +601,13 @@ static void cortex_a15_initfn(Object *obj)
     define_arm_cp_regs(cpu, cortexa15_cp_reginfo);
 }
 
+static void cortex_a57_initfn(Object *obj)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+    set_feature(&cpu->env, ARM_FEATURE_V8);
+    cpu->env.aarch64 = 1;      /* We force 64-bit mode for guests */
+}
+
 static void ti925t_initfn(Object *obj)
 {
     ARMCPU *cpu = ARM_CPU(obj);
@@ -781,6 +788,7 @@ static const ARMCPUInfo arm_cpus[] = {
     { .name = "cortex-a8",   .initfn = cortex_a8_initfn },
     { .name = "cortex-a9",   .initfn = cortex_a9_initfn },
     { .name = "cortex-a15",  .initfn = cortex_a15_initfn },
+    { .name = "cortex-a57",  .initfn = cortex_a57_initfn },
     { .name = "ti925t",      .initfn = ti925t_initfn },
     { .name = "sa1100",      .initfn = sa1100_initfn },
     { .name = "sa1110",      .initfn = sa1110_initfn },
target-arm/cpu.h +1 -0
index cd42814..f1cae7f 100644
@@ -410,6 +410,7 @@ enum arm_features {
     ARM_FEATURE_V6,
     ARM_FEATURE_V6K,
     ARM_FEATURE_V7,
+    ARM_FEATURE_V8,
     ARM_FEATURE_THUMB2,
     ARM_FEATURE_MPU,    /* Only has Memory Protection Unit, not full MMU.  */
     ARM_FEATURE_VFP3,
target-arm/kvm.c +120 -0

164 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#3 lore raw

Re: [Qemu-devel] [PATCH 3/6] Added Aarch64 CPU Initialization, Get and Put Registers Support.

Quoted 20 lines · Mian M. Hamayun

From: "Mian M. Hamayun" <[email protected]>

The init function tries to initialize with Foundation models first and on failure retries initializing on Fast Models.

Get and Put Registers deal with the basic state of Aarch64 CPUs for the moment.

---

linux-headers/linux/kvm.h |    1 +
target-arm/cpu.c          |    8 +++
target-arm/cpu.h          |    1 +
target-arm/kvm.c          |  120 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 130 insertions(+)
linux-headers/linux/kvm.h +0 -0
index c614070..4df5292 100644

linux-headers/linux/kvm.h struct kvm_dirty_tlb { · line 789

Quoted 7 lines
linux-headers/linux/kvm.h +1 -0
@@ -783,6 +783,7 @@ struct kvm_dirty_tlb {
 #define KVM_REG_IA64		0x3000000000000000ULL
 #define KVM_REG_ARM		0x4000000000000000ULL
 #define KVM_REG_S390		0x5000000000000000ULL
+#define KVM_REG_ARM64          0x6000000000000000ULL
 
 #define KVM_REG_SIZE_SHIFT	52
 #define KVM_REG_SIZE_MASK	0x00f0000000000000ULL

This should be part of your header update patch.

Quoted 62 lines
target-arm/cpu.c +8 -0
index 496a59f..34eba77 100644
@@ -601,6 +601,13 @@ static void cortex_a15_initfn(Object *obj)
    define_arm_cp_regs(cpu, cortexa15_cp_reginfo);
 }
 
+static void cortex_a57_initfn(Object *obj)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+    set_feature(&cpu->env, ARM_FEATURE_V8);
+    cpu->env.aarch64 = 1;      /* We force 64-bit mode for guests */
+}
+
 static void ti925t_initfn(Object *obj)
 {
    ARMCPU *cpu = ARM_CPU(obj);
@@ -781,6 +788,7 @@ static const ARMCPUInfo arm_cpus[] = {
    { .name = "cortex-a8",   .initfn = cortex_a8_initfn },
    { .name = "cortex-a9",   .initfn = cortex_a9_initfn },
    { .name = "cortex-a15",  .initfn = cortex_a15_initfn },
+    { .name = "cortex-a57",  .initfn = cortex_a57_initfn },
    { .name = "ti925t",      .initfn = ti925t_initfn },
    { .name = "sa1100",      .initfn = sa1100_initfn },
    { .name = "sa1110",      .initfn = sa1110_initfn },
target-arm/cpu.h +1 -0
index cd42814..f1cae7f 100644
@@ -410,6 +410,7 @@ enum arm_features {
    ARM_FEATURE_V6,
    ARM_FEATURE_V6K,
    ARM_FEATURE_V7,
+    ARM_FEATURE_V8,
    ARM_FEATURE_THUMB2,
    ARM_FEATURE_MPU,    /* Only has Memory Protection Unit, not full MMU.  */
    ARM_FEATURE_VFP3,
target-arm/kvm.c +9 -0
index 27dcab9..0125f16 100644
@@ -23,6 +23,11 @@
 #include "cpu.h"
 #include "hw/arm/arm.h"
 
+#ifdef TARGET_AARCH64
+#define AARCH64_CORE_REG(x)   (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
+                 KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(x))
+#endif
+
 const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
    KVM_CAP_LAST_INFO
 };
@@ -41,6 +46,28 @@ unsigned long kvm_arch_vcpu_id(CPUState *cpu)
    return cpu->cpu_index;
 }
 
+#ifdef TARGET_AARCH64
+int kvm_arch_init_vcpu(CPUState *cs)
+{
+    struct kvm_vcpu_init init;

target-arm/kvm.c unsigned long kvm_arch_vcpu_id(CPUState *cpu) · line 62

Quoted 10 lines
target-arm/kvm.c +10 -0
+    int ret;
+
+    /* Try initializing with Foundation Models */
+    init.target = KVM_ARM_TARGET_FOUNDATION_V8;
+    memset(init.features, 0, sizeof(init.features));
+    ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
+    if (ret) {
+        /* Retry initializing with Fast Models */
+        init.target = KVM_ARM_TARGET_AEM_V8;
+        ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);

Not sure I understand this part. Do we have different CPU types for the different models? If so, they'd be different -cpu parameters, with -cpu host picking the same as the host's.

Quoted 28 lines
target-arm/kvm.c +10 -0
+        if (ret) {
+            return ret;
+        }
+    }
+
+    return ret;
+}
+#else
 int kvm_arch_init_vcpu(CPUState *cs)
 {
    struct kvm_vcpu_init init;
@@ -67,6 +94,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
    }
    return ret;
 }
+#endif
 
 /* We track all the KVM devices which need their memory addresses
 * passing to the kernel in a list of these structures.
@@ -159,6 +187,7 @@ typedef struct Reg {
    int offset;
 } Reg;
 
+#ifndef TARGET_AARCH64
 #define COREREG(KERNELNAME, QEMUFIELD)                       \
    {                                                        \
        KVM_REG_ARM | KVM_REG_SIZE_U32 |                     \

target-arm/kvm.c static const Reg regs[] = { · line 274

Quoted 7 lines
target-arm/kvm.c +4 -0
@@ -239,7 +268,52 @@ static const Reg regs[] = {
    VFPSYSREG(FPINST),
    VFPSYSREG(FPINST2),
 };
+#endif
+
+#ifdef TARGET_AARCH64
+int kvm_arch_put_registers(CPUState *cs, int level)

How does the register transaction interface look like for aarch64 kvm? Are aarch32 registers mapped onto aarch64 ones or are they a separate set of registers? If they're a separate set, just add the aarch64 register sync to the aarch32 one.

target-arm/kvm.c static const Reg regs[] = { · line 283

Quoted 9 lines
target-arm/kvm.c +9 -0
+{
+    struct kvm_one_reg reg;
+    int i;
+    int ret;
+
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+
+    for (i = 0; i < 31; i++) {

s/31/ARRAY_SIZE(...)/

target-arm/kvm.c static const Reg regs[] = { · line 285

Quoted 2 lines
target-arm/kvm.c +2 -0
+        reg.id = AARCH64_CORE_REG(regs.regs[i]);
+        reg.addr = (uintptr_t)(env) + offsetof(CPUARMState, xregs[i]);

reg.addr = (uintptr_t)&env->xregs[i];

Same below.

Alex

Quoted 102 lines
target-arm/kvm.c +76 -0
+        ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
+        if (ret) {
+            return ret;
+        }
+    }
+
+    reg.id = AARCH64_CORE_REG(regs.sp);
+    reg.addr = (uintptr_t)(env) + offsetof(CPUARMState, xregs[31]);
+    ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
+    if (ret) {
+        return ret;
+    }
+
+    reg.id = AARCH64_CORE_REG(regs.pstate);
+    reg.addr = (uintptr_t)(env) + offsetof(CPUARMState, pstate);
+    ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
+    if (ret) {
+        return ret;
+    }
 
+    reg.id = AARCH64_CORE_REG(regs.pc);
+    reg.addr = (uintptr_t)(env) + offsetof(CPUARMState, pc);
+    ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
+    if (ret) {
+        return ret;
+    }
+
+    /* TODO: Set Rest of Registers */
+    return ret;
+}
+#else
 int kvm_arch_put_registers(CPUState *cs, int level)
 {
    ARMCPU *cpu = ARM_CPU(cs);
@@ -321,7 +395,52 @@ int kvm_arch_put_registers(CPUState *cs, int level)
 
    return ret;
 }
+#endif
+
+#ifdef TARGET_AARCH64
+int kvm_arch_get_registers(CPUState *cs)
+{
+    struct kvm_one_reg reg;
+    int i;
+    int ret;
+
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+
+    for (i = 0; i < 31; i++) {
+        reg.id = AARCH64_CORE_REG(regs.regs[i]);
+        reg.addr = (uintptr_t)(env) + offsetof(CPUARMState, xregs[i]);
+        ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &reg);
+        if (ret) {
+            return ret;
+        }
+    }
 
+    reg.id = AARCH64_CORE_REG(regs.sp);
+    reg.addr = (uintptr_t)(env) + offsetof(CPUARMState, xregs[31]);
+    ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &reg);
+    if (ret) {
+        return ret;
+    }
+
+    reg.id = AARCH64_CORE_REG(regs.pstate);
+    reg.addr = (uintptr_t)(env) + offsetof(CPUARMState, pstate);
+    ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &reg);
+    if (ret) {
+        return ret;
+    }
+
+    reg.id = AARCH64_CORE_REG(regs.pc);
+    reg.addr = (uintptr_t)(env) + offsetof(CPUARMState, pc);
+    ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &reg);
+    if (ret) {
+        return ret;
+    }
+
+    /* TODO: Set Rest of Registers */
+    return ret;
+}
+#else
 int kvm_arch_get_registers(CPUState *cs)
 {
    ARMCPU *cpu = ARM_CPU(cs);
@@ -416,6 +535,7 @@ int kvm_arch_get_registers(CPUState *cs)
 
    return 0;
 }
+#endif
 
 void kvm_arch_pre_run(CPUState *cs, struct kvm_run *run)
 {
Signature · 6 lines
1.7.9.5

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/cucslists/listinfo/kvmarm
#4 lore raw

Re: [Qemu-devel] [PATCH 3/6] Added Aarch64 CPU Initialization, Get and Put Registers Support.

Quoted 12 lines · Alexander Graf
Quoted 10 lines · Mian M. Hamayun
linux-headers/linux/kvm.h +1 -0
index c614070..4df5292 100644
@@ -783,6 +783,7 @@ struct kvm_dirty_tlb {
 #define KVM_REG_IA64		0x3000000000000000ULL
 #define KVM_REG_ARM		0x4000000000000000ULL
 #define KVM_REG_S390		0x5000000000000000ULL
+#define KVM_REG_ARM64          0x6000000000000000ULL
 
Quoted 3 lines

linux-headers/linux/kvm.h struct kvm_dirty_tlb { · line 789

Quoted 2 lines
linux-headers/linux/kvm.h +0 -0
 #define KVM_REG_SIZE_SHIFT	52
 #define KVM_REG_SIZE_MASK	0x00f0000000000000ULL

This should be part of your header update patch.

Just to make sure that we understand it correctly, do you mean that this macro definition should be moved to the arm64 specific header that we include in another patch series ? or keep this change in the same file and do it along with the header inclusion in a single patch ?

Quoted 7 lines
Quoted 7 lines
linux-headers/linux/kvm.h +7 -0
+#ifdef TARGET_AARCH64
+int kvm_arch_init_vcpu(CPUState *cs)
+{
+    struct kvm_vcpu_init init;
+    int ret;
+
+    /* Try initializing with Foundation Models */
Quoted 8 lines

linux-headers/linux/kvm.h

Quoted 7 lines
linux-headers/linux/kvm.h +7 -0
+    init.target = KVM_ARM_TARGET_FOUNDATION_V8;
+    memset(init.features, 0, sizeof(init.features));
+    ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
+    if (ret) {
+        /* Retry initializing with Fast Models */
+        init.target = KVM_ARM_TARGET_AEM_V8;
+        ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);

Not sure I understand this part. Do we have different CPU types for the different models? If so, they'd be different -cpu parameters, with -cpu host picking the same as the host's.

KVM tool does a very similar thing, using a loop and tries to initialize supported processors types and gets done when it succeeds with anyone of them. We could include a similar implementation in the next revision.

Quoted 10 lines

linux-headers/linux/kvm.h

Quoted 9 lines
linux-headers/linux/kvm.h +9 -0
+{
+    struct kvm_one_reg reg;
+    int i;
+    int ret;
+
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+
+    for (i = 0; i < 31; i++) {

s/31/ARRAY_SIZE(...)/

Agreed, we should avoid hard-coding as much as possible.

Quoted 3 lines

linux-headers/linux/kvm.h

Quoted 2 lines
linux-headers/linux/kvm.h +2 -0
+        reg.id = AARCH64_CORE_REG(regs.regs[i]);
+        reg.addr = (uintptr_t)(env) + offsetof(CPUARMState, xregs[i]);

reg.addr = (uintptr_t)&env->xregs[i];

Our implementation was influenced by the existing kvm_arch_get_registers() implementation for the A15 CPU, with slight differences. Anyways, we will include the proposed change in the next revision.

--
Hamayun

#5 lore raw

Re: [Qemu-devel] [PATCH 3/6] Added Aarch64 CPU Initialization, Get and Put Registers Support.

Quoted 14 lines · Mian M. Hamayun
Quoted 12 lines · Alexander Graf
Quoted 10 lines · Mian M. Hamayun
linux-headers/linux/kvm.h +1 -0
index c614070..4df5292 100644
@@ -783,6 +783,7 @@ struct kvm_dirty_tlb {
 #define KVM_REG_IA64		0x3000000000000000ULL
 #define KVM_REG_ARM		0x4000000000000000ULL
 #define KVM_REG_S390		0x5000000000000000ULL
+#define KVM_REG_ARM64          0x6000000000000000ULL
 
Quoted 4 lines
Quoted 3 lines

linux-headers/linux/kvm.h struct kvm_dirty_tlb { · line 789

Quoted 2 lines
linux-headers/linux/kvm.h +0 -0
 #define KVM_REG_SIZE_SHIFT	52
 #define KVM_REG_SIZE_MASK	0x00f0000000000000ULL

This should be part of your header update patch.

Just to make sure that we understand it correctly, do you mean that this macro definition should be moved to the arm64 specific header that we include in another patch series ? or keep this change in the same file and do it along with the header inclusion in a single patch ?

I'm saying you should generate the Linux header update from an upstream branch that includes this change.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
linux-headers/linux/kvm.h +7 -0
+#ifdef TARGET_AARCH64
+int kvm_arch_init_vcpu(CPUState *cs)
+{
+    struct kvm_vcpu_init init;
+    int ret;
+
+    /* Try initializing with Foundation Models */
Quoted 8 lines

linux-headers/linux/kvm.h

Quoted 7 lines
linux-headers/linux/kvm.h +7 -0
+    init.target = KVM_ARM_TARGET_FOUNDATION_V8;
+    memset(init.features, 0, sizeof(init.features));
+    ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
+    if (ret) {
+        /* Retry initializing with Fast Models */
+        init.target = KVM_ARM_TARGET_AEM_V8;
+        ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);

Not sure I understand this part. Do we have different CPU types for the different models? If so, they'd be different -cpu parameters, with -cpu host picking the same as the host's.

Quoted 1 line

KVM tool does a very similar thing, using a loop and tries to initialize supported processors types and gets done when it succeeds with anyone of them. We could include a similar implementation in the next revision.

Is there no way to evaluate what we're running on so that we can expose the same thing to the guest? It's what -cpu host does usually. Taking one by trial-and-error breaks cross-virtualization.

Alex

#6 lore raw

Re: [Qemu-devel] [PATCH 3/6] Added Aarch64 CPU Initialization, Get and Put Registers Support.

In reply to Mian M. Hamayun
Quoted 32 lines · Mian M. Hamayun

From: "Mian M. Hamayun" <[email protected]>

The init function tries to initialize with Foundation models first and on failure retries initializing on Fast Models.

Get and Put Registers deal with the basic state of Aarch64 CPUs for the moment.

---
 linux-headers/linux/kvm.h |    1 +
 target-arm/cpu.c          |    8 +++
 target-arm/cpu.h          |    1 +
 target-arm/kvm.c          |  120 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 130 insertions(+)
linux-headers/linux/kvm.h +1 -0
index c614070..4df5292 100644
@@ -783,6 +783,7 @@ struct kvm_dirty_tlb {
 #define KVM_REG_IA64           0x3000000000000000ULL
 #define KVM_REG_ARM            0x4000000000000000ULL
 #define KVM_REG_S390           0x5000000000000000ULL
+#define KVM_REG_ARM64          0x6000000000000000ULL
 
 #define KVM_REG_SIZE_SHIFT     52
 #define KVM_REG_SIZE_MASK      0x00f0000000000000ULL
target-arm/cpu.c +0 -0
index 496a59f..34eba77 100644

target-arm/cpu.c static void cortex_a15_initfn(Object *obj) · line 608

Quoted 8 lines
target-arm/cpu.c +5 -0
@@ -601,6 +601,13 @@ static void cortex_a15_initfn(Object *obj)
     define_arm_cp_regs(cpu, cortexa15_cp_reginfo);
 }
 
+static void cortex_a57_initfn(Object *obj)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+    set_feature(&cpu->env, ARM_FEATURE_V8);
+    cpu->env.aarch64 = 1;      /* We force 64-bit mode for guests */

This is definitely in the wrong place. cpu reset for 64 bit CPUs should start them off in AArch64.

Quoted 48 lines
target-arm/cpu.c +3 -0
+}
+
 static void ti925t_initfn(Object *obj)
 {
     ARMCPU *cpu = ARM_CPU(obj);
@@ -781,6 +788,7 @@ static const ARMCPUInfo arm_cpus[] = {
     { .name = "cortex-a8",   .initfn = cortex_a8_initfn },
     { .name = "cortex-a9",   .initfn = cortex_a9_initfn },
     { .name = "cortex-a15",  .initfn = cortex_a15_initfn },
+    { .name = "cortex-a57",  .initfn = cortex_a57_initfn },
     { .name = "ti925t",      .initfn = ti925t_initfn },
     { .name = "sa1100",      .initfn = sa1100_initfn },
     { .name = "sa1110",      .initfn = sa1110_initfn },
target-arm/cpu.h +1 -0
index cd42814..f1cae7f 100644
@@ -410,6 +410,7 @@ enum arm_features {
     ARM_FEATURE_V6,
     ARM_FEATURE_V6K,
     ARM_FEATURE_V7,
+    ARM_FEATURE_V8,
     ARM_FEATURE_THUMB2,
     ARM_FEATURE_MPU,    /* Only has Memory Protection Unit, not full MMU.  */
     ARM_FEATURE_VFP3,
target-arm/kvm.c +8 -0
index 27dcab9..0125f16 100644
@@ -23,6 +23,11 @@
 #include "cpu.h"
 #include "hw/arm/arm.h"
 
+#ifdef TARGET_AARCH64
+#define AARCH64_CORE_REG(x)   (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
+                 KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(x))
+#endif
+
 const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
     KVM_CAP_LAST_INFO
 };
@@ -41,6 +46,28 @@ unsigned long kvm_arch_vcpu_id(CPUState *cpu)
     return cpu->cpu_index;
 }
 
+#ifdef TARGET_AARCH64
+int kvm_arch_init_vcpu(CPUState *cs)
+{

target-arm/kvm.c unsigned long kvm_arch_vcpu_id(CPUState *cpu) · line 61

Quoted 10 lines
target-arm/kvm.c +10 -0
+    struct kvm_vcpu_init init;
+    int ret;
+
+    /* Try initializing with Foundation Models */
+    init.target = KVM_ARM_TARGET_FOUNDATION_V8;
+    memset(init.features, 0, sizeof(init.features));
+    ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
+    if (ret) {
+        /* Retry initializing with Fast Models */
+        init.target = KVM_ARM_TARGET_AEM_V8;

If we're emulating an A57 we should be asking KVM for an A57 guest. If we're asking KVM for "a CPU like the one in the Foundation model" we need to support that via -cpu $something. But I'm a bit dubious about that anyway -- you need to provide a good justification for why KVM/QEMU should be emulating emulators and not hardware.

-- PMM

#7 lore raw

Re: [Qemu-devel] [PATCH 3/6] Added Aarch64 CPU Initialization, Get and Put Registers Support.

Quoted 10 lines · Peter Maydell
Quoted 10 lines
target-arm/kvm.c +9 -0
+#ifdef TARGET_AARCH64
+int kvm_arch_init_vcpu(CPUState *cs)
+{
+    struct kvm_vcpu_init init;
+    int ret;
+
+    /* Try initializing with Foundation Models */
+    init.target = KVM_ARM_TARGET_FOUNDATION_V8;
+    memset(init.features, 0, sizeof(init.features));
Quoted 8 lines

target-arm/kvm.c unsigned long kvm_arch_vcpu_id(CPUState *cpu) · line 61

Quoted 4 lines
target-arm/kvm.c +4 -0
+    ret = kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init);
+    if (ret) {
+        /* Retry initializing with Fast Models */
+        init.target = KVM_ARM_TARGET_AEM_V8;

If we're emulating an A57 we should be asking KVM for an A57 guest. If we're asking KVM for "a CPU like the one in the Foundation model" we need to support that via -cpu $something.

Wouldn't that be an overkill at this early stage? There is no target to test KVM_ARM_TARGET_CORTEX_A57 so we opted for the other two tested cases.

Quoted 3 lines

But I'm a bit dubious about that anyway -- you need to provide a good justification for why KVM/QEMU should be emulating emulators and not hardware.

Mainly because there is no real hardware yet. This patch series was meant to enable basic working support of KVM in AArch64 on what is available and open discussion on how to proceed from there. Also, given that fact that kvmtool uses the same approach it was the most obvious way at the time to handle it.

#8 lore raw

PATCH 4/6 Added the Versatile Express Machine Model for A57

In reply to Mian M. Hamayun

From: "Mian M. Hamayun" <[email protected]>

The vexpress model for A57 is based on the A15 machine model with a few changes in the daughterboard initialization (using a subset of A15 functionality). The A57 daughterboard init also shares the A15MPCore private memory region with A15 daughterboard init function.

---
 hw/arm/vexpress.c |   91 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)
hw/arm/vexpress.c +91 -0
index a077c62..e8070f3 100644
@@ -393,6 +393,74 @@ static const VEDBoardInfo a15_daughterboard = {
     .init = a15_daughterboard_init,
 };
 
+static void a57_daughterboard_init(const VEDBoardInfo *daughterboard,
+                                   ram_addr_t ram_size,
+                                   const char *cpu_model,
+                                   qemu_irq *pic)
+{
+    int n;
+    MemoryRegion *sysmem = get_system_memory();
+    MemoryRegion *ram = g_new(MemoryRegion, 1);
+    qemu_irq cpu_irq[4];
+    DeviceState *dev;
+    SysBusDevice *busdev;
+
+    if (!cpu_model) {
+        cpu_model = "cortex-a57";
+    }
+
+    for (n = 0; n < smp_cpus; n++) {
+        ARMCPU *cpu;
+        qemu_irq *irqp;
+
+        cpu = cpu_arm_init(cpu_model);
+        if (!cpu) {
+            fprintf(stderr, "Unable to find CPU definition\n");
+            exit(1);
+        }
+        irqp = arm_pic_init_cpu(cpu);
+        cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ];
+    }
+
+    {
+        /* We have to use a separate 64 bit variable here to avoid the gcc
+         * "comparison is always false due to limited range of data type"
+         * warning if we are on a host where ram_addr_t is 32 bits.
+         */
+        uint64_t rsz = ram_size;
+        if (rsz > (30ULL * 1024 * 1024 * 1024)) {
+            fprintf(stderr, "vexpress-a57: cannot model more than 30GB RAM\n");
+            exit(1);
+        }
+    }
+
+    memory_region_init_ram(ram, "vexpress.lowmem", ram_size);
+    vmstate_register_ram_global(ram);
+    /* RAM is from 0x80000000 upwards; there is no low-memory alias for it. */
+    memory_region_add_subregion(sysmem, 0x80000000, ram);
+
+    /* 0x2c000000 A15MPCore private memory region (GIC) */
+    dev = qdev_create(NULL, "a15mpcore_priv");
+    qdev_prop_set_uint32(dev, "num-cpu", smp_cpus);
+    qdev_init_nofail(dev);
+    busdev = SYS_BUS_DEVICE(dev);
+    sysbus_mmio_map(busdev, 0, 0x2c000000);
+    for (n = 0; n < smp_cpus; n++) {
+        sysbus_connect_irq(busdev, n, cpu_irq[n]);
+    }
+    /* Interrupts [42:0] are from the motherboard;
+     * [47:43] are reserved; [63:48] are daughterboard
+     * peripherals. Note that some documentation numbers
+     * external interrupts starting from 32 (because there
+     * are internal interrupts 0..31).
+     */
+    for (n = 0; n < 64; n++) {
+        pic[n] = qdev_get_gpio_in(dev, n);
+    }
+
+    /* A57 daughterboard peripherals: not modeled */
+}
+
 static void vexpress_common_init(const VEDBoardInfo *daughterboard,
                                  QEMUMachineInitArgs *args)
 {
@@ -522,6 +590,14 @@ static void vexpress_common_init(const VEDBoardInfo *daughterboard,
     arm_load_kernel(arm_env_get_cpu(first_cpu), &vexpress_binfo);
 }
 
+static const VEDBoardInfo a57_daughterboard = {
+    .motherboard_map = motherboard_aseries_map,
+    .loader_start = 0x80000000,
+    .gic_cpu_if_addr = 0x2c002000,
+    .proc_id = 0x14000237,
+    .init = a57_daughterboard_init,
+};
+
 static void vexpress_a9_init(QEMUMachineInitArgs *args)
 {
     vexpress_common_init(&a9_daughterboard, args);
@@ -532,6 +608,11 @@ static void vexpress_a15_init(QEMUMachineInitArgs *args)
     vexpress_common_init(&a15_daughterboard, args);
 }
 
+static void vexpress_a57_init(QEMUMachineInitArgs *args)
+{
+    vexpress_common_init(&a57_daughterboard, args);
+}
+
 static QEMUMachine vexpress_a9_machine = {
     .name = "vexpress-a9",
     .desc = "ARM Versatile Express for Cortex-A9",
@@ -550,10 +631,20 @@ static QEMUMachine vexpress_a15_machine = {
     DEFAULT_MACHINE_OPTIONS,
 };
 
+static QEMUMachine vexpress_a57_machine = {
+    .name = "vexpress-a57",
+    .desc = "ARM Versatile Express for Cortex-A57",
+    .init = vexpress_a57_init,
+    .block_default_type = IF_SCSI,
+    .max_cpus = 4,
+    DEFAULT_MACHINE_OPTIONS,
+};
+
 static void vexpress_machine_init(void)
 {
     qemu_register_machine(&vexpress_a9_machine);
     qemu_register_machine(&vexpress_a15_machine);
+    qemu_register_machine(&vexpress_a57_machine);
 }
 
 machine_init(vexpress_machine_init);
Signature · 1 line
1.7.9.5
#9 lore raw

Re: [Qemu-devel] [PATCH 4/6] Added the Versatile Express Machine Model for A57

Quoted 6 lines · Mian M. Hamayun

From: "Mian M. Hamayun" <[email protected]>

The vexpress model for A57 is based on the A15 machine model with a few changes in the daughterboard initialization (using a subset of A15 functionality). The A57 daughterboard init also shares the A15MPCore private memory region with A15 daughterboard init function.

So, which documentation or TRM or hardware are you basing this definition of an A57 Versatile Express daughterboard on?

-- PMM

#10 lore raw

Re: [Qemu-devel] [PATCH 4/6] Added the Versatile Express Machine Model for A57

Quoted 10 lines · Peter Maydell
Quoted 6 lines · Mian M. Hamayun

From: "Mian M. Hamayun" <[email protected]>

The vexpress model for A57 is based on the A15 machine model with a few changes in the daughterboard initialization (using a subset of A15 functionality). The A57 daughterboard init also shares the A15MPCore private memory region with A15 daughterboard init function.

So, which documentation or TRM or hardware are you basing this definition of an A57 Versatile Express daughterboard on?

Currently there is no existing hardware that I am aware of, or a public TRM describing it. On existing ARMv8 models the peripherals used and the platform memory map seems to be identical with the previous iteration. Based on that, the same approach was followed to have a working setup, on which to base further development when another target is available.

#11 lore raw

Re: [Qemu-devel] [PATCH 4/6] Added the Versatile Express Machine Model for A57

Quoted 6 lines · Alexander Spyridakis
Quoted 2 lines · Peter Maydell

So, which documentation or TRM or hardware are you basing this definition of an A57 Versatile Express daughterboard on?

Currently there is no existing hardware that I am aware of, or a public TRM describing it.

Then you can't put a board model into QEMU that claims to be a vexpress-a57. What you want is mach-virt (see John Rigby's patchset).

thanks
-- PMM

#12 lore raw

PATCH 5/6 Added Boot Support for Aarch64 Processor.

In reply to Mian M. Hamayun

From: "Mian M. Hamayun" <[email protected]>

This version supports booting of a single Aarch64 CPU by setting appropriate registers. The bootloader includes placehoders for Board-ID that are used to implementing uniform indexing across different bootloaders.
The same macro names are used with different values when compiling for different processors.

---
 hw/arm/boot.c |   45 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 6 deletions(-)
hw/arm/boot.c +39 -6
index defcf15..94e628b 100644
@@ -18,7 +18,33 @@
 #include "qemu/config-file.h"
 
 #define KERNEL_ARGS_ADDR 0x100
-#define KERNEL_LOAD_ADDR 0x00010000
+
+#ifdef TARGET_AARCH64
+#define KERNEL_LOAD_ADDR        0x00080000
+#define KERNEL_ARGS_INDEX       6
+#define KERNEL_ENTRY_INDEX      8
+#define KERNEL_BOARDID_INDEX    10
+
+static uint32_t bootloader[] = {
+    0x580000c0, 	/* ldr	x0, 18 <_start+0x18> */
+    0xaa1f03e1, 	/* mov	x1, xzr */
+    0xaa1f03e2, 	/* mov	x2, xzr */
+    0xaa1f03e3, 	/* mov	x3, xzr */
+    0x58000084, 	/* ldr	x4, 20 <_start+0x20> */
+    0xd61f0080, 	/* br	x4 */
+    0x00000000, 	/* .word @DTB Lower 32-bits */
+    0x00000000, 	/* .word @DTB Higher 32-bits */
+    0x00000000, 	/* .word @Kernel Entry Lower 32-bits */
+    0x00000000,  	/* .word @Kernel Entry Higher 32-bits */
+    0x00000000, 	/* .word @Board ID Lower 32-bits -- Placeholder */
+    0x00000000  	/* .word @Board ID Higher 32-bits -- Placeholder */
+};
+
+#else
+#define KERNEL_LOAD_ADDR        0x00010000
+#define KERNEL_BOARDID_INDEX    4
+#define KERNEL_ARGS_INDEX       5
+#define KERNEL_ENTRY_INDEX      6
 
 /* The worlds second smallest bootloader.  Set r0-r2, then jump to kernel.  */
 static uint32_t bootloader[] = {
@@ -30,6 +56,7 @@ static uint32_t bootloader[] = {
   0, /* Address of kernel args.  Set by integratorcp_init.  */
   0  /* Kernel entry point.  Set by integratorcp_init.  */
 };
+#endif
 
 /* Handling for secondary CPU boot in a multicore system.
  * Unlike the uniprocessor/primary CPU boot, this is platform
@@ -239,7 +266,6 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo)
         fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename);
         return -1;
     }
-
     fdt = load_device_tree(filename, &size);
     if (!fdt) {
         fprintf(stderr, "Couldn't open dtb file %s\n", filename);
@@ -322,8 +348,15 @@ static void do_cpu_reset(void *opaque)
             env->regs[15] = info->entry & 0xfffffffe;
             env->thumb = info->entry & 1;
         } else {
+#ifdef TARGET_AARCH64
+            env->pstate = PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | PSR_MODE_EL1h;
+#endif
             if (env == first_cpu) {
+#ifdef TARGET_AARCH64
+                env->pc = info->loader_start;
+#else
                 env->regs[15] = info->loader_start;
+#endif
                 if (!info->dtb_filename) {
                     if (old_param) {
                         set_kernel_args_old(info);
@@ -428,7 +461,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)
         }
         info->initrd_size = initrd_size;
 
-        bootloader[4] = info->board_id;
+        bootloader[KERNEL_BOARDID_INDEX] = info->board_id;
 
         /* for device tree boot, we pass the DTB directly in r2. Otherwise
          * we point to the kernel args.
@@ -443,9 +476,9 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)
             if (load_dtb(dtb_start, info)) {
                 exit(1);
             }
-            bootloader[5] = dtb_start;
+            bootloader[KERNEL_ARGS_INDEX] = dtb_start;
         } else {
-            bootloader[5] = info->loader_start + KERNEL_ARGS_ADDR;
+            bootloader[KERNEL_ARGS_INDEX] = info->loader_start + KERNEL_ARGS_ADDR;
             if (info->ram_size >= (1ULL << 32)) {
                 fprintf(stderr, "qemu: RAM size must be less than 4GB to boot"
                         " Linux kernel using ATAGS (try passing a device tree"
@@ -453,7 +486,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)
                 exit(1);
             }
         }
-        bootloader[6] = entry;
+        bootloader[KERNEL_ENTRY_INDEX] = entry;
         for (n = 0; n < sizeof(bootloader) / 4; n++) {
             bootloader[n] = tswap32(bootloader[n]);
         }
Signature · 1 line
1.7.9.5
#13 lore raw

PATCH 6/6 Added SMP for Aarch64 Processors.

In reply to Mian M. Hamayun

From: Alexander Spyridakis <[email protected]>

AArch64 uses a cpu-release-addr memory location (defined in the dts) as a way to inform secondary CPUs where to jump to and enter their holding pen. Inject a very simple bootloader that polls this memory location, until the primary CPU sets it to the right address.

---
 hw/arm/boot.c |   20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
hw/arm/boot.c +17 -3
index 94e628b..f7a97d1 100644
@@ -17,6 +17,8 @@
 #include "sysemu/device_tree.h"
 #include "qemu/config-file.h"
 
+#define DSB_INSN 0xf57ff04f
+#define CP15_DSB_INSN 0xee070f9a /* mcr cp15, 0, r0, c7, c10, 4 */
 #define KERNEL_ARGS_ADDR 0x100
 
 #ifdef TARGET_AARCH64
@@ -40,6 +42,16 @@ static uint32_t bootloader[] = {
     0x00000000  	/* .word @Board ID Higher 32-bits -- Placeholder */
 };
 
+static uint32_t smpboot[] = {
+  0x18000085, /* ldr w5, =0x8000fff8 - mbox value for secondary CPUs */
+  0xf94000a4, /* 1: ldr x4, [x5] - Read address to jump to */
+  0xb4ffffe4, /* cbz x4, 1b - Check if mbox value is zero, if yes retry */
+  0xd61f0080, /* br x4 - Branch to given address */
+  0x8000fff8, /* mbox value */
+  0,
+  0
+};
+
 #else
 #define KERNEL_LOAD_ADDR        0x00010000
 #define KERNEL_BOARDID_INDEX    4
@@ -56,7 +68,6 @@ static uint32_t bootloader[] = {
   0, /* Address of kernel args.  Set by integratorcp_init.  */
   0  /* Kernel entry point.  Set by integratorcp_init.  */
 };
-#endif
 
 /* Handling for secondary CPU boot in a multicore system.
  * Unlike the uniprocessor/primary CPU boot, this is platform
@@ -72,8 +83,6 @@ static uint32_t bootloader[] = {
  * for an interprocessor interrupt and polling a configurable
  * location for the kernel secondary CPU entry point.
  */
-#define DSB_INSN 0xf57ff04f
-#define CP15_DSB_INSN 0xee070f9a /* mcr cp15, 0, r0, c7, c10, 4 */
 
 static uint32_t smpboot[] = {
   0xe59f2028, /* ldr r2, gic_cpu_if */
@@ -91,6 +100,7 @@ static uint32_t smpboot[] = {
   0,          /* gic_cpu_if: base address of GIC CPU interface */
   0           /* bootreg: Boot register address is held here */
 };
+#endif
 
 static void default_write_secondary(ARMCPU *cpu,
                                     const struct arm_boot_info *info)
@@ -115,8 +125,12 @@ static void default_reset_secondary(ARMCPU *cpu,
 {
     CPUARMState *env = &cpu->env;
 
+#ifdef TARGET_AARCH64
+    env->pc = info->smp_loader_start;
+#else
     stl_phys_notdirty(info->smp_bootreg_addr, 0);
     env->regs[15] = info->smp_loader_start;
+#endif
 }
 
 #define WRITE_WORD(p, value) do { \
Signature · 1 line
1.7.9.5
#14 lore raw

Re: [Qemu-devel] [PATCH 6/6] Added SMP for Aarch64 Processors.

Quoted 6 lines · Mian M. Hamayun

From: Alexander Spyridakis <[email protected]>

AArch64 uses a cpu-release-addr memory location (defined in the dts) as a way to inform secondary CPUs where to jump to and enter their holding pen. Inject a very simple bootloader that polls this memory location, until the primary CPU sets it to the right address.

This and the previous patch are a bit heavy on the #ifdef TARGET_AARCH64. I suspect the code could be restructured better to avoid that.

thanks
-- PMM

#15 lore raw

Re: [Qemu-devel] [PATCH 6/6] Added SMP for Aarch64 Processors.

Quoted 10 lines · Peter Maydell
Quoted 6 lines · Mian M. Hamayun

From: Alexander Spyridakis <[email protected]>

AArch64 uses a cpu-release-addr memory location (defined in the dts) as a way to inform secondary CPUs where to jump to and enter their holding pen. Inject a very simple bootloader that polls this memory location, until the primary CPU sets it to the right address.

This and the previous patch are a bit heavy on the #ifdef TARGET_AARCH64. I suspect the code could be restructured better to avoid that.

Fair point. Initially it was even heavier on the #ifdef usage, and for the first version we opted for something in-between in order to get comments first. Next version will improve this with some further restructuring.

Regards.

#16 lore raw
In reply to Mian M. Hamayun
Quoted 16 lines · Mian M. Hamayun

From: "Mian M. Hamayun" <[email protected]>

---
 configure                           |    3 +-
 default-configs/aarch64-softmmu.mak |   83 +++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 1 deletion(-)
 create mode 100644 default-configs/aarch64-softmmu.mak
configure +0 -0
index b247e5b..ddec40d 100755
@@ -4293,10 +4293,11 @@ case "$target_name" in
   *)
 esac

configure case "$target_name" in · line 4303

Quoted 10 lines
configure +2 -1
 case "$target_name" in
-  arm|i386|x86_64|ppcemb|ppc|ppc64|s390x)
+  arm|aarch64|i386|x86_64|ppcemb|ppc|ppc64|s390x)
     # Make sure the target and host cpus are compatible
     if test "$kvm" = "yes" -a "$target_softmmu" = "yes" -a \
       \( "$target_name" = "$cpu" -o \
+      \( "$target_name" = "arm"    -a "$cpu" = "aarch64"   \) -o \
       \( "$target_name" = "ppcemb" -a "$cpu" = "ppc" \) -o \
       \( "$target_name" = "ppc64"  -a "$cpu" = "ppc" \) -o \
       \( "$target_name" = "ppc"    -a "$cpu" = "ppc64" \) -o \

So this is enabling support for emulating 32 bit VMs with a QEMU running as a 64 bit process, but the commit message doesn't mention this. Did you test that combination?

thanks
-- PMM

#17 lore raw
Quoted 3 lines · Peter Maydell

So this is enabling support for emulating 32 bit VMs with a QEMU running as a 64 bit process, but the commit message doesn't mention this. Did you test that combination?

Nope, this case is not handled. Currently it won't crash but of course won't boot either. Definitely worth looking into, at the very minimum it should gracefully deny execution.

Regards.

#18 lore raw
Quoted 4 lines · Alexander Spyridakis
Quoted 3 lines · Peter Maydell

So this is enabling support for emulating 32 bit VMs with a QEMU running as a 64 bit process, but the commit message doesn't mention this. Did you test that combination?

Actually I wasn't quite right here -- in fact

    \( "$target_name" = "arm"    -a "$cpu" = "aarch64"   \)

is the case where you're building a QEMU running as a 64 bit binary but only supporting 32 bit CPUs. In particular this would try to build a 64 bit binary but with QEMU's copy of the 32 bit kernel headers:
I'm not sure that's expected (by the kernel folk) to work at all. If not, we should just not put the line into configure in the first place.

Note that that still leaves the case of "built aarch64-softmmu with KVM support and user used -cpu cortex-a15" which you can only catch at runtime. My guess is that will either (a) work or (b) be caught already by the KVM_ARM_VCPU_INIT ioctl failing because we asked for KVM_ARM_TARGET_CORTEX_A15 and the kernel didn't support it. Either way, it seems like a more sensible way to support the 32-on-64 case when we eventually choose to do so.

Quoted 3 lines

Nope, this case is not handled. Currently it won't crash but of course won't boot either. Definitely worth looking into, at the very minimum it should gracefully deny execution.

Yes, in general I'm happy for us not to support 32-bit-VM-on-64-host initially, as long as it fails gracefully.

thanks
-- PMM

#19 lore raw

On 1 July 2013 20:22, Peter Maydell <[email protected]> wrote:
In particular this would try to build

Quoted 3 lines

a 64 bit binary but with QEMU's copy of the 32 bit kernel headers:
I'm not sure that's expected (by the kernel folk) to work at all. If not, we should just not put the line into configure in the first place.

Sorry, this bit is wrong; ignore it. We pick the kernel headers based on $cpu, not $target, so get the aarch64 ones whether we're building arm-softmmu or aarch64-softmmu.

-- PMM