Re: [tip: x86/cpu] x86/cpu: Clear SVM feature if disabled by BIOS
From: Ingo Molnar
Date: Fri Sep 22 2023 - 06:26:17 EST
* tip-bot2 for Paolo Bonzini <tip-bot2@xxxxxxxxxxxxx> wrote:
> --- a/arch/x86/kernel/cpu/amd.c
> +++ b/arch/x86/kernel/cpu/amd.c
> @@ -1031,6 +1031,8 @@ static void zenbleed_check(struct cpuinfo_x86 *c)
>
> static void init_amd(struct cpuinfo_x86 *c)
> {
> + u64 vm_cr;
> +
> early_init_amd(c);
>
> /*
> @@ -1082,6 +1084,14 @@ static void init_amd(struct cpuinfo_x86 *c)
>
> init_amd_cacheinfo(c);
>
> + if (cpu_has(c, X86_FEATURE_SVM)) {
> + rdmsrl(MSR_VM_CR, vm_cr);
> + if (vm_cr & SVM_VM_CR_SVM_DIS_MASK) {
> + pr_notice_once("SVM disabled (by BIOS) in MSR_VM_CR\n");
> + clear_cpu_cap(c, X86_FEATURE_SVM);
> + }
> + }
> +
> if (!cpu_has(c, X86_FEATURE_LFENCE_RDTSC) && cpu_has(c, X86_FEATURE_XMM2)) {
> /*
> * Use LFENCE for execution serialization. On families which
> diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c
> index defdc59..16f3463 100644
> --- a/arch/x86/kernel/cpu/hygon.c
> +++ b/arch/x86/kernel/cpu/hygon.c
> @@ -290,6 +290,8 @@ static void early_init_hygon(struct cpuinfo_x86 *c)
>
> static void init_hygon(struct cpuinfo_x86 *c)
> {
> + u64 vm_cr;
> +
> early_init_hygon(c);
>
> /*
> @@ -320,6 +322,14 @@ static void init_hygon(struct cpuinfo_x86 *c)
>
> init_hygon_cacheinfo(c);
>
> + if (cpu_has(c, X86_FEATURE_SVM)) {
> + rdmsrl(MSR_VM_CR, vm_cr);
> + if (vm_cr & SVM_VM_CR_SVM_DIS_MASK) {
> + pr_notice_once("SVM disabled (by BIOS) in MSR_VM_CR\n");
> + clear_cpu_cap(c, X86_FEATURE_SVM);
> + }
> + }
> +
1)
It's a bit sad that we are duplicating identical code.
2)
We are doing it in other cases as well: for example nearby_node() is
duplicated between arch/x86/kernel/cpu/amd.c and
arch/x86/kernel/cpu/hygon.c too.
3)
BTW., while look at this code I noticed that the 'Author' copyright
tag in arch/x86/kernel/cpu/hygon.c seems to be inaccurate:
// SPDX-License-Identifier: GPL-2.0+
/*
* Hygon Processor Support for Linux
*
* Copyright (C) 2018 Chengdu Haiguang IC Design Co., Ltd.
*
* Author: Pu Wen <puwen@xxxxxxxx>
*/
... as for example the nearby_node() was clearly copied & derived from
arch/x86/kernel/cpu/amd.c, which does not appear to be accurately reflected
in this copyright notice?
Thanks,
Ingo