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 v4 1/7] KVM: s390: Fix UCONTROL inconsistencies
Date: Wed, 28 Oct 2026 19:54:16 +0100 [thread overview]
Message-ID: <20261028185422.272146-2-imbrenda@linux.ibm.com> (raw)
In-Reply-To: <20261028185422.272146-1-imbrenda@linux.ibm.com>
For UCONTROL VMs, when a vCPU segment entry is mapped but unallocated,
the tl field was set to 1. This collides with the present bit, which
means that other parts of gmap would mistake the entry for a present
one.
Refactor the code to use a different combination of flags to indicate a
mapped but unallocated segment.
The new flags combination will result in several functions returning
-EFAULT when used on UCONTROL guests. This is fine, since those
interfaces should not be used for UCONTROL guests to begin with.
Proper fencing of the interfaces that are not allowed for UCONTROL
guests is outside the scope of this patch.
Fixes: a2c17f9270cc ("KVM: s390: New gmap code")
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: stable@vger.kernel.org # 7.0+
---
arch/s390/kvm/gmap/dat.h | 16 +++++++++++-
arch/s390/kvm/gmap/gmap.c | 54 +++++++++++++++++++--------------------
2 files changed, 41 insertions(+), 29 deletions(-)
diff --git a/arch/s390/kvm/gmap/dat.h b/arch/s390/kvm/gmap/dat.h
index 90389d47ba4e..4665c1112bb9 100644
--- a/arch/s390/kvm/gmap/dat.h
+++ b/arch/s390/kvm/gmap/dat.h
@@ -109,6 +109,8 @@ union pte {
#define _REGION3_FR_MASK (_REGION3_MASK >> PAGE_SHIFT)
#define _PAGES_PER_SEGMENT _PAGE_ENTRIES
#define _PAGES_PER_REGION3 (_PAGES_PER_SEGMENT * _CRST_ENTRIES)
+#define _UCAS_ENTRY_LENGTH 0
+#define _UCAS_ENTRY_OFFSET 3
/* Soft dirty, needed as macro for atomic operations on ptes */
#define _PAGE_SD 0x002
@@ -421,6 +423,17 @@ static inline union crste _crste_fc0(kvm_pfn_t pfn, int tt)
return res;
}
+static inline union crste _crste_ucas(kvm_pfn_t pfn)
+{
+ union crste res = { .val = PFN_PHYS(pfn) };
+
+ res.h.i = 1;
+ res.h.tt = TABLE_TYPE_SEGMENT;
+ res.h.fc0.tl = _UCAS_ENTRY_LENGTH;
+ res.h.fc0.tf = _UCAS_ENTRY_OFFSET;
+ return res;
+}
+
/**
* _crste() - Useful constructor for union crste with FC=1
* @pfn: the pfn this pte should point to.
@@ -985,7 +998,8 @@ static inline int dat_create_slot(struct kvm_s390_mmu_cache *mc, union asce asce
static inline bool crste_is_ucas(union crste crste)
{
- return is_pmd(crste) && crste.h.i && crste.h.fc0.tl == 1 && crste.h.fc == 0;
+ return is_pmd(crste) && crste.h.i && !crste.h.fc &&
+ crste.h.fc0.tl == _UCAS_ENTRY_LENGTH && crste.h.fc0.tf == _UCAS_ENTRY_OFFSET;
}
#endif /* ARCH_KVM_GMAP_DAT_H */
diff --git a/arch/s390/kvm/gmap/gmap.c b/arch/s390/kvm/gmap/gmap.c
index bf91e3d5013b..225fdae3d57c 100644
--- a/arch/s390/kvm/gmap/gmap.c
+++ b/arch/s390/kvm/gmap/gmap.c
@@ -777,16 +777,14 @@ static int gmap_ucas_map_one(struct kvm_s390_mmu_cache *mc, struct gmap *gmap,
if (rc)
return rc;
if (!ptep) {
- newcrste = _crste_fc0(p_gfn, TABLE_TYPE_SEGMENT);
- newcrste.h.i = 1;
- newcrste.h.fc0.tl = 1;
+ newcrste = _crste_ucas(p_gfn);
} else {
pt = pte_table_start(ptep);
dat_set_ptval(pt, PTVAL_VMADDR, p_gfn >> (_SEGMENT_SHIFT - PAGE_SHIFT));
newcrste = _crste_fc0(virt_to_pfn(pt), TABLE_TYPE_SEGMENT);
}
- rc = dat_entry_walk(mc, c_gfn, gmap->asce, DAT_WALK_ALLOC, TABLE_TYPE_SEGMENT,
- &crstep, &ptep);
+ rc = dat_entry_walk(mc, c_gfn, gmap->asce, DAT_WALK_ALLOC | DAT_WALK_IGN_HOLES,
+ TABLE_TYPE_SEGMENT, &crstep, &ptep);
if (rc)
return rc;
do {
@@ -802,8 +800,9 @@ static int gmap_ucas_translate_simple(struct gmap *gmap, gpa_t *gaddr, union crs
union pte *ptep;
int rc;
- rc = dat_entry_walk(NULL, gpa_to_gfn(*gaddr), gmap->asce, DAT_WALK_CONTINUE,
- TABLE_TYPE_SEGMENT, crstepp, &ptep);
+ rc = dat_entry_walk(NULL, gpa_to_gfn(*gaddr), gmap->asce,
+ DAT_WALK_IGN_HOLES | DAT_WALK_ANY,
+ TABLE_TYPE_PAGE_TABLE, crstepp, &ptep);
if (rc || (!ptep && !crste_is_ucas(**crstepp)))
return -EREMOTE;
if (!ptep)
@@ -840,26 +839,24 @@ int gmap_ucas_translate(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, gpa_t
if (rc <= 0)
return rc;
}
- do {
- scoped_guard(write_lock, &gmap->kvm->mmu_lock) {
- rc = gmap_ucas_translate_simple(gmap, gaddr, &crstep);
- if (rc <= 0)
- return rc;
- translated_address = (*gaddr & ~_SEGMENT_MASK) |
- (crstep->val & _SEGMENT_MASK);
- rc = gmap_ucas_map_one(mc, gmap, gpa_to_gfn(translated_address), gfn, true);
- }
- if (!rc) {
- *gaddr = translated_address;
- return 0;
- }
- if (rc != -ENOMEM)
- return -EREMOTE;
- rc = kvm_s390_mmu_cache_topup(mc);
- if (rc)
+ rc = kvm_s390_mmu_cache_topup(mc);
+ if (rc)
+ return rc;
+
+ scoped_guard(write_lock, &gmap->kvm->mmu_lock) {
+ rc = gmap_ucas_translate_simple(gmap, gaddr, &crstep);
+ if (rc <= 0)
return rc;
- } while (1);
- return 0;
+ translated_address = (*gaddr & ~_SEGMENT_MASK) |
+ (crstep->val & _SEGMENT_MASK);
+ rc = gmap_ucas_map_one(mc, gmap, gpa_to_gfn(translated_address), gfn, true);
+ }
+
+ if (!rc)
+ *gaddr = translated_address;
+ if (!rc || rc == -ENOMEM)
+ return rc;
+ return -EREMOTE;
}
int gmap_ucas_map(struct gmap *gmap, gfn_t p_gfn, gfn_t c_gfn, unsigned long count)
@@ -896,8 +893,9 @@ static void gmap_ucas_unmap_one(struct gmap *gmap, gfn_t c_gfn)
union pte *ptep;
int rc;
- rc = dat_entry_walk(NULL, c_gfn, gmap->asce, 0, TABLE_TYPE_SEGMENT, &crstep, &ptep);
- if (rc)
+ rc = dat_entry_walk(NULL, c_gfn, gmap->asce, DAT_WALK_IGN_HOLES,
+ TABLE_TYPE_SEGMENT, &crstep, &ptep);
+ if (rc || !is_pmd(*crstep))
return;
while (!dat_crstep_xchg_atomic(crstep, READ_ONCE(*crstep), _PMD_EMPTY, c_gfn, gmap->asce))
;
--
2.56.0
next prev parent reply other threads:[~2026-10-28 18:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 18:54 [PATCH v4 0/7] KVM: s390: Misc bugfixes for 7.4 Claudio Imbrenda
2026-10-28 18:54 ` Claudio Imbrenda [this message]
2026-10-28 19:15 ` [PATCH v4 1/7] KVM: s390: Fix UCONTROL inconsistencies sashiko-bot
2026-10-28 18:54 ` [PATCH v4 2/7] KVM: s390: Move some skey functions to headers Claudio Imbrenda
2026-10-28 18:57 ` sashiko-bot
2026-10-28 18:54 ` [PATCH v4 3/7] KVM: s390: Fix idte_crste() clobber and table type Claudio Imbrenda
2026-10-28 19:00 ` sashiko-bot
2026-10-28 18:54 ` [PATCH v4 4/7] KVM: s390: Improve unmapping of large ranges Claudio Imbrenda
2026-10-28 19:10 ` sashiko-bot
2026-10-28 18:54 ` [PATCH v4 5/7] KVM: s390: vsie: Fix pinning using the wrong flag Claudio Imbrenda
2026-10-28 18:58 ` sashiko-bot
2026-10-28 18:54 ` [PATCH v4 6/7] KVM: s390: Introduce gmap_allocate_all_page_tables_best_effort() Claudio Imbrenda
2026-10-28 19:10 ` sashiko-bot
2026-10-28 18:54 ` [PATCH v4 7/7] KVM: s390: Allocate page tables when CMMA is used Claudio Imbrenda
2026-10-28 19:28 ` 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=20261028185422.272146-2-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.