Skip to contentSkip to conversation

KVM: s390: Enable 4k granularity for memslots

PATCH In review Claudio Imbrenda 3 participants 24 messages Apr 2 – Apr 10

Subsystems (4)
lore
Share & tools
lore

Claudio Imbrenda

author maintainer
#0 lore raw

v3 cover KVM: s390: Enable 4k granularity for memslots

Currently the memslot granularity for s390 VMs is 1M. Both the s390 core architecture and virtio-mem only support a 1M granularity for guest memory.

Notwithstanding the official architectural limits, it can be beneficial to support memslots with 4k granularity. With the new gmap code, this is a quite simple change. This allows us to enable more existing selftests and makes KVM on s390 more future proof.

v2->v3
* Remove more 1M-alignment #ifdefs in the kvm selftests.
* Do not remove the common tests from loongarch, since loongarch does not include the common tests by default.
* Opportunistically fix a potential NULL pointer dereference when memslots for UCONTROL guests are attempted to be removed (does not actually happen in practice).

v1->v2
* Fixed the first patch (thanks Christian)

Claudio Imbrenda (6):
KVM: s390: Add some useful mask macros
KVM: s390: Add alignment checks for hugepages
KVM: s390: Allow 4k granularity for memslots
KVM: selftests: Remove 1M alignment requirement for s390
KVM: s390: selftests: enable some common memory-related tests
KVM: s390: ucontrol: Fix memslot handling

 arch/s390/kvm/dat.h                           |  5 +++
 arch/s390/kvm/faultin.c                       |  2 +-
 arch/s390/kvm/gaccess.c                       |  2 +-
 arch/s390/kvm/gmap.c                          | 32 +++++++++++++++----
 arch/s390/kvm/gmap.h                          |  3 +-
 arch/s390/kvm/kvm-s390.c                      | 22 ++++---------
 tools/testing/selftests/kvm/Makefile.kvm      |  9 ++----
 tools/testing/selftests/kvm/dirty_log_test.c  |  3 --
 .../testing/selftests/kvm/include/kvm_util.h  |  4 ---
 .../selftests/kvm/kvm_page_table_test.c       |  3 --
 tools/testing/selftests/kvm/lib/kvm_util.c    |  9 +-----
 tools/testing/selftests/kvm/lib/memstress.c   |  4 ---
 .../selftests/kvm/pre_fault_memory_test.c     |  4 ---
 .../selftests/kvm/set_memory_region_test.c    |  9 +-----
 14 files changed, 47 insertions(+), 64 deletions(-)
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH v3 1/6 KVM: s390: Add some useful mask macros

Add _{SEGMENT,REGION3}_FR_MASK, similar to _{SEGMENT,REGION3}_MASK, but working on gfn/pfn instead of addresses. Use them in gaccess.c instead of using the normal masks plus gpa_to_gfn().

Also add _PAGES_PER_{SEGMENT,REGION3} to make future code more readable.

---
 arch/s390/kvm/dat.h     | 5 +++++
 arch/s390/kvm/gaccess.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
arch/s390/kvm/dat.h +5 -0
index 123e11dcd70d..809cd7a8adb7 100644
@@ -104,6 +104,11 @@ union pte {
 	} tok;
 };
 
+#define _SEGMENT_FR_MASK	(_SEGMENT_MASK >> PAGE_SHIFT)
+#define _REGION3_FR_MASK	(_REGION3_MASK >> PAGE_SHIFT)
+#define _PAGES_PER_SEGMENT	_PAGE_ENTRIES
+#define _PAGES_PER_REGION3	(_PAGES_PER_SEGMENT * _CRST_ENTRIES)
+
 /* Soft dirty, needed as macro for atomic operations on ptes */
 #define _PAGE_SD 0x002
 
arch/s390/kvm/gaccess.c +1 -1
index 4630b2a067ea..a2ad11e2bf61 100644
@@ -1461,7 +1461,7 @@ static int _do_shadow_crste(struct gmap *sg, gpa_t raddr, union crste *host, uni
 	lockdep_assert_held(&sg->kvm->mmu_lock);
 	lockdep_assert_held(&sg->parent->children_lock);
 
-	gfn = f->gfn & gpa_to_gfn(is_pmd(*table) ? _SEGMENT_MASK : _REGION3_MASK);
+	gfn = f->gfn & (is_pmd(*table) ? _SEGMENT_FR_MASK : _REGION3_FR_MASK);
 	scoped_guard(spinlock, &sg->host_to_rmap_lock)
 		rc = gmap_insert_rmap(sg, gfn, gpa_to_gfn(raddr), host->h.tt);
 	if (rc)
Signature · 1 line
2.53.0
Reviewed-by on v3 1/6
#2 lore raw

Re: [PATCH v3 1/6] KVM: s390: Add some useful mask macros

Quoted 7 lines · Claudio Imbrenda

Add _{SEGMENT,REGION3}_FR_MASK, similar to _{SEGMENT,REGION3}_MASK, but working on gfn/pfn instead of addresses. Use them in gaccess.c instead of using the normal masks plus gpa_to_gfn().

Also add _PAGES_PER_{SEGMENT,REGION3} to make future code more readable.

Reviewed-by on v3 1/6
#3 lore raw

Re: [PATCH v3 1/6] KVM: s390: Add some useful mask macros

In reply to Claudio Imbrenda
Quoted 7 lines · Claudio Imbrenda

Add _{SEGMENT,REGION3}_FR_MASK, similar to _{SEGMENT,REGION3}_MASK, but working on gfn/pfn instead of addresses. Use them in gaccess.c instead of using the normal masks plus gpa_to_gfn().

Also add _PAGES_PER_{SEGMENT,REGION3} to make future code more readable.

Quoted 4 lines
---
 arch/s390/kvm/dat.h     | 5 +++++
 arch/s390/kvm/gaccess.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
author maintainer
#4 lore raw

PATCH v3 2/6 KVM: s390: Add alignment checks for hugepages

In reply to Claudio Imbrenda

When backing a guest page with a large page, check that the alignment of the guest page matches the alignment of the host physical page backing it within the large page.

Also check that the memslot is large enough to fit the large page.

Those checks are currently not needed, because memslots are guaranteed to be 1m-aligned, but this will change.

---
 arch/s390/kvm/faultin.c |  2 +-
 arch/s390/kvm/gmap.c    | 32 ++++++++++++++++++++++++++------
 arch/s390/kvm/gmap.h    |  3 ++-
 3 files changed, 29 insertions(+), 8 deletions(-)
arch/s390/kvm/faultin.c +1 -1
index e37cd18200f5..ddf0ca71f374 100644
@@ -109,7 +109,7 @@ int kvm_s390_faultin_gfn(struct kvm_vcpu *vcpu, struct kvm *kvm, struct guest_fa
 		scoped_guard(read_lock, &kvm->mmu_lock) {
 			if (!mmu_invalidate_retry_gfn(kvm, inv_seq, f->gfn)) {
 				f->valid = true;
-				rc = gmap_link(mc, kvm->arch.gmap, f);
+				rc = gmap_link(mc, kvm->arch.gmap, f, slot);
 				kvm_release_faultin_page(kvm, f->page, !!rc, f->write_attempt);
 				f->page = NULL;
 			}
arch/s390/kvm/gmap.c +26 -6
index ef0c6ebfdde2..e3c1b070a11d 100644
@@ -613,17 +613,37 @@ int gmap_try_fixup_minor(struct gmap *gmap, struct guest_fault *fault)
 	return rc;
 }
 
-static inline bool gmap_2g_allowed(struct gmap *gmap, gfn_t gfn)
+static inline bool gmap_2g_allowed(struct gmap *gmap, struct guest_fault *f,
+				   struct kvm_memory_slot *slot)
 {
 	return false;
 }
 
-static inline bool gmap_1m_allowed(struct gmap *gmap, gfn_t gfn)
+/**
+ * gmap_1m_allowed() - Check whether a 1M hugepage is allowed.
+ * @gmap: The gmap of the guest.
+ * @f: Describes the fault that is being resolved.
+ * @slot: The memslot the faulting address belongs to.
+ *
+ * The function checks whether the GMAP_FLAG_ALLOW_HPAGE_1M flag is set for
+ * @gmap, whether the offset of the address in the 1M virtual frame is the
+ * same as the offset in the physical 1M frame, and finally whether the whole
+ * 1M page would fit in the given memslot.
+ *
+ * Return: true if a 1M hugepage is allowed to back the faulting address, false
+ *         otherwise.
+ */
+static inline bool gmap_1m_allowed(struct gmap *gmap, struct guest_fault *f,
+				   struct kvm_memory_slot *slot)
 {
-	return test_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &gmap->flags);
+	return test_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &gmap->flags) &&
+	       !((f->gfn ^ f->pfn) & ~_SEGMENT_FR_MASK) &&
+	       slot->base_gfn <= ALIGN_DOWN(f->gfn, _PAGES_PER_SEGMENT) &&
+	       slot->base_gfn + slot->npages >= ALIGN(f->gfn + 1, _PAGES_PER_SEGMENT);
 }
 
-int gmap_link(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, struct guest_fault *f)
+int gmap_link(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, struct guest_fault *f,
+	      struct kvm_memory_slot *slot)
 {
 	unsigned int order;
 	int rc, level;
@@ -633,9 +653,9 @@ int gmap_link(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, struct guest_fau
 	level = TABLE_TYPE_PAGE_TABLE;
 	if (f->page) {
 		order = folio_order(page_folio(f->page));
-		if (order >= get_order(_REGION3_SIZE) && gmap_2g_allowed(gmap, f->gfn))
+		if (order >= get_order(_REGION3_SIZE) && gmap_2g_allowed(gmap, f, slot))
 			level = TABLE_TYPE_REGION3;
-		else if (order >= get_order(_SEGMENT_SIZE) && gmap_1m_allowed(gmap, f->gfn))
+		else if (order >= get_order(_SEGMENT_SIZE) && gmap_1m_allowed(gmap, f, slot))
 			level = TABLE_TYPE_SEGMENT;
 	}
 	rc = dat_link(mc, gmap->asce, level, uses_skeys(gmap), f);
arch/s390/kvm/gmap.h +2 -1
index ccb5cd751e31..a2f74587ddbf 100644
@@ -90,7 +90,8 @@ struct gmap *gmap_new(struct kvm *kvm, gfn_t limit);
 struct gmap *gmap_new_child(struct gmap *parent, gfn_t limit);
 void gmap_remove_child(struct gmap *child);
 void gmap_dispose(struct gmap *gmap);
-int gmap_link(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, struct guest_fault *fault);
+int gmap_link(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, struct guest_fault *fault,
+	      struct kvm_memory_slot *slot);
 void gmap_sync_dirty_log(struct gmap *gmap, gfn_t start, gfn_t end);
 int gmap_set_limit(struct gmap *gmap, gfn_t limit);
 int gmap_ucas_translate(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, gpa_t *gaddr);
Signature · 1 line
2.53.0
Reviewed-by on v3 2/6
#5 lore raw

Re: [PATCH v3 2/6] KVM: s390: Add alignment checks for hugepages

Quoted 10 lines · Claudio Imbrenda

When backing a guest page with a large page, check that the alignment of the guest page matches the alignment of the host physical page backing it within the large page.

Also check that the memslot is large enough to fit the large page.

Those checks are currently not needed, because memslots are guaranteed to be 1m-aligned, but this will change.

Reviewed-by on v3 2/6
#6 lore raw

Re: [PATCH v3 2/6] KVM: s390: Add alignment checks for hugepages

In reply to Claudio Imbrenda
Quoted 10 lines · Claudio Imbrenda

When backing a guest page with a large page, check that the alignment of the guest page matches the alignment of the host physical page backing it within the large page.

Also check that the memslot is large enough to fit the large page.

Those checks are currently not needed, because memslots are guaranteed to be 1m-aligned, but this will change.

Quoted 5 lines
---
 arch/s390/kvm/faultin.c |  2 +-
 arch/s390/kvm/gmap.c    | 32 ++++++++++++++++++++++++++------
 arch/s390/kvm/gmap.h    |  3 ++-
 3 files changed, 29 insertions(+), 8 deletions(-)
author maintainer
#7 lore raw

PATCH v3 3/6 KVM: s390: Allow 4k granularity for memslots

In reply to Claudio Imbrenda

Until now memslots on s390 needed to have 1M granularity and be 1M aligned. Since the new gmap code can handle memslots with 4k granularity and alignment, remove the restrictions.

---
 arch/s390/kvm/kvm-s390.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
arch/s390/kvm/kvm-s390.c +6 -14
index bc7d6fa66eaf..be2a721e2574 100644
@@ -5636,8 +5636,6 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
 				   struct kvm_memory_slot *new,
 				   enum kvm_mr_change change)
 {
-	gpa_t size;
-
 	if (kvm_is_ucontrol(kvm) && new->id < KVM_USER_MEM_SLOTS)
 		return -EINVAL;
 
@@ -5647,20 +5645,14 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
 
 	if (change != KVM_MR_DELETE && change != KVM_MR_FLAGS_ONLY) {
 		/*
-		 * A few sanity checks. We can have memory slots which have to be
-		 * located/ended at a segment boundary (1MB). The memory in userland is
-		 * ok to be fragmented into various different vmas. It is okay to mmap()
-		 * and munmap() stuff in this slot after doing this call at any time
+		 * A few sanity checks. The memory in userland is ok to be
+		 * fragmented into various different vmas. It is okay to mmap()
+		 * and munmap() stuff in this slot after doing this call at any
+		 * time.
 		 */
-
-		if (new->userspace_addr & 0xffffful)
+		if (new->userspace_addr & ~PAGE_MASK)
 			return -EINVAL;
-
-		size = new->npages * PAGE_SIZE;
-		if (size & 0xffffful)
-			return -EINVAL;
-
-		if ((new->base_gfn * PAGE_SIZE) + size > kvm->arch.mem_limit)
+		if ((new->base_gfn + new->npages) * PAGE_SIZE > kvm->arch.mem_limit)
 			return -EINVAL;
 	}
 
Signature · 1 line
2.53.0
Reviewed-by on v3 3/6
#9 lore raw

Re: [PATCH v3 3/6] KVM: s390: Allow 4k granularity for memslots

In reply to Claudio Imbrenda
Quoted 6 lines · Claudio Imbrenda

Until now memslots on s390 needed to have 1M granularity and be 1M aligned. Since the new gmap code can handle memslots with 4k granularity and alignment, remove the restrictions.

Quoted 3 lines
---
 arch/s390/kvm/kvm-s390.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
author maintainer
#10 lore raw

PATCH v3 4/6 KVM: selftests: Remove 1M alignment requirement for s390

In reply to Claudio Imbrenda

Remove the 1M memslot alignment requirement for s390, since it is not needed anymore.

---
 tools/testing/selftests/kvm/dirty_log_test.c         | 3 ---
 tools/testing/selftests/kvm/include/kvm_util.h       | 4 ----
 tools/testing/selftests/kvm/kvm_page_table_test.c    | 3 ---
 tools/testing/selftests/kvm/lib/kvm_util.c           | 9 +--------
 tools/testing/selftests/kvm/lib/memstress.c          | 4 ----
 tools/testing/selftests/kvm/pre_fault_memory_test.c  | 4 ----
 tools/testing/selftests/kvm/set_memory_region_test.c | 9 +--------
 7 files changed, 2 insertions(+), 34 deletions(-)
tools/testing/selftests/kvm/dirty_log_test.c +0 -3
index d58a641b0e6a..7627b328f18a 100644
@@ -641,9 +641,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	}
 
 #ifdef __s390x__
-	/* Align to 1M (segment size) */
-	guest_test_phys_mem = align_down(guest_test_phys_mem, 1 << 20);
-
 	/*
 	 * The workaround in guest_code() to write all pages prior to the first
 	 * iteration isn't compatible with the dirty ring, as the dirty ring
tools/testing/selftests/kvm/include/kvm_util.h +0 -4
index 8b39cb919f4f..f861242b4ae8 100644
@@ -1127,10 +1127,6 @@ vm_adjust_num_guest_pages(enum vm_guest_mode mode, unsigned int num_guest_pages)
 {
 	unsigned int n;
 	n = vm_num_guest_pages(mode, vm_num_host_pages(mode, num_guest_pages));
-#ifdef __s390x__
-	/* s390 requires 1M aligned guest sizes */
-	n = (n + 255) & ~255;
-#endif
 	return n;
 }
 
tools/testing/selftests/kvm/kvm_page_table_test.c +0 -3
index dd8b12f626d3..c60a24a92829 100644
@@ -261,9 +261,6 @@ static struct kvm_vm *pre_init_before_test(enum vm_guest_mode mode, void *arg)
 				       guest_page_size;
 	else
 		guest_test_phys_mem = p->phys_offset;
-#ifdef __s390x__
-	alignment = max(0x100000UL, alignment);
-#endif
 	guest_test_phys_mem = align_down(guest_test_phys_mem, alignment);
 
 	/* Set up the shared data structure test_args */
tools/testing/selftests/kvm/lib/kvm_util.c +1 -8
index 1959bf556e88..f5e076591c64 100644
@@ -985,7 +985,7 @@ void vm_mem_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type,
 	struct userspace_mem_region *region;
 	size_t backing_src_pagesz = get_backing_src_pagesz(src_type);
 	size_t mem_size = npages * vm->page_size;
-	size_t alignment;
+	size_t alignment = 1;
 
 	TEST_REQUIRE_SET_USER_MEMORY_REGION2();
 
@@ -1039,13 +1039,6 @@ void vm_mem_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type,
 	TEST_ASSERT(region != NULL, "Insufficient Memory");
 	region->mmap_size = mem_size;
 
-#ifdef __s390x__
-	/* On s390x, the host address must be aligned to 1M (due to PGSTEs) */
-	alignment = 0x100000;
-#else
-	alignment = 1;
-#endif
-
 	/*
 	 * When using THP mmap is not guaranteed to returned a hugepage aligned
 	 * address so we have to pad the mmap. Padding is not needed for HugeTLB
tools/testing/selftests/kvm/lib/memstress.c +0 -4
index 557c0a0a5658..1ea735d66e15 100644
@@ -196,10 +196,6 @@ struct kvm_vm *memstress_create_vm(enum vm_guest_mode mode, int nr_vcpus,
 
 	args->gpa = (region_end_gfn - guest_num_pages - 1) * args->guest_page_size;
 	args->gpa = align_down(args->gpa, backing_src_pagesz);
-#ifdef __s390x__
-	/* Align to 1M (segment size) */
-	args->gpa = align_down(args->gpa, 1 << 20);
-#endif
 	args->size = guest_num_pages * args->guest_page_size;
 	pr_info("guest physical test memory: [0x%lx, 0x%lx)\n",
 		args->gpa, args->gpa + args->size);
tools/testing/selftests/kvm/pre_fault_memory_test.c +0 -4
index 93e603d91311..f3de0386ba7b 100644
@@ -175,11 +175,7 @@ static void __test_pre_fault_memory(unsigned long vm_type, bool private)
 
 	alignment = guest_page_size = vm_guest_mode_params[VM_MODE_DEFAULT].page_size;
 	gpa = (vm->max_gfn - TEST_NPAGES) * guest_page_size;
-#ifdef __s390x__
-	alignment = max(0x100000UL, guest_page_size);
-#else
 	alignment = SZ_2M;
-#endif
 	gpa = align_down(gpa, alignment);
 	gva = gpa & ((1ULL << (vm->va_bits - 1)) - 1);
 
tools/testing/selftests/kvm/set_memory_region_test.c +1 -8
index 7fe427ff9b38..a398dc3a8c4b 100644
@@ -413,14 +413,7 @@ static void test_add_max_memory_regions(void)
 	uint32_t max_mem_slots;
 	uint32_t slot;
 	void *mem, *mem_aligned, *mem_extra;
-	size_t alignment;
-
-#ifdef __s390x__
-	/* On s390x, the host address must be aligned to 1M (due to PGSTEs) */
-	alignment = 0x100000;
-#else
-	alignment = 1;
-#endif
+	size_t alignment = 1;
 
 	max_mem_slots = kvm_check_cap(KVM_CAP_NR_MEMSLOTS);
 	TEST_ASSERT(max_mem_slots > 0,
Signature · 1 line
2.53.0
Reviewed-by on v3 4/6
#12 lore raw

Re: [PATCH v3 4/6] KVM: selftests: Remove 1M alignment requirement for s390

In reply to Claudio Imbrenda
Quoted 4 lines · Claudio Imbrenda

Remove the 1M memslot alignment requirement for s390, since it is not needed anymore.

Quoted 10 lines
---
 tools/testing/selftests/kvm/dirty_log_test.c         | 3 ---
 tools/testing/selftests/kvm/include/kvm_util.h       | 4 ----
 tools/testing/selftests/kvm/kvm_page_table_test.c    | 3 ---
 tools/testing/selftests/kvm/lib/kvm_util.c           | 9 +--------
 tools/testing/selftests/kvm/lib/memstress.c          | 4 ----
 tools/testing/selftests/kvm/pre_fault_memory_test.c  | 4 ----
 tools/testing/selftests/kvm/set_memory_region_test.c | 9 +--------
 7 files changed, 2 insertions(+), 34 deletions(-)
author maintainer
#13 lore raw

PATCH v3 5/6 KVM: s390: selftests: enable some common memory-related tests

In reply to Claudio Imbrenda

Enable the following tests on s390:
* memslot_modification_stress_test
* memslot_perf_test
* mmu_stress_test

Since the first two tests are now supported on all architectures, move them into TEST_GEN_PROGS_COMMON and out of the indiviual architectures.

---
 tools/testing/selftests/kvm/Makefile.kvm | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tools/testing/selftests/kvm/Makefile.kvm +3 -6
index fdec90e85467..057f17d6b896 100644
@@ -64,6 +64,8 @@ TEST_GEN_PROGS_COMMON += kvm_binary_stats_test
 TEST_GEN_PROGS_COMMON += kvm_create_max_vcpus
 TEST_GEN_PROGS_COMMON += kvm_page_table_test
 TEST_GEN_PROGS_COMMON += set_memory_region_test
+TEST_GEN_PROGS_COMMON += memslot_modification_stress_test
+TEST_GEN_PROGS_COMMON += memslot_perf_test
 
 # Compiled test targets
 TEST_GEN_PROGS_x86 = $(TEST_GEN_PROGS_COMMON)
@@ -147,8 +149,6 @@ TEST_GEN_PROGS_x86 += coalesced_io_test
 TEST_GEN_PROGS_x86 += dirty_log_perf_test
 TEST_GEN_PROGS_x86 += guest_memfd_test
 TEST_GEN_PROGS_x86 += hardware_disable_test
-TEST_GEN_PROGS_x86 += memslot_modification_stress_test
-TEST_GEN_PROGS_x86 += memslot_perf_test
 TEST_GEN_PROGS_x86 += mmu_stress_test
 TEST_GEN_PROGS_x86 += rseq_test
 TEST_GEN_PROGS_x86 += steal_time
@@ -186,8 +186,6 @@ TEST_GEN_PROGS_arm64 += coalesced_io_test
 TEST_GEN_PROGS_arm64 += dirty_log_perf_test
 TEST_GEN_PROGS_arm64 += get-reg-list
 TEST_GEN_PROGS_arm64 += guest_memfd_test
-TEST_GEN_PROGS_arm64 += memslot_modification_stress_test
-TEST_GEN_PROGS_arm64 += memslot_perf_test
 TEST_GEN_PROGS_arm64 += mmu_stress_test
 TEST_GEN_PROGS_arm64 += rseq_test
 TEST_GEN_PROGS_arm64 += steal_time
@@ -205,6 +203,7 @@ TEST_GEN_PROGS_s390 += s390/ucontrol_test
 TEST_GEN_PROGS_s390 += s390/user_operexec
 TEST_GEN_PROGS_s390 += s390/keyop
 TEST_GEN_PROGS_s390 += rseq_test
+TEST_GEN_PROGS_s390 += mmu_stress_test
 
 TEST_GEN_PROGS_riscv = $(TEST_GEN_PROGS_COMMON)
 TEST_GEN_PROGS_riscv += riscv/sbi_pmu_test
@@ -214,8 +213,6 @@ TEST_GEN_PROGS_riscv += arch_timer
 TEST_GEN_PROGS_riscv += coalesced_io_test
 TEST_GEN_PROGS_riscv += dirty_log_perf_test
 TEST_GEN_PROGS_riscv += get-reg-list
-TEST_GEN_PROGS_riscv += memslot_modification_stress_test
-TEST_GEN_PROGS_riscv += memslot_perf_test
 TEST_GEN_PROGS_riscv += mmu_stress_test
 TEST_GEN_PROGS_riscv += rseq_test
 TEST_GEN_PROGS_riscv += steal_time
Signature · 1 line
2.53.0
#14 lore raw

Re: [PATCH v3 5/6] KVM: s390: selftests: enable some common memory-related tests

Quoted 54 lines · Claudio Imbrenda

Enable the following tests on s390:
* memslot_modification_stress_test
* memslot_perf_test
* mmu_stress_test

Since the first two tests are now supported on all architectures, move them into TEST_GEN_PROGS_COMMON and out of the indiviual architectures.

---
 tools/testing/selftests/kvm/Makefile.kvm | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tools/testing/selftests/kvm/Makefile.kvm +3 -4
index fdec90e85467..057f17d6b896 100644
@@ -64,6 +64,8 @@ TEST_GEN_PROGS_COMMON += kvm_binary_stats_test
 TEST_GEN_PROGS_COMMON += kvm_create_max_vcpus
 TEST_GEN_PROGS_COMMON += kvm_page_table_test
 TEST_GEN_PROGS_COMMON += set_memory_region_test
+TEST_GEN_PROGS_COMMON += memslot_modification_stress_test
+TEST_GEN_PROGS_COMMON += memslot_perf_test
 
 # Compiled test targets
 TEST_GEN_PROGS_x86 = $(TEST_GEN_PROGS_COMMON)
@@ -147,8 +149,6 @@ TEST_GEN_PROGS_x86 += coalesced_io_test
 TEST_GEN_PROGS_x86 += dirty_log_perf_test
 TEST_GEN_PROGS_x86 += guest_memfd_test
 TEST_GEN_PROGS_x86 += hardware_disable_test
-TEST_GEN_PROGS_x86 += memslot_modification_stress_test
-TEST_GEN_PROGS_x86 += memslot_perf_test
 TEST_GEN_PROGS_x86 += mmu_stress_test
 TEST_GEN_PROGS_x86 += rseq_test
 TEST_GEN_PROGS_x86 += steal_time
@@ -186,8 +186,6 @@ TEST_GEN_PROGS_arm64 += coalesced_io_test
 TEST_GEN_PROGS_arm64 += dirty_log_memslot_perf_testperf_test
 TEST_GEN_PROGS_arm64 += get-reg-list
 TEST_GEN_PROGS_arm64 += guest_memfd_test
-TEST_GEN_PROGS_arm64 += memslot_modification_stress_test
-TEST_GEN_PROGS_arm64 += memslot_perf_test
 TEST_GEN_PROGS_arm64 += mmu_stress_test
 TEST_GEN_PROGS_arm64 += rseq_test
 TEST_GEN_PROGS_arm64 += steal_time
@@ -205,6 +203,7 @@ TEST_GEN_PROGS_s390 += s390/ucontrol_test
 TEST_GEN_PROGS_s390 += s390/user_operexec
 TEST_GEN_PROGS_s390 += s390/keyop
 TEST_GEN_PROGS_s390 += rseq_test
+TEST_GEN_PROGS_s390 += mmu_stress_test
 
 TEST_GEN_PROGS_riscv = $(TEST_GEN_PROGS_COMMON)
 TEST_GEN_PROGS_riscv += riscv/sbi_pmu_test

tools/testing/selftests/kvm/Makefile.kvm TEST_GEN_PROGS_riscv += arch_timer · line 218

Quoted 8 lines
tools/testing/selftests/kvm/Makefile.kvm +0 -2
@@ -214,8 +213,6 @@ TEST_GEN_PROGS_riscv += arch_timer
 TEST_GEN_PROGS_riscv += coalesced_io_test
 TEST_GEN_PROGS_riscv += dirty_log_perf_test
 TEST_GEN_PROGS_riscv += get-reg-list
-TEST_GEN_PROGS_riscv += memslot_modification_stress_test
-TEST_GEN_PROGS_riscv += memslot_perf_test
 TEST_GEN_PROGS_riscv += mmu_stress_test
 TEST_GEN_PROGS_riscv += rseq_test
 TEST_GEN_PROGS_riscv += steal_time

I think you missed removing the loongarch targets.

Steffen

author maintainer
#15 lore raw

Re: [PATCH v3 5/6] KVM: s390: selftests: enable some common memory-related tests

Quoted 24 lines · On Tue, 7 Apr 2026 14:47:52 +0200 Steffen Eiden <[email protected]> wrote:
Quoted 23 lines · Claudio Imbrenda

Enable the following tests on s390:
* memslot_modification_stress_test
* memslot_perf_test
* mmu_stress_test

Since the first two tests are now supported on all architectures, move them into TEST_GEN_PROGS_COMMON and out of the indiviual architectures.

---
 tools/testing/selftests/kvm/Makefile.kvm | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tools/testing/selftests/kvm/Makefile.kvm +2 -0
index fdec90e85467..057f17d6b896 100644
@@ -64,6 +64,8 @@ TEST_GEN_PROGS_COMMON += kvm_binary_stats_test
 TEST_GEN_PROGS_COMMON += kvm_create_max_vcpus
 TEST_GEN_PROGS_COMMON += kvm_page_table_test
 TEST_GEN_PROGS_COMMON += set_memory_region_test
+TEST_GEN_PROGS_COMMON += memslot_modification_stress_test
+TEST_GEN_PROGS_COMMON += memslot_perf_test

[...]

Quoted 6 lines
Quoted 6 lines

TEST_GEN_PROGS_riscv = $(TEST_GEN_PROGS_COMMON)
TEST_GEN_PROGS_riscv += riscv/sbi_pmu_test

tools/testing/selftests/kvm/Makefile.kvm +0 -0
@@ -214,8 +213,6 @@ TEST_GEN_PROGS_riscv += arch_timer
 TEST_GEN_PROGS_riscv += coalesced_io_test
 TEST_GEN_PROGS_riscv += dirty_log_perf_test
 TEST_GEN_PROGS_riscv += get-reg-list
Quoted 8 lines

tools/testing/selftests/kvm/Makefile.kvm TEST_GEN_PROGS_riscv += arch_timer · line 218

Quoted 6 lines
tools/testing/selftests/kvm/Makefile.kvm +0 -2
-TEST_GEN_PROGS_riscv += memslot_modification_stress_test
-TEST_GEN_PROGS_riscv += memslot_perf_test
 TEST_GEN_PROGS_riscv += mmu_stress_test
 TEST_GEN_PROGS_riscv += rseq_test
 TEST_GEN_PROGS_riscv += steal_time

I think you missed removing the loongarch targets.

no, loongarch does *not* include TEST_GEN_PROGS_COMMON, so if I remove them, they're gone

Quoted 2 lines

Steffen

#16 lore raw

Re: [PATCH v3 5/6] KVM: s390: selftests: enable some common memory-related tests

Quoted 45 lines · Claudio Imbrenda
Quoted 24 lines · On Tue, 7 Apr 2026 14:47:52 +0200 Steffen Eiden <[email protected]> wrote:
Quoted 23 lines · Claudio Imbrenda

Enable the following tests on s390:
* memslot_modification_stress_test
* memslot_perf_test
* mmu_stress_test

Since the first two tests are now supported on all architectures, move them into TEST_GEN_PROGS_COMMON and out of the indiviual architectures.

---
 tools/testing/selftests/kvm/Makefile.kvm | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tools/testing/selftests/kvm/Makefile.kvm +2 -0
index fdec90e85467..057f17d6b896 100644
@@ -64,6 +64,8 @@ TEST_GEN_PROGS_COMMON += kvm_binary_stats_test
 TEST_GEN_PROGS_COMMON += kvm_create_max_vcpus
 TEST_GEN_PROGS_COMMON += kvm_page_table_test
 TEST_GEN_PROGS_COMMON += set_memory_region_test
+TEST_GEN_PROGS_COMMON += memslot_modification_stress_test
+TEST_GEN_PROGS_COMMON += memslot_perf_test

[...]

Quoted 6 lines
Quoted 6 lines

TEST_GEN_PROGS_riscv = $(TEST_GEN_PROGS_COMMON)
TEST_GEN_PROGS_riscv += riscv/sbi_pmu_test

tools/testing/selftests/kvm/Makefile.kvm +0 -0
@@ -214,8 +213,6 @@ TEST_GEN_PROGS_riscv += arch_timer
 TEST_GEN_PROGS_riscv += coalesced_io_test
 TEST_GEN_PROGS_riscv += dirty_log_perf_test
 TEST_GEN_PROGS_riscv += get-reg-list
Quoted 8 lines

tools/testing/selftests/kvm/Makefile.kvm TEST_GEN_PROGS_riscv += arch_timer · line 218

Quoted 6 lines
tools/testing/selftests/kvm/Makefile.kvm +0 -2
-TEST_GEN_PROGS_riscv += memslot_modification_stress_test
-TEST_GEN_PROGS_riscv += memslot_perf_test
 TEST_GEN_PROGS_riscv += mmu_stress_test
 TEST_GEN_PROGS_riscv += rseq_test
 TEST_GEN_PROGS_riscv += steal_time

I think you missed removing the loongarch targets.

Quoted 2 lines

no, loongarch does *not* include TEST_GEN_PROGS_COMMON, so if I remove them, they're gone

Ok, my bad. I just did a quick grep for the test names to look for missing removals. I missed that little detail.

Quoted 4 lines
Quoted 3 lines

Steffen

Reviewed-by on v3 5/6
#17 lore raw

Re: [PATCH v3 5/6] KVM: s390: selftests: enable some common memory-related tests

In reply to Claudio Imbrenda
Quoted 9 lines · Claudio Imbrenda

Enable the following tests on s390:
* memslot_modification_stress_test
* memslot_perf_test
* mmu_stress_test

Since the first two tests are now supported on all architectures, move them into TEST_GEN_PROGS_COMMON and out of the indiviual architectures.

author maintainer
#18 lore raw

Re: [PATCH v3 5/6] KVM: s390: selftests: enable some common memory-related tests

In reply to Claudio Imbrenda

Just realized I had forgotten to CC Paolo and Shuah, since this patch touches common code.

the changes are rather trivial, but they should probably also have a look :)

(as I already replied to another comment: loongarch does not include TEST_GEN_PROGS_COMMON so it should not be touched)

Quoted 61 lines · On Thu, 2 Apr 2026 17:01:34 +0200 Claudio Imbrenda <[email protected]>…

Enable the following tests on s390:
* memslot_modification_stress_test
* memslot_perf_test
* mmu_stress_test

Since the first two tests are now supported on all architectures, move them into TEST_GEN_PROGS_COMMON and out of the indiviual architectures.

---
 tools/testing/selftests/kvm/Makefile.kvm | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tools/testing/selftests/kvm/Makefile.kvm +3 -6
index fdec90e85467..057f17d6b896 100644
@@ -64,6 +64,8 @@ TEST_GEN_PROGS_COMMON += kvm_binary_stats_test
 TEST_GEN_PROGS_COMMON += kvm_create_max_vcpus
 TEST_GEN_PROGS_COMMON += kvm_page_table_test
 TEST_GEN_PROGS_COMMON += set_memory_region_test
+TEST_GEN_PROGS_COMMON += memslot_modification_stress_test
+TEST_GEN_PROGS_COMMON += memslot_perf_test
 
 # Compiled test targets
 TEST_GEN_PROGS_x86 = $(TEST_GEN_PROGS_COMMON)
@@ -147,8 +149,6 @@ TEST_GEN_PROGS_x86 += coalesced_io_test
 TEST_GEN_PROGS_x86 += dirty_log_perf_test
 TEST_GEN_PROGS_x86 += guest_memfd_test
 TEST_GEN_PROGS_x86 += hardware_disable_test
-TEST_GEN_PROGS_x86 += memslot_modification_stress_test
-TEST_GEN_PROGS_x86 += memslot_perf_test
 TEST_GEN_PROGS_x86 += mmu_stress_test
 TEST_GEN_PROGS_x86 += rseq_test
 TEST_GEN_PROGS_x86 += steal_time
@@ -186,8 +186,6 @@ TEST_GEN_PROGS_arm64 += coalesced_io_test
 TEST_GEN_PROGS_arm64 += dirty_log_perf_test
 TEST_GEN_PROGS_arm64 += get-reg-list
 TEST_GEN_PROGS_arm64 += guest_memfd_test
-TEST_GEN_PROGS_arm64 += memslot_modification_stress_test
-TEST_GEN_PROGS_arm64 += memslot_perf_test
 TEST_GEN_PROGS_arm64 += mmu_stress_test
 TEST_GEN_PROGS_arm64 += rseq_test
 TEST_GEN_PROGS_arm64 += steal_time
@@ -205,6 +203,7 @@ TEST_GEN_PROGS_s390 += s390/ucontrol_test
 TEST_GEN_PROGS_s390 += s390/user_operexec
 TEST_GEN_PROGS_s390 += s390/keyop
 TEST_GEN_PROGS_s390 += rseq_test
+TEST_GEN_PROGS_s390 += mmu_stress_test
 
 TEST_GEN_PROGS_riscv = $(TEST_GEN_PROGS_COMMON)
 TEST_GEN_PROGS_riscv += riscv/sbi_pmu_test
@@ -214,8 +213,6 @@ TEST_GEN_PROGS_riscv += arch_timer
 TEST_GEN_PROGS_riscv += coalesced_io_test
 TEST_GEN_PROGS_riscv += dirty_log_perf_test
 TEST_GEN_PROGS_riscv += get-reg-list
-TEST_GEN_PROGS_riscv += memslot_modification_stress_test
-TEST_GEN_PROGS_riscv += memslot_perf_test
 TEST_GEN_PROGS_riscv += mmu_stress_test
 TEST_GEN_PROGS_riscv += rseq_test
 TEST_GEN_PROGS_riscv += steal_time
Reviewed-by on v3 5/6
#19 lore raw

Re: [PATCH v3 5/6] KVM: s390: selftests: enable some common memory-related tests

In reply to Claudio Imbrenda
Quoted 9 lines · Claudio Imbrenda

Enable the following tests on s390:
* memslot_modification_stress_test
* memslot_perf_test
* mmu_stress_test

Since the first two tests are now supported on all architectures, move them into TEST_GEN_PROGS_COMMON and out of the indiviual architectures.

Quoted 3 lines
---
 tools/testing/selftests/kvm/Makefile.kvm | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
author maintainer
#20 lore raw

PATCH v3 6/6 KVM: s390: ucontrol: Fix memslot handling

In reply to Claudio Imbrenda

Fix memslots handling for UCONTROL guests. Attempts to delete user memslots will fail, as they should, without the risk of a NULL pointer dereference.

---
 arch/s390/kvm/kvm-s390.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/kvm-s390.c +1 -1
index be2a721e2574..435c3a1b74f8 100644
@@ -5636,7 +5636,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
 				   struct kvm_memory_slot *new,
 				   enum kvm_mr_change change)
 {
-	if (kvm_is_ucontrol(kvm) && new->id < KVM_USER_MEM_SLOTS)
+	if (kvm_is_ucontrol(kvm) && new && new->id < KVM_USER_MEM_SLOTS)
 		return -EINVAL;
 
 	/* When we are protected, we should not change the memory slots */
Signature · 1 line
2.53.0
Reviewed-by on v3 6/6
#21 lore raw

Re: [PATCH v3 6/6] KVM: s390: ucontrol: Fix memslot handling

Quoted 4 lines · Claudio Imbrenda

Fix memslots handling for UCONTROL guests. Attempts to delete user memslots will fail, as they should, without the risk of a NULL pointer dereference.

You may want to spend a fixes tag:

Fixes 413c98f24c63 ("KVM: s390: fake memslot for ucontrol VMs")
Quoted 1 line

Steffen

author maintainer
#22 lore raw

Re: [PATCH v3 6/6] KVM: s390: ucontrol: Fix memslot handling

Quoted 9 lines · On Tue, 7 Apr 2026 14:55:35 +0200 Steffen Eiden <[email protected]> wrote:
Quoted 4 lines · Claudio Imbrenda

Fix memslots handling for UCONTROL guests. Attempts to delete user memslots will fail, as they should, without the risk of a NULL pointer dereference.

You may want to spend a fixes tag:

Fixes 413c98f24c63 ("KVM: s390: fake memslot for ucontrol VMs")

indeed, I will fix it when picking, thanks

Quoted 6 lines
Quoted 2 lines

Steffen

Reviewed-by on v3 6/6
#23 lore raw

Re: [PATCH v3 6/6] KVM: s390: ucontrol: Fix memslot handling

In reply to Claudio Imbrenda
Quoted 5 lines · Claudio Imbrenda

Fix memslots handling for UCONTROL guests. Attempts to delete user memslots will fail, as they should, without the risk of a NULL pointer dereference.

With the added Fixes tag:

Quoted 3 lines
---
 arch/s390/kvm/kvm-s390.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)