Skip to content

Commit a694067

Browse files
David Hildenbrandborntraeger
authored andcommitted
KVM: s390: allow 255 VCPUs when sca entries aren't used
If the SCA entries aren't used by the hardware (no SIGPIF), we can simply not set the entries, stick to the basic sca and allow more than 64 VCPUs. To hinder any other facility from using these entries, let's properly provoke intercepts by not setting the MCN and keeping the entries unset. This effectively allows when running KVM under KVM (vSIE) or under z/VM to provide more than 64 VCPUs to a guest. Let's limit it to 255 for now, to not run into problems if the CPU numbers are limited somewhere else. Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
1 parent 80cd876 commit a694067

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

arch/s390/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#define KVM_S390_BSCA_CPU_SLOTS 64
3030
#define KVM_S390_ESCA_CPU_SLOTS 248
31-
#define KVM_MAX_VCPUS KVM_S390_ESCA_CPU_SLOTS
31+
#define KVM_MAX_VCPUS 255
3232
#define KVM_USER_MEM_SLOTS 32
3333

3434
/*

arch/s390/kvm/interrupt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static int sca_ext_call_pending(struct kvm_vcpu *vcpu, int *src_id)
4242
if (!(atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_ECALL_PEND))
4343
return 0;
4444

45+
BUG_ON(!kvm_s390_use_sca_entries());
4546
read_lock(&vcpu->kvm->arch.sca_lock);
4647
if (vcpu->kvm->arch.use_esca) {
4748
struct esca_block *sca = vcpu->kvm->arch.sca;
@@ -70,6 +71,7 @@ static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id)
7071
{
7172
int expect, rc;
7273

74+
BUG_ON(!kvm_s390_use_sca_entries());
7375
read_lock(&vcpu->kvm->arch.sca_lock);
7476
if (vcpu->kvm->arch.use_esca) {
7577
struct esca_block *sca = vcpu->kvm->arch.sca;
@@ -111,6 +113,8 @@ static void sca_clear_ext_call(struct kvm_vcpu *vcpu)
111113
struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
112114
int rc, expect;
113115

116+
if (!kvm_s390_use_sca_entries())
117+
return;
114118
atomic_andnot(CPUSTAT_ECALL_PEND, li->cpuflags);
115119
read_lock(&vcpu->kvm->arch.sca_lock);
116120
if (vcpu->kvm->arch.use_esca) {

arch/s390/kvm/kvm-s390.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
376376
case KVM_CAP_NR_VCPUS:
377377
case KVM_CAP_MAX_VCPUS:
378378
r = KVM_S390_BSCA_CPU_SLOTS;
379-
if (sclp.has_esca && sclp.has_64bscao)
379+
if (!kvm_s390_use_sca_entries())
380+
r = KVM_MAX_VCPUS;
381+
else if (sclp.has_esca && sclp.has_64bscao)
380382
r = KVM_S390_ESCA_CPU_SLOTS;
381383
break;
382384
case KVM_CAP_NR_MEMSLOTS:
@@ -1553,6 +1555,8 @@ static int __kvm_ucontrol_vcpu_init(struct kvm_vcpu *vcpu)
15531555

15541556
static void sca_del_vcpu(struct kvm_vcpu *vcpu)
15551557
{
1558+
if (!kvm_s390_use_sca_entries())
1559+
return;
15561560
read_lock(&vcpu->kvm->arch.sca_lock);
15571561
if (vcpu->kvm->arch.use_esca) {
15581562
struct esca_block *sca = vcpu->kvm->arch.sca;
@@ -1570,6 +1574,13 @@ static void sca_del_vcpu(struct kvm_vcpu *vcpu)
15701574

15711575
static void sca_add_vcpu(struct kvm_vcpu *vcpu)
15721576
{
1577+
if (!kvm_s390_use_sca_entries()) {
1578+
struct bsca_block *sca = vcpu->kvm->arch.sca;
1579+
1580+
/* we still need the basic sca for the ipte control */
1581+
vcpu->arch.sie_block->scaoh = (__u32)(((__u64)sca) >> 32);
1582+
vcpu->arch.sie_block->scaol = (__u32)(__u64)sca;
1583+
}
15731584
read_lock(&vcpu->kvm->arch.sca_lock);
15741585
if (vcpu->kvm->arch.use_esca) {
15751586
struct esca_block *sca = vcpu->kvm->arch.sca;
@@ -1650,6 +1661,11 @@ static int sca_can_add_vcpu(struct kvm *kvm, unsigned int id)
16501661
{
16511662
int rc;
16521663

1664+
if (!kvm_s390_use_sca_entries()) {
1665+
if (id < KVM_MAX_VCPUS)
1666+
return true;
1667+
return false;
1668+
}
16531669
if (id < KVM_S390_BSCA_CPU_SLOTS)
16541670
return true;
16551671
if (!sclp.has_esca || !sclp.has_64bscao)

arch/s390/kvm/kvm-s390.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/kvm_host.h>
2121
#include <asm/facility.h>
2222
#include <asm/processor.h>
23+
#include <asm/sclp.h>
2324

2425
typedef int (*intercept_handler_t)(struct kvm_vcpu *vcpu);
2526

@@ -387,4 +388,13 @@ static inline union ipte_control *kvm_s390_get_ipte_control(struct kvm *kvm)
387388

388389
return &sca->ipte_control;
389390
}
391+
static inline int kvm_s390_use_sca_entries(void)
392+
{
393+
/*
394+
* Without SIGP interpretation, only SRS interpretation (if available)
395+
* might use the entries. By not setting the entries and keeping them
396+
* invalid, hardware will not access them but intercept.
397+
*/
398+
return sclp.has_sigpif;
399+
}
390400
#endif

0 commit comments

Comments
 (0)