46 #include <linux/kernel.h>
48 #include <linux/string.h>
50 #include <linux/screen_info.h>
57 #include <linux/virtio_console.h>
59 #include <linux/export.h>
62 #include <asm/paravirt.h>
63 #include <asm/param.h>
65 #include <asm/pgtable.h>
67 #include <asm/setup.h>
72 #include <asm/stackprotector.h>
73 #include <asm/reboot.h>
74 #include <asm/kvm_para.h>
89 .blocked_interrupts = { 1 },
105 static void async_hcall(
unsigned long call,
unsigned long arg1,
106 unsigned long arg2,
unsigned long arg3,
110 static unsigned int next_call;
121 hcall(call, arg1, arg2, arg3, arg4);
123 lguest_data.
hcalls[next_call].arg0 = call;
151 static void lazy_hcall1(
unsigned long call,
unsigned long arg1)
154 hcall(call, arg1, 0, 0, 0);
156 async_hcall(call, arg1, 0, 0, 0);
160 static void lazy_hcall2(
unsigned long call,
165 hcall(call, arg1, arg2, 0, 0);
167 async_hcall(call, arg1, arg2, 0, 0);
170 static void lazy_hcall3(
unsigned long call,
176 hcall(call, arg1, arg2, arg3, 0);
178 async_hcall(call, arg1, arg2, arg3, 0);
181 #ifdef CONFIG_X86_PAE
182 static void lazy_hcall4(
unsigned long call,
189 hcall(call, arg1, arg2, arg3, arg4);
191 async_hcall(call, arg1, arg2, arg3, arg4);
200 static void lguest_leave_lazy_mmu_mode(
void)
237 static unsigned long save_fl(
void)
286 static void lguest_write_idt_entry(
gate_desc *dt,
297 native_write_idt_entry(dt, entrynum, g);
307 static void lguest_load_idt(
const struct desc_ptr *
desc)
312 for (i = 0; i < (desc->
size+1)/8; i++)
328 static void lguest_load_gdt(
const struct desc_ptr *desc)
333 for (i = 0; i < (desc->
size+1)/8; i++)
341 static void lguest_write_gdt_entry(
struct desc_struct *dt,
int entrynum,
342 const void *desc,
int type)
344 native_write_gdt_entry(dt, entrynum, desc, type);
347 dt[entrynum].
a, dt[entrynum].
b, 0);
378 static void lguest_set_ldt(
const void *
addr,
unsigned entries)
393 static void lguest_load_tr_desc(
void)
419 static void lguest_cpuid(
unsigned int *ax,
unsigned int *bx,
420 unsigned int *cx,
unsigned int *dx)
424 native_cpuid(ax, bx, cx, dx);
474 if (*ax > 0x80000008)
508 static unsigned long current_cr0;
509 static void lguest_write_cr0(
unsigned long val)
515 static unsigned long lguest_read_cr0(
void)
525 static void lguest_clts(
void)
536 static unsigned long lguest_read_cr2(
void)
538 return lguest_data.
cr2;
542 static bool cr3_changed =
false;
543 static unsigned long current_cr3;
549 static void lguest_write_cr3(
unsigned long cr3)
559 static unsigned long lguest_read_cr3(
void)
565 static unsigned long lguest_read_cr4(
void)
570 static void lguest_write_cr4(
unsigned long val)
667 static void lguest_pte_update(
struct mm_struct *mm,
unsigned long addr,
670 #ifdef CONFIG_X86_PAE
680 static void lguest_set_pte_at(
struct mm_struct *mm,
unsigned long addr,
683 native_set_pte(ptep, pteval);
684 lguest_pte_update(mm, addr, ptep);
694 #ifdef CONFIG_X86_PAE
695 static void lguest_set_pud(
pud_t *pudp,
pud_t pudval)
697 native_set_pud(pudp, pudval);
704 static void lguest_set_pmd(
pmd_t *pmdp,
pmd_t pmdval)
706 native_set_pmd(pmdp, pmdval);
713 static void lguest_set_pmd(
pmd_t *pmdp,
pmd_t pmdval)
715 native_set_pmd(pmdp, pmdval);
732 static void lguest_set_pte(
pte_t *ptep,
pte_t pteval)
734 native_set_pte(ptep, pteval);
739 #ifdef CONFIG_X86_PAE
747 native_set_pte_atomic(ptep, pte);
752 static void lguest_pte_clear(
struct mm_struct *mm,
unsigned long addr,
755 native_pte_clear(mm, addr, ptep);
756 lguest_pte_update(mm, addr, ptep);
759 static void lguest_pmd_clear(
pmd_t *pmdp)
761 lguest_set_pmd(pmdp,
__pmd(0));
777 static void lguest_flush_tlb_single(
unsigned long addr)
788 static void lguest_flush_tlb_user(
void)
798 static void lguest_flush_tlb_kernel(
void)
818 set_bit(data->
irq, lguest_data.blocked_interrupts);
827 static struct irq_chip lguest_irq_controller = {
829 .irq_mask = disable_lguest_irq,
830 .irq_mask_ack = disable_lguest_irq,
831 .irq_unmask = enable_lguest_irq,
840 static void __init lguest_init_IRQ(
void)
869 err = irq_alloc_desc_at(irq, 0);
870 if (err < 0 && err != -
EEXIST)
884 static unsigned long lguest_get_wallclock(
void)
886 return lguest_data.
time.tv_sec;
895 static unsigned long lguest_tsc_khz(
void)
916 sec = lguest_data.
time.tv_sec;
924 nsec = lguest_data.
time.tv_nsec;
931 return sec*1000000000ULL +
nsec;
938 .read = lguest_clock_read,
948 static int lguest_clockevent_set_next_event(
unsigned long delta,
949 struct clock_event_device *
evt)
954 if (printk_ratelimit())
965 static void lguest_clockevent_set_mode(
enum clock_event_mode
mode,
966 struct clock_event_device *evt)
969 case CLOCK_EVT_MODE_UNUSED:
970 case CLOCK_EVT_MODE_SHUTDOWN:
974 case CLOCK_EVT_MODE_ONESHOT:
977 case CLOCK_EVT_MODE_PERIODIC:
979 case CLOCK_EVT_MODE_RESUME:
985 static struct clock_event_device lguest_clockevent = {
987 .features = CLOCK_EVT_FEAT_ONESHOT,
988 .set_next_event = lguest_clockevent_set_next_event,
989 .set_mode = lguest_clockevent_set_mode,
1001 static void lguest_time_irq(
unsigned int irq,
struct irq_desc *desc)
1003 unsigned long flags;
1007 lguest_clockevent.event_handler(&lguest_clockevent);
1017 static void lguest_time_init(
void)
1021 irq_set_handler(0, lguest_time_irq);
1031 clear_bit(0, lguest_data.blocked_interrupts);
1059 static void lguest_set_debugreg(
int regno,
unsigned long value)
1075 static void lguest_wbinvd(
void)
1086 #ifdef CONFIG_X86_LOCAL_APIC
1087 static void lguest_apic_write(
u32 reg,
u32 v)
1096 static u64 lguest_apic_icr_read(
void)
1101 static void lguest_apic_icr_write(
u32 low,
u32 id)
1107 static void lguest_apic_wait_icr_idle(
void)
1112 static u32 lguest_apic_safe_wait_icr_idle(
void)
1117 static void set_lguest_basic_apic_ops(
void)
1129 static void lguest_safe_halt(
void)
1141 static void lguest_power_off(
void)
1152 static int lguest_panic(
struct notifier_block *nb,
unsigned long l,
void *
p)
1160 .notifier_call = lguest_panic
1164 static __init char *lguest_memory_setup(
void)
1189 if (len >
sizeof(scratch) - 1)
1191 scratch[len] =
'\0';
1192 memcpy(scratch, buf, len);
1203 static void lguest_restart(
char *
reason)
1233 static const struct lguest_insns
1236 } lguest_insns[] = {
1246 static unsigned lguest_patch(
u8 type,
u16 clobber,
void *ibuf,
1247 unsigned long addr,
unsigned len)
1249 unsigned int insn_len;
1255 insn_len = lguest_insns[
type].end - lguest_insns[
type].start;
1262 memcpy(ibuf, lguest_insns[type].start, insn_len);
1326 #ifdef CONFIG_X86_PAE
1327 pv_mmu_ops.set_pte_atomic = lguest_set_pte_atomic;
1339 #ifdef CONFIG_X86_LOCAL_APIC
1341 set_lguest_basic_apic_ops();
1344 x86_init.resources.memory_setup = lguest_memory_setup;
1345 x86_init.irqs.intr_init = lguest_init_IRQ;
1346 x86_init.timers.timer_init = lguest_time_init;
1369 setup_stack_canary_segment(0);
1414 #ifdef CONFIG_X86_MCE