From e82462fbb2cffbae0bf1b8bb15924cb18dba06a7 Mon Sep 17 00:00:00 2001 From: Heiko Carstens Date: Fri, 7 Feb 2025 15:49:01 +0100 Subject: [PATCH] s390/tx: Convert MACHINE_HAS_TE to machine_has_tx() Use static branch(es) to implement and use machine_has_tx() instead of a runtime check with MACHINE_HAS_TE. Reviewed-by: Vasily Gorbik Signed-off-by: Heiko Carstens Signed-off-by: Vasily Gorbik --- arch/s390/boot/startup.c | 4 ++++ arch/s390/include/asm/machine.h | 2 ++ arch/s390/include/asm/setup.h | 2 -- arch/s390/kernel/early.c | 4 ---- arch/s390/kernel/processor.c | 2 +- arch/s390/kernel/ptrace.c | 9 +++++---- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/arch/s390/boot/startup.c b/arch/s390/boot/startup.c index 4ef2622f3d300..50ae83aaef165 100644 --- a/arch/s390/boot/startup.c +++ b/arch/s390/boot/startup.c @@ -84,6 +84,10 @@ static void detect_facilities(void) clock_comparator_max = -1UL >> 1; local_ctl_set_bit(0, CR0_CLOCK_COMPARATOR_SIGN_BIT); } + if (test_facility(50) && test_facility(73)) { + set_machine_feature(MFEATURE_TX); + local_ctl_set_bit(0, CR0_TRANSACTIONAL_EXECUTION_BIT); + } } static int cmma_test_essa(void) diff --git a/arch/s390/include/asm/machine.h b/arch/s390/include/asm/machine.h index 33cb4403fc82b..c31682d6c35d3 100644 --- a/arch/s390/include/asm/machine.h +++ b/arch/s390/include/asm/machine.h @@ -12,6 +12,7 @@ #define MFEATURE_PCI_MIO 1 #define MFEATURE_SCC 2 #define MFEATURE_TLB_GUEST 3 +#define MFEATURE_TX 4 #ifndef __ASSEMBLY__ @@ -82,6 +83,7 @@ static __always_inline bool machine_has_##name(void) \ DEFINE_MACHINE_HAS_FEATURE(relocated_lowcore, MFEATURE_LOWCORE) DEFINE_MACHINE_HAS_FEATURE(scc, MFEATURE_SCC) DEFINE_MACHINE_HAS_FEATURE(tlb_guest, MFEATURE_TLB_GUEST) +DEFINE_MACHINE_HAS_FEATURE(tx, MFEATURE_TX) #endif /* __ASSEMBLY__ */ #endif /* __ASM_S390_MACHINE_H */ diff --git a/arch/s390/include/asm/setup.h b/arch/s390/include/asm/setup.h index bb9d701ec9a6f..7762fb342c396 100644 --- a/arch/s390/include/asm/setup.h +++ b/arch/s390/include/asm/setup.h @@ -22,7 +22,6 @@ #define MACHINE_FLAG_LPAR BIT(2) #define MACHINE_FLAG_DIAG9C BIT(3) #define MACHINE_FLAG_ESOP BIT(4) -#define MACHINE_FLAG_TE BIT(11) #define LPP_MAGIC BIT(31) #define LPP_PID_MASK _AC(0xffffffff, UL) @@ -72,7 +71,6 @@ extern unsigned long mio_wb_bit_mask; #define MACHINE_HAS_DIAG9C (get_lowcore()->machine_flags & MACHINE_FLAG_DIAG9C) #define MACHINE_HAS_ESOP (get_lowcore()->machine_flags & MACHINE_FLAG_ESOP) -#define MACHINE_HAS_TE (get_lowcore()->machine_flags & MACHINE_FLAG_TE) /* * Console mode. Override with conmode= diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c index 708f158cc60ef..cc4e3d4dc55f9 100644 --- a/arch/s390/kernel/early.c +++ b/arch/s390/kernel/early.c @@ -222,10 +222,6 @@ static __init void detect_diag9c(void) static __init void detect_machine_facilities(void) { - if (test_facility(50) && test_facility(73)) { - get_lowcore()->machine_flags |= MACHINE_FLAG_TE; - system_ctl_set_bit(0, CR0_TRANSACTIONAL_EXECUTION_BIT); - } if (test_facility(129)) system_ctl_set_bit(0, CR0_VECTOR_BIT); } diff --git a/arch/s390/kernel/processor.c b/arch/s390/kernel/processor.c index 487c943cbc4c4..6594ded7b722b 100644 --- a/arch/s390/kernel/processor.c +++ b/arch/s390/kernel/processor.c @@ -218,7 +218,7 @@ static int __init setup_hwcaps(void) elf_hwcap |= HWCAP_HIGH_GPRS; /* transactional execution */ - if (MACHINE_HAS_TE) + if (machine_has_tx()) elf_hwcap |= HWCAP_TE; /* vector */ diff --git a/arch/s390/kernel/ptrace.c b/arch/s390/kernel/ptrace.c index 9ed3017bb968d..e2acbbadc75e3 100644 --- a/arch/s390/kernel/ptrace.c +++ b/arch/s390/kernel/ptrace.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "entry.h" @@ -61,7 +62,7 @@ void update_cr_regs(struct task_struct *task) cr0_new = cr0_old; cr2_new = cr2_old; /* Take care of the enable/disable of transactional execution. */ - if (MACHINE_HAS_TE) { + if (machine_has_tx()) { /* Set or clear transaction execution TXC bit 8. */ cr0_new.tcx = 1; if (task->thread.per_flags & PER_FLAG_NO_TE) @@ -471,18 +472,18 @@ long arch_ptrace(struct task_struct *child, long request, case PTRACE_GET_LAST_BREAK: return put_user(child->thread.last_break, (unsigned long __user *)data); case PTRACE_ENABLE_TE: - if (!MACHINE_HAS_TE) + if (!machine_has_tx()) return -EIO; child->thread.per_flags &= ~PER_FLAG_NO_TE; return 0; case PTRACE_DISABLE_TE: - if (!MACHINE_HAS_TE) + if (!machine_has_tx()) return -EIO; child->thread.per_flags |= PER_FLAG_NO_TE; child->thread.per_flags &= ~PER_FLAG_TE_ABORT_RAND; return 0; case PTRACE_TE_ABORT_RAND: - if (!MACHINE_HAS_TE || (child->thread.per_flags & PER_FLAG_NO_TE)) + if (!machine_has_tx() || (child->thread.per_flags & PER_FLAG_NO_TE)) return -EIO; switch (data) { case 0UL: -- 2.47.2