Skip to content

Commit 14375bc

Browse files
Martin SchwidefskyMartin Schwidefsky
authored andcommitted
[S390] cleanup facility list handling
Store the facility list once at system startup with stfl/stfle and reuse the result for all facility tests. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent eca577e commit 14375bc

12 files changed

Lines changed: 66 additions & 74 deletions

File tree

‎arch/s390/crypto/crypt_s390.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static inline int crypt_s390_func_available(int func)
297297
int ret;
298298

299299
/* check if CPACF facility (bit 17) is available */
300-
if (!(stfl() & 1ULL << (31 - 17)))
300+
if (!test_facility(17))
301301
return 0;
302302

303303
switch (func & CRYPT_S390_OP_MASK) {

‎arch/s390/include/asm/lowcore.h‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ struct _lowcore {
150150
*/
151151
__u32 ipib; /* 0x0e00 */
152152
__u32 ipib_checksum; /* 0x0e04 */
153+
__u8 pad_0x0e08[0x0f00-0x0e08]; /* 0x0e08 */
153154

154-
/* Align to the top 1k of prefix area */
155-
__u8 pad_0x0e08[0x1000-0x0e08]; /* 0x0e08 */
155+
/* Extended facility list */
156+
__u64 stfle_fac_list[32]; /* 0x0f00 */
156157
} __packed;
157158

158159
#else /* CONFIG_32BIT */
@@ -285,7 +286,11 @@ struct _lowcore {
285286
*/
286287
__u64 ipib; /* 0x0e00 */
287288
__u32 ipib_checksum; /* 0x0e08 */
288-
__u8 pad_0x0e0c[0x11b8-0x0e0c]; /* 0x0e0c */
289+
__u8 pad_0x0e0c[0x0f00-0x0e0c]; /* 0x0e0c */
290+
291+
/* Extended facility list */
292+
__u64 stfle_fac_list[32]; /* 0x0f00 */
293+
__u8 pad_0x1000[0x11b8-0x1000]; /* 0x1000 */
289294

290295
/* 64 bit extparam used for pfault/diag 250: defined by architecture */
291296
__u64 ext_params2; /* 0x11B8 */

‎arch/s390/include/asm/system.h‎

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -420,30 +420,21 @@ extern void smp_ctl_clear_bit(int cr, int bit);
420420

421421
#endif /* CONFIG_SMP */
422422

423-
static inline unsigned int stfl(void)
424-
{
425-
asm volatile(
426-
" .insn s,0xb2b10000,0(0)\n" /* stfl */
427-
"0:\n"
428-
EX_TABLE(0b,0b));
429-
return S390_lowcore.stfl_fac_list;
430-
}
423+
#define MAX_FACILITY_BIT (256*8) /* stfle_fac_list has 256 bytes */
431424

432-
static inline int __stfle(unsigned long long *list, int doublewords)
425+
/*
426+
* The test_facility function uses the bit odering where the MSB is bit 0.
427+
* That makes it easier to query facility bits with the bit number as
428+
* documented in the Principles of Operation.
429+
*/
430+
static inline int test_facility(unsigned long nr)
433431
{
434-
typedef struct { unsigned long long _[doublewords]; } addrtype;
435-
register unsigned long __nr asm("0") = doublewords - 1;
436-
437-
asm volatile(".insn s,0xb2b00000,%0" /* stfle */
438-
: "=m" (*(addrtype *) list), "+d" (__nr) : : "cc");
439-
return __nr + 1;
440-
}
432+
unsigned char *ptr;
441433

442-
static inline int stfle(unsigned long long *list, int doublewords)
443-
{
444-
if (!(stfl() & (1UL << 24)))
445-
return -EOPNOTSUPP;
446-
return __stfle(list, doublewords);
434+
if (nr >= MAX_FACILITY_BIT)
435+
return 0;
436+
ptr = (unsigned char *) &S390_lowcore.stfle_fac_list + (nr >> 3);
437+
return (*ptr & (0x80 >> (nr & 7))) != 0;
447438
}
448439

449440
static inline unsigned short stap(void)

‎arch/s390/kernel/early.c‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,35 @@ static noinline __init void setup_lowcore_early(void)
256256
s390_base_pgm_handler_fn = early_pgm_check_handler;
257257
}
258258

259+
static noinline __init void setup_facility_list(void)
260+
{
261+
unsigned long nr;
262+
263+
S390_lowcore.stfl_fac_list = 0;
264+
asm volatile(
265+
" .insn s,0xb2b10000,0(0)\n" /* stfl */
266+
"0:\n"
267+
EX_TABLE(0b,0b) : "=m" (S390_lowcore.stfl_fac_list));
268+
memcpy(&S390_lowcore.stfle_fac_list, &S390_lowcore.stfl_fac_list, 4);
269+
nr = 4; /* # bytes stored by stfl */
270+
if (test_facility(7)) {
271+
/* More facility bits available with stfle */
272+
register unsigned long reg0 asm("0") = MAX_FACILITY_BIT/64 - 1;
273+
asm volatile(".insn s,0xb2b00000,%0" /* stfle */
274+
: "=m" (S390_lowcore.stfle_fac_list), "+d" (reg0)
275+
: : "cc");
276+
nr = (reg0 + 1) * 8; /* # bytes stored by stfle */
277+
}
278+
memset((char *) S390_lowcore.stfle_fac_list + nr, 0,
279+
MAX_FACILITY_BIT/8 - nr);
280+
}
281+
259282
static noinline __init void setup_hpage(void)
260283
{
261284
#ifndef CONFIG_DEBUG_PAGEALLOC
262285
unsigned int facilities;
263286

264-
facilities = stfl();
265-
if (!(facilities & (1UL << 23)) || !(facilities & (1UL << 29)))
287+
if (!test_facility(2) || !test_facility(8))
266288
return;
267289
S390_lowcore.machine_flags |= MACHINE_FLAG_HPAGE;
268290
__ctl_set_bit(0, 23);
@@ -356,18 +378,13 @@ static __init void detect_diag44(void)
356378
static __init void detect_machine_facilities(void)
357379
{
358380
#ifdef CONFIG_64BIT
359-
unsigned int facilities;
360-
unsigned long long facility_bits;
361-
362-
facilities = stfl();
363-
if (facilities & (1 << 28))
381+
if (test_facility(3))
364382
S390_lowcore.machine_flags |= MACHINE_FLAG_IDTE;
365-
if (facilities & (1 << 23))
383+
if (test_facility(8))
366384
S390_lowcore.machine_flags |= MACHINE_FLAG_PFMF;
367-
if (facilities & (1 << 4))
385+
if (test_facility(27))
368386
S390_lowcore.machine_flags |= MACHINE_FLAG_MVCOS;
369-
if ((stfle(&facility_bits, 1) > 0) &&
370-
(facility_bits & (1ULL << (63 - 40))))
387+
if (test_facility(40))
371388
S390_lowcore.machine_flags |= MACHINE_FLAG_SPP;
372389
#endif
373390
}
@@ -448,6 +465,7 @@ void __init startup_init(void)
448465
lockdep_off();
449466
sort_main_extable();
450467
setup_lowcore_early();
468+
setup_facility_list();
451469
detect_machine_type();
452470
ipl_update_parameters();
453471
setup_boot_command_line();

‎arch/s390/kernel/setup.c‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ setup_lowcore(void)
409409
lc->current_task = (unsigned long) init_thread_union.thread_info.task;
410410
lc->thread_info = (unsigned long) &init_thread_union;
411411
lc->machine_flags = S390_lowcore.machine_flags;
412+
lc->stfl_fac_list = S390_lowcore.stfl_fac_list;
413+
memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list,
414+
MAX_FACILITY_BIT/8);
412415
#ifndef CONFIG_64BIT
413416
if (MACHINE_HAS_IEEE) {
414417
lc->extended_save_area_addr = (__u32)
@@ -675,12 +678,9 @@ setup_memory(void)
675678
static void __init setup_hwcaps(void)
676679
{
677680
static const int stfl_bits[6] = { 0, 2, 7, 17, 19, 21 };
678-
unsigned long long facility_list_extended;
679-
unsigned int facility_list;
680681
struct cpuid cpu_id;
681682
int i;
682683

683-
facility_list = stfl();
684684
/*
685685
* The store facility list bits numbers as found in the principles
686686
* of operation are numbered with bit 1UL<<31 as number 0 to
@@ -700,11 +700,10 @@ static void __init setup_hwcaps(void)
700700
* HWCAP_S390_ETF3EH bit 8 (22 && 30).
701701
*/
702702
for (i = 0; i < 6; i++)
703-
if (facility_list & (1UL << (31 - stfl_bits[i])))
703+
if (test_facility(stfl_bits[i]))
704704
elf_hwcap |= 1UL << i;
705705

706-
if ((facility_list & (1UL << (31 - 22)))
707-
&& (facility_list & (1UL << (31 - 30))))
706+
if (test_facility(22) && test_facility(30))
708707
elf_hwcap |= HWCAP_S390_ETF3EH;
709708

710709
/*
@@ -720,12 +719,8 @@ static void __init setup_hwcaps(void)
720719
* translated to:
721720
* HWCAP_S390_DFP bit 6 (42 && 44).
722721
*/
723-
if ((elf_hwcap & (1UL << 2)) &&
724-
__stfle(&facility_list_extended, 1) > 0) {
725-
if ((facility_list_extended & (1ULL << (63 - 42)))
726-
&& (facility_list_extended & (1ULL << (63 - 44))))
727-
elf_hwcap |= HWCAP_S390_DFP;
728-
}
722+
if ((elf_hwcap & (1UL << 2)) && test_facility(42) && test_facility(44))
723+
elf_hwcap |= HWCAP_S390_DFP;
729724

730725
/*
731726
* Huge page support HWCAP_S390_HPAGE is bit 7.

‎arch/s390/kernel/smp.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ int __cpuinit __cpu_up(unsigned int cpu)
594594
cpu_lowcore->kernel_asce = S390_lowcore.kernel_asce;
595595
cpu_lowcore->machine_flags = S390_lowcore.machine_flags;
596596
cpu_lowcore->ftrace_func = S390_lowcore.ftrace_func;
597+
memcpy(cpu_lowcore->stfle_fac_list, S390_lowcore.stfle_fac_list,
598+
MAX_FACILITY_BIT/8);
597599
eieio();
598600

599601
while (sigp(cpu, sigp_restart) == sigp_busy)

‎arch/s390/kernel/topology.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,10 @@ static void alloc_masks(struct tl_info *info, struct mask_info *mask, int offset
351351

352352
void __init s390_init_cpu_topology(void)
353353
{
354-
unsigned long long facility_bits;
355354
struct tl_info *info;
356355
int i;
357356

358-
if (stfle(&facility_bits, 1) <= 0)
359-
return;
360-
if (!(facility_bits & (1ULL << 52)) || !(facility_bits & (1ULL << 61)))
357+
if (!test_facility(2) || !test_facility(11))
361358
return;
362359
machine_has_topology = 1;
363360

‎arch/s390/kernel/vdso.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ struct vdso_data *vdso_data = &vdso_data_store.data;
8484
*/
8585
static void vdso_init_data(struct vdso_data *vd)
8686
{
87-
unsigned int facility_list;
88-
89-
facility_list = stfl();
90-
vd->ectg_available =
91-
user_mode != HOME_SPACE_MODE && (facility_list & 1);
87+
vd->ectg_available = user_mode != HOME_SPACE_MODE && test_facility(31);
9288
}
9389

9490
#ifdef CONFIG_64BIT

‎arch/s390/kvm/kvm-s390.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ static int __init kvm_s390_init(void)
740740
kvm_exit();
741741
return -ENOMEM;
742742
}
743-
stfle(facilities, 1);
743+
memcpy(facilities, S390_lowcore.stfle_fac_list, 16);
744744
facilities[0] &= 0xff00fff3f47c0000ULL;
745745
return 0;
746746
}

‎arch/s390/kvm/priv.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ static int handle_chsc(struct kvm_vcpu *vcpu)
154154

155155
static int handle_stfl(struct kvm_vcpu *vcpu)
156156
{
157-
unsigned int facility_list = stfl();
157+
unsigned int facility_list;
158158
int rc;
159159

160160
vcpu->stat.instruction_stfl++;
161161
/* only pass the facility bits, which we can handle */
162-
facility_list &= 0xff00fff3;
162+
facility_list = S390_lowcore.stfl_fac_list & 0xff00fff3;
163163

164164
rc = copy_to_guest(vcpu, offsetof(struct _lowcore, stfl_fac_list),
165165
&facility_list, sizeof(facility_list));

0 commit comments

Comments
 (0)