Skip to content

Commit 185e02d

Browse files
committed
Merge tag 'kvm-s390-next-6.13-1' of https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD
- second part of the ucontrol selftest - cpumodel sanity check selftest - gen17 cpumodel changes
2 parents e3e0f9b + 7a1f314 commit 185e02d

File tree

12 files changed

+737
-13
lines changed

12 files changed

+737
-13
lines changed

arch/s390/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ struct kvm_s390_sie_block {
356356
#define ECD_MEF 0x08000000
357357
#define ECD_ETOKENF 0x02000000
358358
#define ECD_ECC 0x00200000
359+
#define ECD_HMAC 0x00004000
359360
__u32 ecd; /* 0x01c8 */
360361
__u8 reserved1cc[18]; /* 0x01cc */
361362
__u64 pp; /* 0x01de */

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ struct kvm_s390_vm_cpu_subfunc {
469469
__u8 kdsa[16]; /* with MSA9 */
470470
__u8 sortl[32]; /* with STFLE.150 */
471471
__u8 dfltcc[32]; /* with STFLE.151 */
472-
__u8 reserved[1728];
472+
__u8 pfcr[16]; /* with STFLE.201 */
473+
__u8 reserved[1712];
473474
};
474475

475476
#define KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST 6

arch/s390/kvm/kvm-s390.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,16 @@ static inline int plo_test_bit(unsigned char nr)
348348
return cc == 0;
349349
}
350350

351+
static __always_inline void pfcr_query(u8 (*query)[16])
352+
{
353+
asm volatile(
354+
" lghi 0,0\n"
355+
" .insn rsy,0xeb0000000016,0,0,%[query]\n"
356+
: [query] "=QS" (*query)
357+
:
358+
: "cc", "0");
359+
}
360+
351361
static __always_inline void __sortl_query(u8 (*query)[32])
352362
{
353363
asm volatile(
@@ -429,6 +439,9 @@ static void __init kvm_s390_cpu_feat_init(void)
429439
if (test_facility(151)) /* DFLTCC */
430440
__dfltcc_query(&kvm_s390_available_subfunc.dfltcc);
431441

442+
if (test_facility(201)) /* PFCR */
443+
pfcr_query(&kvm_s390_available_subfunc.pfcr);
444+
432445
if (MACHINE_HAS_ESOP)
433446
allow_cpu_feat(KVM_S390_VM_CPU_FEAT_ESOP);
434447
/*
@@ -799,6 +812,14 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap)
799812
set_kvm_facility(kvm->arch.model.fac_mask, 192);
800813
set_kvm_facility(kvm->arch.model.fac_list, 192);
801814
}
815+
if (test_facility(198)) {
816+
set_kvm_facility(kvm->arch.model.fac_mask, 198);
817+
set_kvm_facility(kvm->arch.model.fac_list, 198);
818+
}
819+
if (test_facility(199)) {
820+
set_kvm_facility(kvm->arch.model.fac_mask, 199);
821+
set_kvm_facility(kvm->arch.model.fac_list, 199);
822+
}
802823
r = 0;
803824
} else
804825
r = -EINVAL;
@@ -1543,6 +1564,9 @@ static int kvm_s390_set_processor_subfunc(struct kvm *kvm,
15431564
((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[1],
15441565
((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[2],
15451566
((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[3]);
1567+
VM_EVENT(kvm, 3, "GET: guest PFCR subfunc 0x%16.16lx.%16.16lx",
1568+
((unsigned long *) &kvm_s390_available_subfunc.pfcr)[0],
1569+
((unsigned long *) &kvm_s390_available_subfunc.pfcr)[1]);
15461570

15471571
return 0;
15481572
}
@@ -1757,6 +1781,9 @@ static int kvm_s390_get_processor_subfunc(struct kvm *kvm,
17571781
((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[1],
17581782
((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[2],
17591783
((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[3]);
1784+
VM_EVENT(kvm, 3, "GET: guest PFCR subfunc 0x%16.16lx.%16.16lx",
1785+
((unsigned long *) &kvm_s390_available_subfunc.pfcr)[0],
1786+
((unsigned long *) &kvm_s390_available_subfunc.pfcr)[1]);
17601787

17611788
return 0;
17621789
}
@@ -1825,6 +1852,9 @@ static int kvm_s390_get_machine_subfunc(struct kvm *kvm,
18251852
((unsigned long *) &kvm_s390_available_subfunc.dfltcc)[1],
18261853
((unsigned long *) &kvm_s390_available_subfunc.dfltcc)[2],
18271854
((unsigned long *) &kvm_s390_available_subfunc.dfltcc)[3]);
1855+
VM_EVENT(kvm, 3, "GET: host PFCR subfunc 0x%16.16lx.%16.16lx",
1856+
((unsigned long *) &kvm_s390_available_subfunc.pfcr)[0],
1857+
((unsigned long *) &kvm_s390_available_subfunc.pfcr)[1]);
18281858

18291859
return 0;
18301860
}
@@ -3774,6 +3804,13 @@ static bool kvm_has_pckmo_ecc(struct kvm *kvm)
37743804

37753805
}
37763806

3807+
static bool kvm_has_pckmo_hmac(struct kvm *kvm)
3808+
{
3809+
/* At least one HMAC subfunction must be present */
3810+
return kvm_has_pckmo_subfunc(kvm, 118) ||
3811+
kvm_has_pckmo_subfunc(kvm, 122);
3812+
}
3813+
37773814
static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu)
37783815
{
37793816
/*
@@ -3786,17 +3823,19 @@ static void kvm_s390_vcpu_crypto_setup(struct kvm_vcpu *vcpu)
37863823
vcpu->arch.sie_block->crycbd = vcpu->kvm->arch.crypto.crycbd;
37873824
vcpu->arch.sie_block->ecb3 &= ~(ECB3_AES | ECB3_DEA);
37883825
vcpu->arch.sie_block->eca &= ~ECA_APIE;
3789-
vcpu->arch.sie_block->ecd &= ~ECD_ECC;
3826+
vcpu->arch.sie_block->ecd &= ~(ECD_ECC | ECD_HMAC);
37903827

37913828
if (vcpu->kvm->arch.crypto.apie)
37923829
vcpu->arch.sie_block->eca |= ECA_APIE;
37933830

37943831
/* Set up protected key support */
37953832
if (vcpu->kvm->arch.crypto.aes_kw) {
37963833
vcpu->arch.sie_block->ecb3 |= ECB3_AES;
3797-
/* ecc is also wrapped with AES key */
3834+
/* ecc/hmac is also wrapped with AES key */
37983835
if (kvm_has_pckmo_ecc(vcpu->kvm))
37993836
vcpu->arch.sie_block->ecd |= ECD_ECC;
3837+
if (kvm_has_pckmo_hmac(vcpu->kvm))
3838+
vcpu->arch.sie_block->ecd |= ECD_HMAC;
38003839
}
38013840

38023841
if (vcpu->kvm->arch.crypto.dea_kw)

arch/s390/kvm/vsie.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ static int shadow_crycb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
335335
/* we may only allow it if enabled for guest 2 */
336336
ecb3_flags = scb_o->ecb3 & vcpu->arch.sie_block->ecb3 &
337337
(ECB3_AES | ECB3_DEA);
338-
ecd_flags = scb_o->ecd & vcpu->arch.sie_block->ecd & ECD_ECC;
338+
ecd_flags = scb_o->ecd & vcpu->arch.sie_block->ecd &
339+
(ECD_ECC | ECD_HMAC);
339340
if (!ecb3_flags && !ecd_flags)
340341
goto end;
341342

arch/s390/tools/gen_facilities.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ static struct facility_def facility_defs[] = {
109109
15, /* AP Facilities Test */
110110
156, /* etoken facility */
111111
165, /* nnpa facility */
112+
170, /* ineffective-nonconstrained-transaction facility */
112113
193, /* bear enhancement facility */
113114
194, /* rdp enhancement facility */
114115
196, /* processor activity instrumentation facility */
115116
197, /* processor activity instrumentation extension 1 */
117+
201, /* concurrent-functions facility */
116118
-1 /* END */
117119
}
118120
},

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ struct kvm_s390_vm_cpu_subfunc {
469469
__u8 kdsa[16]; /* with MSA9 */
470470
__u8 sortl[32]; /* with STFLE.150 */
471471
__u8 dfltcc[32]; /* with STFLE.151 */
472-
__u8 reserved[1728];
472+
__u8 pfcr[16]; /* with STFLE.201 */
473+
__u8 reserved[1712];
473474
};
474475

475476
#define KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST 6

tools/testing/selftests/kvm/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ LIBKVM_aarch64 += lib/aarch64/vgic.c
5555
LIBKVM_s390x += lib/s390x/diag318_test_handler.c
5656
LIBKVM_s390x += lib/s390x/processor.c
5757
LIBKVM_s390x += lib/s390x/ucall.c
58+
LIBKVM_s390x += lib/s390x/facility.c
5859

5960
LIBKVM_riscv += lib/riscv/handlers.S
6061
LIBKVM_riscv += lib/riscv/processor.c
@@ -189,6 +190,7 @@ TEST_GEN_PROGS_s390x += s390x/sync_regs_test
189190
TEST_GEN_PROGS_s390x += s390x/tprot
190191
TEST_GEN_PROGS_s390x += s390x/cmma_test
191192
TEST_GEN_PROGS_s390x += s390x/debug_test
193+
TEST_GEN_PROGS_s390x += s390x/cpumodel_subfuncs_test
192194
TEST_GEN_PROGS_s390x += s390x/shared_zeropage_test
193195
TEST_GEN_PROGS_s390x += s390x/ucontrol_test
194196
TEST_GEN_PROGS_s390x += demand_paging_test
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copyright IBM Corp. 2024
4+
*
5+
* Authors:
6+
* Hariharan Mari <[email protected]>
7+
*
8+
* Get the facility bits with the STFLE instruction
9+
*/
10+
11+
#ifndef SELFTEST_KVM_FACILITY_H
12+
#define SELFTEST_KVM_FACILITY_H
13+
14+
#include <linux/bitops.h>
15+
16+
/* alt_stfle_fac_list[16] + stfle_fac_list[16] */
17+
#define NB_STFL_DOUBLEWORDS 32
18+
19+
extern uint64_t stfl_doublewords[NB_STFL_DOUBLEWORDS];
20+
extern bool stfle_flag;
21+
22+
static inline bool test_bit_inv(unsigned long nr, const unsigned long *ptr)
23+
{
24+
return test_bit(nr ^ (BITS_PER_LONG - 1), ptr);
25+
}
26+
27+
static inline void stfle(uint64_t *fac, unsigned int nb_doublewords)
28+
{
29+
register unsigned long r0 asm("0") = nb_doublewords - 1;
30+
31+
asm volatile(" .insn s,0xb2b00000,0(%1)\n"
32+
: "+d" (r0)
33+
: "a" (fac)
34+
: "memory", "cc");
35+
}
36+
37+
static inline void setup_facilities(void)
38+
{
39+
stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS);
40+
stfle_flag = true;
41+
}
42+
43+
static inline bool test_facility(int nr)
44+
{
45+
if (!stfle_flag)
46+
setup_facilities();
47+
return test_bit_inv(nr, stfl_doublewords);
48+
}
49+
50+
#endif

tools/testing/selftests/kvm/include/s390x/processor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@ static inline void cpu_relax(void)
3232
barrier();
3333
}
3434

35+
/* Get the instruction length */
36+
static inline int insn_length(unsigned char code)
37+
{
38+
return ((((int)code + 64) >> 7) + 1) << 1;
39+
}
40+
3541
#endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright IBM Corp. 2024
4+
*
5+
* Authors:
6+
* Hariharan Mari <[email protected]>
7+
*
8+
* Contains the definition for the global variables to have the test facitlity feature.
9+
*/
10+
11+
#include "facility.h"
12+
13+
uint64_t stfl_doublewords[NB_STFL_DOUBLEWORDS];
14+
bool stfle_flag;

0 commit comments

Comments
 (0)