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 v2 02/10] KVM: s390: Refactor and improve DAT tables handling
Date: Fri, 23 Oct 2026 17:55:23 +0200	[thread overview]
Message-ID: <20261023155531.206113-3-imbrenda@linux.ibm.com> (raw)
In-Reply-To: <20261023155531.206113-1-imbrenda@linux.ibm.com>

Refactor and improve functions to handle gmap DAT tables. Handle
machine_has_tlb_guest() inside the helper functions; the callers won't
have to worry about it anymore.

Add crdte_pte() to allow using CRDTE on ptes.

Fix idte_crste() to add the missing table-type bits and the missing
"memory" clobber.

Fixes: 5a74e3d93417 ("KVM: s390: KVM-specific bitfields and helper functions")
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 arch/s390/kvm/gmap/dat.h | 55 ++++++++++++++++++++++++++++++----------
 1 file changed, 41 insertions(+), 14 deletions(-)

diff --git a/arch/s390/kvm/gmap/dat.h b/arch/s390/kvm/gmap/dat.h
index 3167543bf2cc..0832a070f6f7 100644
--- a/arch/s390/kvm/gmap/dat.h
+++ b/arch/s390/kvm/gmap/dat.h
@@ -110,6 +110,9 @@ union pte {
 #define _PAGES_PER_SEGMENT	_PAGE_ENTRIES
 #define _PAGES_PER_REGION3	(_PAGES_PER_SEGMENT * _CRST_ENTRIES)
 
+#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
 
@@ -609,38 +612,62 @@ static inline bool crdte_crste(union crste *crstep, union crste old, union crste
 {
 	unsigned long dtt = 0x10 | new.h.tt << 2;
 	void *table = crste_table_start(crstep);
+	unsigned long addr = gfn_to_gpa(gfn);
+
+	addr |= machine_has_tlb_guest() ? CRDTE_GUEST_ASCE : 0;
+	return crdte(old.val, new.val, table, dtt, addr, asce.val);
+}
 
-	return crdte(old.val, new.val, table, dtt, gfn_to_gpa(gfn), asce.val);
+static inline bool crdte_pte(union pte *ptep, union pte old, union pte new, gfn_t gfn,
+			     union asce asce, bool nt)
+{
+	void *table = pte_table_start(ptep);
+	unsigned long addr = gfn_to_gpa(gfn);
+
+	if (machine_has_tlb_guest())
+		addr |= CRDTE_GUEST_ASCE | (nt ? CRDTE_NODAT : 0);
+	return crdte(old.val, new.val, table, 0, addr, asce.val);
 }
 
 /**
  * idte_crste() - invalidate a crste entry using idte
  * @crstep: pointer to the crste to be invalidated
  * @gfn: a gfn mapped by the crste
- * @opt: options for the idte instruction
  * @asce: the asce
- * @local: whether the operation is cpu-local
  */
-static __always_inline void idte_crste(union crste *crstep, gfn_t gfn, unsigned long opt,
-				       union asce asce, int local)
+static __always_inline void idte_crste(union crste *crstep, gfn_t gfn, union asce asce)
 {
 	unsigned long table_origin = __pa(crste_table_start(crstep));
 	unsigned long gaddr = gfn_to_gpa(gfn) & HPAGE_MASK;
 
-	if (__builtin_constant_p(opt) && opt == 0) {
+	table_origin |= crstep->val & _REGION_ENTRY_TYPE_MASK;
+
+	if (!machine_has_tlb_guest()) {
 		/* flush without guest asce */
-		asm volatile("idte	%[table_origin],0,%[gaddr],%[local]"
+		asm volatile("idte	%[table_origin],0,%[gaddr]"
 			: "+m" (*crstep)
-			: [table_origin] "a" (table_origin), [gaddr] "a" (gaddr),
-			  [local] "i" (local)
-			: "cc");
+			: [table_origin] "a" (table_origin), [gaddr] "a" (gaddr)
+			: "memory", "cc");
 	} else {
 		/* flush with guest asce */
-		asm volatile("idte %[table_origin],%[asce],%[gaddr_opt],%[local]"
+		asm volatile("idte %[table_origin],%[asce],%[gaddr_opt]"
 			: "+m" (*crstep)
-			: [table_origin] "a" (table_origin), [gaddr_opt] "a" (gaddr | opt),
-			  [asce] "a" (asce.val), [local] "i" (local)
-			: "cc");
+			: [table_origin] "a" (table_origin),
+			  [gaddr_opt] "a" (gaddr | IDTE_GUEST_ASCE),
+			  [asce] "a" (asce.val)
+			: "memory", "cc");
+	}
+}
+
+static __always_inline void ipte(gfn_t gfn, union pte *ptep, union asce asce, bool nt)
+{
+	unsigned long flags;
+
+	if (machine_has_tlb_guest()) {
+		flags = IPTE_GUEST_ASCE | (nt ? IPTE_NODAT : 0);
+		__ptep_ipte(gfn_to_gpa(gfn), (void *)ptep, flags, asce.val, IPTE_GLOBAL);
+	} else {
+		__ptep_ipte(gfn_to_gpa(gfn), (void *)ptep, 0, 0, IPTE_GLOBAL);
 	}
 }
 
-- 
2.56.0


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

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

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=20261023155531.206113-3-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