powerpc/powernv: Enable TM without suspend if possible
authorMichael Ellerman <mpe@ellerman.id.au>
Thu, 12 Oct 2017 10:17:18 +0000 (21:17 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 20 Oct 2017 22:33:05 +0000 (09:33 +1100)
Some Power9 revisions can run in a mode where TM operates without
suspended state. If we find ourself on a CPU that might be in this
mode, we query OPAL to check, and if so we reenable TM in CPU
features, and enable a new user feature to signal to userspace that we
are in this mode.

We do not enable the "normal" user feature, PPC_FEATURE2_HTM, but we
do enable PPC_FEATURE2_HTM_NOSC because that indicates to userspace
that the kernel will abort transactions on syscall entry, which is
true regardless of the suspend mode.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/opal-api.h
arch/powerpc/include/asm/powernv.h
arch/powerpc/include/asm/tm.h
arch/powerpc/kernel/process.c
arch/powerpc/kernel/prom.c
arch/powerpc/platforms/powernv/setup.c

index 9d191ebea706922a0ff984f36f5800a0cb266af7..233c7504b1f20bf036b1131eb0c9db6dcecdafaa 100644 (file)
@@ -896,6 +896,8 @@ enum {
         */
        OPAL_REINIT_CPUS_MMU_HASH       = (1 << 2),
        OPAL_REINIT_CPUS_MMU_RADIX      = (1 << 3),
+
+       OPAL_REINIT_CPUS_TM_SUSPEND_DISABLED = (1 << 4),
 };
 
 typedef struct oppanel_line {
index f62797702300db7589f441bfd756012843e4df10..dc5f6a5d45756234f6ce1a395345827d5e70d8ea 100644 (file)
@@ -22,6 +22,8 @@ extern void pnv_npu2_destroy_context(struct npu_context *context,
 extern int pnv_npu2_handle_fault(struct npu_context *context, uintptr_t *ea,
                                unsigned long *flags, unsigned long *status,
                                int count);
+
+void pnv_tm_init(void);
 #else
 static inline void powernv_set_nmmu_ptcr(unsigned long ptcr) { }
 static inline struct npu_context *pnv_npu2_init_context(struct pci_dev *gpdev,
@@ -36,6 +38,8 @@ static inline int pnv_npu2_handle_fault(struct npu_context *context,
                                        unsigned long *status, int count) {
        return -ENODEV;
 }
+
+static inline void pnv_tm_init(void) { }
 #endif
 
 #endif /* _ASM_POWERNV_H */
index 82e06ca3a49b86d1c2a69607bffa83d3459ba74a..ad19fe41931b655e05262e59b84a29259a2b09f2 100644 (file)
@@ -19,4 +19,6 @@ extern void tm_abort(uint8_t cause);
 extern void tm_save_sprs(struct thread_struct *thread);
 extern void tm_restore_sprs(struct thread_struct *thread);
 
+extern bool tm_suspend_disabled;
+
 #endif /* __ASSEMBLY__ */
index 166145b18728b598a0f7091ef495d8fe437cdb72..b02807ea54dc094795ce0d9fa2d7966e129dd48b 100644 (file)
 extern unsigned long _get_SP(void);
 
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+/*
+ * Are we running in "Suspend disabled" mode? If so we have to block any
+ * sigreturn that would get us into suspended state, and we also warn in some
+ * other paths that we should never reach with suspend disabled.
+ */
+bool tm_suspend_disabled __ro_after_init = false;
+
 static void check_if_tm_restore_required(struct task_struct *tsk)
 {
        /*
index d9bd6555f980de61b2e659da923039babb7399a4..101822be525a4c597e6d2d88472c6b4af5a04d88 100644 (file)
@@ -47,6 +47,7 @@
 #include <asm/mmu.h>
 #include <asm/paca.h>
 #include <asm/pgtable.h>
+#include <asm/powernv.h>
 #include <asm/iommu.h>
 #include <asm/btext.h>
 #include <asm/sections.h>
@@ -681,7 +682,10 @@ static void __init tm_init(void)
                cur_cpu_spec->cpu_user_features2 &=
                        ~(PPC_FEATURE2_HTM_NOSC | PPC_FEATURE2_HTM);
                cur_cpu_spec->cpu_features &= ~CPU_FTR_TM;
+               return;
        }
+
+       pnv_tm_init();
 }
 #else
 static void tm_init(void) { }
index cf52d53da4607d4936091d0162c4a631bf3efd64..d23f148a11f0d9a0c52db6fd73fad7499e75e9ec 100644 (file)
@@ -36,6 +36,7 @@
 #include <asm/opal.h>
 #include <asm/kexec.h>
 #include <asm/smp.h>
+#include <asm/tm.h>
 
 #include "powernv.h"
 
@@ -304,6 +305,28 @@ static int __init pnv_probe(void)
        return 1;
 }
 
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+void __init pnv_tm_init(void)
+{
+       if (!firmware_has_feature(FW_FEATURE_OPAL) ||
+           !pvr_version_is(PVR_POWER9) ||
+           early_cpu_has_feature(CPU_FTR_TM))
+               return;
+
+       if (opal_reinit_cpus(OPAL_REINIT_CPUS_TM_SUSPEND_DISABLED) != OPAL_SUCCESS)
+               return;
+
+       pr_info("Enabling TM (Transactional Memory) with Suspend Disabled\n");
+       cur_cpu_spec->cpu_features |= CPU_FTR_TM;
+       /* Make sure "normal" HTM is off (it should be) */
+       cur_cpu_spec->cpu_user_features2 &= ~PPC_FEATURE2_HTM;
+       /* Turn on no suspend mode, and HTM no SC */
+       cur_cpu_spec->cpu_user_features2 |= PPC_FEATURE2_HTM_NO_SUSPEND | \
+                                           PPC_FEATURE2_HTM_NOSC;
+       tm_suspend_disabled = true;
+}
+#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
+
 /*
  * Returns the cpu frequency for 'cpu' in Hz. This is used by
  * /proc/cpuinfo