All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Gleb Natapov <gleb@kernel.org>, Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm <kvm@vger.kernel.org>, Arthur Chunqi Li <yzt356@gmail.com>
Subject: [PATCH 01/15] VMX: Fix initialization of GDT, IDT and TR descriptors
Date: Mon, 16 Dec 2013 10:57:14 +0100	[thread overview]
Message-ID: <5615e8708779a040a6f6cc7bd44b704ac50df29e.1387187847.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1387187847.git.jan.kiszka@siemens.com>
In-Reply-To: <cover.1387187847.git.jan.kiszka@siemens.com>

We were loading the addresses of the descriptor pointers, not the
addresses they are pointing to. By declaring the pointers with the
proper type, we can also save some castings + struct descr.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 x86/vmx.c | 26 ++++++++++++--------------
 x86/vmx.h |  5 -----
 2 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/x86/vmx.c b/x86/vmx.c
index 31d7bd1..4c463fd 100644
--- a/x86/vmx.c
+++ b/x86/vmx.c
@@ -56,9 +56,9 @@ union vmx_ctrl_exit ctrl_exit_rev;
 union vmx_ctrl_ent ctrl_enter_rev;
 union vmx_ept_vpid  ept_vpid;
 
-extern u64 gdt64_desc[];
-extern u64 idt_descr[];
-extern u64 tss_descr[];
+extern struct descriptor_table_ptr gdt64_desc;
+extern struct descriptor_table_ptr idt_descr;
+extern struct descriptor_table_ptr tss_descr;
 extern void *vmx_return;
 extern void *entry_sysenter;
 extern void *guest_entry;
@@ -368,9 +368,9 @@ static void init_vmcs_host(void)
 	vmcs_write(HOST_SEL_FS, SEL_KERN_DATA_64);
 	vmcs_write(HOST_SEL_GS, SEL_KERN_DATA_64);
 	vmcs_write(HOST_SEL_TR, SEL_TSS_RUN);
-	vmcs_write(HOST_BASE_TR,   (u64)tss_descr);
-	vmcs_write(HOST_BASE_GDTR, (u64)gdt64_desc);
-	vmcs_write(HOST_BASE_IDTR, (u64)idt_descr);
+	vmcs_write(HOST_BASE_TR, tss_descr.base);
+	vmcs_write(HOST_BASE_GDTR, gdt64_desc.base);
+	vmcs_write(HOST_BASE_IDTR, idt_descr.base);
 	vmcs_write(HOST_BASE_FS, 0);
 	vmcs_write(HOST_BASE_GS, 0);
 
@@ -424,7 +424,7 @@ static void init_vmcs_guest(void)
 	vmcs_write(GUEST_BASE_DS, 0);
 	vmcs_write(GUEST_BASE_FS, 0);
 	vmcs_write(GUEST_BASE_GS, 0);
-	vmcs_write(GUEST_BASE_TR,   (u64)tss_descr);
+	vmcs_write(GUEST_BASE_TR, tss_descr.base);
 	vmcs_write(GUEST_BASE_LDTR, 0);
 
 	vmcs_write(GUEST_LIMIT_CS, 0xFFFFFFFF);
@@ -434,7 +434,7 @@ static void init_vmcs_guest(void)
 	vmcs_write(GUEST_LIMIT_FS, 0xFFFFFFFF);
 	vmcs_write(GUEST_LIMIT_GS, 0xFFFFFFFF);
 	vmcs_write(GUEST_LIMIT_LDTR, 0xffff);
-	vmcs_write(GUEST_LIMIT_TR, ((struct descr *)tss_descr)->limit);
+	vmcs_write(GUEST_LIMIT_TR, tss_descr.limit);
 
 	vmcs_write(GUEST_AR_CS, 0xa09b);
 	vmcs_write(GUEST_AR_DS, 0xc093);
@@ -446,12 +446,10 @@ static void init_vmcs_guest(void)
 	vmcs_write(GUEST_AR_TR, 0x8b);
 
 	/* 26.3.1.3 */
-	vmcs_write(GUEST_BASE_GDTR, (u64)gdt64_desc);
-	vmcs_write(GUEST_BASE_IDTR, (u64)idt_descr);
-	vmcs_write(GUEST_LIMIT_GDTR,
-		((struct descr *)gdt64_desc)->limit & 0xffff);
-	vmcs_write(GUEST_LIMIT_IDTR,
-		((struct descr *)idt_descr)->limit & 0xffff);
+	vmcs_write(GUEST_BASE_GDTR, gdt64_desc.base);
+	vmcs_write(GUEST_BASE_IDTR, idt_descr.base);
+	vmcs_write(GUEST_LIMIT_GDTR, gdt64_desc.limit);
+	vmcs_write(GUEST_LIMIT_IDTR, idt_descr.limit);
 
 	/* 26.3.1.4 */
 	vmcs_write(GUEST_RIP, (u64)(&guest_entry));
diff --git a/x86/vmx.h b/x86/vmx.h
index 7d967eb..59d627a 100644
--- a/x86/vmx.h
+++ b/x86/vmx.h
@@ -95,11 +95,6 @@ union vmx_ept_vpid {
 	};
 };
 
-struct descr {
-	u16 limit;
-	u64 addr;
-};
-
 enum Encoding {
 	/* 16-Bit Control Fields */
 	VPID			= 0x0000ul,
-- 
1.8.1.1.298.ge7eed54


  reply	other threads:[~2013-12-16  9:57 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-16  9:57 [PATCH 00/15] kvm-unit-tests: Fix and enhance nVMX tests Jan Kiszka
2013-12-16  9:57 ` Jan Kiszka [this message]
2013-12-16  9:57 ` [PATCH 02/15] VMX: Drop redundant return statements Jan Kiszka
2013-12-16  9:57 ` [PATCH 03/15] rmap_chain: Remove dead code Jan Kiszka
2013-12-16  9:57 ` [PATCH 04/15] emulator: Exclude test_lgdt_lidt from building Jan Kiszka
2013-12-17 10:31   ` Paolo Bonzini
2013-12-16  9:57 ` [PATCH 05/15] init: Fix warning about returning without code Jan Kiszka
2013-12-16  9:57 ` [PATCH 06/15] lib/x86/smp: Fix compiler warnings Jan Kiszka
2013-12-17 10:33   ` Paolo Bonzini
2013-12-17 10:35   ` Paolo Bonzini
2013-12-17 11:17     ` [PATCH v2 " Jan Kiszka
2013-12-16  9:57 ` [PATCH 07/15] VMX: Remove unneeded basic_init Jan Kiszka
2013-12-16  9:57 ` [PATCH 08/15] VMX: Fix capability check for EPT test Jan Kiszka
2013-12-16  9:57 ` [PATCH 09/15] VMX: Let init handler decide about test start Jan Kiszka
2013-12-16  9:57 ` [PATCH 10/15] VMX: Remove unused return code from setup_ept_range Jan Kiszka
2013-12-16  9:57 ` [PATCH 11/15] VMX: Make syscall handler optional Jan Kiszka
2013-12-16  9:57 ` [PATCH 12/15] VMX: Simplify basic handlers Jan Kiszka
2013-12-16  9:57 ` [PATCH 13/15] VMX: Rework and enhance initial feature detection/enabling Jan Kiszka
2013-12-16  9:57 ` [PATCH 14/15] VMX: Add test cases around interrupt injection and halting Jan Kiszka
2014-03-25 11:18   ` Paolo Bonzini
2014-03-25 12:05     ` Jan Kiszka
2013-12-16  9:57 ` [PATCH 15/15] VMX: Add test case for preemption timer firing during hlt Jan Kiszka
2013-12-18  9:36 ` [PATCH 00/15] kvm-unit-tests: Fix and enhance nVMX tests 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=5615e8708779a040a6f6cc7bd44b704ac50df29e.1387187847.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=gleb@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=yzt356@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.