Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

HVM-286 Move code into kvm_cache_regs.[ch]

  • Loading branch information...
commit 0e20210cdbb940ca91007d08ff1984c4286776a1 1 parent 45ba741
@rmustacc rmustacc authored
Showing with 124 additions and 82 deletions.
  1. +7 −5 Makefile
  2. +1 −64 kvm.c
  3. +93 −0 kvm_cache_regs.c
  4. +22 −0 kvm_cache_regs.h
  5. +1 −13 kvm_x86.c
View
12 Makefile
@@ -16,7 +16,7 @@ CSTYLE=$(KERNEL_SOURCE)/usr/src/tools/scripts/cstyle
all: kvm kvm.so
-kvm: kvm.c kvm_x86.c kvm_emulate.c kvm.h kvm_x86host.h msr.h bitops.h kvm_subr.c kvm_irq.c kvm_i8254.c kvm_lapic.c kvm_mmu.c kvm_iodev.c kvm_ioapic.c kvm_vmx.c kvm_i8259.c kvm_coalesced_mmio.c kvm_irq_comm.c
+kvm: kvm.c kvm_x86.c kvm_emulate.c kvm.h kvm_x86host.h msr.h bitops.h kvm_subr.c kvm_irq.c kvm_i8254.c kvm_lapic.c kvm_mmu.c kvm_iodev.c kvm_ioapic.c kvm_vmx.c kvm_i8259.c kvm_coalesced_mmio.c kvm_irq_comm.c kvm_cache_regs.c
$(CC) $(CFLAGS) $(INCLUDEDIR) kvm.c
$(CC) $(CFLAGS) $(INCLUDEDIR) kvm_x86.c
$(CC) $(CFLAGS) $(INCLUDEDIR) kvm_emulate.c
@@ -31,6 +31,7 @@ kvm: kvm.c kvm_x86.c kvm_emulate.c kvm.h kvm_x86host.h msr.h bitops.h kvm_subr.c
$(CC) $(CFLAGS) $(INCLUDEDIR) kvm_i8259.c
$(CC) $(CFLAGS) $(INCLUDEDIR) kvm_coalesced_mmio.c
$(CC) $(CFLAGS) $(INCLUDEDIR) kvm_irq_comm.c
+ $(CC) $(CFLAGS) $(INCLUDEDIR) kvm_cache_regs.c
$(CTFCONVERT) -i -L VERSION kvm.o
$(CTFCONVERT) -i -L VERSION kvm_x86.o
$(CTFCONVERT) -i -L VERSION kvm_emulate.o
@@ -45,8 +46,9 @@ kvm: kvm.c kvm_x86.c kvm_emulate.c kvm.h kvm_x86host.h msr.h bitops.h kvm_subr.c
$(CTFCONVERT) -i -L VERSION kvm_i8259.o
$(CTFCONVERT) -i -L VERSION kvm_coalesced_mmio.o
$(CTFCONVERT) -i -L VERSION kvm_irq_comm.o
- $(LD) -r -o kvm kvm.o kvm_x86.o kvm_emulate.o kvm_subr.o kvm_irq.o kvm_i8254.o kvm_lapic.o kvm_mmu.o kvm_iodev.o kvm_ioapic.o kvm_vmx.o kvm_i8259.o kvm_coalesced_mmio.o kvm_irq_comm.o
- $(CTFMERGE) -L VERSION -o kvm kvm.o kvm_x86.o kvm_emulate.o kvm_subr.o kvm_irq.o kvm_i8254.o kvm_lapic.o kvm_mmu.o kvm_iodev.o kvm_ioapic.o kvm_vmx.o kvm_i8259.o kvm_coalesced_mmio.o kvm_irq_comm.o
+ $(CTFCONVERT) -i -L VERSION kvm_cache_regs.o
+ $(LD) -r -o kvm kvm.o kvm_x86.o kvm_emulate.o kvm_subr.o kvm_irq.o kvm_i8254.o kvm_lapic.o kvm_mmu.o kvm_iodev.o kvm_ioapic.o kvm_vmx.o kvm_i8259.o kvm_coalesced_mmio.o kvm_irq_comm.o kvm_cache_regs.o
+ $(CTFMERGE) -L VERSION -o kvm kvm.o kvm_x86.o kvm_emulate.o kvm_subr.o kvm_irq.o kvm_i8254.o kvm_lapic.o kvm_mmu.o kvm_iodev.o kvm_ioapic.o kvm_vmx.o kvm_i8259.o kvm_coalesced_mmio.o kvm_irq_comm.o kvm_cache_regs.o
kvm.so: kvm_mdb.c
gcc -m64 -shared \
@@ -59,8 +61,8 @@ install: kvm
@pfexec cp kvm.conf /usr/kernel/drv
check:
- @$(CSTYLE) kvm.c kvm_mdb.c kvm_emulate.c kvm_x86.c kvm_irq.c kvm_lapic.c kvm_i8254.c kvm_mmu.c kvm_iodev.c kvm_subr.c kvm_ioapic.c kvm_vmx.c kvm_i8259.c kvm_coalesced_mmio.c kvm_irq_comm.c
- @./tools/xxxcheck kvm_x86.c kvm.c kvm_irq.c kvm_lapic.c kvm_i8254.c kvm_mmu.c kvm_iodev.c kvm_ioapic.c kvm_vmx.c kvm_i8259.c kvm_coalesced_mmio.c kvm_irq_comm.c
+ @$(CSTYLE) kvm.c kvm_mdb.c kvm_emulate.c kvm_x86.c kvm_irq.c kvm_lapic.c kvm_i8254.c kvm_mmu.c kvm_iodev.c kvm_subr.c kvm_ioapic.c kvm_vmx.c kvm_i8259.c kvm_coalesced_mmio.c kvm_irq_comm.c kvm_cache_regs.c
+ @./tools/xxxcheck kvm_x86.c kvm.c kvm_irq.c kvm_lapic.c kvm_i8254.c kvm_mmu.c kvm_iodev.c kvm_ioapic.c kvm_vmx.c kvm_i8259.c kvm_coalesced_mmio.c kvm_irq_comm.c kvm_cache_regs.c
load: install
@echo "==> Loading kvm module"
View
65 kvm.c
@@ -52,6 +52,7 @@
#include "kvm_coalesced_mmio.h"
#include "kvm_i8254.h"
#include "kvm_mmu.h"
+#include "kvm_cache_regs.h"
#undef DEBUG
@@ -288,45 +289,7 @@ struct kvm_x86_ops *kvm_x86_ops;
-inline ulong
-kvm_read_cr0_bits(struct kvm_vcpu *vcpu, ulong mask)
-{
- ulong tmask = mask & KVM_POSSIBLE_CR0_GUEST_BITS;
-
- if (tmask & vcpu->arch.cr0_guest_owned_bits)
- kvm_x86_ops->decache_cr0_guest_bits(vcpu);
- return (vcpu->arch.cr0 & mask);
-}
-
-unsigned long
-kvm_register_read(struct kvm_vcpu *vcpu, enum kvm_reg reg)
-{
- if (!test_bit(reg, (unsigned long *)&vcpu->arch.regs_avail))
- kvm_x86_ops->cache_reg(vcpu, reg);
-
- return (vcpu->arch.regs[reg]);
-}
-
-inline void
-kvm_register_write(struct kvm_vcpu *vcpu, enum kvm_reg reg, unsigned long val)
-{
- vcpu->arch.regs[reg] = val;
- __set_bit(reg, (unsigned long *)&vcpu->arch.regs_dirty);
- __set_bit(reg, (unsigned long *)&vcpu->arch.regs_avail);
-}
-
-inline unsigned long
-kvm_rip_read(struct kvm_vcpu *vcpu)
-{
- return (kvm_register_read(vcpu, VCPU_REGS_RIP));
-}
-
-inline void
-kvm_rip_write(struct kvm_vcpu *vcpu, unsigned long val)
-{
- kvm_register_write(vcpu, VCPU_REGS_RIP, val);
-}
inline int
kvm_exception_is_soft(unsigned int nr)
@@ -428,9 +391,6 @@ kvm_reload_remote_mmus(struct kvm *kvm)
make_all_cpus_request(kvm, KVM_REQ_MMU_RELOAD);
}
-
-extern inline uint64_t kvm_pdptr_read(struct kvm_vcpu *vcpu, int index);
-
gfn_t
unalias_gfn_instantiation(struct kvm *kvm, gfn_t gfn)
{
@@ -2186,16 +2146,6 @@ ldt_load(void)
wr_ldtr(ULDT_SEL);
}
-inline ulong
-kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask)
-{
- uint64_t tmask = mask & KVM_POSSIBLE_CR4_GUEST_BITS;
-
- if (tmask & vcpu->arch.cr4_guest_owned_bits)
- kvm_x86_ops->decache_cr4_guest_bits(vcpu);
-
- return (vcpu->arch.cr4 & mask);
-}
inline int
is_pae(struct kvm_vcpu *vcpu)
@@ -2550,19 +2500,6 @@ kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
return (0);
}
-
-inline ulong
-kvm_read_cr4(struct kvm_vcpu *vcpu)
-{
- return (kvm_read_cr4_bits(vcpu, ~0UL));
-}
-
-inline ulong
-kvm_read_cr0(struct kvm_vcpu *vcpu)
-{
- return (kvm_read_cr0_bits(vcpu, ~0UL));
-}
-
unsigned long
kvm_get_cr8(struct kvm_vcpu *vcpu)
{
View
93 kvm_cache_regs.c
@@ -0,0 +1,93 @@
+/*
+ * Ported from Linux by Joyent.
+ * Copyright 2011 Joyent, Inc.
+ */
+/*
+ * XXX Need proper header files!
+ */
+#include "msr.h"
+#include "irqflags.h"
+#include "kvm_host.h"
+#include "kvm_x86host.h"
+#include "kvm_iodev.h"
+#include "kvm.h"
+#include "apicdef.h"
+#include "kvm_ioapic.h"
+#include "kvm_lapic.h"
+#include "irq.h"
+#include "kvm_cache_regs.h"
+
+
+unsigned long
+kvm_register_read(struct kvm_vcpu *vcpu, enum kvm_reg reg)
+{
+ if (!test_bit(reg, (unsigned long *)&vcpu->arch.regs_avail))
+ kvm_x86_ops->cache_reg(vcpu, reg);
+
+ return (vcpu->arch.regs[reg]);
+}
+
+void
+kvm_register_write(struct kvm_vcpu *vcpu, enum kvm_reg reg, unsigned long val)
+{
+ vcpu->arch.regs[reg] = val;
+ __set_bit(reg, (unsigned long *)&vcpu->arch.regs_dirty);
+ __set_bit(reg, (unsigned long *)&vcpu->arch.regs_avail);
+}
+
+unsigned long
+kvm_rip_read(struct kvm_vcpu *vcpu)
+{
+ return (kvm_register_read(vcpu, VCPU_REGS_RIP));
+}
+
+void
+kvm_rip_write(struct kvm_vcpu *vcpu, unsigned long val)
+{
+ kvm_register_write(vcpu, VCPU_REGS_RIP, val);
+}
+
+uint64_t
+kvm_pdptr_read(struct kvm_vcpu *vcpu, int index)
+{
+ if (!test_bit(VCPU_EXREG_PDPTR,
+ (unsigned long *)&vcpu->arch.regs_avail)) {
+ kvm_x86_ops->cache_reg(vcpu, VCPU_EXREG_PDPTR);
+ }
+
+ return (vcpu->arch.pdptrs[index]);
+}
+
+ulong
+kvm_read_cr0_bits(struct kvm_vcpu *vcpu, ulong mask)
+{
+ ulong tmask = mask & KVM_POSSIBLE_CR0_GUEST_BITS;
+
+ if (tmask & vcpu->arch.cr0_guest_owned_bits)
+ kvm_x86_ops->decache_cr0_guest_bits(vcpu);
+
+ return (vcpu->arch.cr0 & mask);
+}
+
+ulong
+kvm_read_cr0(struct kvm_vcpu *vcpu)
+{
+ return (kvm_read_cr0_bits(vcpu, ~0UL));
+}
+
+ulong
+kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask)
+{
+ uint64_t tmask = mask & KVM_POSSIBLE_CR4_GUEST_BITS;
+
+ if (tmask & vcpu->arch.cr4_guest_owned_bits)
+ kvm_x86_ops->decache_cr4_guest_bits(vcpu);
+
+ return (vcpu->arch.cr4 & mask);
+}
+
+ulong
+kvm_read_cr4(struct kvm_vcpu *vcpu)
+{
+ return (kvm_read_cr4_bits(vcpu, ~0UL));
+}
View
22 kvm_cache_regs.h
@@ -0,0 +1,22 @@
+#ifndef ASM_KVM_CACHE_REGS_H
+#define ASM_KVM_CACHE_REGS_H
+
+#include "processor-flags.h"
+#include <sys/types.h>
+
+#define KVM_POSSIBLE_CR0_GUEST_BITS X86_CR0_TS
+#define KVM_POSSIBLE_CR4_GUEST_BITS \
+ (X86_CR4_PVI | X86_CR4_DE | X86_CR4_PCE | X86_CR4_OSFXSR \
+ | X86_CR4_OSXMMEXCPT | X86_CR4_PGE)
+
+extern unsigned long kvm_register_read(struct kvm_vcpu *, enum kvm_reg);
+extern void kvm_register_write(struct kvm_vcpu *, enum kvm_reg, unsigned long);
+extern unsigned long kvm_rip_read(struct kvm_vcpu *vcpu);
+extern void kvm_rip_write(struct kvm_vcpu *vcpu, unsigned long val);
+extern uint64_t kvm_pdptr_read(struct kvm_vcpu *vcpu, int index);
+extern ulong kvm_read_cr0_bits(struct kvm_vcpu *vcpu, ulong mask);
+extern ulong kvm_read_cr0(struct kvm_vcpu *vcpu);
+extern ulong kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask);
+extern ulong kvm_read_cr4(struct kvm_vcpu *vcpu);
+
+#endif
View
14 kvm_x86.c
@@ -43,6 +43,7 @@
#include "irq.h"
#include "kvm_i8254.h"
#include "kvm_lapic.h"
+#include "kvm_cache_regs.h"
#undef DEBUG
@@ -56,10 +57,8 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr,
unsigned long size);
extern uint32_t vmcs_read32(unsigned long field);
extern uint16_t vmcs_read16(unsigned long field);
-extern ulong kvm_read_cr4(struct kvm_vcpu *vcpu);
extern void kvm_rip_write(struct kvm_vcpu *vcpu, unsigned long val);
extern int kvm_is_mmio_pfn(pfn_t pfn);
-extern ulong kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask);
extern int is_long_mode(struct kvm_vcpu *vcpu);
extern void kvm_mmu_unload(struct kvm_vcpu *);
extern void kvm_free_physmem_slot(struct kvm_memory_slot *,
@@ -757,8 +756,6 @@ kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8)
vcpu->arch.cr8 = cr8;
}
-extern inline ulong kvm_read_cr0_bits(struct kvm_vcpu *vcpu, ulong mask);
-
int
is_paging(struct kvm_vcpu *vcpu)
{
@@ -1126,16 +1123,7 @@ kvm_flush_remote_tlbs(struct kvm *kvm)
KVM_KSTAT_INC(kvm, kvmks_remote_tlb_flush);
}
-inline uint64_t
-kvm_pdptr_read(struct kvm_vcpu *vcpu, int index)
-{
- if (!test_bit(VCPU_EXREG_PDPTR,
- (unsigned long *)&vcpu->arch.regs_avail)) {
- kvm_x86_ops->cache_reg(vcpu, VCPU_EXREG_PDPTR);
- }
- return (vcpu->arch.pdptrs[index]);
-}
gfn_t
Please sign in to comment.
Something went wrong with that request. Please try again.