KVM: arm64: Avoid soft lockups due to I-cache maintenance
authorOliver Upton <oliver.upton@linux.dev>
Wed, 20 Sep 2023 08:01:33 +0000 (08:01 +0000)
committerOliver Upton <oliver.upton@linux.dev>
Fri, 22 Sep 2023 17:55:05 +0000 (17:55 +0000)
commit909b583f81b5bb5a398d4580543f59b908a86ccc
treeeb57b723c2583c80f2f2911793f935591144e57f
parentec1c3b9ff16082f880b304be40992568f4eee6a7
KVM: arm64: Avoid soft lockups due to I-cache maintenance

Gavin reports of soft lockups on his Ampere Altra Max machine when
backing KVM guests with hugetlb pages. Upon further investigation, it
was found that the system is unable to keep up with parallel I-cache
invalidations done by KVM's stage-2 fault handler.

This is ultimately an implementation problem. I-cache maintenance
instructions are available at EL0, so nothing stops a malicious
userspace from hammering a system with CMOs and cause it to fall over.
"Fixing" this problem in KVM is nothing more than slapping a bandage
over a much deeper problem.

Anyway, the kernel already has a heuristic for limiting TLB
invalidations to avoid soft lockups. Reuse that logic to limit I-cache
CMOs done by KVM to map executable pages on systems without FEAT_DIC.
While at it, restructure __invalidate_icache_guest_page() to improve
readability and squeeze our new condition into the existing branching
structure.

Link: https://lore.kernel.org/kvmarm/20230904072826.1468907-1-gshan@redhat.com/
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Gavin Shan <gshan@redhat.com>
Link: https://lore.kernel.org/r/20230920080133.944717-3-oliver.upton@linux.dev
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
arch/arm64/include/asm/kvm_mmu.h