Skip to content

Commit 782b034

Browse files
committed
x86/cpu: Remove useless work in detect_tme_early()
JIRA: https://issues.redhat.com/browse/RHEL-111095 commit 98b83cf Author: Alison Schofield <alison.schofield@intel.com> Date: Mon May 6 21:24:21 2024 -0700 x86/cpu: Remove useless work in detect_tme_early() TME (Total Memory Encryption) and MKTME (Multi-Key Total Memory Encryption) BIOS detection were introduced together here [1] and are loosely coupled in the Intel CPU init code. TME is a hardware only feature and its BIOS status is all that needs to be shared with the kernel user: enabled or disabled. The TME algorithm the BIOS is using and whether or not the kernel recognizes that algorithm is useless to the kernel user. MKTME is a hardware feature that requires kernel support. MKTME detection code was added in advance of broader kernel support for MKTME that never followed. So, rather than continuing to spew needless and confusing messages about BIOS MKTME status, remove most of the MKTME pieces from detect_tme_early(). Keep one useful message: alert the user when BIOS enabled MKTME reduces the available physical address bits. Recovery of the MKTME consumed bits requires a reboot with MKTME disabled in BIOS. There is no functional change for the user, only a change in boot messages. Below is one example when both TME and MKTME are enabled in BIOS with AES_XTS_256 which is unknown to the detect tme code. Before: [] x86/tme: enabled by BIOS [] x86/tme: Unknown policy is active: 0x2 [] x86/mktme: No known encryption algorithm is supported: 0x4 [] x86/mktme: enabled by BIOS [] x86/mktme: 127 KeyIDs available After: [] x86/tme: enabled by BIOS [] x86/mktme: BIOS enable: x86_phys_bits reduced by 8 [1] commit cb06d8e ("x86/tme: Detect if TME and MKTME is activated by BIOS") Signed-off-by: Alison Schofield <alison.schofield@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Link: https://lore.kernel.org/all/86dfdf6ced8c9b790f9376bf6c7e22b5608f47c2.1715054189.git.alison.schofield%40intel.com Signed-off-by: Frank Liang <xiliang@redhat.com>
1 parent 9c7435b commit 782b034

File tree

1 file changed

+12
-60
lines changed

1 file changed

+12
-60
lines changed

arch/x86/kernel/cpu/intel.c

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -187,83 +187,35 @@ static bool bad_spectre_microcode(struct cpuinfo_x86 *c)
187187
#define TME_ACTIVATE_LOCKED(x) (x & 0x1)
188188
#define TME_ACTIVATE_ENABLED(x) (x & 0x2)
189189

190-
#define TME_ACTIVATE_POLICY(x) ((x >> 4) & 0xf) /* Bits 7:4 */
191-
#define TME_ACTIVATE_POLICY_AES_XTS_128 0
192-
193190
#define TME_ACTIVATE_KEYID_BITS(x) ((x >> 32) & 0xf) /* Bits 35:32 */
194191

195-
#define TME_ACTIVATE_CRYPTO_ALGS(x) ((x >> 48) & 0xffff) /* Bits 63:48 */
196-
#define TME_ACTIVATE_CRYPTO_AES_XTS_128 1
197-
198-
/* Values for mktme_status (SW only construct) */
199-
#define MKTME_ENABLED 0
200-
#define MKTME_DISABLED 1
201-
#define MKTME_UNINITIALIZED 2
202-
static int mktme_status = MKTME_UNINITIALIZED;
203-
204192
static void detect_tme_early(struct cpuinfo_x86 *c)
205193
{
206-
u64 tme_activate, tme_policy, tme_crypto_algs;
207-
int keyid_bits = 0, nr_keyids = 0;
208-
static u64 tme_activate_cpu0 = 0;
194+
u64 tme_activate;
195+
int keyid_bits;
209196

210197
rdmsrl(MSR_IA32_TME_ACTIVATE, tme_activate);
211198

212-
if (mktme_status != MKTME_UNINITIALIZED) {
213-
if (tme_activate != tme_activate_cpu0) {
214-
/* Broken BIOS? */
215-
pr_err_once("x86/tme: configuration is inconsistent between CPUs\n");
216-
pr_err_once("x86/tme: MKTME is not usable\n");
217-
mktme_status = MKTME_DISABLED;
218-
219-
/* Proceed. We may need to exclude bits from x86_phys_bits. */
220-
}
221-
} else {
222-
tme_activate_cpu0 = tme_activate;
223-
}
224-
225199
if (!TME_ACTIVATE_LOCKED(tme_activate) || !TME_ACTIVATE_ENABLED(tme_activate)) {
226200
pr_info_once("x86/tme: not enabled by BIOS\n");
227-
mktme_status = MKTME_DISABLED;
228201
clear_cpu_cap(c, X86_FEATURE_TME);
229202
return;
230203
}
231-
232-
if (mktme_status != MKTME_UNINITIALIZED)
233-
goto detect_keyid_bits;
234-
235-
pr_info("x86/tme: enabled by BIOS\n");
236-
237-
tme_policy = TME_ACTIVATE_POLICY(tme_activate);
238-
if (tme_policy != TME_ACTIVATE_POLICY_AES_XTS_128)
239-
pr_warn("x86/tme: Unknown policy is active: %#llx\n", tme_policy);
240-
241-
tme_crypto_algs = TME_ACTIVATE_CRYPTO_ALGS(tme_activate);
242-
if (!(tme_crypto_algs & TME_ACTIVATE_CRYPTO_AES_XTS_128)) {
243-
pr_err("x86/mktme: No known encryption algorithm is supported: %#llx\n",
244-
tme_crypto_algs);
245-
mktme_status = MKTME_DISABLED;
246-
}
247-
detect_keyid_bits:
204+
pr_info_once("x86/tme: enabled by BIOS\n");
248205
keyid_bits = TME_ACTIVATE_KEYID_BITS(tme_activate);
249-
nr_keyids = (1UL << keyid_bits) - 1;
250-
if (nr_keyids) {
251-
pr_info_once("x86/mktme: enabled by BIOS\n");
252-
pr_info_once("x86/mktme: %d KeyIDs available\n", nr_keyids);
253-
} else {
254-
pr_info_once("x86/mktme: disabled by BIOS\n");
255-
}
256-
257-
if (mktme_status == MKTME_UNINITIALIZED) {
258-
/* MKTME is usable */
259-
mktme_status = MKTME_ENABLED;
260-
}
206+
if (!keyid_bits)
207+
return;
261208

262209
/*
263-
* KeyID bits effectively lower the number of physical address
264-
* bits. Update cpuinfo_x86::x86_phys_bits accordingly.
210+
* KeyID bits are set by BIOS and can be present regardless
211+
* of whether the kernel is using them. They effectively lower
212+
* the number of physical address bits.
213+
*
214+
* Update cpuinfo_x86::x86_phys_bits accordingly.
265215
*/
266216
c->x86_phys_bits -= keyid_bits;
217+
pr_info_once("x86/mktme: BIOS enabled: x86_phys_bits reduced by %d\n",
218+
keyid_bits);
267219
}
268220

269221
void intel_unlock_cpuid_leafs(struct cpuinfo_x86 *c)

0 commit comments

Comments
 (0)