Re: [PATCH v2] KVM: arm64: Optimize protected mode and FWB
From: Marc Zyngier
Date: Tue Jul 21 2026 - 06:13:35 EST
On Tue, 21 Jul 2026 09:56:45 +0100,
Mostafa Saleh <smostafa@xxxxxxxxxx> wrote:
>
> KVM opportunistically enables FWB if supported by the system for guest
> VMs, which allows it to elude cache maintenance for data as they are
> forced to be cacheable from stage-2.
> In that case, __clean_dcache_guest_page() will immediately return.
> However in protected mode, before calling __clean_dcache_guest_page()
> it loops over the range and fix_map/unmap it, issuing TLB
> invalidations, dsb() and isb() unnecessarily.
>
> This can be optimized by returning early if FWB is supported,
> kvm_pgtable_stage2_map() already issues dsb() and tlb invalidation
> functions issue dsb() for the unmap path.
>
> Signed-off-by: Mostafa Saleh <smostafa@xxxxxxxxxx>
> Reviewed-by: Fuad Tabba <fuad.tabba@xxxxxxxxx>
> ---
> arch/arm64/kvm/hyp/nvhe/mem_protect.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> index 4e329e39a695..049a09be2bbf 100644
> --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
> @@ -261,6 +261,13 @@ static void __apply_guest_page(void *va, size_t size,
>
> static void clean_dcache_guest_page(void *va, size_t size)
> {
> + /*
> + * Guest stage-2 uses FWB if available, making it safe to elide CMOs.
> + * In contrast, the host stage-2 never has FWB enabled.
Beeeeeeep!!! Since a373930ec9406 ("KVM: arm64: Switch pKVM host S2
over to KVM_PGTABLE_S2_AS_S1"), FWB is enabled everywhere when
available.
Not sure that changes anything, but the comment is factually wrong.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.