* [PATCH] x86/CPU/AMD: don't force the CPB cap when running under a hypervisor
@ 2019-05-22 22:17 Frank van der Linden
2019-05-22 23:33 ` Borislav Petkov
2019-05-24 8:06 ` [tip:x86/urgent] x86/CPU/AMD: Don't " tip-bot for Frank van der Linden
0 siblings, 2 replies; 3+ messages in thread
From: Frank van der Linden @ 2019-05-22 22:17 UTC (permalink / raw)
To: x86; +Cc: linux-kernel, bp, jiaxun.yang
For F17h AMD CPUs, the CPB capability is forcibly set, because some
versions of that chip incorrectly report that they do not have it.
However, a hypervisor may filter out the CPB capability, for good
reasons. For example, KVM currently does not emulate setting the CPB
bit in MSR_K7_HWCR, and unchecked MSR access errors will be thrown
when trying to set it as a guest:
unchecked MSR access error: WRMSR to 0xc0010015 (tried to write
0x0000000001000011) at rIP: 0xffffffff890638f4
(native_write_msr+0x4/0x20)
Call Trace:
boost_set_msr+0x50/0x80 [acpi_cpufreq]
cpuhp_invoke_callback+0x86/0x560
sort_range+0x20/0x20
cpuhp_thread_fun+0xb0/0x110
smpboot_thread_fn+0xef/0x160
kthread+0x113/0x130
kthread_create_worker_on_cpu+0x70/0x70
ret_from_fork+0x35/0x40
To avoid this issue, don't forcibly set the CPB capability for a CPU
when running under a hypervisor.
Signed-off-by: Frank van der Linden <fllinden@amazon.com>
Fixes: 0237199186e7 ("x86/CPU/AMD: Set the CPB bit unconditionally on F17h")
---
arch/x86/kernel/cpu/amd.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index fb6a64bd765f..ee4d79fa1b19 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -823,8 +823,11 @@ static void init_amd_zn(struct cpuinfo_x86 *c)
{
set_cpu_cap(c, X86_FEATURE_ZEN);
- /* Fix erratum 1076: CPB feature bit not being set in CPUID. */
- if (!cpu_has(c, X86_FEATURE_CPB))
+ /*
+ * Fix erratum 1076: CPB feature bit not being set in CPUID.
+ * Always set it, except when running under a hypervisor.
+ */
+ if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && !cpu_has(c, X86_FEATURE_CPB))
set_cpu_cap(c, X86_FEATURE_CPB);
}
--
2.17.2
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] x86/CPU/AMD: don't force the CPB cap when running under a hypervisor
2019-05-22 22:17 [PATCH] x86/CPU/AMD: don't force the CPB cap when running under a hypervisor Frank van der Linden
@ 2019-05-22 23:33 ` Borislav Petkov
2019-05-24 8:06 ` [tip:x86/urgent] x86/CPU/AMD: Don't " tip-bot for Frank van der Linden
1 sibling, 0 replies; 3+ messages in thread
From: Borislav Petkov @ 2019-05-22 23:33 UTC (permalink / raw)
To: Frank van der Linden; +Cc: x86, linux-kernel, jiaxun.yang, Rafael J. Wysocki
On Wed, May 22, 2019 at 10:17:45PM +0000, Frank van der Linden wrote:
> For F17h AMD CPUs, the CPB capability is forcibly set, because some
> versions of that chip incorrectly report that they do not have it.
>
> However, a hypervisor may filter out the CPB capability, for good
> reasons. For example, KVM currently does not emulate setting the CPB
> bit in MSR_K7_HWCR, and unchecked MSR access errors will be thrown
> when trying to set it as a guest:
>
> unchecked MSR access error: WRMSR to 0xc0010015 (tried to write
> 0x0000000001000011) at rIP: 0xffffffff890638f4
> (native_write_msr+0x4/0x20)
>
> Call Trace:
> boost_set_msr+0x50/0x80 [acpi_cpufreq]
> cpuhp_invoke_callback+0x86/0x560
> sort_range+0x20/0x20
> cpuhp_thread_fun+0xb0/0x110
> smpboot_thread_fn+0xef/0x160
> kthread+0x113/0x130
> kthread_create_worker_on_cpu+0x70/0x70
> ret_from_fork+0x35/0x40
>
> To avoid this issue, don't forcibly set the CPB capability for a CPU
> when running under a hypervisor.
>
> Signed-off-by: Frank van der Linden <fllinden@amazon.com>
> Fixes: 0237199186e7 ("x86/CPU/AMD: Set the CPB bit unconditionally on F17h")
> ---
> arch/x86/kernel/cpu/amd.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
> index fb6a64bd765f..ee4d79fa1b19 100644
> --- a/arch/x86/kernel/cpu/amd.c
> +++ b/arch/x86/kernel/cpu/amd.c
> @@ -823,8 +823,11 @@ static void init_amd_zn(struct cpuinfo_x86 *c)
> {
> set_cpu_cap(c, X86_FEATURE_ZEN);
>
> - /* Fix erratum 1076: CPB feature bit not being set in CPUID. */
> - if (!cpu_has(c, X86_FEATURE_CPB))
> + /*
> + * Fix erratum 1076: CPB feature bit not being set in CPUID.
> + * Always set it, except when running under a hypervisor.
> + */
> + if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && !cpu_has(c, X86_FEATURE_CPB))
> set_cpu_cap(c, X86_FEATURE_CPB);
> }
I guess...
Acked-by: Borislav Petkov <bp@suse.de>
Btw, it has come up before whether it would be additionally prudent
to replace those *msr calls with their *msr_safe counterparts, in
boost_set_msr() and also check *msr_safe() retvals and exit early there.
Just in case and exactly because of virt.
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply. Srsly.
^ permalink raw reply [flat|nested] 3+ messages in thread* [tip:x86/urgent] x86/CPU/AMD: Don't force the CPB cap when running under a hypervisor
2019-05-22 22:17 [PATCH] x86/CPU/AMD: don't force the CPB cap when running under a hypervisor Frank van der Linden
2019-05-22 23:33 ` Borislav Petkov
@ 2019-05-24 8:06 ` tip-bot for Frank van der Linden
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Frank van der Linden @ 2019-05-24 8:06 UTC (permalink / raw)
To: linux-tip-commits
Cc: luto, mingo, fllinden, hpa, linux-kernel, tglx, torvalds, bp, peterz
Commit-ID: 2ac44ab608705948564791ce1d15d43ba81a1e38
Gitweb: https://git.kernel.org/tip/2ac44ab608705948564791ce1d15d43ba81a1e38
Author: Frank van der Linden <fllinden@amazon.com>
AuthorDate: Wed, 22 May 2019 22:17:45 +0000
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 24 May 2019 08:50:32 +0200
x86/CPU/AMD: Don't force the CPB cap when running under a hypervisor
For F17h AMD CPUs, the CPB capability ('Core Performance Boost') is forcibly set,
because some versions of that chip incorrectly report that they do not have it.
However, a hypervisor may filter out the CPB capability, for good
reasons. For example, KVM currently does not emulate setting the CPB
bit in MSR_K7_HWCR, and unchecked MSR access errors will be thrown
when trying to set it as a guest:
unchecked MSR access error: WRMSR to 0xc0010015 (tried to write 0x0000000001000011) at rIP: 0xffffffff890638f4 (native_write_msr+0x4/0x20)
Call Trace:
boost_set_msr+0x50/0x80 [acpi_cpufreq]
cpuhp_invoke_callback+0x86/0x560
sort_range+0x20/0x20
cpuhp_thread_fun+0xb0/0x110
smpboot_thread_fn+0xef/0x160
kthread+0x113/0x130
kthread_create_worker_on_cpu+0x70/0x70
ret_from_fork+0x35/0x40
To avoid this issue, don't forcibly set the CPB capability for a CPU
when running under a hypervisor.
Signed-off-by: Frank van der Linden <fllinden@amazon.com>
Acked-by: Borislav Petkov <bp@suse.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: bp@alien8.de
Cc: jiaxun.yang@flygoat.com
Fixes: 0237199186e7 ("x86/CPU/AMD: Set the CPB bit unconditionally on F17h")
Link: http://lkml.kernel.org/r/20190522221745.GA15789@dev-dsk-fllinden-2c-c1893d73.us-west-2.amazon.com
[ Minor edits to the changelog. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/kernel/cpu/amd.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 80a405c2048a..8d4e50428b68 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -824,8 +824,11 @@ static void init_amd_zn(struct cpuinfo_x86 *c)
{
set_cpu_cap(c, X86_FEATURE_ZEN);
- /* Fix erratum 1076: CPB feature bit not being set in CPUID. */
- if (!cpu_has(c, X86_FEATURE_CPB))
+ /*
+ * Fix erratum 1076: CPB feature bit not being set in CPUID.
+ * Always set it, except when running under a hypervisor.
+ */
+ if (!cpu_has(c, X86_FEATURE_HYPERVISOR) && !cpu_has(c, X86_FEATURE_CPB))
set_cpu_cap(c, X86_FEATURE_CPB);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-05-24 8:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22 22:17 [PATCH] x86/CPU/AMD: don't force the CPB cap when running under a hypervisor Frank van der Linden
2019-05-22 23:33 ` Borislav Petkov
2019-05-24 8:06 ` [tip:x86/urgent] x86/CPU/AMD: Don't " tip-bot for Frank van der Linden
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome