* [PATCH v2 1/3] x86/msr: Define new bits in TSX_FORCE_ABORT MSR
2021-06-14 21:11 [PATCH v2 0/3] TSX force abort Pawan Gupta
@ 2021-06-14 21:12 ` Pawan Gupta
2021-06-14 21:13 ` [PATCH v2 2/3] perf/x86/intel: Do not deploy workaround when TSX is deprecated Pawan Gupta
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Pawan Gupta @ 2021-06-14 21:12 UTC (permalink / raw)
To: Thomas Gleixner, Borislav Petkov
Cc: Jonathan Corbet, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, x86, H. Peter Anvin, Paul E. McKenney,
Randy Dunlap, Andrew Morton, Maciej W. Rozycki, Viresh Kumar,
Vlastimil Babka, Tony Luck, Paolo Bonzini, Sean Christopherson,
Kyung Min Park, Fenghua Yu, Ricardo Neri, Tom Lendacky,
Juergen Gross, Krish Sadhukhan, Kan Liang, Joerg Roedel,
Victor Ding, Srinivas Pandruvada, Pawan Gupta, Brijesh Singh,
Dave Hansen, Mike Rapoport, Anthony Steinhauser, Anand K Mistry,
Andi Kleen, Miguel Ojeda, Joe Perches, linux-doc, linux-kernel,
linux-perf-users
Intel client processors that support IA32_TSX_FORCE_ABORT MSR related to
perf counter interaction [1] received a microcode update that deprecates
Transactional Synchronization Extension (TSX) feature. MSR
IA32_TSX_FORCE_ABORT bit FORCE_ABORT_RTM now defaults to 1, writes to
this bit are ignored. A new bit TSX_CPUID_CLEAR clears the TSX related
CPUID bits.
Below is the summary of changes to IA32_TSX_FORCE_ABORT MSR:
Bit 0: FORCE_ABORT_RTM (legacy bit, new default=1) Status bit that
indicates if RTM transactions are always aborted. This bit is
essentially !SDV_ENABLE_RTM(Bit 2). Writes to this bit are ignored.
Bit 1: TSX_CPUID_CLEAR (new bit, default=0) When set, CPUID.HLE = 0
and CPUID.RTM = 0.
Bit 2: SDV_ENABLE_RTM (new bit, default=0) When clear, XBEGIN will
always abort with EAX code 0. When set, XBEGIN will not be forced to
abort (but will always abort in SGX enclaves). This bit is intended to
be used on developer systems. If this bit is set transactional
atomicity correctness is not certain.
Performance monitoring counter 3 is usable in all cases, regardless of
the value of above bits.
A new CPUID bit CPUID.RTM_ALWAYS_ABORT (CPUID 7.EDX[11]) is added to
indicate the status of always abort behavior.
Define these new CPUID and MSR bits.
[1] Performance Monitoring Impact of Intel® Transactional Synchronization Extension Memory
http://cdrdv2.intel.com/v1/dl/getContent/604224 (Document ID 604224)
Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Tested-by: Neelima Krishnan <neelima.krishnan@intel.com>
---
arch/x86/include/asm/cpufeatures.h | 1 +
arch/x86/include/asm/msr-index.h | 4 ++++
2 files changed, 5 insertions(+)
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index ac37830ae941..21c1855b5c14 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -378,6 +378,7 @@
#define X86_FEATURE_AVX512_VP2INTERSECT (18*32+ 8) /* AVX-512 Intersect for D/Q */
#define X86_FEATURE_SRBDS_CTRL (18*32+ 9) /* "" SRBDS mitigation MSR available */
#define X86_FEATURE_MD_CLEAR (18*32+10) /* VERW clears CPU buffers */
+#define X86_FEATURE_RTM_ALWAYS_ABORT (18*32+11) /* "" RTM transaction always aborts */
#define X86_FEATURE_TSX_FORCE_ABORT (18*32+13) /* "" TSX_FORCE_ABORT */
#define X86_FEATURE_SERIALIZE (18*32+14) /* SERIALIZE instruction */
#define X86_FEATURE_HYBRID_CPU (18*32+15) /* "" This part has CPUs of more than one type */
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 211ba3375ee9..a7c413432b33 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -772,6 +772,10 @@
#define MSR_TFA_RTM_FORCE_ABORT_BIT 0
#define MSR_TFA_RTM_FORCE_ABORT BIT_ULL(MSR_TFA_RTM_FORCE_ABORT_BIT)
+#define MSR_TFA_TSX_CPUID_CLEAR_BIT 1
+#define MSR_TFA_TSX_CPUID_CLEAR BIT_ULL(MSR_TFA_TSX_CPUID_CLEAR_BIT)
+#define MSR_TFA_SDV_ENABLE_RTM_BIT 2
+#define MSR_TFA_SDV_ENABLE_RTM BIT_ULL(MSR_TFA_SDV_ENABLE_RTM_BIT)
/* P4/Xeon+ specific */
#define MSR_IA32_MCG_EAX 0x00000180
--
git-series 0.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] perf/x86/intel: Do not deploy workaround when TSX is deprecated
2021-06-14 21:11 [PATCH v2 0/3] TSX force abort Pawan Gupta
2021-06-14 21:12 ` [PATCH v2 1/3] x86/msr: Define new bits in TSX_FORCE_ABORT MSR Pawan Gupta
@ 2021-06-14 21:13 ` Pawan Gupta
2021-06-14 21:14 ` [PATCH v2 3/3] x86/tsx: Clear CPUID bits when TSX always force aborts Pawan Gupta
2021-06-15 14:31 ` [PATCH v2 0/3] TSX force abort Thomas Gleixner
3 siblings, 0 replies; 6+ messages in thread
From: Pawan Gupta @ 2021-06-14 21:13 UTC (permalink / raw)
To: Thomas Gleixner, Borislav Petkov
Cc: Jonathan Corbet, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, x86, H. Peter Anvin, Paul E. McKenney,
Randy Dunlap, Andrew Morton, Maciej W. Rozycki, Viresh Kumar,
Vlastimil Babka, Tony Luck, Paolo Bonzini, Sean Christopherson,
Kyung Min Park, Fenghua Yu, Ricardo Neri, Tom Lendacky,
Juergen Gross, Krish Sadhukhan, Kan Liang, Joerg Roedel,
Victor Ding, Srinivas Pandruvada, Pawan Gupta, Brijesh Singh,
Dave Hansen, Mike Rapoport, Anthony Steinhauser, Anand K Mistry,
Andi Kleen, Miguel Ojeda, Joe Perches, linux-doc, linux-kernel,
linux-perf-users
Earlier workaround added by commit 400816f60c54 ("perf/x86/intel:
Implement support for TSX Force Abort") for perf counter interactions
[1] are not required on some client systems which received a microcode
update that deprecates TSX.
Bypass the perf workaround when such microcode is enumerated.
[1] Performance Monitoring Impact of Intel® Transactional Synchronization Extension Memory
http://cdrdv2.intel.com/v1/dl/getContent/604224 (Document ID 604224)
Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Tested-by: Neelima Krishnan <neelima.krishnan@intel.com>
---
arch/x86/events/intel/core.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index e28892270c58..b599a30fcc7d 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -6015,7 +6015,15 @@ __init int intel_pmu_init(void)
tsx_attr = hsw_tsx_events_attrs;
intel_pmu_pebs_data_source_skl(pmem);
- if (boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT)) {
+ /* Processors with CPUID.RTM_ALWAYS_ABORT have TSX deprecated by
+ * default. TSX force abort hooks are not required on these
+ * systems.
+ *
+ * Only deploy the workaround when older microcode is detected
+ * i.e. !X86_FEATURE_RTM_ALWAYS_ABORT.
+ */
+ if (boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT) &&
+ !boot_cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT)) {
x86_pmu.flags |= PMU_FL_TFA;
x86_pmu.get_event_constraints = tfa_get_event_constraints;
x86_pmu.enable_all = intel_tfa_pmu_enable_all;
--
git-series 0.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] x86/tsx: Clear CPUID bits when TSX always force aborts
2021-06-14 21:11 [PATCH v2 0/3] TSX force abort Pawan Gupta
2021-06-14 21:12 ` [PATCH v2 1/3] x86/msr: Define new bits in TSX_FORCE_ABORT MSR Pawan Gupta
2021-06-14 21:13 ` [PATCH v2 2/3] perf/x86/intel: Do not deploy workaround when TSX is deprecated Pawan Gupta
@ 2021-06-14 21:14 ` Pawan Gupta
2021-06-15 14:31 ` [PATCH v2 0/3] TSX force abort Thomas Gleixner
3 siblings, 0 replies; 6+ messages in thread
From: Pawan Gupta @ 2021-06-14 21:14 UTC (permalink / raw)
To: Thomas Gleixner, Borislav Petkov
Cc: Jonathan Corbet, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, x86, H. Peter Anvin, Paul E. McKenney,
Randy Dunlap, Andrew Morton, Maciej W. Rozycki, Viresh Kumar,
Vlastimil Babka, Tony Luck, Paolo Bonzini, Sean Christopherson,
Kyung Min Park, Fenghua Yu, Ricardo Neri, Tom Lendacky,
Juergen Gross, Krish Sadhukhan, Kan Liang, Joerg Roedel,
Victor Ding, Srinivas Pandruvada, Pawan Gupta, Brijesh Singh,
Dave Hansen, Mike Rapoport, Anthony Steinhauser, Anand K Mistry,
Andi Kleen, Miguel Ojeda, Joe Perches, linux-doc, linux-kernel,
linux-perf-users
As a result of TSX deprecation some processors always aborts TSX
transactions by default.
When TSX feature cannot be used it is better to hide it. Clear CPUID.RTM
and CPUID.HLE bits when TSX transactions always aborts.
Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Tested-by: Neelima Krishnan <neelima.krishnan@intel.com>
---
arch/x86/kernel/cpu/cpu.h | 2 ++
arch/x86/kernel/cpu/intel.c | 4 +++-
arch/x86/kernel/cpu/tsx.c | 37 +++++++++++++++++++++++++++++++++++--
3 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/cpu/cpu.h b/arch/x86/kernel/cpu/cpu.h
index 67944128876d..95521302630d 100644
--- a/arch/x86/kernel/cpu/cpu.h
+++ b/arch/x86/kernel/cpu/cpu.h
@@ -48,6 +48,7 @@ extern const struct cpu_dev *const __x86_cpu_dev_start[],
enum tsx_ctrl_states {
TSX_CTRL_ENABLE,
TSX_CTRL_DISABLE,
+ TSX_CTRL_RTM_ALWAYS_ABORT,
TSX_CTRL_NOT_SUPPORTED,
};
@@ -56,6 +57,7 @@ extern __ro_after_init enum tsx_ctrl_states tsx_ctrl_state;
extern void __init tsx_init(void);
extern void tsx_enable(void);
extern void tsx_disable(void);
+extern void tsx_clear_cpuid(void);
#else
static inline void tsx_init(void) { }
#endif /* CONFIG_CPU_SUP_INTEL */
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index 8adffc17fa8b..861e919eba9a 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -717,8 +717,10 @@ static void init_intel(struct cpuinfo_x86 *c)
if (tsx_ctrl_state == TSX_CTRL_ENABLE)
tsx_enable();
- if (tsx_ctrl_state == TSX_CTRL_DISABLE)
+ else if (tsx_ctrl_state == TSX_CTRL_DISABLE)
tsx_disable();
+ else if (tsx_ctrl_state == TSX_CTRL_RTM_ALWAYS_ABORT)
+ tsx_clear_cpuid();
split_lock_init();
bus_lock_init();
diff --git a/arch/x86/kernel/cpu/tsx.c b/arch/x86/kernel/cpu/tsx.c
index e2ad30e474f8..fd258a383bfc 100644
--- a/arch/x86/kernel/cpu/tsx.c
+++ b/arch/x86/kernel/cpu/tsx.c
@@ -2,7 +2,7 @@
/*
* Intel Transactional Synchronization Extensions (TSX) control.
*
- * Copyright (C) 2019 Intel Corporation
+ * Copyright (C) 2019-2021 Intel Corporation
*
* Author:
* Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
@@ -84,13 +84,46 @@ static enum tsx_ctrl_states x86_get_tsx_auto_mode(void)
return TSX_CTRL_ENABLE;
}
+void tsx_clear_cpuid(void)
+{
+ u64 msr;
+
+ /*
+ * MSR_TFA_TSX_CPUID_CLEAR bit is only present when both CPUID bits
+ * RTM_ALWAYS_ABORT and TSX_FORCE_ABORT are present.
+ */
+ if (boot_cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT) &&
+ boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT)) {
+ rdmsrl(MSR_TSX_FORCE_ABORT, msr);
+ msr |= MSR_TFA_TSX_CPUID_CLEAR;
+ wrmsrl(MSR_TSX_FORCE_ABORT, msr);
+ }
+}
+
void __init tsx_init(void)
{
char arg[5] = {};
int ret;
- if (!tsx_ctrl_is_supported())
+ /*
+ * Hardware will always abort a TSX transaction if both CPUID bits
+ * RTM_ALWAYS_ABORT and TSX_FORCE_ABORT are set. In this case it is
+ * better not to enumerate CPUID.RTM and CPUID.HLE bits. Clear them
+ * here.
+ */
+ if (boot_cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT) &&
+ boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT)) {
+ tsx_ctrl_state = TSX_CTRL_RTM_ALWAYS_ABORT;
+ tsx_clear_cpuid();
+ setup_clear_cpu_cap(X86_FEATURE_RTM);
+ setup_clear_cpu_cap(X86_FEATURE_HLE);
return;
+ }
+
+ if (!tsx_ctrl_is_supported()) {
+ tsx_ctrl_state = TSX_CTRL_NOT_SUPPORTED;
+ return;
+ }
ret = cmdline_find_option(boot_command_line, "tsx", arg, sizeof(arg));
if (ret >= 0) {
--
git-series 0.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] TSX force abort
2021-06-14 21:11 [PATCH v2 0/3] TSX force abort Pawan Gupta
` (2 preceding siblings ...)
2021-06-14 21:14 ` [PATCH v2 3/3] x86/tsx: Clear CPUID bits when TSX always force aborts Pawan Gupta
@ 2021-06-15 14:31 ` Thomas Gleixner
2021-06-15 17:58 ` Pawan Gupta
3 siblings, 1 reply; 6+ messages in thread
From: Thomas Gleixner @ 2021-06-15 14:31 UTC (permalink / raw)
To: Pawan Gupta, Borislav Petkov
Cc: Jonathan Corbet, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, x86, H. Peter Anvin, Paul E. McKenney,
Randy Dunlap, Andrew Morton, Maciej W. Rozycki, Viresh Kumar,
Vlastimil Babka, Tony Luck, Paolo Bonzini, Sean Christopherson,
Kyung Min Park, Fenghua Yu, Ricardo Neri, Tom Lendacky,
Juergen Gross, Krish Sadhukhan, Kan Liang, Joerg Roedel,
Victor Ding, Srinivas Pandruvada, Pawan Gupta, Brijesh Singh,
Dave Hansen, Mike Rapoport, Anthony Steinhauser, Anand K Mistry,
Andi Kleen, Miguel Ojeda, Joe Perches, linux-doc, linux-kernel,
linux-perf-users
On Mon, Jun 14 2021 at 14:11, Pawan Gupta wrote:
> v1->v2:
> - Avoid Reading TSX_FORCE_ABORT MSR for detecting new microcode.
> - In tsx_init() move force abort detection before cmdline parsing.
> - Drop tsx=fake patch, not enough use cases to justify the patch.
> - Rebase to v5.13-rc6.
Aside of the "/* Network style" comment in 2/3 this looks good!
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] TSX force abort
2021-06-15 14:31 ` [PATCH v2 0/3] TSX force abort Thomas Gleixner
@ 2021-06-15 17:58 ` Pawan Gupta
0 siblings, 0 replies; 6+ messages in thread
From: Pawan Gupta @ 2021-06-15 17:58 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Borislav Petkov, Jonathan Corbet, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, x86, H. Peter Anvin, Paul E. McKenney,
Randy Dunlap, Andrew Morton, Maciej W. Rozycki, Viresh Kumar,
Vlastimil Babka, Tony Luck, Paolo Bonzini, Sean Christopherson,
Kyung Min Park, Fenghua Yu, Ricardo Neri, Tom Lendacky,
Juergen Gross, Krish Sadhukhan, Kan Liang, Joerg Roedel,
Victor Ding, Srinivas Pandruvada, Brijesh Singh, Dave Hansen,
Mike Rapoport, Anthony Steinhauser, Anand K Mistry, Andi Kleen,
Miguel Ojeda, Joe Perches, linux-doc, linux-kernel,
linux-perf-users
On 15.06.2021 16:31, Thomas Gleixner wrote:
>On Mon, Jun 14 2021 at 14:11, Pawan Gupta wrote:
>> v1->v2:
>> - Avoid Reading TSX_FORCE_ABORT MSR for detecting new microcode.
>> - In tsx_init() move force abort detection before cmdline parsing.
>> - Drop tsx=fake patch, not enough use cases to justify the patch.
>> - Rebase to v5.13-rc6.
>
>Aside of the "/* Network style" comment in 2/3 this looks good!
>
>Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Many thanks for the review Thomas, Boris, Tony and Andi.
^ permalink raw reply [flat|nested] 6+ messages in thread