Move the prefix marker from PGSTEs to PTEs; this is a preparation for PGSTE-less guests. Signed-off-by: Claudio Imbrenda --- arch/s390/kvm/gmap/dat.c | 11 ++++++----- arch/s390/kvm/gmap/dat.h | 10 +++++----- arch/s390/kvm/gmap/gmap.c | 7 ++++--- arch/s390/kvm/gmap/gmap.h | 4 ++-- arch/s390/kvm/s390/gaccess.c | 1 + 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/arch/s390/kvm/gmap/dat.c b/arch/s390/kvm/gmap/dat.c index b9507daaf327..48bb97ae4dd1 100644 --- a/arch/s390/kvm/gmap/dat.c +++ b/arch/s390/kvm/gmap/dat.c @@ -234,12 +234,12 @@ static int dat_split_ste(struct kvm_s390_mmu_cache *mc, union pmd *pmdp, gfn_t g init.s.y = old.s.fc1.y; init.s.sd = old.s.fc1.sd; init.s.pr = old.s.fc1.pr; + init.s.prefix_notif = old.s.fc1.prefix_notif; pgste_init.val = 0; if (old.h.fc) { for (i = 0; i < _PAGE_ENTRIES; i++) pt->ptes[i].val = init.val | i * PAGE_SIZE; /* No need to take locks as the page table is not installed yet. */ - pgste_init.prefix_notif = old.s.fc1.prefix_notif; pgste_init.vsie_notif = old.s.fc1.vsie_notif; pgste_init.vsie_gmem = old.s.fc1.vsie_notif; pgste_init.pcl = uses_skeys && init.h.i; @@ -1017,14 +1017,15 @@ static long dat_set_pn_crste(union crste *crstep, gfn_t gfn, gfn_t next, struct static long dat_set_pn_pte(union pte *ptep, gfn_t gfn, gfn_t next, struct dat_walk *walk) { int *n = walk->priv; - union pgste pgste; - pgste = pgste_get_lock(ptep); + /* + * Updating a softbit while holding kvm->mmu_lock in write mode, no + * need to take the PCL lock. + */ if (!ptep->h.i && !ptep->h.p) { - pgste.prefix_notif = 1; + __atomic64_or(_PAGE_PREFIX_NOTIF, &ptep->val); *n += 1; } - pgste_set_unlock(ptep, pgste); return 0; } diff --git a/arch/s390/kvm/gmap/dat.h b/arch/s390/kvm/gmap/dat.h index 0832a070f6f7..8af4409332e4 100644 --- a/arch/s390/kvm/gmap/dat.h +++ b/arch/s390/kvm/gmap/dat.h @@ -77,7 +77,7 @@ union pte { unsigned long u : 1; /* Page unused */ unsigned long s : 1; /* Special */ unsigned long w : 1; /* Writable */ - unsigned long r : 1; /* Readable */ + unsigned long prefix_notif:1; /* Guest prefix invalidation notification */ unsigned long d : 1; /* Dirty */ unsigned long y : 1; /* Young */ unsigned long sd: 1; /* Soft dirty */ @@ -113,8 +113,9 @@ union pte { #define CRDTE_NODAT IPTE_NODAT #define CRDTE_GUEST_ASCE IPTE_GUEST_ASCE -/* Soft dirty, needed as macro for atomic operations on ptes */ -#define _PAGE_SD 0x002 +/* Needed as macro for atomic operations on ptes */ +#define _PAGE_PREFIX_NOTIF 0x010 /* Guest prefix invalidation notification */ +#define _PAGE_SD 0x002 /* Soft dirty */ /* Needed as macro to perform atomic operations */ #define PGSTE_PCL_BIT 0x0080000000000000UL /* PCL lock, HW bit */ @@ -147,10 +148,9 @@ union pgste { unsigned long usage : 2; unsigned long : 8; unsigned long cmma_d : 1; /* Dirty flag for CMMA bits */ - unsigned long prefix_notif : 1; /* Guest prefix invalidation notification */ unsigned long vsie_notif : 1; /* Referenced in a shadow table */ unsigned long vsie_gmem : 1; /* Contains nested guest memory */ - unsigned long : 4; + unsigned long : 5; unsigned long : 8; }; struct { diff --git a/arch/s390/kvm/gmap/gmap.c b/arch/s390/kvm/gmap/gmap.c index 3f3fa864cc36..bf7f27d6be96 100644 --- a/arch/s390/kvm/gmap/gmap.c +++ b/arch/s390/kvm/gmap/gmap.c @@ -298,7 +298,7 @@ static long gmap_clear_young_pte(union pte *ptep, gfn_t gfn, gfn_t end, struct d return 0; pgste = pgste_get_lock(ptep); - if (!pgste.prefix_notif || gmap_mkold_prefix(p->gmap, gfn, end)) { + if (!pte.s.prefix_notif || gmap_mkold_prefix(p->gmap, gfn, end)) { new = pte; new.h.i = 1; new.s.y = 0; @@ -307,7 +307,7 @@ static long gmap_clear_young_pte(union pte *ptep, gfn_t gfn, gfn_t end, struct d new.s.d = 0; new.h.p = 1; - pgste.prefix_notif = 0; + new.s.prefix_notif = 0; pgste = __dat_ptep_xchg(ptep, pgste, new, gfn, walk->asce, uses_skeys(p->gmap)); } p->young = 1; @@ -470,7 +470,7 @@ static union pgste __pte_test_and_clear_softdirty(union pte *ptep, union pgste p * If this page contains one or more prefixes of vCPUS that are currently * running, do not reset the protection, leave it marked as dirty. */ - if (!pgste.prefix_notif || gmap_mkold_prefix(gmap, gfn, gfn + 1)) { + if (!pte.s.prefix_notif || gmap_mkold_prefix(gmap, gfn, gfn + 1)) { pte.h.p = 1; pte.s.sd = 0; pgste = gmap_ptep_xchg(gmap, ptep, pte, pgste, gfn); @@ -707,6 +707,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.prefix_notif = oldpte.s.prefix_notif; newpte.s.sd = oldpte.s.sd; oldpte.s.sd = 0; if (oldpte.val == _PTE_EMPTY.val || oldpte.h.pfra == f->pfn) { diff --git a/arch/s390/kvm/gmap/gmap.h b/arch/s390/kvm/gmap/gmap.h index 8f47f29c89fd..4042e1d4e77c 100644 --- a/arch/s390/kvm/gmap/gmap.h +++ b/arch/s390/kvm/gmap/gmap.h @@ -232,8 +232,8 @@ static inline union pgste _gmap_ptep_xchg(struct gmap *gmap, union pte *ptep, un else lockdep_assert_not_held(&gmap->children_lock); - if (pgste.prefix_notif && (newpte.h.p || newpte.h.i)) { - pgste.prefix_notif = 0; + if (ptep->s.prefix_notif && (newpte.h.p || newpte.h.i)) { + newpte.s.prefix_notif = 0; gmap_unmap_prefix(gmap, gfn, gfn + 1); } if (pte_needs_unshadow(*ptep, newpte, pgste)) { diff --git a/arch/s390/kvm/s390/gaccess.c b/arch/s390/kvm/s390/gaccess.c index 2d27dcb68002..8dc5b93ef01c 100644 --- a/arch/s390/kvm/s390/gaccess.c +++ b/arch/s390/kvm/s390/gaccess.c @@ -1435,6 +1435,7 @@ static int _do_shadow_pte(struct kvm_s390_mmu_cache *mc, struct gmap *sg, gpa_t newpte.s.d |= ptep_h->s.d; newpte.s.sd |= ptep_h->s.sd; newpte.h.p &= ptep_h->h.p; + newpte.s.prefix_notif = ptep_h->s.prefix_notif; if (!newpte.h.p && !f->writable) { rc = -EOPNOTSUPP; } else { -- 2.56.0