@@ -51,6 +51,7 @@ static void __init srso_select_mitigation(void);
5151static void __init gds_select_mitigation (void );
5252static void __init its_select_mitigation (void );
5353static void __init tsa_select_mitigation (void );
54+ static void __init vmscape_select_mitigation (void );
5455
5556/* The base value of the SPEC_CTRL MSR without task-specific bits set */
5657u64 x86_spec_ctrl_base ;
@@ -194,6 +195,7 @@ void __init cpu_select_mitigations(void)
194195 gds_select_mitigation ();
195196 its_select_mitigation ();
196197 tsa_select_mitigation ();
198+ vmscape_select_mitigation ();
197199}
198200
199201/*
@@ -2949,6 +2951,68 @@ static void __init srso_select_mitigation(void)
29492951 x86_pred_cmd = PRED_CMD_SBPB ;
29502952}
29512953
2954+ #undef pr_fmt
2955+ #define pr_fmt (fmt ) "VMSCAPE: " fmt
2956+
2957+ enum vmscape_mitigations {
2958+ VMSCAPE_MITIGATION_NONE ,
2959+ VMSCAPE_MITIGATION_AUTO ,
2960+ VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER ,
2961+ VMSCAPE_MITIGATION_IBPB_ON_VMEXIT ,
2962+ };
2963+
2964+ static const char * const vmscape_strings [] = {
2965+ [VMSCAPE_MITIGATION_NONE ] = "Vulnerable" ,
2966+ /* [VMSCAPE_MITIGATION_AUTO] */
2967+ [VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER ] = "Mitigation: IBPB before exit to userspace" ,
2968+ [VMSCAPE_MITIGATION_IBPB_ON_VMEXIT ] = "Mitigation: IBPB on VMEXIT" ,
2969+ };
2970+
2971+ static enum vmscape_mitigations vmscape_mitigation __ro_after_init =
2972+ IS_ENABLED (CONFIG_MITIGATION_VMSCAPE ) ? VMSCAPE_MITIGATION_AUTO : VMSCAPE_MITIGATION_NONE ;
2973+
2974+ static int __init vmscape_parse_cmdline (char * str )
2975+ {
2976+ if (!str )
2977+ return - EINVAL ;
2978+
2979+ if (!strcmp (str , "off" )) {
2980+ vmscape_mitigation = VMSCAPE_MITIGATION_NONE ;
2981+ } else if (!strcmp (str , "ibpb" )) {
2982+ vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER ;
2983+ } else if (!strcmp (str , "force" )) {
2984+ setup_force_cpu_bug (X86_BUG_VMSCAPE );
2985+ vmscape_mitigation = VMSCAPE_MITIGATION_AUTO ;
2986+ } else {
2987+ pr_err ("Ignoring unknown vmscape=%s option.\n" , str );
2988+ }
2989+
2990+ return 0 ;
2991+ }
2992+ early_param ("vmscape" , vmscape_parse_cmdline );
2993+
2994+ static void __init vmscape_select_mitigation (void )
2995+ {
2996+ if (cpu_mitigations_off () ||
2997+ !boot_cpu_has_bug (X86_BUG_VMSCAPE ) ||
2998+ !boot_cpu_has (X86_FEATURE_IBPB )) {
2999+ vmscape_mitigation = VMSCAPE_MITIGATION_NONE ;
3000+ return ;
3001+ }
3002+
3003+ if (vmscape_mitigation == VMSCAPE_MITIGATION_AUTO )
3004+ vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER ;
3005+
3006+ if (retbleed_mitigation == RETBLEED_MITIGATION_IBPB ||
3007+ srso_mitigation == SRSO_MITIGATION_IBPB_ON_VMEXIT )
3008+ vmscape_mitigation = VMSCAPE_MITIGATION_IBPB_ON_VMEXIT ;
3009+
3010+ if (vmscape_mitigation == VMSCAPE_MITIGATION_IBPB_EXIT_TO_USER )
3011+ setup_force_cpu_cap (X86_FEATURE_IBPB_EXIT_TO_USER );
3012+
3013+ pr_info ("%s\n" , vmscape_strings [vmscape_mitigation ]);
3014+ }
3015+
29523016#undef pr_fmt
29533017#define pr_fmt (fmt ) fmt
29543018
@@ -3195,6 +3259,11 @@ static ssize_t tsa_show_state(char *buf)
31953259 return sysfs_emit (buf , "%s\n" , tsa_strings [tsa_mitigation ]);
31963260}
31973261
3262+ static ssize_t vmscape_show_state (char * buf )
3263+ {
3264+ return sysfs_emit (buf , "%s\n" , vmscape_strings [vmscape_mitigation ]);
3265+ }
3266+
31983267static ssize_t cpu_show_common (struct device * dev , struct device_attribute * attr ,
31993268 char * buf , unsigned int bug )
32003269{
@@ -3259,6 +3328,9 @@ static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr
32593328 case X86_BUG_TSA :
32603329 return tsa_show_state (buf );
32613330
3331+ case X86_BUG_VMSCAPE :
3332+ return vmscape_show_state (buf );
3333+
32623334 default :
32633335 break ;
32643336 }
@@ -3348,4 +3420,9 @@ ssize_t cpu_show_tsa(struct device *dev, struct device_attribute *attr, char *bu
33483420{
33493421 return cpu_show_common (dev , attr , buf , X86_BUG_TSA );
33503422}
3423+
3424+ ssize_t cpu_show_vmscape (struct device * dev , struct device_attribute * attr , char * buf )
3425+ {
3426+ return cpu_show_common (dev , attr , buf , X86_BUG_VMSCAPE );
3427+ }
33513428#endif
0 commit comments