Skip to content

Commit cb7485d

Browse files
committed
KVM: s390: use switch vs jump table in intercept.c
Instead of having huge jump tables for function selection, let's use normal switch/case statements for the instruction handlers in intercept.c We can now also get rid of intercept_handler_t. This allows the compiler to make the right decision depending on the situation (e.g. avoid jump-tables for thunks). Signed-off-by: Christian Borntraeger <[email protected]> Reviewed-by: Janosch Frank <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Reviewed-by: Cornelia Huck <[email protected]> Signed-off-by: Christian Borntraeger <[email protected]>
1 parent 6db4263 commit cb7485d

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

arch/s390/kvm/intercept.c

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,6 @@
2222
#include "trace.h"
2323
#include "trace-s390.h"
2424

25-
26-
static const intercept_handler_t instruction_handlers[256] = {
27-
[0x01] = kvm_s390_handle_01,
28-
[0x82] = kvm_s390_handle_lpsw,
29-
[0x83] = kvm_s390_handle_diag,
30-
[0xaa] = kvm_s390_handle_aa,
31-
[0xae] = kvm_s390_handle_sigp,
32-
[0xb2] = kvm_s390_handle_b2,
33-
[0xb6] = kvm_s390_handle_stctl,
34-
[0xb7] = kvm_s390_handle_lctl,
35-
[0xb9] = kvm_s390_handle_b9,
36-
[0xe3] = kvm_s390_handle_e3,
37-
[0xe5] = kvm_s390_handle_e5,
38-
[0xeb] = kvm_s390_handle_eb,
39-
};
40-
4125
u8 kvm_s390_get_ilen(struct kvm_vcpu *vcpu)
4226
{
4327
struct kvm_s390_sie_block *sie_block = vcpu->arch.sie_block;
@@ -129,16 +113,39 @@ static int handle_validity(struct kvm_vcpu *vcpu)
129113

130114
static int handle_instruction(struct kvm_vcpu *vcpu)
131115
{
132-
intercept_handler_t handler;
133-
134116
vcpu->stat.exit_instruction++;
135117
trace_kvm_s390_intercept_instruction(vcpu,
136118
vcpu->arch.sie_block->ipa,
137119
vcpu->arch.sie_block->ipb);
138-
handler = instruction_handlers[vcpu->arch.sie_block->ipa >> 8];
139-
if (handler)
140-
return handler(vcpu);
141-
return -EOPNOTSUPP;
120+
121+
switch (vcpu->arch.sie_block->ipa >> 8) {
122+
case 0x01:
123+
return kvm_s390_handle_01(vcpu);
124+
case 0x82:
125+
return kvm_s390_handle_lpsw(vcpu);
126+
case 0x83:
127+
return kvm_s390_handle_diag(vcpu);
128+
case 0xaa:
129+
return kvm_s390_handle_aa(vcpu);
130+
case 0xae:
131+
return kvm_s390_handle_sigp(vcpu);
132+
case 0xb2:
133+
return kvm_s390_handle_b2(vcpu);
134+
case 0xb6:
135+
return kvm_s390_handle_stctl(vcpu);
136+
case 0xb7:
137+
return kvm_s390_handle_lctl(vcpu);
138+
case 0xb9:
139+
return kvm_s390_handle_b9(vcpu);
140+
case 0xe3:
141+
return kvm_s390_handle_e3(vcpu);
142+
case 0xe5:
143+
return kvm_s390_handle_e5(vcpu);
144+
case 0xeb:
145+
return kvm_s390_handle_eb(vcpu);
146+
default:
147+
return -EOPNOTSUPP;
148+
}
142149
}
143150

144151
static int inject_prog_on_prog_intercept(struct kvm_vcpu *vcpu)

arch/s390/kvm/kvm-s390.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include <asm/processor.h>
2020
#include <asm/sclp.h>
2121

22-
typedef int (*intercept_handler_t)(struct kvm_vcpu *vcpu);
23-
2422
/* Transactional Memory Execution related macros */
2523
#define IS_TE_ENABLED(vcpu) ((vcpu->arch.sie_block->ecb & ECB_TE))
2624
#define TDB_FORMAT1 1

0 commit comments

Comments
 (0)