Skip to content

Commit 2940ba0

Browse files
committed
KVM: PPC: Book3S HV: Move HPT guest TLB flushing to C code
This replaces assembler code in book3s_hv_rmhandlers.S that checks the kvm->arch.need_tlb_flush cpumask and optionally does a TLB flush with C code in book3s_hv_builtin.c. Note that unlike the radix version, the hash version doesn't do an explicit ERAT invalidation because we will invalidate and load up the SLB before entering the guest, and that will invalidate the ERAT. Signed-off-by: Paul Mackerras <[email protected]>
1 parent 7ae9bda commit 2940ba0

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

arch/powerpc/include/asm/kvm_ppc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ extern void kvm_hv_vm_activated(void);
476476
extern void kvm_hv_vm_deactivated(void);
477477
extern bool kvm_hv_mode_active(void);
478478

479+
extern void kvmppc_hpt_check_need_tlb_flush(struct kvm *kvm);
480+
479481
#else
480482
static inline void __init kvm_cma_reserve(void)
481483
{}

arch/powerpc/kvm/book3s_hv_builtin.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,3 +805,32 @@ void kvmppc_guest_entry_inject_int(struct kvm_vcpu *vcpu)
805805
vcpu->arch.doorbell_request = 0;
806806
}
807807
}
808+
809+
void kvmppc_hpt_check_need_tlb_flush(struct kvm *kvm)
810+
{
811+
int pcpu = raw_smp_processor_id();
812+
unsigned long rb, set;
813+
814+
/*
815+
* On POWER9, individual threads can come in here, but the
816+
* TLB is shared between the 4 threads in a core, hence
817+
* invalidating on one thread invalidates for all.
818+
* Thus we make all 4 threads use the same bit.
819+
*/
820+
if (cpu_has_feature(CPU_FTR_ARCH_300))
821+
pcpu = cpu_first_thread_sibling(pcpu);
822+
823+
if (cpumask_test_cpu(pcpu, &kvm->arch.need_tlb_flush)) {
824+
rb = PPC_BIT(52); /* IS = 2 */
825+
for (set = 0; set < kvm->arch.tlb_sets; ++set) {
826+
asm volatile(PPC_TLBIEL(%0, %4, %3, %2, %1)
827+
: : "r" (rb), "i" (0), "i" (0), "i" (0),
828+
"r" (0) : "memory");
829+
rb += PPC_BIT(51); /* increment set number */
830+
}
831+
asm volatile("ptesync": : :"memory");
832+
833+
/* Clear the bit after the TLB flush */
834+
cpumask_clear_cpu(pcpu, &kvm->arch.need_tlb_flush);
835+
}
836+
}

arch/powerpc/kvm/book3s_hv_rmhandlers.S

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -623,40 +623,10 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
623623
isync
624624

625625
/* See if we need to flush the TLB. Hash has to be done in RM */
626-
lhz r6,PACAPACAINDEX(r13) /* test_bit(cpu, need_tlb_flush) */
627-
BEGIN_FTR_SECTION
628-
/*
629-
* On POWER9, individual threads can come in here, but the
630-
* TLB is shared between the 4 threads in a core, hence
631-
* invalidating on one thread invalidates for all.
632-
* Thus we make all 4 threads use the same bit here.
633-
*/
634-
clrrdi r6,r6,2
635-
END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
636-
clrldi r7,r6,64-6 /* extract bit number (6 bits) */
637-
srdi r6,r6,6 /* doubleword number */
638-
sldi r6,r6,3 /* address offset */
639-
add r6,r6,r9
640-
addi r6,r6,KVM_NEED_FLUSH /* dword in kvm->arch.need_tlb_flush */
641-
li r8,1
642-
sld r8,r8,r7
643-
ld r7,0(r6)
644-
and. r7,r7,r8
645-
beq 22f
646-
/* Flush the TLB of any entries for this LPID */
647-
lwz r0,KVM_TLB_SETS(r9)
648-
mtctr r0
649-
li r7,0x800 /* IS field = 0b10 */
650-
ptesync
651-
li r0,0 /* RS for P9 version of tlbiel */
652-
28: tlbiel r7 /* On P9, rs=0, RIC=0, PRS=0, R=0 */
653-
addi r7,r7,0x1000
654-
bdnz 28b
655-
ptesync
656-
23: ldarx r7,0,r6 /* clear the bit after TLB flushed */
657-
andc r7,r7,r8
658-
stdcx. r7,0,r6
659-
bne 23b
626+
mr r3, r9 /* kvm pointer */
627+
bl kvmppc_hpt_check_need_tlb_flush
628+
nop
629+
ld r5, HSTATE_KVM_VCORE(r13)
660630

661631
/* Add timebase offset onto timebase */
662632
22: ld r8,VCORE_TB_OFFSET(r5)

0 commit comments

Comments
 (0)