Add kvm_cpu_cap_init_mf() to initialize CPUID leaves that encode multi-bit value fields for specified overlays. Unlike kvm_cpu_cap_init(), this helper directly assigns the provided value without intersecting it with native CPUID or boot_cpu_data. This is necessary because multi-bit fields encode numeric values, e.g. address widths, field sizes, etc., where the value userspace wants to expose to guests may differ from the native hardware value. Signed-off-by: Binbin Wu --- arch/x86/kvm/cpuid.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h index bdfaedb1cfcc..ea8ff5210e4a 100644 --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h @@ -259,6 +259,17 @@ static __always_inline void kvm_cpu_cap_check_and_set(unsigned int x86_feature, kvm_cpu_cap_set(x86_feature, overlay_mask); } +static __always_inline void kvm_cpu_cap_init_mf(u32 leaf, u32 features, u32 overlay_mask) +{ + WARN_ON_ONCE(!kvm_is_configuring_cpu_caps); + BUILD_BUG_ON(leaf >= NR_KVM_CPU_CAPS_PARANOID); + + for (int i = 0; i < NR_CPUID_OL; i++) { + if (overlay_mask & BIT(i)) + kvm_cpu_caps[i][leaf] = features; + } +} + static __always_inline bool guest_pv_has(struct kvm_vcpu *vcpu, unsigned int kvm_feature) { -- 2.46.0