Commit c8a88195 authored by Charlie Jacobsen's avatar Charlie Jacobsen Committed by Vikram Narayanan

Simple re-naming to arch-agnostic names for arch-dep interface.

-- Moved some vmx-specific data structures into implementation file.
-- lcd_vmx_* => lcd_arch_*
-- updated virt/lcd/lcd-domains.c
parent a46b6017
#ifndef LCD_VMX_H
#define LCD_VMX_H
#ifndef LCD_DOMAINS_ARCH_H
#define LCD_DOMAINS_ARCH_H
#include <asm/vmx.h>
#include <linux/spinlock.h>
struct lcd_vmx_vmcs_config {
int size;
int order;
u32 revision_id;
u32 pin_based_exec_controls;
u32 primary_proc_based_exec_controls;
u32 secondary_proc_based_exec_controls;
u32 vmexit_controls;
u32 vmentry_controls;
};
struct lcd_vmx_vmcs {
struct lcd_arch_vmcs {
u32 revision_id;
u32 abort;
char data[0];
};
struct lcd_vmx_capability {
u32 ept;
u32 vpid;
};
int lcd_vmx_autoload_msrs[] = {
int lcd_arch_autoload_msrs[] = {
/* NONE */
};
#define LCD_VMX_NUM_AUTOLOAD_MSRS 0
#define LCD_ARCH_NUM_AUTOLOAD_MSRS 0
enum lcd_vmx_reg {
LCD_VMX_REGS_RAX = 0,
LCD_VMX_REGS_RCX = 1,
LCD_VMX_REGS_RDX = 2,
LCD_VMX_REGS_RBX = 3,
LCD_VMX_REGS_RSP = 4,
LCD_VMX_REGS_RBP = 5,
LCD_VMX_REGS_RSI = 6,
LCD_VMX_REGS_RDI = 7,
LCD_VMX_REGS_R8 = 8,
LCD_VMX_REGS_R9 = 9,
LCD_VMX_REGS_R10 = 10,
LCD_VMX_REGS_R11 = 11,
LCD_VMX_REGS_R12 = 12,
LCD_VMX_REGS_R13 = 13,
LCD_VMX_REGS_R14 = 14,
LCD_VMX_REGS_R15 = 15,
LCD_VMX_REGS_RIP,
LCD_VMX_NUM_REGS
enum lcd_arch_reg {
LCD_ARCH_REGS_RAX = 0,
LCD_ARCH_REGS_RCX = 1,
LCD_ARCH_REGS_RDX = 2,
LCD_ARCH_REGS_RBX = 3,
LCD_ARCH_REGS_RSP = 4,
LCD_ARCH_REGS_RBP = 5,
LCD_ARCH_REGS_RSI = 6,
LCD_ARCH_REGS_RDI = 7,
LCD_ARCH_REGS_R8 = 8,
LCD_ARCH_REGS_R9 = 9,
LCD_ARCH_REGS_R10 = 10,
LCD_ARCH_REGS_R11 = 11,
LCD_ARCH_REGS_R12 = 12,
LCD_ARCH_REGS_R13 = 13,
LCD_ARCH_REGS_R14 = 14,
LCD_ARCH_REGS_R15 = 15,
LCD_ARCH_REGS_RIP,
LCD_ARCH_NUM_REGS
};
#define LCD_VMX_CS_SELECTOR 1
#define LCD_VMX_FS_SELECTOR 2
#define LCD_VMX_GS_SELECTOR 3
#define LCD_ARCH_CS_SELECTOR 1
#define LCD_ARCH_FS_SELECTOR 2
#define LCD_ARCH_GS_SELECTOR 3
struct lcd_vmx_ept {
struct lcd_arch_ept {
spinlock_t lock;
unsigned long root_hpa;
unsigned long vmcs_ptr;
bool access_dirty_enabled;
};
struct lcd_vmx {
struct lcd_arch {
int cpu;
int launched;
int vpid;
struct lcd_vmx_vmcs *vmcs;
struct lcd_vmx_ept ept;
struct lcd_arch_vmcs *vmcs;
struct lcd_arch_ept ept;
struct desc_struct *gdt;
u8 fail;
......@@ -79,15 +63,15 @@ struct lcd_vmx {
u32 error_code;
u32 vec_no;
u64 host_rsp;
u64 regs[LCD_VMX_NUM_REGS];
u64 regs[LCD_ARCH_NUM_REGS];
u64 cr2;
int shutdown;
int ret_code;
struct msr_autoload {
#if LCD_VMX_NUM_AUTOLOAD_MSRS > 0
struct vmx_msr_entry guest[LCD_VMX_NUM_AUTOLOAD_MSRS];
struct vmx_msr_entry host[LCD_VMX_NUM_AUTOLOAD_MSRS];
#if LCD_ARCH_NUM_AUTOLOAD_MSRS > 0
struct vmx_msr_entry guest[LCD_ARCH_NUM_AUTOLOAD_MSRS];
struct vmx_msr_entry host[LCD_ARCH_NUM_AUTOLOAD_MSRS];
#else
struct vmx_msr_entry *guest;
struct vmx_msr_entry *host;
......@@ -99,23 +83,23 @@ struct lcd_vmx {
* Initializes the arch-dependent code for LCD (detects required
* features, turns on VMX on *all* cpu's).
*/
int lcd_vmx_init(void);
int lcd_arch_init(void);
/**
* Turns off VMX on *all* cpu's and tears down arch-dependent code.
*
* Important: All LCDs should be destroyed before calling this
* routine (otherwise, memory will leak).
*/
void lcd_vmx_exit(void);
void lcd_arch_exit(void);
/**
* Creates the arch-dependent part of an LCD, and initializes
* the settings and most register values.
*/
struct lcd_vmx *lcd_vmx_create(void);
struct lcd_arch *lcd_arch_create(void);
/**
* Tears down arch-dep part of LCD. (If LCD is launched on
* some cpu, it will become inactive.)
*/
void lcd_vmx_destroy(struct lcd_vmx *vcpu);
void lcd_arch_destroy(struct lcd_arch *vcpu);
#endif /* LCD_VMX_H */
#endif /* LCD_DOMAINS_ARCH_H */
......@@ -22,19 +22,38 @@
#include <linux/tboot.h>
#include <linux/slab.h>
static struct lcd_vmx_vmcs_config vmcs_config;
static struct lcd_vmx_capability vmx_capability;
/* VMX DATA STRUCTURES -------------------------------------------------- */
struct vmx_vmcs_config {
int size;
int order;
u32 revision_id;
u32 pin_based_exec_controls;
u32 primary_proc_based_exec_controls;
u32 secondary_proc_based_exec_controls;
u32 vmexit_controls;
u32 vmentry_controls;
};
struct vmx_capability {
u32 ept;
u32 vpid;
};
/* SHARED / PERCPU VARS -------------------------------------------------- */
static struct vmx_vmcs_config vmcs_config;
static struct vmx_capability vmx_capability;
static atomic_t vmx_enable_failed;
static DEFINE_PER_CPU(int, vmx_enabled);
static DEFINE_PER_CPU(struct lcd_vmx_vmcs *, vmxon_area);
static DEFINE_PER_CPU(struct vmx_vmcs *, vmxon_area);
static struct {
DECLARE_BITMAP(bitmap, VMX_NR_VPIDS);
spinlock_t lock;
} vpids;
//static DEFINE_PER_CPU(struct desc_ptr, host_gdt);
static DEFINE_PER_CPU(struct lcd_vmx *, local_vcpu);
static unsigned long *msr_bitmap;
......@@ -197,7 +216,7 @@ static inline void invvpid_single_context(u16 vpid)
/**
* Takes vmcs from any state to {inactive, clear, not current}
*/
static void vmcs_clear(struct lcd_vmx_vmcs *vmcs)
static void vmcs_clear(struct vmx_vmcs *vmcs)
{
u64 phys_addr = __pa(vmcs);
u8 error;
......@@ -214,7 +233,7 @@ static void vmcs_clear(struct lcd_vmx_vmcs *vmcs)
* Takes vmcs to {active, current} on cpu. Any vmcs reads and writes
* will affect this vmcs.
*/
static void vmcs_load(struct lcd_vmx_vmcs *vmcs)
static void vmcs_load(struct vmx_vmcs *vmcs)
{
u64 phys_addr = __pa(vmcs);
u8 error;
......@@ -288,7 +307,7 @@ static void vmcs_write64(unsigned long field, u64 value)
/**
* Frees vmcs memory.
*/
static void vmx_free_vmcs(struct lcd_vmx_vmcs *vmcs)
static void vmx_free_vmcs(struct vmx_vmcs *vmcs)
{
free_pages((unsigned long)vmcs, vmcs_config.order);
}
......@@ -297,11 +316,11 @@ static void vmx_free_vmcs(struct lcd_vmx_vmcs *vmcs)
* Allocates memory for a vmcs on cpu, and sets the
* revision id.
*/
static struct lcd_vmx_vmcs *vmx_alloc_vmcs(int cpu)
static struct vmx_vmcs *vmx_alloc_vmcs(int cpu)
{
int node;
struct page *pages;
struct lcd_vmx_vmcs *vmcs;
struct vmx_vmcs *vmcs;
node = cpu_to_node(cpu);
pages = alloc_pages_exact_node(node, GFP_KERNEL, vmcs_config.order);
......@@ -333,7 +352,7 @@ static inline void __vmxoff(void)
* Helper for vmx_enable. A few more low-level checks and
* settings, and then turns on vmx.
*/
static int __vmx_enable(struct lcd_vmx_vmcs *vmxon_buf)
static int __vmx_enable(struct vmx_vmcs *vmxon_buf)
{
u64 phys_addr;
u64 old;
......@@ -387,7 +406,7 @@ static int __vmx_enable(struct lcd_vmx_vmcs *vmxon_buf)
static void vmx_enable(void *unused)
{
int ret;
struct lcd_vmx_vmcs *vmxon_buf;
struct vmx_vmcs *vmxon_buf;
vmxon_buf = __get_cpu_var(vmxon_area);
......@@ -491,7 +510,7 @@ static void vmx_disable_intercept_for_msr(unsigned long *msr_bitmap, u32 msr)
/**
* Checks and sets basic vmcs settings (vmxon region size, etc.)
*/
static int vmcs_config_basic_settings(struct lcd_vmx_vmcs_config *vmcs_conf)
static int vmcs_config_basic_settings(struct vmx_vmcs_config *vmcs_conf)
{
u32 msr_low;
u32 msr_high;
......@@ -589,7 +608,7 @@ static int adjust_vmx_controls(u32 *controls, u32 reserved_mask, u32 msr)
* vm entries, vm exits, vm execution (e.g., interrupt handling),
* etc. for all lcd types.
*/
static int setup_vmcs_config(struct lcd_vmx_vmcs_config *vmcs_conf)
static int setup_vmcs_config(struct vmx_vmcs_config *vmcs_conf)
{
u32 pin_based_exec_controls;
u32 primary_proc_based_exec_controls;
......@@ -805,7 +824,7 @@ int lcd_vmx_init(void)
*/
for_each_possible_cpu(cpu) {
struct lcd_vmx_vmcs *vmxon_buf;
struct vmx_vmcs *vmxon_buf;
vmxon_buf = vmx_alloc_vmcs(cpu);
if (!vmxon_buf) {
......
......@@ -15,7 +15,7 @@
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/lcd-domains.h>
#include <asm/lcd-vmx.h>
#include <asm/lcd-domains-arch.h>
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("LCD driver");
......@@ -68,7 +68,7 @@ static int __init lcd_init(void)
printk(KERN_ERR "LCD module loaded\n");
if ((r = lcd_vmx_init())) {
if ((r = lcd_arch_init())) {
printk(KERN_ERR "lcd: failed to initialize vmx\n");
return r;
}
......@@ -85,7 +85,7 @@ static int __init lcd_init(void)
static void __exit lcd_exit(void)
{
misc_deregister(&lcd_dev);
lcd_vmx_exit();
lcd_arch_exit();
}
module_init(lcd_init);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment