From 627c047d1ce71c9882cefac41a0d0b3c9d379c5b Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sat, 5 Jul 2025 01:03:23 +0000 Subject: kernel/amd64: Add 'feat' field in cpu_info Keep track of per-cpu features by using a 'feat' field which contains the results of various CPUIDs. Signed-off-by: Ian Moffett --- sys/arch/amd64/amd64/machdep.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'sys/arch') diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index 8258f8e..408ac95 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -178,6 +178,19 @@ enable_simd(void) } } +static void +cpu_check_feat(struct cpu_info *ci) +{ + uint32_t unused, ebx; + + /* Extended features */ + CPUID(0x07, unused, ebx, unused, unused); + if (ISSET(ebx, BIT(7))) + ci->feat |= CPU_FEAT_SMEP; + if (ISSET(ebx, BIT(20))) + ci->feat |= CPU_FEAT_SMAP; +} + void cpu_shootdown_tlb(vaddr_t va) { @@ -304,6 +317,7 @@ void cpu_startup(struct cpu_info *ci) { ci->self = ci; + ci->feat = 0; gdt_load(); idt_load(); @@ -313,6 +327,8 @@ cpu_startup(struct cpu_info *ci) init_tss(ci); try_mitigate_spectre(); + cpu_check_feat(ci); + enable_simd(); lapic_init(); -- cgit v1.2.3