Skip to content

Commit a3da7b4

Browse files
committed
KVM: s390: add etoken support for guests
We want to provide facility 156 (etoken facility) to our guests. This includes migration support (via sync regs) and VSIE changes. The tokens are being reset on clear reset. This has to be implemented by userspace (via sync regs). Signed-off-by: Christian Borntraeger <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Acked-by: Cornelia Huck <[email protected]>
1 parent 63747bf commit a3da7b4

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

arch/s390/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ struct kvm_s390_sie_block {
269269
__u8 reserved1c0[8]; /* 0x01c0 */
270270
#define ECD_HOSTREGMGMT 0x20000000
271271
#define ECD_MEF 0x08000000
272+
#define ECD_ETOKENF 0x02000000
272273
__u32 ecd; /* 0x01c8 */
273274
__u8 reserved1cc[18]; /* 0x01cc */
274275
__u64 pp; /* 0x01de */

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/*
55
* KVM s390 specific structures and definitions
66
*
7-
* Copyright IBM Corp. 2008
7+
* Copyright IBM Corp. 2008, 2018
88
*
99
* Author(s): Carsten Otte <[email protected]>
1010
* Christian Borntraeger <[email protected]>
@@ -225,6 +225,7 @@ struct kvm_guest_debug_arch {
225225
#define KVM_SYNC_FPRS (1UL << 8)
226226
#define KVM_SYNC_GSCB (1UL << 9)
227227
#define KVM_SYNC_BPBC (1UL << 10)
228+
#define KVM_SYNC_ETOKEN (1UL << 11)
228229
/* length and alignment of the sdnx as a power of two */
229230
#define SDNXC 8
230231
#define SDNXL (1UL << SDNXC)
@@ -258,6 +259,8 @@ struct kvm_sync_regs {
258259
struct {
259260
__u64 reserved1[2];
260261
__u64 gscb[4];
262+
__u64 etoken;
263+
__u64 etoken_extension;
261264
};
262265
};
263266
};

arch/s390/kvm/kvm-s390.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,6 +2355,8 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
23552355
vcpu->run->kvm_valid_regs |= KVM_SYNC_BPBC;
23562356
if (test_kvm_facility(vcpu->kvm, 133))
23572357
vcpu->run->kvm_valid_regs |= KVM_SYNC_GSCB;
2358+
if (test_kvm_facility(vcpu->kvm, 156))
2359+
vcpu->run->kvm_valid_regs |= KVM_SYNC_ETOKEN;
23582360
/* fprs can be synchronized via vrs, even if the guest has no vx. With
23592361
* MACHINE_HAS_VX, (load|store)_fpu_regs() will work with vrs format.
23602362
*/
@@ -2604,7 +2606,8 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
26042606
}
26052607
if (test_kvm_facility(vcpu->kvm, 139))
26062608
vcpu->arch.sie_block->ecd |= ECD_MEF;
2607-
2609+
if (test_kvm_facility(vcpu->kvm, 156))
2610+
vcpu->arch.sie_block->ecd |= ECD_ETOKENF;
26082611
if (vcpu->arch.sie_block->gd) {
26092612
vcpu->arch.sie_block->eca |= ECA_AIV;
26102613
VCPU_EVENT(vcpu, 3, "AIV gisa format-%u enabled for cpu %03u",
@@ -3522,6 +3525,7 @@ static void sync_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
35223525
}
35233526
preempt_enable();
35243527
}
3528+
/* SIE will load etoken directly from SDNX and therefore kvm_run */
35253529

35263530
kvm_run->kvm_dirty_regs = 0;
35273531
}
@@ -3561,7 +3565,7 @@ static void store_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
35613565
__ctl_clear_bit(2, 4);
35623566
vcpu->arch.host_gscb = NULL;
35633567
}
3564-
3568+
/* SIE will save etoken directly into SDNX and therefore kvm_run */
35653569
}
35663570

35673571
int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)

arch/s390/kvm/vsie.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* kvm nested virtualization support for s390x
44
*
5-
* Copyright IBM Corp. 2016
5+
* Copyright IBM Corp. 2016, 2018
66
*
77
* Author(s): David Hildenbrand <[email protected]>
88
*/
@@ -378,6 +378,10 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
378378
if (test_kvm_facility(vcpu->kvm, 139))
379379
scb_s->ecd |= scb_o->ecd & ECD_MEF;
380380

381+
/* etoken */
382+
if (test_kvm_facility(vcpu->kvm, 156))
383+
scb_s->ecd |= scb_o->ecd & ECD_ETOKENF;
384+
381385
prepare_ibc(vcpu, vsie_page);
382386
rc = shadow_crycb(vcpu, vsie_page);
383387
out:
@@ -627,7 +631,8 @@ static int pin_blocks(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
627631
vsie_page->riccbd_gpa = gpa;
628632
scb_s->riccbd = hpa;
629633
}
630-
if ((scb_s->ecb & ECB_GS) && !(scb_s->ecd & ECD_HOSTREGMGMT)) {
634+
if (((scb_s->ecb & ECB_GS) && !(scb_s->ecd & ECD_HOSTREGMGMT)) ||
635+
(scb_s->ecd & ECD_ETOKENF)) {
631636
unsigned long sdnxc;
632637

633638
gpa = READ_ONCE(scb_o->sdnxo) & ~0xfUL;

arch/s390/tools/gen_facilities.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* numbering scheme from the Princples of Operations: most significant bit
55
* has bit number 0.
66
*
7-
* Copyright IBM Corp. 2015
7+
* Copyright IBM Corp. 2015, 2018
88
*
99
*/
1010

@@ -106,6 +106,7 @@ static struct facility_def facility_defs[] = {
106106

107107
.name = "FACILITIES_KVM_CPUMODEL",
108108
.bits = (int[]){
109+
156, /* etoken facility */
109110
-1 /* END */
110111
}
111112
},

0 commit comments

Comments
 (0)