From: Jack Lange Date: Fri, 15 Jan 2010 17:37:41 +0000 (-0600) Subject: added per core structure to MSR/MEM hooks X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=fd5d916136c80b7c3f873f51a26b88c2149e622b;p=palacios-OLD.git added per core structure to MSR/MEM hooks --- diff --git a/palacios/include/devices/pci.h b/palacios/include/devices/pci.h index 955ce63..bfa9052 100644 --- a/palacios/include/devices/pci.h +++ b/palacios/include/devices/pci.h @@ -59,8 +59,8 @@ struct v3_pci_bar { struct { int num_pages; addr_t default_base_addr; - int (*mem_read)(addr_t guest_addr, void * dst, uint_t length, void * private_data); - int (*mem_write)(addr_t guest_addr, void * src, uint_t length, void * private_data); + int (*mem_read)(struct guest_info * core, addr_t guest_addr, void * dst, uint_t length, void * private_data); + int (*mem_write)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * private_data); }; struct { @@ -71,7 +71,7 @@ struct v3_pci_bar { }; struct { - int (*bar_init)(int bar_num, uint32_t * dst,void * private_data); + int (*bar_init)(int bar_num, uint32_t * dst, void * private_data); int (*bar_write)(int bar_num, uint32_t * src, void * private_data); }; }; diff --git a/palacios/include/palacios/vmm_ctrl_regs.h b/palacios/include/palacios/vmm_ctrl_regs.h index f23caad..0063473 100644 --- a/palacios/include/palacios/vmm_ctrl_regs.h +++ b/palacios/include/palacios/vmm_ctrl_regs.h @@ -212,8 +212,8 @@ int v3_handle_cr4_write(struct guest_info * info); int v3_handle_cr4_read(struct guest_info * info); -int v3_handle_efer_write(uint_t msr, struct v3_msr src, void * priv_data); -int v3_handle_efer_read(uint_t msr, struct v3_msr * dst, void * priv_data); +int v3_handle_efer_write(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data); +int v3_handle_efer_read(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data); #endif // ! __V3VEE__ diff --git a/palacios/include/palacios/vmm_emulator.h b/palacios/include/palacios/vmm_emulator.h index 46836cd..9d1b6be 100644 --- a/palacios/include/palacios/vmm_emulator.h +++ b/palacios/include/palacios/vmm_emulator.h @@ -28,12 +28,12 @@ int v3_emulate_write_op(struct guest_info * info, addr_t write_gva, addr_t write_gpa, addr_t dst_addr, - int (*write_fn)(addr_t guest_addr, void * src, uint_t length, void * priv_data), + int (*write_fn)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data), void * priv_data); int v3_emulate_read_op(struct guest_info * info, addr_t read_gva, addr_t read_gpa, addr_t src_addr, - int (*read_fn)(addr_t guest_addr, void * dst, uint_t length, void * priv_data), - int (*write_fn)(addr_t guest_addr, void * src, uint_t length, void * priv_data), + int (*read_fn)(struct guest_info * core, addr_t guest_addr, void * dst, uint_t length, void * priv_data), + int (*write_fn)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data), void * priv_data); diff --git a/palacios/include/palacios/vmm_mem.h b/palacios/include/palacios/vmm_mem.h index b318526..14423fe 100644 --- a/palacios/include/palacios/vmm_mem.h +++ b/palacios/include/palacios/vmm_mem.h @@ -56,9 +56,9 @@ struct v3_shadow_region { addr_t host_addr; // This either points to a host address mapping // Called when data is read from a memory page - int (*read_hook)(addr_t guest_addr, void * dst, uint_t length, void * priv_data); + int (*read_hook)(struct guest_info * core, addr_t guest_addr, void * dst, uint_t length, void * priv_data); // Called when data is written to a memory page - int (*write_hook)(addr_t guest_addr, void * src, uint_t length, void * priv_data); + int (*write_hook)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data); void * priv_data; @@ -88,13 +88,13 @@ int v3_add_shadow_mem(struct v3_vm_info * vm, uint16_t core_id, int v3_hook_full_mem(struct v3_vm_info * vm, uint16_t core_id, addr_t guest_addr_start, addr_t guest_addr_end, - int (*read)(addr_t guest_addr, void * dst, uint_t length, void * priv_data), - int (*write)(addr_t guest_addr, void * src, uint_t length, void * priv_data), + int (*read)(struct guest_info * core, addr_t guest_addr, void * dst, uint_t length, void * priv_data), + int (*write)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data), void * priv_data); int v3_hook_write_mem(struct v3_vm_info * vm, uint16_t core_id, addr_t guest_addr_start, addr_t guest_addr_end, addr_t host_addr, - int (*write)(addr_t guest_addr, void * src, uint_t length, void * priv_data), + int (*write)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data), void * priv_data); diff --git a/palacios/include/palacios/vmm_msr.h b/palacios/include/palacios/vmm_msr.h index 053644a..f494772 100644 --- a/palacios/include/palacios/vmm_msr.h +++ b/palacios/include/palacios/vmm_msr.h @@ -47,8 +47,8 @@ typedef struct v3_msr v3_msr_t; struct v3_msr_hook { uint_t msr; - int (*read)(uint_t msr, struct v3_msr * dst, void * priv_data); - int (*write)(uint_t msr, struct v3_msr src, void * priv_data); + int (*read)(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data); + int (*write)(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data); void * priv_data; @@ -74,8 +74,8 @@ void v3_init_msr_map(struct v3_vm_info * vm); int v3_unhook_msr(struct v3_vm_info * vm, uint_t msr); int v3_hook_msr(struct v3_vm_info * vm, uint_t msr, - int (*read)(uint_t msr, struct v3_msr * dst, void * priv_data), - int (*write)(uint_t msr, struct v3_msr src, void * priv_data), + int (*read)(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data), + int (*write)(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data), void * priv_data); diff --git a/palacios/src/palacios/vmm_ctrl_regs.c b/palacios/src/palacios/vmm_ctrl_regs.c index d3e9360..04fba8e 100644 --- a/palacios/src/palacios/vmm_ctrl_regs.c +++ b/palacios/src/palacios/vmm_ctrl_regs.c @@ -542,11 +542,10 @@ int v3_handle_cr4_write(struct guest_info * info) { } -int v3_handle_efer_read(uint_t msr, struct v3_msr * dst, void * priv_data) { - struct guest_info * info = (struct guest_info *)(priv_data); - PrintDebug("EFER Read HI=%x LO=%x\n", info->shdw_pg_state.guest_efer.hi, info->shdw_pg_state.guest_efer.lo); +int v3_handle_efer_read(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data) { + PrintDebug("EFER Read HI=%x LO=%x\n", core->shdw_pg_state.guest_efer.hi, core->shdw_pg_state.guest_efer.lo); - dst->value = info->shdw_pg_state.guest_efer.value; + dst->value = core->shdw_pg_state.guest_efer.value; return 0; } @@ -554,11 +553,10 @@ int v3_handle_efer_read(uint_t msr, struct v3_msr * dst, void * priv_data) { // TODO: this is a disaster we need to clean this up... -int v3_handle_efer_write(uint_t msr, struct v3_msr src, void * priv_data) { - struct guest_info * info = (struct guest_info *)(priv_data); +int v3_handle_efer_write(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data) { //struct efer_64 * new_efer = (struct efer_64 *)&(src.value); - struct efer_64 * shadow_efer = (struct efer_64 *)&(info->ctrl_regs.efer); - struct v3_msr * guest_efer = &(info->shdw_pg_state.guest_efer); + struct efer_64 * shadow_efer = (struct efer_64 *)&(core->ctrl_regs.efer); + struct v3_msr * guest_efer = &(core->shdw_pg_state.guest_efer); PrintDebug("EFER Write\n"); PrintDebug("EFER Write Values: HI=%x LO=%x\n", src.hi, src.lo); diff --git a/palacios/src/palacios/vmm_emulator.c b/palacios/src/palacios/vmm_emulator.c index f80aade..83d6d1a 100644 --- a/palacios/src/palacios/vmm_emulator.c +++ b/palacios/src/palacios/vmm_emulator.c @@ -35,7 +35,7 @@ static int run_op(struct guest_info * info, v3_op_type_t op_type, addr_t src_add // We emulate up to the next 4KB page boundry static int emulate_string_write_op(struct guest_info * info, struct x86_instr * dec_instr, addr_t write_gva, addr_t write_gpa, addr_t dst_addr, - int (*write_fn)(addr_t guest_addr, void * src, uint_t length, void * priv_data), + int (*write_fn)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data), void * priv_data) { uint_t emulation_length = 0; uint_t emulation_iter_cnt = 0; @@ -126,7 +126,7 @@ static int emulate_string_write_op(struct guest_info * info, struct x86_instr * return -1; } - if (write_fn(write_gpa, (void *)dst_addr, emulation_length, priv_data) != emulation_length) { + if (write_fn(info, write_gpa, (void *)dst_addr, emulation_length, priv_data) != emulation_length) { PrintError("Did not fully read hooked data\n"); return -1; } @@ -141,7 +141,7 @@ static int emulate_string_write_op(struct guest_info * info, struct x86_instr * static int emulate_xchg_write_op(struct guest_info * info, struct x86_instr * dec_instr, addr_t write_gva, addr_t write_gpa, addr_t dst_addr, - int (*write_fn)(addr_t guest_addr, void * src, uint_t length, void * priv_data), + int (*write_fn)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data), void * priv_data) { addr_t src_addr = 0; addr_t em_dst_addr = 0; @@ -197,7 +197,7 @@ static int emulate_xchg_write_op(struct guest_info * info, struct x86_instr * de return -1; } - if (write_fn(write_gpa, (void *)dst_addr, dst_op_len, priv_data) != dst_op_len) { + if (write_fn(info, write_gpa, (void *)dst_addr, dst_op_len, priv_data) != dst_op_len) { PrintError("Did not fully write hooked data\n"); return -1; } @@ -211,8 +211,8 @@ static int emulate_xchg_write_op(struct guest_info * info, struct x86_instr * de static int emulate_xchg_read_op(struct guest_info * info, struct x86_instr * dec_instr, addr_t read_gva, addr_t read_gpa, addr_t src_addr, - int (*read_fn)(addr_t guest_addr, void * dst, uint_t length, void * priv_data), - int (*write_fn)(addr_t guest_addr, void * src, uint_t length, void * priv_data), + int (*read_fn)(struct guest_info * core, addr_t guest_addr, void * dst, uint_t length, void * priv_data), + int (*write_fn)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data), void * priv_data) { addr_t em_src_addr = 0; addr_t em_dst_addr = 0; @@ -262,7 +262,7 @@ static int emulate_xchg_read_op(struct guest_info * info, struct x86_instr * dec (void *)em_dst_addr, (void *)em_src_addr); - if (read_fn(read_gpa, (void *)src_addr, src_op_len, priv_data) != src_op_len) { + if (read_fn(info, read_gpa, (void *)src_addr, src_op_len, priv_data) != src_op_len) { PrintError("Did not fully read hooked data\n"); return -1; } @@ -272,7 +272,7 @@ static int emulate_xchg_read_op(struct guest_info * info, struct x86_instr * dec return -1; } - if (write_fn(read_gpa, (void *)src_addr, dst_op_len, priv_data) != dst_op_len) { + if (write_fn(info, read_gpa, (void *)src_addr, dst_op_len, priv_data) != dst_op_len) { PrintError("Did not fully write hooked data\n"); return -1; } @@ -286,7 +286,7 @@ static int emulate_xchg_read_op(struct guest_info * info, struct x86_instr * dec int v3_emulate_write_op(struct guest_info * info, addr_t write_gva, addr_t write_gpa, addr_t dst_addr, - int (*write_fn)(addr_t guest_addr, void * src, uint_t length, void * priv_data), + int (*write_fn)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data), void * priv_data) { struct x86_instr dec_instr; uchar_t instr[15]; @@ -366,7 +366,7 @@ int v3_emulate_write_op(struct guest_info * info, addr_t write_gva, addr_t write return -1; } - if (write_fn(write_gpa, (void *)dst_addr, dst_op_len, priv_data) != dst_op_len) { + if (write_fn(info, write_gpa, (void *)dst_addr, dst_op_len, priv_data) != dst_op_len) { PrintError("Did not fully write hooked data\n"); return -1; } @@ -378,8 +378,8 @@ int v3_emulate_write_op(struct guest_info * info, addr_t write_gva, addr_t write int v3_emulate_read_op(struct guest_info * info, addr_t read_gva, addr_t read_gpa, addr_t src_addr, - int (*read_fn)(addr_t guest_addr, void * dst, uint_t length, void * priv_data), - int (*write_fn)(addr_t guest_addr, void * src, uint_t length, void * priv_data), + int (*read_fn)(struct guest_info * core, addr_t guest_addr, void * dst, uint_t length, void * priv_data), + int (*write_fn)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data), void * priv_data) { struct x86_instr dec_instr; uchar_t instr[15]; @@ -451,7 +451,7 @@ int v3_emulate_read_op(struct guest_info * info, addr_t read_gva, addr_t read_gp PrintDebug("Dst_Addr = %p, SRC Addr = %p\n", (void *)dst_addr, (void *)src_addr); - if (read_fn(read_gpa, (void *)src_addr, src_op_len, priv_data) != src_op_len) { + if (read_fn(info, read_gpa, (void *)src_addr, src_op_len, priv_data) != src_op_len) { PrintError("Did not fully read hooked data\n"); return -1; } diff --git a/palacios/src/palacios/vmm_mem.c b/palacios/src/palacios/vmm_mem.c index ea3dec6..0c66a43 100644 --- a/palacios/src/palacios/vmm_mem.c +++ b/palacios/src/palacios/vmm_mem.c @@ -128,7 +128,7 @@ int v3_add_shadow_mem( struct v3_vm_info * vm, uint16_t core_id, int v3_hook_write_mem(struct v3_vm_info * vm, uint16_t core_id, addr_t guest_addr_start, addr_t guest_addr_end, addr_t host_addr, - int (*write)(addr_t guest_addr, void * src, uint_t length, void * priv_data), + int (*write)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data), void * priv_data) { struct v3_shadow_region * entry = (struct v3_shadow_region *)V3_Malloc(sizeof(struct v3_shadow_region)); @@ -153,8 +153,8 @@ int v3_hook_write_mem(struct v3_vm_info * vm, uint16_t core_id, int v3_hook_full_mem(struct v3_vm_info * vm, uint16_t core_id, addr_t guest_addr_start, addr_t guest_addr_end, - int (*read)(addr_t guest_addr, void * dst, uint_t length, void * priv_data), - int (*write)(addr_t guest_addr, void * src, uint_t length, void * priv_data), + int (*read)(struct guest_info * core, addr_t guest_addr, void * dst, uint_t length, void * priv_data), + int (*write)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data), void * priv_data) { struct v3_shadow_region * entry = (struct v3_shadow_region *)V3_Malloc(sizeof(struct v3_shadow_region)); diff --git a/palacios/src/palacios/vmm_msr.c b/palacios/src/palacios/vmm_msr.c index 85bc3f3..96d3ddc 100644 --- a/palacios/src/palacios/vmm_msr.c +++ b/palacios/src/palacios/vmm_msr.c @@ -51,7 +51,7 @@ int v3_handle_msr_write(struct guest_info * info) { msr_val.lo = info->vm_regs.rax; msr_val.hi = info->vm_regs.rdx; - if (hook->write(msr_num, msr_val, hook->priv_data) == -1) { + if (hook->write(info, msr_num, msr_val, hook->priv_data) == -1) { PrintError("Error in MSR hook Write\n"); return -1; } @@ -76,7 +76,7 @@ int v3_handle_msr_read(struct guest_info * info) { msr_val.value = 0; - if (hook->read(msr_num, &msr_val, hook->priv_data) == -1) { + if (hook->read(info, msr_num, &msr_val, hook->priv_data) == -1) { PrintError("Error in MSR hook Read\n"); return -1; } @@ -89,8 +89,8 @@ int v3_handle_msr_read(struct guest_info * info) { } int v3_hook_msr(struct v3_vm_info * vm, uint_t msr, - int (*read)(uint_t msr, struct v3_msr * dst, void * priv_data), - int (*write)(uint_t msr, struct v3_msr src, void * priv_data), + int (*read)(struct guest_info * core, uint_t msr, struct v3_msr * dst, void * priv_data), + int (*write)(struct guest_info * core, uint_t msr, struct v3_msr src, void * priv_data), void * priv_data) { struct v3_msr_map * msr_map = &(vm->msr_map);