| @@ -229,6 +229,9 @@ static const struct { · 228 unmodified lines |
| 229 | 229 | #define L1D_CACHE_ORDER 4 |
| 230 | 230 | static void *vmx_l1d_flush_pages; |
| 231 | 231 | |
| 232 | +/* Control for disabling CPU Fill buffer clear */ |
| 233 | +static bool __read_mostly vmx_fb_clear_ctrl_available; |
| 234 | + |
| 232 | 235 | static int vmx_setup_l1d_flush(enum vmx_l1d_flush_state l1tf) |
| 233 | 236 | { |
| 234 | 237 | struct page *page; |
| @@ -360,6 +363,60 @@ static int vmentry_l1d_flush_get(char *s, const struct kernel_param *kp) · 125 unmodified lines |
| 360 | 363 | return sprintf(s, "%s\n", vmentry_l1d_param[l1tf_vmx_mitigation].option); |
| 361 | 364 | } |
| 362 | 365 | |
| 366 | +static void vmx_setup_fb_clear_ctrl(void) |
| 367 | +{ |
| 368 | + u64 msr; |
| 369 | + |
| 370 | + if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES) && |
| 371 | + !boot_cpu_has_bug(X86_BUG_MDS) && |
| 372 | + !boot_cpu_has_bug(X86_BUG_TAA)) { |
| 373 | + rdmsrl(MSR_IA32_ARCH_CAPABILITIES, msr); |
| 374 | + if (msr & ARCH_CAP_FB_CLEAR_CTRL) |
| 375 | + vmx_fb_clear_ctrl_available = true; |
| 376 | + } |
| 377 | +} |
| 378 | + |
| 379 | +static __always_inline void vmx_disable_fb_clear(struct vcpu_vmx *vmx) |
| 380 | +{ |
| 381 | + u64 msr; |
| 382 | + |
| 383 | + if (!vmx->disable_fb_clear) |
| 384 | + return; |
| 385 | + |
| 386 | + rdmsrl(MSR_IA32_MCU_OPT_CTRL, msr); |
| 387 | + msr |= FB_CLEAR_DIS; |
| 388 | + wrmsrl(MSR_IA32_MCU_OPT_CTRL, msr); |
| 389 | + /* Cache the MSR value to avoid reading it later */ |
| 390 | + vmx->msr_ia32_mcu_opt_ctrl = msr; |
| 391 | +} |
| 392 | + |
| 393 | +static __always_inline void vmx_enable_fb_clear(struct vcpu_vmx *vmx) |
| 394 | +{ |
| 395 | + if (!vmx->disable_fb_clear) |
| 396 | + return; |
| 397 | + |
| 398 | + vmx->msr_ia32_mcu_opt_ctrl &= ~FB_CLEAR_DIS; |
| 399 | + wrmsrl(MSR_IA32_MCU_OPT_CTRL, vmx->msr_ia32_mcu_opt_ctrl); |
| 400 | +} |
| 401 | + |
| 402 | +static void vmx_update_fb_clear_dis(struct kvm_vcpu *vcpu, struct vcpu_vmx *vmx) |
| 403 | +{ |
| 404 | + vmx->disable_fb_clear = vmx_fb_clear_ctrl_available; |
| 405 | + |
| 406 | + /* |
| 407 | + * If guest will not execute VERW, there is no need to set FB_CLEAR_DIS |
| 408 | + * at VMEntry. Skip the MSR read/write when a guest has no use case to |
| 409 | + * execute VERW. |
| 410 | + */ |
| 411 | + if ((vcpu->arch.arch_capabilities & ARCH_CAP_FB_CLEAR) || |
| 412 | + ((vcpu->arch.arch_capabilities & ARCH_CAP_MDS_NO) && |
| 413 | + (vcpu->arch.arch_capabilities & ARCH_CAP_TAA_NO) && |
| 414 | + (vcpu->arch.arch_capabilities & ARCH_CAP_PSDP_NO) && |
| 415 | + (vcpu->arch.arch_capabilities & ARCH_CAP_FBSDP_NO) && |
| 416 | + (vcpu->arch.arch_capabilities & ARCH_CAP_SBDR_SSDP_NO))) |
| 417 | + vmx->disable_fb_clear = false; |
| 418 | +} |
| 419 | + |
| 363 | 420 | static const struct kernel_param_ops vmentry_l1d_flush_ops = { |
| 364 | 421 | .set = vmentry_l1d_flush_set, |
| 365 | 422 | .get = vmentry_l1d_flush_get, |
| @@ -2252,6 +2309,10 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) · 1886 unmodified lines |
| 2252 | 2309 | ret = kvm_set_msr_common(vcpu, msr_info); |
| 2253 | 2310 | } |
| 2254 | 2311 | |
| 2312 | + /* FB_CLEAR may have changed, also update the FB_CLEAR_DIS behavior */ |
| 2313 | + if (msr_index == MSR_IA32_ARCH_CAPABILITIES) |
| 2314 | + vmx_update_fb_clear_dis(vcpu, vmx); |
| 2315 | + |
| 2255 | 2316 | return ret; |
| 2256 | 2317 | } |
| 2257 | 2318 | |
| @@ -4553,6 +4614,8 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) · 2295 unmodified lines |
| 4553 | 4614 | kvm_make_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu); |
| 4554 | 4615 | |
| 4555 | 4616 | vpid_sync_context(vmx->vpid); |
| 4617 | + |
| 4618 | + vmx_update_fb_clear_dis(vcpu, vmx); |
| 4556 | 4619 | } |
| 4557 | 4620 | |
| 4558 | 4621 | static void vmx_enable_irq_window(struct kvm_vcpu *vcpu) |
| @@ -6777,6 +6840,8 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu, · 2218 unmodified lines |
| 6777 | 6840 | kvm_arch_has_assigned_device(vcpu->kvm)) |
| 6778 | 6841 | mds_clear_cpu_buffers(); |
| 6779 | 6842 | |
| 6843 | + vmx_disable_fb_clear(vmx); |
| 6844 | + |
| 6780 | 6845 | if (vcpu->arch.cr2 != native_read_cr2()) |
| 6781 | 6846 | native_write_cr2(vcpu->arch.cr2); |
| 6782 | 6847 | |
| @@ -6785,6 +6850,8 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu, · 2 unmodified lines |
| 6785 | 6850 | |
| 6786 | 6851 | vcpu->arch.cr2 = native_read_cr2(); |
| 6787 | 6852 | |
| 6853 | + vmx_enable_fb_clear(vmx); |
| 6854 | + |
| 6788 | 6855 | guest_state_exit_irqoff(); |
| 6789 | 6856 | } |
| 6790 | 6857 | |
| @@ -8185,6 +8252,8 @@ static int __init vmx_init(void) · 1394 unmodified lines |
| 8185 | 8252 | return r; |
| 8186 | 8253 | } |
| 8187 | 8254 | |
| 8255 | + vmx_setup_fb_clear_ctrl(); |
| 8256 | + |
| 8188 | 8257 | for_each_possible_cpu(cpu) { |
| 8189 | 8258 | INIT_LIST_HEAD(&per_cpu(loaded_vmcss_on_cpu, cpu)); |
| 8190 | 8259 | |