Skip to contentSkip to conversation

amd: disable C6 after 1000 days on Fam17h models 30-3fh

PATCH In review Roger Pau Monne 3 participants 6 messages Jun 5, 2023 – Jun 7, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 amd: disable C6 after 1000 days on Fam17h models 30-3fh

As specified on Errata 1474:

"A core will fail to exit CC6 after about 1044 days after the last system reset. The time of failure may vary depending on the spread spectrum and REFCLK frequency."

Detect when running on AMD Fam17h models 30h-3fh and setup a timer to prevent entering C6 after 1000 days have elapsed. Take into account the TSC value at boot in order to account for any time elapsed before Xen has been booted.

Print a message once C6 is disabled in order to let the user know.

---
I think the only 30-3fh model is 31h (Rome/Castle Peak), but I've coded the check as to allow the whole range.

---
 xen/arch/x86/acpi/cpu_idle.c   |  3 ++-
 xen/arch/x86/cpu/amd.c         | 42 ++++++++++++++++++++++++++++++++++
 xen/arch/x86/include/asm/amd.h |  2 ++
 xen/include/xen/time.h         |  1 +
 4 files changed, 47 insertions(+), 1 deletion(-)
xen/arch/x86/acpi/cpu_idle.c +2 -1
index 427c8c89c5c4..452cba3fb953 100644
@@ -50,6 +50,7 @@
 #include <public/platform.h>
 #include <public/sysctl.h>
 #include <acpi/cpufreq/cpufreq.h>
+#include <asm/amd.h>
 #include <asm/apic.h>
 #include <asm/cpuidle.h>
 #include <asm/mwait.h>
@@ -643,7 +644,7 @@ bool errata_c6_workaround(void)
                       x86_match_cpu(isr_errata));
     }
 
-    return (fix_needed && cpu_has_pending_apic_eoi());
+    return (fix_needed && cpu_has_pending_apic_eoi()) || amd_disable_c6;
 }
 
 void update_last_cx_stat(struct acpi_processor_power *power,
xen/arch/x86/cpu/amd.c +42 -0

51 lines not on this page · raw message

xen/arch/x86/include/asm/amd.h +2 -0
index 09ee52dc1c09..c54bc6a8903f 100644
@@ -157,4 +157,6 @@ bool amd_setup_legacy_ssbd(void);
 void amd_set_legacy_ssbd(bool enable);
 void amd_set_cpuid_user_dis(bool enable);
 
+extern bool amd_disable_c6;
+
 #endif /* __AMD_H__ */
xen/include/xen/time.h +1 -0
index b7427460dd13..99a91579438e 100644
@@ -53,6 +53,7 @@ struct tm wallclock_time(uint64_t *ns);
 
 #define SYSTEM_TIME_HZ  1000000000ULL
 #define NOW()           ((s_time_t)get_s_time())
+#define DAYS(_d)        ((s_time_t)((_d)  * 86400000000000ULL))
 #define SECONDS(_s)     ((s_time_t)((_s)  * 1000000000ULL))
 #define MILLISECS(_ms)  ((s_time_t)((_ms) * 1000000ULL))
 #define MICROSECS(_us)  ((s_time_t)((_us) * 1000ULL))
Signature · 1 line
2.40.0
#1 lore raw
Quoted 5 lines · Roger Pau Monne
xen/arch/x86/cpu/amd.c +0 -0
index 0d3143031b5b..728fa61a54bb 100644

xen/arch/x86/cpu/amd.c const struct cpu_dev amd_cpu_dev = { · line 1198

Quoted 9 lines
xen/arch/x86/cpu/amd.c +6 -0
@@ -1189,3 +1190,44 @@ const struct cpu_dev amd_cpu_dev = {
 	.c_early_init	= early_init_amd,
 	.c_init		= init_amd,
 };
+
+static void cf_check disable_c6(void *arg)
+{
+	printk(XENLOG_WARNING
+	       "Disabling C6 after 1000 days uptime due to AMD errata 1474\n");
+	amd_disable_c6 = true;

I don't think this is good enough.

AMD CPUs can enter C6 from HLT and IOCstate as well as via MWAIT. You're going to need to modify the MSRs as described in the revision guide, which will inhibit all ways of entering C6.

~Andrew

#2 lore raw
In reply to Roger Pau Monne
Quoted 10 lines · Roger Pau Monne

As specified on Errata 1474:

"A core will fail to exit CC6 after about 1044 days after the last system reset. The time of failure may vary depending on the spread spectrum and REFCLK frequency."

Detect when running on AMD Fam17h models 30h-3fh and setup a timer to prevent entering C6 after 1000 days have elapsed. Take into account the TSC value at boot in order to account for any time elapsed before Xen has been booted.

Models 6x are also affected as per their RG. I have some trouble with the site, so it's too slow going to actually try and fish out the RGs for the other possible models.

Given more than one set of models is affected I of course also wonder whether Hygon CPUs wouldn't be affected, too. But I realize we have hardly any means to find out.

Quoted 13 lines
xen/arch/x86/cpu/amd.c +9 -0
@@ -1189,3 +1190,44 @@ const struct cpu_dev amd_cpu_dev = {
 	.c_early_init	= early_init_amd,
 	.c_init		= init_amd,
 };
+
+static void cf_check disable_c6(void *arg)
+{
+	printk(XENLOG_WARNING
+	       "Disabling C6 after 1000 days uptime due to AMD errata 1474\n");
+	amd_disable_c6 = true;
+}
+
+static int __init cf_check amd_c6_errata(void)

xen/arch/x86/cpu/amd.c const struct cpu_dev amd_cpu_dev = { · line 1211

Quoted 10 lines
xen/arch/x86/cpu/amd.c +10 -0
+{
+	/*
+	 * Errata #1474: A Core May Hang After About 1044 Days
+	 * Set up a timer to disable C6 after 1000 days uptime.
+	 */
+	s_time_t;
+
+	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD ||
+	    boot_cpu_data.x86 != 0x17 ||
+	    (boot_cpu_data.x86_model & 0xf0) != 0x30)

Perhaps better ... & ~0xf, just to be future-proof?

xen/arch/x86/cpu/amd.c const struct cpu_dev amd_cpu_dev = { · line 1218

Quoted 7 lines
xen/arch/x86/cpu/amd.c +7 -0
+		return 0;
+
+	/*
+	 * Deduct current TSC value, this would be relevant if
+	 * kexec'ed for example.
+	 */
+	delta = DAYS(1000) - tsc_ticks2ns(rdtsc());

Generally the TSC can be written (and we actually do so under certain circumstances), so deriving any absolute time from the TSC value is of at best questionable value.

Furthermore, perhaps better overall to suppress all of this logic when we're running virtualized ourselves?

xen/arch/x86/cpu/amd.c const struct cpu_dev amd_cpu_dev = { · line 1225

Quoted 7 lines
xen/arch/x86/cpu/amd.c +7 -0
+	if (delta > 0) {
+		static struct timer errata_c6;
+
+		init_timer(&errata_c6, disable_c6, NULL, 0);
+		set_timer(&errata_c6, NOW() + delta);
+	} else
+		disable_c6(NULL);

The log message is going to be misleading in this case. Maybe pass that as the so far unused handler argument? Albeit I realize that this will mean casting away const-ness, which isn't very nice.

xen/include/xen/time.h struct tm wallclock_time(uint64_t *ns); · line 59

Quoted 10 lines
xen/include/xen/time.h +1 -0
@@ -53,6 +53,7 @@ struct tm wallclock_time(uint64_t *ns);
 
 #define SYSTEM_TIME_HZ  1000000000ULL
 #define NOW()           ((s_time_t)get_s_time())
+#define DAYS(_d)        ((s_time_t)((_d)  * 86400000000000ULL))
 #define SECONDS(_s)     ((s_time_t)((_s)  * 1000000000ULL))
 #define MILLISECS(_ms)  ((s_time_t)((_ms) * 1000000ULL))
 #define MICROSECS(_us)  ((s_time_t)((_us) * 1000ULL))

While consistent with the other macros we have here, I think this would be neater as

#define DAYS(_d) SECONDS((_d) * 86400ULL))

especially if considering that yet later someone may want to add YEARS().

Jan

#3 lore raw
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Roger Pau Monne

As specified on Errata 1474:

"A core will fail to exit CC6 after about 1044 days after the last system reset. The time of failure may vary depending on the spread spectrum and REFCLK frequency."

Detect when running on AMD Fam17h models 30h-3fh and setup a timer to prevent entering C6 after 1000 days have elapsed. Take into account the TSC value at boot in order to account for any time elapsed before Xen has been booted.

Quoted 7 lines

Models 6x are also affected as per their RG. I have some trouble with the site, so it's too slow going to actually try and fish out the RGs for the other possible models.

Given more than one set of models is affected I of course also wonder whether Hygon CPUs wouldn't be affected, too. But I realize we have hardly any means to find out.

I'd say it's more likely than unlikely, and ...

Quoted 16 lines
Quoted 16 lines
xen/arch/x86/cpu/amd.c +12 -0
@@ -1189,3 +1190,44 @@ const struct cpu_dev amd_cpu_dev = {
 	.c_early_init	= early_init_amd,
 	.c_init		= init_amd,
 };
+
+static void cf_check disable_c6(void *arg)
+{
+	printk(XENLOG_WARNING
+	       "Disabling C6 after 1000 days uptime due to AMD errata 1474\n");
+	amd_disable_c6 = true;
+}
+
+static int __init cf_check amd_c6_errata(void)
+{
+	/*
+	 * Errata #1474: A Core May Hang After About 1044 Days
Quoted 8 lines

xen/arch/x86/cpu/amd.c const struct cpu_dev amd_cpu_dev = { · line 1211

Quoted 7 lines
xen/arch/x86/cpu/amd.c +7 -0
+	 * Set up a timer to disable C6 after 1000 days uptime.
+	 */
+	s_time_t;
+
+	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD ||
+	    boot_cpu_data.x86 != 0x17 ||
+	    (boot_cpu_data.x86_model & 0xf0) != 0x30)

Perhaps better ... & ~0xf, just to be future-proof?

... this wants to follow the same logic as for Branch Type Confusion. See amd_init_spectral_chicken() looking for STIBP.

It's very likely all Zen2 models, given that it will have taken nearly 3 years to be discovered in the first place...

~Andrew

#4 lore raw
In reply to Jan Beulich
Quoted 12 lines · Jan Beulich
Quoted 10 lines · Roger Pau Monne

As specified on Errata 1474:

"A core will fail to exit CC6 after about 1044 days after the last system reset. The time of failure may vary depending on the spread spectrum and REFCLK frequency."

Detect when running on AMD Fam17h models 30h-3fh and setup a timer to prevent entering C6 after 1000 days have elapsed. Take into account the TSC value at boot in order to account for any time elapsed before Xen has been booted.

Quoted 7 lines

Models 6x are also affected as per their RG. I have some trouble with the site, so it's too slow going to actually try and fish out the RGs for the other possible models.

Given more than one set of models is affected I of course also wonder whether Hygon CPUs wouldn't be affected, too. But I realize we have hardly any means to find out.

I've considered Hygon, but as you say I have no way I know to figure out what models are affected.

Quoted 17 lines
Quoted 17 lines
xen/arch/x86/cpu/amd.c +13 -0
@@ -1189,3 +1190,44 @@ const struct cpu_dev amd_cpu_dev = {
 	.c_early_init	= early_init_amd,
 	.c_init		= init_amd,
 };
+
+static void cf_check disable_c6(void *arg)
+{
+	printk(XENLOG_WARNING
+	       "Disabling C6 after 1000 days uptime due to AMD errata 1474\n");
+	amd_disable_c6 = true;
+}
+
+static int __init cf_check amd_c6_errata(void)
+{
+	/*
+	 * Errata #1474: A Core May Hang After About 1044 Days
+	 * Set up a timer to disable C6 after 1000 days uptime.
Quoted 8 lines

xen/arch/x86/cpu/amd.c const struct cpu_dev amd_cpu_dev = { · line 1211

Quoted 6 lines
xen/arch/x86/cpu/amd.c +6 -0
+	 */
+	s_time_t;
+
+	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD ||
+	    boot_cpu_data.x86 != 0x17 ||
+	    (boot_cpu_data.x86_model & 0xf0) != 0x30)

Perhaps better ... & ~0xf, just to be future-proof?

Right, will need to change anyway to account for 0x60 models. But x86_model is a char, and hence the mask is 0xff only (8 bits).

Quoted 11 lines

xen/arch/x86/cpu/amd.c const struct cpu_dev amd_cpu_dev = { · line 1218

Quoted 7 lines
xen/arch/x86/cpu/amd.c +7 -0
+		return 0;
+
+	/*
+	 * Deduct current TSC value, this would be relevant if
+	 * kexec'ed for example.
+	 */
+	delta = DAYS(1000) - tsc_ticks2ns(rdtsc());

Generally the TSC can be written (and we actually do so under certain circumstances), so deriving any absolute time from the TSC value is of at best questionable value.

It's IMO better than not accounting for the TSC at all. Worst case is we end up disabling C6 before actually required, but that would leave us in safe position anyway.

Quoted 2 lines

Furthermore, perhaps better overall to suppress all of this logic when we're running virtualized ourselves?

Indeed, will do that.

Quoted 11 lines

xen/arch/x86/cpu/amd.c const struct cpu_dev amd_cpu_dev = { · line 1225

Quoted 7 lines
xen/arch/x86/cpu/amd.c +7 -0
+	if (delta > 0) {
+		static struct timer errata_c6;
+
+		init_timer(&errata_c6, disable_c6, NULL, 0);
+		set_timer(&errata_c6, NOW() + delta);
+	} else
+		disable_c6(NULL);

The log message is going to be misleading in this case. Maybe pass that as the so far unused handler argument? Albeit I realize that this will mean casting away const-ness, which isn't very nice.

I think we could use the same message in both cases, what about:

"Disabling C6 after 1000 days hardware uptime due to AMD errata 1474"

Quoted 14 lines

xen/include/xen/time.h struct tm wallclock_time(uint64_t *ns); · line 59

Quoted 10 lines
xen/include/xen/time.h +1 -0
@@ -53,6 +53,7 @@ struct tm wallclock_time(uint64_t *ns);
 
 #define SYSTEM_TIME_HZ  1000000000ULL
 #define NOW()           ((s_time_t)get_s_time())
+#define DAYS(_d)        ((s_time_t)((_d)  * 86400000000000ULL))
 #define SECONDS(_s)     ((s_time_t)((_s)  * 1000000000ULL))
 #define MILLISECS(_ms)  ((s_time_t)((_ms) * 1000000ULL))
 #define MICROSECS(_us)  ((s_time_t)((_us) * 1000ULL))

While consistent with the other macros we have here, I think this would be neater as

Quoted 1 line

#define DAYS(_d) SECONDS((_d) * 86400ULL))

Hm, it would make more sense to introduce the missing macros between DAYS() and SECONDS() (MINUTES() and HOURS()) and use HOURS() in DAYS()?

Thanks, Roger.

#5 lore raw
Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Jan Beulich
Quoted 10 lines · Roger Pau Monne

As specified on Errata 1474:

"A core will fail to exit CC6 after about 1044 days after the last system reset. The time of failure may vary depending on the spread spectrum and REFCLK frequency."

Detect when running on AMD Fam17h models 30h-3fh and setup a timer to prevent entering C6 after 1000 days have elapsed. Take into account the TSC value at boot in order to account for any time elapsed before Xen has been booted.

Models 6x are also affected as per their RG. I have some trouble with the site, so it's too slow going to actually try and fish out the RGs for the other possible models.

Quoted 6 lines
Quoted 3 lines

Given more than one set of models is affected I of course also wonder whether Hygon CPUs wouldn't be affected, too. But I realize we have hardly any means to find out.

I've considered Hygon, but as you say I have no way I know to figure out what models are affected.

Well, see also Andrew's reply.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/cpu/amd.c +5 -0
+static int __init cf_check amd_c6_errata(void)
+{
+	/*
+	 * Errata #1474: A Core May Hang After About 1044 Days
+	 * Set up a timer to disable C6 after 1000 days uptime.
Quoted 8 lines

xen/arch/x86/cpu/amd.c const struct cpu_dev amd_cpu_dev = { · line 1211

Quoted 6 lines
xen/arch/x86/cpu/amd.c +6 -0
+	 */
+	s_time_t;
+
+	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD ||
+	    boot_cpu_data.x86 != 0x17 ||
+	    (boot_cpu_data.x86_model & 0xf0) != 0x30)

Perhaps better ... & ~0xf, just to be future-proof?

Quoted 2 lines

Right, will need to change anyway to account for 0x60 models. But x86_model is a char, and hence the mask is 0xff only (8 bits).

I understand it is right now, hence why I said future proof. I consider it possible that upon widening the field an expression like the one above might be overlooked.

Quoted 12 lines
Quoted 11 lines

xen/arch/x86/cpu/amd.c const struct cpu_dev amd_cpu_dev = { · line 1218

Quoted 7 lines
xen/arch/x86/cpu/amd.c +7 -0
+		return 0;
+
+	/*
+	 * Deduct current TSC value, this would be relevant if
+	 * kexec'ed for example.
+	 */
+	delta = DAYS(1000) - tsc_ticks2ns(rdtsc());

Generally the TSC can be written (and we actually do so under certain circumstances), so deriving any absolute time from the TSC value is of at best questionable value.

Quoted 3 lines

It's IMO better than not accounting for the TSC at all. Worst case is we end up disabling C6 before actually required, but that would leave us in safe position anyway.

Hmm, yes, fair point.

Quoted 12 lines
Quoted 11 lines

xen/arch/x86/cpu/amd.c const struct cpu_dev amd_cpu_dev = { · line 1225

Quoted 7 lines
xen/arch/x86/cpu/amd.c +7 -0
+	if (delta > 0) {
+		static struct timer errata_c6;
+
+		init_timer(&errata_c6, disable_c6, NULL, 0);
+		set_timer(&errata_c6, NOW() + delta);
+	} else
+		disable_c6(NULL);

The log message is going to be misleading in this case. Maybe pass that as the so far unused handler argument? Albeit I realize that this will mean casting away const-ness, which isn't very nice.

Quoted 3 lines

I think we could use the same message in both cases, what about:

"Disabling C6 after 1000 days hardware uptime due to AMD errata 1474"

But that's still misleading if TSC was ever written. The message is pretty long already, but inserting "apparent" would address this.

Quoted 14 lines
Quoted 14 lines

xen/include/xen/time.h struct tm wallclock_time(uint64_t *ns); · line 59

Quoted 10 lines
xen/include/xen/time.h +1 -0
@@ -53,6 +53,7 @@ struct tm wallclock_time(uint64_t *ns);
 
 #define SYSTEM_TIME_HZ  1000000000ULL
 #define NOW()           ((s_time_t)get_s_time())
+#define DAYS(_d)        ((s_time_t)((_d)  * 86400000000000ULL))
 #define SECONDS(_s)     ((s_time_t)((_s)  * 1000000000ULL))
 #define MILLISECS(_ms)  ((s_time_t)((_ms) * 1000000ULL))
 #define MICROSECS(_us)  ((s_time_t)((_us) * 1000ULL))

While consistent with the other macros we have here, I think this would be neater as

Quoted 4 lines
Quoted 1 line

#define DAYS(_d) SECONDS((_d) * 86400ULL))

Hm, it would make more sense to introduce the missing macros between DAYS() and SECONDS() (MINUTES() and HOURS()) and use HOURS() in DAYS()?

Probably, but I didn't want to go as far as asking for this.

Jan