Skip to content

Commit 1856475

Browse files
hcahcaAlexander Gordeev
authored andcommitted
s390/fpu: get rid of MACHINE_HAS_VX
Get rid of MACHINE_HAS_VX and replace it with cpu_has_vx() which is a short readable wrapper for "test_facility(129)". Facility bit 129 is set if the vector facility is present. test_facility() returns also true for all bits which are set in the architecture level set of the cpu that the kernel is compiled for. This means that test_facility(129) is a compile time constant which returns true for z13 and later, since the vector facility bit is part of the z13 kernel ALS. In result the compiled code will have less runtime checks, and less code. Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
1 parent 68422c0 commit 1856475

19 files changed

Lines changed: 64 additions & 54 deletions

File tree

arch/s390/crypto/chacha-glue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src,
8282
* it cannot handle a block of data or less, but otherwise
8383
* it can handle data of arbitrary size
8484
*/
85-
if (bytes <= CHACHA_BLOCK_SIZE || nrounds != 20 || !MACHINE_HAS_VX)
85+
if (bytes <= CHACHA_BLOCK_SIZE || nrounds != 20 || !cpu_has_vx())
8686
chacha_crypt_generic(state, dst, src, bytes, nrounds);
8787
else
8888
chacha20_crypt_s390(state, dst, src, bytes,

arch/s390/include/asm/fpu/api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
#include <linux/preempt.h>
4848
#include <asm/asm-extable.h>
49+
#include <asm/fpu/internal.h>
4950

5051
void save_fpu_regs(void);
5152
void load_fpu_regs(void);

arch/s390/include/asm/fpu/internal.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010
#define _ASM_S390_FPU_INTERNAL_H
1111

1212
#include <linux/string.h>
13+
#include <asm/facility.h>
1314
#include <asm/fpu/types.h>
1415

16+
static inline bool cpu_has_vx(void)
17+
{
18+
return likely(test_facility(129));
19+
}
20+
1521
static inline void save_vx_regs(__vector128 *vxrs)
1622
{
1723
asm volatile(
@@ -41,7 +47,7 @@ static inline void fpregs_store(_s390_fp_regs *fpregs, struct fpu *fpu)
4147
{
4248
fpregs->pad = 0;
4349
fpregs->fpc = fpu->fpc;
44-
if (MACHINE_HAS_VX)
50+
if (cpu_has_vx())
4551
convert_vx_to_fp((freg_t *)&fpregs->fprs, fpu->vxrs);
4652
else
4753
memcpy((freg_t *)&fpregs->fprs, fpu->fprs,
@@ -51,7 +57,7 @@ static inline void fpregs_store(_s390_fp_regs *fpregs, struct fpu *fpu)
5157
static inline void fpregs_load(_s390_fp_regs *fpregs, struct fpu *fpu)
5258
{
5359
fpu->fpc = fpregs->fpc;
54-
if (MACHINE_HAS_VX)
60+
if (cpu_has_vx())
5561
convert_fp_to_vx(fpu->vxrs, (freg_t *)&fpregs->fprs);
5662
else
5763
memcpy(fpu->fprs, (freg_t *)&fpregs->fprs,

arch/s390/include/asm/setup.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#define MACHINE_FLAG_TOPOLOGY BIT(10)
2929
#define MACHINE_FLAG_TE BIT(11)
3030
#define MACHINE_FLAG_TLB_LC BIT(12)
31-
#define MACHINE_FLAG_VX BIT(13)
3231
#define MACHINE_FLAG_TLB_GUEST BIT(14)
3332
#define MACHINE_FLAG_NX BIT(15)
3433
#define MACHINE_FLAG_GS BIT(16)
@@ -90,7 +89,6 @@ extern unsigned long mio_wb_bit_mask;
9089
#define MACHINE_HAS_TOPOLOGY (S390_lowcore.machine_flags & MACHINE_FLAG_TOPOLOGY)
9190
#define MACHINE_HAS_TE (S390_lowcore.machine_flags & MACHINE_FLAG_TE)
9291
#define MACHINE_HAS_TLB_LC (S390_lowcore.machine_flags & MACHINE_FLAG_TLB_LC)
93-
#define MACHINE_HAS_VX (S390_lowcore.machine_flags & MACHINE_FLAG_VX)
9492
#define MACHINE_HAS_TLB_GUEST (S390_lowcore.machine_flags & MACHINE_FLAG_TLB_GUEST)
9593
#define MACHINE_HAS_NX (S390_lowcore.machine_flags & MACHINE_FLAG_NX)
9694
#define MACHINE_HAS_GS (S390_lowcore.machine_flags & MACHINE_FLAG_GS)

arch/s390/kernel/compat_signal.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <asm/lowcore.h>
3030
#include <asm/switch_to.h>
3131
#include <asm/vdso.h>
32+
#include <asm/fpu/api.h>
3233
#include "compat_linux.h"
3334
#include "compat_ptrace.h"
3435
#include "entry.h"
@@ -133,7 +134,7 @@ static int save_sigregs_ext32(struct pt_regs *regs,
133134
return -EFAULT;
134135

135136
/* Save vector registers to signal stack */
136-
if (MACHINE_HAS_VX) {
137+
if (cpu_has_vx()) {
137138
for (i = 0; i < __NUM_VXRS_LOW; i++)
138139
vxrs[i] = current->thread.fpu.vxrs[i].low;
139140
if (__copy_to_user(&sregs_ext->vxrs_low, vxrs,
@@ -161,7 +162,7 @@ static int restore_sigregs_ext32(struct pt_regs *regs,
161162
*(__u32 *)&regs->gprs[i] = gprs_high[i];
162163

163164
/* Restore vector registers from signal stack */
164-
if (MACHINE_HAS_VX) {
165+
if (cpu_has_vx()) {
165166
if (__copy_from_user(vxrs, &sregs_ext->vxrs_low,
166167
sizeof(sregs_ext->vxrs_low)) ||
167168
__copy_from_user(current->thread.fpu.vxrs + __NUM_VXRS_LOW,
@@ -261,7 +262,7 @@ static int setup_frame32(struct ksignal *ksig, sigset_t *set,
261262
* the machine supports it
262263
*/
263264
frame_size = sizeof(*frame) - sizeof(frame->sregs_ext.__reserved);
264-
if (!MACHINE_HAS_VX)
265+
if (!cpu_has_vx())
265266
frame_size -= sizeof(frame->sregs_ext.vxrs_low) +
266267
sizeof(frame->sregs_ext.vxrs_high);
267268
frame = get_sigframe(&ksig->ka, regs, frame_size);
@@ -344,11 +345,12 @@ static int setup_rt_frame32(struct ksignal *ksig, sigset_t *set,
344345
* the machine supports it
345346
*/
346347
uc_flags = UC_GPRS_HIGH;
347-
if (MACHINE_HAS_VX) {
348+
if (cpu_has_vx()) {
348349
uc_flags |= UC_VXRS;
349-
} else
350+
} else {
350351
frame_size -= sizeof(frame->uc.uc_mcontext_ext.vxrs_low) +
351352
sizeof(frame->uc.uc_mcontext_ext.vxrs_high);
353+
}
352354
frame = get_sigframe(&ksig->ka, regs, frame_size);
353355
if (frame == (void __user *) -1UL)
354356
return -EFAULT;

arch/s390/kernel/crash_dump.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <asm/ipl.h>
2323
#include <asm/sclp.h>
2424
#include <asm/maccess.h>
25+
#include <asm/fpu/api.h>
2526

2627
#define PTR_ADD(x, y) (((char *) (x)) + ((unsigned long) (y)))
2728
#define PTR_SUB(x, y) (((char *) (x)) - ((unsigned long) (y)))
@@ -319,7 +320,7 @@ static void *fill_cpu_elf_notes(void *ptr, int cpu, struct save_area *sa)
319320
ptr = nt_init(ptr, NT_S390_TODPREG, &sa->todpreg, sizeof(sa->todpreg));
320321
ptr = nt_init(ptr, NT_S390_CTRS, &sa->ctrs, sizeof(sa->ctrs));
321322
ptr = nt_init(ptr, NT_S390_PREFIX, &sa->prefix, sizeof(sa->prefix));
322-
if (MACHINE_HAS_VX) {
323+
if (cpu_has_vx()) {
323324
ptr = nt_init(ptr, NT_S390_VXRS_HIGH,
324325
&sa->vxrs_high, sizeof(sa->vxrs_high));
325326
ptr = nt_init(ptr, NT_S390_VXRS_LOW,
@@ -343,7 +344,7 @@ static size_t get_cpu_elf_notes_size(void)
343344
size += nt_size(NT_S390_TODPREG, sizeof(sa->todpreg));
344345
size += nt_size(NT_S390_CTRS, sizeof(sa->ctrs));
345346
size += nt_size(NT_S390_PREFIX, sizeof(sa->prefix));
346-
if (MACHINE_HAS_VX) {
347+
if (cpu_has_vx()) {
347348
size += nt_size(NT_S390_VXRS_HIGH, sizeof(sa->vxrs_high));
348349
size += nt_size(NT_S390_VXRS_LOW, sizeof(sa->vxrs_low));
349350
}

arch/s390/kernel/early.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,8 @@ static __init void detect_machine_facilities(void)
229229
}
230230
if (test_facility(51))
231231
S390_lowcore.machine_flags |= MACHINE_FLAG_TLB_LC;
232-
if (test_facility(129)) {
233-
S390_lowcore.machine_flags |= MACHINE_FLAG_VX;
232+
if (test_facility(129))
234233
system_ctl_set_bit(0, CR0_VECTOR_BIT);
235-
}
236234
if (test_facility(130))
237235
S390_lowcore.machine_flags |= MACHINE_FLAG_NX;
238236
if (test_facility(133))

arch/s390/kernel/fpu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void __kernel_fpu_begin(struct kernel_fpu *state, u32 flags)
2424
/* Save floating point control */
2525
asm volatile("stfpc %0" : "=Q" (state->fpc));
2626

27-
if (!MACHINE_HAS_VX) {
27+
if (!cpu_has_vx()) {
2828
if (flags & KERNEL_VXR_V0V7) {
2929
/* Save floating-point registers */
3030
asm volatile("std 0,%0" : "=Q" (state->fprs[0]));
@@ -106,7 +106,7 @@ void __kernel_fpu_end(struct kernel_fpu *state, u32 flags)
106106
/* Restore floating-point controls */
107107
asm volatile("lfpc %0" : : "Q" (state->fpc));
108108

109-
if (!MACHINE_HAS_VX) {
109+
if (!cpu_has_vx()) {
110110
if (flags & KERNEL_VXR_V0V7) {
111111
/* Restore floating-point registers */
112112
asm volatile("ld 0,%0" : : "Q" (state->fprs[0]));
@@ -181,7 +181,7 @@ void __load_fpu_regs(void)
181181
struct fpu *state = &current->thread.fpu;
182182

183183
sfpc_safe(state->fpc);
184-
if (likely(MACHINE_HAS_VX)) {
184+
if (likely(cpu_has_vx())) {
185185
asm volatile("lgr 1,%0\n"
186186
"VLM 0,15,0,1\n"
187187
"VLM 16,31,256,1\n"
@@ -232,7 +232,7 @@ void save_fpu_regs(void)
232232
regs = current->thread.fpu.regs;
233233

234234
asm volatile("stfpc %0" : "=Q" (state->fpc));
235-
if (likely(MACHINE_HAS_VX)) {
235+
if (likely(cpu_has_vx())) {
236236
asm volatile("lgr 1,%0\n"
237237
"VSTM 0,15,0,1\n"
238238
"VSTM 16,31,256,1\n"

arch/s390/kernel/machine_kexec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static noinline void __machine_kdump(void *image)
9191
}
9292
/* Store status of the boot CPU */
9393
mcesa = __va(S390_lowcore.mcesad & MCESA_ORIGIN_MASK);
94-
if (MACHINE_HAS_VX)
94+
if (cpu_has_vx())
9595
save_vx_regs((__vector128 *) mcesa->vector_save_area);
9696
if (MACHINE_HAS_GS) {
9797
local_ctl_store(2, &cr2_old.reg);

arch/s390/kernel/nmi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <asm/asm-offsets.h>
3333
#include <asm/pai.h>
3434
#include <asm/vx-insn.h>
35+
#include <asm/fpu/api.h>
3536

3637
struct mcck_struct {
3738
unsigned int kill_task : 1;
@@ -45,7 +46,7 @@ static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck);
4546

4647
static inline int nmi_needs_mcesa(void)
4748
{
48-
return MACHINE_HAS_VX || MACHINE_HAS_GS;
49+
return cpu_has_vx() || MACHINE_HAS_GS;
4950
}
5051

5152
/*
@@ -235,7 +236,7 @@ static int notrace s390_validate_registers(union mci mci)
235236
}
236237

237238
mcesa = __va(S390_lowcore.mcesad & MCESA_ORIGIN_MASK);
238-
if (!MACHINE_HAS_VX) {
239+
if (!cpu_has_vx()) {
239240
/* Validate floating point registers */
240241
asm volatile(
241242
" ld 0,0(%0)\n"

0 commit comments

Comments
 (0)