mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-05 02:40:37 +00:00
hv: Replace dynamic memory allocation for I/O bitmaps
-- Replace pointer with static memory for io_bitmap inside structure vm_arch. -- Refine allow_guest_pio_access/deny_guest_pio_access Tracked-On: #861 Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com> Reviewed-by: Anthony Xu <anthony.xu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
@@ -94,7 +94,7 @@ static inline void init_cx_port(struct vm *vm)
|
||||
if (cx_data->cx_reg.space_id == SPACE_SYSTEM_IO) {
|
||||
uint16_t port = (uint16_t)cx_data->cx_reg.address;
|
||||
|
||||
allow_guest_io_access(vm, port, 1U);
|
||||
allow_guest_pio_access(vm, port, 1U);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -391,44 +391,32 @@ static void empty_io_handler_list(struct vm *vm)
|
||||
void free_io_emulation_resource(struct vm *vm)
|
||||
{
|
||||
empty_io_handler_list(vm);
|
||||
|
||||
/* Free I/O emulation bitmaps */
|
||||
free(vm->arch_vm.iobitmap[0]);
|
||||
free(vm->arch_vm.iobitmap[1]);
|
||||
}
|
||||
|
||||
void allow_guest_io_access(struct vm *vm, uint32_t address_arg, uint32_t nbytes)
|
||||
void allow_guest_pio_access(struct vm *vm, uint16_t port_address,
|
||||
uint32_t nbytes)
|
||||
{
|
||||
uint32_t address = address_arg;
|
||||
uint16_t address = port_address;
|
||||
uint32_t *b;
|
||||
uint32_t i;
|
||||
uint32_t a;
|
||||
|
||||
b = vm->arch_vm.iobitmap[0];
|
||||
b = (uint32_t *)vm->arch_vm.io_bitmap;
|
||||
for (i = 0U; i < nbytes; i++) {
|
||||
if ((address & 0x8000U) != 0U) {
|
||||
b = vm->arch_vm.iobitmap[1];
|
||||
}
|
||||
a = address & 0x7fffU;
|
||||
b[a >> 5U] &= ~(1U << (a & 0x1fU));
|
||||
b[address >> 5U] &= ~(1U << (address & 0x1fU));
|
||||
address++;
|
||||
}
|
||||
}
|
||||
|
||||
static void deny_guest_io_access(struct vm *vm, uint32_t address_arg, uint32_t nbytes)
|
||||
static void deny_guest_pio_access(struct vm *vm, uint16_t port_address,
|
||||
uint32_t nbytes)
|
||||
{
|
||||
uint32_t address = address_arg;
|
||||
uint16_t address = port_address;
|
||||
uint32_t *b;
|
||||
uint32_t i;
|
||||
uint32_t a;
|
||||
|
||||
b = vm->arch_vm.iobitmap[0];
|
||||
b = (uint32_t *)vm->arch_vm.io_bitmap;
|
||||
for (i = 0U; i < nbytes; i++) {
|
||||
if ((address & 0x8000U) != 0U) {
|
||||
b = vm->arch_vm.iobitmap[1];
|
||||
}
|
||||
a = address & 0x7fffU;
|
||||
b[a >> 5U] |= (1U << (a & 0x1fU));
|
||||
b[address >> 5U] |= (1U << (address & 0x1fU));
|
||||
address++;
|
||||
}
|
||||
}
|
||||
@@ -456,20 +444,11 @@ static struct vm_io_handler *create_io_handler(uint32_t port, uint32_t len,
|
||||
|
||||
void setup_io_bitmap(struct vm *vm)
|
||||
{
|
||||
/* Allocate VM architecture state and IO bitmaps A and B */
|
||||
vm->arch_vm.iobitmap[0] = alloc_page();
|
||||
vm->arch_vm.iobitmap[1] = alloc_page();
|
||||
|
||||
ASSERT((vm->arch_vm.iobitmap[0] != NULL) &&
|
||||
(vm->arch_vm.iobitmap[1] != NULL), "");
|
||||
|
||||
if (is_vm0(vm)) {
|
||||
(void)memset(vm->arch_vm.iobitmap[0], 0x00U, CPU_PAGE_SIZE);
|
||||
(void)memset(vm->arch_vm.iobitmap[1], 0x00U, CPU_PAGE_SIZE);
|
||||
(void)memset(vm->arch_vm.io_bitmap, 0x00U, CPU_PAGE_SIZE * 2);
|
||||
} else {
|
||||
/* block all IO port access from Guest */
|
||||
(void)memset(vm->arch_vm.iobitmap[0], 0xFFU, CPU_PAGE_SIZE);
|
||||
(void)memset(vm->arch_vm.iobitmap[1], 0xFFU, CPU_PAGE_SIZE);
|
||||
(void)memset(vm->arch_vm.io_bitmap, 0xFFU, CPU_PAGE_SIZE * 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,7 +464,7 @@ void register_io_emulation_handler(struct vm *vm, struct vm_io_range *range,
|
||||
}
|
||||
|
||||
if (is_vm0(vm)) {
|
||||
deny_guest_io_access(vm, range->base, range->len);
|
||||
deny_guest_pio_access(vm, range->base, range->len);
|
||||
}
|
||||
|
||||
handler = create_io_handler(range->base,
|
||||
|
@@ -1022,10 +1022,10 @@ static void init_exec_ctrl(struct vcpu *vcpu)
|
||||
exec_vmwrite32(VMX_CR3_TARGET_COUNT, 0U);
|
||||
|
||||
/* Set up IO bitmap register A and B - pg 2902 24.6.4 */
|
||||
value64 = hva2hpa(vm->arch_vm.iobitmap[0]);
|
||||
value64 = hva2hpa(vm->arch_vm.io_bitmap);
|
||||
exec_vmwrite64(VMX_IO_BITMAP_A_FULL, value64);
|
||||
pr_dbg("VMX_IO_BITMAP_A: 0x%016llx ", value64);
|
||||
value64 = hva2hpa(vm->arch_vm.iobitmap[1]);
|
||||
value64 = hva2hpa(&(vm->arch_vm.io_bitmap[CPU_PAGE_SIZE]));
|
||||
exec_vmwrite64(VMX_IO_BITMAP_B_FULL, value64);
|
||||
pr_dbg("VMX_IO_BITMAP_B: 0x%016llx ", value64);
|
||||
|
||||
|
Reference in New Issue
Block a user