[PATCH v12 09/16] KVM: arm64: define kvm_arch_gmem_supports_no_direct_map()

Marc Zyngier maz at kernel.org
Tue Apr 21 09:55:05 PDT 2026


On Fri, 10 Apr 2026 16:19:24 +0100,
"Kalyazin, Nikita" <kalyazin at amazon.co.uk> wrote:
> 
> From: Patrick Roy <patrick.roy at linux.dev>
> 
> Support for GUEST_MEMFD_FLAG_NO_DIRECT_MAP on arm64 depends on 1) direct
> map manipulations at 4k granularity being possible, and 2) FEAT_S2FWB.
> 
> 1) is met whenever the direct map is set up at 4k granularity (e.g. not
>  with huge/gigantic pages) at boottime, as due to ARM's
> break-before-make semantics, breaking huge mappings into 4k mappings in
> the direct map is not possible (BBM would require temporary invalidation
> of the entire huge mapping, even if only a 4k subrange should be zapped,
> which will probably crash the kernel). However, the current default for
> rodata_full is true, which forces a 4k direct map.

Where is this 4kB requirement enforced? Or is it that you means
"PAGE_SIZE"?

> 
> 2) is required to allow KVM to elide cache coherency operations when
> installing stage 2 page tables, which require the direct map to be
> entry for the newly mapped memory to be present (which it will not be,
> as guest_memfd would have removed direct map entries in
> kvm_gmem_get_pfn()).
> 
> Cc: Will Deacon <will at kernel.org>
> Signed-off-by: Patrick Roy <patrick.roy at linux.dev>
> Reviewed-by: David Hildenbrand (Arm) <david at kernel.org>
> Signed-off-by: Nikita Kalyazin <nikita.kalyazin at linux.dev>
> ---
>  arch/arm64/include/asm/kvm_host.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> index 70cb9cfd760a..fbdd43e7e94e 100644
> --- a/arch/arm64/include/asm/kvm_host.h
> +++ b/arch/arm64/include/asm/kvm_host.h
> @@ -19,6 +19,7 @@
>  #include <linux/maple_tree.h>
>  #include <linux/percpu.h>
>  #include <linux/psci.h>
> +#include <linux/set_memory.h>
>  #include <asm/arch_gicv3.h>
>  #include <asm/barrier.h>
>  #include <asm/cpufeature.h>
> @@ -1682,6 +1683,18 @@ static __always_inline enum fgt_group_id __fgt_reg_to_group_id(enum vcpu_sysreg
>  									\
>  		p;							\
>  	})
> +#ifdef CONFIG_KVM_GUEST_MEMFD

KVM/arm64 has:

        select KVM_GUEST_MEMFD

> +static inline bool kvm_arch_gmem_supports_no_direct_map(struct kvm *kvm)
> +{
> +	/*
> +	 * Without FWB, direct map access is needed in kvm_pgtable_stage2_map(),
> +	 * as it calls dcache_clean_inval_poc().
> +	 */
> +	return can_set_direct_map() && cpus_have_final_cap(ARM64_HAS_STAGE2_FWB);
> +}
> +#define kvm_arch_gmem_supports_no_direct_map kvm_arch_gmem_supports_no_direct_map
> +#endif /* CONFIG_KVM_GUEST_MEMFD */

Why is it an inline function? Given that it takes a kvm parameter,
I fully expect that you'll have to evaluate this at some point.

But since struct kvm cannot be dereferenced in asm/kvm_host.h, it will
have to move. How about doing it right now?

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-riscv mailing list