Having variables named idt_table[] and idt_tables[] is not ideal.
Use X86_IDT_VECTORS and remove IDT_ENTRIES. State the size of bsp_idt[] in
idt.h so that load_system_tables() and cpu_smpboot_alloc() can use sizeof()
rather than opencoding the calculation.
Move the variable into a new traps-setup.c, to make a start at splitting
traps.c in half.
No functional change.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
v2:
* Rename traps-init.c to traps-setup.c
---
xen/arch/x86/Makefile | 1 +
xen/arch/x86/cpu/common.c | 2 +-
xen/arch/x86/include/asm/idt.h | 3 +--
xen/arch/x86/pv/traps.c | 4 ++--
xen/arch/x86/smpboot.c | 2 +-
xen/arch/x86/traps-setup.c | 9 +++++++++
xen/arch/x86/traps.c | 14 +++++---------
7 files changed, 20 insertions(+), 15 deletions(-)
create mode 100644 xen/arch/x86/traps-setup.c
diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
index b35fd5196ce2..c763f80b0b22 100644
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -65,6 +65,7 @@ obj-y += spec_ctrl.o
obj-y += srat.o
obj-y += string.o
obj-y += time.o
+obj-y += traps-setup.o
obj-y += traps.o
obj-$(CONFIG_INTEL) += tsx.o
obj-y += usercopy.o
diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c
index 1540ab0007a0..e8b355ebcf36 100644
--- a/xen/arch/x86/cpu/common.c
+++ b/xen/arch/x86/cpu/common.c
@@ -831,7 +831,7 @@ void load_system_tables(void)
};
const struct desc_ptr idtr = {
.base = (unsigned long)idt_tables[cpu],
- .limit = (IDT_ENTRIES * sizeof(idt_entry_t)) - 1,
+ .limit = sizeof(bsp_idt) - 1,
};
/*
diff --git a/xen/arch/x86/include/asm/idt.h b/xen/arch/x86/include/asm/idt.h
index 3689fdecbec3..f00368f28c86 100644
--- a/xen/arch/x86/include/asm/idt.h
+++ b/xen/arch/x86/include/asm/idt.h
@@ -28,8 +28,7 @@ typedef union {
};
} idt_entry_t;
-#define IDT_ENTRIES 256
-extern idt_entry_t idt_table[];
+extern idt_entry_t bsp_idt[X86_IDT_VECTORS];
extern idt_entry_t *idt_tables[];
/*
diff --git a/xen/arch/x86/pv/traps.c b/xen/arch/x86/pv/traps.c
index 77b034e4dc73..4aeb6cab5238 100644
--- a/xen/arch/x86/pv/traps.c
+++ b/xen/arch/x86/pv/traps.c
@@ -148,12 +148,12 @@ void __init pv_trap_init(void)
{
#ifdef CONFIG_PV32
/* The 32-on-64 hypercall vector is only accessible from ring 1. */
- _set_gate(idt_table + HYPERCALL_VECTOR,
+ _set_gate(bsp_idt + HYPERCALL_VECTOR,
SYS_DESC_irq_gate, 1, entry_int82);
#endif
/* Fast trap for int80 (faster than taking the #GP-fixup path). */
- _set_gate(idt_table + LEGACY_SYSCALL_VECTOR, SYS_DESC_irq_gate, 3,
+ _set_gate(bsp_idt + LEGACY_SYSCALL_VECTOR, SYS_DESC_irq_gate, 3,
&entry_int80);
open_softirq(NMI_SOFTIRQ, nmi_softirq);
diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c
index f3d60d5bae35..dc65f9e45269 100644
--- a/xen/arch/x86/smpboot.c
+++ b/xen/arch/x86/smpboot.c
@@ -1080,7 +1080,7 @@ static int cpu_smpboot_alloc(unsigned int cpu)
idt_tables[cpu] = alloc_xenheap_pages(0, memflags);
if ( idt_tables[cpu] == NULL )
goto out;
- memcpy(idt_tables[cpu], idt_table, IDT_ENTRIES * sizeof(idt_entry_t));
+ memcpy(idt_tables[cpu], bsp_idt, sizeof(bsp_idt));
disable_each_ist(idt_tables[cpu]);
for ( stub_page = 0, i = cpu & ~(STUBS_PER_PAGE - 1);
diff --git a/xen/arch/x86/traps-setup.c b/xen/arch/x86/traps-setup.c
new file mode 100644
index 000000000000..b172ea933607
--- /dev/null
+++ b/xen/arch/x86/traps-setup.c
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Configuration of event handling for all CPUs.
+ */
+#include <asm/idt.h>
+#include <asm/page.h>
+
+idt_entry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE)
+ bsp_idt[X86_IDT_VECTORS];
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 4d1aaa78e711..7a68996b02f7 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -98,10 +98,6 @@ DEFINE_PER_CPU_READ_MOSTLY(seg_desc_t *, compat_gdt);
DEFINE_PER_CPU_READ_MOSTLY(l1_pgentry_t, compat_gdt_l1e);
#endif
-/* Master table, used by CPU0. */
-idt_entry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE)
- idt_table[IDT_ENTRIES];
-
/* Pointer to the IDT of every CPU. */
idt_entry_t *idt_tables[NR_CPUS] __read_mostly;
@@ -1874,7 +1870,7 @@ void asmlinkage do_entry_CP(struct cpu_user_regs *regs)
static void __init noinline __set_intr_gate(unsigned int n,
uint32_t dpl, void *addr)
{
- _set_gate(&idt_table[n], SYS_DESC_irq_gate, dpl, addr);
+ _set_gate(&bsp_idt[n], SYS_DESC_irq_gate, dpl, addr);
}
static void __init set_swint_gate(unsigned int n, void *addr)
@@ -1940,10 +1936,10 @@ void __init init_idt_traps(void)
set_intr_gate (X86_EXC_CP, entry_CP);
/* Specify dedicated interrupt stacks for NMI, #DF, and #MC. */
- enable_each_ist(idt_table);
+ enable_each_ist(bsp_idt);
/* CPU0 uses the master IDT. */
- idt_tables[0] = idt_table;
+ idt_tables[0] = bsp_idt;
this_cpu(gdt) = boot_gdt;
if ( IS_ENABLED(CONFIG_PV32) )
@@ -2001,13 +1997,13 @@ void __init trap_init(void)
if ( autogen_entrypoints[vector] )
{
/* Found autogen entry: check we won't clobber an existing trap. */
- ASSERT(idt_table[vector].b == 0);
+ ASSERT(bsp_idt[vector].b == 0);
set_intr_gate(vector, autogen_entrypoints[vector]);
}
else
{
/* No entry point: confirm we have an existing trap in place. */
- ASSERT(idt_table[vector].b != 0);
+ ASSERT(bsp_idt[vector].b != 0);
}
}
--
2.39.5
© 2016 - 2025 Red Hat, Inc.