host_cpu_policy already fetched the SVM CPUIDs, use it instead of open-coding cpuid.
Signed-off-by: Teddy Astie <[email protected]> --- It very likely doesn't work right now, as host_cpu_policy is not evaluated at this point (start_svm is unfortunately called before calculate_host_policy). So this is mostly a intent rather than something ready. There are also some other things I would like to improve on this, but not sure on the approach. It would be nice to move svm_feature_flags to host_cpu_policy, alike other bitmap-like leafs we have in cpu_policy. IOW move most of arch/x86/include/asm/hvm/svm/svm.h to cpu_policy infrastructure, which could also serve later for properly managing nested SVM features of a guest. And also move most policy calculation to it (feature dependencies check, erratas, ...). For instance check for AMD_ERRATUM_170 in cpu policy code, and mask cpu_has_svm_flushbyasid if CPU is affected, trying to declutter SVM logic from some errata checks. xen/arch/x86/hvm/svm/asid.c | 3 ++- xen/arch/x86/hvm/svm/svm.c | 4 ++-- xen/include/xen/lib/x86/cpu-policy.h | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/svm/asid.c b/xen/arch/x86/hvm/svm/asid.c index 03f98b7a8b..0af5874b76 100644 --- a/xen/arch/x86/hvm/svm/asid.c +++ b/xen/arch/x86/hvm/svm/asid.c @@ -5,6 +5,7 @@ */ #include <asm/amd.h> +#include <asm/cpu-policy.h> #include <asm/hvm/nestedhvm.h> #include <asm/hvm/svm/svm.h> @@ -16,7 +17,7 @@ void svm_asid_init(const struct cpuinfo_x86 *c) /* Check for erratum #170, and leave ASIDs disabled if it's present. */ if ( !cpu_has_amd_erratum(c, AMD_ERRATUM_170) ) - nasids = cpuid_ebx(0x8000000aU); + nasids = host_cpu_policy.extd.nasid; hvm_asid_init(nasids); } diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 2d7c598ffe..e3f503c328 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -15,6 +15,7 @@ #include <asm/amd.h> #include <asm/apic.h> +#include <asm/cpu-policy.h> #include <asm/cpufeature.h> #include <asm/current.h> #include <asm/debugreg.h> @@ -2494,8 +2495,7 @@ const struct hvm_function_table * __init start_svm(void) setup_vmcb_dump(); - if ( boot_cpu_data.extended_cpuid_level >= 0x8000000aU ) - svm_feature_flags = cpuid_edx(0x8000000aU); + svm_feature_flags = host_cpu_policy.extd.svm_feature_flags; printk("SVM: Supported advanced features:\n"); diff --git a/xen/include/xen/lib/x86/cpu-policy.h b/xen/include/xen/lib/x86/cpu-policy.h index f94f23e159..1e639ae713 100644 --- a/xen/include/xen/lib/x86/cpu-policy.h +++ b/xen/include/xen/lib/x86/cpu-policy.h @@ -270,7 +270,10 @@ struct cpu_policy uint32_t /* d */:32; uint64_t :64, :64; /* Leaf 0x80000009. */ - uint64_t :64, :64; /* Leaf 0x8000000a - SVM rev and features. */ + + /* Leaf 0x8000000a - SVM rev and features. */ + uint32_t :32, nasid:32, :32, svm_feature_flags:32; + uint64_t :64, :64; /* Leaf 0x8000000b. */ uint64_t :64, :64; /* Leaf 0x8000000c. */ uint64_t :64, :64; /* Leaf 0x8000000d. */ -- 2.51.2 -- Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
