* [PATCH v1 1/1] KVM: s390: Fix UCONTROL inconsistencies
@ 2026-09-17 11:53 Claudio Imbrenda
2026-09-17 12:02 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Claudio Imbrenda @ 2026-09-17 11:53 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
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.
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Fixes: a2c17f9270cc ("KVM: s390: New gmap code")
---
arch/s390/kvm/gmap/dat.h | 16 +++++++++++++++-
arch/s390/kvm/gmap/gmap.c | 40 ++++++++++++++++++---------------------
2 files changed, 33 insertions(+), 23 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 3f3fa864cc36..554015e0dad0 100644
--- a/arch/s390/kvm/gmap/gmap.c
+++ b/arch/s390/kvm/gmap/gmap.c
@@ -773,9 +773,7 @@ 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));
@@ -836,26 +834,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)
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-17 12:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17 11:53 [PATCH v1 1/1] KVM: s390: Fix UCONTROL inconsistencies Claudio Imbrenda
2026-09-17 12:02 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox