aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/powerpc/include/asm/kvm_host.h2
-rw-r--r--arch/powerpc/kvm/book3s_hv.c45
-rw-r--r--arch/powerpc/kvm/book3s_hv_rm_mmu.c11
-rw-r--r--arch/powerpc/kvm/book3s_hv_rmhandlers.S38
4 files changed, 82 insertions, 14 deletions
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index da1421a4d6f2..b2dbeac3f450 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -263,6 +263,7 @@ struct kvm_arch {
263 unsigned long hpt_mask; 263 unsigned long hpt_mask;
264 atomic_t hpte_mod_interest; 264 atomic_t hpte_mod_interest;
265 cpumask_t need_tlb_flush; 265 cpumask_t need_tlb_flush;
266 cpumask_t cpu_in_guest;
266 int hpt_cma_alloc; 267 int hpt_cma_alloc;
267 u8 radix; 268 u8 radix;
268 pgd_t *pgtable; 269 pgd_t *pgtable;
@@ -661,6 +662,7 @@ struct kvm_vcpu_arch {
661 int state; 662 int state;
662 int ptid; 663 int ptid;
663 int thread_cpu; 664 int thread_cpu;
665 int prev_cpu;
664 bool timer_running; 666 bool timer_running;
665 wait_queue_head_t cpu_run; 667 wait_queue_head_t cpu_run;
666 668
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 401e4cc8a91f..50c230e83f9b 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -1821,6 +1821,7 @@ static struct kvm_vcpu *kvmppc_core_vcpu_create_hv(struct kvm *kvm,
1821 vcpu->arch.vcore = vcore; 1821 vcpu->arch.vcore = vcore;
1822 vcpu->arch.ptid = vcpu->vcpu_id - vcore->first_vcpuid; 1822 vcpu->arch.ptid = vcpu->vcpu_id - vcore->first_vcpuid;
1823 vcpu->arch.thread_cpu = -1; 1823 vcpu->arch.thread_cpu = -1;
1824 vcpu->arch.prev_cpu = -1;
1824 1825
1825 vcpu->arch.cpu_type = KVM_CPU_3S_64; 1826 vcpu->arch.cpu_type = KVM_CPU_3S_64;
1826 kvmppc_sanity_check(vcpu); 1827 kvmppc_sanity_check(vcpu);
@@ -1950,11 +1951,33 @@ static void kvmppc_release_hwthread(int cpu)
1950 tpaca->kvm_hstate.kvm_split_mode = NULL; 1951 tpaca->kvm_hstate.kvm_split_mode = NULL;
1951} 1952}
1952 1953
1954static void do_nothing(void *x)
1955{
1956}
1957
1958static void radix_flush_cpu(struct kvm *kvm, int cpu, struct kvm_vcpu *vcpu)
1959{
1960 int i;
1961
1962 cpu = cpu_first_thread_sibling(cpu);
1963 cpumask_set_cpu(cpu, &kvm->arch.need_tlb_flush);
1964 /*
1965 * Make sure setting of bit in need_tlb_flush precedes
1966 * testing of cpu_in_guest bits. The matching barrier on
1967 * the other side is the first smp_mb() in kvmppc_run_core().
1968 */
1969 smp_mb();
1970 for (i = 0; i < threads_per_core; ++i)
1971 if (cpumask_test_cpu(cpu + i, &kvm->arch.cpu_in_guest))
1972 smp_call_function_single(cpu + i, do_nothing, NULL, 1);
1973}
1974
1953static void kvmppc_start_thread(struct kvm_vcpu *vcpu, struct kvmppc_vcore *vc) 1975static void kvmppc_start_thread(struct kvm_vcpu *vcpu, struct kvmppc_vcore *vc)
1954{ 1976{
1955 int cpu; 1977 int cpu;
1956 struct paca_struct *tpaca; 1978 struct paca_struct *tpaca;
1957 struct kvmppc_vcore *mvc = vc->master_vcore; 1979 struct kvmppc_vcore *mvc = vc->master_vcore;
1980 struct kvm *kvm = vc->kvm;
1958 1981
1959 cpu = vc->pcpu; 1982 cpu = vc->pcpu;
1960 if (vcpu) { 1983 if (vcpu) {
@@ -1965,6 +1988,27 @@ static void kvmppc_start_thread(struct kvm_vcpu *vcpu, struct kvmppc_vcore *vc)
1965 cpu += vcpu->arch.ptid; 1988 cpu += vcpu->arch.ptid;
1966 vcpu->cpu = mvc->pcpu; 1989 vcpu->cpu = mvc->pcpu;
1967 vcpu->arch.thread_cpu = cpu; 1990 vcpu->arch.thread_cpu = cpu;
1991
1992 /*
1993 * With radix, the guest can do TLB invalidations itself,
1994 * and it could choose to use the local form (tlbiel) if
1995 * it is invalidating a translation that has only ever been
1996 * used on one vcpu. However, that doesn't mean it has
1997 * only ever been used on one physical cpu, since vcpus
1998 * can move around between pcpus. To cope with this, when
1999 * a vcpu moves from one pcpu to another, we need to tell
2000 * any vcpus running on the same core as this vcpu previously
2001 * ran to flush the TLB. The TLB is shared between threads,
2002 * so we use a single bit in .need_tlb_flush for all 4 threads.
2003 */
2004 if (kvm_is_radix(kvm) && vcpu->arch.prev_cpu != cpu) {
2005 if (vcpu->arch.prev_cpu >= 0 &&
2006 cpu_first_thread_sibling(vcpu->arch.prev_cpu) !=
2007 cpu_first_thread_sibling(cpu))
2008 radix_flush_cpu(kvm, vcpu->arch.prev_cpu, vcpu);
2009 vcpu->arch.prev_cpu = cpu;
2010 }
2011 cpumask_set_cpu(cpu, &kvm->arch.cpu_in_guest);
1968 } 2012 }
1969 tpaca = &paca[cpu]; 2013 tpaca = &paca[cpu];
1970 tpaca->kvm_hstate.kvm_vcpu = vcpu; 2014 tpaca->kvm_hstate.kvm_vcpu = vcpu;
@@ -2552,6 +2596,7 @@ static noinline void kvmppc_run_core(struct kvmppc_vcore *vc)
2552 kvmppc_release_hwthread(pcpu + i); 2596 kvmppc_release_hwthread(pcpu + i);
2553 if (sip && sip->napped[i]) 2597 if (sip && sip->napped[i])
2554 kvmppc_ipi_thread(pcpu + i); 2598 kvmppc_ipi_thread(pcpu + i);
2599 cpumask_clear_cpu(pcpu + i, &vc->kvm->arch.cpu_in_guest);
2555 } 2600 }
2556 2601
2557 kvmppc_set_host_core(pcpu); 2602 kvmppc_set_host_core(pcpu);
diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
index 6c1ac3d21b91..b095afcd4309 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
@@ -43,6 +43,7 @@ static void *real_vmalloc_addr(void *x)
43static int global_invalidates(struct kvm *kvm, unsigned long flags) 43static int global_invalidates(struct kvm *kvm, unsigned long flags)
44{ 44{
45 int global; 45 int global;
46 int cpu;
46 47
47 /* 48 /*
48 * If there is only one vcore, and it's currently running, 49 * If there is only one vcore, and it's currently running,
@@ -60,8 +61,14 @@ static int global_invalidates(struct kvm *kvm, unsigned long flags)
60 /* any other core might now have stale TLB entries... */ 61 /* any other core might now have stale TLB entries... */
61 smp_wmb(); 62 smp_wmb();
62 cpumask_setall(&kvm->arch.need_tlb_flush); 63 cpumask_setall(&kvm->arch.need_tlb_flush);
63 cpumask_clear_cpu(local_paca->kvm_hstate.kvm_vcore->pcpu, 64 cpu = local_paca->kvm_hstate.kvm_vcore->pcpu;
64 &kvm->arch.need_tlb_flush); 65 /*
66 * On POWER9, threads are independent but the TLB is shared,
67 * so use the bit for the first thread to represent the core.
68 */
69 if (cpu_has_feature(CPU_FTR_ARCH_300))
70 cpu = cpu_first_thread_sibling(cpu);
71 cpumask_clear_cpu(cpu, &kvm->arch.need_tlb_flush);
65 } 72 }
66 73
67 return global; 74 return global;
diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 7fc7a9221509..dcc67a87d688 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -598,30 +598,44 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
598 598
599 /* See if we need to flush the TLB */ 599 /* See if we need to flush the TLB */
600 lhz r6,PACAPACAINDEX(r13) /* test_bit(cpu, need_tlb_flush) */ 600 lhz r6,PACAPACAINDEX(r13) /* test_bit(cpu, need_tlb_flush) */
601BEGIN_FTR_SECTION
602 /*
603 * On POWER9, individual threads can come in here, but the
604 * TLB is shared between the 4 threads in a core, hence
605 * invalidating on one thread invalidates for all.
606 * Thus we make all 4 threads use the same bit here.
607 */
608 clrrdi r6,r6,2
609END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
601 clrldi r7,r6,64-6 /* extract bit number (6 bits) */ 610 clrldi r7,r6,64-6 /* extract bit number (6 bits) */
602 srdi r6,r6,6 /* doubleword number */ 611 srdi r6,r6,6 /* doubleword number */
603 sldi r6,r6,3 /* address offset */ 612 sldi r6,r6,3 /* address offset */
604 add r6,r6,r9 613 add r6,r6,r9
605 addi r6,r6,KVM_NEED_FLUSH /* dword in kvm->arch.need_tlb_flush */ 614 addi r6,r6,KVM_NEED_FLUSH /* dword in kvm->arch.need_tlb_flush */
606 li r0,1 615 li r8,1
607 sld r0,r0,r7 616 sld r8,r8,r7
608 ld r7,0(r6) 617 ld r7,0(r6)
609 and. r7,r7,r0 618 and. r7,r7,r8
610 beq 22f 619 beq 22f
61123: ldarx r7,0,r6 /* if set, clear the bit */
612 andc r7,r7,r0
613 stdcx. r7,0,r6
614 bne 23b
615 /* Flush the TLB of any entries for this LPID */ 620 /* Flush the TLB of any entries for this LPID */
616 lwz r6,KVM_TLB_SETS(r9) 621 lwz r0,KVM_TLB_SETS(r9)
617 li r0,0 /* RS for P9 version of tlbiel */ 622 mtctr r0
618 mtctr r6
619 li r7,0x800 /* IS field = 0b10 */ 623 li r7,0x800 /* IS field = 0b10 */
620 ptesync 624 ptesync
62128: tlbiel r7 625 li r0,0 /* RS for P9 version of tlbiel */
626 bne cr7, 29f
62728: tlbiel r7 /* On P9, rs=0, RIC=0, PRS=0, R=0 */
622 addi r7,r7,0x1000 628 addi r7,r7,0x1000
623 bdnz 28b 629 bdnz 28b
624 ptesync 630 b 30f
63129: PPC_TLBIEL(7,0,2,1,1) /* for radix, RIC=2, PRS=1, R=1 */
632 addi r7,r7,0x1000
633 bdnz 29b
63430: ptesync
63523: ldarx r7,0,r6 /* clear the bit after TLB flushed */
636 andc r7,r7,r8
637 stdcx. r7,0,r6
638 bne 23b
625 639
626 /* Add timebase offset onto timebase */ 640 /* Add timebase offset onto timebase */
62722: ld r8,VCORE_TB_OFFSET(r5) 64122: ld r8,VCORE_TB_OFFSET(r5)