Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/cpufeature: Convert MACHINE_HAS_GS to cpu_has_gs()

Convert MACHINE_HAS_... to cpu_has_...() which uses test_facility() instead
of testing the machine_flags lowcore member if the feature is present.

test_facility() generates better code since it results in a static branch
without accessing memory. The branch is patched via alternatives by the
decompressor depending on the availability of the required facility.

Reviewed-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>

authored by

Heiko Carstens and committed by
Vasily Gorbik
42805261 15a36036

+26 -21
+1
arch/s390/include/asm/cpufeature.h
··· 22 22 23 23 int cpu_have_feature(unsigned int nr); 24 24 25 + #define cpu_has_gs() test_facility(133) 25 26 #define cpu_has_rdp() test_facility(194) 26 27 #define cpu_has_seq_insn() test_facility(85) 27 28
-2
arch/s390/include/asm/setup.h
··· 30 30 #define MACHINE_FLAG_TLB_LC BIT(12) 31 31 #define MACHINE_FLAG_TLB_GUEST BIT(14) 32 32 #define MACHINE_FLAG_NX BIT(15) 33 - #define MACHINE_FLAG_GS BIT(16) 34 33 #define MACHINE_FLAG_SCC BIT(17) 35 34 #define MACHINE_FLAG_PCI_MIO BIT(18) 36 35 ··· 89 90 #define MACHINE_HAS_TLB_LC (get_lowcore()->machine_flags & MACHINE_FLAG_TLB_LC) 90 91 #define MACHINE_HAS_TLB_GUEST (get_lowcore()->machine_flags & MACHINE_FLAG_TLB_GUEST) 91 92 #define MACHINE_HAS_NX (get_lowcore()->machine_flags & MACHINE_FLAG_NX) 92 - #define MACHINE_HAS_GS (get_lowcore()->machine_flags & MACHINE_FLAG_GS) 93 93 #define MACHINE_HAS_SCC (get_lowcore()->machine_flags & MACHINE_FLAG_SCC) 94 94 #define MACHINE_HAS_PCI_MIO (get_lowcore()->machine_flags & MACHINE_FLAG_PCI_MIO) 95 95
-2
arch/s390/kernel/early.c
··· 255 255 system_ctl_set_bit(0, CR0_VECTOR_BIT); 256 256 if (test_facility(130)) 257 257 get_lowcore()->machine_flags |= MACHINE_FLAG_NX; 258 - if (test_facility(133)) 259 - get_lowcore()->machine_flags |= MACHINE_FLAG_GS; 260 258 if (test_facility(139) && (tod_clock_base.tod >> 63)) { 261 259 /* Enabled signed clock comparator comparisons */ 262 260 get_lowcore()->machine_flags |= MACHINE_FLAG_SCC;
+2 -1
arch/s390/kernel/guarded_storage.c
··· 4 4 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com> 5 5 */ 6 6 7 + #include <linux/cpufeature.h> 7 8 #include <linux/kernel.h> 8 9 #include <linux/syscalls.h> 9 10 #include <linux/signal.h> ··· 110 109 SYSCALL_DEFINE2(s390_guarded_storage, int, command, 111 110 struct gs_cb __user *, gs_cb) 112 111 { 113 - if (!MACHINE_HAS_GS) 112 + if (!cpu_has_gs()) 114 113 return -EOPNOTSUPP; 115 114 switch (command) { 116 115 case GS_ENABLE:
+2 -1
arch/s390/kernel/machine_kexec.c
··· 13 13 #include <linux/reboot.h> 14 14 #include <linux/ftrace.h> 15 15 #include <linux/debug_locks.h> 16 + #include <linux/cpufeature.h> 16 17 #include <asm/guarded_storage.h> 17 18 #include <asm/pfault.h> 18 19 #include <asm/cio.h> ··· 95 94 mcesa = __va(get_lowcore()->mcesad & MCESA_ORIGIN_MASK); 96 95 if (cpu_has_vx()) 97 96 save_vx_regs((__vector128 *) mcesa->vector_save_area); 98 - if (MACHINE_HAS_GS) { 97 + if (cpu_has_gs()) { 99 98 local_ctl_store(2, &cr2_old.reg); 100 99 cr2_new = cr2_old; 101 100 cr2_new.gse = 1;
+5 -4
arch/s390/kernel/nmi.c
··· 9 9 */ 10 10 11 11 #include <linux/kernel_stat.h> 12 + #include <linux/cpufeature.h> 12 13 #include <linux/init.h> 13 14 #include <linux/errno.h> 14 15 #include <linux/entry-common.h> ··· 46 45 47 46 static inline int nmi_needs_mcesa(void) 48 47 { 49 - return cpu_has_vx() || MACHINE_HAS_GS; 48 + return cpu_has_vx() || cpu_has_gs(); 50 49 } 51 50 52 51 /* ··· 62 61 if (!nmi_needs_mcesa()) 63 62 return; 64 63 *mcesad = __pa(&boot_mcesa); 65 - if (MACHINE_HAS_GS) 64 + if (cpu_has_gs()) 66 65 *mcesad |= ilog2(MCESA_MAX_SIZE); 67 66 } 68 67 ··· 74 73 *mcesad = 0; 75 74 if (!nmi_needs_mcesa()) 76 75 return 0; 77 - size = MACHINE_HAS_GS ? MCESA_MAX_SIZE : MCESA_MIN_SIZE; 76 + size = cpu_has_gs() ? MCESA_MAX_SIZE : MCESA_MIN_SIZE; 78 77 origin = kmalloc(size, GFP_KERNEL); 79 78 if (!origin) 80 79 return -ENOMEM; 81 80 /* The pointer is stored with mcesa_bits ORed in */ 82 81 kmemleak_not_leak(origin); 83 82 *mcesad = __pa(origin); 84 - if (MACHINE_HAS_GS) 83 + if (cpu_has_gs()) 85 84 *mcesad |= ilog2(MCESA_MAX_SIZE); 86 85 return 0; 87 86 }
+2 -1
arch/s390/kernel/processor.c
··· 8 8 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 9 9 10 10 #include <linux/stop_machine.h> 11 + #include <linux/cpufeature.h> 11 12 #include <linux/bitops.h> 12 13 #include <linux/kernel.h> 13 14 #include <linux/random.h> ··· 245 244 elf_hwcap |= HWCAP_NNPA; 246 245 247 246 /* guarded storage */ 248 - if (MACHINE_HAS_GS) 247 + if (cpu_has_gs()) 249 248 elf_hwcap |= HWCAP_GS; 250 249 251 250 if (MACHINE_HAS_PCI_MIO)
+6 -5
arch/s390/kernel/ptrace.c
··· 11 11 #include <linux/kernel.h> 12 12 #include <linux/sched.h> 13 13 #include <linux/sched/task_stack.h> 14 + #include <linux/cpufeature.h> 14 15 #include <linux/mm.h> 15 16 #include <linux/smp.h> 16 17 #include <linux/errno.h> ··· 76 75 } 77 76 } 78 77 /* Take care of enable/disable of guarded storage. */ 79 - if (MACHINE_HAS_GS) { 78 + if (cpu_has_gs()) { 80 79 cr2_new.gse = 0; 81 80 if (task->thread.gs_cb) 82 81 cr2_new.gse = 1; ··· 1034 1033 { 1035 1034 struct gs_cb *data = target->thread.gs_cb; 1036 1035 1037 - if (!MACHINE_HAS_GS) 1036 + if (!cpu_has_gs()) 1038 1037 return -ENODEV; 1039 1038 if (!data) 1040 1039 return -ENODATA; ··· 1051 1050 struct gs_cb gs_cb = { }, *data = NULL; 1052 1051 int rc; 1053 1052 1054 - if (!MACHINE_HAS_GS) 1053 + if (!cpu_has_gs()) 1055 1054 return -ENODEV; 1056 1055 if (!target->thread.gs_cb) { 1057 1056 data = kzalloc(sizeof(*data), GFP_KERNEL); ··· 1088 1087 { 1089 1088 struct gs_cb *data = target->thread.gs_bc_cb; 1090 1089 1091 - if (!MACHINE_HAS_GS) 1090 + if (!cpu_has_gs()) 1092 1091 return -ENODEV; 1093 1092 if (!data) 1094 1093 return -ENODATA; ··· 1102 1101 { 1103 1102 struct gs_cb *data = target->thread.gs_bc_cb; 1104 1103 1105 - if (!MACHINE_HAS_GS) 1104 + if (!cpu_has_gs()) 1106 1105 return -ENODEV; 1107 1106 if (!data) { 1108 1107 data = kzalloc(sizeof(*data), GFP_KERNEL);
+3 -2
arch/s390/kernel/smp.c
··· 18 18 #define KMSG_COMPONENT "cpu" 19 19 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 20 20 21 + #include <linux/cpufeature.h> 21 22 #include <linux/workqueue.h> 22 23 #include <linux/memblock.h> 23 24 #include <linux/export.h> ··· 562 561 if (__pcpu_sigp_relax(pcpu->address, SIGP_STORE_STATUS_AT_ADDRESS, 563 562 pa) != SIGP_CC_ORDER_CODE_ACCEPTED) 564 563 return -EIO; 565 - if (!cpu_has_vx() && !MACHINE_HAS_GS) 564 + if (!cpu_has_vx() && !cpu_has_gs()) 566 565 return 0; 567 566 pa = lc->mcesad & MCESA_ORIGIN_MASK; 568 - if (MACHINE_HAS_GS) 567 + if (cpu_has_gs()) 569 568 pa |= lc->mcesad & MCESA_LC_MASK; 570 569 if (__pcpu_sigp_relax(pcpu->address, SIGP_STORE_ADDITIONAL_STATUS, 571 570 pa) != SIGP_CC_ORDER_CODE_ACCEPTED)
+2 -1
arch/s390/kvm/interrupt.c
··· 10 10 #define KMSG_COMPONENT "kvm-s390" 11 11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 12 12 13 + #include <linux/cpufeature.h> 13 14 #include <linux/interrupt.h> 14 15 #include <linux/kvm_host.h> 15 16 #include <linux/hrtimer.h> ··· 578 577 /* take care of lazy register loading */ 579 578 kvm_s390_fpu_store(vcpu->run); 580 579 save_access_regs(vcpu->run->s.regs.acrs); 581 - if (MACHINE_HAS_GS && vcpu->arch.gs_enabled) 580 + if (cpu_has_gs() && vcpu->arch.gs_enabled) 582 581 save_gs_cb(current->thread.gs_cb); 583 582 584 583 /* Extended save area */
+3 -2
arch/s390/kvm/kvm-s390.c
··· 23 23 #include <linux/mman.h> 24 24 #include <linux/module.h> 25 25 #include <linux/moduleparam.h> 26 + #include <linux/cpufeature.h> 26 27 #include <linux/random.h> 27 28 #include <linux/slab.h> 28 29 #include <linux/timer.h> ··· 5172 5171 vcpu->arch.sie_block->fpf &= ~FPF_BPBC; 5173 5172 vcpu->arch.sie_block->fpf |= kvm_run->s.regs.bpbc ? FPF_BPBC : 0; 5174 5173 } 5175 - if (MACHINE_HAS_GS) { 5174 + if (cpu_has_gs()) { 5176 5175 preempt_disable(); 5177 5176 local_ctl_set_bit(2, CR2_GUARDED_STORAGE_BIT); 5178 5177 if (current->thread.gs_cb) { ··· 5238 5237 kvm_run->s.regs.gbea = vcpu->arch.sie_block->gbea; 5239 5238 kvm_run->s.regs.bpbc = (vcpu->arch.sie_block->fpf & FPF_BPBC) == FPF_BPBC; 5240 5239 kvm_run->s.regs.diag318 = vcpu->arch.diag318_info.val; 5241 - if (MACHINE_HAS_GS) { 5240 + if (cpu_has_gs()) { 5242 5241 preempt_disable(); 5243 5242 local_ctl_set_bit(2, CR2_GUARDED_STORAGE_BIT); 5244 5243 if (vcpu->arch.gs_enabled)