@@ -391,6 +391,90 @@ int intel_microcode_sanity_check(void *mc, bool print_err, int hdr_type)
391391}
392392EXPORT_SYMBOL_GPL (intel_microcode_sanity_check );
393393
394+ #define MSR_IA32_TME_ACTIVATE 0x982
395+
396+ /* Helpers to access TME_ACTIVATE MSR */
397+ #define TME_ACTIVATE_LOCKED (x ) (x & 0x1)
398+ #define TME_ACTIVATE_ENABLED (x ) (x & 0x2)
399+
400+ #define TME_ACTIVATE_POLICY (x ) ((x >> 4) & 0xf) /* Bits 7:4 */
401+ #define TME_ACTIVATE_POLICY_AES_XTS_128 0
402+
403+ #define TME_ACTIVATE_KEYID_BITS (x ) ((x >> 32) & 0xf) /* Bits 35:32 */
404+
405+ #define TME_ACTIVATE_CRYPTO_ALGS (x ) ((x >> 48) & 0xffff) /* Bits 63:48 */
406+ #define TME_ACTIVATE_CRYPTO_AES_XTS_128 1
407+
408+ /* Values for mktme_status (SW only construct) */
409+ #define MKTME_ENABLED 0
410+ #define MKTME_DISABLED 1
411+ #define MKTME_UNINITIALIZED 2
412+ static int mktme_status = MKTME_UNINITIALIZED ;
413+
414+ static void detect_tme_early (struct cpuinfo_x86 * c )
415+ {
416+ u64 tme_activate , tme_policy , tme_crypto_algs ;
417+ int keyid_bits = 0 , nr_keyids = 0 ;
418+ static u64 tme_activate_cpu0 = 0 ;
419+
420+ rdmsrl (MSR_IA32_TME_ACTIVATE , tme_activate );
421+
422+ if (mktme_status != MKTME_UNINITIALIZED ) {
423+ if (tme_activate != tme_activate_cpu0 ) {
424+ /* Broken BIOS? */
425+ pr_err_once ("x86/tme: configuration is inconsistent between CPUs\n" );
426+ pr_err_once ("x86/tme: MKTME is not usable\n" );
427+ mktme_status = MKTME_DISABLED ;
428+
429+ /* Proceed. We may need to exclude bits from x86_phys_bits. */
430+ }
431+ } else {
432+ tme_activate_cpu0 = tme_activate ;
433+ }
434+
435+ if (!TME_ACTIVATE_LOCKED (tme_activate ) || !TME_ACTIVATE_ENABLED (tme_activate )) {
436+ pr_info_once ("x86/tme: not enabled by BIOS\n" );
437+ mktme_status = MKTME_DISABLED ;
438+ return ;
439+ }
440+
441+ if (mktme_status != MKTME_UNINITIALIZED )
442+ goto detect_keyid_bits ;
443+
444+ pr_info ("x86/tme: enabled by BIOS\n" );
445+
446+ tme_policy = TME_ACTIVATE_POLICY (tme_activate );
447+ if (tme_policy != TME_ACTIVATE_POLICY_AES_XTS_128 )
448+ pr_warn ("x86/tme: Unknown policy is active: %#llx\n" , tme_policy );
449+
450+ tme_crypto_algs = TME_ACTIVATE_CRYPTO_ALGS (tme_activate );
451+ if (!(tme_crypto_algs & TME_ACTIVATE_CRYPTO_AES_XTS_128 )) {
452+ pr_err ("x86/mktme: No known encryption algorithm is supported: %#llx\n" ,
453+ tme_crypto_algs );
454+ mktme_status = MKTME_DISABLED ;
455+ }
456+ detect_keyid_bits :
457+ keyid_bits = TME_ACTIVATE_KEYID_BITS (tme_activate );
458+ nr_keyids = (1UL << keyid_bits ) - 1 ;
459+ if (nr_keyids ) {
460+ pr_info_once ("x86/mktme: enabled by BIOS\n" );
461+ pr_info_once ("x86/mktme: %d KeyIDs available\n" , nr_keyids );
462+ } else {
463+ pr_info_once ("x86/mktme: disabled by BIOS\n" );
464+ }
465+
466+ if (mktme_status == MKTME_UNINITIALIZED ) {
467+ /* MKTME is usable */
468+ mktme_status = MKTME_ENABLED ;
469+ }
470+
471+ /*
472+ * KeyID bits effectively lower the number of physical address
473+ * bits. Update cpuinfo_x86::x86_phys_bits accordingly.
474+ */
475+ c -> x86_phys_bits -= keyid_bits ;
476+ }
477+
394478static void early_init_intel (struct cpuinfo_x86 * c )
395479{
396480 u64 misc_enable ;
@@ -542,6 +626,13 @@ static void early_init_intel(struct cpuinfo_x86 *c)
542626 */
543627 if (detect_extended_topology_early (c ) < 0 )
544628 detect_ht_early (c );
629+
630+ /*
631+ * Adjust the number of physical bits early because it affects the
632+ * valid bits of the MTRR mask registers.
633+ */
634+ if (cpu_has (c , X86_FEATURE_TME ))
635+ detect_tme_early (c );
545636}
546637
547638static void bsp_init_intel (struct cpuinfo_x86 * c )
@@ -702,90 +793,6 @@ static void srat_detect_node(struct cpuinfo_x86 *c)
702793#endif
703794}
704795
705- #define MSR_IA32_TME_ACTIVATE 0x982
706-
707- /* Helpers to access TME_ACTIVATE MSR */
708- #define TME_ACTIVATE_LOCKED (x ) (x & 0x1)
709- #define TME_ACTIVATE_ENABLED (x ) (x & 0x2)
710-
711- #define TME_ACTIVATE_POLICY (x ) ((x >> 4) & 0xf) /* Bits 7:4 */
712- #define TME_ACTIVATE_POLICY_AES_XTS_128 0
713-
714- #define TME_ACTIVATE_KEYID_BITS (x ) ((x >> 32) & 0xf) /* Bits 35:32 */
715-
716- #define TME_ACTIVATE_CRYPTO_ALGS (x ) ((x >> 48) & 0xffff) /* Bits 63:48 */
717- #define TME_ACTIVATE_CRYPTO_AES_XTS_128 1
718-
719- /* Values for mktme_status (SW only construct) */
720- #define MKTME_ENABLED 0
721- #define MKTME_DISABLED 1
722- #define MKTME_UNINITIALIZED 2
723- static int mktme_status = MKTME_UNINITIALIZED ;
724-
725- static void detect_tme (struct cpuinfo_x86 * c )
726- {
727- u64 tme_activate , tme_policy , tme_crypto_algs ;
728- int keyid_bits = 0 , nr_keyids = 0 ;
729- static u64 tme_activate_cpu0 = 0 ;
730-
731- rdmsrl (MSR_IA32_TME_ACTIVATE , tme_activate );
732-
733- if (mktme_status != MKTME_UNINITIALIZED ) {
734- if (tme_activate != tme_activate_cpu0 ) {
735- /* Broken BIOS? */
736- pr_err_once ("x86/tme: configuration is inconsistent between CPUs\n" );
737- pr_err_once ("x86/tme: MKTME is not usable\n" );
738- mktme_status = MKTME_DISABLED ;
739-
740- /* Proceed. We may need to exclude bits from x86_phys_bits. */
741- }
742- } else {
743- tme_activate_cpu0 = tme_activate ;
744- }
745-
746- if (!TME_ACTIVATE_LOCKED (tme_activate ) || !TME_ACTIVATE_ENABLED (tme_activate )) {
747- pr_info_once ("x86/tme: not enabled by BIOS\n" );
748- mktme_status = MKTME_DISABLED ;
749- return ;
750- }
751-
752- if (mktme_status != MKTME_UNINITIALIZED )
753- goto detect_keyid_bits ;
754-
755- pr_info ("x86/tme: enabled by BIOS\n" );
756-
757- tme_policy = TME_ACTIVATE_POLICY (tme_activate );
758- if (tme_policy != TME_ACTIVATE_POLICY_AES_XTS_128 )
759- pr_warn ("x86/tme: Unknown policy is active: %#llx\n" , tme_policy );
760-
761- tme_crypto_algs = TME_ACTIVATE_CRYPTO_ALGS (tme_activate );
762- if (!(tme_crypto_algs & TME_ACTIVATE_CRYPTO_AES_XTS_128 )) {
763- pr_err ("x86/mktme: No known encryption algorithm is supported: %#llx\n" ,
764- tme_crypto_algs );
765- mktme_status = MKTME_DISABLED ;
766- }
767- detect_keyid_bits :
768- keyid_bits = TME_ACTIVATE_KEYID_BITS (tme_activate );
769- nr_keyids = (1UL << keyid_bits ) - 1 ;
770- if (nr_keyids ) {
771- pr_info_once ("x86/mktme: enabled by BIOS\n" );
772- pr_info_once ("x86/mktme: %d KeyIDs available\n" , nr_keyids );
773- } else {
774- pr_info_once ("x86/mktme: disabled by BIOS\n" );
775- }
776-
777- if (mktme_status == MKTME_UNINITIALIZED ) {
778- /* MKTME is usable */
779- mktme_status = MKTME_ENABLED ;
780- }
781-
782- /*
783- * KeyID bits effectively lower the number of physical address
784- * bits. Update cpuinfo_x86::x86_phys_bits accordingly.
785- */
786- c -> x86_phys_bits -= keyid_bits ;
787- }
788-
789796static void init_cpuid_fault (struct cpuinfo_x86 * c )
790797{
791798 u64 msr ;
@@ -922,9 +929,6 @@ static void init_intel(struct cpuinfo_x86 *c)
922929
923930 init_ia32_feat_ctl (c );
924931
925- if (cpu_has (c , X86_FEATURE_TME ))
926- detect_tme (c );
927-
928932 init_intel_misc_features (c );
929933
930934 split_lock_init ();
0 commit comments