Skip to content

Commit 23a60f8

Browse files
collinwallingborntraeger
authored andcommitted
s390/kvm: diagnose 0x318 sync and reset
DIAGNOSE 0x318 (diag318) sets information regarding the environment the VM is running in (Linux, z/VM, etc) and is observed via firmware/service events. This is a privileged s390x instruction that must be intercepted by SIE. Userspace handles the instruction as well as migration. Data is communicated via VCPU register synchronization. The Control Program Name Code (CPNC) is stored in the SIE block. The CPNC along with the Control Program Version Code (CPVC) are stored in the kvm_vcpu_arch struct. This data is reset on load normal and clear resets. Signed-off-by: Collin Walling <[email protected]> Reviewed-by: Janosch Frank <[email protected]> Acked-by: Cornelia Huck <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Link: https://lore.kernel.org/r/[email protected] [[email protected]: fix sync_reg position] Signed-off-by: Christian Borntraeger <[email protected]>
1 parent a23816f commit 23a60f8

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

arch/s390/include/asm/kvm_host.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ struct kvm_s390_sie_block {
260260
__u32 scaol; /* 0x0064 */
261261
__u8 sdf; /* 0x0068 */
262262
__u8 epdx; /* 0x0069 */
263-
__u8 reserved6a[2]; /* 0x006a */
263+
__u8 cpnc; /* 0x006a */
264+
__u8 reserved6b; /* 0x006b */
264265
__u32 todpr; /* 0x006c */
265266
#define GISA_FORMAT1 0x00000001
266267
__u32 gd; /* 0x0070 */
@@ -745,6 +746,7 @@ struct kvm_vcpu_arch {
745746
bool gs_enabled;
746747
bool skey_enabled;
747748
struct kvm_s390_pv_vcpu pv;
749+
union diag318_info diag318_info;
748750
};
749751

750752
struct kvm_vm_stat {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,13 @@ struct kvm_guest_debug_arch {
231231
#define KVM_SYNC_GSCB (1UL << 9)
232232
#define KVM_SYNC_BPBC (1UL << 10)
233233
#define KVM_SYNC_ETOKEN (1UL << 11)
234+
#define KVM_SYNC_DIAG318 (1UL << 12)
234235

235236
#define KVM_SYNC_S390_VALID_FIELDS \
236237
(KVM_SYNC_PREFIX | KVM_SYNC_GPRS | KVM_SYNC_ACRS | KVM_SYNC_CRS | \
237238
KVM_SYNC_ARCH0 | KVM_SYNC_PFAULT | KVM_SYNC_VRS | KVM_SYNC_RICCB | \
238-
KVM_SYNC_FPRS | KVM_SYNC_GSCB | KVM_SYNC_BPBC | KVM_SYNC_ETOKEN)
239+
KVM_SYNC_FPRS | KVM_SYNC_GSCB | KVM_SYNC_BPBC | KVM_SYNC_ETOKEN | \
240+
KVM_SYNC_DIAG318)
239241

240242
/* length and alignment of the sdnx as a power of two */
241243
#define SDNXC 8
@@ -264,7 +266,8 @@ struct kvm_sync_regs {
264266
__u8 reserved2 : 7;
265267
__u8 padding1[51]; /* riccb needs to be 64byte aligned */
266268
__u8 riccb[64]; /* runtime instrumentation controls block */
267-
__u8 padding2[192]; /* sdnx needs to be 256byte aligned */
269+
__u64 diag318; /* diagnose 0x318 info */
270+
__u8 padding2[184]; /* sdnx needs to be 256byte aligned */
268271
union {
269272
__u8 sdnx[SDNXL]; /* state description annex */
270273
struct {

arch/s390/kvm/kvm-s390.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
545545
case KVM_CAP_S390_AIS_MIGRATION:
546546
case KVM_CAP_S390_VCPU_RESETS:
547547
case KVM_CAP_SET_GUEST_DEBUG:
548+
case KVM_CAP_S390_DIAG318:
548549
r = 1;
549550
break;
550551
case KVM_CAP_S390_HPAGE_1M:
@@ -3267,7 +3268,8 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
32673268
KVM_SYNC_ACRS |
32683269
KVM_SYNC_CRS |
32693270
KVM_SYNC_ARCH0 |
3270-
KVM_SYNC_PFAULT;
3271+
KVM_SYNC_PFAULT |
3272+
KVM_SYNC_DIAG318;
32713273
kvm_s390_set_prefix(vcpu, 0);
32723274
if (test_kvm_facility(vcpu->kvm, 64))
32733275
vcpu->run->kvm_valid_regs |= KVM_SYNC_RICCB;
@@ -3562,6 +3564,7 @@ static void kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu)
35623564
vcpu->arch.sie_block->pp = 0;
35633565
vcpu->arch.sie_block->fpf &= ~FPF_BPBC;
35643566
vcpu->arch.sie_block->todpr = 0;
3567+
vcpu->arch.sie_block->cpnc = 0;
35653568
}
35663569
}
35673570

@@ -3579,6 +3582,7 @@ static void kvm_arch_vcpu_ioctl_clear_reset(struct kvm_vcpu *vcpu)
35793582

35803583
regs->etoken = 0;
35813584
regs->etoken_extension = 0;
3585+
regs->diag318 = 0;
35823586
}
35833587

35843588
int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
@@ -4196,6 +4200,10 @@ static void sync_regs_fmt2(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
41964200
if (vcpu->arch.pfault_token == KVM_S390_PFAULT_TOKEN_INVALID)
41974201
kvm_clear_async_pf_completion_queue(vcpu);
41984202
}
4203+
if (kvm_run->kvm_dirty_regs & KVM_SYNC_DIAG318) {
4204+
vcpu->arch.diag318_info.val = kvm_run->s.regs.diag318;
4205+
vcpu->arch.sie_block->cpnc = vcpu->arch.diag318_info.cpnc;
4206+
}
41994207
/*
42004208
* If userspace sets the riccb (e.g. after migration) to a valid state,
42014209
* we should enable RI here instead of doing the lazy enablement.
@@ -4297,6 +4305,7 @@ static void store_regs_fmt2(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
42974305
kvm_run->s.regs.pp = vcpu->arch.sie_block->pp;
42984306
kvm_run->s.regs.gbea = vcpu->arch.sie_block->gbea;
42994307
kvm_run->s.regs.bpbc = (vcpu->arch.sie_block->fpf & FPF_BPBC) == FPF_BPBC;
4308+
kvm_run->s.regs.diag318 = vcpu->arch.diag318_info.val;
43004309
if (MACHINE_HAS_GS) {
43014310
__ctl_set_bit(2, 4);
43024311
if (vcpu->arch.gs_enabled)

arch/s390/kvm/vsie.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
548548
scb_s->ecd |= scb_o->ecd & ECD_ETOKENF;
549549

550550
scb_s->hpid = HPID_VSIE;
551+
scb_s->cpnc = scb_o->cpnc;
551552

552553
prepare_ibc(vcpu, vsie_page);
553554
rc = shadow_crycb(vcpu, vsie_page);

include/uapi/linux/kvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ struct kvm_ppc_resize_hpt {
10311031
#define KVM_CAP_PPC_SECURE_GUEST 181
10321032
#define KVM_CAP_HALT_POLL 182
10331033
#define KVM_CAP_ASYNC_PF_INT 183
1034+
#define KVM_CAP_S390_DIAG318 184
10341035

10351036
#ifdef KVM_CAP_IRQ_ROUTING
10361037

0 commit comments

Comments
 (0)