@@ -422,6 +422,13 @@ static void __init mmio_select_mitigation(void)
422422 if (boot_cpu_has_bug (X86_BUG_MDS ) || (boot_cpu_has_bug (X86_BUG_TAA ) &&
423423 boot_cpu_has (X86_FEATURE_RTM )))
424424 setup_force_cpu_cap (X86_FEATURE_CLEAR_CPU_BUF );
425+
426+ /*
427+ * X86_FEATURE_CLEAR_CPU_BUF could be enabled by other VERW based
428+ * mitigations, disable KVM-only mitigation in that case.
429+ */
430+ if (boot_cpu_has (X86_FEATURE_CLEAR_CPU_BUF ))
431+ static_branch_disable (& mmio_stale_data_clear );
425432 else
426433 static_branch_enable (& mmio_stale_data_clear );
427434
@@ -473,6 +480,57 @@ static int __init mmio_stale_data_parse_cmdline(char *str)
473480}
474481early_param ("mmio_stale_data" , mmio_stale_data_parse_cmdline );
475482
483+ #undef pr_fmt
484+ #define pr_fmt (fmt ) "Register File Data Sampling: " fmt
485+
486+ enum rfds_mitigations {
487+ RFDS_MITIGATION_OFF ,
488+ RFDS_MITIGATION_VERW ,
489+ RFDS_MITIGATION_UCODE_NEEDED ,
490+ };
491+
492+ /* Default mitigation for Register File Data Sampling */
493+ static enum rfds_mitigations rfds_mitigation __ro_after_init =
494+ IS_ENABLED (CONFIG_MITIGATION_RFDS ) ? RFDS_MITIGATION_VERW : RFDS_MITIGATION_OFF ;
495+
496+ static const char * const rfds_strings [] = {
497+ [RFDS_MITIGATION_OFF ] = "Vulnerable" ,
498+ [RFDS_MITIGATION_VERW ] = "Mitigation: Clear Register File" ,
499+ [RFDS_MITIGATION_UCODE_NEEDED ] = "Vulnerable: No microcode" ,
500+ };
501+
502+ static void __init rfds_select_mitigation (void )
503+ {
504+ if (!boot_cpu_has_bug (X86_BUG_RFDS ) || cpu_mitigations_off ()) {
505+ rfds_mitigation = RFDS_MITIGATION_OFF ;
506+ return ;
507+ }
508+ if (rfds_mitigation == RFDS_MITIGATION_OFF )
509+ return ;
510+
511+ if (x86_read_arch_cap_msr () & ARCH_CAP_RFDS_CLEAR )
512+ setup_force_cpu_cap (X86_FEATURE_CLEAR_CPU_BUF );
513+ else
514+ rfds_mitigation = RFDS_MITIGATION_UCODE_NEEDED ;
515+ }
516+
517+ static __init int rfds_parse_cmdline (char * str )
518+ {
519+ if (!str )
520+ return - EINVAL ;
521+
522+ if (!boot_cpu_has_bug (X86_BUG_RFDS ))
523+ return 0 ;
524+
525+ if (!strcmp (str , "off" ))
526+ rfds_mitigation = RFDS_MITIGATION_OFF ;
527+ else if (!strcmp (str , "on" ))
528+ rfds_mitigation = RFDS_MITIGATION_VERW ;
529+
530+ return 0 ;
531+ }
532+ early_param ("reg_file_data_sampling" , rfds_parse_cmdline );
533+
476534#undef pr_fmt
477535#define pr_fmt (fmt ) "" fmt
478536
@@ -498,11 +556,19 @@ static void __init md_clear_update_mitigation(void)
498556 taa_mitigation = TAA_MITIGATION_VERW ;
499557 taa_select_mitigation ();
500558 }
501- if (mmio_mitigation == MMIO_MITIGATION_OFF &&
502- boot_cpu_has_bug (X86_BUG_MMIO_STALE_DATA )) {
559+ /*
560+ * MMIO_MITIGATION_OFF is not checked here so that mmio_stale_data_clear
561+ * gets updated correctly as per X86_FEATURE_CLEAR_CPU_BUF state.
562+ */
563+ if (boot_cpu_has_bug (X86_BUG_MMIO_STALE_DATA )) {
503564 mmio_mitigation = MMIO_MITIGATION_VERW ;
504565 mmio_select_mitigation ();
505566 }
567+ if (rfds_mitigation == RFDS_MITIGATION_OFF &&
568+ boot_cpu_has_bug (X86_BUG_RFDS )) {
569+ rfds_mitigation = RFDS_MITIGATION_VERW ;
570+ rfds_select_mitigation ();
571+ }
506572out :
507573 if (boot_cpu_has_bug (X86_BUG_MDS ))
508574 pr_info ("MDS: %s\n" , mds_strings [mds_mitigation ]);
@@ -512,18 +578,21 @@ static void __init md_clear_update_mitigation(void)
512578 pr_info ("MMIO Stale Data: %s\n" , mmio_strings [mmio_mitigation ]);
513579 else if (boot_cpu_has_bug (X86_BUG_MMIO_UNKNOWN ))
514580 pr_info ("MMIO Stale Data: Unknown: No mitigations\n" );
581+ if (boot_cpu_has_bug (X86_BUG_RFDS ))
582+ pr_info ("Register File Data Sampling: %s\n" , rfds_strings [rfds_mitigation ]);
515583}
516584
517585static void __init md_clear_select_mitigation (void )
518586{
519587 mds_select_mitigation ();
520588 taa_select_mitigation ();
521589 mmio_select_mitigation ();
590+ rfds_select_mitigation ();
522591
523592 /*
524- * As MDS, TAA and MMIO Stale Data mitigations are inter-related, update
525- * and print their mitigation after MDS, TAA and MMIO Stale Data
526- * mitigation selection is done.
593+ * As these mitigations are inter-related and rely on VERW instruction
594+ * to clear the microarchitural buffers, update and print their status
595+ * after mitigation selection is done for each of these vulnerabilities .
527596 */
528597 md_clear_update_mitigation ();
529598}
@@ -2613,6 +2682,11 @@ static ssize_t mmio_stale_data_show_state(char *buf)
26132682 sched_smt_active () ? "vulnerable" : "disabled" );
26142683}
26152684
2685+ static ssize_t rfds_show_state (char * buf )
2686+ {
2687+ return sysfs_emit (buf , "%s\n" , rfds_strings [rfds_mitigation ]);
2688+ }
2689+
26162690static char * stibp_state (void )
26172691{
26182692 if (spectre_v2_in_eibrs_mode (spectre_v2_enabled ) &&
@@ -2772,6 +2846,9 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr
27722846 case X86_BUG_GDS :
27732847 return gds_show_state (buf );
27742848
2849+ case X86_BUG_RFDS :
2850+ return rfds_show_state (buf );
2851+
27752852 default :
27762853 break ;
27772854 }
@@ -2846,6 +2923,11 @@ ssize_t cpu_show_gds(struct device *dev, struct device_attribute *attr, char *bu
28462923{
28472924 return cpu_show_common (dev , attr , buf , X86_BUG_GDS );
28482925}
2926+
2927+ ssize_t cpu_show_reg_file_data_sampling (struct device * dev , struct device_attribute * attr , char * buf )
2928+ {
2929+ return cpu_show_common (dev , attr , buf , X86_BUG_RFDS );
2930+ }
28492931#endif
28502932
28512933void __warn_thunk (void )
0 commit comments