From: Paolo Bonzini <pbonzini@redhat.com>
To: kvm@vger.kernel.org
Cc: aaronlewis@google.com, jmattson@google.com, zxwang42@gmail.com,
marcorr@google.com, seanjc@google.com, jroedel@suse.de,
varad.gautam@suse.com
Subject: [PATCH kvm-unit-tests 6/9] x86: unify name of 32-bit and 64-bit GDT
Date: Thu, 21 Oct 2021 07:49:07 -0400 [thread overview]
Message-ID: <20211021114910.1347278-7-pbonzini@redhat.com> (raw)
In-Reply-To: <20211021114910.1347278-1-pbonzini@redhat.com>
There's no need to distinguish gdt32 and gdt64, since the same C functions
operate on both and selector numbers are mostly unified between 32-
and 64-bit versions.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
lib/x86/desc.c | 12 ++++++------
lib/x86/desc.h | 2 +-
x86/cstart.S | 20 ++++++++++----------
x86/cstart64.S | 17 +++++++++--------
x86/taskswitch.c | 2 +-
x86/vmx.c | 8 ++++----
x86/vmx_tests.c | 4 ++--
7 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/lib/x86/desc.c b/lib/x86/desc.c
index 2ef5aad..ac167d0 100644
--- a/lib/x86/desc.c
+++ b/lib/x86/desc.c
@@ -292,16 +292,16 @@ static char intr_alt_stack[4096];
#ifndef __x86_64__
void set_gdt_entry(int sel, u32 base, u32 limit, u8 type, u8 flags)
{
- int num = sel >> 3;
+ gdt_entry_t *entry = &gdt[sel >> 3];
/* Setup the descriptor base address */
- gdt32[num].base1 = (base & 0xFFFF);
- gdt32[num].base2 = (base >> 16) & 0xFF;
- gdt32[num].base3 = (base >> 24) & 0xFF;
+ entry->base1 = (base & 0xFFFF);
+ entry->base2 = (base >> 16) & 0xFF;
+ entry->base3 = (base >> 24) & 0xFF;
/* Setup the descriptor limits, type and flags */
- gdt32[num].limit1 = (limit & 0xFFFF);
- gdt32[num].type_limit_flags = ((limit & 0xF0000) >> 8) | ((flags & 0xF0) << 8) | type;
+ entry->limit1 = (limit & 0xFFFF);
+ entry->type_limit_flags = ((limit & 0xF0000) >> 8) | ((flags & 0xF0) << 8) | type;
}
void set_gdt_task_gate(u16 sel, u16 tss_sel)
diff --git a/lib/x86/desc.h b/lib/x86/desc.h
index 51148d1..c0817d8 100644
--- a/lib/x86/desc.h
+++ b/lib/x86/desc.h
@@ -197,7 +197,6 @@ struct system_desc64 {
extern idt_entry_t boot_idt[256];
#ifndef __x86_64__
-extern gdt_entry_t gdt32[];
extern tss32_t tss;
extern tss32_t tss_intr;
void set_gdt_task_gate(u16 tss_sel, u16 sel);
@@ -207,6 +206,7 @@ void setup_tss32(void);
#else
extern tss64_t tss;
#endif
+extern gdt_entry_t gdt[];
unsigned exception_vector(void);
int write_cr4_checking(unsigned long val);
diff --git a/x86/cstart.S b/x86/cstart.S
index 4461c38..5e925d8 100644
--- a/x86/cstart.S
+++ b/x86/cstart.S
@@ -27,8 +27,8 @@ i = 0
i = i + 1
.endr
-.globl gdt32
-gdt32:
+.globl gdt
+gdt:
.quad 0
.quad 0x00cf9b000000ffff // flat 32-bit code segment
.quad 0x00cf93000000ffff // flat 32-bit data segment
@@ -55,7 +55,7 @@ percpu_descr:
.rept max_cpus
.quad 0x00cf93000000ffff // 32-bit data segment for perCPU area
.endr
-gdt32_end:
+gdt_end:
i = 0
.globl tss
@@ -94,7 +94,7 @@ mb_cmdline = 16
mov %al, percpu_descr+4(,%ecx,8)
mov %ah, percpu_descr+7(,%ecx,8)
- lea percpu_descr-gdt32(,%ecx,8), %eax
+ lea percpu_descr-gdt(,%ecx,8), %eax
mov %ax, %gs
.endm
@@ -110,7 +110,7 @@ mb_cmdline = 16
.globl start
start:
- lgdtl gdt32_descr
+ lgdtl gdt_descr
setup_segments
mov $stacktop, %esp
setup_percpu_area
@@ -195,7 +195,7 @@ load_tss:
shr $16, %eax
mov %al, tss_descr+4(,%ebx,8)
mov %ah, tss_descr+7(,%ebx,8)
- lea tss_descr-gdt32(,%ebx,8), %eax
+ lea tss_descr-gdt(,%ebx,8), %eax
ltr %ax
ret
@@ -224,11 +224,11 @@ sipi_entry:
mov %cr0, %eax
or $1, %eax
mov %eax, %cr0
- lgdtl gdt32_descr - sipi_entry
+ lgdtl gdt_descr - sipi_entry
ljmpl $8, $ap_start32
-gdt32_descr:
- .word gdt32_end - gdt32 - 1
- .long gdt32
+gdt_descr:
+ .word gdt_end - gdt - 1
+ .long gdt
sipi_end:
diff --git a/x86/cstart64.S b/x86/cstart64.S
index b98a0d3..46b9d9b 100644
--- a/x86/cstart64.S
+++ b/x86/cstart64.S
@@ -1,7 +1,8 @@
#include "apic-defs.h"
-.globl gdt64_desc
+.globl gdt
+.globl gdt_descr
.globl online_cpus
.globl cpu_online_count
@@ -47,11 +48,11 @@ ptl5:
.align 4096
-gdt64_desc:
- .word gdt64_end - gdt64 - 1
- .quad gdt64
+gdt_descr:
+ .word gdt_end - gdt - 1
+ .quad gdt
-gdt64:
+gdt:
.quad 0
.quad 0x00af9b000000ffff // 64-bit code segment
.quad 0x00cf93000000ffff // 32/64-bit data segment
@@ -75,7 +76,7 @@ tss_descr:
.quad 0x000089000000ffff // 64-bit avail tss
.quad 0 // tss high addr
.endr
-gdt64_end:
+gdt_end:
i = 0
.globl tss
@@ -162,7 +163,7 @@ switch_to_5level:
jmpl $8, $lvl5
prepare_64:
- lgdt gdt64_desc
+ lgdt gdt_descr
setup_segments
xor %eax, %eax
@@ -300,7 +301,7 @@ load_tss:
mov %al, tss_descr+7(%rbx)
shr $8, %rax
mov %eax, tss_descr+8(%rbx)
- lea tss_descr-gdt64(%rbx), %rax
+ lea tss_descr-gdt(%rbx), %rax
ltr %ax
ret
diff --git a/x86/taskswitch.c b/x86/taskswitch.c
index 0fa818d..1d6e6e2 100644
--- a/x86/taskswitch.c
+++ b/x86/taskswitch.c
@@ -21,7 +21,7 @@ fault_handler(unsigned long error_code)
tss.eip += 2;
- gdt32[TSS_MAIN / 8].type &= ~DESC_BUSY;
+ gdt[TSS_MAIN / 8].type &= ~DESC_BUSY;
set_gdt_task_gate(TSS_RETURN, tss_intr.prev);
}
diff --git a/x86/vmx.c b/x86/vmx.c
index d45c6de..7a2f7a3 100644
--- a/x86/vmx.c
+++ b/x86/vmx.c
@@ -73,7 +73,7 @@ union vmx_ctrl_msr ctrl_exit_rev;
union vmx_ctrl_msr ctrl_enter_rev;
union vmx_ept_vpid ept_vpid;
-extern struct descriptor_table_ptr gdt64_desc;
+extern struct descriptor_table_ptr gdt_descr;
extern struct descriptor_table_ptr idt_descr;
extern void *vmx_return;
extern void *entry_sysenter;
@@ -1275,7 +1275,7 @@ static void init_vmcs_host(void)
vmcs_write(HOST_SEL_GS, KERNEL_DS);
vmcs_write(HOST_SEL_TR, TSS_MAIN);
vmcs_write(HOST_BASE_TR, get_gdt_entry_base(get_tss_descr()));
- vmcs_write(HOST_BASE_GDTR, gdt64_desc.base);
+ vmcs_write(HOST_BASE_GDTR, gdt_descr.base);
vmcs_write(HOST_BASE_IDTR, idt_descr.base);
vmcs_write(HOST_BASE_FS, 0);
vmcs_write(HOST_BASE_GS, 0);
@@ -1354,9 +1354,9 @@ static void init_vmcs_guest(void)
vmcs_write(GUEST_AR_TR, 0x8b);
/* 26.3.1.3 */
- vmcs_write(GUEST_BASE_GDTR, gdt64_desc.base);
+ vmcs_write(GUEST_BASE_GDTR, gdt_descr.base);
vmcs_write(GUEST_BASE_IDTR, idt_descr.base);
- vmcs_write(GUEST_LIMIT_GDTR, gdt64_desc.limit);
+ vmcs_write(GUEST_LIMIT_GDTR, gdt_descr.limit);
vmcs_write(GUEST_LIMIT_IDTR, idt_descr.limit);
/* 26.3.1.4 */
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index ac2b0b4..9ee6653 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -797,8 +797,8 @@ asm(
"insn_wbinvd: wbinvd;ret\n\t"
"insn_cpuid: mov $10, %eax; cpuid;ret\n\t"
"insn_invd: invd;ret\n\t"
- "insn_sgdt: sgdt gdt64_desc;ret\n\t"
- "insn_lgdt: lgdt gdt64_desc;ret\n\t"
+ "insn_sgdt: sgdt gdt_descr;ret\n\t"
+ "insn_lgdt: lgdt gdt_descr;ret\n\t"
"insn_sidt: sidt idt_descr;ret\n\t"
"insn_lidt: lidt idt_descr;ret\n\t"
"insn_sldt: sldt %ax;ret\n\t"
--
2.27.0
next prev parent reply other threads:[~2021-10-21 11:49 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-21 11:49 [PATCH v3 kvm-unit-tests 0/8] x86: Move IDT, GDT and TSS to C code Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 1/9] x86: cleanup handling of 16-byte GDT descriptors Paolo Bonzini
2021-11-29 21:46 ` Marc Orr
2021-11-30 10:55 ` Paolo Bonzini
2021-11-30 17:22 ` Marc Orr
2021-11-30 17:26 ` Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 2/9] x86: fix call to set_gdt_entry Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 3/9] unify field names and definitions for GDT descriptors Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 4/9] replace tss_descr global with a function Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 5/9] x86: Move IDT to desc.c Paolo Bonzini
2021-10-21 11:49 ` Paolo Bonzini [this message]
2021-10-21 11:49 ` [PATCH kvm-unit-tests 7/9] x86: get rid of ring0stacktop Paolo Bonzini
2021-10-21 23:08 ` Aaron Lewis
2021-10-21 11:49 ` [PATCH kvm-unit-tests 8/9] x86: Move 64-bit GDT and TSS to desc.c Paolo Bonzini
2021-10-21 11:49 ` [PATCH kvm-unit-tests 9/9] x86: Move 32-bit " Paolo Bonzini
2021-10-21 14:37 ` [PATCH v3 kvm-unit-tests 0/8] x86: Move IDT, GDT and TSS to C code Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211021114910.1347278-7-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=aaronlewis@google.com \
--cc=jmattson@google.com \
--cc=jroedel@suse.de \
--cc=kvm@vger.kernel.org \
--cc=marcorr@google.com \
--cc=seanjc@google.com \
--cc=varad.gautam@suse.com \
--cc=zxwang42@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.