Skip to content

Commit 98b83cf

Browse files
AlisonSchofieldhansendc
authored andcommitted
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 <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Link: https://lore.kernel.org/all/86dfdf6ced8c9b790f9376bf6c7e22b5608f47c2.1715054189.git.alison.schofield%40intel.com
1 parent 1613e60 commit 98b83cf

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
@@ -190,83 +190,35 @@ static bool bad_spectre_microcode(struct cpuinfo_x86 *c)
190190
#define TME_ACTIVATE_LOCKED(x) (x & 0x1)
191191
#define TME_ACTIVATE_ENABLED(x) (x & 0x2)
192192

193-
#define TME_ACTIVATE_POLICY(x) ((x >> 4) & 0xf) /* Bits 7:4 */
194-
#define TME_ACTIVATE_POLICY_AES_XTS_128 0
195-
196193
#define TME_ACTIVATE_KEYID_BITS(x) ((x >> 32) & 0xf) /* Bits 35:32 */
197194

198-
#define TME_ACTIVATE_CRYPTO_ALGS(x) ((x >> 48) & 0xffff) /* Bits 63:48 */
199-
#define TME_ACTIVATE_CRYPTO_AES_XTS_128 1
200-
201-
/* Values for mktme_status (SW only construct) */
202-
#define MKTME_ENABLED 0
203-
#define MKTME_DISABLED 1
204-
#define MKTME_UNINITIALIZED 2
205-
static int mktme_status = MKTME_UNINITIALIZED;
206-
207195
static void detect_tme_early(struct cpuinfo_x86 *c)
208196
{
209-
u64 tme_activate, tme_policy, tme_crypto_algs;
210-
int keyid_bits = 0, nr_keyids = 0;
211-
static u64 tme_activate_cpu0 = 0;
197+
u64 tme_activate;
198+
int keyid_bits;
212199

213200
rdmsrl(MSR_IA32_TME_ACTIVATE, tme_activate);
214201

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

265212
/*
266-
* KeyID bits effectively lower the number of physical address
267-
* bits. Update cpuinfo_x86::x86_phys_bits accordingly.
213+
* KeyID bits are set by BIOS and can be present regardless
214+
* of whether the kernel is using them. They effectively lower
215+
* the number of physical address bits.
216+
*
217+
* Update cpuinfo_x86::x86_phys_bits accordingly.
268218
*/
269219
c->x86_phys_bits -= keyid_bits;
220+
pr_info_once("x86/mktme: BIOS enabled: x86_phys_bits reduced by %d\n",
221+
keyid_bits);
270222
}
271223

272224
static void early_init_intel(struct cpuinfo_x86 *c)

0 commit comments

Comments
 (0)