Skip to content

Commit 0f2b760

Browse files
author
Claudio Imbrenda
committed
KVM: s390: Correctly handle guest mappings without struct page
Introduce a new special softbit for large pages, like already presend for normal pages, and use it to mark guest mappings that do not have struct pages. Whenever a leaf DAT entry becomes dirty, check the special softbit and only call SetPageDirty() if there is an actual struct page. Move the logic to mark pages dirty inside _gmap_ptep_xchg() and _gmap_crstep_xchg_atomic(), to avoid needlessly duplicating the code. Fixes: 5a74e3d ("KVM: s390: KVM-specific bitfields and helper functions") Fixes: a2c17f9 ("KVM: s390: New gmap code") Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
1 parent 45921d0 commit 0f2b760

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

arch/s390/kvm/dat.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ union pmd {
160160
unsigned long :44; /* HW */
161161
unsigned long : 3; /* Unused */
162162
unsigned long : 1; /* HW */
163+
unsigned long s : 1; /* Special */
163164
unsigned long w : 1; /* Writable soft-bit */
164165
unsigned long r : 1; /* Readable soft-bit */
165166
unsigned long d : 1; /* Dirty */
166167
unsigned long y : 1; /* Young */
167-
unsigned long prefix_notif : 1; /* Guest prefix invalidation notification */
168168
unsigned long : 3; /* HW */
169+
unsigned long prefix_notif : 1; /* Guest prefix invalidation notification */
169170
unsigned long vsie_notif : 1; /* Referenced in a shadow table */
170-
unsigned long : 1; /* Unused */
171171
unsigned long : 4; /* HW */
172172
unsigned long sd : 1; /* Soft-Dirty */
173173
unsigned long pr : 1; /* Present */
@@ -183,14 +183,14 @@ union pud {
183183
unsigned long :33; /* HW */
184184
unsigned long :14; /* Unused */
185185
unsigned long : 1; /* HW */
186+
unsigned long s : 1; /* Special */
186187
unsigned long w : 1; /* Writable soft-bit */
187188
unsigned long r : 1; /* Readable soft-bit */
188189
unsigned long d : 1; /* Dirty */
189190
unsigned long y : 1; /* Young */
190-
unsigned long prefix_notif : 1; /* Guest prefix invalidation notification */
191191
unsigned long : 3; /* HW */
192+
unsigned long prefix_notif : 1; /* Guest prefix invalidation notification */
192193
unsigned long vsie_notif : 1; /* Referenced in a shadow table */
193-
unsigned long : 1; /* Unused */
194194
unsigned long : 4; /* HW */
195195
unsigned long sd : 1; /* Soft-Dirty */
196196
unsigned long pr : 1; /* Present */
@@ -254,14 +254,14 @@ union crste {
254254
struct {
255255
unsigned long :47;
256256
unsigned long : 1; /* HW (should be 0) */
257+
unsigned long s : 1; /* Special */
257258
unsigned long w : 1; /* Writable */
258259
unsigned long r : 1; /* Readable */
259260
unsigned long d : 1; /* Dirty */
260261
unsigned long y : 1; /* Young */
261-
unsigned long prefix_notif : 1; /* Guest prefix invalidation notification */
262262
unsigned long : 3; /* HW */
263+
unsigned long prefix_notif : 1; /* Guest prefix invalidation notification */
263264
unsigned long vsie_notif : 1; /* Referenced in a shadow table */
264-
unsigned long : 1;
265265
unsigned long : 4; /* HW */
266266
unsigned long sd : 1; /* Soft-Dirty */
267267
unsigned long pr : 1; /* Present */

arch/s390/kvm/gmap.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ void gmap_sync_dirty_log(struct gmap *gmap, gfn_t start, gfn_t end)
519519
_dat_walk_gfn_range(start, end, gmap->asce, &walk_ops, 0, gmap);
520520
}
521521

522-
static int gmap_handle_minor_crste_fault(union asce asce, struct guest_fault *f)
522+
static int gmap_handle_minor_crste_fault(struct gmap *gmap, struct guest_fault *f)
523523
{
524524
union crste newcrste, oldcrste = READ_ONCE(*f->crstep);
525525

@@ -544,10 +544,8 @@ static int gmap_handle_minor_crste_fault(union asce asce, struct guest_fault *f)
544544
newcrste.s.fc1.d = 1;
545545
newcrste.s.fc1.sd = 1;
546546
}
547-
if (!oldcrste.s.fc1.d && newcrste.s.fc1.d)
548-
SetPageDirty(phys_to_page(crste_origin_large(newcrste)));
549547
/* In case of races, let the slow path deal with it. */
550-
return !dat_crstep_xchg_atomic(f->crstep, oldcrste, newcrste, f->gfn, asce);
548+
return !gmap_crstep_xchg_atomic(gmap, f->crstep, oldcrste, newcrste, f->gfn);
551549
}
552550
/* Trying to write on a read-only page, let the slow path deal with it. */
553551
return 1;
@@ -576,8 +574,6 @@ static int _gmap_handle_minor_pte_fault(struct gmap *gmap, union pgste *pgste,
576574
newpte.s.d = 1;
577575
newpte.s.sd = 1;
578576
}
579-
if (!oldpte.s.d && newpte.s.d)
580-
SetPageDirty(pfn_to_page(newpte.h.pfra));
581577
*pgste = gmap_ptep_xchg(gmap, f->ptep, newpte, *pgste, f->gfn);
582578

583579
return 0;
@@ -614,7 +610,7 @@ int gmap_try_fixup_minor(struct gmap *gmap, struct guest_fault *fault)
614610
fault->callback(fault);
615611
pgste_set_unlock(fault->ptep, pgste);
616612
} else {
617-
rc = gmap_handle_minor_crste_fault(gmap->asce, fault);
613+
rc = gmap_handle_minor_crste_fault(gmap, fault);
618614
if (!rc && fault->callback)
619615
fault->callback(fault);
620616
}
@@ -669,6 +665,7 @@ static int _gmap_link(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, int leve
669665
oldval = READ_ONCE(*f->crstep);
670666
newval = _crste_fc1(f->pfn, oldval.h.tt, f->writable,
671667
f->write_attempt | oldval.s.fc1.d);
668+
newval.s.fc1.s = !f->page;
672669
newval.s.fc1.sd = oldval.s.fc1.sd;
673670
if (oldval.val != _CRSTE_EMPTY(oldval.h.tt).val &&
674671
crste_origin_large(oldval) != crste_origin_large(newval))

arch/s390/kvm/gmap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ static inline union pgste _gmap_ptep_xchg(struct gmap *gmap, union pte *ptep, un
185185
else
186186
_gmap_handle_vsie_unshadow_event(gmap, gfn);
187187
}
188+
if (!ptep->s.d && newpte.s.d && !newpte.s.s)
189+
SetPageDirty(pfn_to_page(newpte.h.pfra));
188190
return __dat_ptep_xchg(ptep, pgste, newpte, gfn, gmap->asce, uses_skeys(gmap));
189191
}
190192

@@ -220,6 +222,8 @@ static inline bool __must_check _gmap_crstep_xchg_atomic(struct gmap *gmap, unio
220222
else
221223
_gmap_handle_vsie_unshadow_event(gmap, gfn);
222224
}
225+
if (!oldcrste.s.fc1.d && newcrste.s.fc1.d && !newcrste.s.fc1.s)
226+
SetPageDirty(phys_to_page(crste_origin_large(newcrste)));
223227
return dat_crstep_xchg_atomic(crstep, oldcrste, newcrste, gfn, gmap->asce);
224228
}
225229

0 commit comments

Comments
 (0)