]> git.ipfire.org Git - thirdparty/linux.git/commit
KVM: s390: Fix cmma dirty tracking
authorClaudio Imbrenda <imbrenda@linux.ibm.com>
Tue, 23 Jun 2026 15:33:28 +0000 (17:33 +0200)
committerClaudio Imbrenda <imbrenda@linux.ibm.com>
Wed, 24 Jun 2026 08:08:57 +0000 (10:08 +0200)
commit6cfd47f91f6aa3bcf9fe15388be52feb4b180440
tree0ad5a38d0602f26139ccb22704b10ef5d4fe901c
parent9b0bf9b93cbff50764713b62d0f38d5238eea8c8
KVM: s390: Fix cmma dirty tracking

It is possible that some guest memory areas have not been touched yet
when starting migration mode, and thus have no ptes allocated. Only
existing and allocated ptes should count toward the total of dirty cmma
entries.

When starting migration mode, enable the migration_mode flag
immediately, so that any subsequent ESSA will trap in the host and
cause cmma_dirty_pages to be increased as needed.
Subsequently, set the cmma_d bit on all existing cmma-clean PGSTEs,
increasing cmma_dirty_pages as needed. Skipping cmma-dirty pages
prevents double counting.

Conversely, when disabling migration mode, set cmma_dirty_pages to 0
and clear the cmma_d bit in all existing PGSTEs.

The invariant is that when migration mode is off, no PGSTE has its
cmma_d bit set, and cmma_dirty_pages is 0. kvm->slots_lock protects
kvm_s390_vm_start_migration() and kvm_s390_vm_stop_migration() from
each other and from kvm_s390_get_cmma_bits().

Also fix dat_get_cmma() to properly wrap around if the first attempt
reached the end of guest memory without finding cmma-dirty pages.

[ imbrenda: Moved kvm_s390_sync_request_broadcast() before gmap_set_cmma_all_dirty() ]

Fixes: e38c884df921 ("KVM: s390: Switch to new gmap")
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Message-ID: <20260623153331.233784-8-imbrenda@linux.ibm.com>
arch/s390/kvm/dat.c
arch/s390/kvm/gmap.c
arch/s390/kvm/gmap.h
arch/s390/kvm/kvm-s390.c
arch/s390/kvm/priv.c