Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

HVM-286 Move code into kvm_cache_regs.[ch]

  • Loading branch information...
commit 0e20210cdbb940ca91007d08ff1984c4286776a1 1 parent 45ba741
Robert Mustacchi rmustacc authored
12 Makefile
@@ -16,7 +16,7 @@ CSTYLE=$(KERNEL_SOURCE)/usr/src/tools/scripts/cstyle
16 16
17 17 all: kvm kvm.so
18 18
19   -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
  19 +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
20 20 $(CC) $(CFLAGS) $(INCLUDEDIR) kvm.c
21 21 $(CC) $(CFLAGS) $(INCLUDEDIR) kvm_x86.c
22 22 $(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
31 31 $(CC) $(CFLAGS) $(INCLUDEDIR) kvm_i8259.c
32 32 $(CC) $(CFLAGS) $(INCLUDEDIR) kvm_coalesced_mmio.c
33 33 $(CC) $(CFLAGS) $(INCLUDEDIR) kvm_irq_comm.c
  34 + $(CC) $(CFLAGS) $(INCLUDEDIR) kvm_cache_regs.c
34 35 $(CTFCONVERT) -i -L VERSION kvm.o
35 36 $(CTFCONVERT) -i -L VERSION kvm_x86.o
36 37 $(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
45 46 $(CTFCONVERT) -i -L VERSION kvm_i8259.o
46 47 $(CTFCONVERT) -i -L VERSION kvm_coalesced_mmio.o
47 48 $(CTFCONVERT) -i -L VERSION kvm_irq_comm.o
48   - $(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
49   - $(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
  49 + $(CTFCONVERT) -i -L VERSION kvm_cache_regs.o
  50 + $(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
  51 + $(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
50 52
51 53 kvm.so: kvm_mdb.c
52 54 gcc -m64 -shared \
@@ -59,8 +61,8 @@ install: kvm
59 61 @pfexec cp kvm.conf /usr/kernel/drv
60 62
61 63 check:
62   - @$(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
63   - @./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
  64 + @$(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
  65 + @./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
64 66
65 67 load: install
66 68 @echo "==> Loading kvm module"
65 kvm.c
@@ -52,6 +52,7 @@
52 52 #include "kvm_coalesced_mmio.h"
53 53 #include "kvm_i8254.h"
54 54 #include "kvm_mmu.h"
  55 +#include "kvm_cache_regs.h"
55 56
56 57 #undef DEBUG
57 58
@@ -288,45 +289,7 @@ struct kvm_x86_ops *kvm_x86_ops;
288 289
289 290
290 291
291   -inline ulong
292   -kvm_read_cr0_bits(struct kvm_vcpu *vcpu, ulong mask)
293   -{
294   - ulong tmask = mask & KVM_POSSIBLE_CR0_GUEST_BITS;
295   -
296   - if (tmask & vcpu->arch.cr0_guest_owned_bits)
297   - kvm_x86_ops->decache_cr0_guest_bits(vcpu);
298 292
299   - return (vcpu->arch.cr0 & mask);
300   -}
301   -
302   -unsigned long
303   -kvm_register_read(struct kvm_vcpu *vcpu, enum kvm_reg reg)
304   -{
305   - if (!test_bit(reg, (unsigned long *)&vcpu->arch.regs_avail))
306   - kvm_x86_ops->cache_reg(vcpu, reg);
307   -
308   - return (vcpu->arch.regs[reg]);
309   -}
310   -
311   -inline void
312   -kvm_register_write(struct kvm_vcpu *vcpu, enum kvm_reg reg, unsigned long val)
313   -{
314   - vcpu->arch.regs[reg] = val;
315   - __set_bit(reg, (unsigned long *)&vcpu->arch.regs_dirty);
316   - __set_bit(reg, (unsigned long *)&vcpu->arch.regs_avail);
317   -}
318   -
319   -inline unsigned long
320   -kvm_rip_read(struct kvm_vcpu *vcpu)
321   -{
322   - return (kvm_register_read(vcpu, VCPU_REGS_RIP));
323   -}
324   -
325   -inline void
326   -kvm_rip_write(struct kvm_vcpu *vcpu, unsigned long val)
327   -{
328   - kvm_register_write(vcpu, VCPU_REGS_RIP, val);
329   -}
330 293
331 294 inline int
332 295 kvm_exception_is_soft(unsigned int nr)
@@ -428,9 +391,6 @@ kvm_reload_remote_mmus(struct kvm *kvm)
428 391 make_all_cpus_request(kvm, KVM_REQ_MMU_RELOAD);
429 392 }
430 393
431   -
432   -extern inline uint64_t kvm_pdptr_read(struct kvm_vcpu *vcpu, int index);
433   -
434 394 gfn_t
435 395 unalias_gfn_instantiation(struct kvm *kvm, gfn_t gfn)
436 396 {
@@ -2186,16 +2146,6 @@ ldt_load(void)
2186 2146 wr_ldtr(ULDT_SEL);
2187 2147 }
2188 2148
2189   -inline ulong
2190   -kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask)
2191   -{
2192   - uint64_t tmask = mask & KVM_POSSIBLE_CR4_GUEST_BITS;
2193   -
2194   - if (tmask & vcpu->arch.cr4_guest_owned_bits)
2195   - kvm_x86_ops->decache_cr4_guest_bits(vcpu);
2196   -
2197   - return (vcpu->arch.cr4 & mask);
2198   -}
2199 2149
2200 2150 inline int
2201 2151 is_pae(struct kvm_vcpu *vcpu)
@@ -2550,19 +2500,6 @@ kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
2550 2500 return (0);
2551 2501 }
2552 2502
2553   -
2554   -inline ulong
2555   -kvm_read_cr4(struct kvm_vcpu *vcpu)
2556   -{
2557   - return (kvm_read_cr4_bits(vcpu, ~0UL));
2558   -}
2559   -
2560   -inline ulong
2561   -kvm_read_cr0(struct kvm_vcpu *vcpu)
2562   -{
2563   - return (kvm_read_cr0_bits(vcpu, ~0UL));
2564   -}
2565   -
2566 2503 unsigned long
2567 2504 kvm_get_cr8(struct kvm_vcpu *vcpu)
2568 2505 {
93 kvm_cache_regs.c
... ... @@ -0,0 +1,93 @@
  1 +/*
  2 + * Ported from Linux by Joyent.
  3 + * Copyright 2011 Joyent, Inc.
  4 + */
  5 +/*
  6 + * XXX Need proper header files!
  7 + */
  8 +#include "msr.h"
  9 +#include "irqflags.h"
  10 +#include "kvm_host.h"
  11 +#include "kvm_x86host.h"
  12 +#include "kvm_iodev.h"
  13 +#include "kvm.h"
  14 +#include "apicdef.h"
  15 +#include "kvm_ioapic.h"
  16 +#include "kvm_lapic.h"
  17 +#include "irq.h"
  18 +#include "kvm_cache_regs.h"
  19 +
  20 +
  21 +unsigned long
  22 +kvm_register_read(struct kvm_vcpu *vcpu, enum kvm_reg reg)
  23 +{
  24 + if (!test_bit(reg, (unsigned long *)&vcpu->arch.regs_avail))
  25 + kvm_x86_ops->cache_reg(vcpu, reg);
  26 +
  27 + return (vcpu->arch.regs[reg]);
  28 +}
  29 +
  30 +void
  31 +kvm_register_write(struct kvm_vcpu *vcpu, enum kvm_reg reg, unsigned long val)
  32 +{
  33 + vcpu->arch.regs[reg] = val;
  34 + __set_bit(reg, (unsigned long *)&vcpu->arch.regs_dirty);
  35 + __set_bit(reg, (unsigned long *)&vcpu->arch.regs_avail);
  36 +}
  37 +
  38 +unsigned long
  39 +kvm_rip_read(struct kvm_vcpu *vcpu)
  40 +{
  41 + return (kvm_register_read(vcpu, VCPU_REGS_RIP));
  42 +}
  43 +
  44 +void
  45 +kvm_rip_write(struct kvm_vcpu *vcpu, unsigned long val)
  46 +{
  47 + kvm_register_write(vcpu, VCPU_REGS_RIP, val);
  48 +}
  49 +
  50 +uint64_t
  51 +kvm_pdptr_read(struct kvm_vcpu *vcpu, int index)
  52 +{
  53 + if (!test_bit(VCPU_EXREG_PDPTR,
  54 + (unsigned long *)&vcpu->arch.regs_avail)) {
  55 + kvm_x86_ops->cache_reg(vcpu, VCPU_EXREG_PDPTR);
  56 + }
  57 +
  58 + return (vcpu->arch.pdptrs[index]);
  59 +}
  60 +
  61 +ulong
  62 +kvm_read_cr0_bits(struct kvm_vcpu *vcpu, ulong mask)
  63 +{
  64 + ulong tmask = mask & KVM_POSSIBLE_CR0_GUEST_BITS;
  65 +
  66 + if (tmask & vcpu->arch.cr0_guest_owned_bits)
  67 + kvm_x86_ops->decache_cr0_guest_bits(vcpu);
  68 +
  69 + return (vcpu->arch.cr0 & mask);
  70 +}
  71 +
  72 +ulong
  73 +kvm_read_cr0(struct kvm_vcpu *vcpu)
  74 +{
  75 + return (kvm_read_cr0_bits(vcpu, ~0UL));
  76 +}
  77 +
  78 +ulong
  79 +kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask)
  80 +{
  81 + uint64_t tmask = mask & KVM_POSSIBLE_CR4_GUEST_BITS;
  82 +
  83 + if (tmask & vcpu->arch.cr4_guest_owned_bits)
  84 + kvm_x86_ops->decache_cr4_guest_bits(vcpu);
  85 +
  86 + return (vcpu->arch.cr4 & mask);
  87 +}
  88 +
  89 +ulong
  90 +kvm_read_cr4(struct kvm_vcpu *vcpu)
  91 +{
  92 + return (kvm_read_cr4_bits(vcpu, ~0UL));
  93 +}
22 kvm_cache_regs.h
... ... @@ -0,0 +1,22 @@
  1 +#ifndef ASM_KVM_CACHE_REGS_H
  2 +#define ASM_KVM_CACHE_REGS_H
  3 +
  4 +#include "processor-flags.h"
  5 +#include <sys/types.h>
  6 +
  7 +#define KVM_POSSIBLE_CR0_GUEST_BITS X86_CR0_TS
  8 +#define KVM_POSSIBLE_CR4_GUEST_BITS \
  9 + (X86_CR4_PVI | X86_CR4_DE | X86_CR4_PCE | X86_CR4_OSFXSR \
  10 + | X86_CR4_OSXMMEXCPT | X86_CR4_PGE)
  11 +
  12 +extern unsigned long kvm_register_read(struct kvm_vcpu *, enum kvm_reg);
  13 +extern void kvm_register_write(struct kvm_vcpu *, enum kvm_reg, unsigned long);
  14 +extern unsigned long kvm_rip_read(struct kvm_vcpu *vcpu);
  15 +extern void kvm_rip_write(struct kvm_vcpu *vcpu, unsigned long val);
  16 +extern uint64_t kvm_pdptr_read(struct kvm_vcpu *vcpu, int index);
  17 +extern ulong kvm_read_cr0_bits(struct kvm_vcpu *vcpu, ulong mask);
  18 +extern ulong kvm_read_cr0(struct kvm_vcpu *vcpu);
  19 +extern ulong kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask);
  20 +extern ulong kvm_read_cr4(struct kvm_vcpu *vcpu);
  21 +
  22 +#endif
14 kvm_x86.c
@@ -43,6 +43,7 @@
43 43 #include "irq.h"
44 44 #include "kvm_i8254.h"
45 45 #include "kvm_lapic.h"
  46 +#include "kvm_cache_regs.h"
46 47
47 48 #undef DEBUG
48 49
@@ -56,10 +57,8 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr,
56 57 unsigned long size);
57 58 extern uint32_t vmcs_read32(unsigned long field);
58 59 extern uint16_t vmcs_read16(unsigned long field);
59   -extern ulong kvm_read_cr4(struct kvm_vcpu *vcpu);
60 60 extern void kvm_rip_write(struct kvm_vcpu *vcpu, unsigned long val);
61 61 extern int kvm_is_mmio_pfn(pfn_t pfn);
62   -extern ulong kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask);
63 62 extern int is_long_mode(struct kvm_vcpu *vcpu);
64 63 extern void kvm_mmu_unload(struct kvm_vcpu *);
65 64 extern void kvm_free_physmem_slot(struct kvm_memory_slot *,
@@ -757,8 +756,6 @@ kvm_set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8)
757 756 vcpu->arch.cr8 = cr8;
758 757 }
759 758
760   -extern inline ulong kvm_read_cr0_bits(struct kvm_vcpu *vcpu, ulong mask);
761   -
762 759 int
763 760 is_paging(struct kvm_vcpu *vcpu)
764 761 {
@@ -1126,16 +1123,7 @@ kvm_flush_remote_tlbs(struct kvm *kvm)
1126 1123 KVM_KSTAT_INC(kvm, kvmks_remote_tlb_flush);
1127 1124 }
1128 1125
1129   -inline uint64_t
1130   -kvm_pdptr_read(struct kvm_vcpu *vcpu, int index)
1131   -{
1132   - if (!test_bit(VCPU_EXREG_PDPTR,
1133   - (unsigned long *)&vcpu->arch.regs_avail)) {
1134   - kvm_x86_ops->cache_reg(vcpu, VCPU_EXREG_PDPTR);
1135   - }
1136 1126
1137   - return (vcpu->arch.pdptrs[index]);
1138   -}
1139 1127
1140 1128
1141 1129 gfn_t

0 comments on commit 0e20210

Please sign in to comment.
Something went wrong with that request. Please try again.