Skip to content
This repository was archived by the owner on Jan 28, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions core/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "include/debug.h"
#include "include/dump.h"
#include "include/name.h"
#include "include/vtlb.h"
#include "include/intr.h"
#include "include/ept.h"

Expand Down Expand Up @@ -327,12 +326,7 @@ void vcpu_handle_vmcs_pending(struct vcpu_t *vcpu)
vcpu->vmcs_pending_entry_intr_info = 0;
}

if (vcpu->vmcs_pending_guest_cr3) {
vmwrite(vcpu, GUEST_CR3, vtlb_get_cr3(vcpu));
vcpu->vmcs_pending_guest_cr3 = 0;
}
vcpu->vmcs_pending = 0;
return;
}

/* Return the value same as ioctl value */
Expand Down Expand Up @@ -633,7 +627,7 @@ void load_vmcs_common(struct vcpu_t *vcpu)
vmwrite(vcpu, VMX_TSC_OFFSET, vcpu->tsc_offset);

vmwrite(vcpu, GUEST_ACTIVITY_STATE, vcpu->state->_activity_state);
vcpu_vmwrite_all(vcpu, 0);
vcpu_vmwrite_all(vcpu);
}


Expand Down
1 change: 1 addition & 0 deletions core/include/intr.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ uint hax_intr_is_blocked(struct vcpu_t *vcpu);
void hax_handle_idt_vectoring(struct vcpu_t *vcpu);
void vcpu_inject_intr(struct vcpu_t *vcpu, struct hax_tunnel *htun);
void hax_inject_exception(struct vcpu_t *vcpu, uint8_t vector, uint32_t error_code);
void hax_inject_page_fault(struct vcpu_t *vcpu, mword error_code);
/*
* Get highest pending interrupt vector
* Return HAX_INVALID_INTR_VECTOR when no pending
Expand Down
95 changes: 95 additions & 0 deletions core/include/mmio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If mmio.h and mmio.c are not related with VTLB code clean, better submit in another commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your careful review. These MMIO functions had already existed in VTLB module before. All functions will be invoked by vCPU module currently, so they cannot be omitted because of build reason. All changes this time are atomic. For more details, see the comments at line 727 in previous vtlb.c.

* Copyright (c) 2009 Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef HAX_CORE_MMIO_H_
#define HAX_CORE_MMIO_H_

#include "vcpu.h"

// Reads the given number of bytes from guest RAM (using a GVA) into the given
// buffer. This function is supposed to be called by the MMIO handler to obtain
// the instruction being executed by the given vCPU, which has generated an EPT
// violation. Its implementation should make use of the per-vCPU MMIO fetch
// cache.
// |vcpu| The vCPU executing the MMIO instruction.
// |gva| The GVA pointing to the start of the MMIO instruction in guest RAM.
// |buf| The buffer to copy the bytes to.
// |len| The number of bytes to copy. Must not exceed the maximum length of
// any valid IA instruction.
// Returns 0 on success, or one of the following error codes:
// -ENOMEM: Memory allocation/mapping error.

int mmio_fetch_instruction(struct vcpu_t *vcpu, uint64_t gva, uint8_t *buf,
int len);

// Translates guest virtual address to guest physical address.
// |vcpu| Pointer to the vCPU
// |va| Guest virtual address
// |access| Access descriptor (read/write, user/supervisor)
// |pa| Guest physical address
// |len| Number of bytes for which translation is valid
// |update| Update access and dirty bits of guest structures
// Returns 0 if translation is successful, 0x80000000 OR'ed with the exception
// number otherwise.

uint vcpu_translate(struct vcpu_t *vcpu, hax_vaddr_t va, uint access,
hax_paddr_t *pa, uint64_t *len, bool update);

// Reads guest-linear memory.
// If flag is 0, this read is on behalf of the guest. This function updates the
// access/dirty bits in the guest page tables and injects a page fault if there
// is an error. In this case, the return value is true for success, false if a
// page fault was injected.
// If flag is 1, this function updates the access/dirty bits in the guest page
// tables but does not inject a page fault if there is an error. Instead, it
// returns the number of bytes read.
// If flag is 2, the memory read is for internal use. It does not update the
// guest page tables. It returns the number of bytes read.

uint32_t vcpu_read_guest_virtual(struct vcpu_t *vcpu, hax_vaddr_t addr,
void *dst, uint32_t dst_buflen, uint32_t size,
uint flag);

// Writes guest-linear memory.
// If flag is 0, this memory write is on behalf of the guest. This function
// updates the access/dirty bits in the guest page tables and injects a page
// fault if there is an error. In this case, the return value is true for
// success, false if a page fault was injected.
// If flag is 1, it updates the access/dirty bits in the guest page tables but
// does not inject a page fault if there is an error. Instead, it returns the
// number of bytes written.
// A flag value of 2 is implemented, but not used. It does not update the guest
// page tables. It returns the number of bytes written.

uint32_t vcpu_write_guest_virtual(struct vcpu_t *vcpu, hax_vaddr_t addr,
uint32_t dst_buflen, const void *src,
uint32_t size, uint flag);

#endif // HAX_CORE_MMIO_H_
11 changes: 11 additions & 0 deletions core/include/page_walker.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ typedef uint64_t ADDRESS;
#define PW_INVALID_GPA (~((uint64_t)0))
#define PW_NUM_OF_PDPT_ENTRIES_IN_32_BIT_MODE 4

enum {
TF_OK = 0,
TF_FAILED = 0x80000000, // Translation failed
TF_GP2HP = 0x40000000, // GP->HP translation failed
TF_PROTECT = 0x00000001, // Fault due to protection
TF_WRITE = 0x00000002, // Fault due to write
TF_USER = 0x00000004, // Fault due to user mode
TF_RSVD = 0x00000008, // Fault due to reserved bit violation
TF_EXEC = 0x00000010 // Fault due to exec protection
};

/*
* Function: pw_perform_page_walk
* Description: The function performs page walk over guest page tables for
Expand Down
19 changes: 2 additions & 17 deletions core/include/vcpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ struct gstate {
uint64_t apic_base;
};

struct cvtlb {
hax_vaddr_t va;
hax_paddr_t ha;
uint64_t flags;
uint guest_order;
uint order;
uint access;
uint flag;
};

struct hax_mmu;
struct per_cpu_data;

struct vcpu_vmx_data {
Expand Down Expand Up @@ -179,7 +168,6 @@ struct vcpu_t {
hax_mutex tmutex;

struct vm_t *vm;
struct hax_mmu *mmu;
struct vcpu_state_t *state;
struct hax_tunnel *tunnel;
uint8_t *io_buf;
Expand All @@ -199,7 +187,6 @@ struct vcpu_t {
uint64_t vmcs_pending_entry_error_code : 1;
uint64_t vmcs_pending_entry_instr_length : 1;
uint64_t vmcs_pending_entry_intr_info : 1;
uint64_t vmcs_pending_guest_cr3 : 1;
uint64_t debug_control_dirty : 1;
uint64_t dr_dirty : 1;
uint64_t rflags_dirty : 1;
Expand All @@ -208,7 +195,7 @@ struct vcpu_t {
uint64_t interruptibility_dirty : 1;
uint64_t pcpu_ctls_dirty : 1;
uint64_t pae_pdpt_dirty : 1;
uint64_t padding : 45;
uint64_t padding : 46;
};

/* For TSC offseting feature*/
Expand Down Expand Up @@ -237,7 +224,6 @@ struct vcpu_t {
struct gstate gstate;
struct hax_vcpu_mem *tunnel_vcpumem;
struct hax_vcpu_mem *iobuf_vcpumem;
struct cvtlb prefetch[16];

struct em_context_t emulate_ctxt;
struct vcpu_post_mmio post_mmio;
Expand All @@ -261,11 +247,10 @@ void vcpu_save_guest_state(struct vcpu_t *vcpu);
void vcpu_load_host_state(struct vcpu_t *vcpu);
void vcpu_save_host_state(struct vcpu_t *vcpu);

int vtlb_active(struct vcpu_t *vcpu);
int vcpu_vmexit_handler(struct vcpu_t *vcpu, exit_reason_t exit_reason,
struct hax_tunnel *htun);
void vcpu_vmread_all(struct vcpu_t *vcpu);
void vcpu_vmwrite_all(struct vcpu_t *vcpu, int force_vtlb_flush);
void vcpu_vmwrite_all(struct vcpu_t *vcpu);

int vcpu_teardown(struct vcpu_t *vcpu);

Expand Down
133 changes: 0 additions & 133 deletions core/include/vtlb.h

This file was deleted.

Loading