Linux s390 Architecture development
 help / color / mirror / Atom feed
From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org, borntraeger@de.ibm.com,
	frankja@linux.ibm.com, david@kernel.org, nrb@linux.ibm.com,
	schlameuss@linux.ibm.com, gra@linux.ibm.com
Subject: [PATCH v1 03/10] KVM: s390: Move prefix marker from PGSTEs to PTEs
Date: Thu, 22 Oct 2026 17:55:24 +0200	[thread overview]
Message-ID: <20261022155531.204593-4-imbrenda@linux.ibm.com> (raw)
In-Reply-To: <20261022155531.204593-1-imbrenda@linux.ibm.com>

Move the prefix marker from PGSTEs to PTEs; this is a preparation for
PGSTE-less guests.

Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 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 bf01af50e192..27cc5abe6eaf 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


  parent reply	other threads:[~2026-10-22 15:55 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 15:55 [PATCH v1 00/10] KVM: s390: Misc bugfixes and improvements for 7.4 Claudio Imbrenda
2026-10-22 15:55 ` [PATCH v1 01/10] KVM: s390: Move some skey functions to headers Claudio Imbrenda
2026-10-22 15:58   ` sashiko-bot
2026-10-22 15:55 ` [PATCH v1 02/10] KVM: s390: Refactor and improve DAT tables handling Claudio Imbrenda
2026-10-22 16:05   ` sashiko-bot
2026-10-22 15:55 ` Claudio Imbrenda [this message]
2026-10-22 16:06   ` [PATCH v1 03/10] KVM: s390: Move prefix marker from PGSTEs to PTEs sashiko-bot
2026-10-22 15:55 ` [PATCH v1 04/10] KVM: s390: Automatically enable storage keys for UCONTROL VMs Claudio Imbrenda
2026-10-22 16:13   ` sashiko-bot
2026-10-22 15:55 ` [PATCH v1 05/10] KVM: s390: Replace ASCE usage with a struct with more flags Claudio Imbrenda
2026-10-22 16:09   ` sashiko-bot
2026-10-22 15:55 ` [PATCH v1 06/10] KVM: s390: Rework some helper functions Claudio Imbrenda
2026-10-22 16:00   ` sashiko-bot
2026-10-22 15:55 ` [PATCH v1 07/10] KVM: s390: Fix UCONTROL inconsistencies Claudio Imbrenda
2026-10-22 17:00   ` sashiko-bot
2026-10-22 15:55 ` [PATCH v1 08/10] KVM: s390: Improve unmapping of large ranges Claudio Imbrenda
2026-10-22 16:53   ` sashiko-bot
2026-10-22 15:55 ` [PATCH v1 09/10] KVM: s390: vsie: Fix pinning using the wrong flag Claudio Imbrenda
2026-10-22 16:02   ` sashiko-bot
2026-10-22 15:55 ` [PATCH v1 10/10] KVM: s390: Enable 1M pages by default Claudio Imbrenda
2026-10-22 16:11   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261022155531.204593-4-imbrenda@linux.ibm.com \
    --to=imbrenda@linux.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=david@kernel.org \
    --cc=frankja@linux.ibm.com \
    --cc=gra@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=nrb@linux.ibm.com \
    --cc=schlameuss@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox