* [PATCH 1/3] KVM: Drop kvm_get_gdt() in favor of generic linux function.
@ 2010-02-25 10:43 Gleb Natapov
2010-02-25 10:43 ` [PATCH 2/3] KVM: fix segment_base() error checking Gleb Natapov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Gleb Natapov @ 2010-02-25 10:43 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm
Linux now has native_store_gdt() to do the same. Use it instead of
kvm local version.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
arch/x86/include/asm/kvm_host.h | 5 -----
arch/x86/kvm/svm.c | 2 +-
arch/x86/kvm/vmx.c | 4 ++--
arch/x86/kvm/x86.c | 2 +-
4 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 502fff1..e316722 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -723,11 +723,6 @@ static inline void kvm_get_idt(struct desc_ptr *table)
asm("sidt %0" : "=m"(*table));
}
-static inline void kvm_get_gdt(struct desc_ptr *table)
-{
- asm("sgdt %0" : "=m"(*table));
-}
-
static inline unsigned long kvm_read_tr_base(void)
{
u16 tr;
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index d11ff46..7b3cee1 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -364,7 +364,7 @@ static int svm_hardware_enable(void *garbage)
sd->max_asid = cpuid_ebx(SVM_CPUID_FUNC) - 1;
sd->next_asid = sd->max_asid + 1;
- kvm_get_gdt(&gdt_descr);
+ native_store_gdt(&gdt_descr);
gdt = (struct desc_struct *)gdt_descr.address;
sd->tss_desc = (struct kvm_ldttss_desc *)(gdt + GDT_ENTRY_TSS);
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index d772476..fa48e8c 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -600,7 +600,7 @@ static void reload_tss(void)
struct desc_ptr gdt;
struct desc_struct *descs;
- kvm_get_gdt(&gdt);
+ native_store_gdt(&gdt);
descs = (void *)gdt.address;
descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
load_TR_desc();
@@ -764,7 +764,7 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
* processors.
*/
vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
- kvm_get_gdt(&dt);
+ native_store_gdt(&dt);
vmcs_writel(HOST_GDTR_BASE, dt.address); /* 22.2.4 */
rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 7b436c8..558eb9a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -232,7 +232,7 @@ unsigned long segment_base(u16 selector)
if (selector == 0)
return 0;
- kvm_get_gdt(&gdt);
+ native_store_gdt(&gdt);
table_base = gdt.address;
if (selector & 4) { /* from ldt */
--
1.6.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] KVM: fix segment_base() error checking.
2010-02-25 10:43 [PATCH 1/3] KVM: Drop kvm_get_gdt() in favor of generic linux function Gleb Natapov
@ 2010-02-25 10:43 ` Gleb Natapov
2010-02-25 10:43 ` [PATCH 3/3] KVM: move segment_base() into vmx.c Gleb Natapov
2010-02-25 13:28 ` [PATCH 1/3] KVM: Drop kvm_get_gdt() in favor of generic linux function Avi Kivity
2 siblings, 0 replies; 4+ messages in thread
From: Gleb Natapov @ 2010-02-25 10:43 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm
fix segment_base() to properly check for null segment selector and
avoid accessing NULL pointer if ldt selector in null.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
arch/x86/kvm/x86.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 558eb9a..49f5c7b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -229,7 +229,7 @@ unsigned long segment_base(u16 selector)
unsigned long table_base;
unsigned long v;
- if (selector == 0)
+ if (!(selector & ~3))
return 0;
native_store_gdt(&gdt);
@@ -238,6 +238,8 @@ unsigned long segment_base(u16 selector)
if (selector & 4) { /* from ldt */
u16 ldt_selector = kvm_read_ldt();
+ if (!(ldt_selector & ~3))
+ return 0;
table_base = segment_base(ldt_selector);
}
d = (struct desc_struct *)(table_base + (selector & ~7));
--
1.6.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] KVM: move segment_base() into vmx.c
2010-02-25 10:43 [PATCH 1/3] KVM: Drop kvm_get_gdt() in favor of generic linux function Gleb Natapov
2010-02-25 10:43 ` [PATCH 2/3] KVM: fix segment_base() error checking Gleb Natapov
@ 2010-02-25 10:43 ` Gleb Natapov
2010-02-25 13:28 ` [PATCH 1/3] KVM: Drop kvm_get_gdt() in favor of generic linux function Avi Kivity
2 siblings, 0 replies; 4+ messages in thread
From: Gleb Natapov @ 2010-02-25 10:43 UTC (permalink / raw)
To: avi, mtosatti; +Cc: kvm
segment_base() is used only by vmx so move it there.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
arch/x86/include/asm/kvm_host.h | 9 ---------
arch/x86/kvm/vmx.c | 37 +++++++++++++++++++++++++++++++++++++
arch/x86/kvm/x86.c | 30 ------------------------------
3 files changed, 37 insertions(+), 39 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index e316722..ec891a2 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -644,8 +644,6 @@ int emulator_write_emulated(unsigned long addr,
unsigned int bytes,
struct kvm_vcpu *vcpu);
-unsigned long segment_base(u16 selector);
-
void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu);
void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
const u8 *new, int bytes,
@@ -723,13 +721,6 @@ static inline void kvm_get_idt(struct desc_ptr *table)
asm("sidt %0" : "=m"(*table));
}
-static inline unsigned long kvm_read_tr_base(void)
-{
- u16 tr;
- asm("str %0" : "=g"(tr));
- return segment_base(tr);
-}
-
#ifdef CONFIG_X86_64
static inline unsigned long read_msr(unsigned long msr)
{
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index fa48e8c..ae3217d 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -631,6 +631,43 @@ static bool update_transition_efer(struct vcpu_vmx *vmx, int efer_offset)
return true;
}
+static unsigned long segment_base(u16 selector)
+{
+ struct desc_ptr gdt;
+ struct desc_struct *d;
+ unsigned long table_base;
+ unsigned long v;
+
+ if (!(selector & ~3))
+ return 0;
+
+ native_store_gdt(&gdt);
+ table_base = gdt.address;
+
+ if (selector & 4) { /* from ldt */
+ u16 ldt_selector = kvm_read_ldt();
+
+ if (!(ldt_selector & ~3))
+ return 0;
+
+ table_base = segment_base(ldt_selector);
+ }
+ d = (struct desc_struct *)(table_base + (selector & ~7));
+ v = get_desc_base(d);
+#ifdef CONFIG_X86_64
+ if (d->s == 0 && (d->type == 2 || d->type == 9 || d->type == 11))
+ v |= ((unsigned long)((struct ldttss_desc64 *)d)->base3) << 32;
+#endif
+ return v;
+}
+
+static inline unsigned long kvm_read_tr_base(void)
+{
+ u16 tr;
+ asm("str %0" : "=g"(tr));
+ return segment_base(tr);
+}
+
static void vmx_save_host_state(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 49f5c7b..7ebeaf0 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -222,36 +222,6 @@ static void drop_user_return_notifiers(void *ignore)
kvm_on_user_return(&smsr->urn);
}
-unsigned long segment_base(u16 selector)
-{
- struct desc_ptr gdt;
- struct desc_struct *d;
- unsigned long table_base;
- unsigned long v;
-
- if (!(selector & ~3))
- return 0;
-
- native_store_gdt(&gdt);
- table_base = gdt.address;
-
- if (selector & 4) { /* from ldt */
- u16 ldt_selector = kvm_read_ldt();
-
- if (!(ldt_selector & ~3))
- return 0;
- table_base = segment_base(ldt_selector);
- }
- d = (struct desc_struct *)(table_base + (selector & ~7));
- v = get_desc_base(d);
-#ifdef CONFIG_X86_64
- if (d->s == 0 && (d->type == 2 || d->type == 9 || d->type == 11))
- v |= ((unsigned long)((struct ldttss_desc64 *)d)->base3) << 32;
-#endif
- return v;
-}
-EXPORT_SYMBOL_GPL(segment_base);
-
u64 kvm_get_apic_base(struct kvm_vcpu *vcpu)
{
if (irqchip_in_kernel(vcpu->kvm))
--
1.6.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/3] KVM: Drop kvm_get_gdt() in favor of generic linux function.
2010-02-25 10:43 [PATCH 1/3] KVM: Drop kvm_get_gdt() in favor of generic linux function Gleb Natapov
2010-02-25 10:43 ` [PATCH 2/3] KVM: fix segment_base() error checking Gleb Natapov
2010-02-25 10:43 ` [PATCH 3/3] KVM: move segment_base() into vmx.c Gleb Natapov
@ 2010-02-25 13:28 ` Avi Kivity
2 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2010-02-25 13:28 UTC (permalink / raw)
To: Gleb Natapov; +Cc: mtosatti, kvm
On 02/25/2010 12:43 PM, Gleb Natapov wrote:
> Linux now has native_store_gdt() to do the same. Use it instead of
> kvm local version.
>
Applied all, thanks.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-02-25 13:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-25 10:43 [PATCH 1/3] KVM: Drop kvm_get_gdt() in favor of generic linux function Gleb Natapov
2010-02-25 10:43 ` [PATCH 2/3] KVM: fix segment_base() error checking Gleb Natapov
2010-02-25 10:43 ` [PATCH 3/3] KVM: move segment_base() into vmx.c Gleb Natapov
2010-02-25 13:28 ` [PATCH 1/3] KVM: Drop kvm_get_gdt() in favor of generic linux function Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox