Skip to content

Commit 95ca2cb

Browse files
Janosch Frankborntraeger
authored andcommitted
KVM: s390: Add sthyi emulation
Store Hypervisor Information is an emulated z/VM instruction that provides a guest with basic information about the layers it is running on. This includes information about the cpu configuration of both the machine and the lpar, as well as their names, machine model and machine type. This information enables an application to determine the maximum capacity of CPs and IFLs available to software. The instruction is available whenever the facility bit 74 is set, otherwise executing it results in an operation exception. It is important to check the validity flags in the sections before using data from any structure member. It is not guaranteed that all members will be valid on all machines / machine configurations. Signed-off-by: Janosch Frank <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Signed-off-by: Christian Borntraeger <[email protected]>
1 parent a2d57b3 commit 95ca2cb

File tree

9 files changed

+507
-1
lines changed

9 files changed

+507
-1
lines changed

arch/s390/include/asm/diag.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@ struct diag204_x_phys_cpu {
215215
char reserved3[80];
216216
} __packed;
217217

218+
struct diag204_x_part_block {
219+
struct diag204_x_part_hdr hdr;
220+
struct diag204_x_cpu_info cpus[];
221+
} __packed;
222+
223+
struct diag204_x_phys_block {
224+
struct diag204_x_phys_hdr hdr;
225+
struct diag204_x_phys_cpu cpus[];
226+
} __packed;
227+
218228
int diag204(unsigned long subcode, unsigned long size, void *addr);
219229
int diag224(void *ptr);
220230
#endif /* _ASM_S390_DIAG_H */

arch/s390/include/asm/kvm_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ struct kvm_s390_sie_block {
154154
#define LCTL_CR14 0x0002
155155
__u16 lctl; /* 0x0044 */
156156
__s16 icpua; /* 0x0046 */
157+
#define ICTL_OPEREXC 0x80000000
157158
#define ICTL_PINT 0x20000000
158159
#define ICTL_LPSW 0x00400000
159160
#define ICTL_STCTL 0x00040000
@@ -279,6 +280,7 @@ struct kvm_vcpu_stat {
279280
u32 instruction_stfl;
280281
u32 instruction_tprot;
281282
u32 instruction_essa;
283+
u32 instruction_sthyi;
282284
u32 instruction_sigp_sense;
283285
u32 instruction_sigp_sense_running;
284286
u32 instruction_sigp_external_call;

arch/s390/include/uapi/asm/sie.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
exit_code_ipa0(0xB2, 0x4c, "TAR"), \
141141
exit_code_ipa0(0xB2, 0x50, "CSP"), \
142142
exit_code_ipa0(0xB2, 0x54, "MVPG"), \
143+
exit_code_ipa0(0xB2, 0x56, "STHYI"), \
143144
exit_code_ipa0(0xB2, 0x58, "BSG"), \
144145
exit_code_ipa0(0xB2, 0x5a, "BSA"), \
145146
exit_code_ipa0(0xB2, 0x5f, "CHSC"), \

arch/s390/kvm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ common-objs = $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/async_pf.o $(KVM)/irqch
1212
ccflags-y := -Ivirt/kvm -Iarch/s390/kvm
1313

1414
kvm-objs := $(common-objs) kvm-s390.o intercept.o interrupt.o priv.o sigp.o
15-
kvm-objs += diag.o gaccess.o guestdbg.o
15+
kvm-objs += diag.o gaccess.o guestdbg.o sthyi.o
1616

1717
obj-$(CONFIG_KVM) += kvm.o

arch/s390/kvm/intercept.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ static int handle_operexc(struct kvm_vcpu *vcpu)
355355
trace_kvm_s390_handle_operexc(vcpu, vcpu->arch.sie_block->ipa,
356356
vcpu->arch.sie_block->ipb);
357357

358+
if (vcpu->arch.sie_block->ipa == 0xb256 &&
359+
test_kvm_facility(vcpu->kvm, 74))
360+
return handle_sthyi(vcpu);
361+
358362
return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
359363
}
360364

arch/s390/kvm/kvm-s390.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
9494
{ "instruction_stsi", VCPU_STAT(instruction_stsi) },
9595
{ "instruction_stfl", VCPU_STAT(instruction_stfl) },
9696
{ "instruction_tprot", VCPU_STAT(instruction_tprot) },
97+
{ "instruction_sthyi", VCPU_STAT(instruction_sthyi) },
9798
{ "instruction_sigp_sense", VCPU_STAT(instruction_sigp_sense) },
9899
{ "instruction_sigp_sense_running", VCPU_STAT(instruction_sigp_sense_running) },
99100
{ "instruction_sigp_external_call", VCPU_STAT(instruction_sigp_external_call) },
@@ -1189,6 +1190,9 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
11891190
memcpy(kvm->arch.model.fac_list, kvm->arch.model.fac_mask,
11901191
S390_ARCH_FAC_LIST_SIZE_BYTE);
11911192

1193+
set_kvm_facility(kvm->arch.model.fac_mask, 74);
1194+
set_kvm_facility(kvm->arch.model.fac_list, 74);
1195+
11921196
kvm->arch.model.cpuid = kvm_s390_get_initial_cpuid();
11931197
kvm->arch.model.ibc = sclp.ibc & 0x0fff;
11941198

@@ -1679,6 +1683,8 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
16791683
}
16801684
vcpu->arch.sie_block->riccbd = (unsigned long) &vcpu->run->s.regs.riccb;
16811685
vcpu->arch.sie_block->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE;
1686+
if (test_kvm_facility(vcpu->kvm, 74))
1687+
vcpu->arch.sie_block->ictl |= ICTL_OPEREXC;
16821688

16831689
if (vcpu->kvm->arch.use_cmma) {
16841690
rc = kvm_s390_vcpu_setup_cmma(vcpu);

arch/s390/kvm/kvm-s390.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ int kvm_s390_handle_eb(struct kvm_vcpu *vcpu);
250250
int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
251251
int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu);
252252

253+
/* implemented in sthyi.c */
254+
int handle_sthyi(struct kvm_vcpu *vcpu);
255+
253256
/* implemented in kvm-s390.c */
254257
void kvm_s390_set_tod_clock(struct kvm *kvm, u64 tod);
255258
long kvm_arch_fault_in_page(struct kvm_vcpu *vcpu, gpa_t gpa, int writable);

0 commit comments

Comments
 (0)