Re: [PATCH v3 08/23] KVM: s390: KVM page table management functions: allocation

Heiko Carstens
2025-11-20T08:50:44Z

On Thu, Nov 06, 2025 at 05:11:02PM +0100, Claudio Imbrenda wrote:
> Add page table management functions to be used for KVM guest (gmap)
> page tables.
>
> This patch adds the boilerplate and functions for the allocation and
> deallocation of DAT tables.
>
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
> ---
> arch/s390/kvm/Makefile | 1 +
> arch/s390/kvm/dat.c | 103 +++++++++++++++++++++++++++++++++++++
> arch/s390/kvm/dat.h | 77 +++++++++++++++++++++++++++
> arch/s390/mm/page-states.c | 1 +
> 4 files changed, 182 insertions(+)
> create mode 100644 arch/s390/kvm/dat.c

...

> +#define GFP_KVM_S390_MMU_CACHE (GFP_ATOMIC | __GFP_ACCOUNT | __GFP_NOWARN)
> +
> +static inline struct page_table *kvm_s390_mmu_cache_alloc_pt(struct kvm_s390_mmu_cache *mc)
> +{
> + if (mc->n_pts)
> + return mc->pts[--mc->n_pts];
> + return (void *)__get_free_page(GFP_KVM_S390_MMU_CACHE);
> +}
> +
> +static inline struct crst_table *kvm_s390_mmu_cache_alloc_crst(struct kvm_s390_mmu_cache *mc)
> +{
> + if (mc->n_crsts)
> + return mc->crsts[--mc->n_crsts];
> + return (void *)__get_free_pages(GFP_KVM_S390_MMU_CACHE | __GFP_COMP, CRST_ALLOC_ORDER);
> +}
> +
> +static inline struct vsie_rmap *kvm_s390_mmu_cache_alloc_rmap(struct kvm_s390_mmu_cache *mc)
> +{
> + if (mc->n_rmaps)
> + return mc->rmaps[--mc->n_rmaps];
> + return kzalloc(sizeof(struct vsie_rmap), GFP_KVM_S390_MMU_CACHE);
> +}

Given that the fallback allocation (cache empty), may also fail, but unlike
for other architectures also without printing any warning, this might be
difficult to debug, if there is any caller which handles the -ENOMEM case
incorrectly. Maybe it would make sense to save a calltrace (stackdepot?)
whenever that happens, so that in case a guest dies because of incorrect /
missing -ENOMEM handling you have an indication where this happened.

Otherwise you end up scanning the whole code for all users and potential bugs,
just like I did when I reviewed the new allocation paths.