hv: vmtrr: remove vcpu structure pointer from vmtrr

We could use container_of to get vcpu structure pointer from vmtrr. So vcpu
structure pointer is no need in vmtrr structure.

Tracked-On: #4550
Signed-off-by: Li Fei1 <fei1.li@intel.com>
This commit is contained in:
Li Fei1 2020-03-30 14:02:24 +08:00 committed by wenlingz
parent 1946661c51
commit 2b7168da9e
2 changed files with 10 additions and 6 deletions

View File

@ -43,6 +43,11 @@ static struct fixed_range_mtrr_maps fixed_mtrr_map[FIXED_RANGE_MTRR_NUM] = {
{ MSR_IA32_MTRR_FIX4K_F8000, 0xF8000U, 0x1000U }, { MSR_IA32_MTRR_FIX4K_F8000, 0xF8000U, 0x1000U },
}; };
static inline struct acrn_vcpu *vmtrr2vcpu(const struct acrn_vmtrr *vmtrr)
{
return container_of(container_of(vmtrr, struct acrn_vcpu_arch, vmtrr), struct acrn_vcpu, arch);
}
static uint32_t get_index_of_fixed_mtrr(uint32_t msr) static uint32_t get_index_of_fixed_mtrr(uint32_t msr)
{ {
uint32_t i; uint32_t i;
@ -92,8 +97,6 @@ void init_vmtrr(struct acrn_vcpu *vcpu)
union mtrr_cap_reg cap = {0}; union mtrr_cap_reg cap = {0};
uint32_t i; uint32_t i;
vmtrr->vcpu = vcpu;
/* /*
* We emulate fixed range MTRRs only * We emulate fixed range MTRRs only
* And expecting the guests won't write variable MTRRs * And expecting the guests won't write variable MTRRs
@ -165,6 +168,7 @@ static void update_ept_mem_type(const struct acrn_vmtrr *vmtrr)
uint8_t type; uint8_t type;
uint64_t start, size; uint64_t start, size;
uint32_t i, j; uint32_t i, j;
struct acrn_vm *vm = vmtrr2vcpu(vmtrr)->vm;
/* /*
* Intel SDM, Vol 3, 11.11.2.1 Section "IA32_MTRR_DEF_TYPE MSR": * Intel SDM, Vol 3, 11.11.2.1 Section "IA32_MTRR_DEF_TYPE MSR":
@ -172,7 +176,7 @@ static void update_ept_mem_type(const struct acrn_vmtrr *vmtrr)
* - when def_type.FE is clear, MTRRdefType.type is applied * - when def_type.FE is clear, MTRRdefType.type is applied
*/ */
if (!is_mtrr_enabled(vmtrr) || !is_fixed_range_mtrr_enabled(vmtrr)) { if (!is_mtrr_enabled(vmtrr) || !is_fixed_range_mtrr_enabled(vmtrr)) {
update_ept(vmtrr->vcpu->vm, 0U, MAX_FIXED_RANGE_ADDR, get_default_memory_type(vmtrr)); update_ept(vm, 0U, MAX_FIXED_RANGE_ADDR, get_default_memory_type(vmtrr));
} else { } else {
/* Deal with fixed-range MTRRs only */ /* Deal with fixed-range MTRRs only */
for (i = 0U; i < FIXED_RANGE_MTRR_NUM; i++) { for (i = 0U; i < FIXED_RANGE_MTRR_NUM; i++) {
@ -185,14 +189,14 @@ static void update_ept_mem_type(const struct acrn_vmtrr *vmtrr)
if (type == vmtrr->fixed_range[i].type[j]) { if (type == vmtrr->fixed_range[i].type[j]) {
size += get_subrange_size_of_fixed_mtrr(i); size += get_subrange_size_of_fixed_mtrr(i);
} else { } else {
update_ept(vmtrr->vcpu->vm, start, size, type); update_ept(vm, start, size, type);
type = vmtrr->fixed_range[i].type[j]; type = vmtrr->fixed_range[i].type[j];
start = get_subrange_start_of_fixed_mtrr(i, j); start = get_subrange_start_of_fixed_mtrr(i, j);
size = get_subrange_size_of_fixed_mtrr(i); size = get_subrange_size_of_fixed_mtrr(i);
} }
} }
update_ept(vmtrr->vcpu->vm, start, size, type); update_ept(vm, start, size, type);
} }
} }
} }

View File

@ -48,12 +48,12 @@ union mtrr_fixed_range_reg {
}; };
struct acrn_vmtrr { struct acrn_vmtrr {
struct acrn_vcpu *vcpu;
union mtrr_cap_reg cap; union mtrr_cap_reg cap;
union mtrr_def_type_reg def_type; union mtrr_def_type_reg def_type;
union mtrr_fixed_range_reg fixed_range[FIXED_RANGE_MTRR_NUM]; union mtrr_fixed_range_reg fixed_range[FIXED_RANGE_MTRR_NUM];
}; };
struct acrn_vcpu;
/** /**
* @brief Virtual MTRR MSR write * @brief Virtual MTRR MSR write
* *