When resolving a fault in the slow path, via _gmap_link(), the soft-dirty bit of the old entry is used for the new entry, overwriting whatever value it had. If the new entry would have set the soft-dirty bit, it is overwritten with the old value, potentially losing the soft-dirty status. Fix by ORing the soft-dirty bit in the new entries with the old one. This way a soft-dirty entry stays soft-dirty, but a previously clean page can become soft-dirty. Also fix improper check of the old crste. Use crste_none() instead of the improper open coded comparison to _CRSTE_EMPTY(oldval.h.tt). Fixes: 94fd9b16cc67 ("KVM: s390: KVM page table management functions: lifecycle management") Fixes: 45921d0212d4 ("KVM: s390: Fix gmap_link()") Cc: stable@vger.kernel.org Signed-off-by: Claudio Imbrenda --- arch/s390/kvm/gmap/gmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/s390/kvm/gmap/gmap.c b/arch/s390/kvm/gmap/gmap.c index c7af1ad9f7c1..31669a5c51cc 100644 --- a/arch/s390/kvm/gmap/gmap.c +++ b/arch/s390/kvm/gmap/gmap.c @@ -825,7 +825,7 @@ static int _gmap_link(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, int leve pgste = pgste_get_lock(f->ptep); oldpte = *f->ptep; newpte = _pte(f->pfn, f->writable, f->write_attempt | oldpte.s.d, !f->page); - newpte.s.sd = oldpte.s.sd; + newpte.s.sd |= oldpte.s.sd; oldpte.s.sd = 0; if (oldpte.val == _PTE_EMPTY.val || oldpte.h.pfra == f->pfn) { pgste = gmap_ptep_xchg(gmap, f->ptep, newpte, pgste, f->gfn); @@ -841,8 +841,8 @@ static int _gmap_link(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, int leve newval = _crste_fc1(f->pfn, oldval.h.tt, f->writable, f->write_attempt | oldval.s.fc1.d); newval.s.fc1.s = !f->page; - newval.s.fc1.sd = oldval.s.fc1.sd; - if (oldval.val != _CRSTE_EMPTY(oldval.h.tt).val && + newval.s.fc1.sd |= oldval.s.fc1.sd; + if (!crste_none(oldval) && crste_origin_large(oldval) != crste_origin_large(newval)) return -EAGAIN; f->crste_region3 = is_pud(newval); -- 2.56.1