KVM: MIPS: Add Loongson-3 support (Host Side)
Subsystems (4)
v8 cover KVM: MIPS: Add Loongson-3 support (Host Side)
We are preparing to add KVM support for Loongson-3. VZ extension is fully supported in Loongson-3A R4+, and we will not care about old CPUs (at least now). We already have a full functional Linux kernel (based on Linux-5.4.x LTS) and QEMU (based on 5.0.0) and their git repositories are here:
QEMU: https://github.com/chenhuacai/qemu
Kernel: https://github.com/chenhuacai/linux
Of course these two repositories need to be rework and not suitable for upstream (especially the commits need to be splitted). We show them here is just to tell others what we have done, and how KVM/Loongson will look like.
Our plan is make the KVM host side be upstream first, and after that, we will make the KVM guest side and QEMU emulator be upstream.
V1 -> V2:
1, Remove "mips: define pud_index() regardless of page table folding"
because it has been applied.
2, Make Loongson-specific code be guarded by CONFIG_CPU_LOONGSON64.
V2 -> V3:
1, Emulate a reduced feature list of CPUCFG. 2, Fix all possible checkpatch.pl errors and warnings.
V3 -> V4:
1, Emulate LOONGSON_CFG0/LOONGSON_CFG3 in CPUCFG correctly.
2, Update commit messages to explain Loongson-3 Virtual IPI. 3, Add Reviewed-by: Aleksandar Markovic <[email protected]>.
V4 -> V5:
1, Fix a typo.
2, Update MAINTAINERS.
V5 -> V6:
1, Fix a mismatch during rebasing.
2, Add Acked-by: Thomas Bogendoerfer <[email protected]>.
V6 -> V7:
1, Rebase on latest mips-next (Config6 feature bits definition updated).
V7 -> V8:
1, Rebase to be applied on kvm tree, i.e., the linux-next branch of
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/. Building KVM/MIPS need commit 3fbfb4585bfd4ff34e ("mips: define pud_index() regardless of page table folding"), which has already been in mips tree but not in kvm tree.
Xing Li(2):
KVM: MIPS: Define KVM_ENTRYHI_ASID to cpu_asid_mask(&boot_cpu_data)
KVM: MIPS: Fix VPN2_MASK definition for variable cpu_vmbits
Huacai Chen(13):
KVM: MIPS: Increase KVM_MAX_VCPUS and KVM_USER_MEM_SLOTS to 16
KVM: MIPS: Add EVENTFD support which is needed by VHOST
KVM: MIPS: Use lddir/ldpte instructions to lookup gpa_mm.pgd
KVM: MIPS: Introduce and use cpu_guest_has_ldpte
KVM: MIPS: Use root tlb to control guest's CCA for Loongson-3
KVM: MIPS: Let indexed cacheops cause guest exit on Loongson-3
KVM: MIPS: Add more types of virtual interrupts
KVM: MIPS: Add Loongson-3 Virtual IPI interrupt support
KVM: MIPS: Add CPUCFG emulation for Loongson-3
KVM: MIPS: Add CONFIG6 and DIAG registers emulation
KVM: MIPS: Add more MMIO load/store instructions emulation
KVM: MIPS: Enable KVM support for Loongson-3
MAINTAINERS: Update KVM/MIPS maintainers
--- MAINTAINERS | 4 +- arch/mips/Kconfig | 1 + arch/mips/include/asm/cpu-features.h | 3 + arch/mips/include/asm/kvm_host.h | 52 +++- arch/mips/include/asm/mipsregs.h | 7 + arch/mips/include/uapi/asm/inst.h | 37 +++ arch/mips/kernel/cpu-probe.c | 2 + arch/mips/kvm/Kconfig | 1 + arch/mips/kvm/Makefile | 5 +- arch/mips/kvm/emulate.c | 503 ++++++++++++++++++++++++++++++++++- arch/mips/kvm/entry.c | 19 +- arch/mips/kvm/interrupt.c | 93 +------ arch/mips/kvm/interrupt.h | 14 +- arch/mips/kvm/loongson_ipi.c | 214 +++++++++++++++ arch/mips/kvm/mips.c | 49 +++- arch/mips/kvm/tlb.c | 41 +++ arch/mips/kvm/trap_emul.c | 3 + arch/mips/kvm/vz.c | 237 ++++++++++++----- 18 files changed, 1118 insertions(+), 167 deletions(-) create mode 100644 arch/mips/kvm/loongson_ipi.c
--
2.7.0
PATCH v8 1/15 KVM: MIPS: Define KVM_ENTRYHI_ASID to cpu_asid_mask(&boot_cpu_data)
From: Xing Li <[email protected]>
The code in decode_config4() of arch/mips/kernel/cpu-probe.c
asid_mask = MIPS_ENTRYHI_ASID;
if (config4 & MIPS_CONF4_AE)
asid_mask |= MIPS_ENTRYHI_ASIDX;
set_cpu_asid_mask(c, asid_mask);set asid_mask to cpuinfo->asid_mask.
So in order to support variable ASID_MASK, KVM_ENTRYHI_ASID should also be changed to cpu_asid_mask(&boot_cpu_data).
--- arch/mips/include/asm/kvm_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/kvm_host.h +1 -1
@@ -277,7 +277,7 @@ enum emulation_result {#define MIPS3_PG_FRAME 0x3fffffc0#define VPN2_MASK 0xffffe000 -#define KVM_ENTRYHI_ASID MIPS_ENTRYHI_ASID +#define KVM_ENTRYHI_ASID cpu_asid_mask(&boot_cpu_data)#define TLB_IS_GLOBAL (x) ((x).tlb_lo[0] & (x).tlb_lo[1] & ENTRYLO_G)#define TLB_VPN2 (x) ((x).tlb_hi & VPN2_MASK)#define TLB_ASID (x) ((x).tlb_hi & KVM_ENTRYHI_ASID)
Signature · 1 line
2.7.0
PATCH v8 2/15 KVM: MIPS: Fix VPN2_MASK definition for variable cpu_vmbits
In reply to Huacai ChenFrom: Xing Li <[email protected]>
If a CPU support more than 32bit vmbits (which is true for 64bit CPUs), VPN2_MASK set to fixed 0xffffe000 will lead to a wrong EntryHi in some functions such as _kvm_mips_host_tlb_inv().
The cpu_vmbits definition of 32bit CPU in cpu-features.h is 31, so we still use the old definition.
--- arch/mips/include/asm/kvm_host.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/mips/include/asm/kvm_host.h +4 -0
@@ -276,7 +276,11 @@ enum emulation_result {#define MIPS3_PG_SHIFT 6#define MIPS3_PG_FRAME 0x3fffffc0 +#if defined(CONFIG_64BIT ) +#define VPN2_MASK GENMASK(cpu_vmbits - 1, 13) +#else #define VPN2_MASK 0xffffe000 +#endif #define KVM_ENTRYHI_ASID cpu_asid_mask(&boot_cpu_data)#define TLB_IS_GLOBAL (x) ((x).tlb_lo[0] & (x).tlb_lo[1] & ENTRYLO_G)#define TLB_VPN2 (x) ((x).tlb_hi & VPN2_MASK)
Signature · 1 line
2.7.0
PATCH v8 3/15 KVM: MIPS: Increase KVM_MAX_VCPUS and KVM_USER_MEM_SLOTS to 16
In reply to Huacai ChenLoongson-3 based machines can have as many as 16 CPUs, and so does memory slots, so increase KVM_MAX_VCPUS and KVM_USER_MEM_SLOTS to 16.
--- arch/mips/include/asm/kvm_host.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/mips/include/asm/kvm_host.h +2 -2
@@ -78,8 +78,8 @@#define KVM_REG_MIPS_CP0_KSCRATCH6 MIPS_CP0_64(31, 7) -#define KVM_MAX_VCPUS 8 -#define KVM_USER_MEM_SLOTS 8 +#define KVM_MAX_VCPUS 16 +#define KVM_USER_MEM_SLOTS 16/* memory slots that does not exposed to userspace */ #define KVM_PRIVATE_MEM_SLOTS 0
Signature · 1 line
2.7.0
PATCH v8 4/15 KVM: MIPS: Add EVENTFD support which is needed by VHOST
In reply to Huacai ChenAdd EVENTFD support for KVM/MIPS, which is needed by VHOST. Tested on Loongson-3 platform.
--- arch/mips/kvm/Kconfig | 1 + arch/mips/kvm/Makefile | 2 +- arch/mips/kvm/trap_emul.c | 3 +++ arch/mips/kvm/vz.c | 3 +++ 4 files changed, 8 insertions(+), 1 deletion(-)
arch/mips/kvm/Kconfig +1 -0
@@ -22,6 +22,7 @@ config KVM select EXPORT_UASM select PREEMPT_NOTIFIERS select KVM_GENERIC_DIRTYLOG_READ_PROTECT + select HAVE_KVM_EVENTFD select HAVE_KVM_VCPU_ASYNC_IOCTL select KVM_MMIO select MMU_NOTIFIER
arch/mips/kvm/Makefile +1 -1
@@ -2,7 +2,7 @@ # Makefile for KVM support for MIPS # -common-objs-y = $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o) +common-objs-y = $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o eventfd.o) EXTRA_CFLAGS += -Ivirt/kvm -Iarch/mips/kvm
arch/mips/kvm/trap_emul.c +3 -0
@@ -529,6 +529,9 @@ static int kvm_trap_emul_check_extension(struct kvm *kvm, long ext)case KVM_CAP_MIPS_TE : r =1 ;break ; +case KVM_CAP_IOEVENTFD : + r =1 ; +break ;default : r =0 ;break ;
arch/mips/kvm/vz.c +3 -0
@@ -2927,6 +2927,9 @@ static int kvm_vz_check_extension(struct kvm *kvm, long ext) r =2 ;break ;#endif +case KVM_CAP_IOEVENTFD : + r =1 ; +break ;default : r =0 ;break ;
Signature · 1 line
2.7.0
PATCH v8 5/15 KVM: MIPS: Use lddir/ldpte instructions to lookup gpa_mm.pgd
In reply to Huacai ChenLoongson-3 can use lddir/ldpte instuctions to accelerate page table walking, so use them to lookup gpa_mm.pgd.
--- arch/mips/kvm/entry.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
arch/mips/kvm/entry.c +18 -1
@@ -56,6 +56,7 @@#define C0_BADVADDR 8, 0#define C0_BADINSTR 8, 1#define C0_BADINSTRP 8, 2 +#define C0_PGD 9, 7#define C0_ENTRYHI 10, 0#define C0_GUESTCTL1 10, 4#define C0_STATUS 12, 0
@@ -307,7 +308,10 @@ static void *kvm_mips_build_enter_guest(void *addr)#ifdef CONFIG_KVM_MIPS_VZ /* Save normal linux process pgd (VZ guarantees pgd_reg is set) */ -UASM_i_MFC0 (&p,K0 ,c0_kscratch (), pgd_reg); +if (cpu_has_ldpte) +UASM_i_MFC0 (&p,K0 ,C0_PWBASE ); +else +UASM_i_MFC0 (&p,K0 ,c0_kscratch (), pgd_reg);UASM_i_SW (&p,K0 , offsetof(struct kvm_vcpu_arch , host_pgd),K1 );/*
@@ -469,8 +473,10 @@ void *kvm_mips_build_tlb_refill_exception(void *addr, void *handler)u32 *p = addr;struct uasm_label labels[2 ];struct uasm_reloc relocs[2 ]; +#ifndef CONFIG_CPU_LOONGSON64 struct uasm_label *l = labels;struct uasm_reloc *r = relocs; +#endif memset (labels,0 ,sizeof (labels));memset (relocs,0 ,sizeof (relocs));
@@ -490,6 +496,16 @@ void *kvm_mips_build_tlb_refill_exception(void *addr, void *handler)*/ preempt_disable (); +#ifdef CONFIG_CPU_LOONGSON64 +UASM_i_MFC0 (&p,K1 ,C0_PGD ); +uasm_i_lddir (&p,K0 ,K1 ,3 );/* global page dir */ +#ifndef __PAGETABLE_PMD_FOLDED +uasm_i_lddir (&p,K1 ,K0 ,1 );/* middle page dir */ +#endif +uasm_i_ldpte (&p,K1 ,0 );/* even */ +uasm_i_ldpte (&p,K1 ,1 );/* odd */ +uasm_i_tlbwr (&p); +#else /* * Now for the actual refill bit. A lot of this can be common with the * Linux TLB refill handler, however we don't need to handle so many
@@ -512,6 +528,7 @@ void *kvm_mips_build_tlb_refill_exception(void *addr, void *handler)build_get_ptep (&p,K0 ,K1 );build_update_entries (&p,K0 ,K1 );build_tlb_write_entry (&p, &l, &r, tlb_random); +#endif preempt_enable ();
Signature · 1 line
2.7.0
PATCH v8 6/15 KVM: MIPS: Introduce and use cpu_guest_has_ldpte
In reply to Huacai ChenLoongson-3 has lddir/ldpte instructions and their related CP0 registers are the same as HTW. So we introduce a cpu_guest_has_ldpte flag and use it to indicate whether we need to save/restore HTW related CP0 registers (PWBase, PWSize, PWField and PWCtl).
--- arch/mips/include/asm/cpu-features.h | 3 +++ arch/mips/kernel/cpu-probe.c | 1 + arch/mips/kvm/vz.c | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 13 deletions(-)
arch/mips/include/asm/cpu-features.h +3 -0
@@ -665,6 +665,9 @@#ifndef cpu_guest_has_htw#define cpu_guest_has_htw (cpu_data[0].guest.options & MIPS_CPU_HTW)#endif +#ifndef cpu_guest_has_ldpte +#define cpu_guest_has_ldpte (cpu_data[0].guest.options & MIPS_CPU_LDPTE) +#endif #ifndef cpu_guest_has_mvh#define cpu_guest_has_mvh (cpu_data[0].guest.options & MIPS_CPU_MVH)#endif
arch/mips/kernel/cpu-probe.c +1 -0
@@ -1966,6 +1966,7 @@ static inline void cpu_probe_loongson(struct cpuinfo_mips *c, unsigned int cpu)set_isa (c,MIPS_CPU_ISA_M64R2 );decode_configs (c); c->options |=MIPS_CPU_FTLB |MIPS_CPU_TLBINV |MIPS_CPU_LDPTE ; + c->guest.options |=MIPS_CPU_LDPTE ; c->writecombine = _CACHE_UNCACHED_ACCELERATED; c->ases |= (MIPS_ASE_LOONGSON_MMI |MIPS_ASE_LOONGSON_CAM |MIPS_ASE_LOONGSON_EXT |MIPS_ASE_LOONGSON_EXT2 );
arch/mips/kvm/vz.c +13 -13
@@ -1706,7 +1706,7 @@ static unsigned long kvm_vz_num_regs(struct kvm_vcpu *vcpu) ret +=ARRAY_SIZE (kvm_vz_get_one_regs_contextconfig);if (cpu_guest_has_segments) ret +=ARRAY_SIZE (kvm_vz_get_one_regs_segments); -if (cpu_guest_has_htw) +if (cpu_guest_has_htw || cpu_guest_has_ldpte) ret +=ARRAY_SIZE (kvm_vz_get_one_regs_htw);if (cpu_guest_has_maar && !cpu_guest_has_dyn_maar) ret +=1 +ARRAY_SIZE (vcpu->arch.maar);
@@ -1755,7 +1755,7 @@ static int kvm_vz_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices)return -EFAULT ; indices +=ARRAY_SIZE (kvm_vz_get_one_regs_segments); } -if (cpu_guest_has_htw) { +if (cpu_guest_has_htw || cpu_guest_has_ldpte) {if (copy_to_user (indices, kvm_vz_get_one_regs_htw,sizeof (kvm_vz_get_one_regs_htw)))return -EFAULT ;
@@ -1878,17 +1878,17 @@ static int kvm_vz_get_one_reg(struct kvm_vcpu *vcpu, *v =read_gc0_segctl2 ();break ;case KVM_REG_MIPS_CP0_PWBASE : -if (!cpu_guest_has_htw) +if (!cpu_guest_has_htw && !cpu_guest_has_ldpte)return -EINVAL ; *v =read_gc0_pwbase ();break ;case KVM_REG_MIPS_CP0_PWFIELD : -if (!cpu_guest_has_htw) +if (!cpu_guest_has_htw && !cpu_guest_has_ldpte)return -EINVAL ; *v =read_gc0_pwfield ();break ;case KVM_REG_MIPS_CP0_PWSIZE : -if (!cpu_guest_has_htw) +if (!cpu_guest_has_htw && !cpu_guest_has_ldpte)return -EINVAL ; *v =read_gc0_pwsize ();break ;
@@ -1896,7 +1896,7 @@ static int kvm_vz_get_one_reg(struct kvm_vcpu *vcpu, *v = (long )read_gc0_wired ();break ;case KVM_REG_MIPS_CP0_PWCTL : -if (!cpu_guest_has_htw) +if (!cpu_guest_has_htw && !cpu_guest_has_ldpte)return -EINVAL ; *v =read_gc0_pwctl ();break ;
@@ -2101,17 +2101,17 @@ static int kvm_vz_set_one_reg(struct kvm_vcpu *vcpu,write_gc0_segctl2 (v);break ;case KVM_REG_MIPS_CP0_PWBASE : -if (!cpu_guest_has_htw) +if (!cpu_guest_has_htw && !cpu_guest_has_ldpte)return -EINVAL ;write_gc0_pwbase (v);break ;case KVM_REG_MIPS_CP0_PWFIELD : -if (!cpu_guest_has_htw) +if (!cpu_guest_has_htw && !cpu_guest_has_ldpte)return -EINVAL ;write_gc0_pwfield (v);break ;case KVM_REG_MIPS_CP0_PWSIZE : -if (!cpu_guest_has_htw) +if (!cpu_guest_has_htw && !cpu_guest_has_ldpte)return -EINVAL ;write_gc0_pwsize (v);break ;
@@ -2119,7 +2119,7 @@ static int kvm_vz_set_one_reg(struct kvm_vcpu *vcpu,change_gc0_wired (MIPSR6_WIRED_WIRED , v);break ;case KVM_REG_MIPS_CP0_PWCTL : -if (!cpu_guest_has_htw) +if (!cpu_guest_has_htw && !cpu_guest_has_ldpte)return -EINVAL ;write_gc0_pwctl (v);break ;
@@ -2580,7 +2580,7 @@ static int kvm_vz_vcpu_load(struct kvm_vcpu *vcpu, int cpu) }/* restore HTW registers */ -if (cpu_guest_has_htw) { +if (cpu_guest_has_htw || cpu_guest_has_ldpte) {kvm_restore_gc0_pwbase (cop0);kvm_restore_gc0_pwfield (cop0);kvm_restore_gc0_pwsize (cop0);
@@ -2685,8 +2685,8 @@ static int kvm_vz_vcpu_put(struct kvm_vcpu *vcpu, int cpu) }/* save HTW registers if enabled in guest */ -if (cpu_guest_has_htw && -kvm_read_sw_gc0_config3 (cop0) &MIPS_CONF3_PW ) { +if (cpu_guest_has_ldpte || (cpu_guest_has_htw && +kvm_read_sw_gc0_config3 (cop0) &MIPS_CONF3_PW )) {kvm_save_gc0_pwbase (cop0);kvm_save_gc0_pwfield (cop0);kvm_save_gc0_pwsize (cop0);
Signature · 1 line
2.7.0
PATCH v8 7/15 KVM: MIPS: Use root tlb to control guest's CCA for Loongson-3
In reply to Huacai ChenKVM guest has two levels of address translation: guest tlb translates GVA to GPA, and root tlb translates GPA to HPA. By default guest's CCA is controlled by guest tlb, but Loongson-3 maintains all cache coherency by hardware (including multi-core coherency and I/O DMA coherency) so it prefers all guest mappings be cacheable mappings. Thus, we use root tlb to control guest's CCA for Loongson-3.
--- arch/mips/kvm/vz.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/mips/kvm/vz.c +6 -0
@@ -2871,6 +2871,12 @@ static int kvm_vz_hardware_enable(void)if (cpu_has_guestctl2)clear_c0_guestctl2 (0x3f <<10 ); +#ifdef CONFIG_CPU_LOONGSON64 +/* Control guest CCA attribute */ +if (cpu_has_csr ()) +csr_writel (csr_readl (0xffffffec ) |0x1 ,0xffffffec ); +#endif +return 0 ; }
Signature · 1 line
2.7.0
PATCH v8 8/15 KVM: MIPS: Let indexed cacheops cause guest exit on Loongson-3
In reply to Huacai ChenLoongson-3's indexed cache operations need a node-id in the address, but in KVM guest the node-id may be incorrect. So, let indexed cache operations cause guest exit on Loongson-3.
--- arch/mips/kvm/vz.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/mips/kvm/vz.c +6 -2
@@ -2853,8 +2853,12 @@ static int kvm_vz_hardware_enable(void)write_c0_guestctl0 (MIPS_GCTL0_CP0 | (MIPS_GCTL0_AT_GUEST <<MIPS_GCTL0_AT_SHIFT ) |MIPS_GCTL0_CG |MIPS_GCTL0_CF ); -if (cpu_has_guestctl0ext) -set_c0_guestctl0ext (MIPS_GCTL0EXT_CGI ); +if (cpu_has_guestctl0ext) { +if (current_cpu_type () !=CPU_LOONGSON64 ) +set_c0_guestctl0ext (MIPS_GCTL0EXT_CGI ); +else +clear_c0_guestctl0ext (MIPS_GCTL0EXT_CGI ); + }if (cpu_has_guestid) {write_c0_guestctl1 (0 );
Signature · 1 line
2.7.0
PATCH v8 9/15 KVM: MIPS: Add more types of virtual interrupts
In reply to Huacai ChenIn current implementation, MIPS KVM uses IP2, IP3, IP4 and IP7 for external interrupt, two kinds of IPIs and timer interrupt respectively, but Loongson-3 based machines prefer to use IP2, IP3, IP6 and IP7 for two kinds of external interrupts, IPI and timer interrupt. So we define two priority-irq mapping tables: kvm_loongson3_priority_to_irq[] for Loongson-3, and kvm_default_priority_to_irq[] for others. The virtual interrupt infrastructure is updated to deliver all types of interrupts from IP2, IP3, IP4, IP6 and IP7.
--- arch/mips/kvm/interrupt.c | 93 +++++++---------------------------------------- arch/mips/kvm/interrupt.h | 14 ++++--- arch/mips/kvm/mips.c | 40 ++++++++++++++++++-- arch/mips/kvm/vz.c | 53 ++++----------------------- 4 files changed, 67 insertions(+), 133 deletions(-)
arch/mips/kvm/interrupt.c +13 -80
@@ -61,27 +61,8 @@ void kvm_mips_queue_io_int_cb(struct kvm_vcpu *vcpu,* the EXC code will be set when we are actually * delivering the interrupt: */ -switch (intr) { -case 2 : -kvm_set_c0_guest_cause (vcpu->arch.cop0, (C_IRQ0 )); -/* Queue up an INT exception for the core */ -kvm_mips_queue_irq (vcpu,MIPS_EXC_INT_IO ); -break ; - -case 3 : -kvm_set_c0_guest_cause (vcpu->arch.cop0, (C_IRQ1 )); -kvm_mips_queue_irq (vcpu,MIPS_EXC_INT_IPI_1 ); -break ; - -case 4 : -kvm_set_c0_guest_cause (vcpu->arch.cop0, (C_IRQ2 )); -kvm_mips_queue_irq (vcpu,MIPS_EXC_INT_IPI_2 ); -break ; - -default : -break ; - } - +kvm_set_c0_guest_cause (vcpu->arch.cop0,1 << (intr +8 )); +kvm_mips_queue_irq (vcpu,kvm_irq_to_priority (intr)); } void kvm_mips_dequeue_io_int_cb(struct kvm_vcpu *vcpu,
@@ -89,26 +70,8 @@ void kvm_mips_dequeue_io_int_cb(struct kvm_vcpu *vcpu, {int intr = (int )irq->irq; -switch (intr) { -case -2 : -kvm_clear_c0_guest_cause (vcpu->arch.cop0, (C_IRQ0 )); -kvm_mips_dequeue_irq (vcpu,MIPS_EXC_INT_IO ); -break ; - -case -3 : -kvm_clear_c0_guest_cause (vcpu->arch.cop0, (C_IRQ1 )); -kvm_mips_dequeue_irq (vcpu,MIPS_EXC_INT_IPI_1 ); -break ; - -case -4 : -kvm_clear_c0_guest_cause (vcpu->arch.cop0, (C_IRQ2 )); -kvm_mips_dequeue_irq (vcpu,MIPS_EXC_INT_IPI_2 ); -break ; - -default : -break ; - } - +kvm_clear_c0_guest_cause (vcpu->arch.cop0,1 << (-intr +8 )); +kvm_mips_dequeue_irq (vcpu,kvm_irq_to_priority (-intr)); }/* Deliver the interrupt of the corresponding priority, if possible. */
@@ -116,50 +79,20 @@ int kvm_mips_irq_deliver_cb(struct kvm_vcpu *vcpu, unsigned int priority, u32 cause) {int allowed =0 ; -u32 exccode; +u32 exccode, ie;struct kvm_vcpu_arch *arch = &vcpu->arch;struct mips_coproc *cop0 = vcpu->arch.cop0; -switch (priority) { -case MIPS_EXC_INT_TIMER : -if ((kvm_read_c0_guest_status (cop0) &ST0_IE ) - && (!(kvm_read_c0_guest_status (cop0) & (ST0_EXL |ST0_ERL ))) - && (kvm_read_c0_guest_status (cop0) &IE_IRQ5 )) { - allowed =1 ; - exccode =EXCCODE_INT ; - } -break ; - -case MIPS_EXC_INT_IO : -if ((kvm_read_c0_guest_status (cop0) &ST0_IE ) - && (!(kvm_read_c0_guest_status (cop0) & (ST0_EXL |ST0_ERL ))) - && (kvm_read_c0_guest_status (cop0) &IE_IRQ0 )) { - allowed =1 ; - exccode =EXCCODE_INT ; - } -break ; - -case MIPS_EXC_INT_IPI_1 : -if ((kvm_read_c0_guest_status (cop0) &ST0_IE ) - && (!(kvm_read_c0_guest_status (cop0) & (ST0_EXL |ST0_ERL ))) - && (kvm_read_c0_guest_status (cop0) &IE_IRQ1 )) { - allowed =1 ; - exccode =EXCCODE_INT ; - } -break ; - -case MIPS_EXC_INT_IPI_2 : -if ((kvm_read_c0_guest_status (cop0) &ST0_IE ) - && (!(kvm_read_c0_guest_status (cop0) & (ST0_EXL |ST0_ERL ))) - && (kvm_read_c0_guest_status (cop0) &IE_IRQ2 )) { - allowed =1 ; - exccode =EXCCODE_INT ; - } -break ; +if (priority ==MIPS_EXC_MAX ) +return 0 ; -default : -break ; + ie =1 << (kvm_priority_to_irq[priority] +8 ); +if ((kvm_read_c0_guest_status (cop0) &ST0_IE ) + && (!(kvm_read_c0_guest_status (cop0) & (ST0_EXL |ST0_ERL ))) + && (kvm_read_c0_guest_status (cop0) & ie)) { + allowed =1 ; + exccode =EXCCODE_INT ; }/* Are we allowed to deliver the interrupt ??? */
arch/mips/kvm/interrupt.h +9 -5
@@ -21,11 +21,12 @@#define MIPS_EXC_NMI 5#define MIPS_EXC_MCHK 6#define MIPS_EXC_INT_TIMER 7 -#define MIPS_EXC_INT_IO 8 -#define MIPS_EXC_EXECUTE 9 -#define MIPS_EXC_INT_IPI_1 10 -#define MIPS_EXC_INT_IPI_2 11 -#define MIPS_EXC_MAX 12 +#define MIPS_EXC_INT_IO_1 8 +#define MIPS_EXC_INT_IO_2 9 +#define MIPS_EXC_EXECUTE 10 +#define MIPS_EXC_INT_IPI_1 11 +#define MIPS_EXC_INT_IPI_2 12 +#define MIPS_EXC_MAX 13/* XXXSL More to follow */ #define C_TI (_ULCAST_(1) << 30)
@@ -38,6 +39,9 @@#define KVM_MIPS_IRQ_CLEAR_ALL_AT_ONCE (0)#endif +extern u32 *kvm_priority_to_irq; +u32 kvm_irq_to_priority (u32 irq); +void kvm_mips_queue_irq (struct kvm_vcpu *vcpu,unsigned int priority);void kvm_mips_dequeue_irq (struct kvm_vcpu *vcpu,unsigned int priority);int kvm_mips_pending_timer (struct kvm_vcpu *vcpu);
arch/mips/kvm/mips.c +37 -3
@@ -490,7 +490,10 @@ int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,int intr = (int )irq->irq;struct kvm_vcpu *dvcpu =NULL ; -if (intr ==3 || intr ==-3 || intr ==4 || intr ==-4 ) +if (intr == kvm_priority_to_irq[MIPS_EXC_INT_IPI_1 ] || + intr == kvm_priority_to_irq[MIPS_EXC_INT_IPI_2 ] || + intr == (-kvm_priority_to_irq[MIPS_EXC_INT_IPI_1 ]) || + intr == (-kvm_priority_to_irq[MIPS_EXC_INT_IPI_2 ]))kvm_debug ("%s: CPU: %d, INTR: %d\n" , __func__, irq->cpu, (int )intr);
@@ -499,10 +502,10 @@ int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,else dvcpu = vcpu->kvm->vcpus[irq->cpu]; -if (intr ==2 || intr ==3 || intr ==4 ) { +if (intr ==2 || intr ==3 || intr ==4 || intr ==6 ) { kvm_mips_callbacks->queue_io_int (dvcpu, irq); - }else if (intr ==-2 || intr ==-3 || intr ==-4 ) { + }else if (intr ==-2 || intr ==-3 || intr ==-4 || intr ==-6 ) { kvm_mips_callbacks->dequeue_io_int (dvcpu, irq); }else { kvm_err("%s: invalid interrupt ioctl (%d:%d)\n", __func__,
@@ -1620,6 +1623,34 @@ static struct notifier_block kvm_mips_csr_die_notifier = { .notifier_call = kvm_mips_csr_die_notify, }; +static u32 kvm_default_priority_to_irq[MIPS_EXC_MAX ] = { + [MIPS_EXC_INT_TIMER ] =C_IRQ5 , + [MIPS_EXC_INT_IO_1 ] =C_IRQ0 , + [MIPS_EXC_INT_IPI_1 ] =C_IRQ1 , + [MIPS_EXC_INT_IPI_2 ] =C_IRQ2 , +}; + +static u32 kvm_loongson3_priority_to_irq[MIPS_EXC_MAX ] = { + [MIPS_EXC_INT_TIMER ] =C_IRQ5 , + [MIPS_EXC_INT_IO_1 ] =C_IRQ0 , + [MIPS_EXC_INT_IO_2 ] =C_IRQ1 , + [MIPS_EXC_INT_IPI_1 ] =C_IRQ4 , +}; + +u32 *kvm_priority_to_irq = kvm_default_priority_to_irq; + +u32 kvm_irq_to_priority (u32 irq) +{ +int i; + +for (i =MIPS_EXC_INT_TIMER ; i <MIPS_EXC_MAX ; i++) { +if (kvm_priority_to_irq[i] == (1 << (irq +8 ))) +return i; + } + +return MIPS_EXC_MAX ; +} +static int __init kvm_mips_init (void ) {int ret;
@@ -1638,6 +1669,9 @@ static int __init kvm_mips_init(void)if (ret)return ret; +if (boot_cpu_type () ==CPU_LOONGSON64 ) + kvm_priority_to_irq = kvm_loongson3_priority_to_irq; +register_die_notifier (&kvm_mips_csr_die_notifier);return 0 ;
arch/mips/kvm/vz.c +8 -45
89 lines not on this page · raw message
Signature · 1 line
2.7.0
PATCH v8 10/15 KVM: MIPS: Add Loongson-3 Virtual IPI interrupt support
In reply to Huacai ChenThis patch add Loongson-3 Virtual IPI interrupt support in the kernel. The current implementation of IPI emulation in QEMU is based on GIC for MIPS, but Loongson-3 doesn't use GIC. Furthermore, IPI emulation in QEMU is too expensive for performance (because of too many context switches between Host and Guest). With current solution, the IPI delay may even cause RCU stall warnings in a multi-core Guest. So, we design a faster solution that emulate IPI interrupt in kernel (only used by Loongson-3 now).
--- arch/mips/include/asm/kvm_host.h | 32 ++++++ arch/mips/kvm/Makefile | 3 + arch/mips/kvm/emulate.c | 23 ++++- arch/mips/kvm/loongson_ipi.c | 214 +++++++++++++++++++++++++++++++++++++++ arch/mips/kvm/mips.c | 6 ++ 5 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 arch/mips/kvm/loongson_ipi.c
arch/mips/include/asm/kvm_host.h +32 -0
@@ -23,6 +23,8 @@#include <asm/inst.h> #include <asm/mipsregs.h> +#include <kvm/iodev.h> +/* MIPS KVM register ids */ #define MIPS_CP0_32 (_R, _S) \ (KVM_REG_MIPS_CP0 | KVM_REG_SIZE_U32 | (8 * (_R) + (_S)))
@@ -183,11 +185,39 @@ struct kvm_vcpu_stat {struct kvm_arch_memory_slot { }; +#ifdef CONFIG_CPU_LOONGSON64 +struct ipi_state { +uint32_t status; +uint32_t en; +uint32_t set; +uint32_t clear; +uint64_t buf[4 ]; +}; + +struct loongson_kvm_ipi ; + +struct ipi_io_device { +int node_id; +struct loongson_kvm_ipi *ipi; +struct kvm_io_device device; +}; + +struct loongson_kvm_ipi { +spinlock_t lock; +struct kvm *kvm; +struct ipi_state ipistate[16 ]; +struct ipi_io_device dev_ipi[4 ]; +}; +#endif +struct kvm_arch {/* Guest physical mm */ struct mm_struct gpa_mm;/* Mask of CPUs needing GPA ASID flush */ cpumask_t asid_flush_mask; +#ifdef CONFIG_CPU_LOONGSON64 +struct loongson_kvm_ipi ipi; +#endif };#define N_MIPS_COPROC_REGS 32
@@ -1135,6 +1165,8 @@ extern int kvm_mips_trans_mtc0(union mips_instruction inst, u32 *opc,/* Misc */ extern void kvm_mips_dump_stats (struct kvm_vcpu *vcpu);extern unsigned long kvm_mips_get_ramsize (struct kvm *kvm); +extern int kvm_vcpu_ioctl_interrupt (struct kvm_vcpu *vcpu, +struct kvm_mips_interrupt *irq);static inline void kvm_arch_hardware_unsetup (void ) {}static inline void kvm_arch_sync_events (struct kvm *kvm) {}
arch/mips/kvm/Makefile +3 -0
@@ -13,6 +13,9 @@ kvm-objs := $(common-objs-y) mips.o emulate.o entry.o \ fpu.o kvm-objs += hypcall.o kvm-objs += mmu.o +ifdef CONFIG_CPU_LOONGSON64 +kvm-objs += loongson_ipi.o +endif ifdef CONFIG_KVM_MIPS_VZ kvm-objs += vz.o
arch/mips/kvm/emulate.c +22 -1
@@ -1600,6 +1600,7 @@ enum emulation_result kvm_mips_emulate_store(union mips_instruction inst,struct kvm_run *run, struct kvm_vcpu *vcpu) { + int r;enum emulation_result er;u32 rt;void *data = run->mmio.data;
@@ -1666,9 +1667,18 @@ enum emulation_result kvm_mips_emulate_store(union mips_instruction inst, goto out_fail; } - run->mmio.is_write =1 ; vcpu->mmio_needed =1 ; + run->mmio.is_write =1 ; vcpu->mmio_is_write =1 ; + + r =kvm_io_bus_write (vcpu,KVM_MMIO_BUS , + run->mmio.phys_addr, run->mmio.len, data); + +if (!r) { + vcpu->mmio_needed =0 ; +return EMULATE_DONE ; + } +return EMULATE_DO_MMIO ; out_fail:
@@ -1681,6 +1691,7 @@ enum emulation_result kvm_mips_emulate_load(union mips_instruction inst, u32 cause, struct kvm_run *run, struct kvm_vcpu *vcpu) { + int r;enum emulation_result er;unsigned long curr_pc;u32 op, rt;
@@ -1745,6 +1756,16 @@ enum emulation_result kvm_mips_emulate_load(union mips_instruction inst, run->mmio.is_write =0 ; vcpu->mmio_is_write =0 ; + + r =kvm_io_bus_read (vcpu,KVM_MMIO_BUS , + run->mmio.phys_addr, run->mmio.len, run->mmio.data); + +if (!r) { +kvm_mips_complete_mmio_load (vcpu, run); + vcpu->mmio_needed =0 ; +return EMULATE_DONE ; + } +return EMULATE_DO_MMIO ; }
arch/mips/kvm/loongson_ipi.c new file +214 -0
214 lines not on this page · raw message
arch/mips/kvm/mips.c +6 -0
@@ -129,6 +129,8 @@ int kvm_arch_check_processor_compat(void *opaque)return 0 ; } +extern void kvm_init_loongson_ipi (struct kvm *kvm); +int kvm_arch_init_vm (struct kvm *kvm,unsigned long type) {switch (type) {
@@ -148,6 +150,10 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)if (!kvm->arch.gpa_mm.pgd)return -ENOMEM ; +#ifdef CONFIG_CPU_LOONGSON64 +kvm_init_loongson_ipi (kvm); +#endif +return 0 ; }
Signature · 1 line
2.7.0
PATCH v8 11/15 KVM: MIPS: Add CPUCFG emulation for Loongson-3
In reply to Huacai ChenLoongson-3 overrides lwc2 instructions to implement CPUCFG and CSR read/write functions. These instructions all cause guest exit so CSR doesn't benifit KVM guest (and there are always legacy methods to provide the same functions as CSR). So, we only emulate CPUCFG and let it return a reduced feature list (which means the virtual CPU doesn't have any other advanced features, including CSR) in KVM.
--- arch/mips/include/asm/kvm_host.h | 3 ++ arch/mips/include/uapi/asm/inst.h | 11 ++++++ arch/mips/kvm/mips.c | 3 ++ arch/mips/kvm/vz.c | 77 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+)
arch/mips/include/asm/kvm_host.h +3 -0
@@ -173,6 +173,9 @@ struct kvm_vcpu_stat {u64 vz_ghfc_exits;u64 vz_gpa_exits;u64 vz_resvd_exits; +#ifdef CONFIG_CPU_LOONGSON64 +u64 vz_cpucfg_exits; +#endif #endif u64 halt_successful_poll;u64 halt_attempted_poll;
arch/mips/include/uapi/asm/inst.h +11 -0
@@ -988,6 +988,16 @@ struct mm16_r5_format { /* Load/store from stack pointer format */ ;)))) }; +struct loongson3_lscsr_format { /* Loongson-3 CPUCFG&CSR read/write format */ + __BITFIELD_FIELD(unsigned int opcode : 6, + __BITFIELD_FIELD(unsigned int rs : 5, + __BITFIELD_FIELD(unsigned int fr : 5, + __BITFIELD_FIELD(unsigned int rd : 5, + __BITFIELD_FIELD(unsigned int fd : 5, + __BITFIELD_FIELD(unsigned int func : 6, + ;)))))) +}; + /* * MIPS16e instruction formats (16-bit length) */
@@ -1088,6 +1098,7 @@ union mips_instruction {struct mm16_rb_format mm16_rb_format;struct mm16_r3_format mm16_r3_format;struct mm16_r5_format mm16_r5_format; +struct loongson3_lscsr_format loongson3_lscsr_format; };union mips16e_instruction {
arch/mips/kvm/mips.c +3 -0
@@ -67,6 +67,9 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {VCPU_STAT ("vz_ghfc" , vz_ghfc_exits),VCPU_STAT ("vz_gpa" , vz_gpa_exits),VCPU_STAT ("vz_resvd" , vz_resvd_exits), +#ifdef CONFIG_CPU_LOONGSON64 +VCPU_STAT ("vz_cpucfg" , vz_cpucfg_exits), +#endif #endifVCPU_STAT ("halt_successful_poll" , halt_successful_poll), VCPU_STAT("halt_attempted_poll", halt_attempted_poll),
arch/mips/kvm/vz.c +77 -0
95 lines not on this page · raw message
Signature · 1 line
2.7.0
PATCH v8 12/15 KVM: MIPS: Add CONFIG6 and DIAG registers emulation
In reply to Huacai ChenLoongson-3 has CONFIG6 and DIAG registers which need to be emulated. CONFIG6 is mostly used to enable/disable FTLB and SFB, while DIAG is mostly used to flush BTB, ITLB, DTLB, VTLB and FTLB.
--- arch/mips/include/asm/kvm_host.h | 7 +++++ arch/mips/include/asm/mipsregs.h | 7 +++++ arch/mips/kvm/tlb.c | 41 ++++++++++++++++++++++++++ arch/mips/kvm/vz.c | 62 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 116 insertions(+), 1 deletion(-)
arch/mips/include/asm/kvm_host.h +7 -0
@@ -68,9 +68,11 @@#define KVM_REG_MIPS_CP0_CONFIG3 MIPS_CP0_32(16, 3)#define KVM_REG_MIPS_CP0_CONFIG4 MIPS_CP0_32(16, 4)#define KVM_REG_MIPS_CP0_CONFIG5 MIPS_CP0_32(16, 5) +#define KVM_REG_MIPS_CP0_CONFIG6 MIPS_CP0_32(16, 6)#define KVM_REG_MIPS_CP0_CONFIG7 MIPS_CP0_32(16, 7)#define KVM_REG_MIPS_CP0_MAARI MIPS_CP0_64(17, 2)#define KVM_REG_MIPS_CP0_XCONTEXT MIPS_CP0_64(20, 0) +#define KVM_REG_MIPS_CP0_DIAG MIPS_CP0_32(22, 0)#define KVM_REG_MIPS_CP0_ERROREPC MIPS_CP0_64(30, 0)#define KVM_REG_MIPS_CP0_KSCRATCH1 MIPS_CP0_64(31, 2)#define KVM_REG_MIPS_CP0_KSCRATCH2 MIPS_CP0_64(31, 3)
@@ -258,6 +260,7 @@ struct mips_coproc {#define MIPS_CP0_WATCH_LO 18#define MIPS_CP0_WATCH_HI 19#define MIPS_CP0_TLB_XCONTEXT 20 +#define MIPS_CP0_DIAG 22#define MIPS_CP0_ECC 26#define MIPS_CP0_CACHE_ERR 27#define MIPS_CP0_TAG_LO 28
@@ -929,6 +932,10 @@ void kvm_vz_save_guesttlb(struct kvm_mips_tlb *buf, unsigned int index, unsigned int count);void kvm_vz_load_guesttlb (const struct kvm_mips_tlb *buf,unsigned int index,unsigned int count); +#ifdef CONFIG_CPU_LOONGSON64 +void kvm_loongson_clear_guest_vtlb (void ); +void kvm_loongson_clear_guest_ftlb (void ); +#endif #endif void kvm_mips_suspend_mm (int cpu);
arch/mips/include/asm/mipsregs.h +7 -0
@@ -674,6 +674,9 @@#define MIPS_CONF5_CV (_ULCAST_(1) << 29)#define MIPS_CONF5_K (_ULCAST_(1) << 30) +#define MIPS_CONF6_INTIMER (_ULCAST_(1) << 6) +#define MIPS_CONF6_EXTIMER (_ULCAST_(1) << 7) +#define MIPS_CONF6_SFBEN (_ULCAST_(1) << 8)#define MIPS_CONF6_SYND (_ULCAST_(1) << 13)/* proAptiv FTLB on/off bit */ #define MIPS_CONF6_FTLBEN (_ULCAST_(1) << 15)
@@ -993,6 +996,8 @@/* Disable Branch Return Cache */ #define R10K_DIAG_D_BRC (_ULCAST_(1) << 22) +/* Flush BTB */ +#define LOONGSON_DIAG_BTB (_ULCAST_(1) << 1)/* Flush ITLB */ #define LOONGSON_DIAG_ITLB (_ULCAST_(1) << 2)/* Flush DTLB */
@@ -2825,7 +2830,9 @@ __BUILD_SET_C0(status) __BUILD_SET_C0(cause) __BUILD_SET_C0(config) __BUILD_SET_C0(config5) +__BUILD_SET_C0(config6) __BUILD_SET_C0(config7) +__BUILD_SET_C0(diag) __BUILD_SET_C0(intcontrol) __BUILD_SET_C0(intctl) __BUILD_SET_C0(srsmap)
arch/mips/kvm/tlb.c +41 -0
53 lines not on this page · raw message
arch/mips/kvm/vz.c +61 -1
113 lines not on this page · raw message
Signature · 1 line
2.7.0
PATCH v8 13/15 KVM: MIPS: Add more MMIO load/store instructions emulation
In reply to Huacai ChenThis patch add more MMIO load/store instructions emulation, which can be observed in QXL and some other device drivers:
1, LWL, LWR, LDW, LDR, SWL, SWR, SDL and SDR for all MIPS; 2, GSLBX, GSLHX, GSLWX, GSLDX, GSSBX, GSSHX, GSSWX and GSSDX for
Loongson-3.
--- arch/mips/include/uapi/asm/inst.h | 26 +++ arch/mips/kvm/emulate.c | 480 +++++++++++++++++++++++++++++++++++++- 2 files changed, 496 insertions(+), 10 deletions(-)
arch/mips/include/uapi/asm/inst.h +26 -0
@@ -988,6 +988,30 @@ struct mm16_r5_format { /* Load/store from stack pointer format */ ;)))) }; +/* +* Loongson-3 overridden COP2 instruction formats (32-bit length) +*/ +struct loongson3_lswc2_format { /* Loongson-3 overridden lwc2/swc2 Load/Store format */ + __BITFIELD_FIELD(unsigned int opcode : 6, + __BITFIELD_FIELD(unsigned int base : 5, + __BITFIELD_FIELD(unsigned int rt : 5, + __BITFIELD_FIELD(unsigned int fr : 1, + __BITFIELD_FIELD(unsigned int offset : 9, + __BITFIELD_FIELD(unsigned int ls : 1, + __BITFIELD_FIELD(unsigned int rq : 5, + ;))))))) +}; + +struct loongson3_lsdc2_format { /* Loongson-3 overridden ldc2/sdc2 Load/Store format */ + __BITFIELD_FIELD(unsigned int opcode : 6, + __BITFIELD_FIELD(unsigned int base : 5, + __BITFIELD_FIELD(unsigned int rt : 5, + __BITFIELD_FIELD(unsigned int index : 5, + __BITFIELD_FIELD(unsigned int offset : 8, + __BITFIELD_FIELD(unsigned int opcode1 : 3, + ;)))))) +}; + struct loongson3_lscsr_format { /* Loongson-3 CPUCFG&CSR read/write format */ __BITFIELD_FIELD(unsigned int opcode : 6, __BITFIELD_FIELD(unsigned int rs : 5,
@@ -1098,6 +1122,8 @@ union mips_instruction {struct mm16_rb_format mm16_rb_format;struct mm16_r3_format mm16_r3_format;struct mm16_r5_format mm16_r5_format; +struct loongson3_lswc2_format loongson3_lswc2_format; +struct loongson3_lsdc2_format loongson3_lsdc2_format;struct loongson3_lscsr_format loongson3_lscsr_format; };
arch/mips/kvm/emulate.c +470 -10
522 lines not on this page · raw message
Signature · 1 line
2.7.0
PATCH v8 14/15 KVM: MIPS: Enable KVM support for Loongson-3
In reply to Huacai ChenThis patch enable KVM support for Loongson-3 by selecting HAVE_KVM, but only enable KVM/VZ on Loongson-3A R4+ (because VZ of early processors are incomplete). Besides, Loongson-3 support SMP guests, so we clear the linked load bit of LLAddr in kvm_vz_vcpu_load() if the guest has more than one VCPUs.
--- arch/mips/Kconfig | 1 + arch/mips/kernel/cpu-probe.c | 1 + arch/mips/kvm/vz.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-)
arch/mips/Kconfig +1 -0
@@ -1466,6 +1466,7 @@ config CPU_LOONGSON64 select MIPS_L1_CACHE_SHIFT_6 select GPIOLIB select SWIOTLB + select HAVE_KVM help The Loongson GSx64(GS264/GS464/GS464E/GS464V) series of processor cores implements the MIPS64R2 instruction set with many extensions,
arch/mips/kernel/cpu-probe.c +1 -0
@@ -1958,6 +1958,7 @@ static inline void cpu_probe_loongson(struct cpuinfo_mips *c, unsigned int cpu) c->writecombine = _CACHE_UNCACHED_ACCELERATED; c->ases |= (MIPS_ASE_LOONGSON_MMI |MIPS_ASE_LOONGSON_CAM |MIPS_ASE_LOONGSON_EXT |MIPS_ASE_LOONGSON_EXT2 ); + c->ases &= ~MIPS_ASE_VZ ;/* VZ of Loongson-3A2000/3000 is incomplete */ break ;case PRID_IMP_LOONGSON_64G : c->cputype =CPU_LOONGSON64 ;
arch/mips/kvm/vz.c +1 -1
@@ -2697,7 +2697,7 @@ static int kvm_vz_vcpu_load(struct kvm_vcpu *vcpu, int cpu)* prevents a SC on the next VCPU from succeeding by matching a LL on * the previous VCPU. */ -if (cpu_guest_has_rw_llb) +if (vcpu->kvm->created_vcpus >1 )write_gc0_lladdr (0 );return 0 ;
Signature · 1 line
2.7.0
PATCH v8 15/15 MAINTAINERS: Update KVM/MIPS maintainers
In reply to Huacai ChenJames Hogan has become inactive for a long time and leaves KVM for MIPS orphan. I'm working on KVM/Loongson and attempt to make it upstream both in kernel and QEMU, while Aleksandar Markovic is already a maintainer of QEMU/MIPS. We are both interested in QEMU/KVM/MIPS, and we have already made some contributions in kernel and QEMU. If possible, we want to take the KVM/MIPS maintainership.
--- MAINTAINERS | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
MAINTAINERS +3 -1
@@ -9298,9 +9298,11 @@ F: include/kvm/arm_* F: virt/kvm/arm/ KERNEL VIRTUAL MACHINE FOR MIPS (KVM/mips) +M: Aleksandar Markovic <[email protected]> +M: Huacai Chen <[email protected]> L: [email protected] L: [email protected] -S: Orphan +S: Maintained F: arch/mips/include/asm/kvm* F: arch/mips/include/uapi/asm/kvm* F: arch/mips/kvm/
Signature · 1 line
2.7.0
Quoted 7 lines
V7 -> V8:
1, Rebase to be applied on kvm tree, i.e., the linux-next branch of
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/. Building KVM/MIPS need commit3fbfb4585bfd4ff34e("mips: definepud_index()regardless of page table folding"), which has already been in mips tree but not in kvm tree.
Huacai,
I do support and salute the series (as I always did), as I see it as a giant step forward for KVM for MIPS.
However, in general, I think any series should not depend on "pick that patch from another tree", and should be a stand-alone unit that yields to successful build and desired functionality. If there is a dependency like you described, the patch in question, in my opinion, should be integrated into the series in question. Git is even smart enough that it recognizes the same patch has been applied before, so integration of another tree would not be exposed to problems.
From the point of view of synchronizing with QEMU part, and the timing issues wrt kernel and QEMU releases, I want to stress that it is better that this series is integrated sooner rather than later. In other words, I think that potential Paolo's KVM pull request should happen before Thomas' mips-next pull request (Paolo could include "mips: define pud_index() regardless of page table folding", and Thomas could simply omit it).
But, that said, I don't feel I should impose my opinion to others here. Take my statements just as advises. I defer the decision on how to proceed with the integration of this series entirely to Paolo and Thomas.
Yours,
Aleksandar
Hi, Aleksandar,
Quoted 30 lines · Aleksandar Markovic
Quoted 8 lines
V7 -> V8:
1, Rebase to be applied on kvm tree, i.e., the linux-next branch of
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/. Building KVM/MIPS need commit3fbfb4585bfd4ff34e("mips: definepud_index()regardless of page table folding"), which has already been in mips tree but not in kvm tree.Huacai,
I do support and salute the series (as I always did), as I see it as a giant step forward for KVM for MIPS.
However, in general, I think any series should not depend on "pick that patch from another tree", and should be a stand-alone unit that yields to successful build and desired functionality. If there is a dependency like you described, the patch in question, in my opinion, should be integrated into the series in question. Git is even smart enough that it recognizes the same patch has been applied before, so integration of another tree would not be exposed to problems.
From the point of view of synchronizing with QEMU part, and the timing issues wrt kernel and QEMU releases, I want to stress that it is better that this series is integrated sooner rather than later. In other words, I think that potential Paolo's KVM pull request should happen before Thomas' mips-next pull request (Paolo could include "mips: define
pud_index()regardless of page table folding", and Thomas could simply omit it).
Quoted 4 lines
But, that said, I don't feel I should impose my opinion to others here. Take my statements just as advises. I defer the decision on how to proceed with the integration of this series entirely to Paolo and Thomas.
I think I lack some experience of cross-subsystem development, so in V8 I only adjust the context of my own patches to let the series be applied on kvm tree, but didn't consider patches already in other trees (Moreover, that patch is not mine). So, should I send a V9 that take commit 3fbfb4585bfd4ff3 together?
Thanks,
Huacai
Quoted 3 lines
Yours,
Aleksandar
пон, 25. мај 2020. у 03:23 Huacai Chen <[email protected]> је написао/ла:
Quoted 39 lines
Hi, Aleksandar,
Quoted 30 lines · Aleksandar Markovic
Quoted 8 lines
V7 -> V8:
1, Rebase to be applied on kvm tree, i.e., the linux-next branch of
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/. Building KVM/MIPS need commit3fbfb4585bfd4ff34e("mips: definepud_index()regardless of page table folding"), which has already been in mips tree but not in kvm tree.Huacai,
I do support and salute the series (as I always did), as I see it as a giant step forward for KVM for MIPS.
However, in general, I think any series should not depend on "pick that patch from another tree", and should be a stand-alone unit that yields to successful build and desired functionality. If there is a dependency like you described, the patch in question, in my opinion, should be integrated into the series in question. Git is even smart enough that it recognizes the same patch has been applied before, so integration of another tree would not be exposed to problems.
From the point of view of synchronizing with QEMU part, and the timing issues wrt kernel and QEMU releases, I want to stress that it is better that this series is integrated sooner rather than later. In other words, I think that potential Paolo's KVM pull request should happen before Thomas' mips-next pull request (Paolo could include "mips: define
pud_index()regardless of page table folding", and Thomas could simply omit it).Quoted 4 lines
But, that said, I don't feel I should impose my opinion to others here. Take my statements just as advises. I defer the decision on how to proceed with the integration of this series entirely to Paolo and Thomas.
Quoted 6 lines
I think I lack some experience of cross-subsystem development, so in V8 I only adjust the context of my own patches to let the series be applied on kvm tree, but didn't consider patches already in other trees (Moreover, that patch is not mine). So, should I send a V9 that take commit
3fbfb4585bfd4ff3together?
No, I think we should wait for Paolo's feedback.
Quoted 5 lines
Thanks,
HuacaiQuoted 3 lines
Yours,
Aleksandar
пон, 25. мај 2020. у 08:37 Aleksandar Markovic
<[email protected]> је написао/ла:
Quoted 41 lines
пон, 25. мај 2020. у 03:23 Huacai Chen <[email protected]> је написао/ла:
Quoted 39 lines
Hi, Aleksandar,
Quoted 34 lines · Aleksandar Markovic
Quoted 8 lines
V7 -> V8:
1, Rebase to be applied on kvm tree, i.e., the linux-next branch of
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/. Building KVM/MIPS need commit3fbfb4585bfd4ff34e("mips: definepud_index()regardless of page table folding"), which has already been in mips tree but not in kvm tree.Huacai,
I do support and salute the series (as I always did), as I see it as a giant step forward for KVM for MIPS.
However, in general, I think any series should not depend on "pick that patch from another tree", and should be a stand-alone unit that yields to successful build and desired functionality. If there is a dependency like you described, the patch in question, in my opinion, should be integrated into the series in question. Git is even smart enough that it recognizes the same patch has been applied before, so integration of another tree would not be exposed to problems.
From the point of view of synchronizing with QEMU part, and the timing issues wrt kernel and QEMU releases, I want to stress that it is better that this series is integrated sooner rather than later. In other words, I think that potential Paolo's KVM pull request should happen before Thomas' mips-next pull request (Paolo could include "mips: define
pud_index()regardless of page table folding", and Thomas could simply omit it).But, that said, I don't feel I should impose my opinion to others here. Take my statements just as advises. I defer the decision on how to proceed with the integration of this series entirely to Paolo and Thomas.
Quoted 9 lines
Quoted 6 lines
I think I lack some experience of cross-subsystem development, so in V8 I only adjust the context of my own patches to let the series be applied on kvm tree, but didn't consider patches already in other trees (Moreover, that patch is not mine). So, should I send a V9 that take commit
3fbfb4585bfd4ff3together?No, I think we should wait for Paolo's feedback.
Paolo, can you please give us some guidance on integration of this series, and on future workflow?
Since, the reality is, you are the most experienced between us on these topics, so you know what is the optimal organization. I gather, it is very important for us in KVM/MIPS to adopt the efficient and no-nonsens practices, that you know how to choose the best.
I truly appreciate any future response of yours!
Aleksandar
Quoted 5 lines
Quoted 5 lines
Thanks,
HuacaiQuoted 3 lines
Yours,
Aleksandar
нед, 24. мај 2020. у 13:13 Huacai Chen <[email protected]> је написао/ла:
Quoted 10 lines
We are preparing to add KVM support for Loongson-3. VZ extension is fully supported in Loongson-3A R4+, and we will not care about old CPUs (at least now). We already have a full functional Linux kernel (based on Linux-5.4.x LTS) and QEMU (based on 5.0.0) and their git repositories are here:
QEMU: https://github.com/chenhuacai/qemu
Kernel: https://github.com/chenhuacai/linux
Quoted 8 lines
Of course these two repositories need to be rework and not suitable for upstream (especially the commits need to be splitted). We show them here is just to tell others what we have done, and how KVM/Loongson will look like.
Our plan is make the KVM host side be upstream first, and after that, we will make the KVM guest side and QEMU emulator be upstream.
Huacai, Paolo, Thomas,
As you know, there are number of Huacai's patches to QEMU, related to this series, actually we could call them counterparts to this series.
Regarding QEMU upstreaming, unless someone objects, I plan to send pull request that will include some of Huacai-s QEMU patches in next few days - those that are of general nature, do not rely on any kernel changes, and passed review process. The rest of Huacai's QEMU patches will wait for this series to be integrated in kernel upstream.
Please give Huacai and myself some direction and path to go forward with this series. Please take into account that we inherit KVM for MIPS in an "orphaned" state, and do not know exactly all details how to "adopt" it. Forgive us if we made some missteps along the route.
We would like to establish a long-lasting, and high-quality, workflow that will fit well to both KVM and MIPS kernel development.
Please help us do it.
Thanks in advance!
Aleksandar
Quoted 75 lines
V1 -> V2:
1, Remove "mips: definepud_index()regardless of page table folding"
because it has been applied.
2, Make Loongson-specific code be guarded byCONFIG_CPU_LOONGSON64.V2 -> V3:
1, Emulate a reduced feature list of CPUCFG. 2, Fix all possible checkpatch.pl errors and warnings.V3 -> V4:
1, Emulate LOONGSON_CFG0/LOONGSON_CFG3 in CPUCFG correctly.
2, Update commit messages to explain Loongson-3 Virtual IPI. 3, Add Reviewed-by: Aleksandar Markovic <[email protected]>.V4 -> V5:
1, Fix a typo.
2, UpdateMAINTAINERS.V5 -> V6:
1, Fix a mismatch during rebasing.
2, Add Acked-by: Thomas Bogendoerfer <[email protected]>.V6 -> V7:
1, Rebase on latest mips-next (Config6 feature bits definition updated).V7 -> V8:
1, Rebase to be applied on kvm tree, i.e., the linux-next branch of
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/. Building KVM/MIPS need commit3fbfb4585bfd4ff34e("mips: definepud_index()regardless of page table folding"), which has already been in mips tree but not in kvm tree.Xing Li(2):
KVM: MIPS: DefineKVM_ENTRYHI_ASIDtocpu_asid_mask(&boot_cpu_data)
KVM: MIPS: FixVPN2_MASKdefinition for variablecpu_vmbitsHuacai Chen(13):
KVM: MIPS: IncreaseKVM_MAX_VCPUSandKVM_USER_MEM_SLOTSto 16
KVM: MIPS: Add EVENTFD support which is needed by VHOST
KVM: MIPS: Use lddir/ldpte instructions to lookup gpa_mm.pgd
KVM: MIPS: Introduce and usecpu_guest_has_ldpte
KVM: MIPS: Use root tlb to control guest's CCA for Loongson-3
KVM: MIPS: Let indexed cacheops cause guest exit on Loongson-3
KVM: MIPS: Add more types of virtual interrupts
KVM: MIPS: Add Loongson-3 Virtual IPI interrupt support
KVM: MIPS: Add CPUCFG emulation for Loongson-3
KVM: MIPS: Add CONFIG6 and DIAG registers emulation
KVM: MIPS: Add more MMIO load/store instructions emulation
KVM: MIPS: Enable KVM support for Loongson-3
MAINTAINERS: Update KVM/MIPS maintainersSigned-off-by Huacai Chen <[email protected]>--- MAINTAINERS | 4 +- arch/mips/Kconfig | 1 + arch/mips/include/asm/cpu-features.h | 3 + arch/mips/include/asm/kvm_host.h | 52 +++- arch/mips/include/asm/mipsregs.h | 7 + arch/mips/include/uapi/asm/inst.h | 37 +++ arch/mips/kernel/cpu-probe.c | 2 + arch/mips/kvm/Kconfig | 1 + arch/mips/kvm/Makefile | 5 +- arch/mips/kvm/emulate.c | 503 ++++++++++++++++++++++++++++++++++- arch/mips/kvm/entry.c | 19 +- arch/mips/kvm/interrupt.c | 93 +------ arch/mips/kvm/interrupt.h | 14 +- arch/mips/kvm/loongson_ipi.c | 214 +++++++++++++++ arch/mips/kvm/mips.c | 49 +++- arch/mips/kvm/tlb.c | 41 +++ arch/mips/kvm/trap_emul.c | 3 + arch/mips/kvm/vz.c | 237 ++++++++++++----- 18 files changed, 1118 insertions(+), 167 deletions(-) create mode 100644 arch/mips/kvm/loongson_ipi.c--
2.7.0
Hi, Paolo
Quoted 37 lines · Aleksandar Markovic
нед, 24. мај 2020. у 13:13 Huacai Chen <[email protected]> је написао/ла:
Quoted 10 lines
We are preparing to add KVM support for Loongson-3. VZ extension is fully supported in Loongson-3A R4+, and we will not care about old CPUs (at least now). We already have a full functional Linux kernel (based on Linux-5.4.x LTS) and QEMU (based on 5.0.0) and their git repositories are here:
QEMU: https://github.com/chenhuacai/qemu
Kernel: https://github.com/chenhuacai/linuxQuoted 8 lines
Of course these two repositories need to be rework and not suitable for upstream (especially the commits need to be splitted). We show them here is just to tell others what we have done, and how KVM/Loongson will look like.
Our plan is make the KVM host side be upstream first, and after that, we will make the KVM guest side and QEMU emulator be upstream.
Huacai, Paolo, Thomas,
As you know, there are number of Huacai's patches to QEMU, related to this series, actually we could call them counterparts to this series.
Regarding QEMU upstreaming, unless someone objects, I plan to send pull request that will include some of Huacai-s QEMU patches in next few days - those that are of general nature, do not rely on any kernel changes, and passed review process. The rest of Huacai's QEMU patches will wait for this series to be integrated in kernel upstream.
Please give Huacai and myself some direction and path to go forward with this series. Please take into account that we inherit KVM for MIPS in an "orphaned" state, and do not know exactly all details how to "adopt" it. Forgive us if we made some missteps along the route.
Quoted 9 lines
We would like to establish a long-lasting, and high-quality, workflow that will fit well to both KVM and MIPS kernel development.
Please help us do it.
Thanks in advance!
Aleksandar
If you will take this series after MIPS tree be merged into upstream, maybe V7 is better for you.
Huacai
Quoted 77 lines
Quoted 77 lines
V1 -> V2:
1, Remove "mips: definepud_index()regardless of page table folding"
because it has been applied.
2, Make Loongson-specific code be guarded byCONFIG_CPU_LOONGSON64.V2 -> V3:
1, Emulate a reduced feature list of CPUCFG. 2, Fix all possible checkpatch.pl errors and warnings.V3 -> V4:
1, Emulate LOONGSON_CFG0/LOONGSON_CFG3 in CPUCFG correctly.
2, Update commit messages to explain Loongson-3 Virtual IPI. 3, Add Reviewed-by: Aleksandar Markovic <[email protected]>.V4 -> V5:
1, Fix a typo.
2, UpdateMAINTAINERS.V5 -> V6:
1, Fix a mismatch during rebasing.
2, Add Acked-by: Thomas Bogendoerfer <[email protected]>.V6 -> V7:
1, Rebase on latest mips-next (Config6 feature bits definition updated).V7 -> V8:
1, Rebase to be applied on kvm tree, i.e., the linux-next branch of
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/. Building KVM/MIPS need commit3fbfb4585bfd4ff34e("mips: definepud_index()regardless of page table folding"), which has already been in mips tree but not in kvm tree.Xing Li(2):
KVM: MIPS: DefineKVM_ENTRYHI_ASIDtocpu_asid_mask(&boot_cpu_data)
KVM: MIPS: FixVPN2_MASKdefinition for variablecpu_vmbitsHuacai Chen(13):
KVM: MIPS: IncreaseKVM_MAX_VCPUSandKVM_USER_MEM_SLOTSto 16
KVM: MIPS: Add EVENTFD support which is needed by VHOST
KVM: MIPS: Use lddir/ldpte instructions to lookup gpa_mm.pgd
KVM: MIPS: Introduce and usecpu_guest_has_ldpte
KVM: MIPS: Use root tlb to control guest's CCA for Loongson-3
KVM: MIPS: Let indexed cacheops cause guest exit on Loongson-3
KVM: MIPS: Add more types of virtual interrupts
KVM: MIPS: Add Loongson-3 Virtual IPI interrupt support
KVM: MIPS: Add CPUCFG emulation for Loongson-3
KVM: MIPS: Add CONFIG6 and DIAG registers emulation
KVM: MIPS: Add more MMIO load/store instructions emulation
KVM: MIPS: Enable KVM support for Loongson-3
MAINTAINERS: Update KVM/MIPS maintainersSigned-off-by Huacai Chen <[email protected]>--- MAINTAINERS | 4 +- arch/mips/Kconfig | 1 + arch/mips/include/asm/cpu-features.h | 3 + arch/mips/include/asm/kvm_host.h | 52 +++- arch/mips/include/asm/mipsregs.h | 7 + arch/mips/include/uapi/asm/inst.h | 37 +++ arch/mips/kernel/cpu-probe.c | 2 + arch/mips/kvm/Kconfig | 1 + arch/mips/kvm/Makefile | 5 +- arch/mips/kvm/emulate.c | 503 ++++++++++++++++++++++++++++++++++- arch/mips/kvm/entry.c | 19 +- arch/mips/kvm/interrupt.c | 93 +------ arch/mips/kvm/interrupt.h | 14 +- arch/mips/kvm/loongson_ipi.c | 214 +++++++++++++++ arch/mips/kvm/mips.c | 49 +++- arch/mips/kvm/tlb.c | 41 +++ arch/mips/kvm/trap_emul.c | 3 + arch/mips/kvm/vz.c | 237 ++++++++++++----- 18 files changed, 1118 insertions(+), 167 deletions(-) create mode 100644 arch/mips/kvm/loongson_ipi.c--
2.7.0