Skip to content

Commit 80cd876

Browse files
Fan Zhangborntraeger
authored andcommitted
KVM: s390: lazy enable RI
Only enable runtime instrumentation if the guest issues an RI related instruction or if userspace changes the riccb to a valid state. This makes entry/exit a tiny bit faster. Initial patch by Christian Borntraeger Signed-off-by: Fan Zhang <zhangfan@linux.vnet.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
1 parent c14b88d commit 80cd876

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

arch/s390/kvm/intercept.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static const intercept_handler_t instruction_handlers[256] = {
2929
[0x01] = kvm_s390_handle_01,
3030
[0x82] = kvm_s390_handle_lpsw,
3131
[0x83] = kvm_s390_handle_diag,
32+
[0xaa] = kvm_s390_handle_aa,
3233
[0xae] = kvm_s390_handle_sigp,
3334
[0xb2] = kvm_s390_handle_b2,
3435
[0xb6] = kvm_s390_handle_stctl,

arch/s390/kvm/kvm-s390.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,8 +1938,6 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
19381938
vcpu->arch.sie_block->eca |= 1;
19391939
if (sclp.has_sigpif)
19401940
vcpu->arch.sie_block->eca |= 0x10000000U;
1941-
if (test_kvm_facility(vcpu->kvm, 64))
1942-
vcpu->arch.sie_block->ecb3 |= 0x01;
19431941
if (test_kvm_facility(vcpu->kvm, 129)) {
19441942
vcpu->arch.sie_block->eca |= 0x00020000;
19451943
vcpu->arch.sie_block->ecd |= 0x20000000;
@@ -2694,6 +2692,19 @@ static void sync_regs(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
26942692
if (vcpu->arch.pfault_token == KVM_S390_PFAULT_TOKEN_INVALID)
26952693
kvm_clear_async_pf_completion_queue(vcpu);
26962694
}
2695+
/*
2696+
* If userspace sets the riccb (e.g. after migration) to a valid state,
2697+
* we should enable RI here instead of doing the lazy enablement.
2698+
*/
2699+
if ((kvm_run->kvm_dirty_regs & KVM_SYNC_RICCB) &&
2700+
test_kvm_facility(vcpu->kvm, 64)) {
2701+
struct runtime_instr_cb *riccb =
2702+
(struct runtime_instr_cb *) &kvm_run->s.regs.riccb;
2703+
2704+
if (riccb->valid)
2705+
vcpu->arch.sie_block->ecb3 |= 0x01;
2706+
}
2707+
26972708
kvm_run->kvm_dirty_regs = 0;
26982709
}
26992710

arch/s390/kvm/kvm-s390.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ static inline void kvm_s390_retry_instr(struct kvm_vcpu *vcpu)
245245

246246
/* implemented in priv.c */
247247
int is_valid_psw(psw_t *psw);
248+
int kvm_s390_handle_aa(struct kvm_vcpu *vcpu);
248249
int kvm_s390_handle_b2(struct kvm_vcpu *vcpu);
249250
int kvm_s390_handle_e5(struct kvm_vcpu *vcpu);
250251
int kvm_s390_handle_01(struct kvm_vcpu *vcpu);

arch/s390/kvm/priv.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@
3232
#include "kvm-s390.h"
3333
#include "trace.h"
3434

35+
static int handle_ri(struct kvm_vcpu *vcpu)
36+
{
37+
if (test_kvm_facility(vcpu->kvm, 64)) {
38+
vcpu->arch.sie_block->ecb3 |= 0x01;
39+
kvm_s390_retry_instr(vcpu);
40+
return 0;
41+
} else
42+
return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
43+
}
44+
45+
int kvm_s390_handle_aa(struct kvm_vcpu *vcpu)
46+
{
47+
if ((vcpu->arch.sie_block->ipa & 0xf) <= 4)
48+
return handle_ri(vcpu);
49+
else
50+
return -EOPNOTSUPP;
51+
}
52+
3553
/* Handle SCK (SET CLOCK) interception */
3654
static int handle_set_clock(struct kvm_vcpu *vcpu)
3755
{
@@ -1093,6 +1111,9 @@ static int handle_stctg(struct kvm_vcpu *vcpu)
10931111
static const intercept_handler_t eb_handlers[256] = {
10941112
[0x2f] = handle_lctlg,
10951113
[0x25] = handle_stctg,
1114+
[0x60] = handle_ri,
1115+
[0x61] = handle_ri,
1116+
[0x62] = handle_ri,
10961117
};
10971118

10981119
int kvm_s390_handle_eb(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)