aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/x86.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/kvm/x86.c')
-rw-r--r--drivers/kvm/x86.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index b84cb6707f78..5a959220410a 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -16,16 +16,49 @@
16 16
17#include "kvm.h" 17#include "kvm.h"
18#include "x86.h" 18#include "x86.h"
19#include "segment_descriptor.h"
19#include "irq.h" 20#include "irq.h"
20 21
21#include <linux/kvm.h> 22#include <linux/kvm.h>
22#include <linux/fs.h> 23#include <linux/fs.h>
23#include <linux/vmalloc.h> 24#include <linux/vmalloc.h>
25#include <linux/module.h>
24 26
25#include <asm/uaccess.h> 27#include <asm/uaccess.h>
26 28
27#define MAX_IO_MSRS 256 29#define MAX_IO_MSRS 256
28 30
31unsigned long segment_base(u16 selector)
32{
33 struct descriptor_table gdt;
34 struct segment_descriptor *d;
35 unsigned long table_base;
36 unsigned long v;
37
38 if (selector == 0)
39 return 0;
40
41 asm("sgdt %0" : "=m"(gdt));
42 table_base = gdt.base;
43
44 if (selector & 4) { /* from ldt */
45 u16 ldt_selector;
46
47 asm("sldt %0" : "=g"(ldt_selector));
48 table_base = segment_base(ldt_selector);
49 }
50 d = (struct segment_descriptor *)(table_base + (selector & ~7));
51 v = d->base_low | ((unsigned long)d->base_mid << 16) |
52 ((unsigned long)d->base_high << 24);
53#ifdef CONFIG_X86_64
54 if (d->system == 0 && (d->type == 2 || d->type == 9 || d->type == 11))
55 v |= ((unsigned long) \
56 ((struct segment_descriptor_64 *)d)->base_higher) << 32;
57#endif
58 return v;
59}
60EXPORT_SYMBOL_GPL(segment_base);
61
29/* 62/*
30 * List of msr numbers which we expose to userspace through KVM_GET_MSRS 63 * List of msr numbers which we expose to userspace through KVM_GET_MSRS
31 * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST. 64 * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.