x86/asm: Replace magic numbers in GDT descriptors, script-generated change
Actually replace the numeric values by the new symbolic values. I used this to find all the existing users of the GDT_ENTRY*() macros: $ git grep -P 'GDT_ENTRY(_INIT)?\(' Some of the lines will exceed 80 characters, but some of them will be shorter again in the next couple of patches. Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Link: https://lore.kernel.org/r/20231219151200.2878271-4-vegard.nossum@oracle.com
This commit is contained in:
parent
41ef75c848
commit
1445f6e15f
@ -68,13 +68,13 @@ static void setup_gdt(void)
|
|||||||
being 8-byte unaligned. Intel recommends 16 byte alignment. */
|
being 8-byte unaligned. Intel recommends 16 byte alignment. */
|
||||||
static const u64 boot_gdt[] __attribute__((aligned(16))) = {
|
static const u64 boot_gdt[] __attribute__((aligned(16))) = {
|
||||||
/* CS: code, read/execute, 4 GB, base 0 */
|
/* CS: code, read/execute, 4 GB, base 0 */
|
||||||
[GDT_ENTRY_BOOT_CS] = GDT_ENTRY(0xc09b, 0, 0xfffff),
|
[GDT_ENTRY_BOOT_CS] = GDT_ENTRY(DESC_CODE32 | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
/* DS: data, read/write, 4 GB, base 0 */
|
/* DS: data, read/write, 4 GB, base 0 */
|
||||||
[GDT_ENTRY_BOOT_DS] = GDT_ENTRY(0xc093, 0, 0xfffff),
|
[GDT_ENTRY_BOOT_DS] = GDT_ENTRY(DESC_DATA32 | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
/* TSS: 32-bit tss, 104 bytes, base 4096 */
|
/* TSS: 32-bit tss, 104 bytes, base 4096 */
|
||||||
/* We only have a TSS here to keep Intel VT happy;
|
/* We only have a TSS here to keep Intel VT happy;
|
||||||
we don't actually use it for anything. */
|
we don't actually use it for anything. */
|
||||||
[GDT_ENTRY_BOOT_TSS] = GDT_ENTRY(0x0089, 4096, 103),
|
[GDT_ENTRY_BOOT_TSS] = GDT_ENTRY(DESC_TSS32, 4096, 103),
|
||||||
};
|
};
|
||||||
/* Xen HVM incorrectly stores a pointer to the gdt_ptr, instead
|
/* Xen HVM incorrectly stores a pointer to the gdt_ptr, instead
|
||||||
of the gdt_ptr contents. Thus, make it static so it will
|
of the gdt_ptr contents. Thus, make it static so it will
|
||||||
|
@ -420,7 +420,7 @@ static DEFINE_MUTEX(apm_mutex);
|
|||||||
* This is for buggy BIOS's that refer to (real mode) segment 0x40
|
* This is for buggy BIOS's that refer to (real mode) segment 0x40
|
||||||
* even though they are called in protected mode.
|
* even though they are called in protected mode.
|
||||||
*/
|
*/
|
||||||
static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
|
static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(DESC_DATA32_BIOS,
|
||||||
(unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
|
(unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
|
||||||
|
|
||||||
static const char driver_version[] = "1.16ac"; /* no spaces */
|
static const char driver_version[] = "1.16ac"; /* no spaces */
|
||||||
|
@ -188,37 +188,37 @@ DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
|
|||||||
* TLS descriptors are currently at a different place compared to i386.
|
* TLS descriptors are currently at a different place compared to i386.
|
||||||
* Hopefully nobody expects them at a fixed place (Wine?)
|
* Hopefully nobody expects them at a fixed place (Wine?)
|
||||||
*/
|
*/
|
||||||
[GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
|
[GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(DESC_CODE32 | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
[GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
|
[GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(DESC_CODE64 | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
[GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
|
[GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(DESC_DATA64 | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
[GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
|
[GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(DESC_CODE32 | DESC_USER | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
[GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
|
[GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(DESC_DATA64 | DESC_USER | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
[GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
|
[GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(DESC_CODE64 | DESC_USER | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
#else
|
#else
|
||||||
[GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
|
[GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(DESC_CODE32, 0, 0xfffff),
|
||||||
[GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
|
[GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(DESC_DATA32, 0, 0xfffff),
|
||||||
[GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
|
[GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(DESC_CODE32 | DESC_USER, 0, 0xfffff),
|
||||||
[GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
|
[GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(DESC_DATA32 | DESC_USER, 0, 0xfffff),
|
||||||
/*
|
/*
|
||||||
* Segments used for calling PnP BIOS have byte granularity.
|
* Segments used for calling PnP BIOS have byte granularity.
|
||||||
* They code segments and data segments have fixed 64k limits,
|
* They code segments and data segments have fixed 64k limits,
|
||||||
* the transfer segment sizes are set at run time.
|
* the transfer segment sizes are set at run time.
|
||||||
*/
|
*/
|
||||||
[GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
|
[GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(DESC_CODE32_BIOS, 0, 0xffff),
|
||||||
[GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
|
[GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(DESC_CODE16, 0, 0xffff),
|
||||||
[GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
|
[GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(DESC_DATA16, 0, 0xffff),
|
||||||
[GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
|
[GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(DESC_DATA16, 0, 0),
|
||||||
[GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
|
[GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(DESC_DATA16, 0, 0),
|
||||||
/*
|
/*
|
||||||
* The APM segments have byte granularity and their bases
|
* The APM segments have byte granularity and their bases
|
||||||
* are set at run time. All have 64k limits.
|
* are set at run time. All have 64k limits.
|
||||||
*/
|
*/
|
||||||
[GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
|
[GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(DESC_CODE32_BIOS, 0, 0xffff),
|
||||||
[GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
|
[GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(DESC_CODE16, 0, 0xffff),
|
||||||
[GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
|
[GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(DESC_DATA32_BIOS, 0, 0xffff),
|
||||||
|
|
||||||
[GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
|
[GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(DESC_DATA32, 0, 0xfffff),
|
||||||
[GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
|
[GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(DESC_DATA32, 0, 0xfffff),
|
||||||
#endif
|
#endif
|
||||||
} };
|
} };
|
||||||
EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
|
EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
|
||||||
|
@ -71,9 +71,9 @@ EXPORT_SYMBOL(vmemmap_base);
|
|||||||
* GDT used on the boot CPU before switching to virtual addresses.
|
* GDT used on the boot CPU before switching to virtual addresses.
|
||||||
*/
|
*/
|
||||||
static struct desc_struct startup_gdt[GDT_ENTRIES] __initdata = {
|
static struct desc_struct startup_gdt[GDT_ENTRIES] __initdata = {
|
||||||
[GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
|
[GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(DESC_CODE32 | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
[GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
|
[GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(DESC_CODE64 | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
[GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
|
[GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(DESC_DATA64 | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -106,8 +106,8 @@ void __init pcpu_populate_pte(unsigned long addr)
|
|||||||
static inline void setup_percpu_segment(int cpu)
|
static inline void setup_percpu_segment(int cpu)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_X86_32
|
#ifdef CONFIG_X86_32
|
||||||
struct desc_struct d = GDT_ENTRY_INIT(0x8092, per_cpu_offset(cpu),
|
struct desc_struct d = GDT_ENTRY_INIT(DESC_DATA32 & ~_DESC_DB,
|
||||||
0xFFFFF);
|
per_cpu_offset(cpu), 0xFFFFF);
|
||||||
|
|
||||||
write_gdt_entry(get_cpu_gdt_rw(cpu), GDT_ENTRY_PERCPU, &d, DESCTYPE_S);
|
write_gdt_entry(get_cpu_gdt_rw(cpu), GDT_ENTRY_PERCPU, &d, DESCTYPE_S);
|
||||||
#endif
|
#endif
|
||||||
|
@ -149,11 +149,11 @@ SYM_DATA_END(gdt)
|
|||||||
SYM_DATA_START_LOCAL(gdt_start)
|
SYM_DATA_START_LOCAL(gdt_start)
|
||||||
.quad 0x0000000000000000 /* NULL descriptor */
|
.quad 0x0000000000000000 /* NULL descriptor */
|
||||||
#ifdef CONFIG_X86_64
|
#ifdef CONFIG_X86_64
|
||||||
.quad GDT_ENTRY(0xa09a, 0, 0xfffff) /* PVH_CS_SEL */
|
.quad GDT_ENTRY(DESC_CODE64, 0, 0xfffff) /* PVH_CS_SEL */
|
||||||
#else
|
#else
|
||||||
.quad GDT_ENTRY(0xc09a, 0, 0xfffff) /* PVH_CS_SEL */
|
.quad GDT_ENTRY(DESC_CODE32, 0, 0xfffff) /* PVH_CS_SEL */
|
||||||
#endif
|
#endif
|
||||||
.quad GDT_ENTRY(0xc092, 0, 0xfffff) /* PVH_DS_SEL */
|
.quad GDT_ENTRY(DESC_DATA32, 0, 0xfffff) /* PVH_DS_SEL */
|
||||||
SYM_DATA_END_LABEL(gdt_start, SYM_L_LOCAL, gdt_end)
|
SYM_DATA_END_LABEL(gdt_start, SYM_L_LOCAL, gdt_end)
|
||||||
|
|
||||||
.balign 16
|
.balign 16
|
||||||
|
@ -154,5 +154,5 @@ SYM_DATA_START(machine_real_restart_gdt)
|
|||||||
* base value 0x100; since this is consistent with real mode
|
* base value 0x100; since this is consistent with real mode
|
||||||
* semantics we don't have to reload the segments once CR0.PE = 0.
|
* semantics we don't have to reload the segments once CR0.PE = 0.
|
||||||
*/
|
*/
|
||||||
.quad GDT_ENTRY(0x0093, 0x100, 0xffff)
|
.quad GDT_ENTRY(DESC_DATA16 | _DESC_ACCESSED, 0x100, 0xffff)
|
||||||
SYM_DATA_END(machine_real_restart_gdt)
|
SYM_DATA_END(machine_real_restart_gdt)
|
||||||
|
@ -13,8 +13,8 @@ bool efi_no5lvl;
|
|||||||
static void (*la57_toggle)(void *cr3);
|
static void (*la57_toggle)(void *cr3);
|
||||||
|
|
||||||
static const struct desc_struct gdt[] = {
|
static const struct desc_struct gdt[] = {
|
||||||
[GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
|
[GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(DESC_CODE32 | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
[GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
|
[GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(DESC_CODE64 | _DESC_ACCESSED, 0, 0xfffff),
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -60,7 +60,7 @@ do { \
|
|||||||
set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
|
set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
|
static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(DESC_DATA32_BIOS,
|
||||||
(unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
|
(unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user