]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
s390/cpufeature: Convert MACHINE_HAS_GS to cpu_has_gs()
authorHeiko Carstens <hca@linux.ibm.com>
Fri, 7 Feb 2025 14:48:49 +0000 (15:48 +0100)
committerVasily Gorbik <gor@linux.ibm.com>
Tue, 4 Mar 2025 16:18:04 +0000 (17:18 +0100)
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>
arch/s390/include/asm/cpufeature.h
arch/s390/include/asm/setup.h
arch/s390/kernel/early.c
arch/s390/kernel/guarded_storage.c
arch/s390/kernel/machine_kexec.c
arch/s390/kernel/nmi.c
arch/s390/kernel/processor.c
arch/s390/kernel/ptrace.c
arch/s390/kernel/smp.c
arch/s390/kvm/interrupt.c
arch/s390/kvm/kvm-s390.c

index 641a2780fd5a641aab39377c635dc6eb8414ce21..e969f020f7614dff20ffbac904a453e95ff74e03 100644 (file)
@@ -22,6 +22,7 @@ enum {
 
 int cpu_have_feature(unsigned int nr);
 
+#define cpu_has_gs()           test_facility(133)
 #define cpu_has_rdp()          test_facility(194)
 #define cpu_has_seq_insn()     test_facility(85)
 
index 07e7dab27dfac40d4c76701fcaa0372ed50efa3a..e08f4295df14950a695653b04cfbeb7e010e1168 100644 (file)
@@ -30,7 +30,6 @@
 #define MACHINE_FLAG_TLB_LC    BIT(12)
 #define MACHINE_FLAG_TLB_GUEST BIT(14)
 #define MACHINE_FLAG_NX                BIT(15)
-#define MACHINE_FLAG_GS                BIT(16)
 #define MACHINE_FLAG_SCC       BIT(17)
 #define MACHINE_FLAG_PCI_MIO   BIT(18)
 
@@ -90,7 +89,6 @@ extern unsigned long mio_wb_bit_mask;
 #define MACHINE_HAS_TLB_LC     (get_lowcore()->machine_flags & MACHINE_FLAG_TLB_LC)
 #define MACHINE_HAS_TLB_GUEST  (get_lowcore()->machine_flags & MACHINE_FLAG_TLB_GUEST)
 #define MACHINE_HAS_NX         (get_lowcore()->machine_flags & MACHINE_FLAG_NX)
-#define MACHINE_HAS_GS         (get_lowcore()->machine_flags & MACHINE_FLAG_GS)
 #define MACHINE_HAS_SCC                (get_lowcore()->machine_flags & MACHINE_FLAG_SCC)
 #define MACHINE_HAS_PCI_MIO    (get_lowcore()->machine_flags & MACHINE_FLAG_PCI_MIO)
 
index f596a2eb428a4670474d47584ca9c8f213056a1b..9590921e8cdf3d984575152664327a24cd6b540b 100644 (file)
@@ -255,8 +255,6 @@ static __init void detect_machine_facilities(void)
                system_ctl_set_bit(0, CR0_VECTOR_BIT);
        if (test_facility(130))
                get_lowcore()->machine_flags |= MACHINE_FLAG_NX;
-       if (test_facility(133))
-               get_lowcore()->machine_flags |= MACHINE_FLAG_GS;
        if (test_facility(139) && (tod_clock_base.tod >> 63)) {
                /* Enabled signed clock comparator comparisons */
                get_lowcore()->machine_flags |= MACHINE_FLAG_SCC;
index 0b68168d956683212e48fa779e7430b2bd808e9a..cf26d7a37425118e90e8c7a40e41b13b8cc913df 100644 (file)
@@ -4,6 +4,7 @@
  * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  */
 
+#include <linux/cpufeature.h>
 #include <linux/kernel.h>
 #include <linux/syscalls.h>
 #include <linux/signal.h>
@@ -109,7 +110,7 @@ static int gs_broadcast(void)
 SYSCALL_DEFINE2(s390_guarded_storage, int, command,
                struct gs_cb __user *, gs_cb)
 {
-       if (!MACHINE_HAS_GS)
+       if (!cpu_has_gs())
                return -EOPNOTSUPP;
        switch (command) {
        case GS_ENABLE:
index 8f681ccfb83a1d6e21b5b9d707706c4796ca6977..7962dba7bdeaa77774f10aadc94ae57aed257c2b 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/reboot.h>
 #include <linux/ftrace.h>
 #include <linux/debug_locks.h>
+#include <linux/cpufeature.h>
 #include <asm/guarded_storage.h>
 #include <asm/pfault.h>
 #include <asm/cio.h>
@@ -94,7 +95,7 @@ static noinline void __machine_kdump(void *image)
        mcesa = __va(get_lowcore()->mcesad & MCESA_ORIGIN_MASK);
        if (cpu_has_vx())
                save_vx_regs((__vector128 *) mcesa->vector_save_area);
-       if (MACHINE_HAS_GS) {
+       if (cpu_has_gs()) {
                local_ctl_store(2, &cr2_old.reg);
                cr2_new = cr2_old;
                cr2_new.gse = 1;
index fbd218b6fc8e4cdbdfb182d9c44faff2dc91ea28..3da371c144eb93f9859af750a858733be041fc23 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include <linux/kernel_stat.h>
+#include <linux/cpufeature.h>
 #include <linux/init.h>
 #include <linux/errno.h>
 #include <linux/entry-common.h>
@@ -45,7 +46,7 @@ static DEFINE_PER_CPU(struct mcck_struct, cpu_mcck);
 
 static inline int nmi_needs_mcesa(void)
 {
-       return cpu_has_vx() || MACHINE_HAS_GS;
+       return cpu_has_vx() || cpu_has_gs();
 }
 
 /*
@@ -61,7 +62,7 @@ void __init nmi_alloc_mcesa_early(u64 *mcesad)
        if (!nmi_needs_mcesa())
                return;
        *mcesad = __pa(&boot_mcesa);
-       if (MACHINE_HAS_GS)
+       if (cpu_has_gs())
                *mcesad |= ilog2(MCESA_MAX_SIZE);
 }
 
@@ -73,14 +74,14 @@ int nmi_alloc_mcesa(u64 *mcesad)
        *mcesad = 0;
        if (!nmi_needs_mcesa())
                return 0;
-       size = MACHINE_HAS_GS ? MCESA_MAX_SIZE : MCESA_MIN_SIZE;
+       size = cpu_has_gs() ? MCESA_MAX_SIZE : MCESA_MIN_SIZE;
        origin = kmalloc(size, GFP_KERNEL);
        if (!origin)
                return -ENOMEM;
        /* The pointer is stored with mcesa_bits ORed in */
        kmemleak_not_leak(origin);
        *mcesad = __pa(origin);
-       if (MACHINE_HAS_GS)
+       if (cpu_has_gs())
                *mcesad |= ilog2(MCESA_MAX_SIZE);
        return 0;
 }
index 5ce9a795a0fe1b4f3d2afd03e1093b1642308a3a..c8ce8474d769e79ef4579b05add1285be1f83c43 100644 (file)
@@ -8,6 +8,7 @@
 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 
 #include <linux/stop_machine.h>
+#include <linux/cpufeature.h>
 #include <linux/bitops.h>
 #include <linux/kernel.h>
 #include <linux/random.h>
@@ -244,7 +245,7 @@ static int __init setup_hwcaps(void)
                elf_hwcap |= HWCAP_NNPA;
 
        /* guarded storage */
-       if (MACHINE_HAS_GS)
+       if (cpu_has_gs())
                elf_hwcap |= HWCAP_GS;
 
        if (MACHINE_HAS_PCI_MIO)
index 1cfed8b710b8c81f41350b1167a17886be30584a..9ed3017bb968d8db6508a773f46bfb1a77c728f1 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/sched/task_stack.h>
+#include <linux/cpufeature.h>
 #include <linux/mm.h>
 #include <linux/smp.h>
 #include <linux/errno.h>
@@ -75,7 +76,7 @@ void update_cr_regs(struct task_struct *task)
                }
        }
        /* Take care of enable/disable of guarded storage. */
-       if (MACHINE_HAS_GS) {
+       if (cpu_has_gs()) {
                cr2_new.gse = 0;
                if (task->thread.gs_cb)
                        cr2_new.gse = 1;
@@ -1033,7 +1034,7 @@ static int s390_gs_cb_get(struct task_struct *target,
 {
        struct gs_cb *data = target->thread.gs_cb;
 
-       if (!MACHINE_HAS_GS)
+       if (!cpu_has_gs())
                return -ENODEV;
        if (!data)
                return -ENODATA;
@@ -1050,7 +1051,7 @@ static int s390_gs_cb_set(struct task_struct *target,
        struct gs_cb gs_cb = { }, *data = NULL;
        int rc;
 
-       if (!MACHINE_HAS_GS)
+       if (!cpu_has_gs())
                return -ENODEV;
        if (!target->thread.gs_cb) {
                data = kzalloc(sizeof(*data), GFP_KERNEL);
@@ -1087,7 +1088,7 @@ static int s390_gs_bc_get(struct task_struct *target,
 {
        struct gs_cb *data = target->thread.gs_bc_cb;
 
-       if (!MACHINE_HAS_GS)
+       if (!cpu_has_gs())
                return -ENODEV;
        if (!data)
                return -ENODATA;
@@ -1101,7 +1102,7 @@ static int s390_gs_bc_set(struct task_struct *target,
 {
        struct gs_cb *data = target->thread.gs_bc_cb;
 
-       if (!MACHINE_HAS_GS)
+       if (!cpu_has_gs())
                return -ENODEV;
        if (!data) {
                data = kzalloc(sizeof(*data), GFP_KERNEL);
index 7b08399b084664ff2bfe1aee50671bdb158e51cd..2bf45d95165bb81bff57462ec14658ec9c8c5bd4 100644 (file)
@@ -18,6 +18,7 @@
 #define KMSG_COMPONENT "cpu"
 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 
+#include <linux/cpufeature.h>
 #include <linux/workqueue.h>
 #include <linux/memblock.h>
 #include <linux/export.h>
@@ -561,10 +562,10 @@ int smp_store_status(int cpu)
        if (__pcpu_sigp_relax(pcpu->address, SIGP_STORE_STATUS_AT_ADDRESS,
                              pa) != SIGP_CC_ORDER_CODE_ACCEPTED)
                return -EIO;
-       if (!cpu_has_vx() && !MACHINE_HAS_GS)
+       if (!cpu_has_vx() && !cpu_has_gs())
                return 0;
        pa = lc->mcesad & MCESA_ORIGIN_MASK;
-       if (MACHINE_HAS_GS)
+       if (cpu_has_gs())
                pa |= lc->mcesad & MCESA_LC_MASK;
        if (__pcpu_sigp_relax(pcpu->address, SIGP_STORE_ADDITIONAL_STATUS,
                              pa) != SIGP_CC_ORDER_CODE_ACCEPTED)
index 07ff0e10cb7f5c0294bf85f1d65d1eb124698705..2c1f69760e7e0f300ed96ad9b9bd10a97738eae7 100644 (file)
@@ -10,6 +10,7 @@
 #define KMSG_COMPONENT "kvm-s390"
 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
 
+#include <linux/cpufeature.h>
 #include <linux/interrupt.h>
 #include <linux/kvm_host.h>
 #include <linux/hrtimer.h>
@@ -577,7 +578,7 @@ static int __write_machine_check(struct kvm_vcpu *vcpu,
        /* take care of lazy register loading */
        kvm_s390_fpu_store(vcpu->run);
        save_access_regs(vcpu->run->s.regs.acrs);
-       if (MACHINE_HAS_GS && vcpu->arch.gs_enabled)
+       if (cpu_has_gs() && vcpu->arch.gs_enabled)
                save_gs_cb(current->thread.gs_cb);
 
        /* Extended save area */
index ebecb96bacce7d75563bd3a130a7cc31869dc254..703a6594cfafcaab366ccffdfb3b34db3207317a 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/mman.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/cpufeature.h>
 #include <linux/random.h>
 #include <linux/slab.h>
 #include <linux/timer.h>
@@ -5171,7 +5172,7 @@ static void sync_regs_fmt2(struct kvm_vcpu *vcpu)
                vcpu->arch.sie_block->fpf &= ~FPF_BPBC;
                vcpu->arch.sie_block->fpf |= kvm_run->s.regs.bpbc ? FPF_BPBC : 0;
        }
-       if (MACHINE_HAS_GS) {
+       if (cpu_has_gs()) {
                preempt_disable();
                local_ctl_set_bit(2, CR2_GUARDED_STORAGE_BIT);
                if (current->thread.gs_cb) {
@@ -5237,7 +5238,7 @@ static void store_regs_fmt2(struct kvm_vcpu *vcpu)
        kvm_run->s.regs.gbea = vcpu->arch.sie_block->gbea;
        kvm_run->s.regs.bpbc = (vcpu->arch.sie_block->fpf & FPF_BPBC) == FPF_BPBC;
        kvm_run->s.regs.diag318 = vcpu->arch.diag318_info.val;
-       if (MACHINE_HAS_GS) {
+       if (cpu_has_gs()) {
                preempt_disable();
                local_ctl_set_bit(2, CR2_GUARDED_STORAGE_BIT);
                if (vcpu->arch.gs_enabled)