3636#undef pr_fmt
3737#define pr_fmt (fmt ) "" fmt
3838
39- static bool boot_cpu_done ;
40-
41- static int __read_mostly __pat_enabled = IS_ENABLED ( CONFIG_X86_PAT ) ;
42- static void init_cache_modes ( void ) ;
39+ static bool __read_mostly boot_cpu_done ;
40+ static bool __read_mostly pat_disabled = ! IS_ENABLED ( CONFIG_X86_PAT );
41+ static bool __read_mostly pat_initialized ;
42+ static bool __read_mostly init_cm_done ;
4343
4444void pat_disable (const char * reason )
4545{
46- if (! __pat_enabled )
46+ if (pat_disabled )
4747 return ;
4848
4949 if (boot_cpu_done ) {
5050 WARN_ONCE (1 , "x86/PAT: PAT cannot be disabled after initialization\n" );
5151 return ;
5252 }
5353
54- __pat_enabled = 0 ;
54+ pat_disabled = true ;
5555 pr_info ("x86/PAT: %s\n" , reason );
56-
57- init_cache_modes ();
5856}
5957
6058static int __init nopat (char * str )
@@ -66,7 +64,7 @@ early_param("nopat", nopat);
6664
6765bool pat_enabled (void )
6866{
69- return !! __pat_enabled ;
67+ return pat_initialized ;
7068}
7169EXPORT_SYMBOL_GPL (pat_enabled );
7270
@@ -204,6 +202,8 @@ static void __init_cache_modes(u64 pat)
204202 update_cache_mode_entry (i , cache );
205203 }
206204 pr_info ("x86/PAT: Configuration [0-7]: %s\n" , pat_msg );
205+
206+ init_cm_done = true;
207207}
208208
209209#define PAT (x , y ) ((u64)PAT_ ## y << ((x)*8))
@@ -224,6 +224,7 @@ static void pat_bsp_init(u64 pat)
224224 }
225225
226226 wrmsrl (MSR_IA32_CR_PAT , pat );
227+ pat_initialized = true;
227228
228229 __init_cache_modes (pat );
229230}
@@ -241,10 +242,9 @@ static void pat_ap_init(u64 pat)
241242 wrmsrl (MSR_IA32_CR_PAT , pat );
242243}
243244
244- static void init_cache_modes (void )
245+ void init_cache_modes (void )
245246{
246247 u64 pat = 0 ;
247- static int init_cm_done ;
248248
249249 if (init_cm_done )
250250 return ;
@@ -286,8 +286,6 @@ static void init_cache_modes(void)
286286 }
287287
288288 __init_cache_modes (pat );
289-
290- init_cm_done = 1 ;
291289}
292290
293291/**
@@ -305,10 +303,8 @@ void pat_init(void)
305303 u64 pat ;
306304 struct cpuinfo_x86 * c = & boot_cpu_data ;
307305
308- if (!pat_enabled ()) {
309- init_cache_modes ();
306+ if (pat_disabled )
310307 return ;
311- }
312308
313309 if ((c -> x86_vendor == X86_VENDOR_INTEL ) &&
314310 (((c -> x86 == 0x6 ) && (c -> x86_model <= 0xd )) ||
0 commit comments