git: 73e58edc7caa - stable/14 - x86: mask all LAPIC vectors early, before BSP interrupts are enabled

From: Olivier Certner <olce_at_FreeBSD.org>
Date: Thu, 23 Jul 2026 10:01:17 UTC
The branch stable/14 has been updated by olce:

URL: https://cgit.FreeBSD.org/src/commit/?id=73e58edc7caa761d466276cc02fbe0a18f072da5

commit 73e58edc7caa761d466276cc02fbe0a18f072da5
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-12-09 02:18:21 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2026-07-23 09:59:16 +0000

    x86: mask all LAPIC vectors early, before BSP interrupts are enabled
    
    (cherry picked from commit 11f954b021a1aadde1d03d40ed5d6b529e14da98)
    (cherry picked from commit 2079e5864f204c552b82b63809e1b39b13ccfd3c)
---
 sys/x86/x86/local_apic.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/sys/x86/x86/local_apic.c b/sys/x86/x86/local_apic.c
index 4dc826bc5244..2636b87e78b3 100644
--- a/sys/x86/x86/local_apic.c
+++ b/sys/x86/x86/local_apic.c
@@ -434,6 +434,7 @@ lapic_is_x2apic(void)
 	    (APICBASE_X2APIC | APICBASE_ENABLED));
 }
 
+static void	lapic_early_mask_vecs(void);
 static void	lapic_enable(void);
 static void	lapic_resume(struct pic *pic, bool suspend_cancelled);
 static void	lapic_timer_oneshot(struct lapic *);
@@ -559,6 +560,7 @@ lapic_init(vm_paddr_t addr)
 
 	/* Perform basic initialization of the BSP's local APIC. */
 	lapic_enable();
+	lapic_early_mask_vecs();
 
 	/* Set BSP's per-CPU local APIC ID. */
 	PCPU_SET(apic_id, lapic_id());
@@ -799,6 +801,32 @@ lapic_xapic_mode(void)
 	intr_restore(saveintr);
 }
 
+static void
+lapic_early_mask_vec(const struct lvt *l)
+{
+	uint32_t v;
+
+	if (l->lvt_masked != 0) {
+		v = lapic_read32(l->lvt_reg);
+		v |= APIC_LVT_M;
+		lapic_write32(l->lvt_reg, v);
+	}
+}
+
+/* Done on BSP only */
+static void
+lapic_early_mask_vecs(void)
+{
+	int elvt_count, i;
+
+	for (i = 0; i < APIC_LVT_MAX; i++)
+		lapic_early_mask_vec(&lvts[i]);
+
+	elvt_count = amd_read_elvt_count();
+	for (i = 0; i < elvt_count; i++)
+		lapic_early_mask_vec(&elvts[i]);
+}
+
 void
 lapic_setup(int boot)
 {