]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
s390/cpufeature: Convert MACHINE_HAS_NX to cpu_has_nx()
authorHeiko Carstens <hca@linux.ibm.com>
Fri, 7 Feb 2025 14:48:50 +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/boot/startup.c
arch/s390/include/asm/cpufeature.h
arch/s390/include/asm/setup.h
arch/s390/kernel/early.c
arch/s390/mm/dump_pagetables.c
arch/s390/mm/fault.c
arch/s390/mm/init.c
arch/s390/mm/pageattr.c

index 885bd1dd2c82f948199ae369077aba4e0bf8020b..55b8fad06b640c5fc8f5fdc30ab033667b6862ef 100644 (file)
@@ -59,7 +59,7 @@ static void detect_facilities(void)
        page_noexec_mask = -1UL;
        segment_noexec_mask = -1UL;
        region_noexec_mask = -1UL;
-       if (!test_facility(130)) {
+       if (!cpu_has_nx()) {
                page_noexec_mask &= ~_PAGE_NOEXEC;
                segment_noexec_mask &= ~_SEGMENT_ENTRY_NOEXEC;
                region_noexec_mask &= ~_REGION_ENTRY_NOEXEC;
index e969f020f7614dff20ffbac904a453e95ff74e03..64ff316a69e3e46932331f75cc2d864822c7d2be 100644 (file)
@@ -23,6 +23,7 @@ enum {
 int cpu_have_feature(unsigned int nr);
 
 #define cpu_has_gs()           test_facility(133)
+#define cpu_has_nx()           test_facility(130)
 #define cpu_has_rdp()          test_facility(194)
 #define cpu_has_seq_insn()     test_facility(85)
 
index e08f4295df14950a695653b04cfbeb7e010e1168..914d694960e42f7944fe1a47cb237b55ec57de3e 100644 (file)
@@ -29,7 +29,6 @@
 #define MACHINE_FLAG_TE                BIT(11)
 #define MACHINE_FLAG_TLB_LC    BIT(12)
 #define MACHINE_FLAG_TLB_GUEST BIT(14)
-#define MACHINE_FLAG_NX                BIT(15)
 #define MACHINE_FLAG_SCC       BIT(17)
 #define MACHINE_FLAG_PCI_MIO   BIT(18)
 
@@ -88,7 +87,6 @@ extern unsigned long mio_wb_bit_mask;
 #define MACHINE_HAS_TE         (get_lowcore()->machine_flags & MACHINE_FLAG_TE)
 #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_SCC                (get_lowcore()->machine_flags & MACHINE_FLAG_SCC)
 #define MACHINE_HAS_PCI_MIO    (get_lowcore()->machine_flags & MACHINE_FLAG_PCI_MIO)
 
index 9590921e8cdf3d984575152664327a24cd6b540b..32a0983a0378ee40daab89ccee26f1c10fe42f7a 100644 (file)
@@ -253,8 +253,6 @@ static __init void detect_machine_facilities(void)
                get_lowcore()->machine_flags |= MACHINE_FLAG_TLB_LC;
        if (test_facility(129))
                system_ctl_set_bit(0, CR0_VECTOR_BIT);
-       if (test_facility(130))
-               get_lowcore()->machine_flags |= MACHINE_FLAG_NX;
        if (test_facility(139) && (tod_clock_base.tod >> 63)) {
                /* Enabled signed clock comparator comparisons */
                get_lowcore()->machine_flags |= MACHINE_FLAG_SCC;
index fa54f3bc0c8d376d1ca206c4edd5c0c714679a81..b60bc2b4287158128c4b28e73e924d15903c95ab 100644 (file)
@@ -1,4 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
+
+#include <linux/cpufeature.h>
 #include <linux/set_memory.h>
 #include <linux/ptdump.h>
 #include <linux/seq_file.h>
@@ -167,7 +169,7 @@ bool ptdump_check_wx(void)
                },
        };
 
-       if (!MACHINE_HAS_NX)
+       if (!cpu_has_nx())
                return true;
        ptdump_walk_pgd(&st.ptdump, &init_mm, NULL);
        if (st.wx_pages) {
index 9c9d7840cb5787b0d688828ac24bf5e0d7930611..13d8c44bf8ede77b293f8aabd3de96ac5b653915 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/kernel_stat.h>
 #include <linux/mmu_context.h>
+#include <linux/cpufeature.h>
 #include <linux/perf_event.h>
 #include <linux/signal.h>
 #include <linux/sched.h>
@@ -366,7 +367,7 @@ void do_protection_exception(struct pt_regs *regs)
                 */
                return handle_fault_error_nolock(regs, 0);
        }
-       if (unlikely(MACHINE_HAS_NX && teid.b56)) {
+       if (unlikely(cpu_has_nx() && teid.b56)) {
                regs->int_parm_long = (teid.addr * PAGE_SIZE) | (regs->psw.addr & PAGE_MASK);
                return handle_fault_error_nolock(regs, SEGV_ACCERR);
        }
index f2298f7a3f21081f99959d5e59121092951d0c52..6e325f81b89adc86096a7f2b1b26def17dfc6cf4 100644 (file)
@@ -8,6 +8,7 @@
  *    Copyright (C) 1995  Linus Torvalds
  */
 
+#include <linux/cpufeature.h>
 #include <linux/signal.h>
 #include <linux/sched.h>
 #include <linux/kernel.h>
@@ -117,7 +118,7 @@ void mark_rodata_ro(void)
 {
        unsigned long size = __end_ro_after_init - __start_ro_after_init;
 
-       if (MACHINE_HAS_NX)
+       if (cpu_has_nx())
                system_ctl_set_bit(0, CR0_INSTRUCTION_EXEC_PROTECTION_BIT);
        __set_memory_ro(__start_ro_after_init, __end_ro_after_init);
        pr_info("Write protected read-only-after-init data: %luk\n", size >> 10);
index eae97fb6171231b0922c8943712f60743d659a28..93c0ee36436e98c885ab8e9bff9d76cd087c3527 100644 (file)
@@ -3,6 +3,7 @@
  * Copyright IBM Corp. 2011
  * Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
  */
+#include <linux/cpufeature.h>
 #include <linux/hugetlb.h>
 #include <linux/proc_fs.h>
 #include <linux/vmalloc.h>
@@ -373,7 +374,7 @@ int __set_memory(unsigned long addr, unsigned long numpages, unsigned long flags
        unsigned long end;
        int rc;
 
-       if (!MACHINE_HAS_NX)
+       if (!cpu_has_nx())
                flags &= ~(SET_MEMORY_NX | SET_MEMORY_X);
        if (!flags)
                return 0;