Skip to content

Commit 413c98f

Browse files
author
Claudio Imbrenda
committed
KVM: s390: fake memslot for ucontrol VMs
Create a fake memslot for ucontrol VMs. The fake memslot identity-maps userspace. Now memslots will always be present, and ucontrol is not a special case anymore. Suggested-by: Sean Christopherson <seanjc@google.com> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Janosch Frank <frankja@linux.ibm.com> Link: https://lore.kernel.org/r/20250123144627.312456-4-imbrenda@linux.ibm.com Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20250123144627.312456-4-imbrenda@linux.ibm.com>
1 parent decff09 commit 413c98f

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ fetch) is injected in the guest.
14191419
S390:
14201420
^^^^^
14211421

1422-
Returns -EINVAL if the VM has the KVM_VM_S390_UCONTROL flag set.
1422+
Returns -EINVAL or -EEXIST if the VM has the KVM_VM_S390_UCONTROL flag set.
14231423
Returns -EINVAL if called on a protected VM.
14241424

14251425
4.36 KVM_SET_TSS_ADDR

arch/s390/include/asm/kvm_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#define KVM_S390_ESCA_CPU_SLOTS 248
3131
#define KVM_MAX_VCPUS 255
3232

33+
#define KVM_INTERNAL_MEM_SLOTS 1
34+
3335
/*
3436
* These seem to be used for allocating ->chip in the routing table, which we
3537
* don't use. 1 is as small as we can get to reduce the needed memory. If we

arch/s390/kvm/kvm-s390.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3428,8 +3428,20 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
34283428
VM_EVENT(kvm, 3, "vm created with type %lu", type);
34293429

34303430
if (type & KVM_VM_S390_UCONTROL) {
3431+
struct kvm_userspace_memory_region2 fake_memslot = {
3432+
.slot = KVM_S390_UCONTROL_MEMSLOT,
3433+
.guest_phys_addr = 0,
3434+
.userspace_addr = 0,
3435+
.memory_size = ALIGN_DOWN(TASK_SIZE, _SEGMENT_SIZE),
3436+
.flags = 0,
3437+
};
3438+
34313439
kvm->arch.gmap = NULL;
34323440
kvm->arch.mem_limit = KVM_S390_NO_MEM_LIMIT;
3441+
/* one flat fake memslot covering the whole address-space */
3442+
mutex_lock(&kvm->slots_lock);
3443+
KVM_BUG_ON(kvm_set_internal_memslot(kvm, &fake_memslot), kvm);
3444+
mutex_unlock(&kvm->slots_lock);
34333445
} else {
34343446
if (sclp.hamax == U64_MAX)
34353447
kvm->arch.mem_limit = TASK_SIZE_MAX;
@@ -5854,7 +5866,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
58545866
{
58555867
gpa_t size;
58565868

5857-
if (kvm_is_ucontrol(kvm))
5869+
if (kvm_is_ucontrol(kvm) && new->id < KVM_USER_MEM_SLOTS)
58585870
return -EINVAL;
58595871

58605872
/* When we are protected, we should not change the memory slots */
@@ -5906,6 +5918,9 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
59065918
{
59075919
int rc = 0;
59085920

5921+
if (kvm_is_ucontrol(kvm))
5922+
return;
5923+
59095924
switch (change) {
59105925
case KVM_MR_DELETE:
59115926
rc = gmap_unmap_segment(kvm->arch.gmap, old->base_gfn * PAGE_SIZE,

arch/s390/kvm/kvm-s390.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <asm/processor.h>
2121
#include <asm/sclp.h>
2222

23+
#define KVM_S390_UCONTROL_MEMSLOT (KVM_USER_MEM_SLOTS + 0)
24+
2325
static inline void kvm_s390_fpu_store(struct kvm_run *run)
2426
{
2527
fpu_stfpc(&run->s.regs.fpc);

0 commit comments

Comments
 (0)