Skip to content

Commit 6db4263

Browse files
committed
KVM: s390: use switch vs jump table in priv.c
Instead of having huge jump tables for function selection, let's use normal switch/case statements for the instruction handlers in priv.c 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: Cornelia Huck <[email protected]> Reviewed-by: Janosch Frank <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Signed-off-by: Christian Borntraeger <[email protected]>
1 parent f315104 commit 6db4263

File tree

1 file changed

+91
-92
lines changed

1 file changed

+91
-92
lines changed

arch/s390/kvm/priv.c

Lines changed: 91 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -795,55 +795,60 @@ static int handle_stsi(struct kvm_vcpu *vcpu)
795795
return rc;
796796
}
797797

798-
static const intercept_handler_t b2_handlers[256] = {
799-
[0x02] = handle_stidp,
800-
[0x04] = handle_set_clock,
801-
[0x10] = handle_set_prefix,
802-
[0x11] = handle_store_prefix,
803-
[0x12] = handle_store_cpu_address,
804-
[0x14] = kvm_s390_handle_vsie,
805-
[0x21] = handle_ipte_interlock,
806-
[0x29] = handle_iske,
807-
[0x2a] = handle_rrbe,
808-
[0x2b] = handle_sske,
809-
[0x2c] = handle_test_block,
810-
[0x30] = handle_io_inst,
811-
[0x31] = handle_io_inst,
812-
[0x32] = handle_io_inst,
813-
[0x33] = handle_io_inst,
814-
[0x34] = handle_io_inst,
815-
[0x35] = handle_io_inst,
816-
[0x36] = handle_io_inst,
817-
[0x37] = handle_io_inst,
818-
[0x38] = handle_io_inst,
819-
[0x39] = handle_io_inst,
820-
[0x3a] = handle_io_inst,
821-
[0x3b] = handle_io_inst,
822-
[0x3c] = handle_io_inst,
823-
[0x50] = handle_ipte_interlock,
824-
[0x56] = handle_sthyi,
825-
[0x5f] = handle_io_inst,
826-
[0x74] = handle_io_inst,
827-
[0x76] = handle_io_inst,
828-
[0x7d] = handle_stsi,
829-
[0xb1] = handle_stfl,
830-
[0xb2] = handle_lpswe,
831-
};
832-
833798
int kvm_s390_handle_b2(struct kvm_vcpu *vcpu)
834799
{
835-
intercept_handler_t handler;
836-
837-
/*
838-
* A lot of B2 instructions are priviledged. Here we check for
839-
* the privileged ones, that we can handle in the kernel.
840-
* Anything else goes to userspace.
841-
*/
842-
handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
843-
if (handler)
844-
return handler(vcpu);
845-
846-
return -EOPNOTSUPP;
800+
switch (vcpu->arch.sie_block->ipa & 0x00ff) {
801+
case 0x02:
802+
return handle_stidp(vcpu);
803+
case 0x04:
804+
return handle_set_clock(vcpu);
805+
case 0x10:
806+
return handle_set_prefix(vcpu);
807+
case 0x11:
808+
return handle_store_prefix(vcpu);
809+
case 0x12:
810+
return handle_store_cpu_address(vcpu);
811+
case 0x14:
812+
return kvm_s390_handle_vsie(vcpu);
813+
case 0x21:
814+
case 0x50:
815+
return handle_ipte_interlock(vcpu);
816+
case 0x29:
817+
return handle_iske(vcpu);
818+
case 0x2a:
819+
return handle_rrbe(vcpu);
820+
case 0x2b:
821+
return handle_sske(vcpu);
822+
case 0x2c:
823+
return handle_test_block(vcpu);
824+
case 0x30:
825+
case 0x31:
826+
case 0x32:
827+
case 0x33:
828+
case 0x34:
829+
case 0x35:
830+
case 0x36:
831+
case 0x37:
832+
case 0x38:
833+
case 0x39:
834+
case 0x3a:
835+
case 0x3b:
836+
case 0x3c:
837+
case 0x5f:
838+
case 0x74:
839+
case 0x76:
840+
return handle_io_inst(vcpu);
841+
case 0x56:
842+
return handle_sthyi(vcpu);
843+
case 0x7d:
844+
return handle_stsi(vcpu);
845+
case 0xb1:
846+
return handle_stfl(vcpu);
847+
case 0xb2:
848+
return handle_lpswe(vcpu);
849+
default:
850+
return -EOPNOTSUPP;
851+
}
847852
}
848853

849854
static int handle_epsw(struct kvm_vcpu *vcpu)
@@ -1105,25 +1110,22 @@ static int handle_essa(struct kvm_vcpu *vcpu)
11051110
return 0;
11061111
}
11071112

1108-
static const intercept_handler_t b9_handlers[256] = {
1109-
[0x8a] = handle_ipte_interlock,
1110-
[0x8d] = handle_epsw,
1111-
[0x8e] = handle_ipte_interlock,
1112-
[0x8f] = handle_ipte_interlock,
1113-
[0xab] = handle_essa,
1114-
[0xaf] = handle_pfmf,
1115-
};
1116-
11171113
int kvm_s390_handle_b9(struct kvm_vcpu *vcpu)
11181114
{
1119-
intercept_handler_t handler;
1120-
1121-
/* This is handled just as for the B2 instructions. */
1122-
handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
1123-
if (handler)
1124-
return handler(vcpu);
1125-
1126-
return -EOPNOTSUPP;
1115+
switch (vcpu->arch.sie_block->ipa & 0x00ff) {
1116+
case 0x8a:
1117+
case 0x8e:
1118+
case 0x8f:
1119+
return handle_ipte_interlock(vcpu);
1120+
case 0x8d:
1121+
return handle_epsw(vcpu);
1122+
case 0xab:
1123+
return handle_essa(vcpu);
1124+
case 0xaf:
1125+
return handle_pfmf(vcpu);
1126+
default:
1127+
return -EOPNOTSUPP;
1128+
}
11271129
}
11281130

11291131
int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu)
@@ -1271,22 +1273,20 @@ static int handle_stctg(struct kvm_vcpu *vcpu)
12711273
return rc ? kvm_s390_inject_prog_cond(vcpu, rc) : 0;
12721274
}
12731275

1274-
static const intercept_handler_t eb_handlers[256] = {
1275-
[0x2f] = handle_lctlg,
1276-
[0x25] = handle_stctg,
1277-
[0x60] = handle_ri,
1278-
[0x61] = handle_ri,
1279-
[0x62] = handle_ri,
1280-
};
1281-
12821276
int kvm_s390_handle_eb(struct kvm_vcpu *vcpu)
12831277
{
1284-
intercept_handler_t handler;
1285-
1286-
handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff];
1287-
if (handler)
1288-
return handler(vcpu);
1289-
return -EOPNOTSUPP;
1278+
switch (vcpu->arch.sie_block->ipb & 0x000000ff) {
1279+
case 0x25:
1280+
return handle_stctg(vcpu);
1281+
case 0x2f:
1282+
return handle_lctlg(vcpu);
1283+
case 0x60:
1284+
case 0x61:
1285+
case 0x62:
1286+
return handle_ri(vcpu);
1287+
default:
1288+
return -EOPNOTSUPP;
1289+
}
12901290
}
12911291

12921292
static int handle_tprot(struct kvm_vcpu *vcpu)
@@ -1346,10 +1346,12 @@ static int handle_tprot(struct kvm_vcpu *vcpu)
13461346

13471347
int kvm_s390_handle_e5(struct kvm_vcpu *vcpu)
13481348
{
1349-
/* For e5xx... instructions we only handle TPROT */
1350-
if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01)
1349+
switch (vcpu->arch.sie_block->ipa & 0x00ff) {
1350+
case 0x01:
13511351
return handle_tprot(vcpu);
1352-
return -EOPNOTSUPP;
1352+
default:
1353+
return -EOPNOTSUPP;
1354+
}
13531355
}
13541356

13551357
static int handle_sckpf(struct kvm_vcpu *vcpu)
@@ -1380,17 +1382,14 @@ static int handle_ptff(struct kvm_vcpu *vcpu)
13801382
return 0;
13811383
}
13821384

1383-
static const intercept_handler_t x01_handlers[256] = {
1384-
[0x04] = handle_ptff,
1385-
[0x07] = handle_sckpf,
1386-
};
1387-
13881385
int kvm_s390_handle_01(struct kvm_vcpu *vcpu)
13891386
{
1390-
intercept_handler_t handler;
1391-
1392-
handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
1393-
if (handler)
1394-
return handler(vcpu);
1395-
return -EOPNOTSUPP;
1387+
switch (vcpu->arch.sie_block->ipa & 0x00ff) {
1388+
case 0x04:
1389+
return handle_ptff(vcpu);
1390+
case 0x07:
1391+
return handle_sckpf(vcpu);
1392+
default:
1393+
return -EOPNOTSUPP;
1394+
}
13961395
}

0 commit comments

Comments
 (0)