mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH 3/7] KVM: kvm data structures
Date: Thu, 19 Oct 2006 15:49:53 +0200	[thread overview]
Message-ID: <45378281.2050505@qumranet.com> (raw)
In-Reply-To: <4537818D.4060204@qumranet.com>

Define data structures and some constants for a virtual machine.

Signed-off-by: Yaniv Kamay <yaniv@qumranet.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>

Index: linux-2.6/drivers/kvm/kvm.h
===================================================================
--- /dev/null
+++ linux-2.6/drivers/kvm/kvm.h
@@ -0,0 +1,206 @@
+#ifndef __KVM_H
+#define __KVM_H
+
+#include <linux/types.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/spinlock.h>
+#include <linux/mm.h>
+
+#define INVALID_PAGE (~(hpa_t)0)
+#define UNMAPPED_GVA (~(gpa_t)0)
+
+#define KVM_MAX_VCPUS 1
+#define KVM_MEMORY_SLOTS 4
+#define KVM_NUM_MMU_PAGES 256
+
+#define FX_IMAGE_SIZE 512
+#define FX_IMAGE_ALIGN 16
+#define FX_BUF_SIZE (2 * FX_IMAGE_SIZE + FX_IMAGE_ALIGN)
+
+/*
+ * Address types:
+ *
+ *  gva - guest virtual address
+ *  gpa - guest physical address
+ *  gfn - guest frame number
+ *  hva - host virtual address
+ *  hpa - host physical address
+ *  hfn - host frame number
+ */
+
+typedef unsigned long  gva_t;
+typedef u64            gpa_t;
+typedef unsigned long  gfn_t;
+
+typedef unsigned long  hva_t;
+typedef u64            hpa_t;
+typedef unsigned long  hfn_t;
+
+struct kvm_mmu_page {
+    struct list_head link;
+    hpa_t page_hpa;
+    unsigned long slot_bitmap; /* One bit set per slot which has memory
+                    * in this shadow page.
+                    */
+    int global;              /* Set if all ptes in this page are global */
+    u64 *parent_pte;
+};
+
+struct vmcs {
+    u32 revision_id;
+    u32 abort;
+    char data[0];
+};
+
+struct vmx_msr_entry {
+    u32 index;
+    u32 reserved;
+    u64 data;
+};
+
+struct kvm_vcpu;
+
+/*
+ * x86 supports 3 paging modes (4-level 64-bit, 3-level 64-bit, and 2-level
+ * 32-bit).  The kvm_mmu structure abstracts the details of the current mmu
+ * mode.
+ */
+struct kvm_mmu {
+    void (*new_cr3)(struct kvm_vcpu *vcpu);
+    int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err);
+    void (*inval_page)(struct kvm_vcpu *vcpu, gva_t gva);
+    void (*free)(struct kvm_vcpu *vcpu);
+    gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva);
+    hpa_t root_hpa;
+    int root_level;
+    int shadow_root_level;
+};
+
+struct kvm_guest_debug {
+    int enabled;
+    unsigned long bp[4];
+    int singlestep;
+};
+
+enum {
+    VCPU_REGS_RAX = 0,
+    VCPU_REGS_RCX = 1,
+    VCPU_REGS_RDX = 2,
+    VCPU_REGS_RBX = 3,
+    VCPU_REGS_RSP = 4,
+    VCPU_REGS_RBP = 5,
+    VCPU_REGS_RSI = 6,
+    VCPU_REGS_RDI = 7,
+#ifdef __x86_64__
+    VCPU_REGS_R8 = 8,
+    VCPU_REGS_R9 = 9,
+    VCPU_REGS_R10 = 10,
+    VCPU_REGS_R11 = 11,
+    VCPU_REGS_R12 = 12,
+    VCPU_REGS_R13 = 13,
+    VCPU_REGS_R14 = 14,
+    VCPU_REGS_R15 = 15,
+#endif
+    NR_VCPU_REGS
+};
+
+struct kvm_vcpu {
+    struct kvm *kvm;
+    struct vmcs *vmcs;
+    struct mutex mutex;
+    int   cpu;
+    int   launched;
+    unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */
+#define NR_IRQ_WORDS (256 / BITS_PER_LONG)
+    unsigned long irq_pending[NR_IRQ_WORDS];
+    unsigned long regs[NR_VCPU_REGS]; /* for rsp: vcpu_load_rsp_rip() */
+    unsigned long rip;      /* needs vcpu_load_rsp_rip() */
+
+    unsigned long cr2;
+    unsigned long cr3;
+    unsigned long cr8;
+    u64 shadow_efer;
+    u64 apic_base;
+    struct vmx_msr_entry *guest_msrs;
+    struct vmx_msr_entry *host_msrs;
+
+    struct list_head free_pages;
+    struct kvm_mmu_page page_header_buf[KVM_NUM_MMU_PAGES];
+    struct kvm_mmu mmu;
+
+    struct kvm_guest_debug guest_debug;
+
+    char fx_buf[FX_BUF_SIZE];
+    char *host_fx_image;
+    char *guest_fx_image;
+
+    int mmio_needed;
+    int mmio_read_completed;
+    int mmio_is_write;
+    int mmio_size;
+    unsigned char mmio_data[8];
+    gpa_t mmio_phys_addr;
+
+    struct{
+        int active;
+        u8 save_iopl;
+        struct {
+            unsigned long base;
+            u32 limit;
+            u32 ar;
+        } tr;
+    } rmode;
+};
+
+struct kvm_memory_slot {
+    gfn_t base_gfn;
+    unsigned long npages;
+    unsigned long flags;
+    struct page **phys_mem;
+    unsigned long *dirty_bitmap;
+};
+
+struct kvm {
+    spinlock_t lock; /* protects everything except vcpus */
+    int nmemslots;
+    struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS];
+    struct list_head active_mmu_pages;
+    struct kvm_vcpu vcpus[KVM_MAX_VCPUS];
+    int memory_config_version;
+    int busy;
+};
+
+struct kvm_stat {
+    u32 pf_fixed;
+    u32 pf_guest;
+    u32 tlb_flush;
+    u32 invlpg;
+
+    u32 exits;
+    u32 io_exits;
+    u32 mmio_exits;
+    u32 signal_exits;
+    u32 irq_exits;
+};
+
+extern struct kvm_stat kvm_stat;
+
+#define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt)
+#define vcpu_printf(vcpu, fmt...) kvm_printf(vcpu->kvm, fmt)
+
+void kvm_mmu_destroy(struct kvm_vcpu *vcpu);
+int kvm_mmu_init(struct kvm_vcpu *vcpu);
+
+int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
+void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot);
+
+hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa);
+#define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
+#define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB)
+static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; }
+hpa_t gva_to_hpa(struct kvm_vcpu *vcpu, gva_t gva);
+
+extern hpa_t bad_page_address;
+
+#endif

-- 
error compiling committee.c: too many arguments to function


  parent reply	other threads:[~2006-10-19 13:50 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-19 13:45 [PATCH 0/7] KVM: Kernel-based Virtual Machine Avi Kivity
2006-10-19 13:47 ` [PATCH 1/7] KVM: userspace interface Avi Kivity
2006-10-19 14:30   ` John Stoffel
2006-10-19 14:43     ` Avi Kivity
2006-10-19 23:26       ` Greg KH
2006-10-19 14:50     ` Alan Cox
2006-10-19 14:51       ` Avi Kivity
2006-10-19 15:25         ` John Stoffel
2006-10-19 18:49       ` Anthony Liguori
2006-10-19 19:10         ` Avi Kivity
2006-10-19 19:17           ` Anthony Liguori
2006-10-20  7:36             ` Avi Kivity
2006-10-20 15:33               ` Anthony Liguori
2006-10-22  8:10                 ` Avi Kivity
2006-10-19 20:36         ` Alan Cox
2006-10-19 18:46   ` Anthony Liguori
2006-10-19 19:04     ` Avi Kivity
2006-10-19 19:09       ` Anthony Liguori
2006-10-19 19:26         ` Avi Kivity
2006-10-19 19:31           ` Anthony Liguori
2006-10-19 22:15             ` Alan Cox
2006-10-20  7:42             ` Avi Kivity
2006-10-20 15:35               ` Anthony Liguori
2006-10-19 20:10       ` Andi Kleen
2006-10-19 20:14   ` Jan Engelhardt
2006-10-20  7:16     ` Avi Kivity
2006-10-21 15:50       ` Arnd Bergmann
2006-10-22  8:19         ` Avi Kivity
2006-10-21 13:37   ` Steven Rostedt
2006-10-22  8:14     ` Avi Kivity
2006-10-19 13:48 ` [PATCH 2/7] KVM: Intel virtual mode extensions definitions Avi Kivity
2006-10-19 20:19   ` Jan Engelhardt
2006-10-19 21:54     ` Alan Cox
2006-10-20  7:17     ` Avi Kivity
2006-10-21 13:48   ` Steven Rostedt
2006-10-22  8:17     ` Avi Kivity
2006-10-19 13:49 ` Avi Kivity [this message]
2006-10-19 13:53 ` [PATCH 5/7] KVM: mmu virtualization Avi Kivity
2006-10-19 20:26   ` Jan Engelhardt
2006-10-20  7:24     ` Avi Kivity
2006-10-19 13:54 ` [PATCH 6/7] KVM: x86 emulator Avi Kivity
2006-10-19 13:56 ` [PATCH 7/7] KVM: plumbing Avi Kivity
2006-10-19 13:58 ` [PATCH 0/7] KVM: Kernel-based Virtual Machine Avi Kivity
2006-10-19 16:05 ` Andi Kleen
2006-10-19 16:09   ` Avi Kivity
2006-10-19 19:02     ` Anthony Liguori
2006-10-19 19:14       ` Avi Kivity
2006-10-19 19:28         ` Anthony Liguori
2006-10-20  7:37           ` Avi Kivity
2006-10-19 17:31 ` Muli Ben-Yehuda
2006-10-19 18:00   ` Avi Kivity
2006-10-19 18:12     ` Randy Dunlap
2006-10-19 18:14       ` Avi Kivity
2006-10-19 18:30         ` Randy.Dunlap
2006-10-21 16:16     ` Arnd Bergmann
2006-10-22  8:37       ` Avi Kivity
2006-10-22 15:23         ` Arnd Bergmann
2006-10-22 16:18           ` Avi Kivity
2006-10-22 16:51             ` Arnd Bergmann
2006-10-22 17:01               ` Avi Kivity
2006-10-22 17:06                 ` Arnd Bergmann
2006-10-22 17:41                   ` Avi Kivity
2006-10-22 17:47                     ` Arnd Bergmann
2006-10-22 17:56                 ` Christoph Hellwig
2006-10-22 18:00                   ` Avi Kivity
2006-10-22 18:36                     ` Arnd Bergmann
2006-10-22 18:41                       ` Avi Kivity
2006-10-22 18:49                         ` Arnd Bergmann
2006-10-22 18:55                           ` Avi Kivity
2006-10-22 22:26                     ` Andi Kleen
2006-10-23 22:29                       ` Jeremy Fitzhardinge
2006-10-22 20:01                   ` Alan Cox
2006-10-22 20:45                   ` Roland Dreier
2006-10-23  0:29                   ` Anthony Liguori
2006-10-25 16:42                   ` Pavel Machek
2006-10-22 19:59               ` Alan Cox
2006-10-22 22:28                 ` Andi Kleen
2006-10-23  0:27                   ` Roland Dreier
2006-10-23  0:39                     ` Andi Kleen
2006-10-23  0:51                       ` Roland Dreier
2006-10-22 17:39         ` Anthony Liguori
2006-10-22 17:53           ` Arnd Bergmann
2006-10-22 19:56         ` Alan Cox
2006-10-23  7:42           ` Avi Kivity
2006-10-24 21:38       ` kvm_create() (was Re: [PATCH 0/7] KVM: Kernel-based Virtual Machine) Andy Isaacson
2006-10-19 18:55   ` [PATCH 0/7] KVM: Kernel-based Virtual Machine Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45378281.2050505@qumranet.com \
    --to=avi@qumranet.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome