Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 80691
b: refs/heads/master
c: 5fb76f9
h: refs/heads/master
i:
  80689: ba9e20b
  80687: e7e657e
v: v3
  • Loading branch information
Carsten Otte authored and Avi Kivity committed Jan 30, 2008
1 parent 488c9bc commit b5baf99
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 43 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1fe779f8eccd16e527315e1bafd2b3a876ff2489
refs/heads/master: 5fb76f9be1a050a25e21a44ab2003c9d36a72a77
42 changes: 0 additions & 42 deletions trunk/drivers/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "kvm.h"
#include "x86.h"
#include "x86_emulate.h"
#include "segment_descriptor.h"
#include "irq.h"

#include <linux/kvm.h>
Expand Down Expand Up @@ -104,50 +103,9 @@ static struct dentry *debugfs_dir;
#define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)
#define EFER_RESERVED_BITS 0xfffffffffffff2fe

#ifdef CONFIG_X86_64
/* LDT or TSS descriptor in the GDT. 16 bytes. */
struct segment_descriptor_64 {
struct segment_descriptor s;
u32 base_higher;
u32 pad_zero;
};

#endif

static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
unsigned long arg);

unsigned long segment_base(u16 selector)
{
struct descriptor_table gdt;
struct segment_descriptor *d;
unsigned long table_base;
unsigned long v;

if (selector == 0)
return 0;

asm("sgdt %0" : "=m"(gdt));
table_base = gdt.base;

if (selector & 4) { /* from ldt */
u16 ldt_selector;

asm("sldt %0" : "=g"(ldt_selector));
table_base = segment_base(ldt_selector);
}
d = (struct segment_descriptor *)(table_base + (selector & ~7));
v = d->base_low | ((unsigned long)d->base_mid << 16) |
((unsigned long)d->base_high << 24);
#ifdef CONFIG_X86_64
if (d->system == 0 && (d->type == 2 || d->type == 9 || d->type == 11))
v |= ((unsigned long) \
((struct segment_descriptor_64 *)d)->base_higher) << 32;
#endif
return v;
}
EXPORT_SYMBOL_GPL(segment_base);

static inline int valid_vcpu(int n)
{
return likely(n >= 0 && n < KVM_MAX_VCPUS);
Expand Down
12 changes: 12 additions & 0 deletions trunk/drivers/kvm/segment_descriptor.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef __SEGMENT_DESCRIPTOR_H
#define __SEGMENT_DESCRIPTOR_H

struct segment_descriptor {
u16 limit_low;
u16 base_low;
Expand All @@ -14,4 +17,13 @@ struct segment_descriptor {
u8 base_high;
} __attribute__((packed));

#ifdef CONFIG_X86_64
/* LDT or TSS descriptor in the GDT. 16 bytes. */
struct segment_descriptor_64 {
struct segment_descriptor s;
u32 base_higher;
u32 pad_zero;
};

#endif
#endif
33 changes: 33 additions & 0 deletions trunk/drivers/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,49 @@

#include "kvm.h"
#include "x86.h"
#include "segment_descriptor.h"
#include "irq.h"

#include <linux/kvm.h>
#include <linux/fs.h>
#include <linux/vmalloc.h>
#include <linux/module.h>

#include <asm/uaccess.h>

#define MAX_IO_MSRS 256

unsigned long segment_base(u16 selector)
{
struct descriptor_table gdt;
struct segment_descriptor *d;
unsigned long table_base;
unsigned long v;

if (selector == 0)
return 0;

asm("sgdt %0" : "=m"(gdt));
table_base = gdt.base;

if (selector & 4) { /* from ldt */
u16 ldt_selector;

asm("sldt %0" : "=g"(ldt_selector));
table_base = segment_base(ldt_selector);
}
d = (struct segment_descriptor *)(table_base + (selector & ~7));
v = d->base_low | ((unsigned long)d->base_mid << 16) |
((unsigned long)d->base_high << 24);
#ifdef CONFIG_X86_64
if (d->system == 0 && (d->type == 2 || d->type == 9 || d->type == 11))
v |= ((unsigned long) \
((struct segment_descriptor_64 *)d)->base_higher) << 32;
#endif
return v;
}
EXPORT_SYMBOL_GPL(segment_base);

/*
* List of msr numbers which we expose to userspace through KVM_GET_MSRS
* and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.
Expand Down

0 comments on commit b5baf99

Please sign in to comment.