Skip to content

Commit efe5ddc

Browse files
gkurzpaulusmack
authored andcommitted
KVM: PPC: Book3S HV: XIVE: Allow userspace to set the # of VPs
Add a new attribute to both XIVE and XICS-on-XIVE KVM devices so that userspace can tell how many interrupt servers it needs. If a VM needs less than the current default of KVM_MAX_VCPUS (2048), we can allocate less VPs in OPAL. Combined with a core stride (VSMT) that matches the number of guest threads per core, this may substantially increases the number of VMs that can run concurrently with an in-kernel XIVE device. Since the legacy XIVE KVM device is exposed to userspace through the XICS KVM API, a new attribute group is added to it for this purpose. While here, fix the syntax of the existing KVM_DEV_XICS_GRP_SOURCES in the XICS documentation. Signed-off-by: Greg Kurz <groug@kaod.org> Reviewed-by: Cédric Le Goater <clg@kaod.org> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
1 parent 062cfab commit efe5ddc

5 files changed

Lines changed: 36 additions & 2 deletions

File tree

‎Documentation/virt/kvm/devices/xics.txt‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@ XICS interrupt controller
33
Device type supported: KVM_DEV_TYPE_XICS
44

55
Groups:
6-
KVM_DEV_XICS_SOURCES
6+
1. KVM_DEV_XICS_GRP_SOURCES
77
Attributes: One per interrupt source, indexed by the source number.
88

9+
2. KVM_DEV_XICS_GRP_CTRL
10+
Attributes:
11+
2.1 KVM_DEV_XICS_NR_SERVERS (write only)
12+
The kvm_device_attr.addr points to a __u32 value which is the number of
13+
interrupt server numbers (ie, highest possible vcpu id plus one).
14+
Errors:
15+
-EINVAL: Value greater than KVM_MAX_VCPU_ID.
16+
-EFAULT: Invalid user pointer for attr->addr.
17+
-EBUSY: A vcpu is already connected to the device.
18+
919
This device emulates the XICS (eXternal Interrupt Controller
1020
Specification) defined in PAPR. The XICS has a set of interrupt
1121
sources, each identified by a 20-bit source number, and a set of
@@ -38,7 +48,7 @@ least-significant end of the word:
3848

3949
Each source has 64 bits of state that can be read and written using
4050
the KVM_GET_DEVICE_ATTR and KVM_SET_DEVICE_ATTR ioctls, specifying the
41-
KVM_DEV_XICS_SOURCES attribute group, with the attribute number being
51+
KVM_DEV_XICS_GRP_SOURCES attribute group, with the attribute number being
4252
the interrupt source number. The 64 bit state word has the following
4353
bitfields, starting from the least-significant end of the word:
4454

‎Documentation/virt/kvm/devices/xive.txt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ the legacy interrupt mode, referred as XICS (POWER7/8).
7878
migrating the VM.
7979
Errors: none
8080

81+
1.3 KVM_DEV_XIVE_NR_SERVERS (write only)
82+
The kvm_device_attr.addr points to a __u32 value which is the number of
83+
interrupt server numbers (ie, highest possible vcpu id plus one).
84+
Errors:
85+
-EINVAL: Value greater than KVM_MAX_VCPU_ID.
86+
-EFAULT: Invalid user pointer for attr->addr.
87+
-EBUSY: A vCPU is already connected to the device.
88+
8189
2. KVM_DEV_XIVE_GRP_SOURCE (write only)
8290
Initializes a new source in the XIVE device and mask it.
8391
Attributes:

‎arch/powerpc/include/uapi/asm/kvm.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,8 @@ struct kvm_ppc_cpu_char {
667667

668668
/* PPC64 eXternal Interrupt Controller Specification */
669669
#define KVM_DEV_XICS_GRP_SOURCES 1 /* 64-bit source attributes */
670+
#define KVM_DEV_XICS_GRP_CTRL 2
671+
#define KVM_DEV_XICS_NR_SERVERS 1
670672

671673
/* Layout of 64-bit source attribute values */
672674
#define KVM_XICS_DESTINATION_SHIFT 0
@@ -683,6 +685,7 @@ struct kvm_ppc_cpu_char {
683685
#define KVM_DEV_XIVE_GRP_CTRL 1
684686
#define KVM_DEV_XIVE_RESET 1
685687
#define KVM_DEV_XIVE_EQ_SYNC 2
688+
#define KVM_DEV_XIVE_NR_SERVERS 3
686689
#define KVM_DEV_XIVE_GRP_SOURCE 2 /* 64-bit source identifier */
687690
#define KVM_DEV_XIVE_GRP_SOURCE_CONFIG 3 /* 64-bit source identifier */
688691
#define KVM_DEV_XIVE_GRP_EQ_CONFIG 4 /* 64-bit EQ identifier */

‎arch/powerpc/kvm/book3s_xive.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,11 @@ static int xive_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
19111911
switch (attr->group) {
19121912
case KVM_DEV_XICS_GRP_SOURCES:
19131913
return xive_set_source(xive, attr->attr, attr->addr);
1914+
case KVM_DEV_XICS_GRP_CTRL:
1915+
switch (attr->attr) {
1916+
case KVM_DEV_XICS_NR_SERVERS:
1917+
return kvmppc_xive_set_nr_servers(xive, attr->addr);
1918+
}
19141919
}
19151920
return -ENXIO;
19161921
}
@@ -1936,6 +1941,11 @@ static int xive_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
19361941
attr->attr < KVMPPC_XICS_NR_IRQS)
19371942
return 0;
19381943
break;
1944+
case KVM_DEV_XICS_GRP_CTRL:
1945+
switch (attr->attr) {
1946+
case KVM_DEV_XICS_NR_SERVERS:
1947+
return 0;
1948+
}
19391949
}
19401950
return -ENXIO;
19411951
}

‎arch/powerpc/kvm/book3s_xive_native.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,8 @@ static int kvmppc_xive_native_set_attr(struct kvm_device *dev,
921921
return kvmppc_xive_reset(xive);
922922
case KVM_DEV_XIVE_EQ_SYNC:
923923
return kvmppc_xive_native_eq_sync(xive);
924+
case KVM_DEV_XIVE_NR_SERVERS:
925+
return kvmppc_xive_set_nr_servers(xive, attr->addr);
924926
}
925927
break;
926928
case KVM_DEV_XIVE_GRP_SOURCE:
@@ -960,6 +962,7 @@ static int kvmppc_xive_native_has_attr(struct kvm_device *dev,
960962
switch (attr->attr) {
961963
case KVM_DEV_XIVE_RESET:
962964
case KVM_DEV_XIVE_EQ_SYNC:
965+
case KVM_DEV_XIVE_NR_SERVERS:
963966
return 0;
964967
}
965968
break;

0 commit comments

Comments
 (0)