When ESSA is executed in the guest for the first time, allocate all page tables and split all existing large page mappings, regardless of the hpage parameter. With the page tables present (even if all the entries within are not present), ESSA will not cause page faults. Without this fix, ESSA will cause a fault on the first page of each segment (1M block). If userspace is backing the guest with huge pages (hugetlbfs or THP), the page fault will be resolved by faulting in the whole huge page. The result is that at startup the whole guest memory is faulted in, since the guest will mark all of its memory at boot. With this fix, no extra guest memory is allocated. This will also prevent the first page in each segment from being faulted in, regardless of hugepages. Fixes: e38c884df921 ("KVM: s390: Switch to new gmap") Signed-off-by: Claudio Imbrenda --- arch/s390/kvm/s390/priv.c | 5 ++++- arch/s390/kvm/s390/s390.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/s390/kvm/s390/priv.c b/arch/s390/kvm/s390/priv.c index 856939acf012..4f0dd3173ab9 100644 --- a/arch/s390/kvm/s390/priv.c +++ b/arch/s390/kvm/s390/priv.c @@ -1248,7 +1248,10 @@ static int handle_essa(struct kvm_vcpu *vcpu) * value really needs to be written to; if the value is * already correct, we do nothing and avoid the lock. */ - set_bit(GMAP_FLAG_USES_CMM, &vcpu->arch.gmap->flags); + if (!uses_cmm(vcpu->arch.gmap)) { + set_bit(GMAP_FLAG_USES_CMM, &vcpu->arch.gmap->flags); + gmap_allocate_all_page_tables_best_effort(vcpu->arch.gmap); + } /* * If we are here, we are supposed to have CMMA enabled in * the SIE block. Enabling CMMA works on a per-CPU basis, diff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c index 18fb200f854a..739e8c23c3ae 100644 --- a/arch/s390/kvm/s390/s390.c +++ b/arch/s390/kvm/s390/s390.c @@ -2359,7 +2359,10 @@ static int kvm_s390_set_cmma_bits(struct kvm *kvm, } } while (r == -ENOMEM); - set_bit(GMAP_FLAG_USES_CMM, &kvm->arch.gmap->flags); + if (!uses_cmm(kvm->arch.gmap)) { + set_bit(GMAP_FLAG_USES_CMM, &kvm->arch.gmap->flags); + gmap_allocate_all_page_tables_best_effort(kvm->arch.gmap); + } return r <= 0 ? r : -EFAULT; } -- 2.56.0